mirror of
https://github.com/apache/activemq-artemis.git
synced 2025-02-28 06:19:21 +00:00
ARTEMIS-2500 CoreMessage doesn't make a ful copy of its props on moveHeadersAndProperties
When CoreMessage is doing copyHeadersAndProperties() it doesn't make a full copy of its properties (a TypedProperties object). It will cause problem when multiple threads/parties are modifying the properties of the copied messages from the same message. This will be particular bad if the message is a large message where moveHeadersAndProperties is being used.
This commit is contained in:
parent
91f4d0a633
commit
a2504288c6
@ -461,7 +461,7 @@ public class CoreMessage extends RefCountMessage implements ICoreMessage {
|
||||
priority = msg.getPriority();
|
||||
|
||||
if (msg instanceof CoreMessage) {
|
||||
properties = ((CoreMessage) msg).getProperties();
|
||||
properties = new TypedProperties(((CoreMessage) msg).getProperties());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,8 @@ import org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSen
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQServer;
|
||||
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
|
||||
import org.apache.activemq.artemis.utils.RandomUtil;
|
||||
import org.apache.activemq.artemis.utils.UUID;
|
||||
import org.apache.activemq.artemis.utils.UUIDGenerator;
|
||||
import org.apache.activemq.artemis.utils.Wait;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@ -240,6 +242,65 @@ public class MessageImplTest extends ActiveMQTestBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageCopyHeadersAndProperties() {
|
||||
CoreMessage msg1 = new CoreMessage(123, 18);
|
||||
SimpleString address = new SimpleString("address");
|
||||
msg1.setAddress(address);
|
||||
UUID uid = UUIDGenerator.getInstance().generateUUID();
|
||||
msg1.setUserID(uid);
|
||||
byte type = 3;
|
||||
msg1.setType(type);
|
||||
boolean durable = true;
|
||||
msg1.setDurable(durable);
|
||||
long expiration = System.currentTimeMillis();
|
||||
msg1.setExpiration(expiration);
|
||||
long timestamp = System.currentTimeMillis();
|
||||
msg1.setTimestamp(timestamp);
|
||||
byte priority = 9;
|
||||
msg1.setPriority(priority);
|
||||
|
||||
String routeTo = "_HQ_ROUTE_TOsomething";
|
||||
String value = "Byte array substitute";
|
||||
msg1.putStringProperty(routeTo, value);
|
||||
|
||||
CoreMessage msg2 = new CoreMessage(456, 18);
|
||||
|
||||
msg2.copyHeadersAndProperties(msg1);
|
||||
|
||||
assertEquals(msg1.getAddress(), msg2.getAddress());
|
||||
assertEquals(msg1.getUserID(), msg2.getUserID());
|
||||
assertEquals(msg1.getType(), msg2.getType());
|
||||
assertEquals(msg1.isDurable(), msg2.isDurable());
|
||||
assertEquals(msg1.getExpiration(), msg2.getExpiration());
|
||||
assertEquals(msg1.getTimestamp(), msg2.getTimestamp());
|
||||
assertEquals(msg1.getPriority(), msg2.getPriority());
|
||||
|
||||
assertEquals(value, msg2.getStringProperty(routeTo));
|
||||
|
||||
//now change the property on msg2 shouldn't affect msg1
|
||||
msg2.setAddress(address.concat("new"));
|
||||
msg2.setUserID(UUIDGenerator.getInstance().generateUUID());
|
||||
msg2.setType(--type);
|
||||
msg2.setDurable(!durable);
|
||||
msg2.setExpiration(expiration + 1000);
|
||||
msg2.setTimestamp(timestamp + 1000);
|
||||
msg2.setPriority(--priority);
|
||||
|
||||
msg2.putStringProperty(routeTo, value + "new");
|
||||
|
||||
assertNotEquals(msg1.getAddress(), msg2.getAddress());
|
||||
assertNotEquals(msg1.getUserID(), msg2.getUserID());
|
||||
assertNotEquals(msg1.getType(), msg2.getType());
|
||||
assertNotEquals(msg1.isDurable(), msg2.isDurable());
|
||||
assertNotEquals(msg1.getExpiration(), msg2.getExpiration());
|
||||
assertNotEquals(msg1.getTimestamp(), msg2.getTimestamp());
|
||||
assertNotEquals(msg1.getPriority(), msg2.getPriority());
|
||||
|
||||
assertNotEquals(msg1.getStringProperty(routeTo), msg2.getStringProperty(routeTo));
|
||||
|
||||
}
|
||||
|
||||
private void internalMessageCopy() throws Exception {
|
||||
final long RUNS = 2;
|
||||
final CoreMessage msg = new CoreMessage(123, 18);
|
||||
|
Loading…
x
Reference in New Issue
Block a user