From 1aa7b5c038c3791f5dd0e7fdc859d74a63b8d76d Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Tue, 16 Jan 2018 09:15:00 -0600 Subject: [PATCH] ARTEMIS-1609 fix JMS destination s11n compatibility --- .../jms/client/ActiveMQDestination.java | 45 ++++++++++++++----- .../main/resources/serial/jbmserial.groovy | 10 +++++ .../src/main/resources/serial/serial.groovy | 14 +++++- .../compatibility/SerializationTest.java | 8 ++-- 4 files changed, 61 insertions(+), 16 deletions(-) diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java index 7750564f26..8c7a5a03be 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java @@ -241,6 +241,18 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se */ private SimpleString simpleAddress; + /** + * Needed for serialization backwards compatibility. + */ + @Deprecated + private String address; + + /** + * The "JMS" name of the destination. Needed for serialization backwards compatibility. + */ + @Deprecated + private String name; + private final boolean temporary; private final boolean queue; @@ -254,15 +266,7 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se protected ActiveMQDestination(final String address, final TYPE type, final ActiveMQSession session) { - this.simpleAddress = SimpleString.toSimpleString(address); - - this.thetype = type; - - this.session = session; - - this.temporary = TYPE.isTemporary(type); - - this.queue = TYPE.isQueue(type); + this(SimpleString.toSimpleString(address), type, session); } protected ActiveMQDestination(final SimpleString address, @@ -279,6 +283,26 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se this.queue = TYPE.isQueue(type); } + @Deprecated + protected ActiveMQDestination(final String address, + final String name, + final TYPE type, + final ActiveMQSession session) { + this(SimpleString.toSimpleString(address), name, type, session); + } + + @Deprecated + protected ActiveMQDestination(final SimpleString address, + final String name, + final TYPE type, + final ActiveMQSession session) { + this(address, type, session); + + this.name = name; + + this.address = simpleAddress != null ? simpleAddress.toString() : null; + } + public void setAddress(String address) { setSimpleAddress(SimpleString.toSimpleString(address)); } @@ -287,6 +311,7 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se if (address == null) { throw new IllegalArgumentException("address cannot be null"); } + this.address = address.toString(); this.simpleAddress = address; } @@ -319,7 +344,7 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se } public String getName() { - return simpleAddress.toString(); + return name != null ? name : getAddress(); } public boolean isTemporary() { diff --git a/tests/compatibility-tests/src/main/resources/serial/jbmserial.groovy b/tests/compatibility-tests/src/main/resources/serial/jbmserial.groovy index 159cce9b7b..b80dddb469 100644 --- a/tests/compatibility-tests/src/main/resources/serial/jbmserial.groovy +++ b/tests/compatibility-tests/src/main/resources/serial/jbmserial.groovy @@ -31,6 +31,7 @@ import org.apache.activemq.artemis.jms.client.* file = arg[0] method = arg[1] +version = arg[2] System.out.println("File::" + file); @@ -49,6 +50,11 @@ if (method.equals("write")) { topic = new ActiveMQTopic("topic") temporary = ActiveMQDestination.createTemporaryQueue("whatever") temporaryTopic = ActiveMQDestination.createTemporaryTopic("whatever") + if (version.equals("ARTEMIS-SNAPSHOT")) { + destination = new ActiveMQDestination("address", "name", ActiveMQDestination.TYPE.DESTINATION, null) + } else if (version.equals("ARTEMIS-155")) { + destination = new ActiveMQDestination("address", "name", false, true, null) + } Marshaller marshaller = factory.createMarshaller(configuration) FileOutputStream fileOutputStream = new FileOutputStream(file) @@ -58,6 +64,7 @@ if (method.equals("write")) { marshaller.writeObject(topic) marshaller.writeObject(temporary) marshaller.writeObject(temporaryTopic) + marshaller.writeObject(destination) marshaller.finish() fileOutputStream.close(); } else { @@ -69,10 +76,13 @@ if (method.equals("write")) { topic = unmarshaller.readObject() temporary = unmarshaller.readObject() temporaryTopic = unmarshaller.readObject() + destination = unmarshaller.readObject() } GroovyRun.assertTrue(!cf.getServerLocator().isBlockOnDurableSend()); GroovyRun.assertEquals(1048576, cf.getServerLocator().getConfirmationWindowSize()); +GroovyRun.assertEquals(destination.getName(), "name") +GroovyRun.assertEquals(destination.getAddress(), "address") Connection connection = cf.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); diff --git a/tests/compatibility-tests/src/main/resources/serial/serial.groovy b/tests/compatibility-tests/src/main/resources/serial/serial.groovy index 0756fb3aae..f5a3e5f3bc 100644 --- a/tests/compatibility-tests/src/main/resources/serial/serial.groovy +++ b/tests/compatibility-tests/src/main/resources/serial/serial.groovy @@ -24,18 +24,25 @@ import org.apache.activemq.artemis.jms.client.* file = arg[0] method = arg[1] -System.out.println("File::" + file); +version = arg[2] +System.out.println("File::" + file) if (method.equals("write")) { cf = new ActiveMQConnectionFactory("tcp://localhost:61616?confirmationWindowSize=1048576&blockOnDurableSend=false"); queue = new ActiveMQQueue("queue"); topic = new ActiveMQTopic("topic") + if (version.equals("ARTEMIS-SNAPSHOT")) { + destination = new ActiveMQDestination("address", "name", ActiveMQDestination.TYPE.DESTINATION, null) + } else if (version.equals("ARTEMIS-155")) { + destination = new ActiveMQDestination("address", "name", false, true, null) + } ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(file)); objectOutputStream.writeObject(cf); objectOutputStream.writeObject(queue) objectOutputStream.writeObject(topic) + objectOutputStream.writeObject(destination) objectOutputStream.close(); } else { ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(file)) @@ -43,11 +50,14 @@ if (method.equals("write")) { cf = inputStream.readObject(); queue = inputStream.readObject() topic = inputStream.readObject() + destination = inputStream.readObject() inputStream.close(); } GroovyRun.assertTrue(!cf.getServerLocator().isBlockOnDurableSend()); -GroovyRun.assertEquals(1048576, cf.getServerLocator().getConfirmationWindowSize()); +GroovyRun.assertEquals(1048576, cf.getServerLocator().getConfirmationWindowSize()) +GroovyRun.assertEquals(destination.getName(), "name") +GroovyRun.assertEquals(destination.getAddress(), "address") Connection connection = cf.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); diff --git a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/SerializationTest.java b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/SerializationTest.java index 3358bbc92d..2c017f27f5 100644 --- a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/SerializationTest.java +++ b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/SerializationTest.java @@ -91,15 +91,15 @@ public class SerializationTest extends VersionedBaseTest { @Test public void testSerializeFactory() throws Throwable { File file = serverFolder.newFile("objects.ser"); - callScript(senderClassloader, "serial/serial.groovy", file.getAbsolutePath(), "write"); - callScript(receiverClassloader, "serial/serial.groovy", file.getAbsolutePath(), "read"); + callScript(senderClassloader, "serial/serial.groovy", file.getAbsolutePath(), "write", sender); + callScript(receiverClassloader, "serial/serial.groovy", file.getAbsolutePath(), "read", receiver); } @Test public void testJBMSerializeFactory() throws Throwable { File file = serverFolder.newFile("objectsjbm.ser"); - callScript(senderClassloader, "serial/jbmserial.groovy", file.getAbsolutePath(), "write"); - callScript(receiverClassloader, "serial/jbmserial.groovy", file.getAbsolutePath(), "read"); + callScript(senderClassloader, "serial/jbmserial.groovy", file.getAbsolutePath(), "write", sender); + callScript(receiverClassloader, "serial/jbmserial.groovy", file.getAbsolutePath(), "read", receiver); } }