Skip to content

Commit 1f8a5c0

Browse files
files renamed and other edits
1 parent fbc2677 commit 1f8a5c0

2 files changed

Lines changed: 40 additions & 35 deletions

File tree

google-cloud-examples/src/main/java/com/google/cloud/examples/bigtable/TableAdmin.java renamed to google-cloud-examples/src/main/java/com/google/cloud/examples/bigtable/TableAdminExample.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@
3535
* <p>This example demonstrates the usage of BigtableTableAdminClient to create, configure and
3636
* delete a Cloud Bigtable table.
3737
*
38-
* <pre>
39-
* creates table
40-
* lists all tables
41-
* gets table metadata
42-
* creates DurationRule
43-
* creates VersionRule
44-
* creates UnionRule
45-
* creates IntersectionRule
46-
* creates nested rule
47-
* lists column families
48-
* modifies column family rule
49-
* prints modified column family
50-
* deletes column family
51-
* deletes table
52-
* </pre>
38+
* <ul>
39+
* <li>creates table
40+
* <li>lists all tables
41+
* <li>gets table metadata
42+
* <li>creates DurationRule
43+
* <li>creates VersionRule
44+
* <li>creates UnionRule
45+
* <li>creates IntersectionRule
46+
* <li>creates nested rule
47+
* <li>lists column families
48+
* <li>modifies column family rule
49+
* <li>prints modified column family
50+
* <li>deletes column family
51+
* <li>deletes table
52+
* </ul>
5353
*/
54-
public class TableAdmin {
54+
public class TableAdminExample {
5555

5656
private static final String COLUMN_FAMILY_1 = "cf1";
5757
private static final String COLUMN_FAMILY_2 = "cf2";
@@ -70,18 +70,19 @@ public static void main(String[] args) throws IOException {
7070
String projectId = args[0];
7171
String instanceId = args[1];
7272

73-
TableAdmin tableAdmin = new TableAdmin(projectId, instanceId, "test-table");
73+
TableAdminExample tableAdmin = new TableAdminExample(projectId, instanceId, "test-table");
7474
tableAdmin.run();
7575
}
7676

77-
public TableAdmin(String projectId, String instanceId, String tableId) throws IOException {
77+
public TableAdminExample(String projectId, String instanceId, String tableId) throws IOException {
7878
this.tableId = tableId;
7979

8080
// [START connecting_to_bigtable]
8181
// Creates the settings to configure a bigtable table admin client.
8282
BigtableTableAdminSettings adminSettings =
8383
BigtableTableAdminSettings.newBuilder()
84-
.setInstanceName(com.google.bigtable.admin.v2.InstanceName.of(projectId, instanceId))
84+
.setProjectId(projectId)
85+
.setInstanceId(instanceId)
8586
.build();
8687

8788
// Creates a bigtable table admin client.
@@ -358,7 +359,6 @@ public void deleteTable() {
358359
try {
359360
adminClient.deleteTable(tableId);
360361
System.out.printf("Table: %s deleted successfully%n", tableId);
361-
362362
} catch (NotFoundException e) {
363363
System.err.println("Failed to delete a non-existent table: " + e.getMessage());
364364
}
@@ -367,7 +367,7 @@ public void deleteTable() {
367367

368368
private static void printColumnFamily(ColumnFamily columnFamily) {
369369
System.out.printf(
370-
"Column family: %s%nMetadata: %s%n",
370+
"Column family: %s%nGC Rule: %s%n",
371371
columnFamily.getId(), columnFamily.getGCRule().toString());
372372
}
373373
}

google-cloud-examples/src/test/java/com/google/cloud/examples/bigtable/ITTableAdmin.java renamed to google-cloud-examples/src/test/java/com/google/cloud/examples/bigtable/ITTableAdminExample.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.google.cloud.examples.bigtable;
1717

18+
import static org.junit.Assert.assertFalse;
1819
import static org.junit.Assert.assertTrue;
1920

2021
import com.google.bigtable.admin.v2.InstanceName;
@@ -36,15 +37,16 @@
3637
import org.junit.BeforeClass;
3738
import org.junit.Test;
3839

39-
/** Integration tests for {@link TableAdmin} */
40-
public class ITTableAdmin {
40+
/** Integration tests for {@link TableAdminExample} */
41+
public class ITTableAdminExample {
4142

4243
private static final String INSTANCE_PROPERTY_NAME = "bigtable.instance";
4344
private static final String TABLE_PREFIX = "table";
44-
private static String tableId;
4545
private static BigtableTableAdminClient adminClient;
46-
private static InstanceName instanceName;
47-
private TableAdmin tableAdmin;
46+
private static String instanceName;
47+
private static String projectName;
48+
private String tableId;
49+
private TableAdminExample tableAdmin;
4850

4951
@BeforeClass
5052
public static void beforeClass() throws IOException {
@@ -53,9 +55,13 @@ public static void beforeClass() throws IOException {
5355
adminClient = null;
5456
return;
5557
}
56-
instanceName = InstanceName.parse(targetInstance);
58+
instanceName = InstanceName.parse(targetInstance).getInstance();
59+
projectName = InstanceName.parse(targetInstance).getProject();
5760
BigtableTableAdminSettings adminSettings =
58-
BigtableTableAdminSettings.newBuilder().setInstanceName(instanceName).build();
61+
BigtableTableAdminSettings.newBuilder()
62+
.setInstanceId(instanceName)
63+
.setProjectId(projectName)
64+
.build();
5965
adminClient = BigtableTableAdminClient.create(adminSettings);
6066
}
6167

@@ -72,7 +78,7 @@ public void setup() throws IOException {
7278
INSTANCE_PROPERTY_NAME + " property is not set, skipping integration tests.");
7379
}
7480
tableId = generateTableId();
75-
tableAdmin = new TableAdmin(instanceName.getProject(), instanceName.getInstance(), tableId);
81+
tableAdmin = new TableAdminExample(projectName, instanceName, tableId);
7682
adminClient.createTable(CreateTableRequest.of(tableId).addFamily("cf"));
7783
}
7884

@@ -86,15 +92,14 @@ public void after() {
8692
@Test
8793
public void testCreateAndDeleteTable() throws IOException {
8894
// Creates a table.
89-
String fakeTable = generateTableId();
90-
TableAdmin testTableAdmin =
91-
new TableAdmin(instanceName.getProject(), instanceName.getInstance(), fakeTable);
95+
String testTable = generateTableId();
96+
TableAdminExample testTableAdmin = new TableAdminExample(projectName, instanceName, testTable);
9297
testTableAdmin.createTable();
93-
assertTrue(adminClient.exists(fakeTable));
98+
assertTrue(adminClient.exists(testTable));
9499

95100
// Deletes a table.
96101
testTableAdmin.deleteTable();
97-
assertTrue(!adminClient.exists(fakeTable));
102+
assertFalse(adminClient.exists(testTable));
98103
}
99104

100105
@Test
@@ -178,7 +183,7 @@ public void testRunDoesNotFail() {
178183

179184
// TODO: add test for tableAdmin.listAllTables()
180185
// TODO: add test for tableAdmin.getTableMeta()
181-
// TODO: add test for tableAdmin.listColumnFamilies
186+
// TODO: add test for tableAdmin.listColumnFamilies()
182187

183188
private boolean ruleCheck(Object condition) {
184189
boolean found = false;

0 commit comments

Comments
 (0)