JBoss Cache SVN: r4891 - core/trunk/src/test/java/org/jboss/cache/passivation.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-19 22:30:36 -0500 (Wed, 19 Dec 2007)
New Revision: 4891
Modified:
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java
Log:
Removed test for obsolete API
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java 2007-12-20 03:30:17 UTC (rev 4890)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java 2007-12-20 03:30:36 UTC (rev 4891)
@@ -118,24 +118,6 @@
return exists(fqn, null);
}
- public void testPrintPassivation() throws Exception
- {
- final Fqn<String> NODE = Fqn.fromString("/test");
- final String KEY = "key";
- loader.remove(NODE);
- cache.put(NODE, KEY, 10);
- cache.evict(NODE, true);
- assertTrue(loader.exists(NODE));
- addDelay();
- log.info("print node " + NODE);
- Node ret = cache.getRoot().getChild(NODE);
- assertNotNull(ret);
- log.info("loader exists " + NODE);
- assertTrue(!loader.exists(NODE));
- cache.get(NODE, KEY);
- assertFalse(loader.exists(NODE));
- }
-
public void testPutPassivation() throws Exception
{
final Fqn NODE = Fqn.fromString("/test");
17 years, 2 months
JBoss Cache SVN: r4890 - core/trunk/src/main/java/org/jboss/cache/invocation.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-19 22:30:17 -0500 (Wed, 19 Dec 2007)
New Revision: 4890
Modified:
core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
Log:
fixed recursive invocations, e.g., via cache listeners where the context is set to null (i.e., removed)
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2007-12-20 03:11:39 UTC (rev 4889)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2007-12-20 03:30:17 UTC (rev 4890)
@@ -289,7 +289,9 @@
public void setInvocationContext(InvocationContext ctx)
{
- invocationContextContainer.set(ctx);
+ // assume a null ctx is meant to "un-set" the context?
+ if (ctx == null) invocationContextContainer.remove();
+ else invocationContextContainer.set(ctx);
}
public Address getLocalAddress()
17 years, 2 months
JBoss Cache SVN: r4889 - in core/trunk/src: main/java/org/jboss/cache/invocation and 5 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-19 22:11:39 -0500 (Wed, 19 Dec 2007)
New Revision: 4889
Added:
core/trunk/src/test/java/org/jboss/cache/loader/DummyCountingCacheLoader.java
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java
core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java
core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java
core/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java
core/trunk/src/test/java/org/jboss/cache/loader/ClusteredCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/loader/DataSourceIntegrationTest.java
core/trunk/src/test/java/org/jboss/cache/loader/JDBCCacheLoaderConnectionTest.java
core/trunk/src/test/java/org/jboss/cache/loader/SharedCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java
Log:
Cache loader and passivation bugs fixed
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-20 03:11:39 UTC (rev 4889)
@@ -2772,50 +2772,6 @@
}
/**
- * A 'clustered get' call, called from a remote ClusteredCacheLoader.
- *
- * @return a List containing 2 elements: (true or false) and a value (Object). If buddy replication
- * is used one further element is added - an Fqn of the backup subtree in which this node may be found.
- */
- public List _clusteredGet(MethodCall methodCall, Boolean searchBackupSubtrees)
- {
- MethodCall call = methodCall;
- if (log.isTraceEnabled()) log.trace("Clustered Get called with params: " + call + ", " + searchBackupSubtrees);
- Method m = call.getMethod();
- Object[] args = call.getArgs();
-
- Object callResults = null;
-
- try
- {
- Fqn fqn = (Fqn) args[0];
-
- if (log.isTraceEnabled()) log.trace("Clustered get: invoking call " + m + " with Fqn " + fqn);
- callResults = m.invoke(this, args);
- boolean found = validResult(callResults, call, fqn);
- if (log.isTraceEnabled()) log.trace("Got result " + callResults + ", found=" + found);
- if (found && callResults == null) callResults = createEmptyResults(call);
- }
- catch (Exception e)
- {
- log.warn("Problems processing clusteredGet call", e);
- }
-
- List<Object> results = new ArrayList<Object>(2);
- if (callResults != null)
- {
- results.add(true);
- results.add(callResults);
- }
- else
- {
- results.add(false);
- results.add(null);
- }
- return results;
- }
-
- /**
* Used with buddy replication's data gravitation interceptor. If marshalling is necessary, ensure that the cache is
* configured to use {@link org.jboss.cache.config.Configuration#useRegionBasedMarshalling} and the {@link org.jboss.cache.Region}
* pertaining to the Fqn passed in is activated, and has an appropriate ClassLoader.
@@ -2960,41 +2916,7 @@
}
// ------------- end: buddy replication specific 'lifecycle' method calls
-
-
/**
- * Returns true if the call results returned a valid result.
- */
- private boolean validResult(Object callResults, MethodCall mc, Fqn fqn)
- {
- switch (mc.getMethodId())
- {
- case MethodDeclarations.getDataMapMethodLocal_id:
- case MethodDeclarations.getChildrenNamesMethodLocal_id:
- return callResults != null || exists(fqn);
- case MethodDeclarations.existsMethod_id:
- return (Boolean) callResults;
- default:
- return false;
- }
- }
-
- /**
- * Creates an empty Collection class based on the return type of the method called.
- */
- private Object createEmptyResults(MethodCall mc)
- {
- switch (mc.getMethodId())
- {
- case MethodDeclarations.getDataMapMethodLocal_id:
- case MethodDeclarations.getChildrenNamesMethodLocal_id:
- return Collections.emptyMap();
- default:
- return null;
- }
- }
-
- /**
* Releases all locks for a FQN.
*/
public void _releaseAllLocks(Fqn fqn)
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java 2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java 2007-12-20 03:11:39 UTC (rev 4889)
@@ -1,10 +1,14 @@
package org.jboss.cache.invocation;
import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Fqn;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodCallFactory;
import org.jboss.cache.marshall.MethodDeclarations;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
/**
@@ -69,4 +73,82 @@
MethodCall m = MethodCallFactory.create(MethodDeclarations.unblockChannelLocal);
invoke(m, true);
}
+
+ /**
+ * A 'clustered get' call, called from a remote ClusteredCacheLoader.
+ *
+ * @return a List containing 2 elements: (true or false) and a value (Object). If buddy replication
+ * is used one further element is added - an Fqn of the backup subtree in which this node may be found.
+ */
+ public List clusteredGet(MethodCall methodCall, Boolean searchBackupSubtrees)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Clustered Get called with params: " + methodCall + ", " + searchBackupSubtrees);
+ Method m = methodCall.getMethod();
+ Object[] args = methodCall.getArgs();
+
+ Object callResults = null;
+
+ try
+ {
+ Fqn fqn = (Fqn) args[0];
+
+ if (log.isTraceEnabled()) log.trace("Clustered get: invoking call " + m + " with Fqn " + fqn);
+ callResults = m.invoke(cache, args);
+ boolean found = validResult(callResults, methodCall, fqn);
+ if (log.isTraceEnabled()) log.trace("Got result " + callResults + ", found=" + found);
+ if (found && callResults == null) callResults = createEmptyResults(methodCall);
+ }
+ catch (Exception e)
+ {
+ log.warn("Problems processing clusteredGet call", e);
+ }
+
+ List<Object> results = new ArrayList<Object>(2);
+ if (callResults != null)
+ {
+ results.add(true);
+ results.add(callResults);
+ }
+ else
+ {
+ results.add(false);
+ results.add(null);
+ }
+ return results;
+ }
+
+ /**
+ * Returns true if the call results returned a valid result.
+ */
+ private boolean validResult(Object callResults, MethodCall mc, Fqn fqn)
+ {
+ switch (mc.getMethodId())
+ {
+ case MethodDeclarations.getDataMapMethodLocal_id:
+ case MethodDeclarations.getChildrenNamesMethodLocal_id:
+ return callResults != null || exists(fqn);
+ case MethodDeclarations.existsMethod_id:
+ return (Boolean) callResults;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * Creates an empty Collection class based on the return type of the method called.
+ */
+ private Object createEmptyResults(MethodCall mc)
+ {
+ switch (mc.getMethodId())
+ {
+ case MethodDeclarations.getDataMapMethodLocal_id:
+ case MethodDeclarations.getChildrenNamesMethodLocal_id:
+ return Collections.emptyMap();
+ default:
+ return null;
+ }
+ }
+
+
}
Modified: core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java 2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java 2007-12-20 03:11:39 UTC (rev 4889)
@@ -352,10 +352,11 @@
}
/**
- * Overrides generated cache loader with the one provided,for backward compat.
+ * Overrides generated cache loader with the one provided,for backward compat. Deprecated, may not prote to all interceptors that need it.
*
* @param loader
*/
+ @Deprecated
public void setCacheLoader(CacheLoader loader)
{
this.loader = loader;
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java 2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/MethodDeclarations.java 2007-12-20 03:11:39 UTC (rev 4889)
@@ -267,7 +267,7 @@
optimisticPrepareMethod = CacheImpl.class.getDeclaredMethod("optimisticPrepare", GlobalTransaction.class, List.class, Map.class, Address.class, boolean.class);
- clusteredGetMethod = CacheImpl.class.getDeclaredMethod("_clusteredGet", MethodCall.class, Boolean.class);
+ clusteredGetMethod = RemoteCacheInvocationDelegate.class.getDeclaredMethod("clusteredGet", MethodCall.class, Boolean.class);
// ------------ buddy replication
Modified: core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java 2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java 2007-12-20 03:11:39 UTC (rev 4889)
@@ -62,7 +62,7 @@
}
@Inject
- private void injectDependencies(Cache cache)
+ private void injectDependencies(CacheSPI cache)
{
this.cache = cache;
}
Modified: core/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java 2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/test/java/org/jboss/cache/loader/AbstractCacheLoaderTestBase.java 2007-12-20 03:11:39 UTC (rev 4889)
@@ -20,7 +20,7 @@
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
-@Test(groups = {"functional"})
+@Test(groups = "functional")
public abstract class AbstractCacheLoaderTestBase
{
protected final Log log = LogFactory.getLog(getClass());
@@ -38,17 +38,17 @@
protected CacheLoaderConfig getSingleCacheLoaderConfig(boolean passivation, String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared, boolean purgeOnStartup) throws Exception
{
String xml = "<config>\n" +
- "<passivation>" + passivation + "</passivation>\n" +
- "<preload>" + preload + "</preload>\n" +
- "<cacheloader>\n" +
- "<class>" + cacheloaderClass + "</class>\n" +
- "<properties>" + properties + "</properties>\n" +
- "<async>" + async + "</async>\n" +
- "<shared>" + shared + "</shared>\n" +
- "<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
- "<purgeOnStartup>" + purgeOnStartup + "</purgeOnStartup>\n" +
- "</cacheloader>\n" +
- "</config>";
+ "<passivation>" + passivation + "</passivation>\n" +
+ "<preload>" + preload + "</preload>\n" +
+ "<cacheloader>\n" +
+ "<class>" + cacheloaderClass + "</class>\n" +
+ "<properties>" + properties + "</properties>\n" +
+ "<async>" + async + "</async>\n" +
+ "<shared>" + shared + "</shared>\n" +
+ "<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
+ "<purgeOnStartup>" + purgeOnStartup + "</purgeOnStartup>\n" +
+ "</cacheloader>\n" +
+ "</config>";
Element element = XmlHelper.stringToElement(xml);
return XmlConfigurationParser.parseCacheLoaderConfig(element);
}
Modified: core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java 2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java 2007-12-20 03:11:39 UTC (rev 4889)
@@ -20,16 +20,16 @@
public class CacheLoaderMethodCallCounterTest extends AbstractCacheLoaderTestBase
{
private CacheSPI cache;
- private DummyCacheLoader dummyLoader;
+ private DummyCountingCacheLoader dummyLoader;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
if (cache != null) tearDown();
cache = (CacheSPI) new DefaultCacheFactory().createCache(false);
- cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCacheLoader.class.getName(), "", false, false, false));
+ cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCountingCacheLoader.class.getName(), "", false, false, false));
cache.start();
- dummyLoader = (DummyCacheLoader) cache.getCacheLoaderManager().getCacheLoader();
+ dummyLoader = (DummyCountingCacheLoader) cache.getCacheLoaderManager().getCacheLoader();
}
@AfterMethod(alwaysRun = true)
@@ -62,7 +62,7 @@
printReport("removeKey", dummyLoader);
}
- private void printReport(String test, DummyCacheLoader d)
+ private void printReport(String test, DummyCountingCacheLoader d)
{
System.out.println("------------------------------");
System.out.println(" Test name: " + test);
Modified: core/trunk/src/test/java/org/jboss/cache/loader/ClusteredCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/ClusteredCacheLoaderTest.java 2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/test/java/org/jboss/cache/loader/ClusteredCacheLoaderTest.java 2007-12-20 03:11:39 UTC (rev 4889)
@@ -49,8 +49,8 @@
public void setUp() throws Exception
{
if (cache1 != null || cache2 != null) tearDown();
- cache1 = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(false);
- cache2 = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(false);
+ cache1 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
+ cache2 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
cache1.getConfiguration().setClusterName("CCL-Test");
cache1.getConfiguration().setStateRetrievalTimeout(2000);
Modified: core/trunk/src/test/java/org/jboss/cache/loader/DataSourceIntegrationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/DataSourceIntegrationTest.java 2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/test/java/org/jboss/cache/loader/DataSourceIntegrationTest.java 2007-12-20 03:11:39 UTC (rev 4889)
@@ -6,7 +6,7 @@
*/
package org.jboss.cache.loader;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.transaction.DummyTransactionManager;
@@ -14,6 +14,7 @@
import static org.testng.AssertJUnit.assertNull;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -25,12 +26,13 @@
import java.sql.SQLException;
import java.util.Properties;
+@Test(groups = "functional")
public class DataSourceIntegrationTest extends AbstractCacheLoaderTestBase
{
private String old_factory = null;
private final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
private final String JNDI_NAME = "java:/MockDS";
- private CacheImpl cache;
+ private CacheSPI cache;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
@@ -65,7 +67,7 @@
{
// expected
}
- cache = (CacheImpl) new DefaultCacheFactory().createCache(false);
+ cache = (CacheSPI) new DefaultCacheFactory().createCache(false);
cache.getConfiguration().setCacheMode("local");
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig(JNDI_NAME));
Copied: core/trunk/src/test/java/org/jboss/cache/loader/DummyCountingCacheLoader.java (from rev 4826, core/trunk/src/test/java/org/jboss/cache/loader/DummyCacheLoader.java)
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/DummyCountingCacheLoader.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/loader/DummyCountingCacheLoader.java 2007-12-20 03:11:39 UTC (rev 4889)
@@ -0,0 +1,237 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.cache.loader;
+
+import org.jboss.cache.CacheImpl;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Modification;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Dummy cache loader that captures the number of times each method is called. Stores statistics statically, mimicking
+ * a shared cache loader.
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
+ */
+public class DummyCountingCacheLoader extends AbstractCacheLoader
+{
+ private static int getChildrenNamesCount = 0, getCount = 0, putCount = 0, existsCount = 0, removeCount = 0;
+
+ public int getGetChildrenNamesCount()
+ {
+ return getChildrenNamesCount;
+ }
+
+ public int getGetCount()
+ {
+ return getCount;
+ }
+
+ public int getPutCount()
+ {
+ return putCount;
+ }
+
+ public int getExistsCount()
+ {
+ return existsCount;
+ }
+
+ public int getRemoveCount()
+ {
+ return removeCount;
+ }
+
+
+ /**
+ * Sets the configuration. Will be called before {@link #create()} and {@link #start()}
+ */
+ public void setConfig(IndividualCacheLoaderConfig config)
+ {
+ }
+
+ public IndividualCacheLoaderConfig getConfig()
+ {
+ return null;
+ }
+
+ /**
+ * This method allows the CacheLoader to set the CacheImpl, therefore allowing the CacheLoader to invoke
+ * methods of the CacheImpl. It can also use the CacheImpl to fetch configuration information. Alternatively,
+ * the CacheLoader could maintain its own configuration<br/>
+ * This method will be called directly after the CacheLoader instance has been created
+ *
+ * @param c The cache on which this loader works
+ */
+ public void setCache(CacheImpl c)
+ {
+ }
+
+ /**
+ * Returns a list of children names, all names are <em>relative</em>. Returns null if the parent node is not found.
+ * The returned set must not be modified, e.g. use Collections.unmodifiableSet(s) to return the result
+ *
+ * @param fqn The FQN of the parent
+ * @return Set<String>. A list of children. Returns null if no children nodes are present, or the parent is
+ * not present
+ */
+ public Set<String> getChildrenNames(Fqn fqn) throws Exception
+ {
+ getChildrenNamesCount++;
+ return null;
+ }
+
+ /**
+ * Returns the value for a given key. Returns null if the node doesn't exist, or the value is not bound
+ *
+ * @param name
+ * @return
+ * @throws Exception
+ */
+ public Object get(Fqn name, Object key) throws Exception
+ {
+ getCount++;
+ return null;
+ }
+
+ /**
+ * Returns all keys and values from the persistent store, given a fully qualified name
+ *
+ * @param name
+ * @return Map<Object,Object> of keys and values for the given node. Returns null if the node was not found, or
+ * if the node has no attributes
+ * @throws Exception
+ */
+ public Map<Object, Object> get(Fqn name) throws Exception
+ {
+ getCount++;
+ return null;
+ }
+
+ /**
+ * Checks whether the CacheLoader has a node with Fqn
+ *
+ * @param name
+ * @return True if node exists, false otherwise
+ */
+ public boolean exists(Fqn name) throws Exception
+ {
+ existsCount++;
+ return false;
+ }
+
+ /**
+ * Inserts key and value into the attributes hashmap of the given node. If the node does not exist, all
+ * parent nodes from the root down are created automatically. Returns the old value
+ */
+ public Object put(Fqn name, Object key, Object value) throws Exception
+ {
+ putCount++;
+ return null;
+ }
+
+ /**
+ * Inserts all elements of attributes into the attributes hashmap of the given node, overwriting existing
+ * attributes, but not clearing the existing hashmap before insertion (making it a union of existing and
+ * new attributes)
+ * If the node does not exist, all parent nodes from the root down are created automatically
+ *
+ * @param name The fully qualified name of the node
+ * @param attributes A Map of attributes. Can be null
+ */
+ public void put(Fqn name, Map attributes) throws Exception
+ {
+ putCount++;
+ }
+
+ /**
+ * Inserts all modifications to the backend store. Overwrite whatever is already in
+ * the datastore.
+ *
+ * @param modifications A List<Modification> of modifications
+ * @throws Exception
+ */
+ public void put(List<Modification> modifications) throws Exception
+ {
+ putCount++;
+ }
+
+ /**
+ * Removes the given key and value from the attributes of the given node. No-op if node doesn't exist
+ */
+ public Object remove(Fqn name, Object key) throws Exception
+ {
+ removeCount++;
+ return null;
+ }
+
+ /**
+ * Removes the given node. If the node is the root of a subtree, this will recursively remove all subnodes,
+ * depth-first
+ */
+ public void remove(Fqn name) throws Exception
+ {
+ removeCount++;
+ }
+
+ /**
+ * Removes all attributes from a given node, but doesn't delete the node itself
+ *
+ * @param name
+ * @throws Exception
+ */
+ public void removeData(Fqn name) throws Exception
+ {
+ removeCount++;
+ }
+
+ @Override
+ public void loadEntireState(ObjectOutputStream os) throws Exception
+ {
+ //intentional no-op
+ }
+
+ @Override
+ public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
+ {
+ // intentional no-op
+ }
+
+ @Override
+ public void storeEntireState(ObjectInputStream is) throws Exception
+ {
+ // intentional no-op
+ }
+
+ @Override
+ public void storeState(Fqn subtree, ObjectInputStream is) throws Exception
+ {
+ // intentional no-op
+ }
+
+
+ @Override
+ public void destroy()
+ {
+ getChildrenNamesCount = 0;
+ getCount = 0;
+ putCount = 0;
+ existsCount = 0;
+ removeCount = 0;
+ }
+
+ public void scrubStats()
+ {
+ destroy();
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/src/test/java/org/jboss/cache/loader/DummyCountingCacheLoader.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: core/trunk/src/test/java/org/jboss/cache/loader/JDBCCacheLoaderConnectionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/JDBCCacheLoaderConnectionTest.java 2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/test/java/org/jboss/cache/loader/JDBCCacheLoaderConnectionTest.java 2007-12-20 03:11:39 UTC (rev 4889)
@@ -1,7 +1,7 @@
package org.jboss.cache.loader;
import org.jboss.cache.Cache;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.testng.annotations.AfterMethod;
@@ -13,7 +13,7 @@
/**
* To test the closing of JDBC connections
*/
-@Test(groups = {"functional"})
+@Test(groups = "functional")
public class JDBCCacheLoaderConnectionTest extends AbstractCacheLoaderTestBase
{
private Cache cache;
@@ -61,7 +61,7 @@
private void assertConnectionsClosed() throws Exception
{
- JDBCCacheLoader loader = (JDBCCacheLoader) ((CacheImpl) cache).getCacheLoader();
+ JDBCCacheLoader loader = (JDBCCacheLoader) ((CacheSPI) cache).getCacheLoaderManager().getCacheLoader();
NonManagedConnectionFactory cf = (NonManagedConnectionFactory) loader.cf;
Connection conn = cf.connection.get();
if (conn != null)
Modified: core/trunk/src/test/java/org/jboss/cache/loader/SharedCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/SharedCacheLoaderTest.java 2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/test/java/org/jboss/cache/loader/SharedCacheLoaderTest.java 2007-12-20 03:11:39 UTC (rev 4889)
@@ -13,6 +13,7 @@
import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import java.util.Iterator;
@@ -21,37 +22,32 @@
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
+@Test(groups = "functional")
public class SharedCacheLoaderTest extends AbstractCacheLoaderTestBase
{
private CacheSPI<Object, Object> cache1, cache2;
- private DummyCacheLoader dummyCacheLoader;
+ private DummyCountingCacheLoader dummyCacheLoader;
@BeforeMethod(alwaysRun = true)
- @SuppressWarnings("deprecation")
public void setUp() throws Exception
{
if (cache1 != null || cache2 != null) tearDown();
// set up 2 instances of CacheImpl with shared CacheLoaders.
- cache1 = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(false);
- cache2 = (CacheSPI<Object, Object>) new DefaultCacheFactory().createCache(false);
+ cache1 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
+ cache2 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
cache1.getConfiguration().setCacheMode("REPL_SYNC");
cache2.getConfiguration().setCacheMode("REPL_SYNC");
- cache1.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummySharedInMemoryCacheLoader.class.getName(), "", false, false, true));
- cache2.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummySharedInMemoryCacheLoader.class.getName(), "", false, false, true));
+ cache1.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCountingCacheLoader.class.getName(), "", false, false, true));
+ cache2.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCountingCacheLoader.class.getName(), "", false, false, true));
cache1.start();
cache2.start();
- // force setting up the same cache loader class
-// dummyCacheLoader = new DummyCacheLoader();
-//
-// cache1.setCacheLoader(dummyCacheLoader);
-// cache2.setCacheLoader(dummyCacheLoader);
-// findCacheStoreInterceptor(cache1).setCache(cache1);
-// findCacheStoreInterceptor(cache2).setCache(cache2);
+ dummyCacheLoader = new DummyCountingCacheLoader(); // statistics are stored statically so this is safe.
+ dummyCacheLoader.scrubStats();
}
protected CacheStoreInterceptor findCacheStoreInterceptor(CacheSPI cache)
Modified: core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java 2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java 2007-12-20 03:11:39 UTC (rev 4889)
@@ -7,8 +7,10 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.factories.InterceptorChainFactory;
+import org.jboss.cache.interceptors.CacheLoaderInterceptor;
+import org.jboss.cache.interceptors.CacheStoreInterceptor;
import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.reflect.ReflectionUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -20,8 +22,6 @@
import java.util.Set;
/**
- * //TODO: MANIK: Javadoc this class
- *
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 2.0.0
*/
@@ -47,8 +47,8 @@
mockCacheLoader = EasyMock.createMock(CacheLoader.class);
cache.getCacheLoaderManager().setCacheLoader(mockCacheLoader);
- // re-set the cache so that the mock CL is registered with the inerceptors.
- TestingUtil.extractComponentRegistry(cache).getComponent(InterceptorChainFactory.class).correctInterceptorChaining(cache.getInterceptorChain());
+ ReflectionUtil.setValue(TestingUtil.findInterceptor(cache, CacheLoaderInterceptor.class), "loader", mockCacheLoader);
+ ReflectionUtil.setValue(TestingUtil.findInterceptor(cache, CacheStoreInterceptor.class), "loader", mockCacheLoader);
// lifecycle stuff
mockCacheLoader.stop();
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java 2007-12-20 02:21:56 UTC (rev 4888)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java 2007-12-20 03:11:39 UTC (rev 4889)
@@ -298,7 +298,6 @@
keys = cache.getNode(Fqn.fromString("/a/b/c")).getKeys();
assertNotNull(keys);
assertEquals(1, keys.size());
- keys.add("myKey");
}
@@ -404,7 +403,7 @@
{
cache.put("/a/b/c", null);
}
- Set children = cache.getRoot().getChildrenNames();// get "null* node children names
+ Set children = cache.getChildrenNames((Fqn<String>) null);// get "null* node children names
assertTrue(children.isEmpty());
}
catch (Exception e)
@@ -704,7 +703,7 @@
cache.removeNode("/x");
assertNull(cache.get(key, "keyA"));
addDelay();
- Set<Object> keys = cache.getNode(key).getKeys();
+ Set<Object> keys = cache.getKeys(key);
assertNull(keys);
cache.removeNode("/x");
}
17 years, 2 months
JBoss Cache SVN: r4888 - core/trunk/src/main/java/org/jboss/cache/util.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-19 21:21:56 -0500 (Wed, 19 Dec 2007)
New Revision: 4888
Modified:
core/trunk/src/main/java/org/jboss/cache/util/BeanUtils.java
Log:
Very noisy logs!
Modified: core/trunk/src/main/java/org/jboss/cache/util/BeanUtils.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/BeanUtils.java 2007-12-20 02:11:58 UTC (rev 4887)
+++ core/trunk/src/main/java/org/jboss/cache/util/BeanUtils.java 2007-12-20 02:21:56 UTC (rev 4888)
@@ -78,8 +78,7 @@
}
catch (NoSuchMethodException e)
{
- if (log.isTraceEnabled())
- log.trace("Unable to find method " + getterName(componentClass) + " in class " + target);
+ //if (log.isTraceEnabled()) log.trace("Unable to find method " + getterName(componentClass) + " in class " + target);
return null;
}
}
@@ -99,8 +98,7 @@
}
catch (NoSuchMethodException e)
{
- if (log.isTraceEnabled())
- log.trace("Unable to find method " + setterName(componentClass) + " in class " + target);
+ //if (log.isTraceEnabled()) log.trace("Unable to find method " + setterName(componentClass) + " in class " + target);
return null;
}
}
17 years, 2 months
JBoss Cache SVN: r4887 - in core/trunk/src: main/java/org/jboss/cache/factories and 3 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-19 21:11:58 -0500 (Wed, 19 Dec 2007)
New Revision: 4887
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java
Log:
Fixed cache loading issues
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-19 21:51:57 UTC (rev 4886)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-20 02:11:58 UTC (rev 4887)
@@ -850,6 +850,8 @@
}
disp = null;
transactionManager = null;
+
+ componentRegistry.reset();
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2007-12-19 21:51:57 UTC (rev 4886)
+++ core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2007-12-20 02:11:58 UTC (rev 4887)
@@ -143,7 +143,6 @@
// make sure we set the CacheImpl and CacheSPI instance in the component registry.
componentRegistry.registerComponent(cache);
componentRegistry.registerComponent(CacheSPI.class.getName(), spi);
- componentRegistry.registerComponent(Cache.class.getName(), spi);
}
public Cache<K, V> createCache(InputStream is) throws ConfigurationException
Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2007-12-19 21:51:57 UTC (rev 4886)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2007-12-20 02:11:58 UTC (rev 4887)
@@ -120,12 +120,17 @@
Component c = new Component(name, component);
componentLookup.put(name, c);
+ addComponentDependencies(c);
+ c.changeState(overallState == null ? CONSTRUCTED : overallState);
+ }
+
+ protected void addComponentDependencies(Component c)
+ {
// build any dependent components if necessary
for (Dependency d : c.dependencies)
{
getOrCreateComponent(d.name, d.type);
}
- c.changeState(overallState);
}
public <T> T getComponent(Class<T> c)
@@ -475,8 +480,25 @@
*/
public void reset()
{
+ // the bootstrap classes
+ Component spi = componentLookup.get(CacheSPI.class.getName());
+ Component impl = componentLookup.get(CacheImpl.class.getName());
+ Component conf = componentLookup.get(Configuration.class.getName());
+ Component cr = componentLookup.get(ComponentRegistry.class.getName());
+
componentLookup.clear();
- overallState = CONSTRUCTED;
+
+ spi.changeState(CONSTRUCTED);
+ impl.changeState(CONSTRUCTED);
+ conf.changeState(CONSTRUCTED);
+ cr.changeState(CONSTRUCTED);
+
+ componentLookup.put(Configuration.class.getName(), conf);
+ componentLookup.put(ComponentRegistry.class.getName(), cr);
+ componentLookup.put(CacheImpl.class.getName(), impl);
+ componentLookup.put(CacheSPI.class.getName(), spi);
+
+ overallState = null;
}
/**
@@ -505,6 +527,12 @@
void moveComponentsToState(State state)
{
+ if (overallState == null)
+ {
+ // we have been destroyed! Need to bootstrap again.
+ bootstrap();
+ }
+
for (Component c : componentLookup.values())
{
c.changeState(state);
@@ -513,11 +541,27 @@
}
/**
+ * Always assumes that the 4 core bootstrap components are in the registry. Will now attempt to make sure their dependencies are built.
+ */
+ void bootstrap()
+ {
+ // the bootstrap classes
+ Component spi = componentLookup.get(CacheSPI.class.getName());
+ Component impl = componentLookup.get(CacheImpl.class.getName());
+ Component conf = componentLookup.get(Configuration.class.getName());
+ Component cr = componentLookup.get(ComponentRegistry.class.getName());
+ addComponentDependencies(spi);
+ addComponentDependencies(impl);
+ addComponentDependencies(conf);
+ addComponentDependencies(cr);
+ }
+
+ /**
* Represents the state of a component
*/
enum State
{
- STOPPED, CONSTRUCTED, WIRED, STARTED;
+ DESTROYED, STOPPED, CONSTRUCTED, WIRED, STARTED;
/**
* Tests whether the current state is "greater" than the state passed in
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2007-12-19 21:51:57 UTC (rev 4886)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheStoreInterceptor.java 2007-12-20 02:11:58 UTC (rev 4887)
@@ -195,7 +195,6 @@
{
if (!inTransaction())
{
- loader.remove(fqn, key);
Object returnValue = loader.remove(fqn, key);
nextInterceptor(ctx);
return returnValue;
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2007-12-19 21:51:57 UTC (rev 4886)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2007-12-20 02:11:58 UTC (rev 4887)
@@ -76,6 +76,20 @@
this.lockTable = lockTable;
}
+ private void reset()
+ {
+ this.stateTransferManager = null;
+ this.cacheLoaderManager = null;
+ this.notifier = null;
+ this.transactionManager = null;
+ this.buddyManager = null;
+ this.transactionTable = null;
+ this.rpcManager = null;
+ this.regionManager = null;
+ this.marshaller = null;
+ this.lockTable = null;
+ }
+
@Override
public String toString()
{
@@ -259,6 +273,7 @@
public void destroy()
{
+ reset();
cache.destroy();
}
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java 2007-12-19 21:51:57 UTC (rev 4886)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java 2007-12-20 02:11:58 UTC (rev 4887)
@@ -52,7 +52,7 @@
public void setChildrenLoaded(boolean loaded)
{
- node.setChildrenLoaded(true);
+ node.setChildrenLoaded(loaded);
}
public boolean isDataLoaded()
Modified: core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java 2007-12-19 21:51:57 UTC (rev 4886)
+++ core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java 2007-12-20 02:11:58 UTC (rev 4887)
@@ -419,7 +419,6 @@
keys = cache.getNode("/a/b/c").getKeys();
assertNotNull(keys);
assertEquals(1, keys.size());
- keys.add("myKey");
}
@@ -519,7 +518,7 @@
{
cache.put("/a/b/c", null);
}
- Set children = cache.getRoot().getChildrenNames();
+ Set children = cache.getChildrenNames((Fqn<String>) null);
assertTrue(children.isEmpty());
}
catch (Exception e)
@@ -754,9 +753,6 @@
cache.evict(Fqn.fromString("/a/b"));
cache.evict(Fqn.fromString("/a"));
- // now load the children - this set childrenLoaded in /a/b to true
-// cache.getNode("/a/b").getChildrenNames();
-
NodeSPI n = (NodeSPI) cache.getNode("/a/b");
assert !n.isChildrenLoaded();
@@ -966,7 +962,7 @@
cache.removeNode("/x");
assertNull(cache.get(key, "keyA"));
addDelay();
- Set keys = cache.getNode(key).getKeys();
+ Set keys = cache.getKeys(key);
assertNull("got keys " + keys, keys);
cache.removeNode("/x");
}
@@ -1094,8 +1090,8 @@
assertEquals(null, cache.get("/one/two/three/four", "key2"));
addDelay();
assertNull("Loader does not have node /one/two/three", loader.get(Fqn.fromString("/one/two/three")));
- assertEquals("Cache does not have node /one/two/three", null, cache.getNode("/one/two/three").getKeys());
- Set<?> children = cache.getNode("/one").getChildrenNames();
+ assertNull("Cache does not have node /one/two/three", cache.getKeys("/one/two/three"));
+ Set<?> children = cache.getChildrenNames("/one");
assertEquals("Cache has no children under /one", 0, children.size());
children = loader.getChildrenNames(Fqn.fromString("/one"));
assertEquals("Loader has no children under /one", null, children);
17 years, 2 months
Build failed in Hudson: jboss-cache-core-jdk1.5 » JBoss Cache - Core Edition #185
by jboss-qa-internal@redhat.com
See https://hudson.jboss.org/hudson/job/jboss-cache-core-jdk1.5/org.jboss.cac...
------------------------------------------
started
Building remotely on dev36-linux
$ /qa/tools/opt/jdk1.5.0_12/bin/java -Xmx256m -cp /home/hudson/hudson_workspace/maven-agent.jar:/qa/tools/opt/maven-2.0.6/boot/classworlds-1.1.jar hudson.maven.agent.Main /qa/tools/opt/maven-2.0.6 /qa/services/hudson/hudson_1.149/slave.jar /home/hudson/hudson_workspace/maven-interceptor.jar
channel started
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [package]
[INFO] ----------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Cannot execute mojo: resources. It requires a project with an existing pom.xml, but the build is not using one.
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11 seconds
[INFO] Finished at: Wed Dec 19 19:25:22 EST 2007
[INFO] Final Memory: 2M/5M
[INFO] ------------------------------------------------------------------------
Sending e-mails to: dpospisi(a)redhat.com
Build was marked for publishing on https://hudson.jboss.org/hudson/
finished: FAILURE
17 years, 2 months
JBoss Cache SVN: r4886 - in cache-bench-fwk/trunk: cache-products/jbosscache-2.0.0/src/org/cachebench/cachewrappers and 6 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2007-12-19 16:51:57 -0500 (Wed, 19 Dec 2007)
New Revision: 4886
Added:
cache-bench-fwk/trunk/src/org/cachebench/ClusterConfigurationCheck.java
cache-bench-fwk/trunk/src/org/cachebench/cluster/
cache-bench-fwk/trunk/src/org/cachebench/cluster/ClusterBarrier.java
cache-bench-fwk/trunk/src/org/cachebench/cluster/Receiver.java
cache-bench-fwk/trunk/src/org/cachebench/cluster/TcpTransport.java
cache-bench-fwk/trunk/src/org/cachebench/cluster/Transport.java
cache-bench-fwk/trunk/src/org/cachebench/config/CacheWarmupConfig.java
cache-bench-fwk/trunk/src/org/cachebench/config/ClusterConfig.java
cache-bench-fwk/trunk/src/org/cachebench/config/ConfigBuilder.java
cache-bench-fwk/trunk/src/org/cachebench/config/NodeAddress.java
cache-bench-fwk/trunk/src/org/cachebench/warmup/
cache-bench-fwk/trunk/src/org/cachebench/warmup/CacheWarmup.java
cache-bench-fwk/trunk/src/org/cachebench/warmup/NoCacheWarmup.java
cache-bench-fwk/trunk/src/org/cachebench/warmup/PutGetCacheWarmup.java
Modified:
cache-bench-fwk/trunk/build.xml
cache-bench-fwk/trunk/cache-products/jbosscache-2.0.0/src/org/cachebench/cachewrappers/JBossCache200Wrapper.java
cache-bench-fwk/trunk/conf/cachebench.xml
cache-bench-fwk/trunk/src/org/cachebench/CacheBenchmarkRunner.java
cache-bench-fwk/trunk/src/org/cachebench/config/Configuration.java
cache-bench-fwk/trunk/src/org/cachebench/config/TestCase.java
cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/AbstractReportGenerator.java
cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/ClusterReportGenerator.java
cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/ReportGenerator.java
Log:
enhance adding barriers and warmup
Modified: cache-bench-fwk/trunk/build.xml
===================================================================
--- cache-bench-fwk/trunk/build.xml 2007-12-19 17:49:35 UTC (rev 4885)
+++ cache-bench-fwk/trunk/build.xml 2007-12-19 21:51:57 UTC (rev 4886)
@@ -42,9 +42,9 @@
<!-- Module Framework -->
<dirname property="module.framework.basedir" file="${ant.file}"/>
+
+ <property environment="env"/>
-
-
<property name="compiler.args.framework" value="${compiler.args}"/>
<property name="framework.output.dir" value="${module.framework.basedir}/classes/production/Framework"/>
@@ -89,15 +89,15 @@
all - builds the entire project, including plugins for all
cache products in /cache-products/. Output classes
in /classes/.
- runMaster - runs the CacheBenchFwk in "master" mode.
- runSlave - runs the CacheBenchFwk in "slave" mode.
+ runNode - runs the CacheBenchFwk. Depending on the number of nodes in the cluster(configured in cachebenchmark.xml),
+ it will wait for all configured nodes to be launched before starting the tests
-For either runMaster or runSlave, make sure you have looked at:
+Make sure you have looked at:
1) 'build.properties' and have set JVM params (such as heap size,
etc.) as necessary.
- 2) '/conf/cachebench.xml' to configure the tests you want run and
- output file for reports.
+ 2) '/conf/cachebench.xml' to configure the tests you want run, the
+ nodes in the cluster if the case and the output file for reports.
3) '/conf/log4j.xml' for logging settings (make sure these aren't
very verbose as it can skew tests).
4) Provided one of the plugins as a system property. This is
@@ -109,14 +109,17 @@
-Dorg.cachebench.plugins.jbosscache2=true -Dbind.address=${MYTESTIP_1}
-Dorg.cachebench.pluins.ehcache=true -Dbind.address=${MYTESTIP_1}
-Dorg.cachebench.plugins.coherence=true -Dtangosol.coherence.localhost=${MYTESTIP_1}
-
// WORK IN PROGRESS
- -Dorg.cachebench.plugins.terracotta=true
+ -Dorg.cachebench.plugins.terracotta=true
+ when running ant. Note that only one can be set at any time.
+ 5) Make sure you set up an correct NODE_INDEX environment property
+ indicating the index of the node before starting it. E.g. if
+ we have 3 nodes each process should have an environment
+ variable named NODE_INDEX, having values in the range 0-2,
+ each node having an distict value.
+ see cachebench.xml\cachebench\cluster for more details
-
- when running ant. Note that only one can be set at any time.
-
-NB: NEEDS Ant >= 1.7.0
+ NB: NEEDS Ant >= 1.7.0
</echo>
</target>
@@ -531,27 +534,32 @@
<!--<pathelement location="./cache-products/terracotta-2.4.8/lib/bootstrap/boot.jar" />-->
<!--</bootclasspath>-->
<sysproperty key="bind.address" value="${bind.address}" />
- <sysproperty key="tangosol.coherence.localhost" value="${tangosol.coherence.localhost}" />
- <sysproperty key="cluterReportGenerator" value="${cluterReportGenerator}" />
- <sysproperty key="org.cachebench.debug" value="${org.cachebench.debug}" />
+ <sysproperty key="currentIndex" value="${env.NODE_INDEX}" />
+ <sysproperty key="tangosol.coherence.localhost" value="${tangosol.coherence.localhost}" />
+ <sysproperty key="org.cachebench.debug" value="${org.cachebench.debug}" />
<sysproperty key="java.net.preferIPv4Stack" value="${java.net.preferIPv4Stack}" />
<classpath refid="framework.module.classpath" />
<classpath refid="${plugin.classpath.ref}"/>
</java>
</target>
- <target name="runSlave">
+ <target name="runNode">
<antcall target="run">
<param name="runtime.classname" value="org.cachebench.CacheBenchmarkRunner" />
- <param name="cluterReportGenerator" value="false"/>
</antcall>
</target>
- <target name="runMaster">
- <antcall target="run">
- <param name="runtime.classname" value="org.cachebench.CacheBenchmarkRunner" />
- <param name="cluterReportGenerator" value="true"/>
- </antcall>
- </target>
-
+ <target name="checkClusterAddresses" depends="compile.module.framework.production" description="Check whether the cluster config is a valid one">
+ <!--<antcall target="run">-->
+ <!--<param name="runtime.classname" value="org.cachebench.ClusterConfigurationCheck" />-->
+ <!--</antcall>-->
+
+ <java classname="org.cachebench.ClusterConfigurationCheck" clonevm="true" fork="true">
+ <classpath>
+ <pathelement location="${framework.output.dir}"/>
+ <pathelement location="${framework.testoutput.dir}"/>
+ </classpath>
+ <classpath refid="framework.module.classpath" />
+ </java>
+ </target>
</project>
Modified: cache-bench-fwk/trunk/cache-products/jbosscache-2.0.0/src/org/cachebench/cachewrappers/JBossCache200Wrapper.java
===================================================================
--- cache-bench-fwk/trunk/cache-products/jbosscache-2.0.0/src/org/cachebench/cachewrappers/JBossCache200Wrapper.java 2007-12-19 17:49:35 UTC (rev 4885)
+++ cache-bench-fwk/trunk/cache-products/jbosscache-2.0.0/src/org/cachebench/cachewrappers/JBossCache200Wrapper.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -40,7 +40,8 @@
public void empty() throws Exception
{
- cache.removeNode(Fqn.ROOT);
+ //not removing root because there it fails with buddy replication: http://jira.jboss.com/jira/browse/JBCACHE-1241
+ cache.removeNode(new Fqn("test"));
}
public int getNumMembers()
Modified: cache-bench-fwk/trunk/conf/cachebench.xml
===================================================================
--- cache-bench-fwk/trunk/conf/cachebench.xml 2007-12-19 17:49:35 UTC (rev 4885)
+++ cache-bench-fwk/trunk/conf/cachebench.xml 2007-12-19 21:51:57 UTC (rev 4886)
@@ -7,16 +7,32 @@
emptyCacheBetweenTests - again, use if you're running out of mem.
numThreads - the number of executor threads to use to perform the required number of operations.
-->
-<cachebench sampleSize="10000" gcBetweenTestsEnabled="true" sleepBetweenTests="1000" emptyCacheBetweenTests="true" numThreads="10">
+<cachebench sampleSize="2000" gcBetweenTestsEnabled="true" sleepBetweenTests="1000" emptyCacheBetweenTests="true" numThreads="10">
- <!-- Each testcase represents either a single configuration or a cacheing product.
-
- For example, WhirlyCache would be one test case. JBossCache-standalone could be another, JBossCache-replicated could be yet another
-
- See the javadoc for org.cachebench.CacheWrapper for the cacheWrapper property
- -->
<!--
+ There are various steps we want to start executing at once: e.g. all the tests should start at the same time,
+ otherwise (part of) cluster operations do not replicate on all instances. We configure here one socket addresses
+ on each tested node, so that the framework can communicate with all the nodes and sync whenever needed.
+ - bindAddress can be used on a multi-homed host for a ServerSocket that will only accept connect requests to one
+ of its addresses
+ - for each node instance socket address is specified. You can make sure that addresses are available by using
+ checkClusterAddresses ant target
+ -->
+ <cluster bindAddress="127.0.0.1">
+ <member host="127.0.0.1" port="7800"/>
+ <member host="127.0.0.1" port="7801"/>
+ <member host="127.0.0.1" port="7802"/>
+ <member host="127.0.0.1" port="7803"/>
+ <member host="127.0.0.1" port="7804"/>
+ </cluster>
+
+ <!-- Each testcase represents either a single configuration or a cacheing product.
+ For example, WhirlyCache would be one test case. JBossCache-standalone could be another, JBossCache-replicated could be yet another
+ See the javadoc for org.cachebench.CacheWrapper for the cacheWrapper property
+ -->
+
+ <!--
Note that if you are using REPLICATED tests, using the "ant runSlave" command, you can only run one test at a time.
Otherwise, if you are using the test in standalone mode (testing a LOCAL cache), you can add multiple "testcase" elements.
-->
@@ -33,6 +49,14 @@
<!--<testcase name="JBossCache2x-Pessimistic-REPL_ASYNC" cacheWrapper="org.cachebench.cachewrappers.JBossCache200Wrapper">-->
<testcase name="JBossCache2.0" cacheWrapper="org.cachebench.cachewrappers.JBossCache200Wrapper">
+
+ <!-- warms up the cache by doing operation on it; simulates a real-world environment. If no warmup is needed use
+ org.cachebench.warmup.NoCacheWarmup
+ -->
+ <warmup warmupClass="org.cachebench.warmup.PutGetCacheWarmup">
+ <param name="operationCount" value="100"/>
+ </warmup>
+
<!--
* The "name" attrib is just used for display in the reports.
* You can write your own custom testClass.
@@ -65,14 +89,10 @@
<!--
Available generators are: CSVReportGenerator and ClusterReportGenerator.
See javadocs for org.cachebench.reportgenerators.ReportGenerator for writing your
- own report generators such as XML generators, graphic generators, etc
+ own report generators such as XML generators, graphic generators, etc
-->
<!-- The CSV report generated can be plugged in to a spreadsheet to generate graphs, cluster size is
needed so that the . -->
- <report outputFile="performance.csv" generator="org.cachebench.reportgenerators.ClusterReportGenerator">
- <param name="clusterSize" value="3"/>
- <param name="masterHost" value="127.0.0.1"/>
- <param name="masterPort" value="54334"/>
- </report>
+ <report outputFile="performance.csv" generator="org.cachebench.reportgenerators.ClusterReportGenerator"/>
</cachebench>
Modified: cache-bench-fwk/trunk/src/org/cachebench/CacheBenchmarkRunner.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/CacheBenchmarkRunner.java 2007-12-19 17:49:35 UTC (rev 4885)
+++ cache-bench-fwk/trunk/src/org/cachebench/CacheBenchmarkRunner.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -1,19 +1,16 @@
package org.cachebench;
-import org.apache.commons.digester.Digester;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.cachebench.config.Configuration;
-import org.cachebench.config.Report;
-import org.cachebench.config.TestCase;
-import org.cachebench.config.TestConfig;
+import org.cachebench.config.*;
import org.cachebench.reportgenerators.ReportGenerator;
import org.cachebench.tests.CacheTest;
+import org.cachebench.cluster.ClusterBarrier;
import org.cachebench.utils.Instantiator;
+import org.cachebench.warmup.CacheWarmup;
import java.io.File;
-import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
@@ -56,13 +53,9 @@
private CacheBenchmarkRunner(String s)
{
// first, try and find the configuration on the filesystem.
- URL confFile = findOnFS(s);
+ URL confFile = ConfigBuilder.findConfigFile(s);
if (confFile == null)
{
- confFile = findInClasspath(s);
- }
- if (confFile == null)
- {
logger.warn("Unable to locate a configuration file; Application terminated");
}
else
@@ -71,7 +64,7 @@
logger.debug("Parsing configuration");
try
{
- conf = parseConfiguration(confFile);
+ conf = ConfigBuilder.parseConfiguration(confFile);
logger.info("Starting Benchmarking....");
List<TestResult> results = runTests(); // Run the tests from this point.
if (results != null && results.size() != 0)
@@ -86,43 +79,12 @@
}
catch (Exception e)
{
- logger.warn("Unable to parse configuration file " + confFile + ". Application terminated");
+ logger.warn("Unable to parse configuration file " + confFile + ". Application terminated", e);
errorLogger.fatal("Unable to parse configuration file " + confFile, e);
}
}
}
- private Configuration parseConfiguration(URL url) throws Exception
- {
- Digester digester = new Digester();
- // set up the digester rules.
- digester.setValidating(false);
- digester.addObjectCreate("cachebench", "org.cachebench.config.Configuration");
- digester.addSetProperties("cachebench");
- digester.addObjectCreate("cachebench/testcase", "org.cachebench.config.TestCase");
- digester.addSetProperties("cachebench/testcase");
-
- digester.addObjectCreate("cachebench/testcase/test", "org.cachebench.config.TestConfig");
- digester.addSetProperties("cachebench/testcase/test");
- digester.addSetNext("cachebench/testcase/test", "addTest", "org.cachebench.config.TestConfig");
-
- digester.addObjectCreate("cachebench/testcase/param", "org.cachebench.config.NVPair");
- digester.addSetProperties("cachebench/testcase/param");
-
- digester.addSetNext("cachebench/testcase/param", "addParam", "org.cachebench.config.NVPair");
- digester.addSetNext("cachebench/testcase", "addTestCase", "org.cachebench.config.TestCase");
-
- digester.addObjectCreate("cachebench/report", "org.cachebench.config.Report");
- digester.addSetProperties("cachebench/report");
-
- digester.addObjectCreate("cachebench/report/param", "org.cachebench.config.NVPair");
- digester.addSetProperties("cachebench/report/param");
- digester.addSetNext("cachebench/report/param", "addParam", "org.cachebench.config.NVPair");
-
- digester.addSetNext("cachebench/report", "addReport", "org.cachebench.config.Report");
- return (Configuration) digester.parse(url.openStream());
- }
-
/**
* Executes each test case and returns the result.
*
@@ -140,8 +102,14 @@
if (cache != null)
{
cache.init(test.getParams());
+ barrier("BEFORE_WARMUP");
+ warmupCache(test, cache);
+ barrier("AFTER_WARMUP");
+
+ //now start testing
cache.setUp();
List<TestResult> resultsForCache = runTestsOnCache(cache, test);
+ barrier("AFTER_TEST_RUN");
shutdownCache(cache);
results.addAll(resultsForCache);
}
@@ -156,6 +124,25 @@
return results;
}
+ private void barrier(String messageName) throws Exception
+ {
+ ClusterBarrier barrier = new ClusterBarrier();
+ logger.trace("Using following cluster config: " + conf.getClusterConfig());
+ barrier.setConfig(conf.getClusterConfig());
+ barrier.setAcknowledge(true);
+ barrier.barrier(messageName);
+ logger.trace("Barrier finished");
+ }
+
+ private void warmupCache(TestCase test, CacheWrapper cache) throws Exception
+ {
+ CacheWarmupConfig warmupConfig = test.getCacheWarmupConfig();
+ logger.trace("Warmup config is: " + warmupConfig);
+ CacheWarmup warmup = (CacheWarmup) Instantiator.getInstance().createClass(warmupConfig.getWarmupClass());
+ warmup.setConfigParams(warmupConfig.getConfigParams());
+ warmup.warmup(cache);
+ }
+
/**
* Peforms the necessary external tasks for cache benchmarking.
* These external tasks are defined in the cachebench.xml and would
@@ -184,9 +171,9 @@
}
catch (Exception e)
{
- // The Empty process of the cache failed. Add a foot note for the TestResult here.
- testResult.setFootNote("The Cache Empty process failed after test case: " + testResult.getTestName() + " : " + testResult.getTestType());
- errorLogger.error("The Cache Empty process failed after test case : " + testResult.getTestName() + ", " + testResult.getTestType(), e);
+ // The Empty barrier of the cache failed. Add a foot note for the TestResult here.
+ testResult.setFootNote("The Cache Empty barrier failed after test case: " + testResult.getTestName() + " : " + testResult.getTestType());
+ errorLogger.error("The Cache Empty barrier failed after test case : " + testResult.getTestName() + ", " + testResult.getTestType(), e);
}
return testResult;
@@ -241,6 +228,7 @@
generator.setConfigParams(report.getParams());
generator.setResults(results);
generator.setOutputFile(new File(report.getOutputFile()));
+ generator.setClusterConfig(conf.getClusterConfig());
generator.generate();
logger.info("Report Generation Completed");
}
@@ -259,37 +247,6 @@
}
}
- /**
- * Util method to locate a resource on the filesystem as a URL
- *
- * @param filename
- * @return The URL object of the file
- */
- private URL findOnFS(String filename)
- {
- File f = new File(filename);
- try
- {
- if (f.exists()) return f.toURL();
- }
- catch (MalformedURLException mue)
- {
- // bad URL
- }
- return null;
- }
-
- /**
- * Util method to locate a resource in your classpath
- *
- * @param filename
- * @return The URL object of the file
- */
- private URL findInClasspath(String filename)
- {
- return getClass().getClassLoader().getResource(filename);
- }
-
private CacheWrapper getCacheWrapperInstance(TestCase testCaseClass)
{
CacheWrapper cache = null;
Added: cache-bench-fwk/trunk/src/org/cachebench/ClusterConfigurationCheck.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/ClusterConfigurationCheck.java (rev 0)
+++ cache-bench-fwk/trunk/src/org/cachebench/ClusterConfigurationCheck.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -0,0 +1,63 @@
+package org.cachebench;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.cachebench.config.ClusterConfig;
+import org.cachebench.config.ConfigBuilder;
+
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.URL;
+import java.io.IOException;
+
+/**
+ * Loads config file and checks whether the specified ports are available.
+ * Can be used from a script, following exit codes are used:
+ * <pre>
+ * 0 - all ports are available
+ * 1 - config file not found
+ * 2 - a address is in use
+ * </pre>
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ */
+public class ClusterConfigurationCheck
+{
+
+ private static Log log = LogFactory.getLog("ClusterConfigurationCheck");
+
+ public static void main(String[] args) throws Exception
+ {
+ String configFile = "cachebench.xml";
+ if (args.length >= 1)
+ {
+ configFile = args[0];
+ }
+ URL configUrl = ConfigBuilder.findConfigFile(configFile);
+ if (configUrl == null)
+ {
+ log.info("Could not find the config file, exiting with code 1");
+ System.exit(1);
+ }
+ ClusterConfig config = ConfigBuilder.parseConfiguration(configUrl).getClusterConfig();
+ boolean areSuspects = false;
+ for (InetSocketAddress address : config.getMemberAddresses())
+ {
+ try
+ {
+ Socket sock = new Socket(address.getHostName(), address.getPort());
+ areSuspects = true;
+ log.info("Managed to connect to " + address);
+ } catch (IOException e)
+ {
+ log.trace("Connection to : " + address + " failed; expected behavior");
+ }
+ }
+ if (!areSuspects)
+ {
+ log.info("Success (could not establish any connection)");
+ }
+ System.exit(areSuspects ? 2 : 0);
+ }
+}
Added: cache-bench-fwk/trunk/src/org/cachebench/cluster/ClusterBarrier.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/cluster/ClusterBarrier.java (rev 0)
+++ cache-bench-fwk/trunk/src/org/cachebench/cluster/ClusterBarrier.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -0,0 +1,154 @@
+package org.cachebench.cluster;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.cachebench.config.ClusterConfig;
+
+import java.net.SocketAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Use for making the nodes in the cluster to hold until ALL nodes reached the barrier.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class ClusterBarrier implements Receiver
+{
+ private static Log log = LogFactory.getLog(ClusterBarrier.class);
+
+ private ClusterConfig config;
+ public final Map<SocketAddress, Object> receivedMessages = new HashMap<SocketAddress, Object>();
+ private Transport transport;
+ private Object message;
+ private int numMembers;
+ private boolean acknowledge;
+ private static final String ACK = "_ACK";
+
+
+ /**
+ * Returns the messages sent between the nodes in the cluster.
+ */
+ public Map<SocketAddress, Object> getReceivedMessages()
+ {
+ return receivedMessages;
+ }
+
+ /**
+ * Setting this to true would tide up barrier delays.
+ */
+ public void setAcknowledge(boolean acknowledge)
+ {
+ this.acknowledge = acknowledge;
+ }
+
+ /**
+ * Message sent between cluster members to ack on the barrier.
+ */
+ public void barrier(Object message) throws Exception
+ {
+ log.trace("Started processing a message cluster, message='" + message + "'");
+ receivedMessages.clear();
+ this.message = message;
+ transport = new TcpTransport();
+ numMembers = config.getClusterSize();
+ transport.create(config);
+ transport.setReceiver(this);
+ transport.start();
+ log.trace("Transport started, local address is: " + transport.getLocalAddress());
+ log.trace("Waiting for " + numMembers + " member(s) to join");
+ waitForAllMemebers();
+ transport.stop();
+ //just to make sure all other nodes closed their resources
+ //needed e.g. when a new barrier is immediately initiated on this barrier which might connect
+ //to a port on a barrier that is about to close, so messages sent by new barrier might be lost
+ // a nicer way to implement this is to accept connections only if the sender uses same barrier name
+ Thread.sleep(2000);
+ }
+
+ private void waitForAllMemebers() throws Exception
+ {
+ boolean receivedAllMessages = false;
+ while (!receivedAllMessages)
+ {
+ synchronized (receivedMessages)
+ {
+ receivedAllMessages = receivedMessages.size() >= numMembers;
+ if (!receivedAllMessages)
+ {
+ receivedMessages.wait(2000);
+ }
+ }
+ log.trace("sending message " + message + ", expecting " + getMissingMembersCount() + " member(s)");
+ transport.send(null, message);
+ if (acknowledge)
+ {
+ log.trace("Send ack also");
+ transport.send(null, getAcknowledgeMessage(message));
+ }
+ }
+ }
+
+ public void receive(SocketAddress sender, Object payload) throws Exception
+ {
+ log.trace("Received '" + payload + "' from " + sender + " still expecting " + getMissingMembersCount() + " member(s)");
+ if (payload == null)
+ {
+ log.warn("payload is incorrect (sender=" + sender + "): " + payload);
+ return;
+ }
+ if (acknowledge && !isAcknowledgeMessage(payload, message))
+ {
+ log.trace("Sending ack, still expecting " + getMissingMembersCount() + " members.");
+ transport.send(null, getAcknowledgeMessage(message));
+ return;
+ }
+
+ //we are here if either no ack or ack the message is an ack message
+ synchronized (this.receivedMessages)
+ {
+ if (!this.receivedMessages.containsKey(sender))
+ {
+ this.receivedMessages.put(sender, getMessage(payload));
+ int expected = getMissingMembersCount();
+ log.trace("Sender " + sender + " registered, still waiting for " + expected + " member(s)");
+ this.receivedMessages.notifyAll();
+ }
+ }
+ }
+
+ private int getMissingMembersCount()
+ {
+ return numMembers - receivedMessages.size();
+ }
+
+ private Object getMessage(Object payload)
+ {
+ if (!acknowledge)
+ {
+ return message;
+ }
+ String payloadStr = payload.toString();
+ int endIndex = payloadStr.length() - ACK.length();
+ return payloadStr.substring(0, endIndex);
+ }
+
+ private String getAcknowledgeMessage(Object message)
+ {
+ return message.toString() + ACK;
+ }
+
+ private boolean isAcknowledgeMessage(Object payload, Object message)
+ {
+ boolean result;
+ String payloadStr = payload.toString();
+ result = payloadStr.equals(getAcknowledgeMessage(message));
+ log.trace("Is acknowledge? " + result);
+ return result;
+ }
+
+ public void setConfig(ClusterConfig config)
+ {
+ this.config = config;
+ }
+}
Added: cache-bench-fwk/trunk/src/org/cachebench/cluster/Receiver.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/cluster/Receiver.java (rev 0)
+++ cache-bench-fwk/trunk/src/org/cachebench/cluster/Receiver.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -0,0 +1,12 @@
+package org.cachebench.cluster;
+
+import java.net.SocketAddress;
+
+/**
+ * @author Bela Ban Jan 22
+ * @author 2004
+ * @version $Id: Receiver.java,v 1.1 2004/01/23 00:08:31 belaban Exp $
+ */
+public interface Receiver {
+ void receive(SocketAddress sender, Object payload) throws Exception;
+}
Added: cache-bench-fwk/trunk/src/org/cachebench/cluster/TcpTransport.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/cluster/TcpTransport.java (rev 0)
+++ cache-bench-fwk/trunk/src/org/cachebench/cluster/TcpTransport.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -0,0 +1,389 @@
+package org.cachebench.cluster;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.cachebench.config.ClusterConfig;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+
+/**
+ * note: this code is copyed and adapted from jgroups test.
+ *
+ * @author Bela Ban Jan 22
+ * @author 2004
+ * @version $Id: TcpTransport.java,v 1.16 2006/12/19 08:51:46 belaban Exp $
+ */
+public class TcpTransport implements Transport
+{
+
+ private static Log log = LogFactory.getLog(TcpTransport.class);
+
+ Receiver receiver = null;
+ ClusterConfig config = null;
+ int max_receiver_buffer_size = 500000;
+ int max_send_buffer_size = 500000;
+ List<InetSocketAddress> nodes;
+ ConnectionTable connectionTable;
+ int startPort = 7800;
+ ServerSocket srvSock = null;
+ InetAddress bindAddr = null;
+ SocketAddress localAddr = null;
+ List receivers = new ArrayList();
+ private ServerSocket server;
+ private boolean isStoping;
+
+
+ public TcpTransport()
+ {
+ }
+
+ public Object getLocalAddress()
+ {
+ return localAddr;
+ }
+
+ public void create(ClusterConfig clusterConfig) throws Exception
+ {
+ this.config = clusterConfig;
+ String tmp;
+ startPort = config.getPortForThisNode();
+ String bindAddrStr = config.getBindAddress();
+ if (bindAddrStr != null)
+ {
+ bindAddr = InetAddress.getByName(bindAddrStr);
+ }
+ else
+ {
+ bindAddr = InetAddress.getLocalHost();
+ }
+ nodes = clusterConfig.getMemberAddresses();
+ connectionTable = new ConnectionTable(nodes);
+ }
+
+
+ public void start() throws Exception
+ {
+ srvSock = createServerSocket();
+ log.trace("ServerSock created, listening on: "+ srvSock.getLocalSocketAddress());
+ localAddr = new InetSocketAddress(srvSock.getInetAddress(), srvSock.getLocalPort());
+ connectionTable.init();
+
+ // accept connections and start 1 Receiver per connection
+ Thread acceptor = new Thread()
+ {
+ public void run()
+ {
+ while (true)
+ {
+ try
+ {
+ Socket s = srvSock.accept();
+ log.trace("Accepted client " + s.getRemoteSocketAddress());
+ ReceiverThread r = new ReceiverThread(s);
+ r.setDaemon(true);
+ receivers.add(r);
+ r.start();
+ }
+ catch (Exception ex)
+ {
+ if (!isStoping)
+ {
+ log.warn("Exception whilst accepting new threads", ex);
+ }
+ break;
+ }
+ }
+ }
+ };
+ acceptor.setDaemon(true);
+ acceptor.start();
+ }
+
+ private ServerSocket createServerSocket()
+ {
+ int start_port1 = startPort;
+ server = null;
+
+ while (true)
+ {
+ try
+ {
+ server = new ServerSocket(start_port1, 50, bindAddr);
+ }
+ catch (BindException bindEx)
+ {
+ log.trace("Binding exception, most likely port " + start_port1 + " is in use. Trying next value. Error:"
+ + bindEx.getMessage());
+ start_port1++;
+ continue;
+ }
+ catch (IOException ioEx)
+ {
+ log.warn("An exception appeared whilst trying to create server socket on port " + start_port1 + ", error:"
+ + ioEx.getMessage());
+ }
+ break;
+ }
+ return server;
+ }
+
+ public void stop()
+ {
+ try
+ {
+ isStoping = true;
+ server.close();
+ log.trace("Successfully closed server socket " + server);
+ } catch (IOException e)
+ {
+ log.warn("Failed to close servet socket for " + server + ", error is " + e.getMessage());
+ }
+ connectionTable.close();
+ for (Iterator it = receivers.iterator(); it.hasNext();)
+ {
+ ReceiverThread thread = (ReceiverThread) it.next();
+ thread.stopThread();
+ }
+ }
+
+ public void destroy()
+ {
+ ;
+ }
+
+ public void setReceiver(Receiver r)
+ {
+ this.receiver = r;
+ }
+
+ public Map dumpStats()
+ {
+ return null;
+ }
+
+ public void send(Object destination, Object payload) throws Exception
+ {
+ if (destination != null)
+ throw new Exception("TcpTransport.send(): unicasts not supported");
+ connectionTable.writeMessage(payload);
+ }
+
+
+ class ConnectionTable
+ {
+ /**
+ * List<InetSocketAddress>
+ */
+ List myNodes;
+ final Connection[] connections;
+
+ ConnectionTable(List nodes) throws Exception
+ {
+ this.myNodes = nodes;
+ connections = new Connection[nodes.size()];
+ }
+
+
+ void init() throws Exception
+ {
+ int i = 0;
+ log.trace("Nodes is " + myNodes);
+ for (Iterator it = myNodes.iterator(); it.hasNext();)
+ {
+ InetSocketAddress addr = (InetSocketAddress) it.next();
+ if (connections[i] == null)
+ {
+ try
+ {
+ connections[i] = new Connection(addr);
+ connections[i].createSocket();
+ }
+ catch (ConnectException connect_ex)
+ {
+ log.trace("-- failed to connect to " + addr);
+ }
+ catch (Exception all_others)
+ {
+ throw all_others;
+ }
+ }
+ i++;
+ }
+ }
+
+ // todo: parallelize
+ void writeMessage(Object msg) throws Exception
+ {
+ int recieversCount = 0;
+ for (int i = 0; i < connections.length; i++)
+ {
+ Connection c = connections[i];
+ if (c != null)
+ {
+ try
+ {
+ c.writeMessage(msg);
+ recieversCount ++;
+ }
+ catch (Exception e)
+ {
+ // System.err.println("failed sending msg on " + c);
+ }
+ }
+ }
+ log.trace("Message successfully sent to " + recieversCount + "/" + connections.length);
+ }
+
+ void close()
+ {
+ for (int i = 0; i < connections.length; i++)
+ {
+ Connection c = connections[i];
+ if (c != null)
+ c.close();
+ }
+ }
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+ for (Iterator it = myNodes.iterator(); it.hasNext();)
+ {
+ sb.append(it.next()).append(' ');
+ }
+ return sb.toString();
+ }
+ }
+
+ class Connection
+ {
+ Socket sock = null;
+ DataOutputStream out;
+ InetSocketAddress to;
+ final Object mutex = new Object();
+
+ Connection(InetSocketAddress addr)
+ {
+ this.to = addr;
+ }
+
+ void createSocket() throws IOException
+ {
+ sock = new Socket(to.getAddress(), to.getPort());
+ sock.setSendBufferSize(max_send_buffer_size);
+ sock.setReceiveBufferSize(max_receiver_buffer_size);
+ out = new DataOutputStream(new BufferedOutputStream(sock.getOutputStream()));
+ log.trace("-- connected to " + to + ". Local address is " + sock.getLocalSocketAddress());
+ }
+
+ void writeMessage(Object msg) throws Exception
+ {
+ synchronized (mutex)
+ {
+ if (sock == null)
+ {
+ createSocket();
+ }
+ ObjectOutputStream oos = new ObjectOutputStream(out);
+ oos.writeObject(msg);
+ }
+ out.flush();
+ }
+
+
+ void close()
+ {
+ try
+ {
+ out.flush();
+ sock.close();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+
+ public String toString()
+ {
+ return "Connection from " + localAddr + " to " + to;
+ }
+ }
+
+
+ class ReceiverThread extends Thread
+ {
+ Socket sock;
+ DataInputStream in;
+ SocketAddress remote;
+
+ ReceiverThread(Socket sock) throws Exception
+ {
+ this.sock = sock;
+ // sock.setSoTimeout(5000);
+ in = new DataInputStream(new BufferedInputStream(sock.getInputStream()));
+ remote = sock.getRemoteSocketAddress();
+ }
+
+ public void run()
+ {
+ while (sock != null)
+ {
+ try
+ {
+ Object message = new ObjectInputStream(in).readObject();
+ if (receiver != null)
+ receiver.receive(remote, message);
+ }
+ catch (EOFException eof)
+ {
+ break;
+ }
+ catch (Exception ex)
+ {
+ break;
+ }
+ }
+ log.trace("-- receiver thread for " + remote + " terminated");
+ }
+
+ void stopThread()
+ {
+ try
+ {
+ sock.close();
+ sock = null;
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ public List parseCommaDelimitedList(String s) throws Exception
+ {
+ List retval = new ArrayList();
+ StringTokenizer tok;
+ String hostname, tmp;
+ int port;
+ InetSocketAddress addr;
+ int index;
+
+ if (s == null) return null;
+ tok = new StringTokenizer(s, ",");
+ while (tok.hasMoreTokens())
+ {
+ tmp = tok.nextToken();
+ index = tmp.indexOf(':');
+ if (index == -1)
+ throw new Exception("host must be in format <host:port>, was " + tmp);
+ hostname = tmp.substring(0, index);
+ port = Integer.parseInt(tmp.substring(index + 1));
+ addr = new InetSocketAddress(hostname, port);
+ retval.add(addr);
+ }
+ return retval;
+ }
+
+}
Added: cache-bench-fwk/trunk/src/org/cachebench/cluster/Transport.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/cluster/Transport.java (rev 0)
+++ cache-bench-fwk/trunk/src/org/cachebench/cluster/Transport.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -0,0 +1,54 @@
+package org.cachebench.cluster;
+
+import org.cachebench.config.ClusterConfig;
+
+import java.util.Properties;
+import java.util.Map;
+
+/**
+ * Generic transport abstraction for all different transports (JGroups, JMS, UDP, TCP). The lifecycle is
+ * <ol>
+ * <li>Create an instance of the transport (using the empty constructor)
+ * <li>Call <code>create()</code>
+ * <li>Possibly call <code>setReceiver()</code>
+ * <li>Call <code>start()</code>
+ * <li>Call <code>send()</code>
+ * <li>Call <code>stop()</stop>
+ * <li>Call <code>destroy()</code> (alternatively call <code>start()</code> again)
+ * </ol>
+ * @author Bela Ban Jan 22
+ * @author 2004
+ * @version $Id: Transport.java,v 1.4 2006/12/19 08:51:47 belaban Exp $
+ */
+public interface Transport {
+
+ /** Create the transport
+ * @param clusterConfig*/
+ void create(ClusterConfig clusterConfig) throws Exception;
+
+ /** Get the local address (= endpoint) of this transport. Guaranteed to be called <em>after</em>
+ * <code>create()</code>, possibly even later (after <code>start()</code>) */
+ Object getLocalAddress();
+
+ /** Start the transport */
+ void start() throws Exception;
+
+ /** Stop the transport */
+ void stop();
+
+ /** Destroy the transport. Transport cannot be reused after this call, but a new instance has to be created */
+ void destroy();
+
+ /** Set the receiver */
+ void setReceiver(Receiver r);
+
+ Map dumpStats();
+
+ /**
+ * Send a message
+ * @param destination A destination. If null, send a message to all members
+ * @param payload A buffer to be sent
+ * @throws Exception
+ */
+ void send(Object destination, Object payload) throws Exception;
+}
Added: cache-bench-fwk/trunk/src/org/cachebench/config/CacheWarmupConfig.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/config/CacheWarmupConfig.java (rev 0)
+++ cache-bench-fwk/trunk/src/org/cachebench/config/CacheWarmupConfig.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -0,0 +1,34 @@
+package org.cachebench.config;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class CacheWarmupConfig
+{
+ private String warmupClass;
+
+ private Map<String, String> configParams = new HashMap<String, String>();
+
+ public void addConfigParam(NVPair nvPair)
+ {
+ configParams.put(nvPair.getName(), nvPair.getValue());
+ }
+
+ public String getWarmupClass()
+ {
+ return warmupClass;
+ }
+
+ public void setWarmupClass(String warmupClass)
+ {
+ this.warmupClass = warmupClass;
+ }
+
+ public Map<String, String> getConfigParams()
+ {
+ return configParams;
+ }
+}
Added: cache-bench-fwk/trunk/src/org/cachebench/config/ClusterConfig.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/config/ClusterConfig.java (rev 0)
+++ cache-bench-fwk/trunk/src/org/cachebench/config/ClusterConfig.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -0,0 +1,91 @@
+package org.cachebench.config;
+
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Configuration for this cache instance.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class ClusterConfig
+{
+ private int currentNodeIndex = -1;
+
+ private List<NodeAddress> members = new ArrayList<NodeAddress>();
+
+ private String bindAddress;
+
+ public int getCurrentNodeIndex()
+ {
+ if (currentNodeIndex == -1)
+ {
+ String serverindexStr = System.getProperty("currentIndex");
+ try
+ {
+ currentNodeIndex = Integer.parseInt(serverindexStr);
+ } catch (NumberFormatException e)
+ {
+ throw new IllegalStateException("Configuration 'currentIndex' is missing!");
+ }
+ }
+ return currentNodeIndex;
+ }
+
+ public List<NodeAddress> getMembers()
+ {
+ return members;
+ }
+
+ public int getPortForThisNode()
+ {
+ NodeAddress address = members.get(getCurrentNodeIndex());
+ return Integer.parseInt(address.getPort());
+ }
+
+ public int getClusterSize()
+ {
+ return members.size();
+ }
+
+ public boolean isMaster()
+ {
+ return getCurrentNodeIndex() == 0;
+ }
+
+ public void addMember(NodeAddress member)
+ {
+ members.add(member);
+ }
+
+ public void setCurrentNodeIndex(int currentNodeIndex)
+ {
+ this.currentNodeIndex = currentNodeIndex;
+ }
+
+ public String getBindAddress()
+ {
+ return bindAddress;
+ }
+
+ public void setBindAddress(String bindAddress)
+ {
+ this.bindAddress = bindAddress;
+ }
+
+ public List<InetSocketAddress> getMemberAddresses()
+ {
+ List<InetSocketAddress> result = new ArrayList();
+ for (NodeAddress address : getMembers())
+ {
+ result.add(new InetSocketAddress(address.getHost(), address.getPortAsInt()));
+ }
+ return result;
+ }
+
+ public String toString()
+ {
+ return "{bindAddress:" + bindAddress + ", members:" + members + "}";
+ }
+}
Added: cache-bench-fwk/trunk/src/org/cachebench/config/ConfigBuilder.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/config/ConfigBuilder.java (rev 0)
+++ cache-bench-fwk/trunk/src/org/cachebench/config/ConfigBuilder.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -0,0 +1,107 @@
+package org.cachebench.config;
+
+import org.apache.commons.digester.Digester;
+
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.io.File;
+
+/**
+ * Helper class for loading configurations.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class ConfigBuilder
+{
+ /**
+ * Util method to locate a resource on the filesystem as a URL
+ *
+ * @param filename
+ * @return The URL object of the file
+ */
+ private static URL findOnFS(String filename)
+ {
+ File f = new File(filename);
+ try
+ {
+ if (f.exists()) return f.toURL();
+ }
+ catch (MalformedURLException mue)
+ {
+ // bad URL
+ }
+ return null;
+ }
+
+ /**
+ * Looks for config file on disk then on class path.
+ * @return null if the file cannot be found
+ */
+ public static URL findConfigFile(String s)
+ {
+ URL confFile = findOnFS(s);
+ if (confFile == null)
+ {
+ confFile = findInClasspath(s);
+ }
+ return confFile;
+ }
+
+ public static Configuration parseConfiguration(URL url) throws Exception
+ {
+ Digester digester = new Digester();
+ // set up the digester rules.
+ digester.setValidating(false);
+ digester.addObjectCreate("cachebench", "org.cachebench.config.Configuration");
+ digester.addSetProperties("cachebench");
+
+ digester.addObjectCreate("cachebench/cluster", "org.cachebench.config.ClusterConfig");
+ digester.addSetProperties("cachebench/cluster");
+ digester.addObjectCreate("cachebench/cluster/member", "org.cachebench.config.NodeAddress");
+ digester.addSetProperties("cachebench/cluster/member");
+ digester.addSetNext("cachebench/cluster/member", "addMember", "org.cachebench.config.NodeAddress");
+ digester.addSetNext("cachebench/cluster", "setClusterConfig", "org.cachebench.config.ClusterConfig");
+
+ digester.addObjectCreate("cachebench/testcase", "org.cachebench.config.TestCase");
+ digester.addSetProperties("cachebench/testcase");
+
+ digester.addObjectCreate("cachebench/testcase/warmup", "org.cachebench.config.CacheWarmupConfig");
+ digester.addSetProperties("cachebench/testcase/warmup");
+
+ digester.addObjectCreate("cachebench/testcase/warmup/param", "org.cachebench.config.NVPair");
+ digester.addSetProperties("cachebench/testcase/warmup/param");
+ digester.addSetNext("cachebench/testcase/warmup/param", "addConfigParam", "org.cachebench.config.NVPair");
+
+ digester.addSetNext("cachebench/testcase/warmup", "setCacheWarmupConfig", "org.cachebench.config.CacheWarmupConfig");
+
+ digester.addObjectCreate("cachebench/testcase/test", "org.cachebench.config.TestConfig");
+ digester.addSetProperties("cachebench/testcase/test");
+ digester.addSetNext("cachebench/testcase/test", "addTest", "org.cachebench.config.TestConfig");
+
+ digester.addObjectCreate("cachebench/testcase/param", "org.cachebench.config.NVPair");
+ digester.addSetProperties("cachebench/testcase/param");
+
+ digester.addSetNext("cachebench/testcase/param", "addParam", "org.cachebench.config.NVPair");
+ digester.addSetNext("cachebench/testcase", "addTestCase", "org.cachebench.config.TestCase");
+
+ digester.addObjectCreate("cachebench/report", "org.cachebench.config.Report");
+ digester.addSetProperties("cachebench/report");
+
+ digester.addObjectCreate("cachebench/report/param", "org.cachebench.config.NVPair");
+ digester.addSetProperties("cachebench/report/param");
+ digester.addSetNext("cachebench/report/param", "addParam", "org.cachebench.config.NVPair");
+
+ digester.addSetNext("cachebench/report", "addReport", "org.cachebench.config.Report");
+ return (Configuration) digester.parse(url.openStream());
+ }
+
+ /**
+ * Util method to locate a resource in your classpath
+ */
+ private static URL findInClasspath(String filename)
+ {
+ return ConfigBuilder.class.getClassLoader().getResource(filename);
+ }
+
+
+}
Modified: cache-bench-fwk/trunk/src/org/cachebench/config/Configuration.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/config/Configuration.java 2007-12-19 17:49:35 UTC (rev 4885)
+++ cache-bench-fwk/trunk/src/org/cachebench/config/Configuration.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -15,6 +15,8 @@
private boolean gcBetweenTestsEnabled;
private boolean emptyCacheBetweenTests;
+ private ClusterConfig clusterConfig;
+
private List<TestCase> testCases = new ArrayList<TestCase>();
private List<Report> reports = new ArrayList<Report>();
@@ -90,4 +92,14 @@
{
this.numThreads = numThreads;
}
+
+ public ClusterConfig getClusterConfig()
+ {
+ return clusterConfig;
+ }
+
+ public void setClusterConfig(ClusterConfig clusterConfig)
+ {
+ this.clusterConfig = clusterConfig;
+ }
}
Added: cache-bench-fwk/trunk/src/org/cachebench/config/NodeAddress.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/config/NodeAddress.java (rev 0)
+++ cache-bench-fwk/trunk/src/org/cachebench/config/NodeAddress.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -0,0 +1,58 @@
+package org.cachebench.config;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ */
+public class NodeAddress
+{
+ private String host;
+
+ private String port;
+
+ public String getHost()
+ {
+ return host;
+ }
+
+ public void setHost(String host)
+ {
+ this.host = host;
+ }
+
+ public String getPort()
+ {
+ return port;
+ }
+
+ public void setPort(String port)
+ {
+ this.port = port;
+ }
+
+ public int getPort(int defaultValue)
+ {
+ int portInt = Integer.parseInt(port);
+ if (portInt <= 0)
+ {
+ return defaultValue;
+ }
+ else
+ {
+ return portInt;
+ }
+ }
+
+ public String toString()
+ {
+ return host + ':' + port;
+ }
+
+ public int getPortAsInt()
+ {
+ return Integer.parseInt(port);
+ }
+}
Modified: cache-bench-fwk/trunk/src/org/cachebench/config/TestCase.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/config/TestCase.java 2007-12-19 17:49:35 UTC (rev 4885)
+++ cache-bench-fwk/trunk/src/org/cachebench/config/TestCase.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -1,5 +1,7 @@
package org.cachebench.config;
+import org.cachebench.warmup.CacheWarmup;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -13,7 +15,19 @@
private Properties params = new Properties();
private List<TestConfig> tests = new ArrayList<TestConfig>();
+ private CacheWarmupConfig cacheWarmupConfig;
+
+ public CacheWarmupConfig getCacheWarmupConfig()
+ {
+ return cacheWarmupConfig;
+ }
+
+ public void setCacheWarmupConfig(CacheWarmupConfig cacheWarmupConfig)
+ {
+ this.cacheWarmupConfig = cacheWarmupConfig;
+ }
+
public String getName()
{
return name;
Modified: cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/AbstractReportGenerator.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/AbstractReportGenerator.java 2007-12-19 17:49:35 UTC (rev 4885)
+++ cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/AbstractReportGenerator.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -2,10 +2,10 @@
import org.apache.commons.logging.Log;
import org.cachebench.TestResult;
+import org.cachebench.config.ClusterConfig;
import java.io.File;
import java.util.List;
-import java.util.Map;
/**
* Base implementation of {@link org.cachebench.reportgenerators.ReportGenerator}
@@ -15,6 +15,7 @@
protected File output;
protected List<TestResult> results;
protected Log log;
+ protected ClusterConfig clusterConfig;
public void setOutputFile(File output)
{
@@ -25,4 +26,9 @@
{
this.results = results;
}
+
+ public void setClusterConfig(ClusterConfig clusterConfig)
+ {
+ this.clusterConfig = clusterConfig;
+ }
}
Modified: cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/ClusterReportGenerator.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/ClusterReportGenerator.java 2007-12-19 17:49:35 UTC (rev 4885)
+++ cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/ClusterReportGenerator.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -3,124 +3,64 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.cachebench.TestResult;
+import org.cachebench.cluster.ClusterBarrier;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.net.*;
+import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Gathers info from all the nodes executing tests.
- * Merges all the gathered information and generates an CSV file based on that.
+ * Merges all the gathered information and generates an CSV file.
+ * The file is generated on the master node, i.e. the node that has the NODE_INDEX == 0
*
* @author Mircea.Markus(a)jboss.com
- * @version 2.2
*/
public class ClusterReportGenerator extends AbstractReportGenerator
{
private static Log log = LogFactory.getLog(ClusterReportGenerator.class);
- private int clusterSize;
-
- private int masterPort;
-
- private String masterHost;
-
public void setConfigParams(Map<String, String> configParams)
{
log.trace("Received config params: " + configParams);
- this.clusterSize = Integer.parseInt(configParams.get("clusterSize"));
- this.masterPort = Integer.parseInt(configParams.get("masterPort"));
- this.masterHost = configParams.get("masterHost");
}
public void generate() throws Exception
{
try
{
- log.trace("Cluster report generator property value: " + System.getProperty("cluterReportGenerator"));
- boolean isGeneratorNode = System.getProperty("cluterReportGenerator") != null
- && "true".equalsIgnoreCase(System.getProperty("cluterReportGenerator"));
- log.trace(" Starting generating. Is master? " + isGeneratorNode);
- if (isGeneratorNode)
+ ClusterBarrier barrier = new ClusterBarrier();
+ barrier.setConfig(this.clusterConfig);
+ barrier.setAcknowledge(false);
+ barrier.barrier(results);
+ log.trace(" Starting generating. Is master? " + clusterConfig.isMaster());
+ if (clusterConfig.isMaster())
{
- generateReport();
+ log.trace("Received following results: " + results);
+ generateReport(barrier.getReceivedMessages());
}
- else
- {
- submitReportInfo();
- }
} catch (Exception e)
{
log.error("Error while generating report!", e);
}
}
- /**
- * If not a master, sends report data to master.
- */
- private void submitReportInfo() throws IOException, ClassNotFoundException
- {
- log.trace("Sending the following results to master: " + results);
- boolean connected = false;
- Socket socket = null;
- while (!connected)
- {
- try
- {
- log.trace("Connecting to master on " + masterHost + ":" + masterPort + "...");
- socket = new Socket(masterHost, masterPort);
- log.trace("Connected");
- connected = true;
- } catch (IOException e)
- {
- log.trace("Failed to connect(" + e.getMessage() + "), trying again..." );
- connected = false;
- }
- }
- ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
- oos.writeObject(this.results);
- oos.close();
- socket.close();
- log.trace("Following results were sent to server: " + results);
- }
- private void generateReport() throws Exception
+ private void generateReport(Map<SocketAddress, Object> receivedMessages) throws Exception
{
- List<List<TestResult>> results = retrieveResultsFromClients();
- List<TestResult> mergedResults = mergerTestResultsAndGenerateReport(results);
- generateReportFile(mergedResults);
- }
-
- @SuppressWarnings(value = "unchecked")
- private List<List<TestResult>> retrieveResultsFromClients()
- throws IOException, ClassNotFoundException
- {
- ServerSocket socket = new ServerSocket(masterPort);
+ log.trace("Received " + receivedMessages.size() + " results!");
List<List<TestResult>> results = new ArrayList<List<TestResult>>();
- results.add(this.results);
- //we go expect cluster size-1 because this is also a node, ant it does not sent report info
- for (int i = 0; i < clusterSize - 1; i++)
+ for (SocketAddress socketAddress : receivedMessages.keySet())
{
- log.trace("Expecting " + (clusterSize - i - 1) + " more client(s)");
- log.trace(" Waiting for client to conect...");
- Socket client = socket.accept();
- log.trace("Client connected: " + client.getInetAddress());
- ObjectInputStream ois = new ObjectInputStream(client.getInputStream());
- List<TestResult> testResults = (List<TestResult>) ois.readObject();
+ List<TestResult> testResults = (List<TestResult>) receivedMessages.get(socketAddress);
+ log.trace("From " + socketAddress + " received " + testResults);
results.add(testResults);
- log.trace("Received following resullts from client: " + testResults);
- ois.close();
- client.close();
}
- socket.close();
- return results;
+ List<TestResult> mergedResults = mergerTestResultsAndGenerateReport(results);
+ generateReportFile(mergedResults);
}
-
private void generateReportFile(List<TestResult> mergedResults) throws Exception
{
CSVReportGenerator generator = new CSVReportGenerator();
Modified: cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/ReportGenerator.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/ReportGenerator.java 2007-12-19 17:49:35 UTC (rev 4885)
+++ cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/ReportGenerator.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -1,6 +1,7 @@
package org.cachebench.reportgenerators;
import org.cachebench.TestResult;
+import org.cachebench.config.ClusterConfig;
import java.io.File;
import java.util.List;
@@ -13,11 +14,13 @@
*/
public interface ReportGenerator
{
- public abstract void setConfigParams(Map<String, String> configParams);
+ public void setConfigParams(Map<String, String> configParams);
public void setOutputFile(File output);
public void setResults(List<TestResult> results);
public void generate() throws Exception;
+
+ public void setClusterConfig(ClusterConfig clusterConfig);
}
Added: cache-bench-fwk/trunk/src/org/cachebench/warmup/CacheWarmup.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/warmup/CacheWarmup.java (rev 0)
+++ cache-bench-fwk/trunk/src/org/cachebench/warmup/CacheWarmup.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -0,0 +1,40 @@
+package org.cachebench.warmup;
+
+import org.cachebench.CacheWrapper;
+import org.cachebench.config.NVPair;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Warmups the cache.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ */
+public abstract class CacheWarmup
+{
+
+ private Map<String, String> configParams = new HashMap<String, String>();
+
+ public void setConfigParams(Map<String, String> configParams)
+ {
+ this.configParams = configParams;
+ }
+
+ public String getConfigParam(String name)
+ {
+ return configParams.get(name);
+ }
+
+ /**
+ * Calls {@link #performWarmupOperations(CacheWrapper)} amd clears the cache.
+ */
+ public final void warmup(CacheWrapper cacheWrapper) throws Exception
+ {
+ performWarmupOperations(cacheWrapper);
+ cacheWrapper.empty();
+ }
+
+ public abstract void performWarmupOperations(CacheWrapper wrapper) throws Exception;
+}
Added: cache-bench-fwk/trunk/src/org/cachebench/warmup/NoCacheWarmup.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/warmup/NoCacheWarmup.java (rev 0)
+++ cache-bench-fwk/trunk/src/org/cachebench/warmup/NoCacheWarmup.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -0,0 +1,19 @@
+package org.cachebench.warmup;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.cachebench.CacheWrapper;
+
+/**
+ * Does not warmup the cache.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class NoCacheWarmup extends CacheWarmup
+{
+ Log log = LogFactory.getFactory().getInstance(NoCacheWarmup.class);
+ public void performWarmupOperations(CacheWrapper wrapper) throws Exception
+ {
+ log.info("Using no cache warmup");
+ }
+}
Added: cache-bench-fwk/trunk/src/org/cachebench/warmup/PutGetCacheWarmup.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/warmup/PutGetCacheWarmup.java (rev 0)
+++ cache-bench-fwk/trunk/src/org/cachebench/warmup/PutGetCacheWarmup.java 2007-12-19 21:51:57 UTC (rev 4886)
@@ -0,0 +1,32 @@
+package org.cachebench.warmup;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.cachebench.CacheWrapper;
+
+/**
+ * Perfoms N puts, gets and removals, where n is configurable.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ */
+public class PutGetCacheWarmup extends CacheWarmup
+{
+ Log log = LogFactory.getLog(PutGetCacheWarmup.class);
+
+ public void performWarmupOperations(CacheWrapper wrapper) throws Exception
+ {
+ Integer opCount = Integer.parseInt(getConfigParam("operationCount"));
+ log.trace("Cache launched, performing " + opCount + " put and get operations ");
+ for (int i = 0; i < opCount; i++)
+ {
+ wrapper.put(String.valueOf(opCount), String.valueOf(opCount));
+ }
+
+ for (int i = 0; i < opCount; i++)
+ {
+ wrapper.get(String.valueOf(opCount));
+ }
+ log.trace("Cache warmup ended!");
+ }
+}
17 years, 2 months
JBoss Cache SVN: r4885 - core/trunk/src/main/java/org/jboss/cache/lock.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-19 12:49:35 -0500 (Wed, 19 Dec 2007)
New Revision: 4885
Modified:
core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java
Log:
Reverted back to using a concurrent hash set
Modified: core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java 2007-12-19 17:40:14 UTC (rev 4884)
+++ core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java 2007-12-19 17:49:35 UTC (rev 4885)
@@ -6,10 +6,11 @@
*/
package org.jboss.cache.lock;
+import org.jboss.cache.util.concurrent.ConcurrentHashSet;
+
import java.util.Collection;
import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.Set;
/**
* Provide lock ownership mapping.
@@ -26,7 +27,9 @@
private Object writeOwner_ = null;
// This is more efficient (lower CPU utilisation and better concurrency) than a CopyOnWriteArraySet or ConcurrentHashSet.
- private final List<Object> readOwnerList_ = Collections.synchronizedList(new LinkedList<Object>());
+ // for some reason this barfs with concurrent mod exceptions. Need to see why.
+ // private final List<Object> readOwnerList_ = Collections.synchronizedList(new LinkedList<Object>());
+ private final Set<Object> readOwnerList_ = new ConcurrentHashSet<Object>();
/**
* Check whether this owner has reader or writer ownership.
@@ -114,7 +117,8 @@
*/
public Collection<Object> readerOwners()
{
- return Collections.unmodifiableList(readOwnerList_);
+ //return Collections.unmodifiableList(readOwnerList_);
+ return Collections.unmodifiableSet(readOwnerList_);
}
public void releaseReaderOwners(LockStrategy lock)
17 years, 2 months
JBoss Cache SVN: r4884 - core/trunk/src/main/java/org/jboss/cache/factories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-19 12:40:14 -0500 (Wed, 19 Dec 2007)
New Revision: 4884
Modified:
core/trunk/src/main/java/org/jboss/cache/factories/LockTableFactory.java
Log:
Lock table should be a CHM!
Modified: core/trunk/src/main/java/org/jboss/cache/factories/LockTableFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/LockTableFactory.java 2007-12-19 17:19:50 UTC (rev 4883)
+++ core/trunk/src/main/java/org/jboss/cache/factories/LockTableFactory.java 2007-12-19 17:40:14 UTC (rev 4884)
@@ -2,8 +2,8 @@
import org.jboss.cache.factories.annotations.DefaultFactoryFor;
-import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
/**
* Dead simple class to create a lock factory
@@ -21,7 +21,7 @@
protected <T> T construct(String componentName, Class<T> componentType)
{
if (componentName.equals(LOCK_MAP_COMPONENT_NAME))
- return (T) new HashMap();
+ return (T) new ConcurrentHashMap();
else
{
log.warn("Unknown component name " + componentName);
17 years, 2 months