From c5c881bb956860a393c2a7f34d0d790a23d270af Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Thu, 1 Oct 2020 14:33:24 -0400 Subject: [PATCH] fix(test): Clean up tests (#439) * fix(test): Clean up tests * Add missing RunWith annotations * unnecessary downcasts * Make emulator path overridable * add missing annotation * lint --- .../google/cloud/bigtable/emulator/v2/Emulator.java | 4 +++- .../admin/v2/BigtableInstanceAdminSettingsTest.java | 3 +++ .../admin/v2/BigtableTableAdminClientTest.java | 8 ++++++-- .../admin/v2/BigtableTableAdminSettingsTest.java | 3 +++ .../cloud/bigtable/admin/v2/it/BigtableBackupIT.java | 3 +++ .../admin/v2/it/BigtableInstanceAdminClientIT.java | 3 +++ .../admin/v2/it/BigtableTableAdminClientIT.java | 3 +++ .../data/v2/models/ReadModifyWriteRowTest.java | 3 +++ .../data/v2/stub/EnhancedBigtableStubTest.java | 6 +++--- .../cloud/bigtable/test_helpers/env/EmulatorEnv.java | 11 ++++++++++- 10 files changed, 40 insertions(+), 7 deletions(-) diff --git a/google-cloud-bigtable-emulator/src/main/java/com/google/cloud/bigtable/emulator/v2/Emulator.java b/google-cloud-bigtable-emulator/src/main/java/com/google/cloud/bigtable/emulator/v2/Emulator.java index 9c2fa49b38..8e8cd5ad0d 100644 --- a/google-cloud-bigtable-emulator/src/main/java/com/google/cloud/bigtable/emulator/v2/Emulator.java +++ b/google-cloud-bigtable-emulator/src/main/java/com/google/cloud/bigtable/emulator/v2/Emulator.java @@ -42,7 +42,6 @@ */ @BetaApi("Surface for Bigtable emulator is not yet stable") public class Emulator { - private static final Logger LOGGER = Logger.getLogger(Emulator.class.getName()); private final Path executable; @@ -54,6 +53,9 @@ public class Emulator { private ManagedChannel dataChannel; private ManagedChannel adminChannel; + public static Emulator createFromPath(Path path) { + return new Emulator(path); + } /** * Create a new instance of emulator. The emulator will use the bundled binaries in this jar. * Please note that the emulator is created in a stopped state, please use {@link #start()} after diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminSettingsTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminSettingsTest.java index 6fa6f3e4a7..c6ccf9557b 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminSettingsTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminSettingsTest.java @@ -21,8 +21,11 @@ import com.google.api.gax.rpc.StatusCode.Code; import java.io.IOException; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.mockito.Mockito; +@RunWith(JUnit4.class) public class BigtableInstanceAdminSettingsTest { @Test public void testProjectName() throws Exception { diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java index 2cda42b3ea..c265514325 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java @@ -71,18 +71,22 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.mockito.stubbing.Answer; import org.threeten.bp.Instant; -@RunWith(MockitoJUnitRunner.class) +@RunWith(JUnit4.class) public class BigtableTableAdminClientTest { + @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); private static final String PROJECT_ID = "my-project"; private static final String INSTANCE_ID = "my-instance"; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminSettingsTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminSettingsTest.java index 3a16dd236d..77ce733ce0 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminSettingsTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminSettingsTest.java @@ -21,8 +21,11 @@ import com.google.api.gax.rpc.StatusCode.Code; import java.io.IOException; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.mockito.Mockito; +@RunWith(JUnit4.class) public class BigtableTableAdminSettingsTest { @Test diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java index 1e1bc84648..4d17bbf0e9 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableBackupIT.java @@ -47,9 +47,12 @@ import java.util.concurrent.TimeoutException; import java.util.logging.Logger; import org.junit.*; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.threeten.bp.Duration; import org.threeten.bp.Instant; +@RunWith(JUnit4.class) public class BigtableBackupIT { private static final Logger LOGGER = Logger.getLogger(BigtableBackupIT.class.getName()); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java index f31654334d..9b41444c7f 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableInstanceAdminClientIT.java @@ -40,8 +40,11 @@ import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.threeten.bp.Instant; +@RunWith(JUnit4.class) public class BigtableInstanceAdminClientIT { @ClassRule public static TestEnvRule testEnvRule = new TestEnvRule(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java index 333fa875ce..2dc64b6407 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableTableAdminClientIT.java @@ -46,8 +46,11 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.threeten.bp.Duration; +@RunWith(JUnit4.class) public class BigtableTableAdminClientIT { @ClassRule public static TestEnvRule testEnvRule = new TestEnvRule(); @Rule public final TestName testNameRule = new TestName(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadModifyWriteRowTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadModifyWriteRowTest.java index b9e6f9e7ba..b0a8be33c9 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadModifyWriteRowTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/models/ReadModifyWriteRowTest.java @@ -28,7 +28,10 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +@RunWith(JUnit4.class) public class ReadModifyWriteRowTest { private static final String PROJECT_ID = "fake-project"; private static final String INSTANCE_ID = "fake-instance"; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java index b823930fb6..6d0ba10bf6 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java @@ -138,11 +138,11 @@ public void testChannelPrimerConfigured() throws IOException { } private static class FakeDataService extends BigtableGrpc.BigtableImplBase { - final BlockingQueue requests = Queues.newLinkedBlockingDeque(); + final BlockingQueue requests = Queues.newLinkedBlockingDeque(); @SuppressWarnings("unchecked") - T popLastRequest() throws InterruptedException { - return (T) requests.poll(1, TimeUnit.SECONDS); + ReadRowsRequest popLastRequest() throws InterruptedException { + return requests.poll(1, TimeUnit.SECONDS); } @Override diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/EmulatorEnv.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/EmulatorEnv.java index f3e97584e3..d1740fbfcd 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/EmulatorEnv.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/test_helpers/env/EmulatorEnv.java @@ -22,8 +22,12 @@ import com.google.cloud.bigtable.data.v2.BigtableDataClient; import com.google.cloud.bigtable.data.v2.BigtableDataSettings; import com.google.cloud.bigtable.emulator.v2.Emulator; +import com.google.common.base.Strings; +import java.nio.file.Paths; public class EmulatorEnv extends AbstractTestEnv { + private static final String EMULATOR_OVERRIDE_PROPERTY_NAME = "bigtable.emulator-path"; + private static final String PROJECT_ID = "fake-project"; private static final String INSTANCE_ID = "fake-instance"; private static final String TABLE_ID = "default-table"; @@ -42,7 +46,12 @@ private EmulatorEnv() {} @Override void start() throws Exception { - emulator = Emulator.createBundled(); + String overridePath = System.getProperty(EMULATOR_OVERRIDE_PROPERTY_NAME); + if (!Strings.isNullOrEmpty(overridePath)) { + emulator = Emulator.createFromPath(Paths.get(overridePath)); + } else { + emulator = Emulator.createBundled(); + } emulator.start(); dataSettings =