|
27 | 27 |
|
28 | 28 | import java.nio.ByteBuffer; |
29 | 29 | import java.nio.charset.StandardCharsets; |
| 30 | +import java.util.Arrays; |
30 | 31 |
|
31 | 32 | import static org.junit.Assert.assertArrayEquals; |
32 | 33 | import static org.junit.Assert.assertEquals; |
@@ -61,6 +62,44 @@ public void testReadFramesResetMessageSize() throws TTransportException { |
61 | 62 | assertArrayEquals(secondFrame, actualSecondFrame); |
62 | 63 | } |
63 | 64 |
|
| 65 | + @Test |
| 66 | + public void testReadCompressedFramesResetMessageSize() throws TTransportException { |
| 67 | + byte[] firstFrame = {1, 2}; |
| 68 | + byte[] secondFrame = {3, 4, 5, 6, 7, 8}; |
| 69 | + TMemoryBuffer wire = new TMemoryBuffer(128); |
| 70 | + TSnappyElasticFramedTransport output = |
| 71 | + new TSnappyElasticFramedTransport(wire, 4, 128, false); |
| 72 | + output.write(firstFrame); |
| 73 | + output.flush(); |
| 74 | + output.write(secondFrame); |
| 75 | + output.flush(); |
| 76 | + |
| 77 | + byte[] framedData = Arrays.copyOf(wire.getArray(), wire.length()); |
| 78 | + ByteBuffer frameSizes = ByteBuffer.wrap(framedData); |
| 79 | + int firstCompressedSize = frameSizes.getInt(); |
| 80 | + frameSizes.position(Integer.BYTES + firstCompressedSize); |
| 81 | + int secondCompressedSize = frameSizes.getInt(); |
| 82 | + int maxMessageSize = Integer.BYTES + Math.max(firstCompressedSize, secondCompressedSize); |
| 83 | + TConfiguration configuration = |
| 84 | + TConfiguration.custom() |
| 85 | + .setMaxMessageSize(maxMessageSize) |
| 86 | + .setMaxFrameSize(maxMessageSize) |
| 87 | + .build(); |
| 88 | + TMemoryBuffer underlying = new TMemoryBuffer(configuration, maxMessageSize); |
| 89 | + underlying.write(framedData); |
| 90 | + TSnappyElasticFramedTransport input = |
| 91 | + new TSnappyElasticFramedTransport( |
| 92 | + underlying, 4, configuration.getMaxFrameSize(), false); |
| 93 | + |
| 94 | + byte[] actualFirstFrame = new byte[firstFrame.length]; |
| 95 | + input.readAll(actualFirstFrame, 0, actualFirstFrame.length); |
| 96 | + assertArrayEquals(firstFrame, actualFirstFrame); |
| 97 | + |
| 98 | + byte[] actualSecondFrame = new byte[secondFrame.length]; |
| 99 | + input.readAll(actualSecondFrame, 0, actualSecondFrame.length); |
| 100 | + assertArrayEquals(secondFrame, actualSecondFrame); |
| 101 | + } |
| 102 | + |
64 | 103 | @Test |
65 | 104 | public void testSingularSize() { |
66 | 105 |
|
|
0 commit comments