use of org.apache.openejb.util.CountingLatch in project tomee by apache.
the class FullPoolFailoverTest method testStatelessBeanTimeout.
public void testStatelessBeanTimeout() throws Exception {
setup(10, 20);
Client.addRetryCondition(ConcurrentAccessTimeoutException.class);
resume = new CountDownLatch(1);
paused = new CountingLatch(10);
// Do a business method...
final Runnable r = new Runnable() {
public void run() {
counter.hit();
}
};
hold.add(red);
for (int i = 0; i < 10; i++) {
Thread t = new Thread(r);
t.start();
}
// Wait for the beans to reach the start line
try {
if (!paused.await(3000, TimeUnit.MILLISECONDS)) {
System.out.println();
}
} catch (final Throwable t) {
System.out.println();
}
assertTrue("expected 10 invocations", paused.await(3000, TimeUnit.MILLISECONDS));
assertEquals(10, CounterBean.instances.get());
assertEquals(10, hits.size());
final List<URI> expected = new ArrayList<URI>();
for (int i = 0; i < 10; i++) {
expected.add(red);
}
assertEquals(expected, hits);
// This one should failover to the blue server
try {
counter.hit();
fail("Expected ConcurrentAccessTimeoutException");
} catch (ConcurrentAccessTimeoutException e) {
// both "red" and "blue" servers are technically using the
// same stateless session bean pool, which is fully busy
// but ... this exception should have come from the "blue" server
}
// one more hit on red that should have failed over to blue
expected.add(red);
expected.add(blue);
assertEquals(expected, hits);
// then it should fail back to red
try {
counter.hit();
fail("Expected ConcurrentAccessTimeoutException");
} catch (ConcurrentAccessTimeoutException e) {
}
expected.add(blue);
expected.add(red);
assertEquals(expected, hits);
// go
resume.countDown();
}
use of org.apache.openejb.util.CountingLatch in project tomee by apache.
the class FullPoolFailoverTest method testConnectionPoolTimeout.
public void testConnectionPoolTimeout() throws Exception {
setup(30, 10);
resume = new CountDownLatch(1);
// This is used to cause invoking threads to pause
// so all pools can be depleted
paused = new CountingLatch(10);
// Do a business method...
final Runnable r = new Runnable() {
public void run() {
counter.hit();
}
};
hold.add(red);
List<URI> expected = new ArrayList<URI>();
for (int i = 0; i < 10; i++) {
expected.add(red);
Thread t = new Thread(r);
t.start();
}
// Wait for the beans to reach the start line
assertTrue("expected 10 invocations", paused.await(3000, TimeUnit.MILLISECONDS));
assertEquals(10, CounterBean.instances.get());
assertEquals(10, hits.size());
assertEquals(expected, hits);
// This one should failover to the blue server
final URI uri = counter.hit();
assertEquals(blue, uri);
// the red pool is fully busy, so we should have failed over to blue
expected.add(blue);
assertEquals(expected, hits);
// Now hold blue as well
hold.add(blue);
for (int i = 0; i < 10; i++) {
paused.countUp();
expected.add(blue);
final Thread t = new Thread(r);
t.start();
}
// Wait for the beans to reach the start line
assertTrue("expected 20 invocations", paused.await(3000, TimeUnit.MILLISECONDS));
// The extra 10 invocations should all have been on the "blue" server
assertEquals(expected, hits);
// then it should fail back to red
try {
counter.hit();
fail("Expected javax.ejb.EJBException");
} catch (javax.ejb.EJBException e) {
}
// there should be no hits on any server, both connection pools are fully busy
assertEquals(expected, hits);
// go
resume.countDown();
}
Aggregations