Adds a little test case for Http based discovery
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/3c8651ec Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/3c8651ec Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/3c8651ec Branch: refs/heads/activemq-5.9 Commit: 3c8651ec930dd12c20ec08c08e5621574f3ab0a3 Parents: bce750f Author: Timothy Bish <[email protected]> Authored: Fri Oct 18 17:27:13 2013 -0400 Committer: Hadrian Zbarcea <[email protected]> Committed: Tue Mar 11 17:05:39 2014 -0400 ---------------------------------------------------------------------- .../discovery/http/HttpDiscoveryTest.java | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/3c8651ec/activemq-http/src/test/java/org/apache/activemq/transport/discovery/http/HttpDiscoveryTest.java ---------------------------------------------------------------------- diff --git a/activemq-http/src/test/java/org/apache/activemq/transport/discovery/http/HttpDiscoveryTest.java b/activemq-http/src/test/java/org/apache/activemq/transport/discovery/http/HttpDiscoveryTest.java new file mode 100644 index 0000000..72104af --- /dev/null +++ b/activemq-http/src/test/java/org/apache/activemq/transport/discovery/http/HttpDiscoveryTest.java @@ -0,0 +1,70 @@ +package org.apache.activemq.transport.discovery.http; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.net.URI; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.apache.activemq.ActiveMQConnection; +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.TransportConnector; +import org.apache.activemq.transport.TransportListener; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class HttpDiscoveryTest implements TransportListener { + + private BrokerService broker; + private ActiveMQConnectionFactory factory; + private final CountDownLatch discovered = new CountDownLatch(1); + + @Before + public void setUp() throws Exception { + + broker = new BrokerService(); + TransportConnector connector = broker.addConnector("tcp://localhost:0"); + connector.setDiscoveryUri(new URI("http://localhost:8181/default?startEmbeddRegistry=true")); + broker.setPersistent(false); + broker.setUseJmx(false); + broker.deleteAllMessages(); + broker.start(); + + String connectionUri = "discovery:http://localhost:8181/default"; + factory = new ActiveMQConnectionFactory(connectionUri + "?trace=true&soTimeout=1000"); + } + + @After + public void tearDown() throws Exception { + broker.stop(); + } + + @Test + public void testBrokerIsDiscovered() throws Exception { + factory.setTransportListener(this); + ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection(); + assertTrue(discovered.await(60, TimeUnit.SECONDS)); + connection.close(); + } + + @Override + public void onCommand(Object command) { + } + + @Override + public void onException(IOException error) { + } + + @Override + public void transportInterupted() { + } + + @Override + public void transportResumed() { + discovered.countDown(); + } + +}
