JBoss Cache SVN: r4927 - in cache-bench-fwk/trunk: cache-products/coherence-3.2.2/src/org/cachebench/cachewrappers and 8 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2007-12-30 16:45:04 -0500 (Sun, 30 Dec 2007)
New Revision: 4927
Added:
cache-bench-fwk/trunk/src/org/cachebench/config/GenericParamsConfig.java
cache-bench-fwk/trunk/src/org/cachebench/tests/ReplicationOccursTest.java
Modified:
cache-bench-fwk/trunk/cache-products/coherence-3.2.2/src/org/cachebench/cachewrappers/CoherenceWrapper.java
cache-bench-fwk/trunk/cache-products/ehcache-1.2.4/src/org/cachebench/cachewrappers/EHCacheWrapper.java
cache-bench-fwk/trunk/cache-products/jbosscache-1.4.1/src/org/cachebench/cachewrappers/JBossCacheWrapper.java
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/conf/log4j.xml
cache-bench-fwk/trunk/runNode.sh
cache-bench-fwk/trunk/src/org/cachebench/CacheBenchmarkRunner.java
cache-bench-fwk/trunk/src/org/cachebench/CacheWrapper.java
cache-bench-fwk/trunk/src/org/cachebench/TestResult.java
cache-bench-fwk/trunk/src/org/cachebench/config/CacheWarmupConfig.java
cache-bench-fwk/trunk/src/org/cachebench/config/ConfigBuilder.java
cache-bench-fwk/trunk/src/org/cachebench/config/Configuration.java
cache-bench-fwk/trunk/src/org/cachebench/config/Report.java
cache-bench-fwk/trunk/src/org/cachebench/config/TestCase.java
cache-bench-fwk/trunk/src/org/cachebench/config/TestConfig.java
cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/CSVReportGenerator.java
cache-bench-fwk/trunk/src/org/cachebench/tests/CacheTest.java
cache-bench-fwk/trunk/src/org/cachebench/tests/SimpleTest.java
Log:
enhanced - added a new test that checks that caches that replications occurs as expected + refactorings
Modified: cache-bench-fwk/trunk/cache-products/coherence-3.2.2/src/org/cachebench/cachewrappers/CoherenceWrapper.java
===================================================================
--- cache-bench-fwk/trunk/cache-products/coherence-3.2.2/src/org/cachebench/cachewrappers/CoherenceWrapper.java 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/cache-products/coherence-3.2.2/src/org/cachebench/cachewrappers/CoherenceWrapper.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -2,7 +2,7 @@
import org.cachebench.CacheWrapper;
-import java.util.Properties;
+import java.util.Map;
import com.tangosol.net.NamedCache;
import com.tangosol.net.CacheFactory;
@@ -18,7 +18,7 @@
{
NamedCache cache;
- public void init(Properties parameters) throws Exception
+ public void init(Map parameters) throws Exception
{
cache = CacheFactory.getReplicatedCache();
// cache = CacheFactory.getCache("VirtualCache");
@@ -57,4 +57,9 @@
{
return cache.keySet().toString();
}
+
+ public Object getReplicatedData(String key) throws Exception
+ {
+ return get(key);
+ }
}
Modified: cache-bench-fwk/trunk/cache-products/ehcache-1.2.4/src/org/cachebench/cachewrappers/EHCacheWrapper.java
===================================================================
--- cache-bench-fwk/trunk/cache-products/ehcache-1.2.4/src/org/cachebench/cachewrappers/EHCacheWrapper.java 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/cache-products/ehcache-1.2.4/src/org/cachebench/cachewrappers/EHCacheWrapper.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -1,9 +1,8 @@
package org.cachebench.cachewrappers;
-import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
-import net.sf.ehcache.Ehcache;
import net.sf.ehcache.config.Configuration;
import net.sf.ehcache.config.ConfigurationFactory;
import org.apache.commons.logging.Log;
@@ -12,7 +11,7 @@
import java.io.Serializable;
import java.net.URL;
-import java.util.Properties;
+import java.util.Map;
import java.util.StringTokenizer;
@@ -33,10 +32,10 @@
/* (non-Javadoc)
* @see org.cachebench.CacheWrapper#init(java.util.Properties)
*/
- public void init(Properties parameters) throws Exception
+ public void init(Map parameters) throws Exception
{
logger.debug("Initializing the cache with props " + parameters);
- URL url = getClass().getClassLoader().getResource(parameters.getProperty("config"));
+ URL url = getClass().getClassLoader().getResource((String) parameters.get("config"));
logger.debug("Config URL = " + url);
Configuration c = ConfigurationFactory.parseConfiguration(url);
c.setSource("URL of " + url);
@@ -157,4 +156,9 @@
{
return cache.getKeys().toString() + " remote peers: " + manager.getCachePeerListener().getBoundCachePeers();
}
+
+ public Object getReplicatedData(String key) throws Exception
+ {
+ return get(key);
+ }
}
Modified: cache-bench-fwk/trunk/cache-products/jbosscache-1.4.1/src/org/cachebench/cachewrappers/JBossCacheWrapper.java
===================================================================
--- cache-bench-fwk/trunk/cache-products/jbosscache-1.4.1/src/org/cachebench/cachewrappers/JBossCacheWrapper.java 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/cache-products/jbosscache-1.4.1/src/org/cachebench/cachewrappers/JBossCacheWrapper.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -6,7 +6,7 @@
import org.jboss.cache.PropertyConfigurator;
import org.jboss.cache.TreeCache;
-import java.util.Properties;
+import java.util.Map;
import java.util.HashMap;
@@ -21,13 +21,13 @@
private TreeCache tree;
private Log log = LogFactory.getLog("org.cachebench.cachewrappers.JBossCacheWrapper");
- public void init(Properties parameters) throws Exception
+ public void init(Map parameters) throws Exception
{
log.debug("Initializing the cache");
//parameters.
tree = new TreeCache();
PropertyConfigurator conf = new PropertyConfigurator();
- conf.configure( tree, parameters.getProperty("config") );
+ conf.configure( tree, (String)parameters.get("config") );
}
public void setUp() throws Exception
@@ -69,4 +69,10 @@
{
return tree.printDetails();
}
+
+ public Object getReplicatedData(String key)
+ {
+ return null;
+ }
+
}
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-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/cache-products/jbosscache-2.0.0/src/org/cachebench/cachewrappers/JBossCache200Wrapper.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -2,18 +2,21 @@
import org.cachebench.CacheWrapper;
import org.jboss.cache.Cache;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.buddyreplication.GravitateResult;
+import org.jboss.cache.marshall.NodeData;
-import java.util.Properties;
+import java.util.Map;
public class JBossCache200Wrapper implements CacheWrapper
{
private Cache cache;
- public void init(Properties parameters) throws Exception
+ public void init(Map parameters) throws Exception
{
- cache = DefaultCacheFactory.getInstance().createCache(parameters.getProperty("config"));
+ cache = DefaultCacheFactory.getInstance().createCache((String)parameters.get("config"));
}
public void setUp() throws Exception
@@ -54,4 +57,17 @@
return "Num direct children: " + cache.getRoot().getChildren().size();
}
+ public Object getReplicatedData(String key) throws Exception
+ {
+ CacheSPI cacheSpi = (CacheSPI) cache;
+ GravitateResult result = cacheSpi.gravitateData(new Fqn("test", key), true);
+ if (!result.isDataFound())
+ {
+ //totall replication?
+ return get(key);
+ }
+ NodeData nodeData = result.getNodeData().get(0);
+ return nodeData.getAttributes().get(key);
+ }
+
}
Modified: cache-bench-fwk/trunk/conf/cachebench.xml
===================================================================
--- cache-bench-fwk/trunk/conf/cachebench.xml 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/conf/cachebench.xml 2007-12-30 21:45:04 UTC (rev 4927)
@@ -7,7 +7,7 @@
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="2000" gcBetweenTestsEnabled="true" sleepBetweenTests="1000" emptyCacheBetweenTests="true" numThreads="10">
+<cachebench sampleSize="10000" gcBetweenTestsEnabled="true" sleepBetweenTests="1000" emptyCacheBetweenTests="true" numThreads="10">
<!--
@@ -23,22 +23,16 @@
<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
+ testcase::stopOnFailure if set to true and one test in this testcase fails then the process will exit
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.
- -->
+ <!-- Make SURE you read the docs - especially when using Terracotta as this involves some additional setup -->
- <!-- Make SURE you read the docs - especially when using Terracotta as this involves some additional setup -->
-
<!-- Legacy stuff -->
<!--<testcase name="JBossCache140-Pessimistic-REPL_SYNC" cacheWrapper="org.cachebench.cachewrappers.JBossCacheWrapper">-->
<!--<testcase name="EHCache124-replicated" cacheWrapper="org.cachebench.cachewrappers.EHCacheWrapper">-->
@@ -46,23 +40,30 @@
<!--<testcase name="JBossCache2x-Pessimistic-REPL_SYNC_BR" cacheWrapper="org.cachebench.cachewrappers.JBossCache200Wrapper">-->
- <!--<testcase name="JBossCache2x-Pessimistic-REPL_ASYNC" cacheWrapper="org.cachebench.cachewrappers.JBossCache200Wrapper">-->
- <testcase name="JBossCache2.0" cacheWrapper="org.cachebench.cachewrappers.TerracottaWrapper">
+ <testcase name="JBossCache2x-Pessimistic-REPL_ASYNC" cacheWrapper="org.cachebench.cachewrappers.JBossCache200Wrapper" stopOnFailure="true">
+ <!--<testcase name="JBossCache2.0" cacheWrapper="org.cachebench.cachewrappers.TerracottaWrapper" stopOnFailure="true">-->
-
<!-- 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">
+ <warmup warmupClass="org.cachebench.warmup.NoCacheWarmup">
<param name="operationCount" value="100"/>
</warmup>
<!--
+ validates that replication is enabled and works. If repl does not occur and the stopOnFailure is set to true then exists.
+ Should be used to make sure that replication is enabled; see javadoc for more details
+ -->
+ <test name="replicationOccurrsTest" testClass="org.cachebench.tests.ReplicationOccursTest">
+ <param name="partialReplication" value="true"/>
+ </test>
+
+ <!--
* The "name" attrib is just used for display in the reports.
* You can write your own custom testClass.
* weight is currently unused.
-->
- <test name="Strings" testClass="org.cachebench.tests.StringTest" weight="2.0" />
+ <test name="Strings" testClass="org.cachebench.tests.StringTest" weight="2.0" />
<!--
<test name="Primitive Wrappers" testClass="org.cachebench.tests.PrimitiveTest" weight="1.0" />
Modified: cache-bench-fwk/trunk/conf/log4j.xml
===================================================================
--- cache-bench-fwk/trunk/conf/log4j.xml 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/conf/log4j.xml 2007-12-30 21:45:04 UTC (rev 4927)
@@ -48,6 +48,12 @@
<appender-ref ref="CONSOLE"/>
</category>
+ <category name="org.cachebench.cluster" additivity="false">
+ <priority value="INFO"/>
+ <appender-ref ref="FILE"/>
+ <appender-ref ref="CONSOLE"/>
+ </category>
+
<category name="org.cachebench.tests" additivity="false">
<priority value="INFO"/>
<appender-ref ref="CONSOLE"/>
@@ -72,10 +78,21 @@
<priority value="ERROR"/>
<appender-ref ref="FILE"/>
</category>
+
+ <category name="org.cachebench.tests.ReplicationOccursTest" additivity="false">
+ <priority value="TRACE"/>
+ <appender-ref ref="CONSOLE"/>
+ </category>
+ <category name="org.jboss.cache">
+ <priority value="WARN"/>
+ <appender-ref ref="FILE"/>
+ <appender-ref ref="CONSOLE"/>
+ </category>
+
<!-- Here goes the root -->
<root>
- <priority value ="DEBU" />
+ <priority value ="INFO" />
<appender-ref ref="FILE" />
</root>
Modified: cache-bench-fwk/trunk/runNode.sh
===================================================================
--- cache-bench-fwk/trunk/runNode.sh 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/runNode.sh 2007-12-30 21:45:04 UTC (rev 4927)
@@ -7,6 +7,18 @@
CACHE_DEBUG=true
preferIPv4Stack=true
+if [ -z $1]
+then
+ echo "Usage:"
+ echo " ./runNode.sh currentNodeIndex testConfig [other params]"
+ echo "currentNodeIndex : the index of this node in the list of nodes in the cluster, zero based"
+ echo "testConfig : must be on of the directories form cache products"
+ echo "other params : this will be passed as argument to the cache benchmark class."
+ echo " Might be used, for e.g. to pass -D arguments to the custom plugins"
+ echo " configured in cachebench.xml"
+ exit 0
+fi
+
export SYS_PROPS="-Dbind.address=$BIND_ADDRESS -DcurrentIndex=$1 -Dorg.cachebench.debug=$CACHE_DEBUG -Djava.net.preferIPv4Stack=$preferIPv4Stack"
#libraries needed by the fwk, add them to the classpath
Modified: cache-bench-fwk/trunk/src/org/cachebench/CacheBenchmarkRunner.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/CacheBenchmarkRunner.java 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/src/org/cachebench/CacheBenchmarkRunner.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -139,7 +139,7 @@
CacheWarmupConfig warmupConfig = test.getCacheWarmupConfig();
logger.trace("Warmup config is: " + warmupConfig);
CacheWarmup warmup = (CacheWarmup) Instantiator.getInstance().createClass(warmupConfig.getWarmupClass());
- warmup.setConfigParams(warmupConfig.getConfigParams());
+ warmup.setConfigParams(warmupConfig.getParams());
warmup.warmup(cache);
}
@@ -184,7 +184,7 @@
List<TestResult> results = new ArrayList<TestResult>();
for (TestConfig testConfig: testCase.getTests())
{
- CacheTest testConfigClass = getCacheTestWrapper(testConfig);
+ CacheTest testConfigClass = getCacheTest(testConfig);
if (testConfigClass != null)
{
TestResult result;
@@ -192,7 +192,7 @@
String testCaseName = testCase.getName();
try
{
- result = testConfigClass.doTest(testCaseName, cache, testName, conf.getSampleSize(), conf.getNumThreads());
+ result = testConfigClass.doTest(testName, cache, testCaseName, conf.getSampleSize(), conf.getNumThreads());
}
catch (Exception e)
{
@@ -204,11 +204,19 @@
result.setTestPassed(false);
result.setErrorMsg("Failed to Execute - See logs for details : " + e.getMessage());
- logger.warn("Test case : " + testCaseName + ", Test : " + testName + " - Failed");
+ logger.warn("Test case : " + testCaseName + ", Test : " + testName + " - Failed", e);
errorLogger.error("Test case : " + testCaseName + ", Test : " + testName + " - Failed : " + e.getMessage(), e);
}
+ if (!result.isTestPassed() && testCase.isStopOnFailure())
+ {
+ logger.warn("The test '" + testCase + "/" + testName + "' failed, exiting...");
+ System.exit(1);
+ }
executeTestTasks(cache, result);
- results.add(result);
+ if (!result.isSkipReport())
+ {
+ results.add(result);
+ }
}
}
return results;
@@ -282,13 +290,13 @@
}
- private CacheTest getCacheTestWrapper(TestConfig testConfig)
+ private CacheTest getCacheTest(TestConfig testConfig)
{
CacheTest cacheTestClass = null;
try
{
cacheTestClass = (CacheTest) Instantiator.getInstance().createClass(testConfig.getTestClass());
-
+ cacheTestClass.setConfiguration(conf);
}
catch (Exception e)
{
Modified: cache-bench-fwk/trunk/src/org/cachebench/CacheWrapper.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/CacheWrapper.java 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/src/org/cachebench/CacheWrapper.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -1,6 +1,7 @@
package org.cachebench;
import java.util.Properties;
+import java.util.Map;
/**
@@ -21,7 +22,7 @@
*
* @param parameters
*/
- void init(Properties parameters) throws Exception;
+ void init(Map parameters) throws Exception;
/**
* setUp() is called immediately after init(), and usually involves instantiating
@@ -70,4 +71,11 @@
* @return Some info about the cache contents, perhaps just a count of objects.
*/
String getInfo();
+
+ /**
+ * Some caches (e.g. JBossCache with buddy replication) do not store replicated data directlly in the main
+ * structure, but use some additional structure to do this (replication tree, in the case of buddy replication).
+ * This method is a hook for handling this situations.
+ */
+ public Object getReplicatedData(String key) throws Exception;
}
Modified: cache-bench-fwk/trunk/src/org/cachebench/TestResult.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/TestResult.java 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/src/org/cachebench/TestResult.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -23,6 +23,7 @@
private int throughputBytesPerSecond;
private int numMembers;
private int numThreads;
+ private boolean skipReport;
public DescriptiveStatistics getGetData()
{
@@ -171,4 +172,17 @@
", numThreads=" + numThreads +
'}';
}
+
+ /**
+ * If set to true, no reports will be generated from this test result.
+ */
+ public boolean isSkipReport()
+ {
+ return skipReport;
+ }
+
+ public void setSkipReport(boolean skipReport)
+ {
+ this.skipReport = skipReport;
+ }
}
Modified: cache-bench-fwk/trunk/src/org/cachebench/config/CacheWarmupConfig.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/config/CacheWarmupConfig.java 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/src/org/cachebench/config/CacheWarmupConfig.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -6,17 +6,10 @@
/**
* @author Mircea.Markus(a)jboss.com
*/
-public class CacheWarmupConfig
+public class CacheWarmupConfig extends GenericParamsConfig
{
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;
@@ -26,9 +19,4 @@
{
this.warmupClass = warmupClass;
}
-
- public Map<String, String> getConfigParams()
- {
- return configParams;
- }
}
Modified: cache-bench-fwk/trunk/src/org/cachebench/config/ConfigBuilder.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/config/ConfigBuilder.java 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/src/org/cachebench/config/ConfigBuilder.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -70,12 +70,15 @@
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/param", "addParam", "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.addObjectCreate("cachebench/testcase/test/param", "org.cachebench.config.NVPair");
+ digester.addSetProperties("cachebench/testcase/test/param");
+ digester.addSetNext("cachebench/testcase/test/param", "addParam", "org.cachebench.config.NVPair");
digester.addSetNext("cachebench/testcase/test", "addTest", "org.cachebench.config.TestConfig");
digester.addObjectCreate("cachebench/testcase/param", "org.cachebench.config.NVPair");
Modified: cache-bench-fwk/trunk/src/org/cachebench/config/Configuration.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/config/Configuration.java 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/src/org/cachebench/config/Configuration.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -102,4 +102,16 @@
{
this.clusterConfig = clusterConfig;
}
+
+ public TestCase getTestCase(String testCaseName)
+ {
+ for (TestCase testCase : getTestCases())
+ {
+ if (testCaseName.equalsIgnoreCase(testCase.getName()))
+ {
+ return testCase;
+ }
+ }
+ return null;
+ }
}
Added: cache-bench-fwk/trunk/src/org/cachebench/config/GenericParamsConfig.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/config/GenericParamsConfig.java (rev 0)
+++ cache-bench-fwk/trunk/src/org/cachebench/config/GenericParamsConfig.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -0,0 +1,34 @@
+package org.cachebench.config;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Configuration that allows specifying a variable number of key value pairs.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class GenericParamsConfig
+{
+ private Map<String, String> configParams = new HashMap<String, String>();
+
+ public void addParam(NVPair nvPair)
+ {
+ configParams.put(nvPair.getName(), nvPair.getValue());
+ }
+
+ public Map<String, String> getParams()
+ {
+ return configParams;
+ }
+
+ public boolean existsParam(String name)
+ {
+ return configParams.get(name) != null;
+ }
+
+ public String getParamValue(String name)
+ {
+ return configParams.get(name);
+ }
+}
Modified: cache-bench-fwk/trunk/src/org/cachebench/config/Report.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/config/Report.java 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/src/org/cachebench/config/Report.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -1,30 +1,15 @@
package org.cachebench.config;
-import java.util.Map;
-import java.util.HashMap;
-
-
-public class Report
+public class Report extends GenericParamsConfig
{
private String generator;
private String outputFile;
- private Map<String, String> params= new HashMap<String, String>();
public String getGenerator()
{
return generator;
}
- public void addParam(NVPair nvPair)
- {
- params.put(nvPair.getName(), nvPair.getValue());
- }
-
- public Map<String, String> getParams()
- {
- return params;
- }
-
public void setGenerator(String generator)
{
this.generator = generator;
Modified: cache-bench-fwk/trunk/src/org/cachebench/config/TestCase.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/config/TestCase.java 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/src/org/cachebench/config/TestCase.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -1,18 +1,16 @@
package org.cachebench.config;
-import org.cachebench.warmup.CacheWarmup;
-
import java.util.ArrayList;
import java.util.List;
-import java.util.Properties;
-public class TestCase
+public class TestCase extends GenericParamsConfig
{
private String name;
private String cacheWrapper;
- private Properties params = new Properties();
+ private boolean stopOnFailure;
+
private List<TestConfig> tests = new ArrayList<TestConfig>();
private CacheWarmupConfig cacheWarmupConfig;
@@ -38,16 +36,6 @@
this.name = name;
}
- public Properties getParams()
- {
- return params;
- }
-
- public void addParam(NVPair nvPair)
- {
- params.put(nvPair.getName(), nvPair.getValue());
- }
-
/**
* @return Returns the cacheWrapper.
*/
@@ -73,4 +61,26 @@
{
tests.add(test);
}
+
+ public boolean isStopOnFailure()
+ {
+ return stopOnFailure;
+ }
+
+ public void setStopOnFailure(boolean stopOnFailure)
+ {
+ this.stopOnFailure = stopOnFailure;
+ }
+
+ public TestConfig getTest(String testName)
+ {
+ for (TestConfig config : getTests())
+ {
+ if (testName.equals(config.getName()))
+ {
+ return config;
+ }
+ }
+ return null;
+ }
}
\ No newline at end of file
Modified: cache-bench-fwk/trunk/src/org/cachebench/config/TestConfig.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/config/TestConfig.java 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/src/org/cachebench/config/TestConfig.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -1,7 +1,7 @@
package org.cachebench.config;
-public class TestConfig
+public class TestConfig extends GenericParamsConfig
{
private String name;
private String testClass;
Modified: cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/CSVReportGenerator.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/CSVReportGenerator.java 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/src/org/cachebench/reportgenerators/CSVReportGenerator.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -54,10 +54,6 @@
* The method checkes whether the result is passed or failed. And based on the status would generate the report with
* appropriate content. The method also checks whether the report has any foot notes attached to the test case. If
* any foot note is found, then its added to the <code>footNotes</code> ArrayList for later processing.
- *
- * @param result
- * @param writer
- * @throws IOException
*/
private void writeTestResult(TestResult result, BufferedWriter writer) throws IOException
{
Modified: cache-bench-fwk/trunk/src/org/cachebench/tests/CacheTest.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/tests/CacheTest.java 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/src/org/cachebench/tests/CacheTest.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -2,6 +2,7 @@
import org.cachebench.CacheWrapper;
import org.cachebench.TestResult;
+import org.cachebench.config.Configuration;
/**
@@ -10,6 +11,9 @@
*/
public interface CacheTest
{
+
+ public void setConfiguration(Configuration configuration);
+
/**
* Performs the benchmarking on the given tese.
*
Added: cache-bench-fwk/trunk/src/org/cachebench/tests/ReplicationOccursTest.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/tests/ReplicationOccursTest.java (rev 0)
+++ cache-bench-fwk/trunk/src/org/cachebench/tests/ReplicationOccursTest.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -0,0 +1,124 @@
+package org.cachebench.tests;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.cachebench.CacheWrapper;
+import org.cachebench.TestResult;
+import org.cachebench.cluster.ClusterBarrier;
+import org.cachebench.config.Configuration;
+import org.cachebench.config.TestConfig;
+import org.cachebench.config.TestCase;
+
+import java.net.SocketAddress;
+import java.util.Map;
+
+/**
+ * For tests that stress cluster replication, this check whether a put in this node is replicated across the cluster.
+ * The purpose of this is to ensure that nodes are configured correctly (they have replication enabled and it works).
+ *
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class ReplicationOccursTest implements CacheTest
+{
+ public static final Log log = LogFactory.getLog(ReplicationOccursTest.class);
+
+ private Configuration conf;
+ private static final String PREFIX = "_ReplicationOccursTest_";
+
+ public void setConfiguration(Configuration configuration)
+ {
+ this.conf = configuration;
+ }
+
+ public TestResult doTest(String testName, CacheWrapper cache, String testCaseName, int sampleSize, int numThreads) throws Exception
+ {
+ log.trace("TestCase = '" + testCaseName + "', TestName = " + testName);
+ barrierBeforeReplicationTest();
+
+ Integer currentNodeIndex = conf.getClusterConfig().getCurrentNodeIndex();
+ cache.put(PREFIX + currentNodeIndex, "true");
+ Thread.sleep(2000);//just to make sure that prev barrier closed its sockets etc
+
+ boolean allNodesReplicated = nodesReplicated(cache, testCaseName, testName);
+
+ Map<SocketAddress, Object> receivedValues = broadcastReplicationResult(allNodesReplicated);
+ cache.empty();
+ return allReplicatedFine(receivedValues);
+ }
+
+ private Map<SocketAddress, Object> broadcastReplicationResult(boolean allNodesReplicated)
+ throws Exception
+ {
+ ClusterBarrier barrier = new ClusterBarrier();
+ barrier.setConfig(conf.getClusterConfig());
+ barrier.barrier(String.valueOf(allNodesReplicated));
+ Map<SocketAddress,Object> receivedValues = barrier.getReceivedMessages();
+ log.info("Recieved following responses from barrier:" + receivedValues);
+ return receivedValues;
+ }
+
+ private void barrierBeforeReplicationTest()
+ throws Exception
+ {
+ ClusterBarrier barrier = new ClusterBarrier();
+ barrier.setAcknowledge(true);
+ barrier.setConfig(conf.getClusterConfig());
+ barrier.barrier("BEFORE_REPLICATION_OCCURS_BARRIER");
+ }
+
+ private TestResult allReplicatedFine(Map<SocketAddress, Object> receivedValues)
+ {
+ TestResult result = new TestResult();
+ result.setSkipReport(true);
+ for (Object value: receivedValues.values())
+ {
+ if (!"true".equals(value))
+ {
+ log.info("Replication was not successull on the entire cluster!");
+ result.setTestPassed(false);
+ return result;
+ }
+ }
+ result.setTestPassed(true);
+ log.info("Replication test successfully passed.");
+ return result;
+ }
+
+ private boolean isPartialReplication(String testCaseName, String testName)
+ {
+ TestCase testCase = conf.getTestCase(testCaseName);
+ TestConfig thisConfig = testCase.getTest(testName);
+ return thisConfig.existsParam("partialReplication") &&
+ "true".equalsIgnoreCase(thisConfig.getParamValue("partialReplication"));
+ }
+
+ private boolean nodesReplicated(CacheWrapper cache, String testCaseName, String testName) throws Exception
+ {
+ int clusterSize = conf.getClusterConfig().getClusterSize();
+ int replicaCount = 0;
+ for (int i = 0; i < clusterSize; i++)
+ {
+ int currentNodeIndex = conf.getClusterConfig().getCurrentNodeIndex();
+ if (i == currentNodeIndex)
+ {
+ continue;
+ }
+ Object data = cache.getReplicatedData(PREFIX + i);
+ if (data == null || !"true".equals(data))
+ {
+ log.trace("Cache with index " + i + " did *NOT* replicate");
+ }
+ else
+ {
+ log.trace("Cache with index " + i + " replicated here ");
+ replicaCount++;
+ }
+ }
+ log.info("Number of caches that replicated here is " + replicaCount);
+ if (isPartialReplication(testCaseName, testName))
+ {
+ return replicaCount > 0;
+ }
+ return replicaCount == conf.getClusterConfig().getClusterSize() - 1;
+ }
+}
Modified: cache-bench-fwk/trunk/src/org/cachebench/tests/SimpleTest.java
===================================================================
--- cache-bench-fwk/trunk/src/org/cachebench/tests/SimpleTest.java 2007-12-30 08:13:49 UTC (rev 4926)
+++ cache-bench-fwk/trunk/src/org/cachebench/tests/SimpleTest.java 2007-12-30 21:45:04 UTC (rev 4927)
@@ -6,6 +6,7 @@
import org.cachebench.CacheWrapper;
import org.cachebench.SerializableCacheWrapper;
import org.cachebench.TestResult;
+import org.cachebench.config.Configuration;
import java.io.Serializable;
import java.io.ByteArrayOutputStream;
@@ -28,6 +29,7 @@
protected long elapsedSecondsForAllPuts = 0;
protected ExecutorService executor;
private static final int EXECUTOR_SHUTDOWN_TIMEOUT_POLL_SECS = 60;
+ protected Configuration configuration;
protected TestResult performTestWithObjectType(String testCaseName, CacheWrapper cache, Class valueClass, String testName, int sampleSize, int numThreads) throws Exception
{
@@ -277,4 +279,9 @@
return "";
}
}
+
+ public void setConfiguration(Configuration configuration)
+ {
+ this.configuration = configuration;
+ }
}
16 years, 12 months
JBoss Cache SVN: r4926 - core/trunk/src/main/java/org/jboss/cache/notifications.
by jbosscache-commits@lists.jboss.org
Author: bela(a)jboss.com
Date: 2007-12-30 03:13:49 -0500 (Sun, 30 Dec 2007)
New Revision: 4926
Modified:
core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java
Log:
Moved copying of data and other initialization for notification callback into the if block: this only needs to be done if there are listeners available.
JProfiler analysis showed that the copying of data used up a lot of CPU cycles, because it is on the critical path.
This fix should speed up things by a huge margin
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-28 16:58:21 UTC (rev 4925)
+++ core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java 2007-12-30 08:13:49 UTC (rev 4926)
@@ -102,7 +102,7 @@
log.warn("Attempted to register listener of class " + listener.getClass() + ", but no valid, public methods annotated with method-level event annotations found! Ignoring listener.");
}
- private void testListenerClassValidity(Class<?> listenerClass)
+ private static void testListenerClassValidity(Class<?> listenerClass)
{
if (!listenerClass.isAnnotationPresent(CacheListener.class))
throw new IncorrectCacheListenerException("Cache listener class MUST be annotated with org.jboss.cache.notifications.annotation.CacheListener");
@@ -110,7 +110,7 @@
throw new IncorrectCacheListenerException("Cache listener class MUST be public!");
}
- private void testListenerMethodValidity(Method m, Class allowedParameter, String annotationName)
+ private static void testListenerMethodValidity(Method m, Class allowedParameter, String annotationName)
{
if (m.getParameterTypes().length != 1 || !m.getParameterTypes()[0].isAssignableFrom(allowedParameter))
throw new IncorrectCacheListenerException("Methods annotated with " + annotationName + " must accept exactly one parameter, of assignable from type " + allowedParameter.getName());
@@ -168,7 +168,7 @@
l.removeAll(markedForRemoval);
- if (l.size() == 0) listenerInvocations.remove(annotation);
+ if (l.isEmpty()) listenerInvocations.remove(annotation);
}
}
@@ -212,13 +212,12 @@
*/
public void notifyNodeCreated(Fqn fqn, boolean pre, InvocationContext ctx)
{
- boolean originLocal = ctx.isOriginLocal();
- Transaction tx = ctx.getTransaction();
-
List<ListenerInvocation> listeners = listenerInvocations.get(NodeCreated.class);
- if (listeners != null && listeners.size() > 0)
+ if (listeners != null && !listeners.isEmpty())
{
+ boolean originLocal = ctx.isOriginLocal();
+ Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
e.setCache(cache);
@@ -243,14 +242,13 @@
*/
public void notifyNodeModified(Fqn fqn, boolean pre, NodeModifiedEvent.ModificationType modificationType, Map data, InvocationContext ctx)
{
- boolean originLocal = ctx.isOriginLocal();
- Map dataCopy = copy(data);
- Transaction tx = ctx.getTransaction();
-
List<ListenerInvocation> listeners = listenerInvocations.get(NodeModified.class);
- if (listeners != null && listeners.size() > 0)
+ if (listeners != null && !listeners.isEmpty())
{
+ boolean originLocal = ctx.isOriginLocal();
+ Map dataCopy = copy(data);
+ Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
e.setCache(cache);
@@ -276,14 +274,13 @@
*/
public void notifyNodeRemoved(Fqn fqn, boolean pre, Map data, InvocationContext ctx)
{
- boolean originLocal = ctx.isOriginLocal();
- Map dataCopy = copy(data);
- Transaction tx = ctx.getTransaction();
-
List<ListenerInvocation> listeners = listenerInvocations.get(NodeRemoved.class);
- if (listeners != null && listeners.size() > 0)
+ if (listeners != null && !listeners.isEmpty())
{
+ boolean originLocal = ctx.isOriginLocal();
+ Map dataCopy = copy(data);
+ Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
e.setCache(cache);
@@ -307,12 +304,11 @@
*/
public void notifyNodeVisited(Fqn fqn, boolean pre, InvocationContext ctx)
{
- Transaction tx = ctx.getTransaction();
-
List<ListenerInvocation> listeners = listenerInvocations.get(NodeVisited.class);
- if (listeners != null && listeners.size() > 0)
+ if (listeners != null && !listeners.isEmpty())
{
+ Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
e.setCache(cache);
@@ -327,13 +323,12 @@
public void notifyNodeMoved(Fqn originalFqn, Fqn newFqn, boolean pre, InvocationContext ctx)
{
- boolean originLocal = ctx.isOriginLocal();
- Transaction tx = ctx.getTransaction();
-
List<ListenerInvocation> listeners = listenerInvocations.get(NodeMoved.class);
- if (listeners != null && listeners.size() > 0)
+ if (listeners != null && !listeners.isEmpty())
{
+ boolean originLocal = ctx.isOriginLocal();
+ Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
e.setCache(cache);
@@ -358,13 +353,12 @@
*/
public void notifyNodeEvicted(final Fqn fqn, final boolean pre, InvocationContext ctx)
{
- final boolean originLocal = ctx.isOriginLocal();
- Transaction tx = ctx.getTransaction();
-
List<ListenerInvocation> listeners = listenerInvocations.get(NodeEvicted.class);
- if (listeners != null && listeners.size() > 0)
+ if (listeners != null && !listeners.isEmpty())
{
+ final boolean originLocal = ctx.isOriginLocal();
+ Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
e.setCache(cache);
@@ -388,14 +382,13 @@
*/
public void notifyNodeLoaded(Fqn fqn, boolean pre, Map data, InvocationContext ctx)
{
- boolean originLocal = ctx.isOriginLocal();
- Map dataCopy = copy(data);
- Transaction tx = ctx.getTransaction();
-
List<ListenerInvocation> listeners = listenerInvocations.get(NodeLoaded.class);
- if (listeners != null && listeners.size() > 0)
+ if (listeners != null && !listeners.isEmpty())
{
+ boolean originLocal = ctx.isOriginLocal();
+ Map dataCopy = copy(data);
+ Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
e.setCache(cache);
@@ -420,14 +413,13 @@
*/
public void notifyNodeActivated(Fqn fqn, boolean pre, Map data, InvocationContext ctx)
{
- boolean originLocal = ctx.isOriginLocal();
- Map dataCopy = copy(data);
- Transaction tx = ctx.getTransaction();
-
List<ListenerInvocation> listeners = listenerInvocations.get(NodeActivated.class);
- if (listeners != null && listeners.size() > 0)
+ if (listeners != null && !listeners.isEmpty())
{
+ boolean originLocal = ctx.isOriginLocal();
+ Map dataCopy = copy(data);
+ Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
e.setCache(cache);
@@ -452,13 +444,12 @@
*/
public void notifyNodePassivated(Fqn fqn, boolean pre, Map data, InvocationContext ctx)
{
- Map dataCopy = copy(data);
- Transaction tx = ctx.getTransaction();
-
List<ListenerInvocation> listeners = listenerInvocations.get(NodePassivated.class);
- if (listeners != null && listeners.size() > 0)
+ if (listeners != null && !listeners.isEmpty())
{
+ Map dataCopy = copy(data);
+ Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
e.setCache(cache);
@@ -482,7 +473,7 @@
{
List<ListenerInvocation> listeners = listenerInvocations.get(CacheStarted.class);
- if (listeners != null && listeners.size() > 0)
+ if (listeners != null && !listeners.isEmpty())
{
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
@@ -503,7 +494,7 @@
{
List<ListenerInvocation> listeners = listenerInvocations.get(CacheStopped.class);
- if (listeners != null && listeners.size() > 0)
+ if (listeners != null && !listeners.isEmpty())
{
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
@@ -525,7 +516,7 @@
{
List<ListenerInvocation> listeners = listenerInvocations.get(ViewChanged.class);
- if (listeners != null && listeners.size() > 0)
+ if (listeners != null && !listeners.isEmpty())
{
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
@@ -545,12 +536,12 @@
*/
public void notifyTransactionCompleted(Transaction transaction, boolean successful, InvocationContext ctx)
{
- Transaction tx = ctx.getTransaction();
- boolean isOriginLocal = ctx.isOriginLocal();
List<ListenerInvocation> listeners = listenerInvocations.get(TransactionCompleted.class);
- if (listeners != null && listeners.size() > 0)
+ if (listeners != null && !listeners.isEmpty())
{
+ Transaction tx = ctx.getTransaction();
+ boolean isOriginLocal = ctx.isOriginLocal();
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
e.setCache(cache);
@@ -570,12 +561,12 @@
*/
public void notifyTransactionRegistered(Transaction transaction, InvocationContext ctx)
{
- Transaction tx = ctx.getTransaction();
- boolean isOriginLocal = ctx.isOriginLocal();
List<ListenerInvocation> listeners = listenerInvocations.get(TransactionRegistered.class);
- if (listeners != null && listeners.size() > 0)
+ if (listeners != null && !listeners.isEmpty())
{
+ Transaction tx = ctx.getTransaction();
+ boolean isOriginLocal = ctx.isOriginLocal();
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
e.setCache(cache);
@@ -591,7 +582,7 @@
{
List<ListenerInvocation> listeners = listenerInvocations.get(CacheBlocked.class);
- if (listeners != null && listeners.size() > 0)
+ if (listeners != null && !listeners.isEmpty())
{
EventImpl e = new EventImpl();
e.setCache(cache);
@@ -605,7 +596,7 @@
{
List<ListenerInvocation> listeners = listenerInvocations.get(CacheUnblocked.class);
- if (listeners != null && listeners.size() > 0)
+ if (listeners != null && !listeners.isEmpty())
{
EventImpl e = new EventImpl();
e.setCache(cache);
@@ -616,7 +607,7 @@
}
- private Map copy(Map data)
+ private static Map copy(Map data)
{
if (safe(data)) return data;
return new MapCopy(data);
@@ -653,7 +644,7 @@
* @param map
* @return
*/
- private boolean safe(Map map)
+ private static boolean safe(Map map)
{
return map == null || map instanceof MapCopy || map.getClass().equals(emptyMap) || map.getClass().equals(singletonMap);
}
16 years, 12 months
JBoss Cache SVN: r4925 - core/trunk/src/main/java/org/jboss/cache/util.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-28 11:58:21 -0500 (Fri, 28 Dec 2007)
New Revision: 4925
Modified:
core/trunk/src/main/java/org/jboss/cache/util/CachePrinter.java
Log:
Fixed bad cast
Modified: core/trunk/src/main/java/org/jboss/cache/util/CachePrinter.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/CachePrinter.java 2007-12-28 14:50:51 UTC (rev 4924)
+++ core/trunk/src/main/java/org/jboss/cache/util/CachePrinter.java 2007-12-28 16:58:21 UTC (rev 4925)
@@ -23,7 +23,7 @@
public static String printCacheDetails(Cache c)
{
// internal cast
- CacheImpl ci = (CacheImpl) c;
+ CacheImpl ci = ((CacheInvocationDelegate) c).getDelegationTarget();
return ci.printDetails();
}
16 years, 12 months
JBoss Cache SVN: r4924 - in core/trunk/src/main/java/org/jboss/cache: factories and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-28 09:50:51 -0500 (Fri, 28 Dec 2007)
New Revision: 4924
Added:
core/trunk/src/main/java/org/jboss/cache/invocation/InvocationContextContainer.java
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java
Log:
InvocationContextContainer to be shared between all invocation delegates
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-28 13:38:10 UTC (rev 4923)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-28 14:50:51 UTC (rev 4924)
@@ -2173,7 +2173,8 @@
append(fqn).append("\", k=").append(key).append(", v=").append(value).append(")"));
}
-
+ // doesn't matter where we get this from - whether from the spi or the remote delegate - since they both refer to a single
+ // invocation context container instance.
InvocationContext ctx = spi.getInvocationContext();
// if this is a rollback then don't fire notifications.
boolean isRollback = checkIsRollingBack(ctx.getTransaction());
Modified: core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java 2007-12-28 13:38:10 UTC (rev 4923)
+++ core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java 2007-12-28 14:50:51 UTC (rev 4924)
@@ -3,6 +3,7 @@
import org.jboss.cache.RegionManager;
import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.factories.annotations.DefaultFactoryFor;
+import org.jboss.cache.invocation.InvocationContextContainer;
import org.jboss.cache.invocation.RemoteCacheInvocationDelegate;
import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.marshall.Marshaller;
@@ -18,7 +19,7 @@
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 2.1.0
*/
-@DefaultFactoryFor(classes = {StateTransferManager.class, TransactionTable.class, RegionManager.class, Notifier.class, CacheMessageListener.class, CacheLoaderManager.class, RemoteCacheInvocationDelegate.class, Marshaller.class})
+@DefaultFactoryFor(classes = {StateTransferManager.class, TransactionTable.class, RegionManager.class, Notifier.class, CacheMessageListener.class, CacheLoaderManager.class, RemoteCacheInvocationDelegate.class, Marshaller.class, InvocationContextContainer.class})
public class EmptyConstructorFactory extends ComponentFactory
{
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java 2007-12-28 13:38:10 UTC (rev 4923)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/AbstractInvocationDelegate.java 2007-12-28 14:50:51 UTC (rev 4924)
@@ -33,15 +33,7 @@
protected Configuration configuration;
protected boolean originLocal = true;
- protected ThreadLocal<InvocationContext> invocationContextContainer = new ThreadLocal<InvocationContext>()
- {
- @Override
- protected InvocationContext initialValue()
- {
- // create if this is initially unset
- return new InvocationContext();
- }
- };
+ protected InvocationContextContainer invocationContextContainer;
/**
* Used by the interceptor chain factory to inject dependencies.
@@ -51,11 +43,12 @@
* @param configuration configuration for the cache
*/
@Inject
- private void initialise(Interceptor interceptorChain, CacheImpl cache, Configuration configuration)
+ private void initialise(Interceptor interceptorChain, CacheImpl cache, Configuration configuration, InvocationContextContainer invocationContextContainer)
{
this.interceptorChain = interceptorChain;
this.cache = cache;
this.configuration = configuration;
+ this.invocationContextContainer = invocationContextContainer;
}
/**
Added: core/trunk/src/main/java/org/jboss/cache/invocation/InvocationContextContainer.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/InvocationContextContainer.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/InvocationContextContainer.java 2007-12-28 14:50:51 UTC (rev 4924)
@@ -0,0 +1,19 @@
+package org.jboss.cache.invocation;
+
+import org.jboss.cache.InvocationContext;
+
+/**
+ * Container and factory for thread locals
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.1.0
+ */
+public class InvocationContextContainer extends ThreadLocal<InvocationContext>
+{
+ @Override
+ protected InvocationContext initialValue()
+ {
+ // create if this is initially unset
+ return new InvocationContext();
+ }
+}
16 years, 12 months
JBoss Cache SVN: r4923 - in core/trunk/src: main/java/org/jboss/cache/config and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-28 08:38:10 -0500 (Fri, 28 Dec 2007)
New Revision: 4923
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java
core/trunk/src/main/java/org/jboss/cache/notifications/event/EventImpl.java
core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java
Log:
Better cache impl logging and more accurate cloning of runtime configs
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-28 12:17:28 UTC (rev 4922)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-28 13:38:10 UTC (rev 4923)
@@ -681,6 +681,8 @@
{
long start = System.currentTimeMillis();
channel.connect(configuration.getClusterName(), null, null, configuration.getStateRetrievalTimeout());
+ // reconfigure log category so that the instance name is reflected as well.
+ configureLogCategory();
//if I am not the only and the first member than wait for a state to arrive
if (getMembers().size() > 1)
{
@@ -716,6 +718,8 @@
try
{
channel.connect(configuration.getClusterName());
+ // reconfigure log category so that the instance name is reflected as well.
+ configureLogCategory();
}
catch (ChannelException e)
{
@@ -3133,7 +3137,7 @@
*/
private void configureLogCategory()
{
- StringBuffer category = new StringBuffer(getClass().getName());
+ StringBuilder category = new StringBuilder(getClass().getSimpleName());
if (configuration != null)
{
String clusterName = configuration.getClusterName();
@@ -3141,10 +3145,15 @@
{
category.append('.');
category.append(clusterName);
+ if (channel != null && channel.getLocalAddress() != null)
+ {
+ category.append('.');
+ category.append(channel.getLocalAddress());
+ }
}
}
-
- log = LogFactory.getLog(category.toString());
+ // replace .s with _s otherwise Log4J will strip them out
+ log = LogFactory.getLog(category.toString().replace('.', '_'));
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java 2007-12-28 12:17:28 UTC (rev 4922)
+++ core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java 2007-12-28 13:38:10 UTC (rev 4923)
@@ -36,6 +36,7 @@
// only reset the node factory and channel for now.
nodeFactory = null;
channel = null;
+ rpcManager = null;
}
Modified: core/trunk/src/main/java/org/jboss/cache/notifications/event/EventImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/notifications/event/EventImpl.java 2007-12-28 12:17:28 UTC (rev 4922)
+++ core/trunk/src/main/java/org/jboss/cache/notifications/event/EventImpl.java 2007-12-28 13:38:10 UTC (rev 4923)
@@ -14,9 +14,9 @@
* @since 2.0.0
*/
public class EventImpl implements CacheBlockedEvent, CacheUnblockedEvent, CacheStartedEvent, CacheStoppedEvent,
- NodeActivatedEvent, NodeCreatedEvent, NodeEvictedEvent, NodeLoadedEvent, NodeModifiedEvent, NodeMovedEvent,
- NodePassivatedEvent, NodeRemovedEvent, NodeVisitedEvent, TransactionCompletedEvent, TransactionRegisteredEvent,
- ViewChangedEvent
+ NodeActivatedEvent, NodeCreatedEvent, NodeEvictedEvent, NodeLoadedEvent, NodeModifiedEvent, NodeMovedEvent,
+ NodePassivatedEvent, NodeRemovedEvent, NodeVisitedEvent, TransactionCompletedEvent, TransactionRegisteredEvent,
+ ViewChangedEvent
{
private boolean pre = false; // by default events are after the fact
private Cache cache;
@@ -206,18 +206,18 @@
public String toString()
{
return "EventImpl{" +
- "pre=" + pre +
- ", cache=" + cache +
- ", modificationType=" + modificationType +
- ", data=" + data +
- ", fqn=" + fqn +
- ", transaction=" + transaction +
- ", originLocal=" + originLocal +
- ", targetFqn=" + targetFqn +
- ", successful=" + successful +
- ", newView=" + newView +
- ", type=" + type +
- '}';
+ "type=" + type +
+ ",pre=" + pre +
+ ", cache=" + cache +
+ ", modificationType=" + modificationType +
+ ", data=" + data +
+ ", fqn=" + fqn +
+ ", transaction=" + transaction +
+ ", originLocal=" + originLocal +
+ ", targetFqn=" + targetFqn +
+ ", successful=" + successful +
+ ", newView=" + newView +
+ '}';
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java 2007-12-28 12:17:28 UTC (rev 4922)
+++ core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java 2007-12-28 13:38:10 UTC (rev 4923)
@@ -24,10 +24,12 @@
import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.ComponentRegistry;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.notifications.event.Event;
@@ -99,40 +101,28 @@
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
- TransactionManager tm;
- if ((tm = cache1.getConfiguration().getRuntimeConfig().getTransactionManager()) != null)
- {
- if (tm.getTransaction() != null)
- {
- try
- {
- tm.rollback();
- }
- catch (Exception e)
- {
- // do nothing
- }
- }
- }
- if ((tm = cache2.getConfiguration().getRuntimeConfig().getTransactionManager()) != null)
- {
- if (tm.getTransaction() != null)
- {
- try
- {
- tm.rollback();
- }
- catch (Exception e)
- {
- // do nothing
- }
- }
- }
+ TestingUtil.killCaches(cache1, cache2);
+ }
- cache1.stop();
- cache1.destroy();
- cache2.stop();
- cache2.destroy();
+ /**
+ * Make sure the 2 caches have different component instances
+ */
+ public void testSeparateNotifiersAndListeners()
+ {
+ assert cache1 != cache2;
+ ComponentRegistry cr1, cr2;
+ cr1 = TestingUtil.extractComponentRegistry(cache1);
+ cr2 = TestingUtil.extractComponentRegistry(cache2);
+ assert cr1 != cr2;
+ assert cr1.getComponent(Notifier.class) != cr2.getComponent(Notifier.class);
+ assert eventLog1 != eventLog2;
+ assert cache1.getLocalAddress() != cache2.getLocalAddress();
+ CacheSPI spi1, spi2;
+ spi1 = (CacheSPI) cache1;
+ spi2 = (CacheSPI) cache2;
+
+ assert spi1.getRPCManager() != spi2.getRPCManager();
+ assert TestingUtil.extractField(spi1.getRPCManager(), "c") != TestingUtil.extractField(spi2.getRPCManager(), "c");
}
// simple tests first
16 years, 12 months
JBoss Cache SVN: r4922 - core/trunk/src/test/java/org/jboss/cache/loader.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-28 07:17:28 -0500 (Fri, 28 Dec 2007)
New Revision: 4922
Modified:
core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java
Log:
Fixed broken test
Modified: core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java 2007-12-28 01:45:01 UTC (rev 4921)
+++ core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java 2007-12-28 12:17:28 UTC (rev 4922)
@@ -6,6 +6,7 @@
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.marshall.NodeData;
+import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.cache.xml.XmlHelper;
import org.jboss.util.stream.MarshalledValueInputStream;
@@ -37,8 +38,8 @@
@SuppressWarnings("deprecation")
private JDBCCacheLoaderOld oldImpl;
-
private JDBCCacheLoader newImpl;
+ private CacheSPI cache, cache2;
/**
@@ -52,8 +53,8 @@
{
newImpl = getNewCacheLoader();
oldImpl = getOldLoader();
- CacheSPI cache = (CacheSPI) new DefaultCacheFactory().createCache(false);
- CacheSPI cache2 = (CacheSPI) new DefaultCacheFactory().createCache(false);
+ cache = (CacheSPI) new DefaultCacheFactory().createCache();
+ cache2 = (CacheSPI) new DefaultCacheFactory().createCache();
newImpl.setCache(cache);//this is needed for marshaller
oldImpl.setCache(cache2);
oldImpl.start();
@@ -66,6 +67,8 @@
oldImpl.remove(Fqn.ROOT);
oldImpl.stop();
newImpl.stop();
+
+ TestingUtil.killCaches(cache, cache2);
}
public void testCommonOperations() throws Exception
16 years, 12 months
JBoss Cache SVN: r4921 - in core/trunk/src: main/java/org/jboss/cache/factories and 5 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-27 20:45:01 -0500 (Thu, 27 Dec 2007)
New Revision: 4921
Removed:
core/trunk/src/main/java/org/jboss/cache/factories/CacheMarshallerFactory.java
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java
core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller210.java
core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java
core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryFunctionalTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java
core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java
core/trunk/src/test/java/org/jboss/cache/marshall/MethodIdPreservationTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java
core/trunk/src/test/java/org/jboss/cache/util/reflect/ClasspathScannerTest.java
Log:
Fixed marshalling-related issues
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -2798,7 +2798,7 @@
// use a get() call into the cache to make sure cache loading takes place.
// no need to cache the original skipDataGravitation setting here - it will always be false of we got here!!
ctx.getOptionOverrides().setSkipDataGravitation(true);
- Node actualNode = get(fqn);
+ Node actualNode = spi.getNode(fqn);
ctx.getOptionOverrides().setSkipDataGravitation(false);
if (log.isTraceEnabled()) log.trace("In local tree, this is " + actualNode);
@@ -2839,7 +2839,7 @@
else
{
// make sure we LOAD data for this node!!
- getData(actualNode.getFqn());
+ actualNode.getData();
}
if (backupNodeFqn == null && searchSubtrees)
@@ -2897,24 +2897,28 @@
public void _dataGravitationCleanup(GlobalTransaction gtx, Fqn primary, Fqn backup) throws Exception
{
- MethodCall primaryDataCleanup, backupDataCleanup;
+// MethodCall primaryDataCleanup, backupDataCleanup;
if (buddyManager.isDataGravitationRemoveOnFind())
{
if (log.isTraceEnabled())
log.trace("DataGravitationCleanup: Removing primary (" + primary + ") and backup (" + backup + ")");
- primaryDataCleanup = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, primary, false);
- backupDataCleanup = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, backup, false);
+ //primaryDataCleanup = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, primary, false);
+ spi.removeNode(primary);
+ //backupDataCleanup = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, backup, false);
+ spi.removeNode(backup);
}
else
{
if (log.isTraceEnabled())
log.trace("DataGravitationCleanup: Evicting primary (" + primary + ") and backup (" + backup + ")");
- primaryDataCleanup = MethodCallFactory.create(MethodDeclarations.evictNodeMethodLocal, primary);
- backupDataCleanup = MethodCallFactory.create(MethodDeclarations.evictNodeMethodLocal, backup);
+ //primaryDataCleanup = MethodCallFactory.create(MethodDeclarations.evictNodeMethodLocal, primary);
+ spi.evict(primary, true);
+ //backupDataCleanup = MethodCallFactory.create(MethodDeclarations.evictNodeMethodLocal, backup);
+ spi.evict(backup, true);
}
- invokeMethod(primaryDataCleanup, true);
- invokeMethod(backupDataCleanup, true);
+// invokeMethod(primaryDataCleanup, true);
+// invokeMethod(backupDataCleanup, true);
}
// ------------- end: buddy replication specific 'lifecycle' method calls
Deleted: core/trunk/src/main/java/org/jboss/cache/factories/CacheMarshallerFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/CacheMarshallerFactory.java 2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/factories/CacheMarshallerFactory.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -1,52 +0,0 @@
-package org.jboss.cache.factories;
-
-import org.jboss.cache.RegionManager;
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.factories.annotations.DefaultFactoryFor;
-import org.jboss.cache.marshall.CacheMarshaller210;
-import org.jboss.cache.marshall.Marshaller;
-import org.jboss.cache.marshall.VersionAwareMarshaller;
-import org.jboss.cache.util.Util;
-
-/**
- * Factory for creating marshallers
- *
- * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @since 2.1.0
- */
-@DefaultFactoryFor(classes = {Marshaller.class})
-public class CacheMarshallerFactory extends ComponentFactory
-{
- @Override
- @SuppressWarnings("unchecked")
- protected <T> T construct(String componentName, Class<T> componentType)
- {
- assertTypeConstructable(componentType, Marshaller.class);
-
- Marshaller m;
-
- String marshallerClass = configuration.getMarshallerClass();
-
- if (marshallerClass == null)
- {
- marshallerClass = CacheMarshaller210.class.getName();
- log.trace("Cache marshaller implementation not specified; using default " + marshallerClass);
- }
-
- try
- {
- m = (Marshaller) Util.loadClass(marshallerClass).newInstance();
- }
- catch (Exception e)
- {
- throw new ConfigurationException("Unable to instantiate marshaller of type " + marshallerClass, e);
- }
-
- //componentRegistry.wireDependencies(m);
-
- if (log.isDebugEnabled()) log.debug("Instantiated " + marshallerClass + "; wrapping in a VersionAwareMarshaller");
-
- VersionAwareMarshaller vam = new VersionAwareMarshaller(componentRegistry.getOrCreateComponent(null, RegionManager.class), configuration, m);
- return (T) vam;
- }
-}
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-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -136,9 +136,12 @@
c.changeState(stateToMoveTo);
// make sure any other omponents that have inadvertently been stopped are now restarted.
- for (Component comp : componentLookup.values())
+ if (old != null)
{
- if (comp.state != stateToMoveTo) comp.changeState(stateToMoveTo);
+ for (Component comp : componentLookup.values())
+ {
+ if (comp.state != stateToMoveTo) comp.changeState(stateToMoveTo);
+ }
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java 2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -5,6 +5,8 @@
import org.jboss.cache.factories.annotations.DefaultFactoryFor;
import org.jboss.cache.invocation.RemoteCacheInvocationDelegate;
import org.jboss.cache.loader.CacheLoaderManager;
+import org.jboss.cache.marshall.Marshaller;
+import org.jboss.cache.marshall.VersionAwareMarshaller;
import org.jboss.cache.notifications.Notifier;
import org.jboss.cache.remoting.jgroups.CacheMessageListener;
import org.jboss.cache.statetransfer.StateTransferManager;
@@ -16,7 +18,7 @@
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 2.1.0
*/
-@DefaultFactoryFor(classes = {StateTransferManager.class, TransactionTable.class, RegionManager.class, Notifier.class, CacheMessageListener.class, CacheLoaderManager.class, RemoteCacheInvocationDelegate.class})
+@DefaultFactoryFor(classes = {StateTransferManager.class, TransactionTable.class, RegionManager.class, Notifier.class, CacheMessageListener.class, CacheLoaderManager.class, RemoteCacheInvocationDelegate.class, Marshaller.class})
public class EmptyConstructorFactory extends ComponentFactory
{
@Override
@@ -27,8 +29,17 @@
{
if (componentType.isInterface())
{
- // add an "Impl" to the end of the class name and try again
- Class componentImpl = getClass().getClassLoader().loadClass(componentType.getName() + "Impl");
+ Class componentImpl;
+ if (componentType.equals(Marshaller.class))
+ {
+ componentImpl = VersionAwareMarshaller.class;
+ }
+ else
+ {
+ // add an "Impl" to the end of the class name and try again
+ componentImpl = getClass().getClassLoader().loadClass(componentType.getName() + "Impl");
+ }
+
return (T) componentImpl.newInstance();
}
else
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-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/RemoteCacheInvocationDelegate.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -5,6 +5,7 @@
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodCallFactory;
import org.jboss.cache.marshall.MethodDeclarations;
+import org.jboss.cache.transaction.GlobalTransaction;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -27,31 +28,37 @@
public Object _replicate(MethodCall methodCall) throws Throwable
{
- try
+ if (methodCall.getMethodId() == MethodDeclarations.clusteredGetMethod_id)
+ return invokeClusteredGet(methodCall);
+ else if (MethodDeclarations.isDataGravitationMethod(methodCall.getMethodId()))
+ return invokeDataGravitationCall(methodCall);
+ else
{
- Object retVal = invoke(methodCall);
- // we only need to return values for a set of remote calls; not every call.
- if (MethodDeclarations.returnValueForRemoteCall(methodCall.getMethodId()))
+ try
{
- return retVal;
+ Object retVal = invoke(methodCall);
+ // we only need to return values for a set of remote calls; not every call.
+ if (MethodDeclarations.returnValueForRemoteCall(methodCall.getMethodId()))
+ {
+ return retVal;
+ }
+ else
+ {
+ return null;
+ }
}
- else
+ catch (Throwable ex)
{
- return null;
+ if (methodCall.getMethodId() != MethodDeclarations.putForExternalReadMethodLocal_id
+ || methodCall.getMethodId() != MethodDeclarations.putForExternalReadVersionedMethodLocal_id)
+ {
+ if (!MethodDeclarations.isBuddyGroupOrganisationMethod(methodCall.getMethodId()) && log.isWarnEnabled())
+ log.warn("replication failure with methodCall " + methodCall + " exception", ex);
+ throw ex;
+ }
+ else return null;
}
}
- catch (Throwable ex)
- {
- if (methodCall.getMethodId() != MethodDeclarations.putForExternalReadMethodLocal_id
- || methodCall.getMethodId() != MethodDeclarations.putForExternalReadVersionedMethodLocal_id)
- {
- if (!MethodDeclarations.isBuddyGroupOrganisationMethod(methodCall.getMethodId()) && log.isWarnEnabled())
- log.warn("replication failure with methodCall " + methodCall + " exception", ex);
- throw ex;
- }
- else return null;
-
- }
}
/**
@@ -62,6 +69,31 @@
for (MethodCall methodCall : methodCalls) _replicate(methodCall);
}
+ public Object invokeClusteredGet(MethodCall call)
+ {
+ Object[] args = call.getArgs();
+ return clusteredGet((MethodCall) args[0], (Boolean) args[1]);
+ }
+
+ public Object invokeDataGravitationCall(MethodCall call) throws Exception
+ {
+ Object[] args = call.getArgs();
+ if (call.getMethodId() == MethodDeclarations.dataGravitationMethod_id)
+ {
+ return cache.gravitateData((Fqn) args[0], (Boolean) args[1]);
+ }
+ else if (call.getMethodId() == MethodDeclarations.dataGravitationCleanupMethod_id)
+ {
+ cache._dataGravitationCleanup((GlobalTransaction) args[0], (Fqn) args[1], (Fqn) args[2]);
+ return null;
+ }
+ else
+ {
+ throw new UnsupportedOperationException(call + " is not a data gravitation call!");
+ }
+ }
+
+
public void block()
{
MethodCall m = MethodCallFactory.create(MethodDeclarations.blockChannelLocal);
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java 2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -14,6 +14,7 @@
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.transaction.GlobalTransaction;
import java.io.ByteArrayOutputStream;
@@ -40,18 +41,20 @@
* Map<GlobalTransaction, Fqn> for prepared tx that have not committed
*/
private Map<GlobalTransaction, Fqn> transactions = new ConcurrentHashMap<GlobalTransaction, Fqn>(16);
+ protected Configuration configuration;
@Inject
- private void injectDependencies(RegionManager regionManager, Configuration configuration)
+ void injectDependencies(RegionManager regionManager, Configuration configuration)
{
- init(regionManager, configuration.isInactiveOnStartup(), configuration.isUseRegionBasedMarshalling());
+ this.regionManager = regionManager;
+ this.configuration = configuration;
}
- protected void init(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling)
+ @Start
+ protected void init()
{
- this.useRegionBasedMarshalling = useRegionBasedMarshalling;
- this.defaultInactive = defaultInactive;
- this.regionManager = manager;
+ this.useRegionBasedMarshalling = configuration.isUseRegionBasedMarshalling();
+ this.defaultInactive = configuration.isInactiveOnStartup();
}
// implement the basic contract set in RPcDispatcher.AbstractMarshaller
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -10,7 +10,6 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import static org.jboss.cache.Region.Status;
-import org.jboss.cache.RegionManager;
import org.jboss.cache.buddyreplication.GravitateResult;
import org.jboss.cache.optimistic.DefaultDataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
@@ -68,16 +67,6 @@
log = LogFactory.getLog(CacheMarshaller200.class);
}
- public CacheMarshaller200(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling)
- {
- log = LogFactory.getLog(CacheMarshaller200.class);
- init(manager, defaultInactive, useRegionBasedMarshalling);
- if (useRegionBasedMarshalling)
- {
- log.debug("Using region based marshalling logic : marshalling Fqn first for every call.");
- }
- }
-
/**
* Tests if the type of object being marshalled is a method call or a return value
*
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller210.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller210.java 2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller210.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -1,7 +1,6 @@
package org.jboss.cache.marshall;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.RegionManager;
import java.io.IOException;
import java.io.ObjectInputStream;
@@ -24,12 +23,6 @@
log = LogFactory.getLog(CacheMarshaller210.class);
}
- public CacheMarshaller210(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling)
- {
- super(manager, defaultInactive, useRegionBasedMarshalling);
- log = LogFactory.getLog(CacheMarshaller210.class);
- }
-
/**
* This version of writeReference is written to solve JBCACHE-1211, where references are encoded as ints rather than shorts.
*
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java 2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -9,8 +9,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
-import org.jboss.cache.RegionManager;
-import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Start;
+import org.jboss.cache.util.Util;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
@@ -35,59 +35,66 @@
private static final Log log = LogFactory.getLog(VersionAwareMarshaller.class);
private static final int VERSION_200 = 20;
private static final int VERSION_210 = 21;
+ private static final int CUSTOM_MARSHALLER = 999;
- private RegionManager manager;
- private boolean defaultInactive, useRegionBasedMarshalling;
Marshaller defaultMarshaller;
Map<Integer, Marshaller> marshallers = new HashMap<Integer, Marshaller>();
private int versionInt;
- public VersionAwareMarshaller(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling, String version)
+ @Start
+ protected void initReplicationVersions()
{
- this(manager, defaultInactive, useRegionBasedMarshalling, version, null);
- }
+ String replVersionString = configuration.getReplVersionString();
- public VersionAwareMarshaller(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling, String version, Marshaller defaultMarshaller)
- {
- this.manager = manager;
- this.defaultInactive = defaultInactive;
- this.useRegionBasedMarshalling = useRegionBasedMarshalling;
-
- // "Rounds down" the replication version passed in to the MINOR version.
- // E.g., 1.4.1.SP3 -> 1.4.0
-
- versionInt = toMinorVersionInt(version);
-
// this will cause the correct marshaller to be created and put in the map of marshallers
+ defaultMarshaller = configuration.getMarshaller();
if (defaultMarshaller == null)
{
+ String marshallerClass = configuration.getMarshallerClass();
+ if (marshallerClass != null)
+ {
+ log.trace("Cache marshaller implementation specified as " + marshallerClass + ". Overriding any version strings passed in. ");
+ try
+ {
+ defaultMarshaller = (Marshaller) Util.loadClass(marshallerClass).newInstance();
+ }
+ catch (Exception e)
+ {
+ log.warn("Unable to instantiate marshaller of class " + marshallerClass, e);
+ log.warn("Falling back to using the default marshaller for version string " + replVersionString);
+ }
+ }
+ }
+
+ if (defaultMarshaller == null)
+ {
+ // "Rounds down" the replication version passed in to the MINOR version.
+ // E.g., 1.4.1.SP3 -> 1.4.0
+ versionInt = toMinorVersionInt(replVersionString);
this.defaultMarshaller = getMarshaller(versionInt);
}
else
{
log.debug("Using the marshaller passed in - " + defaultMarshaller);
- this.defaultMarshaller = defaultMarshaller;
+ versionInt = getCustomMarshallerVersionInt();
marshallers.put(versionInt, defaultMarshaller);
}
if (log.isDebugEnabled())
{
- log.debug("Initialised with version " + version + " and versionInt " + versionInt);
+ log.debug("Started with version " + replVersionString + " and versionInt " + versionInt);
log.debug("Using default marshaller class " + this.defaultMarshaller.getClass());
}
}
- public VersionAwareMarshaller(RegionManager regionManager, Configuration configuration)
+ protected int getCustomMarshallerVersionInt()
{
- this(regionManager, configuration.isInactiveOnStartup(), configuration.isUseRegionBasedMarshalling(), configuration.getReplVersionString());
+ if (defaultMarshaller.getClass().equals(CacheMarshaller210.class)) return VERSION_210;
+ if (defaultMarshaller.getClass().equals(CacheMarshaller200.class)) return VERSION_200;
+ return CUSTOM_MARSHALLER;
}
- public VersionAwareMarshaller(RegionManager regionManager, Configuration configuration, Marshaller defaultMarshaller)
- {
- this(regionManager, configuration.isInactiveOnStartup(), configuration.isUseRegionBasedMarshalling(), configuration.getReplVersionString(), defaultMarshaller);
- }
-
/**
* Converts versions to known compatible version ids.
* <p/>
@@ -207,6 +214,7 @@
Marshaller getMarshaller(int versionId)
{
Marshaller marshaller;
+ AbstractMarshaller am;
boolean knownVersion = false;
switch (versionId)
{
@@ -214,7 +222,10 @@
marshaller = marshallers.get(VERSION_200);
if (marshaller == null)
{
- marshaller = new CacheMarshaller200(manager, defaultInactive, useRegionBasedMarshalling);
+ am = new CacheMarshaller200();
+ marshaller = am;
+ am.injectDependencies(regionManager, configuration);
+ am.init();
marshallers.put(VERSION_200, marshaller);
}
break;
@@ -222,11 +233,14 @@
knownVersion = true;
default:
if (!knownVersion)
- log.warn("Unknown replication version String. Falling back to the default marshaller, which is Version 2.1.0.");
+ log.warn("Unknown replication version String. Falling back to the default marshaller installed.");
marshaller = marshallers.get(VERSION_210);
if (marshaller == null)
{
- marshaller = new CacheMarshaller210(manager, defaultInactive, useRegionBasedMarshalling);
+ am = new CacheMarshaller210();
+ marshaller = am;
+ am.injectDependencies(regionManager, configuration);
+ am.init();
marshallers.put(VERSION_210, marshaller);
}
break;
Modified: core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryFunctionalTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryFunctionalTest.java 2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryFunctionalTest.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -48,7 +48,7 @@
// at very least, expecting a Marshaller factory and a DefaultCacheFactory.
assert cr.defaultFactories.containsKey(Marshaller.class);
- assert cr.defaultFactories.get(Marshaller.class).equals(CacheMarshallerFactory.class);
+ assert cr.defaultFactories.get(Marshaller.class).equals(EmptyConstructorFactory.class);
assert cr.defaultFactories.containsKey(Notifier.class);
assert cr.defaultFactories.get(Notifier.class).equals(EmptyConstructorFactory.class);
@@ -107,7 +107,7 @@
{
Class<Marshaller> componentToTest = Marshaller.class;
configuration.setMarshallerClass(CacheMarshaller200.class.getName());
- Marshaller instance = new CacheMarshaller210(null, false, false);
+ Marshaller instance = new CacheMarshaller210();
configuration.setCacheMarshaller(instance);
// the setup() would have wired the default marshaller. Need to update deps.
@@ -125,7 +125,7 @@
public void testConstructionOrder3()
{
Class<Marshaller> componentToTest = Marshaller.class;
- Marshaller instance = new CacheMarshaller210(null, false, false);
+ Marshaller instance = new CacheMarshaller210();
configuration.setCacheMarshaller(instance);
// the setup() would have wired the default marshaller. Need to update deps.
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java 2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -12,7 +12,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
-import org.jboss.cache.Version;
+import org.jboss.cache.config.Configuration;
import org.jboss.cache.misc.TestingUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
@@ -163,7 +163,14 @@
Region region_A = rman.getRegion(A, true);
region_A.registerContextClassLoader(this.getClass().getClassLoader());
assertFalse("New regions created should be inactive by default", region_A.isActive());
- VersionAwareMarshaller testee = new VersionAwareMarshaller(rman, true, true, Version.getVersionString(Version.getVersionShort()));
+ Configuration c = new Configuration();
+ c.setUseRegionBasedMarshalling(true);
+ c.setInactiveOnStartup(true);
+ VersionAwareMarshaller testee = new VersionAwareMarshaller();
+ testee.injectDependencies(rman, c);
+ testee.init();
+ testee.initReplicationVersions();
+
byte[] callBytes = testee.objectToByteBuffer(replicate);
try
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java 2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -35,7 +35,10 @@
public void testRegionalisedStream() throws Exception
{
// need to test what's going on with
- CacheMarshaller200 cm200 = new CacheMarshaller200(new RegionManager(), false, true);
+ CacheMarshaller200 cm200 = new CacheMarshaller200();
+ c.setUseRegionBasedMarshalling(true);
+ cm200.injectDependencies(new RegionManager(), c);
+ cm200.init();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
cm200.objectToObjectStream("Hello World", oos, Fqn.fromString("/hello"));
@@ -80,7 +83,10 @@
// first create a stream to unmarshall.
RegionManager rm = new RegionManager();
- final CacheMarshaller200 cm200 = new CacheMarshaller200(rm, false, true);
+ final CacheMarshaller200 cm200 = new CacheMarshaller200();
+ c.setUseRegionBasedMarshalling(true);
+ cm200.injectDependencies(new RegionManager(), c);
+ cm200.init();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
final Fqn region = Fqn.fromString("/hello");
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java 2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -8,6 +8,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.config.Configuration;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -21,13 +22,23 @@
{
protected String currentVersion;
protected int currentVersionShort;
- protected Class expectedMarshallerClass;
+ protected Class expectedMarshallerClass, latestMarshallerClass = CacheMarshaller210.class;
protected VersionAwareMarshaller marshaller;
+ protected RegionManager regionManager;
+ protected Configuration c;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, currentVersion);
+ regionManager = new RegionManager();
+ c = new Configuration();
+ c.setUseRegionBasedMarshalling(false);
+ c.setInactiveOnStartup(false);
+ c.setReplVersionString(currentVersion);
+ marshaller = new VersionAwareMarshaller();
+ marshaller.injectDependencies(regionManager, c);
+ marshaller.init();
+ marshaller.initReplicationVersions();
}
@AfterMethod(alwaysRun = true)
@@ -88,13 +99,17 @@
assertEquals("Only one marshaller should be in the map by this stage", 1, marshaller.marshallers.size());
assertEquals(expectedMarshallerClass, marshaller.getMarshaller(currentVersionShort).getClass());
- assertEquals(expectedMarshallerClass, marshaller.getMarshaller(15).getClass());
- assertEquals(expectedMarshallerClass, marshaller.getMarshaller(1).getClass());
- assertEquals(expectedMarshallerClass, marshaller.getMarshaller(-1).getClass());
- assertEquals(expectedMarshallerClass, marshaller.getMarshaller(0).getClass());
+
+ // defaultMarshaller is used for outgoing streams
+ assert marshaller.defaultMarshaller.getClass().equals(expectedMarshallerClass);
+
+ assertEquals(latestMarshallerClass, marshaller.getMarshaller(15).getClass());
+ assertEquals(latestMarshallerClass, marshaller.getMarshaller(1).getClass());
+ assertEquals(latestMarshallerClass, marshaller.getMarshaller(-1).getClass());
+ assertEquals(latestMarshallerClass, marshaller.getMarshaller(0).getClass());
assertEquals(CacheMarshaller200.class, marshaller.getMarshaller(20).getClass());
- assertEquals("One marshaller should be in the map by this stage", 1, marshaller.marshallers.size());
+ assert marshaller.marshallers.size() == 2 : "Should have 2 marshallers now";
}
public void testStringBasedFqn() throws Exception
@@ -207,7 +222,8 @@
public void testReplicationQueueWithRegionBasedMarshalling() throws Exception
{
- marshaller = new VersionAwareMarshaller(new RegionManager(), false, true, currentVersion);
+ c.setUseRegionBasedMarshalling(true);
+ marshaller.init();
doReplicationQueueTest();
}
@@ -219,12 +235,12 @@
Fqn f = new Fqn<Object>("BlahBlah", 3, false);
String k = "key", v = "value";
- MethodCall actualCall = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, f, k, v, true);
+ MethodCall actualCall = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, null, f, k, v, true);
MethodCall replicateCall = MethodCallFactory.create(MethodDeclarations.replicateMethod, actualCall);
calls.add(replicateCall);
- actualCall = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, f, k, v, true);
+ actualCall = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, null, f, k, v, true);
replicateCall = MethodCallFactory.create(MethodDeclarations.replicateMethod, actualCall);
calls.add(replicateCall);
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/MethodIdPreservationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/MethodIdPreservationTest.java 2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/MethodIdPreservationTest.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -19,7 +19,7 @@
@Test(groups = {"functional"})
public class MethodIdPreservationTest
{
- private Marshaller m = new CacheMarshaller200(null, false, false);
+ private Marshaller m = new CacheMarshaller210();
private ObjectOutputStream stream;
private ByteArrayOutputStream byteStream;
private MethodCall call1;
@@ -37,7 +37,7 @@
list.clear();
list.add(call1);
list.add(call2);
- prepareCall = MethodCallFactory.create(MethodDeclarations.prepareMethod, list, null, true);
+ prepareCall = MethodCallFactory.create(MethodDeclarations.prepareMethod, null, list, null, true);
}
public void testSingleMethodCall() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java 2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -1,8 +1,12 @@
package org.jboss.cache.marshall;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.misc.TestingUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -21,17 +25,20 @@
{
private final Fqn DEFAULT_REGION = Fqn.ROOT;
private RegionManager r;
+ private Configuration c;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- r = new RegionManager();
+ CacheSPI cache = (CacheSPI) new DefaultCacheFactory().createCache();
+ r = cache.getRegionManager();
+ c = cache.getConfiguration();
}
@AfterMethod(alwaysRun = false)
public void tearDown() throws Exception
{
- r.getCache().stop();
+ TestingUtil.killCaches(r.getCache());
r = null;
}
@@ -75,7 +82,7 @@
assertFalse("Should not be expecting any more regions", expectedRegions.hasNext());
}
- public void testNoDefaultRegion()
+ public void testDefaultRegion()
{
Fqn fqn1 = Fqn.fromString("/a/b/c");
Fqn fqn2 = Fqn.fromString("/a/b/");
@@ -83,17 +90,10 @@
r.getRegion(fqn1, true);
r.getRegion(fqn2, true);
- Region region = null;
- try
- {
- region = r.getRegion("/a", false);
- }
- catch (Exception e)
- {
- fail("If we don't setCache the default region, it still should be ok!");
- }
+ Region region = r.getRegion("/a", false);
- assertNull("Default region is not null!", region);
+ assertNotNull("Default region is not null!", region);
+ assert region.getFqn().equals(Fqn.ROOT) : "Should be the default region";
}
@@ -120,28 +120,28 @@
Region r2 = r.getRegion(fqn2, true);
Region r3 = r.getRegion(fqn3, true);
- assertEquals("Expecting 3 regions", 3, r.getAllRegions(Region.Type.ANY).size());
+ assertEquals("Expecting 4 regions", 4, r.getAllRegions(Region.Type.ANY).size());
// test that removal doesn't affect parent traversal.
assertEquals(r3, r.getRegion(fqn3, false));
r.removeRegion(Fqn.fromString(fqn3));
- assertEquals("Expecting 2 regions", 2, r.getAllRegions(Region.Type.ANY).size());
+ assertEquals("Expecting 3 regions", 3, r.getAllRegions(Region.Type.ANY).size());
// test that removal doesn't affect parent traversal.
assertEquals("Should have retrieved parent region", r2, r.getRegion(fqn3, false));
r.removeRegion(Fqn.fromString(fqn2));
- assertEquals("Expecting 1 region", 1, r.getAllRegions(Region.Type.ANY).size());
+ assertEquals("Expecting 2 region", 2, r.getAllRegions(Region.Type.ANY).size());
// test that removal doesn't affect parent traversal.
assertEquals("Should have retrieved parent region", r1, r.getRegion(fqn3, false));
r.removeRegion(Fqn.fromString(fqn1));
- assertEquals("Expecting 0 regions", 0, r.getAllRegions(Region.Type.ANY).size());
+ assertEquals("Expecting 1 regions (default region)", 1, r.getAllRegions(Region.Type.ANY).size());
}
public void testGetRegionsMethods()
@@ -153,7 +153,7 @@
@SuppressWarnings("unused")
Region r1 = r.getRegion(f1, true), r2 = r.getRegion(f2, true), r3 = r.getRegion(f3, true), r4 = r.getRegion(f4, true);
- assertEquals("4 regions should exist", 4, r.getAllRegions(Region.Type.ANY).size());
+ assertEquals("5 regions should exist", 5, r.getAllRegions(Region.Type.ANY).size());
assertEquals("None of the regions should marshalling or active", 0, r.getAllRegions(Region.Type.MARSHALLING).size());
@@ -186,40 +186,4 @@
assertSame("r3 should be marshalling and active", r3, r.getAllRegions(Region.Type.MARSHALLING).get(1));
assertSame("r4 should be marshalling and active", r4, r.getAllRegions(Region.Type.MARSHALLING).get(2));
}
-/*
- public void testUnspecifiedRegionType()
- {
- Fqn fqn = Fqn.fromString("/a/b/c");
- Region region = r.getRegion(fqn, true);
-
- assertNotNull(region);
- assertEquals(fqn, region.getFqn());
-
- region = r.getRegion(fqn, Region.Type.MARSHALLING, false);
-
- assertNotNull(region);
- assertEquals(fqn, region.getFqn());
- }
-
- public void testPreferenceForMarshallingRegion()
- {
- Fqn fqn = Fqn.fromString("/a/b/c");
-
- Region region = r.getRegion(fqn, Region.Type.MARSHALLING, false);
-
- assertNotNull(region);
- assertEquals(Fqn.ROOT, region.getFqn());
-
- region = r.getRegion(fqn, true);
-
- assertNotNull(region);
- assertEquals(fqn, region.getFqn());
-
- region = r.getRegion(fqn, Region.Type.MARSHALLING, false);
-
- assertNotNull(region);
- assertEquals(fqn, region.getFqn());
- }*/
-
-
}
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java 2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -6,6 +6,7 @@
import org.jboss.cache.Region;
import org.jboss.cache.buddyreplication.GravitateResult;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.misc.TestingUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -62,8 +63,7 @@
@AfterMethod(alwaysRun = true)
public void tearDown()
{
- cache1.stop();
- cache2.stop();
+ TestingUtil.killCaches(cache1, cache2);
}
private ClassLoader getClassLoader()
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java 2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -8,10 +8,12 @@
import org.jboss.cache.RegionManager;
import org.jboss.cache.Version;
+import org.jboss.cache.config.Configuration;
import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.Test;
import java.io.ObjectInputStream;
+
/**
* Tests the enhanced treecache marshaller
*
@@ -22,37 +24,48 @@
{
public void testMarshallerSelection()
{
- VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "2.1.0.GA");
+ VersionAwareMarshaller marshaller = createAndConfigure("2.1.0.GA");
assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
- marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "2.0.0.GA");
+ marshaller = createAndConfigure("2.0.0.GA");
assertEquals(CacheMarshaller200.class, marshaller.defaultMarshaller.getClass());
- marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.4.0.GA");
+ marshaller = createAndConfigure("1.4.0.GA");
assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
- marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.5.0.GA");
+ marshaller = createAndConfigure("1.5.0.GA");
assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
- marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.3.0.GA");
+ marshaller = createAndConfigure("1.3.0.GA");
assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
- marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.3.0.SP2");
+ marshaller = createAndConfigure("1.3.0.SP2");
assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
- marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.3.1.GA");
+ marshaller = createAndConfigure("1.3.1.GA");
assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
- marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.2.4.SP2");
+ marshaller = createAndConfigure("1.2.4.SP2");
assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
- marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "1.2.3");
+ marshaller = createAndConfigure("1.2.3");
assertEquals(CacheMarshaller210.class, marshaller.defaultMarshaller.getClass());
}
+ private VersionAwareMarshaller createAndConfigure(String replVersion)
+ {
+ Configuration c = new Configuration();
+ c.setReplVersionString(replVersion);
+ VersionAwareMarshaller vam = new VersionAwareMarshaller();
+ vam.injectDependencies(new RegionManager(), c);
+ vam.init();
+ vam.initReplicationVersions();
+ return vam;
+ }
+
public void testVersionHeaderDefaultCurrent() throws Exception
{
- VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, Version.getVersionString(Version.getVersionShort()));
+ VersionAwareMarshaller marshaller = createAndConfigure(Version.getVersionString(Version.getVersionShort()));
byte[] bytes = marshaller.objectToByteBuffer("Hello");
// expect that this has been serialized using JBoss Serialization so use this to get an OIS.
@@ -62,7 +75,7 @@
public void testVersionHeader200() throws Exception
{
- VersionAwareMarshaller marshaller = new VersionAwareMarshaller(new RegionManager(), false, false, "2.0.0.GA");
+ VersionAwareMarshaller marshaller = createAndConfigure("2.0.0.GA");
byte[] bytes = marshaller.objectToByteBuffer("Hello");
// expect that this has been serialized using JBoss Serialization so use this to get an OIS.
Modified: core/trunk/src/test/java/org/jboss/cache/util/reflect/ClasspathScannerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/util/reflect/ClasspathScannerTest.java 2007-12-27 20:40:54 UTC (rev 4920)
+++ core/trunk/src/test/java/org/jboss/cache/util/reflect/ClasspathScannerTest.java 2007-12-28 01:45:01 UTC (rev 4921)
@@ -1,7 +1,7 @@
package org.jboss.cache.util.reflect;
-import org.jboss.cache.factories.CacheMarshallerFactory;
import org.jboss.cache.factories.ComponentFactory;
+import org.jboss.cache.factories.EmptyConstructorFactory;
import org.jboss.cache.factories.TransactionManagerFactory;
import org.jboss.cache.factories.annotations.DefaultFactoryFor;
import org.testng.annotations.Test;
@@ -22,6 +22,6 @@
// should at least contain these 2.
assert sc.contains(TransactionManagerFactory.class);
- assert sc.contains(CacheMarshallerFactory.class);
+ assert sc.contains(EmptyConstructorFactory.class);
}
}
16 years, 12 months
JBoss Cache SVN: r4920 - in core/trunk/src: main/java/org/jboss/cache/factories and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-27 15:40:54 -0500 (Thu, 27 Dec 2007)
New Revision: 4920
Modified:
core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryFunctionalTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java
core/trunk/src/test/java/org/jboss/cache/optimistic/ConcurrentTransactionTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/HasChildTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/LockParentVersionTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/MockFailureInterceptor.java
core/trunk/src/test/java/org/jboss/cache/optimistic/MockInterceptor.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeyValTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeysTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorKeyValTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutEraseTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutMapTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveDataTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveKeyValTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorTransactionTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticCreateIfNotExistsInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticReplicationInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticVersioningTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithPassivationTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedCacheAccessTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedOptimisticCreateIfNotExistsInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/ValidationFailureTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/ValidatorInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/VersioningOnReadTest.java
Log:
Updated optimistic tests and optimised dependency detection during component registration
Modified: core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/main/java/org/jboss/cache/DefaultCacheFactory.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -132,14 +132,8 @@
// injection bootstrap stuff
componentRegistry = cache.getComponentRegistry();
- // and the configuration
- componentRegistry.registerComponent(configuration);
this.configuration = configuration;
- // and the component registry itself. This bit of recursiveness is needed for factories that are also components.
- // See NodeFactory for example, which is created by an EmptyConstructorFactory
- componentRegistry.registerComponent(componentRegistry);
-
// make sure we set the CacheImpl and CacheSPI instance in the component registry.
componentRegistry.registerComponent(cache);
componentRegistry.registerComponent(CacheSPI.class.getName(), spi);
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-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -59,6 +59,8 @@
*/
public class ComponentRegistry
{
+ static final Object NULL_COMPONENT = new Object();
+
State overallState = CONSTRUCTED;
/**
@@ -81,6 +83,7 @@
public ComponentRegistry(Configuration configuration)
{
// bootstrap.
+ registerComponent(this);
registerComponent(configuration);
}
@@ -125,9 +128,10 @@
// components that depended on the old component should now depend on the new one.
c.dependencyFor.addAll(old.dependencyFor);
}
- addComponentDependencies(c);
+ componentLookup.put(name, c);
- componentLookup.put(name, c);
+ addComponentDependencies(c, old == null);
+
State stateToMoveTo = overallState == null ? CONSTRUCTED : overallState;
c.changeState(stateToMoveTo);
@@ -138,7 +142,7 @@
}
}
- protected void addComponentDependencies(Component c)
+ protected void addComponentDependencies(Component c, boolean firstTimeAdded)
{
// build any dependent components if necessary
for (Dependency d : c.dependencies)
@@ -147,6 +151,16 @@
Component dependencyComponent = componentLookup.get(d.name);
if (dependencyComponent != null) dependencyComponent.dependencyFor.add(c.asDependency());
}
+
+ if (firstTimeAdded)
+ {
+ // loop through all other components already registered and make sure the current component's dependencyFor map is accurate
+ for (Component other : componentLookup.values())
+ {
+ if (other.dependencies.contains(c.asDependency())) c.dependencyFor.add(other.asDependency());
+ }
+ }
+
}
public <T> T getComponent(Class<T> c)
@@ -167,9 +181,9 @@
Component wrapper = componentLookup.get(name);
if (wrapper == null) return null;
- T component = (T) wrapper.instance;
+ T component = (T) (wrapper.instance == NULL_COMPONENT ? null : wrapper.instance);
- if (c.isAssignableFrom(component.getClass())) return component;
+ if (component == null || c.isAssignableFrom(component.getClass())) return component;
else
throw new ConfigurationException("Component registered under " + name + " is of type " + component.getClass() + " and cannot be assigned to " + c);
}
@@ -224,27 +238,37 @@
{
// first see if this has been injected externally.
component = getFromConfiguration(componentClass);
+ boolean attemptedFactoryConstruction = false;
if (component == null && isNonBootstrap(componentClass))
{
// create this component and add it to the registry
ComponentFactory factory = getFactory(componentClass);
component = factory.construct(componentName, componentClass);
+ attemptedFactoryConstruction = true;
+
}
+ String componentNameToUse = componentName == null ? componentClass.getName() : componentName;
+
if (component != null)
{
- // wire dependencies
-// wireDependencies(component);
- if (componentName == null)
- registerComponent(componentClass.getName(), component);
- else
- registerComponent(componentName, component);
+ registerComponent(componentNameToUse, component);
}
+ else if (attemptedFactoryConstruction)
+ {
+ registerNullComponent(componentNameToUse);
+ }
}
return component;
}
+ // registers a special "null" component that has no dependencies.
+ void registerNullComponent(String componentName)
+ {
+ registerComponent(componentName, NULL_COMPONENT);
+ }
+
private boolean isNonBootstrap(Class<?> componentClass)
{
return !(componentClass.equals(CacheSPI.class) || componentClass.equals(CacheImpl.class) || componentClass.equals(Cache.class)
@@ -566,10 +590,10 @@
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);
+ addComponentDependencies(spi, true);
+ addComponentDependencies(impl, true);
+ addComponentDependencies(conf, true);
+ addComponentDependencies(cr, true);
}
/**
@@ -671,14 +695,6 @@
// now for each injection method, get dependencies
for (Method m : injectionMethods) dependencies.addAll(getDeclaredDependencies(m));
-
- // backward-chaining - make sure I know about components that depend on me.
- me = asDependency();
- for (Dependency d : dependencies)
- {
- Component c = componentLookup.get(d.name);
- if (c != null) c.dependencyFor.add(me);
- }
}
/**
Modified: core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryFunctionalTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryFunctionalTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryFunctionalTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -1,7 +1,7 @@
package org.jboss.cache.factories;
-import org.jboss.cache.CacheImpl;
-import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheFactory;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.RPCManager;
import org.jboss.cache.RegionManager;
@@ -10,7 +10,6 @@
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.invocation.CacheInvocationDelegate;
import org.jboss.cache.marshall.CacheMarshaller200;
import org.jboss.cache.marshall.CacheMarshaller210;
import org.jboss.cache.marshall.Marshaller;
@@ -21,8 +20,6 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.lang.reflect.Constructor;
-
/**
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 2.1.0
@@ -36,25 +33,11 @@
@BeforeMethod
public void setUp() throws Exception
{
- ComponentFactory cf = (ComponentFactory) new DefaultCacheFactory();
+ CacheFactory cf = new DefaultCacheFactory();
- CacheSPI spi = new CacheInvocationDelegate();
- Constructor ctor = CacheImpl.class.getDeclaredConstructor();
- ctor.setAccessible(true);
- CacheImpl ci = (CacheImpl) ctor.newInstance();
-
- configuration = ci.getConfiguration();
- cr = TestingUtil.extractComponentRegistry(ci);
-
- cf.componentRegistry = cr;
- cf.configuration = configuration;
-
- cr.registerComponent(cr); // register self
- cr.registerComponent(ci);
- cr.registerComponent(spi);
- cr.registerComponent(configuration);
-
- cr.wire();
+ Cache cache = cf.createCache(false);
+ cr = TestingUtil.extractComponentRegistry(cache);
+ configuration = cache.getConfiguration();
}
public void testDefaultFactoryScanning()
@@ -71,6 +54,28 @@
}
+ public void testDependencyConsistency()
+ {
+ for (ComponentRegistry.Component component : cr.componentLookup.values())
+ {
+ // test that this component appears in all dependencies' dependencyFor collection.
+ for (ComponentRegistry.Dependency dep : component.dependencies)
+ {
+ assert cr.componentLookup.get(dep.name).dependencyFor.contains(component.asDependency()) : "Dependency " + dep.name + " does not have component " + component.name + " in it's dependencyFor collection.";
+ }
+ }
+
+ for (ComponentRegistry.Component component : cr.componentLookup.values())
+ {
+ // test that this component appears in all dependencies' dependencyFor collection.
+ for (ComponentRegistry.Dependency dep : component.dependencyFor)
+ {
+ assert cr.componentLookup.get(dep.name).dependencies.contains(component.asDependency()) : "Dependency " + dep.name + " does not have component " + component.name + " in it's dependencies collection.";
+ }
+ }
+ }
+
+
public void testNamedComponents()
{
cr.registerComponent("blah", new Object());
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -46,7 +46,7 @@
* @author manik
*/
@Test(groups = "functional")
-public abstract class AbstractOptimisticTestCase
+public class AbstractOptimisticTestCase
{
// some test data shared among all the test cases
protected Fqn<String> fqn = Fqn.fromString("/blah");
@@ -140,7 +140,6 @@
c.setClusterName("name");
c.setStateRetrievalTimeout(5000);
- c.setClusterConfig(getDefaultProperties());
c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
c.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
@@ -158,7 +157,6 @@
c.setClusterName("name");
c.setStateRetrievalTimeout(5000);
- c.setClusterConfig(getDefaultProperties());
c.setCacheMode(Configuration.CacheMode.LOCAL);
c.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
@@ -170,23 +168,6 @@
return cache;
}
- protected String getDefaultProperties()
- {
- return "UDP(mcast_addr=228.1.2.3;mcast_port=48866;ip_ttl=32;" +
- "mcast_send_buf_size=150000;mcast_recv_buf_size=80000;loopback=true;ip_mcast=true;bind_addr=127.0.0.1):" +
- "PING(timeout=1000;num_initial_members=2):" +
- "MERGE2(min_interval=5000;max_interval=10000):" +
- "FD_SOCK:" +
- "VERIFY_SUSPECT(timeout=1500):" +
- "pbcast.NAKACK(gc_lag=50;max_xmit_size=8192;retransmit_timeout=600,1200,2400,4800):" +
- "UNICAST(timeout=600,1200,2400,4800):" +
- "pbcast.STABLE(desired_avg_gossip=20000):" +
- "FRAG(frag_size=8192;down_thread=false;up_thread=false):" +
- "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;" +
- "shun=false;print_local_addr=true):" +
- "pbcast.STATE_TRANSFER";
- }
-
protected CacheSPI createReplicatedCache(Configuration.CacheMode mode) throws Exception
{
return createReplicatedCache("test", mode);
@@ -204,7 +185,6 @@
c.setClusterName(name);
c.setStateRetrievalTimeout(5000);
- c.setClusterConfig(getDefaultProperties());
c.setCacheMode(mode);
if (mode == Configuration.CacheMode.REPL_SYNC)
{
@@ -245,12 +225,11 @@
Configuration c = cache.getConfiguration();
c.setClusterName(name);
c.setStateRetrievalTimeout(5000);
- c.setClusterConfig(getDefaultProperties());
c.setCacheMode(cacheMode);
c.setSyncCommitPhase(true);
c.setSyncRollbackPhase(true);
c.setNodeLockingScheme("OPTIMISTIC");
- c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
c.setCacheLoaderConfig(getCacheLoaderConfig(shared, false));
cache.create();
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/ConcurrentTransactionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/ConcurrentTransactionTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/ConcurrentTransactionTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -30,7 +30,7 @@
/**
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
-@Test
+@Test(groups = "functional")
public class ConcurrentTransactionTest extends AbstractOptimisticTestCase
{
private CacheSPI<Object, Object> cache;
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -21,6 +21,7 @@
/**
* @author xenephon
*/
+@Test(groups = "functional")
public class FullStackInterceptorTest extends AbstractOptimisticTestCase
{
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/HasChildTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/HasChildTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/HasChildTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -6,6 +6,7 @@
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@@ -16,6 +17,7 @@
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 2.0.0
*/
+@Test(groups = "functional")
public class HasChildTest extends AbstractOptimisticTestCase
{
private CacheSPI<Object, Object> cache;
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/LockParentVersionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/LockParentVersionTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/LockParentVersionTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -1,9 +1,12 @@
package org.jboss.cache.optimistic;
+import org.testng.annotations.Test;
+
/**
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 2.0.0
*/
+@Test(groups = "functional")
public class LockParentVersionTest extends ParentVersionTest
{
public LockParentVersionTest()
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/MockFailureInterceptor.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/MockFailureInterceptor.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/MockFailureInterceptor.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -1,14 +1,14 @@
package org.jboss.cache.optimistic;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.cache.CacheSPI;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.marshall.MethodCall;
+import org.jboss.cache.marshall.MethodDeclarations;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Handles putXXX() methods: if the given node doesn't exist, it will be created
* (depending on the create_if_not_exists argument)
@@ -19,24 +19,19 @@
*/
public class MockFailureInterceptor extends Interceptor
{
- public void setCache(CacheSPI cache)
- {
- super.setCache(cache);
- }
-
private List<Method> allCalled = new ArrayList<Method>();
private List failurelist = new ArrayList();
+ @Override
public Object invoke(InvocationContext ctx) throws Throwable
{
MethodCall m = ctx.getMethodCall();
- if (failurelist.contains(m.getMethod()))
+ if (!MethodDeclarations.isBlockUnblockMethod(m.getMethodId()))
{
- throw new Exception("Failure in method" + m);
+ if (failurelist.contains(m.getMethod())) throw new Exception("Failure in method " + m);
+ allCalled.add(m.getMethod());
}
- allCalled.add(m.getMethod());
-
return null;
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/MockInterceptor.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/MockInterceptor.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/MockInterceptor.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -1,9 +1,9 @@
package org.jboss.cache.optimistic;
-import org.jboss.cache.CacheSPI;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.marshall.MethodCall;
+import org.jboss.cache.marshall.MethodDeclarations;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -19,20 +19,19 @@
*/
public class MockInterceptor extends Interceptor
{
- public void setCache(CacheSPI cache)
- {
- super.setCache(cache);
- }
-
private Method called = null;
private List<Method> calledlist = new ArrayList<Method>();
+ @Override
public synchronized Object invoke(InvocationContext ctx) throws Throwable
{
MethodCall m = ctx.getMethodCall();
- calledlist.add(m.getMethod());
- called = m.getMethod();
+ if (!MethodDeclarations.isBlockUnblockMethod(m.getMethodId()))
+ {
+ calledlist.add(m.getMethod());
+ called = m.getMethod();
+ }
return null;
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeyValTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeyValTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeyValTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -11,6 +11,9 @@
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@@ -18,25 +21,40 @@
/**
* @author xenephon
*/
+@Test(groups = "functional")
public class NodeInterceptorGetKeyValTest extends AbstractOptimisticTestCase
{
- public void testTransactionGetKeyMethod() throws Exception
+ private CacheSPI<Object, Object> cache;
+ private TransactionManager mgr;
+ private TestListener listener;
+ private MockInterceptor dummy;
+
+ @BeforeMethod
+ public void setUp() throws Exception
{
+ listener = new TestListener();
+ cache = createCacheWithListener(listener);
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
+ Interceptor interceptor = TestingUtil.findInterceptor(cache, OptimisticCreateIfNotExistsInterceptor.class);
+ Interceptor nodeInterceptor = TestingUtil.findInterceptor(cache, OptimisticNodeInterceptor.class);
+ dummy = new MockInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
TestingUtil.replaceInterceptorChain(cache, interceptor);
-// first set up a node with a pojo
- TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+ mgr = cache.getTransactionManager();
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testTransactionGetKeyMethod() throws Exception
+ {
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -83,26 +101,10 @@
assertNull(cache.get("/one/two", "key1"));
mgr.commit();
- cache.stop();
}
public void testTransactionGetKeyValOverwriteMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -139,27 +141,10 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
-
- cache.stop();
}
public void testTransactionGetKeyValOverwriteNullMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -195,27 +180,11 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTwoTransactionGetIsolationKeyValMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -287,8 +256,5 @@
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
-
-
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeysTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeysTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeysTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -11,33 +11,50 @@
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
-import java.util.Iterator;
/**
* @author xenephon
*/
+@Test(groups = "functional")
public class NodeInterceptorGetKeysTest extends AbstractOptimisticTestCase
{
- public void testTransactionGetKeysMethod() throws Exception
+ private TestListener listener;
+ private CacheSPI<Object, Object> cache;
+ private TransactionManager mgr;
+ private MockInterceptor dummy;
+
+ @BeforeMethod
+ public void setUp() throws Exception
{
+ listener = new TestListener();
+ cache = createCacheWithListener(listener);
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
+ Interceptor interceptor = TestingUtil.findInterceptor(cache, OptimisticCreateIfNotExistsInterceptor.class);
+ Interceptor nodeInterceptor = TestingUtil.findInterceptor(cache, OptimisticNodeInterceptor.class);
+ dummy = new MockInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
TestingUtil.replaceInterceptorChain(cache, interceptor);
-// first set up a node with a pojo
- TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+ mgr = cache.getTransactionManager();
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testTransactionGetKeysMethod() throws Exception
+ {
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -84,27 +101,12 @@
assertNull(cache.get("/one/two", "key1"));
mgr.commit();
- cache.stop();
}
public void testTransactionGetNoKeysMethod() throws Exception
{
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -129,27 +131,10 @@
assertEquals(0, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
-
-
- cache.stop();
}
public void testTransactionGetKeysIteratorMethod() throws Exception
{
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -171,13 +156,6 @@
//assert we can see this with a key value get in the transaction
assertEquals(1, cache.getNode("/one/two").getKeys().size());
-
- for (Iterator<?> it = cache.getNode("/one/two").getKeys().iterator(); it.hasNext();)
- {
- it.next();
- it.remove();
- }
- assertEquals(0, cache.getNode("/one/two").getKeys().size());
mgr.commit();
@@ -185,8 +163,5 @@
assertEquals(1, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
-
-
- cache.stop();
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorKeyValTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorKeyValTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorKeyValTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -11,6 +11,9 @@
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@@ -18,25 +21,40 @@
/**
* @author xenephon
*/
+@Test(groups = "functional")
public class NodeInterceptorKeyValTest extends AbstractOptimisticTestCase
{
- public void testTransactionPutKeyMethod() throws Exception
+ private CacheSPI<Object, Object> cache;
+ private TestListener listener;
+ private MockInterceptor dummy;
+ private TransactionManager mgr;
+
+ @BeforeMethod
+ public void setUp() throws Exception
{
+ listener = new TestListener();
+ cache = createCacheWithListener(listener);
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
+ Interceptor interceptor = TestingUtil.findInterceptor(cache, OptimisticCreateIfNotExistsInterceptor.class);
+ Interceptor nodeInterceptor = TestingUtil.findInterceptor(cache, OptimisticNodeInterceptor.class);
+ dummy = new MockInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
TestingUtil.replaceInterceptorChain(cache, interceptor);
-// first set up a node with a pojo
- TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+ mgr = cache.getTransactionManager();
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testTransactionPutKeyMethod() throws Exception
+ {
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -68,27 +86,11 @@
assertEquals(1, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionKeyValOverwriteMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -124,26 +126,10 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionKeyValOverwriteNullMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -177,27 +163,11 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionAdditionlaKeyValMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -233,26 +203,10 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTwoTransactionAdditionKeyValMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -319,8 +273,5 @@
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
-
-
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutEraseTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutEraseTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutEraseTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -7,13 +7,16 @@
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
import java.util.HashMap;
import java.util.Map;
@@ -21,25 +24,40 @@
* @author xenephon
*/
@SuppressWarnings("unchecked")
+@Test(groups = "functional")
public class NodeInterceptorPutEraseTest extends AbstractOptimisticTestCase
{
- public void testTransactionPutKeyMethod() throws Exception
+ private CacheSPI<Object, Object> cache;
+ private TransactionManager mgr;
+ private TestListener listener;
+ private MockInterceptor dummy;
+
+ @BeforeMethod
+ public void setUp() throws Exception
{
+ listener = new TestListener();
+ cache = createCacheWithListener(listener);
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
+ Interceptor interceptor = TestingUtil.findInterceptor(cache, OptimisticCreateIfNotExistsInterceptor.class);
+ Interceptor nodeInterceptor = TestingUtil.findInterceptor(cache, OptimisticNodeInterceptor.class);
+ dummy = new MockInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
TestingUtil.replaceInterceptorChain(cache, interceptor);
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
+ mgr = cache.getTransactionManager();
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testTransactionPutKeyMethod() throws Exception
+ {
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -71,26 +89,10 @@
assertEquals(1, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionKeyValOverwriteMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -125,26 +127,10 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionKeyValOverwriteNullMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -177,8 +163,5 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
-
-
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutMapTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutMapTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutMapTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -7,13 +7,16 @@
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
import java.util.HashMap;
import java.util.Map;
@@ -21,25 +24,40 @@
* @author xenephon
*/
@SuppressWarnings("unchecked")
+@Test(groups = "functional")
public class NodeInterceptorPutMapTest extends AbstractOptimisticTestCase
{
- public void testTransactionPutDataMethod() throws Exception
+ private CacheSPI<Object, Object> cache;
+ private TransactionManager mgr;
+ private TestListener listener;
+ private MockInterceptor dummy;
+
+ @BeforeMethod
+ public void setUp() throws Exception
{
+ listener = new TestListener();
+ cache = createCacheWithListener(listener);
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
+ Interceptor interceptor = TestingUtil.findInterceptor(cache, OptimisticCreateIfNotExistsInterceptor.class);
+ Interceptor nodeInterceptor = TestingUtil.findInterceptor(cache, OptimisticNodeInterceptor.class);
+ dummy = new MockInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
TestingUtil.replaceInterceptorChain(cache, interceptor);
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
+ mgr = cache.getTransactionManager();
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testTransactionPutDataMethod() throws Exception
+ {
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -73,26 +91,10 @@
assertEquals(1, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionPutLocalOverwriteDataMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -129,27 +131,12 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionPutLocalEmptyMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
Fqn f = Fqn.fromString("/one/two");
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -165,7 +152,7 @@
Map temp2 = new HashMap();
- cache.put(f, temp2, true);
+ cache.getNode(f).replaceAll(temp2);
assertEquals(null, dummy.getCalled());
TransactionTable table = cache.getTransactionTable();
@@ -182,9 +169,8 @@
assertNotNull(workspace.getNode(f));
assertEquals(null, workspace.getNode(f).get("key1"));
assertTrue(entry.getLocks().isEmpty());
- assertEquals(2, entry.getModifications().size());
+ assertEquals(3, entry.getModifications().size());
assertTrue(!cache.exists(f));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveDataTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveDataTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveDataTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -7,13 +7,16 @@
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
import java.util.HashMap;
import java.util.Map;
@@ -21,25 +24,40 @@
* @author xenephon
*/
@SuppressWarnings("unchecked")
+@Test(groups = "functional")
public class NodeInterceptorRemoveDataTest extends AbstractOptimisticTestCase
{
- public void testTransactionRemoveNoNodeDataMethod() throws Exception
+ private CacheSPI<Object, Object> cache;
+ private TransactionManager mgr;
+ private TestListener listener;
+ private MockInterceptor dummy;
+
+ @BeforeMethod
+ public void setUp() throws Exception
{
+ listener = new TestListener();
+ cache = createCacheWithListener(listener);
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
+ Interceptor interceptor = TestingUtil.findInterceptor(cache, OptimisticCreateIfNotExistsInterceptor.class);
+ Interceptor nodeInterceptor = TestingUtil.findInterceptor(cache, OptimisticNodeInterceptor.class);
+ dummy = new MockInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
TestingUtil.replaceInterceptorChain(cache, interceptor);
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
+ mgr = cache.getTransactionManager();
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testTransactionRemoveNoNodeDataMethod() throws Exception
+ {
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -47,7 +65,7 @@
cache.getInvocationContext().setTransaction(tx);
cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
- cache.getNode("/one/two").clearData();
+ assert null == cache.getNode("/one/two");
assertEquals(null, dummy.getCalled());
TransactionTable table = cache.getTransactionTable();
@@ -65,29 +83,13 @@
assertEquals(0, workspace.getNodes().size());
assertNull(workspace.getNode(Fqn.fromString("/one/two")));
assertTrue(entry.getLocks().isEmpty());
- assertEquals(1, entry.getModifications().size());
+ assertEquals(0, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionRemoveEmptyMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -122,26 +124,10 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionRemoveDataMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -178,27 +164,11 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionRemoveOtherNodeDataMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -211,7 +181,6 @@
temp.put("key1", pojo);
cache.put("/one/two", temp);
-
assertEquals(null, dummy.getCalled());
TransactionTable table = cache.getTransactionTable();
@@ -235,6 +204,5 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveKeyValTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveKeyValTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveKeyValTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -13,13 +13,16 @@
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
import java.util.HashMap;
import java.util.Map;
@@ -27,25 +30,40 @@
* @author xenephon
*/
@SuppressWarnings("unchecked")
+@Test(groups = "functional")
public class NodeInterceptorRemoveKeyValTest extends AbstractOptimisticTestCase
{
- public void testTransactionRemoveNoNodeKeyValMethod() throws Exception
+ private CacheSPI<Object, Object> cache;
+ private TransactionManager mgr;
+ private TestListener listener;
+ private MockInterceptor dummy;
+
+ @BeforeMethod
+ public void setUp() throws Exception
{
+ listener = new TestListener();
+ cache = createCacheWithListener(listener);
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
+ Interceptor interceptor = TestingUtil.findInterceptor(cache, OptimisticCreateIfNotExistsInterceptor.class);
+ Interceptor nodeInterceptor = TestingUtil.findInterceptor(cache, OptimisticNodeInterceptor.class);
+ dummy = new MockInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
TestingUtil.replaceInterceptorChain(cache, interceptor);
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
+ mgr = cache.getTransactionManager();
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testTransactionRemoveNoNodeKeyValMethod() throws Exception
+ {
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -64,7 +82,6 @@
TransactionWorkspace workspace = entry.getTransactionWorkSpace();
-
mgr.commit();
//assert what should be the results of our call
@@ -74,26 +91,10 @@
assertEquals(1, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionRemoveNoKeyValMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -117,7 +118,6 @@
TransactionWorkspace workspace = entry.getTransactionWorkSpace();
-
mgr.commit();
//assert what should be the results of our call
@@ -129,26 +129,10 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
public void testTransactionRemoveKeyValMethod() throws Exception
{
-
- TestListener listener = new TestListener();
- final CacheSPI cache = createCacheWithListener(listener);
-
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
-
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, interceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -172,7 +156,6 @@
TransactionWorkspace workspace = entry.getTransactionWorkSpace();
-
mgr.commit();
//assert what should be the results of our call
@@ -183,6 +166,5 @@
assertEquals(2, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
assertEquals(null, dummy.getCalled());
- cache.stop();
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorTransactionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorTransactionTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorTransactionTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -12,11 +12,13 @@
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.misc.TestingUtil;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.Test;
/**
* @author xenephon
*/
@SuppressWarnings("unchecked")
+@Test(groups = "functional")
public class NodeInterceptorTransactionTest extends AbstractOptimisticTestCase
{
public void testNoTransactionCRUDMethod() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticCreateIfNotExistsInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticCreateIfNotExistsInterceptorTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticCreateIfNotExistsInterceptorTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -18,6 +18,7 @@
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@@ -26,6 +27,7 @@
* @author xenephon
*/
@SuppressWarnings("unchecked")
+@Test(groups = "functional")
public class OptimisticCreateIfNotExistsInterceptorTest extends AbstractOptimisticTestCase
{
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticReplicationInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticReplicationInterceptorTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticReplicationInterceptorTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -51,8 +51,7 @@
@AfterMethod(alwaysRun = true)
public void tearDown()
{
- super.tearDown();
- destroyCache(cache);
+ TestingUtil.killCaches(cache);
}
public void testLocalTransaction() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticVersioningTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticVersioningTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticVersioningTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -14,6 +14,7 @@
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.RollbackException;
import javax.transaction.Transaction;
@@ -25,6 +26,7 @@
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
@SuppressWarnings("unchecked")
+@Test(groups = "functional")
public class OptimisticVersioningTest extends AbstractOptimisticTestCase
{
CacheSPI cache1, cache2;
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithCacheLoaderTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithCacheLoaderTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -10,6 +10,7 @@
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.transaction.DummyTransactionManager;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
@@ -18,6 +19,7 @@
*
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
*/
+@Test(groups = "functional")
public class OptimisticWithCacheLoaderTest extends AbstractOptimisticTestCase
{
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithPassivationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithPassivationTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithPassivationTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -14,6 +14,7 @@
import org.jboss.cache.xml.XmlHelper;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;
+import org.testng.annotations.Test;
import org.w3c.dom.Element;
/**
@@ -21,6 +22,7 @@
*
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
*/
+@Test(groups = "functional")
public class OptimisticWithPassivationTest extends AbstractOptimisticTestCase
{
protected CacheLoaderConfig getCacheLoaderConfig() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedCacheAccessTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedCacheAccessTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedCacheAccessTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -12,6 +12,7 @@
import org.jboss.cache.Fqn;
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
import javax.transaction.TransactionManager;
@@ -20,6 +21,7 @@
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
+@Test(groups = "functional")
public class ThreadedCacheAccessTest extends AbstractOptimisticTestCase
{
private static final Log log = LogFactory.getLog(ThreadedCacheAccessTest.class);
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedOptimisticCreateIfNotExistsInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedOptimisticCreateIfNotExistsInterceptorTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedOptimisticCreateIfNotExistsInterceptorTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -16,6 +16,7 @@
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@@ -23,6 +24,7 @@
/**
* @author xenephon
*/
+@Test(groups = "functional")
public class ThreadedOptimisticCreateIfNotExistsInterceptorTest extends AbstractOptimisticTestCase
{
protected synchronized void setTransactionsInInvocationCtx(TransactionManager mgr, CacheSPI cache) throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/ValidationFailureTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/ValidationFailureTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/ValidationFailureTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -9,6 +9,7 @@
import org.jboss.cache.CacheSPI;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@@ -18,6 +19,7 @@
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
+@Test(groups = "functional")
public class ValidationFailureTest extends AbstractOptimisticTestCase
{
public void testValidationFailureLockRelease() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/ValidatorInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/ValidatorInterceptorTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/ValidatorInterceptorTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -8,8 +8,10 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.InvocationContext;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.interceptors.Interceptor;
+import org.jboss.cache.interceptors.InvocationContextInterceptor;
import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.interceptors.OptimisticValidatorInterceptor;
@@ -18,37 +20,62 @@
import org.jboss.cache.marshall.MethodCallFactory;
import org.jboss.cache.marshall.MethodDeclarations;
import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
+import org.jboss.cache.util.CachePrinter;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* @author xenephon
*/
+@Test(groups = "functional")
public class ValidatorInterceptorTest extends AbstractOptimisticTestCase
{
- public void testTransactionvalidateMethod() throws Exception
+ private CacheSPI<Object, Object> cache;
+ private TransactionManager mgr;
+ private MockInterceptor dummy;
+
+ @BeforeMethod
+ public void setUp() throws Exception
{
- CacheSPI<Object, Object> cache = createCacheWithListener();
+ cache = createCacheWithListener();
+ mgr = cache.getTransactionManager();
- Interceptor validateInterceptor = new OptimisticValidatorInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
+ Interceptor ici = TestingUtil.findInterceptor(cache, InvocationContextInterceptor.class);
+ Interceptor validateInterceptor = TestingUtil.findInterceptor(cache, OptimisticValidatorInterceptor.class);
+ Interceptor interceptor = TestingUtil.findInterceptor(cache, OptimisticCreateIfNotExistsInterceptor.class);
+ Interceptor nodeInterceptor = TestingUtil.findInterceptor(cache, OptimisticNodeInterceptor.class);
+ dummy = new MockInterceptor();
+ ici.setNext(validateInterceptor);
validateInterceptor.setNext(interceptor);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- TestingUtil.replaceInterceptorChain(cache, validateInterceptor);
+ TestingUtil.replaceInterceptorChain(cache, ici);
+ cache.addInterceptor(new ResetRemoteFlagInterceptor(), InvocationContextInterceptor.class);
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
+ System.out.println("Interceptors: " + CachePrinter.printCacheInterceptors(cache));
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+
+ public void testTransactionvalidateMethod() throws Throwable
+ {
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -68,13 +95,8 @@
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
- @SuppressWarnings("unchecked") TransactionWorkspace<Object, Object> workspace = entry.getTransactionWorkSpace();
+ TransactionWorkspace<Object, Object> workspace = entry.getTransactionWorkSpace();
- /*GlobalTransaction.class,
- List.class,
- Address.class,
- boolean.class*/
-
assertEquals(3, workspace.getNodes().size());
assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
@@ -85,15 +107,8 @@
assertEquals(null, dummy.getCalled());
//now let us do a prepare
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE);
- try
- {
- TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
- }
- catch (Throwable t)
- {
- // do nothing
- }
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx, entry.getModifications(), null, gtx.getAddress(), Boolean.FALSE);
+ TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
assertEquals(3, workspace.getNodes().size());
@@ -103,31 +118,14 @@
assertTrue(entry.getLocks().isEmpty());
assertEquals(1, entry.getModifications().size());
assertTrue(!cache.exists("/one/two"));
- assertEquals(null, dummy.getCalled());
+ assertEquals(prepareMethod.getMethod(), dummy.getCalled());
mgr.commit();
-
- destroyCache(cache);
}
public void testTransactionValidateFailureMethod() throws Exception
{
-
- CacheSPI<Object, Object> cache = createCacheWithListener();
-
- Interceptor validateInterceptor = new OptimisticValidatorInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
- validateInterceptor.setNext(interceptor);
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, validateInterceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -147,13 +145,8 @@
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
- @SuppressWarnings("unchecked") TransactionWorkspace<Object, Object> workspace = entry.getTransactionWorkSpace();
+ TransactionWorkspace<Object, Object> workspace = entry.getTransactionWorkSpace();
- /*GlobalTransaction.class,
- List.class,
- Address.class,
- boolean.class*/
-
assertEquals(3, workspace.getNodes().size());
assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
@@ -166,7 +159,7 @@
//lets change one of the underlying version numbers
workspace.getNode(Fqn.fromString("/one/two")).getNode().setVersion(new DefaultDataVersion(2));
//now let us do a prepare
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE);
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx, entry.getModifications(), null, gtx.getAddress(), Boolean.FALSE);
try
{
TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
@@ -179,27 +172,10 @@
mgr.commit();
-
- destroyCache(cache);
}
- public void testTransactionValidateCommitMethod() throws Exception
+ public void testTransactionValidateCommitMethod() throws Throwable
{
-
- CacheSPI<Object, Object> cache = createCacheWithListener();
-
- Interceptor validateInterceptor = new OptimisticValidatorInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
- validateInterceptor.setNext(interceptor);
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, validateInterceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -207,10 +183,8 @@
cache.getInvocationContext().setTransaction(tx);
cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
- SamplePojo pojo = new SamplePojo(21, "test");
- Map<Object, Object> temp = new HashMap<Object, Object>();
- temp.put("key1", pojo);
- cache.put("/one/two", temp);
+ Object pojo = new SamplePojo(21, "test");
+ cache.put("/one/two", Collections.singletonMap((Object) "key1", pojo));
assertEquals(null, dummy.getCalled());
TransactionTable table = cache.getTransactionTable();
@@ -219,13 +193,8 @@
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
- @SuppressWarnings("unchecked") TransactionWorkspace<Object, Object> workspace = entry.getTransactionWorkSpace();
+ TransactionWorkspace<Object, Object> workspace = entry.getTransactionWorkSpace();
- /*GlobalTransaction.class,
- List.class,
- Address.class,
- boolean.class*/
-
assertEquals(3, workspace.getNodes().size());
assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
@@ -237,7 +206,7 @@
//lets change one of the underlying version numbers
//now let us do a prepare
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE);
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx, entry.getModifications(), null, gtx.getAddress(), Boolean.FALSE);
try
{
TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
@@ -249,14 +218,7 @@
}
MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, gtx);
- try
- {
- TestingUtil.getRemoteDelegate(cache)._replicate(commitMethod);
- }
- catch (Throwable t)
- {
- fail();
- }
+ TestingUtil.getRemoteDelegate(cache)._replicate(commitMethod);
assertEquals(3, workspace.getNodes().size());
@@ -267,46 +229,28 @@
assertEquals(1, entry.getModifications().size());
- assertEquals(null, dummy.getCalled());
- NodeSPI<Object, Object> node = workspace.getNode(Fqn.fromString("/")).getNode();
+ assertEquals(commitMethod.getMethod(), dummy.getCalled());
+ NodeSPI<Object, Object> node = workspace.getNode(Fqn.ROOT).getNode();
//assert we can navigate
assertNotNull(node);
node = (NodeSPI<Object, Object>) node.getChild("one");
assertEquals(new DefaultDataVersion(0), node.getVersion());
assertNotNull(node);
- assertTrue(cache.exists(node.getFqn()));
node = (NodeSPI<Object, Object>) node.getChild("two");
assertNotNull(node);
- assertTrue(cache.exists(node.getFqn()));
+
assertEquals(new DefaultDataVersion(1), node.getVersion());
assertEquals(pojo, node.get("key1"));
mgr.commit();
-
- destroyCache(cache);
}
- public void testTransactionValidateFailRemoteCommitMethod() throws Exception
+ public void testTransactionValidateFailRemoteCommitMethod() throws Throwable
{
-
- CacheSPI<Object, Object> cache = createCacheWithListener();
-
- Interceptor validateInterceptor = new OptimisticValidatorInterceptor();
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
- validateInterceptor.setNext(interceptor);
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, validateInterceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -339,7 +283,7 @@
//lets change one of the underlying version numbers
//now let us do a prepare
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE);
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx, entry.getModifications(), null, gtx.getAddress(), Boolean.FALSE);
try
{
TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
@@ -352,14 +296,7 @@
MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, gtx);
- try
- {
- TestingUtil.getRemoteDelegate(cache)._replicate(commitMethod);
- }
- catch (Throwable t)
- {
- fail();
- }
+ TestingUtil.getRemoteDelegate(cache)._replicate(commitMethod);
assertEquals(3, workspace.getNodes().size());
@@ -370,7 +307,7 @@
assertEquals(1, entry.getModifications().size());
- assertEquals(null, dummy.getCalled());
+ assertEquals(commitMethod.getMethod(), dummy.getCalled());
NodeSPI<Object, Object> node = workspace.getNode(Fqn.fromString("/")).getNode();
//assert we can navigate
@@ -388,27 +325,11 @@
assertEquals(pojo, node.get("key1"));
mgr.commit();
-
- destroyCache(cache);
}
- public void testTransactionValidateRollbackMethod() throws Exception
+ public void testTransactionValidateRollbackMethod() throws Throwable
{
- CacheSPI<Object, Object> cache = createCacheWithListener();
- Interceptor validateInterceptor = new OptimisticValidatorInterceptor();
- validateInterceptor.setCache(cache);
- Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- MockInterceptor dummy = new MockInterceptor();
- validateInterceptor.setNext(interceptor);
- interceptor.setNext(nodeInterceptor);
- nodeInterceptor.setNext(dummy);
-
- TestingUtil.replaceInterceptorChain(cache, validateInterceptor);
-
-// first set up a node with a pojo
- DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Transaction tx = mgr.getTransaction();
@@ -428,13 +349,8 @@
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
- @SuppressWarnings("unchecked") TransactionWorkspace<Object, Object> workspace = entry.getTransactionWorkSpace();
+ TransactionWorkspace<Object, Object> workspace = entry.getTransactionWorkSpace();
- /*GlobalTransaction.class,
- List.class,
- Address.class,
- boolean.class*/
-
assertEquals(3, workspace.getNodes().size());
assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
assertEquals(pojo, workspace.getNode(Fqn.fromString("/one/two")).get("key1"));
@@ -446,7 +362,8 @@
//lets change one of the underlying version numbers
//now let us do a prepare
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE);
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx, entry.getModifications(), null, gtx.getAddress(), Boolean.FALSE);
+
try
{
TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
@@ -458,14 +375,7 @@
}
MethodCall rollbackMethod = MethodCallFactory.create(MethodDeclarations.rollbackMethod, gtx);
- try
- {
- TestingUtil.getRemoteDelegate(cache)._replicate(rollbackMethod);
- }
- catch (Throwable t)
- {
- fail();
- }
+ TestingUtil.getRemoteDelegate(cache)._replicate(rollbackMethod);
assertEquals(0, workspace.getNodes().size());
@@ -475,8 +385,16 @@
assertEquals(1, entry.getModifications().size());
mgr.commit();
-
- destroyCache(cache);
}
+ public static class ResetRemoteFlagInterceptor extends Interceptor
+ {
+ @Override
+ public Object invoke(InvocationContext ctx) throws Throwable
+ {
+ log.trace("Setting isRemote on gtx " + ctx.getGlobalTransaction() + " to true");
+ ctx.getGlobalTransaction().setRemote(true);
+ return nextInterceptor(ctx);
+ }
+ }
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/VersioningOnReadTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/VersioningOnReadTest.java 2007-12-27 20:20:04 UTC (rev 4919)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/VersioningOnReadTest.java 2007-12-27 20:40:54 UTC (rev 4920)
@@ -6,6 +6,7 @@
import static org.testng.AssertJUnit.fail;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
@@ -13,6 +14,7 @@
/**
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
*/
+@Test(groups = "functional")
public class VersioningOnReadTest extends AbstractOptimisticTestCase
{
CacheSPI cache;
16 years, 12 months
JBoss Cache SVN: r4919 - core/trunk/src/test/resources/META-INF.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-27 15:20:04 -0500 (Thu, 27 Dec 2007)
New Revision: 4919
Modified:
core/trunk/src/test/resources/META-INF/unit-test-cache-service.xml
Log:
Removed deprecated JGroups element
Modified: core/trunk/src/test/resources/META-INF/unit-test-cache-service.xml
===================================================================
--- core/trunk/src/test/resources/META-INF/unit-test-cache-service.xml 2007-12-27 20:19:38 UTC (rev 4918)
+++ core/trunk/src/test/resources/META-INF/unit-test-cache-service.xml 2007-12-27 20:20:04 UTC (rev 4919)
@@ -213,8 +213,7 @@
<UNICAST timeout="300,600"/>
<pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
max_bytes="400000"/>
- <pbcast.GMS print_local_addr="true" join_timeout="1000"
- join_retry_timeout="500" shun="false"
+ <pbcast.GMS print_local_addr="true" join_timeout="1000" shun="false"
view_bundling="true" view_ack_collection_timeout="1000"/>
<FC max_credits="20000000" min_threshold="0.10"/>
<FRAG2 frag_size="60000"/>
@@ -285,8 +284,7 @@
<UNICAST timeout="300,600,900,1200"/>
<pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
max_bytes="400000"/>
- <pbcast.GMS print_local_addr="true" join_timeout="1000"
- join_retry_timeout="500" shun="false"
+ <pbcast.GMS print_local_addr="true" join_timeout="1000" shun="false"
view_bundling="true" view_ack_collection_timeout="1000"/>
<FRAG2 frag_size="60000"/>
<pbcast.STREAMING_STATE_TRANSFER/>
@@ -354,8 +352,7 @@
<pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
max_bytes="400000"/>
<VIEW_SYNC avg_send_interval="60000"/>
- <pbcast.GMS print_local_addr="true" join_timeout="3000"
- join_retry_timeout="2000" shun="true"
+ <pbcast.GMS print_local_addr="true" join_timeout="3000" shun="true"
view_bundling="true"/>
<FC max_credits="2000000"
min_threshold="0.10"/>
@@ -425,8 +422,7 @@
<pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
max_bytes="400000"/>
<VIEW_SYNC avg_send_interval="60000"/>
- <pbcast.GMS print_local_addr="true" join_timeout="3000"
- join_retry_timeout="2000" shun="true"
+ <pbcast.GMS print_local_addr="true" join_timeout="3000" shun="true"
view_bundling="true"/>
<FC max_credits="2000000"
min_threshold="0.10"/>
16 years, 12 months