Class ServerUtils
java.lang.Object
io.micronaut.testresources.buildtools.ServerUtils
Utilities used to manage the lifecycle of a server process from build tools.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Forking process parameters. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Path
Returns the default path to the settings directory for the test resources server in case it needs to be shared between builds.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.static boolean
isServerStarted
(int port) Determines if a server is already started at the given port.static Optional<ServerSettings>
readServerSettings
(Path settingsDirectory) Reads the server settings from an input directory.static ServerSettings
startOrConnectToExistingServer
(Integer explicitPort, Path portFilePath, Path serverSettingsDirectory, String accessToken, Path cdsDirectory, Collection<File> serverClasspath, Integer clientTimeoutMs, Integer serverIdleTimeoutMinutes, ServerFactory serverFactory) Starts a server at the given port, or connects to an existing server running at the given port.static ServerSettings
startOrConnectToExistingServer
(Integer explicitPort, Path portFilePath, Path serverSettingsDirectory, String accessToken, Collection<File> serverClasspath, Integer clientTimeoutMs, Integer serverIdleTimeoutMinutes, ServerFactory serverFactory) Starts a server at the given port, or connects to an existing server running at the given port.static void
stopServer
(Path serverSettingsDirectory) Stops a running server.static void
writeServerSettings
(Path destinationDirectory, ServerSettings settings) Writes the server settings in an output directory.
-
Field Details
-
PROPERTIES_FILE_NAME
- See Also:
-
SERVER_TEST_PROPERTY
Used only in tests to skip actual port checking.- See Also:
-
-
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 directorysettings
- the settings- Throws:
IOException
- if an error occurs
-
readServerSettings
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 anycdsDirectory
- the CDS directory. If not null, class data sharing will be enabledserverClasspath
- the server classpathclientTimeoutMs
- the client timeoutserverIdleTimeoutMinutes
- the server idle timeoutserverFactory
- 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 anyserverClasspath
- the server classpathclientTimeoutMs
- the client timeoutserverIdleTimeoutMinutes
- the server idle timeoutserverFactory
- the server factory, responsible for forking a process- Returns:
- the server settings once the server is started
- Throws:
IOException
- if an error occurs
-
stopServer
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
-