JBoss Cache SVN: r4654 - core/trunk/src/main/java/org/jboss/cache.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-10-20 12:46:45 -0400 (Sat, 20 Oct 2007)
New Revision: 4654
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
Log:
JBCACHE-1198 Make PFER failures quieter on remote nodes
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-10-20 14:28:09 UTC (rev 4653)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-10-20 16:46:45 UTC (rev 4654)
@@ -2836,8 +2836,14 @@
}
catch (Throwable ex)
{
- log.warn("replication failure with method_call " + method_call + " exception", ex);
- throw ex;
+ if (method_call.getMethodId() != MethodDeclarations.putForExternalReadMethodLocal_id
+ || method_call.getMethodId() != MethodDeclarations.putForExternalReadVersionedMethodLocal_id )
+ {
+ if (log.isWarnEnabled()) log.warn("replication failure with method_call " + method_call + " exception", ex);
+ throw ex;
+ }
+ else return null;
+
}
}
17 years, 2 months
JBoss Cache SVN: r4653 - in core/trunk/src: main/java/org/jboss/cache/interceptors and 4 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-10-20 10:28:09 -0400 (Sat, 20 Oct 2007)
New Revision: 4653
Removed:
core/trunk/src/test/java/org/jboss/cache/statetransfer/DataVersionTransferTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/NodeSPI.java
core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
core/trunk/src/main/java/org/jboss/cache/VersionedNode.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java
core/trunk/src/test/java/org/jboss/cache/loader/DummyInMemoryCacheLoader.java
core/trunk/src/test/java/org/jboss/cache/loader/DummySharedInMemoryCacheLoader.java
core/trunk/src/test/java/org/jboss/cache/optimistic/DataVersionPersistenceTest.java
Log:
Better fix for JBCACHE-1202
Modified: core/trunk/src/main/java/org/jboss/cache/NodeSPI.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/NodeSPI.java 2007-10-19 18:51:12 UTC (rev 4652)
+++ core/trunk/src/main/java/org/jboss/cache/NodeSPI.java 2007-10-20 14:28:09 UTC (rev 4653)
@@ -444,4 +444,27 @@
* @see org.jboss.cache.Node#isStructural()
*/
void setStructural(boolean structural);
+
+
+ /**
+ * Very similar to {@link #getDataDirect()}, except that this method may also encode some internal data as attributes in the map,
+ * using special <tt>_JBOSS_INTERNAL_XXX</tt> Strings as keys. Designed to be used by {@link org.jboss.cache.statetransfer.StateTransferGenerator}
+ * and {@link org.jboss.cache.interceptors.CacheStoreInterceptor} which attempt to serialize nodes into a stream for storage or transfer.
+ *
+ * @return a map containing data as well as additional information about this node.
+ * @since 2.1.0
+ * @param onlyInternalState if true, the map will only contain internal state and no other data.
+ */
+ Map getInternalState(boolean onlyInternalState);
+
+ /**
+ * Very similar to {@link #putAllDirect(java.util.Map)} except that this method first scans the map for any internal attributes
+ * using special <tt>_JBOSS_INTERNAL_XXX</tt> Strings as keys, and uses these to set internal attributes before passing
+ * the remaining attributes to {@link #putAllDirect(java.util.Map)}. Designed to be used by {@link org.jboss.cache.statetransfer.StateTransferIntegrator}
+ * and {@link org.jboss.cache.interceptors.CacheLoaderInterceptor} classes which attempt to create nodes based on a data stream.
+ *
+ * @param state state to be applied
+ * @since 2.1.0
+ */
+ void setInternalState(Map state);
}
Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2007-10-19 18:51:12 UTC (rev 4652)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2007-10-20 14:28:09 UTC (rev 4653)
@@ -88,10 +88,7 @@
protected UnversionedNode(Object child_name, Fqn fqn, Map<K, V> data, boolean mapSafe, CacheSPI<K, V> cache)
{
init(child_name, fqn, cache);
- if (data != null)
- {
- this.data.putAll(data);// ? is this safe
- }
+ setInternalState(data);
}
/**
@@ -760,4 +757,20 @@
this.setResident(structural);
this.structural = structural;
}
+
+ @SuppressWarnings("unchecked")
+ public void setInternalState(Map state)
+ {
+ // don't bother doing anything here
+ putAllDirect(state);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Map getInternalState(boolean onlyInternalState)
+ {
+ if (onlyInternalState) return new HashMap();
+ // don't bother doing anything here
+ if (data == null) return new HashMap();
+ return new HashMap(data);
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/VersionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/VersionedNode.java 2007-10-19 18:51:12 UTC (rev 4652)
+++ core/trunk/src/main/java/org/jboss/cache/VersionedNode.java 2007-10-20 14:28:09 UTC (rev 4653)
@@ -24,7 +24,9 @@
*/
public class VersionedNode<K, V> extends UnversionedNode<K, V>
{
+ private static final String DATA_VERSION_INTERNAL_KEY = "_JBOSS_INTERNAL_OPTIMISTIC_DATA_VERSION";
private DataVersion version;
+
/**
* Although this object has a reference to the CacheImpl, the optimistic
* node is actually disconnected from the CacheImpl itself.
@@ -37,7 +39,7 @@
super(fqn.getLastElement(), fqn, data, false, cache);
if (parent == null && !fqn.isRoot()) throw new NullPointerException("parent");
this.parent = parent;
- this.version = DefaultDataVersion.ZERO;
+ if (this.version == null) this.version = DefaultDataVersion.ZERO;
}
/**
@@ -70,4 +72,21 @@
{
this.version = version;
}
+
+ public Map getInternalState(boolean onlyInternalState)
+ {
+ Map state = super.getInternalState(onlyInternalState);
+ state.put(DATA_VERSION_INTERNAL_KEY, version);
+ return state;
+ }
+
+ public void setInternalState(Map state)
+ {
+ if (state != null)
+ {
+ DataVersion dv = (DataVersion) state.remove(DATA_VERSION_INTERNAL_KEY);
+ if (dv != null) version = dv;
+ }
+ super.setInternalState(state);
+ }
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2007-10-19 18:51:12 UTC (rev 4652)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2007-10-20 14:28:09 UTC (rev 4653)
@@ -273,7 +273,7 @@
if ((isMove || isActivation) && recursive)
{
// load data for children as well!
- child.putAllDirect(loader.get(child.getFqn()));
+ child.setInternalState(loader.get(child.getFqn()));
child.setDataLoaded(true);
}
@@ -427,7 +427,7 @@
n = createNodes(fqn, entry);
// n.clearDataDirect();
- n.putAllDirect(nodeData);
+ n.setInternalState(nodeData);
cache.getNotifier().notifyNodeLoaded(fqn, false, nodeData, ctx);
if (isActivation)
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2007-10-19 18:51:12 UTC (rev 4652)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2007-10-20 14:28:09 UTC (rev 4653)
@@ -18,6 +18,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -37,7 +38,7 @@
protected TransactionManager tx_mgr = null;
protected TransactionTable tx_table = null;
private HashMap m_txStores = new HashMap();
- private Map preparingTxs = new ConcurrentHashMap();
+ private Map<GlobalTransaction, Set<Fqn>> preparingTxs = new ConcurrentHashMap<GlobalTransaction, Set<Fqn>>();
private long m_cacheStores = 0;
protected CacheLoader loader;
@@ -102,9 +103,10 @@
{
loader.commit(gtx);
}
- finally
+ catch (Throwable t)
{
preparingTxs.remove(gtx);
+ throw t;
}
if (configuration.getExposeManagementStatistics() && getStatisticsEnabled())
{
@@ -147,7 +149,15 @@
}
// pass up the chain
- return super.invoke(ctx);
+ retval = super.invoke(ctx);
+
+ if (m.getMethodId() == MethodDeclarations.commitMethod_id && ctx.isTxHasMods())
+ {
+ // persist additional internal state, if any, and then clean up internal resources
+ Set<Fqn> affectedFqns = preparingTxs.remove(gtx);
+ if (affectedFqns != null) storeInternalState(affectedFqns);
+ }
+ return retval;
}
// if we're here we don't run in a transaction
@@ -226,6 +236,19 @@
}
}
+ private void storeInternalState(Set<Fqn> affectedFqns) throws Exception
+ {
+ if (cache.getConfiguration().isNodeLockingOptimistic())
+ {
+ for (Fqn f : affectedFqns)
+ {
+ NodeSPI n = cache.peek(f, false);
+ Map internalState = n.getInternalState(true);
+ loader.put(f, internalState);
+ }
+ }
+ }
+
private void doMove(Fqn node, Fqn parent) throws Exception
{
Fqn newNodeFqn = new Fqn(parent, node.getLastElement());
@@ -279,6 +302,7 @@
{
throw new Exception("entry for transaction " + gtx + " not found in transaction table");
}
+ Set<Fqn> affectedFqns = new HashSet<Fqn>();
modifications = entry.getCacheLoaderModifications();
if (modifications.size() == 0)
{
@@ -289,8 +313,9 @@
List cache_loader_modifications = new ArrayList();
for (MethodCall methodCall : modifications)
{
- Modification mod = convertMethodCallToModification(methodCall);
+ Modification mod = convertMethodCallToModification(methodCall, affectedFqns);
cache_loader_modifications.add(mod);
+
if (configuration.getExposeManagementStatistics() && getStatisticsEnabled())
{
if ((mod.getType() == Modification.ModificationType.PUT_DATA) ||
@@ -308,7 +333,8 @@
if (cache_loader_modifications.size() > 0)
{
loader.prepare(gtx, cache_loader_modifications, onePhase);
- preparingTxs.put(gtx, gtx);
+
+ preparingTxs.put(gtx, affectedFqns);
if (configuration.getExposeManagementStatistics() && getStatisticsEnabled() && txPuts > 0)
{
m_txStores.put(gtx, txPuts);
@@ -316,7 +342,12 @@
}
}
- private Modification convertMethodCallToModification(MethodCall methodCall) throws Exception
+ /**
+ * Converts a method call to a Modification, to be sent to a cache loader. In addition, adds any affected Fqns to the
+ * affectedFqns collection, which is then used by the calling code.
+ *
+ */
+ private Modification convertMethodCallToModification(MethodCall methodCall, Set<Fqn> affectedFqns) throws Exception
{
if (log.isTraceEnabled()) log.trace("Converting method call " + methodCall + " to modification.");
Method method = methodCall.getMethod();
@@ -327,45 +358,44 @@
}
args = methodCall.getArgs();
- Modification mod = null;
+ Modification mod;
+ Fqn fqn = (Fqn) args[1];
+
switch (methodCall.getMethodId())
{
case MethodDeclarations.putDataMethodLocal_id:
mod = new Modification(Modification.ModificationType.PUT_DATA,
- (Fqn) args[1], // fqn
- (Map) args[2]);// data
+ fqn, (Map) args[2]);// data
break;
case MethodDeclarations.putDataEraseMethodLocal_id:
mod = new Modification(Modification.ModificationType.PUT_DATA_ERASE,
- (Fqn) args[1], // fqn
- (Map) args[2]);// data
+ fqn, (Map) args[2]);// data
break;
case MethodDeclarations.putKeyValMethodLocal_id:
mod = new Modification(Modification.ModificationType.PUT_KEY_VALUE,
- (Fqn) args[1], // fqn
- args[2], // key
- args[3]);// value
+ fqn, args[2], args[3]);// key + value
break;
case MethodDeclarations.removeNodeMethodLocal_id:
mod = new Modification(Modification.ModificationType.REMOVE_NODE,
- (Fqn) args[1]);// fqn
+ fqn);
break;
case MethodDeclarations.removeKeyMethodLocal_id:
mod = new Modification(Modification.ModificationType.REMOVE_KEY_VALUE,
- (Fqn) args[1], // fqn
- args[2]);// key
+ fqn, args[2]);// key
break;
case MethodDeclarations.removeDataMethodLocal_id:
mod = new Modification(Modification.ModificationType.REMOVE_DATA,
- (Fqn) args[1]);// fqn
+ fqn);
break;
case MethodDeclarations.moveMethodLocal_id:
- mod = new Modification(Modification.ModificationType.MOVE, (Fqn) args[0], (Fqn) args[1]);
+ Fqn moveFrom = (Fqn) args[0];
+ affectedFqns.add(moveFrom);
+ mod = new Modification(Modification.ModificationType.MOVE, moveFrom, fqn);
break;
default:
throw new CacheException("method call " + method.getName() + " cannot be converted to a modification");
}
-
+ affectedFqns.add(fqn);
if (log.isTraceEnabled()) log.trace("Converted " + methodCall + " to Modification of type " + mod.getType());
return mod;
}
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java 2007-10-19 18:51:12 UTC (rev 4652)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java 2007-10-20 14:28:09 UTC (rev 4653)
@@ -19,7 +19,6 @@
import java.io.IOException;
import java.io.ObjectOutputStream;
-import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -152,15 +151,8 @@
NodeData nd;
// first handle the current node
- attrs = node.getDataDirect();
+ attrs = node.getInternalState(false);
- // add a dummy attribute to hold the data version if any
- if (cache.getConfiguration().isNodeLockingOptimistic())
- {
- attrs = new HashMap(attrs);
- attrs.put(StateTransferManager.DATA_VERSION_KEY, node.getVersion());
- }
-
if (attrs.size() == 0)
{
nd = new NodeData(node.getFqn());
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java 2007-10-19 18:51:12 UTC (rev 4652)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java 2007-10-20 14:28:09 UTC (rev 4653)
@@ -249,13 +249,9 @@
if (nd != null && !nd.isMarker())
{
Map attributes = nd.getAttributes();
- if (attributes != null)
- {
- DataVersion version = (DataVersion) attributes.remove(StateTransferManager.DATA_VERSION_KEY);
- target.putAllDirect(attributes);
- if (version != null) target.setVersion(version);
- }
+ target.setInternalState(attributes);
+
// Check whether this is an integration into the buddy backup
// subtree
Fqn tferFqn = nd.getFqn();
@@ -331,9 +327,7 @@
// We handle this NodeData. Create a TreeNode and
// integrate its data
- DataVersion version = (DataVersion) attrs.remove(StateTransferManager.DATA_VERSION_KEY);
NodeSPI target = factory.createDataNode(name, fqn, parent, attrs, false);
- if (version != null) target.setVersion(version);
parent.addChild(name, target);
// JBCACHE-913
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java 2007-10-19 18:51:12 UTC (rev 4652)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java 2007-10-20 14:28:09 UTC (rev 4653)
@@ -30,8 +30,6 @@
public static final String PARTIAL_STATE_DELIMITER = "_PARTIAL_STATE_DELIMITER";
- public static final String DATA_VERSION_KEY = "_jboss_internal_data_version";
-
private final CacheImpl cache;
public StateTransferManager(CacheImpl cache)
Modified: core/trunk/src/test/java/org/jboss/cache/loader/DummyInMemoryCacheLoader.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/DummyInMemoryCacheLoader.java 2007-10-19 18:51:12 UTC (rev 4652)
+++ core/trunk/src/test/java/org/jboss/cache/loader/DummyInMemoryCacheLoader.java 2007-10-20 14:28:09 UTC (rev 4653)
@@ -282,4 +282,9 @@
{
return nodes;
}
+
+ public void wipe()
+ {
+ nodes.clear();
+ }
}
Modified: core/trunk/src/test/java/org/jboss/cache/loader/DummySharedInMemoryCacheLoader.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/DummySharedInMemoryCacheLoader.java 2007-10-19 18:51:12 UTC (rev 4652)
+++ core/trunk/src/test/java/org/jboss/cache/loader/DummySharedInMemoryCacheLoader.java 2007-10-20 14:28:09 UTC (rev 4653)
@@ -41,4 +41,9 @@
{
return BINS.get(bin);
}
+
+ public void wipe()
+ {
+ BINS.clear();
+ }
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/DataVersionPersistenceTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/DataVersionPersistenceTest.java 2007-10-19 18:51:12 UTC (rev 4652)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/DataVersionPersistenceTest.java 2007-10-20 14:28:09 UTC (rev 4653)
@@ -1,11 +1,13 @@
package org.jboss.cache.optimistic;
import org.jboss.cache.Cache;
+import org.jboss.cache.CacheImpl;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.DummySharedInMemoryCacheLoader;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.testng.annotations.AfterMethod;
@@ -22,6 +24,7 @@
public class DataVersionPersistenceTest
{
private Cache cache;
+ private CacheLoader loader;
@BeforeMethod
public void setUp()
@@ -39,6 +42,8 @@
cache.getConfiguration().setCacheLoaderConfig(clc);
cache.start();
+
+ loader = ((CacheImpl) cache).getCacheLoader();
}
@AfterMethod
@@ -52,6 +57,7 @@
{
// do nothing?
}
+ ((DummySharedInMemoryCacheLoader) loader).wipe();
cache.stop();
}
@@ -59,9 +65,15 @@
{
Fqn f = Fqn.fromString("/one/two/three");
cache.put(f, "k", "v");
+
+
+
cache.put(f, "k1", "v1");
cache.remove(f, "k1");
+ assert loader.get(f).containsKey("_JBOSS_INTERNAL_OPTIMISTIC_DATA_VERSION");
+ assert ((DefaultDataVersion) loader.get(f).get("_JBOSS_INTERNAL_OPTIMISTIC_DATA_VERSION")).getRawVersion() == 3;
+
NodeSPI n = (NodeSPI) cache.getRoot().getChild(f);
DataVersion dv = n.getVersion();
@@ -69,6 +81,8 @@
assert ((DefaultDataVersion) dv).getRawVersion() == 3 : "Should have accurate data version";
+
+
// now restart cache instance
cache.stop();
cache.start();
Deleted: core/trunk/src/test/java/org/jboss/cache/statetransfer/DataVersionTransferTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/DataVersionTransferTest.java 2007-10-19 18:51:12 UTC (rev 4652)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/DataVersionTransferTest.java 2007-10-20 14:28:09 UTC (rev 4653)
@@ -1,277 +0,0 @@
-package org.jboss.cache.statetransfer;
-
-import org.jboss.cache.Cache;
-import org.jboss.cache.DefaultCacheFactory;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.NodeSPI;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.optimistic.DataVersion;
-import org.jboss.cache.optimistic.DataVersioningException;
-import org.jboss.cache.optimistic.DefaultDataVersion;
-import org.jboss.cache.transaction.DummyTransactionManagerLookup;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Tests whether data versions are transferred along with state
- *
- * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
- * @since 2.1.0
- */
-@Test(groups = {"functional"})
-public class DataVersionTransferTest
-{
- private List<Cache<Object, Object>> caches = new ArrayList<Cache<Object, Object>>(2);
-
- @BeforeMethod
- public void setUp()
- {
-
- caches.add(DefaultCacheFactory.getInstance().createCache(false));
- caches.get(0).getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- caches.get(0).getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
- caches.get(0).getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
- caches.get(0).start();
-
- caches.add(DefaultCacheFactory.getInstance().createCache(false));
- caches.get(1).getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- caches.get(1).getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
- caches.get(1).getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
- }
-
- @AfterMethod
- public void tearDown()
- {
- if (caches != null)
- {
- for (Cache cache: caches)
- {
- try
- {
- cache.getConfiguration().getRuntimeConfig().getTransactionManager().rollback();
- }
- catch (Exception e)
- {
- // do nothing?
- }
- cache.stop();
- }
- }
- }
-
- public void testStateTransferDefaultVersions() throws Exception
- {
- Fqn f = Fqn.fromString("/one/two/three");
- caches.get(0).put(f, "k", "v");
- caches.get(0).put(f, "k1", "v1");
- caches.get(0).remove(f, "k1");
-
- NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(f);
- DataVersion dv = n.getVersion();
-
- assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
-
- assert ((DefaultDataVersion) dv).getRawVersion() == 3 : "Should have accurate data version";
-
- // now start next cache instance
- caches.get(1).start();
-
- TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
-
- assert caches.get(1).get(f, "k").equals("v") : "Value should have transferred";
-
- n = (NodeSPI) caches.get(1).getRoot().getChild(f);
-
- dv = n.getVersion();
-
- assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
-
- assert ((DefaultDataVersion) dv).getRawVersion() == 3 : "Version should have transferred";
- }
-
- public void testStateTransferCustomVersion() throws Exception
- {
- Fqn f = Fqn.fromString("/one/two/three");
- caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('A'));
- caches.get(0).put(f, "k", "v");
- caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('B'));
- caches.get(0).put(f, "k1", "v1");
- caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('C'));
- caches.get(0).remove(f, "k1");
-
- NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(f);
- DataVersion dv = n.getVersion();
-
- assert dv instanceof CharVersion : "Should be an instance of CharVersion";
-
- assert ((CharVersion) dv).version == 'C' : "Should have accurate data version";
-
- // now start next cache instance
- caches.get(1).start();
-
- TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
-
- assert caches.get(1).get(f, "k").equals("v") : "Value should have transferred";
-
- n = (NodeSPI) caches.get(1).getRoot().getChild(f);
-
- dv = n.getVersion();
-
- assert dv instanceof CharVersion : "Should be an instance of CharVersion";
-
- assert ((CharVersion) dv).version == 'C' : "Version should have transferred";
- }
-
- public void testStateTransferIntermediateNodeDefaultVersions() throws Exception
- {
- Fqn f = Fqn.fromString("/one/two/three");
- Fqn intermediate = f.getParent();
-
- caches.get(0).put(f, "k", "v");
- caches.get(0).put(intermediate, "k", "v");
-
- NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(intermediate);
- DataVersion dv = n.getVersion();
-
- assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
-
- assert ((DefaultDataVersion) dv).getRawVersion() == 1 : "Should have accurate data version";
-
- // now start next cache instance
- caches.get(1).start();
-
- TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
-
- assert caches.get(1).get(intermediate, "k").equals("v") : "Value should have transferred";
-
- n = (NodeSPI) caches.get(0).getRoot().getChild(intermediate);
- dv = n.getVersion();
-
- assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
-
- assert ((DefaultDataVersion) dv).getRawVersion() == 1 : "Should have accurate data version";
- }
-
- public void testStateTransferIntermediateNodeCustomVersion() throws Exception
- {
- Fqn f = Fqn.fromString("/one/two/three");
- Fqn intermediate = f.getParent();
-
- caches.get(0).put(f, "k", "v");
- caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('X'));
- caches.get(0).put(intermediate, "k", "v");
-
- NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(intermediate);
- DataVersion dv = n.getVersion();
-
- assert dv instanceof CharVersion : "Should be an instance of CharVersion";
-
- assert ((CharVersion) dv).version == 'X' : "Should have accurate data version";
-
- // now start next cache instance
- caches.get(1).start();
-
- TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
-
- assert caches.get(1).get(intermediate, "k").equals("v") : "Value should have transferred";
-
- n = (NodeSPI) caches.get(0).getRoot().getChild(intermediate);
- dv = n.getVersion();
-
- assert dv instanceof CharVersion : "Should be an instance of CharVersion";
-
- assert ((CharVersion) dv).version == 'X' : "Should have accurate data version";
- }
-
- public void testStateTransferDefaultVersionAfterRemoval() throws Exception
- {
- Fqn f = Fqn.fromString("/one/two/three");
- caches.get(0).put(f, "k", "v");
- caches.get(0).put(f, "k1", "v1");
- caches.get(0).removeNode(f);
-
- NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(f);
- DataVersion dv = n.getVersion();
-
- assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
-
- assert ((DefaultDataVersion) dv).getRawVersion() == 3 : "Should have accurate data version";
-
- // now start next cache instance
- caches.get(1).start();
-
- TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
-
- assert caches.get(1).get(f, "k")== null : "Should be removed";
-
- n = (NodeSPI) caches.get(1).getRoot().getChild(f);
-
- dv = n.getVersion();
-
- assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
-
- assert ((DefaultDataVersion) dv).getRawVersion() == 3 : "Version should have transferred";
- }
-
- public void testStateTransferCustomVersionAfterRemoval() throws Exception
- {
- Fqn f = Fqn.fromString("/one/two/three");
- caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('A'));
- caches.get(0).put(f, "k", "v");
- caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('B'));
- caches.get(0).put(f, "k1", "v1");
- caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('C'));
- caches.get(0).removeNode(f);
-
- NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(f);
- DataVersion dv = n.getVersion();
-
- assert dv instanceof CharVersion : "Should be an instance of CharVersion";
-
- assert ((CharVersion) dv).version == 'C' : "Should have accurate data version";
-
- // now start next cache instance
- caches.get(1).start();
-
- TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
-
- assert caches.get(1).get(f, "k")== null : "Should be removed";
-
- n = (NodeSPI) caches.get(1).getRoot().getChild(f);
-
- dv = n.getVersion();
-
- assert dv instanceof CharVersion : "Should be an instance of CharVersion";
-
- assert ((CharVersion) dv).version == 'C' : "Version should have transferred";
- }
-
- public static class CharVersion implements DataVersion
- {
- private char version = 'A';
-
- public CharVersion(char version)
- {
- this.version = version;
- }
-
- public boolean newerThan(DataVersion other)
- {
- if (other instanceof CharVersion)
- {
- CharVersion otherVersion = (CharVersion) other;
- return version > otherVersion.version;
- }
- else
- {
- return true;
- }
- }
- }
-
-}
17 years, 2 months
JBoss Cache SVN: r4652 - in core/trunk/src: test/java/org/jboss/cache/optimistic and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-10-19 14:51:12 -0400 (Fri, 19 Oct 2007)
New Revision: 4652
Added:
core/trunk/src/test/java/org/jboss/cache/optimistic/DataVersionPersistenceTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/DataVersionTransferTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
Log:
Updated test for JBCACHE-1202 to also cover cache loaders
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java 2007-10-19 17:55:03 UTC (rev 4651)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java 2007-10-19 18:51:12 UTC (rev 4652)
@@ -249,9 +249,12 @@
if (nd != null && !nd.isMarker())
{
Map attributes = nd.getAttributes();
- DataVersion version = (DataVersion) attributes.remove(StateTransferManager.DATA_VERSION_KEY);
- target.putAllDirect(attributes);
- if (version != null) target.setVersion(version);
+ if (attributes != null)
+ {
+ DataVersion version = (DataVersion) attributes.remove(StateTransferManager.DATA_VERSION_KEY);
+ target.putAllDirect(attributes);
+ if (version != null) target.setVersion(version);
+ }
// Check whether this is an integration into the buddy backup
// subtree
Added: core/trunk/src/test/java/org/jboss/cache/optimistic/DataVersionPersistenceTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/DataVersionPersistenceTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/DataVersionPersistenceTest.java 2007-10-19 18:51:12 UTC (rev 4652)
@@ -0,0 +1,208 @@
+package org.jboss.cache.optimistic;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.loader.DummySharedInMemoryCacheLoader;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Tests whether data versions are transferred along with state
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
+ * @since 2.1.0
+ */
+@Test(groups = {"functional"})
+public class DataVersionPersistenceTest
+{
+ private Cache cache;
+
+ @BeforeMethod
+ public void setUp()
+ {
+
+ cache = DefaultCacheFactory.getInstance().createCache(false);
+ cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ cache.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
+
+ CacheLoaderConfig clc = new CacheLoaderConfig();
+ CacheLoaderConfig.IndividualCacheLoaderConfig iclc = new CacheLoaderConfig.IndividualCacheLoaderConfig();
+ iclc.setClassName(DummySharedInMemoryCacheLoader.class.getName());
+ clc.addIndividualCacheLoaderConfig(iclc);
+
+ cache.getConfiguration().setCacheLoaderConfig(clc);
+
+ cache.start();
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ try
+ {
+ cache.getConfiguration().getRuntimeConfig().getTransactionManager().rollback();
+ }
+ catch (Exception e)
+ {
+ // do nothing?
+ }
+ cache.stop();
+ }
+
+ public void testStateTransferDefaultVersions() throws Exception
+ {
+ Fqn f = Fqn.fromString("/one/two/three");
+ cache.put(f, "k", "v");
+ cache.put(f, "k1", "v1");
+ cache.remove(f, "k1");
+
+ NodeSPI n = (NodeSPI) cache.getRoot().getChild(f);
+ DataVersion dv = n.getVersion();
+
+ assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
+
+ assert ((DefaultDataVersion) dv).getRawVersion() == 3 : "Should have accurate data version";
+
+ // now restart cache instance
+ cache.stop();
+ cache.start();
+
+ assert cache.get(f, "k").equals("v") : "Value should have peristed";
+
+ n = (NodeSPI) cache.getRoot().getChild(f);
+
+ dv = n.getVersion();
+
+ assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
+
+ assert ((DefaultDataVersion) dv).getRawVersion() == 3 : "Version should have peristed";
+ // make sure leakage doesn't occur into data map
+ assert n.getData().size() == 1;
+ }
+
+ public void testStateTransferCustomVersion() throws Exception
+ {
+ Fqn f = Fqn.fromString("/one/two/three");
+ cache.getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('A'));
+ cache.put(f, "k", "v");
+ cache.getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('B'));
+ cache.put(f, "k1", "v1");
+ cache.getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('C'));
+ cache.remove(f, "k1");
+
+ NodeSPI n = (NodeSPI) cache.getRoot().getChild(f);
+ DataVersion dv = n.getVersion();
+
+ assert dv instanceof CharVersion : "Should be an instance of CharVersion";
+
+ assert ((CharVersion) dv).version == 'C' : "Should have accurate data version";
+
+ // now restart cache instance
+ cache.stop();
+ cache.start();
+
+ assert cache.get(f, "k").equals("v") : "Value should have peristed";
+
+ n = (NodeSPI) cache.getRoot().getChild(f);
+
+ dv = n.getVersion();
+
+ assert dv instanceof CharVersion : "Should be an instance of CharVersion";
+
+ assert ((CharVersion) dv).version == 'C' : "Version should have peristed";
+
+ // make sure leakage doesn't occur into data map
+ assert n.getData().size() == 1;
+ }
+
+ public void testStateTransferDefaultVersionAfterRemoval() throws Exception
+ {
+ Fqn f = Fqn.fromString("/one/two/three");
+ cache.put(f, "k", "v");
+ cache.put(f, "k1", "v1");
+ cache.removeNode(f);
+
+ NodeSPI n = (NodeSPI) cache.getRoot().getChild(f);
+ DataVersion dv = n.getVersion();
+
+ assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
+
+ assert ((DefaultDataVersion) dv).getRawVersion() == 3 : "Should have accurate data version";
+
+ // now restart cache instance
+ cache.stop();
+ cache.start();
+
+ assert cache.get(f, "k")== null : "Should be removed";
+
+ n = (NodeSPI) cache.getRoot().getChild(f);
+
+ dv = n.getVersion();
+
+ assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
+
+ assert ((DefaultDataVersion) dv).getRawVersion() == 3 : "Version should have persisted";
+ }
+
+ public void testStateTransferCustomVersionAfterRemoval() throws Exception
+ {
+ Fqn f = Fqn.fromString("/one/two/three");
+ cache.getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('A'));
+ cache.put(f, "k", "v");
+ cache.getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('B'));
+ cache.put(f, "k1", "v1");
+ cache.getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('C'));
+ cache.removeNode(f);
+
+ NodeSPI n = (NodeSPI) cache.getRoot().getChild(f);
+ DataVersion dv = n.getVersion();
+
+ assert dv instanceof CharVersion : "Should be an instance of CharVersion";
+
+ assert ((CharVersion) dv).version == 'C' : "Should have accurate data version";
+
+ // now restart cache instance
+ cache.stop();
+ cache.start();
+
+ assert cache.get(f, "k")== null : "Should be removed";
+
+ n = (NodeSPI) cache.getRoot().getChild(f);
+
+ dv = n.getVersion();
+
+ assert dv instanceof CharVersion : "Should be an instance of CharVersion";
+
+ assert ((CharVersion) dv).version == 'C' : "Version should have persisted";
+ }
+
+ public static class CharVersion implements DataVersion
+ {
+ private char version = 'A';
+
+ public CharVersion(char version)
+ {
+ this.version = version;
+ }
+
+ public boolean newerThan(DataVersion other)
+ {
+ if (other instanceof CharVersion)
+ {
+ CharVersion otherVersion = (CharVersion) other;
+ return version > otherVersion.version;
+ }
+ else
+ {
+ return true;
+ }
+ }
+ }
+
+}
Copied: core/trunk/src/test/java/org/jboss/cache/optimistic/DataVersionTransferTest.java (from rev 4651, core/trunk/src/test/java/org/jboss/cache/statetransfer/DataVersionTransferTest.java)
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/DataVersionTransferTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/DataVersionTransferTest.java 2007-10-19 18:51:12 UTC (rev 4652)
@@ -0,0 +1,282 @@
+package org.jboss.cache.optimistic;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests whether data versions are transferred along with state
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
+ * @since 2.1.0
+ */
+@Test(groups = {"functional"})
+public class DataVersionTransferTest
+{
+ private List<Cache<Object, Object>> caches = new ArrayList<Cache<Object, Object>>(2);
+
+ @BeforeMethod
+ public void setUp()
+ {
+
+ caches.add(DefaultCacheFactory.getInstance().createCache(false));
+ caches.get(0).getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ caches.get(0).getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
+ caches.get(0).getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ caches.get(0).start();
+
+ caches.add(DefaultCacheFactory.getInstance().createCache(false));
+ caches.get(1).getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ caches.get(1).getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
+ caches.get(1).getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ if (caches != null)
+ {
+ for (Cache cache: caches)
+ {
+ try
+ {
+ cache.getConfiguration().getRuntimeConfig().getTransactionManager().rollback();
+ }
+ catch (Exception e)
+ {
+ // do nothing?
+ }
+ cache.stop();
+ }
+ }
+ }
+
+ public void testStateTransferDefaultVersions() throws Exception
+ {
+ Fqn f = Fqn.fromString("/one/two/three");
+ caches.get(0).put(f, "k", "v");
+ caches.get(0).put(f, "k1", "v1");
+ caches.get(0).remove(f, "k1");
+
+ NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(f);
+ DataVersion dv = n.getVersion();
+
+ assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
+
+ assert ((DefaultDataVersion) dv).getRawVersion() == 3 : "Should have accurate data version";
+
+ // now start next cache instance
+ caches.get(1).start();
+
+ TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
+
+ assert caches.get(1).get(f, "k").equals("v") : "Value should have transferred";
+
+ n = (NodeSPI) caches.get(1).getRoot().getChild(f);
+
+ dv = n.getVersion();
+
+ assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
+
+ assert ((DefaultDataVersion) dv).getRawVersion() == 3 : "Version should have transferred";
+ // make sure leakage doesn't occur into data map
+ assert n.getData().size() == 1;
+ }
+
+ public void testStateTransferCustomVersion() throws Exception
+ {
+ Fqn f = Fqn.fromString("/one/two/three");
+ caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('A'));
+ caches.get(0).put(f, "k", "v");
+ caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('B'));
+ caches.get(0).put(f, "k1", "v1");
+ caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('C'));
+ caches.get(0).remove(f, "k1");
+
+ NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(f);
+ DataVersion dv = n.getVersion();
+
+ assert dv instanceof CharVersion : "Should be an instance of CharVersion";
+
+ assert ((CharVersion) dv).version == 'C' : "Should have accurate data version";
+
+ // now start next cache instance
+ caches.get(1).start();
+
+ TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
+
+ assert caches.get(1).get(f, "k").equals("v") : "Value should have transferred";
+
+ n = (NodeSPI) caches.get(1).getRoot().getChild(f);
+
+ dv = n.getVersion();
+
+ assert dv instanceof CharVersion : "Should be an instance of CharVersion";
+
+ assert ((CharVersion) dv).version == 'C' : "Version should have transferred";
+ // make sure leakage doesn't occur into data map
+ assert n.getData().size() == 1;
+ }
+
+ public void testStateTransferIntermediateNodeDefaultVersions() throws Exception
+ {
+ Fqn f = Fqn.fromString("/one/two/three");
+ Fqn intermediate = f.getParent();
+
+ caches.get(0).put(f, "k", "v");
+ caches.get(0).put(intermediate, "k", "v");
+
+ NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(intermediate);
+ DataVersion dv = n.getVersion();
+
+ assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
+
+ assert ((DefaultDataVersion) dv).getRawVersion() == 1 : "Should have accurate data version";
+
+ // now start next cache instance
+ caches.get(1).start();
+
+ TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
+
+ assert caches.get(1).get(intermediate, "k").equals("v") : "Value should have transferred";
+
+ n = (NodeSPI) caches.get(0).getRoot().getChild(intermediate);
+ dv = n.getVersion();
+
+ assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
+
+ assert ((DefaultDataVersion) dv).getRawVersion() == 1 : "Should have accurate data version";
+ // make sure leakage doesn't occur into data map
+ assert n.getData().size() == 1;
+ }
+
+ public void testStateTransferIntermediateNodeCustomVersion() throws Exception
+ {
+ Fqn f = Fqn.fromString("/one/two/three");
+ Fqn intermediate = f.getParent();
+
+ caches.get(0).put(f, "k", "v");
+ caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('X'));
+ caches.get(0).put(intermediate, "k", "v");
+
+ NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(intermediate);
+ DataVersion dv = n.getVersion();
+
+ assert dv instanceof CharVersion : "Should be an instance of CharVersion";
+
+ assert ((CharVersion) dv).version == 'X' : "Should have accurate data version";
+
+ // now start next cache instance
+ caches.get(1).start();
+
+ TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
+
+ assert caches.get(1).get(intermediate, "k").equals("v") : "Value should have transferred";
+
+ n = (NodeSPI) caches.get(0).getRoot().getChild(intermediate);
+ dv = n.getVersion();
+
+ assert dv instanceof CharVersion : "Should be an instance of CharVersion";
+
+ assert ((CharVersion) dv).version == 'X' : "Should have accurate data version";
+ // make sure leakage doesn't occur into data map
+ assert n.getData().size() == 1;
+ }
+
+ public void testStateTransferDefaultVersionAfterRemoval() throws Exception
+ {
+ Fqn f = Fqn.fromString("/one/two/three");
+ caches.get(0).put(f, "k", "v");
+ caches.get(0).put(f, "k1", "v1");
+ caches.get(0).removeNode(f);
+
+ NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(f);
+ DataVersion dv = n.getVersion();
+
+ assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
+
+ assert ((DefaultDataVersion) dv).getRawVersion() == 3 : "Should have accurate data version";
+
+ // now start next cache instance
+ caches.get(1).start();
+
+ TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
+
+ assert caches.get(1).get(f, "k")== null : "Should be removed";
+
+ n = (NodeSPI) caches.get(1).getRoot().getChild(f);
+
+ dv = n.getVersion();
+
+ assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
+
+ assert ((DefaultDataVersion) dv).getRawVersion() == 3 : "Version should have transferred";
+ }
+
+ public void testStateTransferCustomVersionAfterRemoval() throws Exception
+ {
+ Fqn f = Fqn.fromString("/one/two/three");
+ caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('A'));
+ caches.get(0).put(f, "k", "v");
+ caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('B'));
+ caches.get(0).put(f, "k1", "v1");
+ caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('C'));
+ caches.get(0).removeNode(f);
+
+ NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(f);
+ DataVersion dv = n.getVersion();
+
+ assert dv instanceof CharVersion : "Should be an instance of CharVersion";
+
+ assert ((CharVersion) dv).version == 'C' : "Should have accurate data version";
+
+ // now start next cache instance
+ caches.get(1).start();
+
+ TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
+
+ assert caches.get(1).get(f, "k")== null : "Should be removed";
+
+ n = (NodeSPI) caches.get(1).getRoot().getChild(f);
+
+ dv = n.getVersion();
+
+ assert dv instanceof CharVersion : "Should be an instance of CharVersion";
+
+ assert ((CharVersion) dv).version == 'C' : "Version should have transferred";
+ }
+
+ public static class CharVersion implements DataVersion
+ {
+ private char version = 'A';
+
+ public CharVersion(char version)
+ {
+ this.version = version;
+ }
+
+ public boolean newerThan(DataVersion other)
+ {
+ if (other instanceof CharVersion)
+ {
+ CharVersion otherVersion = (CharVersion) other;
+ return version > otherVersion.version;
+ }
+ else
+ {
+ return true;
+ }
+ }
+ }
+
+}
17 years, 2 months
JBoss Cache SVN: r4651 - in core/trunk/src: test/java/org/jboss/cache/statetransfer and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-10-19 13:55:03 -0400 (Fri, 19 Oct 2007)
New Revision: 4651
Modified:
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java
core/trunk/src/test/java/org/jboss/cache/statetransfer/DataVersionTransferTest.java
Log:
Updated test for JBCACHE-1202 and a fix for the same
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java 2007-10-19 17:37:24 UTC (rev 4650)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java 2007-10-19 17:55:03 UTC (rev 4651)
@@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.ObjectOutputStream;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -152,6 +153,14 @@
// first handle the current node
attrs = node.getDataDirect();
+
+ // add a dummy attribute to hold the data version if any
+ if (cache.getConfiguration().isNodeLockingOptimistic())
+ {
+ attrs = new HashMap(attrs);
+ attrs.put(StateTransferManager.DATA_VERSION_KEY, node.getVersion());
+ }
+
if (attrs.size() == 0)
{
nd = new NodeData(node.getFqn());
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java 2007-10-19 17:37:24 UTC (rev 4650)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java 2007-10-19 17:55:03 UTC (rev 4651)
@@ -23,6 +23,7 @@
import org.jboss.cache.marshall.NodeData;
import org.jboss.cache.marshall.NodeDataExceptionMarker;
import org.jboss.cache.marshall.NodeDataMarker;
+import org.jboss.cache.optimistic.DataVersion;
import java.io.IOException;
import java.io.ObjectInputStream;
@@ -247,7 +248,10 @@
//are there any transient nodes at all?
if (nd != null && !nd.isMarker())
{
- target.putAllDirect(nd.getAttributes());
+ Map attributes = nd.getAttributes();
+ DataVersion version = (DataVersion) attributes.remove(StateTransferManager.DATA_VERSION_KEY);
+ target.putAllDirect(attributes);
+ if (version != null) target.setVersion(version);
// Check whether this is an integration into the buddy backup
// subtree
@@ -323,8 +327,10 @@
Map attrs = nd.getAttributes();
// We handle this NodeData. Create a TreeNode and
- // integrate its data
+ // integrate its data
+ DataVersion version = (DataVersion) attrs.remove(StateTransferManager.DATA_VERSION_KEY);
NodeSPI target = factory.createDataNode(name, fqn, parent, attrs, false);
+ if (version != null) target.setVersion(version);
parent.addChild(name, target);
// JBCACHE-913
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java 2007-10-19 17:37:24 UTC (rev 4650)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java 2007-10-19 17:55:03 UTC (rev 4651)
@@ -30,6 +30,8 @@
public static final String PARTIAL_STATE_DELIMITER = "_PARTIAL_STATE_DELIMITER";
+ public static final String DATA_VERSION_KEY = "_jboss_internal_data_version";
+
private final CacheImpl cache;
public StateTransferManager(CacheImpl cache)
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/DataVersionTransferTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/DataVersionTransferTest.java 2007-10-19 17:37:24 UTC (rev 4650)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/DataVersionTransferTest.java 2007-10-19 17:55:03 UTC (rev 4651)
@@ -127,6 +127,67 @@
assert ((CharVersion) dv).version == 'C' : "Version should have transferred";
}
+ public void testStateTransferIntermediateNodeDefaultVersions() throws Exception
+ {
+ Fqn f = Fqn.fromString("/one/two/three");
+ Fqn intermediate = f.getParent();
+
+ caches.get(0).put(f, "k", "v");
+ caches.get(0).put(intermediate, "k", "v");
+
+ NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(intermediate);
+ DataVersion dv = n.getVersion();
+
+ assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
+
+ assert ((DefaultDataVersion) dv).getRawVersion() == 1 : "Should have accurate data version";
+
+ // now start next cache instance
+ caches.get(1).start();
+
+ TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
+
+ assert caches.get(1).get(intermediate, "k").equals("v") : "Value should have transferred";
+
+ n = (NodeSPI) caches.get(0).getRoot().getChild(intermediate);
+ dv = n.getVersion();
+
+ assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
+
+ assert ((DefaultDataVersion) dv).getRawVersion() == 1 : "Should have accurate data version";
+ }
+
+ public void testStateTransferIntermediateNodeCustomVersion() throws Exception
+ {
+ Fqn f = Fqn.fromString("/one/two/three");
+ Fqn intermediate = f.getParent();
+
+ caches.get(0).put(f, "k", "v");
+ caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('X'));
+ caches.get(0).put(intermediate, "k", "v");
+
+ NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(intermediate);
+ DataVersion dv = n.getVersion();
+
+ assert dv instanceof CharVersion : "Should be an instance of CharVersion";
+
+ assert ((CharVersion) dv).version == 'X' : "Should have accurate data version";
+
+ // now start next cache instance
+ caches.get(1).start();
+
+ TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
+
+ assert caches.get(1).get(intermediate, "k").equals("v") : "Value should have transferred";
+
+ n = (NodeSPI) caches.get(0).getRoot().getChild(intermediate);
+ dv = n.getVersion();
+
+ assert dv instanceof CharVersion : "Should be an instance of CharVersion";
+
+ assert ((CharVersion) dv).version == 'X' : "Should have accurate data version";
+ }
+
public void testStateTransferDefaultVersionAfterRemoval() throws Exception
{
Fqn f = Fqn.fromString("/one/two/three");
@@ -208,7 +269,7 @@
}
else
{
- throw new DataVersioningException("Incompatible version types");
+ return true;
}
}
}
17 years, 2 months
JBoss Cache SVN: r4650 - core/trunk/src/test/java/org/jboss/cache/statetransfer.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-10-19 13:37:24 -0400 (Fri, 19 Oct 2007)
New Revision: 4650
Added:
core/trunk/src/test/java/org/jboss/cache/statetransfer/DataVersionTransferTest.java
Log:
Added test for JBCACHE-1202
Added: core/trunk/src/test/java/org/jboss/cache/statetransfer/DataVersionTransferTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/DataVersionTransferTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/DataVersionTransferTest.java 2007-10-19 17:37:24 UTC (rev 4650)
@@ -0,0 +1,216 @@
+package org.jboss.cache.statetransfer;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.optimistic.DataVersion;
+import org.jboss.cache.optimistic.DataVersioningException;
+import org.jboss.cache.optimistic.DefaultDataVersion;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests whether data versions are transferred along with state
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
+ * @since 2.1.0
+ */
+@Test(groups = {"functional"})
+public class DataVersionTransferTest
+{
+ private List<Cache<Object, Object>> caches = new ArrayList<Cache<Object, Object>>(2);
+
+ @BeforeMethod
+ public void setUp()
+ {
+
+ caches.add(DefaultCacheFactory.getInstance().createCache(false));
+ caches.get(0).getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ caches.get(0).getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
+ caches.get(0).getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ caches.get(0).start();
+
+ caches.add(DefaultCacheFactory.getInstance().createCache(false));
+ caches.get(1).getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ caches.get(1).getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
+ caches.get(1).getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ if (caches != null)
+ {
+ for (Cache cache: caches)
+ {
+ try
+ {
+ cache.getConfiguration().getRuntimeConfig().getTransactionManager().rollback();
+ }
+ catch (Exception e)
+ {
+ // do nothing?
+ }
+ cache.stop();
+ }
+ }
+ }
+
+ public void testStateTransferDefaultVersions() throws Exception
+ {
+ Fqn f = Fqn.fromString("/one/two/three");
+ caches.get(0).put(f, "k", "v");
+ caches.get(0).put(f, "k1", "v1");
+ caches.get(0).remove(f, "k1");
+
+ NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(f);
+ DataVersion dv = n.getVersion();
+
+ assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
+
+ assert ((DefaultDataVersion) dv).getRawVersion() == 3 : "Should have accurate data version";
+
+ // now start next cache instance
+ caches.get(1).start();
+
+ TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
+
+ assert caches.get(1).get(f, "k").equals("v") : "Value should have transferred";
+
+ n = (NodeSPI) caches.get(1).getRoot().getChild(f);
+
+ dv = n.getVersion();
+
+ assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
+
+ assert ((DefaultDataVersion) dv).getRawVersion() == 3 : "Version should have transferred";
+ }
+
+ public void testStateTransferCustomVersion() throws Exception
+ {
+ Fqn f = Fqn.fromString("/one/two/three");
+ caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('A'));
+ caches.get(0).put(f, "k", "v");
+ caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('B'));
+ caches.get(0).put(f, "k1", "v1");
+ caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('C'));
+ caches.get(0).remove(f, "k1");
+
+ NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(f);
+ DataVersion dv = n.getVersion();
+
+ assert dv instanceof CharVersion : "Should be an instance of CharVersion";
+
+ assert ((CharVersion) dv).version == 'C' : "Should have accurate data version";
+
+ // now start next cache instance
+ caches.get(1).start();
+
+ TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
+
+ assert caches.get(1).get(f, "k").equals("v") : "Value should have transferred";
+
+ n = (NodeSPI) caches.get(1).getRoot().getChild(f);
+
+ dv = n.getVersion();
+
+ assert dv instanceof CharVersion : "Should be an instance of CharVersion";
+
+ assert ((CharVersion) dv).version == 'C' : "Version should have transferred";
+ }
+
+ public void testStateTransferDefaultVersionAfterRemoval() throws Exception
+ {
+ Fqn f = Fqn.fromString("/one/two/three");
+ caches.get(0).put(f, "k", "v");
+ caches.get(0).put(f, "k1", "v1");
+ caches.get(0).removeNode(f);
+
+ NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(f);
+ DataVersion dv = n.getVersion();
+
+ assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
+
+ assert ((DefaultDataVersion) dv).getRawVersion() == 3 : "Should have accurate data version";
+
+ // now start next cache instance
+ caches.get(1).start();
+
+ TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
+
+ assert caches.get(1).get(f, "k")== null : "Should be removed";
+
+ n = (NodeSPI) caches.get(1).getRoot().getChild(f);
+
+ dv = n.getVersion();
+
+ assert dv instanceof DefaultDataVersion : "Should be an instance of DefaultDataVersion";
+
+ assert ((DefaultDataVersion) dv).getRawVersion() == 3 : "Version should have transferred";
+ }
+
+ public void testStateTransferCustomVersionAfterRemoval() throws Exception
+ {
+ Fqn f = Fqn.fromString("/one/two/three");
+ caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('A'));
+ caches.get(0).put(f, "k", "v");
+ caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('B'));
+ caches.get(0).put(f, "k1", "v1");
+ caches.get(0).getInvocationContext().getOptionOverrides().setDataVersion(new CharVersion('C'));
+ caches.get(0).removeNode(f);
+
+ NodeSPI n = (NodeSPI) caches.get(0).getRoot().getChild(f);
+ DataVersion dv = n.getVersion();
+
+ assert dv instanceof CharVersion : "Should be an instance of CharVersion";
+
+ assert ((CharVersion) dv).version == 'C' : "Should have accurate data version";
+
+ // now start next cache instance
+ caches.get(1).start();
+
+ TestingUtil.blockUntilViewsReceived(10000, caches.get(0), caches.get(1));
+
+ assert caches.get(1).get(f, "k")== null : "Should be removed";
+
+ n = (NodeSPI) caches.get(1).getRoot().getChild(f);
+
+ dv = n.getVersion();
+
+ assert dv instanceof CharVersion : "Should be an instance of CharVersion";
+
+ assert ((CharVersion) dv).version == 'C' : "Version should have transferred";
+ }
+
+ public static class CharVersion implements DataVersion
+ {
+ private char version = 'A';
+
+ public CharVersion(char version)
+ {
+ this.version = version;
+ }
+
+ public boolean newerThan(DataVersion other)
+ {
+ if (other instanceof CharVersion)
+ {
+ CharVersion otherVersion = (CharVersion) other;
+ return version > otherVersion.version;
+ }
+ else
+ {
+ throw new DataVersioningException("Incompatible version types");
+ }
+ }
+ }
+
+}
17 years, 2 months