mirror of https://github.com/apache/activemq.git
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;
|
||||
|
||||
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.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
@ -28,10 +34,6 @@ import javax.jms.Connection;
|
|||
import javax.jms.JMSException;
|
||||
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.ActiveMQConnectionFactory;
|
||||
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.log4j.Logger;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* call to getSession() blocks.
|
||||
*/
|
||||
public class PooledConnectionFactoryTest extends TestCase {
|
||||
public class PooledConnectionFactoryTest {
|
||||
|
||||
public final static Logger LOG = Logger.getLogger(PooledConnectionFactoryTest.class);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClearAllConnections() throws Exception {
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxConnectionsAreCreated() throws Exception {
|
||||
|
||||
ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
|
||||
|
@ -118,6 +106,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||
assertEquals(3, cf.getNumConnections());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectionsAreRotated() throws Exception {
|
||||
|
||||
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 {
|
||||
|
||||
ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
|
||||
|
@ -157,6 +147,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||
assertEquals(1, cf.getNumConnections());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectionsArePooledAsyncCreate() throws Exception {
|
||||
|
||||
final ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
|
||||
|
@ -193,7 +184,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||
executor.shutdown();
|
||||
assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
|
||||
|
||||
for(PooledConnection connection : connections) {
|
||||
for (PooledConnection connection : connections) {
|
||||
assertSame(primary.getConnection(), connection.getConnection());
|
||||
}
|
||||
|
||||
|
@ -201,11 +192,13 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||
cf.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConcurrentCreateGetsUniqueConnectionCreateOnDemand() throws Exception {
|
||||
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!")
|
||||
@Test
|
||||
public void testConcurrentCreateGetsUniqueConnectionCreateOnStart() throws Exception {
|
||||
doTestConcurrentCreateGetsUniqueConnection(true);
|
||||
}
|
||||
|
@ -216,6 +209,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||
brokerService.setPersistent(false);
|
||||
brokerService.addConnector("tcp://localhost:0");
|
||||
brokerService.start();
|
||||
brokerService.waitUntilStarted();
|
||||
|
||||
try {
|
||||
final int numConnections = 2;
|
||||
|
@ -227,8 +221,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||
cf.setCreateConnectionOnStartup(createOnStart);
|
||||
cf.start();
|
||||
|
||||
final ConcurrentHashMap<ConnectionId, Connection> connections =
|
||||
new ConcurrentHashMap<ConnectionId, Connection>();
|
||||
final ConcurrentHashMap<ConnectionId, Connection> connections = new ConcurrentHashMap<ConnectionId, Connection>();
|
||||
final ExecutorService executor = Executors.newFixedThreadPool(numConnections);
|
||||
|
||||
for (int i = 0; i < numConnections; ++i) {
|
||||
|
@ -247,7 +240,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||
}
|
||||
|
||||
executor.shutdown();
|
||||
assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
|
||||
assertTrue(executor.awaitTermination(30, TimeUnit.SECONDS));
|
||||
|
||||
assertEquals("Should have all unique connections", numConnections, connections.size());
|
||||
|
||||
|
@ -277,9 +270,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||
if (!result.isDone() || !result.get().booleanValue()) {
|
||||
PooledConnectionFactoryTest.LOG.error("2nd call to createSession() " +
|
||||
"is blocking but should have returned an error instead.");
|
||||
|
||||
executor.shutdownNow();
|
||||
|
||||
fail("SessionPool inside PooledConnectionFactory is blocking if " +
|
||||
"limit is exceeded but should return an exception instead.");
|
||||
}
|
||||
|
@ -312,8 +303,7 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||
|
||||
Session two = null;
|
||||
try {
|
||||
// this should raise an exception as we called
|
||||
// setMaximumActive(1)
|
||||
// this should raise an exception as we called setMaximumActive(1)
|
||||
two = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
two.close();
|
||||
|
||||
|
@ -331,11 +321,13 @@ public class PooledConnectionFactoryTest extends TestCase {
|
|||
return new Boolean(false);
|
||||
}
|
||||
} finally {
|
||||
if (one != null)
|
||||
if (one != null) {
|
||||
one.close();
|
||||
if (conn != null)
|
||||
}
|
||||
if (conn != null) {
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.error(ex.getMessage());
|
||||
return new Boolean(false);
|
||||
|
|
Loading…
Reference in New Issue