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

EmbeddedIdClassloaderTestCase

public class EmbeddedIdClassloaderTestCase extends org.jboss.test.JBossClusteredTestCase
Simple test of replication of entities and related queries with @EmbeddedId fields involved.
author
Brian Stansberry
version
$Revision: 60233 $

Fields Summary
private Logger
log
protected static final long
SLEEP_TIME
private org.jboss.ejb3.test.clusteredentity.embeddedid.EmbeddedIdTest
sfsb0
private org.jboss.ejb3.test.clusteredentity.embeddedid.EmbeddedIdTest
sfsb1
Constructors Summary
public EmbeddedIdClassloaderTestCase(String name)

   
     
   
      super(name);
   
Methods Summary
protected java.lang.StringgetEarName()

      return "clusteredentity-embeddedid-test";
   
protected org.jboss.ejb3.test.clusteredentity.embeddedid.EmbeddedIdTestgetUserTest(java.lang.String nodeJNDIAddress)

      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://" + nodeJNDIAddress + ":1099");
   
      log.info("===== Naming properties for " + nodeJNDIAddress + ": ");
      log.info(prop1);
      log.info("Create InitialContext for " + nodeJNDIAddress);
      InitialContext ctx1 = new InitialContext(prop1);
   
      log.info("Lookup sfsb from " + nodeJNDIAddress);
      return (EmbeddedIdTest) ctx1.lookup(getEarName() + "/EmbeddedIdTestBean/remote");
      
   
private voidqueryByInstrument(org.jboss.ejb3.test.clusteredentity.embeddedid.EmbeddedIdTest sfsb, java.lang.String instrument, boolean useNamedRegion)

      List<MusicianPK> pks = sfsb.getMusiciansForInstrument(instrument, useNamedRegion);
      assertNotNull("Got pks", pks);
      assertEquals("Got one pk", 1, pks.size());
      assertEquals("Got correct pks", EmbeddedIdTest.DEFAULT_PK, pks.get(0));
   
protected voidsetUp()

      super.setUp();
      
      sfsb0 = getUserTest(System.getProperty("jbosstest.cluster.node0"));
      sfsb1 = getUserTest(System.getProperty("jbosstest.cluster.node1"));  
      sfsb0.cleanup();
      sfsb1.cleanup();
   
protected voidsleep(long millis)

      try
      {
         Thread.sleep(millis);
      }
      catch (InterruptedException e)
      {
         log.warn("Interrupted while sleeping", e);
      }
   
public static junit.framework.Testsuite()


      TestSuite suite = new TestSuite();
      Test t1 = getDeploySetup(EmbeddedIdClassloaderTestCase.class, 
                               "clusteredentity-embeddedid-test.ear");

      suite.addTest(t1);

      // Create an initializer for the test suite
      DBSetup wrapper = new DBSetup(suite);
      return wrapper;
   
protected voidtearDown()

      if (sfsb0 != null)
      {
         try
         {
            sfsb0.remove();
         }
         catch (Exception e) {}
      }
      if (sfsb1 != null)
      {
         try
         {
            sfsb1.remove();
         }
         catch (Exception e) {}
      }
      
      sfsb0 = sfsb1 = null;
   
public voidtestQuery()

      try
      {
         sfsb0.createMusician(EmbeddedIdTest.DEFAULT_PK, "zither");
         
         queryByInstrument(sfsb0, "zither", false);
         queryByInstrument(sfsb0, "zither", true);
         
         // pause to let queries replicate async
         sleep(SLEEP_TIME);
         
         queryByInstrument(sfsb1, "zither", false);
         queryByInstrument(sfsb1, "zither", true);
      }
      finally
      {
         // cleanup the db so we can run this test multiple times w/o restarting the cluster
         sfsb0.cleanup();
      }