@Test public void wrapMethodDefinition_handler() throws Exception { final List<String> observedRequest = new ArrayList<>(); final AtomicReference<ServerCall<String, Integer>> serverCall = new AtomicReference<ServerCall<String, Integer>>(); ServerMethodDefinition<String, Integer> methodDef = ServerMethodDefinition.create( method, new ServerCallHandler<String, Integer>() { @Override public ServerCall.Listener<String> startCall( ServerCall<String, Integer> call, Metadata headers) { serverCall.set(call); return new ServerCall.Listener<String>() { @Override public void onMessage(String message) { observedRequest.add(message); } }; } }); ServerMethodDefinition<?, ?> wDef = binlogProvider.wrapMethodDefinition(methodDef); List<Object> serializedResp = new ArrayList<>(); ServerCall.Listener<?> wListener = startServerCallHelper(wDef, serializedResp); String expectedRequest = "hello world"; assertThat(binlogReq).isEmpty(); assertThat(observedRequest).isEmpty(); assertEquals(0, reqMarshaller.parseInvocations); onServerMessageHelper(wListener, StringMarshaller.INSTANCE.stream(expectedRequest)); assertEquals(1, reqMarshaller.parseInvocations); assertEquals(0, reqMarshaller.streamInvocations); assertThat(binlogReq).hasSize(1); assertThat(observedRequest).hasSize(1); assertEquals( expectedRequest, StringMarshaller.INSTANCE.parse(new ByteArrayInputStream(binlogReq.get(0)))); assertEquals(expectedRequest, observedRequest.get(0)); int expectedResponse = 12345; assertThat(binlogResp).isEmpty(); assertThat(serializedResp).isEmpty(); assertEquals(0, respMarshaller.streamInvocations); serverCall.get().sendMessage(expectedResponse); assertEquals(0, respMarshaller.parseInvocations); assertEquals(1, respMarshaller.streamInvocations); assertThat(binlogResp).hasSize(1); assertThat(serializedResp).hasSize(1); assertEquals( expectedResponse, (int) IntegerMarshaller.INSTANCE.parse(new ByteArrayInputStream(binlogResp.get(0)))); assertEquals(expectedResponse, (int) method.parseResponse(new ByteArrayInputStream((byte[]) serializedResp.get(0)))); }
@Override public final <ReqT, RespT> ServerMethodDefinition<?, ?> wrapMethodDefinition( ServerMethodDefinition<ReqT, RespT> oMethodDef) { ServerInterceptor binlogInterceptor = getServerInterceptor(oMethodDef.getMethodDescriptor().getFullMethodName()); if (binlogInterceptor == null) { return oMethodDef; } MethodDescriptor<byte[], byte[]> binMethod = BinaryLogProvider.toByteBufferMethod(oMethodDef.getMethodDescriptor()); ServerMethodDefinition<byte[], byte[]> binDef = InternalServerInterceptors.wrapMethod(oMethodDef, binMethod); ServerCallHandler<byte[], byte[]> binlogHandler = InternalServerInterceptors.interceptCallHandlerCreate( binlogInterceptor, binDef.getServerCallHandler()); return ServerMethodDefinition.create(binMethod, binlogHandler); }
BinaryLogProvider extends BinaryLog { @Override public final <ReqT, RespT> ServerMethodDefinition<?, ?> wrapMethodDefinition( ServerMethodDefinition<ReqT, RespT> oMethodDef) { ServerInterceptor binlogInterceptor = getServerInterceptor(oMethodDef.getMethodDescriptor().getFullMethodName()); if (binlogInterceptor == null) { return oMethodDef; } MethodDescriptor<byte[], byte[]> binMethod = BinaryLogProvider.toByteBufferMethod(oMethodDef.getMethodDescriptor()); ServerMethodDefinition<byte[], byte[]> binDef = InternalServerInterceptors.wrapMethod(oMethodDef, binMethod); ServerCallHandler<byte[], byte[]> binlogHandler = InternalServerInterceptors.interceptCallHandlerCreate( binlogInterceptor, binDef.getServerCallHandler()); return ServerMethodDefinition.create(binMethod, binlogHandler); } }
BinaryLogProvider extends BinaryLog { @Override public final <ReqT, RespT> ServerMethodDefinition<?, ?> wrapMethodDefinition( ServerMethodDefinition<ReqT, RespT> oMethodDef) { ServerInterceptor binlogInterceptor = getServerInterceptor(oMethodDef.getMethodDescriptor().getFullMethodName()); if (binlogInterceptor == null) { return oMethodDef; } MethodDescriptor<byte[], byte[]> binMethod = BinaryLogProvider.toByteBufferMethod(oMethodDef.getMethodDescriptor()); ServerMethodDefinition<byte[], byte[]> binDef = InternalServerInterceptors.wrapMethod(oMethodDef, binMethod); ServerCallHandler<byte[], byte[]> binlogHandler = InternalServerInterceptors.interceptCallHandlerCreate( binlogInterceptor, binDef.getServerCallHandler()); return ServerMethodDefinition.create(binMethod, binlogHandler); }  }
BinaryLogProvider extends BinaryLog { @Override public final <ReqT, RespT> ServerMethodDefinition<?, ?> wrapMethodDefinition( ServerMethodDefinition<ReqT, RespT> oMethodDef) { ServerInterceptor binlogInterceptor = getServerInterceptor(oMethodDef.getMethodDescriptor().getFullMethodName()); if (binlogInterceptor == null) { return oMethodDef; } MethodDescriptor<byte[], byte[]> binMethod = BinaryLogProvider.toByteBufferMethod(oMethodDef.getMethodDescriptor()); ServerMethodDefinition<byte[], byte[]> binDef = InternalServerInterceptors.wrapMethod(oMethodDef, binMethod); ServerCallHandler<byte[], byte[]> binlogHandler = InternalServerInterceptors.interceptCallHandlerCreate( binlogInterceptor, binDef.getServerCallHandler()); return ServerMethodDefinition.create(binMethod, binlogHandler); }  @Override final Channel wrapChannel(Channel channel); @Override final ServerMethodDefinition<?, ?> wrapMethodDefinition(
      ServerMethodDefinition<ReqT, RespT> oMethodDef); @Override void close(); }
BinaryLogProvider extends BinaryLog { @Override public final <ReqT, RespT> ServerMethodDefinition<?, ?> wrapMethodDefinition( ServerMethodDefinition<ReqT, RespT> oMethodDef) { ServerInterceptor binlogInterceptor = getServerInterceptor(oMethodDef.getMethodDescriptor().getFullMethodName()); if (binlogInterceptor == null) { return oMethodDef; } MethodDescriptor<byte[], byte[]> binMethod = BinaryLogProvider.toByteBufferMethod(oMethodDef.getMethodDescriptor()); ServerMethodDefinition<byte[], byte[]> binDef = InternalServerInterceptors.wrapMethod(oMethodDef, binMethod); ServerCallHandler<byte[], byte[]> binlogHandler = InternalServerInterceptors.interceptCallHandlerCreate( binlogInterceptor, binDef.getServerCallHandler()); return ServerMethodDefinition.create(binMethod, binlogHandler); }  @Override final Channel wrapChannel(Channel channel); @Override final ServerMethodDefinition<?, ?> wrapMethodDefinition(
      ServerMethodDefinition<ReqT, RespT> oMethodDef); @Override void close(); @VisibleForTesting
  static final Marshaller<byte[]> BYTEARRAY_MARSHALLER; }