AsynchronousTestCasepublic class AsynchronousTestCase extends org.jboss.test.JBossTestCase
Fields Summary |
---|
private static final Logger | log | static boolean | deployed | static int | test |
Constructors Summary |
---|
public AsynchronousTestCase(String name)
super(name);
|
Methods Summary |
---|
private java.lang.Object | getReturnOrException(org.jboss.aspects.asynch.AsynchProvider provider)
try
{
Future future = provider.getFuture();
waitForFuture(future);
return future.get();
}
catch(InvocationTargetException e)
{
return e.getCause();
}
| public static junit.framework.Test | suite()
return getDeploySetup(AsynchronousTestCase.class, "asynchronous-test.sar, asynchronous-test.jar");
| public void | testAsynchSecurity()
SecuredStatelessRemote tester =
(SecuredStatelessRemote) getInitialContext().lookup("SecuredStatelessBean/remote");
SecuredStatelessRemote asynchTester = (SecuredStatelessRemote)((JBossProxy)tester).getAsynchronousProxy();
AsynchProvider ap = (AsynchProvider)asynchTester;
SecurityAssociation.setPrincipal(new SimplePrincipal("rolefail"));
SecurityAssociation.setCredential("password".toCharArray());
asynchTester.method(61);
Object ret = getReturnOrException(ap);
assertTrue("SecurityException not thrown: " + ret, ret instanceof EJBAccessException);
asynchTester.uncheckedMethod(62);
ret = getReturnOrException(ap);
assertEquals("Wrong value", 62, ret);
asynchTester.excludedMethod(63);
ret = getReturnOrException(ap);
assertTrue("SecurityException not thrown: " + ret, ret instanceof EJBAccessException);
SecurityAssociation.setPrincipal(new SimplePrincipal("somebody"));
SecurityAssociation.setCredential("password".toCharArray());
asynchTester.method(64);
ret = getReturnOrException(ap);
assertEquals("Wrong return for authorised method", 64, ret);
SecurityAssociation.setPrincipal(new SimplePrincipal("nosuchuser"));
SecurityAssociation.setCredential("password".toCharArray());
asynchTester.method(65);
ret = getReturnOrException(ap);
assertTrue("SecurityException not thrown: " + ret, ret instanceof EJBAccessException);
| public void | testLocalAsynchTransaction()
MBeanServerConnection server = getServer();
ObjectName testerName = new ObjectName("jboss.ejb3:service=Tester,test=asynchronous");
Object[] params = {};
String[] sig = {};
server.invoke(testerName, "testLocalAsynchTransaction", params, sig);
| public void | testRemoteAsynchTransaction()
TxSessionRemote tester = (TxSessionRemote) getInitialContext().lookup("TxSessionBean/remote");
TxSessionRemote asynchTester = (TxSessionRemote)((JBossProxy)tester).getAsynchronousProxy();
AsynchProvider ap = (AsynchProvider) asynchTester;
UserTransaction tx = (UserTransaction)getInitialContext().lookup("UserTransaction");
//Add some entries in different threads and commit
tx.begin();
tester.createFruit("apple", false);
tester.createFruit("pear", false);
tester.createFruit("tomato", false);
asynchTester.createVeg("Potato", false);
waitForProvider(ap);
asynchTester.createVeg("Turnip", false);
waitForProvider(ap);
asynchTester.createVeg("Carrot", false);
waitForProvider(ap);
tx.commit();
tx.begin();
Collection entries = tester.getEntries();
tx.commit();
assertEquals("Wrong number of entries", 6, entries.size());
//Cleanup synchronously
tx.begin();
tester.cleanAll();
tx.commit();
tx.begin();
entries = tester.getEntries();
tx.commit();
assertEquals("Wrong number of entries", 0, entries.size());
//Add some entries in different threads and rollback
tx.begin();
tester.createFruit("apple", false);
tester.createFruit("pear", false);
tester.createFruit("tomato", false);
asynchTester.createVeg("Potato", false);
waitForProvider(ap);
asynchTester.createVeg("Turnip", false);
waitForProvider(ap);
asynchTester.createVeg("Carrot", false);
waitForProvider(ap);
tx.rollback();
tx.begin();
entries = tester.getEntries();
tx.commit();
assertEquals("Wrong number of entries", 0, entries.size());
//Add some entries in different threads and rollback from within Tx
tx.begin();
tester.createFruit("apple", false);
tester.createFruit("pear", false);
tester.createFruit("tomato", true);
asynchTester.createVeg("Potato", false);
waitForProvider(ap);
asynchTester.createVeg("Turnip", false);
waitForProvider(ap);
asynchTester.createVeg("Carrot", true);
waitForProvider(ap);
boolean rollbackException = false;
try
{
tx.commit();
}
catch(RollbackException e)
{
rollbackException = true;
}
assertTrue("RollbackException not picked up", rollbackException);
tx.begin();
entries = tester.getEntries();
tx.commit();
assertEquals("Wrong number of entries", 0, entries.size());
| public void | testSFClusteredAsynchronous()
StatefulClusteredRemote tester =
(StatefulClusteredRemote) getInitialContext().lookup("StatefulClusteredBean/remote");
assertEquals("Wrong return for stateful clustered", 41, tester.method(41));
StatefulClusteredRemote asynchTester = (StatefulClusteredRemote)((JBossProxy)tester).getAsynchronousProxy();
assertEquals("Wrong return value for stateful clustered", 0, asynchTester.method(42));
AsynchProvider ap = (AsynchProvider) asynchTester;
Future future = ap.getFuture();
int ret = (Integer) future.get();
assertEquals("Wrong async return value for stateful clustered", ret, 42);
| public void | testSFLocalAsynchrounous()
MBeanServerConnection server = getServer();
ObjectName testerName = new ObjectName("jboss.ejb3:service=Tester,test=asynchronous");
Object[] params = {};
String[] sig = {};
server.invoke(testerName, "testSFLocalAsynchronous", params, sig);
| public void | testSFRemoteAsynchronous()
StatefulRemote tester =
(StatefulRemote) getInitialContext().lookup("StatefulBean/remote");
assertEquals("Wrong return for stateful remote", 31, tester.method(31));
StatefulRemote asynchTester = (StatefulRemote)((JBossProxy)tester).getAsynchronousProxy();
assertEquals("Wrong return value for stateful remote", 0, asynchTester.method(32));
AsynchProvider ap = (AsynchProvider) asynchTester;
Future future = ap.getFuture();
int ret = (Integer) future.get();
assertEquals("Wrong async return value for stateful remote", ret, 32);
| public void | testSLClusteredAsynchronous()
StatelessClusteredRemote tester =
(StatelessClusteredRemote) getInitialContext().lookup("StatelessClusteredBean/remote");
assertEquals("Wrong return for stateless clustered", 21, tester.method(21));
StatelessClusteredRemote asynchTester = (StatelessClusteredRemote)((JBossProxy)tester).getAsynchronousProxy();
assertEquals("Wrong return value for stateless clustered", 0, asynchTester.method(22));
AsynchProvider ap = (AsynchProvider) asynchTester;
Future future = ap.getFuture();
int ret = (Integer) future.get();
assertEquals("Wrong async return value for stateless clustered", ret, 22);
| public void | testSLLocalAsynchrounous()
MBeanServerConnection server = getServer();
ObjectName testerName = new ObjectName("jboss.ejb3:service=Tester,test=asynchronous");
Object[] params = {};
String[] sig = {};
server.invoke(testerName, "testSLLocalAsynchronous", params, sig);
| public void | testSLRemoteAsynchronous()
StatelessRemote tester =
(StatelessRemote) getInitialContext().lookup("StatelessBean/remote");
assertEquals("Wrong return for stateless remote", 11, tester.method(11));
StatelessRemote asynchTester = (StatelessRemote)Asynch.getAsynchronousProxy(tester);
assertEquals("Wrong return value for stateless remote", 0, asynchTester.method(12));
Future future = Asynch.getFutureResult(asynchTester);
int ret = (Integer) future.get();
assertEquals("Wrong async return value for stateless remote", ret, 12);
| public void | testServiceLocalAsynchrounous()
MBeanServerConnection server = getServer();
ObjectName testerName = new ObjectName("jboss.ejb3:service=Tester,test=asynchronous");
Object[] params = {};
String[] sig = {};
server.invoke(testerName, "testServiceLocalAsynchronous", params, sig);
| public void | testServiceRemoteAsynchronous()
ServiceRemote tester =
(ServiceRemote) getInitialContext().lookup("ServiceBean/remote");
assertEquals("Wrong return for service remote", 51, tester.method(51));
ServiceRemote asynchTester = (ServiceRemote)((JBossProxy)tester).getAsynchronousProxy();
assertEquals("Wrong return value for service remote", 0, asynchTester.method(52));
AsynchProvider ap = (AsynchProvider) asynchTester;
Future future = ap.getFuture();
int ret = (Integer) future.get();
assertEquals("Wrong async return value for service remote", ret, 52);
| private void | waitForFuture(org.jboss.aspects.asynch.Future future)
while (!future.isDone())
{
Thread.sleep(100);
}
| private void | waitForProvider(org.jboss.aspects.asynch.AsynchProvider provider)
Future future = provider.getFuture();
waitForFuture(future);
|
|