mirror of https://github.com/grpc/grpc-java.git
services: added even more (context-related) test cases for CallMetricRecorder (#6033)
This commit is contained in:
parent
f9509694b9
commit
b8933faae1
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.grpc.services;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import io.grpc.Context;
|
||||
import io.grpc.ExperimentalApi;
|
||||
import java.util.Collections;
|
||||
|
|
@ -96,6 +97,11 @@ public final class CallMetricRecorder {
|
|||
return Collections.unmodifiableMap(savedMetrics);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean isDisabled() {
|
||||
return disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn this recorder into a no-op one.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package io.grpc.services;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.grpc.Context;
|
||||
import java.util.Map;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
|
@ -63,4 +64,28 @@ public class CallMetricRecorderTest {
|
|||
assertThat(dump)
|
||||
.containsExactly("cost1", 4654.67, "cost2", 75.83);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCurrent_sameEnabledInstance() {
|
||||
CallMetricRecorder recorder = new CallMetricRecorder();
|
||||
Context ctx = Context.ROOT.withValue(CallMetricRecorder.CONTEXT_KEY, recorder);
|
||||
Context origCtx = ctx.attach();
|
||||
try {
|
||||
assertThat(CallMetricRecorder.getCurrent()).isSameInstanceAs(recorder);
|
||||
assertThat(recorder.isDisabled()).isFalse();
|
||||
} finally {
|
||||
ctx.detach(origCtx);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCurrent_blankContext() {
|
||||
Context blankCtx = Context.ROOT;
|
||||
Context origCtx = blankCtx.attach();
|
||||
try {
|
||||
assertThat(CallMetricRecorder.getCurrent().isDisabled()).isTrue();
|
||||
} finally {
|
||||
blankCtx.detach(origCtx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue