ConnectionFactory factorySend = new ActiveMQConnectionFactory();
Connection connection = factorySend.createConnection();
try (Session session = connection.createSession()) {
javax.jms.Queue queue = session.createQueue("queueStop");
MessageProducer producer = session.createProducer(queue);
producer.send(session.createTextMessage("text"));
connection.start();
MessageConsumer consumer = session.createConsumer(queue);
assertNotNull(consumer.receive(1000));
final CountDownLatch stoppingLatch = new CountDownLatch(1);
(new Thread(new Runnable() {
@Override
public void run() {
try {
stoppingLatch.countDown();
Thread.sleep(1000);
server.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
})).start();
try {
stoppingLatch.await();
consumer.receive(5000);
Assert.fail("didn't get expected exception!");
} catch (Exception e) {
e.printStackTrace();
}
}