use of com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse in project java-bigtable by googleapis.
the class AwaitReplicationCallableTest method testGenerateFailure.
@Test
public void testGenerateFailure() throws Exception {
GenerateConsistencyTokenRequest expectedRequest = GenerateConsistencyTokenRequest.newBuilder().setName(TABLE_NAME.toString()).build();
FakeApiException fakeError = new FakeApiException("fake", null, Code.INTERNAL, false);
Mockito.when(mockGenerateConsistencyTokenCallable.futureCall(expectedRequest, CALL_CONTEXT)).thenReturn(ApiFutures.<GenerateConsistencyTokenResponse>immediateFailedFuture(fakeError));
ApiFuture<Void> future = callable.futureCall(TABLE_NAME, CALL_CONTEXT);
Throwable actualError = null;
try {
future.get();
} catch (ExecutionException e) {
actualError = e.getCause();
}
assertThat(actualError).isSameInstanceAs(fakeError);
}
use of com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse in project java-bigtable by googleapis.
the class AwaitReplicationCallableTest method testCheckFailure.
@Test
public void testCheckFailure() throws Exception {
GenerateConsistencyTokenRequest expectedRequest = GenerateConsistencyTokenRequest.newBuilder().setName(TABLE_NAME.toString()).build();
GenerateConsistencyTokenResponse expectedResponse = GenerateConsistencyTokenResponse.newBuilder().setConsistencyToken("fake-token").build();
Mockito.when(mockGenerateConsistencyTokenCallable.futureCall(expectedRequest, CALL_CONTEXT)).thenReturn(ApiFutures.immediateFuture(expectedResponse));
CheckConsistencyRequest expectedRequest2 = CheckConsistencyRequest.newBuilder().setName(TABLE_NAME.toString()).setConsistencyToken("fake-token").build();
FakeApiException expectedError = new FakeApiException("fake", null, Code.INTERNAL, false);
Mockito.when(mockCheckConsistencyCallable.futureCall(expectedRequest2, CALL_CONTEXT)).thenReturn(ApiFutures.<CheckConsistencyResponse>immediateFailedFuture(expectedError));
ApiFuture<Void> future = callable.futureCall(TABLE_NAME, CALL_CONTEXT);
Throwable actualError = null;
try {
future.get();
} catch (ExecutionException e) {
actualError = e.getCause();
}
assertThat(actualError).isSameInstanceAs(expectedError);
}
use of com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse in project java-bigtable by googleapis.
the class AwaitReplicationCallableTest method testPollingTimeout.
@Test
public void testPollingTimeout() throws Exception {
GenerateConsistencyTokenRequest expectedRequest = GenerateConsistencyTokenRequest.newBuilder().setName(TABLE_NAME.toString()).build();
GenerateConsistencyTokenResponse expectedResponse = GenerateConsistencyTokenResponse.newBuilder().setConsistencyToken("fake-token").build();
Mockito.when(mockGenerateConsistencyTokenCallable.futureCall(expectedRequest, CALL_CONTEXT)).thenReturn(ApiFutures.immediateFuture(expectedResponse));
CheckConsistencyRequest expectedRequest2 = CheckConsistencyRequest.newBuilder().setName(TABLE_NAME.toString()).setConsistencyToken("fake-token").build();
CheckConsistencyResponse expectedResponse2 = CheckConsistencyResponse.newBuilder().setConsistent(false).build();
Mockito.when(mockCheckConsistencyCallable.futureCall(expectedRequest2, CALL_CONTEXT)).thenReturn(ApiFutures.immediateFuture(expectedResponse2));
ApiFuture<Void> consistentFuture = callable.futureCall(TABLE_NAME, CALL_CONTEXT);
Throwable actualError = null;
try {
consistentFuture.get(1, TimeUnit.SECONDS);
} catch (ExecutionException e) {
actualError = e.getCause();
}
assertThat(actualError).isInstanceOf(PollException.class);
}
use of com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse in project java-bigtable by googleapis.
the class AwaitReplicationCallableTest method testPolling.
@Test
public void testPolling() throws Exception {
GenerateConsistencyTokenRequest expectedRequest = GenerateConsistencyTokenRequest.newBuilder().setName(TABLE_NAME.toString()).build();
GenerateConsistencyTokenResponse expectedResponse = GenerateConsistencyTokenResponse.newBuilder().setConsistencyToken("fake-token").build();
Mockito.when(mockGenerateConsistencyTokenCallable.futureCall(expectedRequest, CALL_CONTEXT)).thenReturn(ApiFutures.immediateFuture(expectedResponse));
CheckConsistencyRequest expectedRequest2 = CheckConsistencyRequest.newBuilder().setName(TABLE_NAME.toString()).setConsistencyToken("fake-token").build();
CheckConsistencyResponse expectedResponse2 = CheckConsistencyResponse.newBuilder().setConsistent(false).build();
CheckConsistencyResponse expectedResponse3 = CheckConsistencyResponse.newBuilder().setConsistent(true).build();
Mockito.when(mockCheckConsistencyCallable.futureCall(expectedRequest2, CALL_CONTEXT)).thenReturn(ApiFutures.immediateFuture(expectedResponse2)).thenReturn(ApiFutures.immediateFuture(expectedResponse3));
ApiFuture<Void> consistentFuture = callable.futureCall(TABLE_NAME, CALL_CONTEXT);
consistentFuture.get(1, TimeUnit.SECONDS);
}
use of com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method generateConsistencyTokenTest2.
@Test
public void generateConsistencyTokenTest2() throws Exception {
GenerateConsistencyTokenResponse expectedResponse = GenerateConsistencyTokenResponse.newBuilder().setConsistencyToken("consistencyToken-1985152319").build();
mockBigtableTableAdmin.addResponse(expectedResponse);
String name = "name3373707";
GenerateConsistencyTokenResponse actualResponse = client.generateConsistencyToken(name);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
GenerateConsistencyTokenRequest actualRequest = ((GenerateConsistencyTokenRequest) actualRequests.get(0));
Assert.assertEquals(name, actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations