Package com.google.cloud.testing
Class BaseEmulatorHelper<T extends ServiceOptions>
java.lang.Object
com.google.cloud.testing.BaseEmulatorHelper<T>
Utility class to start and stop a local service which is used by unit testing.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classUtility class to start and run an emulator from a download URL.protected static interfaceUtility interface to start and run an emulator.protected static classUtility class to start and run an emulator from the Google Cloud SDK. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseEmulatorHelper(String emulator, int port, String projectId) -
Method Summary
Modifier and TypeMethodDescriptionprotected static intfindAvailablePort(int defaultPort) protected abstract List<BaseEmulatorHelper.EmulatorRunner>Returns the emulator runners supported by this emulator.protected abstract LoggerReturns a logger.abstract TReturns service options to access the local emulator.intgetPort()Returns the port to which the local emulator is listening.Returns the project ID associated with the local emulator.protected static booleanabstract voidreset()Resets the internal state of the emulator.protected final StringsendPostRequest(String request) abstract voidstart()Starts the local emulator.protected final voidstartProcess(String blockUntilOutput) Starts the local service as a subprocess.abstract voidstop(org.threeten.bp.Duration timeout) Stops the local emulator.protected final 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 Details
-
PROJECT_ID_PREFIX
- See Also:
-
DEFAULT_HOST
- See Also:
-
DEFAULT_PORT
protected static final int DEFAULT_PORT- See Also:
-
-
Constructor Details
-
BaseEmulatorHelper
@InternalApi("This class should only be extended within google-cloud-java") protected BaseEmulatorHelper(String emulator, int port, String projectId)
-
-
Method Details
-
getEmulatorRunners
Returns the emulator runners supported by this emulator. Runners are evaluated in order, the first available runner is selected and executed -
getLogger
Returns a logger. -
startProcess
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, 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
Returns the project ID associated with the local emulator. -
getOptions
Returns service options to access the local emulator. -
start
Starts the local emulator.- Throws:
IOExceptionInterruptedException
-
stop
public abstract void stop(org.threeten.bp.Duration timeout) throws IOException, InterruptedException, TimeoutException Stops the local emulator. -
reset
Resets the internal state of the emulator.- Throws:
IOException
-
sendPostRequest
- Throws:
IOException
-
findAvailablePort
protected static int findAvailablePort(int defaultPort) -
isWindows
protected static boolean isWindows()
-