Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added reader rewind to remote payload processor #112

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ private static PayloadContent prepareContentBody(Payload payload) {
return new PayloadContent(id, modelId, data, kind, status, metadataMap);
}

private static String encodeBinaryToString(ByteBuf byteBuf) {
static String encodeBinaryToString(ByteBuf byteBuf) {
byteBuf = byteBuf.readerIndex(0);
ByteBuf encodedBinary = Base64.encode(byteBuf, byteBuf.readerIndex(), byteBuf.readableBytes(), false);
//TODO custom jackson serialization for this field to avoid round-tripping to string
return encodedBinary.toString(StandardCharsets.US_ASCII);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,20 @@ void testDestinationUnreachable() {
Payload payload = new Payload(id, modelId, method, metadata, data, kind);
assertFalse(remotePayloadProcessor.process(payload));
}

@Test
void testByteBufReaderIndexReset() {
ByteBuf byteBuf = Unpooled.wrappedBuffer("{[0, 0.1, 2.3, 4, 5.6]}".getBytes());
// mock the payload getting read too early
byteBuf.readerIndex(byteBuf.capacity()); // force set reader index to the end of the ByteBuf
String encodedString = RemotePayloadProcessor.encodeBinaryToString(byteBuf);
assertFalse(encodedString.isEmpty());
}

@Test
void testByteBufReaderIndexUntouched() {
ByteBuf byteBuf = Unpooled.wrappedBuffer("{[0, 0.1, 2.3, 4, 5.6]}".getBytes());
String encodedString = RemotePayloadProcessor.encodeBinaryToString(byteBuf);
assertFalse(encodedString.isEmpty());
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a new line at the end of file

Loading