use of com.google.bigtable.admin.v2.TableName in project java-bigtable by googleapis.
the class BigtableTableAdminClientTests method testAwaitReplication.
@Test
public void testAwaitReplication() {
// Setup
Mockito.when(mockStub.awaitReplicationCallable()).thenReturn(mockAwaitReplicationCallable);
TableName expectedRequest = TableName.parse(TABLE_NAME);
final AtomicBoolean wasCalled = new AtomicBoolean(false);
Mockito.when(mockAwaitReplicationCallable.futureCall(expectedRequest)).thenAnswer((Answer<ApiFuture<Void>>) invocationOnMock -> {
wasCalled.set(true);
return ApiFutures.immediateFuture(null);
});
// Execute
adminClient.awaitReplication(TABLE_ID);
// Verify
assertThat(wasCalled.get()).isTrue();
}
use of com.google.bigtable.admin.v2.TableName in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method snapshotTableTest.
@Test
public void snapshotTableTest() throws Exception {
Snapshot expectedResponse = Snapshot.newBuilder().setName(SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]").toString()).setSourceTable(Table.newBuilder().build()).setDataSizeBytes(-2110122398).setCreateTime(Timestamp.newBuilder().build()).setDeleteTime(Timestamp.newBuilder().build()).setDescription("description-1724546052").build();
Operation resultOperation = Operation.newBuilder().setName("snapshotTableTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
mockBigtableTableAdmin.addResponse(resultOperation);
TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
ClusterName cluster = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]");
String snapshotId = "snapshotId-1113817601";
String description = "description-1724546052";
Snapshot actualResponse = client.snapshotTableAsync(name, cluster, snapshotId, description).get();
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
SnapshotTableRequest actualRequest = ((SnapshotTableRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertEquals(cluster.toString(), actualRequest.getCluster());
Assert.assertEquals(snapshotId, actualRequest.getSnapshotId());
Assert.assertEquals(description, actualRequest.getDescription());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.bigtable.admin.v2.TableName in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method modifyColumnFamiliesExceptionTest.
@Test
public void modifyColumnFamiliesExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.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.
}
}
use of com.google.bigtable.admin.v2.TableName in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method checkConsistencyTest.
@Test
public void checkConsistencyTest() throws Exception {
CheckConsistencyResponse expectedResponse = CheckConsistencyResponse.newBuilder().setConsistent(true).build();
mockBigtableTableAdmin.addResponse(expectedResponse);
TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
String consistencyToken = "consistencyToken-1985152319";
CheckConsistencyResponse actualResponse = client.checkConsistency(name, consistencyToken);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
CheckConsistencyRequest actualRequest = ((CheckConsistencyRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertEquals(consistencyToken, actualRequest.getConsistencyToken());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.bigtable.admin.v2.TableName in project java-bigtable by googleapis.
the class TableTest method testFromProto.
@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().setName(testName.toString()).setGranularity(TimestampGranularity.MILLIS).putClusterStates("cluster1", com.google.bigtable.admin.v2.Table.ClusterState.newBuilder().setReplicationState(com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState.READY).build()).putClusterStates("cluster2", com.google.bigtable.admin.v2.Table.ClusterState.newBuilder().setReplicationState(com.google.bigtable.admin.v2.Table.ClusterState.ReplicationState.INITIALIZING).build()).putColumnFamilies("cf1", ColumnFamily.newBuilder().build()).putColumnFamilies("cf2", ColumnFamily.newBuilder().setGcRule(GcRule.newBuilder().setMaxNumVersions(1)).build()).putColumnFamilies("cf3", ColumnFamily.newBuilder().setGcRule(GcRule.newBuilder().setMaxAge(com.google.protobuf.Duration.newBuilder().setSeconds(1).setNanos(99))).build()).build();
Table result = Table.fromProto(proto);
assertThat(result.getInstanceId()).isEqualTo("my-instance");
assertThat(result.getId()).isEqualTo("my-table");
assertThat(result.getReplicationStatesByClusterId()).containsExactly("cluster1", Table.ReplicationState.READY, "cluster2", Table.ReplicationState.INITIALIZING);
assertThat(result.getColumnFamilies()).hasSize(3);
for (Entry<String, ColumnFamily> entry : proto.getColumnFamiliesMap().entrySet()) {
assertThat(result.getColumnFamilies()).contains(com.google.cloud.bigtable.admin.v2.models.ColumnFamily.fromProto(entry.getKey(), entry.getValue()));
}
}
Aggregations