[jbosscache-commits] JBoss Cache SVN: r4666 - in core/trunk/src: main/java/org/jboss/cache/interceptors and 3 other directories.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Mon Oct 22 21:40:26 EDT 2007
Author: manik.surtani at jboss.com
Date: 2007-10-22 21:40:26 -0400 (Mon, 22 Oct 2007)
New Revision: 4666
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
core/trunk/src/test/java/org/jboss/cache/api/pfer/PutForExternalReadTestBase.java
core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java
core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/invalidation/VersionInconsistencyTest.java
Log:
More fixes, and patched a broken test
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-10-22 23:57:59 UTC (rev 4665)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-10-23 01:40:26 UTC (rev 4666)
@@ -2760,15 +2760,31 @@
NodeSPI nodeSPI = peek(fqn, false, true);
if (nodeSPI == null)
{
+ log.trace("Node doesn't exist; creating a tombstone");
// create the node we need.
Map<K, V> m = Collections.emptyMap();
InvocationContext ic = getInvocationContext();
boolean origCacheModeLocal = ic.getOptionOverrides().isCacheModeLocal();
ic.getOptionOverrides().setCacheModeLocal(true);
- put(fqn, m);
- ic.getOptionOverrides().setCacheModeLocal(origCacheModeLocal);
+ // if we are in a tx this call should happen outside of any tx
+ try
+ {
+ Transaction suspended = null;
+ if (getTransactionManager() != null)
+ {
+ suspended = getTransactionManager().suspend();
+ }
+ put(fqn, m);
+ if (suspended != null) getTransactionManager().resume(suspended);
+ ic.getOptionOverrides().setCacheModeLocal(origCacheModeLocal);
+ }
+ catch (Exception e)
+ {
+ log.error("Unable to create tombstone!", e);
+ }
nodeSPI = (NodeSPI) root.getChild(fqn);
}
+ log.trace("Retrieved node. Setting version to " + versionToInvalidate + " and marking as invalid");
nodeSPI.setVersion(versionToInvalidate);
// mark the node to be removed (and all children) as invalid so anyone holding a direct reference to it will
// be aware that it is no longer valid.
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java 2007-10-22 23:57:59 UTC (rev 4665)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java 2007-10-23 01:40:26 UTC (rev 4666)
@@ -63,7 +63,7 @@
{
MethodCall m = ctx.getMethodCall();
Option optionOverride = ctx.getOptionOverrides();
- if (optionOverride != null && optionOverride.isCacheModeLocal() && ctx.getTransaction() == null)
+ if (optionOverride != null && optionOverride.isCacheModeLocal() && (ctx.getTransaction() == null || MethodDeclarations.isTransactionLifecycleMethod(m.getMethodId())))
{
// skip replication!!
return super.invoke(ctx);
@@ -77,7 +77,7 @@
// now see if this is a CRUD method:
if (MethodDeclarations.isCrudMethod(m.getMethodId()))
{
- if (m.getMethodId() != MethodDeclarations.putForExternalReadMethodLocal_id)
+ if (m.getMethodId() != MethodDeclarations.putForExternalReadMethodLocal_id && m.getMethodId() != MethodDeclarations.putForExternalReadVersionedMethodLocal_id)
{
if (log.isDebugEnabled()) log.debug("Is a CRUD method");
Set<Fqn> fqns = new HashSet<Fqn>();
Modified: core/trunk/src/test/java/org/jboss/cache/api/pfer/PutForExternalReadTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/pfer/PutForExternalReadTestBase.java 2007-10-22 23:57:59 UTC (rev 4665)
+++ core/trunk/src/test/java/org/jboss/cache/api/pfer/PutForExternalReadTestBase.java 2007-10-23 01:40:26 UTC (rev 4666)
@@ -1,27 +1,7 @@
package org.jboss.cache.api.pfer;
-import static org.easymock.EasyMock.anyBoolean;
-import static org.easymock.EasyMock.anyInt;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import java.lang.reflect.Method;
-import java.util.List;
-
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.easymock.EasyMock;
+import static org.easymock.EasyMock.*;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
import org.jboss.cache.CacheSPI;
@@ -39,10 +19,17 @@
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jgroups.Address;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.lang.reflect.Method;
+import java.util.List;
+
@Test(groups = {"functional", "jgroups", "transaction"})
public abstract class PutForExternalReadTestBase
{
@@ -66,6 +53,8 @@
cache1 = cf.createCache(UnitTestCacheConfigurationFactory.createConfiguration(cacheMode), false);
cache1.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache1.getConfiguration().setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
+ cache1.getConfiguration().setSyncCommitPhase(optimistic);
+ cache1.getConfiguration().setSyncRollbackPhase(optimistic);
cache1.start();
tm1 = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -73,6 +62,8 @@
cache2 = cf.createCache(UnitTestCacheConfigurationFactory.createConfiguration(cacheMode), false);
cache2.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache2.getConfiguration().setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
+ cache2.getConfiguration().setSyncCommitPhase(optimistic);
+ cache2.getConfiguration().setSyncRollbackPhase(optimistic);
cache2.start();
tm2 = cache2.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -215,10 +206,15 @@
// inject a mock RPC manager so that we can test whether calls made are sync or async.
cache1.getConfiguration().getRuntimeConfig().setRPCManager(rpcManager);
- // specify what we expect called on the mock Rpc Manager. For params we don't care about, just use ANYTHING.
- // setting the mock object to expect the "sync" param to be false.
- expect(rpcManager.getReplicationQueue()).andReturn(null);
- expect(rpcManager.callRemoteMethods(anyAddresses(), (Method)anyObject(), (Object[]) anyObject(), eq(false), anyBoolean(), anyInt())).andReturn(null);
+ // invalidations will not trigger any rpc call sfor PFER
+ if (!isUsingInvalidation())
+ {
+ // specify what we expect called on the mock Rpc Manager. For params we don't care about, just use ANYTHING.
+ // setting the mock object to expect the "sync" param to be false.
+ expect(rpcManager.getReplicationQueue()).andReturn(null);
+ expect(rpcManager.callRemoteMethods(anyAddresses(), (Method)anyObject(), (Object[]) anyObject(), eq(false), anyBoolean(), anyInt())).andReturn(null);
+ }
+
replay(rpcManager);
// now try a simple replication. Since the RPCManager is a mock object it will not actually replicate anything.
@@ -291,9 +287,9 @@
{
}
- if (optimistic)
+ if (optimistic && !isUsingInvalidation())
{
- // proves that the put did, in fact, barf.
+ // proves that the put did, in fact, barf. Doesn't work for invalidations since the inability to invalidate will not cause a rollback.
assertNull(cache1.get(fqn, key));
}
else
@@ -302,7 +298,8 @@
try
{
cache1.removeNode(fqn);
- fail("Should have barfed");
+ // as above, the inability to invalidate will not cause an exception
+ if (!isUsingInvalidation()) fail("Should have barfed");
}
catch (RuntimeException re)
{
Modified: core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java 2007-10-22 23:57:59 UTC (rev 4665)
+++ core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java 2007-10-23 01:40:26 UTC (rev 4666)
@@ -6,17 +6,17 @@
*/
package org.jboss.cache.factories;
-import java.io.InputStream;
-
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.transaction.TransactionSetup;
import org.jboss.cache.xml.XmlHelper;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
+import java.io.InputStream;
+
/**
* Cache configuration factory used by unit tests.
*/
@@ -94,7 +94,7 @@
public Configuration parseFile(String filename, CacheMode mode)
{
- return parseStream(getAsInputStreamFromClassLoader(DEFAULT_CONFIGURATION_FILE), mode);
+ return parseStream(getAsInputStreamFromClassLoader(filename == null ? DEFAULT_CONFIGURATION_FILE : filename), mode);
}
public Configuration parseStream(InputStream stream, CacheMode mode)
@@ -143,6 +143,9 @@
}
}
}
+
+ // either way, set mode in the config!!
+ c.setCacheMode(mode);
return c;
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2007-10-22 23:57:59 UTC (rev 4665)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2007-10-23 01:40:26 UTC (rev 4666)
@@ -29,7 +29,9 @@
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
/**
* Tests the async interceptor
@@ -40,15 +42,18 @@
public class InvalidationInterceptorTest
{
private static Log log = LogFactory.getLog(InvalidationInterceptorTest.class);
- CacheImpl<Object, Object> cache1, cache2;
+ private CacheImpl<Object, Object> cache1, cache2;
+ private Set<CacheImpl> toClean = new HashSet<CacheImpl>();
@AfterMethod
public void tearDown()
{
- TestingUtil.killCaches(cache1);
- TestingUtil.killCaches(cache2);
+ TestingUtil.killCaches(cache1, cache2);
+ for (CacheImpl c : toClean) TestingUtil.killCaches(c);
+ toClean.clear();
}
+
public void testPessimisticNonTransactional() throws Exception
{
cache1 = createCache(false);
@@ -211,8 +216,8 @@
cache2.put(fqn, "key", "value");
Assert.assertEquals("value", cache2.get(fqn, "key"));
Node n = cache1.get(fqn);
- assert n != null : "Should not be null";
- assert n.getKeys().isEmpty() : "But should not contain any data";
+ assertHasBeenInvalidated(n, "Should have been invalidated");
+ assertHasBeenInvalidated(cache1.peek(fqn, true, true), "Should have been invalidated");
// start a tx that cache1 will have to send out an evict ...
TransactionManager mgr1 = cache1.getTransactionManager();
@@ -480,8 +485,8 @@
// test that this has NOT replicated, but rather has been invalidated:
Assert.assertEquals("value", cache1.get(fqn, "key"));
Node n2 = cache2.get(fqn);
- assert n2 != null : "Should NOT be null; we need to have version info on all instances.";
- assert n2.get("key") == null : "Data should not have replicated!";
+ assertHasBeenInvalidated(n2, "Should have been invalidated");
+ assertHasBeenInvalidated(cache2.peek(fqn, true, true), "Should have been invalidated");
// now make sure cache2 is in sync with cache1:
cache2.put(fqn, "key", "value");
@@ -668,16 +673,7 @@
caches.get(0).put(fqn, "key", "value");
assertEquals("expecting value", "value", caches.get(0).get(fqn, "key"));
Node n = caches.get(1).get(fqn);
- if (optimistic)
- {
- assert n != null : "Should NOT be null";
- assert n.getKeys().isEmpty() : "but should be empty";
- }
- else
- {
- // only opt locking requires a stub node created on invalidation to hold the data version
- assert n == null : "Should be null!";
- }
+ assertHasBeenInvalidated(n, "Should have been invalidated");
// now put in caches.get(1), should fire an eviction
caches.get(1).put(fqn, "key", "value2");
@@ -694,6 +690,7 @@
cache.getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
if (optimistic) cache.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ toClean.add(cache);
return cache;
}
@@ -701,6 +698,7 @@
{
CacheImpl<Object, Object> cache = createUnstartedCache(optimistic);
cache.start();
+ toClean.add(cache);
return cache;
}
@@ -715,6 +713,7 @@
caches.get(0).start();
caches.get(1).start();
+ toClean.addAll(caches);
return caches;
}
Modified: core/trunk/src/test/java/org/jboss/cache/invalidation/VersionInconsistencyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/VersionInconsistencyTest.java 2007-10-22 23:57:59 UTC (rev 4665)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/VersionInconsistencyTest.java 2007-10-23 01:40:26 UTC (rev 4666)
@@ -1,20 +1,20 @@
package org.jboss.cache.invalidation;
-import org.testng.annotations.Test;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.AfterTest;
import org.jboss.cache.Cache;
+import org.jboss.cache.CacheImpl;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
-import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.optimistic.DefaultDataVersion;
-import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
-import org.jboss.cache.config.Configuration;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
-import javax.transaction.Transaction;
/**
* This test simulates the problem described in JBCACHE-1155
@@ -91,7 +91,7 @@
assert val.equals("v-newer");
// test node versions
- NodeSPI n = (NodeSPI) cache1.getRoot().getChild(node);
+ NodeSPI n = (NodeSPI) ((CacheImpl) cache1).peek(node, true, true);
assert ((DefaultDataVersion) n.getVersion()).getRawVersion() == 1 : "Version should be 1";
}
}
More information about the jbosscache-commits
mailing list