9797import io .opentelemetry .sdk .testing .exporter .InMemoryMetricReader ;
9898import java .nio .charset .Charset ;
9999import java .util .ArrayList ;
100- import java .util .Collection ;
101100import java .util .Collections ;
102101import java .util .Iterator ;
103102import java .util .List ;
@@ -298,9 +297,7 @@ public void testReadRowsOperationLatencies() {
298297 .put (CLIENT_NAME_KEY , CLIENT_NAME )
299298 .build ();
300299
301- Collection <MetricData > allMetricData = metricReader .collectAllMetrics ();
302-
303- MetricData metricData = getMetricData (allMetricData , OPERATION_LATENCIES_NAME );
300+ MetricData metricData = getMetricData (metricReader , OPERATION_LATENCIES_NAME );
304301
305302 long value = getAggregatedValue (metricData , expectedAttributes );
306303 assertThat (value ).isIn (Range .closed (SERVER_LATENCY , elapsed ));
@@ -326,9 +323,7 @@ public void testReadRowsOperationLatenciesOnAuthorizedView() {
326323 .put (CLIENT_NAME_KEY , CLIENT_NAME )
327324 .build ();
328325
329- Collection <MetricData > allMetricData = metricReader .collectAllMetrics ();
330-
331- MetricData metricData = getMetricData (allMetricData , OPERATION_LATENCIES_NAME );
326+ MetricData metricData = getMetricData (metricReader , OPERATION_LATENCIES_NAME );
332327 long value = getAggregatedValue (metricData , expectedAttributes );
333328 assertThat (value ).isIn (Range .closed (SERVER_LATENCY , elapsed ));
334329 }
@@ -348,15 +343,13 @@ public void testGfeMetrics() {
348343 .put (METHOD_KEY , "Bigtable.ReadRows" )
349344 .build ();
350345
351- Collection <MetricData > allMetricData = metricReader .collectAllMetrics ();
352-
353- MetricData serverLatenciesMetricData = getMetricData (allMetricData , SERVER_LATENCIES_NAME );
346+ MetricData serverLatenciesMetricData = getMetricData (metricReader , SERVER_LATENCIES_NAME );
354347
355348 long serverLatencies = getAggregatedValue (serverLatenciesMetricData , expectedAttributes );
356349 assertThat (serverLatencies ).isEqualTo (FAKE_SERVER_TIMING );
357350
358351 MetricData connectivityErrorCountMetricData =
359- getMetricData (allMetricData , CONNECTIVITY_ERROR_COUNT_NAME );
352+ getMetricData (metricReader , CONNECTIVITY_ERROR_COUNT_NAME );
360353 Attributes expected1 =
361354 baseAttributes
362355 .toBuilder ()
@@ -420,9 +413,8 @@ public void onComplete() {
420413
421414 assertThat (counter .get ()).isEqualTo (fakeService .getResponseCounter ().get ());
422415
423- Collection <MetricData > allMetricData = metricReader .collectAllMetrics ();
424416 MetricData applicationLatency =
425- getMetricData (allMetricData , APPLICATION_BLOCKING_LATENCIES_NAME );
417+ getMetricData (metricReader , APPLICATION_BLOCKING_LATENCIES_NAME );
426418
427419 Attributes expectedAttributes =
428420 baseAttributes
@@ -437,7 +429,7 @@ public void onComplete() {
437429
438430 assertThat (value ).isAtLeast ((APPLICATION_LATENCY - SLEEP_VARIABILITY ) * counter .get ());
439431
440- MetricData operationLatency = getMetricData (allMetricData , OPERATION_LATENCIES_NAME );
432+ MetricData operationLatency = getMetricData (metricReader , OPERATION_LATENCIES_NAME );
441433 long operationLatencyValue =
442434 getAggregatedValue (
443435 operationLatency ,
@@ -457,9 +449,8 @@ public void testReadRowsApplicationLatencyWithManualFlowControl() throws Excepti
457449 rows .next ();
458450 }
459451
460- Collection <MetricData > allMetricData = metricReader .collectAllMetrics ();
461452 MetricData applicationLatency =
462- getMetricData (allMetricData , APPLICATION_BLOCKING_LATENCIES_NAME );
453+ getMetricData (metricReader , APPLICATION_BLOCKING_LATENCIES_NAME );
463454
464455 Attributes expectedAttributes =
465456 baseAttributes
@@ -477,7 +468,7 @@ public void testReadRowsApplicationLatencyWithManualFlowControl() throws Excepti
477468 assertThat (counter ).isEqualTo (fakeService .getResponseCounter ().get ());
478469 assertThat (value ).isAtLeast (APPLICATION_LATENCY * (counter - 1 ) - SERVER_LATENCY );
479470
480- MetricData operationLatency = getMetricData (allMetricData , OPERATION_LATENCIES_NAME );
471+ MetricData operationLatency = getMetricData (metricReader , OPERATION_LATENCIES_NAME );
481472 long operationLatencyValue =
482473 getAggregatedValue (
483474 operationLatency ,
@@ -490,8 +481,7 @@ public void testRetryCount() throws InterruptedException {
490481 stub .mutateRowCallable ()
491482 .call (RowMutation .create (TABLE , "random-row" ).setCell ("cf" , "q" , "value" ));
492483
493- Collection <MetricData > allMetricData = metricReader .collectAllMetrics ();
494- MetricData metricData = getMetricData (allMetricData , RETRY_COUNT_NAME );
484+ MetricData metricData = getMetricData (metricReader , RETRY_COUNT_NAME );
495485 Attributes expectedAttributes =
496486 baseAttributes
497487 .toBuilder ()
@@ -512,8 +502,7 @@ public void testMutateRowAttemptsTagValues() {
512502 stub .mutateRowCallable ()
513503 .call (RowMutation .create (TABLE , "random-row" ).setCell ("cf" , "q" , "value" ));
514504
515- Collection <MetricData > allMetricData = metricReader .collectAllMetrics ();
516- MetricData metricData = getMetricData (allMetricData , ATTEMPT_LATENCIES_NAME );
505+ MetricData metricData = getMetricData (metricReader , ATTEMPT_LATENCIES_NAME );
517506
518507 Attributes expected1 =
519508 baseAttributes
@@ -554,8 +543,7 @@ public void testMutateRowsPartialError() throws InterruptedException {
554543
555544 Assert .assertThrows (BatchingException .class , batcher ::close );
556545
557- Collection <MetricData > allMetricData = metricReader .collectAllMetrics ();
558- MetricData metricData = getMetricData (allMetricData , ATTEMPT_LATENCIES_NAME );
546+ MetricData metricData = getMetricData (metricReader , ATTEMPT_LATENCIES_NAME );
559547
560548 Attributes expected =
561549 baseAttributes
@@ -584,8 +572,7 @@ public void testMutateRowsRpcError() {
584572
585573 Assert .assertThrows (BatchingException .class , batcher ::close );
586574
587- Collection <MetricData > allMetricData = metricReader .collectAllMetrics ();
588- MetricData metricData = getMetricData (allMetricData , ATTEMPT_LATENCIES_NAME );
575+ MetricData metricData = getMetricData (metricReader , ATTEMPT_LATENCIES_NAME );
589576
590577 Attributes expected =
591578 baseAttributes
@@ -606,8 +593,7 @@ public void testMutateRowsRpcError() {
606593 public void testReadRowsAttemptsTagValues () {
607594 Lists .newArrayList (stub .readRowsCallable ().call (Query .create ("fake-table" )).iterator ());
608595
609- Collection <MetricData > allMetricData = metricReader .collectAllMetrics ();
610- MetricData metricData = getMetricData (allMetricData , ATTEMPT_LATENCIES_NAME );
596+ MetricData metricData = getMetricData (metricReader , ATTEMPT_LATENCIES_NAME );
611597
612598 Attributes expected1 =
613599 baseAttributes
@@ -649,8 +635,7 @@ public void testBatchBlockingLatencies() throws InterruptedException {
649635
650636 int expectedNumRequests = 6 / batchElementCount ;
651637
652- Collection <MetricData > allMetricData = metricReader .collectAllMetrics ();
653- MetricData applicationLatency = getMetricData (allMetricData , CLIENT_BLOCKING_LATENCIES_NAME );
638+ MetricData applicationLatency = getMetricData (metricReader , CLIENT_BLOCKING_LATENCIES_NAME );
654639
655640 Attributes expectedAttributes =
656641 baseAttributes
@@ -675,8 +660,7 @@ public void testBatchBlockingLatencies() throws InterruptedException {
675660 public void testQueuedOnChannelServerStreamLatencies () {
676661 stub .readRowsCallable ().all ().call (Query .create (TABLE ));
677662
678- Collection <MetricData > allMetricData = metricReader .collectAllMetrics ();
679- MetricData clientLatency = getMetricData (allMetricData , CLIENT_BLOCKING_LATENCIES_NAME );
663+ MetricData clientLatency = getMetricData (metricReader , CLIENT_BLOCKING_LATENCIES_NAME );
680664
681665 Attributes attributes =
682666 baseAttributes
@@ -697,8 +681,7 @@ public void testQueuedOnChannelUnaryLatencies() {
697681
698682 stub .mutateRowCallable ().call (RowMutation .create (TABLE , "a-key" ).setCell ("f" , "q" , "v" ));
699683
700- Collection <MetricData > allMetricData = metricReader .collectAllMetrics ();
701- MetricData clientLatency = getMetricData (allMetricData , CLIENT_BLOCKING_LATENCIES_NAME );
684+ MetricData clientLatency = getMetricData (metricReader , CLIENT_BLOCKING_LATENCIES_NAME );
702685
703686 Attributes attributes =
704687 baseAttributes
@@ -723,8 +706,7 @@ public void testPermanentFailure() {
723706 } catch (NotFoundException e ) {
724707 }
725708
726- Collection <MetricData > allMetricData = metricReader .collectAllMetrics ();
727- MetricData attemptLatency = getMetricData (allMetricData , ATTEMPT_LATENCIES_NAME );
709+ MetricData attemptLatency = getMetricData (metricReader , ATTEMPT_LATENCIES_NAME );
728710
729711 Attributes expected =
730712 baseAttributes
@@ -740,7 +722,7 @@ public void testPermanentFailure() {
740722
741723 verifyAttributes (attemptLatency , expected );
742724
743- MetricData opLatency = getMetricData (allMetricData , OPERATION_LATENCIES_NAME );
725+ MetricData opLatency = getMetricData (metricReader , OPERATION_LATENCIES_NAME );
744726 verifyAttributes (opLatency , expected );
745727 }
746728
0 commit comments