From df06bdabdc0e9f892449e0ef0d8783aea6047802 Mon Sep 17 00:00:00 2001 From: Timothy Bish Date: Mon, 1 Jun 2015 17:50:20 -0400 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-5816 Apply patch from Ievgen Tarasov that ensures that the data locator is initialized when a MessageId is deserialized. --- .../apache/activemq/command/MessageId.java | 5 + .../org/apache/activemq/bugs/AMQ5816Test.java | 122 ++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 activemq-http/src/test/java/org/apache/activemq/bugs/AMQ5816Test.java diff --git a/activemq-client/src/main/java/org/apache/activemq/command/MessageId.java b/activemq-client/src/main/java/org/apache/activemq/command/MessageId.java index de8cc12e87..71319b2bf5 100755 --- a/activemq-client/src/main/java/org/apache/activemq/command/MessageId.java +++ b/activemq-client/src/main/java/org/apache/activemq/command/MessageId.java @@ -244,4 +244,9 @@ public class MessageId implements DataStructure, Comparable { public void setPlistLocator(Object plistLocator) { this.plistLocator = plistLocator; } + + private Object readResolve() { + dataLocator = new AtomicReference(); + return this; + } } diff --git a/activemq-http/src/test/java/org/apache/activemq/bugs/AMQ5816Test.java b/activemq-http/src/test/java/org/apache/activemq/bugs/AMQ5816Test.java new file mode 100644 index 0000000000..5e281959a8 --- /dev/null +++ b/activemq-http/src/test/java/org/apache/activemq/bugs/AMQ5816Test.java @@ -0,0 +1,122 @@ +/** + * 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.bugs; + +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.io.IOException; +import java.net.ServerSocket; + +import javax.jms.Connection; +import javax.jms.DeliveryMode; +import javax.jms.JMSException; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Queue; +import javax.jms.Session; +import javax.net.ServerSocketFactory; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.TransportConnector; +import org.apache.activemq.leveldb.LevelDBStore; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + +public class AMQ5816Test { + + private static BrokerService brokerService; + + @Rule public TestName name = new TestName(); + + private File dataDirFile; + private String connectionURI; + + @Before + public void setUp() throws Exception { + + dataDirFile = new File("target/" + name.getMethodName()); + + brokerService = new BrokerService(); + brokerService.setBrokerName("LevelDBBroker"); + brokerService.setPersistent(true); + brokerService.setUseJmx(false); + brokerService.setAdvisorySupport(false); + brokerService.setDeleteAllMessagesOnStartup(true); + brokerService.setDataDirectoryFile(dataDirFile); + + TransportConnector connector = brokerService.addConnector("http://0.0.0.0:" + getFreePort()); + + LevelDBStore persistenceFactory = new LevelDBStore(); + persistenceFactory.setDirectory(dataDirFile); + brokerService.setPersistenceAdapter(persistenceFactory); + brokerService.start(); + brokerService.waitUntilStarted(); + + connectionURI = connector.getPublishableConnectString(); + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + brokerService.stop(); + brokerService.waitUntilStopped(); + } + + @Test + public void testSendPersistentMessage() throws JMSException { + ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionURI); + Connection connection = factory.createConnection(); + connection.start(); + + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Queue queue = session.createQueue(name.getMethodName()); + MessageProducer producer = session.createProducer(queue); + MessageConsumer consumer = session.createConsumer(queue); + + producer.setDeliveryMode(DeliveryMode.PERSISTENT); + producer.send(session.createTextMessage()); + + assertNotNull(consumer.receive(5000)); + } + + protected int getFreePort() { + int port = 8161; + ServerSocket ss = null; + + try { + ss = ServerSocketFactory.getDefault().createServerSocket(0); + port = ss.getLocalPort(); + } catch (IOException e) { // ignore + } finally { + try { + if (ss != null ) { + ss.close(); + } + } catch (IOException e) { // ignore + } + } + + return port; + } +}