Class BigtableEmulatorRule

java.lang.Object
org.junit.rules.ExternalResource
com.google.cloud.bigtable.emulator.v2.BigtableEmulatorRule
All Implemented Interfaces:
org.junit.rules.TestRule

@BetaApi("Surface for Bigtable emulator is not yet stable") public class BigtableEmulatorRule extends org.junit.rules.ExternalResource
The BigtableEmulatorRule manages the lifecycle of the Bigtable Emulator. Before the start of a test, the emulator will be started on a random port and will be shutdown after the test finishes.

Example usage: {@literal @RunWith(JUnit4.class)} public class MyTest { {@literal @Rule} public final BigtableEmulatorRule bigtableEmulator = BigtableEmulatorRule.create(); {@literal @Test} public void testUsingEmulator() { ManagedChannel adminChannel = bigtableEmulator.getAdminChannel(); // Do something with channel } }

  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Stops the Bigtable emulator after a test finishes.
    protected void
    Initializes the Bigtable emulator before a test runs.
     
    io.grpc.ManagedChannel
    Gets a ManagedChannel connected to the Emulator.
    io.grpc.ManagedChannel
    Gets a ManagedChannel connected to the Emulator.
    int
    Gets the port of the emulator, allowing the caller to create their own ManagedChannel.

    Methods inherited from class org.junit.rules.ExternalResource

    apply

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • create

      public static BigtableEmulatorRule create()
    • before

      protected void before() throws Throwable
      Initializes the Bigtable emulator before a test runs.
      Overrides:
      before in class org.junit.rules.ExternalResource
      Throws:
      Throwable
    • after

      protected void after()
      Stops the Bigtable emulator after a test finishes.
      Overrides:
      after in class org.junit.rules.ExternalResource
    • getDataChannel

      public io.grpc.ManagedChannel getDataChannel()
      Gets a ManagedChannel connected to the Emulator. The channel is configured for data operations.
    • getAdminChannel

      public io.grpc.ManagedChannel getAdminChannel()
      Gets a ManagedChannel connected to the Emulator. This channel should be used for admin operations.
    • getPort

      public int getPort()
      Gets the port of the emulator, allowing the caller to create their own ManagedChannel.