ARTEMIS-1609 fix JMS destination s11n compatibility

This commit is contained in:
Justin Bertram 2018-01-16 09:15:00 -06:00 committed by Clebert Suconic
parent 60055d7a08
commit 1aa7b5c038
4 changed files with 61 additions and 16 deletions

View File

@ -241,6 +241,18 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se
*/ */
private SimpleString simpleAddress; 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 temporary;
private final boolean queue; private final boolean queue;
@ -254,15 +266,7 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se
protected ActiveMQDestination(final String address, protected ActiveMQDestination(final String address,
final TYPE type, final TYPE type,
final ActiveMQSession session) { final ActiveMQSession session) {
this.simpleAddress = SimpleString.toSimpleString(address); this(SimpleString.toSimpleString(address), type, session);
this.thetype = type;
this.session = session;
this.temporary = TYPE.isTemporary(type);
this.queue = TYPE.isQueue(type);
} }
protected ActiveMQDestination(final SimpleString address, protected ActiveMQDestination(final SimpleString address,
@ -279,6 +283,26 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se
this.queue = TYPE.isQueue(type); 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) { public void setAddress(String address) {
setSimpleAddress(SimpleString.toSimpleString(address)); setSimpleAddress(SimpleString.toSimpleString(address));
} }
@ -287,6 +311,7 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se
if (address == null) { if (address == null) {
throw new IllegalArgumentException("address cannot be null"); throw new IllegalArgumentException("address cannot be null");
} }
this.address = address.toString();
this.simpleAddress = address; this.simpleAddress = address;
} }
@ -319,7 +344,7 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se
} }
public String getName() { public String getName() {
return simpleAddress.toString(); return name != null ? name : getAddress();
} }
public boolean isTemporary() { public boolean isTemporary() {

View File

@ -31,6 +31,7 @@ import org.apache.activemq.artemis.jms.client.*
file = arg[0] file = arg[0]
method = arg[1] method = arg[1]
version = arg[2]
System.out.println("File::" + file); System.out.println("File::" + file);
@ -49,6 +50,11 @@ if (method.equals("write")) {
topic = new ActiveMQTopic("topic") topic = new ActiveMQTopic("topic")
temporary = ActiveMQDestination.createTemporaryQueue("whatever") temporary = ActiveMQDestination.createTemporaryQueue("whatever")
temporaryTopic = ActiveMQDestination.createTemporaryTopic("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) Marshaller marshaller = factory.createMarshaller(configuration)
FileOutputStream fileOutputStream = new FileOutputStream(file) FileOutputStream fileOutputStream = new FileOutputStream(file)
@ -58,6 +64,7 @@ if (method.equals("write")) {
marshaller.writeObject(topic) marshaller.writeObject(topic)
marshaller.writeObject(temporary) marshaller.writeObject(temporary)
marshaller.writeObject(temporaryTopic) marshaller.writeObject(temporaryTopic)
marshaller.writeObject(destination)
marshaller.finish() marshaller.finish()
fileOutputStream.close(); fileOutputStream.close();
} else { } else {
@ -69,10 +76,13 @@ if (method.equals("write")) {
topic = unmarshaller.readObject() topic = unmarshaller.readObject()
temporary = unmarshaller.readObject() temporary = unmarshaller.readObject()
temporaryTopic = unmarshaller.readObject() temporaryTopic = unmarshaller.readObject()
destination = unmarshaller.readObject()
} }
GroovyRun.assertTrue(!cf.getServerLocator().isBlockOnDurableSend()); 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(); Connection connection = cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

View File

@ -24,18 +24,25 @@ import org.apache.activemq.artemis.jms.client.*
file = arg[0] file = arg[0]
method = arg[1] method = arg[1]
System.out.println("File::" + file); version = arg[2]
System.out.println("File::" + file)
if (method.equals("write")) { if (method.equals("write")) {
cf = new ActiveMQConnectionFactory("tcp://localhost:61616?confirmationWindowSize=1048576&blockOnDurableSend=false"); cf = new ActiveMQConnectionFactory("tcp://localhost:61616?confirmationWindowSize=1048576&blockOnDurableSend=false");
queue = new ActiveMQQueue("queue"); queue = new ActiveMQQueue("queue");
topic = new ActiveMQTopic("topic") 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 objectOutputStream = new ObjectOutputStream(new FileOutputStream(file));
objectOutputStream.writeObject(cf); objectOutputStream.writeObject(cf);
objectOutputStream.writeObject(queue) objectOutputStream.writeObject(queue)
objectOutputStream.writeObject(topic) objectOutputStream.writeObject(topic)
objectOutputStream.writeObject(destination)
objectOutputStream.close(); objectOutputStream.close();
} else { } else {
ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(file)) ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(file))
@ -43,11 +50,14 @@ if (method.equals("write")) {
cf = inputStream.readObject(); cf = inputStream.readObject();
queue = inputStream.readObject() queue = inputStream.readObject()
topic = inputStream.readObject() topic = inputStream.readObject()
destination = inputStream.readObject()
inputStream.close(); inputStream.close();
} }
GroovyRun.assertTrue(!cf.getServerLocator().isBlockOnDurableSend()); 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(); Connection connection = cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

View File

@ -91,15 +91,15 @@ public class SerializationTest extends VersionedBaseTest {
@Test @Test
public void testSerializeFactory() throws Throwable { public void testSerializeFactory() throws Throwable {
File file = serverFolder.newFile("objects.ser"); File file = serverFolder.newFile("objects.ser");
callScript(senderClassloader, "serial/serial.groovy", file.getAbsolutePath(), "write"); callScript(senderClassloader, "serial/serial.groovy", file.getAbsolutePath(), "write", sender);
callScript(receiverClassloader, "serial/serial.groovy", file.getAbsolutePath(), "read"); callScript(receiverClassloader, "serial/serial.groovy", file.getAbsolutePath(), "read", receiver);
} }
@Test @Test
public void testJBMSerializeFactory() throws Throwable { public void testJBMSerializeFactory() throws Throwable {
File file = serverFolder.newFile("objectsjbm.ser"); File file = serverFolder.newFile("objectsjbm.ser");
callScript(senderClassloader, "serial/jbmserial.groovy", file.getAbsolutePath(), "write"); callScript(senderClassloader, "serial/jbmserial.groovy", file.getAbsolutePath(), "write", sender);
callScript(receiverClassloader, "serial/jbmserial.groovy", file.getAbsolutePath(), "read"); callScript(receiverClassloader, "serial/jbmserial.groovy", file.getAbsolutePath(), "read", receiver);
} }
} }