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;
/**
* 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() {

View File

@ -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);

View File

@ -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);

View File

@ -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);
}
}