You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2016/03/23 15:23:54 UTC
activemq git commit: NO-JIRA Fix test such that the broker ports are
selected dynamically instead of hardcoded.
Repository: activemq
Updated Branches:
refs/heads/master 75990ef14 -> c53b99c14
NO-JIRA Fix test such that the broker ports are selected dynamically
instead of hardcoded.
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/c53b99c1
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/c53b99c1
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/c53b99c1
Branch: refs/heads/master
Commit: c53b99c14d44af64bc76581723d4ba564a19c083
Parents: 75990ef
Author: Timothy Bish <ta...@gmail.com>
Authored: Wed Mar 23 10:23:10 2016 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Wed Mar 23 10:23:10 2016 -0400
----------------------------------------------------------------------
.../activemq/broker/LinkStealingTest.java | 70 +++++++++++---------
1 file changed, 40 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq/blob/c53b99c1/activemq-broker/src/test/java/org/apache/activemq/broker/LinkStealingTest.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/test/java/org/apache/activemq/broker/LinkStealingTest.java b/activemq-broker/src/test/java/org/apache/activemq/broker/LinkStealingTest.java
index 60fce40..bd88430 100644
--- a/activemq-broker/src/test/java/org/apache/activemq/broker/LinkStealingTest.java
+++ b/activemq-broker/src/test/java/org/apache/activemq/broker/LinkStealingTest.java
@@ -16,51 +16,63 @@
*/
package org.apache.activemq.broker;
-import junit.framework.TestCase;
-import org.apache.activemq.ActiveMQConnectionFactory;
-import org.apache.activemq.command.ConnectionInfo;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
-import javax.jms.Connection;
-import javax.jms.InvalidClientIDException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
-public class LinkStealingTest extends TestCase {
- protected BrokerService brokerService;
- protected int timeOutInSeconds = 10;
- protected final AtomicReference<Throwable> removeException = new AtomicReference<Throwable>();
+import javax.jms.Connection;
+import javax.jms.InvalidClientIDException;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.command.ConnectionInfo;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class LinkStealingTest {
+
+ private BrokerService brokerService;
+ private final AtomicReference<Throwable> removeException = new AtomicReference<Throwable>();
+ private String stealableConnectionURI;
+ private String unstealableConnectionURI;
- @Override
- protected void setUp() throws Exception {
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp() throws Exception {
brokerService = new BrokerService();
brokerService.setPersistent(false);
brokerService.setPlugins(new BrokerPlugin[]{
- new BrokerPluginSupport() {
- @Override
- public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception {
- removeException.set(error);
- super.removeConnection(context, info, error);
- }
+ new BrokerPluginSupport() {
+ @Override
+ public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception {
+ removeException.set(error);
+ super.removeConnection(context, info, error);
}
+ }
});
+
+ stealableConnectionURI = brokerService.addConnector("tcp://0.0.0.0:0?allowLinkStealing=true").getPublishableConnectString();
+ unstealableConnectionURI = brokerService.addConnector("tcp://0.0.0.0:0?allowLinkStealing=false").getPublishableConnectString();
+
+ brokerService.start();
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
if (brokerService != null) {
brokerService.stop();
}
}
-
+ @Test(timeout=60000)
public void testStealLinkFails() throws Exception {
- brokerService.addConnector(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL);
- brokerService.start();
-
final String clientID = "ThisIsAClientId";
- ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL);
+ ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(unstealableConnectionURI);
Connection connection1 = factory.createConnection();
connection1.setClientID(clientID);
connection1.start();
@@ -73,17 +85,15 @@ public class LinkStealingTest extends TestCase {
} catch (InvalidClientIDException e) {
exceptionFlag.set(true);
}
- assertTrue(exceptionFlag.get());
+ assertTrue(exceptionFlag.get());
}
+ @Test(timeout=60000)
public void testStealLinkSuccess() throws Exception {
- brokerService.addConnector(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL+"?allowLinkStealing=true");
- brokerService.start();
-
final String clientID = "ThisIsAClientId";
- ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL);
+ ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(stealableConnectionURI);
Connection connection1 = factory.createConnection();
connection1.setClientID(clientID);
connection1.start();
@@ -97,8 +107,8 @@ public class LinkStealingTest extends TestCase {
e.printStackTrace();
exceptionFlag.set(true);
}
+
assertFalse(exceptionFlag.get());
assertNotNull(removeException.get());
-
}
}