JBoss Cache SVN: r7807 - core/trunk/src/test/java/org/jboss/cache/statetransfer.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-27 12:41:15 -0500 (Fri, 27 Feb 2009)
New Revision: 7807
Modified:
core/trunk/src/test/java/org/jboss/cache/statetransfer/NBSTCacheLoaderTest.java
Log:
Reset threadlocal after methods
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/NBSTCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/NBSTCacheLoaderTest.java 2009-02-27 16:27:41 UTC (rev 7806)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/NBSTCacheLoaderTest.java 2009-02-27 17:41:15 UTC (rev 7807)
@@ -5,7 +5,9 @@
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.testloaders.DummySharedInMemoryCacheLoaderConfig;
import org.jboss.cache.util.TestingUtil;
-import static org.testng.AssertJUnit.*;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import java.io.IOException;
@@ -22,6 +24,13 @@
}
};
+ @AfterMethod
+ public void resetThreadLocal()
+ {
+ sharedCacheLoader.set(false);
+ }
+
+
@Override
protected CacheSPI<Object, Object> createCache(String name, boolean start) throws IOException
{
15 years, 10 months
JBoss Cache SVN: r7806 - core/trunk/src/test/java/org/jboss/cache/statetransfer.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-27 11:27:41 -0500 (Fri, 27 Feb 2009)
New Revision: 7806
Modified:
core/trunk/src/test/java/org/jboss/cache/statetransfer/NonBlockingStateTransferTest.java
Log:
Bug in writer thread loop
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/NonBlockingStateTransferTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/NonBlockingStateTransferTest.java 2009-02-27 13:08:31 UTC (rev 7805)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/NonBlockingStateTransferTest.java 2009-02-27 16:27:41 UTC (rev 7806)
@@ -102,7 +102,7 @@
{
try
{
- if (c % 1000 == 0)
+ if (c == 1000)
{
startTxIfNeeded();
for (int i=0; i<1000; i++) cache.removeNode("/test" + i);
15 years, 10 months
JBoss Cache SVN: r7805 - core/trunk/src/test/java/org/jboss/cache/statetransfer.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-27 08:08:31 -0500 (Fri, 27 Feb 2009)
New Revision: 7805
Modified:
core/trunk/src/test/java/org/jboss/cache/statetransfer/NonBlockingStateTransferTest.java
Log:
Writer thread to stop on error and if test exists
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/NonBlockingStateTransferTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/NonBlockingStateTransferTest.java 2009-02-27 12:52:48 UTC (rev 7804)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/NonBlockingStateTransferTest.java 2009-02-27 13:08:31 UTC (rev 7805)
@@ -87,7 +87,7 @@
WritingRunner(Cache<Object, Object> cache, boolean tx)
{
this.cache = cache;
- this.tx = tx;
+ this.tx = tx;
}
public int result()
@@ -120,6 +120,7 @@
{
e.printStackTrace();
log.error(e);
+ stop = true;
}
}
result = c;
@@ -331,6 +332,7 @@
WritingRunner writer = new WritingRunner(cache3, tx);
Thread writerThread = new Thread(writer);
+ writerThread.setDaemon(true);
writerThread.start();
cache2 = createCache(name);
@@ -384,6 +386,7 @@
WritingRunner writer = new WritingRunner(cache1, tx);
Thread writerThread = new Thread(writer);
+ writerThread.setDaemon(true);
writerThread.start();
cache2 = createCache(name);
15 years, 10 months
JBoss Cache SVN: r7804 - core/trunk/src/main/java/org/jboss/cache/statetransfer.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-27 07:52:48 -0500 (Fri, 27 Feb 2009)
New Revision: 7804
Modified:
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java
Log:
Potential fix for NBST + loaders
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java 2009-02-27 12:40:34 UTC (rev 7803)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java 2009-02-27 12:52:48 UTC (rev 7804)
@@ -87,20 +87,22 @@
{
Fqn fqn = getFqn(rootNode);
boolean activated = false;
+ CacheLoader cacheLoader = cache.getCacheLoaderManager() == null ? null : cache.getCacheLoaderManager().getCacheLoader();
+ boolean needToGeneratePersistentState = generatePersistent && cacheLoader != null;
try
{
cache.getMarshaller().objectToObjectStream(STATE_TRANSFER_VERSION, out);
- if (generateTransient)
+
+ // activate the tx log only if we need to generate either transient or persistent state
+ if (nonBlocking && (generateTransient || needToGeneratePersistentState))
{
- if (nonBlocking)
- {
- activated = txLog.activate();
- if (! activated)
- throw new StateProviderBusyException("Busy performing state transfer for someone else");
+ activated = txLog.activate();
+ if (! activated) throw new StateProviderBusyException("Busy performing state transfer for someone else");
+ if (trace) log.trace("Transaction log activated!");
+ }
- if (trace) log.trace("Transaction log activated!");
- }
-
+ if (generateTransient)
+ {
//transient + marker
if (trace) log.trace("writing transient state for " + fqn);
marshallTransientState((InternalNode) rootNode, out);
@@ -121,11 +123,8 @@
delimitStream(out);
}
- CacheLoader cacheLoader = cache.getCacheLoaderManager() == null ? null : cache.getCacheLoaderManager().getCacheLoader();
- if (cacheLoader != null && generatePersistent)
- {
- writePersistentData(out, fqn, cacheLoader);
- }
+ if (needToGeneratePersistentState) writePersistentData(out, fqn, cacheLoader);
+
delimitStream(out);
if (nonBlocking && generateTransient)
15 years, 10 months
JBoss Cache SVN: r7803 - core/trunk/src/test/java/org/jboss/cache/statetransfer.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-27 07:40:34 -0500 (Fri, 27 Feb 2009)
New Revision: 7803
Modified:
core/trunk/src/test/java/org/jboss/cache/statetransfer/NBSTCacheLoaderTest.java
Log:
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/NBSTCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/NBSTCacheLoaderTest.java 2009-02-27 12:38:16 UTC (rev 7802)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/NBSTCacheLoaderTest.java 2009-02-27 12:40:34 UTC (rev 7803)
@@ -10,7 +10,7 @@
import java.io.IOException;
-@Test(groups = "functional", testName = "statetransfer.NBSTCacheLoaderTest")
+@Test(groups = "functional", testName = "statetransfer.NBSTCacheLoaderTest", enabled = false)
public class NBSTCacheLoaderTest extends NonBlockingStateTransferTest
{
int id;
15 years, 10 months
JBoss Cache SVN: r7802 - in core/trunk/src: main/java/org/jboss/cache/statetransfer and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-27 07:38:16 -0500 (Fri, 27 Feb 2009)
New Revision: 7802
Added:
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateProviderBusyException.java
Modified:
core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.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/DefaultStateTransferManager.java
core/trunk/src/test/java/org/jboss/cache/statetransfer/NBSTCacheLoaderTest.java
Log:
Tweaks to NBST code
Modified: core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2009-02-27 10:26:02 UTC (rev 7801)
+++ core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2009-02-27 12:38:16 UTC (rev 7802)
@@ -63,6 +63,7 @@
import org.jgroups.blocks.GroupRequest;
import org.jgroups.blocks.RspFilter;
import org.jgroups.protocols.TP;
+import org.jgroups.protocols.pbcast.FLUSH;
import org.jgroups.protocols.pbcast.STREAMING_STATE_TRANSFER;
import org.jgroups.stack.ProtocolStack;
import org.jgroups.util.Rsp;
@@ -379,6 +380,15 @@
}
}
+ private void sanityCheckJGroupsStack(JChannel channel)
+ {
+ if (channel.getProtocolStack().findProtocol(STREAMING_STATE_TRANSFER.class) == null)
+ throw new ConfigurationException("JGroups channel does not use STREAMING_STATE_TRANSFER! This is a requirement for non-blocking state transfer. Either make sure your JGroups configuration uses STREAMING_STATE_TRANSFER or disable non-blocking state transfer.");
+
+ if (channel.getProtocolStack().findProtocol(FLUSH.class) == null)
+ throw new ConfigurationException("JGroups channel does not use FLUSH! This is a requirement for non-blocking state transfer. Either make sure your JGroups configuration uses FLUSH or disable non-blocking state transfer.");
+ }
+
private void sanityCheckConfiguration(boolean nonBlockingStateTransfer, boolean fetchStateOnStart)
{
if (isInLocalMode || !nonBlockingStateTransfer || !fetchStateOnStart) return; // don't care about these cases!
@@ -392,16 +402,17 @@
private void startNonBlockStateTransfer(List<Address> members)
{
-
if (members.size() < 2)
{
+ if (log.isInfoEnabled()) log.info("Not retrieving state since cluster size is " + members.size());
return;
}
-
boolean success = false;
+ int numRetries = 2; // should be 5
+ int initwait = 100; // should be 1000
outer:
- for (int i = 0, wait = 1000; i < 5; i++)
+ for (int i = 0, wait = initwait; i < numRetries; i++)
{
for (Address member : members)
{
@@ -428,11 +439,12 @@
if (!success)
{
- if (log.isWarnEnabled()) log.warn("Could not find available peer for state, backing off and retrying");
+ wait <<= 2;
+ if (log.isWarnEnabled()) log.warn("Could not find available peer for state, backing off and retrying after "+wait+" millis. Retries left: " + (numRetries -1 -i) );
try
{
- Thread.sleep(wait <<= 2);
+ Thread.sleep(wait);
}
catch (InterruptedException e)
{
@@ -542,10 +554,8 @@
configuration.getRuntimeConfig().setChannel(channel);
}
+ if (nbst) sanityCheckJGroupsStack((JChannel) channel);
- if (nbst && ((JChannel) channel).getProtocolStack().findProtocol(STREAMING_STATE_TRANSFER.class) == null)
- throw new ConfigurationException("JGroups channel does not use STREAMING_STATE_TRANSFER! This is a requirement for non-blocking state transfer. Either make sure your JGroups configuration uses STREAMING_STATE_TRANSFER or disable non-blocking state transfer.");
-
// Channel.LOCAL *must* be set to false so we don't see our own messages - otherwise invalidations targeted at
// remote instances will be received by self.
channel.setOpt(Channel.LOCAL, false);
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java 2009-02-27 10:26:02 UTC (rev 7801)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java 2009-02-27 12:38:16 UTC (rev 7802)
@@ -23,7 +23,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.InternalNode;
@@ -97,7 +96,7 @@
{
activated = txLog.activate();
if (! activated)
- throw new CacheException("Busy performing state transfer for someone else");
+ throw new StateProviderBusyException("Busy performing state transfer for someone else");
if (trace) log.trace("Transaction log activated!");
}
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java 2009-02-27 10:26:02 UTC (rev 7801)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java 2009-02-27 12:38:16 UTC (rev 7802)
@@ -21,16 +21,6 @@
*/
package org.jboss.cache.statetransfer;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
@@ -61,6 +51,16 @@
import org.jgroups.Address;
import org.jgroups.Channel;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
public class DefaultStateTransferIntegrator implements StateTransferIntegrator
{
@@ -120,6 +120,49 @@
integrateTxLog(ois);
}
+ private void doPartialFlush(Channel channel, List<Address> members)
+ {
+ int retries = 5;
+ int sleepBetweenRetries = 250;
+ int sleepIncreaseFactor = 2;
+ if (trace) log.trace("Attempting a partial flush on members " + members + " with up to " + retries + " retries.");
+
+ boolean success = false;
+ int i;
+ for (i=1; i<=retries; i++)
+ {
+ if (trace) log.trace("Attempt number " + i);
+ try
+ {
+ if (success = channel.startFlush(members, false)) break;
+ if (trace) log.trace("Channel.startFlush() returned false!");
+ }
+ catch (Exception e)
+ {
+ if (trace) log.trace("Caught exception attempting a partial flush", e);
+ }
+ try
+ {
+ if (trace) log.trace("Partial state transfer failed. Backing off for " + sleepBetweenRetries + " millis and retrying");
+ Thread.sleep(sleepBetweenRetries);
+ sleepBetweenRetries *= sleepIncreaseFactor;
+ }
+ catch (InterruptedException ie)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ if (success)
+ {
+ if (log.isDebugEnabled()) log.debug("Partial flush between " + members + " succeeded!");
+ }
+ else
+ {
+ throw new CacheException("Could initiate partial flush between " +members+ "! State-transfer failed!");
+ }
+ }
+
private void integrateTxLog(ObjectInputStream ois) throws Exception
{
if (trace)
@@ -129,16 +172,9 @@
Channel channel = manager.getChannel();
- List<Address> targets = new ArrayList<Address>(2);
- targets.add(channel.getLocalAddress());
- targets.add(manager.getLastStateTransferSource());
+ List<Address> targets = Arrays.asList(channel.getLocalAddress(), manager.getLastStateTransferSource());
+ doPartialFlush(channel, targets);
- if (trace)
- log.trace("Flushing targets: " + targets);
-
- if (!channel.startFlush(targets, false))
- throw new CacheException("Could not flush channel! State-transfer failed!");
-
try
{
if (trace)
@@ -169,8 +205,7 @@
}
finally
{
- if (trace)
- log.trace("Stopping flush");
+ if (trace) log.trace("Stopping partial flush");
channel.stopFlush(targets);
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java 2009-02-27 10:26:02 UTC (rev 7801)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java 2009-02-27 12:38:16 UTC (rev 7802)
@@ -103,6 +103,7 @@
if (log.isDebugEnabled())
log.debug("Generating in-memory (transient) state for subtree " + fqn);
+ // this method will throw a StateProviderBusyException if the state provider is busy providing state to someone else.
generator.generateState(out, subtreeRoot, fetchTransientState, fetchPersistentState, suppressErrors);
if (log.isDebugEnabled())
Added: core/trunk/src/main/java/org/jboss/cache/statetransfer/StateProviderBusyException.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/StateProviderBusyException.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/StateProviderBusyException.java 2009-02-27 12:38:16 UTC (rev 7802)
@@ -0,0 +1,29 @@
+package org.jboss.cache.statetransfer;
+
+/**
+ * Thrown when a state provider is busy
+ *
+ * @author Manik Surtani
+ * @since 3.1
+ */
+public class StateProviderBusyException extends Exception
+{
+ public StateProviderBusyException()
+ {
+ }
+
+ public StateProviderBusyException(String message)
+ {
+ super(message);
+ }
+
+ public StateProviderBusyException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public StateProviderBusyException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/NBSTCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/NBSTCacheLoaderTest.java 2009-02-27 10:26:02 UTC (rev 7801)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/NBSTCacheLoaderTest.java 2009-02-27 12:38:16 UTC (rev 7802)
@@ -10,7 +10,7 @@
import java.io.IOException;
-@Test(groups = "functional", testName = "statetransfer.NBSTCacheLoaderTest", enabled = false)
+@Test(groups = "functional", testName = "statetransfer.NBSTCacheLoaderTest")
public class NBSTCacheLoaderTest extends NonBlockingStateTransferTest
{
int id;
15 years, 10 months
JBoss Cache SVN: r7801 - core/trunk/src/test/java/org/jboss/cache/statetransfer.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-27 05:26:02 -0500 (Fri, 27 Feb 2009)
New Revision: 7801
Modified:
core/trunk/src/test/java/org/jboss/cache/statetransfer/NonBlockingStateTransferTest.java
Log:
Writer thread clears data periodically to prevent OOMs
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/NonBlockingStateTransferTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/NonBlockingStateTransferTest.java 2009-02-27 10:06:26 UTC (rev 7800)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/NonBlockingStateTransferTest.java 2009-02-27 10:26:02 UTC (rev 7801)
@@ -102,11 +102,19 @@
{
try
{
- if (tx)
- cache.getConfiguration().getRuntimeConfig().getTransactionManager().begin();
- cache.put("/test" + c, "test", c++);
- if (tx)
- cache.getConfiguration().getRuntimeConfig().getTransactionManager().commit();
+ if (c % 1000 == 0)
+ {
+ startTxIfNeeded();
+ for (int i=0; i<1000; i++) cache.removeNode("/test" + i);
+ commitTxIfNeeded();
+ c = 0;
+ }
+ else
+ {
+ startTxIfNeeded();
+ cache.put("/test" + c, "test", c++);
+ commitTxIfNeeded();
+ }
}
catch (Exception e)
{
@@ -117,6 +125,16 @@
result = c;
}
+ private void startTxIfNeeded() throws Exception
+ {
+ if (tx) cache.getConfiguration().getRuntimeConfig().getTransactionManager().begin();
+ }
+
+ private void commitTxIfNeeded() throws Exception
+ {
+ if (tx) cache.getConfiguration().getRuntimeConfig().getTransactionManager().commit();
+ }
+
public void stop()
{
stop = true;
15 years, 10 months
JBoss Cache SVN: r7800 - core/trunk/src/test/java/org/jboss/cache/loader/testloaders.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-27 05:06:26 -0500 (Fri, 27 Feb 2009)
New Revision: 7800
Modified:
core/trunk/src/test/java/org/jboss/cache/loader/testloaders/DummyInMemoryCacheLoader.java
Log:
Logging changes
Modified: core/trunk/src/test/java/org/jboss/cache/loader/testloaders/DummyInMemoryCacheLoader.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/testloaders/DummyInMemoryCacheLoader.java 2009-02-27 04:24:29 UTC (rev 7799)
+++ core/trunk/src/test/java/org/jboss/cache/loader/testloaders/DummyInMemoryCacheLoader.java 2009-02-27 10:06:26 UTC (rev 7800)
@@ -61,8 +61,7 @@
public Set<?> getChildrenNames(Fqn fqn) throws Exception
{
- if (log.isDebugEnabled()) log.debug("Calling getChildrenNames on Fqn " + fqn + ". Data map = " + getNodesMap());
- debugMessage("Calling getChildrenNames on Fqn " + fqn + ". Data map = " + getNodesMap());
+ debugMessage("Calling getChildrenNames on Fqn " + fqn);
if (!getNodesMap().containsKey(fqn))
{
log.debug("node not in loader");
@@ -95,7 +94,6 @@
DummyNode dn = getNodesMap().get(name);
Map<Object, Object> d = dn != null ? dn.data : null;
- if (log.isDebugEnabled()) log.debug("Getting data for fqn " + name + " = " + d);
debugMessage("Getting data for fqn " + name + " = " + d);
return stripNULLs(d);
}
15 years, 10 months
JBoss Cache SVN: r7797 - in core/trunk/src: test/java/org/jboss/cache/loader/testloaders and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-26 10:05:48 -0500 (Thu, 26 Feb 2009)
New Revision: 7797
Added:
core/trunk/src/test/java/org/jboss/cache/loader/testloaders/DummyInMemoryCacheLoaderConfig.java
core/trunk/src/test/java/org/jboss/cache/loader/testloaders/DummySharedInMemoryCacheLoaderConfig.java
core/trunk/src/test/java/org/jboss/cache/statetransfer/NBSTCacheLoaderTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java
core/trunk/src/test/java/org/jboss/cache/loader/testloaders/DummyInMemoryCacheLoader.java
core/trunk/src/test/java/org/jboss/cache/statetransfer/NonBlockingStateTransferTest.java
core/trunk/src/test/java/org/jboss/cache/util/TestingUtil.java
Log:
NBST tweaks + test for NBST with loaders
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java 2009-02-26 14:56:19 UTC (rev 7796)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java 2009-02-26 15:05:48 UTC (rev 7797)
@@ -82,7 +82,8 @@
public void start()
{
fetchTransientState = configuration.isFetchInMemoryState();
- fetchPersistentState = cacheLoaderManager != null && cacheLoaderManager.isFetchPersistentState();
+ // do not do state transfers if the cache loader config is shared
+ fetchPersistentState = cacheLoaderManager != null && cacheLoaderManager.isFetchPersistentState() && !configuration.getCacheLoaderConfig().isShared();
stateRetrievalTimeout = configuration.getStateRetrievalTimeout();
}
Modified: core/trunk/src/test/java/org/jboss/cache/loader/testloaders/DummyInMemoryCacheLoader.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/testloaders/DummyInMemoryCacheLoader.java 2009-02-26 14:56:19 UTC (rev 7796)
+++ core/trunk/src/test/java/org/jboss/cache/loader/testloaders/DummyInMemoryCacheLoader.java 2009-02-26 15:05:48 UTC (rev 7797)
@@ -290,5 +290,5 @@
public void wipe()
{
nodes.clear();
- }
+ }
}
Added: core/trunk/src/test/java/org/jboss/cache/loader/testloaders/DummyInMemoryCacheLoaderConfig.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/testloaders/DummyInMemoryCacheLoaderConfig.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/loader/testloaders/DummyInMemoryCacheLoaderConfig.java 2009-02-26 15:05:48 UTC (rev 7797)
@@ -0,0 +1,40 @@
+package org.jboss.cache.loader.testloaders;
+
+import org.jboss.cache.config.CacheLoaderConfig;
+
+import java.util.Properties;
+import java.io.IOException;
+
+public class DummyInMemoryCacheLoaderConfig extends CacheLoaderConfig.IndividualCacheLoaderConfig
+{
+ String storeName;
+ public DummyInMemoryCacheLoaderConfig()
+ {
+ setClassName(DummyInMemoryCacheLoader.class.getName());
+ }
+
+ public DummyInMemoryCacheLoaderConfig(String storeName)
+ {
+ setClassName(DummyInMemoryCacheLoader.class.getName());
+ this.storeName = storeName;
+ }
+
+ public void setProperties(Properties p)
+ {
+ if (storeName != null)
+ {
+ if (p == null) p = new Properties();
+ p.setProperty("bin", storeName);
+ }
+ super.setProperties(p);
+ }
+
+ public void setProperties(String s) throws IOException
+ {
+ super.setProperties(s);
+ if (storeName != null)
+ {
+ this.properties.setProperty("bin", storeName);
+ }
+ }
+}
Added: core/trunk/src/test/java/org/jboss/cache/loader/testloaders/DummySharedInMemoryCacheLoaderConfig.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/testloaders/DummySharedInMemoryCacheLoaderConfig.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/loader/testloaders/DummySharedInMemoryCacheLoaderConfig.java 2009-02-26 15:05:48 UTC (rev 7797)
@@ -0,0 +1,15 @@
+package org.jboss.cache.loader.testloaders;
+
+public class DummySharedInMemoryCacheLoaderConfig extends DummyInMemoryCacheLoaderConfig
+{
+ public DummySharedInMemoryCacheLoaderConfig()
+ {
+ setClassName(DummySharedInMemoryCacheLoader.class.getName());
+ }
+
+ public DummySharedInMemoryCacheLoaderConfig(String storeName)
+ {
+ super(storeName);
+ setClassName(DummySharedInMemoryCacheLoader.class.getName());
+ }
+}
Added: core/trunk/src/test/java/org/jboss/cache/statetransfer/NBSTCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/NBSTCacheLoaderTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/NBSTCacheLoaderTest.java 2009-02-26 15:05:48 UTC (rev 7797)
@@ -0,0 +1,91 @@
+package org.jboss.cache.statetransfer;
+
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.loader.CacheLoader;
+import org.jboss.cache.loader.testloaders.DummySharedInMemoryCacheLoaderConfig;
+import org.jboss.cache.util.TestingUtil;
+import static org.testng.AssertJUnit.*;
+import org.testng.annotations.Test;
+
+import java.io.IOException;
+
+@Test(groups = "functional", testName = "statetransfer.NBSTCacheLoaderTest", enabled = false)
+public class NBSTCacheLoaderTest extends NonBlockingStateTransferTest
+{
+ int id;
+ ThreadLocal<Boolean> sharedCacheLoader = new ThreadLocal<Boolean>()
+ {
+ protected Boolean initialValue()
+ {
+ return false;
+ }
+ };
+
+ @Override
+ protected CacheSPI<Object, Object> createCache(String name, boolean start) throws IOException
+ {
+ CacheSPI<Object, Object> c = super.createCache(name, false);
+
+ CacheLoaderConfig clmc = new CacheLoaderConfig();
+ DummySharedInMemoryCacheLoaderConfig clc = new DummySharedInMemoryCacheLoaderConfig("store number " + id++);
+ clc.setFetchPersistentState(true);
+ clc.setProperties("debug=true");
+ clmc.setShared(sharedCacheLoader.get());
+ clmc.addIndividualCacheLoaderConfig(clc);
+ c.getConfiguration().setCacheLoaderConfig(clmc);
+
+ if (start) c.start();
+ return c;
+ }
+
+ @Override
+ protected void writeInitialData(final CacheSPI<Object, Object> cache)
+ {
+ super.writeInitialData(cache);
+ cache.evict(A_B);
+ cache.evict(A_C);
+ cache.evict(A_D);
+ }
+
+ protected void verifyInitialDataOnLoader(CacheSPI<Object, Object> c) throws Exception
+ {
+ CacheLoader l = TestingUtil.getCacheLoader(c);
+ assertEquals("Incorrect name for /a/b on loader", JOE, l.get(A_B).get("name"));
+ assertEquals("Incorrect age for /a/b on loader", TWENTY, l.get(A_B).get("age"));
+ assertEquals("Incorrect name for /a/c on loader", BOB, l.get(A_C).get("name"));
+ assertEquals("Incorrect age for /a/c on loader", FORTY, l.get(A_C).get("age"));
+ }
+
+ protected void verifyNoData(CacheSPI<Object, Object> c)
+ {
+ assert c.getRoot().getChildrenNames().isEmpty(): "Cache should be empty!";
+ }
+
+ protected void verifyNoDataOnLoader(CacheSPI<Object, Object> c) throws Exception
+ {
+ CacheLoader l = TestingUtil.getCacheLoader(c);
+ assertNull("Node /a/b should not exist on loader", l.get(A_B));
+ assertNull("Node /a/c should not exist on loader", l.get(A_C));
+ assertNull("Node /a/d should not exist on loader", l.get(A_D));
+ }
+
+
+ public void testSharedLoader() throws Exception
+ {
+ sharedCacheLoader.set(true);
+ CacheSPI<Object, Object> c1 = createCache("testSharedLoader", true);
+ writeInitialData(c1);
+
+ // starting the second cache would initialize an in-memory state transfer but not a persistent one since the loader is shared
+ CacheSPI<Object, Object> c2 = createCache("testSharedLoader", true);
+
+ TestingUtil.blockUntilViewsReceived(60000, c1, c2);
+
+ verifyInitialDataOnLoader(c1);
+ verifyInitialData(c1);
+
+ verifyNoDataOnLoader(c2);
+ verifyNoData(c2);
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/NonBlockingStateTransferTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/NonBlockingStateTransferTest.java 2009-02-26 14:56:19 UTC (rev 7796)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/NonBlockingStateTransferTest.java 2009-02-26 15:05:48 UTC (rev 7797)
@@ -123,13 +123,13 @@
}
}
- private CacheSPI<Object, Object> createCache(String name)
+ private CacheSPI<Object, Object> createCache(String name) throws IOException
{
return createCache(name, true);
}
- private CacheSPI<Object, Object> createCache(String name, boolean start)
+ protected CacheSPI<Object, Object> createCache(String name, boolean start) throws IOException
{
Configuration config = UnitTestConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC);
config.setSyncCommitPhase(true);
@@ -298,7 +298,7 @@
log.info("testSTWithWritingTxThread end - " + testCount);
}
- private void thirdWritingCacheTest(boolean tx, String name) throws InterruptedException
+ private void thirdWritingCacheTest(boolean tx, String name) throws InterruptedException, IOException
{
CacheSPI<Object, Object> cache1 = null, cache2 = null, cache3 = null;
try
@@ -336,7 +336,7 @@
}
}
- private void verifyInitialData(CacheSPI<Object, Object> cache2)
+ protected void verifyInitialData(CacheSPI<Object, Object> cache2)
{
assertEquals("Incorrect name for /a/b", JOE, cache2.get(A_B, "name"));
assertEquals("Incorrect age for /a/b", TWENTY, cache2.get(A_B, "age"));
@@ -344,7 +344,7 @@
assertEquals("Incorrect age for /a/c", FORTY, cache2.get(A_C, "age"));
}
- private void writeInitialData(final CacheSPI<Object, Object> cache1)
+ protected void writeInitialData(final CacheSPI<Object, Object> cache1)
{
cache1.put(A_B, "name", JOE);
cache1.put(A_B, "age", TWENTY);
@@ -352,7 +352,7 @@
cache1.put(A_C, "age", FORTY);
}
- private void writingThreadTest(boolean tx, String name) throws InterruptedException
+ private void writingThreadTest(boolean tx, String name) throws InterruptedException, IOException
{
CacheSPI<Object, Object> cache1 = null, cache2 = null;
try
Modified: core/trunk/src/test/java/org/jboss/cache/util/TestingUtil.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/util/TestingUtil.java 2009-02-26 14:56:19 UTC (rev 7796)
+++ core/trunk/src/test/java/org/jboss/cache/util/TestingUtil.java 2009-02-26 15:05:48 UTC (rev 7797)
@@ -11,6 +11,7 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.CacheStatus;
import org.jboss.cache.Fqn;
+import org.jboss.cache.UnitTestCacheFactory;
import org.jboss.cache.commands.CommandsFactory;
import org.jboss.cache.commands.VisitableCommand;
import org.jboss.cache.factories.ComponentRegistry;
@@ -20,17 +21,16 @@
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.lock.LockManager;
+import org.jgroups.Channel;
import org.jgroups.JChannel;
+import javax.transaction.TransactionManager;
import java.io.File;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
-import javax.transaction.TransactionManager;
-import org.jboss.cache.UnitTestCacheFactory;
-import org.jgroups.Channel;
/**
* Utilities for unit testing JBossCache.
@@ -720,4 +720,10 @@
public static int getThreadId() {
return threadID.get();
}
+
+ public static CacheLoader getCacheLoader(Cache<?, ?> c)
+ {
+ CacheLoaderManager clm = extractComponentRegistry(c).getComponent(CacheLoaderManager.class);
+ return clm == null ? null : clm.getCacheLoader();
+ }
}
15 years, 10 months
JBoss Cache SVN: r7796 - demos/core-demo-gui/trunk.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-02-26 09:56:19 -0500 (Thu, 26 Feb 2009)
New Revision: 7796
Modified:
demos/core-demo-gui/trunk/pom.xml
Log:
Modified: demos/core-demo-gui/trunk/pom.xml
===================================================================
--- demos/core-demo-gui/trunk/pom.xml 2009-02-26 14:53:37 UTC (rev 7795)
+++ demos/core-demo-gui/trunk/pom.xml 2009-02-26 14:56:19 UTC (rev 7796)
@@ -10,7 +10,7 @@
</parent>
<groupId>org.jboss.cache</groupId>
<artifactId>jbosscache-demo</artifactId>
- <version>1.2-SNAPSHOT</version>
+ <version>1.3-SNAPSHOT</version>
<name>JBoss Cache - Core Edition GUI Demo</name>
<description>JBoss Cache - Core Edition GUI Demo</description>
<packaging>jar</packaging>
@@ -18,7 +18,7 @@
<dependency>
<groupId>org.jboss.cache</groupId>
<artifactId>jbosscache-core</artifactId>
- <version>3.0.3.GA</version>
+ <version>3.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>jgoodies</groupId>
15 years, 10 months