This is an automated email from the ASF dual-hosted git repository. valentyn pushed a commit to branch valentyn/streaming-serializers in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/valentyn/streaming-serializers by this push: new caee19ebd7 test cleanup caee19ebd7 is described below commit caee19ebd77e325f69891a790b66714c5fa3836e Author: Valentyn Kahamlyk <valentyn.kaham...@improving.com> AuthorDate: Wed Mar 27 12:42:51 2024 -0700 test cleanup --- .../util/ser/GraphSONMessageSerializerV3Test.java | 4 +- .../util/ser/GraphSONMessageSerializerV4Test.java | 23 +++-------- .../binary/GraphBinaryMessageSerializerV4Test.java | 44 ++++++++++++++++++---- 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/util/ser/GraphSONMessageSerializerV3Test.java b/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/util/ser/GraphSONMessageSerializerV3Test.java index 24cf8391bf..9398840036 100644 --- a/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/util/ser/GraphSONMessageSerializerV3Test.java +++ b/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/util/ser/GraphSONMessageSerializerV3Test.java @@ -408,12 +408,12 @@ public class GraphSONMessageSerializerV3Test { assertEquals(ResponseStatusCode.SUCCESS, response.getStatus().getCode()); } - private ResponseMessage convert(final Object toSerialize, MessageSerializer<?> serializer) throws SerializationException { + protected ResponseMessage convert(final Object toSerialize, MessageSerializer<?> serializer) throws SerializationException { final ByteBuf bb = serializer.serializeResponseAsBinary(responseMessageBuilder.result(toSerialize).create(), allocator); return serializer.deserializeResponse(bb); } - private ResponseMessage convert(final Object toSerialize) throws SerializationException { + protected ResponseMessage convert(final Object toSerialize) throws SerializationException { return convert(toSerialize, this.serializer); } } diff --git a/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/util/ser/GraphSONMessageSerializerV4Test.java b/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/util/ser/GraphSONMessageSerializerV4Test.java index 27cb804a3b..7d77e07b37 100644 --- a/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/util/ser/GraphSONMessageSerializerV4Test.java +++ b/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/util/ser/GraphSONMessageSerializerV4Test.java @@ -60,13 +60,7 @@ public class GraphSONMessageSerializerV4Test extends GraphSONMessageSerializerV3 final ByteBuf bb2 = serializer.writeChunk(Arrays.asList("chunk", 2), allocator); final ByteBuf bb3 = serializer.writeFooter(response, allocator); - final ByteBuf bbCombined = allocator.buffer(bb0.readableBytes() + bb1.readableBytes() + - bb2.readableBytes() + bb3.readableBytes()); - - bbCombined.writeBytes(bb0); - bbCombined.writeBytes(bb1); - bbCombined.writeBytes(bb2); - bbCombined.writeBytes(bb3); + final ByteBuf bbCombined = allocator.buffer().writeBytes(bb0).writeBytes(bb1).writeBytes(bb2).writeBytes(bb3); final ResponseMessage deserialized = serializer.deserializeResponse(bbCombined); @@ -89,13 +83,7 @@ public class GraphSONMessageSerializerV4Test extends GraphSONMessageSerializerV3 final ByteBuf bb2 = serializer.writeChunk(Arrays.asList("chunk", 2), allocator); final ByteBuf bb3 = serializer.writeErrorFooter(response, allocator); - final ByteBuf bbCombined = allocator.buffer(bb0.readableBytes() + bb1.readableBytes() + - bb2.readableBytes() + bb3.readableBytes()); - - bbCombined.writeBytes(bb0); - bbCombined.writeBytes(bb1); - bbCombined.writeBytes(bb2); - bbCombined.writeBytes(bb3); + final ByteBuf bbCombined = allocator.buffer().writeBytes(bb0).writeBytes(bb1).writeBytes(bb2).writeBytes(bb3); final ResponseMessage deserialized = serializer.deserializeResponse(bbCombined); @@ -106,9 +94,8 @@ public class GraphSONMessageSerializerV4Test extends GraphSONMessageSerializerV3 assertEquals("OK", deserialized.getStatus().getMessage()); } - private static String getString(final ByteBuf bb) { - final String result = bb.readCharSequence(bb.readableBytes(), CharsetUtil.UTF_8).toString(); - bb.resetReaderIndex(); - return result; + @Override + protected ResponseMessage convert(final Object toSerialize) throws SerializationException { + return convert(toSerialize, this.serializer); } } diff --git a/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/util/ser/binary/GraphBinaryMessageSerializerV4Test.java b/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/util/ser/binary/GraphBinaryMessageSerializerV4Test.java index daeb368ab4..d6a9e47c7f 100644 --- a/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/util/ser/binary/GraphBinaryMessageSerializerV4Test.java +++ b/gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/util/ser/binary/GraphBinaryMessageSerializerV4Test.java @@ -121,13 +121,7 @@ public class GraphBinaryMessageSerializerV4Test { final ByteBuf bb2 = serializer.writeChunk(chunkData2, allocator); final ByteBuf bb3 = serializer.writeFooter(footer, allocator); - final ByteBuf bbCombined = allocator.buffer(bb0.readableBytes() + bb1.readableBytes() + - bb2.readableBytes() + bb3.readableBytes()); - - bbCombined.writeBytes(bb0); - bbCombined.writeBytes(bb1); - bbCombined.writeBytes(bb2); - bbCombined.writeBytes(bb3); + final ByteBuf bbCombined = allocator.buffer().writeBytes(bb0).writeBytes(bb1).writeBytes(bb2).writeBytes(bb3); final ResponseMessage deserialized = serializer.readChunk(bbCombined, true); @@ -141,6 +135,42 @@ public class GraphBinaryMessageSerializerV4Test { assertEquals(combinedData, deserialized.getResult().getData()); } + @Test + public void shouldSerializeAndDeserializeCompositeResponseWithError() throws SerializationException { + final List headerData = Arrays.asList(0, "header"); + final ResponseMessage header = ResponseMessage.buildV4(UUID.randomUUID()) + .result(headerData) + .create(); + + final List chunkData1 = Arrays.asList(1, "data1"); + final List chunkData2 = Arrays.asList(2, "data2"); + + final List footerData = Arrays.asList(0xFF, "footer"); + final ResponseMessage footer = ResponseMessage.build((UUID)null) + .result(footerData) + .code(ResponseStatusCode.SERVER_ERROR) + .statusMessage("SERVER_ERROR") + .create(); + + final ByteBuf bb0 = serializer.writeHeader(header, allocator); + final ByteBuf bb1 = serializer.writeChunk(chunkData1, allocator); + final ByteBuf bb2 = serializer.writeChunk(chunkData2, allocator); + final ByteBuf bb3 = serializer.writeErrorFooter(footer, allocator); + + final ByteBuf bbCombined = allocator.buffer().writeBytes(bb0).writeBytes(bb1).writeBytes(bb2).writeBytes(bb3); + + final ResponseMessage deserialized = serializer.readChunk(bbCombined, true); + + assertEquals(header.getRequestId(), deserialized.getRequestId()); + // Status + assertEquals(footer.getStatus().getCode(), deserialized.getStatus().getCode()); + assertEquals(footer.getStatus().getMessage(), deserialized.getStatus().getMessage()); + // Result + List<Integer> combinedData = new ArrayList<>(); + Stream.of(headerData, chunkData1, chunkData2).forEach(combinedData::addAll); + assertEquals(combinedData, deserialized.getResult().getData()); + } + // copy-paste because response format will be different private static void assertResponseEquals(final ResponseMessage expected, final ResponseMessage actual) {