FileDocCategorySizeDatePackage
Tester.javaAPI DocJBoss 4.2.17344Fri Jul 13 20:53:36 BST 2007org.jboss.ejb3.test.asynchronous

Tester

public class Tester extends Object implements TesterMBean
author
Kabir Khan
version
$Revision: 57207 $

Fields Summary
Constructors Summary
Methods Summary
public voidtestLocalAsynchTransaction()

      InitialContext ctx = new InitialContext();
      TxSessionLocal tester = (TxSessionLocal) ctx.lookup("TxSessionBean/local");
      TxSessionLocal asynchTester = (TxSessionLocal)((JBossProxy)tester).getAsynchronousProxy();
      AsynchProvider ap = (AsynchProvider) asynchTester;
      TransactionManager tx = (TransactionManager) ctx.lookup(TransactionManagerService.JNDI_NAME);

      //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();
      if (entries.size() != 6) throw new RuntimeException("Wrong number of entries, should have been 6, have: " + entries.size());

      //Cleanup synchronously
      tx.begin();
      tester.cleanAll();
      tx.commit();

      tx.begin();
      entries = tester.getEntries();
      tx.commit();
      if (entries.size() != 0) throw new RuntimeException("Wrong number of entries, should have been 0, have: " + 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();

      if (entries.size() != 0) throw new RuntimeException("Wrong number of entries, should have been 0, have: " + 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;
      }

      if (!rollbackException) throw new RuntimeException("RollbackException not picked up");

      tx.begin();
      entries = tester.getEntries();
      tx.commit();
      if (entries.size() != 0) throw new RuntimeException("Wrong number of entries, should have been 0, have: " + entries.size());
   
public voidtestSFLocalAsynchronous()

      Context ctx = new InitialContext();
      StatefulLocal tester =
            (StatefulLocal) ctx.lookup("StatefulBean/local");
      int ret = tester.method(121);
      if (ret != 121) throw new RuntimeException("Wrong return for stateful local "+ ret);

      StatefulLocal asynchTester = (StatefulLocal)((JBossProxy)tester).getAsynchronousProxy();
      ret = asynchTester.method(122);
      if (ret != 0) throw new RuntimeException("Wrong return value for stateful local "+ ret);
      AsynchProvider ap = (AsynchProvider) asynchTester;
      Future future = ap.getFuture();
      ret = (Integer) future.get();
      if (ret != 122) throw new RuntimeException("Wrong async return value for stateful local "+ ret);
   
public voidtestSLLocalAsynchronous()

      Context ctx = new InitialContext();
      StatelessLocal tester =
            (StatelessLocal) ctx.lookup("StatelessBean/local");
      int ret = tester.method(111);
      if (ret != 111) throw new RuntimeException("Wrong return for stateless local "+ ret);

      StatelessLocal asynchTester = (StatelessLocal)((JBossProxy)tester).getAsynchronousProxy();
      ret = asynchTester.method(112);
      if (ret != 0) throw new RuntimeException("Wrong return value for stateless local "+ ret);
      AsynchProvider ap = (AsynchProvider) asynchTester;
      Future future = ap.getFuture();
      ret = (Integer) future.get();
      if (ret != 112) throw new RuntimeException("Wrong async return value for stateless local "+ ret);
   
public voidtestServiceLocalAsynchronous()

      Context ctx = new InitialContext();
      ServiceLocal tester =
            (ServiceLocal) ctx.lookup("ServiceBean/local");
      int ret = tester.method(131);
      if (ret != 131) throw new RuntimeException("Wrong return for service local "+ ret);

      ServiceLocal asynchTester = (ServiceLocal)((JBossProxy)tester).getAsynchronousProxy();
      ret = asynchTester.method(132);
      if (ret != 0) throw new RuntimeException("Wrong return value for service local "+ ret);
      AsynchProvider ap = (AsynchProvider) asynchTester;
      Future future = ap.getFuture();
      ret = (Integer) future.get();
      if (ret != 132) throw new RuntimeException("Wrong async return value for service local "+ ret);
   
private voidwaitForFuture(org.jboss.aspects.asynch.Future future)

      while (!future.isDone())
      {
         Thread.sleep(100);
      }
   
private voidwaitForProvider(org.jboss.aspects.asynch.AsynchProvider provider)

      Future future = provider.getFuture();
      waitForFuture(future);