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 classBaseEmulatorHelper.DownloadableEmulatorRunnerUtility class to start and run an emulator from a download URL.protected static interfaceBaseEmulatorHelper.EmulatorRunnerUtility interface to start and run an emulator.protected static classBaseEmulatorHelper.GcloudEmulatorRunnerUtility class to start and run an emulator from the Google Cloud SDK.
-
Field Summary
Fields Modifier and Type Field Description protected static StringDEFAULT_HOSTprotected static intDEFAULT_PORTprotected static StringPROJECT_ID_PREFIX
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseEmulatorHelper(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 intfindAvailablePort(int defaultPort)protected abstract List<BaseEmulatorHelper.EmulatorRunner>getEmulatorRunners()Returns the emulator runners supported by this emulator.protected abstract LoggergetLogger()Returns a logger.abstract TgetOptions()Returns service options to access the local emulator.intgetPort()Returns the port to which the local emulator is listening.StringgetProjectId()Returns the project ID associated with the local emulator.protected static booleanisWindows()abstract voidreset()Resets the internal state of the emulator.protected StringsendPostRequest(String request)abstract voidstart()Starts the local emulator.protected voidstartProcess(String blockUntilOutput)Starts the local service as a subprocess.abstract voidstop(org.threeten.bp.Duration timeout)Stops the local emulator.protected intwaitForProcess(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
-
-
Constructor Detail
-
BaseEmulatorHelper
@InternalApi("This class should only be extended within google-cloud-java") protected BaseEmulatorHelper(String emulator, int port, String projectId)
-
-
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 untilblockUntilOutputis found on stdout.- Throws:
IOExceptionInterruptedException
-
waitForProcess
protected final int waitForProcess(org.threeten.bp.Duration timeout) throws IOException, InterruptedException, TimeoutExceptionWaits 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, InterruptedExceptionStarts the local emulator.- Throws:
IOExceptionInterruptedException
-
stop
public abstract void stop(org.threeten.bp.Duration timeout) throws IOException, InterruptedException, TimeoutExceptionStops the local emulator.
-
reset
public abstract void reset() throws IOExceptionResets 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()
-
-