Test for CensusStatsModule and CensusTracingModule.
| 127 | * Test for {@link CensusStatsModule} and {@link CensusTracingModule}. |
| 128 | */ |
| 129 | @RunWith(JUnit4.class) |
| 130 | public 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 |
nothing calls this directly
no test coverage detected