Skip to content

Commit

Permalink
test: add a test for readrows tags for fix googleapis#1477
Browse files Browse the repository at this point in the history
  • Loading branch information
mutianf committed Nov 5, 2022
1 parent 6db9326 commit ee5ea42
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public void testRetryCount() {
}

@Test
public void testMutateRowAttempts() {
public void testMutateRowAttemptsTagValues() {
when(mockFactory.newTracer(any(), any(), any()))
.thenReturn(
new BuiltinMetricsTracer(
Expand All @@ -345,6 +345,29 @@ public void testMutateRowAttempts() {
assertThat(status.getAllValues()).containsExactly("UNAVAILABLE", "UNAVAILABLE", "OK");
}

@Test
public void testReadRowsAttemptsTagValues() {
when(mockFactory.newTracer(any(), any(), any()))
.thenReturn(
new BuiltinMetricsTracer(
OperationType.ServerStreaming,
SpanName.of("Bigtable", "ReadRows"),
statsRecorderWrapper));

Lists.newArrayList(stub.readRowsCallable().call(Query.create("fake-table")).iterator());

// Set a timeout to reduce flakiness of this test. BasicRetryingFuture will set
// attempt succeeded and set the response which will call complete() in AbstractFuture which
// calls releaseWaiters(). onOperationComplete() is called in TracerFinisher which will be
// called after the mutateRow call is returned. So there's a race between when the call returns
// and when the record() is called in onOperationCompletion().
verify(statsRecorderWrapper, timeout(50).times(fakeService.getAttemptCounter().get()))
.recordAttempt(status.capture(), tableId.capture(), zone.capture(), cluster.capture());
assertThat(zone.getAllValues()).containsExactly("global", ZONE);
assertThat(cluster.getAllValues()).containsExactly("unspecified", CLUSTER);
assertThat(status.getAllValues()).containsExactly("UNAVAILABLE", "OK");
}

private static class FakeService extends BigtableGrpc.BigtableImplBase {

static List<ReadRowsResponse> createFakeResponse() {
Expand Down

0 comments on commit ee5ea42

Please sign in to comment.