From 0e8ae3aceabaa403789f5f1d67e4ac1fc826532e Mon Sep 17 00:00:00 2001 From: cloud-java-bot Date: Mon, 4 Nov 2024 22:32:45 +0000 Subject: [PATCH] chore: generate libraries at Mon Nov 4 22:30:01 UTC 2024 --- .../BigtableUnaryOperationCallableTest.java | 248 +++++++++--------- 1 file changed, 125 insertions(+), 123 deletions(-) diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableUnaryOperationCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableUnaryOperationCallableTest.java index b4def0085..d509fc1c5 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableUnaryOperationCallableTest.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/BigtableUnaryOperationCallableTest.java @@ -1,5 +1,9 @@ package com.google.cloud.bigtable.data.v2.stub; +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + import com.google.api.core.ApiFuture; import com.google.api.gax.grpc.GrpcCallContext; import com.google.api.gax.rpc.InternalException; @@ -10,6 +14,8 @@ import com.google.cloud.bigtable.gaxx.testing.MockStreamingApi.MockServerStreamingCall; import com.google.cloud.bigtable.gaxx.testing.MockStreamingApi.MockServerStreamingCallable; import com.google.common.collect.ImmutableList; +import java.util.concurrent.ExecutionException; +import java.util.logging.Logger; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; @@ -22,128 +28,124 @@ import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; -import java.util.concurrent.ExecutionException; -import java.util.logging.Logger; - -import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; - @RunWith(JUnit4.class) public class BigtableUnaryOperationCallableTest { - @Rule - public final MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock - private ApiTracerFactory tracerFactory; - @Mock - private BigtableTracer tracer; - - @Before - public void setUp() throws Exception { - Mockito.when(tracerFactory.newTracer(Mockito.any(), Mockito.any(), Mockito.any())) - .thenReturn(tracer); - } - - @Test - public void testFutureResolve() throws Exception { - BigtableUnaryOperationCallable callable = new BigtableUnaryOperationCallable<>( - new FakeStreamingApi.ServerStreamingStashCallable<>(ImmutableList.of("value")), - GrpcCallContext.createDefault(), - tracerFactory, - SpanName.of("Fake", "method"), - false - ); - - ApiFuture f = callable.futureCall("fake"); - assertThat(f.get()).isEqualTo("value"); - } - - @Test - public void testMultipleResponses() throws Exception { - MockServerStreamingCallable inner = new MockServerStreamingCallable<>(); - - BigtableUnaryOperationCallable callable = new BigtableUnaryOperationCallable<>( - inner, - GrpcCallContext.createDefault(), - tracerFactory, - SpanName.of("Fake", "method"), - false - ); - callable.logger = Mockito.mock(Logger.class); - - ApiFuture f = callable.futureCall("fake"); - MockServerStreamingCall call = inner.popLastCall(); - call.getController().getObserver().onResponse("first"); - call.getController().getObserver().onResponse("second"); - - Throwable e = Assert.assertThrows(ExecutionException.class, f::get).getCause(); - assertThat(e).isInstanceOf(InternalException.class); - assertThat(e).hasMessageThat().contains("Received multiple responses for a Fake.method unary operation. Previous: first, New: second"); - - ArgumentCaptor msgCaptor = ArgumentCaptor.forClass(String.class); - verify(callable.logger).log(Mockito.any(), msgCaptor.capture()); - assertThat(msgCaptor.getValue()).isEqualTo("Received multiple responses for a Fake.method unary operation. Previous: first, New: second"); - - assertThat(call.getController().isCancelled()).isTrue(); - - } - - @Test - public void testCancel() { - MockServerStreamingCallable inner = new MockServerStreamingCallable<>(); - BigtableUnaryOperationCallable callable = new BigtableUnaryOperationCallable<>( - inner, - GrpcCallContext.createDefault(), - tracerFactory, - SpanName.of("Fake", "method"), - false - ); - ApiFuture f = callable.futureCall("req"); - f.cancel(true); - - MockServerStreamingCall call = inner.popLastCall(); - assertThat(call.getController().isCancelled()).isTrue(); - } - - @Test - public void testMissingResponse() { - MockServerStreamingCallable inner = new MockServerStreamingCallable<>(); - BigtableUnaryOperationCallable callable = new BigtableUnaryOperationCallable<>( - inner, - GrpcCallContext.createDefault(), - tracerFactory, - SpanName.of("Fake", "method"), - false - ); - ApiFuture f = callable.futureCall("req"); - MockServerStreamingCall call = inner.popLastCall(); - call.getController().getObserver().onComplete(); - - Throwable cause = Assert.assertThrows(ExecutionException.class, f::get).getCause(); - assertThat(cause).hasMessageThat().isEqualTo("Fake.method unary operation completed without a response message"); - } - - @Test - public void testTracing() throws Exception { - MockServerStreamingCallable inner = new MockServerStreamingCallable<>(); - BigtableUnaryOperationCallable callable = new BigtableUnaryOperationCallable<>( - inner, - GrpcCallContext.createDefault(), - tracerFactory, - SpanName.of("Fake", "method"), - false - ); - ApiFuture f = callable.futureCall("req"); - MockServerStreamingCall call = inner.popLastCall(); - call.getController().getObserver().onResponse("value"); - call.getController().getObserver().onComplete(); - - f.get(); - verify(tracer).responseReceived(); - verify(tracer).operationSucceeded(); - - // afterResponse is the responsibility of BigtableTracerStreamingCallable - verify(tracer, never()).afterResponse(Mockito.anyLong()); - } -} \ No newline at end of file + @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); + + @Mock private ApiTracerFactory tracerFactory; + @Mock private BigtableTracer tracer; + + @Before + public void setUp() throws Exception { + Mockito.when(tracerFactory.newTracer(Mockito.any(), Mockito.any(), Mockito.any())) + .thenReturn(tracer); + } + + @Test + public void testFutureResolve() throws Exception { + BigtableUnaryOperationCallable callable = + new BigtableUnaryOperationCallable<>( + new FakeStreamingApi.ServerStreamingStashCallable<>(ImmutableList.of("value")), + GrpcCallContext.createDefault(), + tracerFactory, + SpanName.of("Fake", "method"), + false); + + ApiFuture f = callable.futureCall("fake"); + assertThat(f.get()).isEqualTo("value"); + } + + @Test + public void testMultipleResponses() throws Exception { + MockServerStreamingCallable inner = new MockServerStreamingCallable<>(); + + BigtableUnaryOperationCallable callable = + new BigtableUnaryOperationCallable<>( + inner, + GrpcCallContext.createDefault(), + tracerFactory, + SpanName.of("Fake", "method"), + false); + callable.logger = Mockito.mock(Logger.class); + + ApiFuture f = callable.futureCall("fake"); + MockServerStreamingCall call = inner.popLastCall(); + call.getController().getObserver().onResponse("first"); + call.getController().getObserver().onResponse("second"); + + Throwable e = Assert.assertThrows(ExecutionException.class, f::get).getCause(); + assertThat(e).isInstanceOf(InternalException.class); + assertThat(e) + .hasMessageThat() + .contains( + "Received multiple responses for a Fake.method unary operation. Previous: first, New: second"); + + ArgumentCaptor msgCaptor = ArgumentCaptor.forClass(String.class); + verify(callable.logger).log(Mockito.any(), msgCaptor.capture()); + assertThat(msgCaptor.getValue()) + .isEqualTo( + "Received multiple responses for a Fake.method unary operation. Previous: first, New: second"); + + assertThat(call.getController().isCancelled()).isTrue(); + } + + @Test + public void testCancel() { + MockServerStreamingCallable inner = new MockServerStreamingCallable<>(); + BigtableUnaryOperationCallable callable = + new BigtableUnaryOperationCallable<>( + inner, + GrpcCallContext.createDefault(), + tracerFactory, + SpanName.of("Fake", "method"), + false); + ApiFuture f = callable.futureCall("req"); + f.cancel(true); + + MockServerStreamingCall call = inner.popLastCall(); + assertThat(call.getController().isCancelled()).isTrue(); + } + + @Test + public void testMissingResponse() { + MockServerStreamingCallable inner = new MockServerStreamingCallable<>(); + BigtableUnaryOperationCallable callable = + new BigtableUnaryOperationCallable<>( + inner, + GrpcCallContext.createDefault(), + tracerFactory, + SpanName.of("Fake", "method"), + false); + ApiFuture f = callable.futureCall("req"); + MockServerStreamingCall call = inner.popLastCall(); + call.getController().getObserver().onComplete(); + + Throwable cause = Assert.assertThrows(ExecutionException.class, f::get).getCause(); + assertThat(cause) + .hasMessageThat() + .isEqualTo("Fake.method unary operation completed without a response message"); + } + + @Test + public void testTracing() throws Exception { + MockServerStreamingCallable inner = new MockServerStreamingCallable<>(); + BigtableUnaryOperationCallable callable = + new BigtableUnaryOperationCallable<>( + inner, + GrpcCallContext.createDefault(), + tracerFactory, + SpanName.of("Fake", "method"), + false); + ApiFuture f = callable.futureCall("req"); + MockServerStreamingCall call = inner.popLastCall(); + call.getController().getObserver().onResponse("value"); + call.getController().getObserver().onComplete(); + + f.get(); + verify(tracer).responseReceived(); + verify(tracer).operationSucceeded(); + + // afterResponse is the responsibility of BigtableTracerStreamingCallable + verify(tracer, never()).afterResponse(Mockito.anyLong()); + } +}