mirror of https://github.com/apache/activemq.git
Convert to JUnit 4 test and add a timeout, also remove the tcp transport
connector on a fixed port as its not needed.
This commit is contained in:
parent
707940f1a6
commit
b8830ddab1
|
@ -16,18 +16,21 @@
|
|||
*/
|
||||
package org.apache.activemq.transport.vm;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.junit.Test;
|
||||
|
||||
public class VMTransportWaitForTest extends TestCase {
|
||||
public class VMTransportWaitForTest {
|
||||
|
||||
private static final String VM_BROKER_URI_NO_WAIT =
|
||||
"vm://localhost?broker.persistent=false&create=false";
|
||||
|
@ -38,6 +41,7 @@ public class VMTransportWaitForTest extends TestCase {
|
|||
CountDownLatch started = new CountDownLatch(1);
|
||||
CountDownLatch gotConnection = new CountDownLatch(1);
|
||||
|
||||
@Test(timeout=90000)
|
||||
public void testWaitFor() throws Exception {
|
||||
try {
|
||||
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(new URI(VM_BROKER_URI_NO_WAIT));
|
||||
|
@ -46,15 +50,16 @@ public class VMTransportWaitForTest extends TestCase {
|
|||
} catch (JMSException expectedOnNoBrokerAndNoCreate) {
|
||||
}
|
||||
|
||||
// spawn a thread that will wait for an embedded broker to start via vm://..
|
||||
// spawn a thread that will wait for an embedded broker to start via
|
||||
// vm://..
|
||||
Thread t = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
started.countDown();
|
||||
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(new URI(VM_BROKER_URI_WAIT_FOR_START));
|
||||
cf.createConnection();
|
||||
gotConnection.countDown();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("unexpected exception: " + e);
|
||||
|
@ -68,7 +73,6 @@ public class VMTransportWaitForTest extends TestCase {
|
|||
|
||||
BrokerService broker = new BrokerService();
|
||||
broker.setPersistent(false);
|
||||
broker.addConnector("tcp://localhost:61616");
|
||||
broker.start();
|
||||
assertTrue("has got connection", gotConnection.await(400, TimeUnit.MILLISECONDS));
|
||||
broker.stop();
|
||||
|
|
Loading…
Reference in New Issue