diff options
| author | Kristen Kozak <sebright@google.com> | 2017-10-23 13:39:26 -0700 |
|---|---|---|
| committer | Kristen Kozak <sebright@google.com> | 2017-10-23 17:27:02 -0700 |
| commit | 6f94a23dbef32f87522ce373cf0f05537aa9155a (patch) | |
| tree | d25dfc59cc672fd47e5770cafce1c37921c9afff /api/src/test | |
| parent | fc86613fd3527481de9884f6e20a968efc641627 (diff) | |
| download | platform_external_opencensus-java-6f94a23dbef32f87522ce373cf0f05537aa9155a.tar.gz platform_external_opencensus-java-6f94a23dbef32f87522ce373cf0f05537aa9155a.tar.bz2 platform_external_opencensus-java-6f94a23dbef32f87522ce373cf0f05537aa9155a.zip | |
Make StatsRecord.record take the TagContext, not StatsRecorder.newRecord.
StatsRecorder now has one method, newRecord(). StatsRecord has record() and
recordWithExplicitTagContext(TagContext tags). This is slightly more flexible,
because it allows a StatsRecord to be reused to record the same stats with
different TagContexts, at least at the API level.
Diffstat (limited to 'api/src/test')
| -rw-r--r-- | api/src/test/java/io/opencensus/stats/NoopStatsTest.java | 8 | ||||
| -rw-r--r-- | api/src/test/java/io/opencensus/stats/StatsRecorderTest.java | 14 |
2 files changed, 13 insertions, 9 deletions
diff --git a/api/src/test/java/io/opencensus/stats/NoopStatsTest.java b/api/src/test/java/io/opencensus/stats/NoopStatsTest.java index aa7a562b..fe3e8108 100644 --- a/api/src/test/java/io/opencensus/stats/NoopStatsTest.java +++ b/api/src/test/java/io/opencensus/stats/NoopStatsTest.java @@ -87,9 +87,9 @@ public final class NoopStatsTest { @Test public void noopStatsRecorder_Record() { NoopStats.getNoopStatsRecorder() - .newRecordWithExplicitTagContext(tagContext) + .newRecord() .put(MEASURE, 5) - .record(); + .recordWithExplicitTagContext(tagContext); } // The NoopStatsRecorder should do nothing, so this test just checks that record doesn't throw an @@ -101,8 +101,8 @@ public final class NoopStatsTest { @Test public void noopStatsRecorder_Record_DisallowNullTagContext() { - StatsRecorder noopStatsRecorder = NoopStats.getNoopStatsRecorder(); + StatsRecord record = NoopStats.getNoopStatsRecorder().newRecord(); thrown.expect(NullPointerException.class); - noopStatsRecorder.newRecordWithExplicitTagContext(null); + record.recordWithExplicitTagContext(null); } } diff --git a/api/src/test/java/io/opencensus/stats/StatsRecorderTest.java b/api/src/test/java/io/opencensus/stats/StatsRecorderTest.java index 6129d0f4..0f94cb33 100644 --- a/api/src/test/java/io/opencensus/stats/StatsRecorderTest.java +++ b/api/src/test/java/io/opencensus/stats/StatsRecorderTest.java @@ -18,6 +18,7 @@ package io.opencensus.stats; import static org.mockito.Matchers.same; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import io.grpc.Context; import io.opencensus.tags.Tag; @@ -51,25 +52,28 @@ public final class StatsRecorderTest { }; @Mock private StatsRecorder statsRecorder; + @Mock private StatsRecord statsRecord; @Before public void setUp() { MockitoAnnotations.initMocks(this); + when(statsRecorder.newRecord()).thenReturn(statsRecord); } @Test public void record_CurrentContextNotSet() { - statsRecorder.newRecord(); - verify(statsRecorder) - .newRecordWithExplicitTagContext(same(ContextUtils.TAG_CONTEXT_KEY.get())); + StatsRecord record = statsRecorder.newRecord(); + record.record(); + verify(record).recordWithExplicitTagContext(same(ContextUtils.TAG_CONTEXT_KEY.get())); } @Test public void record_CurrentContextSet() { Context orig = Context.current().withValue(ContextUtils.TAG_CONTEXT_KEY, tagContext).attach(); try { - statsRecorder.newRecord(); - verify(statsRecorder).newRecordWithExplicitTagContext(same(tagContext)); + StatsRecord record = statsRecorder.newRecord(); + record.record(); + verify(record).recordWithExplicitTagContext(same(tagContext)); } finally { Context.current().detach(orig); } |
