Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ public void testAwaitOptimizeRestoredTable() throws Exception {

// 4. Mock the Stub's behavior (resuming the Optimize Op)
OperationFuture<Empty, OptimizeRestoredTableMetadata> mockOptimizeOp =
Mockito.mock(OperationFuture.class);
Mockito.mock(OperationFuture.class, Mockito.withSettings().withoutAnnotations());
Mockito.when(mockOptimizeRestoredTableCallable.resumeFutureCall(optimizeToken))
.thenReturn(mockOptimizeOp);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public void testMissingInstanceName() {

@Test
public void testCredentials() throws IOException {
CredentialsProvider credentialsProvider = Mockito.mock(CredentialsProvider.class);
CredentialsProvider credentialsProvider =
Mockito.mock(CredentialsProvider.class, Mockito.withSettings().withoutAnnotations());

BigtableTableAdminSettings settings =
BigtableTableAdminSettings.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
Expand All @@ -63,11 +62,9 @@ public class AwaitConsistencyCallableTest {
private static final TableAdminRequestContext REQUEST_CONTEXT =
TableAdminRequestContext.create(PROJECT_ID, INSTANCE_ID);

@Mock
private UnaryCallable<GenerateConsistencyTokenRequest, GenerateConsistencyTokenResponse>
mockGenerateConsistencyTokenCallable;

@Mock
private UnaryCallable<CheckConsistencyRequest, CheckConsistencyResponse>
mockCheckConsistencyCallable;

Expand All @@ -77,6 +74,11 @@ public class AwaitConsistencyCallableTest {

@Before
public void setUp() {
mockGenerateConsistencyTokenCallable =
Mockito.mock(UnaryCallable.class, Mockito.withSettings().withoutAnnotations());
mockCheckConsistencyCallable =
Mockito.mock(UnaryCallable.class, Mockito.withSettings().withoutAnnotations());

ClientContext clientContext =
ClientContext.newBuilder().setDefaultCallContext(CALL_CONTEXT).build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
Expand All @@ -59,18 +58,21 @@ public class AwaitConsistencyCallableV2Test {
private static final TableName TABLE_NAME = TableName.of(PROJECT_ID, INSTANCE_ID, TABLE_ID);
private static final ApiCallContext CALL_CONTEXT = FakeCallContext.createDefault();

@Mock
private UnaryCallable<GenerateConsistencyTokenRequest, GenerateConsistencyTokenResponse>
mockGenerateConsistencyTokenCallable;

@Mock
private UnaryCallable<CheckConsistencyRequest, CheckConsistencyResponse>
mockCheckConsistencyCallable;

private AwaitConsistencyCallableV2 awaitConsistencyCallable;

@Before
public void setUp() {
mockGenerateConsistencyTokenCallable =
Mockito.mock(UnaryCallable.class, Mockito.withSettings().withoutAnnotations());
mockCheckConsistencyCallable =
Mockito.mock(UnaryCallable.class, Mockito.withSettings().withoutAnnotations());

RetrySettings retrySettings =
RetrySettings.newBuilder()
.setTotalTimeout(Duration.ofMillis(100))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,27 +134,42 @@ public void transportTerminated(Attributes transportAttrs) {
transportChannelProvider =
Mockito.mock(
TransportChannelProvider.class,
new BuilderAnswer<>(
TransportChannelProvider.class,
builder.stubSettings().getTransportChannelProvider()));
Mockito.withSettings()
.withoutAnnotations()
.defaultAnswer(
new BuilderAnswer<>(
TransportChannelProvider.class,
builder.stubSettings().getTransportChannelProvider())));

credentialsProvider =
Mockito.mock(
CredentialsProvider.class,
new BuilderAnswer<>(
CredentialsProvider.class, builder.stubSettings().getCredentialsProvider()));
Mockito.withSettings()
.withoutAnnotations()
.defaultAnswer(
new BuilderAnswer<>(
CredentialsProvider.class,
builder.stubSettings().getCredentialsProvider())));

executorProvider =
Mockito.mock(
ExecutorProvider.class,
new BuilderAnswer<>(
ExecutorProvider.class, builder.stubSettings().getBackgroundExecutorProvider()));
Mockito.withSettings()
.withoutAnnotations()
.defaultAnswer(
new BuilderAnswer<>(
ExecutorProvider.class,
builder.stubSettings().getBackgroundExecutorProvider())));

watchdogProvider =
Mockito.mock(
WatchdogProvider.class,
new BuilderAnswer<>(
WatchdogProvider.class, builder.stubSettings().getStreamWatchdogProvider()));
Mockito.withSettings()
.withoutAnnotations()
.defaultAnswer(
new BuilderAnswer<>(
WatchdogProvider.class,
builder.stubSettings().getStreamWatchdogProvider())));

ApiClock apiClock = builder.stubSettings().getClock();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
Expand All @@ -76,36 +75,62 @@ public class BigtableDataClientTests {

@Rule public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.WARN);

@Mock private EnhancedBigtableStub mockStub;
private EnhancedBigtableStub mockStub;

@Mock private ServerStreamingCallable<Query, Row> mockReadRowsCallable;
private ServerStreamingCallable<Query, Row> mockReadRowsCallable;

@Mock private UnaryCallable<Query, Row> mockReadRowCallable;
@Mock private UnaryCallable<String, List<KeyOffset>> mockSampleRowKeysCallable;
private UnaryCallable<Query, Row> mockReadRowCallable;
private UnaryCallable<String, List<KeyOffset>> mockSampleRowKeysCallable;

@Mock
private UnaryCallable<SampleRowKeysRequest, List<KeyOffset>> mockSampleRowKeysCallableWithRequest;

@Mock private UnaryCallable<RowMutation, Void> mockMutateRowCallable;
@Mock private UnaryCallable<ConditionalRowMutation, Boolean> mockCheckAndMutateRowCallable;
@Mock private UnaryCallable<ReadModifyWriteRow, Row> mockReadModifyWriteRowCallable;
@Mock private UnaryCallable<BulkMutation, Void> mockBulkMutateRowsCallable;
@Mock private Batcher<RowMutationEntry, Void> mockBulkMutationBatcher;
@Mock private Batcher<ByteString, Row> mockBulkReadRowsBatcher;
@Mock private UnaryCallable<PrepareQueryRequest, PrepareResponse> mockPrepareQueryCallable;
private UnaryCallable<RowMutation, Void> mockMutateRowCallable;
private UnaryCallable<ConditionalRowMutation, Boolean> mockCheckAndMutateRowCallable;
private UnaryCallable<ReadModifyWriteRow, Row> mockReadModifyWriteRowCallable;
private UnaryCallable<BulkMutation, Void> mockBulkMutateRowsCallable;
private Batcher<RowMutationEntry, Void> mockBulkMutationBatcher;
private Batcher<ByteString, Row> mockBulkReadRowsBatcher;
private UnaryCallable<PrepareQueryRequest, PrepareResponse> mockPrepareQueryCallable;

@Mock
private ServerStreamingCallable<String, ByteStringRange>
mockGenerateInitialChangeStreamPartitionsCallable;

@Mock
private ServerStreamingCallable<ReadChangeStreamQuery, ChangeStreamRecord>
mockReadChangeStreamCallable;

private BigtableDataClient bigtableDataClient;

@Before
@SuppressWarnings("unchecked")
public void setUp() {
mockStub =
Mockito.mock(EnhancedBigtableStub.class, Mockito.withSettings().withoutAnnotations());
mockReadRowsCallable =
Mockito.mock(ServerStreamingCallable.class, Mockito.withSettings().withoutAnnotations());
mockReadRowCallable =
Mockito.mock(UnaryCallable.class, Mockito.withSettings().withoutAnnotations());
mockSampleRowKeysCallable =
Mockito.mock(UnaryCallable.class, Mockito.withSettings().withoutAnnotations());
mockSampleRowKeysCallableWithRequest =
Mockito.mock(UnaryCallable.class, Mockito.withSettings().withoutAnnotations());
mockMutateRowCallable =
Mockito.mock(UnaryCallable.class, Mockito.withSettings().withoutAnnotations());
mockCheckAndMutateRowCallable =
Mockito.mock(UnaryCallable.class, Mockito.withSettings().withoutAnnotations());
mockReadModifyWriteRowCallable =
Mockito.mock(UnaryCallable.class, Mockito.withSettings().withoutAnnotations());
mockBulkMutateRowsCallable =
Mockito.mock(UnaryCallable.class, Mockito.withSettings().withoutAnnotations());
mockBulkMutationBatcher =
Mockito.mock(Batcher.class, Mockito.withSettings().withoutAnnotations());
mockBulkReadRowsBatcher =
Mockito.mock(Batcher.class, Mockito.withSettings().withoutAnnotations());
mockPrepareQueryCallable =
Mockito.mock(UnaryCallable.class, Mockito.withSettings().withoutAnnotations());
mockGenerateInitialChangeStreamPartitionsCallable =
Mockito.mock(ServerStreamingCallable.class, Mockito.withSettings().withoutAnnotations());
mockReadChangeStreamCallable =
Mockito.mock(ServerStreamingCallable.class, Mockito.withSettings().withoutAnnotations());

bigtableDataClient = new BigtableDataClient(mockStub);
}

Expand Down Expand Up @@ -597,7 +622,8 @@ public void proxyReadRowsAsyncTest() {

Query query = Query.create(TableId.of("fake-table"));
@SuppressWarnings("unchecked")
ResponseObserver<Row> mockObserver = Mockito.mock(ResponseObserver.class);
ResponseObserver<Row> mockObserver =
Mockito.mock(ResponseObserver.class, Mockito.withSettings().withoutAnnotations());
bigtableDataClient.readRowsAsync(query, mockObserver);

Mockito.verify(mockReadRowsCallable).call(query, mockObserver);
Expand All @@ -609,7 +635,8 @@ public void proxyReadRowsOnAuthorizedViewAsyncTest() {

Query query = Query.create(AuthorizedViewId.of("fake-table", "fake-authorized-view"));
@SuppressWarnings("unchecked")
ResponseObserver<Row> mockObserver = Mockito.mock(ResponseObserver.class);
ResponseObserver<Row> mockObserver =
Mockito.mock(ResponseObserver.class, Mockito.withSettings().withoutAnnotations());
bigtableDataClient.readRowsAsync(query, mockObserver);

Mockito.verify(mockReadRowsCallable).call(query, mockObserver);
Expand All @@ -631,7 +658,8 @@ public void proxyGenerateInitialChangeStreamPartitionsAsyncTest() {
.thenReturn(mockGenerateInitialChangeStreamPartitionsCallable);

@SuppressWarnings("unchecked")
ResponseObserver<ByteStringRange> mockObserver = Mockito.mock(ResponseObserver.class);
ResponseObserver<ByteStringRange> mockObserver =
Mockito.mock(ResponseObserver.class, Mockito.withSettings().withoutAnnotations());
bigtableDataClient.generateInitialChangeStreamPartitionsAsync("fake-table", mockObserver);

Mockito.verify(mockGenerateInitialChangeStreamPartitionsCallable)
Expand All @@ -653,7 +681,8 @@ public void proxyReadChangeStreamAsyncTest() {
Mockito.when(mockStub.readChangeStreamCallable()).thenReturn(mockReadChangeStreamCallable);

@SuppressWarnings("unchecked")
ResponseObserver<ChangeStreamRecord> mockObserver = Mockito.mock(ResponseObserver.class);
ResponseObserver<ChangeStreamRecord> mockObserver =
Mockito.mock(ResponseObserver.class, Mockito.withSettings().withoutAnnotations());
ReadChangeStreamQuery query = ReadChangeStreamQuery.create("fake-table");
bigtableDataClient.readChangeStreamAsync(query, mockObserver);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void setUp() {
new MetricsImpl(
registry,
clientInfo,
Mockito.mock(ApiTracerFactory.class),
Mockito.mock(ApiTracerFactory.class, Mockito.withSettings().withoutAnnotations()),
internalOtel,
userOtel,
Mockito.mock(Tagger.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -144,7 +143,8 @@ public void testExportingSumData() {
ArgumentCaptor<CreateTimeSeriesRequest> argumentCaptor =
ArgumentCaptor.forClass(CreateTimeSeriesRequest.class);

UnaryCallable<CreateTimeSeriesRequest, Empty> mockCallable = mock(UnaryCallable.class);
UnaryCallable<CreateTimeSeriesRequest, Empty> mockCallable =
Mockito.mock(UnaryCallable.class, Mockito.withSettings().withoutAnnotations());
when(mockMetricServiceStub.createServiceTimeSeriesCallable()).thenReturn(mockCallable);
ApiFuture<Empty> future = ApiFutures.immediateFuture(Empty.getDefaultInstance());
when(mockCallable.futureCall(argumentCaptor.capture())).thenReturn(future);
Expand Down Expand Up @@ -201,7 +201,8 @@ public void testExportingHistogramData() {
ArgumentCaptor<CreateTimeSeriesRequest> argumentCaptor =
ArgumentCaptor.forClass(CreateTimeSeriesRequest.class);

UnaryCallable<CreateTimeSeriesRequest, Empty> mockCallable = mock(UnaryCallable.class);
UnaryCallable<CreateTimeSeriesRequest, Empty> mockCallable =
Mockito.mock(UnaryCallable.class, Mockito.withSettings().withoutAnnotations());
when(mockMetricServiceStub.createServiceTimeSeriesCallable()).thenReturn(mockCallable);
ApiFuture<Empty> future = ApiFutures.immediateFuture(Empty.getDefaultInstance());
when(mockCallable.futureCall(argumentCaptor.capture())).thenReturn(future);
Expand Down Expand Up @@ -267,7 +268,8 @@ public void testExportingSumDataInBatches() {
ArgumentCaptor<CreateTimeSeriesRequest> argumentCaptor =
ArgumentCaptor.forClass(CreateTimeSeriesRequest.class);

UnaryCallable<CreateTimeSeriesRequest, Empty> mockCallable = mock(UnaryCallable.class);
UnaryCallable<CreateTimeSeriesRequest, Empty> mockCallable =
Mockito.mock(UnaryCallable.class, Mockito.withSettings().withoutAnnotations());
when(mockMetricServiceStub.createServiceTimeSeriesCallable()).thenReturn(mockCallable);
ApiFuture<Empty> future = ApiFutures.immediateFuture(Empty.getDefaultInstance());
when(mockCallable.futureCall(argumentCaptor.capture())).thenReturn(future);
Expand Down Expand Up @@ -352,7 +354,8 @@ public void testTimeSeriesForMetricWithGceOrGkeResource() {
ArgumentCaptor<CreateTimeSeriesRequest> argumentCaptor =
ArgumentCaptor.forClass(CreateTimeSeriesRequest.class);

UnaryCallable<CreateTimeSeriesRequest, Empty> mockCallable = mock(UnaryCallable.class);
UnaryCallable<CreateTimeSeriesRequest, Empty> mockCallable =
Mockito.mock(UnaryCallable.class, Mockito.withSettings().withoutAnnotations());
when(mockMetricServiceStub.createServiceTimeSeriesCallable()).thenReturn(mockCallable);
ApiFuture<Empty> future = ApiFutures.immediateFuture(Empty.getDefaultInstance());
when(mockCallable.futureCall(argumentCaptor.capture())).thenReturn(future);
Expand Down Expand Up @@ -430,7 +433,8 @@ public void testExportingToMultipleProjects() {
ArgumentCaptor<CreateTimeSeriesRequest> argumentCaptor =
ArgumentCaptor.forClass(CreateTimeSeriesRequest.class);

UnaryCallable<CreateTimeSeriesRequest, Empty> mockCallable = mock(UnaryCallable.class);
UnaryCallable<CreateTimeSeriesRequest, Empty> mockCallable =
Mockito.mock(UnaryCallable.class, Mockito.withSettings().withoutAnnotations());
when(mockMetricServiceStub.createServiceTimeSeriesCallable()).thenReturn(mockCallable);
ApiFuture<Empty> future = ApiFutures.immediateFuture(Empty.getDefaultInstance());
when(mockCallable.futureCall(any())).thenReturn(future);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
Expand Down Expand Up @@ -104,7 +103,6 @@ public class MetricsTracerTest {

private Server server;

@Mock(answer = Answers.CALLS_REAL_METHODS)
private BigtableGrpc.BigtableImplBase mockService;

private final StatsComponent localStats = new SimpleStatsComponent();
Expand All @@ -113,6 +111,10 @@ public class MetricsTracerTest {

@Before
public void setUp() throws Exception {
mockService =
Mockito.mock(
BigtableGrpc.BigtableImplBase.class,
Mockito.withSettings().withoutAnnotations().defaultAnswer(Answers.CALLS_REAL_METHODS));
server = FakeServiceBuilder.create(mockService).start();

com.google.cloud.bigtable.data.v2.stub.metrics.RpcViews.registerBigtableClientViews(
Expand Down Expand Up @@ -414,7 +416,8 @@ public void testBatchReadRowsThrottledTime() throws Exception {

@Test
public void testBatchMutateRowsThrottledTime() throws Exception {
FlowController flowController = Mockito.mock(FlowController.class);
FlowController flowController =
Mockito.mock(FlowController.class, Mockito.withSettings().withoutAnnotations());
MutateRowsBatchingDescriptor batchingDescriptor = new MutateRowsBatchingDescriptor();

// Mock throttling
Expand Down
Loading
Loading