Package com.google.cloud.testing
Class BaseEmulatorHelper<T extends ServiceOptions>
- java.lang.Object
-
- com.google.cloud.testing.BaseEmulatorHelper<T>
-
@InternalApi public abstract class BaseEmulatorHelper<T extends ServiceOptions> extends Object
Utility class to start and stop a local service which is used by unit testing.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
BaseEmulatorHelper.DownloadableEmulatorRunner
Utility class to start and run an emulator from a download URL.protected static interface
BaseEmulatorHelper.EmulatorRunner
Utility interface to start and run an emulator.protected static class
BaseEmulatorHelper.GcloudEmulatorRunner
Utility class to start and run an emulator from the Google Cloud SDK.
-
Field Summary
Fields Modifier and Type Field Description protected static String
DEFAULT_HOST
protected static int
DEFAULT_PORT
protected static String
PROJECT_ID_PREFIX
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseEmulatorHelper(String emulator, int port, String projectId)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static int
findAvailablePort(int defaultPort)
protected abstract List<BaseEmulatorHelper.EmulatorRunner>
getEmulatorRunners()
Returns the emulator runners supported by this emulator.protected abstract Logger
getLogger()
Returns a logger.abstract T
getOptions()
Returns service options to access the local emulator.int
getPort()
Returns the port to which the local emulator is listening.String
getProjectId()
Returns the project ID associated with the local emulator.protected static boolean
isWindows()
abstract void
reset()
Resets the internal state of the emulator.protected String
sendPostRequest(String request)
abstract void
start()
Starts the local emulator.protected void
startProcess(String blockUntilOutput)
Starts the local service as a subprocess.abstract void
stop(org.threeten.bp.Duration timeout)
Stops the local emulator.protected int
waitForProcess(org.threeten.bp.Duration timeout)
Waits for the local service's subprocess to terminate, and stop any possible thread listening for its output.
-
-
-
Field Detail
-
PROJECT_ID_PREFIX
protected static final String PROJECT_ID_PREFIX
- See Also:
- Constant Field Values
-
DEFAULT_HOST
protected static final String DEFAULT_HOST
- See Also:
- Constant Field Values
-
DEFAULT_PORT
protected static final int DEFAULT_PORT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getEmulatorRunners
protected abstract List<BaseEmulatorHelper.EmulatorRunner> getEmulatorRunners()
Returns the emulator runners supported by this emulator. Runners are evaluated in order, the first available runner is selected and executed
-
getLogger
protected abstract Logger getLogger()
Returns a logger.
-
startProcess
protected final void startProcess(String blockUntilOutput) throws IOException, InterruptedException
Starts the local service as a subprocess. Blocks the execution untilblockUntilOutput
is found on stdout.- Throws:
IOException
InterruptedException
-
waitForProcess
protected final int waitForProcess(org.threeten.bp.Duration timeout) throws IOException, InterruptedException, TimeoutException
Waits for the local service's subprocess to terminate, and stop any possible thread listening for its output.
-
getPort
public int getPort()
Returns the port to which the local emulator is listening.
-
getProjectId
public String getProjectId()
Returns the project ID associated with the local emulator.
-
getOptions
public abstract T getOptions()
Returns service options to access the local emulator.
-
start
public abstract void start() throws IOException, InterruptedException
Starts the local emulator.- Throws:
IOException
InterruptedException
-
stop
public abstract void stop(org.threeten.bp.Duration timeout) throws IOException, InterruptedException, TimeoutException
Stops the local emulator.
-
reset
public abstract void reset() throws IOException
Resets the internal state of the emulator.- Throws:
IOException
-
sendPostRequest
protected final String sendPostRequest(String request) throws IOException
- Throws:
IOException
-
findAvailablePort
protected static int findAvailablePort(int defaultPort)
-
isWindows
protected static boolean isWindows()
-
-