MCPcopy Create free account
hub / github.com/grpc/grpc-java / CensusModulesTest

Class CensusModulesTest

census/src/test/java/io/grpc/census/CensusModulesTest.java:129–1640  ·  view source on GitHub ↗

Test for CensusStatsModule and CensusTracingModule.

Source from the content-addressed store, hash-verified

127 * Test for {@link CensusStatsModule} and {@link CensusTracingModule}.
128 */
129@RunWith(JUnit4.class)
130public class CensusModulesTest {
131
132 private static final double TOLERANCE = 1e-6;
133 private static final CallOptions.Key<String> CUSTOM_OPTION =
134 CallOptions.Key.createWithDefault("option1", "default");
135 private static final CallOptions CALL_OPTIONS =
136 CallOptions.DEFAULT.withOption(CUSTOM_OPTION, "customvalue");
137 private static final ClientStreamTracer.StreamInfo STREAM_INFO =
138 ClientStreamTracer.StreamInfo.newBuilder()
139 .setCallOptions(CallOptions.DEFAULT.withOption(NAME_RESOLUTION_DELAYED, 10L)).build();
140
141 private static class StringInputStream extends InputStream implements KnownLength {
142 final String string;
143
144 StringInputStream(String string) {
145 this.string = string;
146 }
147
148 @Override
149 public int read() {
150 // InProcessTransport doesn't actually read bytes from the InputStream. The InputStream is
151 // passed to the InProcess server and consumed by MARSHALLER.parse().
152 throw new UnsupportedOperationException("Should not be called");
153 }
154
155 @Override
156 public int available() throws IOException {
157 return string == null ? 0 : string.length();
158 }
159 }
160
161 private static final MethodDescriptor.Marshaller<String> MARSHALLER =
162 new MethodDescriptor.Marshaller<String>() {
163 @Override
164 public InputStream stream(String value) {
165 return new StringInputStream(value);
166 }
167
168 @Override
169 public String parse(InputStream stream) {
170 return ((StringInputStream) stream).string;
171 }
172 };
173
174 @Rule
175 public final MockitoRule mocks = MockitoJUnit.rule();
176
177 private final MethodDescriptor<String, String> method =
178 MethodDescriptor.<String, String>newBuilder()
179 .setType(MethodDescriptor.MethodType.UNKNOWN)
180 .setRequestMarshaller(MARSHALLER)
181 .setResponseMarshaller(MARSHALLER)
182 .setFullMethodName("package1.service2/method3")
183 .build();
184 private final MethodDescriptor<String, String> sampledMethod =
185 method.toBuilder().setSampledToLocalTracing(true).build();
186

Callers

nothing calls this directly

Calls 14

newBuilderMethod · 0.95
generateRandomSpanMethod · 0.95
setCallOptionsMethod · 0.80
setFullMethodNameMethod · 0.80
setResponseMarshallerMethod · 0.80
setRequestMarshallerMethod · 0.80
setTypeMethod · 0.80
buildMethod · 0.65
createWithDefaultMethod · 0.45
withOptionMethod · 0.45
newBuilderMethod · 0.45

Tested by

no test coverage detected