MCPcopy Index your code
hub / github.com/grpc/grpc-java / ServerImplTest

Class ServerImplTest

core/src/test/java/io/grpc/internal/ServerImplTest.java:121–1898  ·  view source on GitHub ↗

Unit tests for ServerImpl.

Source from the content-addressed store, hash-verified

119
120/** Unit tests for {@link ServerImpl}. */
121@RunWith(JUnit4.class)
122public class ServerImplTest {
123 private static final IntegerMarshaller INTEGER_MARSHALLER = IntegerMarshaller.INSTANCE;
124 private static final StringMarshaller STRING_MARSHALLER = StringMarshaller.INSTANCE;
125 private static final MethodDescriptor<String, Integer> METHOD =
126 MethodDescriptor.<String, Integer>newBuilder()
127 .setType(MethodDescriptor.MethodType.UNKNOWN)
128 .setFullMethodName("Waiter/serve")
129 .setRequestMarshaller(STRING_MARSHALLER)
130 .setResponseMarshaller(INTEGER_MARSHALLER)
131 .build();
132 private static final MethodDescriptor<String, Integer> GENERATED_METHOD =
133 METHOD.toBuilder()
134 .setSampledToLocalTracing(true)
135 .build();
136 private static final Context.Key<String> SERVER_ONLY = Context.key("serverOnly");
137 private static final Context.Key<String> SERVER_TRACER_ADDED_KEY = Context.key("tracer-added");
138 private static final Context.CancellableContext SERVER_CONTEXT =
139 Context.ROOT.withValue(SERVER_ONLY, "yes").withCancellation();
140 private static final FakeClock.TaskFilter CONTEXT_CLOSER_TASK_FILTER =
141 new FakeClock.TaskFilter() {
142 @Override
143 public boolean shouldAccept(Runnable runnable) {
144 return runnable instanceof ServerImpl.ContextCloser;
145 }
146 };
147 private static final String AUTHORITY = "some_authority";
148
149 private static final class MethodNameCapturingTracer extends ServerStreamTracer
150 implements StatsTraceContext.ServerCallMethodListener {
151 @Nullable private ServerCallInfo<?, ?> serverCallInfo;
152 @Nullable private String recordedMethodName;
153 @Nullable private String resolvedMethodName;
154 private boolean streamClosed;
155
156 @Override
157 public synchronized void serverCallMethodResolved(MethodDescriptor<?, ?> method) {
158 resolvedMethodName =
159 recordMethodName(method.isSampledToLocalTracing(), method.getFullMethodName());
160 }
161
162 @Override
163 public synchronized void streamClosed(Status status) {
164 streamClosed = true;
165 if (serverCallInfo != null) {
166 recordedMethodName =
167 recordMethodName(
168 serverCallInfo.getMethodDescriptor().isSampledToLocalTracing(),
169 serverCallInfo.getMethodDescriptor().getFullMethodName());
170 } else if (resolvedMethodName != null) {
171 recordedMethodName = resolvedMethodName;
172 } else {
173 recordedMethodName = "other";
174 }
175 }
176
177 @Override
178 public synchronized void serverCallStarted(ServerCallInfo<?, ?> callInfo) {

Callers

nothing calls this directly

Calls 11

newBuilderMethod · 0.95
keyMethod · 0.95
setResponseMarshallerMethod · 0.80
setRequestMarshallerMethod · 0.80
setFullMethodNameMethod · 0.80
setTypeMethod · 0.80
withCancellationMethod · 0.80
withValueMethod · 0.80
buildMethod · 0.65
toBuilderMethod · 0.45

Tested by

no test coverage detected