Class ServerUtils

java.lang.Object
io.micronaut.testresources.buildtools.ServerUtils

public class ServerUtils extends Object
Utilities used to manage the lifecycle of a server process from build tools.
  • Field Details

  • Constructor Details

    • ServerUtils

      public ServerUtils()
  • Method Details

    • writeServerSettings

      public static void writeServerSettings(Path destinationDirectory, ServerSettings settings) throws IOException
      Writes the server settings in an output directory.
      Parameters:
      destinationDirectory - the destination directory
      settings - the settings
      Throws:
      IOException - if an error occurs
    • readServerSettings

      public static Optional<ServerSettings> readServerSettings(Path settingsDirectory)
      Reads the server settings from an input directory.
      Parameters:
      settingsDirectory - the settings directory
      Returns:
      the server settings, if any
    • isServerStarted

      public static boolean isServerStarted(int port)
      Determines if a server is already started at the given port.
      Parameters:
      port - the port to check
      Returns:
      true if the port is already bound
    • startOrConnectToExistingServer

      public static ServerSettings startOrConnectToExistingServer(Integer explicitPort, Path portFilePath, Path serverSettingsDirectory, String accessToken, Path cdsDirectory, Collection<File> serverClasspath, Integer clientTimeoutMs, Integer serverIdleTimeoutMinutes, ServerFactory serverFactory) throws IOException
      Starts a server at the given port, or connects to an existing server running at the given port.
      Parameters:
      explicitPort - the explicit port to connect to, if it exists.
      portFilePath - the path to the port file, where the port will be written.
      serverSettingsDirectory - the server settings directory, will be written.
      accessToken - the access token, if any
      cdsDirectory - the CDS directory. If not null, class data sharing will be enabled
      serverClasspath - the server classpath
      clientTimeoutMs - the client timeout
      serverIdleTimeoutMinutes - the server idle timeout
      serverFactory - the server factory, responsible for forking a process
      Returns:
      the server settings once the server is started
      Throws:
      IOException - if an error occurs
    • startOrConnectToExistingServer

      public static ServerSettings startOrConnectToExistingServer(Integer explicitPort, Path portFilePath, Path serverSettingsDirectory, String accessToken, Collection<File> serverClasspath, Integer clientTimeoutMs, Integer serverIdleTimeoutMinutes, ServerFactory serverFactory) throws IOException
      Starts a server at the given port, or connects to an existing server running at the given port.
      Parameters:
      explicitPort - the explicit port to connect to, if it exists.
      portFilePath - the path to the port file, where the port will be written.
      serverSettingsDirectory - the server settings directory, will be written.
      accessToken - the access token, if any
      serverClasspath - the server classpath
      clientTimeoutMs - the client timeout
      serverIdleTimeoutMinutes - the server idle timeout
      serverFactory - the server factory, responsible for forking a process
      Returns:
      the server settings once the server is started
      Throws:
      IOException - if an error occurs
    • stopServer

      public static void stopServer(Path serverSettingsDirectory) throws IOException
      Stops a running server. The server will be contacted thanks to the settings in the given directory.
      Parameters:
      serverSettingsDirectory - the settings directory
      Throws:
      IOException - if an error occurs
    • getDefaultSharedSettingsPath

      public static Path getDefaultSharedSettingsPath()
      Returns the default path to the settings directory for the test resources server in case it needs to be shared between builds. Equivalent to calling getDefaultSharedSettingsPath(String) without a namespace.
      Returns:
      the default path to the settings directory
    • getDefaultSharedSettingsPath

      public static Path getDefaultSharedSettingsPath(String namespace)
      Returns the default path to the settings directory for the test resources server in case it needs to be shared between builds.
      Parameters:
      namespace - the namespace of the shared settings
      Returns:
      the default path to the settings directory