|
24 | 24 | import com.google.api.gax.rpc.NotFoundException;
|
25 | 25 | import com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient;
|
26 | 26 | import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient;
|
| 27 | +import com.google.cloud.bigtable.admin.v2.models.CreateInstanceRequest; |
27 | 28 | import com.google.cloud.bigtable.admin.v2.models.CreateMaterializedViewRequest;
|
28 | 29 | import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest;
|
| 30 | +import com.google.cloud.bigtable.admin.v2.models.Instance; |
29 | 31 | import com.google.cloud.bigtable.admin.v2.models.MaterializedView;
|
| 32 | +import com.google.cloud.bigtable.admin.v2.models.StorageType; |
30 | 33 | import com.google.cloud.bigtable.admin.v2.models.Table;
|
31 | 34 | import com.google.cloud.bigtable.admin.v2.models.UpdateMaterializedViewRequest;
|
32 | 35 | import com.google.cloud.bigtable.test_helpers.env.EmulatorEnv;
|
33 | 36 | import com.google.cloud.bigtable.test_helpers.env.PrefixGenerator;
|
34 | 37 | import com.google.cloud.bigtable.test_helpers.env.TestEnvRule;
|
35 | 38 | import io.grpc.StatusRuntimeException;
|
| 39 | +import java.io.IOException; |
36 | 40 | import java.util.List;
|
37 | 41 | import java.util.logging.Logger;
|
| 42 | +import org.junit.AfterClass; |
38 | 43 | import org.junit.Before;
|
39 | 44 | import org.junit.BeforeClass;
|
40 | 45 | import org.junit.ClassRule;
|
41 |
| -import org.junit.Ignore; |
42 | 46 | import org.junit.Rule;
|
43 | 47 | import org.junit.Test;
|
44 | 48 | import org.junit.runner.RunWith;
|
45 | 49 | import org.junit.runners.JUnit4;
|
46 | 50 |
|
47 | 51 | @RunWith(JUnit4.class)
|
48 |
| -@Ignore("Not fully working yet in production") |
49 | 52 | public class BigtableMaterializedViewIT {
|
50 | 53 | @ClassRule public static final TestEnvRule testEnvRule = new TestEnvRule();
|
51 | 54 | @Rule public final PrefixGenerator prefixGenerator = new PrefixGenerator();
|
52 | 55 | private static final Logger LOGGER = Logger.getLogger(BigtableMaterializedViewIT.class.getName());
|
53 | 56 | private static final int[] BACKOFF_DURATION = {2, 4, 8, 16, 32, 64, 128, 256, 512, 1024};
|
54 | 57 |
|
55 | 58 | private static BigtableInstanceAdminClient client;
|
| 59 | + private static BigtableTableAdminClient tableAdminClient; |
56 | 60 | private static Table testTable;
|
57 |
| - |
58 |
| - private String instanceId = testEnvRule.env().getInstanceId(); |
| 61 | + private static String instanceId = ""; |
59 | 62 |
|
60 | 63 | // TODO: Update this test once emulator supports InstanceAdmin operation
|
61 | 64 | // https://github.com/googleapis/google-cloud-go/issues/1069
|
62 | 65 | @BeforeClass
|
63 |
| - public static void validatePlatform() { |
| 66 | + public static void validatePlatform() throws IOException { |
64 | 67 | assume()
|
65 | 68 | .withMessage("BigtableInstanceAdminClient doesn't support on Emulator")
|
66 | 69 | .that(testEnvRule.env())
|
67 | 70 | .isNotInstanceOf(EmulatorEnv.class);
|
| 71 | + |
| 72 | + createInstance(); |
| 73 | + } |
| 74 | + |
| 75 | + public static void createInstance() throws IOException { |
| 76 | + client = testEnvRule.env().getInstanceAdminClient(); |
| 77 | + |
| 78 | + Instance instance = |
| 79 | + client.createInstance( |
| 80 | + CreateInstanceRequest.of(new PrefixGenerator().newPrefix()) |
| 81 | + .addCluster("my-cluster", "us-east1-c", 3, StorageType.SSD)); |
| 82 | + instanceId = instance.getId(); |
| 83 | + tableAdminClient = |
| 84 | + BigtableTableAdminClient.create(testEnvRule.env().getProjectId(), instanceId); |
| 85 | + } |
| 86 | + |
| 87 | + @AfterClass |
| 88 | + public static void deleteInstance() { |
| 89 | + if (!instanceId.isEmpty()) { |
| 90 | + client.deleteInstance(instanceId); |
| 91 | + } |
68 | 92 | }
|
69 | 93 |
|
70 | 94 | @Before
|
71 | 95 | public void setUp() throws InterruptedException {
|
72 |
| - client = testEnvRule.env().getInstanceAdminClient(); |
73 |
| - testTable = createTestTable(testEnvRule.env().getTableAdminClient()); |
| 96 | + testTable = createTestTable(tableAdminClient); |
74 | 97 | }
|
75 | 98 |
|
76 | 99 | @Test
|
|
0 commit comments