Search in sources :

Example 1 with FakeApiException

use of com.google.api.gax.rpc.testing.FakeApiException 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);
}
Also used : GenerateConsistencyTokenRequest(com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest) ExecutionException(java.util.concurrent.ExecutionException) FakeApiException(com.google.api.gax.rpc.testing.FakeApiException) Test(org.junit.Test)

Example 2 with FakeApiException

use of com.google.api.gax.rpc.testing.FakeApiException 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);
}
Also used : GenerateConsistencyTokenRequest(com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest) GenerateConsistencyTokenResponse(com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse) ExecutionException(java.util.concurrent.ExecutionException) CheckConsistencyRequest(com.google.bigtable.admin.v2.CheckConsistencyRequest) FakeApiException(com.google.api.gax.rpc.testing.FakeApiException) Test(org.junit.Test)

Aggregations

FakeApiException (com.google.api.gax.rpc.testing.FakeApiException)2 GenerateConsistencyTokenRequest (com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest)2 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.Test)2 CheckConsistencyRequest (com.google.bigtable.admin.v2.CheckConsistencyRequest)1 GenerateConsistencyTokenResponse (com.google.bigtable.admin.v2.GenerateConsistencyTokenResponse)1