mirror of https://github.com/apache/activemq.git
Adding in test case to get this on our radar git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1487905 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c90322fff0
commit
6fa059837f
|
@ -58,6 +58,11 @@
|
|||
<version>${qpid-jms-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>activemq-kahadb-store</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Joram JMS conformance tests -->
|
||||
<dependency>
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
/**
|
||||
* 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.transport.amqp;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.ExceptionListener;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageConsumer;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Session;
|
||||
import javax.jms.TextMessage;
|
||||
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.spring.SpringSslContext;
|
||||
import org.apache.activemq.store.kahadb.KahaDBStore;
|
||||
import org.apache.activemq.transport.amqp.joram.ActiveMQAdmin;
|
||||
import org.apache.qpid.amqp_1_0.jms.impl.ConnectionFactoryImpl;
|
||||
import org.apache.qpid.amqp_1_0.jms.impl.QueueImpl;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AMQ4563Test extends AmqpTestSupport {
|
||||
|
||||
public static final String KAHADB_DIRECTORY = "target/activemq-data/kahadb-amq4563";
|
||||
|
||||
@Test(timeout = 60000)
|
||||
public void testTransactions() throws Exception {
|
||||
int messagesSent = 3;
|
||||
ActiveMQAdmin.enableJMSFrameTracing();
|
||||
QueueImpl queue = new QueueImpl("queue://txqueue");
|
||||
assertTrue(brokerService.isPersistent());
|
||||
|
||||
Connection connection = createConnection();
|
||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
MessageProducer p = session.createProducer(queue);
|
||||
TextMessage message = null;
|
||||
for (int i=0; i < messagesSent; i++) {
|
||||
message = session.createTextMessage();
|
||||
String messageText = "Hello " + i + " sent at " + new java.util.Date().toString();
|
||||
message.setText(messageText);
|
||||
LOG.debug(">>>> Sent [" + messageText + "]");
|
||||
p.send(message);
|
||||
}
|
||||
|
||||
// After the first restart we should get all messages sent above
|
||||
restartBroker(connection, session);
|
||||
int messagesReceived = readAllMessages(queue);
|
||||
assertEquals(messagesSent, messagesReceived);
|
||||
|
||||
// This time there should be no messages on this queue
|
||||
restartBroker(connection, session);
|
||||
messagesReceived = readAllMessages(queue);
|
||||
assertEquals(0, messagesReceived);
|
||||
}
|
||||
|
||||
private int readAllMessages(QueueImpl queue) throws JMSException {
|
||||
Connection connection = createConnection();
|
||||
try {
|
||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
int messagesReceived = 0;
|
||||
MessageConsumer consumer = session.createConsumer(queue);
|
||||
Message msg = consumer.receive(5000);
|
||||
while(msg != null) {
|
||||
assertNotNull(msg);
|
||||
assertTrue(msg instanceof TextMessage);
|
||||
TextMessage textMessage = (TextMessage) msg;
|
||||
LOG.debug(">>>> Received [" + textMessage.getText() + "]");
|
||||
messagesReceived++;
|
||||
msg = consumer.receive(5000);
|
||||
}
|
||||
consumer.close();
|
||||
|
||||
return messagesReceived;
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void restartBroker(Connection connection, Session session) throws Exception {
|
||||
session.close();
|
||||
connection.close();
|
||||
|
||||
stopBroker();
|
||||
createBroker(false);
|
||||
}
|
||||
|
||||
private Connection createConnection() throws JMSException {
|
||||
LOG.debug(">>> In createConnection using port " + port);
|
||||
final ConnectionFactoryImpl factory = new ConnectionFactoryImpl("localhost", port, "admin", "password");
|
||||
final Connection connection = factory.createConnection();
|
||||
connection.setExceptionListener(new ExceptionListener() {
|
||||
@Override
|
||||
public void onException(JMSException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
});
|
||||
connection.start();
|
||||
return connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startBroker() throws Exception {
|
||||
createBroker(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from AmqpTestSupport, modified to use persistence
|
||||
*/
|
||||
public void createBroker(boolean deleteAllMessages) throws Exception {
|
||||
KahaDBStore kaha = new KahaDBStore();
|
||||
kaha.setDirectory(new File(KAHADB_DIRECTORY));
|
||||
|
||||
brokerService = new BrokerService();
|
||||
brokerService.setDeleteAllMessagesOnStartup(deleteAllMessages);
|
||||
brokerService.setPersistent(true);
|
||||
brokerService.setPersistenceAdapter(kaha);
|
||||
brokerService.setAdvisorySupport(false);
|
||||
brokerService.setUseJmx(false);
|
||||
|
||||
// Setup SSL context...
|
||||
final File classesDir = new File(AmqpProtocolConverter.class.getProtectionDomain().getCodeSource().getLocation().getFile());
|
||||
File keystore = new File(classesDir, "../../src/test/resources/keystore");
|
||||
final SpringSslContext sslContext = new SpringSslContext();
|
||||
sslContext.setKeyStore(keystore.getCanonicalPath());
|
||||
sslContext.setKeyStorePassword("password");
|
||||
sslContext.setTrustStore(keystore.getCanonicalPath());
|
||||
sslContext.setTrustStorePassword("password");
|
||||
sslContext.afterPropertiesSet();
|
||||
brokerService.setSslContext(sslContext);
|
||||
|
||||
addAMQPConnector();
|
||||
brokerService.start();
|
||||
this.numberOfMessages = 2000;
|
||||
}
|
||||
}
|
|
@ -16,6 +16,9 @@
|
|||
*/
|
||||
package org.apache.activemq.transport.amqp;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.apache.activemq.AutoFailTestSupport;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.TransportConnector;
|
||||
|
@ -25,31 +28,23 @@ import org.junit.Before;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Vector;
|
||||
|
||||
import static org.fusesource.hawtbuf.UTF8Buffer.utf8;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
public class AmqpTestSupport {
|
||||
|
||||
protected static final Logger LOG = LoggerFactory.getLogger(AmqpTestSupport.class);
|
||||
protected BrokerService brokerService;
|
||||
protected Vector<Throwable> exceptions = new Vector<Throwable>();
|
||||
protected int numberOfMessages;
|
||||
AutoFailTestSupport autoFailTestSupport = new AutoFailTestSupport() {};
|
||||
AutoFailTestSupport autoFailTestSupport = new AutoFailTestSupport() {
|
||||
};
|
||||
protected int port;
|
||||
protected int sslPort;
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
final AmqpTestSupport s = new AmqpTestSupport();
|
||||
s.sslPort = 5671;
|
||||
s.port = 5672;
|
||||
s.startBroker();
|
||||
while(true) {
|
||||
while (true) {
|
||||
Thread.sleep(100000);
|
||||
}
|
||||
}
|
||||
|
@ -83,13 +78,12 @@ public class AmqpTestSupport {
|
|||
}
|
||||
|
||||
protected void addAMQPConnector() throws Exception {
|
||||
TransportConnector connector =brokerService.addConnector("amqp+ssl://0.0.0.0:"+sslPort);
|
||||
TransportConnector connector = brokerService.addConnector("amqp+ssl://0.0.0.0:" + sslPort);
|
||||
sslPort = connector.getConnectUri().getPort();
|
||||
connector = brokerService.addConnector("amqp://0.0.0.0:"+port);
|
||||
connector = brokerService.addConnector("amqp://0.0.0.0:" + port);
|
||||
port = connector.getConnectUri().getPort();
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void stopBroker() throws Exception {
|
||||
if (brokerService != null) {
|
||||
|
@ -98,5 +92,4 @@ public class AmqpTestSupport {
|
|||
}
|
||||
autoFailTestSupport.stopAutoFailThread();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue