29
29
import com .google .api .gax .batching .BatchingSettings ;
30
30
import com .google .api .gax .batching .FlowControlSettings ;
31
31
import com .google .api .gax .rpc .ClientContext ;
32
+ import com .google .api .gax .rpc .NotFoundException ;
32
33
import com .google .api .gax .rpc .ResponseObserver ;
33
34
import com .google .api .gax .rpc .StreamController ;
34
35
import com .google .api .gax .tracing .SpanName ;
72
73
import java .util .concurrent .atomic .AtomicBoolean ;
73
74
import java .util .concurrent .atomic .AtomicInteger ;
74
75
import org .junit .After ;
76
+ import org .junit .Assert ;
75
77
import org .junit .Before ;
76
78
import org .junit .Rule ;
77
79
import org .junit .Test ;
@@ -91,6 +93,8 @@ public class BuiltinMetricsTracerTest {
91
93
private static final String INSTANCE_ID = "fake-instance" ;
92
94
private static final String APP_PROFILE_ID = "default" ;
93
95
private static final String TABLE_ID = "fake-table" ;
96
+
97
+ private static final String BAD_TABLE_ID = "non-exist-table" ;
94
98
private static final String ZONE = "us-west-1" ;
95
99
private static final String CLUSTER = "cluster-0" ;
96
100
private static final long FAKE_SERVER_TIMING = 50 ;
@@ -438,6 +442,35 @@ public void testClientBlockingLatencies() throws InterruptedException {
438
442
}
439
443
}
440
444
445
+ @ Test
446
+ public void testPermanentFailure () {
447
+ when (mockFactory .newTracer (any (), any (), any ()))
448
+ .thenReturn (
449
+ new BuiltinMetricsTracer (
450
+ OperationType .ServerStreaming ,
451
+ SpanName .of ("Bigtable" , "ReadRows" ),
452
+ statsRecorderWrapper ));
453
+
454
+ try {
455
+ Lists .newArrayList (stub .readRowsCallable ().call (Query .create (BAD_TABLE_ID )).iterator ());
456
+ Assert .fail ("Request should throw not found error" );
457
+ } catch (NotFoundException e ) {
458
+ }
459
+
460
+ ArgumentCaptor <Long > attemptLatency = ArgumentCaptor .forClass (Long .class );
461
+ ArgumentCaptor <Long > operationLatency = ArgumentCaptor .forClass (Long .class );
462
+
463
+ verify (statsRecorderWrapper , timeout (50 )).putAttemptLatencies (attemptLatency .capture ());
464
+ verify (statsRecorderWrapper , timeout (50 )).putOperationLatencies (operationLatency .capture ());
465
+ verify (statsRecorderWrapper , timeout (50 ))
466
+ .recordAttempt (status .capture (), tableId .capture (), zone .capture (), cluster .capture ());
467
+
468
+ assertThat (status .getValue ()).isEqualTo ("NOT_FOUND" );
469
+ assertThat (tableId .getValue ()).isEqualTo (BAD_TABLE_ID );
470
+ assertThat (cluster .getValue ()).isEqualTo ("unspecified" );
471
+ assertThat (zone .getValue ()).isEqualTo ("global" );
472
+ }
473
+
441
474
private static class FakeService extends BigtableGrpc .BigtableImplBase {
442
475
443
476
static List <ReadRowsResponse > createFakeResponse () {
@@ -468,6 +501,10 @@ static List<ReadRowsResponse> createFakeResponse() {
468
501
@ Override
469
502
public void readRows (
470
503
ReadRowsRequest request , StreamObserver <ReadRowsResponse > responseObserver ) {
504
+ if (request .getTableName ().contains (BAD_TABLE_ID )) {
505
+ responseObserver .onError (new StatusRuntimeException (Status .NOT_FOUND ));
506
+ return ;
507
+ }
471
508
final AtomicBoolean done = new AtomicBoolean ();
472
509
final ServerCallStreamObserver <ReadRowsResponse > target =
473
510
(ServerCallStreamObserver <ReadRowsResponse >) responseObserver ;
0 commit comments