@Override Service.Request decode(byte[] serializedRequest) throws IOException { return translation.parseRequest(serializedRequest); }
@Override Service.Request decode(byte[] serializedRequest) throws IOException { try (final Context ctx = serializationTimer.start()) { return translation.parseRequest(serializedRequest); } }
@Override Service.Request decode(byte[] serializedRequest) throws IOException { try (final Context ctx = serializationTimer.start()) { return translation.parseRequest(serializedRequest); } }
public Request apply(Request request) throws IOException { // Serialize and then re-parse the request return translation.parseRequest(translation.serializeRequest(request)); } }
public Request apply(Request request) throws IOException { // Serialize and then re-parse the request return translation.parseRequest(translation.serializeRequest(request)); } }
public Request apply(Request request) throws IOException { // Serialize and then re-parse the request return translation.parseRequest(translation.serializeRequest(request)); } }
@Override public Response _apply(Request request) { try { // Serialize the request to "send to the server" byte[] serializedRequest = translation.serializeRequest(request); // *some transport would normally happen here* // Fake deserializing that request somewhere else Request request2 = translation.parseRequest(serializedRequest); // Serialize the response from the service to "send to the client" byte[] serializedResponse = translation.serializeResponse(request2.accept(service)); // *some transport would normally happen here* // Deserialize the response on "the client" return translation.parseResponse(serializedResponse); } catch (IOException e) { throw new RuntimeException(e); } } }
@Override public Response _apply(Request request) { try { // Serialize the request to "send to the server" byte[] serializedRequest = translation.serializeRequest(request); // *some transport would normally happen here* // Fake deserializing that request somewhere else Request request2 = translation.parseRequest(serializedRequest); // Serialize the response from the service to "send to the client" byte[] serializedResponse = translation.serializeResponse(request2.accept(service)); // *some transport would normally happen here* // Deserialize the response on "the client" return translation.parseResponse(serializedResponse); } catch (IOException e) { throw new RuntimeException(e); } } }
@Override public Response _apply(Request request) { try { // Serialize the request to "send to the server" byte[] serializedRequest = translation.serializeRequest(request); // *some transport would normally happen here* // Fake deserializing that request somewhere else Request request2 = translation.parseRequest(serializedRequest); // Serialize the response from the service to "send to the client" byte[] serializedResponse = translation.serializeResponse(request2.accept(service)); // *some transport would normally happen here* // Deserialize the response on "the client" return translation.parseResponse(serializedResponse); } catch (IOException e) { throw new RuntimeException(e); } } }
@Test public void testExecuteSerialization() throws Exception { Service.ExecuteRequest executeRequest = new Service.ExecuteRequest( new StatementHandle("connection", 12345, getSignature()), getTypedValues(), 0); Requests.ExecuteRequest pbExecuteRequest = executeRequest.serialize(); ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); pbExecuteRequest.writeTo(baos); byte[] serialized = baos.toByteArray(); baos.reset(); WireMessage wireMsg = WireMessage.newBuilder().setName(Requests.ExecuteRequest.class.getName()) .setWrappedMessage(UnsafeByteOperations.unsafeWrap(serialized)).build(); wireMsg.writeTo(baos); serialized = baos.toByteArray(); ProtobufTranslation translator = new ProtobufTranslationImpl(); Request newRequest = translator.parseRequest(serialized); Assert.assertEquals(executeRequest, newRequest); }
@Test public void testExecuteSerialization() throws Exception { Service.ExecuteRequest executeRequest = new Service.ExecuteRequest( new StatementHandle("connection", 12345, getSignature()), getTypedValues(), 0); Requests.ExecuteRequest pbExecuteRequest = executeRequest.serialize(); ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); pbExecuteRequest.writeTo(baos); byte[] serialized = baos.toByteArray(); baos.reset(); WireMessage wireMsg = WireMessage.newBuilder().setName(Requests.ExecuteRequest.class.getName()) .setWrappedMessage(UnsafeByteOperations.unsafeWrap(serialized)).build(); wireMsg.writeTo(baos); serialized = baos.toByteArray(); ProtobufTranslation translator = new ProtobufTranslationImpl(); Request newRequest = translator.parseRequest(serialized); Assert.assertEquals(executeRequest, newRequest); }
FetchResponse response = new FetchResponse(frame, false, false, metadata); when(translation.parseRequest(serializedRequest)).thenReturn(request); when(service.apply(request)).thenReturn(response); when(translation.serializeResponse(response))
FetchResponse response = new FetchResponse(frame, false, false, metadata); when(translation.parseRequest(serializedRequest)).thenReturn(request); when(service.apply(request)).thenReturn(response); when(translation.serializeResponse(response))
FetchResponse response = new FetchResponse(frame, false, false, metadata); when(translation.parseRequest(serializedRequest)).thenReturn(request); when(service.apply(request)).thenReturn(response); when(translation.serializeResponse(response))