[jboss-cvs] JBossAS SVN: r58826 - branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Dec 4 01:50:40 EST 2006
Author: bstansberry at jboss.com
Date: 2006-12-04 01:50:39 -0500 (Mon, 04 Dec 2006)
New Revision: 58826
Added:
branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/EmbeddedIdClassloaderTestCase.java
Log:
Add a test with @EmbeddedId
Added: branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/EmbeddedIdClassloaderTestCase.java
===================================================================
--- branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/EmbeddedIdClassloaderTestCase.java 2006-12-04 06:50:13 UTC (rev 58825)
+++ branches/Branch_4_0/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/EmbeddedIdClassloaderTestCase.java 2006-12-04 06:50:39 UTC (rev 58826)
@@ -0,0 +1,162 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.clusteredentity.unit;
+
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.naming.InitialContext;
+import org.jboss.ejb3.test.clusteredentity.Customer;
+import org.jboss.ejb3.test.clusteredentity.EntityTest;
+import org.jboss.ejb3.test.clusteredentity.classloader.EntityQueryTest;
+import org.jboss.ejb3.test.clusteredentity.embeddedid.MusicianPK;
+import org.jboss.ejb3.test.clusteredentity.embeddedid.EmbeddedIdTest;
+import org.jboss.test.JBossClusteredTestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Simple test of replication of entities and related queries with @EmbeddedId
+ * fields involved.
+ *
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.1 $
+ */
+public class EmbeddedIdClassloaderTestCase
+extends JBossClusteredTestCase
+{
+ private org.apache.log4j.Category log = getLog();
+
+ protected static final long SLEEP_TIME = 300L;
+
+ private EmbeddedIdTest sfsb0;
+ private EmbeddedIdTest sfsb1;
+
+ public EmbeddedIdClassloaderTestCase(String name)
+ {
+ super(name);
+ }
+
+ protected void setUp() throws Exception
+ {
+ sfsb0 = getUserTest(System.getProperty("jbosstest.cluster.node0"));
+ sfsb1 = getUserTest(System.getProperty("jbosstest.cluster.node1"));
+ sfsb0.cleanup();
+ sfsb1.cleanup();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ if (sfsb0 != null)
+ {
+ try
+ {
+ sfsb0.remove();
+ }
+ catch (Exception e) {}
+ }
+ if (sfsb1 != null)
+ {
+ try
+ {
+ sfsb1.remove();
+ }
+ catch (Exception e) {}
+ }
+
+ sfsb0 = sfsb1 = null;
+ }
+
+ protected EmbeddedIdTest getUserTest(String nodeJNDIAddress) throws Exception
+ {
+ 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("clusteredentity-embeddedid-test/EmbeddedIdTestBean/remote");
+
+ }
+
+ public void testQuery() throws Exception
+ {
+ 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();
+ }
+ }
+
+ private void queryByInstrument(EmbeddedIdTest sfsb, 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 void sleep(long millis)
+ {
+ try
+ {
+ Thread.sleep(millis);
+ }
+ catch (InterruptedException e)
+ {
+ log.warn("Interrupted while sleeping", e);
+ }
+ }
+
+ public static Test suite() throws Exception
+ {
+
+ 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;
+ }
+}
More information about the jboss-cvs-commits
mailing list