From c8dc7de44506745499b830edf3ffec87ff3d0b4b Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Mon, 8 Jan 2018 15:11:52 -0500 Subject: [PATCH] ARTEMIS-1545 Fixing compatibility issues with topic Subscriptions --- .../core/impl/ActiveMQSessionContext.java | 7 +- tests/compatibility-tests/pom.xml | 4 + .../tests/compatibility/GroovyRun.java | 28 ++-- .../resources/clients/artemisClient.groovy | 20 +-- .../resources/clients/hornetqClient.groovy | 26 ++-- .../main/resources/exportimport/export.groovy | 39 ++++++ .../resources/exportimport/export1X.groovy | 38 ++++++ .../main/resources/exportimport/import.groovy | 27 ++++ .../resources/exportimport/import1X.groovy | 28 ++++ .../resources/meshTest/sendMessages.groovy | 58 ++++++--- .../sendAckTest/sendAckMessages.groovy | 20 +-- .../src/main/resources/serial/serial.groovy | 20 +-- .../resources/servers/artemisServer.groovy | 29 +++-- .../resources/servers/hornetqServer.groovy | 26 ++-- .../tests/compatibility/ExportImportTest.java | 121 ++++++++++++++++++ .../artemis/tests/compatibility/MeshTest.java | 58 +++++++-- .../tests/compatibility/SendAckTest.java | 26 ++-- .../compatibility/SerializationTest.java | 26 ++-- .../tests/compatibility/ServerBaseTest.java | 41 ++++++ .../compatibility/VersionedBaseTest.java | 95 +++++++------- .../tests/compatibility/package-info.java | 20 +-- 21 files changed, 579 insertions(+), 178 deletions(-) create mode 100644 tests/compatibility-tests/src/main/resources/exportimport/export.groovy create mode 100644 tests/compatibility-tests/src/main/resources/exportimport/export1X.groovy create mode 100644 tests/compatibility-tests/src/main/resources/exportimport/import.groovy create mode 100644 tests/compatibility-tests/src/main/resources/exportimport/import1X.groovy create mode 100644 tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/ExportImportTest.java create mode 100644 tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/ServerBaseTest.java diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/ActiveMQSessionContext.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/ActiveMQSessionContext.java index a9c34f7ee4..1a81259960 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/ActiveMQSessionContext.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/protocol/core/impl/ActiveMQSessionContext.java @@ -640,8 +640,11 @@ public class ActiveMQSessionContext extends SessionContext { int maxConsumers, boolean purgeOnNoConsumers, boolean autoCreated) throws ActiveMQException { - CreateQueueMessage request = new CreateQueueMessage_V2(address, queueName, routingType, filterString, durable, temp, maxConsumers, purgeOnNoConsumers, autoCreated, true); - if (!sessionChannel.getConnection().isVersionBeforeAddressChange()) { + if (sessionChannel.getConnection().isVersionBeforeAddressChange()) { + CreateQueueMessage request = new CreateQueueMessage(address, queueName, filterString, durable, temp, true); + sessionChannel.sendBlocking(request, PacketImpl.NULL_RESPONSE); + } else { + CreateQueueMessage request = new CreateQueueMessage_V2(address, queueName, routingType, filterString, durable, temp, maxConsumers, purgeOnNoConsumers, autoCreated, true); sessionChannel.sendBlocking(request, PacketImpl.NULL_RESPONSE); } } diff --git a/tests/compatibility-tests/pom.xml b/tests/compatibility-tests/pom.xml index def806e8d4..7d3ed3ca7d 100644 --- a/tests/compatibility-tests/pom.xml +++ b/tests/compatibility-tests/pom.xml @@ -311,6 +311,7 @@ org.apache.activemq:artemis-jms-server:${project.version} + org.apache.activemq:artemis-cli:${project.version} org.apache.activemq:artemis-jms-client:${project.version} org.apache.activemq:artemis-hornetq-protocol:${project.version} org.apache.activemq:artemis-amqp-protocol:${project.version} @@ -333,6 +334,7 @@ org.apache.activemq:artemis-jms-server:2.4.0 org.apache.activemq:artemis-jms-client:2.4.0 + org.apache.activemq:artemis-cli:2.4.0 org.apache.activemq:artemis-hornetq-protocol:2.4.0 org.apache.activemq:artemis-amqp-protocol:2.4.0 org.apache.activemq:artemis-hornetq-protocol:2.4.0 @@ -354,6 +356,7 @@ org.apache.activemq:artemis-jms-server:1.4.0 org.apache.activemq:artemis-jms-client:1.4.0 + org.apache.activemq:artemis-cli:1.4.0 org.apache.activemq:artemis-hornetq-protocol:1.4.0 org.apache.activemq:artemis-amqp-protocol:1.4.0 org.apache.activemq:artemis-hornetq-protocol:1.4.0 @@ -375,6 +378,7 @@ org.apache.activemq:artemis-jms-server:1.5.5 org.apache.activemq:artemis-jms-client:1.5.5 + org.apache.activemq:artemis-cli:1.5.5 org.apache.activemq:artemis-hornetq-protocol:1.5.5 org.apache.activemq:artemis-amqp-protocol:1.5.5 org.apache.activemq:artemis-hornetq-protocol:1.5.5 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 80c4756286..6fd38f7302 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 @@ -1,14 +1,18 @@ /* - * Copyright 2005-2014 Red Hat, Inc. - * Red Hat 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 + * 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. + * 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. */ package org.apache.activemq.artemis.tests.compatibility; @@ -36,7 +40,7 @@ public class GroovyRun { public static GroovyShell shell = new GroovyShell(binding); // Called with reflection - public static void doMain(String script, String... arg) throws Throwable { + public static void doTest(String script, String... arg) throws Throwable { int i = 0; for (String a : arg) { System.out.println("[" + (i++) + "]=" + a); @@ -62,11 +66,15 @@ public class GroovyRun { } URI scriptURI = scriptURL.toURI(); - binding.setVariable(argVariableName, arg); + setVariable(argVariableName, arg); shell.evaluate(scriptURI); } + public static void setVariable(String name, Object arg) { + binding.setVariable(name, arg); + } + // Called with reflection public static void execute(String script) throws Throwable { shell.evaluate(script); diff --git a/tests/compatibility-tests/src/main/resources/clients/artemisClient.groovy b/tests/compatibility-tests/src/main/resources/clients/artemisClient.groovy index e729ebb0fa..0926e0a420 100644 --- a/tests/compatibility-tests/src/main/resources/clients/artemisClient.groovy +++ b/tests/compatibility-tests/src/main/resources/clients/artemisClient.groovy @@ -1,15 +1,19 @@ package clients /* - * Copyright 2005-2014 Red Hat, Inc. - * Red Hat 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 + * 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. + * 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 diff --git a/tests/compatibility-tests/src/main/resources/clients/hornetqClient.groovy b/tests/compatibility-tests/src/main/resources/clients/hornetqClient.groovy index 63bf4e6da1..b04a01a5df 100644 --- a/tests/compatibility-tests/src/main/resources/clients/hornetqClient.groovy +++ b/tests/compatibility-tests/src/main/resources/clients/hornetqClient.groovy @@ -1,26 +1,24 @@ package clients /* - * Copyright 2005-2014 Red Hat, Inc. - * Red Hat 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 + * 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. + * 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. */ // This script is called by sendMessages.groovy -import javax.jms.ConnectionFactory; -import java.util.HashMap; -import java.util.Map; - import org.hornetq.api.core.TransportConfiguration; -import org.hornetq.api.jms.HornetQJMSConstants; -import org.hornetq.core.message.impl.MessageImpl; import org.hornetq.core.remoting.impl.netty.NettyConnectorFactory; import org.hornetq.core.remoting.impl.netty.TransportConstants; import org.hornetq.jms.client.HornetQJMSConnectionFactory; diff --git a/tests/compatibility-tests/src/main/resources/exportimport/export.groovy b/tests/compatibility-tests/src/main/resources/exportimport/export.groovy new file mode 100644 index 0000000000..0b6fb73fc6 --- /dev/null +++ b/tests/compatibility-tests/src/main/resources/exportimport/export.groovy @@ -0,0 +1,39 @@ +/* + * 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. + */ + +import org.apache.activemq.artemis.cli.commands.ActionContext +import org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataExporter + + +System.out.println("Arg::" + arg[0]); +File pagingfile = new File(arg[0] + "/sender/data/paging") +pagingfile.mkdirs() +XmlDataExporter exporter = new XmlDataExporter(); +exporter.binding = arg[0] + "/sender/data/bindings" +exporter.journal = arg[0] + "/sender/data/journal" +try { + exporter.largeMessages = arg[0] + "/sender/data/largeMessages" +} catch (Throwable e) { + exporter.largeMessges = arg[0] + "/sender/data/largeMessages" +} +exporter.paging = arg[0] + "/sender/data/paging" + + +PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(arg[0] + "/journal.export"))); +exporter.execute(new ActionContext(System.in, out, System.err)) +out.close(); +//exporter.binding diff --git a/tests/compatibility-tests/src/main/resources/exportimport/export1X.groovy b/tests/compatibility-tests/src/main/resources/exportimport/export1X.groovy new file mode 100644 index 0000000000..7667533763 --- /dev/null +++ b/tests/compatibility-tests/src/main/resources/exportimport/export1X.groovy @@ -0,0 +1,38 @@ +/* + * 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. + */ + +import org.apache.activemq.artemis.cli.commands.ActionContext +import org.apache.activemq.artemis.cli.commands.tools.XmlDataExporter + +System.out.println("Arg::" + arg[0]); +File pagingfile = new File(arg[0] + "/sender/data/paging") +pagingfile.mkdirs() +XmlDataExporter exporter = new XmlDataExporter(); +exporter.binding = arg[0] + "/sender/data/bindings" +exporter.journal = arg[0] + "/sender/data/journal" +try { + exporter.largeMessages = arg[0] + "/sender/data/largeMessages" +} catch (Throwable e) { + exporter.largeMessges = arg[0] + "/sender/data/largeMessages" +} +exporter.paging = arg[0] + "/sender/data/paging" + + +PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(arg[0] + "/journal.export"))); +exporter.execute(new ActionContext(System.in, out, System.err)) +out.close(); +//exporter.binding diff --git a/tests/compatibility-tests/src/main/resources/exportimport/import.groovy b/tests/compatibility-tests/src/main/resources/exportimport/import.groovy new file mode 100644 index 0000000000..6b9cf9b1f0 --- /dev/null +++ b/tests/compatibility-tests/src/main/resources/exportimport/import.groovy @@ -0,0 +1,27 @@ +/* + * 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. + */ +import org.apache.activemq.artemis.cli.commands.ActionContext +import org.apache.activemq.artemis.cli.commands.tools.xml.XmlDataImporter + + +System.out.println("Arg::" + arg[0]); +File pagingfile = new File(arg[0] + "/sender/data/paging") +pagingfile.mkdirs() +XmlDataImporter importer = new XmlDataImporter(); + +importer.input = arg[0] + "/journal.export" +importer.execute(new ActionContext(System.in, System.out, System.err)) diff --git a/tests/compatibility-tests/src/main/resources/exportimport/import1X.groovy b/tests/compatibility-tests/src/main/resources/exportimport/import1X.groovy new file mode 100644 index 0000000000..ceccb0308a --- /dev/null +++ b/tests/compatibility-tests/src/main/resources/exportimport/import1X.groovy @@ -0,0 +1,28 @@ +/* + * 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. + */ + +import org.apache.activemq.artemis.cli.commands.ActionContext +import org.apache.activemq.artemis.cli.commands.tools.XmlDataImporter + + +System.out.println("Arg::" + arg[0]); +File pagingfile = new File(arg[0] + "/sender/data/paging") +pagingfile.mkdirs() +XmlDataImporter importer = new XmlDataImporter(); + +importer.input = arg[0] + "/journal.export" +importer.execute(new ActionContext(System.in, System.out, System.err)) diff --git a/tests/compatibility-tests/src/main/resources/meshTest/sendMessages.groovy b/tests/compatibility-tests/src/main/resources/meshTest/sendMessages.groovy index d13fa2f3f1..71d33ef68c 100644 --- a/tests/compatibility-tests/src/main/resources/meshTest/sendMessages.groovy +++ b/tests/compatibility-tests/src/main/resources/meshTest/sendMessages.groovy @@ -5,16 +5,20 @@ import org.apache.activemq.artemis.tests.compatibility.GroovyRun import javax.jms.* /* - * Copyright 2005-2014 Red Hat, Inc. - * Red Hat 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 + * 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. + * 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. */ // starts an artemis server @@ -24,6 +28,7 @@ String operation = arg[2]; String queueName = "queue"; +String topicName = "topic"; int LARGE_MESSAGE_SIZE = 10 * 1024; @@ -57,9 +62,18 @@ if (clientType.startsWith("ARTEMIS")) { Connection connection = cf.createConnection(); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); Queue queue = session.createQueue(queueName); +Topic topic = session.createTopic(topicName); -if (operation.equals("sendAckMessages")) { - MessageProducer producer = session.createProducer(queue); +Destination destination = queue; + +if (operation.equals("sendTopic") || operation.equals("receiveNonDurableSubscription")) { + destination = topic; +} + + +if (operation.equals("sendAckMessages") || operation.equals("sendTopic")) { + println("sending...") + MessageProducer producer = session.createProducer(destination); producer.setDeliveryMode(DeliveryMode.PERSISTENT); System.out.println("Sending messages"); @@ -67,29 +81,36 @@ if (operation.equals("sendAckMessages")) { TextMessage message = session.createTextMessage(textBody); message.setStringProperty(HDR_DUPLICATE_DETECTION_ID, "some-duplicate"); message.setStringProperty("prop", "test"); + message.setIntProperty("order", 0) producer.send(message); BytesMessage bytesMessage = session.createBytesMessage(); bytesMessage.writeBytes(BYTES_BODY); + bytesMessage.setIntProperty("order", 1) producer.send(bytesMessage); for (int i = 0; i < 10; i++) { BytesMessage m = session.createBytesMessage(); m.setIntProperty("count", i); + m.setIntProperty("order", 2 + i) m.setObjectProperty(propertyLargeMessage, createFakeLargeStream(LARGE_MESSAGE_SIZE)); producer.send(m); } - producer.send(session.createObjectMessage("rapadura")); + ObjectMessage objMessage = session.createObjectMessage("rapadura"); + objMessage.setIntProperty("count", 13) + producer.send(objMessage); MapMessage mapMessage = session.createMapMessage(); mapMessage.setString("prop", "rapadura") + mapMessage.setIntProperty("order", 14) producer.send(mapMessage); StreamMessage streamMessage = session.createStreamMessage(); + streamMessage.setIntProperty("order", 15); streamMessage.writeString("rapadura"); streamMessage.writeString("doce"); streamMessage.writeInt(33); @@ -97,16 +118,25 @@ if (operation.equals("sendAckMessages")) { Message plain = session.createMessage(); plain.setStringProperty("plain", "doce"); + plain.setIntProperty("order", 15) producer.send(plain); session.commit(); connection.close(); System.out.println("Message sent"); -} else if (operation.equals("receiveMessages")) { - MessageConsumer consumer = session.createConsumer(queue); +} + +if (operation.equals("receiveMessages") || operation.equals("receiveNonDurableSubscription")) { + MessageConsumer consumer; + + consumer = session.createConsumer(destination); connection.start(); + if (latch != null) { + latch.countDown(); + } + System.out.println("Receiving messages"); TextMessage message = (TextMessage) consumer.receive(5000); @@ -165,8 +195,6 @@ if (operation.equals("sendAckMessages")) { session.commit(); connection.close(); System.out.println("Message received"); -} else { - throw new RuntimeException("Invalid operation " + operation); } diff --git a/tests/compatibility-tests/src/main/resources/sendAckTest/sendAckMessages.groovy b/tests/compatibility-tests/src/main/resources/sendAckTest/sendAckMessages.groovy index 344625763e..75751f16db 100644 --- a/tests/compatibility-tests/src/main/resources/sendAckTest/sendAckMessages.groovy +++ b/tests/compatibility-tests/src/main/resources/sendAckTest/sendAckMessages.groovy @@ -7,16 +7,20 @@ import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit /* - * Copyright 2005-2014 Red Hat, Inc. - * Red Hat 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 + * 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. + * 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. */ // starts an artemis server diff --git a/tests/compatibility-tests/src/main/resources/serial/serial.groovy b/tests/compatibility-tests/src/main/resources/serial/serial.groovy index 1fc9dbd8ef..0756fb3aae 100644 --- a/tests/compatibility-tests/src/main/resources/serial/serial.groovy +++ b/tests/compatibility-tests/src/main/resources/serial/serial.groovy @@ -1,15 +1,19 @@ package clients /* - * Copyright 2005-2014 Red Hat, Inc. - * Red Hat 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 + * 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. + * 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 diff --git a/tests/compatibility-tests/src/main/resources/servers/artemisServer.groovy b/tests/compatibility-tests/src/main/resources/servers/artemisServer.groovy index eb6383de50..9c15a086de 100644 --- a/tests/compatibility-tests/src/main/resources/servers/artemisServer.groovy +++ b/tests/compatibility-tests/src/main/resources/servers/artemisServer.groovy @@ -1,15 +1,19 @@ package servers /* - * Copyright 2005-2014 Red Hat, Inc. - * Red Hat 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 + * 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. + * 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. */ // starts an artemis server @@ -36,7 +40,7 @@ System.out.println("folder:: " + folder); configuration.setBrokerInstance(new File(folder + "/" + id)); configuration.addAcceptorConfiguration("artemis", "tcp://0.0.0.0:61616"); configuration.setSecurityEnabled(false); -configuration.setPersistenceEnabled(false); +configuration.setPersistenceEnabled(persistent); try { if (!type.startsWith("ARTEMIS-1")) { configuration.addAddressesSetting("#", new AddressSettings().setAutoCreateAddresses(true)); @@ -53,8 +57,5 @@ server.setConfiguration(configuration); server.setJmsConfiguration(jmsConfiguration); server.start(); -// uncomment this next statements to validate https://issues.apache.org/jira/browse/ARTEMIS-1561 -if (producer.toString().startsWith("ARTEMIS-1") && type.equals("ARTEMIS-SNAPSHOT") || - producer.toString().startsWith("HORNETQ")) { - server.getJMSServerManager().createQueue(true, "queue", null, true); -} +server.getJMSServerManager().createTopic(true, "topic"); +server.getJMSServerManager().createQueue(true, "queue", null, true); diff --git a/tests/compatibility-tests/src/main/resources/servers/hornetqServer.groovy b/tests/compatibility-tests/src/main/resources/servers/hornetqServer.groovy index be92768b1a..6b49f42805 100644 --- a/tests/compatibility-tests/src/main/resources/servers/hornetqServer.groovy +++ b/tests/compatibility-tests/src/main/resources/servers/hornetqServer.groovy @@ -1,15 +1,19 @@ package servers /* - * Copyright 2005-2014 Red Hat, Inc. - * Red Hat 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 + * 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. + * 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. */ // starts a hornetq server @@ -19,7 +23,7 @@ import org.hornetq.core.config.impl.ConfigurationImpl import org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory import org.hornetq.core.remoting.impl.netty.TransportConstants import org.hornetq.jms.server.config.impl.JMSConfigurationImpl -import org.hornetq.jms.server.config.impl.JMSQueueConfigurationImpl +import org.hornetq.jms.server.config.impl.* import org.hornetq.jms.server.embedded.EmbeddedJMS String folder = arg[0]; @@ -46,7 +50,11 @@ configuration.getAcceptorConfigurations().add(tpc); jmsConfiguration = new JMSConfigurationImpl(); JMSQueueConfigurationImpl queueConfiguration = new JMSQueueConfigurationImpl("queue", null, true); +TopicConfigurationImpl topicConfiguration = new TopicConfigurationImpl("topic"); + + jmsConfiguration.getQueueConfigurations().add(queueConfiguration); +jmsConfiguration.getTopicConfigurations().add(topicConfiguration); server = new EmbeddedJMS(); server.setConfiguration(configuration); server.setJmsConfiguration(jmsConfiguration); diff --git a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/ExportImportTest.java b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/ExportImportTest.java new file mode 100644 index 0000000000..44f9011ea2 --- /dev/null +++ b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/ExportImportTest.java @@ -0,0 +1,121 @@ +/* + * 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. + */ + +package org.apache.activemq.artemis.tests.compatibility; + +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.Ignore; +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.SNAPSHOT; +import static org.apache.activemq.artemis.tests.compatibility.GroovyRun.TWO_FOUR; + +/** + * To run this test on the IDE and debug it, run the compatibility-tests through a command line once: + * + * cd /compatibility-tests + * mvn install -Ptests | tee output.log + * + * on the output.log you will see the output generated by {@link #getClasspathProperty(String)} + * + * On your IDE, edit the Run Configuration to your test and add those -D as parameters to your test. + * On Idea you would do the following: + * + * Run->Edit Configuration->Add ArtemisMeshTest and add your properties. + */ +@RunWith(Parameterized.class) +public class ExportImportTest 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" + @Parameterized.Parameters(name = "server={0}, producer={1}, consumer={2}") + public static Collection getParameters() { + // we don't need every single version ever released.. + // if we keep testing current one against 2.4 and 1.4.. we are sure the wire and API won't change over time + List combinations = new ArrayList<>(); + + /* + // during development sometimes is useful to comment out the combinations + // and add the ones you are interested.. example: + */ + // combinations.add(new Object[]{SNAPSHOT, ONE_FIVE, ONE_FIVE}); + // combinations.add(new Object[]{ONE_FIVE, ONE_FIVE, ONE_FIVE}); + + combinations.addAll(combinatory(new Object[]{null}, new Object[]{ONE_FIVE, TWO_FOUR, SNAPSHOT}, new Object[]{ONE_FIVE, TWO_FOUR, SNAPSHOT})); + return combinations; + } + + public ExportImportTest(String server, String sender, String receiver) throws Exception { + super(server, sender, receiver); + } + + @Before + public void removeFolder() throws Throwable { + FileUtil.deleteDirectory(serverFolder.getRoot()); + serverFolder.getRoot().mkdirs(); + } + + @After + public void tearDown() { + try { + stopServer(serverClassloader); + } catch (Throwable ignored) { + } + try { + stopServer(receiverClassloader); + } catch (Throwable ignored) { + } + } + + @Test + @Ignore // There's some work to be done on exporter / importer, but I wanted to send it in already + public void testSendReceive() throws Throwable { + setVariable(senderClassloader, "persistent", Boolean.TRUE); + startServer(serverFolder.getRoot(), senderClassloader, "sender"); + callScript(senderClassloader, "meshTest/sendMessages.groovy", server, sender, "sendAckMessages"); + stopServer(senderClassloader); + + if (sender.startsWith("ARTEMIS-1")) { + callScript(senderClassloader, "exportimport/export1X.groovy", serverFolder.getRoot().getAbsolutePath()); + } else { + callScript(senderClassloader, "exportimport/export.groovy", serverFolder.getRoot().getAbsolutePath()); + } + + setVariable(receiverClassloader, "persistent", Boolean.TRUE); + startServer(serverFolder.getRoot(), receiverClassloader, "receiver"); + + if (receiver.startsWith("ARTEMIS-1")) { + callScript(receiverClassloader, "exportimport/import1X.groovy", serverFolder.getRoot().getAbsolutePath()); + } else { + callScript(receiverClassloader, "exportimport/import.groovy", serverFolder.getRoot().getAbsolutePath()); + } + + setVariable(receiverClassloader, "latch", null); + callScript(receiverClassloader, "meshTest/sendMessages.groovy", server, receiver, "receiveMessages"); + } + +} + diff --git a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/MeshTest.java b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/MeshTest.java index 0c782554bc..37978dc285 100644 --- a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/MeshTest.java +++ b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/MeshTest.java @@ -1,14 +1,18 @@ /* - * Copyright 2005-2014 Red Hat, Inc. - * Red Hat 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 + * 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. + * 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. */ package org.apache.activemq.artemis.tests.compatibility; @@ -16,7 +20,11 @@ package org.apache.activemq.artemis.tests.compatibility; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -42,7 +50,7 @@ import static org.apache.activemq.artemis.tests.compatibility.GroovyRun.TWO_FOUR * Run->Edit Configuration->Add ArtemisMeshTest and add your properties. */ @RunWith(Parameterized.class) -public class MeshTest extends VersionedBaseTest { +public class MeshTest extends ServerBaseTest { // this will ensure that all tests in this class are run twice, // once with "true" passed to the class' constructor and once with "false" @@ -73,8 +81,36 @@ public class MeshTest extends VersionedBaseTest { @Test public void testSendReceive() throws Throwable { - callMain(senderClassloader, GroovyRun.class.getName(), "meshTest/sendMessages.groovy", server, sender, "sendAckMessages"); - callMain(receiverClassloader, GroovyRun.class.getName(), "meshTest/sendMessages.groovy", server, receiver, "receiveMessages"); + setVariable(receiverClassloader, "latch", null); + callScript(senderClassloader, "meshTest/sendMessages.groovy", server, sender, "sendAckMessages"); + callScript(receiverClassloader, "meshTest/sendMessages.groovy", server, receiver, "receiveMessages"); + } + + @Test + public void testSendReceiveTopicNonDurable() throws Throwable { + CountDownLatch latch = new CountDownLatch(1); + + setVariable(receiverClassloader, "latch", latch); + AtomicInteger errors = new AtomicInteger(0); + Thread t = new Thread() { + @Override + public void run() { + try { + callScript(receiverClassloader, "meshTest/sendMessages.groovy", server, receiver, "receiveNonDurableSubscription"); + } catch (Exception e) { + e.printStackTrace(); + errors.incrementAndGet(); + } + } + }; + + t.start(); + Assert.assertTrue(latch.await(10, TimeUnit.SECONDS)); + callScript(senderClassloader,"meshTest/sendMessages.groovy", server, sender, "sendTopic"); + + t.join(); + + Assert.assertEquals(0, errors.get()); } } diff --git a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/SendAckTest.java b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/SendAckTest.java index aeec6dc0c4..e9156796f3 100644 --- a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/SendAckTest.java +++ b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/SendAckTest.java @@ -1,14 +1,18 @@ /* - * Copyright 2005-2014 Red Hat, Inc. - * Red Hat 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 + * 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. + * 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. */ package org.apache.activemq.artemis.tests.compatibility; @@ -40,7 +44,7 @@ import static org.apache.activemq.artemis.tests.compatibility.GroovyRun.ONE_FIVE * Run->Edit Configuration->Add ArtemisMeshTest and add your properties. */ @RunWith(Parameterized.class) -public class SendAckTest extends VersionedBaseTest { +public class SendAckTest extends ServerBaseTest { // this will ensure that all tests in this class are run twice, // once with "true" passed to the class' constructor and once with "false" @@ -72,8 +76,8 @@ public class SendAckTest extends VersionedBaseTest { @Test public void testSendReceive() throws Throwable { - callMain(senderClassloader, GroovyRun.class.getName(), "sendAckTest/sendAckMessages.groovy", server, sender, "sendAckMessages"); - callMain(receiverClassloader, GroovyRun.class.getName(), "sendAckTest/sendAckMessages.groovy", server, receiver, "receiveMessages"); + callScript(senderClassloader, "sendAckTest/sendAckMessages.groovy", server, sender, "sendAckMessages"); + callScript(receiverClassloader, "sendAckTest/sendAckMessages.groovy", server, receiver, "receiveMessages"); } } 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 b5a871dbad..6108cecc96 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 @@ -1,14 +1,18 @@ /* - * Copyright 2005-2014 Red Hat, Inc. - * Red Hat 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 + * 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. + * 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. */ package org.apache.activemq.artemis.tests.compatibility; @@ -39,7 +43,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 VersionedBaseTest { +public class SerializationTest extends ServerBaseTest { // this will ensure that all tests in this class are run twice, // once with "true" passed to the class' constructor and once with "false" @@ -68,8 +72,8 @@ public class SerializationTest extends VersionedBaseTest { public void testSerializeFactory() throws Throwable { File file = serverFolder.newFile("objects.ser"); file.mkdirs(); - callMain(senderClassloader, GroovyRun.class.getName(), "serial/serial.groovy", file.getAbsolutePath(), "write"); - callMain(receiverClassloader, GroovyRun.class.getName(), "serial/serial.groovy", file.getAbsolutePath(), "read"); + callScript(senderClassloader, "serial/serial.groovy", file.getAbsolutePath(), "write"); + callScript(receiverClassloader, "serial/serial.groovy", file.getAbsolutePath(), "read"); } } diff --git a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/ServerBaseTest.java b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/ServerBaseTest.java new file mode 100644 index 0000000000..f519eab745 --- /dev/null +++ b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/ServerBaseTest.java @@ -0,0 +1,41 @@ +/* + * 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. + */ + +package org.apache.activemq.artemis.tests.compatibility; + +import org.apache.activemq.artemis.utils.FileUtil; +import org.junit.After; +import org.junit.Before; + +public class ServerBaseTest extends VersionedBaseTest { + + public ServerBaseTest(String server, String sender, String receiver) throws Exception { + super(server, sender, receiver); + } + + @Before + public void setUp() throws Throwable { + FileUtil.deleteDirectory(serverFolder.getRoot()); + setVariable(serverClassloader, "persistent", Boolean.FALSE); + startServer(serverFolder.getRoot(), serverClassloader, "live"); + } + + @After + public void tearDown() throws Throwable { + stopServer(serverClassloader); + } +} diff --git a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/VersionedBaseTest.java b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/VersionedBaseTest.java index 5423d3634d..62b98c6870 100644 --- a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/VersionedBaseTest.java +++ b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/VersionedBaseTest.java @@ -1,14 +1,18 @@ /* - * Copyright 2005-2014 Red Hat, Inc. - * Red Hat 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 + * 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. + * 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. */ package org.apache.activemq.artemis.tests.compatibility; @@ -24,12 +28,9 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import org.apache.activemq.artemis.utils.FileUtil; import org.apache.activemq.artemis.utils.RunnableEx; -import org.junit.After; import org.junit.AfterClass; import org.junit.Assume; -import org.junit.Before; import org.junit.ClassRule; import org.junit.rules.TemporaryFolder; @@ -48,6 +49,9 @@ public abstract class VersionedBaseTest { protected static Map loaderMap = new HashMap<>(); public VersionedBaseTest(String server, String sender, String receiver) throws Exception { + if (server == null) { + server = sender; + } this.server = server; this.sender = sender; this.receiver = receiver; @@ -72,53 +76,30 @@ public abstract class VersionedBaseTest { serverFolder = new TemporaryFolder(parent); } - @Before - public void startServer() throws Throwable { - FileUtil.deleteDirectory(serverFolder.getRoot()); - - serverFolder.getRoot().mkdirs(); - - System.out.println("Folder::" + serverFolder.getRoot()); - - String scriptToUse; - if (server.startsWith("ARTEMIS")) { - scriptToUse = "servers/artemisServer.groovy"; - } else { - scriptToUse = "servers/hornetqServer.groovy"; - } - - callMain(serverClassloader, GroovyRun.class.getName(), scriptToUse, serverFolder.getRoot().getAbsolutePath(), "1", server, sender, receiver); - } - - @After - public void stopServer() throws Throwable { - callExecute(serverClassloader, GroovyRun.class.getName(), "server.stop()"); - - // GC help!!! - serverClassloader = null; - senderClassloader = null; - receiverClassloader = null; - } - @AfterClass public static void cleanup() { loaderMap.clear(); } - protected static void callMain(ClassLoader loader, - String className, - String script, - String... arguments) throws Exception { + protected static void callScript(ClassLoader loader, String script, String... arguments) throws Exception { tclCall(loader, () -> { - Class clazz = loader.loadClass(className); - Method method = clazz.getMethod("doMain", String.class, String[].class); + Class clazz = loader.loadClass(GroovyRun.class.getName()); + Method method = clazz.getMethod("doTest", String.class, String[].class); method.invoke(null, script, arguments); }); } - protected static void callExecute(ClassLoader loader, String className, String script) throws Exception { + protected static void setVariable(ClassLoader loader, String name, Object object) throws Exception { tclCall(loader, () -> { - Class clazz = loader.loadClass(className); + Class clazz = loader.loadClass(GroovyRun.class.getName()); + Method method = clazz.getMethod("setVariable", String.class, Object.class); + method.invoke(null, name, object); + }); + } + + protected static void callExecute(ClassLoader loader, String script) throws Exception { + tclCall(loader, () -> { + Class clazz = loader.loadClass(GroovyRun.class.getName()); Method method = clazz.getMethod("execute", String.class); method.invoke(null, script); }); @@ -135,7 +116,6 @@ public abstract class VersionedBaseTest { } } - protected static ClassLoader defineClassLoader(String classPath) throws MalformedURLException { String[] classPathArray = classPath.split(File.pathSeparator); URL[] elements = new URL[classPathArray.length]; @@ -176,7 +156,6 @@ public abstract class VersionedBaseTest { Assume.assumeTrue("Cannot run these tests, no classpath found", ok); } - loader = defineClassLoader(value); loaderMap.put(name, loader); @@ -197,4 +176,22 @@ public abstract class VersionedBaseTest { return combinations; } + public void startServer(File folder, ClassLoader loader, String serverName) throws Throwable { + folder.mkdirs(); + + System.out.println("Folder::" + folder); + + String scriptToUse; + if (server.startsWith("ARTEMIS")) { + scriptToUse = "servers/artemisServer.groovy"; + } else { + scriptToUse = "servers/hornetqServer.groovy"; + } + + callScript(loader, scriptToUse, folder.getAbsolutePath(), serverName, server, sender, receiver); + } + + public void stopServer(ClassLoader loader) throws Throwable { + callExecute(loader, "server.stop()"); + } } diff --git a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/package-info.java b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/package-info.java index 0c3c124613..e78ed58299 100644 --- a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/package-info.java +++ b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/package-info.java @@ -1,14 +1,18 @@ /* - * Copyright 2005-2014 Red Hat, Inc. - * Red Hat 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 + * 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. + * 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. */ /**