Skip to content

Commit

Permalink
fix(test): Clean up tests (googleapis#439)
Browse files Browse the repository at this point in the history
* fix(test): Clean up tests

* Add missing RunWith annotations
* unnecessary downcasts
* Make emulator path overridable

* add missing annotation

* lint
  • Loading branch information
igorbernstein2 authored Oct 1, 2020
1 parent fb7bc5c commit c5c881b
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ public void testChannelPrimerConfigured() throws IOException {
}

private static class FakeDataService extends BigtableGrpc.BigtableImplBase {
final BlockingQueue<Object> requests = Queues.newLinkedBlockingDeque();
final BlockingQueue<ReadRowsRequest> requests = Queues.newLinkedBlockingDeque();

@SuppressWarnings("unchecked")
<T> T popLastRequest() throws InterruptedException {
return (T) requests.poll(1, TimeUnit.SECONDS);
ReadRowsRequest popLastRequest() throws InterruptedException {
return requests.poll(1, TimeUnit.SECONDS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 =
Expand Down

0 comments on commit c5c881b

Please sign in to comment.