mirror of
https://github.com/apache/activemq.git
synced 2025-02-18 07:56:20 +00:00
Convert the JUnit 4 test so that the ignore is honoered.
This commit is contained in:
parent
736ffc9b96
commit
77713d9d1a
@ -16,6 +16,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.activemq.jms.pool;
|
package org.apache.activemq.jms.pool;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotSame;
|
||||||
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
@ -28,10 +34,6 @@ import javax.jms.Connection;
|
|||||||
import javax.jms.JMSException;
|
import javax.jms.JMSException;
|
||||||
import javax.jms.Session;
|
import javax.jms.Session;
|
||||||
|
|
||||||
import junit.framework.Test;
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnection;
|
import org.apache.activemq.ActiveMQConnection;
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
@ -39,6 +41,7 @@ import org.apache.activemq.command.ConnectionId;
|
|||||||
import org.apache.activemq.util.Wait;
|
import org.apache.activemq.util.Wait;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the behavior of the PooledConnectionFactory when the maximum amount of
|
* Checks the behavior of the PooledConnectionFactory when the maximum amount of
|
||||||
@ -49,27 +52,11 @@ import org.junit.Ignore;
|
|||||||
* don't block. This test succeeds if an exception is returned and fails if the
|
* don't block. This test succeeds if an exception is returned and fails if the
|
||||||
* call to getSession() blocks.
|
* call to getSession() blocks.
|
||||||
*/
|
*/
|
||||||
public class PooledConnectionFactoryTest extends TestCase {
|
public class PooledConnectionFactoryTest {
|
||||||
|
|
||||||
public final static Logger LOG = Logger.getLogger(PooledConnectionFactoryTest.class);
|
public final static Logger LOG = Logger.getLogger(PooledConnectionFactoryTest.class);
|
||||||
|
|
||||||
/**
|
@Test
|
||||||
* Create the test case
|
|
||||||
*
|
|
||||||
* @param testName
|
|
||||||
* name of the test case
|
|
||||||
*/
|
|
||||||
public PooledConnectionFactoryTest(String testName) {
|
|
||||||
super(testName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the suite of tests being tested
|
|
||||||
*/
|
|
||||||
public static Test suite() {
|
|
||||||
return new TestSuite(PooledConnectionFactoryTest.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testClearAllConnections() throws Exception {
|
public void testClearAllConnections() throws Exception {
|
||||||
|
|
||||||
ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
|
ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
|
||||||
@ -100,6 +87,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||||||
assertNotSame(conn2.getConnection(), conn3.getConnection());
|
assertNotSame(conn2.getConnection(), conn3.getConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMaxConnectionsAreCreated() throws Exception {
|
public void testMaxConnectionsAreCreated() throws Exception {
|
||||||
|
|
||||||
ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
|
ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
|
||||||
@ -118,6 +106,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||||||
assertEquals(3, cf.getNumConnections());
|
assertEquals(3, cf.getNumConnections());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testConnectionsAreRotated() throws Exception {
|
public void testConnectionsAreRotated() throws Exception {
|
||||||
|
|
||||||
ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
|
ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
|
||||||
@ -139,6 +128,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testConnectionsArePooled() throws Exception {
|
public void testConnectionsArePooled() throws Exception {
|
||||||
|
|
||||||
ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
|
ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
|
||||||
@ -157,6 +147,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||||||
assertEquals(1, cf.getNumConnections());
|
assertEquals(1, cf.getNumConnections());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testConnectionsArePooledAsyncCreate() throws Exception {
|
public void testConnectionsArePooledAsyncCreate() throws Exception {
|
||||||
|
|
||||||
final ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
|
final ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
|
||||||
@ -193,7 +184,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||||||
executor.shutdown();
|
executor.shutdown();
|
||||||
assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
|
assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
|
||||||
|
|
||||||
for(PooledConnection connection : connections) {
|
for (PooledConnection connection : connections) {
|
||||||
assertSame(primary.getConnection(), connection.getConnection());
|
assertSame(primary.getConnection(), connection.getConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,11 +192,13 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||||||
cf.stop();
|
cf.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testConcurrentCreateGetsUniqueConnectionCreateOnDemand() throws Exception {
|
public void testConcurrentCreateGetsUniqueConnectionCreateOnDemand() throws Exception {
|
||||||
doTestConcurrentCreateGetsUniqueConnection(false);
|
doTestConcurrentCreateGetsUniqueConnection(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("something up - don't know why the start call to createConnection does not cause close - but that does not fix it either!")
|
@Ignore("something up - don't know why the start call to createConnection does not cause close - but that does not fix it either!")
|
||||||
|
@Test
|
||||||
public void testConcurrentCreateGetsUniqueConnectionCreateOnStart() throws Exception {
|
public void testConcurrentCreateGetsUniqueConnectionCreateOnStart() throws Exception {
|
||||||
doTestConcurrentCreateGetsUniqueConnection(true);
|
doTestConcurrentCreateGetsUniqueConnection(true);
|
||||||
}
|
}
|
||||||
@ -216,6 +209,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||||||
brokerService.setPersistent(false);
|
brokerService.setPersistent(false);
|
||||||
brokerService.addConnector("tcp://localhost:0");
|
brokerService.addConnector("tcp://localhost:0");
|
||||||
brokerService.start();
|
brokerService.start();
|
||||||
|
brokerService.waitUntilStarted();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final int numConnections = 2;
|
final int numConnections = 2;
|
||||||
@ -227,8 +221,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||||||
cf.setCreateConnectionOnStartup(createOnStart);
|
cf.setCreateConnectionOnStartup(createOnStart);
|
||||||
cf.start();
|
cf.start();
|
||||||
|
|
||||||
final ConcurrentHashMap<ConnectionId, Connection> connections =
|
final ConcurrentHashMap<ConnectionId, Connection> connections = new ConcurrentHashMap<ConnectionId, Connection>();
|
||||||
new ConcurrentHashMap<ConnectionId, Connection>();
|
|
||||||
final ExecutorService executor = Executors.newFixedThreadPool(numConnections);
|
final ExecutorService executor = Executors.newFixedThreadPool(numConnections);
|
||||||
|
|
||||||
for (int i = 0; i < numConnections; ++i) {
|
for (int i = 0; i < numConnections; ++i) {
|
||||||
@ -247,7 +240,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
executor.shutdown();
|
executor.shutdown();
|
||||||
assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
|
assertTrue(executor.awaitTermination(30, TimeUnit.SECONDS));
|
||||||
|
|
||||||
assertEquals("Should have all unique connections", numConnections, connections.size());
|
assertEquals("Should have all unique connections", numConnections, connections.size());
|
||||||
|
|
||||||
@ -277,9 +270,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||||||
if (!result.isDone() || !result.get().booleanValue()) {
|
if (!result.isDone() || !result.get().booleanValue()) {
|
||||||
PooledConnectionFactoryTest.LOG.error("2nd call to createSession() " +
|
PooledConnectionFactoryTest.LOG.error("2nd call to createSession() " +
|
||||||
"is blocking but should have returned an error instead.");
|
"is blocking but should have returned an error instead.");
|
||||||
|
|
||||||
executor.shutdownNow();
|
executor.shutdownNow();
|
||||||
|
|
||||||
fail("SessionPool inside PooledConnectionFactory is blocking if " +
|
fail("SessionPool inside PooledConnectionFactory is blocking if " +
|
||||||
"limit is exceeded but should return an exception instead.");
|
"limit is exceeded but should return an exception instead.");
|
||||||
}
|
}
|
||||||
@ -312,8 +303,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||||||
|
|
||||||
Session two = null;
|
Session two = null;
|
||||||
try {
|
try {
|
||||||
// this should raise an exception as we called
|
// this should raise an exception as we called setMaximumActive(1)
|
||||||
// setMaximumActive(1)
|
|
||||||
two = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
two = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||||
two.close();
|
two.close();
|
||||||
|
|
||||||
@ -331,11 +321,13 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||||||
return new Boolean(false);
|
return new Boolean(false);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (one != null)
|
if (one != null) {
|
||||||
one.close();
|
one.close();
|
||||||
if (conn != null)
|
}
|
||||||
|
if (conn != null) {
|
||||||
conn.close();
|
conn.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LOG.error(ex.getMessage());
|
LOG.error(ex.getMessage());
|
||||||
return new Boolean(false);
|
return new Boolean(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user