From 12ef662b919b373ee8e4ec8e35fea6a57b00bfe1 Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Tue, 9 Jan 2018 20:27:17 -0500 Subject: [PATCH] ARTEMIS-1595 Fixing serialization issues between Artemis 1.5 and master --- .../jms/client/ActiveMQConnectionFactory.java | 4 +- .../jms/client/ActiveMQDestination.java | 39 ++++++-- .../maven/ArtemisDependencyScanPlugin.java | 2 +- tests/compatibility-tests/pom.xml | 6 ++ .../tests/compatibility/GroovyRun.java | 7 ++ .../main/resources/serial/jbmserial.groovy | 99 +++++++++++++++++++ .../compatibility/SerializationTest.java | 37 ++++++- 7 files changed, 181 insertions(+), 13 deletions(-) create mode 100644 tests/compatibility-tests/src/main/resources/serial/jbmserial.groovy diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java index 31f39f282f..aad68a90ab 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java @@ -195,7 +195,9 @@ public class ActiveMQConnectionFactory extends JNDIStorable implements Connectio serverLocator = locatorParser.newObject(uri, null); parser.populateObject(uri, this); } catch (Exception e) { - throw new InvalidObjectException(e.getMessage()); + InvalidObjectException ex = new InvalidObjectException(e.getMessage()); + ex.initCause(e); + throw ex; } } 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 d374265a27..626dd4d1a5 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 @@ -231,7 +231,11 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se */ private SimpleString simpleAddress; - private final TYPE type; + private final boolean temporary; + + private final boolean queue; + + private transient TYPE thetype; private final transient ActiveMQSession session; @@ -242,9 +246,13 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se final ActiveMQSession session) { this.simpleAddress = SimpleString.toSimpleString(address); - this.type = type; + this.thetype = type; this.session = session; + + this.temporary = TYPE.isTemporary(type); + + this.queue = TYPE.isQueue(type); } protected ActiveMQDestination(final SimpleString address, @@ -252,9 +260,13 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se final ActiveMQSession session) { this.simpleAddress = address; - this.type = type; + this.thetype = type; this.session = session; + + this.temporary = TYPE.isTemporary(type); + + this.queue = TYPE.isQueue(type); } public void setAddress(String address) { @@ -283,7 +295,7 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se } public boolean isQueue() { - return TYPE.isQueue(type); + return queue; } // Public -------------------------------------------------------- @@ -301,11 +313,26 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se } public boolean isTemporary() { - return TYPE.isTemporary(type); + return temporary; } public TYPE getType() { - return type; + if (thetype == null) { + if (temporary) { + if (isQueue()) { + thetype = TYPE.TEMP_QUEUE; + } else { + thetype = TYPE.TEMP_TOPIC; + } + } else { + if (isQueue()) { + thetype = TYPE.QUEUE; + } else { + thetype = TYPE.TOPIC; + } + } + } + return thetype; } @Override diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisDependencyScanPlugin.java b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisDependencyScanPlugin.java index 2c653fae97..9091535ca7 100644 --- a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisDependencyScanPlugin.java +++ b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisDependencyScanPlugin.java @@ -138,7 +138,7 @@ public class ArtemisDependencyScanPlugin extends ArtemisAbstractPlugin { private void setVariable(String classPathGenerated) { if (variableName != null) { project.getProperties().setProperty(variableName, classPathGenerated); - getLog().info("dependency-scan setting: " + variableName + "=" + classPathGenerated); + getLog().info("dependency-scan setting: -D" + variableName + "=\"" + classPathGenerated + "\""); } } diff --git a/tests/compatibility-tests/pom.xml b/tests/compatibility-tests/pom.xml index 7d3ed3ca7d..8c1fc523ca 100644 --- a/tests/compatibility-tests/pom.xml +++ b/tests/compatibility-tests/pom.xml @@ -275,6 +275,11 @@ slf4j-api 1.7.5 + + org.jboss.marshalling + jboss-marshalling-river + 2.0.2.Final + @@ -383,6 +388,7 @@ org.apache.activemq:artemis-amqp-protocol:1.5.5 org.apache.activemq:artemis-hornetq-protocol:1.5.5 org.codehaus.groovy:groovy-all:${groovy.version} + org.jboss.marshalling:jboss-marshalling-river:2.0.2.Final org.apache.activemq.tests:compatibility-tests:${project.version} diff --git a/tests/compatibility-tests/src/main/java/org/apache/activemq/artemis/tests/compatibility/GroovyRun.java b/tests/compatibility-tests/src/main/java/org/apache/activemq/artemis/tests/compatibility/GroovyRun.java index 6fd38f7302..c66a518ef3 100644 --- a/tests/compatibility-tests/src/main/java/org/apache/activemq/artemis/tests/compatibility/GroovyRun.java +++ b/tests/compatibility-tests/src/main/java/org/apache/activemq/artemis/tests/compatibility/GroovyRun.java @@ -98,6 +98,13 @@ public class GroovyRun { } } + + public static void assertFalse(boolean value) { + if (value) { + throw new RuntimeException("Expected false"); + } + } + public static void assertEquals(Object value1, Object value2) { if (!value1.equals(value2)) { throw new RuntimeException(value1 + "!=" + value2); diff --git a/tests/compatibility-tests/src/main/resources/serial/jbmserial.groovy b/tests/compatibility-tests/src/main/resources/serial/jbmserial.groovy new file mode 100644 index 0000000000..159cce9b7b --- /dev/null +++ b/tests/compatibility-tests/src/main/resources/serial/jbmserial.groovy @@ -0,0 +1,99 @@ +package clients +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Create a client connection factory + +import org.apache.activemq.artemis.tests.compatibility.GroovyRun +import org.jboss.marshalling.Marshaller +import org.jboss.marshalling.MarshallerFactory +import org.jboss.marshalling.Marshalling +import org.jboss.marshalling.MarshallingConfiguration +import org.jboss.marshalling.Unmarshaller + +import javax.jms.*; +import org.apache.activemq.artemis.jms.client.* + + +file = arg[0] +method = arg[1] +System.out.println("File::" + file); + + + +// Get the factory for the "river" marshalling protocol +final MarshallerFactory factory = Marshalling.getProvidedMarshallerFactory("river"); + +// Create a configuration +final MarshallingConfiguration configuration = new MarshallingConfiguration(); +// Use version 3 +configuration.setVersion(3); + +if (method.equals("write")) { + cf = new ActiveMQConnectionFactory("tcp://localhost:61616?confirmationWindowSize=1048576&blockOnDurableSend=false"); + queue = new ActiveMQQueue("queue"); + topic = new ActiveMQTopic("topic") + temporary = ActiveMQDestination.createTemporaryQueue("whatever") + temporaryTopic = ActiveMQDestination.createTemporaryTopic("whatever") + + Marshaller marshaller = factory.createMarshaller(configuration) + FileOutputStream fileOutputStream = new FileOutputStream(file) + marshaller.start(Marshalling.createByteOutput(fileOutputStream)); + marshaller.writeObject(cf); + marshaller.writeObject(queue) + marshaller.writeObject(topic) + marshaller.writeObject(temporary) + marshaller.writeObject(temporaryTopic) + marshaller.finish() + fileOutputStream.close(); +} else { + Unmarshaller unmarshaller = factory.createUnmarshaller(configuration) + FileInputStream inputfile = new FileInputStream(file) + unmarshaller.start(Marshalling.createByteInput(inputfile)) + cf = unmarshaller.readObject(); + queue = unmarshaller.readObject() + topic = unmarshaller.readObject() + temporary = unmarshaller.readObject() + temporaryTopic = unmarshaller.readObject() +} + +GroovyRun.assertTrue(!cf.getServerLocator().isBlockOnDurableSend()); +GroovyRun.assertEquals(1048576, cf.getServerLocator().getConfirmationWindowSize()); + +Connection connection = cf.createConnection(); +Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); +ActiveMQDestination queueDest = (ActiveMQDestination)queue; +GroovyRun.assertTrue(queueDest.isQueue()) +GroovyRun.assertFalse(queueDest.isTemporary()) + +ActiveMQDestination topicDest = (ActiveMQDestination)topic +GroovyRun.assertFalse(topicDest.isQueue()) +GroovyRun.assertFalse(queueDest.isTemporary()) + +ActiveMQDestination temporaryDest = (ActiveMQDestination)temporary +GroovyRun.assertTrue(temporaryDest.isQueue()) +GroovyRun.assertTrue(temporaryDest.isTemporary()) + +temporaryDest = (ActiveMQDestination)temporaryTopic +GroovyRun.assertFalse(temporaryDest.isQueue()) +GroovyRun.assertTrue(temporaryDest.isTemporary()) + +MessageConsumer consumer = session.createConsumer(queue); +MessageProducer topicProducer = session.createProducer(topic) +connection.close(); + + 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 6108cecc96..93107820ae 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 @@ -22,11 +22,15 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.apache.activemq.artemis.utils.FileUtil; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import static org.apache.activemq.artemis.tests.compatibility.GroovyRun.ONE_FIVE; +import static org.apache.activemq.artemis.tests.compatibility.GroovyRun.ONE_FOUR; import static org.apache.activemq.artemis.tests.compatibility.GroovyRun.SNAPSHOT; /** @@ -43,7 +47,7 @@ import static org.apache.activemq.artemis.tests.compatibility.GroovyRun.SNAPSHOT * Run->Edit Configuration->Add ArtemisMeshTest and add your properties. */ @RunWith(Parameterized.class) -public class SerializationTest extends ServerBaseTest { +public class SerializationTest extends VersionedBaseTest { // this will ensure that all tests in this class are run twice, // once with "true" passed to the class' constructor and once with "false" @@ -60,7 +64,7 @@ public class SerializationTest extends ServerBaseTest { // combinations.add(new Object[]{SNAPSHOT, ONE_FIVE, ONE_FIVE}); // combinations.add(new Object[]{ONE_FIVE, ONE_FIVE, ONE_FIVE}); - combinations.addAll(combinatory(new Object[]{SNAPSHOT}, new Object[]{ONE_FIVE, SNAPSHOT}, new Object[]{ONE_FIVE, SNAPSHOT})); + combinations.addAll(combinatory(new Object[]{null}, new Object[]{ONE_FIVE, SNAPSHOT}, new Object[]{ONE_FIVE, SNAPSHOT})); return combinations; } @@ -68,12 +72,35 @@ public class SerializationTest extends ServerBaseTest { super(server, sender, receiver); } + @Before + public void beforeTest() throws Throwable { + FileUtil.deleteDirectory(serverFolder.getRoot()); + serverFolder.getRoot().mkdirs(); + setVariable(senderClassloader, "persistent", false); + startServer(serverFolder.getRoot(), senderClassloader, "1"); + } + + @After + public void afterTest() { + try { + stopServer(senderClassloader); + } catch (Throwable ignored) { + ignored.printStackTrace(); + } + } + @Test public void testSerializeFactory() throws Throwable { File file = serverFolder.newFile("objects.ser"); - file.mkdirs(); - callScript(senderClassloader, "serial/serial.groovy", file.getAbsolutePath(), "write"); - callScript(receiverClassloader, "serial/serial.groovy", file.getAbsolutePath(), "read"); + callScript(senderClassloader, "serial/serial.groovy", file.getAbsolutePath(), "write"); + callScript(receiverClassloader, "serial/serial.groovy", file.getAbsolutePath(), "read"); + } + + @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"); } }