public static TableName parse(String formattedString) { if (formattedString.isEmpty()) { return null; } Map<String, String> matchMap = PATH_TEMPLATE.validatedMatch( formattedString, "TableName.parse: formattedString not in valid format"); return of(matchMap.get("project"), matchMap.get("instance"), matchMap.get("table")); }
com.google.bigtable.admin.v2.TableName.of(projectId, instanceId, tableId); return stub.awaitReplicationCallable().futureCall(tableName);
/** * Blocks until replication has caught up to the point this method was called. This allows callers * to make sure that their mutations have been replicated across all of their clusters. * * <p>Sample code * * <pre>{@code * client.awaitReplication("my-table"); * }</pre> * * @throws com.google.api.gax.retrying.PollException when polling exceeds the total timeout */ @SuppressWarnings("WeakerAccess") public void awaitReplication(String tableId) { // TODO(igorbernstein2): remove usage of typesafe names com.google.bigtable.admin.v2.TableName tableName = com.google.bigtable.admin.v2.TableName.of(projectId, instanceId, tableId); ApiExceptions.callAndTranslateApiException( stub.awaitReplicationCallable().futureCall(tableName)); }
@Test @SuppressWarnings("all") public void modifyColumnFamiliesExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockBigtableTableAdmin.addException(exception); try { TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); List<ModifyColumnFamiliesRequest.Modification> modifications = new ArrayList<>(); client.modifyColumnFamilies(name, modifications); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Test @SuppressWarnings("all") public void getTableExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockBigtableTableAdmin.addException(exception); try { TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); client.getTable(name); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Test @SuppressWarnings("all") public void deleteTableExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockBigtableTableAdmin.addException(exception); try { TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); client.deleteTable(name); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Test @SuppressWarnings("all") public void generateConsistencyTokenExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockBigtableTableAdmin.addException(exception); try { TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); client.generateConsistencyToken(name); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Test @SuppressWarnings("all") public void checkConsistencyExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockBigtableTableAdmin.addException(exception); try { TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); String consistencyToken = "consistencyToken-1090516718"; client.checkConsistency(name, consistencyToken); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Test @SuppressWarnings("all") public void snapshotTableExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockBigtableTableAdmin.addException(exception); try { TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); ClusterName cluster = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]"); SnapshotName snapshotId = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); String description = "description-1724546052"; client.snapshotTableAsync(name, cluster, snapshotId, description).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } }
@Test @SuppressWarnings("all") public void getTableTest() { TableName name2 = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); Table expectedResponse = Table.newBuilder().setName(name2.toString()).build(); mockBigtableTableAdmin.addResponse(expectedResponse); TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); Table actualResponse = client.getTable(name); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockBigtableTableAdmin.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetTableRequest actualRequest = (GetTableRequest) actualRequests.get(0); Assert.assertEquals(name, TableName.parse(actualRequest.getName())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test @SuppressWarnings("all") public void modifyColumnFamiliesTest() { TableName name2 = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); Table expectedResponse = Table.newBuilder().setName(name2.toString()).build(); mockBigtableTableAdmin.addResponse(expectedResponse); TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); List<ModifyColumnFamiliesRequest.Modification> modifications = new ArrayList<>(); Table actualResponse = client.modifyColumnFamilies(name, modifications); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockBigtableTableAdmin.getRequests(); Assert.assertEquals(1, actualRequests.size()); ModifyColumnFamiliesRequest actualRequest = (ModifyColumnFamiliesRequest) actualRequests.get(0); Assert.assertEquals(name, TableName.parse(actualRequest.getName())); Assert.assertEquals(modifications, actualRequest.getModificationsList()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test @SuppressWarnings("all") public void deleteTableTest() { Empty expectedResponse = Empty.newBuilder().build(); mockBigtableTableAdmin.addResponse(expectedResponse); TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); client.deleteTable(name); List<GeneratedMessageV3> actualRequests = mockBigtableTableAdmin.getRequests(); Assert.assertEquals(1, actualRequests.size()); DeleteTableRequest actualRequest = (DeleteTableRequest) actualRequests.get(0); Assert.assertEquals(name, TableName.parse(actualRequest.getName())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test @SuppressWarnings("all") public void generateConsistencyTokenTest() { String consistencyToken = "consistencyToken-1090516718"; GenerateConsistencyTokenResponse expectedResponse = GenerateConsistencyTokenResponse.newBuilder().setConsistencyToken(consistencyToken).build(); mockBigtableTableAdmin.addResponse(expectedResponse); TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); GenerateConsistencyTokenResponse actualResponse = client.generateConsistencyToken(name); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockBigtableTableAdmin.getRequests(); Assert.assertEquals(1, actualRequests.size()); GenerateConsistencyTokenRequest actualRequest = (GenerateConsistencyTokenRequest) actualRequests.get(0); Assert.assertEquals(name, TableName.parse(actualRequest.getName())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test @SuppressWarnings("all") public void checkConsistencyTest() { boolean consistent = true; CheckConsistencyResponse expectedResponse = CheckConsistencyResponse.newBuilder().setConsistent(consistent).build(); mockBigtableTableAdmin.addResponse(expectedResponse); TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); String consistencyToken = "consistencyToken-1090516718"; CheckConsistencyResponse actualResponse = client.checkConsistency(name, consistencyToken); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockBigtableTableAdmin.getRequests(); Assert.assertEquals(1, actualRequests.size()); CheckConsistencyRequest actualRequest = (CheckConsistencyRequest) actualRequests.get(0); Assert.assertEquals(name, TableName.parse(actualRequest.getName())); Assert.assertEquals(consistencyToken, actualRequest.getConsistencyToken()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test @SuppressWarnings("all") public void createTableTest() { TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); Table expectedResponse = Table.newBuilder().setName(name.toString()).build(); mockBigtableTableAdmin.addResponse(expectedResponse); InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]"); String tableId = "tableId-895419604"; Table table = Table.newBuilder().build(); Table actualResponse = client.createTable(parent, tableId, table); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockBigtableTableAdmin.getRequests(); Assert.assertEquals(1, actualRequests.size()); CreateTableRequest actualRequest = (CreateTableRequest) actualRequests.get(0); Assert.assertEquals(parent, InstanceName.parse(actualRequest.getParent())); Assert.assertEquals(tableId, actualRequest.getTableId()); Assert.assertEquals(table, actualRequest.getTable()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test public void testFromProto() { TableName testName = TableName.of("my-project", "my-instance", "my-table"); com.google.bigtable.admin.v2.Table proto = com.google.bigtable.admin.v2.Table.newBuilder()
@Test @SuppressWarnings("all") public void createTableFromSnapshotTest() throws Exception { TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); Table expectedResponse = Table.newBuilder().setName(name.toString()).build(); Operation resultOperation =
mockBigtableTableAdmin.addResponse(resultOperation); TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); ClusterName cluster = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]"); SnapshotName snapshotId = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]");
public static TableName parse(String formattedString) { if (formattedString.isEmpty()) { return null; } Map<String, String> matchMap = PATH_TEMPLATE.validatedMatch( formattedString, "TableName.parse: formattedString not in valid format"); return of(matchMap.get("project"), matchMap.get("instance"), matchMap.get("table")); }
/** * Blocks until replication has caught up to the point this method was called. This allows callers * to make sure that their mutations have been replicated across all of their clusters. * * <p>Sample code * * <pre>{@code * client.awaitReplication("my-table"); * }</pre> * * @throws com.google.api.gax.retrying.PollException when polling exceeds the total timeout */ @SuppressWarnings("WeakerAccess") public void awaitReplication(String tableId) { // TODO(igorbernstein2): remove usage of typesafe names com.google.bigtable.admin.v2.TableName tableName = com.google.bigtable.admin.v2.TableName.of(projectId, instanceId, tableId); ApiExceptions.callAndTranslateApiException( stub.awaitReplicationCallable().futureCall(tableName)); }