[jboss-cvs] JBossAS SVN: r76719 - projects/cluster/hibernate-jbc-cacheprovider/trunk/src/test/java/org/jboss/hibernate/jbc/cacheprovider/functional.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 6 11:43:42 EDT 2008
Author: galder.zamarreno at jboss.com
Date: 2008-08-06 11:43:41 -0400 (Wed, 06 Aug 2008)
New Revision: 76719
Added:
projects/cluster/hibernate-jbc-cacheprovider/trunk/src/test/java/org/jboss/hibernate/jbc/cacheprovider/functional/PessimisticEntityReplicationNoLocalPutsOnlyTest.java
Modified:
projects/cluster/hibernate-jbc-cacheprovider/trunk/src/test/java/org/jboss/hibernate/jbc/cacheprovider/functional/PessimisticEntityReplicationTest.java
Log:
[JBCLUSTER-206] Fixed pessimistic entity replication test that represents default local put only behaivour and added new test with local puts only disabled.
Added: projects/cluster/hibernate-jbc-cacheprovider/trunk/src/test/java/org/jboss/hibernate/jbc/cacheprovider/functional/PessimisticEntityReplicationNoLocalPutsOnlyTest.java
===================================================================
--- projects/cluster/hibernate-jbc-cacheprovider/trunk/src/test/java/org/jboss/hibernate/jbc/cacheprovider/functional/PessimisticEntityReplicationNoLocalPutsOnlyTest.java (rev 0)
+++ projects/cluster/hibernate-jbc-cacheprovider/trunk/src/test/java/org/jboss/hibernate/jbc/cacheprovider/functional/PessimisticEntityReplicationNoLocalPutsOnlyTest.java 2008-08-06 15:43:41 UTC (rev 76719)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.hibernate.jbc.cacheprovider.functional;
+
+import javax.transaction.TransactionManager;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.jboss.cache.TreeCache;
+import org.jboss.hibernate.jbc.cacheprovider.CacheProperties;
+import org.jboss.hibernate.jbc.cacheprovider.functional.util.DualNodeTestUtil;
+import org.jboss.hibernate.jbc.cacheprovider.functional.util.TestCacheInstanceManager;
+
+/**
+ * PessimisticEntityReplicationNoLocalPutsOnlyTest.
+ *
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class PessimisticEntityReplicationNoLocalPutsOnlyTest extends PessimisticEntityReplicationTest
+{
+ public PessimisticEntityReplicationNoLocalPutsOnlyTest(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ protected void configureCacheFactory(Configuration cfg)
+ {
+ cfg.setProperty(Environment.CACHE_PROVIDER_CONFIG, PessimisticJBossCacheTest.JBC_CONFIG);
+ cfg.setProperty(Environment.CACHE_PROVIDER, PessimisticJBossCacheTest.JBC_CACHE_PROVIDER);
+ cfg.setProperty(CacheProperties.HIBERNATE_CACHE_LOCAL_PUTS_ONLY_PROPERTY, "false");
+ }
+
+ public void testAll() throws Exception
+ {
+ System.out.println("*** " + getName());
+
+ // Bind a listener to the "local" cache
+ // Our region factory makes its CacheManager available to us
+ TreeCache localCache = TestCacheInstanceManager.getTreeCache(DualNodeTestUtil.LOCAL);
+ MyListener localListener = new MyListener();
+ localCache.addTreeCacheListener(localListener);
+ TransactionManager localTM = localCache.getTransactionManager();
+
+ // Bind a listener to the "remote" cache
+ TreeCache remoteCache = TestCacheInstanceManager.getTreeCache(DualNodeTestUtil.REMOTE);
+ MyListener remoteListener = new MyListener();
+ remoteCache.addTreeCacheListener(remoteListener);
+
+ TransactionManager remoteTM = remoteCache.getTransactionManager();
+
+ SessionFactory localFactory = getEnvironment().getSessionFactory();
+ SessionFactory remoteFactory = getSecondNodeEnvironment().getSessionFactory();
+
+ try
+ {
+ System.out.println("Create node 0");
+ IdContainer ids = createCustomer(localFactory, localTM);
+
+ // Sleep a bit to let async commit propagate. Really just to
+ // help keep the logs organized for debugging any issues
+ sleep(SLEEP_TIME);
+
+ System.out.println("Find node 0");
+ // This actually brings the collection into the cache
+ getCustomer(ids.customerId, localFactory, localTM);
+
+ sleep(SLEEP_TIME);
+
+ // Now the collection is in the cache so, the 2nd "get"
+ // should read everything from the cache
+ System.out.println("Find(2) node 0");
+ localListener.clear();
+ getCustomer(ids.customerId, localFactory, localTM);
+
+ //Check the read came from the cache
+ System.out.println("Check cache 0");
+ assertLoadedFromCache(localListener, ids.customerId, ids.contactIds);
+
+ System.out.println("Find node 1");
+ getCustomer(ids.customerId, remoteFactory, remoteTM);
+
+ //Check everything was in cache
+ System.out.println("Check cache 1");
+ assertLoadedFromCache(remoteListener, ids.customerId, ids.contactIds);
+ }
+ finally
+ {
+ // cleanup the db
+ System.out.println("Cleaning up");
+ cleanup(localFactory, localTM);
+ }
+ }
+}
Modified: projects/cluster/hibernate-jbc-cacheprovider/trunk/src/test/java/org/jboss/hibernate/jbc/cacheprovider/functional/PessimisticEntityReplicationTest.java
===================================================================
--- projects/cluster/hibernate-jbc-cacheprovider/trunk/src/test/java/org/jboss/hibernate/jbc/cacheprovider/functional/PessimisticEntityReplicationTest.java 2008-08-06 15:43:00 UTC (rev 76718)
+++ projects/cluster/hibernate-jbc-cacheprovider/trunk/src/test/java/org/jboss/hibernate/jbc/cacheprovider/functional/PessimisticEntityReplicationTest.java 2008-08-06 15:43:41 UTC (rev 76719)
@@ -58,7 +58,7 @@
{
private static final Logger log = Logger.getLogger(PessimisticEntityReplicationTest.class);
- private static final long SLEEP_TIME = 50l;
+ protected static final long SLEEP_TIME = 50l;
private static final Integer CUSTOMER_ID = new Integer(1);
@@ -129,7 +129,17 @@
assertLoadedFromCache(localListener, ids.customerId, ids.contactIds);
System.out.println("Find node 1");
+ // With local puts only, this actually brings the collection into the
+ // cache. IOW, putting the customer into the cache in node 0 does not
+ // result on the customer being already available in node 1, we need to
+ // get it.
getCustomer(ids.customerId, remoteFactory, remoteTM);
+
+ sleep(SLEEP_TIME);
+
+ System.out.println("Find(2) node 1");
+ remoteListener.clear();
+ getCustomer(ids.customerId, remoteFactory, remoteTM);
//Check everything was in cache
System.out.println("Check cache 1");
@@ -143,7 +153,7 @@
}
}
- private IdContainer createCustomer(SessionFactory sessionFactory, TransactionManager tm)
+ protected IdContainer createCustomer(SessionFactory sessionFactory, TransactionManager tm)
throws Exception
{
System.out.println("CREATE CUSTOMER");
@@ -201,7 +211,7 @@
}
}
- private Customer getCustomer(Integer id, SessionFactory sessionFactory, TransactionManager tm)
+ protected Customer getCustomer(Integer id, SessionFactory sessionFactory, TransactionManager tm)
throws Exception
{
System.out.println("FIND CUSTOMER");
@@ -234,7 +244,7 @@
}
}
- private void cleanup(SessionFactory sessionFactory, TransactionManager tm) throws Exception
+ protected void cleanup(SessionFactory sessionFactory, TransactionManager tm) throws Exception
{
tm.begin();
try
@@ -264,7 +274,7 @@
}
}
- private void assertLoadedFromCache(MyListener listener, Integer custId, Set contactIds)
+ protected void assertLoadedFromCache(MyListener listener, Integer custId, Set contactIds)
{
assertTrue("Customer#" + custId + " was in cache", listener.visited.contains("Customer#" + custId));
for (Iterator it = contactIds.iterator(); it.hasNext();) {
@@ -285,28 +295,6 @@
{
visited.clear();
}
-
-// @NodeVisited
-// public void nodeVisited(NodeVisitedEvent event)
-// {
-// System.out.println(event);
-//
-// if (!event.isPre())
-// {
-// Fqn fqn = event.getFqn();
-// System.out.println("MyListener - Visiting node " + fqn.toString());
-// String name = fqn.toString();
-// String token = ".functional.";
-// int index = name.indexOf(token);
-// if (index > -1)
-// {
-// index += token.length();
-// name = name.substring(index);
-// System.out.println("MyListener - recording visit to " + name);
-// visited.add(name);
-// }
-// }
-// }
@Override
public void nodeVisited(Fqn fqn)
@@ -327,7 +315,7 @@
}
}
- private class IdContainer
+ class IdContainer
{
Integer customerId;
Set contactIds;
More information about the jboss-cvs-commits
mailing list