io.grpc.internal.NoopServerCall Java Examples
The following examples show how to use
io.grpc.internal.NoopServerCall.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BinaryLogProviderTest.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
private static <ReqT, RespT> ServerCall.Listener<ReqT> startServerCallHelper( final ServerMethodDefinition<ReqT, RespT> methodDef, final List<Object> serializedResp) { ServerCall<ReqT, RespT> serverCall = new NoopServerCall<ReqT, RespT>() { @Override public void sendMessage(RespT message) { serializedResp.add(message); } @Override public MethodDescriptor<ReqT, RespT> getMethodDescriptor() { return methodDef.getMethodDescriptor(); } }; return methodDef.getServerCallHandler().startCall(serverCall, new Metadata()); }
Example #2
Source File: ServerInterceptorsTest.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
@Test public void argumentsPassed() { @SuppressWarnings("unchecked") final ServerCall<String, Integer> call2 = new NoopServerCall<String, Integer>(); @SuppressWarnings("unchecked") final ServerCall.Listener<String> listener2 = mock(ServerCall.Listener.class); ServerInterceptor interceptor = new ServerInterceptor() { @SuppressWarnings("unchecked") // Lot's of casting for no benefit. Not intended use. @Override public <R1, R2> ServerCall.Listener<R1> interceptCall( ServerCall<R1, R2> call, Metadata headers, ServerCallHandler<R1, R2> next) { assertSame(call, ServerInterceptorsTest.this.call); assertSame(listener, next.startCall((ServerCall<R1, R2>)call2, headers)); return (ServerCall.Listener<R1>) listener2; } }; ServerServiceDefinition intercepted = ServerInterceptors.intercept( serviceDefinition, Arrays.asList(interceptor)); assertSame(listener2, getSoleMethod(intercepted).getServerCallHandler().startCall(call, headers)); verify(handler).startCall(call2, headers); }
Example #3
Source File: ServerInterceptorsTest.java From grpc-java with Apache License 2.0 | 6 votes |
@Test public void argumentsPassed() { @SuppressWarnings("unchecked") final ServerCall<String, Integer> call2 = new NoopServerCall<>(); @SuppressWarnings("unchecked") final ServerCall.Listener<String> listener2 = mock(ServerCall.Listener.class); ServerInterceptor interceptor = new ServerInterceptor() { @SuppressWarnings("unchecked") // Lot's of casting for no benefit. Not intended use. @Override public <R1, R2> ServerCall.Listener<R1> interceptCall( ServerCall<R1, R2> call, Metadata headers, ServerCallHandler<R1, R2> next) { assertSame(call, ServerInterceptorsTest.this.call); assertSame(listener, next.startCall((ServerCall<R1, R2>)call2, headers)); return (ServerCall.Listener<R1>) listener2; } }; ServerServiceDefinition intercepted = ServerInterceptors.intercept( serviceDefinition, Arrays.asList(interceptor)); assertSame(listener2, getSoleMethod(intercepted).getServerCallHandler().startCall(call, headers)); verify(handler).startCall(call2, headers); }
Example #4
Source File: BinaryLogProviderTest.java From grpc-java with Apache License 2.0 | 6 votes |
private static <ReqT, RespT> ServerCall.Listener<ReqT> startServerCallHelper( final ServerMethodDefinition<ReqT, RespT> methodDef, final List<Object> serializedResp) { ServerCall<ReqT, RespT> serverCall = new NoopServerCall<ReqT, RespT>() { @Override public void sendMessage(RespT message) { serializedResp.add(message); } @Override public MethodDescriptor<ReqT, RespT> getMethodDescriptor() { return methodDef.getMethodDescriptor(); } }; return methodDef.getServerCallHandler().startCall(serverCall, new Metadata()); }
Example #5
Source File: StreamExecutorRejectedExecutionRequestSchedulerTest.java From pinpoint with Apache License 2.0 | 5 votes |
@Test public void schedule() { StreamExecutorRejectedExecutionRequestScheduler scheduler = new StreamExecutorRejectedExecutionRequestScheduler(scheduledExecutorService, 1000, 10); StreamExecutorRejectedExecutionRequestScheduler.Listener listener = scheduler.schedule(new NoopServerCall()); assertEquals(0, listener.getRejectedExecutionCount()); listener.onRejectedExecution(); assertEquals(1, listener.getRejectedExecutionCount()); ScheduledFuture scheduledFuture = listener.getRequestScheduledFuture(); assertFalse(scheduledFuture.isCancelled()); listener.onCancel(); assertTrue(scheduledFuture.isCancelled()); }
Example #6
Source File: BinlogHelperTest.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
@Test @SuppressWarnings({"rawtypes", "unchecked"}) public void serverDeadlineLogged() { final AtomicReference<ServerCall> interceptedCall = new AtomicReference<ServerCall>(); final ServerCall.Listener mockListener = mock(ServerCall.Listener.class); final MethodDescriptor<byte[], byte[]> method = MethodDescriptor.<byte[], byte[]>newBuilder() .setType(MethodType.UNKNOWN) .setFullMethodName("service/method") .setRequestMarshaller(BYTEARRAY_MARSHALLER) .setResponseMarshaller(BYTEARRAY_MARSHALLER) .build(); // We expect the contents of the "grpc-timeout" header to be installed the context Context.current() .withDeadlineAfter(1, TimeUnit.SECONDS, Executors.newSingleThreadScheduledExecutor()) .run(new Runnable() { @Override public void run() { ServerCall.Listener<byte[]> unused = new BinlogHelper(mockSinkWriter) .getServerInterceptor(CALL_ID) .interceptCall( new NoopServerCall<byte[], byte[]>() { @Override public MethodDescriptor<byte[], byte[]> getMethodDescriptor() { return method; } }, new Metadata(), new ServerCallHandler<byte[], byte[]>() { @Override public ServerCall.Listener<byte[]> startCall( ServerCall<byte[], byte[]> call, Metadata headers) { interceptedCall.set(call); return mockListener; } }); } }); ArgumentCaptor<Duration> timeoutCaptor = ArgumentCaptor.forClass(Duration.class); verify(mockSinkWriter).logClientHeader( /*seq=*/ eq(1L), eq("service/method"), isNull(String.class), timeoutCaptor.capture(), any(Metadata.class), eq(Logger.LOGGER_SERVER), eq(CALL_ID), isNull(SocketAddress.class)); verifyNoMoreInteractions(mockSinkWriter); Duration timeout = timeoutCaptor.getValue(); assertThat(TimeUnit.SECONDS.toNanos(1) - Durations.toNanos(timeout)) .isAtMost(TimeUnit.MILLISECONDS.toNanos(250)); }
Example #7
Source File: BinlogHelperTest.java From grpc-java with Apache License 2.0 | 4 votes |
@Test @SuppressWarnings({"rawtypes", "unchecked"}) public void serverDeadlineLogged() { final AtomicReference<ServerCall> interceptedCall = new AtomicReference<>(); final ServerCall.Listener mockListener = mock(ServerCall.Listener.class); final MethodDescriptor<byte[], byte[]> method = MethodDescriptor.<byte[], byte[]>newBuilder() .setType(MethodType.UNKNOWN) .setFullMethodName("service/method") .setRequestMarshaller(BYTEARRAY_MARSHALLER) .setResponseMarshaller(BYTEARRAY_MARSHALLER) .build(); // We expect the contents of the "grpc-timeout" header to be installed the context Context.current() .withDeadlineAfter(1, TimeUnit.SECONDS, Executors.newSingleThreadScheduledExecutor()) .run(new Runnable() { @Override public void run() { ServerCall.Listener<byte[]> unused = new BinlogHelper(mockSinkWriter) .getServerInterceptor(CALL_ID) .interceptCall( new NoopServerCall<byte[], byte[]>() { @Override public MethodDescriptor<byte[], byte[]> getMethodDescriptor() { return method; } }, new Metadata(), new ServerCallHandler<byte[], byte[]>() { @Override public ServerCall.Listener<byte[]> startCall( ServerCall<byte[], byte[]> call, Metadata headers) { interceptedCall.set(call); return mockListener; } }); } }); ArgumentCaptor<Duration> timeoutCaptor = ArgumentCaptor.forClass(Duration.class); verify(mockSinkWriter).logClientHeader( /*seq=*/ eq(1L), eq("service/method"), ArgumentMatchers.<String>isNull(), timeoutCaptor.capture(), any(Metadata.class), eq(Logger.LOGGER_SERVER), eq(CALL_ID), ArgumentMatchers.<SocketAddress>isNull()); verifyNoMoreInteractions(mockSinkWriter); Duration timeout = timeoutCaptor.getValue(); assertThat(TimeUnit.SECONDS.toNanos(1) - Durations.toNanos(timeout)) .isAtMost(TimeUnit.MILLISECONDS.toNanos(250)); }