Skip to content

Commit

Permalink
ARTEMIS-4309 Read all bytes of compressed objmsg
Browse files Browse the repository at this point in the history
Continually read from the compressed byte[] into
the decompressed object

Add test to validate large (>1024 bytes) compressed data can be
deserialized properly
  • Loading branch information
prb17 authored and clebertsuconic committed Jun 13, 2023
1 parent c96a074 commit 2f5463c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private static ByteSequence writeCompressedObjectType(final ByteSequence content
int n = ois.read(buf);
while (n != -1) {
decompressed.write(buf, 0, n);
n = ois.read();
n = ois.read(buf);
}
//read done
return decompressed.toByteSequence();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
public class CompressedInteropTest extends BasicOpenWireTest {

private static final String TEXT;
private static final String LARGE_TEXT;

static {
StringBuilder builder = new StringBuilder();
Expand All @@ -46,6 +47,7 @@ public class CompressedInteropTest extends BasicOpenWireTest {
builder.append("The quick red fox jumped over the lazy brown dog. ");
}
TEXT = builder.toString();
LARGE_TEXT = TEXT + TEXT + TEXT + TEXT + TEXT;
}

@Before
Expand Down Expand Up @@ -90,6 +92,9 @@ private void testCompressedMessageSendReceive(boolean useCore) throws Exception
//ObjectMessage
sendCompressedObjectMessageUsingOpenWire();
receiveObjectMessage(useCore);
//Large ObjectMessage
sendCompressedLargeObjectMessageUsingOpenWire();
receiveLargeObjectMessage(useCore);
}

private void sendCompressedStreamMessageUsingOpenWire() throws Exception {
Expand Down Expand Up @@ -164,6 +169,24 @@ private void receiveObjectMessage(boolean useCore) throws Exception {
assertEquals(TEXT, objectVal);
}

private void sendCompressedLargeObjectMessageUsingOpenWire() throws Exception {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);

final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);

ObjectMessage objectMessage = session.createObjectMessage();
objectMessage.setObject(LARGE_TEXT);

producer.send(objectMessage);
}

private void receiveLargeObjectMessage(boolean useCore) throws Exception {
ObjectMessage objectMessage = (ObjectMessage) receiveMessage(useCore);
Object objectVal = objectMessage.getObject();
assertEquals(LARGE_TEXT, objectVal);
}

private void sendCompressedMapMessageUsingOpenWire() throws Exception {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
Expand Down

0 comments on commit 2f5463c

Please sign in to comment.