Skip to content

Commit

Permalink
Bugfix/chunking cuts 2 bytes per chunk (#187)
Browse files Browse the repository at this point in the history
* Fix wrong boundaries while chunking.
Fix test case and add valid recipient for integration testing.
Remove unused methods.
Fix test case.

* Format.
  • Loading branch information
saschadoemer committed Apr 13, 2022
1 parent 985867c commit 786f08e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ class PayloadParameters : AbstractParameterBase(), ParameterValidation {
return value!!.toStringUtf8().length > MAX_LENGTH_FOR_RAW_MESSAGE_CONTENT
}

/**
* The maximum length for messages / the payload.
*/
fun maxLengthForMessages(): Int {
return MAX_LENGTH_FOR_RAW_MESSAGE_CONTENT
}

fun copyFrom(payload: PayloadParameters) {
applicationMessageId = payload.applicationMessageId
teamsetContextId = payload.teamsetContextId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public List<MessageParameterTuple> chunkAndBase64EncodeEachChunk(
header.setApplicationMessageSeqNo(sequenceNumberForChunk);
Chunk.ChunkComponent.Builder chunkInfo = Chunk.ChunkComponent.newBuilder();
chunkInfo.setContextId(chunkContextId);
chunkInfo.setCurrent(chunkNr.get());
chunkInfo.setCurrent(chunkNr.getAndIncrement());
chunkInfo.setTotal(messageChunks.size());
chunkInfo.setTotalSize(wholeMessage.length);
header.setChunkInfo(chunkInfo.build());
Expand All @@ -139,8 +139,6 @@ public List<MessageParameterTuple> chunkAndBase64EncodeEachChunk(
payload.setValue(ByteString.copyFromUtf8(Base64.getEncoder().encodeToString(chunk)));

tuples.add(new MessageParameterTuple(header, payload));

chunkNr.getAndIncrement();
});
return tuples;
} else {
Expand Down Expand Up @@ -182,7 +180,7 @@ private List<byte[]> splitIntoChunks(byte[] wholeMessage) {
chunks.add(chunk);
remainingBytes =
Arrays.copyOfRange(
remainingBytes, MAX_LENGTH_FOR_RAW_MESSAGE_CONTENT + 1, remainingBytes.length - 1);
remainingBytes, MAX_LENGTH_FOR_RAW_MESSAGE_CONTENT, remainingBytes.length);
} while (remainingBytes.length > MAX_LENGTH_FOR_RAW_MESSAGE_CONTENT);
if (remainingBytes.length > 0) {
chunks.add(remainingBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class EncodeMessageServiceImplTest {
class AEncodeEncodeMessageServiceImplTest {

@Test
void givenEmptyMessageWhenChunkingThenTheImplementationShouldReturnTheRightNumberOfChunks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SendChunkedMessageTest extends AbstractIntegrationTest {
SequenceNumberService.generateSequenceNumberForEndpoint(onboardingResponse));
messageHeaderParameters.setMode(Request.RequestEnvelope.Mode.DIRECT);
messageHeaderParameters.setRecipients(
Collections.singletonList("37cd61d1-76eb-4145-a735-c938d05a32d8"));
Collections.singletonList("797b7f4b-79ec-4247-9fba-e726a55c4c7f"));

PayloadParameters payloadParameters = new PayloadParameters();
payloadParameters.setValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,12 @@ private void actionsForSender(ByteString messageContent, int expectedNrOfChunks)
* @return -
*/
@SuppressWarnings("unused")
private static @NotNull Stream<Arguments> givenRealMessageContentWhenSendingMessagesTheContentShouldMatchAfterReceivingAndMergingIt() throws Throwable {
private static @NotNull Stream<Arguments>
givenRealMessageContentWhenSendingMessagesTheContentShouldMatchAfterReceivingAndMergingIt()
throws Throwable {
return Stream.of(
Arguments.of(
ByteString.copyFrom(
ContentReader.readRawData(ContentReader.Identifier.BIG_TASK_DATA)),
ByteString.copyFrom(ContentReader.readRawData(ContentReader.Identifier.BIG_TASK_DATA)),
3));
}

Expand Down

0 comments on commit 786f08e

Please sign in to comment.