|
20 | 20 | import static org.junit.Assert.assertFalse;
|
21 | 21 | import static org.junit.Assert.assertNotNull;
|
22 | 22 | import static org.junit.Assert.assertTrue;
|
23 |
| -import java.io.IOException; |
24 |
| -import java.util.List; |
25 |
| -import org.junit.AfterClass; |
26 |
| -import org.junit.BeforeClass; |
27 |
| -import org.junit.Test; |
28 |
| -import org.threeten.bp.Duration; |
29 | 23 | import com.google.bigtable.admin.v2.InstanceName;
|
30 | 24 | import com.google.bigtable.admin.v2.TableName;
|
31 | 25 | import com.google.cloud.bigtable.admin.v2.TableAdminClient;
|
|
39 | 33 | import com.google.cloud.bigtable.admin.v2.models.TableAdminResponses.ConsistencyToken;
|
40 | 34 | import com.google.cloud.bigtable.admin.v2.models.TableAdminResponses.Table;
|
41 | 35 | import com.google.protobuf.ByteString;
|
| 36 | +import java.io.IOException; |
| 37 | +import java.util.List; |
| 38 | +import org.junit.AfterClass; |
| 39 | +import org.junit.AssumptionViolatedException; |
| 40 | +import org.junit.Before; |
| 41 | +import org.junit.BeforeClass; |
| 42 | +import org.junit.Test; |
| 43 | +import org.threeten.bp.Duration; |
42 | 44 |
|
43 | 45 | public class TableAdminClientIT {
|
| 46 | + // TODO(igorbernstein2): remove these properties once admin is split from data client |
| 47 | + private static final String ENV_PROPERTY = "bigtable.env"; |
| 48 | + private static final String TABLE_PROPERTY_NAME = "bigtable.table"; |
| 49 | + |
44 | 50 | static TableAdminClient tableAdmin;
|
45 | 51 |
|
46 | 52 | @BeforeClass
|
47 | 53 | public static void createClient() throws IOException {
|
48 |
| - tableAdmin = TableAdminClient.create(InstanceName.of("sduskis-hello-shakespear", "beam-test")); |
| 54 | + if (!"prod".equals(System.getProperty(ENV_PROPERTY))) { |
| 55 | + tableAdmin = null; |
| 56 | + return; |
| 57 | + } |
| 58 | + |
| 59 | + TableName tableName = TableName.parse(System.getProperty(TABLE_PROPERTY_NAME)); |
| 60 | + InstanceName instanceName = InstanceName.of(tableName.getProject(), tableName.getInstance()); |
| 61 | + |
| 62 | + tableAdmin = TableAdminClient.create(instanceName); |
49 | 63 | }
|
50 | 64 |
|
51 | 65 | @AfterClass
|
52 |
| - public static void closeClient() throws Exception { |
53 |
| - tableAdmin.close(); |
| 66 | + public static void closeClient() { |
| 67 | + if (tableAdmin != null) { |
| 68 | + tableAdmin.close(); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + @Before |
| 73 | + public void setup() { |
| 74 | + // TODO(igorbernstein2): remove this check once admin is split |
| 75 | + if (tableAdmin == null) { |
| 76 | + throw new AssumptionViolatedException("Tests can only run against prod environment"); |
| 77 | + } |
54 | 78 | }
|
55 | 79 |
|
56 | 80 | @Test
|
57 |
| - public void createTable() throws Exception { |
| 81 | + public void createTable() { |
58 | 82 | String tableId = "adminCreateTest";
|
59 | 83 | CreateTable createTableReq =
|
60 | 84 | TableAdminRequests.createTable(tableId)
|
@@ -83,7 +107,7 @@ public void createTable() throws Exception {
|
83 | 107 | public void modifyFamilies() {
|
84 | 108 | String tableId = "adminModifyFamTest";
|
85 | 109 | ModifyFamilies modifyFamiliesReq = TableAdminRequests.modifyFamilies(tableId);
|
86 |
| - Duration.ofSeconds(1000); |
| 110 | + |
87 | 111 | modifyFamiliesReq
|
88 | 112 | .addFamily("mf1")
|
89 | 113 | .addFamily("mf2", GCRULES.maxAge(Duration.ofSeconds(1000, 20000)))
|
|
0 commit comments