FileDocCategorySizeDatePackage
EntityUnitTestCase.javaAPI DocJBoss 4.2.15209Fri Jul 13 20:53:06 BST 2007org.jboss.ejb3.test.clusteredentity.unit

EntityUnitTestCase

public class EntityUnitTestCase extends org.jboss.test.JBossClusteredTestCase
Sample client for the jboss container.
author
Bill Burke
version
$Id: EntityUnitTestCase.java 60697 2007-02-20 05:08:31Z bstansberry@jboss.com $

Fields Summary
Logger
log
private static final long
SLEEP_TIME
static boolean
deployed
static int
test
Constructors Summary
public EntityUnitTestCase(String name)


     
   

      super(name);

   
Methods Summary
protected booleanisOptimistic()

      return false;
   
public static junit.framework.Testsuite()

      return getDeploySetup(EntityUnitTestCase.class, "clusteredentity-test.jar");
   
public voidtestAll()

      System.out.println("*** testServerFound()");
      String node0 = System.getProperty("jbosstest.cluster.node0");
      String node1 = System.getProperty("jbosstest.cluster.node1");
        
      Properties prop0 = new Properties();
      prop0.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
      prop0.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
      prop0.put("java.naming.provider.url", "jnp://" + node0 + ":1099");
      
      System.out.println("===== Node0 properties: ");
      System.out.println(prop0);
      
      Properties prop1 = new Properties();
      prop1.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
      prop1.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
      prop1.put("java.naming.provider.url", "jnp://" + node1 + ":1099");

      System.out.println("===== Node1 properties: ");
      System.out.println(prop1);

      System.out.println("Lookup node 0");
      InitialContext ctx0 = new InitialContext(prop0);
      
      System.out.println("Create node 0");
      EntityTest tester0 = (EntityTest)ctx0.lookup("EntityTestBean/remote");
      
      try
      {
         tester0.getCache(isOptimistic());
         
         Customer customer = tester0.createCustomer();
         
         //Call finder twice since Hibernate seems to not actually save collections 
         //into cache on persist(), so make sure it is put into cache on find.       
         System.out.println("Find node 0");
         customer = tester0.findByCustomerId(customer.getId());
         System.out.println("Find(2) node 0");
         customer = tester0.findByCustomerId(customer.getId());
         
         //Check everything was in cache
         System.out.println("Check cache 0");
         try
         {
            tester0.loadedFromCache();
         }
         catch (Exception e)
         {
            log.info("Call to tester0 failed", e);
            fail(e.getMessage());
         }
   
         // The above placement of the collection in the cache is replicated async
         // so pause a bit before checking node 1
         sleep(SLEEP_TIME);
         
         //Now connect to cache on node2 and make sure it is all there
         System.out.println("Lookup node 1");
         InitialContext ctx1 = new InitialContext(prop1);
         
         EntityTest tester1 = (EntityTest)ctx1.lookup("EntityTestBean/remote");
         tester1.getCache(isOptimistic());
         
         System.out.println("Find node 1");
         customer = tester1.findByCustomerId(customer.getId());
   
         //Check everything was in cache
         System.out.println("Check cache 1");
         try
         {
            tester1.loadedFromCache();
         }
         catch (Exception e)
         {
            log.info("Call to tester1 failed", e);
            fail(e.getMessage());
         }
      }
      finally
      {
         // cleanup the db so we can run this test multiple times w/o restarting the cluster
         tester0.cleanup();
      }