JBoss Cache SVN: r4841 - core/trunk/src/main/java/org/jboss/cache.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-11 13:17:24 -0500 (Tue, 11 Dec 2007)
New Revision: 4841
Modified:
core/trunk/src/main/java/org/jboss/cache/AbstractNode.java
core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
Log:
AbstractNode and UnversionedNode no longer implement Node and NodeSPI. Only the delegates do this now.
Modified: core/trunk/src/main/java/org/jboss/cache/AbstractNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/AbstractNode.java 2007-12-11 18:09:55 UTC (rev 4840)
+++ core/trunk/src/main/java/org/jboss/cache/AbstractNode.java 2007-12-11 18:17:24 UTC (rev 4841)
@@ -10,7 +10,7 @@
*
* @author manik
*/
-public abstract class AbstractNode<K, V> implements Node<K, V>
+public abstract class AbstractNode<K, V>// implements Node<K, V>
{
protected boolean deleted;
protected Map<Object, Node<K, V>> children;
@@ -34,7 +34,7 @@
{
synchronized (this)
{
- for (Node<?,?> child : children.values())
+ for (Node<?, ?> child : children.values())
{
((AbstractNode) child).markAsDeleted(marker, true);
}
@@ -54,12 +54,11 @@
}
-
public boolean equals(Object another)
{
if (another instanceof AbstractNode)
{
- AbstractNode<?,?> anotherNode = (AbstractNode) another;
+ AbstractNode<?, ?> anotherNode = (AbstractNode) another;
return fqn == null && anotherNode.fqn == null || !(fqn == null || anotherNode.fqn == null) && fqn.equals(anotherNode.fqn);
}
return false;
Modified: core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/NodeFactory.java 2007-12-11 18:09:55 UTC (rev 4840)
+++ core/trunk/src/main/java/org/jboss/cache/NodeFactory.java 2007-12-11 18:17:24 UTC (rev 4841)
@@ -91,6 +91,8 @@
un.setDataLoaded(false);
NodeInvocationDelegate<K, V> nid = new NodeInvocationDelegate(un);
componentRegistry.wireDependencies(nid);
+ // back ref
+ un.setDelegate(nid);
return nid;
}
@@ -103,9 +105,10 @@
{
if (template instanceof WorkspaceNode)
{
- NodeSPI<K, V> dataNodeParent = ((WorkspaceNode<K, V>) parent).getNode();
- TransactionWorkspace workspace = ((WorkspaceNode) template).getTransactionWorkspace();
- return createWorkspaceNode(dataNodeParent, workspace);
+// NodeSPI<K, V> dataNodeParent = ((WorkspaceNode<K, V>) parent).getNode();
+// TransactionWorkspace workspace = ((WorkspaceNode) template).getTransactionWorkspace();
+// return createWorkspaceNode(dataNodeParent, workspace);
+ throw new RuntimeException("DEPRECATED! Use createWorkspaceNode() to create workspace nodes!");
}
// not a workspace node.
Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2007-12-11 18:09:55 UTC (rev 4840)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2007-12-11 18:17:24 UTC (rev 4841)
@@ -29,7 +29,7 @@
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 2.0.0
*/
-public class UnversionedNode<K, V> extends AbstractNode<K, V> implements NodeSPI<K, V>
+public class UnversionedNode<K, V> extends AbstractNode<K, V>// implements NodeSPI<K, V>
{
/**
@@ -76,6 +76,8 @@
*/
private boolean valid = true;
+ private NodeSPI delegate;
+
/**
* Constructs a new node with an FQN of Root.
*/
@@ -97,6 +99,16 @@
setInternalState(data);
}
+ public NodeSPI getDelegate()
+ {
+ return delegate;
+ }
+
+ public void setDelegate(NodeSPI delegate)
+ {
+ this.delegate = delegate;
+ }
+
/**
* Initializes with a name and FQN and cache.
*/
@@ -131,7 +143,7 @@
{
if (lock_ == null)
{
- lock_ = new IdentityLock(cache.getConfiguration().getIsolationLevel(), this);
+ lock_ = new IdentityLock(cache.getConfiguration().getIsolationLevel(), delegate);
}
}
@@ -248,7 +260,7 @@
// construct the new child outside the synchronized block to avoid
// spending any more time than necessary in the synchronized section
Fqn child_fqn = new Fqn(this.fqn, child_name);
- NodeSPI<K, V> newChild = (NodeSPI<K, V>) cache.getConfiguration().getRuntimeConfig().getNodeFactory().createNode(child_name, this, null);
+ NodeSPI<K, V> newChild = (NodeSPI<K, V>) cache.getConfiguration().getRuntimeConfig().getNodeFactory().createNode(child_name, delegate, null);
if (newChild == null)
{
throw new IllegalStateException();
@@ -416,7 +428,7 @@
}
else
{
- NodeSPI currentNode = this;
+ NodeSPI currentNode = delegate;
for (int i = 0; i < fqn.size(); i++)
{
Object nextChildName = fqn.get(i);
17 years, 3 months
JBoss Cache SVN: r4840 - in core/trunk/src/main/java/org/jboss/cache: interceptors and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-11 13:09:55 -0500 (Tue, 11 Dec 2007)
New Revision: 4840
Modified:
core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
Log:
Migrated to new arch
Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2007-12-11 17:44:44 UTC (rev 4839)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2007-12-11 18:09:55 UTC (rev 4840)
@@ -800,7 +800,7 @@
{
for (Node child : children().values())
{
- ((UnversionedNode) child).setValid(valid, recursive);
+ ((NodeSPI) child).setValid(valid, recursive);
}
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2007-12-11 17:44:44 UTC (rev 4839)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/BaseRpcInterceptor.java 2007-12-11 18:09:55 UTC (rev 4840)
@@ -36,7 +36,7 @@
super.setCache(cache);
buddyManager = cache.getBuddyManager();
usingBuddyReplication = buddyManager != null;
- CacheMode mode = cache.getConfiguration().getCacheMode();
+ CacheMode mode = configuration.getCacheMode();
defaultSynchronous = (mode == CacheMode.REPL_SYNC || mode == CacheMode.INVALIDATION_SYNC);
}
@@ -101,11 +101,11 @@
if (syncReplTimeout < 0) syncReplTimeout = configuration.getSyncReplTimeout();
List rsps = cache.getRPCManager().callRemoteMethods(callRecipients,
- MethodDeclarations.replicateMethod,
- new Object[]{call},
- sync, // is synchronised?
- true, // ignore self?
- syncReplTimeout);
+ MethodDeclarations.replicateMethod,
+ new Object[]{call},
+ sync, // is synchronised?
+ true, // ignore self?
+ syncReplTimeout);
if (log.isTraceEnabled())
{
log.trace("responses=" + rsps);
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2007-12-11 17:44:44 UTC (rev 4839)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/EvictionInterceptor.java 2007-12-11 18:09:55 UTC (rev 4840)
@@ -9,9 +9,14 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.*;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.Region;
+import org.jboss.cache.RegionManager;
import org.jboss.cache.eviction.EvictedEventNode;
import org.jboss.cache.eviction.NodeEventType;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.transaction.GlobalTransaction;
@@ -37,17 +42,12 @@
* <p/>
* Not to be attempted to be used anywhere else.
*/
+ @Inject
void setRegionManager(RegionManager regionManager)
{
this.regionManager = regionManager;
}
- public void setCache(CacheSPI cache)
- {
- super.setCache(cache);
- this.regionManager = cache.getRegionManager();
- }
-
protected Log getLog()
{
return log;
@@ -85,7 +85,7 @@
Object retVal = nextInterceptor(ctx);
if (fqn != null && key != null && !canIgnoreEvent(fqn, NodeEventType.ADD_ELEMENT_EVENT))
{
- registerEvictionEventToRegionManager( new EvictedEventNode(fqn, NodeEventType.ADD_ELEMENT_EVENT, 1));
+ registerEvictionEventToRegionManager(new EvictedEventNode(fqn, NodeEventType.ADD_ELEMENT_EVENT, 1));
}
return retVal;
}
@@ -173,7 +173,8 @@
{
log.trace("No event added. Node does not exist");
}
- } else
+ }
+ else
{
if (fqn != null && !canIgnoreEvent(fqn, NodeEventType.VISIT_NODE_EVENT))
{
@@ -228,7 +229,7 @@
return;
}
- NodeSPI<?,?> nodeSPI = cache.peek(event.getFqn(), false);
+ NodeSPI<?, ?> nodeSPI = cache.peek(event.getFqn(), false);
//we do not trigger eviction events for resident nodes
if (nodeSPI != null && nodeSPI.isResident())
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-12-11 17:44:44 UTC (rev 4839)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-12-11 18:09:55 UTC (rev 4840)
@@ -51,8 +51,8 @@
*/
public class PessimisticLockInterceptor extends MethodDispacherInterceptor
{
- private TransactionTable tx_table = null;
-
+ private TransactionTable tx_table;
+ private CacheImpl cacheImpl;
/**
* Map<Thread, List<NodeLock>>. Keys = threads, values = lists of locks held by that thread
*/
@@ -60,10 +60,11 @@
private long lock_acquisition_timeout;
@Inject
- public void injectDependencies(@ComponentName("LockTable")Map<Thread, List<NodeLock>> lockTable, Configuration configuration)
+ public void injectDependencies(@ComponentName("LockTable")Map<Thread, List<NodeLock>> lockTable, Configuration configuration, CacheImpl cacheImpl)
{
this.lock_table = lockTable;
lock_acquisition_timeout = configuration.getLockAcquisitionTimeout();
+ this.cacheImpl = cacheImpl;
}
public void setCache(CacheSPI cache)
@@ -232,7 +233,7 @@
Object retVal = nextInterceptor(ctx);
if (ctx.getGlobalTransaction() == null)
{
- ((CacheImpl) cache).realRemove(fqn, true);
+ cacheImpl.realRemove(fqn, true);
NodeSPI n = cache.peek(fqn, true);
if (n != null)
{
17 years, 3 months
JBoss Cache SVN: r4839 - in core/tags/1.4.1.SP8: docs and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-11 12:44:44 -0500 (Tue, 11 Dec 2007)
New Revision: 4839
Modified:
core/tags/1.4.1.SP8/build.xml
core/tags/1.4.1.SP8/docs/Changelog.txt
core/tags/1.4.1.SP8/src/org/jboss/cache/Version.java
Log:
Releasing SP8
Modified: core/tags/1.4.1.SP8/build.xml
===================================================================
--- core/tags/1.4.1.SP8/build.xml 2007-12-11 17:43:24 UTC (rev 4838)
+++ core/tags/1.4.1.SP8/build.xml 2007-12-11 17:44:44 UTC (rev 4839)
@@ -6,7 +6,7 @@
<property name="module.name" value="JBossCache"/>
<!--We now requires version to have no white space since Ant+JBossAop will sometime choke. -->
- <property name="module.version" value="1.4.1.SP7"/>
+ <property name="module.version" value="1.4.1.SP8"/>
<property name="implementation.url" value="http://www.jboss.com/products/jbosscache"/>
<property file="build.properties"/>
<property name="root.dir" value="${basedir}"/>
Modified: core/tags/1.4.1.SP8/docs/Changelog.txt
===================================================================
--- core/tags/1.4.1.SP8/docs/Changelog.txt 2007-12-11 17:43:24 UTC (rev 4838)
+++ core/tags/1.4.1.SP8/docs/Changelog.txt 2007-12-11 17:44:44 UTC (rev 4839)
@@ -1,16 +1,24 @@
$Id$
-Release 1.4.1.SP6 (November 21, 2007)
+Release 1.4.1.SP8 (December 12, 2007)
=====================================
Patch release on 1.4.1.GA
** Bug
+ * [ JBCACHE-1225 ] TreeCache._enqueueMethodCall doesn't handle buddy backup FQNs
+ * [ JBCACHE-1228 ] Optimistic lock interceptor always acquires write locks for nodes in workspace at commit time
+ * [ JBCACHE-1234 ] Region activation requests partial state transfer from wrong nodes
+
+Release 1.4.1.SP7 (November 21, 2007)
+=====================================
+Patch release on 1.4.1.GA
+
+** Bug
* [ JBCACHE-1165 ] Endless loop in PessimisticLockInterceptor, sometimes seen as a NodeNotExistsException (when using READ_COMMITTED)
* [ JBCACHE-1166 ] UpgradeException on concurrent put/remove operation
* [ JBCACHE-1217 ] Exceptions in BuddyReplication group organisation methods not propagated to caller
* [ JBCACHE-1220 ] DataGravitatorInterceptor logs ERROR when alone in cluster
-
Release 1.4.1.SP6 (October 31, 2007)
====================================
Patch release on 1.4.1.GA
Modified: core/tags/1.4.1.SP8/src/org/jboss/cache/Version.java
===================================================================
--- core/tags/1.4.1.SP8/src/org/jboss/cache/Version.java 2007-12-11 17:43:24 UTC (rev 4838)
+++ core/tags/1.4.1.SP8/src/org/jboss/cache/Version.java 2007-12-11 17:44:44 UTC (rev 4839)
@@ -10,9 +10,9 @@
*/
public class Version
{
- public static final String version = "1.4.1.SP7";
+ public static final String version = "1.4.1.SP8";
public static final String codename = "Cayenne";
- public static byte[] version_id = {'0', '1', '4', '1', 'S', 'P', '7'};
+ public static byte[] version_id = {'0', '1', '4', '1', 'S', 'P', '8'};
public static final String cvs = "$Id$";
private static final int MAJOR_SHIFT = 11;
17 years, 3 months
JBoss Cache SVN: r4838 - in core/branches/1.4.X: docs and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-11 12:43:24 -0500 (Tue, 11 Dec 2007)
New Revision: 4838
Modified:
core/branches/1.4.X/build.xml
core/branches/1.4.X/docs/Changelog.txt
core/branches/1.4.X/etc/log4j.xml
core/branches/1.4.X/src/org/jboss/cache/Version.java
Log:
Releasing SP8
Modified: core/branches/1.4.X/build.xml
===================================================================
--- core/branches/1.4.X/build.xml 2007-12-11 17:36:33 UTC (rev 4837)
+++ core/branches/1.4.X/build.xml 2007-12-11 17:43:24 UTC (rev 4838)
@@ -6,7 +6,7 @@
<property name="module.name" value="JBossCache"/>
<!--We now requires version to have no white space since Ant+JBossAop will sometime choke. -->
- <property name="module.version" value="1.4.1.SP7"/>
+ <property name="module.version" value="1.4.1.SP8"/>
<property name="implementation.url" value="http://www.jboss.com/products/jbosscache"/>
<property file="build.properties"/>
<property name="root.dir" value="${basedir}"/>
Modified: core/branches/1.4.X/docs/Changelog.txt
===================================================================
--- core/branches/1.4.X/docs/Changelog.txt 2007-12-11 17:36:33 UTC (rev 4837)
+++ core/branches/1.4.X/docs/Changelog.txt 2007-12-11 17:43:24 UTC (rev 4838)
@@ -1,16 +1,24 @@
$Id$
-Release 1.4.1.SP6 (November 21, 2007)
+Release 1.4.1.SP8 (December 12, 2007)
=====================================
Patch release on 1.4.1.GA
** Bug
+ * [ JBCACHE-1225 ] TreeCache._enqueueMethodCall doesn't handle buddy backup FQNs
+ * [ JBCACHE-1228 ] Optimistic lock interceptor always acquires write locks for nodes in workspace at commit time
+ * [ JBCACHE-1234 ] Region activation requests partial state transfer from wrong nodes
+
+Release 1.4.1.SP7 (November 21, 2007)
+=====================================
+Patch release on 1.4.1.GA
+
+** Bug
* [ JBCACHE-1165 ] Endless loop in PessimisticLockInterceptor, sometimes seen as a NodeNotExistsException (when using READ_COMMITTED)
* [ JBCACHE-1166 ] UpgradeException on concurrent put/remove operation
* [ JBCACHE-1217 ] Exceptions in BuddyReplication group organisation methods not propagated to caller
* [ JBCACHE-1220 ] DataGravitatorInterceptor logs ERROR when alone in cluster
-
Release 1.4.1.SP6 (October 31, 2007)
====================================
Patch release on 1.4.1.GA
Modified: core/branches/1.4.X/etc/log4j.xml
===================================================================
--- core/branches/1.4.X/etc/log4j.xml 2007-12-11 17:36:33 UTC (rev 4837)
+++ core/branches/1.4.X/etc/log4j.xml 2007-12-11 17:43:24 UTC (rev 4838)
@@ -79,7 +79,7 @@
-->
<category name="org.jboss.cache">
- <priority value="ERROR"/>
+ <priority value="TRACE"/>
</category>
<category name="org.jboss">
Modified: core/branches/1.4.X/src/org/jboss/cache/Version.java
===================================================================
--- core/branches/1.4.X/src/org/jboss/cache/Version.java 2007-12-11 17:36:33 UTC (rev 4837)
+++ core/branches/1.4.X/src/org/jboss/cache/Version.java 2007-12-11 17:43:24 UTC (rev 4838)
@@ -10,9 +10,9 @@
*/
public class Version
{
- public static final String version = "1.4.1.SP7";
+ public static final String version = "1.4.1.SP8";
public static final String codename = "Cayenne";
- public static byte[] version_id = {'0', '1', '4', '1', 'S', 'P', '7'};
+ public static byte[] version_id = {'0', '1', '4', '1', 'S', 'P', '8'};
public static final String cvs = "$Id$";
private static final int MAJOR_SHIFT = 11;
17 years, 3 months
JBoss Cache SVN: r4837 - core/tags.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-11 12:36:33 -0500 (Tue, 11 Dec 2007)
New Revision: 4837
Added:
core/tags/1.4.1.SP8/
Log:
Tagging 1.4.1.SP8
Copied: core/tags/1.4.1.SP8 (from rev 4836, core/branches/1.4.X)
17 years, 3 months
JBoss Cache SVN: r4836 - in core/trunk/src/test/java/org/jboss/cache: api and 24 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-11 12:34:04 -0500 (Tue, 11 Dec 2007)
New Revision: 4836
Added:
core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java
core/trunk/src/test/java/org/jboss/cache/factories/annotations/
core/trunk/src/test/java/org/jboss/cache/factories/annotations/ClasspathScannerTest.java
Modified:
core/trunk/src/test/java/org/jboss/cache/CacheFactoryTest.java
core/trunk/src/test/java/org/jboss/cache/CallbackTest.java
core/trunk/src/test/java/org/jboss/cache/FqnTest.java
core/trunk/src/test/java/org/jboss/cache/GetKeysTest.java
core/trunk/src/test/java/org/jboss/cache/LifeCycleTest.java
core/trunk/src/test/java/org/jboss/cache/TreeCacheFunctionalTest.java
core/trunk/src/test/java/org/jboss/cache/TreeNodeTest.java
core/trunk/src/test/java/org/jboss/cache/api/CacheAPITest.java
core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java
core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java
core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyBackupActivationInactivationTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyPoolBroadcastTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationFailoverTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/config/ChannelInjectionTest.java
core/trunk/src/test/java/org/jboss/cache/demo/JBossCacheGUI.java
core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizePolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/EvictionConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/FIFOPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LFUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/MRUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/eviction/ReplicatedLRUPolicyTest.java
core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java
core/trunk/src/test/java/org/jboss/cache/interceptors/EvictionInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/interceptors/InterceptorCacheReferenceTest.java
core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/invalidation/TombstoneEvictionTest.java
core/trunk/src/test/java/org/jboss/cache/invalidation/VersionInconsistencyTest.java
core/trunk/src/test/java/org/jboss/cache/jmx/NotificationTest.java
core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java
core/trunk/src/test/java/org/jboss/cache/loader/AsyncFileCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/loader/BdbjeTest.java
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderManagerTest.java
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderPurgingTest.java
core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java
core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderFullTest.java
core/trunk/src/test/java/org/jboss/cache/loader/ClusteredCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/loader/InterceptorSynchronizationTest.java
core/trunk/src/test/java/org/jboss/cache/loader/JDBCCacheLoaderDerbyDSTest.java
core/trunk/src/test/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/loader/SharedCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/loader/SingletonStoreCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheServerTest.java
core/trunk/src/test/java/org/jboss/cache/loader/TxCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java
core/trunk/src/test/java/org/jboss/cache/loader/deadlock/ConcurrentCreationDeadlockTest.java
core/trunk/src/test/java/org/jboss/cache/lock/AcquireAllTest.java
core/trunk/src/test/java/org/jboss/cache/lock/BreakDeadMemberLocksTest.java
core/trunk/src/test/java/org/jboss/cache/lock/LockReleaseTest.java
core/trunk/src/test/java/org/jboss/cache/lock/ReentrantWriterPreference2Readers1WriterLockTest.java
core/trunk/src/test/java/org/jboss/cache/lock/ReentrantWriterPreferenceReadWriteLockTest.java
core/trunk/src/test/java/org/jboss/cache/lock/UpgradeLockTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/AsyncReplTest.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/CustomCollectionTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/MethodCallFactoryTest.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/RemoteCallerReturnValuesTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/ReplicateToInactiveRegionTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/SelectedClassnameClassLoader.java
core/trunk/src/test/java/org/jboss/cache/marshall/SyncReplTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/data/Address.java
core/trunk/src/test/java/org/jboss/cache/marshall/data/Person.java
core/trunk/src/test/java/org/jboss/cache/mgmt/InvalidationTest.java
core/trunk/src/test/java/org/jboss/cache/mgmt/MgmtCoreTest.java
core/trunk/src/test/java/org/jboss/cache/mgmt/TxTest.java
core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
core/trunk/src/test/java/org/jboss/cache/multiplexer/MultiplexerTestHelper.java
core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java
core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncCacheTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncFullStackInterceptorTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/CacheTest.java
core/trunk/src/test/java/org/jboss/cache/optimistic/ComparatorTest.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/MockInterceptor.java
core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetChildrenNamesTest.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/NodeInterceptorRemoveNodeTest.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/RemoveBeforeCreateTest.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/TxInterceptorTest.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
core/trunk/src/test/java/org/jboss/cache/options/CacheModeLocalSimpleTest.java
core/trunk/src/test/java/org/jboss/cache/options/ExplicitVersionsReplTest.java
core/trunk/src/test/java/org/jboss/cache/options/ExplicitVersionsTest.java
core/trunk/src/test/java/org/jboss/cache/options/FailSilentlyTest.java
core/trunk/src/test/java/org/jboss/cache/options/ForceCacheModeTest.java
core/trunk/src/test/java/org/jboss/cache/options/ForceWriteLockTest.java
core/trunk/src/test/java/org/jboss/cache/options/LockAcquisitionTimeoutTest.java
core/trunk/src/test/java/org/jboss/cache/options/SuppressLockingTest.java
core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java
core/trunk/src/test/java/org/jboss/cache/passivation/BasicPassivationTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/ConcurrentPassivationTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/LocalPassivationIntegrationTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToJDBCCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java
core/trunk/src/test/java/org/jboss/cache/replicated/AsyncReplTest.java
core/trunk/src/test/java/org/jboss/cache/replicated/ReplicationExceptionTest.java
core/trunk/src/test/java/org/jboss/cache/replicated/SyncCacheListenerTest.java
core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTxTest.java
core/trunk/src/test/java/org/jboss/cache/statetransfer/CorruptedFileCacheLoader.java
core/trunk/src/test/java/org/jboss/cache/statetransfer/FailedStateTransferTest.java
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransfer200Test.java
core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/AbortionTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/AsyncRollbackTxTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/ConcurrentBankTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/ConcurrentTransactionalTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/DeadlockTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/InvocationContextCleanupTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelNoneTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelReadCommittedNodeCreationRollbackTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelReadCommittedTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelRepeatableReadTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelSerializableTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/PrepareTxTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/ReplicatedTransactionDeadlockTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/SuspendTxTest.java
core/trunk/src/test/java/org/jboss/cache/transaction/TransactionTest.java
Log:
Updated tests to deal with new API
Modified: core/trunk/src/test/java/org/jboss/cache/CacheFactoryTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/CacheFactoryTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/CacheFactoryTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -9,7 +9,9 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.lock.IsolationLevel;
-import static org.testng.AssertJUnit.*;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -19,12 +21,12 @@
/**
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
-@Test (groups = {"functional"})
+@Test(groups = {"functional"})
public class CacheFactoryTest
{
Configuration expected;
String configFile = "META-INF/replSync-service.xml";
- private CacheImpl cache;
+ private CacheSPI cache;
@BeforeMethod(alwaysRun = true)
public void setUp()
@@ -44,39 +46,38 @@
public void testFromConfigFileStarted()
{
- cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(configFile);
+ cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(configFile);
// can't test for this anymore since the RuntimeConfig is attached to the running cache
//assertEquals(expected, cache.getConfiguration());
-
- assertTrue("Should have started", cache.isStarted());
+ assert cache.getCacheStatus() == CacheStatus.STARTED : "Should have started";
doSimpleConfTests(cache.getConfiguration());
}
public void testFromConfigFileUnstarted()
{
- cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(configFile, false);
+ cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(configFile, false);
// can't test for this anymore since the RuntimeConfig is attached to the running cache
// assertEquals(expected, cache.getConfiguration());
- assertFalse("Should not have started", cache.isStarted());
+ assert cache.getCacheStatus() != CacheStatus.STARTED : "Should not have started";
doSimpleConfTests(cache.getConfiguration());
}
public void testFromConfigObjStarted()
{
- cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(expected);
+ cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(expected);
- assertTrue("Should have started", cache.isStarted());
+ assert cache.getCacheStatus() == CacheStatus.STARTED : "Should have started";
doSimpleConfTests(cache.getConfiguration());
}
public void testFromConfigObjUnstarted()
{
- cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(expected, false);
+ cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(expected, false);
- assertFalse("Should not have started", cache.isStarted());
+ assert cache.getCacheStatus() != CacheStatus.STARTED : "Should not have started";
doSimpleConfTests(cache.getConfiguration());
}
@@ -93,29 +94,45 @@
public void testLifecycle() throws Exception
{
- cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(expected, false);
- assertFalse(cache.isStarted());
+ cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(expected, false);
+ assert cache.getCacheStatus() != CacheStatus.STARTED : "Should not have started";
cache.start();
- assertTrue(cache.isStarted());
+ assert cache.getCacheStatus() == CacheStatus.STARTED : "Should have started";
cache.stop();
- assertFalse(cache.isStarted());
+ assert cache.getCacheStatus() != CacheStatus.STARTED : "Should not have started";
}
public void testCreationFromStreamStarted() throws Exception
{
InputStream is = getClass().getClassLoader().getResourceAsStream(configFile);
CacheFactory cf = DefaultCacheFactory.getInstance();
- cache = (CacheImpl) cf.createCache(is);
- assertTrue("Should have started", cache.isStarted());
+ cache = (CacheSPI) cf.createCache(is);
+ assert cache.getCacheStatus() == CacheStatus.STARTED : "Should have started";
doSimpleConfTests(cache.getConfiguration());
}
-
+
public void testCreationFromStream() throws Exception
{
InputStream is = getClass().getClassLoader().getResourceAsStream(configFile);
CacheFactory cf = DefaultCacheFactory.getInstance();
- cache = (CacheImpl) cf.createCache(is, false);
- assertFalse("Should not have started", cache.isStarted());
+ cache = (CacheSPI) cf.createCache(is, false);
+ assert cache.getCacheStatus() != CacheStatus.STARTED : "Should not have started";
doSimpleConfTests(cache.getConfiguration());
}
+
+ public void testComponentsInjected() throws Exception
+ {
+ CacheFactory cf = DefaultCacheFactory.getInstance();
+ Configuration c = new Configuration();
+ c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ cache = (CacheSPI) cf.createCache(c);
+
+ assert TestingUtil.extractField(cache, "regionManager") != null;
+ assert TestingUtil.extractField(cache, "notifier") != null;
+ assert TestingUtil.extractField(cache, "marshaller") != null;
+ assert TestingUtil.extractField(cache, "transactionManager") != null;
+ assert TestingUtil.extractField(cache, "transactionTable") != null;
+ assert TestingUtil.extractField(cache, "stateTransferManager") != null;
+ }
}
Modified: core/trunk/src/test/java/org/jboss/cache/CallbackTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/CallbackTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/CallbackTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,22 +1,17 @@
package org.jboss.cache;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import javax.transaction.NotSupportedException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.notifications.annotation.CacheListener;
import org.jboss.cache.notifications.annotation.NodeCreated;
import org.jboss.cache.notifications.event.Event;
+import org.jboss.cache.util.CachePrinter;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
+
+import javax.transaction.TransactionManager;
+
/**
* Tests whether modifications within callbacks (TreeCacheListener) are handled correctly
*
@@ -25,7 +20,7 @@
*/
public class CallbackTest
{
- CacheImpl<Object, Object> cache = null, cache2;
+ CacheSPI<Object, Object> cache = null, cache2;
final Fqn<String> FQN_A = Fqn.fromString("/a");
final Fqn<String> FQN_B = Fqn.fromString("/b");
static final String KEY = "key";
@@ -43,7 +38,7 @@
}
@Test(groups = {"functional"})
- public void testLocalPutCallbackWithoutTransaction() throws Exception, NotSupportedException
+ public void testLocalPutCallbackWithoutTransaction() throws Exception
{
cache = createCache(Configuration.CacheMode.LOCAL, IsolationLevel.SERIALIZABLE);
cache.addCacheListener(new PutListener(cache));
@@ -52,12 +47,12 @@
assertTrue(cache.exists(FQN_A));
assertTrue(cache.exists(FQN_B));//created by callback
assertEquals(cache.getLockTable().size(), 0);
- System.out.println("cache locks:\n" + cache.printLockInfo());
+ System.out.println("cache locks:\n" + CachePrinter.printCacheLockingInfo(cache));
assertEquals(0, cache.getNumberOfLocksHeld());
}
@Test(groups = {"functional"})
- public void testLocalGetCallbackSameFqnWithoutTransaction() throws Exception, NotSupportedException
+ public void testLocalGetCallbackSameFqnWithoutTransaction() throws Exception
{
cache = createCache(Configuration.CacheMode.LOCAL, IsolationLevel.SERIALIZABLE);
cache.getNotifier().addCacheListener(new GetListener(cache, FQN_A));
@@ -65,12 +60,12 @@
cache.put(FQN_A, null);
assertTrue(cache.exists(FQN_A));
assertEquals(cache.getLockTable().size(), 0);
- System.out.println("cache locks:\n" + cache.printLockInfo());
+ System.out.println("cache locks:\n" + CachePrinter.printCacheLockingInfo(cache));
assertEquals(0, cache.getNumberOfLocksHeld());
}
@Test(groups = {"functional"})
- public void testLocalGetCallbackDifferentFqnWithoutTransaction() throws Exception, NotSupportedException
+ public void testLocalGetCallbackDifferentFqnWithoutTransaction() throws Exception
{
cache = createCache(Configuration.CacheMode.LOCAL, IsolationLevel.SERIALIZABLE);
cache.put(FQN_B, null);
@@ -80,12 +75,12 @@
assertTrue(cache.exists(FQN_A));
assertTrue(cache.exists(FQN_B));
assertEquals(cache.getLockTable().size(), 0);
- System.out.println("cache locks:\n" + cache.printLockInfo());
+ System.out.println("cache locks:\n" + CachePrinter.printCacheLockingInfo(cache));
assertEquals(0, cache.getNumberOfLocksHeld());
}
@Test(groups = {"functional"})
- public void testLocalCallbackWithTransaction() throws Exception, NotSupportedException
+ public void testLocalCallbackWithTransaction() throws Exception
{
cache = createCache(Configuration.CacheMode.LOCAL, IsolationLevel.SERIALIZABLE);
cache.getNotifier().addCacheListener(new PutListener(cache));
@@ -98,7 +93,7 @@
}
@Test(groups = {"functional"})
- public void testLocalCallbackWithException() throws Exception, NotSupportedException
+ public void testLocalCallbackWithException() throws Exception
{
cache = createCache(Configuration.CacheMode.LOCAL, IsolationLevel.SERIALIZABLE);
cache.getNotifier().addCacheListener(new ExceptionListener());
@@ -116,13 +111,13 @@
assertEquals(0, cache.getNumberOfLocksHeld());
}
- private CacheImpl<Object, Object> createCache(Configuration.CacheMode mode, IsolationLevel level) throws Exception
+ private CacheSPI<Object, Object> createCache(Configuration.CacheMode mode, IsolationLevel level)
{
Configuration c = new Configuration();
c.setCacheMode(mode);
c.setIsolationLevel(level);
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- return (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(c);
+ return (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(c);
}
private TransactionManager startTransaction()
@@ -153,10 +148,10 @@
@CacheListener
public class GetListener
{
- CacheImpl<Object, Object> c;
+ CacheSPI<Object, Object> c;
Fqn<?> my_fqn;
- public GetListener(CacheImpl<Object, Object> c, Fqn<?> my_fqn)
+ public GetListener(CacheSPI<Object, Object> c, Fqn<?> my_fqn)
{
this.c = c;
this.my_fqn = my_fqn;
@@ -169,7 +164,7 @@
{
try
{
- Node<?,?> n = c.get(this.my_fqn);
+ Node<?, ?> n = c.getNode(this.my_fqn);
assertNotNull(n);
}
catch (CacheException ex)
@@ -184,9 +179,9 @@
@CacheListener
public class PutListener
{
- CacheImpl<Object, Object> c;
+ CacheSPI<Object, Object> c;
- public PutListener(CacheImpl<Object, Object> c)
+ public PutListener(CacheSPI<Object, Object> c)
{
this.c = c;
}
Modified: core/trunk/src/test/java/org/jboss/cache/FqnTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/FqnTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/FqnTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -7,14 +7,14 @@
package org.jboss.cache;
-import java.util.HashMap;
-
import org.jboss.cache.config.Configuration;
import org.jgroups.util.Util;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
+import java.util.HashMap;
+
/**
* Tests {@link Fqn}.
*
@@ -174,7 +174,7 @@
public void testEquals3()
{
Fqn<Object> f1;
- Fqn<? extends Object> f2;
+ Fqn<?> f2;
f1 = new Fqn<Object>("a", 322649, Boolean.TRUE);
f2 = new Fqn<String>();
assert !f1.equals(f2);
@@ -364,7 +364,7 @@
}
@SuppressWarnings("unchecked")
- <T> Fqn<T> marshalAndUnmarshal(Fqn<T> fqn) throws Exception
+ <T> Fqn<T> marshalAndUnmarshal(Fqn<T> fqn) throws Exception
{
byte[] buf = Util.objectToByteBuffer(fqn);
return (Fqn<T>) Util.objectFromByteBuffer(buf);
Modified: core/trunk/src/test/java/org/jboss/cache/GetKeysTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/GetKeysTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/GetKeysTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -7,30 +7,29 @@
package org.jboss.cache;
import static org.testng.AssertJUnit.*;
+import org.testng.annotations.Test;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.util.Set;
-import org.testng.annotations.Test;
-
/**
* @author <a href="mailto:bela@jboss.org">Bela Ban</a>
* @version $Id$
*/
public class GetKeysTest
{
- CacheImpl<Object, Object> cache;
+ CacheSPI<Object, Object> cache;
@Test(groups = {"functional"})
public void testGetKeys() throws Exception
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache();
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache();
cache.put("/a/b/c", "name", "Bela Ban");
cache.put("/a/b/c", "age", 40);
cache.put("/a/b/c", "city", "Kreuzlingen");
- Set keys = cache.getKeys("/a/b/c");
+ Set keys = cache.getNode("/a/b/c").getKeys();
log("keys are " + keys);
assertNotNull(keys);
assertEquals(3, keys.size());
@@ -43,13 +42,13 @@
@Test(groups = {"functional"})
public void testGetChildren() throws Exception
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache();
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache();
cache.put("/a/b/c", null);
cache.put("/a/b/c/1", null);
cache.put("/a/b/c/2", null);
cache.put("/a/b/c/3", null);
- Set children = cache.getChildrenNames("/a/b/c");
+ Set children = cache.getNode("/a/b/c").getChildrenNames();
log("children are " + children);
assertNotNull(children);
assertEquals(3, children.size());
@@ -62,7 +61,7 @@
@Test(groups = {"functional"})
public void testGetKeysOnNode()
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache();
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache();
cache.put("/a/b/c", "key", "value");
Node node = cache.getRoot().getChild(Fqn.fromString("/a/b/c"));
Set keySet = node.getKeys();
@@ -71,7 +70,8 @@
keySet.add("asd");
fail();
- } catch (Exception e)
+ }
+ catch (Exception e)
{
//expected
}
Modified: core/trunk/src/test/java/org/jboss/cache/LifeCycleTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/LifeCycleTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/LifeCycleTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,18 +1,5 @@
package org.jboss.cache;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.config.Configuration;
@@ -21,11 +8,19 @@
import org.jboss.cache.notifications.annotation.CacheStarted;
import org.jboss.cache.notifications.annotation.CacheStopped;
import org.jboss.cache.notifications.event.Event;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import java.util.LinkedList;
+import java.util.List;
+
/**
- * Tests restart (stop-destroy-create-start) of CacheImpl
+ * Tests restart (stop-destroy-create-start) of CacheSPI
*
* @author Bela Ban
* @version $Id$
@@ -34,7 +29,7 @@
public class LifeCycleTest
{
private static Log log = LogFactory.getLog(LifeCycleTest.class);
- private CacheImpl[] c;
+ private CacheSPI[] c;
@AfterMethod
public void tearDown()
@@ -65,7 +60,7 @@
List<Cache> caches = new LinkedList<Cache>();
if (c != null) for (Cache existingCache : c) caches.add(existingCache);
caches.add(cache);
- c = caches.toArray(new CacheImpl[]{});
+ c = caches.toArray(new CacheSPI[]{});
if (start)
{
cache.start();
@@ -82,9 +77,7 @@
assertTrue(c[0].getNumberOfNodes() > 0);
assertEquals(0, c[0].getNumberOfLocksHeld());
- System.out.println("cache locks before restart:\n" + c[0].printLockInfo());
restartCache(c[0]);
- System.out.println("cache locks after restart:\n" + c[0].printLockInfo());
assertEquals(0, c[0].getNumberOfNodes());
assertEquals(0, c[0].getNumberOfLocksHeld());
@@ -97,12 +90,10 @@
TransactionManager tm = beginTransaction();
c[0].put("/a/b/c", null);
- log.debug("cache locks before restart:\n" + c[0].printLockInfo());
assertTrue(c[0].getNumberOfNodes() > 0);
assertEquals(4, c[0].getNumberOfLocksHeld());
restartCache(c[0]);
- log.debug("cache locks after restart:\n" + c[0].printLockInfo());
//assertEquals(4, cache.getNumberOfLocksHeld());
assertEquals(0, c[0].getNumberOfNodes());
@@ -120,9 +111,7 @@
assertTrue(c[0].getNumberOfNodes() > 0);
assertEquals(0, c[0].getNumberOfLocksHeld());
- System.out.println("cache locks before restart:\n" + c[0].printLockInfo());
restartCache(c[0]);
- System.out.println("cache locks after restart:\n" + c[0].printLockInfo());
assertEquals(0, c[0].getNumberOfNodes());
assertEquals(0, c[0].getNumberOfLocksHeld());
@@ -139,9 +128,7 @@
assertTrue(c[0].getNumberOfNodes() > 0);
assertEquals(0, c[0].getNumberOfLocksHeld());
- System.out.println("cache locks before restart:\n" + c[0].printLockInfo());
restartCache(c[0]);
- System.out.println("cache locks after restart:\n" + c[0].printLockInfo());
assertEquals(0, c[0].getNumberOfNodes());
assertEquals(0, c[0].getNumberOfLocksHeld());
@@ -159,9 +146,7 @@
assertTrue(c[0].getNumberOfNodes() > 0);
assertEquals(0, c[0].getNumberOfLocksHeld());
- System.out.println("cache locks before restart:\n" + c[0].printLockInfo());
restartCache(c[0]);
- System.out.println("cache locks after restart:\n" + c[0].printLockInfo());
assertEquals(0, c[0].getNumberOfNodes());
assertEquals(0, c[0].getNumberOfLocksHeld());
@@ -285,7 +270,8 @@
{
// now DIRECTLY change the status of c2.
// emulate the race condition where the remote cache is stopping but hasn't disconnected from the channel.
- c[1].cacheStatus = CacheStatus.STOPPING;
+ CacheImpl ci1 = (CacheImpl) TestingUtil.extractField(c[1], "cache");
+ ci1.cacheStatus = CacheStatus.STOPPING;
// Thanks to JBCACHE-1179, this should only log a warning and not throw an exception
c[0].put(Fqn.ROOT, "k", "v");
@@ -293,11 +279,13 @@
finally
{
// reset c[1] to running so the tearDown method can clean it up
- c[1].cacheStatus = CacheStatus.STARTED;
+ CacheImpl ci1 = (CacheImpl) TestingUtil.extractField(c[1], "cache");
+ ci1.cacheStatus = CacheStatus.STARTED;
}
}
- @Test (enabled = false) // TODO: needs investigation ... !
+ @Test(enabled = false)
+ // TODO: needs investigation ... !
public void testRemoteInvalidStateInvocations2() throws Exception
{
createAndRegisterCache(Configuration.CacheMode.REPL_SYNC, true);
@@ -306,7 +294,8 @@
{
// now DIRECTLY change the status of c2.
// emulate the race condition where the remote cache is stopping but hasn't disconnected from the channel.
- c[1].cacheStatus = CacheStatus.STARTING;
+ CacheImpl ci1 = (CacheImpl) TestingUtil.extractField(c[1], "cache");
+ ci1.cacheStatus = CacheStatus.STARTING;
try
{
@@ -326,7 +315,8 @@
public void run()
{
TestingUtil.sleepThread(sleepTime);
- c[1].cacheStatus = CacheStatus.STARTED;
+ CacheImpl ci1 = (CacheImpl) TestingUtil.extractField(c[1], "cache");
+ ci1.cacheStatus = CacheStatus.STARTED;
}
}.start();
@@ -339,7 +329,8 @@
finally
{
// reset c[1] to running so the tearDown method can clean it up
- c[1].cacheStatus = CacheStatus.STARTED;
+ CacheImpl ci1 = (CacheImpl) TestingUtil.extractField(c[1], "cache");
+ ci1.cacheStatus = CacheStatus.STARTED;
}
}
@@ -351,7 +342,8 @@
c[0].put(Fqn.ROOT, "k2", "v2");
// now DIRECTLY change the status of c.
- c[0].cacheStatus = CacheStatus.STOPPING;
+ CacheImpl ci0 = (CacheImpl) TestingUtil.extractField(c[0], "cache");
+ ci0.cacheStatus = CacheStatus.STOPPING;
try
{
@@ -385,7 +377,7 @@
{
public void run()
{
- int i=0;
+ int i = 0;
while (running.get(0))
{
try
@@ -425,16 +417,17 @@
c[0].put(Fqn.ROOT, "k2", "v2");
// now DIRECTLY change the status of c.
- c[0].cacheStatus = CacheStatus.STOPPING;
+ CacheImpl ci0 = (CacheImpl) TestingUtil.extractField(c[0], "cache");
+ ci0.cacheStatus = CacheStatus.STOPPING;
// rollbacks should just log a message
c[0].getTransactionManager().rollback();
}
- private CacheImpl<Object, Object> createCache(Configuration.CacheMode cache_mode) throws Exception
+ private CacheSPI<Object, Object> createCache(Configuration.CacheMode cache_mode)
{
- CacheImpl<Object, Object> retval = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ CacheSPI<Object, Object> retval = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
retval.getConfiguration().setCacheMode(cache_mode);
retval.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
return retval;
@@ -449,19 +442,19 @@
}
- private void startCache(CacheImpl c) throws Exception
+ private void startCache(CacheSPI c)
{
c.create();
c.start();
}
- private void stopCache(CacheImpl c)
+ private void stopCache(CacheSPI c)
{
c.stop();
c.destroy();
}
- private void restartCache(CacheImpl c) throws Exception
+ private void restartCache(CacheSPI c) throws Exception
{
stopCache(c);
startCache(c);
Modified: core/trunk/src/test/java/org/jboss/cache/TreeCacheFunctionalTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/TreeCacheFunctionalTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/TreeCacheFunctionalTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,17 +1,17 @@
package org.jboss.cache;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-
-import java.util.HashMap;
-
import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.IsolationLevel;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+
+import java.util.HashMap;
+
/**
- * Simple functional tests for CacheImpl
+ * Simple functional tests for CacheSPI
*
* @author Bela Ban
* @version $Id$
@@ -19,13 +19,13 @@
@Test(groups = {"functional"})
public class TreeCacheFunctionalTest
{
- CacheImpl<Object, Object> cache = null;
+ CacheSPI<Object, Object> cache = null;
final Fqn FQN = Fqn.fromString("/myNode");
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
@@ -48,7 +48,7 @@
{
cache.put("/a/b/c", "age", 38);
assertEquals(cache.get("/a/b/c", "age"), 38);
- assertNotNull(cache.get("/a/b/c"));
+ assertNotNull(cache.getNode("/a/b/c"));
assertEquals(0, cache.getNumberOfLocksHeld());
assertEquals(0, cache.getLockTable().size());
}
@@ -58,32 +58,28 @@
{
Object key = null;
cache.put("/a/b/c", key, "val");
- System.out.println("value of /a/b/c " + cache.print("/a/b/c"));
}
public void testPutNullValue() throws CacheException
{
Object val = null;
cache.put("/a/b/c", "key", val);
- System.out.println("value of /a/b/c " + cache.print("/a/b/c"));
}
public void testPutNullKeyAndValues() throws CacheException
{
Object key = null, val = null;
cache.put("/a/b/c", key, val);
- System.out.println("value of /a/b/c " + cache.print("/a/b/c"));
}
public void testPutMapsWithNullValues() throws CacheException
{
- HashMap<String, String> map = new HashMap<String, String>();
+ HashMap<Object, Object> map = new HashMap<Object, Object>();
map.put("key", null);
map.put(null, "val");
map.put("a", "b");
map.put(null, null);
cache.put("/a/b/c", map);
- System.out.println("value of /a/b/c " + cache.print("/a/b/c"));
}
public void testPutKeys() throws CacheException
@@ -91,8 +87,8 @@
cache.put("/a/b/c", "age", 38);
cache.put("/a/b/c", "name", "Bela");
assertEquals(cache.get("/a/b/c", "age"), 38);
- assertNotNull(cache.get("/a/b/c"));
- assertEquals(cache.getKeys("/a/b/c").size(), 2);
+ assertNotNull(cache.getNode("/a/b/c"));
+ assertEquals(cache.getNode("/a/b/c").getKeys().size(), 2);
assertEquals(cache.exists("/a/b/c"), true);
assertEquals(0, cache.getNumberOfLocksHeld());
assertEquals(0, cache.getLockTable().size());
@@ -106,7 +102,7 @@
cache.put("/a/b/c/3", null);
cache.put("/a/b/c/3/a/b/c", null);
- cache.remove("/a/b/c");
+ cache.removeNode("/a/b/c");
assertEquals(0, cache.getNumberOfLocksHeld());
assertEquals(0, cache.getLockTable().size());
}
Modified: core/trunk/src/test/java/org/jboss/cache/TreeNodeTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/TreeNodeTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/TreeNodeTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -2,26 +2,25 @@
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
-
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
- * Tests restart (stop-destroy-create-start) of CacheImpl
+ * Tests restart (stop-destroy-create-start) of CacheSPI
*
* @author Bela Ban
* @version $Id$
*/
-@Test(groups={"functional"})
+@Test(groups = {"functional"})
public class TreeNodeTest
{
- CacheImpl<Object, Object> cache;
+ CacheSPI<Object, Object> cache;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache();
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache();
}
@AfterMethod(alwaysRun = true)
@@ -35,13 +34,13 @@
{
Object key = 1;
cache.put(Fqn.fromString("/a/b/c"), key, "test");
- Node<Object, Object> node = cache.get(Fqn.fromString("/a/b"));
+ Node<Object, Object> node = cache.getNode(Fqn.fromString("/a/b"));
assertFalse(node.getChildren().isEmpty());
assertTrue(node.getChild(new Fqn<String>("c")) != null);
Fqn fqn = Fqn.fromString("/e/f");
cache.put(fqn, "1", "1");
- node = cache.get(Fqn.fromString("/e"));
+ node = cache.getNode(Fqn.fromString("/e"));
assertFalse(node.getChildren().isEmpty());
assertTrue(node.getChild(new Fqn<String>("f")) != null);
}
Modified: core/trunk/src/test/java/org/jboss/cache/api/CacheAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/CacheAPITest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/api/CacheAPITest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,22 +1,7 @@
package org.jboss.cache.api;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNotSame;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertSame;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
@@ -27,9 +12,16 @@
import org.jboss.cache.notifications.annotation.NodeCreated;
import org.jboss.cache.notifications.event.Event;
import org.jboss.cache.transaction.GenericTransactionManagerLookup;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
/**
* Tests the {@link org.jboss.cache.Cache} public API at a high level
*
@@ -74,7 +66,7 @@
try
{
c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
- fail("Should have thrown an Exception");
+ assert false : "Should have thrown an Exception";
}
catch (ConfigurationException e)
{
@@ -175,8 +167,6 @@
cache.put(fqn, data);
- System.out.println(((CacheImpl) cache).printDetails());
-
assertEquals(value, cache.get(fqn, key));
}
@@ -194,7 +184,7 @@
assertEquals(true, cache.removeNode(fqn));
assertFalse(cache.getRoot().hasChild(fqn));
assertEquals(false, cache.removeNode(fqn));
-
+
// Check that it's removed if it has a child
Fqn<String> child = Fqn.fromString("/test/fqn/child");
cache.getRoot().addChild(child);
Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,6 +1,6 @@
package org.jboss.cache.api;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
@@ -30,12 +30,12 @@
{
private Node<Object, Object> rootNode;
- private CacheImpl<Object, Object> cache;
+ private CacheSPI<Object, Object> cache;
private TransactionManager tm;
private static final Fqn<String> A = Fqn.fromString("/a"), B = Fqn.fromString("/b"), C = Fqn.fromString("/c"), D = Fqn
- .fromString("/d");
+ .fromString("/d");
protected boolean optimistic = false;
@@ -43,7 +43,7 @@
public void setUp() throws Exception
{
// start a single cache instance
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/local-tx-service.xml", false);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/local-tx-service.xml", false);
cache.getConfiguration().setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
cache.start();
rootNode = cache.getRoot();
Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,20 +1,8 @@
package org.jboss.cache.api;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-
-import java.util.Map;
-import java.util.Random;
-import java.util.concurrent.CountDownLatch;
-
-import javax.transaction.TransactionManager;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
@@ -25,10 +13,17 @@
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.xml.XmlHelper;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
+
+import javax.transaction.TransactionManager;
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+
/**
* Excercises and tests the new move() api
*
@@ -40,7 +35,7 @@
protected final Log log = LogFactory.getLog(getClass());
protected Node<Object, Object> rootNode, nodeA, nodeB, nodeC, nodeD, nodeE;
- protected CacheImpl<Object, Object> cache;
+ protected CacheSPI<Object, Object> cache;
protected TransactionManager tm;
protected static final Fqn<String> A = Fqn.fromString("/a"), B = Fqn.fromString("/b"), C = Fqn.fromString("/c"), D = Fqn.fromString("/d"), E = Fqn.fromString("/e");
protected Object k = "key", vA = "valueA", vB = "valueB", vC = "valueC", vD = "valueD", vE = "valueE";
@@ -51,7 +46,7 @@
public void setUp() throws Exception
{
// start a single cache instance
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/local-tx-service.xml", false);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/local-tx-service.xml", false);
cache.getConfiguration().setNodeLockingScheme(optimistic ? Configuration.NodeLockingScheme.OPTIMISTIC : Configuration.NodeLockingScheme.PESSIMISTIC);
cache.start();
rootNode = cache.getRoot();
@@ -97,7 +92,7 @@
cache.move(nodeC.getFqn(), nodeB.getFqn());
// re-fetch nodeC
- nodeC = cache.get(new Fqn<String>(genericize(nodeB.getFqn()), C));
+ nodeC = cache.getNode(new Fqn<String>(genericize(nodeB.getFqn()), C));
log.info("POST MOVE " + cache);
log.info("HC " + nodeC + " " + System.identityHashCode(nodeC));
@@ -182,8 +177,6 @@
nodeD = nodeC.getChild(D);
nodeE = nodeD.getChild(E);
- System.out.println("Tree " + cache.printLockInfo());
-
assertTrue(rootNode.hasChild(A));
assertTrue(rootNode.hasChild(B));
assertFalse(rootNode.hasChild(C));
@@ -355,12 +348,8 @@
System.out.println("Loader" + loader);
- log.info("Current tree is " + cache.printDetails());
-
cache.evict(Fqn.ROOT, true);
- log.info("POST EVICT tree is " + cache.printDetails());
-
// move
if (useTx) tm.begin();
cache.move(nodeC.getFqn(), nodeB.getFqn());
@@ -380,21 +369,15 @@
// System.out.println(" Contents in loader: " + loader.get(f));
// }
- log.info("Post commit tree is " + cache.printDetails());
-
// after eviction, the node objects we hold are probably stale.
nodeA = rootNode.getChild(A);
nodeB = rootNode.getChild(B);
nodeC = nodeB.getChild(C);
- log.info("Current tree is " + cache.printDetails());
log.info("nodeC get child B ");
nodeD = nodeC.getChild(D);
- log.info("Current tree is " + cache.printDetails());
log.info("nodeD get child E ");
nodeE = nodeD.getChild(E);
- log.info("Current tree is " + cache.printDetails());
-
Fqn<String> old_C = new Fqn<String>(C);
Fqn<String> old_D = new Fqn<String>(old_C, D);
Fqn<String> old_E = new Fqn<String>(old_D, E);
@@ -450,11 +433,8 @@
cache.move(nodeC.getFqn(), nodeB.getFqn());
// nodeC should have a RL, nodeA should have a RL, nodeB should have a WL, nodeD should have a WL
- System.out.println("LOCKS: " + cache.printLockInfo());
-
assertEquals("ROOT should have a RL, nodeC should have a RL, nodeA should have a RL, nodeB should have a WL, nodeD should have a WL", 5, cache.getNumberOfLocksHeld());
-
tm.commit();
assertEquals(0, cache.getNumberOfLocksHeld());
@@ -471,13 +451,8 @@
cache.move(nodeC.getFqn(), nodeB.getFqn());
- // nodeC should have a RL, nodeA should have a RL, nodeB should have a WL
-
- System.out.println("LOCKS: " + cache.printLockInfo());
-
assertEquals("ROOT should have a RL, nodeC should have a RL, nodeA should have a RL, nodeB should have a WL", 4, cache.getNumberOfLocksHeld());
-
tm.commit();
assertEquals(0, cache.getNumberOfLocksHeld());
@@ -507,8 +482,8 @@
// set up the initial structure.
final Node[] NODES = {
- rootNode.addChild(FQN_A), rootNode.addChild(FQN_B),
- rootNode.addChild(FQN_C), rootNode.addChild(FQN_D), rootNode.addChild(FQN_E)
+ rootNode.addChild(FQN_A), rootNode.addChild(FQN_B),
+ rootNode.addChild(FQN_C), rootNode.addChild(FQN_D), rootNode.addChild(FQN_E)
};
final Node<Object, Object> NODE_X = genericize(NODES[0]).addChild(FQN_X);
@@ -616,17 +591,17 @@
protected CacheLoaderConfig getSingleCacheLoaderConfig(boolean passivation, String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared, boolean purgeOnStartup) throws Exception
{
String xml = "<config>\n" +
- "<passivation>" + passivation + "</passivation>\n" +
- "<preload>" + preload + "</preload>\n" +
- "<cacheloader>\n" +
- "<class>" + cacheloaderClass + "</class>\n" +
- "<properties>" + properties + "</properties>\n" +
- "<async>" + async + "</async>\n" +
- "<shared>" + shared + "</shared>\n" +
- "<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
- "<purgeOnStartup>" + purgeOnStartup + "</purgeOnStartup>\n" +
- "</cacheloader>\n" +
- "</config>";
+ "<passivation>" + passivation + "</passivation>\n" +
+ "<preload>" + preload + "</preload>\n" +
+ "<cacheloader>\n" +
+ "<class>" + cacheloaderClass + "</class>\n" +
+ "<properties>" + properties + "</properties>\n" +
+ "<async>" + async + "</async>\n" +
+ "<shared>" + shared + "</shared>\n" +
+ "<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
+ "<purgeOnStartup>" + purgeOnStartup + "</purgeOnStartup>\n" +
+ "</cacheloader>\n" +
+ "</config>";
Element element = XmlHelper.stringToElement(xml);
return XmlConfigurationParser.parseCacheLoaderConfig(element);
}
Modified: core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,26 +1,21 @@
package org.jboss.cache.api;
-import org.testng.annotations.Test;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.AfterMethod;
-import static org.testng.Assert.*;
-import static org.testng.Assert.assertNotNull;
-import org.jboss.cache.*;
-import org.jboss.cache.eviction.LRUConfiguration;
-import org.jboss.cache.transaction.DummyTransactionManagerLookup;
-import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.loader.DummyInMemoryCacheLoader;
-import org.jboss.cache.loader.DummyCacheLoader;
-import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.eviction.LRUConfiguration;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.misc.TestingUtil;
+import static org.testng.Assert.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
-import javax.transaction.*;
-import java.util.List;
-import java.util.ArrayList;
+import javax.transaction.TransactionManager;
/**
* Tester class for Node.isResident functionality.
@@ -32,18 +27,17 @@
public class ResidentNodesTest
{
- private CacheImpl<Object, Object> cache;
+ private CacheSPI<Object, Object> cache;
private final String TEST_NODES_ROOT = "residentNodesTest";
- private Configuration cacheConfig;
private Cache[] caches = {};
@BeforeMethod(alwaysRun = true)
public void setUp()
{
- cacheConfig = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
+ Configuration cacheConfig = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
cacheConfig.setCacheMode(Configuration.CacheMode.LOCAL);
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(cacheConfig, false);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(cacheConfig, false);
cache.getConfiguration().getEvictionConfig().setWakeupIntervalSeconds(1);
createNewRegion();
cache.start();
@@ -87,9 +81,9 @@
public void testHappyFlow() throws InterruptedException
{
cache.put(getSubFqn("/a"), "k_a", "v_a");
- cache.get(getSubFqn("/a")).setResident(true);
+ cache.getNode(getSubFqn("/a")).setResident(true);
cache.put(getSubFqn("/b"), "k_b", "v_b");
- cache.get(getSubFqn("/b")).setResident(true);
+ cache.getNode(getSubFqn("/b")).setResident(true);
cache.put(getSubFqn("/c"), "k_c", "v_c");
cache.put(getSubFqn("/d"), "k_d", "v_d");
cache.put(getSubFqn("/e"), "k_e", "v_e");
@@ -124,8 +118,8 @@
cache.put(getSubFqn("/a"), "k_a", "v_a");
cache.put(getSubFqn("/b"), "k_b", "v_b");
- cache.get(getSubFqn("/a")).setResident(true);
- cache.get(getSubFqn("/b")).setResident(true);
+ cache.getNode(getSubFqn("/a")).setResident(true);
+ cache.getNode(getSubFqn("/b")).setResident(true);
cache.put(getSubFqn("/c"), "k_c", "v_c");
cache.put(getSubFqn("/d"), "k_d", "v_d");
@@ -136,8 +130,8 @@
//at this point the oldest nodes are /a and /b so. There are eviction events in the queue corresponding
// to those nodes
- cache.get(getSubFqn("/a"));
- cache.get(getSubFqn("/b"));
+ cache.getNode(getSubFqn("/a"));
+ cache.getNode(getSubFqn("/b"));
TestingUtil.sleepThread(3000);//so that eviction is activated
@@ -167,7 +161,7 @@
Configuration config = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
config.setCacheMode(Configuration.CacheMode.LOCAL);
config.setNodeLockingOptimistic(true);
- CacheImpl cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(config, true);
+ CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(config, true);
cache.put(Fqn.fromString("/a/b"), "key", "value");
TransactionManager txManager = cache.getTransactionManager();
@@ -192,7 +186,8 @@
{
cache.getTransactionManager().rollback();
}
- } finally
+ }
+ finally
{
cache.stop();
}
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyBackupActivationInactivationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyBackupActivationInactivationTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyBackupActivationInactivationTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -7,7 +7,6 @@
package org.jboss.cache.buddyreplication;
import org.jboss.cache.Cache;
-import org.jboss.cache.CacheImpl;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
@@ -49,8 +48,8 @@
public void testBuddyBackupActivation() throws Exception
{
- CacheSPI<Object, Object> cache1 = createCache("cache1", true, true, true);
- CacheSPI<Object, Object> cache2 = createCache("cache2", true, true, true);
+ CacheSPI cache1 = createCache("cache1", true, true, true);
+ CacheSPI cache2 = createCache("cache2", true, true, true);
Fqn A = Fqn.fromString("/a");
TestingUtil.blockUntilViewsReceived(VIEW_BLOCK_TIMEOUT, cache1, cache2);
@@ -83,8 +82,8 @@
public void testReplToInactiveRegion() throws Exception
{
- CacheSPI<Object, Object> cache1 = createCache("cache1", true, true, true);
- CacheSPI<Object, Object> cache2 = createCache("cache2", true, true, true);
+ CacheSPI cache1 = createCache("cache1", true, true, true);
+ CacheSPI cache2 = createCache("cache2", true, true, true);
TestingUtil.blockUntilViewsReceived(VIEW_BLOCK_TIMEOUT, cache1, cache2);
Fqn backupFqn = BuddyManager.getBackupFqn(cache1.getLocalAddress(), A_B);
@@ -109,7 +108,7 @@
public void testBuddyBackupInactivation() throws Exception
{
- CacheImpl<Object, Object> cache1 = createCache("cache1", true, true, true);
+ CacheSPI cache1 = createCache("cache1", true, true, true);
Fqn<String> A = Fqn.fromString("/a");
Region regionA = cache1.getRegion(A, true);
regionA.registerContextClassLoader(getClass().getClassLoader());
@@ -127,23 +126,22 @@
assertNull("Inactivation should have cleared region", cache1.get(fqn, "name"));
}
- protected CacheImpl<Object, Object> createCache(String cacheID,
- boolean sync,
- boolean useMarshalling,
- boolean startCache)
- throws Exception
+ protected CacheSPI<?, ?> createCache(String cacheID,
+ boolean sync,
+ boolean useMarshalling,
+ boolean startCache)
+ throws Exception
{
if (caches.get(cacheID) != null)
{
throw new IllegalStateException(cacheID + " already created");
}
- CacheImpl<Object, Object> cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
-
CacheMode mode = sync ? CacheMode.REPL_SYNC : CacheMode.REPL_ASYNC;
Configuration c = UnitTestCacheConfigurationFactory.createConfiguration(mode);
- cache.setConfiguration(c);
+ CacheSPI<?, ?> cache = (CacheSPI<?, ?>) DefaultCacheFactory.getInstance().createCache(c, false);
+
cache.getConfiguration().setClusterName("TestCluster");
if (useMarshalling)
{
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyPoolBroadcastTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyPoolBroadcastTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyPoolBroadcastTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,19 +6,18 @@
*/
package org.jboss.cache.buddyreplication;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.misc.TestingUtil;
import static org.testng.AssertJUnit.assertEquals;
+import org.testng.annotations.AfterMethod;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheImpl;
-import org.jboss.cache.misc.TestingUtil;
-import org.testng.annotations.AfterMethod;
-
/**
* Tests basic group membership semantics
*
@@ -28,7 +27,7 @@
{
private Log log = LogFactory.getLog(BuddyPoolBroadcastTest.class);
- private void checkConsistentPoolState(List<CacheImpl<Object, Object>> caches)
+ private void checkConsistentPoolState(List<CacheSPI<Object, Object>> caches)
{
for (int i = 0; i < caches.size(); i++)
{
@@ -38,7 +37,7 @@
if (i != j)
{
Map groupMap2 = caches.get(j).getBuddyManager().buddyPool;
- for (CacheImpl cache : caches)
+ for (CacheSPI cache : caches)
{
assertEquals("Comparing contents of cache " + (i + 1) + " pool map with cache " + (j + 1), groupMap.get(cache), groupMap2.get(cache));
}
@@ -119,7 +118,7 @@
caches.get(1).stop();
caches.set(1, createCache(1, "Z"));
- TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheImpl[0]), VIEW_BLOCK_TIMEOUT);
+ TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheSPI[0]), VIEW_BLOCK_TIMEOUT);
TestingUtil.sleepThread(getSleepTimeout());
// first test the values
@@ -135,7 +134,7 @@
{
log.debug("Running testConcurrency");
int numCaches = 4;
- caches = new ArrayList<CacheImpl<Object, Object>>(4);
+ caches = new ArrayList<CacheSPI<Object, Object>>(4);
CountDownLatch latch = new CountDownLatch(1);
CacheStarter[] starters = new CacheStarter[numCaches];
@@ -151,7 +150,7 @@
latch.countDown();
// allow a generous sleep time
- TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheImpl[0]), 240000);
+ TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheSPI[0]), 240000);
TestingUtil.sleepThread(1000 * numCaches); // the max timeout we can expect is 2500ms * 10 nodes
// and now look at the state of things.
@@ -171,9 +170,9 @@
public class CacheStarter extends Thread
{
private CountDownLatch latch;
- private CacheImpl cache;
+ private CacheSPI cache;
- public CacheStarter(String name, CountDownLatch latch, CacheImpl cache)
+ public CacheStarter(String name, CountDownLatch latch, CacheSPI cache)
{
super(name);
this.latch = latch;
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,12 +6,6 @@
*/
package org.jboss.cache.buddyreplication;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-
-import org.jboss.cache.CacheImpl;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.BuddyReplicationConfig;
@@ -20,9 +14,11 @@
import org.jboss.cache.interceptors.DataGravitatorInterceptor;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.xml.XmlHelper;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
+
/**
* Tests basic configuration options by passing stuff into the CacheImpl.
*
@@ -79,8 +75,7 @@
public void testXmlConfig() throws Exception
{
- cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
- ((CacheImpl) cache).setConfiguration(new XmlConfigurationParser().parseFile("META-INF/buddyreplication-service.xml"));
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(new XmlConfigurationParser().parseFile("META-INF/buddyreplication-service.xml"), false);
cache.create();
cache.start();
BuddyManager bm = cache.getBuddyManager();
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationContentTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -8,7 +8,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.notifications.annotation.CacheBlocked;
@@ -27,7 +27,7 @@
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
-@Test (groups = {"functional"})
+@Test(groups = {"functional"})
public class BuddyReplicationContentTest extends BuddyReplicationTestsBase
{
private String key = "key";
@@ -35,14 +35,14 @@
private Log log = LogFactory.getLog(BuddyGroupAssignmentTest.class);
- private void assertNoStaleLocks(List<CacheImpl<Object, Object>> caches)
+ private void assertNoStaleLocks(List<CacheSPI<Object, Object>> caches)
{
- for (CacheImpl<Object, Object> cache : caches) assertNoStaleLocks(cache);
+ for (CacheSPI<Object, Object> cache : caches) assertNoStaleLocks(cache);
}
- private void assertNoStaleLocks(CacheImpl<Object, Object> cache)
+ private void assertNoStaleLocks(CacheSPI<Object, Object> cache)
{
- assertEquals("Number of locks in cache instance " + cache.toString(true) + " should be 0", 0, cache.getNumberOfLocksHeld());
+ assertEquals("Number of locks in cache instance " + cache + " should be 0", 0, cache.getNumberOfLocksHeld());
}
public void testSimplePut() throws Exception
@@ -101,7 +101,7 @@
assertNoStaleLocks(caches);
// now remove
- caches.get(0).remove(fqn);
+ caches.get(0).removeNode(fqn);
assertNoStaleLocks(caches);
@@ -146,7 +146,7 @@
assertNoStaleLocks(caches);
// now remove
- caches.get(0).remove(fqn);
+ caches.get(0).removeNode(fqn);
assertNoStaleLocks(caches);
assertNull("Should be null", caches.get(0).get(fqn, key));
@@ -167,7 +167,7 @@
{
log.debug("Running testBuddyJoin");
caches = createCaches(2, false);
- CacheImpl<Object, Object> cache2 = null;
+ CacheSPI<Object, Object> cache2 = null;
try
{
@@ -198,7 +198,7 @@
TestingUtil.sleepThread(2000); // allow buddy group reorg
- List<CacheImpl<Object, Object>> dump = new ArrayList<CacheImpl<Object,Object>>(caches);
+ List<CacheSPI<Object, Object>> dump = new ArrayList<CacheSPI<Object, Object>>(caches);
dump.add(cache2);
dumpCacheContents(dump);
@@ -215,7 +215,7 @@
// while cache2 should now posess this backup (due to a state transfer)
assertEquals("Backup state should have been transferred to this new cache instance", value, cache2.get(backupFqn, key));
- caches.get(1).remove(fqn);
+ caches.get(1).removeNode(fqn);
assertNoStaleLocks(caches);
@@ -261,28 +261,13 @@
log.info("stopping 2");
caches.get(2).stop();
- log.info("0 ** " + caches.get(0).printLockInfo());
- log.info("1 ** " + caches.get(1).printLockInfo());
- log.info("2 ** " + caches.get(2).printLockInfo());
-
-// TestingUtil.sleepThread(getSleepTimeout());
-// TestingUtil.sleepThread(caches.get(0).getConfiguration().getStateRetrievalTimeout() * 3);
blockListener.blockUntilAllCachesAreUnblocked(caches.get(0).getConfiguration().getStateRetrievalTimeout() * 5);
assertEquals("value", caches.get(0).get("/2", "key"));
- log.info("0 ** " + caches.get(0).printLockInfo());
- log.info("1 ** " + caches.get(1).printLockInfo());
- log.info("2 ** " + caches.get(2).printLockInfo());
-
-// TestingUtil.sleepThread(getSleepTimeout());
-// TestingUtil.sleepThread(caches.get(0).getConfiguration().getStateRetrievalTimeout() * 3);
blockListener.blockUntilAllCachesAreUnblocked(caches.get(0).getConfiguration().getStateRetrievalTimeout() * 5);
caches.get(1).stop();
- log.info("0 ** " + caches.get(0).printLockInfo());
- log.info("1 ** " + caches.get(1).printLockInfo());
- log.info("2 ** " + caches.get(2).printLockInfo());
// cache[0] is all thats left!!
@@ -310,6 +295,7 @@
public static class CacheBlockListener
{
private int blocks = 0;
+
@CacheBlocked
public void processBlock(Event e)
{
@@ -318,7 +304,7 @@
System.out.println(">>>>>>>> Got BLOCK on cache " + e.getCache().getLocalAddress());
synchronized (this)
{
- blocks ++;
+ blocks++;
notifyAll();
}
}
@@ -332,7 +318,7 @@
System.out.println(">>>>>>>> Got UNBLOCK on cache " + e.getCache().getLocalAddress());
synchronized (this)
{
- blocks --;
+ blocks--;
notifyAll();
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationFailoverTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationFailoverTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationFailoverTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,13 +6,10 @@
*/
package org.jboss.cache.buddyreplication;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertTrue;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.*;
/**
* Tests behaviour when data owners fail - essentially this tests data gravitation
@@ -174,7 +171,7 @@
assertNoLocks(caches);
// gravitate to 2:
- caches.get(2).get(fqn); // expect entire subtree to gravitate.
+ caches.get(2).getNode(fqn); // expect entire subtree to gravitate.
Fqn<String> newBackupFqn = Fqn.fromString("/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyManager.getGroupNameFromAddress(caches.get(2).getLocalAddress()) + "/test");
Fqn<String> newBackupFqn2 = Fqn.fromString("/" + BuddyManager.BUDDY_BACKUP_SUBTREE + "/" + BuddyManager.getGroupNameFromAddress(caches.get(2).getLocalAddress()) + "/test/subtree");
@@ -193,7 +190,7 @@
assertTrue(!caches.get(1).exists(newBackupFqn));
assertTrue(!caches.get(1).exists(newBackupFqn2));
- for (CacheImpl<Object, Object> cache : caches)
+ for (CacheSPI<Object, Object> cache : caches)
{
assertTrue(!cache.exists(backupFqn));
assertTrue(!cache.exists(backupFqn2));
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationTestsBase.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -7,7 +7,6 @@
package org.jboss.cache.buddyreplication;
import org.jboss.cache.Cache;
-import org.jboss.cache.CacheImpl;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
@@ -21,6 +20,7 @@
import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.CachePrinter;
import org.jboss.cache.xml.XmlHelper;
import org.jgroups.Address;
import static org.testng.AssertJUnit.*;
@@ -40,7 +40,7 @@
@Test(groups = {"functional", "jgroups"})
public abstract class BuddyReplicationTestsBase
{
- protected List<CacheImpl<Object, Object>> caches;
+ protected List<CacheSPI<Object, Object>> caches;
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
@@ -100,42 +100,42 @@
protected final static int VIEW_BLOCK_TIMEOUT = 5000;
- protected CacheImpl<Object, Object> createCache(int numBuddies, String buddyPoolName) throws Exception
+ protected CacheSPI<Object, Object> createCache(int numBuddies, String buddyPoolName) throws Exception
{
return createCache(numBuddies, buddyPoolName, false, true);
}
- protected CacheImpl<Object, Object> createCache(int numBuddies, String buddyPoolName, boolean useDataGravitation) throws Exception
+ protected CacheSPI<?, ?> createCache(int numBuddies, String buddyPoolName, boolean useDataGravitation) throws Exception
{
return createCache(numBuddies, buddyPoolName, useDataGravitation, true);
}
- protected CacheImpl<Object, Object> createCache(int numBuddies, String buddyPoolName, boolean useDataGravitation, boolean start) throws Exception
+ protected CacheSPI<Object, Object> createCache(int numBuddies, String buddyPoolName, boolean useDataGravitation, boolean start) throws Exception
{
return createCache(false, numBuddies, buddyPoolName, useDataGravitation, true, start);
}
- protected CacheImpl<Object, Object> createCache(boolean optimisticLocks, int numBuddies, String buddyPoolName, boolean useDataGravitation, boolean start) throws Exception
+ protected CacheSPI<Object, Object> createCache(boolean optimisticLocks, int numBuddies, String buddyPoolName, boolean useDataGravitation, boolean start) throws Exception
{
return createCache(optimisticLocks, numBuddies, buddyPoolName, useDataGravitation, true, start);
}
- protected CacheImpl<Object, Object> createCache(int numBuddies, String buddyPoolName, boolean useDataGravitation, boolean removeOnFind, boolean start) throws Exception
+ protected CacheSPI<?, ?> createCache(int numBuddies, String buddyPoolName, boolean useDataGravitation, boolean removeOnFind, boolean start) throws Exception
{
return createCache(false, numBuddies, buddyPoolName, useDataGravitation, removeOnFind, start);
}
- protected CacheImpl<Object, Object> createCache(boolean optimisticLocks, int numBuddies, String buddyPoolName, boolean useDataGravitation, boolean removeOnFind, boolean start) throws Exception
+ protected CacheSPI<Object, Object> createCache(boolean optimisticLocks, int numBuddies, String buddyPoolName, boolean useDataGravitation, boolean removeOnFind, boolean start) throws Exception
{
- CacheImpl<Object, Object> c = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
+ CacheSPI<Object, Object> c = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
c.getConfiguration().setClusterName("BuddyReplicationTest");
// basic config
String xmlString = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled>\n" +
- "<buddyCommunicationTimeout>500</buddyCommunicationTimeout>\n" +
- " <buddyLocatorClass>org.jboss.cache.buddyreplication.NextMemberBuddyLocator</buddyLocatorClass>\n" +
- " <autoDataGravitation>" + useDataGravitation + "</autoDataGravitation>\n" +
- " <dataGravitationRemoveOnFind>" + removeOnFind + "</dataGravitationRemoveOnFind>\n" +
- " <buddyLocatorProperties>numBuddies = " + numBuddies + "</buddyLocatorProperties>\n";
+ "<buddyCommunicationTimeout>500</buddyCommunicationTimeout>\n" +
+ " <buddyLocatorClass>org.jboss.cache.buddyreplication.NextMemberBuddyLocator</buddyLocatorClass>\n" +
+ " <autoDataGravitation>" + useDataGravitation + "</autoDataGravitation>\n" +
+ " <dataGravitationRemoveOnFind>" + removeOnFind + "</dataGravitationRemoveOnFind>\n" +
+ " <buddyLocatorProperties>numBuddies = " + numBuddies + "</buddyLocatorProperties>\n";
if (buddyPoolName != null) xmlString += "<buddyPoolName>" + buddyPoolName + "</buddyPoolName>";
xmlString += "</config>";
@@ -186,55 +186,55 @@
assertFalse("Cache is not using multiplexer", cache.getConfiguration().isUsingMultiplexer());
}
- protected List<CacheImpl<Object, Object>> createCaches(int numCaches, boolean useBuddyPool) throws Exception
+ protected List<CacheSPI<Object, Object>> createCaches(int numCaches, boolean useBuddyPool) throws Exception
{
return createCaches(1, numCaches, useBuddyPool, false);
}
- protected List<CacheImpl<Object, Object>> createCaches(int numCaches, boolean useBuddyPool, boolean useDataGravitation, boolean optimisticLocks) throws Exception
+ protected List<CacheSPI<Object, Object>> createCaches(int numCaches, boolean useBuddyPool, boolean useDataGravitation, boolean optimisticLocks) throws Exception
{
return createCaches(1, numCaches, useBuddyPool, useDataGravitation, optimisticLocks);
}
- protected List<CacheImpl<Object, Object>> createCaches(int numCaches, boolean useBuddyPool, boolean useDataGravitation) throws Exception
+ protected List<CacheSPI<Object, Object>> createCaches(int numCaches, boolean useBuddyPool, boolean useDataGravitation) throws Exception
{
return createCaches(1, numCaches, useBuddyPool, useDataGravitation);
}
- protected List<CacheImpl<Object, Object>> createCachesWithCacheLoader(int numCaches, boolean useDataGravitation, boolean removeOnFind, boolean passivation) throws Exception
+ protected List<CacheSPI<Object, Object>> createCachesWithCacheLoader(int numCaches, boolean useDataGravitation, boolean removeOnFind, boolean passivation) throws Exception
{
return this.createCachesWithCacheLoader(numCaches, useDataGravitation, removeOnFind, passivation, false);
}
- protected List<CacheImpl<Object, Object>> createCachesWithCacheLoader(int numCaches, boolean useDataGravitation, boolean removeOnFind, boolean passivation, boolean fetchPersistent) throws Exception
+ protected List<CacheSPI<Object, Object>> createCachesWithCacheLoader(int numCaches, boolean useDataGravitation, boolean removeOnFind, boolean passivation, boolean fetchPersistent) throws Exception
{
- List<CacheImpl<Object, Object>> caches = new ArrayList<CacheImpl<Object, Object>>();
+ List<CacheSPI<Object, Object>> caches = new ArrayList<CacheSPI<Object, Object>>();
for (int i = 0; i < numCaches; i++)
{
caches.add(createCacheWithCacheLoader(useDataGravitation, removeOnFind, passivation, fetchPersistent, true));
}
// allow some time for the caches to start up and discover each other
- TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheImpl[0]), VIEW_BLOCK_TIMEOUT);
+ TestingUtil.blockUntilViewsReceived(caches.toArray(new Cache[0]), VIEW_BLOCK_TIMEOUT);
TestingUtil.sleepThread(getSleepTimeout());
return caches;
}
- protected CacheImpl<Object, Object> createCacheWithCacheLoader(boolean useDataGravitation, boolean removeOnFind, boolean passivation, boolean fetchPersistent, boolean start) throws Exception
+ protected CacheSPI createCacheWithCacheLoader(boolean useDataGravitation, boolean removeOnFind, boolean passivation, boolean fetchPersistent, boolean start) throws Exception
{
- CacheImpl<Object, Object> cache = createCache(1, null, useDataGravitation, removeOnFind, false);
+ CacheSPI cache = createCache(1, null, useDataGravitation, removeOnFind, false);
String cloader = "<config>\n" +
- "<passivation>" + passivation + "</passivation>\n" +
- "<preload></preload>\n" +
+ "<passivation>" + passivation + "</passivation>\n" +
+ "<preload></preload>\n" +
- "<cacheloader>\n" +
- "<class>"+ DummyInMemoryCacheLoader.class.getName() +"</class>\n" +
- "<async>false</async>\n" +
- "<shared>false</shared>\n" +
- "<fetchPersistentState>" + fetchPersistent + "</fetchPersistentState>\n" +
- "</cacheloader>\n" +
- "</config>";
+ "<cacheloader>\n" +
+ "<class>" + DummyInMemoryCacheLoader.class.getName() + "</class>\n" +
+ "<async>false</async>\n" +
+ "<shared>false</shared>\n" +
+ "<fetchPersistentState>" + fetchPersistent + "</fetchPersistentState>\n" +
+ "</cacheloader>\n" +
+ "</config>";
Element element = XmlHelper.stringToElement(cloader);
CacheLoaderConfig cfg = XmlConfigurationParser.parseCacheLoaderConfig(element);
@@ -247,24 +247,24 @@
return cache;
}
- protected List<CacheImpl<Object, Object>> createCaches(int numBuddies, int numCaches, boolean useBuddyPool) throws Exception
+ protected List<CacheSPI<Object, Object>> createCaches(int numBuddies, int numCaches, boolean useBuddyPool) throws Exception
{
return createCaches(numBuddies, numCaches, useBuddyPool, false);
}
- protected List<CacheImpl<Object, Object>> createCaches(int numBuddies, int numCaches, boolean useBuddyPool, boolean useDataGravitation) throws Exception
+ protected List<CacheSPI<Object, Object>> createCaches(int numBuddies, int numCaches, boolean useBuddyPool, boolean useDataGravitation) throws Exception
{
return createCaches(numBuddies, numCaches, useBuddyPool, useDataGravitation, false);
}
- protected List<CacheImpl<Object, Object>> createCaches(int numBuddies, int numCaches, boolean useBuddyPool, boolean useDataGravitation, boolean optimisticLocks) throws Exception
+ protected List<CacheSPI<Object, Object>> createCaches(int numBuddies, int numCaches, boolean useBuddyPool, boolean useDataGravitation, boolean optimisticLocks) throws Exception
{
- List<CacheImpl<Object, Object>> caches = new ArrayList<CacheImpl<Object, Object>>(numCaches);
+ List<CacheSPI<Object, Object>> caches = new ArrayList<CacheSPI<Object, Object>>(numCaches);
for (int i = 0; i < numCaches; i++)
caches.add(createCache(optimisticLocks, numBuddies, useBuddyPool ? Character.toString((char) ('A' + i)) : null, useDataGravitation, true));
// allow some time for the caches to start up and discover each other
- TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheImpl[0]), VIEW_BLOCK_TIMEOUT);
+ TestingUtil.blockUntilViewsReceived(caches.toArray(new Cache[0]), VIEW_BLOCK_TIMEOUT);
TestingUtil.sleepThread(getSleepTimeout());
return caches;
@@ -312,7 +312,7 @@
assertTrue(buddyLocalAddress + " should be a buddy to " + group.getGroupName(), group.getBuddies().contains(buddyLocalAddress));
}
- protected void dumpCacheContents(List<CacheImpl<Object, Object>> caches)
+ protected void dumpCacheContents(List<CacheSPI<Object, Object>> caches)
{
System.out.println("**** START: Cache Contents ****");
for (int i = 0; i < caches.size(); i++)
@@ -324,17 +324,17 @@
else
{
System.out.println(" ** Cache " + i + " is " + caches.get(i).getLocalAddress());
- System.out.println(" " + caches.get(i).printLockInfo());
+ System.out.println(" " + CachePrinter.printCacheLockingInfo(caches.get(i)));
}
}
System.out.println("**** END: Cache Contents ****");
}
- protected void assertNoLocks(List<CacheImpl<Object, Object>> caches)
+ protected void assertNoLocks(List<CacheSPI<Object, Object>> caches)
{
for (Cache cache : caches)
{
- if (cache != null) assertEquals(0, ((CacheImpl) cache).getNumberOfLocksHeld());
+ if (cache != null) assertEquals(0, ((CacheSPI) cache).getNumberOfLocksHeld());
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationWithCacheLoaderTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,15 +6,8 @@
*/
package org.jboss.cache.buddyreplication;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
import org.jboss.cache.Cache;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
@@ -23,14 +16,20 @@
import org.jboss.cache.eviction.LRUConfiguration;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.Test;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
/**
* Tests use of the data gravitator alongside other cache loaders as well as data gravitator options such as removeOnFind.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
-@Test (groups = {"functional"})
+@Test(groups = {"functional"})
public class BuddyReplicationWithCacheLoaderTest extends BuddyReplicationTestsBase
{
@@ -40,7 +39,7 @@
protected boolean passivation = false;
- private CacheLoader[] getLoaders(List<CacheImpl<Object, Object>> caches)
+ private CacheLoader[] getLoaders(List<CacheSPI<Object, Object>> caches)
{
CacheLoader[] retVal = new CacheLoader[caches.size()];
@@ -90,6 +89,7 @@
// request data from cache2
if (!autoGravitate)
caches.get(2).getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
+
assertEquals(value, caches.get(2).get(fqn, key));
assertNoLocks(caches);
@@ -146,7 +146,7 @@
/**
* Tests data gravitation when "removeOnFind=false"; i.e. nodes
* from which data is gravitated evict it instead of removing it.
- *
+ *
* @throws Exception
*/
public void testWithDataGravitationEvictOnFind() throws Exception
@@ -155,10 +155,10 @@
}
/**
- * Tests data gravitation when auto-gravitation is disabled and
- * "removeOnFind=false"; i.e. nodes from which data is gravitated
+ * Tests data gravitation when auto-gravitation is disabled and
+ * "removeOnFind=false"; i.e. nodes from which data is gravitated
* evict it instead of removing it.
- *
+ *
* @throws Exception
*/
public void testWithDataGravitationEvictOnFindNoAuto() throws Exception
@@ -228,30 +228,30 @@
assertTrue("should not exist in loaders2", !loaders[2].exists(b1));
assertTrue("should not exist in loaders2", !loaders[2].exists(b2));
}
-
+
/**
* Tests whether nodes that have been evicted can successfully be
* gravitated.
- *
+ *
* @throws Exception
*/
public void testLocalGravitationOfEvictedNodes() throws Exception
{
- CacheImpl<Object,Object> cache1 = createCacheWithCacheLoader(true, true, passivation, true, false);
+ CacheSPI<Object, Object> cache1 = createCacheWithCacheLoader(true, true, passivation, true, false);
Configuration cfg1 = cache1.getConfiguration();
configureEviction(cfg1);
Configuration cfg0 = cfg1.clone();
- CacheImpl<Object,Object> cache0 = (CacheImpl<Object,Object>) DefaultCacheFactory.getInstance().createCache(cfg0, false);
-
+ CacheSPI<Object, Object> cache0 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(cfg0, false);
+
// Store them for the teardown method
if (caches == null)
- caches = new ArrayList<CacheImpl<Object,Object>>();
+ caches = new ArrayList<CacheSPI<Object, Object>>();
caches.add(cache0);
caches.add(cache1);
-
+
cache0.start();
cache1.start();
-
+
TestingUtil.blockUntilViewsReceived(caches.toArray(new Cache[caches.size()]), VIEW_BLOCK_TIMEOUT * caches.size());
TestingUtil.sleepThread(getSleepTimeout());
@@ -271,69 +271,68 @@
assert !cache1.exists(backupFoo) : "Buddy should have data evicted";
// now test that this exists in both loaders.
- assert cache0.getCacheLoader().get(foo) != null : "Should exist in data owner's cache loader";
- assert cache1.getCacheLoader().get(backupFoo) != null : "Should exist in buddy's loader";
+ assert cache0.getCacheLoaderManager().getCacheLoader().get(foo) != null : "Should exist in data owner's cache loader";
+ assert cache1.getCacheLoaderManager().getCacheLoader().get(backupFoo) != null : "Should exist in buddy's loader";
-
// a local gravitation should occur since cache1 has foo in it's backup tree.
assertEquals("Passivated value available from buddy", "value", cache1.get(foo, "key"));
}
/**
- * Tests whether nodes that have been evicted can successfully be
- * gravitated.
- *
- * @throws Exception
- */
- public void testRemoteGravitationOfEvictedNodes() throws Exception
- {
- CacheImpl<Object,Object> cache0 = createCacheWithCacheLoader(true, true, passivation, true, false);
- Configuration cfg0 = cache0.getConfiguration();
- configureEviction(cfg0);
- Configuration cfg1 = cfg0.clone();
- CacheImpl<Object,Object> cache1 = (CacheImpl<Object,Object>) DefaultCacheFactory.getInstance().createCache(cfg1, false);
- Configuration cfg2 = cfg0.clone();
- CacheImpl<Object,Object> cache2 = (CacheImpl<Object,Object>) DefaultCacheFactory.getInstance().createCache(cfg2, false);
+ * Tests whether nodes that have been evicted can successfully be
+ * gravitated.
+ *
+ * @throws Exception
+ */
+ public void testRemoteGravitationOfEvictedNodes() throws Exception
+ {
+ CacheSPI<Object, Object> cache0 = createCacheWithCacheLoader(true, true, passivation, true, false);
+ Configuration cfg0 = cache0.getConfiguration();
+ configureEviction(cfg0);
+ Configuration cfg1 = cfg0.clone();
+ CacheSPI<Object, Object> cache1 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(cfg1, false);
+ Configuration cfg2 = cfg0.clone();
+ CacheSPI<Object, Object> cache2 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(cfg2, false);
- // Store them for the teardown method
- if (caches == null)
- caches = new ArrayList<CacheImpl<Object,Object>>();
- caches.add(cache0);
- caches.add(cache1);
- caches.add(cache2);
+ // Store them for the teardown method
+ if (caches == null)
+ caches = new ArrayList<CacheSPI<Object, Object>>();
+ caches.add(cache0);
+ caches.add(cache1);
+ caches.add(cache2);
- cache0.start();
- cache1.start();
- cache2.start();
+ cache0.start();
+ cache1.start();
+ cache2.start();
- TestingUtil.blockUntilViewsReceived(caches.toArray(new Cache[caches.size()]), 600000);
- TestingUtil.sleepThread(getSleepTimeout());
+ TestingUtil.blockUntilViewsReceived(caches.toArray(new Cache[caches.size()]), 600000);
+ TestingUtil.sleepThread(getSleepTimeout());
- assert (cache0.getBuddyManager().getBuddyAddresses().contains(cache1.getLocalAddress())) : "Cache1 should be cache0's buddy!";
+ assert (cache0.getBuddyManager().getBuddyAddresses().contains(cache1.getLocalAddress())) : "Cache1 should be cache0's buddy!";
- Fqn foo = Fqn.fromString("/foo");
- Fqn backupFoo = BuddyManager.getBackupFqn(cache0.getLocalAddress(), foo);
- cache0.put(foo, "key", "value");
+ Fqn foo = Fqn.fromString("/foo");
+ Fqn backupFoo = BuddyManager.getBackupFqn(cache0.getLocalAddress(), foo);
+ cache0.put(foo, "key", "value");
- // test that the data exists in both the data owner and the buddy
- assert cache0.exists(foo) : "Data should exist in data owner";
- assert cache1.exists(backupFoo) : "Buddy should have data";
+ // test that the data exists in both the data owner and the buddy
+ assert cache0.exists(foo) : "Data should exist in data owner";
+ assert cache1.exists(backupFoo) : "Buddy should have data";
- // Sleep long enough for eviction to run twice plus a bit
- TestingUtil.sleepThread(3050);
+ // Sleep long enough for eviction to run twice plus a bit
+ TestingUtil.sleepThread(3050);
- // test that the data we're looking for has been evicted in both the data owner and the buddy.
- assert !cache0.exists(foo) : "Data should have evicted in data owner";
- assert !cache1.exists(backupFoo) : "Buddy should have data evicted";
+ // test that the data we're looking for has been evicted in both the data owner and the buddy.
+ assert !cache0.exists(foo) : "Data should have evicted in data owner";
+ assert !cache1.exists(backupFoo) : "Buddy should have data evicted";
- // now test that this exists in both loaders.
- assert cache0.getCacheLoader().get(foo) != null : "Should exist in data owner's loader";
- assert cache1.getCacheLoader().get(backupFoo) != null : "Should exist in buddy's loader";
+ // now test that this exists in both loaders.
+ assert cache0.getCacheLoaderManager().getCacheLoader().get(foo) != null : "Should exist in data owner's loader";
+ assert cache1.getCacheLoaderManager().getCacheLoader().get(backupFoo) != null : "Should exist in buddy's loader";
- // doing a get on cache2 will guarantee a remote data gravitation.
- assertEquals("Passivated value available from buddy", "value", cache2.get(foo, "key"));
- }
+ // doing a get on cache2 will guarantee a remote data gravitation.
+ assertEquals("Passivated value available from buddy", "value", cache2.get(foo, "key"));
+ }
private void configureEviction(Configuration cfg)
{
Modified: core/trunk/src/test/java/org/jboss/cache/config/ChannelInjectionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/ChannelInjectionTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/config/ChannelInjectionTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,19 +1,18 @@
package org.jboss.cache.config;
-import static org.testng.AssertJUnit.assertEquals;
-
-import java.util.HashSet;
-import java.util.Set;
-
import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.misc.TestingUtil;
import org.jgroups.JChannel;
+import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
+import java.util.HashSet;
+import java.util.Set;
+
/**
* Tests that JBC prefers an injected Channel to creating one via
* a configured JChannelFactory and stack name.
@@ -21,7 +20,7 @@
* @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
* @version $Revision$
*/
-@Test(groups={"functional"})
+@Test(groups = {"functional"})
public class ChannelInjectionTest
{
private Set<Cache<String, String>> caches = new HashSet<Cache<String, String>>();
@@ -63,7 +62,7 @@
assertEquals("Value replicated", "value", cache2.get(fqn, "key"));
}
- private Cache<String, String> createCache() throws Exception
+ private Cache<String, String> createCache()
{
Configuration config = new Configuration();
config.setCacheMode(Configuration.CacheMode.REPL_SYNC);
Modified: core/trunk/src/test/java/org/jboss/cache/demo/JBossCacheGUI.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/demo/JBossCacheGUI.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/demo/JBossCacheGUI.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -187,7 +187,6 @@
{
log.trace("clicked on node in GUI");
}
- ;
Runnable r = new Runnable()
{
@@ -206,8 +205,8 @@
catch (TimeoutException te)
{
String message = "Unable to update GUI due to a timeout trying to acquire lock on a node." +
- "This might be due to clicking on a node which is currently locked by an ongoing " +
- "transaction: ";
+ "This might be due to clicking on a node which is currently locked by an ongoing " +
+ "transaction: ";
printAndLogStacktrace(message, te);
}
catch (Exception e)
@@ -396,8 +395,8 @@
catch (TimeoutException te)
{
String message = "Unable to update GUI due to a timeout trying to acquire lock on a node." +
- "This might be due to clicking on a node which is currently locked by an ongoing " +
- "transaction: ";
+ "This might be due to clicking on a node which is currently locked by an ongoing " +
+ "transaction: ";
printAndLogStacktrace(message, te);
}
catch (Exception e)
@@ -417,14 +416,14 @@
protected String getWelcomeMessage()
{
return "Welcome to the BeanShell console.\n\n" +
- "This console gives you a direct shell interface to the GUI above and allows you to manipulate the cache directly. " +
- "Some of the variables initialised in this shell session are:\n\n" +
- "// an instance of org.jboss.cache\n" +
- " Cache<String, String> cache;\n" +
- "// a reference to the root node\n" +
- " Node<String, String> root;\n" +
- "// the transaction manager registered with the cache\n" +
- " TransactionManager transactionManager;\n";
+ "This console gives you a direct shell interface to the GUI above and allows you to manipulate the cache directly. " +
+ "Some of the variables initialised in this shell session are:\n\n" +
+ "// an instance of org.jboss.cache\n" +
+ " Cache<String, String> cache;\n" +
+ "// a reference to the root node\n" +
+ " Node<String, String> root;\n" +
+ "// the transaction manager registered with the cache\n" +
+ " TransactionManager transactionManager;\n";
}
protected void configureInterpreter(Interpreter interpreter, CacheModelDelegate cacheDelegate) throws EvalError
@@ -885,18 +884,18 @@
fqnTextField.setText(Fqn.SEPARATOR);
}
Object[] information = {"Enter fully qualified name",
- fqnTextField};
+ fqnTextField};
final String btnString1 = "OK";
final String btnString2 = "Cancel";
Object[] options = {btnString1, btnString2};
int userChoice = JOptionPane.showOptionDialog(null,
- information,
- "Add DataNode",
- JOptionPane.YES_NO_OPTION,
- JOptionPane.PLAIN_MESSAGE,
- null,
- options,
- options[0]);
+ information,
+ "Add DataNode",
+ JOptionPane.YES_NO_OPTION,
+ JOptionPane.PLAIN_MESSAGE,
+ null,
+ options,
+ options[0]);
if (userChoice == 0)
{
String userInput = fqnTextField.getText();
@@ -922,18 +921,18 @@
}
Object[] information = {"Enter fully qualified name",
- fqnTextField};
+ fqnTextField};
final String btnString1 = "OK";
final String btnString2 = "Cancel";
Object[] options = {btnString1, btnString2};
int userChoice = JOptionPane.showOptionDialog(null,
- information,
- "Load DataNode",
- JOptionPane.YES_NO_OPTION,
- JOptionPane.PLAIN_MESSAGE,
- null,
- options,
- options[0]);
+ information,
+ "Load DataNode",
+ JOptionPane.YES_NO_OPTION,
+ JOptionPane.PLAIN_MESSAGE,
+ null,
+ options,
+ options[0]);
if (userChoice == 0)
{
String userInput = fqnTextField.getText();
@@ -958,18 +957,18 @@
fqnTextField.setText(Fqn.SEPARATOR);
}
Object[] information = {"Enter fully qualified name",
- fqnTextField};
+ fqnTextField};
final String btnString1 = "OK";
final String btnString2 = "Cancel";
Object[] options = {btnString1, btnString2};
int userChoice = JOptionPane.showOptionDialog(null,
- information,
- "Evict DataNode",
- JOptionPane.YES_NO_OPTION,
- JOptionPane.PLAIN_MESSAGE,
- null,
- options,
- options[0]);
+ information,
+ "Evict DataNode",
+ JOptionPane.YES_NO_OPTION,
+ JOptionPane.PLAIN_MESSAGE,
+ null,
+ options,
+ options[0]);
if (userChoice == 0)
{
String userInput = fqnTextField.getText();
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizePolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizePolicyTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/ElementSizePolicyTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,19 +6,17 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.lock.IsolationLevel;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+
/**
* @author Daniel Huang
* @version $Revison: $
@@ -26,7 +24,7 @@
@Test(groups = {"functional"})
public class ElementSizePolicyTest
{
- CacheImpl<Object, Object> cache;
+ CacheSPI<Object, Object> cache;
int wakeupIntervalMillis = 0;
final String ROOT_STR = "/test";
Throwable t1_ex, t2_ex;
@@ -50,7 +48,7 @@
void initCaches() throws Exception
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/local-elementsize-eviction-service.xml", false);// read in generic local xml
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/local-elementsize-eviction-service.xml", false);// read in generic local xml
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
cache.start();
@@ -93,7 +91,7 @@
for (int i = 0; i < 10; i++)
{
- Node node = cache.get("/org/jboss/test/data/" + Integer.toString(i));
+ Node node = cache.getNode("/org/jboss/test/data/" + Integer.toString(i));
System.out.println(node);
if (i % 2 == 0)
{
@@ -128,18 +126,13 @@
}
}
- System.out.println(cache.toString(true));
_sleep(wakeupIntervalMillis + 500);
- System.out.println(cache.toString(true));
- System.out.println("*******");
- System.out.println(cache.printLockInfo());
-
for (int i = 0; i < 20; i++)
{
String str = rootStr + Integer.toString(i);
Fqn fqn = Fqn.fromString(str);
- Node node = cache.get(fqn);
+ Node node = cache.getNode(fqn);
System.out.println(i + " " + node);
if (i > 9)
{
@@ -156,11 +149,11 @@
cache.put("/org/jboss/data/" + Integer.toString(3), 100 + i, "value");
}
- Node node = cache.get("/org/jboss/data/" + Integer.toString(3));
+ Node node = cache.getNode("/org/jboss/data/" + Integer.toString(3));
assertEquals(21, node.getData().size());
_sleep(wakeupIntervalMillis + 500);
- assertNull(cache.get("/org/jboss/data/" + Integer.toString(3)));
+ assertNull(cache.getNode("/org/jboss/data/" + Integer.toString(3)));
}
class MyPutter extends Thread
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/EvictionConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/EvictionConfigurationTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/EvictionConfigurationTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,16 +6,15 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-
-import org.jboss.cache.CacheImpl;
+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.EvictionPolicyConfig;
import org.jboss.cache.lock.IsolationLevel;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.Test;
/**
@@ -27,7 +26,7 @@
@Test(groups = {"functional"})
public class EvictionConfigurationTest
{
- CacheImpl<Object, Object> cache;
+ CacheSPI<Object, Object> cache;
RegionManager regionManager;
public void testPolicyPerRegion() throws Exception
@@ -194,14 +193,14 @@
public void testNoEviction() throws Exception
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache();
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache();
regionManager = cache.getRegionManager();
assertEquals(0, regionManager.getAllRegions(Region.Type.ANY).size());
}
- private void setupCache(String configurationName) throws Exception
+ private void setupCache(String configurationName)
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(configurationName, false);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(configurationName, false);
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
cache.start();
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationPolicyTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/ExpirationPolicyTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,13 +6,9 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
@@ -20,6 +16,7 @@
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionPolicyConfig;
import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -35,7 +32,7 @@
{
private static final Log log = LogFactory.getLog(ExpirationPolicyTest.class);
- private CacheImpl<Object, Object> cache;
+ private CacheSPI<Object, Object> cache;
Fqn fqn1 = Fqn.fromString("/node/1");
Fqn fqn2 = Fqn.fromString("/node/2");
@@ -48,12 +45,11 @@
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
Configuration conf = cache.getConfiguration();
EvictionConfig econf = new EvictionConfig(ExpirationPolicy.class.getName());
econf.setWakeupIntervalSeconds(1);
conf.setEvictionConfig(econf);
- cache.setConfiguration(conf);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(conf, false);
cache.start();
future = System.currentTimeMillis() + 4000;
@@ -73,27 +69,27 @@
cache.put(fqn3, ExpirationConfiguration.EXPIRATION_KEY, future);
cache.put(fqn4, "foo", "bar");
TestingUtil.sleepThread(2000);
- assertNotNull(cache.get(fqn1));
- assertNull(cache.get(fqn2));
- assertNotNull(cache.get(fqn3));
- assertNotNull(cache.get(fqn4));
+ assertNotNull(cache.getNode(fqn1));
+ assertNull(cache.getNode(fqn2));
+ assertNotNull(cache.getNode(fqn3));
+ assertNotNull(cache.getNode(fqn4));
log.info("should remove 1 and 3 now");
TestingUtil.sleepThread(3000);
- assertNull(cache.get(fqn1));
- assertNull(cache.get(fqn3));
+ assertNull(cache.getNode(fqn1));
+ assertNull(cache.getNode(fqn3));
}
public void testUpdate() throws Exception
{
log.info("update 1 from future to past");
cache.put(fqn1, ExpirationConfiguration.EXPIRATION_KEY, future);
- assertNotNull(cache.get(fqn1));
+ assertNotNull(cache.getNode(fqn1));
TestingUtil.sleepThread(1500);
cache.put(fqn1, ExpirationConfiguration.EXPIRATION_KEY, past);
TestingUtil.sleepThread(1500);
- assertNull(cache.get(fqn1));
- cache.remove(Fqn.ROOT);
+ assertNull(cache.getNode(fqn1));
+ cache.removeNode(Fqn.ROOT);
}
@@ -103,13 +99,13 @@
Long future2 = future + 2000;
cache.put(fqn1, ExpirationConfiguration.EXPIRATION_KEY, future);
TestingUtil.sleepThread(2000);
- assertNotNull(cache.get(fqn1));
+ assertNotNull(cache.getNode(fqn1));
cache.put(fqn1, ExpirationConfiguration.EXPIRATION_KEY, future2);
TestingUtil.sleepThread(3000);
- assertNotNull(cache.get(fqn1));
+ assertNotNull(cache.getNode(fqn1));
TestingUtil.sleepThread(3000);
- assertNull(cache.get(fqn1));
- cache.remove(Fqn.ROOT);
+ assertNull(cache.getNode(fqn1));
+ cache.removeNode(Fqn.ROOT);
}
public void testMaxNodes() throws Exception
@@ -125,10 +121,10 @@
cache.put(fqn4, ExpirationConfiguration.EXPIRATION_KEY, past);
assertEquals(5, cache.getNumberOfNodes());
Thread.sleep(2000);
- assertNotNull(cache.get(fqn1));
- assertNotNull(cache.get(fqn2));
- assertNull(cache.get(fqn3));
- assertNull(cache.get(fqn4));
+ assertNotNull(cache.getNode(fqn1));
+ assertNotNull(cache.getNode(fqn2));
+ assertNull(cache.getNode(fqn3));
+ assertNull(cache.getNode(fqn4));
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/FIFOPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/FIFOPolicyTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/FIFOPolicyTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,16 +6,12 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -29,7 +25,7 @@
@Test(groups = {"functional"})
public class FIFOPolicyTest
{
- CacheImpl<Object, Object> cache;
+ CacheSPI<Object, Object> cache;
int wakeupIntervalMillis = 0;
final String ROOT_STR = "/test";
Throwable t1_ex, t2_ex;
@@ -53,7 +49,7 @@
void initCaches() throws Exception
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/local-fifo-eviction-service.xml", false);// read in generic local xml
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/local-fifo-eviction-service.xml", false);// read in generic local xml
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
cache.start();
@@ -83,10 +79,7 @@
}
}
- System.out.println(cache.toString(true));
TestingUtil.sleepThread(wakeupIntervalMillis + 500);
-
- System.out.println(cache.toString(true));
try
{
String val = (String) cache.get(rootStr + "3", rootStr + "3");
@@ -121,8 +114,8 @@
for (int i = 0; i < maxNodes; i++)
{
String n = rootStr + i;
- assertNull("DataNode should be empty " + cache.get(n) + " " + n,
- cache.get(n, n));
+ assertNull("DataNode should be empty " + cache.getNode(n) + " " + n,
+ cache.get(n, n));
}
for (int i = maxNodes; i < maxNodes * 2; i++)
@@ -157,7 +150,6 @@
e.printStackTrace();
}
}
- System.out.println("cache is:\n" + cache.toString(true));
int period = wakeupIntervalMillis + 500;
@@ -227,11 +219,11 @@
{
assertNotNull(cache.get(fqn2, str2));
assertNotNull(cache.get(fqn1, str1));
- cache.remove(fqn2);
+ cache.removeNode(fqn2);
TestingUtil.sleepThread(period);
assertNull(cache.get(fqn2, str2));
assertNotNull(cache.get(fqn1, str1));
- cache.remove(fqn1);
+ cache.removeNode(fqn1);
TestingUtil.sleepThread(period);
assertNull(cache.get(fqn1, str1));
assertNull(cache.get(fqn2, str2));
@@ -246,7 +238,7 @@
TestingUtil.sleepThread(period);
// remove the node above fqn4 /org/jboss/test/5 will cascade the delete into /org/jboss/test/5/5
- cache.remove(fqn4);
+ cache.removeNode(fqn4);
TestingUtil.sleepThread(period);
assertNull(cache.get(fqn3, str3));
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LFUAlgorithmTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,19 +6,15 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.Iterator;
-
-import org.jboss.cache.CacheImpl;
-import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+
+import java.util.Iterator;
+
/**
* Unit test for LFUAlgorithm.
*
@@ -36,7 +32,7 @@
{
algo = new LFUAlgorithm();
LFUConfiguration config = new LFUConfiguration();
- regionManager = new RegionManager((CacheImpl) DefaultCacheFactory.getInstance().createCache(false));
+ regionManager = new RegionManager();
config.setEvictionPolicyClass(DummyEvictionPolicy.class.getName());
regionManager.getRegion("/a/b", true).setEvictionPolicy(config);
// doesn't this need a cache?!?? :-/
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LFUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LFUPolicyTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LFUPolicyTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,15 +6,12 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -28,7 +25,7 @@
@Test(groups = {"functional"})
public class LFUPolicyTest
{
- CacheImpl<Object, Object> cache;
+ CacheSPI<Object, Object> cache;
int wakeupIntervalMillis = 0;
final String ROOT_STR = "/test";
Throwable t1_ex, t2_ex;
@@ -52,7 +49,7 @@
void initCaches() throws Exception
{
- cache = (CacheImpl<Object, Object>)DefaultCacheFactory.getInstance().createCache("META-INF/local-lfu-eviction-service.xml", false);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/local-lfu-eviction-service.xml", false);
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
cache.start();
@@ -124,15 +121,12 @@
e.printStackTrace();
}
}
- System.out.println("cache is:\n" + cache.toString(true));
int period = wakeupIntervalMillis + 500;
log("sleeping for " + period + "ms");
TestingUtil.sleepThread(period);// it really depends the eviction thread time.
- System.out.println("cache is:\n" + cache.toString(true));
-
try
{
for (int i = 0; i < 5; i++)
@@ -150,8 +144,6 @@
TestingUtil.sleepThread(period);
- System.out.println(cache.toString(true));
-
// since min is 5 the cache won't deplete past 5 nodes left in the cache.
for (int i = 5; i < 10; i++)
{
@@ -185,8 +177,6 @@
TestingUtil.sleepThread(period);
- System.out.println(cache.toString(true));
-
// now make sure we still only have 5 nodes and they are the ones we expect based on LFU
for (int i = 5; i < 7; i++)
{
@@ -259,7 +249,7 @@
{
String str = rootStr + i;
Fqn fqn = Fqn.fromString(str);
- cache.remove(fqn);
+ cache.removeNode(fqn);
}
}
@@ -272,7 +262,7 @@
{
String str = rootStr + i;
Fqn fqn = Fqn.fromString(str);
- assertNull(cache.get(fqn));
+ assertNull(cache.getNode(fqn));
}
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/LRUPolicyTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,16 +1,12 @@
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -25,7 +21,7 @@
@Test(groups = {"functional"})
public class LRUPolicyTest
{
- CacheImpl<Object, Object> cache_;
+ CacheSPI<Object, Object> cache_;
int wakeupIntervalMillis_ = 0;
final String ROOT_STR = "/test";
Throwable t1_ex, t2_ex;
@@ -49,7 +45,7 @@
public void initCaches() throws Exception
{
- cache_ = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/local-lru-eviction-service.xml", false);// read in generic local xml
+ cache_ = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/local-lru-eviction-service.xml", false);// read in generic local xml
cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache_.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
cache_.start();
@@ -90,18 +86,18 @@
for (int i = 0; i < 5; i++)
{
- assertNull(cache_.get(Fqn.fromString(rootStr + i)));
+ assertNull(cache_.getNode(Fqn.fromString(rootStr + i)));
}
- assertNotNull(cache_.get(Fqn.fromString(rootStr + 5)));
+ assertNotNull(cache_.getNode(Fqn.fromString(rootStr + 5)));
for (int i = 6; i < 11; i++)
{
- assertNull(cache_.get(Fqn.fromString(rootStr + i)));
+ assertNull(cache_.getNode(Fqn.fromString(rootStr + i)));
}
for (int i = 11; i < 15; i++)
{
- assertNotNull(cache_.get(Fqn.fromString(rootStr + i)));
+ assertNotNull(cache_.getNode(Fqn.fromString(rootStr + i)));
}
}
@@ -157,7 +153,6 @@
e.printStackTrace();
}
}
- System.out.println("cache is:\n" + cache_.toString(true));
int period = (wakeupIntervalMillis_ / 2 + 500);
log("sleeping for " + period + "ms");
@@ -226,7 +221,7 @@
TestingUtil.sleepThread(period);// it really depends the eviction thread time.
String val = (String) cache_.get(rootStr + "7/7", rootStr + "7/7");
assertNotNull("DataNode should not be empty ", val);
- cache_.remove(fqn1);
+ cache_.removeNode(fqn1);
TestingUtil.sleepThread(wakeupIntervalMillis_ + 500);
val = (String) cache_.get(rootStr + "7/7", rootStr + "7/7");
assertNull("DataNode should be empty ", val);
@@ -364,8 +359,7 @@
}
// clear the root
- Fqn root = cache_.get("/").getFqn();
- cache_.remove(root);
+ cache_.removeNode(Fqn.ROOT);
// wait for an eviction
TestingUtil.sleepThread(2 * wakeupIntervalMillis_ + 1000);
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/MRUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/MRUPolicyTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/MRUPolicyTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,14 +6,11 @@
*/
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -27,7 +24,7 @@
@Test(groups = {"functional"})
public class MRUPolicyTest
{
- CacheImpl<Object, Object> cache;
+ CacheSPI<Object, Object> cache;
int wakeupIntervalMillis = 0;
final String ROOT_STR = "/test";
Throwable t1_ex, t2_ex;
@@ -55,9 +52,9 @@
cache.stop();
}
- private void initCaches() throws Exception
+ private void initCaches()
{
- cache = (CacheImpl<Object,Object>) DefaultCacheFactory.getInstance().createCache("META-INF/local-mru-eviction-service.xml", false);// read in generic local xml
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/local-mru-eviction-service.xml", false);// read in generic local xml
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
cache.start();
@@ -73,8 +70,6 @@
TestingUtil.sleepThread(wakeupIntervalMillis + 500);
- System.out.println(cache.toString(true));
-
cache.put("/org/jboss/test/data/f", "/org/jboss/test/data/f", "/org/jboss/test/data/f");
cache.put("/org/jboss/test/data/g", "/org/jboss/test/data/g", "/org/jboss/test/data/g");
cache.put("/org/jboss/test/data/h", "/org/jboss/test/data/h", "/org/jboss/test/data/h");
@@ -83,8 +78,6 @@
TestingUtil.sleepThread(wakeupIntervalMillis + 500);
- System.out.println(cache.toString(true));
-
assertNull(cache.get("/org/jboss/test/data/a", "/org/jboss/test/data/a"));
assertNull(cache.get("/org/jboss/test/data/b", "/org/jboss/test/data/b"));
}
@@ -99,8 +92,8 @@
TestingUtil.sleepThread(wakeupIntervalMillis + 500);
- cache.remove("/org/jboss/test/data/d");
- cache.remove("/org/jboss/test/data/e");
+ cache.removeNode("/org/jboss/test/data/d");
+ cache.removeNode("/org/jboss/test/data/e");
cache.put("/org/jboss/test/data/f", "/org/jboss/test/data/f", "/org/jboss/test/data/f");
cache.put("/org/jboss/test/data/g", "/org/jboss/test/data/g", "/org/jboss/test/data/g");
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/OptimisticEvictionTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,23 +1,21 @@
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertTrue;
-
-import java.util.Iterator;
-import java.util.List;
-
-import javax.transaction.TransactionManager;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.interceptors.EvictionInterceptor;
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.TransactionManager;
+import java.util.Iterator;
+import java.util.List;
+
/**
* Tests the eviction and the possible lack of locking nodes.
* The configuration is with an aggressive eviction policy, 100 objects 2 seconds interval.
@@ -37,13 +35,13 @@
private Fqn<Object> region = new Fqn<Object>("testingRegion");
private TransactionManager txManager;
- private CacheImpl<Object, Object> cache;
+ private CacheSPI<Object, Object> cache;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
txManager = new DummyTransactionManagerLookup().getTransactionManager();
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/optimistic-eviction.xml");
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/optimistic-eviction.xml");
}
@AfterMethod(alwaysRun = true)
@@ -98,7 +96,7 @@
public void testInterceptorChain() throws Exception
{
- List interceptors = cache.getInterceptors();
+ List interceptors = cache.getInterceptorChain();
System.out.println(interceptors);
Iterator i = interceptors.iterator();
boolean found = false;
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/ProgrammaticLRUPolicyTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -23,11 +23,7 @@
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.RegionManager;
@@ -37,6 +33,7 @@
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.xml.XmlHelper;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -51,7 +48,7 @@
@Test(groups = {"functional"})
public class ProgrammaticLRUPolicyTest
{
- CacheImpl<Object, Object> cache_;
+ CacheSPI<Object, Object> cache_;
int wakeupIntervalMillis_ = 0;
@BeforeMethod(alwaysRun = true)
@@ -67,9 +64,9 @@
}
- private void initCaches() throws Exception
+ private void initCaches()
{
- cache_ = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/local-lru-eviction-service.xml", false);// read in generic local xml
+ cache_ = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/local-lru-eviction-service.xml", false);// read in generic local xml
cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache_.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
@@ -87,9 +84,9 @@
{
// region name is ignored here.
String xml = "<region name=\"/dummy\">" +
- "<attribute name=\"maxNodes\">10000</attribute>" +
- "<attribute name=\"timeToLiveSeconds\">4</attribute>" +
- "</region>";
+ "<attribute name=\"maxNodes\">10000</attribute>" +
+ "<attribute name=\"timeToLiveSeconds\">4</attribute>" +
+ "</region>";
Element element = XmlHelper.stringToElement(xml);
RegionManager regionManager = cache_.getRegionManager();
EvictionConfig topConfig = cache_.getConfiguration().getEvictionConfig();
@@ -125,15 +122,15 @@
{
// region name is ignored here.
String xml = "<region name=\"/dummy\">" +
- "<attribute name=\"maxNodes\">10000</attribute>" +
- "<attribute name=\"timeToLiveSeconds\">4</attribute>" +
- "</region>";
+ "<attribute name=\"maxNodes\">10000</attribute>" +
+ "<attribute name=\"timeToLiveSeconds\">4</attribute>" +
+ "</region>";
Element element = XmlHelper.stringToElement(xml);
RegionManager regionManager = cache_.getRegionManager();
EvictionConfig topEC = cache_.getConfiguration().getEvictionConfig();
EvictionRegionConfig erc = XmlConfigurationParser.parseEvictionRegionConfig(element,
- topEC.getDefaultEvictionPolicyClass(),
- topEC.getDefaultEventQueueSize());
+ topEC.getDefaultEvictionPolicyClass(),
+ topEC.getDefaultEventQueueSize());
// Fqn is the region name
Integer ii = 1;
Fqn fqn = new Fqn<Integer>(ii);
Modified: core/trunk/src/test/java/org/jboss/cache/eviction/ReplicatedLRUPolicyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/eviction/ReplicatedLRUPolicyTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/eviction/ReplicatedLRUPolicyTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,11 +1,6 @@
package org.jboss.cache.eviction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration.CacheMode;
@@ -14,6 +9,8 @@
import org.jboss.cache.notifications.annotation.CacheListener;
import org.jboss.cache.notifications.annotation.NodeEvicted;
import org.jboss.cache.notifications.event.Event;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -24,22 +21,21 @@
@Test(groups = {"functional"})
public class ReplicatedLRUPolicyTest
{
- CacheImpl<Object, Object> cache_, cache1_, cache2_;
+ CacheSPI<Object, Object> cache_, cache1_, cache2_;
int wakeupIntervalMillis_ = 0;
EvictionListener listener_ = new EvictionListener();
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- cache_ = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
- initCaches(cache_);
+ cache_ = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC, true), false);
+ cache_.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
cache_.getConfiguration().setUseRegionBasedMarshalling(true);
cache_.start();
cache_.getNotifier().addCacheListener(listener_);
listener_.resetCounter();
- cache2_ = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
- cache2_.setConfiguration(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC));// read in generic local xml
+ cache2_ = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
cache2_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache2_.getConfiguration().setUseRegionBasedMarshalling(true);
cache2_.start();
@@ -52,12 +48,6 @@
}
}
- void initCaches(CacheImpl cache) throws Exception
- {
- cache.setConfiguration(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC, true));
- cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- }
-
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
Added: core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/factories/ComponentRegistryTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -0,0 +1,171 @@
+package org.jboss.cache.factories;
+
+import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.RPCManager;
+import org.jboss.cache.RegionManager;
+import org.jboss.cache.buddyreplication.BuddyManager;
+import org.jboss.cache.buddyreplication.NextMemberBuddyLocator;
+import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.invocation.CacheInvocationDelegate;
+import org.jboss.cache.marshall.CacheMarshaller200;
+import org.jboss.cache.marshall.CacheMarshaller210;
+import org.jboss.cache.marshall.Marshaller;
+import org.jboss.cache.marshall.VersionAwareMarshaller;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.statetransfer.StateTransferManager;
+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
+ */
+@Test(groups = {"functional"})
+public class ComponentRegistryTest
+{
+ private ComponentFactory cf;
+ private ComponentRegistry cr;
+ private Configuration configuration;
+
+ @BeforeMethod
+ public void setUp() throws Exception
+ {
+ cf = (ComponentFactory) DefaultCacheFactory.getInstance();
+
+ CacheSPI spi = new CacheInvocationDelegate();
+ Constructor ctor = CacheImpl.class.getDeclaredConstructor();
+ ctor.setAccessible(true);
+ CacheImpl ci = (CacheImpl) ctor.newInstance();
+
+ configuration = ci.getConfiguration();
+ cr = TestingUtil.extractComponentRegistry(ci);
+
+ cr.registerComponent(ci);
+ cr.registerComponent(spi);
+ cr.registerComponent(cr); // register self
+ cr.registerComponent(configuration);
+
+ cr.wireDependencies(cf);
+ cr.wireDependencies(ci);
+ cr.wireDependencies(spi);
+ }
+
+ public void testWiringDependenciesInFactory()
+ {
+ assert cf.componentRegistry == cr;
+ assert cf.configuration == configuration;
+ }
+
+ public void testDefaultFactoryScanning()
+ {
+ cr.scanDefaultFactories();
+
+ assert cr.defaultFactories != null : "Should be populated";
+
+ // at very least, expecting a Marshaller factory and a DefaultCacheFactory.
+
+ assert cr.defaultFactories.containsKey(CacheSPI.class);
+ assert cr.defaultFactories.get(CacheSPI.class).equals(DefaultCacheFactory.class);
+ assert cr.defaultFactories.containsKey(Marshaller.class);
+ assert cr.defaultFactories.get(Marshaller.class).equals(CacheMarshallerFactory.class);
+ }
+
+ /**
+ * Case 1:
+ * nothing injected, nothing specified in Configuration. Should use default factory.
+ */
+ public void testConstructionOrder1()
+ {
+ Class<Marshaller> componentToTest = Marshaller.class;
+ Marshaller m = cr.getOrCreateComponent(null, componentToTest);
+ assert m instanceof VersionAwareMarshaller;
+ VersionAwareMarshaller vam = (VersionAwareMarshaller) m;
+ m = (Marshaller) TestingUtil.extractField(vam, "defaultMarshaller");
+ assert m instanceof CacheMarshaller210;
+ }
+
+ /**
+ * Case 2:
+ * instance injected, class specified in Configuration. Should use injected.
+ */
+ public void testConstructionOrder2()
+ {
+ Class<Marshaller> componentToTest = Marshaller.class;
+ configuration.setMarshallerClass(CacheMarshaller200.class.getName());
+ Marshaller instance = new CacheMarshaller210(null, false, false);
+ configuration.setCacheMarshaller(instance);
+
+ // the setup() would have wired the default marshaller. Need to update deps.
+ cr.unregisterComponent(Marshaller.class);
+ cr.updateDependencies();
+
+ Marshaller m = cr.getOrCreateComponent(null, componentToTest);
+ assert m == instance : "m is " + m + " but expected " + instance;
+ }
+
+ /**
+ * Case 3:
+ * instance injected, no class specified in Configuration. Should use injected.
+ */
+ public void testConstructionOrder3()
+ {
+ Class<Marshaller> componentToTest = Marshaller.class;
+ Marshaller instance = new CacheMarshaller210(null, false, false);
+ configuration.setCacheMarshaller(instance);
+
+ // the setup() would have wired the default marshaller. Need to update deps.
+ cr.unregisterComponent(Marshaller.class);
+ cr.updateDependencies();
+
+ Marshaller m = cr.getOrCreateComponent(null, componentToTest);
+ assert m == instance : "m is " + m + " but expected " + instance;
+ }
+
+ /**
+ * Case 4:
+ * nothing injected, class specified in Configuration. Should use class specified.
+ */
+ public void testConstructionOrder4()
+ {
+ Class<Marshaller> componentToTest = Marshaller.class;
+ configuration.setMarshallerClass(CacheMarshaller200.class.getName());
+ Marshaller m = cr.getOrCreateComponent(null, componentToTest);
+ assert m instanceof VersionAwareMarshaller;
+ VersionAwareMarshaller vam = (VersionAwareMarshaller) m;
+ m = (Marshaller) TestingUtil.extractField(vam, "defaultMarshaller");
+ assert m instanceof CacheMarshaller200;
+ }
+
+ public void testTransitiveDependencies()
+ {
+ Class<BuddyManager> componentToTest = BuddyManager.class;
+
+ // configure the cfg to use BR
+ BuddyReplicationConfig brc = new BuddyReplicationConfig();
+ brc.setEnabled(true);
+ BuddyReplicationConfig.BuddyLocatorConfig blc = new BuddyReplicationConfig.BuddyLocatorConfig();
+ blc.setBuddyLocatorClass(NextMemberBuddyLocator.class.getName());
+ brc.setBuddyLocatorConfig(blc);
+ configuration.setBuddyReplicationConfig(brc);
+
+ BuddyManager bm = cr.getOrCreateComponent(null, componentToTest);
+ assert bm != null;
+
+ StateTransferManager stm = (StateTransferManager) TestingUtil.extractField(bm, "stateTransferManager");
+ assert stm != null;
+
+ RPCManager rpcm = (RPCManager) TestingUtil.extractField(bm, "rpcManager");
+ assert rpcm != null;
+
+ RegionManager rm = (RegionManager) TestingUtil.extractField(bm, "regionManager");
+ assert rm != null;
+
+ Configuration cfg = (Configuration) TestingUtil.extractField(bm, "configuration");
+ assert cfg == configuration;
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,45 +1,23 @@
package org.jboss.cache.factories;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-
-import java.util.Iterator;
-import java.util.List;
-
import junit.framework.Assert;
-
import org.jboss.cache.CacheImpl;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.interceptors.ActivationInterceptor;
-import org.jboss.cache.interceptors.CacheLoaderInterceptor;
-import org.jboss.cache.interceptors.CacheMgmtInterceptor;
-import org.jboss.cache.interceptors.CacheStoreInterceptor;
-import org.jboss.cache.interceptors.CallInterceptor;
-import org.jboss.cache.interceptors.DataGravitatorInterceptor;
-import org.jboss.cache.interceptors.EvictionInterceptor;
-import org.jboss.cache.interceptors.Interceptor;
-import org.jboss.cache.interceptors.InvalidationInterceptor;
-import org.jboss.cache.interceptors.InvocationContextInterceptor;
-import org.jboss.cache.interceptors.NotificationInterceptor;
-import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
-import org.jboss.cache.interceptors.OptimisticLockingInterceptor;
-import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
-import org.jboss.cache.interceptors.OptimisticReplicationInterceptor;
-import org.jboss.cache.interceptors.OptimisticValidatorInterceptor;
-import org.jboss.cache.interceptors.PassivationInterceptor;
-import org.jboss.cache.interceptors.PessimisticLockInterceptor;
-import org.jboss.cache.interceptors.ReplicationInterceptor;
-import org.jboss.cache.interceptors.TxInterceptor;
-import org.jboss.cache.interceptors.UnlockInterceptor;
+import org.jboss.cache.interceptors.*;
import org.jboss.cache.xml.XmlHelper;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
+import java.util.Iterator;
+import java.util.List;
+
@Test(groups = {"functional"})
public class InterceptorChainFactoryTest extends InterceptorChainTestBase
{
@@ -65,7 +43,7 @@
public void testBareConfig() throws Exception
{
cache.getConfiguration().setExposeManagementStatistics(false);
- Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain(cache);
+ Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain();
List<Interceptor> list = InterceptorChainFactory.getInstance().asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
@@ -89,7 +67,7 @@
cache.getConfiguration().setExposeManagementStatistics(false);
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain(cache);
+ Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain();
List<Interceptor> list = InterceptorChainFactory.getInstance().asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
@@ -110,21 +88,21 @@
protected CacheLoaderConfig getCacheLoaderConfig(boolean pasv, boolean fetchPersistentState) throws Exception
{
String xml = " <config>\n" +
- " \n" +
- " <passivation>" + pasv + "</passivation>\n" +
- " <preload></preload>\n" +
- "\n" +
- " <cacheloader>\n" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
- " <properties>\n" +
- " location=/tmp\n" +
- " </properties>\n" +
- " <async>false</async>\n" +
- " <fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
- " <ignoreModifications>false</ignoreModifications>\n" +
- " </cacheloader>\n" +
- " \n" +
- " </config>";
+ " \n" +
+ " <passivation>" + pasv + "</passivation>\n" +
+ " <preload></preload>\n" +
+ "\n" +
+ " <cacheloader>\n" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
+ " <properties>\n" +
+ " location=/tmp\n" +
+ " </properties>\n" +
+ " <async>false</async>\n" +
+ " <fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
+ " <ignoreModifications>false</ignoreModifications>\n" +
+ " </cacheloader>\n" +
+ " \n" +
+ " </config>";
Element element = XmlHelper.stringToElement(xml);
return XmlConfigurationParser.parseCacheLoaderConfig(element);
}
@@ -137,7 +115,7 @@
cache.getConfiguration().setCacheMode("REPL_ASYNC");
cache.getConfiguration().setFetchInMemoryState(false);
cache.create();
- Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain(cache);
+ Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain();
List<Interceptor> list = InterceptorChainFactory.getInstance().asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
@@ -167,7 +145,7 @@
cache.getConfiguration().setCacheMode("REPL_ASYNC");
cache.getConfiguration().setFetchInMemoryState(false);
cache.create();
- Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain(cache);
+ Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain();
List<Interceptor> list = InterceptorChainFactory.getInstance().asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
@@ -194,7 +172,7 @@
cache.getConfiguration().setExposeManagementStatistics(false);
cache.getConfiguration().setCacheMode("repl_sync");
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain(cache);
+ Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain();
List<Interceptor> list = InterceptorChainFactory.getInstance().asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
@@ -221,7 +199,7 @@
cache.getConfiguration().setExposeManagementStatistics(false);
cache.getConfiguration().setNodeLockingOptimistic(true);
- Interceptor next = InterceptorChainFactory.getInstance().buildInterceptorChain(cache);
+ Interceptor next = InterceptorChainFactory.getInstance().buildInterceptorChain();
// test the chain size.
List<Interceptor> list = InterceptorChainFactory.getInstance().asList(next);
@@ -248,7 +226,7 @@
cache.getConfiguration().setNodeLockingOptimistic(true);
cache.getConfiguration().setCacheMode("REPL_SYNC");
- Interceptor next = InterceptorChainFactory.getInstance().buildInterceptorChain(cache);
+ Interceptor next = InterceptorChainFactory.getInstance().buildInterceptorChain();
// test the chain size.
List<Interceptor> list = InterceptorChainFactory.getInstance().asList(next);
@@ -276,7 +254,7 @@
cache.getConfiguration().setNodeLockingOptimistic(true);
cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig(false, false));
cache.create();
- Interceptor next = InterceptorChainFactory.getInstance().buildInterceptorChain(cache);
+ Interceptor next = InterceptorChainFactory.getInstance().buildInterceptorChain();
// test the chain size.
List<Interceptor> list = InterceptorChainFactory.getInstance().asList(next);
@@ -305,7 +283,7 @@
cache.getConfiguration().setNodeLockingOptimistic(true);
cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig(true, false));
cache.create();
- Interceptor next = InterceptorChainFactory.getInstance().buildInterceptorChain(cache);
+ Interceptor next = InterceptorChainFactory.getInstance().buildInterceptorChain();
// test the chain size.
List<Interceptor> list = InterceptorChainFactory.getInstance().asList(next);
@@ -334,7 +312,7 @@
cache.getConfiguration().setExposeManagementStatistics(false);
cache.getConfiguration().setCacheMode("REPL_ASYNC");
- Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain(cache);
+ Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain();
// test the chain size.
List<Interceptor> list = InterceptorChainFactory.getInstance().asList(chain);
@@ -356,7 +334,7 @@
cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
cache.getConfiguration().setExposeManagementStatistics(false);
cache.getConfiguration().setCacheMode("INVALIDATION_ASYNC");
- chain = InterceptorChainFactory.getInstance().buildInterceptorChain(cache);
+ chain = InterceptorChainFactory.getInstance().buildInterceptorChain();
// test the chain size.
list = InterceptorChainFactory.getInstance().asList(chain);
@@ -378,7 +356,7 @@
public void testCacheMgmtConfig() throws Exception
{
cache.getConfiguration().setExposeManagementStatistics(true);
- Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain(cache);
+ Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain();
List<Interceptor> list = InterceptorChainFactory.getInstance().asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
@@ -410,7 +388,7 @@
}
}
);
- Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain(cache);
+ Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain();
List<Interceptor> list = InterceptorChainFactory.getInstance().asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
@@ -433,9 +411,9 @@
public void testBuddyReplicationOptLocking() throws Exception
{
String xmlString = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled>\n" +
- "<buddyCommunicationTimeout>600000</buddyCommunicationTimeout>\n" +
- " <buddyLocatorClass>org.jboss.cache.buddyreplication.NextMemberBuddyLocator</buddyLocatorClass>\n" +
- " <buddyLocatorProperties>numBuddies = 1</buddyLocatorProperties>\n";
+ "<buddyCommunicationTimeout>600000</buddyCommunicationTimeout>\n" +
+ " <buddyLocatorClass>org.jboss.cache.buddyreplication.NextMemberBuddyLocator</buddyLocatorClass>\n" +
+ " <buddyLocatorProperties>numBuddies = 1</buddyLocatorProperties>\n";
xmlString += "<buddyPoolName>buddyPoolName</buddyPoolName>";
xmlString += "</config>";
@@ -446,7 +424,7 @@
cache.getConfiguration().setCacheMode("REPL_SYNC");
cache.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
cache.create();// initialise various subsystems such as BRManager
- Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain(cache);
+ Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain();
List<Interceptor> list = InterceptorChainFactory.getInstance().asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
@@ -473,9 +451,9 @@
public void testBuddyReplicationPessLocking() throws Exception
{
String xmlString = "<config><buddyReplicationEnabled>true</buddyReplicationEnabled>\n" +
- "<buddyCommunicationTimeout>600000</buddyCommunicationTimeout>\n" +
- " <buddyLocatorClass>org.jboss.cache.buddyreplication.NextMemberBuddyLocator</buddyLocatorClass>\n" +
- " <buddyLocatorProperties>numBuddies = 1</buddyLocatorProperties>\n";
+ "<buddyCommunicationTimeout>600000</buddyCommunicationTimeout>\n" +
+ " <buddyLocatorClass>org.jboss.cache.buddyreplication.NextMemberBuddyLocator</buddyLocatorClass>\n" +
+ " <buddyLocatorProperties>numBuddies = 1</buddyLocatorProperties>\n";
xmlString += "<buddyPoolName>buddyPoolName</buddyPoolName>";
xmlString += "</config>";
@@ -485,7 +463,7 @@
cache.getConfiguration().setCacheMode("REPL_SYNC");
cache.create();// initialise various subsystems such as BRManager
- Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain(cache);
+ Interceptor chain = InterceptorChainFactory.getInstance().buildInterceptorChain();
List<Interceptor> list = InterceptorChainFactory.getInstance().asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
Added: core/trunk/src/test/java/org/jboss/cache/factories/annotations/ClasspathScannerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/annotations/ClasspathScannerTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/factories/annotations/ClasspathScannerTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -0,0 +1,26 @@
+package org.jboss.cache.factories.annotations;
+
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.factories.CacheMarshallerFactory;
+import org.jboss.cache.factories.ComponentFactory;
+import org.testng.annotations.Test;
+
+import java.util.Set;
+
+/**
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.1.0
+ */
+@Test(groups = {"functional"})
+public class ClasspathScannerTest
+{
+ public void testScanning()
+ {
+ ClasspathScanner cs = new ClasspathScanner();
+ Set<Class<? extends ComponentFactory>> sc = cs.scan(DefaultFactoryFor.class, ComponentFactory.class);
+
+ // should at least contain these 2.
+ assert sc.contains(DefaultCacheFactory.class);
+ assert sc.contains(CacheMarshallerFactory.class);
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/interceptors/EvictionInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/interceptors/EvictionInterceptorTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/interceptors/EvictionInterceptorTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,16 +6,7 @@
*/
package org.jboss.cache.interceptors;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
@@ -26,14 +17,20 @@
import org.jboss.cache.eviction.DummyEvictionConfiguration;
import org.jboss.cache.eviction.EvictedEventNode;
import org.jboss.cache.eviction.NodeEventType;
+import org.jboss.cache.factories.InterceptorChainFactory;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodCallFactory;
import org.jboss.cache.marshall.MethodDeclarations;
+import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* @author Daniel Huang (dhuang(a)jboss.org)
* @version $Revision: $
@@ -47,7 +44,7 @@
private static final String fqn4 = "/d/e/f";
- private CacheImpl<Object, Object> cache;
+ private CacheSPI<Object, Object> cache;
private Interceptor interceptor;
private RegionManager regionManager;
@@ -68,37 +65,31 @@
regionManager.getRegion("/d/e/g", true).setEvictionPolicy(config);
regionManager.getRegion("/d/e", true).setEvictionPolicy(config);
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
- // make the interceptor chain (separate from the CacheImpl object.
+ // make the interceptor chain (separate from the CacheSPI object.
interceptor = new CacheMgmtInterceptor();
- interceptor.setCache(cache);
TxInterceptor ti = new TxInterceptor();
- ti.setCache(cache);
interceptor.setNext(ti);
UnlockInterceptor ui = new UnlockInterceptor();
- ui.setCache(cache);
ti.setNext(ui);
PessimisticLockInterceptor pli = new PessimisticLockInterceptor();
- pli.setCache(cache);
ui.setNext(pli);
EvictionInterceptor ei = new EvictionInterceptor();
- ei.setCache(cache);
- ei.setRegionManager(regionManager);
pli.setNext(ei);
CallInterceptor ci = new CallInterceptor();
- ci.setCache(cache);
- ci.setTreeCacheInstance(cache);
ei.setNext(ci);
+ InterceptorChainFactory.getInstance().correctInterceptorChaining(interceptor, cache.getConfiguration(), TestingUtil.extractComponentRegistry(cache));
+
cache.getConfiguration().setCacheMode("LOCAL");
cache.start();
}
@@ -106,7 +97,7 @@
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
- cache.remove("/");
+ cache.removeNode(Fqn.ROOT);
cache.stop();
}
@@ -121,26 +112,26 @@
// make sure node that doesn't exist does not result in a node visit event.
MethodCall mc = MethodCallFactory.create(MethodDeclarations.getNodeMethodLocal,
- Fqn.fromString(fqn1));
+ Fqn.fromString(fqn1));
interceptor.invoke(InvocationContext.fromMethodCall(mc));
Region regionABC = regionManager.getRegion(fqn1, false);
assertNull(regionABC.takeLastEventNode());
cache.put(fqn1, "key", "value");
assertEquals("value", cache.get(fqn1, "key"));
- Node<Object, Object> node = cast(cache.get(fqn1));
+ Node<Object, Object> node = cast(cache.getNode(fqn1));
assertNotNull(node);
assertEquals("value", node.get("key"));
cache.put(fqn3, "key", "value");
assertEquals("value", cache.get(fqn3, "key"));
- node = cast(cache.get(fqn3));
+ node = cast(cache.getNode(fqn3));
assertNotNull(node);
assertEquals("value", node.get("key"));
mc = MethodCallFactory.create(MethodDeclarations.getNodeMethodLocal,
- Fqn.fromString(fqn1));
+ Fqn.fromString(fqn1));
interceptor.invoke(InvocationContext.fromMethodCall(mc));
regionABC = regionManager.getRegion(fqn1, false);
@@ -150,7 +141,7 @@
assertNull(regionABC.takeLastEventNode());
mc = MethodCallFactory.create(MethodDeclarations.getNodeMethodLocal,
- Fqn.fromString(fqn2));
+ Fqn.fromString(fqn2));
interceptor.invoke(InvocationContext.fromMethodCall(mc));
Region regionAB = regionManager.getRegion(fqn2, false);
@@ -266,7 +257,7 @@
{
key = i;
- cache.put(fqn.toString(), key, "");
+ cache.put(fqn, key, "");
mc = MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn, key, true);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
@@ -282,11 +273,11 @@
assertNull(region.takeLastEventNode());
// check null handling
- mc = MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, null, key, true);
+ mc = MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, key, true);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
assertNull(region.takeLastEventNode());
- mc = MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, null, null, true);
+ mc = MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, null, true);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
assertNull(region.takeLastEventNode());
@@ -306,7 +297,7 @@
// this region is node granularity
Fqn fqn = Fqn.fromString("/a/b/c");
- MethodCall mc = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal, null, fqn, data, false);
+ MethodCall mc = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal, fqn, data, false);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
Region region = regionManager.getRegion(fqn.toString(), false);
@@ -316,7 +307,7 @@
assertEquals(fqn, event.getFqn());
assertEquals(100, event.getElementDifference());
- Node<Object, Object> node = cast(cache.get(fqn.toString()));
+ Node<Object, Object> node = cast(cache.getNode(fqn));
assertNotNull(node);
for (int i = 0; i < 100; i++)
@@ -327,11 +318,11 @@
for (int i = 0; i < 100; i++)
{
- mc = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, null, fqn, i,
- "value", false);
+ mc = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, fqn, i,
+ "value", false);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
- assertEquals("value", cache.get(fqn.toString(), i));
+ assertEquals("value", cache.get(fqn, i));
}
for (int i = 0; i < 100; i++)
@@ -345,7 +336,7 @@
assertNull(region.takeLastEventNode());
fqn = Fqn.fromString("/a/b");
- mc = MethodCallFactory.create(MethodDeclarations.putDataEraseMethodLocal, null, fqn, data, false, false);
+ mc = MethodCallFactory.create(MethodDeclarations.putDataEraseMethodLocal, fqn, data, false, false);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
event = regionManager.getRegion(fqn.toString(), false).takeLastEventNode();
assertFalse(event.isResetElementCount());
@@ -353,7 +344,7 @@
assertEquals(fqn, event.getFqn());
assertEquals(100, event.getElementDifference());
assertNull(regionManager.getRegion(fqn.toString(), false).takeLastEventNode());
- node = cast(cache.get(fqn.toString()));
+ node = cast(cache.getNode(fqn));
assertEquals(100, node.getData().size());
assertNotNull(node);
@@ -364,7 +355,7 @@
assertEquals(i, node.get(i));
}
- mc = MethodCallFactory.create(MethodDeclarations.putDataEraseMethodLocal, null, fqn, data, false, true);
+ mc = MethodCallFactory.create(MethodDeclarations.putDataEraseMethodLocal, fqn, data, false, true);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
event = regionManager.getRegion(fqn.toString(), false).takeLastEventNode();
assertEquals(NodeEventType.ADD_NODE_EVENT, event.getEventType());
@@ -374,7 +365,7 @@
assertNull(regionManager.getRegion(fqn.toString(), false).takeLastEventNode());
- node = cast(cache.get(fqn.toString()));
+ node = cast(cache.getNode(fqn));
assertEquals(100, node.getData().size());
assertNotNull(node);
@@ -394,7 +385,7 @@
Object value = "value";
MethodCall mc = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal,
- null, fqn, key, value, false);
+ fqn, key, value, false);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
assertEquals("value", cache.get(fqn, key));
EvictedEventNode event = region.takeLastEventNode();
@@ -405,7 +396,7 @@
assertNull(region.takeLastEventNode());
mc = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal,
- null, fqn, key, value, false);
+ fqn, key, value, false);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
assertEquals("value", cache.get(fqn, key));
event = region.takeLastEventNode();
@@ -423,20 +414,20 @@
cache.put(fqn, "a", "b");
cache.put(fqn, "b", "c");
- MethodCall mc = MethodCallFactory.create(MethodDeclarations.removeDataMethodLocal, null, fqn, false);
+ MethodCall mc = MethodCallFactory.create(MethodDeclarations.removeDataMethodLocal, fqn, false);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
- assertEquals(0, cache.get(fqn).getData().size());
+ assertEquals(0, cache.getNode(fqn).getData().size());
Region region = regionManager.getRegion(fqn.toString(), false);
EvictedEventNode event = region.takeLastEventNode();
assertEquals(NodeEventType.REMOVE_NODE_EVENT, event.getEventType());
assertEquals(fqn, event.getFqn());
assertNull(region.takeLastEventNode());
- mc = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, null, fqn, false);
+ mc = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, fqn, false);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
- assertNull(cache.get(fqn));
+ assertNull(cache.getNode(fqn));
event = region.takeLastEventNode();
assertEquals(NodeEventType.REMOVE_NODE_EVENT, event.getEventType());
assertEquals(fqn, event.getFqn());
@@ -450,7 +441,7 @@
cache.put(fqn, "b", "c");
MethodCall mc = MethodCallFactory.create(MethodDeclarations.removeKeyMethodLocal,
- null, fqn, "a", false);
+ fqn, "a", false);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
assertNull(cache.get(fqn, "a"));
@@ -462,7 +453,7 @@
assertNull(region.takeLastEventNode());
mc = MethodCallFactory.create(MethodDeclarations.removeKeyMethodLocal,
- null, fqn, "b", false);
+ fqn, "b", false);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
assertNull(cache.get(fqn, "b"));
@@ -473,7 +464,7 @@
assertNull(region.takeLastEventNode());
mc = MethodCallFactory.create(MethodDeclarations.removeKeyMethodLocal,
- null, fqn, "b", false);
+ fqn, "b", false);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
event = region.takeLastEventNode();
@@ -491,7 +482,7 @@
// this region is node granularity
Fqn fqn = Fqn.fromString("/a/b/c");
- MethodCall mc = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal, null, fqn, data, false);
+ MethodCall mc = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal, fqn, data, false);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
Region region = regionManager.getRegion(fqn.toString(), false);
@@ -503,16 +494,16 @@
assertNull(region.takeLastEventNode());
mc = MethodCallFactory.create(MethodDeclarations.getNodeMethodLocal,
- fqn);
+ fqn);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
event = region.takeLastEventNode();
assertEquals(NodeEventType.VISIT_NODE_EVENT, event.getEventType());
assertEquals(fqn, event.getFqn());
assertNull(region.takeLastEventNode());
- mc = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, null, fqn, false);
+ mc = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, fqn, false);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
- assertNull(cache.get(fqn));
+ assertNull(cache.getNode(fqn));
event = region.takeLastEventNode();
assertEquals(NodeEventType.REMOVE_NODE_EVENT, event.getEventType());
assertEquals(fqn, event.getFqn());
@@ -521,7 +512,7 @@
Object key = "key";
Object value = "value";
mc = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal,
- null, fqn, key, value, false);
+ fqn, key, value, false);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
assertEquals("value", cache.get(fqn, key));
event = region.takeLastEventNode();
@@ -540,7 +531,7 @@
assertNull(region.takeLastEventNode());
mc = MethodCallFactory.create(MethodDeclarations.removeKeyMethodLocal,
- null, fqn, key, false);
+ fqn, key, false);
interceptor.invoke(InvocationContext.fromMethodCall(mc));
assertNull(cache.get(fqn, key));
Modified: core/trunk/src/test/java/org/jboss/cache/interceptors/InterceptorCacheReferenceTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/interceptors/InterceptorCacheReferenceTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/interceptors/InterceptorCacheReferenceTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,12 +6,11 @@
*/
package org.jboss.cache.interceptors;
-import static org.testng.AssertJUnit.assertSame;
-
import org.jboss.cache.Cache;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.Configuration;
+import static org.testng.AssertJUnit.assertSame;
import org.testng.annotations.Test;
/**
@@ -44,7 +43,7 @@
cache.stop();
}
- private void assertInterceptorsHaveSameCache(CacheSPI<?, ?> c) throws Exception
+ private void assertInterceptorsHaveSameCache(CacheSPI<?, ?> c)
{
for (Interceptor i : c.getInterceptorChain())
{
Modified: core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -9,7 +9,6 @@
import junit.framework.Assert;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheImpl;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
@@ -42,14 +41,14 @@
public class InvalidationInterceptorTest
{
private static Log log = LogFactory.getLog(InvalidationInterceptorTest.class);
- private CacheImpl<Object, Object> cache1, cache2;
- private Set<CacheImpl> toClean = new HashSet<CacheImpl>();
+ private CacheSPI<Object, Object> cache1, cache2;
+ private Set<CacheSPI> toClean = new HashSet<CacheSPI>();
@AfterMethod
public void tearDown()
{
TestingUtil.killCaches(cache1, cache2);
- for (CacheImpl c : toClean) TestingUtil.killCaches(c);
+ for (CacheSPI c : toClean) TestingUtil.killCaches(c);
toClean.clear();
}
@@ -64,7 +63,7 @@
// test that this has NOT replicated, but rather has been invalidated:
Assert.assertEquals("value", cache1.get(fqn, "key"));
- Assert.assertNull("Should NOT have replicated!", cache2.get(fqn));
+ Assert.assertNull("Should NOT have replicated!", cache2.getNode(fqn));
log.info("***** Node not replicated, as expected.");
@@ -72,14 +71,14 @@
cache2.put(fqn, "key", "value");
// since the node already exists even PL will not remove it - but will invalidate it's data
- Node n = cache1.get(fqn);
+ Node n = cache1.getNode(fqn);
assertHasBeenInvalidated(n, "Should have been invalidated");
Assert.assertEquals("value", cache2.get(fqn, "key"));
// now test the invalidation:
cache1.put(fqn, "key2", "value2");
Assert.assertEquals("value2", cache1.get(fqn, "key2"));
- n = cache2.get(fqn);
+ n = cache2.getNode(fqn);
assertHasBeenInvalidated(n, "Should have been invalidated");
}
@@ -124,16 +123,14 @@
TestingUtil.sleepThread(500);// give it time to broadcast the evict call
// test that this has NOT replicated, but rather has been invalidated:
Assert.assertEquals("value", cache1.get(fqn, "key"));
- Assert.assertNull("Should NOT have replicated!", cache2.get(fqn));
+ Assert.assertNull("Should NOT have replicated!", cache2.getNode(fqn));
- log.info("***** Node not replicated, as expected.");
-
// now make sure cache2 is in sync with cache1:
cache2.put(fqn, "key", "value");
TestingUtil.sleepThread(500);// give it time to broadcast the evict call
- // since the node already exists even PL will not remove it - but will invalidate it's data
- Node n = cache1.get(fqn);
+ // since the node already exists even PL will not remove it - but will invalidate it's data
+ Node n = cache1.getNode(fqn);
assertHasBeenInvalidated(n, "Should have been invalidated");
Assert.assertEquals("value", cache2.get(fqn, "key"));
@@ -141,9 +138,9 @@
cache1.put(fqn, "key2", "value2");
Assert.assertEquals("value2", cache1.get(fqn, "key2"));
TestingUtil.sleepThread(500);// give it time to broadcast the evict call
-
+
// since the node already exists even PL will not remove it - but will invalidate it's data
- n = cache2.get(fqn);
+ n = cache2.getNode(fqn);
assertHasBeenInvalidated(n, "Should have been invalidated");
}
@@ -158,7 +155,7 @@
// test that this has NOT replicated, but rather has been invalidated:
Assert.assertEquals("value", cache1.get(fqn, "key"));
- Assert.assertNull("Should NOT have replicated!", cache2.get(fqn));
+ Assert.assertNull("Should NOT have replicated!", cache2.getNode(fqn));
log.info("***** Node not replicated, as expected.");
@@ -172,8 +169,8 @@
Assert.assertEquals("value", cache2.get(fqn, "key"));
txm.commit();
- // since the node already exists even PL will not remove it - but will invalidate it's data
- Node n = cache1.get(fqn);
+ // since the node already exists even PL will not remove it - but will invalidate it's data
+ Node n = cache1.getNode(fqn);
assertHasBeenInvalidated(n, "Should have been invalidated");
Assert.assertEquals("value", cache2.get(fqn, "key"));
@@ -188,7 +185,7 @@
Assert.assertEquals("value2", cache1.get(fqn, "key2"));
// since the node already exists even PL will not remove it - but will invalidate it's data
- n = cache2.get(fqn);
+ n = cache2.getNode(fqn);
assertHasBeenInvalidated(n, "Should have been invalidated");
// test a rollback
@@ -201,7 +198,7 @@
txm.rollback();
Assert.assertEquals("value2", cache1.get(fqn, "key2"));
- n = cache2.get(fqn);
+ n = cache2.getNode(fqn);
assertHasBeenInvalidated(n, "Should have been invalidated");
}
@@ -215,7 +212,7 @@
cache2.put(fqn, "key", "value");
Assert.assertEquals("value", cache2.get(fqn, "key"));
- Node n = cache1.get(fqn);
+ Node n = cache1.getNode(fqn);
assertHasBeenInvalidated(n, "Should have been invalidated");
assertHasBeenInvalidated(cache1.peek(fqn, true, true), "Should have been invalidated");
@@ -262,7 +259,7 @@
cache1.put("/a/b", "key", "value");
Assert.assertEquals("value", cache1.get(fqn, "key"));
- Assert.assertNull(cache2.get(fqn));
+ Assert.assertNull(cache2.getNode(fqn));
// start a tx that cacahe1 will have to send out an evict ...
TransactionManager mgr1 = cache1.getTransactionManager();
@@ -311,7 +308,7 @@
cache1.put("/a/b", "key", "value");
Assert.assertEquals("value", cache1.get(fqn, "key"));
- Assert.assertNull(cache2.get(fqn));
+ Assert.assertNull(cache2.getNode(fqn));
// start a tx that cacahe1 will have to send out an evict ...
TransactionManager mgr1 = cache1.getTransactionManager();
@@ -356,7 +353,7 @@
{
nodeRemovalTest(true);
}
-
+
@SuppressWarnings("unchecked")
private void nodeRemovalTest(boolean optimistic) throws Exception
{
@@ -395,7 +392,7 @@
checkRemoteNodeIsRemoved(remoteNode);
assertEquals(false, cache1.removeNode(fqn));
}
-
+
private void checkRemoteNodeIsRemoved(Node<Object, Object> remoteNode)
{
assertHasBeenInvalidated(remoteNode, "Should have been removed");
@@ -408,15 +405,17 @@
}
}
}
-
- public void testPessimisticNodeResurrection() throws Exception {
+
+ public void testPessimisticNodeResurrection() throws Exception
+ {
nodeResurrectionTest(false);
}
-
- public void testOptimisticNodeResurrection() throws Exception {
+
+ public void testOptimisticNodeResurrection() throws Exception
+ {
nodeResurrectionTest(true);
}
-
+
private void nodeResurrectionTest(boolean optimistic) throws Exception
{
cache1 = createCache(optimistic);
@@ -463,7 +462,7 @@
private void dumpVersionInfo(CacheSPI c1, CacheSPI c2, Fqn fqn)
{
- System.out.println("**** Versin Info for Fqn ["+fqn+"] ****");
+ System.out.println("**** Versin Info for Fqn [" + fqn + "] ****");
NodeSPI n1 = c1.getRoot().getChildDirect(fqn);
System.out.println(" Cache 1: " + n1.getVersion() + " dataLoaded? " + n1.isDataLoaded());
@@ -484,7 +483,7 @@
// test that this has NOT replicated, but rather has been invalidated:
Assert.assertEquals("value", cache1.get(fqn, "key"));
- Node n2 = cache2.get(fqn);
+ Node n2 = cache2.getNode(fqn);
assertHasBeenInvalidated(n2, "Should have been invalidated");
assertHasBeenInvalidated(cache2.peek(fqn, true, true), "Should have been invalidated");
@@ -493,7 +492,7 @@
dumpVersionInfo(cache1, cache2, fqn);
- Node n1 = cache1.get(fqn);
+ Node n1 = cache1.getNode(fqn);
assertHasBeenInvalidated(n1, "Should have been invalidated");
assertHasBeenInvalidated(cache1.peek(fqn, true, true), "Should have been invalidated");
@@ -505,7 +504,7 @@
dumpVersionInfo(cache1, cache2, fqn);
Assert.assertEquals("value2", cache1.get(fqn, "key2"));
- n2 = cache2.get(fqn);
+ n2 = cache2.getNode(fqn);
assertHasBeenInvalidated(n2, "Should have been invalidated");
assertHasBeenInvalidated(cache2.peek(fqn, false, false), "Should have been invalidated");
@@ -518,7 +517,7 @@
Assert.assertEquals("value2", cache1.get(fqn, "key2"));
txm.commit();
- n1 = cache1.get(fqn);
+ n1 = cache1.getNode(fqn);
assertHasBeenInvalidated(n1, "Should have been invalidated");
assertHasBeenInvalidated(cache1.peek(fqn, false, false), "Should have been invalidated");
Assert.assertEquals("value", cache2.get(fqn, "key"));
@@ -533,7 +532,7 @@
txm.commit();
Assert.assertEquals("value2", cache1.get(fqn, "key2"));
- n2 = cache2.get(fqn);
+ n2 = cache2.getNode(fqn);
assertHasBeenInvalidated(n2, "Should have been invalidated");
assertHasBeenInvalidated(cache2.peek(fqn, false, false), "Should have been invalidated");
@@ -547,14 +546,14 @@
txm.rollback();
Assert.assertEquals("value2", cache1.get(fqn, "key2"));
- n2 = cache2.get(fqn);
+ n2 = cache2.getNode(fqn);
assertHasBeenInvalidated(n2, "Should have been invalidated");
- assertHasBeenInvalidated(cache2.peek(fqn, false, false), "Should have been invalidated");
+ assertHasBeenInvalidated(cache2.peek(fqn, false, false), "Should have been invalidated");
}
public void testPessimisticNonTransactionalWithCacheLoader() throws Exception
{
- List<CacheImpl<Object, Object>> caches = createCachesWithSharedCL(false);
+ List<CacheSPI<Object, Object>> caches = createCachesWithSharedCL(false);
cache1 = caches.get(0);
cache2 = caches.get(1);
@@ -579,7 +578,7 @@
public void testPessimisticTransactionalWithCacheLoader() throws Exception
{
- List<CacheImpl<Object,Object>> caches = createCachesWithSharedCL(false);
+ List<CacheSPI<Object, Object>> caches = createCachesWithSharedCL(false);
cache1 = caches.get(0);
cache2 = caches.get(1);
@@ -606,7 +605,7 @@
public void testOptimisticWithCacheLoader() throws Exception
{
- List<CacheImpl<Object, Object>> caches = createCachesWithSharedCL(true);
+ List<CacheSPI<Object, Object>> caches = createCachesWithSharedCL(true);
cache1 = caches.get(0);
cache2 = caches.get(1);
@@ -616,7 +615,7 @@
Assert.assertNull("Should be null", caches.get(1).get(fqn, "key"));
mgr.begin();
caches.get(0).put(fqn, "key", "value");
- Assert.assertEquals("value", caches.get(0).get(fqn, "key"));
+ Assert.assertEquals("value", caches.get(0).get(fqn, "key"));
Assert.assertNull("Should be null", caches.get(1).get(fqn, "key"));
mgr.commit();
Assert.assertEquals("value", caches.get(1).get(fqn, "key"));
@@ -645,7 +644,7 @@
protected void doRegionBasedTest(boolean optimistic) throws Exception
{
- List<CacheImpl<Object,Object>> caches = new ArrayList<CacheImpl<Object, Object>>();
+ List<CacheSPI<Object, Object>> caches = new ArrayList<CacheSPI<Object, Object>>();
caches.add(createUnstartedCache(false));
caches.add(createUnstartedCache(false));
cache1 = caches.get(0);
@@ -663,28 +662,28 @@
caches.get(0).start();
caches.get(1).start();
- TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheImpl[0]), 5000);
+ TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheSPI[0]), 5000);
Fqn fqn = Fqn.fromString("/a/b");
- assertNull("Should be null", caches.get(0).get(fqn));
- assertNull("Should be null", caches.get(1).get(fqn));
+ assertNull("Should be null", caches.get(0).getNode(fqn));
+ assertNull("Should be null", caches.get(1).getNode(fqn));
caches.get(0).put(fqn, "key", "value");
assertEquals("expecting value", "value", caches.get(0).get(fqn, "key"));
- Node n = caches.get(1).get(fqn);
+ Node n = caches.get(1).getNode(fqn);
assertHasBeenInvalidated(n, "Should have been invalidated");
// now put in caches.get(1), should fire an eviction
caches.get(1).put(fqn, "key", "value2");
assertEquals("expecting value2", "value2", caches.get(1).get(fqn, "key"));
- n = caches.get(0).get(fqn);
+ n = caches.get(0).getNode(fqn);
assertHasBeenInvalidated(n, "Should have been invalidated");
}
- protected CacheImpl<Object, Object> createUnstartedCache(boolean optimistic) throws Exception
+ protected CacheSPI<Object, Object> createUnstartedCache(boolean optimistic) throws Exception
{
- CacheImpl<Object, Object> cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
cache.getConfiguration().setClusterName("MyCluster");
cache.getConfiguration().setStateRetrievalTimeout(3000);
cache.getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
@@ -694,17 +693,17 @@
return cache;
}
- protected CacheImpl<Object, Object> createCache(boolean optimistic) throws Exception
+ protected CacheSPI<Object, Object> createCache(boolean optimistic) throws Exception
{
- CacheImpl<Object, Object> cache = createUnstartedCache(optimistic);
+ CacheSPI<Object, Object> cache = createUnstartedCache(optimistic);
cache.start();
toClean.add(cache);
return cache;
}
- protected List<CacheImpl<Object, Object>> createCachesWithSharedCL(boolean optimistic) throws Exception
+ protected List<CacheSPI<Object, Object>> createCachesWithSharedCL(boolean optimistic) throws Exception
{
- List<CacheImpl<Object, Object>> caches = new ArrayList<CacheImpl<Object, Object>>();
+ List<CacheSPI<Object, Object>> caches = new ArrayList<CacheSPI<Object, Object>>();
caches.add(createUnstartedCache(optimistic));
caches.add(createUnstartedCache(optimistic));
@@ -721,17 +720,17 @@
protected CacheLoaderConfig getCacheLoaderConfig() throws Exception
{
String xml = " <config>\n" +
- " <shared>shared</shared>\n" +
- " <passivation>false</passivation>\n" +
- " <preload></preload>\n" +
- " <cacheloader>\n" +
- " <class>org.jboss.cache.loader.DummySharedInMemoryCacheLoader</class>\n" +
- " <async>false</async>\n" +
- " <fetchPersistentState>false</fetchPersistentState>\n" +
- " <ignoreModifications>false</ignoreModifications>\n" +
- " </cacheloader>\n" +
- " \n" +
- " </config>";
+ " <shared>shared</shared>\n" +
+ " <passivation>false</passivation>\n" +
+ " <preload></preload>\n" +
+ " <cacheloader>\n" +
+ " <class>org.jboss.cache.loader.DummySharedInMemoryCacheLoader</class>\n" +
+ " <async>false</async>\n" +
+ " <fetchPersistentState>false</fetchPersistentState>\n" +
+ " <ignoreModifications>false</ignoreModifications>\n" +
+ " </cacheloader>\n" +
+ " \n" +
+ " </config>";
Element element = XmlHelper.stringToElement(xml);
return XmlConfigurationParser.parseCacheLoaderConfig(element);
}
Modified: core/trunk/src/test/java/org/jboss/cache/invalidation/TombstoneEvictionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/TombstoneEvictionTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/TombstoneEvictionTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,6 +1,6 @@
package org.jboss.cache.invalidation;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
@@ -22,10 +22,10 @@
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 2.1.0
*/
-@Test (groups = {"functional"})
+@Test(groups = {"functional"})
public class TombstoneEvictionTest
{
- private CacheImpl c1, c2;
+ private CacheSPI c1, c2;
private Fqn fqn = Fqn.fromString("/data/test");
private Fqn dummy = Fqn.fromString("/data/dummy");
private long evictionWaitTime = 2100;
@@ -33,8 +33,7 @@
@BeforeMethod
public void setUp() throws Exception
{
- c1 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
- c2 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
+ c1 = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
// the FIFO policy cfg
FIFOConfiguration cfg = new FIFOConfiguration();
@@ -60,7 +59,7 @@
c1.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
c1.getConfiguration().setEvictionConfig(ec);
- c2.setConfiguration(c1.getConfiguration().clone());
+ c2 = (CacheSPI) DefaultCacheFactory.getInstance().createCache(c1.getConfiguration().clone(), false);
c1.start();
c2.start();
@@ -107,7 +106,7 @@
assert c2.peek(fqn, false, true) == null : "Should have evicted";
assert c2.peek(dummy, false, true) != null : "Node should exist";
}
-
+
public void testWithTombstones()
{
c1.put(fqn, "k", "v");
Modified: core/trunk/src/test/java/org/jboss/cache/invalidation/VersionInconsistencyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/VersionInconsistencyTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/VersionInconsistencyTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -91,7 +91,7 @@
assert val.equals("v-newer");
// test node versions
- NodeSPI n = (NodeSPI) ((CacheImpl) cache1).peek(node, true, true);
+ NodeSPI n = ((CacheImpl) cache1).peek(node, true, true);
assert ((DefaultDataVersion) n.getVersion()).getRawVersion() == 1 : "Version should be 1";
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/jmx/NotificationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/NotificationTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/NotificationTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,23 +1,8 @@
package org.jboss.cache.jmx;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertTrue;
-
-import java.util.EnumSet;
-import java.util.HashMap;
-
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.Notification;
-import javax.management.NotificationListener;
-import javax.management.ObjectName;
-
import junit.framework.AssertionFailedError;
-
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.CacheLoaderConfig;
@@ -27,18 +12,27 @@
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.xml.XmlHelper;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import java.util.EnumSet;
+import java.util.HashMap;
+
/**
* Functional tests for CacheJmxWrapper broadcast of cache event notifications
*
* @author Jerry Gauthier
* @version $Id$
*/
-@Test(groups={"functional"})
+@Test(groups = {"functional"})
public class NotificationTest
{
protected static final String CLUSTER_NAME = "NotificationTestCluster";
@@ -59,7 +53,7 @@
protected MBeanServer m_server;
protected EnumSet<Type> events = EnumSet.noneOf(Type.class);
- protected CacheImpl<Object, Object> cache = null;
+ protected CacheSPI<Object, Object> cache = null;
protected boolean optimistic = false;
@BeforeMethod(alwaysRun = true)
@@ -161,10 +155,10 @@
assertNotNull("Retrieval error: expected to retrieve " + CURRENCY + " for " + key, cache.get(key, CURRENCY));
// remove the node - this will trigger NodeRemoved and NodeRemove(pre/post)
- cache.remove(key);
+ cache.removeNode(key);
// clean up before stopping the cache
- CacheLoader cl = cache.getCacheLoader();
+ CacheLoader cl = cache.getCacheLoaderManager().getCacheLoader();
cl.remove(Fqn.fromString(EUROPE_NODE));
// stop the cache
@@ -235,7 +229,7 @@
m_server.addNotificationListener(mgmt, listener, null, null);
// add a node - this will trigger NodeCreated, NodeModify(pre/post) and NodeModified
- HashMap<String, String> albania = new HashMap<String, String>(4);
+ HashMap<Object, Object> albania = new HashMap<Object, Object>(4);
albania.put(CAPITAL, "Tirana");
albania.put(CURRENCY, "Lek");
cache.put("Europe/Albania", albania);
@@ -283,11 +277,11 @@
}
}
- private CacheImpl<Object, Object> createCache(String clusterName) throws Exception
+ private CacheSPI<Object, Object> createCache(String clusterName) throws Exception
{
Configuration config = createConfiguration(clusterName);
CacheFactory<Object, Object> factory = DefaultCacheFactory.getInstance();
- CacheImpl<Object, Object> cache = (CacheImpl<Object, Object>)factory.createCache(config, false);
+ CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) factory.createCache(config, false);
cache.create();
// start the cache after the listener has been registered
@@ -329,17 +323,17 @@
protected static CacheLoaderConfig getCacheLoaderConfig(String properties) throws Exception
{
String xml = "<config>\n" +
- "<passivation>true</passivation>\n" +
- "<preload></preload>\n" +
- "<shared>true</shared>\n" +
- "<cacheloader>\n" +
- "<class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
- "<properties>" + properties + "</properties>\n" +
- "<async>false</async>\n" +
- "<fetchPersistentState>false</fetchPersistentState>\n" +
- "<ignoreModifications>false</ignoreModifications>\n" +
- "</cacheloader>\n" +
- "</config>";
+ "<passivation>true</passivation>\n" +
+ "<preload></preload>\n" +
+ "<shared>true</shared>\n" +
+ "<cacheloader>\n" +
+ "<class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
+ "<properties>" + properties + "</properties>\n" +
+ "<async>false</async>\n" +
+ "<fetchPersistentState>false</fetchPersistentState>\n" +
+ "<ignoreModifications>false</ignoreModifications>\n" +
+ "</cacheloader>\n" +
+ "</config>";
Element element = XmlHelper.stringToElement(xml);
return XmlConfigurationParser.parseCacheLoaderConfig(element);
}
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderCompatibilityTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,18 +1,6 @@
package org.jboss.cache.loader;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Properties;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.CacheLoaderConfig;
@@ -22,11 +10,18 @@
import org.jboss.cache.xml.XmlHelper;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Properties;
+
/**
* Tests the compatibility between <tt>JDBCCacheLoader</tt> and <tt>JDBCCacheLoaderOld</tt>. More exactly,
* it tests whether the new <tt>JDBCCacheLoader</tt> works fine on data previously created
@@ -57,8 +52,8 @@
{
newImpl = getNewCacheLoader();
oldImpl = getOldLoader();
- CacheImpl cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
- CacheImpl cache2 = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
+ CacheSPI cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
+ CacheSPI cache2 = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
newImpl.setCache(cache);//this is needed for marshaller
oldImpl.setCache(cache2);
oldImpl.start();
@@ -207,17 +202,17 @@
protected CacheLoaderConfig getSingleCacheLoaderConfig(String preload, String cacheloaderClass, String properties) throws Exception
{
String xml = "<config>\n" +
- "<passivation>false</passivation>\n" +
- "<preload>" + preload + "</preload>\n" +
- "<cacheloader>\n" +
- "<class>" + cacheloaderClass + "</class>\n" +
- "<properties>" + properties + "</properties>\n" +
- "<async>false</async>\n" +
- "<shared>false</shared>\n" +
- "<fetchPersistentState>true</fetchPersistentState>\n" +
- "<purgeOnStartup>false</purgeOnStartup>\n" +
- "</cacheloader>\n" +
- "</config>";
+ "<passivation>false</passivation>\n" +
+ "<preload>" + preload + "</preload>\n" +
+ "<cacheloader>\n" +
+ "<class>" + cacheloaderClass + "</class>\n" +
+ "<properties>" + properties + "</properties>\n" +
+ "<async>false</async>\n" +
+ "<shared>false</shared>\n" +
+ "<fetchPersistentState>true</fetchPersistentState>\n" +
+ "<purgeOnStartup>false</purgeOnStartup>\n" +
+ "</cacheloader>\n" +
+ "</config>";
Element element = XmlHelper.stringToElement(xml);
return XmlConfigurationParser.parseCacheLoaderConfig(element);
}
@@ -241,11 +236,11 @@
Properties prop = getProperties();
String props = "cache.jdbc.driver =" + prop.getProperty("cache.jdbc.driver") + "\n" +
- "cache.jdbc.url=" + prop.getProperty("cache.jdbc.url") + "\n" +
- "cache.jdbc.user=" + prop.getProperty("cache.jdbc.user") + "\n" +
- "cache.jdbc.password=" + prop.getProperty("cache.jdbc.password") + "\n" +
- "cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type") + "\n" +
- "cache.jdbc.sql-concat=" + prop.getProperty("cache.jdbc.sql-concat") + "\n";
+ "cache.jdbc.url=" + prop.getProperty("cache.jdbc.url") + "\n" +
+ "cache.jdbc.user=" + prop.getProperty("cache.jdbc.user") + "\n" +
+ "cache.jdbc.password=" + prop.getProperty("cache.jdbc.password") + "\n" +
+ "cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type") + "\n" +
+ "cache.jdbc.sql-concat=" + prop.getProperty("cache.jdbc.sql-concat") + "\n";
CacheLoaderConfig.IndividualCacheLoaderConfig base = getSingleCacheLoaderConfig("", "org.jboss.cache.loader.JDBCCacheLoader", props).getFirstCacheLoaderConfig();
@@ -261,11 +256,11 @@
Properties prop = getProperties();
String props = "cache.jdbc.driver =" + prop.getProperty("cache.jdbc.driver") + "\n" +
- "cache.jdbc.url=" + prop.getProperty("cache.jdbc.url") + "\n" +
- "cache.jdbc.user=" + prop.getProperty("cache.jdbc.user") + "\n" +
- "cache.jdbc.password=" + prop.getProperty("cache.jdbc.password") + "\n" +
- "cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type") + "\n" +
- "cache.jdbc.sql-concat=" + prop.getProperty("cache.jdbc.sql-concat");// + "\n" +
+ "cache.jdbc.url=" + prop.getProperty("cache.jdbc.url") + "\n" +
+ "cache.jdbc.user=" + prop.getProperty("cache.jdbc.user") + "\n" +
+ "cache.jdbc.password=" + prop.getProperty("cache.jdbc.password") + "\n" +
+ "cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type") + "\n" +
+ "cache.jdbc.sql-concat=" + prop.getProperty("cache.jdbc.sql-concat");// + "\n" +
// "cache.jdbc.connection.factory=org.jboss.cache.manualtests.cacheloader.OneConnectionFactory";
Modified: core/trunk/src/test/java/org/jboss/cache/loader/AsyncFileCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/AsyncFileCacheLoaderTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/AsyncFileCacheLoaderTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,17 +1,8 @@
package org.jboss.cache.loader;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.util.Collections;
-import java.util.HashMap;
-
import junit.framework.Assert;
-
import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
@@ -19,11 +10,18 @@
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.Collections;
+import java.util.HashMap;
+
public class AsyncFileCacheLoaderTest extends AbstractCacheLoaderTestBase
{
- private CacheImpl<Object, Object> cache;
+ private CacheSPI<Object, Object> cache;
protected void configureCache() throws Exception
{
@@ -32,7 +30,7 @@
protected void configureCache(String props) throws Exception
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
// cache.setCacheLoaderConfiguration(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.jdbm.JdbmCacheLoader",
cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.FileCacheLoader", props, true, false, true));
@@ -80,9 +78,9 @@
public void testPutImmediate() throws Exception
{
configureCache(
- "cache.async.put=false\n" +
- "cache.async.pollWait=10000\n" +
- "");
+ "cache.async.put=false\n" +
+ "cache.async.pollWait=10000\n" +
+ "");
CacheLoader loader = cache.getCacheLoaderManager().getCacheLoader();
Fqn fqn = Fqn.fromString("/a/b/c/d");
HashMap<Object, Object> map = new HashMap<Object, Object>();
@@ -99,9 +97,9 @@
public void testBounded() throws Exception
{
configureCache(
- "cache.async.queueSize=1\n" +
- "cache.async.pollWait=10\n" +
- "");
+ "cache.async.queueSize=1\n" +
+ "cache.async.pollWait=10\n" +
+ "");
CacheLoader loader = cache.getCacheLoaderManager().getCacheLoader();
Fqn fqn = Fqn.fromString("/bound");
loader.remove(fqn);
@@ -118,9 +116,9 @@
public void testNoReturnOld() throws Exception
{
configureCache(
- "cache.async.returnOld=false\n" +
- "cache.async.pollWait=10\n" +
- "");
+ "cache.async.returnOld=false\n" +
+ "cache.async.pollWait=10\n" +
+ "");
CacheLoader loader = cache.getCacheLoaderManager().getCacheLoader();
System.out.println("Loader " + loader);
cache.put(Fqn.ROOT, "key1", "value1");
Modified: core/trunk/src/test/java/org/jboss/cache/loader/BdbjeTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/BdbjeTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/BdbjeTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,23 +1,9 @@
package org.jboss.cache.loader;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.jboss.cache.CacheImpl;
+import com.sleepycat.je.Database;
+import com.sleepycat.je.DatabaseConfig;
+import com.sleepycat.je.DeadlockException;
+import com.sleepycat.je.Environment;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
@@ -26,15 +12,21 @@
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import com.sleepycat.je.Database;
-import com.sleepycat.je.DatabaseConfig;
-import com.sleepycat.je.DatabaseException;
-import com.sleepycat.je.DeadlockException;
-import com.sleepycat.je.Environment;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* Tests BdbjeCacheLoader directly via the CacheLoader interface.
@@ -53,7 +45,7 @@
private static final String envHome = ".";
private static final Fqn<String> FQN = new Fqn<String>("key");
- private CacheImpl cache;
+ private CacheSPI cache;
private CacheLoader loader;
/**
@@ -129,20 +121,20 @@
* @param dbName a database name, or null to default to the cluster name.
*/
private void startLoader(boolean transactional, String dbName)
- throws Exception
+ throws Exception
{
/*
- * Create a dummy CacheImpl object. This is used for setting the cluster
+ * Create a dummy CacheSPI object. This is used for setting the cluster
* name and TransactionManagerLookupClass (transactional) propertes only.
- * the CacheImpl object is not used otherwise during testing.
+ * the CacheSPI object is not used otherwise during testing.
*/
- cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
+ cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
cache.getConfiguration().setClusterName("myCluster");
if (transactional)
{
cache.getConfiguration().setTransactionManagerLookupClass(
- "org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ "org.jboss.cache.transaction.DummyTransactionManagerLookup");
}
cache.start();
@@ -181,12 +173,12 @@
* Creates the loader instance.
*/
private void instantiateLoader()
- throws Exception
+ throws Exception
{
- /* Create the cache loader as CacheImpl would. */
+ /* Create the cache loader as CacheSPI would. */
Class cls =
- Class.forName("org.jboss.cache.loader.bdbje.BdbjeCacheLoader");
+ Class.forName("org.jboss.cache.loader.bdbje.BdbjeCacheLoader");
loader = (CacheLoader) cls.newInstance();
}
@@ -194,7 +186,6 @@
* Stops and destroys the loader.
*/
private void stopLoader()
- throws Exception
{
loader.stop();
@@ -205,7 +196,7 @@
* Tests basic operations without a transaction.
*/
public void testBasicOperations()
- throws Exception
+ throws Exception
{
doTestBasicOperations(false);
@@ -215,7 +206,7 @@
* Tests basic operations with a transaction.
*/
public void testBasicOperationsTransactional()
- throws Exception
+ throws Exception
{
doTestBasicOperations(true);
@@ -225,7 +216,7 @@
* Tests basic operations.
*/
private void doTestBasicOperations(boolean transactional)
- throws Exception
+ throws Exception
{
startLoader(transactional, null);
@@ -267,7 +258,7 @@
* Do basic put tests for a given FQN.
*/
private void doPutTests(Fqn<String> fqn)
- throws Exception
+ throws Exception
{
assertTrue(!loader.exists(fqn));
@@ -307,7 +298,7 @@
* Do basic remove tests for a given FQN.
*/
private void doRemoveTests(Fqn<String> fqn)
- throws Exception
+ throws Exception
{
/* remove(Fqn,Object) */
@@ -337,7 +328,7 @@
* and tests removing subtrees.
*/
public void testMultiLevelTree()
- throws Exception
+ throws Exception
{
startLoader(false, null);
@@ -486,7 +477,7 @@
* Tests the getChildrenNames() method.
*/
public void testGetChildrenNames()
- throws Exception
+ throws Exception
{
startLoader(false, null);
@@ -510,13 +501,13 @@
loader.put(Fqn.fromString("/key0/ab"), null);
loader.put(Fqn.fromString("/key0/abc"), null);
checkChildren(Fqn.fromString("/key0"),
- new String[]{"a", "ab", "abc"});
+ new String[]{"a", "ab", "abc"});
loader.put(Fqn.fromString("/key0/xxx"), null);
loader.put(Fqn.fromString("/key0/xx"), null);
loader.put(Fqn.fromString("/key0/x"), null);
checkChildren(Fqn.fromString("/key0"),
- new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
+ new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
loader.put(Fqn.fromString("/key0/a/1"), null);
loader.put(Fqn.fromString("/key0/a/2"), null);
@@ -524,13 +515,13 @@
checkChildren(Fqn.fromString("/key0/a/2"), new String[]{"1"});
checkChildren(Fqn.fromString("/key0/a"), new String[]{"1", "2"});
checkChildren(Fqn.fromString("/key0"),
- new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
+ new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
loader.put(Fqn.fromString("/key0/\u0000"), null);
loader.put(Fqn.fromString("/key0/\u0001"), null);
checkChildren(Fqn.fromString("/key0"),
- new String[]{"a", "ab", "abc", "x", "xx", "xxx",
- "\u0000", "\u0001"});
+ new String[]{"a", "ab", "abc", "x", "xx", "xxx",
+ "\u0000", "\u0001"});
loader.put(Fqn.fromString("/\u0001"), null);
checkChildren(new Fqn<String>(), new String[]{"key0", "key1", "\u0001"});
@@ -540,11 +531,11 @@
loader.put(Fqn.fromString("/\u0001/\uFFFF"), null);
checkChildren(Fqn.fromString("/\u0001"),
- new String[]{"\u0001", "\uFFFF"});
+ new String[]{"\u0001", "\uFFFF"});
loader.put(Fqn.fromString("/\u0001/\uFFFF/\u0001"), null);
checkChildren(Fqn.fromString("/\u0001/\uFFFF"),
- new String[]{"\u0001"});
+ new String[]{"\u0001"});
stopLoader();
}
@@ -553,7 +544,7 @@
* Checks that the given list of children part names is returned.
*/
private void checkChildren(Fqn<String> fqn, String[] names)
- throws Exception
+ throws Exception
{
Set set = loader.getChildrenNames(fqn);
@@ -575,7 +566,7 @@
* Tests basic operations without a transaction.
*/
public void testModifications()
- throws Exception
+ throws Exception
{
doTestModifications(false);
@@ -585,7 +576,7 @@
* Tests basic operations with a transaction.
*/
public void testModificationsTransactional()
- throws Exception
+ throws Exception
{
doTestModifications(true);
@@ -595,7 +586,7 @@
* Tests modifications.
*/
private void doTestModifications(boolean transactional)
- throws Exception
+ throws Exception
{
startLoader(transactional, null);
@@ -644,7 +635,7 @@
* Tests a one-phase transaction.
*/
public void testOnePhaseTransaction()
- throws Exception
+ throws Exception
{
startLoader(true, null);
@@ -660,7 +651,7 @@
* Tests a two-phase transaction.
*/
public void testTwoPhaseTransaction()
- throws Exception
+ throws Exception
{
startLoader(true, null);
@@ -686,7 +677,7 @@
* Tests rollback of a two-phase transaction.
*/
public void testTransactionRollback()
- throws Exception
+ throws Exception
{
startLoader(true, null);
@@ -741,7 +732,7 @@
* Checks that a list of modifications was applied.
*/
private void checkModifications(List<Modification> list)
- throws Exception
+ throws Exception
{
for (int i = 0; i < list.size(); i += 1)
@@ -783,7 +774,7 @@
* Tests a non-transactional prepare.
*/
public void testTransactionExceptions()
- throws Exception
+ throws Exception
{
List<Modification> mods = createUpdates();
@@ -884,7 +875,7 @@
* Tests that null keys and values work as for a standard Java Map.
*/
public void testNullKeysAndValues()
- throws Exception
+ throws Exception
{
startLoader(false, null);
@@ -934,7 +925,7 @@
* Test non-default database name.
*/
public void testDatabaseName()
- throws Exception
+ throws Exception
{
startLoader(false, "nonDefaultDbName");
@@ -947,7 +938,7 @@
* Test load/store state.
*/
public void testLoadAndStore()
- throws Exception
+ throws Exception
{
startLoader(false, null);
@@ -1056,7 +1047,7 @@
{
Complex x = (Complex) o;
return (nested != null) ? nested.equals(x.nested)
- : (x.nested == null);
+ : (x.nested == null);
}
catch (ClassCastException e)
{
Modified: core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderManagerTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderManagerTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,22 +6,16 @@
*/
package org.jboss.cache.loader;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.List;
-import java.util.Properties;
-
import org.jboss.cache.CacheSPI;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.xml.XmlHelper;
+import static org.testng.AssertJUnit.*;
import org.w3c.dom.Element;
+import java.util.List;
+import java.util.Properties;
+
/**
* Tests the construction of a cache laoder based on an XML element passed in.
*
@@ -37,7 +31,7 @@
return cfg;
}
- private CacheLoaderConfig.IndividualCacheLoaderConfig createIndividualCacheLoaderConfig(CacheLoaderConfig parent, boolean async, String classname) throws Exception
+ private CacheLoaderConfig.IndividualCacheLoaderConfig createIndividualCacheLoaderConfig(CacheLoaderConfig parent, boolean async, String classname)
{
CacheLoaderConfig.IndividualCacheLoaderConfig cfg = new CacheLoaderConfig.IndividualCacheLoaderConfig();
cfg.setAsync(async);
@@ -134,34 +128,34 @@
{
// without async
String conf = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
- "<config><passivation>true</passivation>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.bdbje.BdbjeCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader></config>";
+ "<config><passivation>true</passivation>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>false</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ "</cacheloader>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.bdbje.BdbjeCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>false</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ "</cacheloader>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>false</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ "</cacheloader></config>";
CacheLoaderConfig clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
CacheLoaderManager mgr = new CacheLoaderManager();
mgr.setConfig(clc, null);
@@ -171,33 +165,33 @@
// with async
conf = "<config><passivation>true</passivation>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>true</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.bdbje.BdbjeCacheLoader</class>" +
- " <async>true</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
- " <async>true</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader></config>";
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
+ " <async>true</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>false</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ "</cacheloader>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.bdbje.BdbjeCacheLoader</class>" +
+ " <async>true</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>false</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ "</cacheloader>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
+ " <async>true</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>false</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ "</cacheloader></config>";
clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
mgr.setConfig(clc, null);
cl = mgr.getCacheLoader();
@@ -241,24 +235,24 @@
{
// async = false
String conf = "<config><passivation>false</passivation>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
- " </properties>" +
- "</cacheloader></config>";
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>false</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ "</cacheloader>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>false</ignoreModifications>" +
+ " <properties>" +
+ "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
+ " </properties>" +
+ "</cacheloader></config>";
CacheLoaderConfig clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
CacheLoaderManager mgr = new CacheLoaderManager();
@@ -274,25 +268,25 @@
// async = true
conf = "<config>" +
- "<passivation>false</passivation>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
- " <async>true</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
- " </properties>" +
- "</cacheloader></config>";
+ "<passivation>false</passivation>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>false</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ "</cacheloader>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
+ " <async>true</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>false</ignoreModifications>" +
+ " <properties>" +
+ "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
+ " </properties>" +
+ "</cacheloader></config>";
clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
mgr.setConfig(clc, null);
cl = mgr.getCacheLoader();
@@ -372,26 +366,26 @@
{
String conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
- " <async>true</async>" +
- " <fetchPersistentState>true</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
- " </properties>" +
- "</cacheloader></config>";
+ "<passivation>false</passivation>" +
+ "<preload>/, /blah, /blah2</preload>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>true</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ "</cacheloader>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
+ " <async>true</async>" +
+ " <fetchPersistentState>true</fetchPersistentState>" +
+ " <ignoreModifications>false</ignoreModifications>" +
+ " <properties>" +
+ "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
+ " </properties>" +
+ "</cacheloader></config>";
CacheLoaderConfig clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
CacheLoaderManager mgr = new CacheLoaderManager();
mgr.setConfig(clc, null);
@@ -420,26 +414,26 @@
// fetch PersistentState shld be false now
conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
- " <async>true</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>false</ignoreModifications>" +
- " <properties>" +
- "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
- " </properties>" +
- "</cacheloader></config>";
+ "<passivation>false</passivation>" +
+ "<preload>/, /blah, /blah2</preload>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>true</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ "</cacheloader>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.JDBCCacheLoader</class>" +
+ " <async>true</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>false</ignoreModifications>" +
+ " <properties>" +
+ "cache.jdbc.driver=com.mysql.jdbc.Driver\ncache.jdbc.url=jdbc:mysql://localhost/test\ncache.jdbc.user=user\ncache.jdbc.password=pwd" +
+ " </properties>" +
+ "</cacheloader></config>";
clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
mgr = new CacheLoaderManager();
@@ -453,18 +447,18 @@
public void testSingletonConfiguration() throws Exception
{
String conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- "</cacheloader>" +
- "</config>";
+ "<passivation>false</passivation>" +
+ "<preload>/, /blah, /blah2</preload>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>true</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ "</cacheloader>" +
+ "</config>";
CacheLoaderConfig clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
CacheLoaderManager mgr = new CacheLoaderManager();
mgr.setConfig(clc, null);
@@ -475,21 +469,21 @@
/************************************************************************************************************/
conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>false</enabled>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
+ "<passivation>false</passivation>" +
+ "<preload>/, /blah, /blah2</preload>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>true</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ " <singletonStore>" +
+ " <enabled>false</enabled>" +
+ " </singletonStore>" +
+ "</cacheloader>" +
+ "</config>";
clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
mgr = new MockCacheLoaderManager();
mgr.setConfig(clc, null);
@@ -501,21 +495,21 @@
/************************************************************************************************************/
conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>true</enabled>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
+ "<passivation>false</passivation>" +
+ "<preload>/, /blah, /blah2</preload>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>true</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ " <singletonStore>" +
+ " <enabled>true</enabled>" +
+ " </singletonStore>" +
+ "</cacheloader>" +
+ "</config>";
clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
mgr = new MockCacheLoaderManager();
mgr.setConfig(clc, null);
@@ -526,29 +520,29 @@
assertEquals("Singleton class should be default", SingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
assertNotNull("Singleton properties should be not null", iclc.getSingletonStoreConfig().getSingletonStoreproperties());
assertTrue("Singleton properties should be empty", iclc.getSingletonStoreConfig().getSingletonStoreproperties().keySet().isEmpty());
- SingletonStoreDefaultConfig ssdc = ((SingletonStoreCacheLoader)mgr.getCacheLoader()).getSingletonStoreDefaultConfig();
+ SingletonStoreDefaultConfig ssdc = ((SingletonStoreCacheLoader) mgr.getCacheLoader()).getSingletonStoreDefaultConfig();
assertTrue("Singleton pushStateWhenCoordinator should be true (default)", ssdc.isPushStateWhenCoordinator());
assertEquals("Singleton pushStateWhenCoordinatorTimeout should be default value", 20000, ssdc.getPushStateWhenCoordinatorTimeout());
/************************************************************************************************************/
conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>true</enabled>" +
- " <class>org.jboss.cache.loader.CacheLoaderManagerTest$MockSingletonStoreCacheLoader</class>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
+ "<passivation>false</passivation>" +
+ "<preload>/, /blah, /blah2</preload>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>true</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ " <singletonStore>" +
+ " <enabled>true</enabled>" +
+ " <class>org.jboss.cache.loader.CacheLoaderManagerTest$MockSingletonStoreCacheLoader</class>" +
+ " </singletonStore>" +
+ "</cacheloader>" +
+ "</config>";
clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
mgr = new CacheLoaderManager();
mgr.setConfig(clc, null);
@@ -564,22 +558,22 @@
/************************************************************************************************************/
conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>false</enabled>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
+ "<passivation>false</passivation>" +
+ "<preload>/, /blah, /blah2</preload>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>true</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ " <singletonStore>" +
+ " <enabled>false</enabled>" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
+ " </singletonStore>" +
+ "</cacheloader>" +
+ "</config>";
clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
mgr = new CacheLoaderManager();
mgr.setConfig(clc, null);
@@ -591,22 +585,22 @@
/************************************************************************************************************/
conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>true</enabled>" +
- " <properties></properties>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
+ "<passivation>false</passivation>" +
+ "<preload>/, /blah, /blah2</preload>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>true</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ " <singletonStore>" +
+ " <enabled>true</enabled>" +
+ " <properties></properties>" +
+ " </singletonStore>" +
+ "</cacheloader>" +
+ "</config>";
clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
mgr = new MockCacheLoaderManager();
mgr.setConfig(clc, null);
@@ -616,30 +610,30 @@
assertTrue("Singleton should enabled", iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
assertEquals("Singleton class should be default", SingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
assertNotNull("Singleton properties should be defined, but empty", iclc.getSingletonStoreConfig().getSingletonStoreproperties());
- ssdc = ((SingletonStoreCacheLoader)mgr.getCacheLoader()).getSingletonStoreDefaultConfig();
+ ssdc = ((SingletonStoreCacheLoader) mgr.getCacheLoader()).getSingletonStoreDefaultConfig();
assertTrue("Singleton pushStateWhenCoordinator should be true", ssdc.isPushStateWhenCoordinator());
/************************************************************************************************************/
conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>true</enabled>" +
- " <properties>" +
- " pushStateWhenCoordinator = false" +
- " </properties>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
+ "<passivation>false</passivation>" +
+ "<preload>/, /blah, /blah2</preload>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>true</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ " <singletonStore>" +
+ " <enabled>true</enabled>" +
+ " <properties>" +
+ " pushStateWhenCoordinator = false" +
+ " </properties>" +
+ " </singletonStore>" +
+ "</cacheloader>" +
+ "</config>";
clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
mgr = new MockCacheLoaderManager();
mgr.setConfig(clc, null);
@@ -649,31 +643,31 @@
assertTrue("Singleton should enabled", iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
assertEquals("Singleton class should be default", SingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
assertNotNull("Singleton properties should be defined", iclc.getSingletonStoreConfig().getSingletonStoreproperties());
- ssdc = ((SingletonStoreCacheLoader)mgr.getCacheLoader()).getSingletonStoreDefaultConfig();
+ ssdc = ((SingletonStoreCacheLoader) mgr.getCacheLoader()).getSingletonStoreDefaultConfig();
assertFalse("Singleton pushStateWhenCoordinator should be false", ssdc.isPushStateWhenCoordinator());
/************************************************************************************************************/
conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>true</enabled>" +
- " <properties>" +
- " pushStateWhenCoordinator = true\n" +
- " pushStateWhenCoordinatorTimeout = 5000\n" +
- " </properties>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
+ "<passivation>false</passivation>" +
+ "<preload>/, /blah, /blah2</preload>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>true</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ " <singletonStore>" +
+ " <enabled>true</enabled>" +
+ " <properties>" +
+ " pushStateWhenCoordinator = true\n" +
+ " pushStateWhenCoordinatorTimeout = 5000\n" +
+ " </properties>" +
+ " </singletonStore>" +
+ "</cacheloader>" +
+ "</config>";
clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
mgr = new MockCacheLoaderManager();
mgr.setConfig(clc, null);
@@ -683,29 +677,29 @@
assertTrue("Singleton should enabled", iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
assertEquals("Singleton class should be default", SingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
assertNotNull("Singleton properties should not be defined", iclc.getSingletonStoreConfig().getSingletonStoreproperties());
- ssdc = ((SingletonStoreCacheLoader)mgr.getCacheLoader()).getSingletonStoreDefaultConfig();
+ ssdc = ((SingletonStoreCacheLoader) mgr.getCacheLoader()).getSingletonStoreDefaultConfig();
assertTrue("Singleton pushStateWhenCoordinator should be true", ssdc.isPushStateWhenCoordinator());
assertEquals("Singleton pushStateWhenCoordinatorTimeout should be default value", 5000, ssdc.getPushStateWhenCoordinatorTimeout());
/************************************************************************************************************/
conf = "<config>" +
- "<passivation>false</passivation>" +
- "<shared>true</shared>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>true</enabled>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
+ "<passivation>false</passivation>" +
+ "<shared>true</shared>" +
+ "<preload>/, /blah, /blah2</preload>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>true</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ " <singletonStore>" +
+ " <enabled>true</enabled>" +
+ " </singletonStore>" +
+ "</cacheloader>" +
+ "</config>";
clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
mgr = new CacheLoaderManager();
try
@@ -720,22 +714,22 @@
/************************************************************************************************************/
conf = "<config>" +
- "<passivation>false</passivation>" +
- "<preload>/, /blah, /blah2</preload>" +
- "<cacheloader>" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
- " <async>false</async>" +
- " <fetchPersistentState>false</fetchPersistentState>" +
- " <ignoreModifications>true</ignoreModifications>" +
- " <properties>" +
- " location=" + getTempDir() +
- " </properties>" +
- " <singletonStore>" +
- " <enabled>true</enabled>" +
- " <class>org.jboss.cache.loader.DummyInMemoryCacheLoader</class>" +
- " </singletonStore>" +
- "</cacheloader>" +
- "</config>";
+ "<passivation>false</passivation>" +
+ "<preload>/, /blah, /blah2</preload>" +
+ "<cacheloader>" +
+ " <class>org.jboss.cache.loader.FileCacheLoader</class>" +
+ " <async>false</async>" +
+ " <fetchPersistentState>false</fetchPersistentState>" +
+ " <ignoreModifications>true</ignoreModifications>" +
+ " <properties>" +
+ " location=" + getTempDir() +
+ " </properties>" +
+ " <singletonStore>" +
+ " <enabled>true</enabled>" +
+ " <class>org.jboss.cache.loader.DummyInMemoryCacheLoader</class>" +
+ " </singletonStore>" +
+ "</cacheloader>" +
+ "</config>";
clc = XmlConfigurationParser.parseCacheLoaderConfig(strToElement(conf));
mgr = new CacheLoaderManager();
Modified: core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderMethodCallCounterTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,10 +6,9 @@
*/
package org.jboss.cache.loader;
-import static org.testng.AssertJUnit.assertEquals;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
+import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -20,14 +19,14 @@
*/
public class CacheLoaderMethodCallCounterTest extends AbstractCacheLoaderTestBase
{
- private CacheImpl<Object, Object> cache;
+ private CacheSPI cache;
private DummyCacheLoader dummyLoader;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
if (cache != null) tearDown();
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCacheLoader.class.getName(), "", false, false, false));
cache.start();
dummyLoader = (DummyCacheLoader) cache.getCacheLoaderManager().getCacheLoader();
@@ -45,19 +44,19 @@
}
- public void testPut() throws Exception
+ public void testPut()
{
cache.put("/node", "key", "value");
printReport("putKeyValue", dummyLoader);
}
- public void testGet() throws Exception
+ public void testGet()
{
cache.get("/node", "key");
printReport("getKey", dummyLoader);
}
- public void testRemove() throws Exception
+ public void testRemove()
{
cache.remove("/node", "key");
printReport("removeKey", dummyLoader);
@@ -76,7 +75,7 @@
System.out.println("------------------------------");
}
- public void testLoopedGets() throws Exception
+ public void testLoopedGets()
{
// put an object in cache
cache.put("/test", "key", "value");
@@ -88,7 +87,7 @@
for (int i = 0; i < 2000; i++)
{
- cache.get("/test");
+ cache.getNode("/test");
}
assertEquals(1, dummyLoader.getPutCount());
Modified: core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderPurgingTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderPurgingTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderPurgingTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -7,7 +7,7 @@
package org.jboss.cache.loader;
import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
@@ -17,13 +17,14 @@
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
+
/**
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
@Test(groups = {"functional"})
public class CacheLoaderPurgingTest extends AbstractCacheLoaderTestBase
{
- private CacheImpl<Object, Object> cache;
+ private CacheSPI<Object, Object> cache;
private String key = "key", value = "value";
private Fqn fqn = Fqn.fromString("/a/b/c");
@@ -32,7 +33,7 @@
{
if (cache != null)
{
- cache.remove(Fqn.ROOT);
+ cache.removeNode(Fqn.ROOT);
cache.stop();
cache = null;
}
@@ -40,9 +41,9 @@
public void testSingleLoaderNoPurge() throws Exception
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
- Configuration c = new Configuration();
- cache.setConfiguration(c);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ Configuration c = cache.getConfiguration();
+
c.setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummySharedInMemoryCacheLoader.class.getName(), "", false, false, false));
cache.start();
@@ -64,9 +65,8 @@
public void testSingleLoaderPurge() throws Exception
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
- Configuration c = new Configuration();
- cache.setConfiguration(c);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ Configuration c = cache.getConfiguration();
c.setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummySharedInMemoryCacheLoader.class.getName(), "", false, false, false, true));
cache.start();
@@ -85,39 +85,38 @@
assertTrue(cache.getCacheLoaderManager().getCacheLoaderConfig().getFirstCacheLoaderConfig().isPurgeOnStartup());
- assertNull(cache.get(fqn));
+ assertNull(cache.getNode(fqn));
assertNull(loader.get(fqn));
}
public void testTwoLoadersPurge() throws Exception
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
String xml = "<config>\n" +
- "<passivation>false</passivation>\n" +
- "<preload></preload>\n" +
- "<cacheloader>\n" +
- "<class>" + DummySharedInMemoryCacheLoader.class.getName() + "</class>\n" +
- "<properties>" +
- " bin=bin1\n" +
- "</properties>\n" +
- "<async>false</async>\n" +
- "<fetchPersistentState>true</fetchPersistentState>\n" +
- "<purgeOnStartup>" + true + "</purgeOnStartup>\n" +
- "</cacheloader>\n" +
- "<cacheloader>\n" +
- "<class>" + DummySharedInMemoryCacheLoader.class.getName() + "</class>\n" +
- "<properties>" +
- " bin=bin2\n" +
- "</properties>\n" +
- "<async>false</async>\n" +
- "<fetchPersistentState>false</fetchPersistentState>\n" +
- "<purgeOnStartup>" + false + "</purgeOnStartup>\n" +
- "</cacheloader>\n" +
- "</config>";
+ "<passivation>false</passivation>\n" +
+ "<preload></preload>\n" +
+ "<cacheloader>\n" +
+ "<class>" + DummySharedInMemoryCacheLoader.class.getName() + "</class>\n" +
+ "<properties>" +
+ " bin=bin1\n" +
+ "</properties>\n" +
+ "<async>false</async>\n" +
+ "<fetchPersistentState>true</fetchPersistentState>\n" +
+ "<purgeOnStartup>" + true + "</purgeOnStartup>\n" +
+ "</cacheloader>\n" +
+ "<cacheloader>\n" +
+ "<class>" + DummySharedInMemoryCacheLoader.class.getName() + "</class>\n" +
+ "<properties>" +
+ " bin=bin2\n" +
+ "</properties>\n" +
+ "<async>false</async>\n" +
+ "<fetchPersistentState>false</fetchPersistentState>\n" +
+ "<purgeOnStartup>" + false + "</purgeOnStartup>\n" +
+ "</cacheloader>\n" +
+ "</config>";
- Configuration c = new Configuration();
- cache.setConfiguration(c);
+ Configuration c = cache.getConfiguration();
Element element = XmlHelper.stringToElement(xml);
c.setCacheLoaderConfig(XmlConfigurationParser.parseCacheLoaderConfig(element));
cache.start();
Modified: core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/CacheLoaderTestsBase.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,46 +1,40 @@
package org.jboss.cache.loader;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.concurrent.CountDownLatch;
-
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
import org.jboss.cache.Node;
+import org.jboss.cache.NodeSPI;
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.cache.transaction.TransactionSetup;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
+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.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.CountDownLatch;
+
/**
* Commons tests for all CacheLoaders
*
@@ -52,7 +46,7 @@
{
private static final Log log = LogFactory.getLog(CacheLoaderTestsBase.class);
- CacheImpl<Object, Object> cache;
+ CacheSPI<Object, Object> cache;
CacheLoader loader = null;
static final Fqn<String> FQN = new Fqn<String>("key");
private static final Fqn<String> SUBTREE_FQN = new Fqn<String>(FQN, "subtree");
@@ -66,9 +60,8 @@
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
- Configuration c = new Configuration();
- cache.setConfiguration(c);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ Configuration c = cache.getConfiguration();
c.setCacheMode(Configuration.CacheMode.LOCAL);
c.setTransactionManagerLookupClass(TransactionSetup.getManagerLookup());
configureCache();
@@ -90,7 +83,7 @@
cleanup();
try
{
- cache.remove("/");
+ cache.removeNode(Fqn.ROOT);
}
catch (Exception e)
{
@@ -120,14 +113,27 @@
// returns immediately in this case. Subclasses may override where a delay is needed.
}
+ /**
+ * Helper method to test the existence of a key
+ *
+ * @param fqn
+ * @param key
+ */
+ protected boolean exists(String fqn, String key)
+ {
+ NodeSPI n = cache.peek(Fqn.fromString(fqn), false, false);
+ if (key == null) return n != null;
+ return n != null && n.getKeysDirect().contains(key);
+ }
+
public void testPrint() throws CacheException
{
final Fqn NODE = Fqn.fromString("/test");
final String KEY = "key";
cache.put(NODE, KEY, 10);
- cache.evict(NODE);
+ cache.evict(NODE, false);
addDelay();
- String ret = cache.print(NODE);
+ Node ret = cache.getNode(NODE);
assertNotNull(ret);
}
@@ -136,14 +142,14 @@
final String NODE = "/test";
final String KEY = "key";
Object retval;
- cache.remove(NODE);
+ cache.removeNode(NODE);
addDelay();
retval = cache.put(NODE, KEY, 10);
assertEquals(null, retval);
retval = cache.put(NODE, KEY, 20);
addDelay();
assertEquals(10, retval);
- cache.evict(Fqn.fromString(NODE));// evicts from memory, but *not* from store
+ cache.evict(Fqn.fromString(NODE), false);// evicts from memory, but *not* from store
addDelay();
log.debug("put 30, expect 20 back");
retval = cache.put(NODE, KEY, 30);
@@ -157,7 +163,7 @@
assertNull(loader.get(Fqn.fromString(NODE)));
final String KEY = "key";
Object retval;
- cache.remove(NODE);
+ cache.removeNode(NODE);
assertNull(loader.get(Fqn.fromString(NODE)));
addDelay();
retval = cache.put(NODE, KEY, 10);
@@ -165,9 +171,9 @@
addDelay();
retval = cache.put(NODE, KEY, 20);
assertEquals(10, retval);
- cache.evict(Fqn.fromString(NODE));// evicts from memory, but *not* from store
- cache.evict(Fqn.fromString("/a/b"));
- cache.evict(Fqn.fromString("/a"));
+ cache.evict(Fqn.fromString(NODE), false);// evicts from memory, but *not* from store
+ cache.evict(Fqn.fromString("/a/b"), false);
+ cache.evict(Fqn.fromString("/a"), false);
addDelay();
log.debug("replace KEY with 30, expect 20");
retval = cache.put(NODE, KEY, 30);
@@ -181,7 +187,7 @@
{
final Fqn NODE = Fqn.fromString("/a/b/c");
- cache.remove(NODE);
+ cache.removeNode(NODE);
addDelay();
Map<Object, Object> m = new HashMap<Object, Object>();
m.put("a", "b");
@@ -196,15 +202,15 @@
cache.get(NODE, "X");
assertEquals(m, loader.get(NODE));
- assertEquals(m, cache.get(NODE).getData());
- cache.evict(NODE);
+ assertEquals(m, cache.getNode(NODE).getData());
+ cache.evict(NODE, false);
addDelay();
cache.get(NODE, "X");
- assertEquals(m, cache.get(NODE).getData());
- cache.evict(NODE);
+ assertEquals(m, cache.getNode(NODE).getData());
+ cache.evict(NODE, false);
cache.get(NODE, "X");
cache.put(NODE, m2);
- assertEquals("combined", 4, cache.get(NODE).getData().size());
+ assertEquals("combined", 4, cache.getNode(NODE).getData().size());
}
public void testShallowMove() throws Exception
@@ -277,40 +283,35 @@
public void testPutRemoveCombos() throws Exception
{
final String NODE = "/a/b/c";
- cache.remove(NODE);
+ cache.removeNode(NODE);
Fqn fqn = Fqn.fromString(NODE);
addDelay();
Map<Object, Object> m = new HashMap<Object, Object>();
m.put("a", "b");
m.put("c", "d");
loader.put(fqn, m);
- System.out.println("*** MANIK: LOADER " + loader.get(fqn));
cache.put(NODE, "e", "f");
- System.out.println("*** MANIK: CACHE " + cache.get(NODE).getData());
- System.out.println("*** MANIK: LOADER " + loader.get(fqn));
addDelay();
- System.out.println("*** MANIK: CACHE " + cache.get(NODE));
cache.get(NODE, "X");
- System.out.println("*** MANIK: CACHE " + cache.get(NODE).getData());
- assertEquals(3, cache.get(NODE).getData().size());
- cache.evict(fqn);
+ assertEquals(3, cache.getNode(NODE).getData().size());
+ cache.evict(fqn, false);
cache.get(NODE, "X");
cache.remove(NODE, "e");
- assertEquals(2, cache.get(NODE).getData().size());
+ assertEquals(2, cache.getNode(NODE).getData().size());
}
public void testGet() throws CacheException
{
final String NODE = "/a/b/c";
Object retval;
- cache.remove(NODE);
+ cache.removeNode(NODE);
addDelay();
retval = cache.put(NODE, "1", 10);
assertNull(retval);
addDelay();
cache.put(NODE, "2", 20);
- cache.evict(Fqn.fromString("/a/b/c"));
- assertTrue("DataNode should not exisit ", !cache.exists("/a/b/c"));
+ cache.evict(Fqn.fromString("/a/b/c"), false);
+ assertNull("DataNode should not exisit ", cache.peek(Fqn.fromString("/a/b/c"), false, false));
addDelay();
retval = cache.get(NODE, "1");
assertEquals(10, retval);
@@ -323,13 +324,13 @@
{
final String NODE = "/a/b/c";
Object retval;
- cache.remove(NODE);
+ cache.removeNode(NODE);
addDelay();
cache.put(NODE, "1", 10);
- cache.evict(Fqn.fromString(NODE));
- assertTrue("DataNode should not exisit ", !cache.exists("/a/b/c"));
+ cache.evict(Fqn.fromString(NODE), false);
+ assertNull("DataNode should not exisit ", cache.peek(Fqn.fromString("/a/b/c"), false, false));
addDelay();
- retval = cache.get(NODE);
+ retval = cache.getNode(NODE);
assertNotNull("Should not be null", retval);
@@ -347,8 +348,8 @@
cache.put("/mypojo", 322649, pojo);
addDelay();
assertNotNull(cache.get("/mypojo", 322649));
- cache.evict(Fqn.fromString("/mypojo"));
- assertFalse(cache.exists("/mypojo"));
+ cache.evict(Fqn.fromString("/mypojo"), false);
+ assertNull(cache.peek(Fqn.fromString("/mypojo"), false, false));
SamplePojo pojo2 = (SamplePojo) cache.get("/mypojo", 322649);// should fetch from CacheLoader
assertNotNull(pojo2);
assertEquals(39, pojo2.getAge());
@@ -369,7 +370,10 @@
m.put("key" + i, "val" + i);
}
cache.put("/a/b/c", m);
- cache.load("/1/2/3/4/5");
+
+ // force preload on /1/2/3/4/5
+ cache.getCacheLoaderManager().preload(Fqn.fromString("/1/2/3/4/5"), true, true);
+
cache.put("/1/2/3/4/5", null);
cache.put("/1/2/3/4/5/a", null);
cache.put("/1/2/3/4/5/b", null);
@@ -384,7 +388,7 @@
assertTrue(cache.exists("/1/2/3/4"));
assertTrue(cache.exists("/a/b/c"));
- assertFalse(cache.exists("/a/b/c/d"));
+ assert (!exists("/a/b/c/d", null));
}
catch (Exception e)
{
@@ -395,13 +399,13 @@
public void testPreloading() throws CacheException
{
- cache.remove("/");
+ cache.removeNode(Fqn.ROOT);
cache.put("1/2/3/4/5/d", "key", "val");
cache.evict(Fqn.fromString("1/2/3/4/5/d"));
System.out.println("-- checking for 1/2/3/4/5/d");
addDelay();
- assertFalse(cache.exists("1/2/3/4/5/d"));// exists() doesn't load
- cache.get("1/2/3/4/5/d");// get *does* load
+ assert (!exists("1/2/3/4/5/d", null));// exists() doesn't load
+ cache.getNode("1/2/3/4/5/d");// get *does* load
assertTrue(cache.exists("1/2/3/4/5/d"));
System.out.println("-- 1/2/3/4/5/d exists");
}
@@ -412,7 +416,7 @@
{
Set keys = null;
cache.put("/a/b/c", "key", "val");
- keys = cache.getKeys("/a/b/c");
+ keys = cache.getNode("/a/b/c").getKeys();
assertNotNull(keys);
assertEquals(1, keys.size());
keys.add("myKey");
@@ -423,10 +427,10 @@
{
cache.put("/eins/zwei/drei", "key1", "val1");
assertTrue(cache.exists("/eins/zwei/drei"));
- assertTrue(cache.exists("/eins/zwei/drei", "key1"));
- assertFalse(cache.exists("/eins/zwei/drei", "key2"));
- assertFalse(cache.exists("/uno/due/tre"));
- assertFalse(cache.exists("/une/due/tre", "key1"));
+ assert (exists("/eins/zwei/drei", "key1"));
+ assert (!exists("/eins/zwei/drei", "key2"));
+ assert (!exists("/uno/due/tre", null));
+ assert (!exists("/une/due/tre", "key1"));
}
public void testGetChildren()
@@ -436,7 +440,7 @@
cache.put("/1/2/3/4/5/d/one", null);
cache.put("/1/2/3/4/5/d/two", null);
cache.put("/1/2/3/4/5/d/three", null);
- Set children = cache.getChildrenNames("/1/2/3/4/5/d");
+ Set children = cache.getNode("/1/2/3/4/5/d").getChildrenNames();
assertNotNull(children);
assertEquals(3, children.size());
assertTrue(children.contains("one"));
@@ -463,7 +467,7 @@
cache.evict(Fqn.fromString("/a"));
cache.evict(Fqn.fromString("/"));
addDelay();
- Set children = cache.getChildrenNames("/a/b/c");
+ Set children = cache.getNode("/a/b/c").getChildrenNames();
assertNotNull(children);
assertEquals(3, children.size());
assertTrue(children.contains("1"));
@@ -477,7 +481,7 @@
{
cache.put("/1", null);
cache.put("a", null);
- Set children = cache.getChildrenNames("/");
+ Set children = cache.getRoot().getChildrenNames();
assertNotNull(children);
assertEquals(2, children.size());
assertTrue(children.contains("1"));
@@ -495,7 +499,7 @@
{
cache.put("/1", null);
cache.put("a", null);
- Set children = cache.getChildrenNames("");
+ Set children = cache.getRoot().getChildrenNames();
assertNotNull(children);
assertEquals(2, children.size());
assertTrue(children.contains("1"));
@@ -515,7 +519,7 @@
{
cache.put("/a/b/c", null);
}
- Set children = cache.getChildrenNames((Fqn<String>) null);
+ Set children = cache.getRoot().getChildrenNames();
assertTrue(children.isEmpty());
}
catch (Exception e)
@@ -532,12 +536,11 @@
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
- System.out.println("cache is " + cache.printLockInfo());
- Node n = cache.get("/a");
+ Node n = cache.getNode("/a");
assertNotNull(n);
- Set children = cache.getChildrenNames("/a");
+ Set children = n.getChildrenNames();
assertNotNull(children);
assertEquals(3, children.size());
}
@@ -555,16 +558,14 @@
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
- System.out.println("cache is " + cache.printLockInfo());
cache.evict(Fqn.fromString("/a/1"));
cache.evict(Fqn.fromString("/a/2"));
cache.evict(Fqn.fromString("/a/3"));
cache.evict(Fqn.fromString("/a"));
- System.out.println("cache is " + cache.printLockInfo());
addDelay();
- assertNotNull(cache.get("/a"));
+ assertNotNull(cache.getNode("/a"));
- Set children = cache.getChildrenNames("/a");
+ Set children = cache.getNode("/a").getChildrenNames();
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
@@ -583,17 +584,15 @@
cache.put("/a/2", null);
cache.put("/a/3", null);
cache.put("/a", "test", "test");
- System.out.println("cache is " + cache.printLockInfo());
cache.evict(Fqn.fromString("/a/1"));
cache.evict(Fqn.fromString("/a/2"));
cache.evict(Fqn.fromString("/a/3"));
cache.evict(Fqn.fromString("/a"));
- System.out.println("cache is " + cache.printLockInfo());
addDelay();
Object val = cache.get("/a", "test");
assertEquals("attributes weren't loaded", "test", val);
- Set children = cache.getChildrenNames("/a");
+ Set children = cache.getNode("/a").getChildrenNames();
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
@@ -609,17 +608,15 @@
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
- System.out.println("cache is " + cache.printLockInfo());
cache.evict(Fqn.fromString("/a/1"));
cache.evict(Fqn.fromString("/a/2"));
cache.evict(Fqn.fromString("/a/3"));
cache.evict(Fqn.fromString("/a"));
- System.out.println("cache is " + cache.printLockInfo());
addDelay();
assertNull(cache.get("/a", "test"));
- cache.get("/a/1");
- Set children = cache.getChildrenNames("/a");
+ cache.getNode("/a/1");
+ Set children = cache.getNode("/a").getChildrenNames();
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
@@ -632,17 +629,15 @@
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
- System.out.println("cache is " + cache.printLockInfo());
cache.evict(Fqn.fromString("/a/1"));
cache.evict(Fqn.fromString("/a/2"));
cache.evict(Fqn.fromString("/a/3"));
cache.evict(Fqn.fromString("/a"));
- System.out.println("cache is " + cache.printLockInfo());
addDelay();
assertNull(cache.get("/a", "test"));
- cache.get("/a/1");
- Set children = cache.getChildrenNames("/a");
+ cache.getNode("/a/1");
+ Set children = cache.getNode("/a").getChildrenNames();
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
@@ -651,12 +646,11 @@
cache.evict(Fqn.fromString("/a/2"));
cache.evict(Fqn.fromString("/a/3"));
cache.evict(Fqn.fromString("/a"));
- System.out.println("cache is " + cache.printLockInfo());
assertNull(cache.get("/a", "test"));
- cache.get("/a/1");
- children = cache.getChildrenNames("/a");
+ cache.getNode("/a/1");
+ children = cache.getNode("/a").getChildrenNames();
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
@@ -675,22 +669,20 @@
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
- System.out.println("cache is " + cache.printLockInfo());
cache.evict(Fqn.fromString("/a/1"));
cache.evict(Fqn.fromString("/a/2"));
cache.evict(Fqn.fromString("/a/3"));
cache.evict(Fqn.fromString("/a"));
- System.out.println("cache is " + cache.printLockInfo());
addDelay();
assertNull(cache.get("/a", "test"));
- cache.get("/a/1");
- Set children = cache.getChildrenNames("/a");
+ cache.getNode("/a/1");
+ Set children = cache.getNode("/a").getChildrenNames();
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
- children = cache.getChildrenNames("/a");
+ children = cache.getNode("/a").getChildrenNames();
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
@@ -722,7 +714,7 @@
cache.evict(Fqn.fromString("/a/b/3"));
// now load the children - this set childrenLoaded in /a/b to true
- children = cache.getChildrenNames("/a/b");
+ children = cache.getNode("/a/b").getChildrenNames();
assertEquals(3, children.size());
cache.evict(Fqn.fromString("/a/b"));
@@ -734,7 +726,7 @@
cache.evict(Fqn.fromString(("/a/b/3")));
cache.evict(Fqn.fromString("/a"));
- children = cache.getChildrenNames("/a/b");
+ children = cache.getNode("/a/b").getChildrenNames();
assertEquals(3, children.size());
}
catch (Exception e)
@@ -753,7 +745,7 @@
cache.put("/a/b/1", "key", "val");
cache.put("/a/b/2", "key", "val");
cache.put("/a/b/3", "key", "val");
- children = cache.getChildrenNames("/a/b");
+ children = cache.getNode("/a/b").getChildrenNames();
assertEquals(3, children.size());
cache.evict(Fqn.fromString("/a/b/3"));
@@ -763,8 +755,8 @@
cache.evict(Fqn.fromString("/a"));
// now load the children - this set childrenLoaded in /a/b to true
- cache.getChildrenNames("/a/b");
- children = cache.getChildrenNames("/a/b");
+ cache.getNode("/a/b").getChildrenNames();
+ children = cache.getNode("/a/b").getChildrenNames();
assertEquals(3, children.size());
cache.evict(Fqn.fromString("/a/b/3"));
@@ -772,7 +764,7 @@
// cache.evict(Fqn.fromString("/a/b/1"));
cache.evict(Fqn.fromString("/a/b"));
cache.evict(Fqn.fromString("/a"));
- children = cache.getChildrenNames("/a/b");
+ children = cache.getNode("/a/b").getChildrenNames();
assertEquals(3, children.size());
}
catch (Exception e)
@@ -821,11 +813,11 @@
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
- assertEquals(3, cache.getKeys(key).size());
- cache.removeData(key);
- Set keys = cache.getKeys(key);
+ assertEquals(3, cache.getNode(key).getKeys().size());
+ cache.getNode(key).clearData();
+ Set keys = cache.getNode(key).getKeys();
assertEquals(0, keys.size());
- cache.remove("/x");
+ cache.removeNode("/x");
Object val = cache.get(key, "keyA");
assertNull(val);
}
@@ -839,12 +831,12 @@
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
addDelay();
- keys = cache.getKeys(key);
+ keys = cache.getNode(key).getKeys();
assertEquals(3, keys.size());
- cache.removeData(key);
+ cache.getNode(key).clearData();
cache.evict(key);
addDelay();
- keys = cache.getKeys(key);
+ keys = cache.getNode(key).getKeys();
assertNotNull(keys);
assertEquals(0, keys.size());
}
@@ -856,11 +848,11 @@
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
- keys = cache.getKeys(key);
+ keys = cache.getNode(key).getKeys();
assertEquals(3, keys.size());
cache.evict(key);
- cache.removeData(key);
- keys = cache.getKeys(key);
+ cache.getNode(key).clearData();
+ keys = cache.getNode(key).getKeys();
assertEquals("no more keys", 0, keys.size());
}
@@ -871,7 +863,7 @@
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
- keys = cache.getKeys(key);
+ keys = cache.getNode(key).getKeys();
assertEquals(3, keys.size());
cache.evict(key);
Map<Object, Object> map = new HashMap<Object, Object>();
@@ -891,7 +883,7 @@
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
- keys = cache.getKeys(key);
+ keys = cache.getNode(key).getKeys();
assertEquals(3, keys.size());
cache.evict(key);
@@ -913,14 +905,14 @@
{
String key = "/x/y/z/";
cache.put(key, "keyA", "valA");
- assertEquals(1, cache.getKeys(key).size());
+ assertEquals(1, cache.getNode(key).getKeys().size());
cache.put(key, "keyB", "valB");
- assertEquals(2, cache.getKeys(key).size());
+ assertEquals(2, cache.getNode(key).getKeys().size());
cache.put(key, "keyC", "valC");
- assertEquals(3, cache.getKeys(key).size());
+ assertEquals(3, cache.getNode(key).getKeys().size());
cache.remove(key, "keyA");
- assertEquals(2, cache.getKeys(key).size());
- cache.remove("/x");
+ assertEquals(2, cache.getNode(key).getKeys().size());
+ cache.removeNode("/x");
}
@@ -929,7 +921,7 @@
final String NODE = "/test";
final String KEY = "key";
Object retval;
- cache.remove(NODE);
+ cache.removeNode(NODE);
retval = cache.put(NODE, KEY, 10);
assertNull(retval);
addDelay();
@@ -945,7 +937,7 @@
final String NODE = "/test";
final String KEY = "key";
Object retval;
- cache.remove(NODE);
+ cache.removeNode(NODE);
retval = cache.put(NODE, KEY, 10);
assertNull(retval);
@@ -967,25 +959,25 @@
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
- cache.remove("/x");
+ cache.removeNode("/x");
assertNull(cache.get(key, "keyA"));
addDelay();
- Set keys = cache.getKeys(key);
+ Set keys = cache.getNode(key).getKeys();
assertNull("got keys " + keys, keys);
- cache.remove("/x");
+ cache.removeNode("/x");
}
public void testRemoveRoot()
{
- assertEquals(0, cache.getKeys("/").size());
+ assertEquals(0, cache.getRoot().getKeys().size());
cache.put("/1/2/3/4/5", null);
cache.put("uno/due/tre", null);
cache.put("1/2/3/a", null);
cache.put("/eins/zwei/drei", null);
cache.put("/one/two/three", null);
- cache.remove("/");
- assertEquals(0, cache.getKeys("/").size());
+ cache.removeNode(Fqn.ROOT);
+ assertEquals(0, cache.getRoot().getKeys().size());
}
public void testLoaderRemoveRoot() throws Exception
@@ -1023,7 +1015,7 @@
cache.put("/first/second/third", "key1", "val1");// stored in cache loader
cache.evict(Fqn.fromString("/first/second/third"));// removes node, because there are no children
addDelay();
- assertFalse(cache.exists("/first/second/third"));
+ assert (!exists("/first/second/third", null));
assertTrue(cache.exists("/first/second"));
assertTrue(cache.exists("/first"));
String val = (String) cache.get("/first/second/third", "key1");// should be loaded from cache loader
@@ -1049,7 +1041,7 @@
TransactionManager mgr = getTransactionManager();
mgr.begin();
- Set children = cache.getChildrenNames("/a");
+ Set children = cache.getNode("/a").getChildrenNames();
System.out.println("**** " + cache.getTransactionManager());
@@ -1058,8 +1050,6 @@
assertTrue(children.contains("2"));
assertTrue(children.contains("3"));
- System.out.println("lock info " + cache.printLockInfo());
-
assertEquals(5, cache.getNumberOfLocksHeld());
mgr.commit();
@@ -1074,34 +1064,34 @@
cache.put("/one/two/three", "key1", "val1");
cache.put("/one/two/three/four", "key2", "val2");
mgr.commit();
- assertNotNull("Cache has node /one/two/three", cache.getKeys("/one/two/three"));
+ assertNotNull("Cache has node /one/two/three", cache.getNode("/one/two/three").getKeys());
assertNotNull("Loader has node /one/two/three", loader.get(Fqn.fromString("/one/two/three")));
- Set<?> children = cache.getChildrenNames("/one");
+ Set<?> children = cache.getNode("/one").getChildrenNames();
assertEquals("Cache has correct number of children", 1, children.size());
children = loader.getChildrenNames(Fqn.fromString("/one"));
assertEquals("Loader has correct number of children", 1, children.size());
- cache.remove("/");
+ cache.removeNode(Fqn.ROOT);
}
public void testTxPutRollback() throws Exception
{
TransactionManager mgr = getTransactionManager();
- cache.remove("/one");
+ cache.removeNode("/one");
addDelay();
mgr.begin();
cache.put("/one/two/three", "key1", "val1");
cache.put("/one/two/three/four", "key2", "val2");
- log.debug("NODE1 " + cache.get("/one/two/three").getData());
+ log.debug("NODE1 " + cache.getNode("/one/two/three").getData());
mgr.rollback();
- log.debug("NODE2 " + cache.get("/one/two/three"));
+ log.debug("NODE2 " + cache.getNode("/one/two/three"));
assertEquals(null, cache.get("/one/two/three", "key1"));
assertEquals(null, cache.get("/one/two/three/four", "key2"));
addDelay();
assertNull("Loader does not have node /one/two/three", loader.get(Fqn.fromString("/one/two/three")));
- assertEquals("Cache does not have node /one/two/three", null, cache.getKeys("/one/two/three"));
- Set<?> children = cache.getChildrenNames("/one");
+ assertEquals("Cache does not have node /one/two/three", null, cache.getNode("/one/two/three").getKeys());
+ Set<?> children = cache.getNode("/one").getChildrenNames();
assertEquals("Cache has no children under /one", 0, children.size());
children = loader.getChildrenNames(Fqn.fromString("/one"));
assertEquals("Loader has no children under /one", null, children);
@@ -1433,14 +1423,14 @@
loader.put(Fqn.fromString("/key0/abc"), null);
addDelay();
checkChildren(Fqn.fromString("/key0"),
- new String[]{"a", "ab", "abc"});
+ new String[]{"a", "ab", "abc"});
loader.put(Fqn.fromString("/key0/xxx"), null);
loader.put(Fqn.fromString("/key0/xx"), null);
loader.put(Fqn.fromString("/key0/x"), null);
addDelay();
checkChildren(Fqn.fromString("/key0"),
- new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
+ new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
loader.put(Fqn.fromString("/key0/a/1"), null);
loader.put(Fqn.fromString("/key0/a/2"), null);
@@ -1449,7 +1439,7 @@
checkChildren(Fqn.fromString("/key0/a/2"), new String[]{"1"});
checkChildren(Fqn.fromString("/key0/a"), new String[]{"1", "2"});
checkChildren(Fqn.fromString("/key0"),
- new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
+ new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
//
// loader.put(Fqn.fromString("/key0/\u0000"), null);
// loader.put(Fqn.fromString("/key0/\u0001"), null);
@@ -1692,13 +1682,11 @@
/**
* Checks that a list of modifications was applied.
*/
- private void checkModifications(List list)
- throws Exception
+ private void checkModifications(List<Modification> list) throws Exception
{
- for (int i = 0; i < list.size(); i += 1)
+ for (Modification mod : list)
{
- Modification mod = (Modification) list.get(i);
Fqn fqn = mod.getFqn();
switch (mod.getType())
{
@@ -1894,7 +1882,7 @@
}
Complex x = (Complex) o;
return (nested != null) ? nested.equals(x.nested)
- : (x.nested == null);
+ : (x.nested == null);
}
public int hashCode()
@@ -1924,9 +1912,9 @@
cache.getTransactionManager().begin();
- cache.remove(fqn);
+ cache.removeNode(fqn);
- cache.get(fqn);// forces the node to be loaded from cache loader again
+ cache.getNode(fqn);// forces the node to be loaded from cache loader again
cache.getTransactionManager().commit();
log.debug("expect the cache and the loader to be null here.");
@@ -1950,8 +1938,8 @@
cache.getTransactionManager().begin();
- cache.remove(fqn);
- cache.get(fqn);// forces a reload from cloader
+ cache.removeNode(fqn);
+ cache.getNode(fqn);// forces a reload from cloader
cache.getTransactionManager().rollback();
assertEquals(value, cache.get(fqn, key));
@@ -1976,7 +1964,7 @@
cache.getTransactionManager().begin();
- cache.remove(fqn);
+ cache.removeNode(fqn);
assertNull("Expecting a null since I have already called a remove() - see JBCACHE-352", cache.get(fqn, key));
cache.getTransactionManager().rollback();
@@ -2105,15 +2093,13 @@
cache.stop();
cache.destroy();
- assert cache.getCacheLoader() == null : "Should nullify cache loader in the cache";
assert cache.getCacheLoaderManager() == null : "Should nullify cache loader manager in the cache";
cache.getConfiguration().getCacheLoaderConfig().getIndividualCacheLoaderConfigs().get(0).setIgnoreModifications(true);
cache.start();
- loader = cache.getCacheLoader();
+ loader = cache.getCacheLoaderManager().getCacheLoader();
postConfigure();
-
// CCL uses it's own mechanisms to ensure read-only behaviour
if (!(loader instanceof ChainingCacheLoader))
{
@@ -2121,10 +2107,9 @@
assert loader instanceof ReadOnlyDelegatingCacheLoader;
}
-
// old state should be persisted.
assert "v".equals(loader.get(fqn).get("k"));
- assert "v".equals(cache.get(fqn, "k"));
+ assert "v".equals(cache.get(fqn, "k"));
// the loader should now be read-only
cache.put(fqn, "k", "v2");
Modified: core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderFullTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderFullTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/ChainingCacheLoaderFullTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,7 +6,7 @@
*/
package org.jboss.cache.loader;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.CacheLoaderConfig;
@@ -29,7 +29,7 @@
@Test(groups = {"functional"})
public class ChainingCacheLoaderFullTest
{
- private CacheImpl<Object, Object> cache;
+ private CacheSPI<Object, Object> cache;
private ChainingCacheLoader chainingCacheLoader;
private CacheLoader loader1, loader2;
private Fqn fqn = Fqn.fromString("/a/b");
@@ -39,7 +39,7 @@
protected void startCache(boolean ignoreMods1, boolean ignoreMods2) throws Exception
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig(ignoreMods1, ignoreMods2));
cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
@@ -51,13 +51,15 @@
loader2 = chainingCacheLoader.getCacheLoaders().get(1);
// we need to make sure we have the raw loaders - not the "ReadOnly.." wrapped versions.
- while (loader1 instanceof AbstractDelegatingCacheLoader) loader1 = ((AbstractDelegatingCacheLoader) loader1).getCacheLoader();
- while (loader2 instanceof AbstractDelegatingCacheLoader) loader2 = ((AbstractDelegatingCacheLoader) loader2).getCacheLoader();
+ while (loader1 instanceof AbstractDelegatingCacheLoader)
+ loader1 = ((AbstractDelegatingCacheLoader) loader1).getCacheLoader();
+ while (loader2 instanceof AbstractDelegatingCacheLoader)
+ loader2 = ((AbstractDelegatingCacheLoader) loader2).getCacheLoader();
}
protected void cleanup() throws Exception
{
- cache.remove("/");
+ cache.removeNode(Fqn.ROOT);
cache.stop();
cache = null;
}
@@ -65,25 +67,25 @@
protected CacheLoaderConfig getCacheLoaderConfig(boolean ignoreMods1, boolean ignoreMods2) throws Exception
{
String xml = "<config>\n" +
- "<passivation>false</passivation>\n" +
- "<preload></preload>\n" +
- "<cacheloader>\n" +
- "<class>"+ DummyInMemoryCacheLoader.class.getName() +"</class>\n" +
- "<properties>" +
- "</properties>\n" +
- "<async>false</async>\n" +
- "<fetchPersistentState>true</fetchPersistentState>\n" +
- "<ignoreModifications>" + ignoreMods1 + "</ignoreModifications>\n" +
- "</cacheloader>\n" +
- "<cacheloader>\n" +
- "<class>"+ DummyInMemoryCacheLoader.class.getName() +"</class>\n" +
- "<properties>" +
- "</properties>\n" +
- "<async>false</async>\n" +
- "<fetchPersistentState>false</fetchPersistentState>\n" +
- "<ignoreModifications>" + ignoreMods2 + "</ignoreModifications>\n" +
- "</cacheloader>\n" +
- "</config>";
+ "<passivation>false</passivation>\n" +
+ "<preload></preload>\n" +
+ "<cacheloader>\n" +
+ "<class>" + DummyInMemoryCacheLoader.class.getName() + "</class>\n" +
+ "<properties>" +
+ "</properties>\n" +
+ "<async>false</async>\n" +
+ "<fetchPersistentState>true</fetchPersistentState>\n" +
+ "<ignoreModifications>" + ignoreMods1 + "</ignoreModifications>\n" +
+ "</cacheloader>\n" +
+ "<cacheloader>\n" +
+ "<class>" + DummyInMemoryCacheLoader.class.getName() + "</class>\n" +
+ "<properties>" +
+ "</properties>\n" +
+ "<async>false</async>\n" +
+ "<fetchPersistentState>false</fetchPersistentState>\n" +
+ "<ignoreModifications>" + ignoreMods2 + "</ignoreModifications>\n" +
+ "</cacheloader>\n" +
+ "</config>";
Element element = XmlHelper.stringToElement(xml);
return XmlConfigurationParser.parseCacheLoaderConfig(element);
}
@@ -108,7 +110,7 @@
assertEquals(value, cache.get(fqn, key));
// remove
- cache.remove(fqn);
+ cache.removeNode(fqn);
assertNull(value, cache.get(fqn, key));
assertNull(value, chainingCacheLoader.get(fqn));
assertNull(value, loader1.get(fqn));
@@ -131,7 +133,7 @@
assertEquals(value + 2, chainingCacheLoader.get(fqn).get(key));
assertEquals(value + 2, cache.get(fqn, key));
- cache.remove("/");
+ cache.removeNode(Fqn.ROOT);
cache.put(fqn, key, value);
// test that loader2 is NOT checked if loader1 has the value
@@ -142,7 +144,7 @@
assertEquals(value, chainingCacheLoader.get(fqn).get(key));
assertEquals(value, cache.get(fqn, key));
- cache.remove("/");
+ cache.removeNode(Fqn.ROOT);
cache.put(fqn, key, value);
// test that loader2 is checked if loader1 returns a null
@@ -178,7 +180,7 @@
assertEquals(value, loader2.get(fqn).get(key));
// remove
- cache.remove(fqn);
+ cache.removeNode(fqn);
assertEquals(value, chainingCacheLoader.get(fqn).get(key));
assertNull(loader1.get(fqn));
assertEquals(value, loader2.get(fqn).get(key));
@@ -217,7 +219,7 @@
// remove - not in a tx, see http://jira.jboss.com/jira/browse/JBCACHE-352
// mgr.begin();
- cache.remove(fqn);
+ cache.removeNode(fqn);
// assertNull(cache.get(fqn, key));
// assertEquals(value + 2, chainingCacheLoader.get(fqn).get(key));
@@ -265,7 +267,7 @@
// remove - not in a tx, see http://jira.jboss.com/jira/browse/JBCACHE-352
// mgr.begin();
- cache.remove(fqn);
+ cache.removeNode(fqn);
// assertEquals(value, chainingCacheLoader.get(fqn).get(key));
// assertEquals(value, loader1.get(fqn).get(key));
// assertEquals(value, loader2.get(fqn).get(key));
Modified: core/trunk/src/test/java/org/jboss/cache/loader/ClusteredCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/ClusteredCacheLoaderTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/ClusteredCacheLoaderTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -9,13 +9,13 @@
import junit.framework.Assert;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
-import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.TimeoutException;
+import org.jboss.cache.misc.TestingUtil;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -37,7 +37,7 @@
public class ClusteredCacheLoaderTest extends AbstractCacheLoaderTestBase
{
private static Log log = LogFactory.getLog(ClusteredCacheLoaderTest.class);
- private CacheImpl<Object, Object> cache1, cache2;
+ private CacheSPI<Object, Object> cache1, cache2;
private CacheLoader loader1, loader2;
private Fqn<String> fqn = Fqn.fromString("/a");
private String key = "key";
@@ -49,8 +49,8 @@
public void setUp() throws Exception
{
if (cache1 != null || cache2 != null) tearDown();
- cache1 = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
- cache2 = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache1 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache2 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
cache1.getConfiguration().setClusterName("CCL-Test");
cache1.getConfiguration().setStateRetrievalTimeout(2000);
Modified: core/trunk/src/test/java/org/jboss/cache/loader/InterceptorSynchronizationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/InterceptorSynchronizationTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/InterceptorSynchronizationTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,6 +1,14 @@
package org.jboss.cache.loader;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Modification;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import static org.testng.AssertJUnit.assertTrue;
+import org.testng.annotations.Test;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -11,14 +19,6 @@
import java.util.Map;
import java.util.Set;
-import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheImpl;
-import org.jboss.cache.DefaultCacheFactory;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.Modification;
-import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
-import org.testng.annotations.Test;
-
/**
* Test case that proves that the CacheImpl is serialized inside the CacheLoaderInterceptor
* when the node is empty. ANY call to retrieve a node that is not loaded will lock
@@ -39,8 +39,13 @@
public void testBlockingProblem() throws Exception
{
- CacheImpl<Object, Object> cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
- cache.setCacheLoader(new TestSlowCacheLoader());
+ CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ //setCacheLoader(new TestSlowCacheLoader());
+ CacheLoaderConfig clc = new CacheLoaderConfig();
+ IndividualCacheLoaderConfig iclc = new IndividualCacheLoaderConfig();
+ iclc.setClassName(TestSlowCacheLoader.class.getName());
+ clc.addIndividualCacheLoaderConfig(iclc);
+ cache.getConfiguration().setCacheLoaderConfig(clc);
cache.start();
long begin = System.currentTimeMillis();
@@ -101,7 +106,7 @@
return null;
}
- public Object get(Fqn arg0, Object arg1) throws Exception
+ public Object get(Fqn arg0, Object arg1)
{
return null;
}
@@ -109,7 +114,7 @@
public Map<Object, Object> get(Fqn arg0) throws Exception
{
Thread.sleep(CACHELOADER_WAITTIME);
- return Collections.singletonMap((Object)"foo", (Object)"bar");
+ return Collections.singletonMap((Object) "foo", (Object) "bar");
}
public boolean exists(Fqn arg0) throws Exception
@@ -159,23 +164,6 @@
{
}
- /*public byte[] loadEntireState() throws Exception {
- return null;
- }
-
- public void storeEntireState(byte[] arg0) throws Exception {
-
- }
-
- public byte[] loadState(Fqn subtree) throws Exception
- {
- return new byte[0];
- }
-
- public void storeState(byte[] state, Fqn subtree) throws Exception
- {
- }*/
-
public void loadEntireState(ObjectOutputStream os) throws Exception
{
// nothing to do here
@@ -222,9 +210,9 @@
private static class Retriever implements Runnable
{
private final String fqn;
- private CacheImpl<Object, Object> cache;
+ private CacheSPI<Object, Object> cache;
- private Retriever(CacheImpl<Object, Object> cache, String fqn)
+ private Retriever(CacheSPI<Object, Object> cache, String fqn)
{
this.fqn = fqn;
this.cache = cache;
Modified: core/trunk/src/test/java/org/jboss/cache/loader/JDBCCacheLoaderDerbyDSTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/JDBCCacheLoaderDerbyDSTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/JDBCCacheLoaderDerbyDSTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,23 +6,18 @@
*/
package org.jboss.cache.loader;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NameNotFoundException;
-
import org.apache.derby.jdbc.EmbeddedXADataSource;
import org.jboss.cache.Fqn;
import org.jboss.cache.transaction.DummyTransactionManager;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import java.util.Properties;
+
/**
* This test runs cache loader tests using Database as the cache loader store.
* The default test is configured using MySQL.
@@ -37,7 +32,7 @@
*/
@Test(groups = {"functional"})
public class JDBCCacheLoaderDerbyDSTest
- extends CacheLoaderTestsBase
+ extends CacheLoaderTestsBase
{
private String old_factory = null;
private final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
@@ -75,13 +70,12 @@
ds.setDatabaseName("jbossdb");
ds.setCreateDatabase("create");
ds.setUser(prop.getProperty("cache.jdbc.user"));
- ;
ds.setPassword(prop.getProperty("cache.jdbc.password"));
String props = "cache.jdbc.datasource =" + JNDI_NAME + "\n" +
- "cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type") + "\n" +
- "cache.jdbc.sql-concat= 1 || 2";
+ "cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type") + "\n" +
+ "cache.jdbc.sql-concat= 1 || 2";
cache.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", "org.jboss.cache.loader.JDBCCacheLoader", props, false, true, false));
Modified: core/trunk/src/test/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/LocalDelegatingCacheLoaderTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,8 +1,9 @@
package org.jboss.cache.loader;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.misc.TestingUtil;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -14,12 +15,12 @@
*/
public class LocalDelegatingCacheLoaderTest extends CacheLoaderTestsBase
{
- CacheImpl delegating_cache;
+ CacheSPI delegating_cache;
@SuppressWarnings("deprecation")
protected void configureCache() throws Exception
{
- delegating_cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
+ delegating_cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
delegating_cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
delegating_cache.create();
delegating_cache.start();
@@ -29,7 +30,9 @@
// force our own cache loader instance
LocalDelegatingCacheLoader cacheLoader = new LocalDelegatingCacheLoader(delegating_cache);
- cache.setCacheLoader(cacheLoader);
+
+ // don't actually alter the interceptor chain, but this will force a re-injection of all deps in all components.
+ TestingUtil.replaceInterceptorChain(cache, cache.getInterceptorChain().get(0));
}
protected void postConfigure()
Modified: core/trunk/src/test/java/org/jboss/cache/loader/SharedCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/SharedCacheLoaderTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/SharedCacheLoaderTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,17 +6,17 @@
*/
package org.jboss.cache.loader;
-import static org.testng.AssertJUnit.assertEquals;
-
-import java.util.Iterator;
-
import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.interceptors.CacheStoreInterceptor;
import org.jboss.cache.interceptors.Interceptor;
+import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import java.util.Iterator;
+
/**
* See http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3919374#3919374
*
@@ -24,7 +24,7 @@
*/
public class SharedCacheLoaderTest extends AbstractCacheLoaderTestBase
{
- private CacheImpl<Object, Object> cache1, cache2;
+ private CacheSPI<Object, Object> cache1, cache2;
private DummyCacheLoader dummyCacheLoader;
@BeforeMethod(alwaysRun = true)
@@ -34,25 +34,25 @@
if (cache1 != null || cache2 != null) tearDown();
// set up 2 instances of CacheImpl with shared CacheLoaders.
- cache1 = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
- cache2 = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache1 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache2 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
cache1.getConfiguration().setCacheMode("REPL_SYNC");
cache2.getConfiguration().setCacheMode("REPL_SYNC");
- cache1.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCacheLoader.class.getName(), "", false, false, true));
- cache2.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyCacheLoader.class.getName(), "", false, false, true));
+ cache1.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummySharedInMemoryCacheLoader.class.getName(), "", false, false, true));
+ cache2.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummySharedInMemoryCacheLoader.class.getName(), "", false, false, true));
cache1.start();
cache2.start();
// force setting up the same cache loader class
- dummyCacheLoader = new DummyCacheLoader();
-
- cache1.setCacheLoader(dummyCacheLoader);
- cache2.setCacheLoader(dummyCacheLoader);
- findCacheStoreInterceptor(cache1).setCache(cache1);
- findCacheStoreInterceptor(cache2).setCache(cache2);
+// dummyCacheLoader = new DummyCacheLoader();
+//
+// cache1.setCacheLoader(dummyCacheLoader);
+// cache2.setCacheLoader(dummyCacheLoader);
+// findCacheStoreInterceptor(cache1).setCache(cache1);
+// findCacheStoreInterceptor(cache2).setCache(cache2);
}
protected CacheStoreInterceptor findCacheStoreInterceptor(CacheImpl cache)
@@ -80,7 +80,7 @@
cache2 = null;
}
- public void testReplicationWithSharedCL() throws Exception
+ public void testReplicationWithSharedCL()
{
cache1.put("/test", "one", "two");
Modified: core/trunk/src/test/java/org/jboss/cache/loader/SingletonStoreCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/SingletonStoreCacheLoaderTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/SingletonStoreCacheLoaderTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -8,7 +8,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheImpl;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
@@ -31,6 +30,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+
/**
* Unit test class for SingletonStoreCacheLoader
*
@@ -46,9 +46,9 @@
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- cache1 = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
- cache2 = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
- cache3 = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
+ cache1 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
+ cache2 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
+ cache3 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
}
public void testPutCacheLoaderWithNoPush() throws Exception
@@ -244,14 +244,14 @@
}
- private void createCaches() throws Exception
+ private void createCaches()
{
cache1.create();
cache2.create();
cache3.create();
}
- private void statCaches() throws Exception
+ private void statCaches()
{
cache1.start();
cache2.start();
@@ -276,20 +276,20 @@
int pushStateWhenCoordinatorTimeout) throws Exception
{
String xml = "<config>\n" +
- "<passivation>false</passivation>\n" +
- "<preload></preload>\n" +
- "<cacheloader>\n" +
- " <class>" + cacheloaderClass + "</class>\n" +
- " <properties></properties>\n" +
- " <singletonStore>" +
- " <enabled>true</enabled>" +
- " <properties>" +
- " pushStateWhenCoordinator = true\n" +
- " pushStateWhenCoordinatorTimeout = 5000\n" +
- " </properties>" +
- " </singletonStore>" +
- "</cacheloader>\n" +
- "</config>";
+ "<passivation>false</passivation>\n" +
+ "<preload></preload>\n" +
+ "<cacheloader>\n" +
+ " <class>" + cacheloaderClass + "</class>\n" +
+ " <properties></properties>\n" +
+ " <singletonStore>" +
+ " <enabled>true</enabled>" +
+ " <properties>" +
+ " pushStateWhenCoordinator = true\n" +
+ " pushStateWhenCoordinatorTimeout = 5000\n" +
+ " </properties>" +
+ " </singletonStore>" +
+ "</cacheloader>\n" +
+ "</config>";
Element element = XmlHelper.stringToElement(xml);
return XmlConfigurationParser.parseCacheLoaderConfig(element);
}
@@ -297,13 +297,13 @@
private void initSingletonNonPushCache(CacheSPI cache) throws Exception
{
cache.getConfiguration().setCacheLoaderConfig(getSingletonStoreCacheLoaderConfig(
- DummyInMemoryCacheLoader.class.getName(), true, false, 1000));
+ DummyInMemoryCacheLoader.class.getName(), true, false, 1000));
}
private void initSingletonWithPushCache(CacheSPI cache) throws Exception
{
cache.getConfiguration().setCacheLoaderConfig(getSingletonStoreCacheLoaderConfig(
- DummyInMemoryCacheLoader.class.getName(), true, true, 1000));
+ DummyInMemoryCacheLoader.class.getName(), true, true, 1000));
}
private CacheLoader getDelegatingCacheLoader(CacheSPI cache)
Modified: core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheServerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheServerTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/TcpCacheServerTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,29 +1,23 @@
package org.jboss.cache.loader;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-
-import java.net.UnknownHostException;
-
import org.jboss.cache.Cache;
-import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheImpl;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.jmx.CacheJmxWrapper;
import org.jboss.cache.loader.tcp.TcpCacheServer;
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.xml.XmlHelper;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
+
+import java.net.UnknownHostException;
+
/**
* Tests various ways of setting up the TcpCacheServer
*
@@ -37,7 +31,7 @@
static TcpCacheServer cache_server = null;
- private CacheImpl<Object, Object> cache;
+ private CacheSPI<Object, Object> cache;
private CacheLoader loader;
static
@@ -55,13 +49,13 @@
});
}
- private void createCacheAndLoader() throws Exception, ConfigurationException, CacheException
+ private void createCacheAndLoader() throws Exception
{
Configuration c = new Configuration();
c.setCacheMode(Configuration.CacheMode.LOCAL);
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
c.setCacheLoaderConfig(getCacheLoaderConfig());
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(c);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(c);
cache.start();
loader = cache.getCacheLoaderManager().getCacheLoader();
@@ -70,17 +64,17 @@
protected CacheLoaderConfig getCacheLoaderConfig() throws Exception
{
String xml = "<config>\n" +
- "<passivation>false</passivation>\n" +
- "<preload></preload>\n" +
- "<cacheloader>\n" +
- "<class>org.jboss.cache.loader.TcpDelegatingCacheLoader</class>\n" +
- "<properties>host=127.0.0.1\nport=12121</properties>\n" +
- "<async>false</async>\n" +
- "<shared>true</shared>\n" +
- "<fetchPersistentState>true</fetchPersistentState>\n" +
- "<purgeOnStartup>false</purgeOnStartup>\n" +
- "</cacheloader>\n" +
- "</config>";
+ "<passivation>false</passivation>\n" +
+ "<preload></preload>\n" +
+ "<cacheloader>\n" +
+ "<class>org.jboss.cache.loader.TcpDelegatingCacheLoader</class>\n" +
+ "<properties>host=127.0.0.1\nport=12121</properties>\n" +
+ "<async>false</async>\n" +
+ "<shared>true</shared>\n" +
+ "<fetchPersistentState>true</fetchPersistentState>\n" +
+ "<purgeOnStartup>false</purgeOnStartup>\n" +
+ "</cacheloader>\n" +
+ "</config>";
Element element = XmlHelper.stringToElement(xml);
return XmlConfigurationParser.parseCacheLoaderConfig(element);
}
Modified: core/trunk/src/test/java/org/jboss/cache/loader/TxCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/TxCacheLoaderTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/TxCacheLoaderTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,30 +1,21 @@
package org.jboss.cache.loader;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import java.io.File;
-import java.util.Set;
-
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.TransactionSetup;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.Set;
+
/**
* @author Bela Ban
* @version $Id$
@@ -32,14 +23,14 @@
@Test(groups = {"functional", "transaction"})
public class TxCacheLoaderTest extends AbstractCacheLoaderTestBase
{
- CacheImpl<Object, Object> cache1, cache2;
+ CacheSPI<Object, Object> cache1, cache2;
private Fqn<String> fqn = Fqn.fromString("/one/two/three");
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- cache1 = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache1 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
cache1.getConfiguration().setCacheMode("repl_sync");
cache1.getConfiguration().setTransactionManagerLookupClass(TransactionSetup.getManagerLookup());
@@ -48,7 +39,7 @@
cache1.create();
cache1.start();
- cache2 = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache2 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
cache2.getConfiguration().setCacheMode("repl_sync");
cache2.getConfiguration().setTransactionManagerLookupClass(TransactionSetup.getManagerLookup());
cache2.getConfiguration().setCacheLoaderConfig(getSingleCacheLoaderConfig("", DummyInMemoryCacheLoader.class.getName(), "", false, false, false));
@@ -62,7 +53,7 @@
public void tearDown() throws Exception
{
// clean up cache loaders!!
- cache1.remove(Fqn.ROOT);
+ cache1.removeNode(Fqn.ROOT);
cache1.stop();
cache1.destroy();
@@ -71,7 +62,7 @@
}
- public void testTxPutCommit() throws Exception, NotSupportedException
+ public void testTxPutCommit() throws Exception
{
TransactionManager mgr = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
@@ -82,8 +73,8 @@
assertNull(cache2.get(fqn, "key1"));
assertNull(cache2.get("/one/two/three/four", "key2"));
mgr.commit();
- assertNotNull(cache1.getKeys(fqn));
- Set<?> children = cache1.getChildrenNames("/one");
+ assertNotNull(cache1.getNode(fqn).getKeys());
+ Set<?> children = cache1.getNode("/one").getChildrenNames();
assertEquals(1, children.size());
TestingUtil.sleepThread(2000);
assertEquals("val1", cache2.get(fqn, "key1"));
@@ -91,7 +82,7 @@
}
- public void testTxPrepareAndRollback() throws Exception, NotSupportedException
+ public void testTxPrepareAndRollback() throws Exception
{
final TransactionManager mgr = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
@@ -157,7 +148,7 @@
}
- public void testPutAfterTxCommit() throws Exception, NotSupportedException
+ public void testPutAfterTxCommit() throws Exception
{
TransactionManager mgr = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
@@ -170,7 +161,7 @@
assertTrue(cache1.exists("/a/b/c"));
}
- public void testPutAfterTxRollback() throws Exception, NotSupportedException
+ public void testPutAfterTxRollback() throws Exception
{
TransactionManager mgr = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
@@ -178,7 +169,7 @@
cache1.put(fqn, "key1", "val1");
assertTrue(cache1.exists(fqn));
mgr.rollback();
- assertFalse(cache1.getCacheLoader().exists(fqn));
+ assertFalse(cache1.getCacheLoaderManager().getCacheLoader().exists(fqn));
assertFalse(cache1.exists(fqn));
cache1.put("/a/b/c", null);// should be run outside a TX !
assertTrue(cache1.exists("/a/b/c"));
Modified: core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/UnnecessaryLoadingTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,31 +1,24 @@
package org.jboss.cache.loader;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
import org.easymock.EasyMock;
+import static org.easymock.EasyMock.*;
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.CacheLoaderConfig;
import org.jboss.cache.factories.InterceptorChainFactory;
-import org.jboss.cache.interceptors.Interceptor;
+import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
/**
* //TODO: MANIK: Javadoc this class
*
@@ -55,7 +48,7 @@
cache.getCacheLoaderManager().setCacheLoader(mockCacheLoader);
// re-set the cache so that the mock CL is registered with the inerceptors.
- InterceptorChainFactory.getInstance().initialiseInterceptors((Interceptor) cache.getInterceptorChain().get(0), cache);
+ InterceptorChainFactory.getInstance().correctInterceptorChaining(cache.getInterceptorChain(), cache.getConfiguration(), TestingUtil.extractComponentRegistry(cache));
// lifecycle stuff
mockCacheLoader.stop();
@@ -169,7 +162,7 @@
// expecting a put on child
mockCacheLoader.put(eq(child), eq(m));
expect(mockCacheLoader.get(eq(child))).andReturn(null);
- expect((Set<String>)mockCacheLoader.getChildrenNames(eq(parent))).andReturn(Collections.singleton(child.getLastElementAsString()));
+ expect((Set<String>) mockCacheLoader.getChildrenNames(eq(parent))).andReturn(Collections.singleton(child.getLastElementAsString()));
replay(mockCacheLoader);
cache.put(child, m);
@@ -253,7 +246,7 @@
expect(mockCacheLoader.get(eq(parent))).andReturn(null);
expect(mockCacheLoader.exists(eq(parent))).andReturn(true);
mockCacheLoader.removeData(eq(parent));
- mockCacheLoader.put(eq(parent), eq(Collections.singletonMap((Object)"hello", (Object)"world")));
+ mockCacheLoader.put(eq(parent), eq(Collections.singletonMap((Object) "hello", (Object) "world")));
replay(mockCacheLoader);
cache.put(parent, k, v);
@@ -271,7 +264,7 @@
// will trigger a put() though
// for the moment this does a get as well - which while unnecessary is the best we can do for now until we bring in
// an AOP framework to work on nodes directly.
- n.replaceAll(Collections.singletonMap((Object)"hello", (Object)"world"));
+ n.replaceAll(Collections.singletonMap((Object) "hello", (Object) "world"));
assertDataLoaded(parent);
verify(mockCacheLoader);
@@ -282,7 +275,7 @@
expect(mockCacheLoader.put(eq(parent), eq(k), eq(v))).andReturn(null);
expect(mockCacheLoader.get(eq(parent))).andReturn(null);
expect(mockCacheLoader.exists(eq(parent))).andReturn(true);
- expect(mockCacheLoader.get(eq(parent))).andReturn(Collections.singletonMap((Object)k, (Object)v));
+ expect(mockCacheLoader.get(eq(parent))).andReturn(Collections.singletonMap((Object) k, (Object) v));
replay(mockCacheLoader);
cache.put(parent, k, v);
@@ -312,7 +305,7 @@
expect(mockCacheLoader.get(eq(parent))).andReturn(null);
expect(mockCacheLoader.put(eq(parent), eq(k), eq(v))).andReturn(null);
mockCacheLoader.put(eq(parent), eq(m));
- expect(mockCacheLoader.get(eq(parent))).andReturn(Collections.singletonMap((Object)k, (Object)v));
+ expect(mockCacheLoader.get(eq(parent))).andReturn(Collections.singletonMap((Object) k, (Object) v));
replay(mockCacheLoader);
cache.put(parent, k, v);
assertDataLoaded(parent);
Modified: core/trunk/src/test/java/org/jboss/cache/loader/deadlock/ConcurrentCreationDeadlockTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/deadlock/ConcurrentCreationDeadlockTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/loader/deadlock/ConcurrentCreationDeadlockTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,6 +1,6 @@
package org.jboss.cache.loader.deadlock;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
@@ -62,7 +62,8 @@
* CacheLoader/StoreInterceptor's...</li>
* </ul>
*/
-@Test (groups = {"functional"}, enabled = false) // Disabling since this has issues with ReadWriteWithUpgradeLock. See JBCACHE-461
+@Test(groups = {"functional"}, enabled = false)
+// Disabling since this has issues with ReadWriteWithUpgradeLock. See JBCACHE-461
public class ConcurrentCreationDeadlockTest extends AbstractCacheLoaderTestBase
{
/**
@@ -100,13 +101,13 @@
/**
* The cache under test.
*/
- private CacheImpl<Object, Object> cache = null;
+ private CacheSPI<Object, Object> cache = null;
static
{
PROPERTIES = new Properties();
PROPERTIES.put(Context.INITIAL_CONTEXT_FACTORY,
- "org.jboss.cache.transaction.DummyContextFactory");
+ "org.jboss.cache.transaction.DummyContextFactory");
}
/**
@@ -118,10 +119,10 @@
mcl_exception = null;
m_contextFactory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, CONTEXT_FACTORY);
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+
Configuration c = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC);
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- cache.setConfiguration(c);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(c, false);
}
/**
@@ -136,7 +137,7 @@
if (m_contextFactory != null)
{
System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
- m_contextFactory);
+ m_contextFactory);
m_contextFactory = null;
}
}
@@ -346,7 +347,7 @@
for (int j = 0; j < t.length; j++)
{
t[j] = new Worker(latch, NUM_FQNS_PER_RUN * i,
- NUM_FQNS_PER_RUN, modificationsPerTx);
+ NUM_FQNS_PER_RUN, modificationsPerTx);
t[j].start();
}
// fire the workers to start processing
@@ -379,7 +380,7 @@
private void log(String msg)
{
System.out.println(System.currentTimeMillis() + " "
- + Thread.currentThread() + " " + msg);
+ + Thread.currentThread() + " " + msg);
}
/**
Modified: core/trunk/src/test/java/org/jboss/cache/lock/AcquireAllTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/lock/AcquireAllTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/lock/AcquireAllTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,12 +1,11 @@
package org.jboss.cache.lock;
-import static org.testng.AssertJUnit.assertEquals;
-
import org.jboss.cache.CacheImpl;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.Configuration;
+import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -83,7 +82,7 @@
}
- private CacheImpl createCache(Configuration.CacheMode mode, IsolationLevel level) throws Exception
+ private CacheImpl createCache(Configuration.CacheMode mode, IsolationLevel level)
{
CacheImpl c = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
c.getConfiguration().setCacheMode(mode);
Modified: core/trunk/src/test/java/org/jboss/cache/lock/BreakDeadMemberLocksTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/lock/BreakDeadMemberLocksTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/lock/BreakDeadMemberLocksTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -22,45 +22,45 @@
package org.jboss.cache.lock;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.transaction.Synchronization;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.Synchronization;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* Tests the breaking of locks held by dead members.
*
* @author <a href="mailto://brian.stansberry@jboss.com">Brian Stansberry</a>
* @version $Revision$
*/
-@Test(groups={"functional"})
+@Test(groups = {"functional"})
public class BreakDeadMemberLocksTest
{
- private Map<String, CacheImpl<Object, Object>> caches;
+ private Map<String, CacheSPI<Object, Object>> caches;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- caches = new HashMap<String, CacheImpl<Object, Object>>();
+ caches = new HashMap<String, CacheSPI<Object, Object>>();
}
public void testBreakDeadMemberLocks() throws Exception
{
- CacheImpl<Object, Object> cacheA = createCache("A");
+ CacheSPI<Object, Object> cacheA = createCache("A");
cacheA.put("/1/A", "1", "A");
cacheA.put("/1/A", "2", "A");
@@ -69,10 +69,10 @@
cacheA.put("/1/A/I", "1", "A");
cacheA.put("/1/A/I", "2", "A");
- CacheImpl<Object, Object> cacheB = createCache("B");
+ CacheSPI<Object, Object> cacheB = createCache("B");
// Pause to give caches time to see each other
- TestingUtil.blockUntilViewsReceived(new CacheImpl[]{cacheA, cacheB}, 60000);
+ TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cacheA, cacheB}, 60000);
final TransactionManager tm = cacheB.getTransactionManager();
tm.begin();
@@ -99,7 +99,9 @@
tm.resume(tx);
tm.commit();
}
- catch (Exception e) {}
+ catch (Exception e)
+ {
+ }
}
};
@@ -116,7 +118,7 @@
tm.suspend();
// Confirm that B's tx replicated
- assertTrue(cacheA.exists("/EXISTS"));
+ assertTrue(cacheA.peek(Fqn.fromString("/EXISTS"), false, false) != null);
cacheB.stop();
cacheB.destroy();
@@ -127,7 +129,9 @@
{
Thread.sleep(100);
}
- catch (InterruptedException e) {}
+ catch (InterruptedException e)
+ {
+ }
}
assertEquals("A", cacheA.get("/1/A", "1"));
@@ -143,15 +147,14 @@
}
}
- protected CacheImpl<Object, Object> createCache(String cacheID) throws Exception
+ protected CacheSPI<Object, Object> createCache(String cacheID) throws Exception
{
if (caches.get(cacheID) != null)
{
throw new IllegalStateException(cacheID + " already created");
}
- CacheImpl<Object, Object> cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
- cache.setConfiguration(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC));
+ CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
cache.create();
cache.start();
@@ -214,7 +217,9 @@
{
Thread.sleep(30000);
}
- catch (InterruptedException e) {}
+ catch (InterruptedException e)
+ {
+ }
}
Modified: core/trunk/src/test/java/org/jboss/cache/lock/LockReleaseTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/lock/LockReleaseTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/lock/LockReleaseTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -8,21 +8,19 @@
package org.jboss.cache.lock;
-import static org.testng.AssertJUnit.assertEquals;
-
-import java.util.Set;
-
-import javax.transaction.UserTransaction;
-
import org.apache.commons.logging.Log;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.transaction.TransactionSetup;
+import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.UserTransaction;
+import java.util.Set;
+
/**
* Verifies that there are no read locks held when a transaction ends.
*
@@ -32,7 +30,7 @@
@Test(groups = {"functional"})
public class LockReleaseTest
{
- CacheImpl<Object, Object> cache = null;
+ CacheSPI<Object, Object> cache = null;
UserTransaction tx = null;
Log log;
final Fqn<String> NODE1 = Fqn.fromString("/test");
@@ -71,9 +69,9 @@
}
}
- CacheImpl<Object, Object> createCache(IsolationLevel level) throws Exception
+ CacheSPI<Object, Object> createCache(IsolationLevel level) throws Exception
{
- CacheImpl<Object, Object> c = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ CacheSPI<Object, Object> c = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
c.getConfiguration().setClusterName("test");
c.getConfiguration().setStateRetrievalTimeout(10000);
c.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.GenericTransactionManagerLookup");
@@ -137,14 +135,14 @@
cache.put(NODE2, KEY, VAL1);
assertEquals("we ran outside of a TX, locks should have been released: ", 0, cache.getNumberOfLocksHeld());
- Set<Object> keys = cache.getKeys(NODE1);
+ Set<Object> keys = cache.getNode(NODE1).getKeys();
System.out.println("keys of " + NODE1 + " are " + keys);
assertEquals("getKeys() called outside the TX should have released all locks", 0, cache.getNumberOfLocksHeld());
tx.begin();
- keys = cache.getKeys(NODE1);
+ keys = cache.getNode(NODE1).getKeys();
assertEquals("we should hold 1 read locks now: ", 2, cache.getNumberOfLocksHeld());
- keys = cache.getKeys(NODE2);
+ keys = cache.getNode(NODE2).getKeys();
assertEquals("we should hold 3 read locks now: ", 4, cache.getNumberOfLocksHeld());
tx.commit();
assertEquals("we should have released all 3 read locks: ", 0, cache.getNumberOfLocksHeld());
@@ -159,15 +157,15 @@
cache.put(NODE2, KEY, VAL1);
assertEquals("we ran outside of a TX, locks should have been released: ", 0, cache.getNumberOfLocksHeld());
- Set<String> keys = cache.getChildrenNames(NODE2);
+ Set<String> keys = cache.getNode(NODE2).getChildrenNames();
System.out.println("keys of " + NODE2 + " are " + keys);
assertEquals("getChildrenNames() called outside the TX should have released all locks", 0,
- cache.getNumberOfLocksHeld());
+ cache.getNumberOfLocksHeld());
tx.begin();
- keys = cache.getChildrenNames(NODE1);
+ keys = cache.getNode(NODE1).getChildrenNames();
assertEquals("we should hold 1 read locks now: ", 2, cache.getNumberOfLocksHeld());
- keys = cache.getChildrenNames(NODE2);
+ keys = cache.getNode(NODE2).getChildrenNames();
assertEquals("we should hold 3 read locks now: ", 4, cache.getNumberOfLocksHeld());
tx.commit();
assertEquals("we should have released all 3 read locks: ", 0, cache.getNumberOfLocksHeld());
@@ -181,13 +179,13 @@
cache.put(NODE2, KEY, VAL1);
assertEquals("we ran outside of a TX, locks should have been released: ", 0, cache.getNumberOfLocksHeld());
- cache.print(NODE1);
+ System.out.println(cache.getNode(NODE1));
assertEquals("print() called outside the TX should have released all locks", 0, cache.getNumberOfLocksHeld());
tx.begin();
- cache.print(NODE1);
+ System.out.println(cache.getNode(NODE1));
assertEquals("we should hold 1 read locks now (for print()): ", 2, cache.getNumberOfLocksHeld());
- cache.print(NODE2);
+ System.out.println(cache.getNode(NODE2));
assertEquals("we should hold 3 read locks now (for print()): ", 4, cache.getNumberOfLocksHeld());
tx.commit();
assertEquals("we should have released all 3 read locks: ", 0, cache.getNumberOfLocksHeld());
Modified: core/trunk/src/test/java/org/jboss/cache/lock/ReentrantWriterPreference2Readers1WriterLockTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/lock/ReentrantWriterPreference2Readers1WriterLockTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/lock/ReentrantWriterPreference2Readers1WriterLockTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,24 +6,22 @@
*/
package org.jboss.cache.lock;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
/**
* Tests ReentrantWriterPreferenceReadWriteLock
*
* @author Bela Ban
* @version $Id$
*/
-@Test(groups = { "functional" }, enabled = false) // historical disabled - and wont fix. See JBCACHE-461
+@Test(groups = {"functional"}, enabled = false)
+// historical disabled - and wont fix. See JBCACHE-461
public class ReentrantWriterPreference2Readers1WriterLockTest
{
ReentrantReadWriteLock lock;
@@ -48,7 +46,7 @@
private void log(String msg)
{
System.out.println(System.currentTimeMillis() + " " + Thread.currentThread() +
- " [" + Thread.currentThread().getName() + "]: " + msg);
+ " [" + Thread.currentThread().getName() + "]: " + msg);
}
@@ -134,7 +132,7 @@
upgrader.join(3000);
assertTrue("Known failure. See JBCACHE-461; This is due to a potential bug in ReentrantWriterPreferenceReadWriteLock !",
- upgrader.wasUpgradeSuccessful());
+ upgrader.wasUpgradeSuccessful());
}
@@ -213,7 +211,6 @@
}
catch (InterruptedException e)
{
- ;
}
finally
{
Modified: core/trunk/src/test/java/org/jboss/cache/lock/ReentrantWriterPreferenceReadWriteLockTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/lock/ReentrantWriterPreferenceReadWriteLockTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/lock/ReentrantWriterPreferenceReadWriteLockTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,24 +1,21 @@
package org.jboss.cache.lock;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Lock;
-
import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
+
/**
* Tests ReentrantWriterPreferenceReadWriteLock
*
* @author Bela Ban
* @version $Id$
*/
-@Test(groups = { "functional" })
+@Test(groups = {"functional"})
public class ReentrantWriterPreferenceReadWriteLockTest
{
// ReentrantWriterPreferenceReadWriteLock lock;
@@ -219,7 +216,7 @@
private static void log(String msg)
{
System.out.println(System.currentTimeMillis() + " " + Thread.currentThread() +
- " [" + Thread.currentThread().getName() + "]: " + msg);
+ " [" + Thread.currentThread().getName() + "]: " + msg);
}
class Reader extends Thread
@@ -247,7 +244,6 @@
}
catch (InterruptedException e)
{
- ;
}
}
}
@@ -278,7 +274,6 @@
}
catch (InterruptedException e)
{
- ;
}
}
}
@@ -321,7 +316,6 @@
}
catch (InterruptedException e)
{
- ;
}
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/lock/UpgradeLockTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/lock/UpgradeLockTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/lock/UpgradeLockTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -8,30 +8,29 @@
package org.jboss.cache.lock;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.transaction.DummyTransactionManager;
import static org.testng.AssertJUnit.assertEquals;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
-import java.util.Properties;
-
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.transaction.UserTransaction;
+import java.util.Properties;
-import org.jboss.cache.CacheImpl;
-import org.jboss.cache.DefaultCacheFactory;
-import org.jboss.cache.transaction.DummyTransactionManager;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
/**
* Tests upgrade locks from read -> write
*
* @author Bela Ban
* @version $Id$
*/
-@Test(groups = { "functional" })
+@Test(groups = {"functional"})
public class UpgradeLockTest
{
- CacheImpl<Object, Object> cache = null;
+ CacheSPI<Object, Object> cache = null;
UserTransaction tx = null;
Properties p = null;
String old_factory = null;
@@ -85,9 +84,9 @@
}
}
- private CacheImpl<Object, Object> createCache(IsolationLevel level) throws Exception
+ private CacheSPI<Object, Object> createCache(IsolationLevel level)
{
- CacheImpl<Object, Object> c = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ CacheSPI<Object, Object> c = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
c.getConfiguration().setClusterName("test");
c.getConfiguration().setStateRetrievalTimeout(10000);
c.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.JBossTransactionManagerLookup");
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/ActiveInactiveTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -7,23 +7,20 @@
package org.jboss.cache.marshall;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import java.lang.reflect.Method;
-
import org.jboss.cache.CacheImpl;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
import org.jboss.cache.Version;
+import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.lang.reflect.Method;
+
/**
* Tests the "activate/deactivate" functionality of LegacyTreeCacheMarshaller.
*
@@ -46,7 +43,7 @@
c.getConfiguration().setUseRegionBasedMarshalling(true);
c.getConfiguration().setFetchInMemoryState(false);
c.start();
- rman = c.getRegionManager();
+ rman = TestingUtil.extractComponentRegistry(c).getComponent(RegionManager.class);
}
@AfterMethod(alwaysRun = true)
@@ -64,11 +61,11 @@
rman.deactivate(A);
assertFalse("Root is not active after inactivating subtree",
- rman.isInactive(Fqn.ROOT));
+ rman.isInactive(Fqn.ROOT));
rman.activate(A);
assertFalse("Root is not active after activating subtree",
- rman.isInactive(Fqn.ROOT));
+ rman.isInactive(Fqn.ROOT));
rman.activate(A_B);
@@ -84,11 +81,11 @@
rman.activate(A);
assertTrue("Root is not inactive after activating subtree",
- rman.isInactive(Fqn.ROOT));
+ rman.isInactive(Fqn.ROOT));
rman.deactivate(A);
assertTrue("Root is not inactive after inactivating subtree",
- rman.isInactive(Fqn.ROOT));
+ rman.isInactive(Fqn.ROOT));
rman.deactivate(A_B);
@@ -101,26 +98,26 @@
rman.setDefaultInactive(false);
rman.activate(A);
assertFalse("/a is not active after activating",
- rman.isInactive(A));
+ rman.isInactive(A));
rman.deactivate(A);
rman.activate(A);
assertFalse("/a is not active after reactivating",
- rman.isInactive(A));
+ rman.isInactive(A));
rman.reset();
rman.setDefaultInactive(true);
rman.activate(I);
assertFalse("/i is not active after activating",
- rman.isInactive(I));
+ rman.isInactive(I));
assertFalse("/i/k is not active after activating /i",
- rman.isInactive(Fqn.fromString("/i/k")));
+ rman.isInactive(Fqn.fromString("/i/k")));
rman.deactivate(I);
rman.activate(I);
assertFalse("/i is not active after reactivating",
- rman.isInactive(I));
+ rman.isInactive(I));
}
public void testInactivate() throws Exception
@@ -129,32 +126,32 @@
rman.deactivate(I);
assertTrue("/i is not inactive after inactivating",
- rman.isInactive(I));
+ rman.isInactive(I));
rman.activate(I);
rman.deactivate(I);
assertTrue("/i is not inactive after re-inactivating",
- rman.isInactive(I));
+ rman.isInactive(I));
rman.reset();
rman.setDefaultInactive(false);
rman.deactivate(A);
assertTrue("/a is not inactive after inactivating",
- rman.isInactive(A));
+ rman.isInactive(A));
assertTrue("/a/b is not inactive after inactivating /a",
- rman.isInactive(A_B));
+ rman.isInactive(A_B));
rman.activate(A);
rman.deactivate(A);
assertTrue("/a is not inactive after re-inactivating",
- rman.isInactive(A));
+ rman.isInactive(A));
}
public void testObjectFromByteBuffer() throws Exception
{
MethodCall put = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal,
- null, A_B, "name", "Joe", false);
+ A_B, "name", "Joe", false);
MethodCall replicate = MethodCallFactory.create(MethodDeclarations.replicateMethod, put);
@@ -182,7 +179,7 @@
MethodCall result = (MethodCall) testee.objectFromByteBuffer(callBytes);
Method method = result.getMethod();
assertEquals("Did not get replicate method when passing" +
- " call for active node", MethodDeclarations.replicateMethod, method);
+ " call for active node", MethodDeclarations.replicateMethod, method);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/AsyncReplTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/AsyncReplTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/AsyncReplTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -9,20 +9,6 @@
package org.jboss.cache.marshall;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-
-import java.lang.reflect.Method;
-
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
@@ -32,9 +18,20 @@
import org.jboss.cache.marshall.data.Address;
import org.jboss.cache.marshall.data.Person;
import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.lang.reflect.Method;
+
/**
* Test marshalling for async mode.
*
@@ -71,7 +68,7 @@
TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cache1, cache2}, 60000);
}
- private CacheSPI<Object, Object> createCache(String name) throws Exception
+ private CacheSPI<Object, Object> createCache(String name)
{
CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_ASYNC), false);
cache.getConfiguration().setClusterName(name);
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshaller200Test.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -61,16 +61,15 @@
* region based marshalling is used, and it is expected that we would need to marshall the response using the same
* region as well. To deal with this, the region (as an Fqn) is read off the stream when unmarshalling and then
* stored in a ThreadLocal so it can be accessed for when the response needs to be marshalled again.
- *
+ * <p/>
* The problem here - registered as JBCACHE-1170 - is that this has a tendency to leak scope and affect more than the
* required method call.
- *
*/
public void testLeakageOfFqn() throws Throwable
{
// Use a thread pool so that we know threads will be reused.
// You don't need any concurrency here to demonstrate the failure - a single thread is enough.
- ExecutorService e = Executors.newFixedThreadPool(1);
+ ExecutorService e = Executors.newFixedThreadPool(1);
// to capture throwables
final List<Throwable> throwables = new CopyOnWriteArrayList<Throwable>();
@@ -87,14 +86,14 @@
final Fqn region = Fqn.fromString("/hello");
Region r = rm.getRegion(region, true);
r.registerContextClassLoader(this.getClass().getClassLoader());
- cm200.objectToObjectStream(MethodCallFactory.create(MethodDeclarations.clusteredGetMethod, null, null), oos, region);
+ cm200.objectToObjectStream(MethodCallFactory.create(MethodDeclarations.clusteredGetMethod, null), oos, region);
oos.close();
final byte[] stream = baos.toByteArray();
// so now the stream starts with the Fqn "/hello".
// repeat 100 times
- for (int i=0; i<100; i++)
+ for (int i = 0; i < 100; i++)
{
if (i % 3 == 0)
{
@@ -185,7 +184,7 @@
e.shutdown();
e.awaitTermination(60, TimeUnit.SECONDS);
-
+
for (Throwable t : throwables)
{
t.printStackTrace();
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -99,7 +99,7 @@
public void testStringBasedFqn() throws Exception
{
- Fqn fqn = new Fqn<Object>(new Object[]{"JSESSIONID", "1010.10.5:3000", "1234567890", "1"});
+ Fqn fqn = new Fqn<Object>("JSESSIONID", "1010.10.5:3000", "1234567890", "1");
byte[] asBytes = marshaller.objectToByteBuffer(fqn);
System.out.println("Marshalled to " + asBytes.length + " bytes");
Object o2 = marshaller.objectFromByteBuffer(asBytes);
@@ -108,7 +108,7 @@
public void testNonStringBasedFqn() throws Exception
{
- Fqn fqn = new Fqn<Object>(new Object[]{3, false});
+ Fqn fqn = new Fqn<Object>(3, false);
byte[] asBytes = marshaller.objectToByteBuffer(fqn);
Object o2 = marshaller.objectFromByteBuffer(asBytes);
assertEquals(fqn, o2);
@@ -116,8 +116,8 @@
public void testMethodCall() throws Exception
{
- Fqn fqn = new Fqn<Object>(new Object[]{3, false});
- MethodCall call = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, null, fqn, "key", "value", true);
+ Fqn fqn = new Fqn<Object>(3, false);
+ MethodCall call = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, fqn, "key", "value", true);
byte[] asBytes = marshaller.objectToByteBuffer(call);
Object o2 = marshaller.objectFromByteBuffer(asBytes);
@@ -129,8 +129,8 @@
public void testNestedMethodCall() throws Exception
{
- Fqn fqn = new Fqn<Object>(new Object[]{3, false});
- MethodCall call = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, null, fqn, "key", "value", true);
+ Fqn fqn = new Fqn<Object>(3, false);
+ MethodCall call = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, fqn, "key", "value", true);
MethodCall replicateCall = MethodCallFactory.create(MethodDeclarations.replicateMethod, call);
byte[] asBytes = marshaller.objectToByteBuffer(replicateCall);
Object o2 = marshaller.objectFromByteBuffer(asBytes);
@@ -216,15 +216,15 @@
// replication queue takes a list of replicate() MethodCalls and wraps them in a single replicate call.
List<MethodCall> calls = new ArrayList<MethodCall>();
- Fqn f = new Fqn<Object>(new Object[]{"BlahBlah", 3, false});
+ Fqn f = new Fqn<Object>("BlahBlah", 3, false);
String k = "key", v = "value";
- MethodCall actualCall = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, null, f, k, v, true);
+ MethodCall actualCall = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, f, k, v, true);
MethodCall replicateCall = MethodCallFactory.create(MethodDeclarations.replicateMethod, actualCall);
calls.add(replicateCall);
- actualCall = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, null, f, k, v, true);
+ actualCall = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, f, k, v, true);
replicateCall = MethodCallFactory.create(MethodDeclarations.replicateMethod, actualCall);
calls.add(replicateCall);
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CustomCollectionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CustomCollectionTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CustomCollectionTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,27 +1,20 @@
package org.jboss.cache.marshall;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNotSame;
-import static org.testng.AssertJUnit.assertSame;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import org.jboss.cache.Cache;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.IsolationLevel;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* Unit test to cover replication and marshalling of custom collections
*
@@ -31,8 +24,8 @@
@Test(groups = {"functional"})
public class CustomCollectionTest
{
- private Cache<Object, Object> cache1 =null;
- private Cache<Object, Object> cache2 =null;
+ private Cache<Object, Object> cache1 = null;
+ private Cache<Object, Object> cache2 = null;
private String myListClass = MyList.class.getName();
private String mySetClass = MySet.class.getName();
private String myMapClass = MyMap.class.getName();
@@ -202,7 +195,7 @@
}
}
- private void enableRegionBasedClassLoading(ClassLoader customClassLoader) throws Exception
+ private void enableRegionBasedClassLoading(ClassLoader customClassLoader)
{
cache1.getConfiguration().setUseRegionBasedMarshalling(true);
Region region1 = cache1.getRegion(fqn("/a"), true);
@@ -218,10 +211,10 @@
// cache2.getMarshaller().defaultMarshaller.useRegionBasedMarshalling = true;
}
- private ClassLoader getClassLoader() throws Exception
+ private ClassLoader getClassLoader()
{
- String[] includesClasses = { myListClass, mySetClass, myMapClass };
- String [] excludesClasses = {};
+ String[] includesClasses = {myListClass, mySetClass, myMapClass};
+ String[] excludesClasses = {};
ClassLoader cl = Thread.currentThread().getContextClassLoader();
return new SelectedClassnameClassLoader(includesClasses, excludesClasses, cl);
}
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/MethodCallFactoryTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/MethodCallFactoryTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/MethodCallFactoryTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,8 +1,7 @@
package org.jboss.cache.marshall;
-import static org.testng.AssertJUnit.assertEquals;
-
import org.jboss.cache.transaction.GlobalTransaction;
+import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.Test;
/**
@@ -22,7 +21,7 @@
public void testObjectArrayMethod()
{
GlobalTransaction gtx = new GlobalTransaction();
- MethodCall c = MethodCallFactory.create(MethodDeclarations.commitMethod, new Object[]{gtx});
+ MethodCall c = MethodCallFactory.create(MethodDeclarations.commitMethod, gtx);
assertEquals(gtx, c.getArgs()[0]);
}
@@ -30,7 +29,7 @@
public void testMultipleArrayElems()
{
GlobalTransaction gtx = new GlobalTransaction();
- MethodCall c = MethodCallFactory.create(MethodDeclarations.commitMethod, new Object[]{gtx, gtx, gtx});
+ MethodCall c = MethodCallFactory.create(MethodDeclarations.commitMethod, gtx, gtx, gtx);
assertEquals(gtx, c.getArgs()[0]);
assertEquals(gtx, c.getArgs()[1]);
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/MethodIdPreservationTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,6 +1,9 @@
package org.jboss.cache.marshall;
+import org.jboss.cache.Fqn;
import static org.testng.AssertJUnit.assertEquals;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -9,10 +12,6 @@
import java.util.ArrayList;
import java.util.List;
-import org.jboss.cache.Fqn;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
/**
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 2.0.0
@@ -33,12 +32,12 @@
{
byteStream = new ByteArrayOutputStream();
stream = new ObjectOutputStream(byteStream);
- call1 = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal, null, Fqn.ROOT, null, null, true);
- call2 = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal, null, Fqn.ROOT, null, null, true);
+ call1 = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal, Fqn.ROOT, null, null, true);
+ call2 = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal, Fqn.ROOT, null, null, true);
list.clear();
list.add(call1);
list.add(call2);
- prepareCall = MethodCallFactory.create(MethodDeclarations.prepareMethod, null, list, null, true);
+ prepareCall = MethodCallFactory.create(MethodDeclarations.prepareMethod, 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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/RegionManagerTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,24 +1,18 @@
package org.jboss.cache.marshall;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertSame;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.jboss.cache.CacheImpl;
-import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
/**
* Test on ERegionManager class, from a marshalling perspective.
*/
@@ -31,10 +25,7 @@
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- CacheImpl c = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
- c.create();
- r = new RegionManager(c);
- c.start();
+ r = new RegionManager();
}
@AfterMethod(alwaysRun = false)
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/RemoteCallerReturnValuesTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/RemoteCallerReturnValuesTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/RemoteCallerReturnValuesTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,12 +1,6 @@
package org.jboss.cache.marshall;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-
-import java.lang.reflect.Method;
-import java.util.Collections;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.buddyreplication.BuddyGroup;
@@ -14,16 +8,19 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.lang.reflect.Method;
+import java.util.Collections;
+
/**
* Tests whether remote calls to RPC methods suppress return values (as sometimes expected)
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 2.0.0
*/
-@Test(groups={"functional"})
+@Test(groups = {"functional"})
public class RemoteCallerReturnValuesTest
{
- private CacheImpl<Object, Object> cache;
+ private CacheSPI<Object, Object> cache;
private Fqn fqn = Fqn.fromString("/a");
private Object key = "key";
private Object value = "value";
@@ -31,7 +28,7 @@
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache();
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache();
cache.put(fqn, key, value);
}
@@ -43,10 +40,13 @@
public void testMethodsThatShouldReturnValues() throws Throwable
{
+ assert false : "Implement me";
+ /*
Object retval = cache._replicate(MethodCallFactory.create(MethodDeclarations.clusteredGetMethod, MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn), false));
assertNotNull(retval);
assertNotNull(cache._replicate(MethodCallFactory.create(MethodDeclarations.dataGravitationMethod, fqn, false)));
+ */
}
@@ -60,7 +60,6 @@
doNullReturnTest(MethodDeclarations.releaseAllLocksMethodLocal, fqn);
doNullReturnTest(MethodDeclarations.printMethodLocal, fqn);
-
// ------------ buddy replication
doNullReturnTest(MethodDeclarations.remoteAnnounceBuddyPoolNameMethod, cache.getLocalAddress(), null);
@@ -76,9 +75,12 @@
}
- private void doNullReturnTest(Method m, Object... args) throws Throwable
+ private void doNullReturnTest(Method m, Object... args)
{
+ assert false : "Implement me";
+ /*
MethodCall c = MethodCallFactory.create(m, args);
assertNull(m + " should return a null when called remotely", cache._replicate(c));
+ */
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/ReplicateToInactiveRegionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/ReplicateToInactiveRegionTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/ReplicateToInactiveRegionTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,15 +1,11 @@
package org.jboss.cache.marshall;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -17,12 +13,12 @@
@Test(groups = {"functional", "jgroups"})
public class ReplicateToInactiveRegionTest
{
- CacheImpl[] caches;
+ CacheSPI[] caches;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- caches = new CacheImpl[]{createCache(), createCache()};
+ caches = new CacheSPI[]{createCache(), createCache()};
TestingUtil.blockUntilViewsReceived(caches, 10000);
}
@@ -34,14 +30,14 @@
caches = null;
}
- private void destroyCache(CacheImpl c)
+ private void destroyCache(CacheSPI c)
{
c.stop();
}
- private CacheImpl createCache() throws Exception
+ private CacheSPI createCache()
{
- CacheImpl c = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
+ CacheSPI c = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
c.getConfiguration().setCacheMode("REPL_SYNC");
c.getConfiguration().setUseRegionBasedMarshalling(true);
c.start();
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/ReturnValueMarshallingTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,21 +1,18 @@
package org.jboss.cache.marshall;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNotSame;
-import static org.testng.AssertJUnit.assertSame;
-import static org.testng.AssertJUnit.assertTrue;
-
-import java.util.List;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.buddyreplication.GravitateResult;
import org.jboss.cache.config.Configuration;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+
+import java.util.List;
+
/**
* Tests the marshalling of retvals
*
@@ -25,7 +22,7 @@
@Test(groups = {"functional", "jgroups"})
public class ReturnValueMarshallingTest
{
- private CacheImpl<Object, Object> cache1, cache2;
+ private CacheSPI<Object, Object> cache1, cache2;
private Fqn fqn = Fqn.fromString("/a");
private ClassLoader classLoader;
private Object key = "key", value;
@@ -35,13 +32,13 @@
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- cache1 = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache1 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
cache1.getConfiguration().setUseRegionBasedMarshalling(true);
cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
cache1.getConfiguration().setSyncReplTimeout(60000);// to aid with debugging
cache1.start();
- cache2 = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache2 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
cache2.getConfiguration().setUseRegionBasedMarshalling(true);
cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
cache2.getConfiguration().setSyncReplTimeout(60000);// to aid with debugging
@@ -69,7 +66,7 @@
cache2.stop();
}
- private ClassLoader getClassLoader() throws Exception
+ private ClassLoader getClassLoader()
{
String[] includesClasses = {className};
String[] excludesClasses = {};
@@ -87,13 +84,12 @@
assertNotSame(MyList.class, cache2.get(fqn, key).getClass());
assertSame(listClass, cache2.get(fqn, key).getClass());
-
// now test if this is the same when obtained using a clustered get mcall
MethodCall call = MethodCallFactory.create(MethodDeclarations.replicateMethod,
- MethodCallFactory.create(MethodDeclarations.clusteredGetMethod,
- MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn, key, false),
- false
- )
+ MethodCallFactory.create(MethodDeclarations.clusteredGetMethod,
+ MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn, key, false),
+ false
+ )
);
List responses = cache1.getRPCManager().callRemoteMethods(null, call, true, true, 15000);
@@ -120,12 +116,11 @@
assertNotSame(MyList.class, cache2.get(fqn, key).getClass());
assertSame(listClass, cache2.get(fqn, key).getClass());
-
// now test if this is the same when obtained using a data gravitate call
MethodCall call = MethodCallFactory.create(MethodDeclarations.replicateMethod,
- MethodCallFactory.create(MethodDeclarations.dataGravitationMethod,
- fqn, false
- )
+ MethodCallFactory.create(MethodDeclarations.dataGravitationMethod,
+ fqn, false
+ )
);
List responses = cache1.getRPCManager().callRemoteMethods(null, call, true, true, 15000);
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/SelectedClassnameClassLoader.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/SelectedClassnameClassLoader.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/SelectedClassnameClassLoader.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,14 +1,14 @@
package org.jboss.cache.marshall;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
/**
* A ClassLoader that loads classes whose classname begins with one of a
* given set of strings, without attempting first to delegate to its
@@ -30,173 +30,201 @@
* </p>
*
* @author Brian Stansberry
- *
*/
-public class SelectedClassnameClassLoader extends ClassLoader {
+public class SelectedClassnameClassLoader extends ClassLoader
+{
- private String[] includedClasses = null;
- private String[] excludedClasses = null;
- private String[] notFoundClasses = null;
- private Log log = LogFactory.getLog(SelectedClassnameClassLoader.class);
+ private String[] includedClasses = null;
+ private String[] excludedClasses = null;
+ private String[] notFoundClasses = null;
+ private Log log = LogFactory.getLog(SelectedClassnameClassLoader.class);
- private Map<String, Class> classes = new java.util.HashMap<String, Class>();
+ private Map<String, Class> classes = new java.util.HashMap<String, Class>();
- /**
- * Creates a new classloader that loads the given classes.
- *
- * @param includedClasses array of class or package names that should be
- * directly loaded by this loader. Classes
- * whose name starts with any of the strings
- * in this array will be loaded by this class,
- * unless their name appears in
- * <code>excludedClasses</code>.
- * Can be <code>null</code>
- * @param excludedClasses array of class or package names that should NOT
- * be directly loaded by this loader. Loading of
- * classes whose name starts with any of the
- * strings in this array will be delegated to
- * <code>parent</code>, even if the classes
- * package or classname appears in
- * <code>includedClasses</code>. Typically this
- * parameter is used to exclude loading one or
- * more classes in a package whose other classes
- * are loaded by this object.
- * @param parent ClassLoader to which loading of classes should
- * be delegated if necessary
- */
- public SelectedClassnameClassLoader(String[] includedClasses,
- String[] excludedClasses,
- ClassLoader parent) {
- super(parent);
- this.includedClasses = includedClasses;
- this.excludedClasses = excludedClasses;
- }
+ /**
+ * Creates a new classloader that loads the given classes.
+ *
+ * @param includedClasses array of class or package names that should be
+ * directly loaded by this loader. Classes
+ * whose name starts with any of the strings
+ * in this array will be loaded by this class,
+ * unless their name appears in
+ * <code>excludedClasses</code>.
+ * Can be <code>null</code>
+ * @param excludedClasses array of class or package names that should NOT
+ * be directly loaded by this loader. Loading of
+ * classes whose name starts with any of the
+ * strings in this array will be delegated to
+ * <code>parent</code>, even if the classes
+ * package or classname appears in
+ * <code>includedClasses</code>. Typically this
+ * parameter is used to exclude loading one or
+ * more classes in a package whose other classes
+ * are loaded by this object.
+ * @param parent ClassLoader to which loading of classes should
+ * be delegated if necessary
+ */
+ public SelectedClassnameClassLoader(String[] includedClasses,
+ String[] excludedClasses,
+ ClassLoader parent)
+ {
+ super(parent);
+ this.includedClasses = includedClasses;
+ this.excludedClasses = excludedClasses;
+ }
- /**
- * Creates a new classloader that loads the given classes.
- *
- * @param includedClasses array of class or package names that should be
- * directly loaded by this loader. Classes
- * whose name starts with any of the strings
- * in this array will be loaded by this class,
- * unless their name appears in
- * <code>excludedClasses</code>.
- * Can be <code>null</code>
- * @param excludedClasses array of class or package names that should NOT
- * be directly loaded by this loader. Loading of
- * classes whose name starts with any of the
- * strings in this array will be delegated to
- * <code>parent</code>, even if the classes
- * package or classname appears in
- * <code>includedClasses</code>. Typically this
- * parameter is used to exclude loading one or
- * more classes in a package whose other classes
- * are loaded by this object.
- * @param notFoundClasses array of class or package names for which this
- * should raise a ClassNotFoundException
- * @param parent ClassLoader to which loading of classes should
- * be delegated if necessary
- */
- public SelectedClassnameClassLoader(String[] includedClasses,
- String[] excludedClasses,
- String[] notFoundClasses,
- ClassLoader parent) {
- super(parent);
- this.includedClasses = includedClasses;
- this.excludedClasses = excludedClasses;
- this.notFoundClasses = notFoundClasses;
- }
+ /**
+ * Creates a new classloader that loads the given classes.
+ *
+ * @param includedClasses array of class or package names that should be
+ * directly loaded by this loader. Classes
+ * whose name starts with any of the strings
+ * in this array will be loaded by this class,
+ * unless their name appears in
+ * <code>excludedClasses</code>.
+ * Can be <code>null</code>
+ * @param excludedClasses array of class or package names that should NOT
+ * be directly loaded by this loader. Loading of
+ * classes whose name starts with any of the
+ * strings in this array will be delegated to
+ * <code>parent</code>, even if the classes
+ * package or classname appears in
+ * <code>includedClasses</code>. Typically this
+ * parameter is used to exclude loading one or
+ * more classes in a package whose other classes
+ * are loaded by this object.
+ * @param notFoundClasses array of class or package names for which this
+ * should raise a ClassNotFoundException
+ * @param parent ClassLoader to which loading of classes should
+ * be delegated if necessary
+ */
+ public SelectedClassnameClassLoader(String[] includedClasses,
+ String[] excludedClasses,
+ String[] notFoundClasses,
+ ClassLoader parent)
+ {
+ super(parent);
+ this.includedClasses = includedClasses;
+ this.excludedClasses = excludedClasses;
+ this.notFoundClasses = notFoundClasses;
+ }
- protected synchronized Class<?> loadClass(String name, boolean resolve)
- throws ClassNotFoundException
- {
- log.info("In SelectedClassnameClassLoader.loadClass("+name+","+resolve+")");
- if (isIncluded(name) && (isExcluded(name) == false)) {
- Class c = findClass(name);
+ protected synchronized Class<?> loadClass(String name, boolean resolve)
+ throws ClassNotFoundException
+ {
+ log.info("In SelectedClassnameClassLoader.loadClass(" + name + "," + resolve + ")");
+ if (isIncluded(name) && (isExcluded(name) == false))
+ {
+ Class c = findClass(name);
- if (resolve) {
- resolveClass(c);
- }
- return c;
- }
- else {
- return super.loadClass(name, resolve);
- }
- }
+ if (resolve)
+ {
+ resolveClass(c);
+ }
+ return c;
+ }
+ else
+ {
+ return super.loadClass(name, resolve);
+ }
+ }
- protected Class<?> findClass(String name) throws ClassNotFoundException {
+ protected Class<?> findClass(String name) throws ClassNotFoundException
+ {
- log.info("In SelectedClassnameClassLoader.findClass()");
- Class result = (Class)classes.get(name);
- if(result != null){
- return result;
- }
+ log.info("In SelectedClassnameClassLoader.findClass()");
+ Class result = classes.get(name);
+ if (result != null)
+ {
+ return result;
+ }
- if (isIncluded(name) && (isExcluded(name) == false)) {
- try {
- InputStream is = getResourceAsStream( name.replace('.','/').concat(".class"));
- byte[] bytes = new byte[1024];
- ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
- int read;
- while ((read = is.read(bytes)) > -1) {
- baos.write(bytes, 0, read);
- }
- bytes = baos.toByteArray();
- result = this.defineClass(name, bytes, 0, bytes.length);
- } catch (FileNotFoundException e) {
- throw new ClassNotFoundException("cannot find " + name, e);
- } catch (IOException e) {
- throw new ClassNotFoundException("cannot read " + name, e);
+ if (isIncluded(name) && (isExcluded(name) == false))
+ {
+ try
+ {
+ InputStream is = getResourceAsStream(name.replace('.', '/').concat(".class"));
+ byte[] bytes = new byte[1024];
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+ int read;
+ while ((read = is.read(bytes)) > -1)
+ {
+ baos.write(bytes, 0, read);
}
- }
- else if (isNotFound(name)) {
- throw new ClassNotFoundException(name + " is discarded");
- }
- else {
- result = super.findClass(name);
- }
+ bytes = baos.toByteArray();
+ result = this.defineClass(name, bytes, 0, bytes.length);
+ }
+ catch (FileNotFoundException e)
+ {
+ throw new ClassNotFoundException("cannot find " + name, e);
+ }
+ catch (IOException e)
+ {
+ throw new ClassNotFoundException("cannot read " + name, e);
+ }
+ }
+ else if (isNotFound(name))
+ {
+ throw new ClassNotFoundException(name + " is discarded");
+ }
+ else
+ {
+ result = super.findClass(name);
+ }
- classes.put(name, result);
+ classes.put(name, result);
- return result;
- }
+ return result;
+ }
- private boolean isIncluded(String className) {
+ private boolean isIncluded(String className)
+ {
- if (includedClasses != null) {
- for (int i = 0; i < includedClasses.length; i++) {
- if (className.startsWith(includedClasses[i])) {
- return true;
- }
+ if (includedClasses != null)
+ {
+ for (int i = 0; i < includedClasses.length; i++)
+ {
+ if (className.startsWith(includedClasses[i]))
+ {
+ return true;
}
- }
+ }
+ }
- return false;
- }
+ return false;
+ }
- private boolean isExcluded(String className) {
+ private boolean isExcluded(String className)
+ {
- if (excludedClasses != null) {
- for (int i = 0; i < excludedClasses.length; i++) {
- if (className.startsWith(excludedClasses[i])) {
- return true;
- }
+ if (excludedClasses != null)
+ {
+ for (int i = 0; i < excludedClasses.length; i++)
+ {
+ if (className.startsWith(excludedClasses[i]))
+ {
+ return true;
}
- }
+ }
+ }
- return false;
- }
+ return false;
+ }
- private boolean isNotFound(String className) {
+ private boolean isNotFound(String className)
+ {
- if (notFoundClasses != null) {
- for (int i = 0; i < notFoundClasses.length; i++) {
- if (className.startsWith(notFoundClasses[i])) {
- return true;
- }
+ if (notFoundClasses != null)
+ {
+ for (int i = 0; i < notFoundClasses.length; i++)
+ {
+ if (className.startsWith(notFoundClasses[i]))
+ {
+ return true;
}
- }
+ }
+ }
- return false;
- }
+ return false;
+ }
}
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/SyncReplTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/SyncReplTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/SyncReplTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -9,20 +9,6 @@
package org.jboss.cache.marshall;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import java.lang.reflect.Method;
-import java.util.HashMap;
-
-import javax.transaction.NotSupportedException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
@@ -32,11 +18,17 @@
import org.jboss.cache.marshall.data.Address;
import org.jboss.cache.marshall.data.Person;
import org.jboss.cache.misc.TestingUtil;
-import org.jboss.cache.transaction.DummyTransactionManager;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.NotSupportedException;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+
/**
* Test case for marshalling using Sync mode.
*
@@ -72,7 +64,7 @@
TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cache1, cache2}, 60000);
}
- private CacheSPI<Object, Object> createCache(String name) throws Exception
+ private CacheSPI<Object, Object> createCache(String name)
{
CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
cache.getConfiguration().setClusterName(name);
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/data/Address.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/data/Address.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/data/Address.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -19,11 +19,6 @@
String city = "San Jose";
int zip = 0;
- public Address()
- {
-
- }
-
public String getStreet()
{
return street;
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/data/Person.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/data/Person.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/data/Person.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -16,10 +16,6 @@
String name = null;
Address address;
- public Person()
- {
- }
-
public String getName()
{
return name;
Modified: core/trunk/src/test/java/org/jboss/cache/mgmt/InvalidationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/mgmt/InvalidationTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/mgmt/InvalidationTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,6 +1,6 @@
package org.jboss.cache.mgmt;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
@@ -14,6 +14,7 @@
import org.testng.annotations.Test;
import java.util.HashMap;
+
/**
* Simple functional tests for InvalidationInterceptor statistics
*
@@ -29,8 +30,8 @@
private static final String POPULATION = "population";
private static final String AREA = "area";
- private CacheImpl<Object, Object> cache1 = null;
- private CacheImpl<Object, Object> cache2 = null;
+ private CacheSPI<Object, Object> cache1 = null;
+ private CacheSPI<Object, Object> cache2 = null;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
@@ -112,7 +113,7 @@
}
- private void loadCache1(CacheImpl<Object, Object> cache) throws Exception
+ private void loadCache1(CacheSPI<Object, Object> cache)
{
cache.put("Europe", new HashMap());
cache.put("Europe/Austria", new HashMap());
@@ -129,7 +130,7 @@
}
- private void loadCache2(CacheImpl<Object, Object> cache) throws Exception
+ private void loadCache2(CacheSPI<Object, Object> cache)
{
// the following line will invalidate /Europe (and its' children) across the cluster!!
// cache.put("Europe", new HashMap<Object, Object>());
@@ -146,16 +147,13 @@
}
- private CacheImpl<Object, Object> createCache(String clusterName) throws Exception
+ private CacheSPI<Object, Object> createCache(String clusterName)
{
- CacheImpl<Object, Object> cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+
Configuration c = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.INVALIDATION_SYNC);
- cache.setConfiguration(c);
c.setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
c.setExposeManagementStatistics(true);
c.setClusterName(clusterName);
- cache.create();
- cache.start();
- return cache;
+ return (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(c);
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/mgmt/MgmtCoreTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/mgmt/MgmtCoreTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/mgmt/MgmtCoreTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,21 +1,19 @@
package org.jboss.cache.mgmt;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.HashMap;
-import java.util.List;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.interceptors.CacheMgmtInterceptor;
+import org.jboss.cache.interceptors.Interceptor;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+
+import java.util.HashMap;
+import java.util.List;
+
/**
* Simple functional tests for CacheMgmtInterceptor
*
@@ -30,12 +28,12 @@
private static final String POPULATION = "population";
private static final String AREA = "area";
- CacheImpl<Object, Object> cache = null;
+ CacheSPI<Object, Object> cache = null;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
cache.getConfiguration().setExposeManagementStatistics(true);
cache.create();
@@ -162,7 +160,7 @@
assertEquals("Misses count error after reset: ", new Long(0), new Long(mgmt.getMisses()));
}
- private void loadCacheData() throws Exception
+ private void loadCacheData()
{
cache.put("Europe", new HashMap());
cache.put("Europe/Austria", new HashMap());
@@ -201,28 +199,28 @@
cache.put("Europe/Poland", POPULATION, 38635144);
cache.put("Europe/Switzerland", POPULATION, 7489370);
- HashMap<Object, Object> albania = new HashMap<Object, Object> (4);
+ HashMap<Object, Object> albania = new HashMap<Object, Object>(4);
albania.put(CAPITAL, "Tirana");
albania.put(CURRENCY, "Lek");
albania.put(POPULATION, 3563112);
albania.put(AREA, 28748);
cache.put("Europe/Albania", albania);
- HashMap<Object, Object> hungary = new HashMap<Object, Object> (4);
+ HashMap<Object, Object> hungary = new HashMap<Object, Object>(4);
hungary.put(CAPITAL, "Budapest");
hungary.put(CURRENCY, "Forint");
hungary.put(POPULATION, 10006835);
hungary.put(AREA, 93030);
cache.put("Europe/Hungary", hungary);
- HashMap<Object, Object> romania = new HashMap<Object, Object> (4);
+ HashMap<Object, Object> romania = new HashMap<Object, Object>(4);
romania.put(CAPITAL, "Bucharest");
romania.put(CURRENCY, "Leu");
romania.put(POPULATION, 22329977);
romania.put(AREA, 237500);
cache.put("Europe/Romania", romania);
- HashMap<Object, Object> slovakia = new HashMap<Object, Object> (4);
+ HashMap<Object, Object> slovakia = new HashMap<Object, Object>(4);
slovakia.put(CAPITAL, "Bratislava");
slovakia.put(CURRENCY, "Slovak Koruna");
slovakia.put(POPULATION, 5431363);
@@ -233,18 +231,17 @@
private CacheMgmtInterceptor getCacheMgmtInterceptor()
{
- List interceptors = cache.getInterceptors();
+ List<Interceptor> interceptors = cache.getInterceptorChain();
if (interceptors.isEmpty())
{
return null;
}
- for (int i = 0; i < interceptors.size(); i++)
+ for (Interceptor interceptor : interceptors)
{
- Object o = interceptors.get(i);
- if (o instanceof CacheMgmtInterceptor)
+ if (interceptor instanceof CacheMgmtInterceptor)
{
- return (CacheMgmtInterceptor) o;
+ return (CacheMgmtInterceptor) interceptor;
}
}
return null;
Modified: core/trunk/src/test/java/org/jboss/cache/mgmt/TxTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/mgmt/TxTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/mgmt/TxTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,24 +1,20 @@
package org.jboss.cache.mgmt;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-
-import java.util.HashMap;
-import java.util.List;
-
-import javax.transaction.TransactionManager;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.interceptors.TxInterceptor;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.TransactionManager;
+import java.util.HashMap;
+import java.util.List;
+
/**
* Simple functional tests for TxInterceptor statistics
*
@@ -34,8 +30,8 @@
private static final String POPULATION = "population";
private static final String AREA = "area";
- private CacheImpl<Object, Object> cache1 = null;
- private CacheImpl<Object, Object> cache2 = null;
+ private CacheSPI<Object, Object> cache1 = null;
+ private CacheSPI<Object, Object> cache2 = null;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
@@ -141,7 +137,7 @@
assertEquals("Cache2 Tx Rollbacks error after reset: ", new Long(0), new Long(tx2.getRollbacks()));
}
- private void loadCacheNoTx(CacheImpl<Object, Object> cache) throws Exception
+ private void loadCacheNoTx(CacheSPI<Object, Object> cache)
{
cache.put("Europe", new HashMap<Object, Object>());
cache.put("Europe/Austria", new HashMap());
@@ -157,7 +153,7 @@
cache.put("Europe/Albania", albania);
}
- private void loadCacheTxCommit(CacheImpl<Object, Object> cache, TransactionManager tm) throws Exception
+ private void loadCacheTxCommit(CacheSPI<Object, Object> cache, TransactionManager tm) throws Exception
{
tm.begin();
@@ -174,7 +170,7 @@
tm.commit();
}
- private void loadCacheTxCommit2(CacheImpl<Object, Object> cache, TransactionManager tm) throws Exception
+ private void loadCacheTxCommit2(CacheSPI<Object, Object> cache, TransactionManager tm) throws Exception
{
tm.begin();
@@ -195,7 +191,7 @@
tm.commit();
}
- private void loadCacheTxRollback(CacheImpl<Object, Object> cache, TransactionManager tm) throws Exception
+ private void loadCacheTxRollback(CacheSPI<Object, Object> cache, TransactionManager tm) throws Exception
{
tm.begin();
@@ -212,10 +208,9 @@
tm.rollback();
}
- private CacheImpl<Object, Object> createCache(String clusterName) throws Exception
+ private CacheSPI<Object, Object> createCache(String clusterName)
{
- CacheImpl<Object, Object> cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
- cache.setConfiguration(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC));
+ CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
cache.getConfiguration().setUseRegionBasedMarshalling(false);
cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
cache.getConfiguration().setExposeManagementStatistics(true);
@@ -225,17 +220,16 @@
return cache;
}
- private TxInterceptor getTxInterceptor(CacheImpl cache)
+ private TxInterceptor getTxInterceptor(CacheSPI cache)
{
- List interceptors = cache.getInterceptors();
+ List interceptors = cache.getInterceptorChain();
if (interceptors.isEmpty())
{
return null;
}
- for (int i = 0; i < interceptors.size(); i++)
+ for (Object o : interceptors)
{
- Object o = interceptors.get(i);
if (o instanceof TxInterceptor)
{
return (TxInterceptor) o;
Modified: core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/misc/TestingUtil.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -12,10 +12,14 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.CacheStatus;
import org.jboss.cache.Fqn;
+import org.jboss.cache.factories.ComponentRegistry;
+import org.jboss.cache.factories.InterceptorChainFactory;
import org.jboss.cache.interceptors.Interceptor;
+import org.jboss.cache.invocation.RemoteCacheInvocationDelegate;
import org.jboss.cache.util.CachePrinter;
import java.io.File;
+import java.lang.reflect.Field;
import java.util.List;
import java.util.Random;
@@ -29,6 +33,29 @@
{
private static Random random = new Random();
+ /**
+ * Extracts the value of a field in a given target instance using reflection, able to extract private fields as well.
+ *
+ * @param target object to extract field from
+ * @param fieldName name of field to extract
+ * @return field value
+ */
+ public static Object extractField(Object target, String fieldName)
+ {
+ Field field;
+ try
+ {
+ field = target.getClass().getDeclaredField(fieldName);
+ field.setAccessible(true);
+ return field.get(target);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
public static <T extends Interceptor> T findInterceptor(CacheSPI<?, ?> cache, Class<T> interceptorToFind)
{
for (Interceptor i : cache.getInterceptorChain())
@@ -96,7 +123,7 @@
}
/**
- * Loops, continually calling {@link #areCacheViewsComplete(CacheImpl[])}
+ * Loops, continually calling {@link #areCacheViewsComplete(org.jboss.cache.CacheSPI[])}
* until it either returns true or <code>timeout</code> ms have elapsed.
*
* @param caches caches which must all have consistent views
@@ -104,7 +131,7 @@
* @throws RuntimeException if <code>timeout</code> ms have elapse without
* all caches having the same number of members.
*/
- public static void blockUntilViewsReceived(CacheImpl[] caches, long timeout)
+ public static void blockUntilViewsReceived(CacheSPI[] caches, long timeout)
{
long failTime = System.currentTimeMillis() + timeout;
@@ -120,6 +147,7 @@
throw new RuntimeException("timed out before caches had complete views");
}
+
/**
* An overloaded version of {@link #blockUntilViewsReceived(long,org.jboss.cache.Cache[])} that allows for 'shrinking' clusters.
* I.e., the usual method barfs if there are more members than expected. This one takes a param (barfIfTooManyMembers) which,
@@ -147,7 +175,7 @@
}
/**
- * Loops, continually calling {@link #areCacheViewsComplete(CacheImpl[])}
+ * Loops, continually calling {@link #areCacheViewsComplete(org.jboss.cache.CacheSPI[])}
* until it either returns true or <code>timeout</code> ms have elapsed.
*
* @param groupSize number of caches expected in the group
@@ -172,7 +200,7 @@
}
/**
- * Loops, continually calling {@link #areCacheViewsComplete(CacheImpl[])}
+ * Loops, continually calling {@link #areCacheViewsComplete(org.jboss.cache.CacheSPI[])}
* until it either returns true or <code>timeout</code> ms have elapsed.
*
* @param groupSize number of caches expected in the group
@@ -238,7 +266,7 @@
* @throws IllegalStateException if any of the caches have MORE view
* members than caches.length
*/
- public static boolean areCacheViewsComplete(CacheImpl[] caches)
+ public static boolean areCacheViewsComplete(CacheSPI[] caches)
{
if (caches == null) throw new NullPointerException("Cache impl array is null");
Cache[] c = new Cache[caches.length];
@@ -382,7 +410,7 @@
*/
public static void killCaches(Cache... caches)
{
- for (Cache c: caches)
+ for (Cache c : caches)
{
if (c != null && c.getCacheStatus() == CacheStatus.STARTED)
{
@@ -422,7 +450,7 @@
*/
public static void killTransactions(Cache... caches)
{
- for (Cache c: caches)
+ for (Cache c : caches)
{
if (c != null && c.getCacheStatus() == CacheStatus.STARTED)
{
@@ -441,4 +469,63 @@
}
}
}
+
+ /**
+ * For testing only - introspects a cache and extracts the ComponentRegistry
+ *
+ * @param cache cache to introspect
+ * @return component registry
+ */
+ public static ComponentRegistry extractComponentRegistry(Cache cache)
+ {
+ CacheImpl ci = (CacheImpl) extractField(cache, "cache");
+ return extractComponentRegistry(ci);
+ }
+
+ /**
+ * For testing only - introspects a cache and extracts the ComponentRegistry
+ *
+ * @param cache cache to introspect
+ * @return component registry
+ */
+ public static ComponentRegistry extractComponentRegistry(CacheImpl ci)
+ {
+ ComponentRegistry cr = (ComponentRegistry) extractField(ci, "componentRegistry");
+ return cr;
+ }
+
+
+ /**
+ * Replaces the existing interceptor chain in the cache wih one represented by the interceptor passed in. This
+ * utility updates dependencies on all components that rely on the interceptor chain as well.
+ *
+ * @param cache cache that needs to be altered
+ * @param interceptor the first interceptor in the new chain.
+ */
+ public static void replaceInterceptorChain(CacheSPI<?, ?> cache, Interceptor interceptor)
+ {
+ ComponentRegistry cr = extractComponentRegistry(cache);
+
+ // This will replace the previous interceptor chain in the component registry
+ cr.registerComponent(interceptor);
+
+ // update all component dependencies
+ cr.updateDependencies();
+
+ // make sure the new interceptors have their deps satisfied.
+ InterceptorChainFactory.getInstance().correctInterceptorChaining(interceptor, cache.getConfiguration(), cr);
+ }
+
+ /**
+ * Retrieves the remote delegate for a given cache. It is on this remote delegate that the JGroups RPCDispatcher
+ * invokes remote methods.
+ *
+ * @param cache cache instance for which a remote delegate is to be retrieved
+ * @return remote delegate, or null if the cacge is not configured for replication.
+ */
+ public static RemoteCacheInvocationDelegate getRemoteDelegate(CacheSPI cache)
+ {
+ ComponentRegistry cr = extractComponentRegistry(cache);
+ return cr.getComponent(RemoteCacheInvocationDelegate.class);
+ }
}
Modified: core/trunk/src/test/java/org/jboss/cache/multiplexer/MultiplexerTestHelper.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/multiplexer/MultiplexerTestHelper.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/multiplexer/MultiplexerTestHelper.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -25,7 +25,6 @@
import org.jgroups.ChannelFactory;
import org.jgroups.JChannel;
import org.jgroups.JChannelFactory;
-import org.testng.annotations.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -50,10 +49,6 @@
private final Set<JChannelFactory> factories = Collections.synchronizedSet(new HashSet<JChannelFactory>());
private final Set<Cache> caches = Collections.synchronizedSet(new HashSet<Cache>());
- public MultiplexerTestHelper()
- {
- }
-
/**
* Configures the given cache to get its JChannel from a
* multiplexer-enabled JChannelFactory. The JChannelFactory will
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/AbstractOptimisticTestCase.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -3,19 +3,7 @@
*/
package org.jboss.cache.optimistic;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Random;
-
-import javax.transaction.SystemException;
-import javax.transaction.TransactionManager;
-
import org.jboss.cache.Cache;
-import org.jboss.cache.CacheImpl;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
@@ -35,6 +23,7 @@
import org.jboss.cache.marshall.MethodCallFactory;
import org.jboss.cache.marshall.MethodDeclarations;
import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.cache.transaction.TransactionSetup;
import org.jboss.cache.xml.XmlHelper;
import org.jgroups.Address;
@@ -42,6 +31,16 @@
import org.testng.annotations.Test;
import org.w3c.dom.Element;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Random;
+
/**
* @author manik
*/
@@ -52,31 +51,29 @@
protected Fqn<String> fqn = Fqn.fromString("/blah");
protected String key = "myKey", value = "myValue";
- protected CacheImpl<Object, Object> createCacheUnstarted() throws Exception
+ protected CacheSPI<Object, Object> createCacheUnstarted() throws Exception
{
return createCacheUnstarted(true);
}
- protected CacheImpl<Object, Object> createCacheUnstarted(boolean optimistic) throws Exception
+ protected CacheSPI<Object, Object> createCacheUnstarted(boolean optimistic) throws Exception
{
- CacheImpl<Object, Object> cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
- Configuration c = new Configuration();
- cache.setConfiguration(c);
- if (optimistic) c.setNodeLockingScheme("OPTIMISTIC");
+ CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ if (optimistic) cache.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
- c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- c.setCacheMode("LOCAL");
+ cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
return cache;
}
- protected CacheImpl<Object, Object> createCacheWithListener() throws Exception
+ protected CacheSPI<Object, Object> createCacheWithListener() throws Exception
{
return createCacheWithListener(new TestListener());
}
- protected CacheImpl<Object, Object> createCacheWithListener(Object listener) throws Exception
+ protected CacheSPI<Object, Object> createCacheWithListener(Object listener) throws Exception
{
- CacheImpl<Object, Object> cache = createCacheUnstarted();
+ CacheSPI<Object, Object> cache = createCacheUnstarted();
cache.create();
cache.start();
cache.getNotifier().addCacheListener(listener);
@@ -85,11 +82,8 @@
/**
* Returns a tree cache with passivation disabled in the loader.
- *
- * @return
- * @throws Exception
*/
- protected CacheImpl<Object, Object> createCacheWithLoader() throws Exception
+ protected CacheSPI<Object, Object> createCacheWithLoader() throws Exception
{
return createCacheWithLoader(false);
}
@@ -97,27 +91,26 @@
protected CacheLoaderConfig getCacheLoaderConfig(boolean shared, boolean passivation) throws Exception
{
String xml = " <config>\n" +
- " <passivation>" + passivation + "</passivation>\n" +
- " <preload></preload>\n" +
- " <shared>" + shared + "</shared>\n" +
- " <cacheloader>\n" +
- " <class>" + (shared ? DummySharedInMemoryCacheLoader.class.getName() : DummyInMemoryCacheLoader.class.getName()) + "</class>\n" +
- " <properties>\n" +
- " </properties>\n" +
- " <async>false</async>\n" +
- " <fetchPersistentState>" + (!shared) + "</fetchPersistentState>\n" +
- " <ignoreModifications>false</ignoreModifications>\n" +
- " </cacheloader>\n" +
- " </config>";
+ " <passivation>" + passivation + "</passivation>\n" +
+ " <preload></preload>\n" +
+ " <shared>" + shared + "</shared>\n" +
+ " <cacheloader>\n" +
+ " <class>" + (shared ? DummySharedInMemoryCacheLoader.class.getName() : DummyInMemoryCacheLoader.class.getName()) + "</class>\n" +
+ " <properties>\n" +
+ " </properties>\n" +
+ " <async>false</async>\n" +
+ " <fetchPersistentState>" + (!shared) + "</fetchPersistentState>\n" +
+ " <ignoreModifications>false</ignoreModifications>\n" +
+ " </cacheloader>\n" +
+ " </config>";
Element element = XmlHelper.stringToElement(xml);
return XmlConfigurationParser.parseCacheLoaderConfig(element);
}
- protected CacheImpl<Object, Object> createCacheWithLoader(boolean passivationEnabled) throws Exception
+ protected CacheSPI<Object, Object> createCacheWithLoader(boolean passivationEnabled) throws Exception
{
- CacheImpl<Object, Object> cache = createCacheUnstarted();
+ CacheSPI<Object, Object> cache = createCacheUnstarted();
Configuration c = cache.getConfiguration();
- cache.setConfiguration(c);
c.setCacheLoaderConfig(getCacheLoaderConfig(true, passivationEnabled));
cache.create();
cache.start();
@@ -125,9 +118,9 @@
}
- protected CacheImpl<Object, Object> createCache() throws Exception
+ protected CacheSPI<Object, Object> createCache() throws Exception
{
- CacheImpl<Object, Object> cache = createCacheUnstarted();
+ CacheSPI<Object, Object> cache = createCacheUnstarted();
cache.create();
cache.start();
return cache;
@@ -140,11 +133,10 @@
}
- protected CacheImpl<Object, Object> createPessimisticCache() throws Exception
+ protected CacheSPI createPessimisticCache() throws Exception
{
- CacheImpl<Object, Object> cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
- Configuration c = new Configuration();
- cache.setConfiguration(c);
+ CacheSPI cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
+ Configuration c = cache.getConfiguration();
c.setClusterName("name");
c.setStateRetrievalTimeout(5000);
@@ -159,11 +151,10 @@
return cache;
}
- protected CacheImpl<Object, Object> createPessimisticCacheLocal() throws Exception
+ protected CacheSPI createPessimisticCacheLocal() throws Exception
{
- CacheImpl<Object, Object> cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
- Configuration c = new Configuration();
- cache.setConfiguration(c);
+ CacheSPI cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
+ Configuration c = cache.getConfiguration();
c.setClusterName("name");
c.setStateRetrievalTimeout(5000);
@@ -182,36 +173,35 @@
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";
+ "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 CacheImpl<Object, Object> createReplicatedCache(Configuration.CacheMode mode) throws Exception
+ protected CacheSPI createReplicatedCache(Configuration.CacheMode mode) throws Exception
{
return createReplicatedCache("test", mode);
}
- protected CacheImpl<Object, Object> createReplicatedCache(String name, Configuration.CacheMode mode) throws Exception
+ protected CacheSPI createReplicatedCache(String name, Configuration.CacheMode mode) throws Exception
{
return createReplicatedCache(name, mode, true);
}
-
- protected CacheImpl<Object, Object> createReplicatedCache(String name, Configuration.CacheMode mode, boolean start) throws Exception
- {
- CacheImpl<Object, Object> cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
- Configuration c = new Configuration();
- cache.setConfiguration(c);
+ protected CacheSPI<Object, Object> createReplicatedCache(String name, Configuration.CacheMode mode, boolean start) throws Exception
+ {
+ CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ Configuration c = cache.getConfiguration();
+
c.setClusterName(name);
c.setStateRetrievalTimeout(5000);
c.setClusterConfig(getDefaultProperties());
@@ -224,7 +214,7 @@
}
c.setNodeLockingScheme("OPTIMISTIC");
c.setTransactionManagerLookupClass(TransactionSetup.getManagerLookup());
-
+
if (start)
{
cache.create();
@@ -234,26 +224,25 @@
return cache;
}
- protected CacheImpl<Object, Object> createReplicatedCacheWithLoader(boolean shared, Configuration.CacheMode cacheMode) throws Exception
+ protected CacheSPI createReplicatedCacheWithLoader(boolean shared, Configuration.CacheMode cacheMode) throws Exception
{
return createReplicatedCacheWithLoader("temp-loader", shared, cacheMode);
}
- protected CacheImpl<Object, Object> createReplicatedCacheWithLoader(boolean shared) throws Exception
+ protected CacheSPI<Object, Object> createReplicatedCacheWithLoader(boolean shared) throws Exception
{
return createReplicatedCacheWithLoader("temp-loader", shared, Configuration.CacheMode.REPL_SYNC);
}
- protected CacheImpl<Object, Object> createReplicatedCacheWithLoader(String name, boolean shared) throws Exception
+ protected CacheSPI createReplicatedCacheWithLoader(String name, boolean shared) throws Exception
{
return createReplicatedCacheWithLoader(name, shared, Configuration.CacheMode.REPL_SYNC);
}
- protected CacheImpl<Object, Object> createReplicatedCacheWithLoader(String name, boolean shared, Configuration.CacheMode cacheMode) throws Exception
+ protected CacheSPI<Object, Object> createReplicatedCacheWithLoader(String name, boolean shared, Configuration.CacheMode cacheMode) throws Exception
{
- CacheImpl<Object, Object> cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
- Configuration c = new Configuration();
- cache.setConfiguration(c);
+ CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ Configuration c = cache.getConfiguration();
c.setClusterName(name);
c.setStateRetrievalTimeout(5000);
c.setClusterConfig(getDefaultProperties());
@@ -369,22 +358,22 @@
}
public void readFrom(DataInputStream
- arg0)
+ arg0)
{
}
public void writeTo(DataOutputStream
- arg0)
+ arg0)
{
}
public void readExternal(ObjectInput
- arg0)
+ arg0)
{
}
public void writeExternal(ObjectOutput
- arg0)
+ arg0)
{
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncCacheTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncCacheTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncCacheTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -3,28 +3,25 @@
*
*/
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.TransactionSetup;
+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;
+
@Test(groups = {"functional", "transaction"})
public class AsyncCacheTest extends AbstractOptimisticTestCase
{
- private CacheImpl<Object, Object> cache, cache2;
+ private CacheSPI<Object, Object> cache, cache2;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
@@ -44,9 +41,9 @@
}
@Override
- protected CacheImpl<Object, Object> createCacheUnstarted(boolean optimistic) throws Exception
+ protected CacheSPI<Object, Object> createCacheUnstarted(boolean optimistic) throws Exception
{
- CacheImpl<Object, Object> cache = super.createCacheUnstarted(optimistic);
+ CacheSPI<Object, Object> cache = super.createCacheUnstarted(optimistic);
cache.getConfiguration().setTransactionManagerLookupClass(TransactionSetup.getManagerLookup());
return cache;
}
@@ -83,7 +80,7 @@
assertEquals(pojo, cache.get(Fqn.fromString("/one/two"), "key1"));
// allow changes to replicate since this is async
- TestingUtil.sleepThread((long)1000);
+ TestingUtil.sleepThread((long) 1000);
assertEquals(0, cache2.getTransactionTable().getNumGlobalTransactions());
assertEquals(0, cache2.getTransactionTable().getNumLocalTransactions());
@@ -105,7 +102,7 @@
Transaction tx = mgr.getTransaction();
//this sets
- cache.getCurrentTransaction(tx);
+ cache.getCurrentTransaction(tx, false);
SamplePojo pojo = new SamplePojo(21, "test");
@@ -125,7 +122,7 @@
assertEquals(pojo, cache.get(Fqn.fromString("/one/two"), "key1"));
// let the async calls complete
- TestingUtil.sleepThread((long)1000);
+ TestingUtil.sleepThread((long) 1000);
assertEquals(0, cache2.getTransactionTable().getNumGlobalTransactions());
assertEquals(0, cache2.getTransactionTable().getNumLocalTransactions());
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncFullStackInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncFullStackInterceptorTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/AsyncFullStackInterceptorTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,17 +1,8 @@
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import org.testng.annotations.Test;
-
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.Configuration;
@@ -20,7 +11,12 @@
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.Test;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
/**
* @author xenephon
*/
@@ -38,7 +34,7 @@
public void testSingleInstanceRollback() throws Exception
{
groupIncreaser++;
- CacheImpl<Object, Object> cache = createAsyncReplicatedCache();
+ CacheSPI<Object, Object> cache = createAsyncReplicatedCache();
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -59,7 +55,7 @@
assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
assertEquals(false, cache.exists(Fqn.fromString("/one/two")));
- assertNull(cache.get(Fqn.fromString("/")).getChild("one"));
+ assertNull(cache.getNode("/one"));
destroyCache(cache);
@@ -68,7 +64,7 @@
public void testSingleInstanceDuplicateCommit() throws Exception
{
groupIncreaser++;
- CacheImpl<Object, Object> cache = createAsyncReplicatedCache();
+ CacheSPI<Object, Object> cache = createAsyncReplicatedCache();
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -102,11 +98,11 @@
assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
- assertEquals(false, ((NodeSPI<Object, Object>)cache.get(Fqn.fromString("/"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>)cache.get(Fqn.fromString("/one"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>)cache.get(Fqn.fromString("/one/two"))).getLock().isLocked());
- assertNotNull(cache.get(Fqn.fromString("/one")).getChild("two"));
+ assertNotNull(cache.getNode("/one"));
+ assertEquals(false, cache.getRoot().getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode(Fqn.fromString("/one"))).getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode(Fqn.fromString("/one/two"))).getLock().isLocked());
+ assertNotNull(cache.getNode("/one/two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
destroyCache(cache);
@@ -116,7 +112,7 @@
public void testValidationFailCommit() throws Exception
{
groupIncreaser++;
- CacheImpl<Object, Object> cache = createAsyncReplicatedCache();
+ CacheSPI<Object, Object> cache = createAsyncReplicatedCache();
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -167,11 +163,11 @@
assertEquals(true, fail);
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
- assertEquals(false, ((NodeSPI<Object, Object>)cache.get(Fqn.fromString("/"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>)cache.get(Fqn.fromString("/one"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>)cache.get(Fqn.fromString("/one/two"))).getLock().isLocked());
- assertNotNull(cache.get(Fqn.fromString("/one")).getChild("two"));
+ assertNotNull(cache.getNode("/one"));
+ assertEquals(false, cache.getRoot().getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertNotNull(cache.getNode("/one").getChild("two"));
assertEquals(pojo2, cache.get(Fqn.fromString("/one/two"), "key1"));
destroyCache(cache);
@@ -181,8 +177,8 @@
public void test2InstanceCommit() throws Exception
{
groupIncreaser++;
- CacheImpl<Object, Object> cache = createAsyncReplicatedCache();
- CacheImpl<Object, Object> cache2 = createAsyncReplicatedCache();
+ CacheSPI<Object, Object> cache = createAsyncReplicatedCache();
+ CacheSPI<Object, Object> cache2 = createAsyncReplicatedCache();
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -204,34 +200,34 @@
assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
+ assertNotNull(cache.getNode("/one"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
- assertEquals(false, ((NodeSPI<Object, Object>)cache.get(Fqn.fromString("/"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>)cache.get(Fqn.fromString("/one"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>)cache.get(Fqn.fromString("/one/two"))).getLock().isLocked());
- assertNotNull(cache.get(Fqn.fromString("/one")).getChild("two"));
+ assertNotNull(cache.getNode("/one"));
+ assertEquals(false, cache.getRoot().getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertNotNull(cache.getNode("/one").getChild("two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
// let async calls propagate
- TestingUtil.sleepThread((long)1000);
+ TestingUtil.sleepThread((long) 1000);
// cache2 asserts
assertEquals(0, cache2.getTransactionTable().getNumGlobalTransactions());
assertEquals(0, cache2.getTransactionTable().getNumLocalTransactions());
assertTrue(cache2.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache2.get(Fqn.fromString("/")).getChild("one"));
+ assertNotNull(cache2.getRoot().getChild("one"));
assertNotNull(cache2.get(Fqn.fromString("/one/two"), "key1"));
assertTrue(cache2.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache2.get(Fqn.fromString("/")).getChild("one"));
- assertEquals(false, ((NodeSPI<Object, Object>)cache2.get(Fqn.fromString("/"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>)cache2.get(Fqn.fromString("/one"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>)cache2.get(Fqn.fromString("/one/two"))).getLock().isLocked());
- assertNotNull(cache2.get(Fqn.fromString("/one")).getChild("two"));
+ assertNotNull(cache2.getRoot().getChild("one"));
+ assertEquals(false, cache2.getRoot().getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache2.getNode("/one")).getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache2.getNode("/one/two")).getLock().isLocked());
+ assertNotNull(cache2.getNode("/one").getChild("two"));
assertNotNull(cache2.get(Fqn.fromString("/one/two"), "key1"));
destroyCache(cache);
@@ -241,8 +237,8 @@
public void test2InstanceRemove() throws Exception
{
groupIncreaser++;
- CacheImpl<Object, Object> cache = createAsyncReplicatedCache();
- CacheImpl<Object, Object> cache2 = createAsyncReplicatedCache();
+ CacheSPI<Object, Object> cache = createAsyncReplicatedCache();
+ CacheSPI<Object, Object> cache2 = createAsyncReplicatedCache();
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -264,45 +260,43 @@
assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
+ assertNotNull(cache.getNode("/one"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
- assertEquals(false, ((NodeSPI<Object, Object>)cache.get(Fqn.fromString("/"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>)cache.get(Fqn.fromString("/one"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>)cache.get(Fqn.fromString("/one/two"))).getLock().isLocked());
- assertNotNull(cache.get(Fqn.fromString("/one")).getChild("two"));
+ assertNotNull(cache.getNode("/one"));
+ assertEquals(false, cache.getRoot().getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertNotNull(cache.getNode("/one").getChild("two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
// let async calls propagate
- TestingUtil.sleepThread((long)1000);
+ TestingUtil.sleepThread((long) 1000);
// cache2 asserts
assertEquals(0, cache2.getTransactionTable().getNumGlobalTransactions());
assertEquals(0, cache2.getTransactionTable().getNumLocalTransactions());
assertTrue(cache2.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache2.get(Fqn.fromString("/")).getChild("one"));
+ assertNotNull(cache2.getRoot().getChild("one"));
assertNotNull(cache2.get(Fqn.fromString("/one/two"), "key1"));
assertTrue(cache2.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache2.get(Fqn.fromString("/")).getChild("one"));
- assertEquals(false, ((NodeSPI<Object, Object>)cache2.get(Fqn.fromString("/"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>)cache2.get(Fqn.fromString("/one"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>)cache2.get(Fqn.fromString("/one/two"))).getLock().isLocked());
- assertNotNull(cache2.get(Fqn.fromString("/one")).getChild("two"));
+ assertNotNull(cache2.getRoot().getChild("one"));
+ assertEquals(false, cache2.getRoot().getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache2.getNode("/one")).getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache2.getNode("/one/two")).getLock().isLocked());
+ assertNotNull(cache2.getNode("/one").getChild("two"));
assertNotNull(cache2.get(Fqn.fromString("/one/two"), "key1"));
- cache.remove("/one/two");
- log.debug(" C1 " + cache.get("/one/two"));
+ cache.removeNode("/one/two");
assertEquals(false, cache.exists("/one/two"));
assertEquals(null, cache.get("/one/two", "key1"));
// let async calls propagate
- TestingUtil.sleepThread((long)1000);
+ TestingUtil.sleepThread((long) 1000);
- log.debug(" C2 " + cache2.get("/one/two"));
assertEquals(false, cache2.exists("/one/two"));
assertEquals(null, cache2.get("/one/two", "key1"));
@@ -313,8 +307,8 @@
public void testValidationFailCommit2Instances() throws Exception
{
groupIncreaser++;
- CacheImpl<Object, Object> cache = createAsyncReplicatedCache();
- CacheImpl<Object, Object> cache2 = createAsyncReplicatedCache();
+ CacheSPI<Object, Object> cache = createAsyncReplicatedCache();
+ CacheSPI<Object, Object> cache2 = createAsyncReplicatedCache();
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -333,9 +327,9 @@
assertEquals(1, cache.getTransactionTable().getNumGlobalTransactions());
assertEquals(1, cache.getTransactionTable().getNumLocalTransactions());
- GlobalTransaction gtx = cache.getCurrentTransaction(tx);
+ GlobalTransaction gtx = cache.getCurrentTransaction(tx, true);
TransactionTable table = cache.getTransactionTable();
- OptimisticTransactionEntry entry = (OptimisticTransactionEntry)table.get(gtx);
+ OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
assertEquals(3, entry.getTransactionWorkSpace().getNodes().size());
assertNull(mgr.getTransaction());
@@ -349,7 +343,7 @@
mgr.commit();
// let async calls propagate
- TestingUtil.sleepThread((long)1000);
+ TestingUtil.sleepThread((long) 1000);
assertEquals(1, cache.getTransactionTable().getNumGlobalTransactions());
assertEquals(1, cache.getTransactionTable().getNumLocalTransactions());
@@ -375,11 +369,11 @@
assertEquals(0, entry.getTransactionWorkSpace().getNodes().size());
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
- assertEquals(false, ((NodeSPI<Object, Object>)cache.get(Fqn.fromString("/"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>)cache.get(Fqn.fromString("/one"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>)cache.get(Fqn.fromString("/one/two"))).getLock().isLocked());
- assertNotNull(cache.get(Fqn.fromString("/one")).getChild("two"));
+ assertNotNull(cache.getNode("/one"));
+ assertEquals(false, cache.getRoot().getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertNotNull(cache.getNode("/one").getChild("two"));
assertEquals(pojo2, cache.get(Fqn.fromString("/one/two"), "key1"));
destroyCache(cache);
@@ -387,7 +381,7 @@
}
- protected CacheImpl<Object, Object> createAsyncReplicatedCache() throws Exception
+ protected CacheSPI<Object, Object> createAsyncReplicatedCache() throws Exception
{
return createReplicatedCache("temp" + groupIncreaser, Configuration.CacheMode.REPL_ASYNC);
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/CacheTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/CacheTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/CacheTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -3,42 +3,38 @@
*
*/
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-
-import javax.transaction.RollbackException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodCallFactory;
import org.jboss.cache.marshall.MethodDeclarations;
+import org.jboss.cache.misc.TestingUtil;
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.RollbackException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+
@Test(groups = "functional")
public class CacheTest extends AbstractOptimisticTestCase
{
Log log = LogFactory.getLog(CacheTest.class);
- private CacheImpl<Object, Object> c;
+ private CacheSPI<Object, Object> c;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
@@ -84,7 +80,8 @@
for (int i = 0; i < numThreads; i++)
{
- thread[i] = new ExceptionThread() {
+ thread[i] = new ExceptionThread()
+ {
public void run()
{
try
@@ -125,10 +122,8 @@
public void testLocalTransaction() throws Exception
{
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(c);
+ TestingUtil.replaceInterceptorChain(c, getAlteredInterceptorChain(dummy, c, true));
- c.setInterceptorChain(getAlteredInterceptorChain(dummy, c, true));
-
TransactionManager mgr = c.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -162,9 +157,8 @@
c = createCacheWithListener();
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(c);
+ TestingUtil.replaceInterceptorChain(c, getAlteredInterceptorChain(dummy, c, true));
- c.setInterceptorChain(getAlteredInterceptorChain(dummy, c, true));
TransactionManager mgr = c.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -193,9 +187,8 @@
c = createCacheWithListener();
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(c);
+ TestingUtil.replaceInterceptorChain(c, getAlteredInterceptorChain(dummy, c, true));
- c.setInterceptorChain(getAlteredInterceptorChain(dummy, c, true));
TransactionManager mgr = c.getConfiguration().getRuntimeConfig().getTransactionManager();
//start local transaction
@@ -203,15 +196,15 @@
Transaction tx = mgr.getTransaction();
//this sets
- c.getCurrentTransaction(tx);
+ c.getCurrentTransaction(tx, true);
SamplePojo pojo = new SamplePojo(21, "test");
c.put("/one/two", "key1", pojo);
- GlobalTransaction gtx = c.getCurrentTransaction(tx);
+ GlobalTransaction gtx = c.getCurrentTransaction(tx, true);
TransactionTable table = c.getTransactionTable();
- OptimisticTransactionEntry entry = (OptimisticTransactionEntry)table.get(gtx);
+ OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
assertNotNull(mgr.getTransaction());
mgr.commit();
@@ -225,7 +218,7 @@
//call our remote method
MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, injectDataVersion(entry.getModifications()), null,
remoteGtx.getAddress(), Boolean.FALSE);
- c._replicate(prepareMethod);
+ TestingUtil.getRemoteDelegate(c)._replicate(prepareMethod);
//our thread should be null
assertNull(mgr.getTransaction());
@@ -250,8 +243,8 @@
{
destroyCache(c);
- CacheImpl<Object, Object> cache = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
- CacheImpl<Object, Object> cache2 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
+ CacheSPI<Object, Object> cache = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
+ CacheSPI<Object, Object> cache2 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
assertEquals(2, cache.getMembers().size());
assertEquals(2, cache2.getMembers().size());
@@ -294,8 +287,8 @@
{
destroyCache(c);
- CacheImpl<Object, Object> cache = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
- CacheImpl<Object, Object> cache2 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
+ CacheSPI<Object, Object> cache = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
+ CacheSPI<Object, Object> cache2 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
assertEquals(2, cache.getMembers().size());
assertEquals(2, cache2.getMembers().size());
@@ -306,7 +299,7 @@
Transaction tx = mgr.getTransaction();
//this sets
- cache.getCurrentTransaction(tx);
+ cache.getCurrentTransaction(tx, true);
SamplePojo pojo = new SamplePojo(21, "test");
@@ -342,8 +335,8 @@
// {
// destroyCache(c);
//
- // CacheImpl cache = createPessimisticCache();
- // CacheImpl cache2 = createPessimisticCache();
+ // CacheSPI cache = createPessimisticCache();
+ // CacheSPI cache2 = createPessimisticCache();
//
// TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
//
@@ -379,7 +372,7 @@
Transaction tx = mgr.suspend();
// now remove the original node...
- c.remove(fqn);
+ c.removeNode(fqn);
mgr.resume(tx);
// now try and commit this - this should fail.
@@ -455,8 +448,8 @@
TransactionManager tm = c.getTransactionManager();
c.put(Fqn.fromString("/a/b"), "k", "v");
tm.begin();
- c.remove(Fqn.fromString("/a"));
- c.remove(Fqn.fromString("/a/b"));
+ c.removeNode(Fqn.fromString("/a"));
+ c.removeNode(Fqn.fromString("/a/b"));
tm.commit();
destroyCache(c);
@@ -468,7 +461,7 @@
TransactionManager tm = c.getTransactionManager();
c.put(Fqn.fromString("/a/b"), "k", "v");
tm.begin();
- c.remove(Fqn.fromString("/a"));
+ c.removeNode(Fqn.fromString("/a"));
c.put(Fqn.fromString("/a/b"), "k", "v");
tm.commit();
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/ComparatorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/ComparatorTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/ComparatorTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,14 +1,14 @@
package org.jboss.cache.optimistic;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.FqnComparator;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
+import org.testng.annotations.Test;
import java.util.ArrayList;
import java.util.List;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.FqnComparator;
-import org.testng.annotations.Test;
-
/**
* Tests {@link FqnComparator}.
*
@@ -142,11 +142,11 @@
public void testOrdinaryObjectCompare()
{
- Fqn<Object> fqn1 = new Fqn<Object>(new Object[]{new XYZ(), new ABC()});
- Fqn<Object> fqn2 = new Fqn<Object>(new Object[]{"XYZ", "ABC"});
- Fqn<Object> fqn3 = new Fqn<Object>(new Object[]{"XYZ", new ABC()});
+ Fqn<Object> fqn1 = new Fqn<Object>(new XYZ(), new ABC());
+ Fqn<Object> fqn2 = new Fqn<Object>("XYZ", "ABC");
+ Fqn<Object> fqn3 = new Fqn<Object>("XYZ", new ABC());
- Fqn<Object> fqn4 = new Fqn<Object>(new Object[]{"XYZ", new XYZ()});
+ Fqn<Object> fqn4 = new Fqn<Object>("XYZ", new XYZ());
assertEquals(0, comp.compare(fqn1, fqn2));
assertEquals(0, comp.compare(fqn1, fqn3));
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/FullStackInterceptorTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -4,7 +4,7 @@
import junit.framework.AssertionFailedError;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.Configuration;
@@ -19,6 +19,7 @@
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import java.util.Set;
+
/**
* @author xenephon
*/
@@ -32,7 +33,7 @@
public void testLocalTransaction() throws Exception
{
- CacheImpl<Object, Object> cache = createCacheWithListener();
+ CacheSPI<Object, Object> cache = createCacheWithListener();
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -53,7 +54,7 @@
assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
+ assertNotNull(cache.getRoot().getChild("one"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
// flesh this out a bit more
@@ -65,7 +66,7 @@
{
TestListener listener = new TestListener();
- CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ CacheSPI<Object, Object> cache = createCacheWithListener(listener);
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -82,13 +83,13 @@
assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/"))).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/one"))).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/one/two"))).getLock().isLocked());
- assertNotNull(cache.get(Fqn.fromString("/one")).getChild("two"));
+ assertNotNull(cache.getRoot().getChild("one"));
+ assertEquals(false, cache.getRoot().getLock()
+ .isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock()
+ .isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertNotNull(cache.getNode("/one").getChild("two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
assertEquals(2, listener.getNodesAdded());
@@ -101,7 +102,7 @@
public void testSingleInstanceCommit() throws Exception
{
groupIncreaser++;
- CacheImpl<Object, Object> cache = createCacheWithListener();
+ CacheSPI<Object, Object> cache = createCacheWithListener();
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -122,17 +123,17 @@
assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
+ assertNotNull(cache.getRoot().getChild("one"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/"))).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/one"))).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/one/two"))).getLock().isLocked());
- assertNotNull(cache.get(Fqn.fromString("/one")).getChild("two"));
+ assertNotNull(cache.getRoot().getChild("one"));
+ assertEquals(false, cache.getRoot().getLock()
+ .isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock()
+ .isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertNotNull(cache.getNode("/one").getChild("two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
destroyCache(cache);
@@ -141,7 +142,7 @@
public void testSingleInstanceRollback() throws Exception
{
groupIncreaser++;
- CacheImpl<Object, Object> cache = createSyncReplicatedCache();
+ CacheSPI<Object, Object> cache = createSyncReplicatedCache();
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -162,7 +163,7 @@
assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
assertEquals(false, cache.exists(Fqn.fromString("/one/two")));
- assertNull(cache.get(Fqn.fromString("/")).getChild("one"));
+ assertNull(cache.getRoot().getChild("one"));
destroyCache(cache);
@@ -171,7 +172,7 @@
public void testSingleInstanceDuplicateCommit() throws Exception
{
groupIncreaser++;
- CacheImpl<Object, Object> cache = createSyncReplicatedCache();
+ CacheSPI<Object, Object> cache = createSyncReplicatedCache();
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -205,13 +206,13 @@
assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/"))).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/one"))).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/one/two"))).getLock().isLocked());
- assertNotNull(cache.get(Fqn.fromString("/one")).getChild("two"));
+ assertNotNull(cache.getRoot().getChild("one"));
+ assertEquals(false, cache.getRoot().getLock()
+ .isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock()
+ .isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertNotNull(cache.getNode("/one").getChild("two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
destroyCache(cache);
@@ -221,7 +222,7 @@
public void testValidationFailCommit() throws Exception
{
groupIncreaser++;
- CacheImpl<Object, Object> cache = createSyncReplicatedCache();
+ CacheSPI<Object, Object> cache = createSyncReplicatedCache();
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -272,13 +273,13 @@
assertEquals(true, fail);
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/"))).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/one"))).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/one/two"))).getLock().isLocked());
- assertNotNull(cache.get(Fqn.fromString("/one")).getChild("two"));
+ assertNotNull(cache.getRoot().getChild("one"));
+ assertEquals(false, cache.getRoot().getLock()
+ .isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock()
+ .isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertNotNull(cache.getNode("/one").getChild("two"));
assertEquals(pojo2, cache.get(Fqn.fromString("/one/two"), "key1"));
destroyCache(cache);
@@ -288,8 +289,8 @@
public void test2InstanceCommit() throws Exception
{
groupIncreaser++;
- CacheImpl<Object, Object> cache = createSyncReplicatedCache();
- CacheImpl<Object, Object> cache2 = createSyncReplicatedCache();
+ CacheSPI<Object, Object> cache = createSyncReplicatedCache();
+ CacheSPI<Object, Object> cache2 = createSyncReplicatedCache();
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -311,17 +312,17 @@
assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
+ assertNotNull(cache.getRoot().getChild("one"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/"))).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/one"))).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/one/two"))).getLock().isLocked());
- assertNotNull(cache.get(Fqn.fromString("/one")).getChild("two"));
+ assertNotNull(cache.getRoot().getChild("one"));
+ assertEquals(false, cache.getRoot().getLock()
+ .isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock()
+ .isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertNotNull(cache.getNode("/one").getChild("two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
// cache2 asserts
@@ -329,15 +330,15 @@
assertEquals(0, cache2.getTransactionTable().getNumLocalTransactions());
assertTrue(cache2.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache2.get(Fqn.fromString("/")).getChild("one"));
+ assertNotNull(cache2.getRoot().getChild("one"));
assertNotNull(cache2.get(Fqn.fromString("/one/two"), "key1"));
assertTrue(cache2.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache2.get(Fqn.fromString("/")).getChild("one"));
- assertEquals(false, ((NodeSPI<Object, Object>) cache2.get(Fqn.fromString("/"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache2.get(Fqn.fromString("/one"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache2.get(Fqn.fromString("/one/two"))).getLock().isLocked());
- assertNotNull(cache2.get(Fqn.fromString("/one")).getChild("two"));
+ assertNotNull(cache2.getRoot().getChild("one"));
+ assertEquals(false, cache2.getRoot().getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache2.getNode("/one")).getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache2.getNode("/one/two")).getLock().isLocked());
+ assertNotNull(cache2.getNode("/one").getChild("two"));
assertNotNull(cache2.get(Fqn.fromString("/one/two"), "key1"));
destroyCache(cache);
@@ -347,8 +348,8 @@
public void test2InstanceRemove() throws Exception
{
groupIncreaser++;
- CacheImpl<Object, Object> cache = createSyncReplicatedCache();
- CacheImpl<Object, Object> cache2 = createSyncReplicatedCache();
+ CacheSPI<Object, Object> cache = createSyncReplicatedCache();
+ CacheSPI<Object, Object> cache2 = createSyncReplicatedCache();
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -370,17 +371,17 @@
assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
+ assertNotNull(cache.getRoot().getChild("one"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/"))).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/one"))).getLock()
- .isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/one/two"))).getLock().isLocked());
- assertNotNull(cache.get(Fqn.fromString("/one")).getChild("two"));
+ assertNotNull(cache.getRoot().getChild("one"));
+ assertEquals(false, cache.getRoot().getLock()
+ .isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock()
+ .isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertNotNull(cache.getNode("/one").getChild("two"));
assertNotNull(cache.get(Fqn.fromString("/one/two"), "key1"));
// cache2 asserts
@@ -388,20 +389,18 @@
assertEquals(0, cache2.getTransactionTable().getNumLocalTransactions());
assertTrue(cache2.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache2.get(Fqn.fromString("/")).getChild("one"));
+ assertNotNull(cache2.getRoot().getChild("one"));
assertNotNull(cache2.get(Fqn.fromString("/one/two"), "key1"));
assertTrue(cache2.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache2.get(Fqn.fromString("/")).getChild("one"));
- assertEquals(false, ((NodeSPI<Object, Object>) cache2.get(Fqn.fromString("/"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache2.get(Fqn.fromString("/one"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache2.get(Fqn.fromString("/one/two"))).getLock().isLocked());
- assertNotNull(cache2.get(Fqn.fromString("/one")).getChild("two"));
+ assertNotNull(cache2.getRoot().getChild("one"));
+ assertEquals(false, cache2.getRoot().getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache2.getNode("/one")).getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache2.getNode("/one/two")).getLock().isLocked());
+ assertNotNull(cache2.getNode("/one").getChild("two"));
assertNotNull(cache2.get(Fqn.fromString("/one/two"), "key1"));
- cache.remove("/one/two");
- log.debug(" C1 " + cache.get("/one/two"));
- log.debug(" C2 " + cache2.get("/one/two"));
+ cache.removeNode("/one/two");
assertEquals(false, cache.exists("/one/two"));
assertEquals(false, cache2.exists("/one/two"));
@@ -415,8 +414,8 @@
public void testValidationFailCommit2Instances() throws Exception
{
groupIncreaser++;
- CacheImpl<Object, Object> cache = createSyncReplicatedCache();
- CacheImpl<Object, Object> cache2 = createSyncReplicatedCache();
+ CacheSPI<Object, Object> cache = createSyncReplicatedCache();
+ CacheSPI<Object, Object> cache2 = createSyncReplicatedCache();
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -435,10 +434,10 @@
assertEquals(1, cache.getTransactionTable().getNumGlobalTransactions());
assertEquals(1, cache.getTransactionTable().getNumLocalTransactions());
- GlobalTransaction gtx = cache.getCurrentTransaction(tx);
+ GlobalTransaction gtx = cache.getCurrentTransaction(tx, true);
TransactionTable table = cache.getTransactionTable();
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table
- .get(gtx);
+ .get(gtx);
assertEquals(3, entry.getTransactionWorkSpace().getNodes().size());
@@ -476,11 +475,11 @@
assertEquals(0, entry.getTransactionWorkSpace().getNodes().size());
assertTrue(cache.exists(Fqn.fromString("/one/two")));
- assertNotNull(cache.get(Fqn.fromString("/")).getChild("one"));
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/one"))).getLock().isLocked());
- assertEquals(false, ((NodeSPI<Object, Object>) cache.get(Fqn.fromString("/one/two"))).getLock().isLocked());
- assertNotNull(cache.get(Fqn.fromString("/one")).getChild("two"));
+ assertNotNull(cache.getRoot().getChild("one"));
+ assertEquals(false, cache.getRoot().getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one")).getLock().isLocked());
+ assertEquals(false, ((NodeSPI<Object, Object>) cache.getNode("/one/two")).getLock().isLocked());
+ assertNotNull(cache.getNode("/one").getChild("two"));
assertEquals(pojo2, cache.get(Fqn.fromString("/one/two"), "key1"));
destroyCache(cache);
@@ -493,7 +492,7 @@
SamplePojo pojo1 = new SamplePojo(21, "test-1");
SamplePojo pojo2 = new SamplePojo(21, "test-2");
- CacheImpl<Object, Object> cache = createCacheWithListener();
+ CacheSPI<Object, Object> cache = createCacheWithListener();
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
@@ -540,7 +539,7 @@
public void testGetKeysIsolationTransaction() throws Exception
{
- CacheImpl<Object, Object> cache = createCacheWithListener();
+ CacheSPI<Object, Object> cache = createCacheWithListener();
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
if (mgr.getTransaction() != null) mgr.rollback();
@@ -560,7 +559,7 @@
mgr.begin();
Transaction tx = mgr.getTransaction();
- assertEquals(1, cache.getKeys("/one/two").size());
+ assertEquals(1, cache.getNode("/one/two").getKeys().size());
// start another
mgr.suspend();
@@ -570,12 +569,12 @@
mgr.commit();
// assert we can see this outsode the existing tx
- assertEquals(2, cache.getKeys("/one/two").size());
+ assertEquals(2, cache.getNode("/one/two").getKeys().size());
// resume the suspended one
mgr.resume(tx);
// assert we can't see thge change from tx2 as we already touched the node
- assertEquals(1, cache.getKeys("/one/two").size());
+ assertEquals(1, cache.getNode("/one/two").getKeys().size());
mgr.commit();
destroyCache(cache);
@@ -584,7 +583,7 @@
public void testTxRollbackThroughConcurrentWrite() throws Exception
{
- CacheImpl<Object, Object> cache = createCacheWithListener();
+ CacheSPI<Object, Object> cache = createCacheWithListener();
Set keys;
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -597,7 +596,7 @@
assertEquals(0, cache.getTransactionTable().getNumLocalTransactions());
cache.put("/one/two", "key1", "val1");
mgr.commit();
- keys = cache.getKeys("/one/two");
+ keys = cache.getNode("/one/two").getKeys();
System.out.println("keys after TX #1: " + keys);
assertEquals(1, keys.size());
@@ -615,14 +614,14 @@
mgr.commit();// now version is 2, attrs are key1 and key3
// assert we can see this outside the existing tx
- keys = cache.getKeys("/one/two");
+ keys = cache.getNode("/one/two").getKeys();
System.out.println("keys after TX #3 committed: " + keys);
assertEquals(2, keys.size());
// resume the suspended one
mgr.resume(tx);
// assert we can't see the change from tx2 as we already touched the node
- keys = cache.getKeys("/one/two");
+ keys = cache.getNode("/one/two").getKeys();
System.out.println("keys after TX #2 resumed (in private workspace of TX #2): " + keys);
assertEquals(2, keys.size());// we will see key1 and key2, but *not* key3
@@ -635,24 +634,24 @@
catch (RollbackException rollback_ex)
{
System.out.println("TX was rolled back because the other TX committed first and incremented version ID." +
- " This is the expected behavior");
+ " This is the expected behavior");
}
- keys = cache.getKeys("/one/two");
+ keys = cache.getNode("/one/two").getKeys();
System.out.println("keys after TX #2 was rolled back: " + keys);
assertEquals(2, keys.size());// key1 and key2
destroyCache(cache);
}
- protected CacheImpl<Object, Object> createSyncReplicatedCache() throws Exception
+ protected CacheSPI<Object, Object> createSyncReplicatedCache() throws Exception
{
return createReplicatedCache("temp" + groupIncreaser, Configuration.CacheMode.REPL_SYNC);
}
-
- protected CacheImpl<Object, Object> createSyncReplicatedCacheAsyncCommit() throws Exception
+
+ protected CacheSPI<Object, Object> createSyncReplicatedCacheAsyncCommit() throws Exception
{
- CacheImpl<Object, Object> cache = createReplicatedCache("temp" + groupIncreaser, Configuration.CacheMode.REPL_SYNC, false);
+ CacheSPI<Object, Object> cache = createReplicatedCache("temp" + groupIncreaser, Configuration.CacheMode.REPL_SYNC, false);
cache.getConfiguration().setSyncCommitPhase(false);
cache.getConfiguration().setSyncRollbackPhase(false);
cache.create();
@@ -662,11 +661,11 @@
public void testPuts() throws Exception
{
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI cache = createCache();
Transaction tx;
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
- Assert.assertNull(cache.get(fqn));
+ Assert.assertNull(cache.getNode(fqn));
mgr.begin();
cache.put(fqn, key, value);
@@ -688,18 +687,18 @@
public void testRemoves() throws Exception
{
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
Transaction tx;
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
- Assert.assertNull(cache.get(fqn));
+ Assert.assertNull(cache.getNode(fqn));
cache.put(fqn, key, value);
Assert.assertEquals(value, cache.get(fqn, key));
mgr.begin();
Assert.assertEquals(value, cache.get(fqn, key));
- cache.remove(fqn);
- Assert.assertNull(cache.get(fqn));
+ cache.removeNode(fqn);
+ Assert.assertNull(cache.getNode(fqn));
tx = mgr.getTransaction();
mgr.suspend();
@@ -708,26 +707,26 @@
mgr.commit();
mgr.resume(tx);
- Assert.assertNull(cache.get(fqn));
+ Assert.assertNull(cache.getNode(fqn));
mgr.commit();
- Assert.assertNull(cache.get(fqn));
+ Assert.assertNull(cache.getNode(fqn));
}
public void testRemovesBeforeGet() throws Exception
{
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
Transaction tx;
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
- Assert.assertNull(cache.get(fqn));
+ Assert.assertNull(cache.getNode(fqn));
cache.put(fqn, key, value);
Assert.assertEquals(value, cache.get(fqn, key));
mgr.begin();
- cache.remove(fqn);
- Assert.assertNull(cache.get(fqn));
+ cache.removeNode(fqn);
+ Assert.assertNull(cache.getNode(fqn));
tx = mgr.getTransaction();
mgr.suspend();
@@ -736,10 +735,10 @@
mgr.commit();
mgr.resume(tx);
- Assert.assertNull(cache.get(fqn));
+ Assert.assertNull(cache.getNode(fqn));
mgr.commit();
- Assert.assertNull(cache.get(fqn));
+ Assert.assertNull(cache.getNode(fqn));
}
public void testLoopedPutAndGet() throws Exception
@@ -747,8 +746,8 @@
try
{
log.debug("Starting test");
- CacheImpl<Object, Object> cache1 = createSyncReplicatedCache();
- CacheImpl<Object, Object> cache2 = createSyncReplicatedCache();
+ CacheSPI<Object, Object> cache1 = createSyncReplicatedCache();
+ CacheSPI<Object, Object> cache2 = createSyncReplicatedCache();
log.debug("Created caches");
TransactionManager mgr = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -779,60 +778,64 @@
throw e;
}
}
-
+
/**
* Tests that if synchronous commit messages are not used, the proper
* data is returned from remote nodes after a tx that does a local
* put returns.
- *
+ *
* @throws Exception
*/
- @Test(enabled = false) // known failure - JBCACHE-1201
- public void testAsynchronousCommit() throws Exception
+ @Test(enabled = false)
+ // known failure - JBCACHE-1201
+ public void testAsynchronousCommit() throws Exception
{
- CacheImpl<Object, Object> cache1 = createSyncReplicatedCacheAsyncCommit();
- CacheImpl<Object, Object> cache2 = createSyncReplicatedCacheAsyncCommit();
+ CacheSPI<Object, Object> cache1 = createSyncReplicatedCacheAsyncCommit();
+ CacheSPI<Object, Object> cache2 = createSyncReplicatedCacheAsyncCommit();
// Test will pass if we set up the caches with SyncCommitPhaseTrue
-// CacheImpl<Object, Object> cache1 = createSyncReplicatedCache();
-// CacheImpl<Object, Object> cache2 = createSyncReplicatedCache();
-
+// CacheSPI<Object, Object> cache1 = createSyncReplicatedCache();
+// CacheSPI<Object, Object> cache2 = createSyncReplicatedCache();
+
TransactionManager tm1 = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
-
+
Fqn<String> fqn = Fqn.fromString("/test/node");
String KEY = "key";
String VALUE1 = "value1";
-
+
tm1.begin();
cache1.put(fqn, KEY, VALUE1);
tm1.commit();
-
+
// A simple sleep will also make this test pass
// try { Thread.sleep(100); } catch (InterruptedException e) {}
-
+
assertEquals("Known issue JBCACHE-1201: Correct node2 value", VALUE1, cache2.get(fqn, KEY));
assertEquals("Correct node1 value", VALUE1, cache1.get(fqn, KEY));
-
+
destroyCache(cache1);
destroyCache(cache2);
- }
-
- private void rollback(TransactionManager tm) {
- try {
- tm.rollback();
- }
- catch (Exception e) {
- log.error(e.getMessage(), e);
- }
-
}
-
- private class ExceptionHolder
- {
- Exception node1Exception;
- Exception node2Exception;
-
- AssertionFailedError node1Failure;
- AssertionFailedError node2Failure;
- }
+ private void rollback(TransactionManager tm)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (Exception e)
+ {
+ log.error(e.getMessage(), e);
+ }
+
+ }
+
+ private class ExceptionHolder
+ {
+ Exception node1Exception;
+ Exception node2Exception;
+
+ AssertionFailedError node1Failure;
+ AssertionFailedError node2Failure;
+ }
+
}
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/HasChildTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,16 +1,15 @@
package org.jboss.cache.optimistic;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
-import org.jboss.cache.CacheImpl;
-import org.jboss.cache.Fqn;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-
/**
* Tests the hasChild() API
*
@@ -19,7 +18,7 @@
*/
public class HasChildTest extends AbstractOptimisticTestCase
{
- private CacheImpl<Object, Object> cache;
+ private CacheSPI<Object, Object> cache;
private TransactionManager txMgr;
private Fqn f = Fqn.fromString("/a");
@@ -43,7 +42,7 @@
assertTrue(cache.getRoot().hasChild(f));
- cache.remove(f);
+ cache.removeNode(f);
assertFalse(cache.getRoot().hasChild(f));
@@ -63,7 +62,7 @@
txMgr.begin();
assertTrue(cache.getRoot().hasChild(f));
- cache.remove(f);
+ cache.removeNode(f);
assertFalse(cache.getRoot().hasChild(f));
t = txMgr.suspend();
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/MockInterceptor.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,14 +1,14 @@
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 java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
-import org.jboss.cache.CacheImpl;
-import org.jboss.cache.InvocationContext;
-import org.jboss.cache.interceptors.Interceptor;
-import org.jboss.cache.marshall.MethodCall;
-
/**
* Handles putXXX() methods: if the given node doesn't exist, it will be created
* (depending on the create_if_not_exists argument)
@@ -19,7 +19,7 @@
*/
public class MockInterceptor extends Interceptor
{
- public void setCache(CacheImpl cache)
+ public void setCache(CacheSPI cache)
{
super.setCache(cache);
}
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetChildrenNamesTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetChildrenNamesTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetChildrenNamesTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,11 +1,12 @@
package org.jboss.cache.optimistic;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.loader.SamplePojo;
+import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
@@ -19,26 +20,23 @@
/**
* @author xenephon
*/
-@Test (groups = {"functional"})
+@Test(groups = {"functional"})
public class NodeInterceptorGetChildrenNamesTest extends AbstractOptimisticTestCase
{
public void testTransactionGetNamesMethod() throws Exception
{
TestListener listener = new TestListener();
- final CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -47,7 +45,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
@@ -65,7 +63,7 @@
TransactionWorkspace<Object, Object> workspace = entry.getTransactionWorkSpace();
//assert we can see this with a key value get in the transaction
- assertEquals(1, cache.getChildrenNames("/one").size());
+ assertEquals(1, cache.getNode("/one").getChildrenNames().size());
mgr.commit();
//assert what should be the results of our call
@@ -85,9 +83,9 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx2);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx2));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx2, true));
- assertEquals(0, cache.getChildrenNames("/").size());
+ assertEquals(0, cache.getRoot().getChildrenNames().size());
mgr.commit();
cache.stop();
}
@@ -97,19 +95,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -118,7 +113,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
assertEquals(null, dummy.getCalled());
@@ -129,7 +124,7 @@
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
//assert we can see this with a key value get in the transaction
- assertEquals(0, cache.getChildrenNames("/").size());
+ assertEquals(0, cache.getRoot().getChildrenNames().size());
mgr.commit();
@@ -147,19 +142,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -168,7 +160,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
@@ -185,11 +177,11 @@
TransactionWorkspace<Object, Object> workspace = entry.getTransactionWorkSpace();
//assert we can see this
- assertEquals(1, cache.getChildrenNames("/one").size());
+ assertEquals(1, cache.getNode("/one").getChildrenNames().size());
try
{
- for (Iterator<?> it = cache.getChildrenNames("/one").iterator(); it.hasNext();)
+ for (Iterator<?> it = cache.getNode("/one").getChildrenNames().iterator(); it.hasNext();)
{
it.next();
it.remove();
@@ -202,7 +194,7 @@
}
//assert the removal has had no effect
- assertEquals(1, cache.getChildrenNames("/one").size());
+ assertEquals(1, cache.getNode("/one").getChildrenNames().size());
assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
mgr.commit();
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeyValTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,22 +1,20 @@
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.loader.SamplePojo;
+import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
+import static org.testng.AssertJUnit.*;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
/**
* @author xenephon
*/
@@ -26,19 +24,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -47,7 +42,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
@@ -84,7 +79,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx2);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx2));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx2, true));
assertNull(cache.get("/one/two", "key1"));
mgr.commit();
@@ -95,19 +90,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -116,7 +108,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
@@ -155,19 +147,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -176,7 +165,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
@@ -214,19 +203,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -235,7 +221,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
@@ -250,7 +236,7 @@
Transaction tx2 = mgr.getTransaction();
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx2);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx2));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx2, true));
SamplePojo pojo2 = new SamplePojo(22, "test2");
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorGetKeysTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,24 +1,21 @@
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import java.util.Iterator;
-
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.loader.SamplePojo;
+import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
+import static org.testng.AssertJUnit.*;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.Iterator;
+
/**
* @author xenephon
*/
@@ -28,19 +25,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -49,7 +43,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
@@ -66,7 +60,7 @@
TransactionWorkspace<Object, Object> workspace = entry.getTransactionWorkSpace();
//assert we can see this with a key value get in the transaction
- assertEquals(1, cache.getKeys("/one/two").size());
+ assertEquals(1, cache.getNode("/one/two").getKeys().size());
mgr.commit();
//assert what should be the results of our call
@@ -86,7 +80,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx2);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx2));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx2, true));
assertNull(cache.get("/one/two", "key1"));
mgr.commit();
@@ -98,19 +92,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -119,7 +110,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
assertEquals(null, dummy.getCalled());
@@ -130,7 +121,7 @@
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
//assert we can see this with a key value get in the transaction
- assertEquals(0, cache.getKeys("/").size());
+ assertEquals(0, cache.getRoot().getKeys().size());
mgr.commit();
@@ -146,19 +137,16 @@
public void testTransactionGetKeysIteratorMethod() throws Exception
{
TestListener listener = new TestListener();
- final CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -167,7 +155,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
@@ -182,14 +170,14 @@
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
//assert we can see this with a key value get in the transaction
- assertEquals(1, cache.getKeys("/one/two").size());
+ assertEquals(1, cache.getNode("/one/two").getKeys().size());
- for (Iterator<?> it = cache.getKeys("/one/two").iterator(); it.hasNext();)
+ for (Iterator<?> it = cache.getNode("/one/two").getKeys().iterator(); it.hasNext();)
{
it.next();
it.remove();
}
- assertEquals(0, cache.getKeys("/one/two").size());
+ assertEquals(0, cache.getNode("/one/two").getKeys().size());
mgr.commit();
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorKeyValTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,21 +1,20 @@
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertTrue;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
import org.jboss.cache.loader.SamplePojo;
+import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionTable;
+import static org.testng.AssertJUnit.*;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
/**
* @author xenephon
*/
@@ -25,19 +24,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -46,7 +42,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
@@ -80,19 +76,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -101,7 +94,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
@@ -138,19 +131,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -159,7 +149,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
@@ -195,19 +185,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -216,7 +203,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
@@ -253,19 +240,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -274,7 +258,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
@@ -287,7 +271,7 @@
mgr.begin();
Transaction tx2 = mgr.getTransaction();
cache.getInvocationContext().setTransaction(tx2);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx2));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx2, true));
SamplePojo pojo2 = new SamplePojo(21, "test");
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutEraseTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,24 +1,22 @@
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertTrue;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.transaction.Transaction;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
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 javax.transaction.Transaction;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* @author xenephon
*/
@@ -29,19 +27,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -50,7 +45,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
Map temp = new HashMap();
@@ -83,19 +78,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -104,7 +96,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
@@ -140,19 +132,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -161,7 +150,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorPutMapTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,24 +1,22 @@
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertTrue;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.transaction.Transaction;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
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 javax.transaction.Transaction;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* @author xenephon
*/
@@ -29,20 +27,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
-
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -51,7 +45,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
Map temp = new HashMap();
@@ -86,19 +80,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -107,7 +98,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
Map temp = new HashMap();
@@ -145,20 +136,17 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Fqn f = Fqn.fromString("/one/two");
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -167,7 +155,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
Map temp = new HashMap();
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveDataTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,25 +1,22 @@
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.transaction.Transaction;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
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 javax.transaction.Transaction;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* @author xenephon
*/
@@ -30,19 +27,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -51,9 +45,9 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
- cache.removeData("/one/two");
+ cache.getNode("/one/two").clearData();
assertEquals(null, dummy.getCalled());
TransactionTable table = cache.getTransactionTable();
@@ -81,19 +75,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -102,13 +93,13 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
Map temp = new HashMap();
cache.put("/one/two", temp);
- cache.removeData("/one/two");
+ cache.getNode("/one/two").clearData();
assertEquals(null, dummy.getCalled());
TransactionTable table = cache.getTransactionTable();
@@ -138,19 +129,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -159,7 +147,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
Map temp = new HashMap();
@@ -177,7 +165,7 @@
TransactionWorkspace workspace = entry.getTransactionWorkSpace();
assertEquals(1, workspace.getNode(Fqn.fromString("/one/two")).getMergedData().size());
- cache.removeData("/one/two");
+ cache.getNode("/one/two").clearData();
mgr.commit();
@@ -198,19 +186,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -219,7 +204,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
Map temp = new HashMap();
@@ -237,7 +222,7 @@
TransactionWorkspace workspace = entry.getTransactionWorkSpace();
assertEquals(1, workspace.getNode(Fqn.fromString("/one/two")).getMergedData().size());
- cache.removeData("/one");
+ cache.getNode("/one").clearData();
mgr.commit();
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveKeyValTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -5,27 +5,24 @@
*
*/
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.transaction.Transaction;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
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 javax.transaction.Transaction;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* @author xenephon
*/
@@ -36,19 +33,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -57,7 +51,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
cache.remove("/one/two", "keyOne");
@@ -87,19 +81,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -108,7 +99,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
Map temp = new HashMap();
@@ -145,19 +136,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -166,7 +154,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
Map temp = new HashMap();
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveNodeTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveNodeTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorRemoveNodeTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,7 +6,7 @@
*/
package org.jboss.cache.optimistic;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.factories.InterceptorChainFactory;
@@ -31,16 +31,17 @@
/**
* @author xenephon
*/
-@Test (groups = {"functional"})
+@Test(groups = {"functional"})
@SuppressWarnings("unchecked")
public class NodeInterceptorRemoveNodeTest extends AbstractOptimisticTestCase
{
- private CacheImpl<Object, Object> cache;
+ private CacheSPI<Object, Object> cache;
private TestListener listener;
private MockInterceptor dummy;
private TransactionManager mgr;
- @BeforeMethod(alwaysRun = true) public void setUp() throws Exception
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws Exception
{
listener = new TestListener();
cache = createCacheWithListener(listener);
@@ -61,11 +62,11 @@
InterceptorChainFactory.getInstance().setLastInterceptorPointer(interceptor, dummy);
- cache.setInterceptorChain(interceptor);
mgr = cache.getTransactionManager();
}
- @AfterMethod(alwaysRun = true) public void tearDown()
+ @AfterMethod(alwaysRun = true)
+ public void tearDown()
{
super.tearDown();
cache.stop();
@@ -78,10 +79,10 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
- cache.remove("/one/two");
+ cache.removeNode("/one/two");
TransactionTable table = cache.getTransactionTable();
GlobalTransaction gtx = table.get(tx);
@@ -108,14 +109,14 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
Map temp = new HashMap();
temp.put("key1", pojo);
cache.put("/one/two", temp);
- cache.remove("/one/two");
+ cache.removeNode("/one/two");
assertEquals(null, dummy.getCalled());
TransactionTable table = cache.getTransactionTable();
@@ -149,14 +150,14 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
Map temp = new HashMap();
temp.put("key1", pojo);
cache.put("/one/two", temp);
- cache.remove("/one");
+ cache.removeNode("/one");
assertEquals(null, dummy.getCalled());
TransactionTable table = cache.getTransactionTable();
@@ -188,7 +189,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
Map temp = new HashMap();
@@ -207,7 +208,7 @@
workspace.getNode(Fqn.fromString("/one/two"));
- cache.remove("/one");
+ cache.removeNode("/one");
assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
assertEquals(true, workspace.getNode(Fqn.fromString("/one/two")).isDeleted());
@@ -215,7 +216,7 @@
assertEquals(true, workspace.getNode(Fqn.fromString("/one")).isDeleted());
//now put /one/two back in
- cache.remove("/one");
+ cache.removeNode("/one");
assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
@@ -244,7 +245,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
Map temp = new HashMap();
@@ -263,7 +264,7 @@
Node two = workspace.getNode(Fqn.fromString("/one/two"));
- cache.remove("/one");
+ cache.removeNode("/one");
assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
assertEquals(true, workspace.getNode(Fqn.fromString("/one/two")).isDeleted());
@@ -303,7 +304,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
Map temp = new HashMap();
@@ -322,7 +323,7 @@
Node two = workspace.getNode(Fqn.fromString("/one/two"));
- cache.remove("/one");
+ cache.removeNode("/one");
assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
assertEquals(true, workspace.getNode(Fqn.fromString("/one/two")).isDeleted());
@@ -363,7 +364,7 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
Map temp = new HashMap();
@@ -382,7 +383,7 @@
assertEquals(1, one.getMergedChildren().get(0).size());
- cache.remove("/one/two");
+ cache.removeNode("/one/two");
assertNotNull(workspace.getNode(Fqn.fromString("/one/two")));
assertEquals(true, workspace.getNode(Fqn.fromString("/one/two")).isDeleted());
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/NodeInterceptorTransactionTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -5,14 +5,13 @@
*
*/
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
import org.jboss.cache.interceptors.OptimisticNodeInterceptor;
+import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.*;
/**
* @author xenephon
@@ -24,19 +23,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
try
{
@@ -56,19 +52,16 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
boolean fail = false;
try
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticCreateIfNotExistsInterceptorTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -5,24 +5,23 @@
*
*/
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertTrue;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
import org.jboss.cache.loader.SamplePojo;
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 static org.testng.AssertJUnit.*;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
/**
* @author xenephon
*/
@@ -37,7 +36,7 @@
protected OptimisticTransactionEntry entry;
protected TransactionWorkspace workspace;
- protected void setupTransactionsInInvocationCtx(CacheImpl cache) throws Exception
+ protected void setupTransactionsInInvocationCtx(CacheSPI cache) throws Exception
{
txManager = DummyTransactionManager.getInstance();
// start a tx
@@ -61,16 +60,14 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
setupTransactionsInInvocationCtx(cache);
@@ -95,18 +92,14 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(dummy);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
-
- cache.setInterceptorChain(interceptor);
-
setupTransactionsInInvocationCtx(cache);
final SamplePojo pojo = new SamplePojo(21, "test");
cache.put("/one/two", "key1", pojo);
@@ -142,15 +135,12 @@
{
TestListener listener = new TestListener();
- final CacheImpl cache = createCacheWithListener(listener);
+ final CacheSPI cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(dummy);
-
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
SamplePojo pojo = new SamplePojo(21, "test");
setupTransactionsInInvocationCtx(cache);
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticReplicationInterceptorTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -5,50 +5,48 @@
*
*/
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.transaction.RollbackException;
-import javax.transaction.Transaction;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.marshall.MethodCall;
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.jgroups.Address;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import javax.transaction.RollbackException;
+import javax.transaction.Transaction;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* @author xenephon
*/
@SuppressWarnings("unchecked")
public class OptimisticReplicationInterceptorTest extends AbstractOptimisticTestCase
{
- private CacheImpl cache;
+ private CacheSPI cache;
- @BeforeMethod(alwaysRun = true) public void setUp() throws Exception
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws Exception
{
cache = createCache();
}
- @AfterMethod(alwaysRun = true) public void tearDown()
+ @AfterMethod(alwaysRun = true)
+ public void tearDown()
{
super.tearDown();
destroyCache(cache);
@@ -57,10 +55,8 @@
public void testLocalTransaction() throws Exception
{
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, true));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
-
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
assertNull(mgr.getTransaction());
@@ -90,10 +86,8 @@
public void testRollbackTransaction() throws Exception
{
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, true));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
-
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
assertNull(mgr.getTransaction());
assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
@@ -118,10 +112,8 @@
public void testRemotePrepareTransaction() throws Exception
{
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, true));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
-
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
//start local transaction
@@ -129,13 +121,13 @@
Transaction tx = mgr.getTransaction();
//this sets
- cache.getCurrentTransaction(tx);
+ cache.getCurrentTransaction(tx, true);
SamplePojo pojo = new SamplePojo(21, "test");
cache.put("/one/two", "key1", pojo);
- GlobalTransaction gtx = cache.getCurrentTransaction(tx);
+ GlobalTransaction gtx = cache.getCurrentTransaction(tx, true);
TransactionTable table = cache.getTransactionTable();
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
assertNotNull(mgr.getTransaction());
@@ -153,7 +145,7 @@
MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), false);
try
{
- cache._replicate(prepareMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
}
catch (Throwable t)
{
@@ -185,10 +177,8 @@
public void testRemoteRollbackTransaction() throws Exception
{
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, true));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
-
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
//start local transaction
@@ -196,13 +186,13 @@
Transaction tx = mgr.getTransaction();
//this sets
- cache.getCurrentTransaction(tx);
+ cache.getCurrentTransaction(tx, true);
SamplePojo pojo = new SamplePojo(21, "test");
cache.put("/one/two", "key1", pojo);
- GlobalTransaction gtx = cache.getCurrentTransaction(tx);
+ GlobalTransaction gtx = cache.getCurrentTransaction(tx, true);
TransactionTable table = cache.getTransactionTable();
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
assertNotNull(mgr.getTransaction());
@@ -220,7 +210,7 @@
MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), false);
try
{
- cache._replicate(prepareMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
}
catch (Throwable t)
{
@@ -249,7 +239,7 @@
MethodCall rollbackMethod = MethodCallFactory.create(MethodDeclarations.rollbackMethod, remoteGtx);
try
{
- cache._replicate(rollbackMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(rollbackMethod);
}
catch (Throwable t)
{
@@ -266,10 +256,8 @@
public void testRemoteCommitNoPrepareTransaction() throws Exception
{
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, true));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
-
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
//start local transaction
@@ -277,13 +265,13 @@
Transaction tx = mgr.getTransaction();
//this sets
- cache.getCurrentTransaction(tx);
+ cache.getCurrentTransaction(tx, true);
SamplePojo pojo = new SamplePojo(21, "test");
cache.put("/one/two", "key1", pojo);
- GlobalTransaction gtx = cache.getCurrentTransaction(tx);
+ GlobalTransaction gtx = cache.getCurrentTransaction(tx, true);
TransactionTable table = cache.getTransactionTable();
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
assertNotNull(mgr.getTransaction());
@@ -310,7 +298,7 @@
MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, remoteGtx);
try
{
- cache._replicate(commitMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(commitMethod);
fail();
}
catch (Throwable t)
@@ -329,10 +317,8 @@
public void testRemoteRollbackNoPrepareTransaction() throws Throwable
{
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, true));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
-
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
//start local transaction
@@ -340,13 +326,13 @@
Transaction tx = mgr.getTransaction();
//this sets
- cache.getCurrentTransaction(tx);
+ cache.getCurrentTransaction(tx, true);
SamplePojo pojo = new SamplePojo(21, "test");
cache.put("/one/two", "key1", pojo);
- GlobalTransaction gtx = cache.getCurrentTransaction(tx);
+ GlobalTransaction gtx = cache.getCurrentTransaction(tx, true);
TransactionTable table = cache.getTransactionTable();
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
assertNotNull(mgr.getTransaction());
@@ -372,7 +358,7 @@
// call our remote method
MethodCall rollbackMethod = MethodCallFactory.create(MethodDeclarations.rollbackMethod, remoteGtx);
- cache._replicate(rollbackMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(rollbackMethod);
assertTrue("Should be handled on the remote end without barfing, in the event of a rollback without a prepare", true);
//we should have the commit as well now
@@ -386,10 +372,8 @@
public void testRemoteCommitTransaction() throws Exception
{
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, true));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
-
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
//start local transaction
@@ -397,13 +381,13 @@
Transaction tx = mgr.getTransaction();
//this sets
- cache.getCurrentTransaction(tx);
+ cache.getCurrentTransaction(tx, true);
SamplePojo pojo = new SamplePojo(21, "test");
cache.put("/one/two", "key1", pojo);
- GlobalTransaction gtx = cache.getCurrentTransaction(tx);
+ GlobalTransaction gtx = cache.getCurrentTransaction(tx, true);
TransactionTable table = cache.getTransactionTable();
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
assertNotNull(mgr.getTransaction());
@@ -421,7 +405,7 @@
MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), false);
try
{
- cache._replicate(prepareMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
}
catch (Throwable t)
{
@@ -451,7 +435,7 @@
MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, remoteGtx);
try
{
- cache._replicate(commitMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(commitMethod);
}
catch (Throwable t)
{
@@ -471,15 +455,12 @@
cache = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, true));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
-
- CacheImpl cache2 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
+ CacheSPI cache2 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
MockInterceptor dummy2 = new MockInterceptor();
- dummy.setCache(cache2);
+ TestingUtil.replaceInterceptorChain(cache2, getAlteredInterceptorChain(dummy2, cache2, true));
- cache2.setInterceptorChain(getAlteredInterceptorChain(dummy2, cache2, true));
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -488,7 +469,7 @@
Transaction tx = mgr.getTransaction();
//this sets
- cache.getCurrentTransaction(tx);
+ cache.getCurrentTransaction(tx, true);
SamplePojo pojo = new SamplePojo(21, "test");
@@ -527,19 +508,15 @@
cache = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, true));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
-
- CacheImpl cache2 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
+ CacheSPI cache2 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
MockFailureInterceptor dummy2 = new MockFailureInterceptor();
List failures = new ArrayList();
failures.add(MethodDeclarations.optimisticPrepareMethod);
dummy2.setFailurelist(failures);
- dummy.setCache(cache2);
+ TestingUtil.replaceInterceptorChain(cache2, getAlteredInterceptorChain(dummy2, cache2, true));
- cache2.setInterceptorChain(getAlteredInterceptorChain(dummy2, cache2, true));
-
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
//start local transaction
@@ -547,7 +524,7 @@
Transaction tx = mgr.getTransaction();
//this sets
- cache.getCurrentTransaction(tx);
+ cache.getCurrentTransaction(tx, true);
SamplePojo pojo = new SamplePojo(21, "test");
@@ -594,16 +571,12 @@
cache = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
MockFailureInterceptor dummy = new MockFailureInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, true));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
-
- CacheImpl cache2 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
+ CacheSPI cache2 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
MockInterceptor dummy2 = new MockInterceptor();
- dummy.setCache(cache2);
+ TestingUtil.replaceInterceptorChain(cache2, getAlteredInterceptorChain(dummy2, cache2, true));
- cache2.setInterceptorChain(getAlteredInterceptorChain(dummy2, cache2, true));
-
List failures = new ArrayList();
failures.add(MethodDeclarations.optimisticPrepareMethod);
dummy.setFailurelist(failures);
@@ -615,7 +588,7 @@
Transaction tx = mgr.getTransaction();
//this sets
- cache.getCurrentTransaction(tx);
+ cache.getCurrentTransaction(tx, true);
SamplePojo pojo = new SamplePojo(21, "test");
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticVersioningTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -5,19 +5,19 @@
* See terms of license at gnu.org.
*/
package org.jboss.cache.optimistic;
-import javax.transaction.RollbackException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
import junit.framework.Assert;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.Configuration;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import javax.transaction.RollbackException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
/**
* Unit test that covers versioning of data and workspace nodes when using optimistic locking.
*
@@ -26,15 +26,17 @@
@SuppressWarnings("unchecked")
public class OptimisticVersioningTest extends AbstractOptimisticTestCase
{
- CacheImpl cache1, cache2;
+ CacheSPI cache1, cache2;
- @BeforeMethod(alwaysRun = true) public void setUp() throws Exception
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws Exception
{
cache1 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
cache2 = createReplicatedCache(Configuration.CacheMode.REPL_SYNC);
}
- @AfterMethod(alwaysRun = true) public void tearDown()
+ @AfterMethod(alwaysRun = true)
+ public void tearDown()
{
super.tearDown();
destroyCache(cache1);
@@ -43,15 +45,15 @@
cache2 = null;
}
- public void testVersionPropagation() throws Exception
+ public void testVersionPropagation()
{
Fqn fqn = Fqn.fromString("/a/b");
String key = "key";
cache1.put(fqn, key, "value");
- DataVersion v1 = ((NodeSPI) cache1.get(fqn)).getVersion();
- DataVersion v2 = ((NodeSPI) cache2.get(fqn)).getVersion();
+ DataVersion v1 = ((NodeSPI) cache1.getNode(fqn)).getVersion();
+ DataVersion v2 = ((NodeSPI) cache2.getNode(fqn)).getVersion();
Assert.assertEquals("value", cache1.get(fqn, key));
Assert.assertEquals("value", cache2.get(fqn, key));
@@ -60,8 +62,8 @@
// change stuff in the node again...
cache1.put(fqn, key, "value2");
- v1 = ((NodeSPI) cache1.get(fqn)).getVersion();
- v2 = ((NodeSPI) cache2.get(fqn)).getVersion();
+ v1 = ((NodeSPI) cache1.getNode(fqn)).getVersion();
+ v2 = ((NodeSPI) cache2.getNode(fqn)).getVersion();
Assert.assertEquals("value2", cache1.get(fqn, key));
Assert.assertEquals("value2", cache2.get(fqn, key));
@@ -79,8 +81,8 @@
cache1.put(fqn, key, "value");
- DataVersion v1 = ((NodeSPI) cache1.get(fqn)).getVersion();
- DataVersion v2 = ((NodeSPI) cache2.get(fqn)).getVersion();
+ DataVersion v1 = ((NodeSPI) cache1.getNode(fqn)).getVersion();
+ DataVersion v2 = ((NodeSPI) cache2.getNode(fqn)).getVersion();
Assert.assertEquals("value", cache1.get(fqn, key));
Assert.assertEquals("value", cache2.get(fqn, key));
@@ -113,8 +115,8 @@
}
// data versions should be in sync.
- v1 = ((NodeSPI) cache1.get(fqn)).getVersion();
- v2 = ((NodeSPI) cache2.get(fqn)).getVersion();
+ v1 = ((NodeSPI) cache1.getNode(fqn)).getVersion();
+ v2 = ((NodeSPI) cache2.getNode(fqn)).getVersion();
Assert.assertEquals("Version info should have propagated", v1, v2);
}
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithCacheLoaderTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -5,17 +5,16 @@
* See terms of license at gnu.org.
*/
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-import javax.transaction.Transaction;
-
import junit.framework.Assert;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.transaction.DummyTransactionManager;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
+import javax.transaction.Transaction;
+
/**
* Tests optimistic locking with cache loaders
*
@@ -26,7 +25,7 @@
public void testLoaderIndependently() throws Exception
{
- CacheImpl cache = createCacheWithLoader();
+ CacheSPI cache = createCacheWithLoader();
CacheLoader loader = cache.getCacheLoaderManager().getCacheLoader();
// test the cache loader independently first ...
@@ -44,14 +43,14 @@
CacheLoader loader = null;
try
{
- CacheImpl<Object, Object> cache = createCacheWithLoader();
+ CacheSPI<Object, Object> cache = createCacheWithLoader();
loader = cache.getCacheLoaderManager().getCacheLoader();
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
Transaction tx;
// make sure the fqn is not in cache
- assertNull(cache.get(fqn));
+ assertNull(cache.getNode(fqn));
// put something in the loader and make sure all tx's can see it
loader.put(fqn, key, value);
@@ -81,7 +80,7 @@
public void testCacheStoring() throws Exception
{
Transaction tx;
- CacheImpl<Object, Object> cache = createCacheWithLoader();
+ CacheSPI<Object, Object> cache = createCacheWithLoader();
CacheLoader loader = cache.getCacheLoaderManager().getCacheLoader();
// test the cache ...
@@ -98,7 +97,7 @@
mgr.begin();
- cache.remove(fqn);
+ cache.removeNode(fqn);
mgr.commit();
Assert.assertNull(cache.get(fqn, key));
@@ -127,7 +126,7 @@
public void testCacheLoading() throws Exception
{
- CacheImpl<Object, Object> cache = createCacheWithLoader();
+ CacheSPI<Object, Object> cache = createCacheWithLoader();
CacheLoader loader = cache.getCacheLoaderManager().getCacheLoader();
Assert.assertNull(cache.get(fqn, key));
@@ -148,11 +147,11 @@
public void testCacheLoadingWithReplication() throws Exception
{
- CacheImpl<Object, Object> cache1 = createReplicatedCacheWithLoader(false);
- CacheLoader loader1 = cache1.getCacheLoader();
+ CacheSPI<Object, Object> cache1 = createReplicatedCacheWithLoader(false);
+ CacheLoader loader1 = cache1.getCacheLoaderManager().getCacheLoader();
- CacheImpl<Object, Object> cache2 = createReplicatedCacheWithLoader(false);
- CacheLoader loader2 = cache2.getCacheLoader();
+ CacheSPI<Object, Object> cache2 = createReplicatedCacheWithLoader(false);
+ CacheLoader loader2 = cache2.getCacheLoaderManager().getCacheLoader();
// test the cache ...
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -180,7 +179,7 @@
// cache2 removes entry
mgr.begin();
- cache2.remove(fqn);
+ cache2.removeNode(fqn);
Assert.assertNull(cache2.get(fqn, key));
// test that loader1, loader2 and cache2 have the entry
Assert.assertEquals(value, cache1.get(fqn, key));
@@ -191,20 +190,20 @@
mgr.commit();
// test that the entry has been removed everywhere.
- Assert.assertNull(cache1.get(fqn));
+ Assert.assertNull(cache1.getNode(fqn));
Assert.assertNull(loader1.get(fqn));
Assert.assertNull(loader2.get(fqn));
- Assert.assertNull(cache2.get(fqn));
+ Assert.assertNull(cache2.getNode(fqn));
}
public void testSharedCacheLoadingWithReplication() throws Exception
{
- CacheImpl<Object, Object> cache1 = createReplicatedCacheWithLoader(true);
- CacheLoader loader1 = cache1.getCacheLoader();
+ CacheSPI<Object, Object> cache1 = createReplicatedCacheWithLoader(true);
+ CacheLoader loader1 = cache1.getCacheLoaderManager().getCacheLoader();
- CacheImpl<Object, Object> cache2 = createReplicatedCacheWithLoader(true);
- CacheLoader loader2 = cache2.getCacheLoader();
+ CacheSPI<Object, Object> cache2 = createReplicatedCacheWithLoader(true);
+ CacheLoader loader2 = cache2.getCacheLoaderManager().getCacheLoader();
// test the cache ...
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -233,7 +232,7 @@
// cache2 removes entry
mgr.begin();
- cache2.remove(fqn);
+ cache2.removeNode(fqn);
Assert.assertNull(cache2.get(fqn, key));
// test that loader1, loader2 and cache2 have the entry
Assert.assertEquals(value, cache1.get(fqn, key));
@@ -244,10 +243,10 @@
mgr.commit();
// test that the entry has been removed everywhere.
- Assert.assertNull(cache1.get(fqn));
+ Assert.assertNull(cache1.getNode(fqn));
Assert.assertNull(loader1.get(fqn));
Assert.assertNull(loader2.get(fqn));
- Assert.assertNull(cache2.get(fqn));
+ Assert.assertNull(cache2.getNode(fqn));
}
}
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/OptimisticWithPassivationTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -5,9 +5,9 @@
* See terms of license at gnu.org.
*/
package org.jboss.cache.optimistic;
+
import junit.framework.Assert;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.loader.CacheLoader;
@@ -25,25 +25,25 @@
protected CacheLoaderConfig getCacheLoaderConfig() throws Exception
{
String xml = " <config>\n" +
- " \n" +
- " <passivation>true</passivation>\n" +
- " <preload></preload>\n" +
- "\n" +
- " <cacheloader>\n" +
- " <class>org.jboss.cache.loader.DummyInMemoryCacheLoader</class>\n" +
- " <async>false</async>\n" +
- " <fetchPersistentState>false</fetchPersistentState>\n" +
- " <ignoreModifications>false</ignoreModifications>\n" +
- " </cacheloader>\n" +
- " \n" +
- " </config>";
+ " \n" +
+ " <passivation>true</passivation>\n" +
+ " <preload></preload>\n" +
+ "\n" +
+ " <cacheloader>\n" +
+ " <class>org.jboss.cache.loader.DummyInMemoryCacheLoader</class>\n" +
+ " <async>false</async>\n" +
+ " <fetchPersistentState>false</fetchPersistentState>\n" +
+ " <ignoreModifications>false</ignoreModifications>\n" +
+ " </cacheloader>\n" +
+ " \n" +
+ " </config>";
Element element = XmlHelper.stringToElement(xml);
return XmlConfigurationParser.parseCacheLoaderConfig(element);
}
- private CacheImpl<Object, Object> createLocalCache() throws Exception
+ private CacheSPI createLocalCache() throws Exception
{
- CacheImpl<Object, Object> cache = createCacheUnstarted(false);
+ CacheSPI cache = createCacheUnstarted(false);
cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig());
cache.create();
@@ -53,11 +53,11 @@
public void testPassivationLocal() throws Exception
{
- CacheImpl<Object, Object> cache = createLocalCache();
- CacheLoader loader = cache.getCacheLoader();
+ CacheSPI cache = createLocalCache();
+ CacheLoader loader = cache.getCacheLoaderManager().getCacheLoader();
// clean up
- cache.remove(fqn);
+ cache.removeNode(fqn);
loader.remove(fqn);
Assert.assertNull(loader.get(fqn));
@@ -93,7 +93,7 @@
// clean up
mgr.begin();
- cache.remove(fqn);
+ cache.removeNode(fqn);
loader.remove(fqn);
mgr.commit();
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/RemoveBeforeCreateTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/RemoveBeforeCreateTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/RemoveBeforeCreateTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,28 +1,29 @@
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-import javax.transaction.TransactionManager;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import javax.transaction.TransactionManager;
+
/**
* Tests removal of a node before the node is even created.
*/
public class RemoveBeforeCreateTest extends AbstractOptimisticTestCase
{
- CacheImpl[] c = null;
+ CacheSPI<Object, Object>[] c = null;
TransactionManager t;
- @BeforeMethod(alwaysRun = true) public void setUp() throws Exception
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws Exception
{
- c = new CacheImpl[2];
+ c = new CacheSPI[2];
c[0] = createReplicatedCache(Configuration.CacheMode.REPL_ASYNC);
c[1] = createReplicatedCache(Configuration.CacheMode.REPL_ASYNC);
@@ -31,7 +32,8 @@
t = c[0].getTransactionManager();
}
- @AfterMethod(alwaysRun = true) public void tearDown()
+ @AfterMethod(alwaysRun = true)
+ public void tearDown()
{
if (c != null)
{
@@ -52,10 +54,10 @@
assertEquals("value", c[0].get("/control", "key"));
assertEquals("value", c[1].get("/control", "key"));
- DefaultDataVersion v1 = (DefaultDataVersion) ((NodeSPI) c[0].get("/control")).getVersion();
+ DefaultDataVersion v1 = (DefaultDataVersion) ((NodeSPI) c[0].getNode("/control")).getVersion();
assertEquals(1, v1.getRawVersion());
- DefaultDataVersion v2 = (DefaultDataVersion) ((NodeSPI) c[1].get("/control")).getVersion();
+ DefaultDataVersion v2 = (DefaultDataVersion) ((NodeSPI) c[1].getNode("/control")).getVersion();
assertEquals(1, v2.getRawVersion());
@@ -65,18 +67,18 @@
public void testRemoveBeforePut() throws Exception
{
Fqn f = Fqn.fromString("/test");
- assertNull(c[0].get(f));
- assertNull(c[1].get(f));
+ assertNull(c[0].getNode(f));
+ assertNull(c[1].getNode(f));
t.begin();
- c[0].remove(f);
+ c[0].removeNode(f);
// should NOT barf!!!
t.commit();
TestingUtil.sleepThread(200);
- assertNull(c[0].get(f));
- assertNull(c[1].get(f));
+ assertNull(c[0].getNode(f));
+ assertNull(c[1].getNode(f));
}
}
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedCacheAccessTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,16 +6,15 @@
*/
package org.jboss.cache.optimistic;
-import javax.transaction.TransactionManager;
-
import junit.framework.Assert;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.testng.annotations.AfterMethod;
+import javax.transaction.TransactionManager;
+
/**
* Tests multiple thread access on opt locked cache
*
@@ -36,7 +35,7 @@
private final Fqn fqn = Fqn.fromString("/a/b");
private final String key = "key", value = "value";
- private CacheImpl<Object, Object> cache;
+ private CacheSPI cache;
private WorkerThread[] threads;
@AfterMethod(alwaysRun = true)
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/ThreadedOptimisticCreateIfNotExistsInterceptorTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -5,13 +5,8 @@
*
*/
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor;
@@ -19,19 +14,24 @@
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
/**
* @author xenephon
*/
public class ThreadedOptimisticCreateIfNotExistsInterceptorTest extends AbstractOptimisticTestCase
{
- protected synchronized void setTransactionsInInvocationCtx(TransactionManager mgr, CacheImpl cache) throws Exception
+ protected synchronized void setTransactionsInInvocationCtx(TransactionManager mgr, CacheSPI cache) throws Exception
{
cache.getInvocationContext().setTransaction(mgr.getTransaction());
cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction());
}
- protected void resetInvocationCtx(CacheImpl cache)
+ protected void resetInvocationCtx(CacheSPI cache)
{
cache.getInvocationContext().setTransaction(null);
cache.getInvocationContext().setGlobalTransaction(null);
@@ -44,15 +44,13 @@
final int minSleep = 0;
final int maxSleep = 1000;
TestListener listener = new TestListener();
- final CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
// should just be the root node
assertEquals(0, cache.getNumberOfNodes());
@@ -110,15 +108,13 @@
final int minSleep = 0;
final int maxSleep = 500;
TestListener listener = new TestListener();
- final CacheImpl<Object, Object> cache = createCacheWithListener(listener);
+ final CacheSPI<Object, Object> cache = createCacheWithListener(listener);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
interceptor.setNext(dummy);
- cache.setInterceptorChain(interceptor);
+ TestingUtil.replaceInterceptorChain(cache, interceptor);
final DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
Modified: core/trunk/src/test/java/org/jboss/cache/optimistic/TxInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/optimistic/TxInterceptorTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/TxInterceptorTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -5,48 +5,40 @@
*
*/
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNotSame;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-import java.util.List;
-
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.loader.SamplePojo;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodCallFactory;
import org.jboss.cache.marshall.MethodDeclarations;
+import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionSetup;
import org.jboss.cache.transaction.TransactionTable;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.Test;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.List;
+
@Test(groups = {"functional", "transaction"})
public class TxInterceptorTest extends AbstractOptimisticTestCase
{
@Override
- protected CacheImpl<Object, Object> createCacheUnstarted(boolean optimistic) throws Exception
+ protected CacheSPI<Object, Object> createCacheUnstarted(boolean optimistic) throws Exception
{
- CacheImpl<Object, Object> cache = super.createCacheUnstarted(optimistic);
+ CacheSPI<Object, Object> cache = super.createCacheUnstarted(optimistic);
cache.getConfiguration().setTransactionManagerLookupClass(TransactionSetup.getManagerLookup());
return cache;
}
public void testNoTransaction() throws Exception
{
-
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
-
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, false));
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, false));
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
assertNull(mgr.getTransaction());
assertEquals(0, cache.getTransactionTable().getNumGlobalTransactions());
@@ -72,11 +64,10 @@
public void testLocalTransactionExists() throws Exception
{
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, false));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, false));
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
@@ -110,11 +101,10 @@
public void testRollbackTransaction() throws Exception
{
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, false));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, false));
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
//start local transaction
@@ -142,11 +132,10 @@
public void testEmptyLocalTransaction() throws Exception
{
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, false));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, false));
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
//start local transaction
@@ -171,12 +160,10 @@
public void testEmptyRollbackLocalTransaction() throws Exception
{
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, false));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, false));
-
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
//start local transaction
@@ -201,12 +188,10 @@
public void testLocalRollbackAftercommitTransaction() throws Exception
{
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, false));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, false));
-
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
//start local transaction
@@ -246,11 +231,10 @@
public void testgtxTransactionExists() throws Exception
{
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, false));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, false));
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
//start local transaction
@@ -258,7 +242,7 @@
Transaction tx = mgr.getTransaction();
//this sets
- cache.getCurrentTransaction(tx);
+ cache.getCurrentTransaction(tx, true);
SamplePojo pojo = new SamplePojo(21, "test");
@@ -284,11 +268,10 @@
public void testRemotePrepareTransaction() throws Exception
{
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, false));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, false));
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
//start local transaction
@@ -300,7 +283,7 @@
cache.put("/one/two", "key1", pojo);
- GlobalTransaction gtx = cache.getCurrentTransaction(tx);
+ GlobalTransaction gtx = cache.getCurrentTransaction(tx, true);
TransactionTable table = cache.getTransactionTable();
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
assertNotNull(mgr.getTransaction());
@@ -327,7 +310,7 @@
MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), Boolean.FALSE);
try
{
- cache._replicate(prepareMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
}
catch (Throwable t)
{
@@ -354,11 +337,10 @@
public void testRemotePrepareSuspendTransaction() throws Exception
{
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, false));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, false));
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
//start local transaction
@@ -370,7 +352,7 @@
cache.put("/one/two", "key1", pojo);
- GlobalTransaction gtx = cache.getCurrentTransaction(tx);
+ GlobalTransaction gtx = cache.getCurrentTransaction(tx, true);
TransactionTable table = cache.getTransactionTable();
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
assertEquals(tx, mgr.getTransaction());
@@ -388,7 +370,7 @@
MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), Boolean.FALSE);
try
{
- cache._replicate(prepareMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
}
catch (Throwable t)
{
@@ -437,12 +419,10 @@
public void testRemoteCommitSuspendTransaction() throws Exception
{
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, true));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
-
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
//start local transaction
@@ -450,13 +430,13 @@
Transaction tx = mgr.getTransaction();
//this sets
- cache.getCurrentTransaction(tx);
+ cache.getCurrentTransaction(tx, true);
SamplePojo pojo = new SamplePojo(21, "test");
cache.put("/one/two", "key1", pojo);
- GlobalTransaction gtx = cache.getCurrentTransaction(tx);
+ GlobalTransaction gtx = cache.getCurrentTransaction(tx, true);
TransactionTable table = cache.getTransactionTable();
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
assertEquals(tx, mgr.getTransaction());
@@ -474,7 +454,7 @@
MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), Boolean.FALSE);
try
{
- cache._replicate(prepareMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
}
catch (Throwable t)
{
@@ -488,7 +468,7 @@
MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, remoteGtx);
try
{
- cache._replicate(commitMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(commitMethod);
}
catch (Throwable t)
{
@@ -528,11 +508,10 @@
public void testRemoteRollbackSuspendTransaction() throws Exception
{
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, true));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
//start local transaction
@@ -540,13 +519,13 @@
Transaction tx = mgr.getTransaction();
//this sets
- cache.getCurrentTransaction(tx);
+ cache.getCurrentTransaction(tx, true);
SamplePojo pojo = new SamplePojo(21, "test");
cache.put("/one/two", "key1", pojo);
- GlobalTransaction gtx = cache.getCurrentTransaction(tx);
+ GlobalTransaction gtx = cache.getCurrentTransaction(tx, true);
TransactionTable table = cache.getTransactionTable();
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
assertEquals(tx, mgr.getTransaction());
@@ -564,7 +543,7 @@
MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), Boolean.FALSE);
try
{
- cache._replicate(prepareMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
}
catch (Throwable t)
{
@@ -578,7 +557,7 @@
MethodCall rollbackMethod = MethodCallFactory.create(MethodDeclarations.rollbackMethod, remoteGtx);
try
{
- cache._replicate(rollbackMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(rollbackMethod);
}
catch (Throwable t)
{
@@ -617,11 +596,10 @@
public void testRemoteCommitTransaction() throws Exception
{
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, true));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
//start local transaction
@@ -629,13 +607,13 @@
Transaction tx = mgr.getTransaction();
//this sets
- cache.getCurrentTransaction(tx);
+ cache.getCurrentTransaction(tx, true);
SamplePojo pojo = new SamplePojo(21, "test");
cache.put("/one/two", "key1", pojo);
- GlobalTransaction gtx = cache.getCurrentTransaction(tx);
+ GlobalTransaction gtx = cache.getCurrentTransaction(tx, true);
TransactionTable table = cache.getTransactionTable();
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
assertNotNull(mgr.getTransaction());
@@ -664,7 +642,7 @@
MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), Boolean.FALSE);
try
{
- cache._replicate(prepareMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
}
catch (Throwable t)
{
@@ -690,7 +668,7 @@
MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, remoteGtx, Boolean.TRUE);
try
{
- cache._replicate(commitMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(commitMethod);
}
catch (Throwable t)
{
@@ -710,11 +688,10 @@
public void testRemoteRollbackTransaction() throws Exception
{
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, true));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, true));
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
//start local transaction
@@ -722,13 +699,13 @@
Transaction tx = mgr.getTransaction();
//this sets
- cache.getCurrentTransaction(tx);
+ cache.getCurrentTransaction(tx, true);
SamplePojo pojo = new SamplePojo(21, "test");
cache.put("/one/two", "key1", pojo);
- GlobalTransaction gtx = cache.getCurrentTransaction(tx);
+ GlobalTransaction gtx = cache.getCurrentTransaction(tx, true);
TransactionTable table = cache.getTransactionTable();
OptimisticTransactionEntry entry = (OptimisticTransactionEntry) table.get(gtx);
assertNotNull(mgr.getTransaction());
@@ -751,7 +728,7 @@
MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, remoteGtx, injectDataVersion(entry.getModifications()), null, remoteGtx.getAddress(), Boolean.FALSE);
try
{
- cache._replicate(prepareMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
}
catch (Throwable t)
{
@@ -774,7 +751,7 @@
MethodCall rollbackMethod = MethodCallFactory.create(MethodDeclarations.rollbackMethod, remoteGtx);
try
{
- cache._replicate(rollbackMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(rollbackMethod);
}
catch (Throwable t)
{
@@ -798,11 +775,10 @@
public void testSequentialTransactionExists() throws Exception
{
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
+ TestingUtil.replaceInterceptorChain(cache, getAlteredInterceptorChain(dummy, cache, false));
- cache.setInterceptorChain(getAlteredInterceptorChain(dummy, cache, false));
TransactionManager mgr = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/ValidationFailureTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -5,14 +5,14 @@
* See terms of license at gnu.org.
*/
package org.jboss.cache.optimistic;
+
+import org.jboss.cache.CacheSPI;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
-import org.jboss.cache.CacheImpl;
-
/**
* Tests a failure in validating a concurrently updated node
*
@@ -22,7 +22,7 @@
{
public void testValidationFailureLockRelease() throws Exception
{
- CacheImpl<Object, Object> cache = createCache();
+ CacheSPI<Object, Object> cache = createCache();
TransactionManager mgr = cache.getTransactionManager();
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/ValidatorInterceptorTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -5,18 +5,8 @@
*
*/
package org.jboss.cache.optimistic;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.transaction.Transaction;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.interceptors.Interceptor;
@@ -27,11 +17,17 @@
import org.jboss.cache.marshall.MethodCall;
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 static org.testng.AssertJUnit.*;
+import javax.transaction.Transaction;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* @author xenephon
*/
@@ -39,21 +35,17 @@
{
public void testTransactionvalidateMethod() throws Exception
{
- CacheImpl<Object, Object> cache = createCacheWithListener();
+ CacheSPI<Object, Object> cache = createCacheWithListener();
Interceptor validateInterceptor = new OptimisticValidatorInterceptor();
- validateInterceptor.setCache(cache);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
validateInterceptor.setNext(interceptor);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(validateInterceptor);
+ TestingUtil.replaceInterceptorChain(cache, validateInterceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -62,10 +54,10 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
- Map<String, SamplePojo> temp = new HashMap<String, SamplePojo>();
+ Map<Object, Object> temp = new HashMap<Object, Object>();
temp.put("key1", pojo);
cache.put("/one/two", temp);
@@ -93,14 +85,14 @@
assertEquals(null, dummy.getCalled());
//now let us do a prepare
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE});
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE);
try
{
- cache._replicate(prepareMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
}
catch (Throwable t)
{
-
+ // do nothing
}
@@ -122,21 +114,17 @@
public void testTransactionValidateFailureMethod() throws Exception
{
- CacheImpl<Object, Object> cache = createCacheWithListener();
+ CacheSPI<Object, Object> cache = createCacheWithListener();
Interceptor validateInterceptor = new OptimisticValidatorInterceptor();
- validateInterceptor.setCache(cache);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
validateInterceptor.setNext(interceptor);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(validateInterceptor);
+ TestingUtil.replaceInterceptorChain(cache, validateInterceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -145,10 +133,10 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
- Map<String, SamplePojo> temp = new HashMap<String, SamplePojo>();
+ Map<Object, Object> temp = new HashMap<Object, Object>();
temp.put("key1", pojo);
cache.put("/one/two", temp);
@@ -181,7 +169,7 @@
MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE);
try
{
- cache._replicate(prepareMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
fail();
}
catch (Throwable t)
@@ -198,21 +186,17 @@
public void testTransactionValidateCommitMethod() throws Exception
{
- CacheImpl<Object, Object> cache = createCacheWithListener();
+ CacheSPI<Object, Object> cache = createCacheWithListener();
Interceptor validateInterceptor = new OptimisticValidatorInterceptor();
- validateInterceptor.setCache(cache);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
validateInterceptor.setNext(interceptor);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(validateInterceptor);
+ TestingUtil.replaceInterceptorChain(cache, validateInterceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -221,10 +205,10 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
- Map<String, SamplePojo> temp = new HashMap<String, SamplePojo>();
+ Map<Object, Object> temp = new HashMap<Object, Object>();
temp.put("key1", pojo);
cache.put("/one/two", temp);
@@ -253,10 +237,10 @@
//lets change one of the underlying version numbers
//now let us do a prepare
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE});
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE);
try
{
- cache._replicate(prepareMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
fail();
}
catch (Throwable t)
@@ -264,10 +248,10 @@
assertTrue(true);
}
- MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, new Object[]{gtx});
+ MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, gtx);
try
{
- cache._replicate(commitMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(commitMethod);
}
catch (Throwable t)
{
@@ -309,21 +293,17 @@
public void testTransactionValidateFailRemoteCommitMethod() throws Exception
{
- CacheImpl<Object, Object> cache = createCacheWithListener();
+ CacheSPI<Object, Object> cache = createCacheWithListener();
Interceptor validateInterceptor = new OptimisticValidatorInterceptor();
- validateInterceptor.setCache(cache);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
validateInterceptor.setNext(interceptor);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(validateInterceptor);
+ TestingUtil.replaceInterceptorChain(cache, validateInterceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -332,10 +312,10 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
- Map<String, SamplePojo> temp = new HashMap<String, SamplePojo>();
+ Map<Object, Object> temp = new HashMap<Object, Object>();
temp.put("key1", pojo);
cache.put("/one/two", temp);
@@ -359,10 +339,10 @@
//lets change one of the underlying version numbers
//now let us do a prepare
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE});
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE);
try
{
- cache._replicate(prepareMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
fail();
}
catch (Throwable t)
@@ -371,10 +351,10 @@
}
- MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, new Object[]{gtx});
+ MethodCall commitMethod = MethodCallFactory.create(MethodDeclarations.commitMethod, gtx);
try
{
- cache._replicate(commitMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(commitMethod);
}
catch (Throwable t)
{
@@ -415,20 +395,17 @@
public void testTransactionValidateRollbackMethod() throws Exception
{
- CacheImpl<Object, Object> cache = createCacheWithListener();
+ CacheSPI<Object, Object> cache = createCacheWithListener();
Interceptor validateInterceptor = new OptimisticValidatorInterceptor();
validateInterceptor.setCache(cache);
Interceptor interceptor = new OptimisticCreateIfNotExistsInterceptor();
- interceptor.setCache(cache);
Interceptor nodeInterceptor = new OptimisticNodeInterceptor();
- nodeInterceptor.setCache(cache);
MockInterceptor dummy = new MockInterceptor();
- dummy.setCache(cache);
validateInterceptor.setNext(interceptor);
interceptor.setNext(nodeInterceptor);
nodeInterceptor.setNext(dummy);
- cache.setInterceptorChain(validateInterceptor);
+ TestingUtil.replaceInterceptorChain(cache, validateInterceptor);
// first set up a node with a pojo
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -437,10 +414,10 @@
// inject InvocationContext
cache.getInvocationContext().setTransaction(tx);
- cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx));
+ cache.getInvocationContext().setGlobalTransaction(cache.getCurrentTransaction(tx, true));
SamplePojo pojo = new SamplePojo(21, "test");
- Map<String, SamplePojo> temp = new HashMap<String, SamplePojo>();
+ Map<Object, Object> temp = new HashMap<Object, Object>();
temp.put("key1", pojo);
cache.put("/one/two", temp);
@@ -469,10 +446,10 @@
//lets change one of the underlying version numbers
//now let us do a prepare
- MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, new Object[]{gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE});
+ MethodCall prepareMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod, gtx, entry.getModifications(), gtx.getAddress(), Boolean.FALSE);
try
{
- cache._replicate(prepareMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(prepareMethod);
fail();
}
catch (Throwable t)
@@ -480,10 +457,10 @@
assertTrue(true);
}
- MethodCall rollbackMethod = MethodCallFactory.create(MethodDeclarations.rollbackMethod, new Object[]{gtx});
+ MethodCall rollbackMethod = MethodCallFactory.create(MethodDeclarations.rollbackMethod, gtx);
try
{
- cache._replicate(rollbackMethod);
+ TestingUtil.getRemoteDelegate(cache)._replicate(rollbackMethod);
}
catch (Throwable t)
{
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-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/optimistic/VersioningOnReadTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,31 +1,33 @@
package org.jboss.cache.optimistic;
+
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.fail;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
-import org.jboss.cache.CacheImpl;
-import org.jboss.cache.Fqn;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-
/**
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
*/
public class VersioningOnReadTest extends AbstractOptimisticTestCase
{
- CacheImpl<Object, Object> cache;
+ CacheSPI cache;
Fqn fqn = Fqn.fromString("/a");
TransactionManager tm;
- @BeforeMethod(alwaysRun = true) public void setUp() throws Exception
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws Exception
{
cache = createCache();
tm = cache.getTransactionManager();
}
- @AfterMethod(alwaysRun = true) public void tearDown()
+ @AfterMethod(alwaysRun = true)
+ public void tearDown()
{
super.tearDown();
destroyCache(cache);
@@ -99,7 +101,7 @@
// now start a tx to mod the node
tm.begin();
- cache.remove(fqn);
+ cache.removeNode(fqn);
// suspend the tx
Transaction tx = tm.suspend();
Modified: core/trunk/src/test/java/org/jboss/cache/options/CacheModeLocalSimpleTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/CacheModeLocalSimpleTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/options/CacheModeLocalSimpleTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,41 +6,38 @@
*/
package org.jboss.cache.options;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-
-import javax.transaction.TransactionManager;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Option;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.TransactionManager;
+
/**
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
@Test(groups = {"functional"})
public class CacheModeLocalSimpleTest
{
- private CacheImpl<Object, Object> cache1, cache2;
+ private CacheSPI<Object, Object> cache1, cache2;
private Option cacheModeLocal;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- cache1 = (CacheImpl<Object, Object>)DefaultCacheFactory.getInstance().createCache(false);
- Configuration c = new Configuration();
- cache1.setConfiguration(c);
+ cache1 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ Configuration c = cache1.getConfiguration();
c.setCacheMode("REPL_SYNC");
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- cache2 = (CacheImpl<Object, Object>)DefaultCacheFactory.getInstance().createCache(false);
- c = new Configuration();
- cache2.setConfiguration(c);
+ cache2 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ c = cache2.getConfiguration();
c.setCacheMode("REPL_SYNC");
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
Modified: core/trunk/src/test/java/org/jboss/cache/options/ExplicitVersionsReplTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/ExplicitVersionsReplTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/options/ExplicitVersionsReplTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,14 +1,7 @@
package org.jboss.cache.options;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.fail;
-
-import javax.transaction.RollbackException;
-import javax.transaction.TransactionManager;
-
import junit.framework.Assert;
-
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
@@ -16,20 +9,25 @@
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.optimistic.DefaultDataVersion;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.fail;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.RollbackException;
+import javax.transaction.TransactionManager;
+
/**
* Tests the passing in of explicit {@see DataVersion} instances when using optimistic locking + replication.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
-@Test(groups = { "functional" })
+@Test(groups = {"functional"})
@SuppressWarnings("unchecked")
public class ExplicitVersionsReplTest
{
- private CacheImpl cache[];
+ private CacheSPI cache[];
private Fqn fqn = Fqn.fromString("/a");
private String key = "key";
@@ -38,16 +36,15 @@
{
if (cache != null)
tearDown();
- cache = new CacheImpl[2];
+ cache = new CacheSPI[2];
cache[0] = createCache();
cache[1] = createCache();
TestingUtil.blockUntilViewsReceived(cache, 20000);
}
- private CacheImpl createCache() throws Exception
+ private CacheSPI createCache()
{
- CacheImpl cache = (CacheImpl)DefaultCacheFactory.getInstance().createCache(false);
- Configuration c = cache.getConfiguration();
+ Configuration c = new Configuration();
c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
c.setNodeLockingScheme("OPTIMISTIC");
// give us lots of time to trace and debug shit
@@ -57,9 +54,8 @@
c.setLockAcquisitionTimeout(1000);
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- cache.setConfiguration(c);
- cache.start();
- return cache;
+
+ return (CacheSPI) DefaultCacheFactory.getInstance().createCache(c);
}
@AfterMethod(alwaysRun = true)
@@ -67,13 +63,13 @@
{
if (cache != null)
{
- for (CacheImpl aCache : cache)
+ for (CacheSPI aCache : cache)
destroyCache(aCache);
cache = null;
}
}
- private void destroyCache(CacheImpl c)
+ private void destroyCache(CacheSPI c)
{
TransactionManager tm = c.getTransactionManager();
try
@@ -112,9 +108,6 @@
{
mgr.commit();
- System.out.println(cache[0].printDetails());
- System.out.println(cache[1].printDetails());
-
Assert.assertTrue("expected to fail", false);
}
catch (RollbackException e)
@@ -258,22 +251,22 @@
public void testPropagationOfDefaultVersions() throws Exception
{
DefaultDataVersion expected = new DefaultDataVersion();
- expected = (DefaultDataVersion)expected.increment();
+ expected = (DefaultDataVersion) expected.increment();
cache[0].put(fqn, key, "value");
assertEquals("value", cache[0].get(fqn, key));
assertEquals("value", cache[1].get(fqn, key));
- assertEquals(expected, ((NodeSPI)cache[0].get(fqn)).getVersion());
- assertEquals(expected, ((NodeSPI)cache[1].get(fqn)).getVersion());
+ assertEquals(expected, ((NodeSPI) cache[0].getNode(fqn)).getVersion());
+ assertEquals(expected, ((NodeSPI) cache[1].getNode(fqn)).getVersion());
cache[1].put(fqn, key, "value2");
- expected = (DefaultDataVersion)expected.increment();
+ expected = (DefaultDataVersion) expected.increment();
assertEquals("value2", cache[0].get(fqn, key));
assertEquals("value2", cache[1].get(fqn, key));
- assertEquals(expected, ((NodeSPI)cache[0].get(fqn)).getVersion());
- assertEquals(expected, ((NodeSPI)cache[1].get(fqn)).getVersion());
+ assertEquals(expected, ((NodeSPI) cache[0].getNode(fqn)).getVersion());
+ assertEquals(expected, ((NodeSPI) cache[1].getNode(fqn)).getVersion());
}
public void testPropagationOfCustomVersions() throws Exception
@@ -284,8 +277,8 @@
assertEquals("value", cache[0].get(fqn, key));
assertEquals("value", cache[1].get(fqn, key));
- assertEquals(expected, ((NodeSPI)cache[0].get(fqn)).getVersion());
- assertEquals(expected, ((NodeSPI)cache[1].get(fqn)).getVersion());
+ assertEquals(expected, ((NodeSPI) cache[0].getNode(fqn)).getVersion());
+ assertEquals(expected, ((NodeSPI) cache[1].getNode(fqn)).getVersion());
expected = new TestVersion("200");
cache[1].getInvocationContext().getOptionOverrides().setDataVersion(expected);
@@ -293,8 +286,8 @@
assertEquals("value2", cache[0].get(fqn, key));
assertEquals("value2", cache[1].get(fqn, key));
- assertEquals(expected, ((NodeSPI)cache[0].get(fqn)).getVersion());
- assertEquals(expected, ((NodeSPI)cache[1].get(fqn)).getVersion());
+ assertEquals(expected, ((NodeSPI) cache[0].getNode(fqn)).getVersion());
+ assertEquals(expected, ((NodeSPI) cache[1].getNode(fqn)).getVersion());
}
public void testExplicitVersionOnRoot() throws Exception
@@ -319,18 +312,18 @@
public void testExplicitVersionOnLeaf() throws Exception
{
cache[0].put("/org/domain/Entity", null);
- assertEquals(1, ((DefaultDataVersion)((NodeSPI)cache[0].get("/org/domain/Entity")).getVersion()).getRawVersion());
- assertEquals(1, ((DefaultDataVersion)((NodeSPI)cache[1].get("/org/domain/Entity")).getVersion()).getRawVersion());
+ assertEquals(1, ((DefaultDataVersion) ((NodeSPI) cache[0].getNode("/org/domain/Entity")).getVersion()).getRawVersion());
+ assertEquals(1, ((DefaultDataVersion) ((NodeSPI) cache[1].getNode("/org/domain/Entity")).getVersion()).getRawVersion());
TestVersion v = new TestVersion("Arse");
cache[0].getInvocationContext().getOptionOverrides().setDataVersion(v);
cache[0].put(Fqn.fromString("/org/domain/Entity/EntityInstance#1"), "k", "v");
- assertEquals(1, ((DefaultDataVersion)((NodeSPI)cache[0].get("/org/domain/Entity")).getVersion()).getRawVersion());
- assertEquals(v, ((NodeSPI)cache[0].get("/org/domain/Entity/EntityInstance#1")).getVersion());
- assertEquals(1, ((DefaultDataVersion)((NodeSPI)cache[1].get("/org/domain/Entity")).getVersion()).getRawVersion());
- assertEquals(v, ((NodeSPI)cache[1].get("/org/domain/Entity/EntityInstance#1")).getVersion());
+ assertEquals(1, ((DefaultDataVersion) ((NodeSPI) cache[0].getNode("/org/domain/Entity")).getVersion()).getRawVersion());
+ assertEquals(v, ((NodeSPI) cache[0].getNode("/org/domain/Entity/EntityInstance#1")).getVersion());
+ assertEquals(1, ((DefaultDataVersion) ((NodeSPI) cache[1].getNode("/org/domain/Entity")).getVersion()).getRawVersion());
+ assertEquals(v, ((NodeSPI) cache[1].getNode("/org/domain/Entity/EntityInstance#1")).getVersion());
}
@@ -341,10 +334,10 @@
cache[0].put(Fqn.fromString("/org/domain/Entity/EntityInstance#1"), "k", "v");
- assertEquals(0, ((DefaultDataVersion)((NodeSPI)cache[0].get("/org/domain/Entity")).getVersion()).getRawVersion());
- assertEquals(v, ((NodeSPI)cache[0].get("/org/domain/Entity/EntityInstance#1")).getVersion());
- assertEquals(0, ((DefaultDataVersion)((NodeSPI)cache[1].get("/org/domain/Entity")).getVersion()).getRawVersion());
- assertEquals(v, ((NodeSPI)cache[1].get("/org/domain/Entity/EntityInstance#1")).getVersion());
+ assertEquals(0, ((DefaultDataVersion) ((NodeSPI) cache[0].getNode("/org/domain/Entity")).getVersion()).getRawVersion());
+ assertEquals(v, ((NodeSPI) cache[0].getNode("/org/domain/Entity/EntityInstance#1")).getVersion());
+ assertEquals(0, ((DefaultDataVersion) ((NodeSPI) cache[1].getNode("/org/domain/Entity")).getVersion()).getRawVersion());
+ assertEquals(v, ((NodeSPI) cache[1].getNode("/org/domain/Entity/EntityInstance#1")).getVersion());
}
@@ -357,10 +350,10 @@
cache[0].put(Fqn.fromString("/parent"), "k", "v");
cache[0].getTransactionManager().commit();
- assertEquals(0, ((DefaultDataVersion)((NodeSPI)cache[0].get("/")).getVersion()).getRawVersion());
- assertEquals(vParent, ((NodeSPI)cache[0].get("/parent")).getVersion());
- assertEquals(0, ((DefaultDataVersion)((NodeSPI)cache[1].get("/")).getVersion()).getRawVersion());
- assertEquals(vParent, ((NodeSPI)cache[1].get("/parent")).getVersion());
+ assertEquals(0, ((DefaultDataVersion) ((NodeSPI) cache[0].getRoot()).getVersion()).getRawVersion());
+ assertEquals(vParent, ((NodeSPI) cache[0].getNode("/parent")).getVersion());
+ assertEquals(0, ((DefaultDataVersion) ((NodeSPI) cache[1].getRoot()).getVersion()).getRawVersion());
+ assertEquals(vParent, ((NodeSPI) cache[1].getNode("/parent")).getVersion());
TestVersion vChild = new TestVersion("Child-Version");
@@ -369,12 +362,12 @@
cache[0].put(Fqn.fromString("/parent/child"), "k", "v");
cache[0].getTransactionManager().commit();
- assertEquals(0, ((DefaultDataVersion)((NodeSPI)cache[0].get("/")).getVersion()).getRawVersion());
- assertEquals(vParent, ((NodeSPI)cache[0].get("/parent")).getVersion());
- assertEquals(vChild, ((NodeSPI)cache[0].get("/parent/child")).getVersion());
- assertEquals(0, ((DefaultDataVersion)((NodeSPI)cache[1].get("/")).getVersion()).getRawVersion());
- assertEquals(vParent, ((NodeSPI)cache[1].get("/parent")).getVersion());
- assertEquals(vChild, ((NodeSPI)cache[1].get("/parent/child")).getVersion());
+ assertEquals(0, ((DefaultDataVersion) ((NodeSPI) cache[0].getRoot()).getVersion()).getRawVersion());
+ assertEquals(vParent, ((NodeSPI) cache[0].getNode("/parent")).getVersion());
+ assertEquals(vChild, ((NodeSPI) cache[0].getNode("/parent/child")).getVersion());
+ assertEquals(0, ((DefaultDataVersion) ((NodeSPI) cache[1].getRoot()).getVersion()).getRawVersion());
+ assertEquals(vParent, ((NodeSPI) cache[1].getNode("/parent")).getVersion());
+ assertEquals(vChild, ((NodeSPI) cache[1].getNode("/parent/child")).getVersion());
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/options/ExplicitVersionsTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/ExplicitVersionsTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/options/ExplicitVersionsTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,15 +6,9 @@
*/
package org.jboss.cache.options;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-
-import javax.transaction.TransactionManager;
-
import junit.framework.Assert;
-
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
@@ -22,19 +16,23 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.optimistic.DefaultDataVersion;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.TransactionManager;
+
/**
* Tests the passing in of explicit {@see DataVersion} instances when using optimistic locking.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
-@Test(groups = { "functional" })
+@Test(groups = {"functional"})
public class ExplicitVersionsTest
{
- private CacheImpl<String, String> cache;
+ private CacheSPI<String, String> cache;
private Fqn fqn = Fqn.fromString("/a");
private String key = "key";
@@ -44,7 +42,7 @@
if (cache != null)
tearDown();
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache = (CacheImpl<String, String>)instance.createCache(false);
+ cache = (CacheSPI<String, String>) instance.createCache(false);
cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
cache.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
@@ -71,11 +69,11 @@
Assert.assertEquals("value", cache.get(fqn, key));
// get a hold of the node
- NodeSPI<String, String> node = (NodeSPI<String, String>)cache.get(fqn);
+ NodeSPI<String, String> node = (NodeSPI<String, String>) cache.getNode(fqn);
DataVersion versionFromCache = node.getVersion();
Assert.assertEquals(TestVersion.class, versionFromCache.getClass());
- Assert.assertEquals("99", ((TestVersion)versionFromCache).getInternalVersion());
+ Assert.assertEquals("99", ((TestVersion) versionFromCache).getInternalVersion());
}
public void testFailingPut() throws Exception
@@ -126,14 +124,14 @@
public void testExplicitVersionOnLeaf() throws Exception
{
cache.put("/org/domain/Entity", null);
- assertEquals(1, ((DefaultDataVersion)((NodeSPI)cache.get("/org/domain/Entity")).getVersion()).getRawVersion());
+ assertEquals(1, ((DefaultDataVersion) ((NodeSPI) cache.getNode("/org/domain/Entity")).getVersion()).getRawVersion());
TestVersion v = new TestVersion("Arse");
cache.getInvocationContext().getOptionOverrides().setDataVersion(v);
cache.put(Fqn.fromString("/org/domain/Entity/EntityInstance#1"), "k", "v");
- assertEquals(1, ((DefaultDataVersion)((NodeSPI)cache.get("/org/domain/Entity")).getVersion()).getRawVersion());
- assertEquals(v, ((NodeSPI)cache.get("/org/domain/Entity/EntityInstance#1")).getVersion());
+ assertEquals(1, ((DefaultDataVersion) ((NodeSPI) cache.getNode("/org/domain/Entity")).getVersion()).getRawVersion());
+ assertEquals(v, ((NodeSPI) cache.getNode("/org/domain/Entity/EntityInstance#1")).getVersion());
}
public void testExplicitVersionOnLeafImplicitParentCreation() throws Exception
@@ -142,8 +140,8 @@
cache.getInvocationContext().getOptionOverrides().setDataVersion(v);
cache.put(Fqn.fromString("/org/domain/Entity/EntityInstance#1"), "k", "v");
- assertEquals(0, ((DefaultDataVersion)((NodeSPI)cache.get("/org/domain/Entity")).getVersion()).getRawVersion());
- assertEquals(v, ((NodeSPI)cache.get("/org/domain/Entity/EntityInstance#1")).getVersion());
+ assertEquals(0, ((DefaultDataVersion) ((NodeSPI) cache.getNode("/org/domain/Entity")).getVersion()).getRawVersion());
+ assertEquals(v, ((NodeSPI) cache.getNode("/org/domain/Entity/EntityInstance#1")).getVersion());
}
public void testExplicitVersionsOnParents()
@@ -154,7 +152,7 @@
cache.getInvocationContext().getOptionOverrides().setDataVersion(lev2V);
root.addChild(Fqn.fromString("LEV2"));
- NodeSPI<String, String> lev2 = (NodeSPI<String, String>)root.getChild(Fqn.fromString("LEV2"));
+ NodeSPI<String, String> lev2 = (NodeSPI<String, String>) root.getChild(Fqn.fromString("LEV2"));
assertNotNull(lev2);
@@ -164,7 +162,7 @@
cache.getInvocationContext().getOptionOverrides().setDataVersion(lev3V);
lev2.addChild(Fqn.fromString("LEV3"));
- NodeSPI<String, String> lev3 = (NodeSPI<String, String>)lev2.getChild(Fqn.fromString("LEV3"));
+ NodeSPI<String, String> lev3 = (NodeSPI<String, String>) lev2.getChild(Fqn.fromString("LEV3"));
assertNotNull(lev3);
@@ -174,7 +172,7 @@
cache.getInvocationContext().getOptionOverrides().setDataVersion(lev4V);
lev3.addChild(Fqn.fromString("LEV4"));
- NodeSPI<String, String> lev4 = (NodeSPI<String, String>)lev3.getChild(Fqn.fromString("LEV4"));
+ NodeSPI<String, String> lev4 = (NodeSPI<String, String>) lev3.getChild(Fqn.fromString("LEV4"));
assertNotNull(lev4);
@@ -190,8 +188,8 @@
cache.put(Fqn.fromString("/parent"), "k", "v");
cache.getTransactionManager().commit();
- assertEquals(0, ((DefaultDataVersion)((NodeSPI)cache.get("/")).getVersion()).getRawVersion());
- assertEquals(vParent, ((NodeSPI)cache.get("/parent")).getVersion());
+ assertEquals(0, ((DefaultDataVersion) ((NodeSPI) cache.getNode("/")).getVersion()).getRawVersion());
+ assertEquals(vParent, ((NodeSPI) cache.getNode("/parent")).getVersion());
TestVersion vChild = new TestVersion("Child-Version");
@@ -200,9 +198,9 @@
cache.put(Fqn.fromString("/parent/child"), "k", "v");
cache.getTransactionManager().commit();
- assertEquals(0, ((DefaultDataVersion)((NodeSPI)cache.get("/")).getVersion()).getRawVersion());
- assertEquals(vParent, ((NodeSPI)cache.get("/parent")).getVersion());
- assertEquals(vChild, ((NodeSPI)cache.get("/parent/child")).getVersion());
+ assertEquals(0, ((DefaultDataVersion) ((NodeSPI) cache.getNode("/")).getVersion()).getRawVersion());
+ assertEquals(vParent, ((NodeSPI) cache.getNode("/parent")).getVersion());
+ assertEquals(vChild, ((NodeSPI) cache.getNode("/parent/child")).getVersion());
}
}
\ No newline at end of file
Modified: core/trunk/src/test/java/org/jboss/cache/options/FailSilentlyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/FailSilentlyTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/options/FailSilentlyTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,23 +6,21 @@
*/
package org.jboss.cache.options;
-import static org.testng.AssertJUnit.assertEquals;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.jboss.cache.CacheFactory;
import org.jboss.cache.CacheImpl;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
+import static org.testng.AssertJUnit.assertEquals;
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;
+
/**
* Tests passing in the failSilently option in various scenarios.
*
@@ -31,7 +29,7 @@
@Test(groups = {"functional"})
public class FailSilentlyTest
{
- private CacheImpl<String, String> cache;
+ private CacheImpl cache;
private TransactionManager manager;
private Transaction tx;
private Fqn<String> fqn = Fqn.fromString("/a");
@@ -43,7 +41,7 @@
if (cache != null)
tearDown();
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache = (CacheImpl<String, String>)instance.createCache(false);
+ cache = (CacheImpl) instance.createCache(false);
// very short acquisition timeout
cache.getConfiguration().setLockAcquisitionTimeout(100);
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
Modified: core/trunk/src/test/java/org/jboss/cache/options/ForceCacheModeTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/ForceCacheModeTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/options/ForceCacheModeTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -9,7 +9,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
@@ -46,24 +46,22 @@
private static final String VALUE1 = "value1";
private static final String VALUE2 = "value2";
- private CacheImpl<Object, Object> cache1, cache2;
+ private CacheSPI<Object, Object> cache1, cache2;
private Option asyncOption;
private Option syncOption;
private static CountDownLatch latch;
private BlockingListener listener;
- private void createCaches(NodeLockingScheme scheme, CacheMode mode) throws Exception
+ private void createCaches(NodeLockingScheme scheme, CacheMode mode)
{
- cache1 = (CacheImpl<Object, Object>)DefaultCacheFactory.getInstance().createCache(false);
- Configuration c = new Configuration();
- cache1.setConfiguration(c);
+ cache1 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ Configuration c = cache1.getConfiguration();
c.setNodeLockingScheme(scheme);
c.setCacheMode(mode);
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- cache2 = (CacheImpl<Object, Object>)DefaultCacheFactory.getInstance().createCache(false);
- c = new Configuration();
- cache2.setConfiguration(c);
+ cache2 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ c = cache2.getConfiguration();
c.setNodeLockingScheme(scheme);
c.setCacheMode(mode);
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
@@ -82,9 +80,9 @@
cache1.getInvocationContext().setOptionOverrides(local);
cache1.put(FQNA, KEY, VALUE1);
-
+
assertEquals("Cache1 correct", VALUE1, cache1.get(FQNA, KEY));
-
+
local = new Option();
local.setCacheModeLocal(true);
cache2.getInvocationContext().setOptionOverrides(local);
@@ -93,7 +91,7 @@
// Validate data is as expected
assertEquals("Cache1 correct", VALUE1, cache1.get(FQNA, KEY));
assertEquals("Cache2 correct", VALUE1, cache2.get(FQNA, KEY));
-
+
listener = new BlockingListener();
cache2.addCacheListener(listener);
}
@@ -298,9 +296,9 @@
* Confirms the updater is not blocked and that the cache state is as
* expected at the end.
*
- * @param tm transction manager Updater should use. For non-transactional
- * tests, should be <code>null</code>
- * @param option Option to set before doing put
+ * @param tm transction manager Updater should use. For non-transactional
+ * tests, should be <code>null</code>
+ * @param option Option to set before doing put
* @param removeTest true if we're testing a remove; false if a put
* @throws InterruptedException
* @throws CacheException
@@ -344,9 +342,9 @@
* Confirms the updater is blocked and that the cache state is as
* expected at the end.
*
- * @param tm transction manager Updater should use. For non-transactional
- * tests, should be <code>null</code>
- * @param option Option to set before doing put
+ * @param tm transction manager Updater should use. For non-transactional
+ * tests, should be <code>null</code>
+ * @param option Option to set before doing put
* @param removeTest true if we're testing a remove; false if a put
* @throws InterruptedException
* @throws CacheException
@@ -376,7 +374,7 @@
break;
TestingUtil.sleepThread(10);
}
-
+
assertTrue("Updater finished", updater.finished);
assertFalse("Listener blocked", listener.blocked);
assertNull("Updater succeeded", updater.failure);
@@ -469,7 +467,9 @@
{
latch.await();
}
- catch (InterruptedException e) {}
+ catch (InterruptedException e)
+ {
+ }
blocked = false;
}
Modified: core/trunk/src/test/java/org/jboss/cache/options/ForceWriteLockTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/ForceWriteLockTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/options/ForceWriteLockTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,10 +1,5 @@
package org.jboss.cache.options;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertTrue;
-
-import javax.transaction.TransactionManager;
-
import org.jboss.cache.CacheFactory;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
@@ -12,17 +7,21 @@
import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.NodeLock;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.TransactionManager;
+
/**
* Tests forcing a write lock to be obtained on a node
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 2.0.0
*/
-@Test(groups = { "functional" })
+@Test(groups = {"functional"})
public class ForceWriteLockTest
{
private CacheSPI<String, String> cache;
@@ -35,7 +34,7 @@
Configuration c = new Configuration();
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache = (CacheSPI<String, String>)instance.createCache(c);
+ cache = (CacheSPI<String, String>) instance.createCache(c);
tm = cache.getTransactionManager();
}
@@ -113,14 +112,14 @@
testControl();
}
- private void assertNotLocked(Fqn fqn) throws Exception
+ private void assertNotLocked(Fqn fqn)
{
NodeSPI<String, String> n = cache.peek(fqn, true);
NodeLock lock = n.getLock();
assertFalse("node " + fqn + " is locked!", lock.isLocked());
}
- private void assertLocked(Object owner, Fqn fqn, boolean write_locked) throws Exception
+ private void assertLocked(Object owner, Fqn fqn, boolean write_locked)
{
NodeSPI<String, String> n = cache.peek(fqn, true);
if (owner == null)
Modified: core/trunk/src/test/java/org/jboss/cache/options/LockAcquisitionTimeoutTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/LockAcquisitionTimeoutTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/options/LockAcquisitionTimeoutTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,26 +6,21 @@
*/
package org.jboss.cache.options;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Option;
import org.jboss.cache.lock.TimeoutException;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.TransactionManager;
+
/**
* Test functionality of {@link Option#setLockAcquisitionTimeout(int)}.
*
@@ -42,15 +37,14 @@
private static final String VALUE1 = "value1";
private static final String VALUE2 = "value2";
- private CacheImpl<Object, Object> cache;
+ private CacheSPI<Object, Object> cache;
private Option option;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
- cache = (CacheImpl<Object, Object>)DefaultCacheFactory.getInstance().createCache(false);
- Configuration c = new Configuration();
- cache.setConfiguration(c);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ Configuration c = cache.getConfiguration();
c.setCacheMode("REPL_SYNC");
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
Modified: core/trunk/src/test/java/org/jboss/cache/options/SuppressLockingTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/SuppressLockingTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/options/SuppressLockingTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,26 +6,21 @@
*/
package org.jboss.cache.options;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.transaction.TransactionManager;
-
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.TransactionManager;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* Tests the suppression of locking nodes
*
@@ -37,7 +32,7 @@
private Fqn fqn = Fqn.fromString("/blah");
private Fqn fqn1 = Fqn.fromString("/blah/1");
- private CacheImpl<String, String> cache;
+ private CacheSPI<String, String> cache;
private TransactionManager m;
@@ -48,7 +43,7 @@
config.setCacheMode(Configuration.CacheMode.LOCAL);
config.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache = (CacheImpl<String, String>)instance.createCache(config);
+ cache = (CacheSPI<String, String>) instance.createCache(config);
m = cache.getTransactionManager();
}
@@ -75,7 +70,7 @@
m.commit();
assertEquals(0, cache.getNumberOfLocksHeld());
- cache.remove(fqn);
+ cache.removeNode(fqn);
m.begin();
cache.getInvocationContext().getOptionOverrides().setSuppressLocking(true);
@@ -87,7 +82,7 @@
assertEquals(0, cache.getNumberOfLocksHeld());
// test normal operation again
- cache.remove(fqn);
+ cache.removeNode(fqn);
m.begin();
assertFalse(cache.getInvocationContext().getOptionOverrides().isSuppressLocking());
@@ -113,7 +108,7 @@
m.commit();
assertEquals(0, cache.getNumberOfLocksHeld());
- cache.remove(fqn);
+ cache.removeNode(fqn);
m.begin();
cache.getInvocationContext().getOptionOverrides().setSuppressLocking(true);
@@ -136,7 +131,7 @@
assertEquals(0, cache.getNumberOfLocksHeld());
// test normal operation again
- cache.remove(fqn);
+ cache.removeNode(fqn);
m.begin();
cache.put(fqn, "x", "3");
Modified: core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,26 +6,23 @@
*/
package org.jboss.cache.options.cachemodelocal;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.transaction.SystemException;
-import javax.transaction.TransactionManager;
-
import junit.framework.Assert;
-
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* Tests the cache mode local override in various scenarios. To be subclassed to test REPL_SYNC, REPL_ASYNC, INVALIDATION_SYNC, INVALIDATION_ASYNC for Opt and Pess locking.
* <p/>
@@ -33,7 +30,7 @@
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
-@Test(groups = { "functional" })
+@Test(groups = {"functional"})
public abstract class CacheModeLocalTestBase
{
// to be subclassed.
@@ -44,8 +41,8 @@
*/
protected boolean isInvalidation;
- private CacheImpl<String, String> cache1;
- private CacheImpl<String, String> cache2;
+ private CacheSPI<String, String> cache1;
+ private CacheSPI<String, String> cache2;
private Fqn fqn = Fqn.fromString("/a");
private String key = "key";
@@ -58,7 +55,7 @@
tearDown();
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache1 = (CacheImpl<String, String>)instance.createCache(false);
+ cache1 = (CacheSPI<String, String>) instance.createCache(false);
cache1.getConfiguration().setClusterName("test");
cache1.getConfiguration().setStateRetrievalTimeout(1000);
cache1.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
@@ -66,7 +63,7 @@
cache1.getConfiguration().setCacheMode(cacheMode);
cache1.start();
- cache2 = (CacheImpl<String, String>)instance.createCache(false);
+ cache2 = (CacheSPI<String, String>) instance.createCache(false);
cache2.getConfiguration().setClusterName("test");
cache2.getConfiguration().setStateRetrievalTimeout(1000);
cache2.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
@@ -259,7 +256,7 @@
// now try again with passing the default options
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
- cache1.remove(fqn);
+ cache1.removeNode(fqn);
delay();
// both should be null
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/BasicPassivationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/BasicPassivationTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/BasicPassivationTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -7,11 +7,6 @@
package org.jboss.cache.passivation;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.fail;
-
import org.jboss.cache.CacheFactory;
import org.jboss.cache.CacheImpl;
import org.jboss.cache.DefaultCacheFactory;
@@ -24,6 +19,7 @@
import org.jboss.cache.notifications.annotation.NodePassivated;
import org.jboss.cache.notifications.event.Event;
import org.jboss.cache.notifications.event.NodeEvent;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -32,10 +28,10 @@
* @author Ben Wang
* @version $Revision$
*/
-@Test(groups = { "functional" })
+@Test(groups = {"functional"})
public class BasicPassivationTest
{
- CacheImpl<String, String> cache_;
+ CacheImpl cache;
int wakeupIntervalMillis_ = 0;
final String ROOT_STR = "/test";
Throwable t1_ex, t2_ex;
@@ -49,7 +45,7 @@
public void setUp() throws Exception
{
initCaches();
- wakeupIntervalMillis_ = cache_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
+ wakeupIntervalMillis_ = cache.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
log("wakeupInterval is " + wakeupIntervalMillis_);
if (wakeupIntervalMillis_ < 0)
{
@@ -60,22 +56,21 @@
isTrue = true;
}
- private void initCaches() throws Exception
+ private void initCaches()
{
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache_ = (CacheImpl<String, String>)instance.createCache(false);
- cache_.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/local-passivation-service.xml"));// read in generic local xml
- cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ cache = (CacheImpl) instance.createCache(new XmlConfigurationParser().parseFile("META-INF/local-passivation-service.xml"), false);
+ cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
Object listener = new TestCacheListener();
- cache_.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig().setClassName(DummyInMemoryCacheLoader.class.getName());
- cache_.start();
- cache_.getNotifier().addCacheListener(listener);
+ cache.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig().setClassName(DummyInMemoryCacheLoader.class.getName());
+ cache.start();
+ cache.getNotifier().addCacheListener(listener);
}
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
- cache_.stop();
+ cache.stop();
}
public void testBasic()
@@ -85,20 +80,20 @@
Fqn fqn = Fqn.fromString(FQNSTR);
try
{
- cache_.put(fqn, FQNSTR, FQNSTR);
+ cache.put(fqn, FQNSTR, FQNSTR);
}
catch (Exception e)
{
fail("Failed to insert data" + e);
e.printStackTrace();
}
- System.out.println(cache_.toString());
+ System.out.println(cache.toString());
TestingUtil.sleepThread(21000);
- System.out.println(cache_.toString());
+ System.out.println(cache.toString());
try
{
- assertFalse(cache_.exists(FQNSTR, FQNSTR));
- String val = cache_.get(FQNSTR, FQNSTR);
+ assertFalse(cache.exists(FQNSTR, FQNSTR));
+ Object val = cache.get(FQNSTR, FQNSTR);
assertNotNull("DataNode should not be empty ", val);
}
catch (Exception e)
@@ -113,20 +108,20 @@
public void testDualPassivation() throws Exception
{
Fqn fqn = Fqn.fromString(FQNSTR);
- cache_.put(fqn, "key", "value");
- cache_.evict(fqn);
- cache_.evict(fqn);
- assertEquals("Proper value after 2 passivations", "value", cache_.get(fqn, "key"));
+ cache.put(fqn, "key", "value");
+ cache.evict(fqn);
+ cache.evict(fqn);
+ assertEquals("Proper value after 2 passivations", "value", cache.get(fqn, "key"));
}
public void testIntermingledPassivation() throws Exception
{
Fqn fqn = Fqn.fromString(FQNSTR);
- cache_.put(fqn, "key1", "value");
- cache_.evict(fqn);
- cache_.put(fqn, "key2", "value");
- cache_.evict(fqn);
- assertEquals("Proper value after 2 passivations", "value", cache_.get(fqn, "key1"));
+ cache.put(fqn, "key1", "value");
+ cache.evict(fqn);
+ cache.put(fqn, "key2", "value");
+ cache.evict(fqn);
+ assertEquals("Proper value after 2 passivations", "value", cache.get(fqn, "key1"));
}
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/ConcurrentPassivationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/ConcurrentPassivationTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/ConcurrentPassivationTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -7,15 +7,14 @@
package org.jboss.cache.passivation;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.fail;
-
import org.jboss.cache.CacheFactory;
import org.jboss.cache.CacheImpl;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.fail;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -30,7 +29,7 @@
@Test(groups = {"functional"})
public class ConcurrentPassivationTest
{
- private CacheImpl<Integer, String> cache_;
+ private CacheImpl cache_;
private int wakeupIntervalMillis_ = 0;
@BeforeMethod(alwaysRun = true)
@@ -45,11 +44,10 @@
}
- private void initCaches() throws Exception
+ private void initCaches()
{
CacheFactory<Integer, String> instance = DefaultCacheFactory.getInstance();
- cache_ = (CacheImpl<Integer, String>)instance.createCache(false);
- cache_.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/local-passivation-service.xml"));// read in generic local xml
+ cache_ = (CacheImpl) instance.createCache(new XmlConfigurationParser().parseFile("META-INF/local-passivation-service.xml"), false);
cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache_.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig().setClassName(DummyInMemoryCacheLoader.class.getName());
cache_.start();
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/LocalPassivationIntegrationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/LocalPassivationIntegrationTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/LocalPassivationIntegrationTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -7,16 +7,12 @@
package org.jboss.cache.passivation;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.fail;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.misc.TestingUtil;
@@ -26,6 +22,8 @@
import org.jboss.cache.notifications.annotation.NodePassivated;
import org.jboss.cache.notifications.event.Event;
import org.jboss.cache.notifications.event.NodeEvent;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -36,7 +34,7 @@
@Test(groups = {"functional"})
public class LocalPassivationIntegrationTest
{
- CacheImpl<String, String> cache_;
+ CacheSPI<String, String> cache;
protected final static Log log = LogFactory.getLog(LocalPassivationIntegrationTest.class);
int wakeupIntervalMillis_ = 0;
PassivationListener listener_;
@@ -46,18 +44,19 @@
public void setUp() throws Exception
{
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache_ = (CacheImpl<String, String>)instance.createCache(false);
- initCaches(cache_);
- cache_.getConfiguration().setUseRegionBasedMarshalling(true);
+ cache = (CacheSPI<String, String>) instance.createCache(new XmlConfigurationParser().parseFile("META-INF/local-passivation-service.xml"), false);
+ cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ cache.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig().setClassName(DummyInMemoryCacheLoader.class.getName());
+ cache.getConfiguration().setUseRegionBasedMarshalling(true);
- cache_.start();
+ cache.start();
listener_ = new PassivationListener();
- cache_.getNotifier().addCacheListener(listener_);
+ cache.getNotifier().addCacheListener(listener_);
listener_.resetCounter();
- wakeupIntervalMillis_ = cache_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
+ wakeupIntervalMillis_ = cache.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
log("wakeupInterval is " + wakeupIntervalMillis_);
if (wakeupIntervalMillis_ <= 0)
{
@@ -65,17 +64,10 @@
}
}
- void initCaches(CacheImpl<String, String> cache) throws Exception
- {
- cache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/local-passivation-service.xml"));// read in generic local xml
- cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- cache.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig().setClassName(DummyInMemoryCacheLoader.class.getName());
- }
-
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
- cache_.stop();
+ cache.stop();
}
/**
@@ -84,14 +76,14 @@
{
String rootStr = "/org/jboss/test/data/";
String str = rootStr + "0";
- cache_.remove("/");
+ cache.removeNode(Fqn.ROOT);
listener_.resetCounter();
- cache_.put(str, str, str);
+ cache.put(str, str, str);
TestingUtil.sleepThread(20000);
- assertFalse("UnversionedNode should not exist", cache_.exists(str, str));
- String val = cache_.get(str, str);
+ assertFalse("UnversionedNode should not exist", cache.exists(str));
+ String val = cache.get(str, str);
assertNotNull("DataNode should be activated ", val);
TestingUtil.sleepThread(LISTENER_WAIT_TIME);
assertEquals("Eviction counter ", 1, listener_.getCounter());
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,21 +6,10 @@
*/
package org.jboss.cache.passivation;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
@@ -35,10 +24,16 @@
import org.jboss.cache.notifications.annotation.NodeActivated;
import org.jboss.cache.notifications.annotation.NodePassivated;
import org.jboss.cache.notifications.event.NodeEvent;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
/**
* Tests that the TreeCacheListener implementation used by EJB3 SFSBs works.
*
@@ -60,7 +55,7 @@
{
log.debug("");
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache = (CacheImpl<String, String>)instance.createCache(false);
+ cache = (CacheSPI<String, String>) instance.createCache(false);
cache.getConfiguration().setCacheMode("local");
configureEviction();
configureCacheLoader();
@@ -184,7 +179,7 @@
if (bean == null)
{
activationException = new IllegalStateException("nodeActivate(): null bean instance.");
- throw (IllegalStateException)activationException;
+ throw (IllegalStateException) activationException;
}
if (log.isTraceEnabled())
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationTestsBase.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,33 +1,14 @@
package org.jboss.cache.passivation;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.transaction.NotSupportedException;
-import javax.transaction.Transaction;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
import org.jboss.cache.Node;
+import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.loader.CacheLoader;
@@ -38,11 +19,22 @@
import org.jboss.cache.xml.XmlHelper;
import org.jboss.util.stream.MarshalledValueInputStream;
import org.jboss.util.stream.MarshalledValueOutputStream;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* Base tests for passivation using any of the cache loaders
*
@@ -56,7 +48,7 @@
Log log = LogFactory.getLog(getClass());
//Cache Loader fields
- CacheImpl<Object, Object> cache;
+ CacheSPI<Object, Object> cache;
CacheLoader loader = null;
static final Fqn<String> FQN = new Fqn<String>("key");
@@ -64,40 +56,40 @@
protected CacheLoaderConfig getCacheLoaderConfig(String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState) throws Exception
{
String xml = "<config>\n" +
- "<passivation>true</passivation>\n" +
- "<preload>" + preload + "</preload>\n" +
- "<cacheloader>\n" +
- "<class>" + cacheloaderClass + "</class>\n" +
- "<properties>" + properties + "</properties>\n" +
- "<async>" + async + "</async>\n" +
- "<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
- "</cacheloader>\n" +
- "</config>";
+ "<passivation>true</passivation>\n" +
+ "<preload>" + preload + "</preload>\n" +
+ "<cacheloader>\n" +
+ "<class>" + cacheloaderClass + "</class>\n" +
+ "<properties>" + properties + "</properties>\n" +
+ "<async>" + async + "</async>\n" +
+ "<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
+ "</cacheloader>\n" +
+ "</config>";
Element element = XmlHelper.stringToElement(xml);
return XmlConfigurationParser.parseCacheLoaderConfig(element);
}
- @BeforeMethod(alwaysRun = true) public void setUp() throws Exception
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws Exception
{
- log.debug("");
- cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
cache.getConfiguration().setCacheMode("local");
configureCache();
- // cache.setCacheLoaderPreload("/1/2/3/4/5/d");
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
cache.create();
cache.start();
- loader = cache.getCacheLoader();
+ loader = cache.getCacheLoaderManager().getCacheLoader();
}
abstract protected void configureCache() throws Exception;
- @AfterMethod(alwaysRun = true) public void tearDown() throws Exception
+ @AfterMethod(alwaysRun = true)
+ public void tearDown() throws Exception
{
- cache.remove("/");
- loader.remove(Fqn.fromString("/"));
+ cache.removeNode(Fqn.ROOT);
+ loader.remove(Fqn.ROOT);
cache.stop();
cache.destroy();
}
@@ -105,20 +97,38 @@
protected void addDelay()
{
- ;// returns immediately in this case. Subclasses may override where a delay is needed.
+ // returns immediately in this case. Subclasses may override where a delay is needed.
}
+ /**
+ * Helper method to test the existence of a key
+ *
+ * @param fqn
+ * @param key
+ */
+ protected boolean exists(String fqn, String key)
+ {
+ NodeSPI n = cache.peek(Fqn.fromString(fqn), false, false);
+ if (key == null) return n != null;
+ return n != null && n.getKeysDirect().contains(key);
+ }
+
+ protected boolean exists(String fqn)
+ {
+ return exists(fqn, null);
+ }
+
public void testPrintPassivation() throws Exception
{
final Fqn<String> NODE = Fqn.fromString("/test");
final String KEY = "key";
loader.remove(NODE);
cache.put(NODE, KEY, 10);
- cache.evict(NODE);
+ cache.evict(NODE, true);
assertTrue(loader.exists(NODE));
addDelay();
log.info("print node " + NODE);
- String ret = cache.print(NODE);
+ Node ret = cache.getRoot().getChild(NODE);
assertNotNull(ret);
log.info("loader exists " + NODE);
assertTrue(!loader.exists(NODE));
@@ -128,39 +138,39 @@
public void testPutPassivation() throws Exception
{
- final String NODE = "/test";
+ final Fqn NODE = Fqn.fromString("/test");
final String KEY = "key";
Object retval = null;
- cache.remove(NODE);// nothing to remove
+ cache.removeNode(NODE);// nothing to remove
addDelay();
retval = cache.put(NODE, KEY, 10);// put in memory
assertNull(retval);
retval = cache.put(NODE, KEY, 20);// put in memory
addDelay();
assertEquals(10, retval);// get from memory
- cache.evict(Fqn.fromString(NODE));// passivate node
+ cache.evict(NODE, true);// passivate node
addDelay();
log.debug("______________");
retval = cache.put(NODE, KEY, 30);// activate node then does put in memory
- assertFalse(loader.exists(Fqn.fromString(NODE)));
+ assertFalse(loader.exists(NODE));
assertEquals(20, retval);
}
public void testPut2Passivation() throws CacheException
{
- final String NODE = "/a/b/c";
+ final Fqn NODE = Fqn.fromString("/a/b/c");
final String KEY = "key";
- Object retval = null;
- cache.remove(NODE);// nothing to remove
+ Object retval;
+ cache.removeNode(NODE);// nothing to remove
addDelay();
retval = cache.put(NODE, KEY, 10);// put in memory
assertNull(retval);
addDelay();
retval = cache.put(NODE, KEY, 20);// put in memory
assertEquals(10, retval);
- cache.evict(Fqn.fromString(NODE));// passivate node
- cache.evict(Fqn.fromString("/a/b"));// passivate parent node
- cache.evict(Fqn.fromString("/a"));// passivate parent node
+ cache.evict(NODE, true);// passivate node
+ cache.evict(Fqn.fromString("/a/b"), true);// passivate parent node
+ cache.evict(Fqn.fromString("/a"), true);// passivate parent node
addDelay();
try
{
@@ -173,7 +183,7 @@
retval = cache.put(NODE, KEY, 30);// activate node, put in memory new value
try
{
- assertFalse(loader.exists(Fqn.fromString(NODE)));
+ assertFalse(loader.exists(NODE));
}
catch (Exception e)
{
@@ -185,26 +195,27 @@
public void testSerializationPassivation() throws CacheException
{
+ Fqn fqn = Fqn.fromString("/mypojo");
SamplePojo pojo = new SamplePojo(39, "Hany");
pojo.getHobbies().add("Running");
pojo.getHobbies().add("Beerathlon");
pojo.getHobbies().add("Triathlon");
- cache.put("/mypojo", 322649, pojo);// put in memory
+ cache.put(fqn, 322649, pojo);// put in memory
addDelay();
- assertNotNull(cache.get("/mypojo", 322649));// get from memory
- cache.evict(Fqn.fromString("/mypojo"));// passivate node
+ assertNotNull(cache.get(fqn, 322649));// get from memory
+ cache.evict(fqn, false);// passivate node
try
{
- assertTrue(loader.exists(Fqn.fromString("/mypojo")));
+ assertTrue(loader.exists(fqn));
}
catch (Exception e)
{
fail(e.toString());
}
- SamplePojo pojo2 = (SamplePojo) cache.get("/mypojo", 322649);// activate node
+ SamplePojo pojo2 = (SamplePojo) cache.get(fqn, 322649);// activate node
try
{
- assertFalse(loader.exists(Fqn.fromString("/mypojo")));
+ assertFalse(loader.exists(fqn));
}
catch (Exception e)
{
@@ -229,7 +240,10 @@
m.put("key" + i, "val" + i);
}
cache.put("/a/b/c", m);
- cache.load("/1/2/3/4/5");
+
+ // force preloading this node from the cache loader.
+ cache.getCacheLoaderManager().preload(Fqn.fromString("/1/2/3/4/5"), true, true);
+
cache.put("/1/2/3/4/5", null);
cache.put("/1/2/3/4/5/a", null);
cache.put("/1/2/3/4/5/b", null);
@@ -242,9 +256,9 @@
// cache.put("/a/b/c", "newKey", "newValue");
System.out.println("cache: " + cache);
- assertTrue(cache.exists("/1/2/3/4"));
- assertTrue(cache.exists("/a/b/c"));
- assertFalse(cache.exists("/a/b/c/d"));
+ assert (exists("/1/2/3/4"));
+ assert (exists("/a/b/c"));
+ assert (!exists("/a/b/c/d"));
}
catch (Exception e)
{
@@ -255,7 +269,7 @@
public void testPreloadingPassivation() throws Exception
{
- cache.remove("/");// remove nothing
+ cache.removeNode(Fqn.ROOT);// remove nothing
cache.put("1/2/3/4/5/d", "key", "val");// put in memory
cache.evict(Fqn.fromString("1/2/3/4/5/d"));// passivate node
System.out.println("-- checking for 1/2/3/4/5/d");
@@ -268,9 +282,9 @@
{
fail(e.toString());
}
- cache.get("1/2/3/4/5/d");// get from loader but doesn't load attributes
+ cache.getNode("1/2/3/4/5/d");// get from loader but doesn't load attributes
assertEquals(true, loader.exists(Fqn.fromString("1/2/3/4/5/d")));
- assertTrue(cache.exists("1/2/3/4/5/d"));
+ assert (exists("1/2/3/4/5/d"));
System.out.println("-- 1/2/3/4/5/d exists");
cache.get("1/2/3/4/5/d", "key");// activate node
assertEquals(false, loader.exists(Fqn.fromString("1/2/3/4/5/d")));
@@ -281,7 +295,7 @@
{
Set<Object> keys = null;
cache.put("/a/b/c", "key", "val");
- keys = cache.getKeys(Fqn.fromString("/a/b/c"));
+ keys = cache.getNode(Fqn.fromString("/a/b/c")).getKeys();
assertNotNull(keys);
assertEquals(1, keys.size());
keys.add("myKey");
@@ -291,11 +305,11 @@
public void testExists() throws Exception
{
cache.put("/eins/zwei/drei", "key1", "val1");
- assertTrue(cache.exists("/eins/zwei/drei"));
- assertTrue(cache.exists("/eins/zwei/drei", "key1"));
- assertFalse(cache.exists("/eins/zwei/drei", "key2"));
- assertFalse(cache.exists("/uno/due/tre"));
- assertFalse(cache.exists("/une/due/tre", "key1"));
+ assert (exists("/eins/zwei/drei"));
+ assert (exists("/eins/zwei/drei", "key1"));
+ assert (!exists("/eins/zwei/drei", "key2"));
+ assert (!exists("/uno/due/tre"));
+ assert (!exists("/une/due/tre", "key1"));
}
public void testGetChildren() throws Exception
@@ -303,8 +317,8 @@
cache.put("/d/one", null);
cache.put("/d/two", null);
cache.put("/d/three", null);
- cache.get("/d");
- Set children = cache.getChildrenNames("/d");
+ cache.getNode("/d");
+ Set children = cache.getNode("/d").getChildrenNames();
assertNotNull(children);
assertEquals(3, children.size());
assertTrue(children.contains("one"));
@@ -326,7 +340,7 @@
cache.evict(Fqn.fromString("/a"));// passivate node
cache.evict(Fqn.fromString("/"));// passivate node
addDelay();
- Set children = cache.getChildrenNames("/a/b/c");// load node children names
+ Set children = cache.getNode("/a/b/c").getChildrenNames();// load node children names
assertNotNull(children);
assertEquals(3, children.size());
assertTrue(children.contains("1"));
@@ -352,7 +366,7 @@
{
cache.put("/1", null);
cache.put("a", null);
- Set children = cache.getChildrenNames("/");// get root node children names
+ Set children = cache.getRoot().getChildrenNames();// get root node children names
assertNotNull(children);
assertEquals(2, children.size());
assertTrue(children.contains("1"));
@@ -370,7 +384,7 @@
{
cache.put("/1", null);
cache.put("a", null);
- Set children = cache.getChildrenNames("");// get children from root node
+ Set children = cache.getRoot().getChildrenNames();// get children from root node
assertNotNull(children);
assertEquals(2, children.size());
assertTrue(children.contains("1"));
@@ -390,7 +404,7 @@
{
cache.put("/a/b/c", null);
}
- Set children = cache.getChildrenNames((Fqn<Object>) null);// get "null* node children names
+ Set children = cache.getRoot().getChildrenNames();// get "null* node children names
assertTrue(children.isEmpty());
}
catch (Exception e)
@@ -407,12 +421,11 @@
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
- System.out.println("cache is " + cache.printLockInfo());
- Node n = cache.get("/a");
+ Node n = cache.getNode("/a");
assertNotNull(n);
- Set children = cache.getChildrenNames("/a");
+ Set children = n.getChildrenNames();
assertNotNull(children);
assertEquals(3, children.size());
}
@@ -428,17 +441,15 @@
cache.put("/a/1", null);// put node in memory
cache.put("/a/2", null);// put node in memory
cache.put("/a/3", null);// put node in memory
- System.out.println("cache is " + cache.printLockInfo());
cache.evict(Fqn.fromString("/a/1"));// passivate node
cache.evict(Fqn.fromString("/a/2"));// passivate node
cache.evict(Fqn.fromString("/a/3"));// passivate node
cache.evict(Fqn.fromString("/a"));// passivate node
assertTrue(loader.exists(Fqn.fromString("/a")));
- System.out.println("cache is " + cache.printLockInfo());
addDelay();
- assertNotNull(cache.get("/a"));// load node
+ assertNotNull(cache.getNode("/a"));// load node
assertTrue(loader.exists(Fqn.fromString("/a")));// children haven't been loaded
- Set children = cache.getChildrenNames("/a");
+ Set children = cache.getNode("/a").getChildrenNames();
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
@@ -458,18 +469,16 @@
cache.put("/a/2", null);
cache.put("/a/3", null);
cache.put("/a", "test", "test");
- System.out.println("cache is " + cache.printLockInfo());
cache.evict(Fqn.fromString("/a/1"));// passivate node
cache.evict(Fqn.fromString("/a/2"));// passivate node
cache.evict(Fqn.fromString("/a/3"));// passivate node
cache.evict(Fqn.fromString("/a"));// passivate node
assertTrue(loader.exists(Fqn.fromString("/a")));
- System.out.println("cache is " + cache.printLockInfo());
addDelay();
Object val = cache.get("/a", "test");// load node's attributes but not children
assertEquals("attributes weren't loaded", "test", val);
- Set children = cache.getChildrenNames("/a");// get node's children names
+ Set children = cache.getNode("/a").getChildrenNames();
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
@@ -487,20 +496,18 @@
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
- System.out.println("cache is " + cache.printLockInfo());
cache.evict(Fqn.fromString("/a/1"));// passivate node
cache.evict(Fqn.fromString("/a/2"));// passivate node
cache.evict(Fqn.fromString("/a/3"));// passivate node
cache.evict(Fqn.fromString("/a"));// passivate node
- System.out.println("cache is " + cache.printLockInfo());
addDelay();
assertNull(cache.get("/a", "test"));// load attributes only
assertTrue(loader.exists(Fqn.fromString("/a")));// loaded attibutes but not children
assertNull(cache.get("/a/1", "test"));// activate node
assertFalse(loader.exists(Fqn.fromString("/a/1")));// loaded attributes and has no children
- Set children = cache.getChildrenNames("/a");// load children names
+ Set children = cache.getNode("/a").getChildrenNames();// load children names
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
@@ -512,13 +519,11 @@
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
- System.out.println("cache is " + cache.printLockInfo());
cache.evict(Fqn.fromString("/a/1"));// passivate node
cache.evict(Fqn.fromString("/a/2"));// passivate node
cache.evict(Fqn.fromString("/a/3"));// passivate node
cache.evict(Fqn.fromString("/a"));// passivate node
assertTrue(loader.exists(Fqn.fromString("/a")));
- System.out.println("cache is " + cache.printLockInfo());
addDelay();
cache.get("/a/1", "test");// activate node
@@ -527,7 +532,7 @@
assertFalse(loader.exists(Fqn.fromString("/a/2")));
cache.get("/a/3", "test");// activate node
assertFalse(loader.exists(Fqn.fromString("/a/3")));
- Set children = cache.getChildrenNames("/a");// get node's children names
+ Set children = cache.getNode("/a").getChildrenNames();// get node's children names
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
@@ -538,7 +543,6 @@
cache.evict(Fqn.fromString("/a/2"));// passivate node
cache.evict(Fqn.fromString("/a/3"));// passivate node
cache.evict(Fqn.fromString("/a"));// passivate node
- System.out.println("cache is " + cache.printLockInfo());
assertTrue(loader.exists(Fqn.fromString("/a")));
cache.get("/a/1", "test");// activate node
@@ -547,7 +551,7 @@
assertFalse(loader.exists(Fqn.fromString("/a/2")));
cache.get("/a/3", "test");// activate node
assertFalse(loader.exists(Fqn.fromString("/a/3")));
- children = cache.getChildrenNames("/a");// get children names
+ children = cache.getNode("/a").getChildrenNames();// get children names
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
@@ -561,12 +565,10 @@
cache.put("/a/1", null);
cache.put("/a/2", null);
cache.put("/a/3", null);
- System.out.println("cache is " + cache.printLockInfo());
cache.evict(Fqn.fromString("/a/1"));// passivate node
cache.evict(Fqn.fromString("/a/2"));// passivate node
cache.evict(Fqn.fromString("/a/3"));// passivate node
cache.evict(Fqn.fromString("/a"));// passivate node
- System.out.println("cache is " + cache.printLockInfo());
addDelay();
assertTrue(loader.exists(Fqn.fromString("/a")));
assertNull(cache.get("/a", "test"));// load attributes from loader
@@ -579,7 +581,7 @@
assertFalse(loader.exists(Fqn.fromString("/a/2")));
cache.get("/a/3", "test");// passivate node
assertFalse(loader.exists(Fqn.fromString("/a/3")));
- Set children = cache.getChildrenNames("/a");
+ Set children = cache.getNode("/a").getChildrenNames();
assertNotNull("No children were loaded", children);
System.out.println("children: " + children);
assertEquals("3 children weren't loaded", 3, children.size());
@@ -594,11 +596,11 @@
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
- assertEquals(3, cache.getKeys(key).size());
- cache.removeData(key);
- Set<Object> keys = cache.getKeys(Fqn.fromString(key));
+ assertEquals(3, cache.getNode(key).getKeys().size());
+ cache.getNode(key).clearData();
+ Set<Object> keys = cache.getNode(key).getKeys();
assertEquals(0, keys.size());
- cache.remove("/x");
+ cache.removeNode("/x");
Object val = cache.get(key, "keyA");
assertNull(val);
}
@@ -612,13 +614,13 @@
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
addDelay();
- keys = cache.getKeys(key);
+ keys = cache.getNode(key).getKeys();
assertEquals(3, keys.size());
- cache.removeData(key);
+ cache.getNode(key).clearData();
cache.evict(key);// passivate node
addDelay();
- keys = cache.getKeys(key);// activate node
+ keys = cache.getNode(key).getKeys();// activate node
assertFalse(loader.exists(key));
assertEquals(0, keys.size());
}
@@ -630,12 +632,12 @@
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
- keys = cache.getKeys(key);
+ keys = cache.getNode(key).getKeys();
assertEquals(3, keys.size());
cache.evict(key);// passivate node
assertTrue(loader.exists(key));
- cache.removeData(key);
- keys = cache.getKeys(key);// activate node
+ cache.getNode(key).clearData();
+ keys = cache.getNode(key).getKeys();// activate node
assertFalse(loader.exists(key));
assertEquals(0, keys.size());
}
@@ -647,17 +649,17 @@
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
cache.remove(key, "keyA");
- assertEquals(2, cache.getKeys(key).size());
- cache.remove("/x");
+ assertEquals(2, cache.getNode(key).getKeys().size());
+ cache.removeNode("/x");
}
public void testRemoveKey2() throws CacheException
{
- final String NODE = "/test";
+ final Fqn NODE = Fqn.fromString("/test");
final String KEY = "key";
Object retval = null;
- cache.remove(NODE);
+ cache.removeNode(NODE);
retval = cache.put(NODE, KEY, 10);
assertNull(retval);
addDelay();
@@ -670,25 +672,25 @@
public void testRemoveKey3Passivation() throws Exception
{
- final String NODE = "/test";
+ final Fqn NODE = Fqn.fromString("/test");
final String KEY = "key";
Object retval = null;
- cache.remove(NODE);
+ cache.removeNode(NODE);
retval = cache.put(NODE, KEY, 10);
assertNull(retval);
- cache.evict(Fqn.fromString(NODE));// passivate node
+ cache.evict(NODE);// passivate node
addDelay();
- assertTrue(loader.exists(Fqn.fromString(NODE)));
- assertEquals(10, loader.get(Fqn.fromString(NODE)).get(KEY));
+ assertTrue(loader.exists(NODE));
+ assertEquals(10, loader.get(NODE).get(KEY));
retval = cache.remove(NODE, KEY);// activate node
assertEquals(10, retval);
- assertFalse(loader.exists(Fqn.fromString(NODE)));
+ assertFalse(loader.exists(NODE));
- cache.evict(Fqn.fromString(NODE));// passiave node
+ cache.evict(NODE);// passiave node
addDelay();
retval = cache.remove(NODE, KEY);// activate node
- assertFalse(loader.exists(Fqn.fromString(NODE)));
+ assertFalse(loader.exists(NODE));
assertNull(retval);
}
@@ -699,25 +701,25 @@
cache.put(key, "keyA", "valA");
cache.put(key, "keyB", "valB");
cache.put(key, "keyC", "valC");
- cache.remove("/x");
+ cache.removeNode("/x");
assertNull(cache.get(key, "keyA"));
addDelay();
- Set<Object> keys = cache.getKeys(Fqn.fromString(key));
+ Set<Object> keys = cache.getNode(key).getKeys();
assertNull(keys);
- cache.remove("/x");
+ cache.removeNode("/x");
}
public void testRemoveRoot() throws Exception
{
- assertEquals(0, cache.getKeys("/").size());
+ assertEquals(0, cache.getRoot().getKeys().size());
cache.put("/1/2/3/4/5", null);
cache.put("uno/due/tre", null);
cache.put("1/2/3/a", null);
cache.put("/eins/zwei/drei", null);
cache.put("/one/two/three", null);
- cache.remove("/");
- assertEquals(0, cache.getKeys("/").size());
+ cache.removeNode(Fqn.ROOT);
+ assertEquals(0, cache.getRoot().getKeys().size());
}
@@ -728,16 +730,16 @@
cache.evict(Fqn.fromString("/first/second"));// pasivate node to cache loader
addDelay();
assertTrue(loader.exists(Fqn.fromString("/first/second")));
- assertTrue(cache.exists("/first"));
+ assert (exists("/first"));
String val = (String) cache.get("/first/second", "key1");
assertTrue(loader.exists(Fqn.fromString("/first/second")));
assertEquals("val1", val);
String val2 = (String) cache.get("/first/second/third", "key2");// activate node
assertFalse(loader.exists(Fqn.fromString("/first/second/third")));
assertEquals("val2", val2);
- assertTrue(cache.exists("/first/second/third"));
- assertTrue(cache.exists("/first/second"));
- assertTrue(cache.exists("/first"));
+ assert (exists("/first/second/third"));
+ assert (exists("/first/second"));
+ assert (exists("/first"));
}
@@ -747,14 +749,14 @@
cache.evict(Fqn.fromString("/first/second/third"));// passivate node, note: it has no children
addDelay();
assertTrue(loader.exists(Fqn.fromString("/first/second/third")));
- assertTrue(cache.exists("/first/second"));
- assertTrue(cache.exists("/first"));
+ assert (exists("/first/second"));
+ assert (exists("/first"));
String val = (String) cache.get("/first/second/third", "key1");// activate node
assertFalse(loader.exists(Fqn.fromString("/first/second/third")));
assertEquals("val1", val);
- assertTrue(cache.exists("/first/second/third"));
- assertTrue(cache.exists("/first/second"));
- assertTrue(cache.exists("/first"));
+ assert (exists("/first/second/third"));
+ assert (exists("/first/second"));
+ assert (exists("/first"));
}
@@ -775,7 +777,7 @@
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
mgr.getTransaction();
- Set<?> children = cache.getChildrenNames("/a");
+ Set<?> children = cache.getNode("/a").getChildrenNames();
assertEquals(3, children.size());
assertTrue(children.contains("1"));
assertTrue(children.contains("2"));
@@ -785,7 +787,7 @@
}
- public void testTxPutCommit() throws Exception, NotSupportedException
+ public void testTxPutCommit() throws Exception
{
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -796,7 +798,7 @@
mgr.commit();
- assertNotNull(cache.getKeys("/one/two/three"));
+ assertNotNull(cache.getNode("/one/two/three").getKeys());
assertEquals("val1", cache.get(Fqn.fromString("/one/two/three"), "key1"));
mgr.begin();
@@ -806,10 +808,10 @@
mgr.commit();
assertTrue(loader.exists(Fqn.fromString("/one/two/three")));
assertTrue(loader.exists(Fqn.fromString("/one/two/three/four")));
- assertNotNull(cache.getKeys("/one/two/three"));
- Set<?> children = cache.getChildrenNames("/one");
+ assertNotNull(cache.getNode("/one/two/three").getKeys());
+ Set<?> children = cache.getNode("/one").getChildrenNames();
assertEquals(1, children.size());
- cache.remove("/");
+ cache.removeNode(Fqn.ROOT);
}
@@ -817,7 +819,7 @@
{
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
- cache.remove("/one");
+ cache.removeNode("/one");
addDelay();
mgr.begin();
@@ -825,9 +827,9 @@
cache.put("/one/two/three/four", "key2", "val2");
mgr.rollback();
addDelay();
- assertNull(cache.getKeys("/one/two/three"));
- Set<?> children = cache.getChildrenNames("/one");
- assertTrue(children.isEmpty());
+ assertNull(cache.getNode("/one/two/three"));
+ assert cache.getNode("/one") == null;
+
assertFalse(loader.exists(Fqn.fromString("/one/two/three")));
assertFalse(loader.exists(Fqn.fromString("/one/two/three/four")));
}
@@ -859,7 +861,7 @@
* Tests basic operations without a transaction.
*/
public void testBasicOperations()
- throws Exception
+ throws Exception
{
doTestBasicOperations();
@@ -869,7 +871,7 @@
* Tests basic operations with a transaction.
*/
public void testBasicOperationsTransactional()
- throws Exception
+ throws Exception
{
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
@@ -911,7 +913,7 @@
* Do basic put tests for a given FQN.
*/
private void doPutTests(Fqn<String> fqn)
- throws Exception
+ throws Exception
{
assertTrue(!loader.exists(fqn));
@@ -958,7 +960,7 @@
* Do basic remove tests for a given FQN.
*/
private void doRemoveTests(Fqn<String> fqn)
- throws Exception
+ throws Exception
{
/* remove(Fqn,Object) */
@@ -991,7 +993,7 @@
* and tests removing subtrees.
*/
public void testMultiLevelTree()
- throws Exception
+ throws Exception
{
/* Create top level node implicitly. */
@@ -1155,7 +1157,7 @@
* Tests the getChildrenNames() method.
*/
public void testGetChildrenNames()
- throws Exception
+ throws Exception
{
checkChildren(new Fqn(), null);
@@ -1181,14 +1183,14 @@
loader.put(Fqn.fromString("/key0/abc"), null);
addDelay();
checkChildren(Fqn.fromString("/key0"),
- new String[]{"a", "ab", "abc"});
+ new String[]{"a", "ab", "abc"});
loader.put(Fqn.fromString("/key0/xxx"), null);
loader.put(Fqn.fromString("/key0/xx"), null);
loader.put(Fqn.fromString("/key0/x"), null);
addDelay();
checkChildren(Fqn.fromString("/key0"),
- new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
+ new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
loader.put(Fqn.fromString("/key0/a/1"), null);
loader.put(Fqn.fromString("/key0/a/2"), null);
@@ -1197,7 +1199,7 @@
checkChildren(Fqn.fromString("/key0/a/2"), new String[]{"1"});
checkChildren(Fqn.fromString("/key0/a"), new String[]{"1", "2"});
checkChildren(Fqn.fromString("/key0"),
- new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
+ new String[]{"a", "ab", "abc", "x", "xx", "xxx"});
//
// loader.put(Fqn.fromString("/key0/\u0000"), null);
// loader.put(Fqn.fromString("/key0/\u0001"), null);
@@ -1224,7 +1226,7 @@
* Checks that the given list of children part names is returned.
*/
private void checkChildren(Fqn fqn, String[] names)
- throws Exception
+ throws Exception
{
Set set = loader.getChildrenNames(fqn);
@@ -1246,7 +1248,7 @@
* Tests basic operations without a transaction.
*/
public void testModifications()
- throws Exception
+ throws Exception
{
doTestModifications();
@@ -1256,7 +1258,7 @@
* Tests basic operations with a transaction.
*/
public void testModificationsTransactional()
- throws Exception
+ throws Exception
{
DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
@@ -1268,7 +1270,7 @@
* Tests modifications.
*/
private void doTestModifications()
- throws Exception
+ throws Exception
{
/* PUT_KEY_VALUE, PUT_DATA */
@@ -1315,7 +1317,7 @@
* Tests a one-phase transaction.
*/
public void testOnePhaseTransaction()
- throws Exception
+ throws Exception
{
List<Modification> mods = createUpdates();
loader.prepare(null, mods, true);
@@ -1326,7 +1328,7 @@
* Tests a two-phase transaction.
*/
public void testTwoPhaseTransactionPassivation()
- throws Exception
+ throws Exception
{
Object txnKey = new Object();
@@ -1345,7 +1347,7 @@
* Tests rollback of a two-phase transaction.
*/
public void testTransactionRollbackPassivation()
- throws Exception
+ throws Exception
{
loader.remove(Fqn.fromString("/"));
@@ -1407,7 +1409,7 @@
* Checks that a list of modifications was applied.
*/
private void checkModifications(List<Modification> list)
- throws Exception
+ throws Exception
{
for (int i = 0; i < list.size(); i += 1)
@@ -1451,7 +1453,7 @@
* Tests that null keys and values work as for a standard Java Map.
*/
public void testNullKeysAndValues()
- throws Exception
+ throws Exception
{
loader.put(FQN, null, "x");
@@ -1506,7 +1508,7 @@
* Test non-default database name.
*/
public void testDatabaseNamePassivation()
- throws Exception
+ throws Exception
{
loader.put(FQN, "one", "two");
@@ -1518,7 +1520,7 @@
* Test load/store state.
*/
public void testLoadAndStore()
- throws Exception
+ throws Exception
{
/* Empty state. */
@@ -1593,7 +1595,7 @@
{
Complex x = (Complex) o;
return (nested != null) ? nested.equals(x.nested)
- : (x.nested == null);
+ : (x.nested == null);
}
catch (ClassCastException e)
{
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToJDBCCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToJDBCCacheLoaderTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToJDBCCacheLoaderTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,13 +6,13 @@
*/
package org.jboss.cache.passivation;
-import java.util.Properties;
-
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.xml.XmlHelper;
import org.w3c.dom.Element;
+import java.util.Properties;
+
/**
* Tests passivation using JDBC Cache Loader.
* This test has MySQL hard-coded. To run it, run MySQL first: mysqld -u=root
@@ -27,27 +27,27 @@
protected CacheLoaderConfig getCacheLoaderConfig() throws Exception
{
String xml = " <config>\n" +
- " \n" +
- " <passivation>true</passivation>\n" +
- " <preload></preload>\n" +
- "\n" +
- " <cacheloader>\n" +
- " <class>org.jboss.cache.loader.JDBCCacheLoader</class>\n" +
- " <properties>\n" +
- getJDBCProps() +
- " </properties>\n" +
- " <async>false</async>\n" +
- " <fetchPersistentState>false</fetchPersistentState>\n" +
- " <ignoreModifications>false</ignoreModifications>\n" +
- " </cacheloader>\n" +
- " \n" +
- " </config>";
+ " \n" +
+ " <passivation>true</passivation>\n" +
+ " <preload></preload>\n" +
+ "\n" +
+ " <cacheloader>\n" +
+ " <class>org.jboss.cache.loader.JDBCCacheLoader</class>\n" +
+ " <properties>\n" +
+ getJDBCProps() +
+ " </properties>\n" +
+ " <async>false</async>\n" +
+ " <fetchPersistentState>false</fetchPersistentState>\n" +
+ " <ignoreModifications>false</ignoreModifications>\n" +
+ " </cacheloader>\n" +
+ " \n" +
+ " </config>";
Element element = XmlHelper.stringToElement(xml);
return XmlConfigurationParser.parseCacheLoaderConfig(element);
}
- protected String getJDBCProps() throws Exception
+ protected String getJDBCProps()
{
Properties prop = new Properties();
try
@@ -59,11 +59,11 @@
System.out.println("Error loading jdbc properties ");
}
return "cache.jdbc.driver =" + prop.getProperty("cache.jdbc.driver") + "\n" +
- "cache.jdbc.url=" + prop.getProperty("cache.jdbc.url") + "\n" +
- "cache.jdbc.user=" + prop.getProperty("cache.jdbc.user") + "\n" +
- "cache.jdbc.password=" + prop.getProperty("cache.jdbc.password") + "\n" +
- "cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type") + "\n" +
- "cache.jdbc.sql-concat=" + prop.getProperty("cache.jdbc.sql-concat");
+ "cache.jdbc.url=" + prop.getProperty("cache.jdbc.url") + "\n" +
+ "cache.jdbc.user=" + prop.getProperty("cache.jdbc.user") + "\n" +
+ "cache.jdbc.password=" + prop.getProperty("cache.jdbc.password") + "\n" +
+ "cache.jdbc.node.type=" + prop.getProperty("cache.jdbc.node.type") + "\n" +
+ "cache.jdbc.sql-concat=" + prop.getProperty("cache.jdbc.sql-concat");
}
protected void configureCache() throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/PassivationToLocalDelegatingCacheLoaderTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,10 +1,11 @@
package org.jboss.cache.passivation;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.LocalDelegatingCacheLoader;
+import org.jboss.cache.misc.TestingUtil;
import org.testng.annotations.AfterMethod;
/**
@@ -15,23 +16,27 @@
*/
public class PassivationToLocalDelegatingCacheLoaderTest extends PassivationTestsBase
{
- CacheImpl delegating_cache;
+ CacheSPI delegating_cache;
CacheLoader cache_loader;
@SuppressWarnings("deprecation")
protected void configureCache() throws Exception
{
- delegating_cache = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
+ delegating_cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
delegating_cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
delegating_cache.create();
delegating_cache.start();
cache_loader = new LocalDelegatingCacheLoader(delegating_cache);
// setCache first ...
cache.getConfiguration().setCacheLoaderConfig(getCacheLoaderConfig("", "org.jboss.cache.loader.LocalDelegatingCacheLoader", "", false, false));
- cache.setCacheLoader(cache_loader);
+ cache.getCacheLoaderManager().setCacheLoader(cache_loader);
+
+ // don't actually alter the interceptor chain, but this will force a re-injection of all deps in all components.
+ TestingUtil.replaceInterceptorChain(cache, cache.getInterceptorChain().get(0));
}
- @AfterMethod(alwaysRun = true) public void tearDown() throws Exception
+ @AfterMethod(alwaysRun = true)
+ public void tearDown() throws Exception
{
super.tearDown();
delegating_cache.stop();
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -22,15 +22,14 @@
package org.jboss.cache.passivation;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.fail;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+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.XmlConfigurationParser;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.misc.TestingUtil;
@@ -39,6 +38,8 @@
import org.jboss.cache.notifications.annotation.NodeLoaded;
import org.jboss.cache.notifications.annotation.NodePassivated;
import org.jboss.cache.notifications.event.NodeEvent;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.fail;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -46,11 +47,11 @@
/**
* @author Ben Wang, Feb 11, 2004
*/
-@Test(groups = { "functional", "jgroups" })
+@Test(groups = {"functional", "jgroups"})
public class ReplicatedPassivationIntegrationTest
{
- private CacheImpl<String, String> cache_;
- private CacheImpl<String, String> cache1_;
+ private CacheSPI<String, String> cache_;
+ private CacheSPI<String, String> cache1_;
protected final static Log log = LogFactory.getLog(ReplicatedPassivationIntegrationTest.class);
int wakeupIntervalMillis_ = 0;
PassivationListener listener_;
@@ -64,13 +65,11 @@
public void setUp() throws Exception
{
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache_ = (CacheImpl<String, String>)instance.createCache(false);
- initCaches(cache_);
+ cache_ = (CacheSPI<String, String>) instance.createCache(getCfg(), false);
cache_.getConfiguration().setUseRegionBasedMarshalling(true);
cache_.start();
- cache1_ = (CacheImpl<String, String>)instance.createCache(false);
- initCaches(cache1_);
+ cache1_ = (CacheSPI<String, String>) instance.createCache(getCfg(), false);
cache1_.getConfiguration().setUseRegionBasedMarshalling(true);
cache1_.start();
@@ -85,11 +84,12 @@
}
}
- void initCaches(CacheImpl<String, String> cache) throws Exception
+ Configuration getCfg() throws Exception
{
- cache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replSync-passivation-service.xml"));// read in generic local xml
- cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- cache.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig().setClassName(DummyInMemoryCacheLoader.class.getName());
+ Configuration cfg = new XmlConfigurationParser().parseFile("META-INF/replSync-passivation-service.xml");// read in generic local xml
+ cfg.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ cfg.getCacheLoaderConfig().getFirstCacheLoaderConfig().setClassName(DummyInMemoryCacheLoader.class.getName());
+ return cfg;
}
@AfterMethod(alwaysRun = true)
@@ -106,13 +106,14 @@
String rootStr = "/org/jboss/test/data/";
String rootStr1 = "/__JBossInternal__/5c4o12-pzhlhj-esnuy3sg-1-esnuy3sg-2";
String str = rootStr + "0";
- cache_.remove("/");
+ cache_.removeNode(Fqn.ROOT);
cache_.put(str, str, str);
cache_.put(rootStr1, str, str);
TestingUtil.sleepThread(11000);
- assertFalse("UnversionedNode should not exist", cache1_.exists(str, str));
+ Node n = cache1_.peek(Fqn.fromString(str), false, false);
+ assert n == null || !n.getKeys().contains(str) : "UnversionedNode should not exist";
String val;
val = cache1_.get(str, str);
val = cache1_.get(rootStr1, str);
Modified: core/trunk/src/test/java/org/jboss/cache/replicated/AsyncReplTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/replicated/AsyncReplTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/replicated/AsyncReplTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -8,35 +8,31 @@
package org.jboss.cache.replicated;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import javax.transaction.TransactionManager;
-
import org.jboss.cache.Cache;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.misc.TestingUtil;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.TransactionManager;
+
/**
- * Unit test for replicated async CacheImpl. Use locking and multiple threads to test
+ * Unit test for replicated async CacheSPI. Use locking and multiple threads to test
* concurrent access to the tree.
*
* @version $Revision$
*/
-@Test(groups = { "functional", "jgroups" })
+@Test(groups = {"functional", "jgroups"})
public class AsyncReplTest
{
- private CacheImpl<Object, Object> cache1, cache2;
+ private CacheSPI<Object, Object> cache1, cache2;
+
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
@@ -47,10 +43,9 @@
cache2 = createCache("CacheGroup");
}
- private CacheImpl<Object, Object> createCache(String name) throws Exception
+ private CacheSPI<Object, Object> createCache(String name) throws Exception
{
- CacheImpl<Object, Object> cache = (CacheImpl<Object, Object>)DefaultCacheFactory.getInstance().createCache(false);
- cache.setConfiguration(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_ASYNC));
+ CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_ASYNC), false);
cache.getConfiguration().setClusterName(name);
// Call the hook that allows mux integration
@@ -114,7 +109,7 @@
cache1.put(fqn, key, "value1");
// allow for replication
- TestingUtil.sleepThread((long)500);
+ TestingUtil.sleepThread((long) 500);
assertEquals("value1", cache1.get(fqn, key));
assertEquals("value1", cache2.get(fqn, key));
@@ -127,7 +122,7 @@
mgr.commit();
- TestingUtil.sleepThread((long)500);
+ TestingUtil.sleepThread((long) 500);
assertEquals("value2", cache1.get(fqn, key));
assertEquals("value2", cache2.get(fqn, key));
@@ -139,7 +134,7 @@
mgr.rollback();
- TestingUtil.sleepThread((long)500);
+ TestingUtil.sleepThread((long) 500);
assertEquals("value2", cache1.get(fqn, key));
assertEquals("value2", cache2.get(fqn, key));
@@ -160,7 +155,7 @@
public void testPutShouldNotReplicateToDifferentCluster()
{
- CacheImpl<Object, Object> cache3 = null, cache4 = null;
+ CacheSPI<Object, Object> cache3 = null, cache4 = null;
try
{
cache3 = createCache("DifferentGroup");
@@ -168,7 +163,7 @@
cache1.put("/a/b/c", "age", 38);
// because we use async repl, modfication may not yet have been propagated to cache2, so
// we have to wait a little
- TestingUtil.sleepThread((long)1000);
+ TestingUtil.sleepThread((long) 1000);
assertNull("Should not have replicated", cache3.get("/a/b/c", "age"));
}
catch (Exception e)
@@ -190,7 +185,7 @@
public void testStateTransfer()
{
- CacheImpl<Object, Object> cache4 = null;
+ CacheSPI<Object, Object> cache4 = null;
try
{
cache1.put("a/b/c", "age", 38);
@@ -222,7 +217,7 @@
cache1.put("/a/b/c", "age", 38);
// value on cache2 may be 38 or not yet replicated
- age = (Integer)cache2.get("/a/b/c", "age");
+ age = (Integer) cache2.get("/a/b/c", "age");
log("attr \"age\" of \"/a/b/c\" on cache2=" + age);
assertTrue("should be either null or 38", age == null || age == 38);
}
@@ -244,7 +239,7 @@
tm.commit();
// value on cache2 may be 38 or not yet replicated
- age = (Integer)cache2.get("/a/b/c", "age");
+ age = (Integer) cache2.get("/a/b/c", "age");
log("attr \"age\" of \"/a/b/c\" on cache2=" + age);
assertTrue("should be either null or 38", age == null || age == 38);
}
Modified: core/trunk/src/test/java/org/jboss/cache/replicated/ReplicationExceptionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/replicated/ReplicationExceptionTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/replicated/ReplicationExceptionTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -7,39 +7,36 @@
*/
package org.jboss.cache.replicated;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.fail;
-
-import java.io.NotSerializableException;
-import java.io.Serializable;
-
-import javax.naming.Context;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.transaction.DummyTransactionManager;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.fail;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.naming.Context;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import java.io.NotSerializableException;
+import java.io.Serializable;
+
/**
* Teting of replication exception for a Nonerislizable object
*
* @author Ben Wang
* @version $Revision$
*/
-@Test(groups = { "functional" })
+@Test(groups = {"functional"})
public class ReplicationExceptionTest
{
- private CacheImpl<String, ContainerData> cache1, cache2;
+ private CacheSPI<String, ContainerData> cache1, cache2;
String old_factory = null;
final String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
@@ -70,11 +67,11 @@
return mgr;
}
- private void initCaches(Configuration.CacheMode caching_mode) throws Exception
+ private void initCaches(Configuration.CacheMode caching_mode)
{
CacheFactory<String, ContainerData> instance = DefaultCacheFactory.getInstance();
- cache1 = (CacheImpl<String, ContainerData>)instance.createCache(false);
- cache2 = (CacheImpl<String, ContainerData>)instance.createCache(false);
+ cache1 = (CacheSPI<String, ContainerData>) instance.createCache(false);
+ cache2 = (CacheSPI<String, ContainerData>) instance.createCache(false);
cache1.getConfiguration().setCacheMode(caching_mode);
cache2.getConfiguration().setCacheMode(caching_mode);
cache1.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
Modified: core/trunk/src/test/java/org/jboss/cache/replicated/SyncCacheListenerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/replicated/SyncCacheListenerTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/replicated/SyncCacheListenerTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -7,26 +7,10 @@
*/
package org.jboss.cache.replicated;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import javax.naming.Context;
-import javax.transaction.NotSupportedException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.IsolationLevel;
@@ -35,19 +19,27 @@
import org.jboss.cache.notifications.annotation.NodeRemoved;
import org.jboss.cache.notifications.event.NodeEvent;
import org.jboss.cache.transaction.DummyTransactionManager;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.naming.Context;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
/**
* Test out the TreeCacheListener
*
* @version $Revision$
*/
-@Test(groups={"functional"})
+@Test(groups = {"functional"})
public class SyncCacheListenerTest
{
- private CacheImpl<Object, Object> cache1, cache2;
+ private CacheSPI<Object, Object> cache1, cache2;
private final static Log log_ = LogFactory.getLog(SyncCacheListenerTest.class);
private String old_factory = null;
private final static String FACTORY = "org.jboss.cache.transaction.DummyContextFactory";
@@ -77,10 +69,10 @@
System.out.println("*** finished tearDown()");
}
- private void initCaches() throws Exception
+ private void initCaches()
{
- cache1 = (CacheImpl<Object, Object>)DefaultCacheFactory.getInstance().createCache(false);
- cache2 = (CacheImpl<Object, Object>)DefaultCacheFactory.getInstance().createCache(false);
+ cache1 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache2 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
cache2.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
cache1.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
@@ -127,7 +119,7 @@
tm.commit();
// value on cache2 must be 38
- age = (Integer)cache2.get("/a/b/c", "age");
+ age = (Integer) cache2.get("/a/b/c", "age");
assertNotNull("\"age\" obtained from cache2 must be non-null ", age);
assertTrue("\"age\" must be 38", age == 38);
}
@@ -140,7 +132,7 @@
cache1.put("/a/b/c", "age", 38);
// value on cache2 must be 38
- age = (Integer)cache2.get("/a/b/c", "age");
+ age = (Integer) cache2.get("/a/b/c", "age");
assertNotNull("\"age\" obtained from cache2 must be non-null ", age);
assertTrue("\"age\" must be 38", age == 38);
cache1.remove("/a/b/c", "age");
@@ -154,7 +146,7 @@
lis.put("/a/b/c", "age", 38);
// value on cache2 must be 38
- age = (Integer)cache2.get("/a/b/c", "age");
+ age = (Integer) cache2.get("/a/b/c", "age");
assertNotNull("\"age\" obtained from cache2 must be non-null ", age);
assertTrue("\"age\" must be 38", age == 38);
}
@@ -177,7 +169,7 @@
tm.commit();
// value on cache2 must be 38
- age = (Integer)cache2.get("/a/b/c", "age");
+ age = (Integer) cache2.get("/a/b/c", "age");
assertNotNull("\"age\" obtained from cache2 must be non-null ", age);
assertTrue("\"age\" must be 38", age == 38);
}
@@ -194,7 +186,7 @@
lis.put("/a/b/c", map);
// value on cache2 must be 38
- age = (Integer)cache2.get("/a/b/c", "age");
+ age = (Integer) cache2.get("/a/b/c", "age");
assertNotNull("\"age\" obtained from cache2 must be non-null ", age);
assertTrue("\"age\" must be 38", age == 38);
}
@@ -210,7 +202,7 @@
cache1.put(fqn, key, val);
}
- public void put(String fqn, Map<String, Comparable> map)
+ public void put(String fqn, Map map)
{
if (map.size() == 0)
fail("put(): map size can't be 0");
Modified: core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTxTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTxTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/replicated/SyncReplTxTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -7,31 +7,12 @@
*/
package org.jboss.cache.replicated;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.assertTrue;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.Semaphore;
-
-import javax.naming.Context;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import javax.transaction.Status;
-import javax.transaction.Synchronization;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
@@ -41,11 +22,24 @@
import org.jboss.cache.notifications.annotation.CacheListener;
import org.jboss.cache.notifications.annotation.NodeModified;
import org.jboss.cache.notifications.event.NodeEvent;
-import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.cache.transaction.TransactionSetup;
+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.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Semaphore;
+
/**
* Replicated unit test for sync transactional CacheImpl
* Note: we use DummyTransactionManager for Tx purpose instead of relying on
@@ -57,8 +51,8 @@
public class SyncReplTxTest
{
private static Log log = LogFactory.getLog(SyncReplTxTest.class);
- private CacheImpl<Object, Object> cache1;
- private CacheImpl<Object, Object> cache2;
+ private CacheSPI<Object, Object> cache1;
+ private CacheSPI<Object, Object> cache2;
Semaphore lock;
private Throwable t1_ex;
@@ -83,7 +77,7 @@
return beginTransaction(cache1);
}
- private TransactionManager beginTransaction(Cache c) throws SystemException, NotSupportedException
+ private TransactionManager beginTransaction(CacheSPI c) throws SystemException, NotSupportedException
{
TransactionManager mgr = c.getConfiguration().getRuntimeConfig().getTransactionManager();
mgr.begin();
@@ -92,8 +86,8 @@
private void initCaches(Configuration.CacheMode caching_mode) throws Exception
{
- cache1 = (CacheImpl<Object, Object>)DefaultCacheFactory.getInstance().createCache(false);
- cache2 = (CacheImpl<Object, Object>)DefaultCacheFactory.getInstance().createCache(false);
+ cache1 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
+ cache2 = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
cache1.getConfiguration().setCacheMode(caching_mode);
cache2.getConfiguration().setCacheMode(caching_mode);
cache1.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
@@ -156,7 +150,7 @@
{
initCaches(Configuration.CacheMode.REPL_SYNC);
cache1.getConfiguration().setSyncCommitPhase(true);
- cache1.releaseAllLocks("/");
+ cache1.getRoot().getLock().releaseAll();
TransactionManager tm = beginTransaction();
cache1.put("/bela/ban", "name", "Bela Ban");
assertEquals(3, cache1.getNumberOfLocksHeld());
@@ -183,15 +177,15 @@
cache1.put("/a/b/c", "age", 38);
tx = mgr.suspend();
assertNull("age on cache2 must be null as the TX has not yet been committed", cache2.get("/a/b/c", "age"));
- log.debug("cache1: locks held before commit: " + cache1.printLockInfo());
- log.debug("cache2: locks held before commit: " + cache2.printLockInfo());
+ log.debug("cache1: locks held before commit: " + CachePrinter.printCacheLockingInfo(cache1));
+ log.debug("cache2: locks held before commit: " + CachePrinter.printCacheLockingInfo(cache2));
mgr.resume(tx);
mgr.commit();
- log.debug("cache1: locks held after commit: " + cache1.printLockInfo());
- log.debug("cache2: locks held after commit: " + cache2.printLockInfo());
+ log.debug("cache1: locks held after commit: " + CachePrinter.printCacheLockingInfo(cache1));
+ log.debug("cache2: locks held after commit: " + CachePrinter.printCacheLockingInfo(cache2));
// value on cache2 must be 38
- age = (Integer)cache2.get("/a/b/c", "age");
+ age = (Integer) cache2.get("/a/b/c", "age");
assertNotNull("\"age\" obtained from cache2 must be non-null ", age);
assertTrue("\"age\" must be 38", age == 38);
}
@@ -267,8 +261,8 @@
cache2.put(NODE2, "age", 39);
System.out.println("TransactionTable for cache2 after cache2.put():\n" + cache2.getTransactionTable().toString(true));
- System.out.println("cache1 before commit:\n" + cache1.printLockInfo());
- System.out.println("cache2 before commit:\n" + cache2.printLockInfo());
+ System.out.println("cache1 before commit:\n" + CachePrinter.printCacheLockingInfo(cache1));
+ System.out.println("cache2 before commit:\n" + CachePrinter.printCacheLockingInfo(cache2));
try
{
@@ -280,8 +274,8 @@
//should be a classic deadlock here.
}
- System.out.println("cache1 after commit:\n" + cache1.printLockInfo());
- System.out.println("cache2 after commit:\n" + cache2.printLockInfo());
+ System.out.println("cache1 after commit:\n" + CachePrinter.printCacheLockingInfo(cache1));
+ System.out.println("cache2 after commit:\n" + CachePrinter.printCacheLockingInfo(cache2));
/*
assertTrue(cache1.exists(NODE1));
@@ -324,8 +318,8 @@
cache2.put(NODE, "age", 39);
System.out.println("TransactionTable for cache2 after cache2.put():\n" + cache2.getTransactionTable().toString(true));
- System.out.println("cache1 before commit:\n" + cache1.printLockInfo());
- System.out.println("cache2 before commit:\n" + cache2.printLockInfo());
+ System.out.println("cache1 before commit:\n" + CachePrinter.printCacheLockingInfo(cache1));
+ System.out.println("cache2 before commit:\n" + CachePrinter.printCacheLockingInfo(cache2));
try
{
@@ -337,8 +331,8 @@
System.out.println("Transaction was rolled back, this is correct");
}
- System.out.println("cache1 after commit:\n" + cache1.printLockInfo());
- System.out.println("cache2 after commit:\n" + cache2.printLockInfo());
+ System.out.println("cache1 after commit:\n" + CachePrinter.printCacheLockingInfo(cache1));
+ System.out.println("cache2 after commit:\n" + CachePrinter.printCacheLockingInfo(cache2));
assertEquals(0, cache1.getNumberOfLocksHeld());
assertEquals(0, cache2.getNumberOfLocksHeld());
@@ -362,8 +356,8 @@
cache1.put(NODE1, "age", 38);
cache2.put(NODE2, "age", 39);
- System.out.println("cache1 (before commit):\n" + cache1.printLockInfo());
- System.out.println("cache2 (before commit):\n" + cache2.printLockInfo());
+ System.out.println("cache1 (before commit):\n" + CachePrinter.printCacheLockingInfo(cache1));
+ System.out.println("cache2 (before commit):\n" + CachePrinter.printCacheLockingInfo(cache2));
// this will rollback the transaction
Transaction tx = tm.getTransaction();
@@ -379,8 +373,8 @@
System.out.println("Transaction was rolled back, this is correct");
}
- System.out.println("cache1 (after rollback):\n" + cache1.printLockInfo());
- System.out.println("cache2 (after rollback):\n" + cache2.printLockInfo());
+ System.out.println("cache1 (after rollback):\n" + CachePrinter.printCacheLockingInfo(cache1));
+ System.out.println("cache2 (after rollback):\n" + CachePrinter.printCacheLockingInfo(cache2));
assertEquals(0, cache1.getNumberOfLocksHeld());
assertEquals(0, cache2.getNumberOfLocksHeld());
@@ -415,8 +409,8 @@
// tx = beginTransaction();
// cache1.put(NODE1, "age", 38);
//
- // System.out.println("cache1 (before commit):\n" + cache1.printLockInfo());
- // System.out.println("cache2 (before commit):\n" + cache2.printLockInfo());
+ // System.out.println("cache1 (before commit):\n" + CachePrinter.printCacheLockingInfo(cache1));
+ // System.out.println("cache2 (before commit):\n" + CachePrinter.printCacheLockingInfo(cache2));
//
// // this will rollback the transaction
// tx.registerSynchronization(new TransactionAborter(tx));
@@ -435,8 +429,8 @@
// // Sleep, as the rollback call to cache2 is async
// TestingUtil.sleepThread(1000);
//
- // System.out.println("cache1 (after rollback):\n" + cache1.printLockInfo());
- // System.out.println("cache2 (after rollback):\n" + cache2.printLockInfo());
+ // System.out.println("cache1 (after rollback):\n" + CachePrinter.printCacheLockingInfo(cache1));
+ // System.out.println("cache2 (after rollback):\n" + CachePrinter.printCacheLockingInfo(cache2));
//
// assertNull(cbl1.getCallbackException());
// assertNull(cbl2.getCallbackException());
@@ -456,16 +450,16 @@
// tx = beginTransaction();
// cache1.put(NODE1, "age", 38);
//
- // System.out.println("cache1 (before commit):\n" + cache1.printLockInfo());
- // System.out.println("cache2 (before commit):\n" + cache2.printLockInfo());
+ // System.out.println("cache1 (before commit):\n" + CachePrinter.printCacheLockingInfo(cache1));
+ // System.out.println("cache2 (before commit):\n" + CachePrinter.printCacheLockingInfo(cache2));
//
// tx.commit();
//
// // Sleep, as the commit call to cache2 is async
// TestingUtil.sleepThread(1000);
//
- // System.out.println("cache1 (after rollback):\n" + cache1.printLockInfo());
- // System.out.println("cache2 (after rollback):\n" + cache2.printLockInfo());
+ // System.out.println("cache1 (after rollback):\n" + CachePrinter.printCacheLockingInfo(cache1));
+ // System.out.println("cache2 (after rollback):\n" + CachePrinter.printCacheLockingInfo(cache2));
//
// assertNull(cbl1.getCallbackException());
// assertNull(cbl2.getCallbackException());
@@ -503,8 +497,8 @@
tm = beginTransaction();
cache1.put(NODE1, "age", 38);
- System.out.println("cache1 (before commit):\n" + cache1.printLockInfo());
- System.out.println("cache2 (before commit):\n" + cache2.printLockInfo());
+ System.out.println("cache1 (before commit):\n" + CachePrinter.printCacheLockingInfo(cache1));
+ System.out.println("cache2 (before commit):\n" + CachePrinter.printCacheLockingInfo(cache2));
// instead of a listener lets just get a WL on ROOT on cache2. And hold on to it.
Transaction tx = tm.suspend();
@@ -513,7 +507,7 @@
cache2.getRoot().put("x", "y");
Transaction tx2 = cache2.getTransactionManager().suspend();
- System.out.println("cache2 (before commit):\n" + cache2.printLockInfo());
+ System.out.println("cache2 (before commit):\n" + CachePrinter.printCacheLockingInfo(cache2));
tm.resume(tx);
try
@@ -534,8 +528,8 @@
// Sleep, as the commit call to cache2 is async
TestingUtil.sleepThread(1000);
- System.out.println("cache1 (after rollback):\n" + cache1.printLockInfo());
- System.out.println("cache2 (after rollback):\n" + cache2.printLockInfo());
+ System.out.println("cache1 (after rollback):\n" + CachePrinter.printCacheLockingInfo(cache1));
+ System.out.println("cache2 (after rollback):\n" + CachePrinter.printCacheLockingInfo(cache2));
//assertNull(tal.getCallbackException());
@@ -562,7 +556,7 @@
Thread.sleep(1000);
// value on cache2 must be 38
- age = (Integer)cache2.get("/a/b/c", "age");
+ age = (Integer) cache2.get("/a/b/c", "age");
assertNotNull("\"age\" obtained from cache2 is null ", age);
assertTrue("\"age\" must be 38", age == 38);
@@ -609,7 +603,8 @@
initCaches(Configuration.CacheMode.REPL_SYNC);
cache1.getConfiguration().setSyncCommitPhase(true);
- Thread t1 = new Thread("Thread1") {
+ Thread t1 = new Thread("Thread1")
+ {
TransactionManager tm;
public void run()
@@ -620,8 +615,8 @@
cache1.put("/bela/ban", "name", "Bela Ban");
TestingUtil.sleepThread(2000);// Thread2 will be blocked until we commit
tm.commit();
- System.out.println("[Thread1] ** LOCK INFO cache1: " + cache1.printLockInfo());
- System.out.println("[Thread1] ** LOCK INFO cache2: " + cache2.printLockInfo());
+ System.out.println("[Thread1] ** LOCK INFO cache1: " + CachePrinter.printCacheLockingInfo(cache1));
+ System.out.println("[Thread1] ** LOCK INFO cache2: " + CachePrinter.printCacheLockingInfo(cache2));
}
catch (Throwable ex)
{
@@ -631,7 +626,8 @@
}
};
- Thread t2 = new Thread("Thread2") {
+ Thread t2 = new Thread("Thread2")
+ {
TransactionManager tm;
public void run()
@@ -640,14 +636,14 @@
{
TestingUtil.sleepThread(1000);// give Thread1 time to acquire the lock
tm = beginTransaction();
- System.out.println("[Thread2] ** LOCK INFO cache1: " + cache1.printLockInfo());
- System.out.println("[Thread2] ** LOCK INFO cache2: " + cache2.printLockInfo());
+ System.out.println("[Thread2] ** LOCK INFO cache1: " + CachePrinter.printCacheLockingInfo(cache1));
+ System.out.println("[Thread2] ** LOCK INFO cache2: " + CachePrinter.printCacheLockingInfo(cache2));
cache1.put("/bela/ban", "name", "Michelle Ban");
- System.out.println("[Thread2] ** LOCK INFO cache1: " + cache1.printLockInfo());
- System.out.println("[Thread2] ** LOCK INFO cache2: " + cache2.printLockInfo());
+ System.out.println("[Thread2] ** LOCK INFO cache1: " + CachePrinter.printCacheLockingInfo(cache1));
+ System.out.println("[Thread2] ** LOCK INFO cache2: " + CachePrinter.printCacheLockingInfo(cache2));
tm.commit();
- System.out.println("[Thread2] ** LOCK INFO cache1: " + cache1.printLockInfo());
- System.out.println("[Thread2] ** LOCK INFO cache2: " + cache2.printLockInfo());
+ System.out.println("[Thread2] ** LOCK INFO cache1: " + CachePrinter.printCacheLockingInfo(cache1));
+ System.out.println("[Thread2] ** LOCK INFO cache2: " + CachePrinter.printCacheLockingInfo(cache2));
}
catch (Throwable ex)
{
@@ -696,12 +692,12 @@
/**
* Should reproduce JBCACHE-32 problem (http://jira.jboss.com/jira/browse/JBCACHE-32)
*/
- private void _testConcurrentCommits(int num_threads) throws Exception
+ private void _testConcurrentCommits(int num_threads)
{
Object myMutex = new Object();
- final CacheImpl c1 = (CacheImpl)DefaultCacheFactory.getInstance().createCache(false);
- final CacheImpl c2 = (CacheImpl)DefaultCacheFactory.getInstance().createCache(false);
+ final CacheSPI c1 = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
+ final CacheSPI c2 = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
c1.getConfiguration().setClusterName("TempCluster");
c2.getConfiguration().setClusterName("TempCluster");
c1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
@@ -781,7 +777,7 @@
TestingUtil.sleepThread(6000);
synchronized (myMutex)
{
- System.out.println("cache is " + c1.printLockInfo());
+ System.out.println("cache is " + CachePrinter.printCacheLockingInfo(c1));
System.out.println("******************* SIGNALLING THREADS ********************");
myMutex.notifyAll();
}
@@ -799,7 +795,7 @@
}
}
- System.out.println("FINAL c1:\n" + c1.printDetails() + "\nlocks:\n" + c1.printLockInfo());
+ System.out.println("FINAL c1:\n" + CachePrinter.printCacheDetails(c1) + "\nlocks:\n" + CachePrinter.printCacheLockingInfo(c1));
assertEquals(0, c1.getNumberOfLocksHeld());
assertEquals(0, c2.getNumberOfLocksHeld());
@@ -827,10 +823,11 @@
public void testConcurrentPutsOnTwoInstances() throws Exception
{
initCaches(Configuration.CacheMode.REPL_SYNC);
- final CacheImpl<Object, Object> c1 = this.cache1;
- final CacheImpl<Object, Object> c2 = this.cache2;
+ final CacheSPI<Object, Object> c1 = this.cache1;
+ final CacheSPI<Object, Object> c2 = this.cache2;
- Thread t1 = new Thread() {
+ Thread t1 = new Thread()
+ {
TransactionManager tm;
public void run()
@@ -850,7 +847,8 @@
}
};
- Thread t2 = new Thread() {
+ Thread t2 = new Thread()
+ {
TransactionManager tm;
public void run()
@@ -896,9 +894,10 @@
public void testPut() throws Exception
{
initCaches(Configuration.CacheMode.REPL_SYNC);
- final CacheImpl<Object, Object> c1 = this.cache1;
+ final CacheSPI<Object, Object> c1 = this.cache1;
- Thread t1 = new Thread() {
+ Thread t1 = new Thread()
+ {
public void run()
{
try
@@ -934,7 +933,8 @@
}
};
- Thread t2 = new Thread() {
+ Thread t2 = new Thread()
+ {
public void run()
{
try
@@ -944,7 +944,7 @@
lock.acquire();
System.out.println("-- t2 has lock");
// Should replicate the value right away.
- Integer val = (Integer)cache2.get("/a/b/c", "age");
+ Integer val = (Integer) cache2.get("/a/b/c", "age");
System.out.println("[Thread2] value is " + val);
assertEquals(new Integer(38), val);
System.out.println("-- t2 releases lock");
@@ -954,7 +954,7 @@
TestingUtil.sleepThread(500);
lock.acquire();
System.out.println("-- t2 has lock");
- val = (Integer)cache2.get("/a/b/c", "age");
+ val = (Integer) cache2.get("/a/b/c", "age");
System.out.println("-- t2 releases lock");
lock.release();
assertEquals(new Integer(39), val);
@@ -1037,8 +1037,9 @@
public void testPutTx1() throws Exception
{
initCaches(Configuration.CacheMode.REPL_SYNC);
- final CacheImpl<Object, Object> c1 = this.cache1;
- Thread t1 = new Thread() {
+ final CacheSPI<Object, Object> c1 = this.cache1;
+ Thread t1 = new Thread()
+ {
public void run()
{
TransactionManager tm = null;
@@ -1078,7 +1079,8 @@
}
};
- Thread t2 = new Thread() {
+ Thread t2 = new Thread()
+ {
public void run()
{
TransactionManager tm = null;
@@ -1136,8 +1138,9 @@
public void testPutTxWithRollback() throws Exception
{
initCaches(Configuration.CacheMode.REPL_SYNC);
- final CacheImpl<Object, Object> c2 = this.cache1;
- Thread t1 = new Thread() {
+ final CacheSPI<Object, Object> c2 = this.cache1;
+ Thread t1 = new Thread()
+ {
public void run()
{
TransactionManager tm = null;
@@ -1167,7 +1170,8 @@
}
};
- Thread t2 = new Thread() {
+ Thread t2 = new Thread()
+ {
public void run()
{
TransactionManager tm = null;
@@ -1246,12 +1250,12 @@
static class CallbackListener
{
- CacheImpl<Object, Object> callbackCache;
+ CacheSPI<Object, Object> callbackCache;
Object callbackKey;
Exception ex;
Object mutex = new Object();
- CallbackListener(CacheImpl<Object, Object> cache, Object callbackKey)
+ CallbackListener(CacheSPI<Object, Object> cache, Object callbackKey)
{
this.callbackCache = cache;
this.callbackKey = callbackKey;
@@ -1295,7 +1299,7 @@
TransactionManager callbackTM;
- TransactionAborterCallbackListener(CacheImpl<Object, Object> cache, Object callbackKey)
+ TransactionAborterCallbackListener(CacheSPI<Object, Object> cache, Object callbackKey)
{
super(cache, callbackKey);
callbackTM = callbackCache.getTransactionManager();
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/CorruptedFileCacheLoader.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/CorruptedFileCacheLoader.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/CorruptedFileCacheLoader.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,17 +1,13 @@
package org.jboss.cache.statetransfer;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-
import org.jboss.cache.Fqn;
import org.jboss.cache.loader.FileCacheLoader;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+
public class CorruptedFileCacheLoader extends FileCacheLoader
{
- public CorruptedFileCacheLoader()
- {
- super();
- }
@Override
public void loadState(Fqn subtree, ObjectOutputStream os) throws Exception
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/FailedStateTransferTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/FailedStateTransferTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/FailedStateTransferTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -23,11 +23,15 @@
package org.jboss.cache.statetransfer;
import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Version;
import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.factories.ComponentRegistry;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.lock.TimeoutException;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.remoting.jgroups.CacheMessageListener;
import static org.testng.AssertJUnit.fail;
import org.testng.annotations.Test;
@@ -45,8 +49,7 @@
public void testFailedStateTransfer() throws Exception
{
- CacheImpl cache = new SecretiveStateCache();
- cache.setConfiguration(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_ASYNC));
+ CacheSPI cache = (CacheSPI) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_ASYNC), false);
cache.getConfiguration().setClusterName("VersionedTestBase");
cache.getConfiguration().setReplVersionString(getReplicationVersion());
// Use a long timeout to facilitate setting debugger breakpoints
@@ -56,12 +59,16 @@
// start it can still be destroyed later
caches.put("secretive", cache);
- cache.create();
+ // inject our own message listener and re-wire deps
+ ComponentRegistry cr = TestingUtil.extractComponentRegistry(cache);
+ cr.unregisterComponent(CacheMessageListener.class);
+ cr.registerComponent(new SecretiveStateCacheMessageListener());
+ cr.updateDependencies();
+
cache.start();
- CacheImpl recipient = new SecretiveStateCache();
- recipient.setConfiguration(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_ASYNC));
+ CacheSPI recipient = (CacheSPI) DefaultCacheFactory.getInstance().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_ASYNC), false);
recipient.getConfiguration().setClusterName("VersionedTestBase");
recipient.getConfiguration().setReplVersionString(getReplicationVersion());
// Use a long timeout to facilitate setting debugger breakpoints
@@ -71,9 +78,14 @@
// start it can still be destroyed later
caches.put("secretive2", recipient);
+ // inject our own message listener and re-wire deps
+ cr = TestingUtil.extractComponentRegistry(recipient);
+ cr.unregisterComponent(CacheMessageListener.class);
+ cr.registerComponent(new SecretiveStateCacheMessageListener());
+ cr.updateDependencies();
+
try
{
- recipient.create();
recipient.start();
fail("start() should throw an exception");
}
@@ -88,40 +100,30 @@
return Version.version;
}
- private static class SecretiveStateCache extends CacheImpl<Object, Object>
+ private static class SecretiveStateCacheMessageListener extends CacheMessageListener
{
- SecretiveStateCache() throws Exception
+ @Override
+ public void setState(byte[] new_state)
{
- super();
- setMessageListener(new Adaptor());
+ setStateException = new TimeoutException("Planned Timeout");
}
- class Adaptor extends MessageListenerAdaptor
+ @Override
+ public void setState(InputStream istream)
{
+ setStateException = new TimeoutException("Planned Timeout");
+ }
- @Override
- public void setState(byte[] new_state)
- {
- setStateException = new TimeoutException("Planned Timeout");
- }
+ @Override
+ public void setState(String state_id, byte[] state)
+ {
+ setStateException = new TimeoutException("Planned Timeout");
+ }
- @Override
- public void setState(InputStream istream)
- {
- setStateException = new TimeoutException("Planned Timeout");
- }
-
- @Override
- public void setState(String state_id, byte[] state)
- {
- setStateException = new TimeoutException("Planned Timeout");
- }
-
- @Override
- public void setState(String state_id, InputStream istream)
- {
- setStateException = new TimeoutException("Planned Timeout");
- }
+ @Override
+ public void setState(String state_id, InputStream istream)
+ {
+ setStateException = new TimeoutException("Planned Timeout");
}
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransfer200Test.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransfer200Test.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransfer200Test.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -110,7 +110,7 @@
cache2 = createCache("cache2", false, false, true, false, false);
cache2.create();
cache2.start();
-
+
//Vladimir October 5th 2007
//failure of integration of persistent state is not considered to be fatal
//to revisit with Manik
@@ -196,7 +196,7 @@
protected void initialStateTferWithLoaderTest(boolean asyncLoader) throws Exception
{
initialStateTferWithLoaderTest("org.jboss.cache.loader.FileCacheLoader",
- "org.jboss.cache.loader.FileCacheLoader", asyncLoader);
+ "org.jboss.cache.loader.FileCacheLoader", asyncLoader);
}
public void testPartialStateTransfer() throws Exception
@@ -361,10 +361,10 @@
Thread.currentThread().setContextClassLoader(getNotFoundClassLoader());
CacheSPI<Object, Object> cache1 = createCache("cache1",
- false, // async
- true, // use marshaller
- true, // use cacheloader
- false, false);// don't start
+ false, // async
+ true, // use marshaller
+ true, // use cacheloader
+ false, false);// don't start
ClassLoader cl1 = getClassLoader();
cache1.getRegion(A, true).registerContextClassLoader(cl1);
startCache(cache1);
@@ -377,10 +377,10 @@
// For cache 2 we won't register loader until later
CacheSPI<Object, Object> cache2 = createCache("cache2",
- false, // async
- true, // use marshalling
- true, // use cacheloader
- false, true);// start
+ false, // async
+ true, // use marshalling
+ true, // use cacheloader
+ false, true);// start
// Pause to give caches time to see each other
TestingUtil.blockUntilViewsReceived(new CacheSPI[]{cache1, cache2}, 60000);
@@ -408,20 +408,20 @@
private Object createBen(ClassLoader loader) throws Exception
{
Class addrClazz = loader.loadClass(ADDRESS_CLASSNAME);
- Method setCity = addrClazz.getMethod("setCity", new Class[]{String.class});
- Method setStreet = addrClazz.getMethod("setStreet", new Class[]{String.class});
- Method setZip = addrClazz.getMethod("setZip", new Class[]{int.class});
+ Method setCity = addrClazz.getMethod("setCity", String.class);
+ Method setStreet = addrClazz.getMethod("setStreet", String.class);
+ Method setZip = addrClazz.getMethod("setZip", int.class);
Object addr = addrClazz.newInstance();
- setCity.invoke(addr, new Object[]{"San Jose"});
- setStreet.invoke(addr, new Object[]{"1007 Home"});
- setZip.invoke(addr, new Object[]{90210});
+ setCity.invoke(addr, "San Jose");
+ setStreet.invoke(addr, "1007 Home");
+ setZip.invoke(addr, 90210);
Class benClazz = loader.loadClass(PERSON_CLASSNAME);
- Method setName = benClazz.getMethod("setName", new Class[]{String.class});
- Method setAddress = benClazz.getMethod("setAddress", new Class[]{addrClazz});
+ Method setName = benClazz.getMethod("setName", String.class);
+ Method setAddress = benClazz.getMethod("setAddress", addrClazz);
Object ben = benClazz.newInstance();
- setName.invoke(ben, new Object[]{"Ben"});
- setAddress.invoke(ben, new Object[]{addr});
+ setName.invoke(ben, "Ben");
+ setAddress.invoke(ben, addr);
return ben;
}
Modified: core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/statetransfer/StateTransferConcurrencyTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -82,7 +82,7 @@
* @param sync use REPL_SYNC or REPL_ASYNC
* @throws Exception
*/
- private void concurrentActivationTest(boolean sync) throws Exception
+ private void concurrentActivationTest(boolean sync)
{
String[] names = {"A", "B", "C", "D", "E"};
int count = names.length;
@@ -135,8 +135,8 @@
{
Exception aException = activators[i].getException();
boolean gotUnexpectedException = aException != null
- && !(aException instanceof InactiveRegionException ||
- aException.getCause() instanceof InactiveRegionException);
+ && !(aException instanceof InactiveRegionException ||
+ aException.getCause() instanceof InactiveRegionException);
if (gotUnexpectedException)
{
fail("Activator " + names[i] + " caught an exception " + aException);
@@ -146,7 +146,7 @@
{
Fqn fqn = new Fqn<String>(A_B, names[j]);
assertEquals("Incorrect value for " + fqn + " on activator " + names[i],
- "VALUE", activators[i].getCacheValue(fqn));
+ "VALUE", activators[i].getCacheValue(fqn));
// System.out.println(names[i] + ":" + fqn + " = " + activators[i].getCacheValue(fqn));
}
}
@@ -183,7 +183,7 @@
* @param sync use REPL_SYNC or REPL_ASYNC
* @throws Exception
*/
- private void concurrentActivationTest2(boolean sync) throws Exception
+ private void concurrentActivationTest2(boolean sync)
{
String[] names = {"A", "B"};
int count = names.length;
@@ -238,8 +238,8 @@
{
Exception aException = activators[i].getException();
boolean gotUnexpectedException = aException != null
- && !(aException instanceof InactiveRegionException ||
- aException.getCause() instanceof InactiveRegionException);
+ && !(aException instanceof InactiveRegionException ||
+ aException.getCause() instanceof InactiveRegionException);
if (gotUnexpectedException)
{
fail("Activator " + names[i] + " caught an exception " + aException);
@@ -249,7 +249,7 @@
{
Fqn fqn = Fqn.fromString("/a/" + i + "/" + names[i]);
assertEquals("Incorrect value for " + fqn + " on activator " + names[i],
- "VALUE", activators[i].getCacheValue(fqn));
+ "VALUE", activators[i].getCacheValue(fqn));
}
}
}
@@ -434,8 +434,8 @@
{
Fqn fqn = Fqn.fromString("/" + names[i] + "/" + j);
assertEquals("/A/" + j + " matches " + fqn,
- cacheA.get(fqn, "KEY"),
- stressors[i].getCacheSPI().get(fqn, "KEY"));
+ cacheA.get(fqn, "KEY"),
+ stressors[i].getCacheSPI().get(fqn, "KEY"));
}
}
}
@@ -482,10 +482,10 @@
Region region = cache2.getRegion(Fqn.ROOT, false);
// We expect events for /a, /a/b and /a/b/c
int nodeEventQueueSize = region.nodeEventQueueSize();
- int i=0;
+ int i = 0;
while (region.nodeEventQueueSize() > 0)
{
- System.out.println(++i+") Queue contains : " + region.takeLastEventNode());
+ System.out.println(++i + ") Queue contains : " + region.takeLastEventNode());
}
assertEquals("Saw the expected number of node events", 3, nodeEventQueueSize);
@@ -658,7 +658,7 @@
CacheActivator(Semaphore semaphore,
String name,
boolean sync, CacheSPI[] caches)
- throws Exception
+ throws Exception
{
super(semaphore, name, sync, false);
this.caches = caches;
@@ -683,10 +683,9 @@
* A activates the /a/b
* A puts something in /a/b and replicates
* B fails to accept the replication as it has the /a/b region inactive.
- *
+ * <p/>
* So we cannot expect all the put operation to replicate accross all the members from the cluser, WITHOUTH
* having the region active on ALL members.
- *
*/
private void waitUntillAllChachesActivatedRegion()
{
@@ -721,7 +720,7 @@
String name,
boolean sync,
int regionCount)
- throws Exception
+ throws Exception
{
super(semaphore, name, sync, false);
this.regionCount = regionCount;
@@ -755,7 +754,7 @@
CacheStressor(Semaphore semaphore,
String name,
boolean sync)
- throws Exception
+ throws Exception
{
super(semaphore, name, sync, true);
}
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/AbortionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/AbortionTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/AbortionTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,35 +6,30 @@
*/
package org.jboss.cache.transaction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotSame;
-import static org.testng.AssertJUnit.assertSame;
-import static org.testng.AssertJUnit.assertTrue;
-
-import javax.transaction.RollbackException;
-import javax.transaction.Synchronization;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
-import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.interceptors.OrderedSynchronizationHandler;
import org.jboss.cache.misc.TestingUtil;
import org.jboss.cache.transaction.NotifyingTransactionManager.Notification;
-import org.jgroups.Channel;
import org.jgroups.JChannel;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.RollbackException;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
/**
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
-@Test(groups={"functional"})
+@Test(groups = {"functional"})
public class AbortionTest
{
- private MyTC cache1, cache2, cache3;
+ private CacheSPI cache1, cache2, cache3;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
@@ -60,9 +55,9 @@
System.out.println("********* END: TEAR DOWN *************");
}
- private MyTC initCache(boolean notifying) throws Exception
+ private CacheSPI initCache(boolean notifying)
{
- MyTC c = new MyTC();
+ CacheSPI c = (CacheSPI) DefaultCacheFactory.getInstance().createCache(false);
c.getConfiguration().setCacheMode("REPL_SYNC");
c.getConfiguration().setClusterConfig(getJGroupsStack());
c.getConfiguration().setFetchInMemoryState(false);
@@ -81,19 +76,10 @@
// we need a 'special' stack that does not attempt redelivery since we kill a channel midway during a tx in this test.
private String getJGroupsStack()
{
- // return "UDP(mcast_addr=224.0.0.36;mcast_port=55566;ip_ttl=32;" +
- // "mcast_send_buf_size=150000;mcast_recv_buf_size=80000):" +
- // "PING(timeout=10;num_initial_members=1):" +
- // "pbcast.NAKACK(gc_lag=50;max_xmit_size=8192;retransmit_timeout=10):" +
- // "UNICAST(timeout=600):" +
- // "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";
return JChannel.DEFAULT_PROTOCOL_STACK;
}
- private void destroyCache(MyTC c)
+ private void destroyCache(CacheSPI c)
{
if (c != null)
{
@@ -134,7 +120,7 @@
TransactionManager mgr1 = cache1.getTransactionManager();
TransactionManager mgr2 = cache2.getTransactionManager();
assertTrue(cache3.getTransactionManager() instanceof NotifyingTransactionManager);
- NotifyingTransactionManager mgr3 = (NotifyingTransactionManager)cache3.getTransactionManager();
+ NotifyingTransactionManager mgr3 = (NotifyingTransactionManager) cache3.getTransactionManager();
assertSame(mgr1, mgr2);
assertNotSame(mgr1, mgr3);
@@ -179,13 +165,14 @@
final Transaction finalTx = tx;
System.out.println("Notify called.");
// add an aborting sync handler.
- Synchronization abort = new Synchronization() {
+ Synchronization abort = new Synchronization()
+ {
public void beforeCompletion()
{
if (abortBeforeCompletion)
{
- cache3.myChannel.close();
+ cache3.getConfiguration().getRuntimeConfig().getChannel().close();
System.out.println("Returning from abort.beforeCompletion");
try
{
@@ -203,7 +190,7 @@
{
if (!abortBeforeCompletion)
{
- cache3.myChannel.close();
+ cache3.getConfiguration().getRuntimeConfig().getChannel().close();
System.out.println("Returning from abort.afterCompletion");
throw new RuntimeException("Dummy exception");
}
@@ -216,23 +203,4 @@
}
}
-
- ;
-
- public static class MyTC extends CacheImpl<Object, Object>
- {
- Channel myChannel;
-
- public MyTC() throws Exception
- {
- super();
- }
-
- public void start() throws CacheException
- {
- super.start();
- myChannel = channel;
- }
- }
-
}
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/AsyncRollbackTxTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/AsyncRollbackTxTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/AsyncRollbackTxTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,32 +1,28 @@
package org.jboss.cache.transaction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
-
-import javax.transaction.SystemException;
-import javax.transaction.TransactionManager;
-
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+
/**
* Test behaviour of async rollback timeouted transaction
*
* @author <a href="mailto:jhalat@infovide.pl">Jacek Halat</a>
* @since 1.4.0
*/
-@Test(groups={"functional"})
+@Test(groups = {"functional"})
public class AsyncRollbackTxTest
{
- private CacheImpl<String, String> cache;
+ private CacheSPI<String, String> cache;
private TransactionManager tm;
private Fqn fqn = Fqn.fromString("/test");
// This sleep time (millis) should be longer than the transaction timeout time.
@@ -40,7 +36,7 @@
Configuration c = new Configuration();
c.setTransactionManagerLookupClass("org.jboss.cache.transaction.AsyncRollbackTransactionManagerLookup");
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache = (CacheImpl<String, String>)instance.createCache(c);
+ cache = (CacheSPI<String, String>) instance.createCache(c);
tm = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
tm.setTransactionTimeout(txTimeout);
}
@@ -240,5 +236,4 @@
}
}
- ;
}
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/ConcurrentBankTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/ConcurrentBankTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/ConcurrentBankTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,28 +1,27 @@
package org.jboss.cache.transaction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Set;
-
-import javax.transaction.UserTransaction;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.Fqn;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.TimeoutException;
import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.CachePrinter;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.fail;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.UserTransaction;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+
/**
* Unit test for local CacheImpl with concurrent transactions.
* Uses locking and multiple threads to test concurrent r/w access to the tree.
@@ -31,15 +30,15 @@
* @author Ben Wang
* @version $Revision$
*/
-@Test(groups = { "functional", "transaction" }, enabled = false)
+@Test(groups = {"functional", "transaction"}, enabled = false)
public class ConcurrentBankTest
{
- private CacheImpl<Object, Integer> cache;
+ private CacheSPI<Object, Integer> cache;
private static Log logger_ = LogFactory.getLog(ConcurrentBankTest.class);
- private final String NODE = "/cachetest";
+ private final Fqn NODE = Fqn.fromString("/cachetest");
private final int ROLLBACK_CHANCE = 100;
- private static String customer[] = { "cu1", "cu2", "cu3" };
+ private static String customer[] = {"cu1", "cu2", "cu3"};
private static final int BOOKINGS = 1000;
private static boolean _testFailedinThread = false;
@@ -52,10 +51,8 @@
public void setUp() throws Exception
{
CacheFactory<Object, Integer> instance = DefaultCacheFactory.getInstance();
- cache = (CacheImpl<Object, Integer>)instance.createCache(false);
+ cache = (CacheSPI<Object, Integer>) instance.createCache("META-INF/local-lru-eviction-service.xml", false);
- cache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/local-lru-eviction-service.xml"));
-
// XML file above only sets REPEATABLE-READ
cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
@@ -78,7 +75,7 @@
Teller one, two;
try
{
- if (cache.get(NODE) == null)
+ if (cache.getRoot().get(NODE) == null)
{
cache.put(NODE, "cu1", 1000);
cache.put(NODE, "cu2", 1000);
@@ -89,12 +86,12 @@
two = new Teller("two", cache);
one.start();
- TestingUtil.sleepThread((long)100);
+ TestingUtil.sleepThread((long) 100);
two.start();
one.join();
two.join();
- log("lock info:\n" + cache.printLockInfo() + _testFailedinThread);
+ log("lock info:\n" + CachePrinter.printCacheLockingInfo(cache) + _testFailedinThread);
if (_testFailedinThread)
fail();
}
@@ -124,9 +121,9 @@
private class Teller extends Thread
{
- CacheImpl<Object, Integer> cache;
+ CacheSPI<Object, Integer> cache;
- public Teller(String str, CacheImpl<Object, Integer> cache)
+ public Teller(String str, CacheSPI<Object, Integer> cache)
{
super(str);
this.cache = cache;
@@ -149,9 +146,9 @@
{
if (!again)
{
- src = (int)(Math.random() * count);
- dst = (int)(Math.random() * (count - 1));
- amo = 1 + (int)(Math.random() * 20);
+ src = (int) (Math.random() * count);
+ dst = (int) (Math.random() * (count - 1));
+ amo = 1 + (int) (Math.random() * 20);
if (dst >= src)
dst++;
}
@@ -213,7 +210,7 @@
log("deposit(" + from + ", " + to + ", " + amount + ") debited.");
// eventually rollback the transaction
- if ((int)(Math.random() * ROLLBACK_CHANCE) == 0)
+ if ((int) (Math.random() * ROLLBACK_CHANCE) == 0)
{
log("!!!manually set rollback (" + from + ", " + to + ", " + amount + ").");
tx.setRollbackOnly();
@@ -236,7 +233,7 @@
HashMap<Object, Integer> result = new HashMap<Object, Integer>();
try
{
- Set set = cache.getKeys(NODE);// gets read lock
+ Set set = cache.getRoot().getChild(NODE).getKeys();// gets read lock
for (Object name : set)
{
result.put(name, cache.get(NODE, name));
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/ConcurrentTransactionalTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/ConcurrentTransactionalTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/ConcurrentTransactionalTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -7,39 +7,37 @@
*/
package org.jboss.cache.transaction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import javax.transaction.UserTransaction;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.lock.IsolationLevel;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.fail;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.UserTransaction;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
/**
- * Unit test for local CacheImpl. Use locking and multiple threads to test
+ * Unit test for local CacheSPI. Use locking and multiple threads to test
* concurrent access to the tree.
*
* @version $Id$
*/
-@Test(groups = { "functional", "transaction" })
+@Test(groups = {"functional", "transaction"})
public class ConcurrentTransactionalTest
{
- private CacheImpl<Integer, String> cache;
+ private CacheSPI<Integer, String> cache;
private Log logger_ = LogFactory.getLog(ConcurrentTransactionalTest.class);
private static Throwable thread_ex = null;
private static final int NUM = 10000;
@@ -49,11 +47,10 @@
{
}
- private void createCache(IsolationLevel level) throws Exception
+ private void createCache(IsolationLevel level)
{
CacheFactory<Integer, String> factory = DefaultCacheFactory.getInstance();
- cache = (CacheImpl<Integer, String>)factory.createCache(false);
- cache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/local-service.xml"));
+ cache = (CacheSPI<Integer, String>) factory.createCache(new XmlConfigurationParser().parseFile("META-INF/local-service.xml"), false);
cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
cache.getConfiguration().setIsolationLevel(level);
@@ -103,7 +100,7 @@
log("*** Time elapsed: " + (now - current));
System.out.println("cache content: " + cache.toString());
- Set<Integer> keys = cache.getKeys(Fqn.fromString("/a/b/c"));
+ Set<Integer> keys = cache.getNode(Fqn.fromString("/a/b/c")).getKeys();
System.out.println("number of keys=" + keys.size());
if (keys.size() != NUM)
@@ -144,8 +141,6 @@
}
assertEquals(NUM, keys.size());
- log("lock info:\n" + cache.printLockInfo());
-
}
catch (Exception e)
{
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/DeadlockTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/DeadlockTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/DeadlockTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -8,16 +8,11 @@
package org.jboss.cache.transaction;
-import javax.transaction.NotSupportedException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
@@ -25,20 +20,25 @@
import org.jboss.cache.lock.TimeoutException;
import org.jboss.cache.lock.UpgradeException;
import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.CachePrinter;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.NotSupportedException;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+
/**
* Tests transactional access to a local CacheImpl, with concurrent (deadlock-prone) access.
* Note: we use DummpyTranasctionManager to replace jta
*
* @version $Id$
*/
-@Test(groups = { "functional", "transaction" })
+@Test(groups = {"functional", "transaction"})
public class DeadlockTest
{
- CacheImpl<String, String> cache = null;
+ CacheSPI<String, String> cache = null;
Exception thread_ex;
final Fqn NODE = Fqn.fromString("/a/b/c");
@@ -51,7 +51,7 @@
public void setUp() throws Exception
{
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache = (CacheImpl<String, String>)instance.createCache(false);
+ cache = (CacheSPI<String, String>) instance.createCache(false);
cache.getConfiguration().setStateRetrievalTimeout(10000);
cache.getConfiguration().setClusterName("test");
cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
@@ -87,14 +87,14 @@
t1.start();
t2.start();
- TestingUtil.sleepThread((long)5000);
+ TestingUtil.sleepThread((long) 5000);
synchronized (t1)
{
t1.notify();// t1 will now try to upgrade RL to WL, but fails b/c t2 still has a RL
}
- TestingUtil.sleepThread((long)5000);
+ TestingUtil.sleepThread((long) 5000);
synchronized (t2)
{
@@ -120,14 +120,14 @@
t1.start();
t2.start();
- TestingUtil.sleepThread((long)1000);
+ TestingUtil.sleepThread((long) 1000);
synchronized (t1)
{
t1.notify();// t1 will now try to acquire WL on /1/2/3 (held by t2) - this will time out
}
- TestingUtil.sleepThread((long)1000);
+ TestingUtil.sleepThread((long) 1000);
synchronized (t2)
{
@@ -221,8 +221,8 @@
upgraders[i].start();
}
- TestingUtil.sleepThread((long)1000);
- log("locks: " + cache.printLockInfo());
+ TestingUtil.sleepThread((long) 1000);
+ log("locks: " + CachePrinter.printCacheLockingInfo(cache));
synchronized (lock)
{
@@ -242,7 +242,7 @@
ContinuousRemover remover = new ContinuousRemover("Remover", PARENT_NODE);
putter.start();
remover.start();
- TestingUtil.sleepThread((long)5000);
+ TestingUtil.sleepThread((long) 5000);
log("stopping Putter");
putter.looping = false;
log("stopping Remover");
@@ -257,7 +257,7 @@
ContinuousRemover remover = new ContinuousRemover("Remover", NODE);
putter.start();
remover.start();
- TestingUtil.sleepThread((long)5000);
+ TestingUtil.sleepThread((long) 5000);
log("stopping Putter");
putter.looping = false;
log("stopping Remover");
@@ -272,7 +272,7 @@
ContinuousRemover remover = new ContinuousRemover("Remover", NODE);
putter.start();
remover.start();
- TestingUtil.sleepThread((long)5000);
+ TestingUtil.sleepThread((long) 5000);
log("stopping Putter");
putter.looping = false;
log("stopping Remover");
@@ -349,7 +349,7 @@
}
tm = startTransaction();
log("remove(" + fqn + ")");
- cache.remove(fqn);
+ cache.removeNode(fqn);
sleep(random(20));
tm.commit();
}
@@ -409,7 +409,7 @@
private static long random(long range)
{
- return (long)((Math.random() * 100000) % range) + 1;
+ return (long) ((Math.random() * 100000) % range) + 1;
}
class MyThread extends GenericThread
@@ -427,7 +427,7 @@
tm = startTransaction();
log("get(" + fqn + ")");
cache.get(fqn, "bla");// acquires RL
- log("done, locks: " + cache.printLockInfo());
+ log("done, locks: " + CachePrinter.printCacheLockingInfo(cache));
synchronized (this)
{
@@ -436,9 +436,9 @@
log("put(" + fqn + ")");
cache.put(fqn, "key", "val");// need to upgrade RL to WL
- log("done, locks: " + cache.printLockInfo());
+ log("done, locks: " + CachePrinter.printCacheLockingInfo(cache));
tm.commit();
- log("committed TX, locks: " + cache.printLockInfo());
+ log("committed TX, locks: " + CachePrinter.printCacheLockingInfo(cache));
}
}
@@ -473,9 +473,9 @@
log("put(" + fqn + ")");
cache.put(fqn, "key", "val");// need to upgrade RL to WL
- log("done, locks: " + cache.printLockInfo());
+ log("done, locks: " + CachePrinter.printCacheLockingInfo(cache));
tm.commit();
- log("committed TX, locks: " + cache.printLockInfo());
+ log("committed TX, locks: " + CachePrinter.printCacheLockingInfo(cache));
}
catch (UpgradeException upge)
{
@@ -503,13 +503,13 @@
{
log("received UpgradeException as expected");
tm.rollback();
- log("rolled back TX, locks: " + cache.printLockInfo());
+ log("rolled back TX, locks: " + CachePrinter.printCacheLockingInfo(cache));
}
catch (TimeoutException timeoutEx)
{
log("received TimeoutException as expected");
tm.rollback();
- log("rolled back TX, locks: " + cache.printLockInfo());
+ log("rolled back TX, locks: " + CachePrinter.printCacheLockingInfo(cache));
}
}
}
@@ -530,16 +530,16 @@
tm = startTransaction();
log("put(" + fqn1 + ")");
cache.put(fqn1, "key", "val");// need to upgrade RL to WL
- log("done, locks: " + cache.printLockInfo());
+ log("done, locks: " + CachePrinter.printCacheLockingInfo(cache));
synchronized (this)
{
wait();
}
log("put(" + fqn2 + ")");
cache.put(fqn2, "key", "val");// need to upgrade RL to WL
- log("done, locks: " + cache.printLockInfo());
+ log("done, locks: " + CachePrinter.printCacheLockingInfo(cache));
tm.commit();
- log("committed TX, locks: " + cache.printLockInfo());
+ log("committed TX, locks: " + CachePrinter.printCacheLockingInfo(cache));
}
}
@@ -561,7 +561,7 @@
{
log("received TimeoutException as expected");
tm.rollback();
- log("rolled back TX, locks: " + cache.printLockInfo());
+ log("rolled back TX, locks: " + CachePrinter.printCacheLockingInfo(cache));
}
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/InvocationContextCleanupTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/InvocationContextCleanupTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/InvocationContextCleanupTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,35 +6,35 @@
*/
package org.jboss.cache.transaction;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.interceptors.OrderedSynchronizationHandler;
+import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.util.CachePrinter;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
-import org.jboss.cache.CacheImpl;
-import org.jboss.cache.DefaultCacheFactory;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.interceptors.OrderedSynchronizationHandler;
-import org.jboss.cache.misc.TestingUtil;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.Test;
-
/**
* Tests cleaning of invocation contexts on completion of txs
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
-@Test(groups={"functional", "transaction"})
+@Test(groups = {"functional", "transaction"})
public class InvocationContextCleanupTest
{
- private CacheImpl[] caches;
+ private CacheSPI[] caches;
- private CacheImpl<Object, Object> createCache(boolean optimistic) throws Exception
+ private CacheSPI<?, ?> createCache(boolean optimistic)
{
- CacheImpl<Object, Object> cache = (CacheImpl<Object, Object>)DefaultCacheFactory.getInstance().createCache(false);
+ CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) DefaultCacheFactory.getInstance().createCache(false);
cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
if (optimistic)
cache.getConfiguration().setNodeLockingScheme("OPTIMISTIC");
@@ -69,9 +69,9 @@
private void test2CachesSync(boolean optimistic) throws Exception
{
- caches = new CacheImpl[2];
- CacheImpl<Object, Object> cache0 = createCache(optimistic);
- CacheImpl<Object, Object> cache1 = createCache(optimistic);
+ caches = new CacheSPI[2];
+ CacheSPI cache0 = createCache(optimistic);
+ CacheSPI cache1 = createCache(optimistic);
caches[0] = cache0;
caches[1] = cache1;
@@ -93,18 +93,18 @@
{
}
- System.out.println(caches[0].printLockInfo());
- System.out.println(caches[1].printLockInfo());
+ System.out.println(CachePrinter.printCacheLockingInfo(caches[0]));
+ System.out.println(CachePrinter.printCacheLockingInfo(caches[1]));
assertEquals("y", cache0.get("/test", "x"));
assertEquals("y", cache0.get("/test", "x"));
}
public static class DummySynchronization implements Synchronization
{
- private CacheImpl<Object, Object> cache;
+ private CacheSPI cache;
private TransactionManager mgr;
- public DummySynchronization(CacheImpl<Object, Object> cache, TransactionManager mgr)
+ public DummySynchronization(CacheSPI<?, ?> cache, TransactionManager mgr)
{
this.cache = cache;
this.mgr = mgr;
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelNoneTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelNoneTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelNoneTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,32 +1,31 @@
package org.jboss.cache.transaction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-
-import javax.transaction.NotSupportedException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+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.lock.IsolationLevel;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
+import javax.transaction.NotSupportedException;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+
/**
* Tests whether modifications within callbacks (TreeCacheListener) are handled correctly
*
* @author Bela Ban
* @version $Id$
*/
-@Test(groups={"functional", "transaction"})
+@Test(groups = {"functional", "transaction"})
public class IsolationLevelNoneTest
{
- CacheImpl<String, String> cache = null;
+ CacheSPI<String, String> cache = null;
final Fqn FQN = Fqn.fromString("/a/b/c");
final String KEY = "key";
final String VALUE = "value";
@@ -46,22 +45,22 @@
public void testWithoutTransactions() throws Exception
{
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache = (CacheImpl<String, String>)instance.createCache(false);
+ cache = (CacheSPI<String, String>) instance.createCache(false);
cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
cache.getConfiguration().setIsolationLevel(IsolationLevel.NONE);
cache.start();
cache.put(FQN, KEY, VALUE);
cache.put(FQN + "/d", KEY, VALUE);
- assertTrue(cache.exists(FQN, KEY));
+ Node node = cache.peek(FQN, false, false);
+ assertTrue(node != null && node.getKeys().contains(KEY));
assertEquals(VALUE, cache.get(FQN, KEY));
- System.out.println("cache: " + cache.toString(true) + ", locks: " + cache.printLockInfo());
assertEquals(0, cache.getNumberOfLocksHeld());
}
public void testWithTransactions() throws Exception
{
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache = (CacheImpl<String, String>)instance.createCache(false);
+ cache = (CacheSPI<String, String>) instance.createCache(false);
cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
cache.getConfiguration().setIsolationLevel(IsolationLevel.NONE);
cache.getConfiguration().setTransactionManagerLookupClass(TransactionSetup.getManagerLookup());
@@ -69,9 +68,9 @@
tm = startTransaction();
cache.put(FQN, KEY, VALUE);
cache.put(FQN + "/d", KEY, VALUE);
- assertTrue(cache.exists(FQN, KEY));
+ Node node = cache.peek(FQN, false, false);
+ assertTrue(node != null && node.getKeys().contains(KEY));
assertEquals(VALUE, cache.get(FQN, KEY));
- System.out.println("cache: " + cache.toString(true) + ", locks: " + cache.printLockInfo());
assertEquals(0, cache.getNumberOfLocksHeld());
tm.commit();
}
@@ -79,7 +78,7 @@
public void testWithTransactionsRepeatableRead() throws Exception
{
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache = (CacheImpl<String, String>)instance.createCache(false);
+ cache = (CacheSPI<String, String>) instance.createCache(false);
cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
cache.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
cache.getConfiguration().setTransactionManagerLookupClass(TransactionSetup.getManagerLookup());
@@ -87,9 +86,9 @@
tm = startTransaction();
cache.put(FQN, KEY, VALUE);
cache.put(FQN + "/d", KEY, VALUE);
- assertTrue(cache.exists(FQN, KEY));
+ Node node = cache.peek(FQN, false, false);
+ assertTrue(node != null && node.getKeys().contains(KEY));
assertEquals(VALUE, cache.get(FQN, KEY));
- System.out.println("cache: " + cache.toString(true) + ", locks: " + cache.printLockInfo());
assertEquals(5, cache.getNumberOfLocksHeld());
tm.commit();
}
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelReadCommittedNodeCreationRollbackTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelReadCommittedNodeCreationRollbackTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelReadCommittedNodeCreationRollbackTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -6,31 +6,25 @@
*/
package org.jboss.cache.transaction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import javax.transaction.NotSupportedException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import junit.framework.AssertionFailedError;
-
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.TimeoutException;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.NotSupportedException;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
/**
* Tests READ_COMMITED isolation level.
*
@@ -41,7 +35,7 @@
public class IsolationLevelReadCommittedNodeCreationRollbackTest
{
- private CacheImpl<String, String> cache = null;
+ private CacheSPI<String, String> cache = null;
private final String KEY = "key";
private final String VALUE = "value";
@@ -61,7 +55,7 @@
readerError = null;
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache = (CacheImpl<String, String>) instance.createCache(false);
+ cache = (CacheSPI<String, String>) instance.createCache(false);
cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
cache.getConfiguration().setIsolationLevel(IsolationLevel.READ_COMMITTED);
cache.getConfiguration().setTransactionManagerLookupClass(TransactionSetup.getManagerLookup());
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelReadCommittedTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelReadCommittedTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelReadCommittedTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,32 +1,25 @@
package org.jboss.cache.transaction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import javax.transaction.NotSupportedException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import junit.framework.AssertionFailedError;
-
import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.TimeoutException;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.NotSupportedException;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
/**
* Tests READ_COMMITED isolation level.
*
@@ -34,7 +27,7 @@
* @version $Id$
*/
-@Test(groups={"functional", "transaction"})
+@Test(groups = {"functional", "transaction"})
public class IsolationLevelReadCommittedTest
{
private Cache<String, String> cache = null;
@@ -95,7 +88,8 @@
// start a reader thread; need a transaction so its initial
// read lock is maintained while the writer does its work
- Thread readerThread = new Thread(new Runnable() {
+ Thread readerThread = new Thread(new Runnable()
+ {
public void run()
{
TransactionManager tm = null;
@@ -160,7 +154,8 @@
// start a writer thread and a transaction
- Thread writerThread = new Thread(new Runnable() {
+ Thread writerThread = new Thread(new Runnable()
+ {
public void run()
{
try
@@ -247,7 +242,8 @@
// start a writer thread and a transaction
- Thread writerThread = new Thread(new Runnable() {
+ Thread writerThread = new Thread(new Runnable()
+ {
public void run()
{
try
@@ -305,7 +301,7 @@
// wait for the writer to finish
writerDone.await();
- assertNull("Node was removed", ((CacheImpl<String, String>)cache).get(FQN));
+ assertNull("Node was removed", cache.getNode(FQN));
// If any assertion failed, throw on the AssertionFailedError
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelRepeatableReadTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelRepeatableReadTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelRepeatableReadTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,39 +1,33 @@
package org.jboss.cache.transaction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.concurrent.CountDownLatch;
-
-import javax.transaction.NotSupportedException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import junit.framework.AssertionFailedError;
-
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.TimeoutException;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.NotSupportedException;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import java.util.concurrent.CountDownLatch;
+
/**
* Tests READ_COMMITED isolation level.
*
* @author <a href="mailto:ovidiu@jboss.org">Ovidiu Feodorov</a>
* @version $Id$
*/
-@Test(groups={"functional", "transaction"})
+@Test(groups = {"functional", "transaction"})
public class IsolationLevelRepeatableReadTest
{
- private CacheImpl<String, String> cache = null;
+ private CacheSPI<String, String> cache = null;
private final Fqn FQN = Fqn.fromString("/a");
private final String KEY = "key";
private final String VALUE = "value";
@@ -48,7 +42,7 @@
writerError = null;
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache = (CacheImpl<String, String>)instance.createCache(false);
+ cache = (CacheSPI<String, String>) instance.createCache(false);
cache.getConfiguration().setCacheMode("LOCAL");
cache.getConfiguration().setIsolationLevel(IsolationLevel.REPEATABLE_READ);
cache.getConfiguration().setTransactionManagerLookupClass(TransactionSetup.getManagerLookup());
@@ -80,7 +74,8 @@
// start a writer thread and a transaction
- Thread writerThread = new Thread(new Runnable() {
+ Thread writerThread = new Thread(new Runnable()
+ {
public void run()
{
try
@@ -88,7 +83,7 @@
TransactionManager tm = startTransaction();
// change VALUE in a transaction
- cache.remove(FQN);
+ cache.removeNode(FQN);
// notify the reading thread
readerCanRead.countDown();
@@ -138,7 +133,7 @@
// wait for the writer to finish
writerDone.await();
- assertNull("Node was not removed", cache.get(FQN));
+ assertNull("Node was not removed", cache.getNode(FQN));
// If any assertion failed, throw on the AssertionFailedError
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelSerializableTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelSerializableTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/IsolationLevelSerializableTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,38 +1,31 @@
package org.jboss.cache.transaction;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.concurrent.CountDownLatch;
-
-import javax.transaction.NotSupportedException;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import junit.framework.AssertionFailedError;
-
import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.TimeoutException;
+import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.NotSupportedException;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+import java.util.concurrent.CountDownLatch;
+
/**
* Tests READ_COMMITED isolation level.
*
* @author <a href="mailto:ovidiu@jboss.org">Ovidiu Feodorov</a>
* @version $Id$
*/
-@Test(groups={"functional", "transaction"})
+@Test(groups = {"functional", "transaction"})
public class IsolationLevelSerializableTest
{
@@ -86,7 +79,8 @@
// start a writer thread and a transaction
- Thread writerThread = new Thread(new Runnable() {
+ Thread writerThread = new Thread(new Runnable()
+ {
public void run()
{
try
@@ -144,7 +138,7 @@
// wait for the writer to finish
writerDone.await();
- assertNull("Node was removed", ((CacheImpl<String, String>)cache).get(FQN));
+ assertNull("Node was removed", cache.getNode(FQN));
// If any assertion failed, throw on the AssertionFailedError
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/PrepareTxTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/PrepareTxTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/PrepareTxTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,36 +1,35 @@
package org.jboss.cache.transaction;
-import static org.testng.AssertJUnit.assertEquals;
-
-import javax.transaction.NotSupportedException;
-import javax.transaction.Synchronization;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
+import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.NotSupportedException;
+import javax.transaction.Synchronization;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
/**
* Created by IntelliJ IDEA.
* User: bela
* Date: Jun 9, 2004
* Time: 9:05:19 AM
*/
-@Test(groups={"functional", "transaction"})
+@Test(groups = {"functional", "transaction"})
public class PrepareTxTest
{
- CacheImpl<String, String> cache;
+ CacheSPI<String, String> cache;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache = (CacheImpl<String, String>)instance.createCache(false);
+ cache = (CacheSPI<String, String>) instance.createCache(false);
cache.getConfiguration().setCacheMode("local");
cache.getConfiguration().setTransactionManagerLookupClass(TransactionSetup.getManagerLookup());
cache.create();
@@ -51,7 +50,7 @@
* @throws Exception
* @throws NotSupportedException
*/
- public void testCacheModificationInBeforeCompletionPhase() throws Exception, NotSupportedException
+ public void testCacheModificationInBeforeCompletionPhase() throws Exception
{
int numLocks = 0;
TransactionManager mgr = cache.getTransactionManager();
@@ -60,19 +59,18 @@
// this will cause the cache to register with TransactionManager for TX completion callbacks
cache.put("/one/two/three", "key1", "val1");
- System.out.println("before commit:\n" + cache.printLockInfo());
numLocks = cache.getNumberOfLocksHeld();
assertEquals(4, numLocks);
// we register *second*
- tx.registerSynchronization(new Synchronization() {
+ tx.registerSynchronization(new Synchronization()
+ {
public void beforeCompletion()
{
try
{
cache.put("/a/b/c", null);
- System.out.println("before commit:\n" + cache.printLockInfo());
}
catch (CacheException e)
{
@@ -86,7 +84,6 @@
});
mgr.commit();
- System.out.println("after commit:\n" + cache.printLockInfo());
numLocks = cache.getNumberOfLocksHeld();
assertEquals(0, numLocks);
@@ -107,7 +104,7 @@
* @throws Exception
* @throws NotSupportedException
*/
- public void testCacheModificationInAfterCompletionPhase() throws Exception, NotSupportedException
+ public void testCacheModificationInAfterCompletionPhase() throws Exception
{
int numLocks = 0;
TransactionManager mgr = cache.getTransactionManager();
@@ -116,12 +113,12 @@
// this will cause the cache to register with TransactionManager for TX completion callbacks
cache.put("/one/two/three", "key1", "val1");
- System.out.println("before commit:\n" + cache.printLockInfo());
numLocks = cache.getNumberOfLocksHeld();
assertEquals(4, numLocks);
// we register *second*
- tx.registerSynchronization(new Synchronization() {
+ tx.registerSynchronization(new Synchronization()
+ {
public void beforeCompletion()
{
@@ -132,7 +129,6 @@
try
{
cache.put("/a/b/c", null);
- System.out.println("before commit:\n" + cache.printLockInfo());
}
catch (CacheException e)
{
@@ -142,7 +138,6 @@
});
mgr.commit();
- System.out.println("after commit:\n" + cache.printLockInfo());
numLocks = cache.getNumberOfLocksHeld();
assertEquals(0, numLocks);
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/ReplicatedTransactionDeadlockTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/ReplicatedTransactionDeadlockTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/ReplicatedTransactionDeadlockTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,26 +1,22 @@
package org.jboss.cache.transaction;
-import static org.testng.AssertJUnit.fail;
-
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.transaction.UserTransaction;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheFactory;
import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import static org.testng.AssertJUnit.fail;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.UserTransaction;
+
/**
* A test created to simulate an unexpected TimeoutException in JBossCache
* 1.3.0SP1 (not relevant for 1.2.4 and earlier releases). The error has been
@@ -65,7 +61,7 @@
* @author $Author$
* @version $Date$
*/
-@Test(groups={"functional", "transaction"})
+@Test(groups = {"functional", "transaction"})
public class ReplicatedTransactionDeadlockTest
{
@@ -86,7 +82,7 @@
/**
* The source cache where we put modifications.
*/
- private CacheImpl<Boolean, Boolean> srcCache = null;
+ private CacheSPI<Boolean, Boolean> srcCache = null;
/**
* The target cache where we replicate modifications.
*/
@@ -109,8 +105,7 @@
exception = null;
CacheFactory<Boolean, Boolean> instance = DefaultCacheFactory.getInstance();
// setup and start the source cache
- srcCache = (CacheImpl<Boolean, Boolean>)instance.createCache(false);
- srcCache.setConfiguration(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC));
+ srcCache = (CacheSPI<Boolean, Boolean>) instance.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
srcCache.getConfiguration().setTransactionManagerLookupClass(TransactionSetup.getManagerLookup());
srcCache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
@@ -119,8 +114,7 @@
srcCache.create();
srcCache.start();
// setup and start the destination cache
- dstCache = (CacheImpl)instance.createCache(false);
- dstCache.setConfiguration(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC));
+ dstCache = (CacheImpl) instance.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
dstCache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
dstCache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
@@ -189,9 +183,9 @@
* @return A user transaction.
* @throws Exception Any exception thrown by the context lookup.
*/
- private UserTransaction getTransaction() throws Exception
+ private UserTransaction getTransaction()
{
- return TransactionSetup.getUserTransaction();
+ return TransactionSetup.getUserTransaction();
}
/**
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/SuspendTxTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/SuspendTxTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/SuspendTxTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -1,35 +1,34 @@
package org.jboss.cache.transaction;
-import static org.testng.AssertJUnit.assertEquals;
-
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
+import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
/**
* Based on a contribution by Owen Taylor
*
* @author otaylor(a)redhat.com
* @author Manik Surtani (manik(a)jboss.org)
*/
-@Test(groups = { "functional", "transaction" })
+@Test(groups = {"functional", "transaction"})
public class SuspendTxTest
{
- CacheImpl<String, String> cache;
+ CacheSPI<String, String> cache;
TransactionManager mgr;
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
CacheFactory<String, String> instance = DefaultCacheFactory.getInstance();
- cache = (CacheImpl<String, String>)instance.createCache(false);
+ cache = (CacheSPI<String, String>) instance.createCache(false);
cache.getConfiguration().setCacheMode("local");
cache.getConfiguration().setTransactionManagerLookupClass(TransactionSetup.getManagerLookup());
cache.start();
Modified: core/trunk/src/test/java/org/jboss/cache/transaction/TransactionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/transaction/TransactionTest.java 2007-12-11 17:30:10 UTC (rev 4835)
+++ core/trunk/src/test/java/org/jboss/cache/transaction/TransactionTest.java 2007-12-11 17:34:04 UTC (rev 4836)
@@ -10,13 +10,15 @@
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
+import org.jboss.cache.factories.ComponentRegistry;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.NodeLock;
+import org.jboss.cache.misc.TestingUtil;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -40,10 +42,10 @@
*
* @version $Id$
*/
-@Test(groups={"functional", "transaction"})
+@Test(groups = {"functional", "transaction"})
public class TransactionTest
{
- CacheImpl<String, Comparable> cache = null;
+ CacheSPI cache = null;
UserTransaction tx = null;
Exception thread_ex;
@@ -52,7 +54,7 @@
{
CacheFactory<String, Comparable> instance = DefaultCacheFactory.getInstance();
- cache = (CacheImpl<String, Comparable>)instance.createCache(false);
+ cache = (CacheSPI) instance.createCache(false);
cache.getConfiguration().setClusterName("test");
cache.getConfiguration().setStateRetrievalTimeout(10000);
cache.getConfiguration().setIsolationLevel(IsolationLevel.SERIALIZABLE);
@@ -132,19 +134,20 @@
assertEquals(0, cache.getNumberOfLocksHeld());
assertTrue(cache.exists("/a/b"));
tx.begin();
- cache.remove("/a/b");
+ cache.removeNode("/a/b");
assertFalse(cache.exists("/a/b"));
tx.rollback();
assertTrue(cache.exists("/a/b"));
assertEquals(0, cache.getNumberOfLocksHeld());
// new tx in new thread
- Thread th = new Thread() {
+ Thread th = new Thread()
+ {
public void run()
{
try
{
cache.getTransactionManager().begin();
- assertNotNull(cache.get("/a/b"));
+ assertNotNull(cache.getNode("/a/b"));
cache.getTransactionManager().rollback();
}
catch (Exception e)
@@ -185,9 +188,7 @@
{
try
{
- System.out.println("locks " + cache.printLockInfo());
cache.put("/a/b/c", "age", 38);
- System.out.println("locks " + cache.printLockInfo());
tx.begin();
cache.remove("/a/b/c", "age");
tx.rollback();
@@ -235,7 +236,7 @@
map.put("age", 38);
tx.begin();
cache.put("/a/b/c", map);
- cache.remove("/a/b/c");
+ cache.removeNode("/a/b/c");
tx.rollback();
// This test is done outside the TX, it wouldn't work if someone else
@@ -260,7 +261,7 @@
tx.rollback();
System.out.println("after rollback():\n" + cache);
- assertNull("node should be not existent", cache.get("/bela/ban"));
+ assertNull("node should be not existent", cache.getNode("/bela/ban"));
}
catch (Throwable t)
{
@@ -277,8 +278,8 @@
tx.begin();
cache.put("/bela/ban/michelle", null);
tx.rollback();
- assertNotNull("node should be not null", cache.get("/bela/ban"));
- assertNull("node should be not existent", cache.get("/bela/ban/michelle"));
+ assertNotNull("node should be not null", cache.getNode("/bela/ban"));
+ assertNull("node should be not existent", cache.getNode("/bela/ban/michelle"));
}
catch (Throwable t)
{
@@ -293,16 +294,16 @@
{
cache.put("/a/b/c", null);
tx.begin();
- cache.remove("/a/b/c");
- assertNull(cache.get("/a/b/c"));
- cache.remove("/a/b");
- assertNull(cache.get("/a/b"));
- cache.remove("/a");
- assertNull(cache.get("/a"));
+ cache.removeNode("/a/b/c");
+ assertNull(cache.getNode("/a/b/c"));
+ cache.removeNode("/a/b");
+ assertNull(cache.getNode("/a/b"));
+ cache.removeNode("/a");
+ assertNull(cache.getNode("/a"));
tx.rollback();
- assertNotNull(cache.get("/a/b/c"));
- assertNotNull(cache.get("/a/b"));
- assertNotNull(cache.get("/a"));
+ assertNotNull(cache.getNode("/a/b/c"));
+ assertNotNull(cache.getNode("/a/b"));
+ assertNotNull(cache.getNode("/a"));
}
catch (Throwable t)
{
@@ -317,23 +318,23 @@
cache.put("/a/b/c1", null);
cache.put("/a/b/c2", null);
tx.begin();
- cache.remove("/a");
- assertNull(cache.get("/a/b/c"));
- assertNull(cache.get("/a/b/c1"));
- assertNull(cache.get("/a/b/c2"));
- assertNull(cache.get("/a/b"));
- assertNull(cache.get("/a"));
- Set children = cache.getChildrenNames("/a/b");
+ cache.removeNode("/a");
+ assertNull(cache.getNode("/a/b/c"));
+ assertNull(cache.getNode("/a/b/c1"));
+ assertNull(cache.getNode("/a/b/c2"));
+ assertNull(cache.getNode("/a/b"));
+ assertNull(cache.getNode("/a"));
+ Set children = cache.getChildrenNames(Fqn.fromString("/a/b"));
assertTrue(children.isEmpty());
children = cache.getChildrenNames("/a");
assertTrue(children.isEmpty());
tx.rollback();
- assertNotNull(cache.get("/a"));
- assertNotNull(cache.get("/a/b"));
- assertNotNull(cache.get("/a/b/c"));
- assertNotNull(cache.get("/a/b/c1"));
- assertNotNull(cache.get("/a/b/c2"));
- children = cache.getChildrenNames("/a/b");
+ assertNotNull(cache.getNode("/a"));
+ assertNotNull(cache.getNode("/a/b"));
+ assertNotNull(cache.getNode("/a/b/c"));
+ assertNotNull(cache.getNode("/a/b/c1"));
+ assertNotNull(cache.getNode("/a/b/c2"));
+ children = cache.getChildrenNames(Fqn.fromString("/a/b"));
assertEquals(3, children.size());
}
@@ -347,7 +348,6 @@
assertLocked(gtx, "/a", false);
assertLocked(gtx, "/a/b", true);
assertLocked(gtx, "/a/b/c", true);
- System.out.println("locks: " + cache.printLockInfo());
}
public void testNodeCreation2() throws Exception
@@ -359,7 +359,6 @@
assertLocked(gtx, "/a", true);
assertLocked(gtx, "/a/b", true);
assertLocked(gtx, "/a/b/c", true);
- System.out.println("locks: " + cache.printLockInfo());
}
public void testNodeRemoval()
@@ -370,12 +369,10 @@
cache.put("/a/b/c", null);
tx.begin();
gtx = cache.getCurrentTransaction();
- cache.remove("/a/b/c");// need to remove the node, not just the data in the node.
- System.out.println("Locks: " + cache.printLockInfo());
+ cache.removeNode("/a/b/c");// need to remove the node, not just the data in the node.
assertLocked(gtx, "/a", false);
assertLocked(gtx, "/a/b", true);
assertLocked(gtx, "/a/b/c", true);
- System.out.println("locks: " + cache.printLockInfo());
}
catch (Throwable t)
{
@@ -392,11 +389,10 @@
cache.put("/a/b/c", null);
tx.begin();
gtx = cache.getCurrentTransaction();
- cache.remove("/a/b");// need to remove the node, not just the data in the node.
+ cache.removeNode("/a/b");// need to remove the node, not just the data in the node.
assertLocked(gtx, "/a", true);
assertLocked(gtx, "/a/b", true);
assertLocked(gtx, "/a/b/c", true);
- System.out.println("locks: " + cache.printLockInfo());
}
catch (Throwable t)
{
@@ -423,7 +419,7 @@
{
cache.put("/a", null);
tx.begin();
- cache.get("/a/b/c");
+ cache.getNode("/a/b/c");
// expecting RLs on /, /a
// /a/b, /a/b/c should NOT be created!
@@ -442,7 +438,7 @@
{
cache.put("/a", null);
tx.begin();
- cache.remove("/a/b/c");
+ cache.removeNode("/a/b/c");
// expecting RLs on /, /a
// /a/b, /a/b/c should NOT be created!
@@ -495,12 +491,10 @@
assertLocked(gtx, "/a/b/c1/two/2/3", true);
assertLocked(gtx, "/a/b/c1/two/2/3/4", true);
- System.out.println("locks: " + cache.printLockInfo());
-
- cache.remove("/a/b");
+ cache.removeNode("/a/b");
tx.rollback();
assertTrue(cache.getChildrenNames("/a/b/c1").isEmpty());
- Set cn = cache.getChildrenNames("/a/b");
+ Set cn = cache.getChildrenNames(Fqn.fromString("/a/b"));
assertEquals(1, cn.size());
assertEquals("c1", cn.iterator().next());
}
@@ -512,21 +506,21 @@
cache.put("/a/b/c", null);
cache.put("/a/b/c", null);
- NodeSPI n = (NodeSPI)cache.get("/a");
+ NodeSPI n = (NodeSPI) cache.getNode("/a");
NodeLock lock = n.getLock();
int num = lock.getReaderOwners().size();
assertEquals(0, num);
// make sure this is write locked.
assertLocked(gtx, "/a", true);
- n = (NodeSPI)cache.get("/a/b");
+ n = (NodeSPI) cache.getNode("/a/b");
lock = n.getLock();
num = lock.getReaderOwners().size();
assertEquals(0, num);
// make sure this is write locked.
assertLocked(gtx, "/a/b", true);
- n = (NodeSPI)cache.get("/a/b/c");
+ n = (NodeSPI) cache.getNode("/a/b/c");
lock = n.getLock();
num = lock.getReaderOwners().size();
assertEquals(0, num);
@@ -537,7 +531,7 @@
assertEquals(0, cache.getNumberOfLocksHeld());
}
- private void assertLocked(Object owner, String fqn, boolean write_locked) throws Exception
+ private void assertLocked(Object owner, String fqn, boolean write_locked)
{
NodeSPI<String, Comparable> n = cache.peek(Fqn.fromString(fqn), true);
NodeLock lock = n.getLock();
@@ -561,18 +555,17 @@
{
cache.put("/a/b/c", null);
tx.begin();
- cache.remove("/a/b/c");
+ cache.removeNode("/a/b/c");
// this node should now be locked.
TransactionManager tm = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
Transaction t = tm.suspend();
Transaction t2;
- System.out.println(cache.printLockInfo());
// start a new tx
tm.begin();
t2 = tm.getTransaction();
try
{
- cache.get("/a/b/c");// should fail
+ cache.getNode("/a/b/c");// should fail
fail("Should not be able to get a hold of /a/b/c until the deleting tx completes");
}
catch (Exception e)
@@ -585,7 +578,7 @@
tm.resume(t);
tx.rollback();
- assertNotNull(cache.get("/a/b/c"));
+ assertNotNull(cache.getNode("/a/b/c"));
assertEquals(0, cache.getNumberOfLocksHeld());
}
@@ -593,16 +586,16 @@
{
cache.put("/a/b/c", null);
tx.begin();
- cache.remove("/a/b/c");
+ cache.removeNode("/a/b/c");
// this node should now be locked.
Transaction t = cache.getTransactionManager().suspend();
- Thread th = new Thread() {
+ Thread th = new Thread()
+ {
public void run()
{
try
{
- System.out.println(cache.printLockInfo());
- cache.get("/a/b/c");// should fail
+ cache.getNode("/a/b/c");// should fail
fail("Should not be able to get a hold of /a/b/c until the deleting tx completes");
}
@@ -619,10 +612,16 @@
cache.getTransactionManager().resume(t);
tx.rollback();
- assertNotNull(cache.get("/a/b/c"));
+ assertNotNull(cache.getNode("/a/b/c"));
assertEquals(0, cache.getNumberOfLocksHeld());
}
+ private Map getLockTable(CacheSPI c)
+ {
+ ComponentRegistry cr = TestingUtil.extractComponentRegistry(c);
+ return cr.getComponent("LockTable", Map.class);
+ }
+
public void testRemove() throws CacheException, SystemException, NotSupportedException, HeuristicMixedException, HeuristicRollbackException, RollbackException
{
cache.put("/a/b/c", null);
@@ -632,16 +631,14 @@
cache.put("/a/b/c/3/a/b/c", null);
assertEquals(0, cache.getNumberOfLocksHeld());
- assertEquals(0, cache.getLockTable().size());
+ assertEquals(0, getLockTable(cache).size());
tx.begin();
- cache.remove("/a/b/c");
- System.out.println("locks held (after removing /a/b/c): \n" + cache.printLockInfo());
+ cache.removeNode("/a/b/c");
// this used to test for 2 locks held. After the fixes for JBCACHE-875 however, 2 more locks are acquired - for the root node as well as the deleted node.
// and since we would lock all children of the deleted node as well, we have 10 locks here.
assertEquals(10, cache.getNumberOfLocksHeld());
tx.commit();
- System.out.println("locks held (after committing /a/b/c): \n" + cache.printLockInfo());
assertEquals(0, cache.getNumberOfLocksHeld());
}
@@ -655,15 +652,12 @@
cache.put("/a/b/c/3/a/b/c", null);
assertEquals(0, cache.getNumberOfLocksHeld());
- assertEquals(0, cache.getLockTable().size());
+ assertEquals(0, getLockTable(cache).size());
tx.begin();
- System.out.println("locks held (before removing /a/b/c): \n" + cache.printLockInfo());
- cache.remove("/a/b/c");
- System.out.println("locks held (after removing /a/b/c): \n" + cache.printLockInfo());
+ cache.removeNode("/a/b/c");
assertEquals(10, cache.getNumberOfLocksHeld());
tx.rollback();
- System.out.println("locks held (after rollback): \n" + cache.printLockInfo());
assertEquals(0, cache.getNumberOfLocksHeld());
assertTrue(cache.exists("/a/b/c"));
@@ -732,9 +726,9 @@
tx.begin();
cache.put("/foo/1", "item", 1);
assertEquals(cache.get("/foo/1", "item"), 1);
- cache.remove("/foo/1");
+ cache.removeNode("/foo/1");
assertNull(cache.get("/foo/1", "item"));
- cache.remove("/foo/1");
+ cache.removeNode("/foo/1");
assertNull(cache.get("/foo/1", "item"));
tx.rollback();
assertFalse(cache.exists("/foo/1"));
@@ -762,7 +756,7 @@
cache.put("/bela/ban", m);
tx.rollback();
- Node n = cache.get("/bela/ban");
+ Node n = cache.getNode("/bela/ban");
if (n.getData() == null)
return;
assertEquals("map should be empty", 0, n.getData().size());
@@ -793,14 +787,14 @@
tx.begin();
cache.put("/bela/ban", m2);
- Map tmp = cache.get("/bela/ban").getData();
+ Map tmp = cache.getNode("/bela/ban").getData();
assertEquals(3, tmp.size());
assertEquals("Michelle", tmp.get("name"));
assertEquals(tmp.get("id"), 322649);
assertEquals("bla", tmp.get("other"));
tx.rollback();
- tmp = cache.get("/bela/ban").getData();
+ tmp = cache.getNode("/bela/ban").getData();
assertEquals(2, tmp.size());
assertEquals("Bela", tmp.get("name"));
assertEquals(tmp.get("id"), 322649);
@@ -857,15 +851,15 @@
tx.begin();
cache.put(FQN, "entry", "rollback");
- cache.remove(FQN);
+ cache.removeNode(FQN);
tx.rollback();
- assertEquals("Node should keep the commited value", "commit", cache.get(FQN).get("entry"));
+ assertEquals("Node should keep the commited value", "commit", cache.getNode(FQN).get("entry"));
tx.begin();
- cache.remove(FQN);
+ cache.removeNode(FQN);
cache.put(FQN, "entry", "rollback");
tx.rollback();
- assertEquals("Node should keep the commited value", "commit", cache.get(FQN).get("entry"));// THIS FAILS
+ assertEquals("Node should keep the commited value", "commit", cache.getNode(FQN).get("entry"));// THIS FAILS
}
private TransactionManager startTransaction() throws Exception
@@ -964,7 +958,7 @@
assertTrue(cache.exists(A));
cache.getTransactionManager().begin();
- cache.remove(A);
+ cache.removeNode(A);
cache.get(A_B, "k");
cache.getTransactionManager().commit();
}
@@ -980,7 +974,7 @@
assertTrue(cache.exists(A));
cache.getTransactionManager().begin();
- cache.remove(A_B);
+ cache.removeNode(A_B);
cache.put(A_B, "k", "v2");
cache.getTransactionManager().commit();
@@ -1004,7 +998,7 @@
assertTrue(cache.exists(A));
cache.getTransactionManager().begin();
- cache.remove(A);
+ cache.removeNode(A);
cache.put(A_B, "k", "v2");
cache.getTransactionManager().commit();
@@ -1025,7 +1019,7 @@
assertTrue(cache.exists(A));
cache.getTransactionManager().begin();
- cache.remove(A);
+ cache.removeNode(A);
cache.put(A_B_C, "k", "v2");
cache.getTransactionManager().commit();
@@ -1051,7 +1045,7 @@
//remove all
tx.begin();
- this.cache.remove(root);
+ this.cache.removeNode(root);
tx.commit();
//get returns null - ok
@@ -1077,7 +1071,7 @@
//remove all
tx.begin();
- this.cache.remove(Fqn.ROOT);
+ this.cache.removeNode(Fqn.ROOT);
tx.commit();
//get returns null - ok
@@ -1105,7 +1099,7 @@
//remove all
tx.begin();
- this.cache.remove(root);
+ this.cache.removeNode(root);
tx.rollback();
assertEquals("v", this.cache.get(fqn, "k"));
17 years, 3 months
JBoss Cache SVN: r4835 - core/trunk/src/main/java/org/jboss/cache.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-11 12:30:10 -0500 (Tue, 11 Dec 2007)
New Revision: 4835
Modified:
core/trunk/src/main/java/org/jboss/cache/RegionManager.java
Log:
Removed dodgy import
Modified: core/trunk/src/main/java/org/jboss/cache/RegionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2007-12-11 17:28:33 UTC (rev 4834)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2007-12-11 17:30:10 UTC (rev 4835)
@@ -12,7 +12,6 @@
import org.jboss.cache.eviction.RegionNameConflictException;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.lock.NodeLock;
-import org.jboss.classadapter.spi.ClassAdapterFactory;
import org.jgroups.Address;
import java.util.ArrayList;
17 years, 3 months
JBoss Cache SVN: r4834 - in core/trunk/src/main/java/org/jboss/cache: buddyreplication and 12 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-11 12:28:33 -0500 (Tue, 11 Dec 2007)
New Revision: 4834
Added:
core/trunk/src/main/java/org/jboss/cache/factories/jgroups/
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/FqnComparator.java
core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java
core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java
core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java
core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java
core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java
core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionPolicy.java
core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeQueue.java
core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java
core/trunk/src/main/java/org/jboss/cache/eviction/LFUQueue.java
core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java
core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java
core/trunk/src/main/java/org/jboss/cache/loader/C3p0ConnectionFactory.java
core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoader.java
core/trunk/src/main/java/org/jboss/cache/loader/tcp/TcpCacheServer.java
core/trunk/src/main/java/org/jboss/cache/lock/IdentityLock.java
core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java
core/trunk/src/main/java/org/jboss/cache/lock/NodeLock.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/MethodCallFactory.java
core/trunk/src/main/java/org/jboss/cache/marshall/NodeDataMarker.java
core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java
core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferFactory.java
core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java
core/trunk/src/main/java/org/jboss/cache/transaction/BatchModeTransactionManager.java
core/trunk/src/main/java/org/jboss/cache/transaction/DummyContextFactory.java
core/trunk/src/main/java/org/jboss/cache/transaction/DummyTransactionManager.java
core/trunk/src/main/java/org/jboss/cache/transaction/JBossTransactionManagerLookup.java
core/trunk/src/main/java/org/jboss/cache/transaction/OptimisticTransactionEntry.java
core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java
Log:
Initial check in of injection and aop code
Modified: core/trunk/src/main/java/org/jboss/cache/CacheManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheManagerImpl.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/CacheManagerImpl.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -16,20 +16,20 @@
package org.jboss.cache;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.ConfigurationRegistry;
+import org.jboss.cache.config.XmlParsingConfigurationRegistry;
+import org.jgroups.ChannelFactory;
+
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.ConfigurationRegistry;
-import org.jboss.cache.config.XmlParsingConfigurationRegistry;
-import org.jgroups.ChannelFactory;
-
/**
* Basic implementation of {@link CacheManager}.
- *
+ *
* @author <a href="brian.stansberry(a)jboss.com">Brian Stansberry</a>
* @version $Revision: 1 $
*/
@@ -66,8 +66,8 @@
}
/**
- * Create a new CacheRegistryImpl using the provided ChannelFactory and
- * using the provided file name to create an
+ * Create a new CacheRegistryImpl using the provided ChannelFactory and
+ * using the provided file name to create an
* {@link XmlParsingConfigurationRegistry}.
*/
public CacheManagerImpl(String configFileName, ChannelFactory factory)
@@ -77,7 +77,7 @@
}
// ---------------------------------------------------------- CacheRegistry
-
+
public ChannelFactory getChannelFactory()
{
return channelFactory;
@@ -88,8 +88,8 @@
{
synchronized (caches)
{
- Set<String> configNames = configRegistry == null ? new HashSet<String>()
- : configRegistry.getConfigurationNames();
+ Set<String> configNames = configRegistry == null ? new HashSet<String>()
+ : configRegistry.getConfigurationNames();
configNames.addAll(getCacheNames());
return configNames;
}
@@ -108,11 +108,12 @@
Cache<Object, Object> cache = null;
synchronized (caches)
{
- cache = (Cache<Object, Object>) caches.get(configName);
+ cache = caches.get(configName);
if (cache == null && create)
{
Configuration config = configRegistry.getConfiguration(configName);
- if (channelFactory != null && config.getMultiplexerStack() != null) {
+ if (channelFactory != null && config.getMultiplexerStack() != null)
+ {
config.getRuntimeConfig().setMuxChannelFactory(channelFactory);
}
cache = DefaultCacheFactory.getInstance().createCache(config, false);
@@ -142,7 +143,7 @@
}
// ----------------------------------------------------------------- Public
-
+
public ConfigurationRegistry getConfigurationRegistry()
{
return configRegistry;
@@ -178,12 +179,12 @@
throw new IllegalStateException("Must configure a ConfigurationRegistry before calling start()");
if (channelFactory == null)
throw new IllegalStateException("Must provide a ChannelFactory before calling start()");
-
+
if (!configRegistryInjected)
{
((XmlParsingConfigurationRegistry) configRegistry).start();
}
-
+
started = true;
}
}
@@ -203,23 +204,23 @@
caches.clear();
checkouts.clear();
}
-
+
if (!configRegistryInjected)
{
((XmlParsingConfigurationRegistry) configRegistry).stop();
}
-
+
started = false;
}
}
// ---------------------------------------------------------------- Private
-
+
private int incrementCheckout(String configName)
{
synchronized (checkouts)
{
- Integer count = (Integer) checkouts.get(configName);
+ Integer count = checkouts.get(configName);
if (count == null)
count = new Integer(0);
Integer newVal = new Integer(count.intValue() + 1);
@@ -232,7 +233,7 @@
{
synchronized (checkouts)
{
- Integer count = (Integer) checkouts.get(configName);
+ Integer count = checkouts.get(configName);
if (count == null || count.intValue() < 1)
throw new IllegalStateException("invalid count of " + count + " for " + configName);
Modified: core/trunk/src/main/java/org/jboss/cache/FqnComparator.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/FqnComparator.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/FqnComparator.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -28,13 +28,6 @@
public static final FqnComparator INSTANCE = new FqnComparator();
/**
- * Sorts by name, then depth.
- */
- public FqnComparator()
- {
- }
-
- /**
* Returns -1 if the first comes before; 0 if they are the same; 1 if the
* second Fqn comes before. <code>null</code> always comes first.
*/
Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -61,7 +61,8 @@
/**
* A reference of the CacheImpl instance.
*/
- private transient CacheImpl<K, V> cache;
+ private transient CacheSPI<K, V> cache;
+ private transient CacheImpl cacheImpl;
/**
* Map of general data keys to values.
@@ -105,7 +106,7 @@
{
throw new IllegalArgumentException("no cache init for " + fqn);
}
- this.cache = (CacheImpl<K, V>) cache;
+ this.cache = cache;
this.fqn = fqn;
if (!fqn.isRoot() && !child_name.equals(fqn.getLastElement()))
{
@@ -166,7 +167,8 @@
childrenLoaded = flag;
}
- private void assertValid() {
+ private void assertValid()
+ {
if (!valid)
throw new NodeNotValidException("Node " + getFqn() + " is not valid. Perhaps it has been moved or removed.");
}
@@ -201,9 +203,11 @@
public Map<K, V> getData()
{
- assertValid();
- if (cache == null) return Collections.emptyMap();
- return cache.getData(getFqn());
+ // TODO: Fix this
+ throw new RuntimeException("Should never get here - use NodeInterceptorDelegate!");
+// assertValid();
+// if (cache == null) return Collections.emptyMap();
+// return cache.getData(getFqn());
}
public Map<K, V> getDataDirect()
@@ -261,9 +265,9 @@
children.put(child_name, child);
if (gtx != null)
{
- MethodCall undo_op = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, gtx,
- child_fqn, false);
- cache.addUndoOperation(gtx, undo_op);
+ MethodCall undo_op = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal,
+ gtx, child_fqn, false);
+ cacheImpl.addUndoOperation(gtx, undo_op);
// add the node name to the list maintained for the current tx
// (needed for abort/rollback of transaction)
// cache.addNode(gtx, child.getFqn());
@@ -383,8 +387,11 @@
public void clearData()
{
- assertValid();
- cache.removeData(getFqn());
+ // TODO: Fix this
+ throw new RuntimeException("Should never get here - use NodeInterceptorDelegate!");
+
+// assertValid();
+// cache.removeData(getFqn());
}
public void clearDataDirect()
@@ -394,8 +401,11 @@
public Node<K, V> getChild(Fqn fqn)
{
- assertValid();
- return cache.get(new Fqn(getFqn(), fqn));
+ // TODO: Fix this
+ throw new RuntimeException("Should never get here - use NodeInterceptorDelegate!");
+//
+// assertValid();
+// return cache.get(new Fqn(getFqn(), fqn));
}
public NodeSPI<K, V> getChildDirect(Fqn fqn)
@@ -419,8 +429,11 @@
public Set<Object> getChildrenNames()
{
- assertValid();
- return cache.getChildrenNames(getFqn());
+ // TODO: Fix this
+ throw new RuntimeException("Should never get here - use NodeInterceptorDelegate!");
+
+// assertValid();
+// return cache.getChildrenNames(getFqn());
}
public Set<Object> getChildrenNamesDirect()
@@ -430,9 +443,12 @@
public Set<K> getKeys()
{
- assertValid();
- Set<K> keys = cache.getKeys(getFqn());
- return keys == null ? Collections.<K>emptySet() : Collections.<K>unmodifiableSet(keys);
+ // TODO: Fix this
+ throw new RuntimeException("Should never get here - use NodeInterceptorDelegate!");
+
+// assertValid();
+// Set<K> keys = cache.getKeys(getFqn());
+// return keys == null ? Collections.<K>emptySet() : Collections.<K>unmodifiableSet(keys);
}
public Set<K> getKeysDirect()
@@ -508,8 +524,11 @@
public int dataSize()
{
- assertValid();
- return cache.getKeys(getFqn()).size();
+ // TODO: Fix this
+ throw new RuntimeException("Should never get here - use NodeInterceptorDelegate!");
+//
+// assertValid();
+// return cache.getKeys(getFqn()).size();
}
public boolean removeChild(Object childName)
@@ -555,8 +574,11 @@
public void replaceAll(Map<K, V> data)
{
- assertValid();
- cache.put(fqn, data, true);
+ // TODO: Fix this
+ throw new RuntimeException("Should never get here - use NodeInterceptorDelegate!");
+
+// assertValid();
+// cache.put(fqn, data, true);
}
public void putAllDirect(Map<K, V> data)
@@ -659,7 +681,10 @@
public Node<K, V> getChild(Object childName)
{
- return cache.get(new Fqn(getFqn(), childName));
+ // TODO: Fix this
+ throw new RuntimeException("Should never get here - use NodeInterceptorDelegate!");
+//
+// return cache.get(new Fqn(getFqn(), childName));
}
public NodeSPI<K, V> getChildDirect(Object childName)
@@ -670,15 +695,18 @@
public Set<Node<K, V>> getChildren()
{
- assertValid();
- if (cache == null) return Collections.emptySet();
- Set<Node<K, V>> children = new HashSet<Node<K, V>>();
- for (Object c : cache.getChildrenNames(getFqn()))
- {
- Node n = cache.get(new Fqn(getFqn(), c));
- if (n != null) children.add(n);
- }
- return Collections.unmodifiableSet(children);
+ // TODO: Fix this
+ throw new RuntimeException("Should never get here - use NodeInterceptorDelegate!");
+
+// assertValid();
+// if (cache == null) return Collections.emptySet();
+// Set<Node<K, V>> children = new HashSet<Node<K, V>>();
+// for (Object c : cache.getChildrenNames(getFqn()))
+// {
+// Node n = cache.get(new Fqn(getFqn(), c));
+// if (n != null) children.add(n);
+// }
+// return Collections.unmodifiableSet(children);
}
public Set<NodeSPI<K, V>> getChildrenDirect()
@@ -770,7 +798,7 @@
if (log.isTraceEnabled()) log.trace("Marking node " + getFqn() + " as " + (valid ? "" : "in") + "valid");
if (recursive)
{
- for (Node child: children().values())
+ for (Node child : children().values())
{
((UnversionedNode) child).setValid(valid, recursive);
}
Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -9,11 +9,15 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.RPCManager;
import org.jboss.cache.Region;
+import org.jboss.cache.RegionManager;
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.lock.TimeoutException;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodCallFactory;
@@ -32,16 +36,7 @@
import org.jgroups.util.Util;
import java.io.ByteArrayInputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Vector;
+import java.util.*;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
@@ -60,7 +55,7 @@
/**
* Configuration object.
*/
- final BuddyReplicationConfig config;
+ BuddyReplicationConfig config;
/**
* Buddy locator class
@@ -70,8 +65,11 @@
/**
* back-refernce to the CacheImpl object
*/
- private CacheImpl<?,?> cache;
-
+ private CacheSPI<?, ?> cache;
+ private Configuration configuration;
+ private RegionManager regionManager;
+ private StateTransferManager stateTransferManager;
+ private RPCManager rpcManager;
/**
* The buddy group set up for this instance
*/
@@ -133,8 +131,18 @@
private boolean receivedBuddyInfo;
+ public BuddyManager()
+ {
+ }
+
public BuddyManager(BuddyReplicationConfig config)
{
+ setupInternals(config);
+ }
+
+
+ private void setupInternals(BuddyReplicationConfig config)
+ {
this.config = config;
BuddyLocatorConfig blc = config.getBuddyLocatorConfig();
@@ -157,6 +165,18 @@
}
}
+ @Inject
+ private void injectDependencies(CacheSPI cache, Configuration configuration, RegionManager regionManager, StateTransferManager stateTransferManager, RPCManager rpcManager)
+ {
+ this.cache = cache;
+ this.configuration = configuration;
+ this.regionManager = regionManager;
+ this.stateTransferManager = stateTransferManager;
+ this.rpcManager = rpcManager;
+
+ setupInternals(configuration.getBuddyReplicationConfig());
+ }
+
public BuddyReplicationConfig getConfig()
{
return config;
@@ -210,10 +230,9 @@
}
}
- public void init(CacheImpl<?, ?> cache) throws CacheException
+ public void init() throws CacheException
{
log.debug("Starting buddy manager");
- this.cache = cache;
buddyGroup = new BuddyGroup();
buddyGroup.setDataOwner(cache.getLocalAddress());
buddyGroup.setGroupName(getGroupNameFromAddress(cache.getLocalAddress()));
@@ -367,7 +386,7 @@
if (buddyGroupMutated)
{
if (log.isInfoEnabled()) log.info("Buddy group members have changed. New buddy group: " + buddyGroup);
- cache.getConfiguration().getRuntimeConfig().setBuddyGroup(buddyGroup);
+ configuration.getRuntimeConfig().setBuddyGroup(buddyGroup);
}
else
log.debug("Nothing has changed; new buddy list is identical to the old one.");
@@ -382,7 +401,7 @@
*/
private List<Address> checkBuddyStatus(List<Address> members)
{
- Channel ch = cache.getConfiguration().getRuntimeConfig().getChannel();
+ Channel ch = configuration.getRuntimeConfig().getChannel();
View currentView = ch.getView();
List<Address> deadBuddies = new LinkedList<Address>();
for (Address a : members) if (!currentView.containsMember(a)) deadBuddies.add(a);
@@ -449,7 +468,7 @@
// should be a LOCAL call.
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- cache.remove(new Fqn(BUDDY_BACKUP_SUBTREE_FQN, groupName));
+ cache.removeNode(new Fqn(BUDDY_BACKUP_SUBTREE_FQN, groupName));
}
catch (CacheException e)
{
@@ -475,7 +494,8 @@
{
if (!initialisationLatch.await(0, TimeUnit.NANOSECONDS))
{
- if (log.isDebugEnabled()) log.debug("Local buddy mamanger not initialized, rejecting assign call " + newGroup);
+ if (log.isDebugEnabled())
+ log.debug("Local buddy mamanger not initialized, rejecting assign call " + newGroup);
throw new BuddyNotInitException("Not yet initialised");
}
}
@@ -489,14 +509,12 @@
// Integrate state transfer from the data owner of the buddy group
Fqn integrationBase = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN,
- newGroup.getGroupName());
+ newGroup.getGroupName());
- StateTransferManager stateMgr = cache.getStateTransferManager();
-
for (Map.Entry<Fqn, byte[]> entry : state.entrySet())
{
Fqn fqn = entry.getKey();
- if (!cache.getRegionManager().isInactive(fqn))
+ if (!regionManager.isInactive(fqn))
{
//ClassLoader cl = (marshaller == null) ? null : marshaller.getClassLoader(fqnS);
Fqn integrationRoot = new Fqn(integrationBase, fqn);
@@ -508,22 +526,22 @@
ByteArrayInputStream bais = new ByteArrayInputStream(stateBuffer);
in = new MarshalledValueInputStream(bais);
//stateMgr.setState(in, integrationRoot, cl);
- stateMgr.setState(in, integrationRoot);
+ stateTransferManager.setState(in, integrationRoot);
}
catch (Throwable t)
{
- if (t instanceof CacheException)
- {
- //excepected/common and can happen due to inactive regions and so on
- log.debug(t);
- }
- else
- {
- //something has gone wrong
- log.error("State for fqn " + fqn
- + " could not be transferred to a buddy at "
- + cache.getLocalAddress(), t);
- }
+ if (t instanceof CacheException)
+ {
+ //excepected/common and can happen due to inactive regions and so on
+ log.debug(t);
+ }
+ else
+ {
+ //something has gone wrong
+ log.error("State for fqn " + fqn
+ + " could not be transferred to a buddy at "
+ + cache.getLocalAddress(), t);
+ }
}
finally
{
@@ -535,7 +553,7 @@
}
}
}
-
+
/**
* Returns a List<IpAddress> identifying the DataOwner for each buddy
* group for which this node serves as a backup node.
@@ -549,8 +567,6 @@
}
return owners;
}
-
-
// -------------- static util methods ------------------
@@ -724,9 +740,9 @@
Map<Fqn, byte[]> stateMap = new HashMap<Fqn, byte[]>();
byte[] state;
- if (cache.getConfiguration().isUseRegionBasedMarshalling())
+ if (configuration.isUseRegionBasedMarshalling())
{
- Collection<Region> regions = cache.getRegionManager().getAllRegions(Region.Type.MARSHALLING);
+ Collection<Region> regions = regionManager.getAllRegions(Region.Type.MARSHALLING);
if (regions.size() > 0)
{
for (Region r : regions)
@@ -739,7 +755,7 @@
}
}
}
- else if (!cache.getConfiguration().isInactiveOnStartup())
+ else if (!configuration.isInactiveOnStartup())
{
// No regions defined; try the root
state = acquireState(Fqn.ROOT);
@@ -852,7 +868,7 @@
if (timeoutException != null)
{
throw new CacheException("acquireState(): Failed getting state due to timeout",
- timeoutException);
+ timeoutException);
}
if (log.isDebugEnabled())
@@ -891,7 +907,7 @@
{
ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(16 * 1024);
out = new MarshalledValueOutputStream(baos);
- cache.getStateTransferManager().getState(out, fqn, timeout, force, suppressErrors);
+ stateTransferManager.getState(out, fqn, timeout, force, suppressErrors);
result = baos.getRawBuffer();
}
finally
@@ -948,7 +964,7 @@
}
}
- cache.getRPCManager().callRemoteMethods(recipients, call, sync, true, config.getBuddyCommunicationTimeout());
+ rpcManager.callRemoteMethods(recipients, call, sync, true, config.getBuddyCommunicationTimeout());
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/config/BuddyReplicationConfig.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -47,10 +47,6 @@
private int buddyCommunicationTimeout = 10000;
private BuddyLocatorConfig buddyLocatorConfig;
- public BuddyReplicationConfig()
- {
- }
-
public boolean isAutoDataGravitation()
{
return autoDataGravitation;
@@ -138,12 +134,12 @@
{
BuddyReplicationConfig other = (BuddyReplicationConfig) obj;
return (this.autoDataGravitation == other.autoDataGravitation)
- && (this.dataGravitationRemoveOnFind == other.dataGravitationRemoveOnFind)
- && (this.dataGravitationSearchBackupTrees == other.dataGravitationSearchBackupTrees)
- && (this.enabled == other.enabled)
- && (this.buddyCommunicationTimeout == other.buddyCommunicationTimeout)
- && safeEquals(this.buddyPoolName, other.buddyPoolName)
- && safeEquals(this.buddyLocatorConfig, other.buddyLocatorConfig);
+ && (this.dataGravitationRemoveOnFind == other.dataGravitationRemoveOnFind)
+ && (this.dataGravitationSearchBackupTrees == other.dataGravitationSearchBackupTrees)
+ && (this.enabled == other.enabled)
+ && (this.buddyCommunicationTimeout == other.buddyCommunicationTimeout)
+ && safeEquals(this.buddyPoolName, other.buddyPoolName)
+ && safeEquals(this.buddyLocatorConfig, other.buddyLocatorConfig);
}
return false;
@@ -166,7 +162,7 @@
public BuddyReplicationConfig clone() throws CloneNotSupportedException
{
BuddyReplicationConfig clone = (BuddyReplicationConfig) super.clone();
- if (buddyLocatorConfig != null)
+ if (buddyLocatorConfig != null)
clone.setBuddyLocatorConfig(buddyLocatorConfig.clone());
return clone;
}
@@ -176,13 +172,8 @@
private static final long serialVersionUID = -8003634097931826091L;
private String buddyLocatorClass = NextMemberBuddyLocator.class.getName();
- ;
private Properties buddyLocatorProperties;
- public BuddyLocatorConfig()
- {
- }
-
public String getBuddyLocatorClass()
{
return buddyLocatorClass;
@@ -216,7 +207,7 @@
{
BuddyLocatorConfig other = (BuddyLocatorConfig) obj;
return (safeEquals(this.buddyLocatorClass, other.buddyLocatorClass)
- && safeEquals(this.buddyLocatorProperties, other.buddyLocatorProperties));
+ && safeEquals(this.buddyLocatorProperties, other.buddyLocatorProperties));
}
return false;
}
@@ -232,7 +223,7 @@
public String toString()
{
return super.toString() + " class=" + buddyLocatorClass +
- " properties=" + buddyLocatorProperties;
+ " properties=" + buddyLocatorProperties;
}
@Override
@@ -243,8 +234,7 @@
clone.buddyLocatorProperties = (Properties) buddyLocatorProperties.clone();
return clone;
}
-
-
+
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/config/CacheLoaderConfig.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -6,8 +6,8 @@
*/
package org.jboss.cache.config;
-import org.jboss.cache.xml.XmlHelper;
import org.jboss.cache.loader.SingletonStoreCacheLoader;
+import org.jboss.cache.xml.XmlHelper;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -33,10 +33,6 @@
private boolean shared;
- public CacheLoaderConfig()
- {
- }
-
public String getPreload()
{
return preload;
@@ -117,9 +113,9 @@
{
CacheLoaderConfig other = (CacheLoaderConfig) obj;
return (this.passivation == other.passivation)
- && (this.shared == other.shared)
- && safeEquals(this.preload, other.preload)
- && safeEquals(this.cacheLoaderConfigs, other.cacheLoaderConfigs);
+ && (this.shared == other.shared)
+ && safeEquals(this.preload, other.preload)
+ && safeEquals(this.cacheLoaderConfigs, other.cacheLoaderConfigs);
}
return false;
}
@@ -134,14 +130,12 @@
result = 51 * result + (cacheLoaderConfigs == null ? 0 : cacheLoaderConfigs.hashCode());
return result;
}
-
-
@Override
public CacheLoaderConfig clone() throws CloneNotSupportedException
{
- CacheLoaderConfig clone = (CacheLoaderConfig) super.clone();
+ CacheLoaderConfig clone = (CacheLoaderConfig) super.clone();
if (cacheLoaderConfigs != null)
{
List<IndividualCacheLoaderConfig> clcs = new ArrayList<IndividualCacheLoaderConfig>(cacheLoaderConfigs.size());
@@ -155,8 +149,6 @@
}
-
-
/**
* Configuration object that holds the confguration of an individual cache loader.
*
@@ -178,10 +170,6 @@
private SingletonStoreConfig singletonStoreConfig;
- public IndividualCacheLoaderConfig()
- {
- }
-
protected void populateFromBaseConfig(IndividualCacheLoaderConfig base)
{
if (base != null)
@@ -282,7 +270,7 @@
public void setSingletonStoreConfig(SingletonStoreConfig singletonStoreConfig)
{
- testImmutability("singletonStoreConfig");
+ testImmutability("singletonStoreConfig");
replaceChildConfig(this.singletonStoreConfig, singletonStoreConfig);
this.singletonStoreConfig = singletonStoreConfig;
}
@@ -292,16 +280,16 @@
{
if (!(obj instanceof IndividualCacheLoaderConfig))
return false;
- IndividualCacheLoaderConfig i = (IndividualCacheLoaderConfig)obj;
+ IndividualCacheLoaderConfig i = (IndividualCacheLoaderConfig) obj;
return equalsExcludingProperties(i)
- && safeEquals(this.properties, i.properties);
+ && safeEquals(this.properties, i.properties);
}
protected boolean equalsExcludingProperties(Object obj)
{
if (!(obj instanceof IndividualCacheLoaderConfig))
return false;
- IndividualCacheLoaderConfig other = (IndividualCacheLoaderConfig)obj;
+ IndividualCacheLoaderConfig other = (IndividualCacheLoaderConfig) obj;
return safeEquals(this.className, other.className)
&& (this.async == other.async)
@@ -333,17 +321,16 @@
public String toString()
{
return new StringBuffer().append("IndividualCacheLoaderConfig{").append("className='").append(className).append('\'')
- .append(", async=").append(async)
- .append(", ignoreModifications=").append(ignoreModifications)
- .append(", fetchPersistentState=").append(fetchPersistentState)
- .append(", properties=").append(properties)
- .append(", purgeOnStartup=").append(purgeOnStartup).append("},")
- .append("SingletonStoreConfig{").append(singletonStoreConfig).append('}')
- .toString();
+ .append(", async=").append(async)
+ .append(", ignoreModifications=").append(ignoreModifications)
+ .append(", fetchPersistentState=").append(fetchPersistentState)
+ .append(", properties=").append(properties)
+ .append(", purgeOnStartup=").append(purgeOnStartup).append("},")
+ .append("SingletonStoreConfig{").append(singletonStoreConfig).append('}')
+ .toString();
}
-
-
+
@Override
public IndividualCacheLoaderConfig clone() throws CloneNotSupportedException
{
@@ -356,7 +343,6 @@
}
-
/**
* Configuration for a SingletonStoreCacheLoader
*/
@@ -430,13 +416,13 @@
{
SingletonStoreConfig other = (SingletonStoreConfig) obj;
return ((this.singletonStoreEnabled == other.singletonStoreEnabled)
- && safeEquals(this.singletonStoreClass, other.singletonStoreClass)
- && safeEquals(this.singletonStoreproperties, other.singletonStoreproperties));
+ && safeEquals(this.singletonStoreClass, other.singletonStoreClass)
+ && safeEquals(this.singletonStoreproperties, other.singletonStoreproperties));
}
return false;
}
- @Override
+ @Override
public int hashCode()
{
int result = 19;
@@ -446,12 +432,12 @@
return result;
}
- @Override
+ @Override
public String toString()
{
return super.toString() + " enabled=" + singletonStoreEnabled +
- " class=" + singletonStoreClass +
- " properties=" + singletonStoreproperties;
+ " class=" + singletonStoreClass +
+ " properties=" + singletonStoreproperties;
}
@Override
@@ -462,8 +448,8 @@
clone.singletonStoreproperties = (Properties) singletonStoreproperties.clone();
return clone;
}
-
-
+
+
}
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/Configuration.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/config/Configuration.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -6,10 +6,10 @@
*/
package org.jboss.cache.config;
-import org.jboss.cache.CacheImpl;
import org.jboss.cache.Version;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.marshall.Marshaller;
import org.w3c.dom.Element;
import java.net.URL;
@@ -27,6 +27,18 @@
private static final long serialVersionUID = 5553791890144997466L;
private int numberOfNotifierThreads = 25;
+ private Marshaller marshaller;
+
+ public void setCacheMarshaller(Marshaller instance)
+ {
+ marshaller = instance;
+ }
+
+ public Marshaller getMarshaller()
+ {
+ return marshaller;
+ }
+
/**
* Cache replication mode.
*/
@@ -57,13 +69,13 @@
*/
INVALIDATION_ASYNC;
- /**
- * Returns true if the mode is invalidation, either sync or async.
- */
- public boolean isInvalidation()
- {
- return this.equals(INVALIDATION_SYNC) || this.equals(INVALIDATION_SYNC);
- }
+ /**
+ * Returns true if the mode is invalidation, either sync or async.
+ */
+ public boolean isInvalidation()
+ {
+ return this.equals(INVALIDATION_SYNC) || this.equals(INVALIDATION_SYNC);
+ }
}
@@ -83,7 +95,7 @@
return CacheMode.INVALIDATION_SYNC;
default:
throw new IllegalArgumentException("Unknown legacy cache mode " +
- legacyMode);
+ legacyMode);
}
}
@@ -153,30 +165,9 @@
private String muxStackName = null;
private boolean usingMultiplexer = false;
private transient RuntimeConfig runtimeConfig;
- private String marshallerClass = "org.jboss.cache.marshall.VersionAwareMarshaller";
+ private String marshallerClass;// = "org.jboss.cache.marshall.VersionAwareMarshaller";
// ------------------------------------------------------------------------------------------------------------
- // CONSTRUCTORS
- // ------------------------------------------------------------------------------------------------------------
-
- /**
- * Sets a reference to an existing CacheImpl instance
- *
- * @param cache
- */
- public Configuration(CacheImpl cache)
- {
- setCacheImpl(cache);
- }
-
- /**
- * Default empty constructor
- */
- public Configuration()
- {
- }
-
- // ------------------------------------------------------------------------------------------------------------
// SETTERS - MAKE SURE ALL SETTERS PERFORM testImmutability()!!!
// ------------------------------------------------------------------------------------------------------------
@@ -640,6 +631,7 @@
/**
* Returns a {@link java.net.URL} to a default JGroups configuration file.
+ *
* @return a default JGroups config file
*/
public URL getDefaultClusterConfig()
@@ -649,7 +641,6 @@
return url;
}
-
// ------------------------------------------------------------------------------------------------------------
// HELPERS
// ------------------------------------------------------------------------------------------------------------
Modified: core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/config/ConfigurationComponent.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -8,7 +8,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.CacheStatus;
+import org.jboss.cache.factories.annotations.Inject;
import java.io.Serializable;
import java.util.Collection;
@@ -29,9 +31,9 @@
private static final long serialVersionUID = 4879873994727821938L;
protected transient Log log = LogFactory.getLog(getClass());
- private transient CacheImpl cache; // back-reference to test whether the cache is running.
+ private transient CacheSPI cache; // back-reference to test whether the cache is running.
private final Set<ConfigurationComponent> children =
- Collections.synchronizedSet(new HashSet<ConfigurationComponent>());
+ Collections.synchronizedSet(new HashSet<ConfigurationComponent>());
protected ConfigurationComponent()
{
@@ -41,14 +43,14 @@
{
if (child != null)
{
- child.setCacheImpl(cache);
+ child.setCache(cache);
}
}
protected void addChildConfig(ConfigurationComponent child)
{
if (child != null && children.add(child))
- child.setCacheImpl(cache);
+ child.setCache(cache);
}
protected void addChildConfigs(Collection<? extends ConfigurationComponent> toAdd)
@@ -99,7 +101,7 @@
{
try
{
- if (cache != null && cache.isStarted() && !getClass().getDeclaredField(fieldName).isAnnotationPresent(Dynamic.class))
+ if (cache != null && (cache.getCacheStatus() == CacheStatus.STARTED || cache.getCacheStatus() == CacheStatus.STARTING) && !getClass().getDeclaredField(fieldName).isAnnotationPresent(Dynamic.class))
{
throw new ConfigurationException("Attempted to modify a non-Dynamic configuration element [" + fieldName + "] after the cache has started!");
}
@@ -110,24 +112,20 @@
}
}
- protected CacheImpl getTreeCache()
- {
- return cache;
- }
-
/**
* Sets a back-reference to the cache associated with this configuration
*
* @param cache
*/
- public void setCacheImpl(CacheImpl cache)
+ @Inject
+ public void setCache(CacheSPI cache)
{
this.cache = cache;
synchronized (children)
{
for (ConfigurationComponent child : children)
{
- child.setCacheImpl(cache);
+ child.setCache(cache);
}
}
}
@@ -135,7 +133,7 @@
public ConfigurationComponent clone() throws CloneNotSupportedException
{
ConfigurationComponent c = (ConfigurationComponent) super.clone();
- c.setCacheImpl(null);
+ c.setCache(null);
return c;
}
Modified: core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/config/EvictionRegionConfig.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -21,11 +21,11 @@
*/
package org.jboss.cache.config;
-import java.lang.reflect.Method;
-
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
+import java.lang.reflect.Method;
+
public class EvictionRegionConfig extends ConfigurationComponent
{
/**
@@ -43,10 +43,6 @@
private Integer eventQueueSize;
private EvictionPolicyConfig evictionPolicyConfig;
- public EvictionRegionConfig()
- {
- }
-
public EvictionPolicyConfig getEvictionPolicyConfig()
{
return evictionPolicyConfig;
@@ -101,8 +97,8 @@
if (queueSize <= 0)
{
LogFactory.getLog(EvictionRegionConfig.class).warn("Ignoring invalid queue capacity " +
- queueSize + " -- using " +
- EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
+ queueSize + " -- using " +
+ EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
queueSize = EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT;
}
this.eventQueueSize = queueSize;
@@ -148,16 +144,17 @@
{
throw new CloneNotSupportedException(evictionPolicyConfig + " is not Cloneable");
}
-
+
if (evictionPolicyConfig instanceof ConfigurationComponent)
{
clone.setEvictionPolicyConfig((EvictionPolicyConfig) ((ConfigurationComponent) evictionPolicyConfig).clone());
}
- else {
+ else
+ {
try
{
- Method cloneMethod = evictionPolicyConfig.getClass().getDeclaredMethod("clone", new Class[]{});
- EvictionPolicyConfig epc = (EvictionPolicyConfig) cloneMethod.invoke(evictionPolicyConfig, new Object[]{});
+ Method cloneMethod = evictionPolicyConfig.getClass().getDeclaredMethod("clone");
+ EvictionPolicyConfig epc = (EvictionPolicyConfig) cloneMethod.invoke(evictionPolicyConfig);
clone.setEvictionPolicyConfig(epc);
}
catch (Exception e)
@@ -168,11 +165,9 @@
}
}
}
-
+
return clone;
}
-
-
}
\ No newline at end of file
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-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/config/RuntimeConfig.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -28,11 +28,6 @@
private transient BuddyGroup buddyGroup;
private RPCManager rpcManager;
- public RuntimeConfig()
- {
- // needs a public ctor for DI frameworks to instantiate.
- }
-
/**
* Resets the runtime to default values.
*/
@@ -155,9 +150,9 @@
{
RuntimeConfig other = (RuntimeConfig) obj;
return safeEquals(transactionManager, other.transactionManager)
- && safeEquals(muxChannelFactory, other.muxChannelFactory)
- && safeEquals(rpcManager, other.rpcManager)
- && safeEquals(channel, other.channel);
+ && safeEquals(muxChannelFactory, other.muxChannelFactory)
+ && safeEquals(rpcManager, other.rpcManager)
+ && safeEquals(channel, other.channel);
}
return false;
@@ -199,6 +194,6 @@
{
return (RuntimeConfig) super.clone();
}
-
-
+
+
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionAlgorithm.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -81,7 +81,8 @@
Configuration c = region.getCacheConfiguration();
Configuration.CacheMode cm = c != null ? c.getCacheMode() : Configuration.CacheMode.LOCAL;
allowTombstones = c != null && c.isNodeLockingOptimistic() &&
- (cm == Configuration.CacheMode.INVALIDATION_ASYNC || cm == Configuration.CacheMode.INVALIDATION_SYNC);
+ (cm == Configuration.CacheMode.INVALIDATION_ASYNC || cm == Configuration.CacheMode.INVALIDATION_SYNC);
+
}
/**
@@ -151,8 +152,8 @@
{
case ADD_NODE_EVENT:
this.processAddedNodes(fqn,
- node.getElementDifference(),
- node.isResetElementCount());
+ node.getElementDifference(),
+ node.isResetElementCount());
break;
case REMOVE_NODE_EVENT:
this.processRemovedNodes(fqn);
@@ -216,7 +217,7 @@
{
log.trace("Attempting to evict cache node with fqn of " + fqn);
}
-
+
EvictionPolicy policy = region.getEvictionPolicy();
try
{
@@ -365,7 +366,7 @@
if (log.isTraceEnabled())
{
log.trace("processRemoveNodes(): Can't find node associated with fqn: " + fqn
- + "Could have been evicted earlier. Will just continue.");
+ + "Could have been evicted earlier. Will just continue.");
}
return;
}
@@ -417,7 +418,7 @@
if (log.isDebugEnabled())
{
log.debug("Removing element from " + fqn + " but eviction queue does not contain this node. " +
- "Ignoring removeElement event.");
+ "Ignoring removeElement event.");
}
return;
}
@@ -543,13 +544,14 @@
public String toString()
{
return super.toString() +
- " reqion=" + region.getFqn() +
- " recycle=" + recycleQueue.size() +
- " evict=" + evictionQueue.getNumberOfNodes();
+ " reqion=" + region.getFqn() +
+ " recycle=" + recycleQueue.size() +
+ " evict=" + evictionQueue.getNumberOfNodes();
}
/**
* Tests whether a node entry is younger than the minimum time to live - if one is configured.
+ *
* @param entry the node entry being examined
* @return true if the node is younger than - or exactly equal to - the minimum time to live, if one is configured for the given region. False otherwise.
*/
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionPolicy.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionPolicy.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/BaseEvictionPolicy.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -14,10 +14,6 @@
{
protected CacheSPI cache_;
- public BaseEvictionPolicy()
- {
- }
-
/** EvictionPolicy interface implementation */
/**
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeQueue.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeQueue.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ElementSizeQueue.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -8,16 +8,7 @@
import org.jboss.cache.Fqn;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
+import java.util.*;
/**
* @author Daniel Huang
@@ -181,9 +172,6 @@
*/
static class MaxElementComparator implements Comparator<NodeEntry>
{
- MaxElementComparator()
- {
- }
public int compare(NodeEntry ne1, NodeEntry ne2)
{
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/ExpirationConfiguration.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -16,22 +16,17 @@
public static final String EXPIRATION_KEY = "expiration";
/**
- * Node key name used to indicate the expiration of a node.
+ * Node key name used to indicate the expiration of a node.
*/
@Dynamic
private String expirationKeyName = EXPIRATION_KEY;
-
+
@Dynamic
private boolean warnNoExpirationKey = true;
@Dynamic
private int timeToLiveSeconds = 0;
- public ExpirationConfiguration()
- {
- super();
- }
-
@Override
protected void setEvictionPolicyClassName()
{
@@ -85,8 +80,7 @@
public ExpirationConfiguration clone() throws CloneNotSupportedException
{
return (ExpirationConfiguration) super.clone();
- }
-
-
+ }
+
}
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithm.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/FIFOAlgorithm.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -22,11 +22,6 @@
private static final Log log = LogFactory.getLog(FIFOAlgorithm.class);
- public FIFOAlgorithm()
- {
- super();
- }
-
protected EvictionQueue setupEvictionQueue(Region region) throws EvictionException
{
return new FIFOQueue();
@@ -40,7 +35,7 @@
// check the minimum time to live and see if we should not evict the node. This check will
// ensure that, if configured, nodes are kept alive for at least a minimum period of time.
if (isYoungerThanMinimumTimeToLive(ne)) return false;
-
+
FIFOConfiguration config = (FIFOConfiguration) region.getEvictionPolicyConfig();
if (log.isTraceEnabled())
{
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithm.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LFUAlgorithm.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -37,11 +37,6 @@
private static final Log log = LogFactory.getLog(LFUAlgorithm.class);
- public LFUAlgorithm()
- {
- super();
- }
-
protected boolean shouldEvictNode(NodeEntry ne)
{
if (log.isTraceEnabled())
@@ -51,7 +46,7 @@
// check the minimum time to live and see if we should not evict the node. This check will
// ensure that, if configured, nodes are kept alive for at least a minimum period of time.
- if (isYoungerThanMinimumTimeToLive(ne)) return false;
+ if (isYoungerThanMinimumTimeToLive(ne)) return false;
LFUConfiguration config = (LFUConfiguration) region.getEvictionPolicyConfig();
int size = this.getEvictionQueue().getNumberOfNodes();
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LFUConfiguration.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -9,7 +9,7 @@
import org.jboss.cache.config.Dynamic;
/**
- * Configuration implementation for {@link LFUPolicy}.
+ * Configuration implementation for {@link LFUPolicy}.
* <p/>
* If configured via XML, expects the following:
* <p/>
@@ -25,17 +25,14 @@
*/
public class LFUConfiguration extends EvictionPolicyConfigBase
{
- /** The serialVersionUID */
+ /**
+ * The serialVersionUID
+ */
private static final long serialVersionUID = 1865801530398969179L;
-
+
@Dynamic
private int minNodes;
- public LFUConfiguration()
- {
- super();
- }
-
@Override
protected void setEvictionPolicyClassName()
{
@@ -52,7 +49,7 @@
testImmutability("minNodes");
this.minNodes = minNodes;
}
-
+
public String toString()
{
StringBuffer ret = new StringBuffer();
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LFUQueue.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LFUQueue.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LFUQueue.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -8,16 +8,7 @@
import org.jboss.cache.Fqn;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
+import java.util.*;
/**
* LFUQueue EvictionQueue implementation for LFU Policy.
@@ -192,9 +183,6 @@
*/
static class LFUComparator implements Comparator<NodeEntry>
{
- LFUComparator()
- {
- }
public int compare(NodeEntry ne1, NodeEntry ne2)
{
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -24,11 +24,6 @@
{
private static final Log log = LogFactory.getLog(LRUAlgorithm.class);
- public LRUAlgorithm()
- {
- super();
- }
-
protected EvictionQueue setupEvictionQueue(Region region) throws EvictionException
{
return new LRUQueue();
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -1,9 +1,9 @@
package org.jboss.cache.interceptors;
import org.jboss.cache.CacheImpl;
-import org.jboss.cache.CacheSPI;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.config.Option;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodDeclarations;
import org.jboss.cache.transaction.GlobalTransaction;
@@ -23,18 +23,14 @@
*/
public class CallInterceptor extends Interceptor
{
- private CacheImpl cache;
+ private CacheImpl cacheImpl;
- public void setCache(CacheSPI cache)
+ @Inject
+ private void injectDependencies(CacheImpl cacheImpl)
{
- super.setCache(cache);
+ this.cacheImpl = cacheImpl;
}
- public void setTreeCacheInstance(CacheImpl c)
- {
- cache = c;
- }
-
public Object invoke(InvocationContext ctx) throws Throwable
{
MethodCall m = ctx.getMethodCall();
@@ -45,8 +41,7 @@
if (log.isTraceEnabled()) log.trace("Passing up method " + m + " so it gets invoked on cache.");
try
{
- //retval = nextInterceptor(m);
- retval = m.invoke(cache);
+ retval = m.invoke(cacheImpl);
}
catch (Throwable t)
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/Interceptor.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -27,6 +27,7 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Inject;
import javax.transaction.Status;
import javax.transaction.SystemException;
@@ -36,7 +37,7 @@
/**
* Class representing an interceptor.
- * <em>Note that this will be replaced by {@link org.jboss.aop.advice.Interceptor} in one of the nextInterceptor releases</em>
+ * <em>Note that this will be replaced by {@link org.jboss.aop.advice.Interceptor} in one of the next releases</em>
*
* @author Bela Ban
* @version $Id$
@@ -64,12 +65,19 @@
return next;
}
+ @Inject
public void setCache(CacheSPI cache)
{
this.cache = cache;
- this.configuration = cache.getConfiguration();
+ //this.configuration = cache.getConfiguration();
}
+ @Inject
+ private void injectDependencies(Configuration configuration)
+ {
+ this.configuration = configuration;
+ }
+
/**
* Using this method call for forwarding a call in the chain is not redable and error prone in the case of interceptors
* extending other interceptors. This metod rather refers to interceptor doing its business operations rather than
@@ -174,7 +182,7 @@
return isActive(tx) || isPreparing(tx);
}
- /**
+ /**
* Tests whether the caller is in a valid transaction. If not, will throw a CacheException.
*/
protected void assertTransactionValid(InvocationContext ctx)
@@ -193,10 +201,10 @@
public String toString()
{
return getClass().getName()
- + "{next: "
- + (getNext() == null ? null : getNext().getClass())
- + "; last: "
- + (getLast() == null ? null : getLast().getClass())
- + "}";
+ + "{next: "
+ + (getNext() == null ? null : getNext().getClass())
+ + "; last: "
+ + (getLast() == null ? null : getLast().getClass())
+ + "}";
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -7,7 +7,15 @@
package org.jboss.cache.interceptors;
import org.apache.commons.logging.Log;
-import org.jboss.cache.*;
+import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.Node;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.ComponentName;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.LockingException;
import org.jboss.cache.lock.NodeLock;
@@ -17,7 +25,12 @@
import org.jboss.cache.transaction.TransactionTable;
import org.jgroups.Address;
-import java.util.*;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/*
* todo refactorings ideas
@@ -41,17 +54,24 @@
private TransactionTable tx_table = null;
/**
- * Map<Object, java.util.List>. Keys = threads, values = lists of locks held by that thread
+ * Map<Thread, List<NodeLock>>. Keys = threads, values = lists of locks held by that thread
*/
private Map<Thread, List<NodeLock>> lock_table;
private long lock_acquisition_timeout;
+ @Inject
+ public void injectDependencies(@ComponentName("LockTable")Map<Thread, List<NodeLock>> lockTable, Configuration configuration)
+ {
+ this.lock_table = lockTable;
+ lock_acquisition_timeout = configuration.getLockAcquisitionTimeout();
+ }
+
public void setCache(CacheSPI cache)
{
super.setCache(cache);
tx_table = cache.getTransactionTable();
- lock_table = cache.getLockTable();
- lock_acquisition_timeout = cache.getConfiguration().getLockAcquisitionTimeout();
+ //lock_table = cache.getLockTable();
+ //lock_acquisition_timeout = cache.getConfiguration().getLockAcquisitionTimeout();
}
protected Log getLog()
@@ -75,7 +95,7 @@
}
private Object handlePutMethod(InvocationContext ctx, Fqn fqn)
- throws Throwable
+ throws Throwable
{
log.trace("Suppressing locking");
if (ctx.getOptionOverrides() != null && ctx.getOptionOverrides().isSuppressLocking())
@@ -92,7 +112,8 @@
manageReverseRemove(ctx.getGlobalTransaction(), child_node, true);
n = child_node;
}
- } else
+ }
+ else
{
acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.READ, true, false, false, true);
}
@@ -174,7 +195,7 @@
long timeout = ctx.getContextLockAcquisitionTimeout(lock_acquisition_timeout);
// this call will ensure the node gets a WL and it's current parent gets RL.
if (log.isTraceEnabled()) log.trace("Attempting to get WL on node to be moved [" + from + "]");
- if (from != null && ! (configuration.getIsolationLevel() == IsolationLevel.NONE))
+ if (from != null && !(configuration.getIsolationLevel() == IsolationLevel.NONE))
{
lock(ctx, from, NodeLock.LockType.WRITE, false, timeout, true, false);
if (ctx.getGlobalTransaction() != null)
@@ -195,7 +216,7 @@
NodeSPI n = cache.peek(from, true);
if (n != null)
{
- n.getLock().releaseAll(Thread.currentThread());
+ n.getLock().releaseAll(Thread.currentThread());
}
return retValue;
}
@@ -215,7 +236,7 @@
NodeSPI n = cache.peek(fqn, true);
if (n != null)
{
- n.getLock().releaseAll(Thread.currentThread());
+ n.getLock().releaseAll(Thread.currentThread());
}
}
// if this is a delete op and we had to create the node, return a FALSE as nothing *really* was deleted!
@@ -253,49 +274,49 @@
protected Object handleGetKeyValueMethod(InvocationContext ctx, Fqn fqn, Object key, boolean sendNodeEvent) throws Throwable
{
- acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.READ, false, false, false, false);
- return nextInterceptor(ctx);
+ acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.READ, false, false, false, false);
+ return nextInterceptor(ctx);
}
- protected Object handleGetNodeMethod(InvocationContext ctx, Fqn fqn) throws Throwable
+ protected Object handleGetNodeMethod(InvocationContext ctx, Fqn fqn) throws Throwable
{
- acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.READ, false, false, false, false);
- return nextInterceptor(ctx);
+ acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.READ, false, false, false, false);
+ return nextInterceptor(ctx);
}
protected Object handleGetKeysMethod(InvocationContext ctx, Fqn fqn) throws Throwable
{
- acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.READ, false, false, false, false);
- return nextInterceptor(ctx);
+ acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.READ, false, false, false, false);
+ return nextInterceptor(ctx);
}
protected Object handleGetChildrenNamesMethod(InvocationContext ctx, Fqn fqn) throws Throwable
{
- acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.READ, false, false, false, false);
- return nextInterceptor(ctx);
+ acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.READ, false, false, false, false);
+ return nextInterceptor(ctx);
}
protected Object handlePrintMethod(InvocationContext ctx, Fqn fqn) throws Throwable
{
- acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.READ, false, false, false, false);
- return nextInterceptor(ctx);
+ acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.READ, false, false, false, false);
+ return nextInterceptor(ctx);
}
protected Object handleReleaseAllLocksMethod(InvocationContext ctx, Fqn fqn) throws Throwable
{
- acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.READ, false, false, false, false);
- return nextInterceptor(ctx);
+ acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.READ, false, false, false, false);
+ return nextInterceptor(ctx);
}
private boolean acquireLocksWithTimeout(InvocationContext ctx, Fqn fqn, NodeLock.LockType lockType,
boolean createIfNotExists, boolean zeroLockTimeout,
boolean acquireLockOnParent, boolean reverseRemoveCheck)
- throws InterruptedException
+ throws InterruptedException
{
if (fqn == null || configuration.getIsolationLevel() == IsolationLevel.NONE)
{
return false;
- }
+ }
boolean created;
long timeout = zeroLockTimeout ? 0 : ctx.getContextLockAcquisitionTimeout(lock_acquisition_timeout);
// make sure we can bail out of this loop
@@ -319,14 +340,15 @@
* Acquires locks on the node and on its parrents. Read locks are acquired for exsiting ancestors, with two exceptions:
* 1) createIfNotExists is true. If an ancestor is created on the fly, then an WL is acquired by default
* 2) acquireWriteLockOnParent is true. If so AND {@link org.jboss.cache.Node#isLockForChildInsertRemove()} then a read
- * lock will be aquired for the parent of the node.
- * @param createIfNotExists if true, then missing nodes will be cretaed on the fly. If false, method returns if we
- * reach a node that does not exists
+ * lock will be aquired for the parent of the node.
+ *
+ * @param createIfNotExists if true, then missing nodes will be cretaed on the fly. If false, method returns if we
+ * reach a node that does not exists
* @param reverseRemoveCheck see {@link #manageReverseRemove(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.NodeSPI, boolean)}
*/
private boolean lock(InvocationContext ctx, Fqn fqn, NodeLock.LockType lockType, boolean createIfNotExists, long timeout,
boolean acquireWriteLockOnParent, boolean reverseRemoveCheck)
- throws TimeoutException, LockingException, InterruptedException
+ throws TimeoutException, LockingException, InterruptedException
{
Thread currentThread = Thread.currentThread();
GlobalTransaction gtx = ctx.getGlobalTransaction();
@@ -356,7 +378,8 @@
}
else
{
- if (log.isTraceEnabled()) log.trace("failed to find or create child " + childName + " of node " + currentNode);
+ if (log.isTraceEnabled())
+ log.trace("failed to find or create child " + childName + " of node " + currentNode);
return false;
}
}
@@ -376,7 +399,8 @@
NodeSPI repeek = cache.peek(currentNode.getFqn(), true, true);
if (currentNode != repeek)
{
- if (log.isTraceEnabled()) log.trace("Was waiting for and obtained a lock on a node that doesn't exist anymore! Attempting lock acquisition again.");
+ if (log.isTraceEnabled())
+ log.trace("Was waiting for and obtained a lock on a node that doesn't exist anymore! Attempting lock acquisition again.");
// we have an orphan!! Lose the unnecessary lock and re-acquire the lock (and potentially recreate the node).
// check if the parent exists!!
// look into invalidated nodes as well
@@ -384,7 +408,8 @@
if (cache.peek(parent.getFqn(), true, true) == null)
{
// crap!
- if (log.isTraceEnabled()) log.trace("Parent has been deleted again. Go through the lock method all over again.");
+ if (log.isTraceEnabled())
+ log.trace("Parent has been deleted again. Go through the lock method all over again.");
currentNode = cache.getRoot();
parent = null;
}
@@ -413,22 +438,22 @@
}
- /**
- * Acquires nodes on the children of this node. nodes on the node itself are not aquired.
- * If the supplied parent node is null the method returns(no op).
- */
+ /**
+ * Acquires nodes on the children of this node. nodes on the node itself are not aquired.
+ * If the supplied parent node is null the method returns(no op).
+ */
private void acquireLocksOnChildren(NodeSPI parentNode, NodeLock.LockType lockType, InvocationContext ctx)
- throws InterruptedException
+ throws InterruptedException
{
if (parentNode == null)
{
- return;
+ return;
}
long timeout = ctx.getContextLockAcquisitionTimeout(lock_acquisition_timeout);
GlobalTransaction gtx = ctx.getGlobalTransaction();
Object owner = (gtx != null) ? gtx : Thread.currentThread();
- Set<NodeLock> acquiredLocks = parentNode.getLock().acquireAll(owner, timeout, lockType);
+ Set<NodeLock> acquiredLocks = parentNode.getLock().acquireAll(owner, timeout, lockType);
if (acquiredLocks.size() > 0)
{
if (gtx != null)
@@ -443,16 +468,16 @@
}
}
- /**
- * Used by {@link #lock(org.jboss.cache.InvocationContext, org.jboss.cache.Fqn, org.jboss.cache.lock.NodeLock.LockType, boolean, long, boolean, boolean)}.
- * Determins whter an arbitrary node from the supplied fqn needs an write lock.
- */
+ /**
+ * Used by {@link #lock(org.jboss.cache.InvocationContext, org.jboss.cache.Fqn, org.jboss.cache.lock.NodeLock.LockType, boolean, long, boolean, boolean)}.
+ * Determins whter an arbitrary node from the supplied fqn needs an write lock.
+ */
private boolean writeLockNeeded(InvocationContext ctx, NodeLock.LockType lockType, int currentNodeIndex, boolean acquireWriteLockOnParent, boolean createIfNotExists, Fqn targetFqn, NodeSPI currentNode)
{
int treeNodeSize = targetFqn.size();
// write lock forced!!
- boolean isTargetNode = currentNodeIndex == (treeNodeSize - 1);
- if (ctx.getOptionOverrides().isForceWriteLock() && isTargetNode) return true;
+ boolean isTargetNode = currentNodeIndex == (treeNodeSize - 1);
+ if (ctx.getOptionOverrides().isForceWriteLock() && isTargetNode) return true;
//this can be injected, from the caller as a param named wlParent
if (currentNode.isLockForChildInsertRemove())
{
@@ -468,31 +493,31 @@
return lockType == NodeLock.LockType.WRITE && isTargetNode;//write lock explicitly requested and this is the target to be written to.
}
- private void acquireNodeLock(NodeSPI node, Object owner, GlobalTransaction gtx, NodeLock.LockType lockType, long lockTimeout) throws LockingException, TimeoutException, InterruptedException
+ private void acquireNodeLock(NodeSPI node, Object owner, GlobalTransaction gtx, NodeLock.LockType lockType, long lockTimeout) throws LockingException, TimeoutException, InterruptedException
{
boolean acquired = node.getLock().acquire(owner, lockTimeout, lockType);
if (acquired)
{
// Record the lock for release on method return or tx commit/rollback
- NodeLock lock = node.getLock();
- if (gtx != null)
- {
- cache.getTransactionTable().recordNodeLock(gtx, lock);
- }
- else
- {
- Thread currentThread = Thread.currentThread();
- List<NodeLock> locks = getLocks(currentThread);
- if (!locks.contains(lock))
- {
- locks.add(lock);
- lock_table.put(currentThread, locks);
- }
- }
+ NodeLock lock = node.getLock();
+ if (gtx != null)
+ {
+ cache.getTransactionTable().recordNodeLock(gtx, lock);
+ }
+ else
+ {
+ Thread currentThread = Thread.currentThread();
+ List<NodeLock> locks = getLocks(currentThread);
+ if (!locks.contains(lock))
+ {
+ locks.add(lock);
+ lock_table.put(currentThread, locks);
+ }
+ }
}
}
- private List<NodeLock> getLocks(Thread currentThread)
+ private List<NodeLock> getLocks(Thread currentThread)
{
// This sort of looks like a get/put race condition, but
// since we key off the Thread, it's not
@@ -506,16 +531,16 @@
}
- /**
- * Test if this node needs to be 'undeleted'
- * reverse the "remove" if the node has been previously removed in the same tx, if this operation is a put()
- */
+ /**
+ * Test if this node needs to be 'undeleted'
+ * reverse the "remove" if the node has been previously removed in the same tx, if this operation is a put()
+ */
private void manageReverseRemove(GlobalTransaction gtx, NodeSPI childNode, boolean reverseRemoveCheck)
{
boolean needToReverseRemove = reverseRemoveCheck && childNode.isDeleted() && tx_table.get(gtx).getRemovedNodes().contains(childNode.getFqn());
if (gtx != null && needToReverseRemove)
{
- childNode.markAsDeleted(false);
+ childNode.markAsDeleted(false);
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/TxInterceptor.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -6,10 +6,15 @@
*/
package org.jboss.cache.interceptors;
-import org.jboss.cache.*;
-import org.jboss.cache.lock.NodeLock;
+import org.apache.commons.logging.Log;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.Node;
+import org.jboss.cache.ReplicationException;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Option;
+import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodCallFactory;
import org.jboss.cache.marshall.MethodDeclarations;
@@ -17,7 +22,6 @@
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionEntry;
-import org.apache.commons.logging.Log;
import org.jgroups.Address;
import javax.transaction.Status;
@@ -82,7 +86,8 @@
if (log.isTraceEnabled()) log.trace("received my own message (discarding it)");
result = null;
}
- } catch (Throwable e)
+ }
+ catch (Throwable e)
{
throwIfNeeded(ctx, e);
}
@@ -119,14 +124,16 @@
if (log.isTraceEnabled()) log.trace("received my own message (discarding it)");
result = null;
}
- } catch (Throwable throwable)
+ }
+ catch (Throwable throwable)
{
throwIfNeeded(ctx, throwable);
- } finally
+ }
+ finally
{
scrubOnExist(ctx, scrubTxsOnExit);
}
- return result;
+ return result;
}
@@ -332,7 +339,7 @@
// --------------------------------------------------------------
- private Object handleRemotePrepare(InvocationContext ctx,List<MethodCall> modifications, boolean onePhase ) throws Throwable
+ private Object handleRemotePrepare(InvocationContext ctx, List<MethodCall> modifications, boolean onePhase) throws Throwable
{
GlobalTransaction gtx = ctx.getGlobalTransaction();
// Is there a local transaction associated with GTX ?
@@ -442,8 +449,8 @@
GlobalTransaction gtx = ctx.getGlobalTransaction();
try
- {
- result = nextInterceptor(ctx);
+ {
+ result = nextInterceptor(ctx);
if (implicitTransaction)
{
copyInvocationScopeOptionsToTxScope(ctx);
@@ -473,7 +480,8 @@
}
}
return result;
- } catch (Throwable throwable)
+ }
+ catch (Throwable throwable)
{
throwIfNeeded(ctx, throwable);
return null;
@@ -486,7 +494,7 @@
private void copyForcedCacheModeToTxScope(InvocationContext ctx)
{
Option optionOverride = ctx.getOptionOverrides();
- if (optionOverride != null
+ if (optionOverride != null
&& (optionOverride.isForceAsynchronous() || optionOverride.isForceSynchronous()))
{
TransactionEntry entry = txTable.get(ctx.getGlobalTransaction());
@@ -550,8 +558,8 @@
if (!isActive(ltx))
{
throw new ReplicationException("prepare() failed -- " +
- "local transaction status is not STATUS_ACTIVE;" +
- " is " + ltx.getStatus());
+ "local transaction status is not STATUS_ACTIVE;" +
+ " is " + ltx.getStatus());
}
return retval;
}
@@ -566,7 +574,7 @@
try
{
replayModifications(modifications, ctx, false);
- if (m.isOnePhaseCommitPrepareMehod())
+ if (m.isOnePhaseCommitPrepareMehod())
{
log.trace("Using one-phase prepare. Not propagating the prepare call up the stack until called to do so by the sync handler.");
}
@@ -579,8 +587,8 @@
if (!isActive(ltx))
{
throw new ReplicationException("prepare() failed -- " +
- "local transaction status is not STATUS_ACTIVE;" +
- " is " + ltx.getStatus());
+ "local transaction status is not STATUS_ACTIVE;" +
+ " is " + ltx.getStatus());
}
}
catch (Throwable th)
@@ -866,13 +874,13 @@
if (configuration.isNodeLockingOptimistic())
{
commitMethod = MethodCallFactory.create(MethodDeclarations.optimisticPrepareMethod,
- gtx, modifications, null, cache.getLocalAddress(), true);
+ gtx, modifications, null, cache.getLocalAddress(), true);
}
else
{
commitMethod = MethodCallFactory.create(MethodDeclarations.prepareMethod,
- gtx, modifications, cache.getLocalAddress(),
- true);
+ gtx, modifications, cache.getLocalAddress(),
+ true);
}
}
else
@@ -979,8 +987,8 @@
else if (configuration.getCacheMode() != Configuration.CacheMode.REPL_ASYNC)
{
prepareMethod = MethodCallFactory.create(MethodDeclarations.prepareMethod,
- gtx, modifications, cache.getLocalAddress(),
- false);// don't commit or rollback - wait for call
+ gtx, modifications, cache.getLocalAddress(),
+ false);// don't commit or rollback - wait for call
}
//}
else
@@ -1148,7 +1156,7 @@
{
Transaction tx = null;
GlobalTransaction gtx = null;
-// CacheSPI cache = null;
+ // CacheSPI cache = null;
List modifications = null;
TransactionEntry entry = null;
protected InvocationContext ctx; // the context for this call.
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -1,15 +1,17 @@
package org.jboss.cache.interceptors;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.factories.annotations.ComponentName;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.lock.IdentityLock;
+import org.jboss.cache.lock.NodeLock;
+
+import javax.transaction.Transaction;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
-import javax.transaction.Transaction;
-
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.InvocationContext;
-import org.jboss.cache.lock.IdentityLock;
-
/**
* When a call returns, unlocks all locks held by the current thread in the
* LockTable. This is a no-op if a transaction is used.
@@ -20,9 +22,15 @@
public class UnlockInterceptor extends Interceptor
{
- Map lock_table = null;
+ Map<Thread, List<NodeLock>> lock_table = null;
boolean trace = log.isTraceEnabled();
+ @Inject
+ private void injectDependencies(@ComponentName("LockTable")Map<Thread, List<NodeLock>> lockTable)
+ {
+ this.lock_table = lockTable;
+ }
+
public void setCache(CacheSPI cache)
{
super.setCache(cache);
Modified: core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -27,6 +27,7 @@
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheFactory;
import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.CacheStatus;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.BuddyReplicationConfig;
@@ -37,23 +38,14 @@
import org.jboss.cache.config.RuntimeConfig;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.interceptors.Interceptor;
+import org.jboss.cache.util.CachePrinter;
import org.jgroups.Address;
import org.jgroups.Channel;
import org.jgroups.ChannelFactory;
import org.jgroups.jmx.JChannelFactoryMBean;
import org.w3c.dom.Element;
-import javax.management.AttributeChangeNotification;
-import javax.management.JMException;
-import javax.management.ListenerNotFoundException;
-import javax.management.MBeanNotificationInfo;
-import javax.management.MBeanRegistration;
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.NotificationBroadcasterSupport;
-import javax.management.NotificationFilter;
-import javax.management.NotificationListener;
-import javax.management.ObjectName;
+import javax.management.*;
import javax.transaction.TransactionManager;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@@ -76,7 +68,7 @@
private MBeanServer server;
private String cacheObjectName;
private boolean interceptorsRegistered;
- private CacheImpl<K, V> cache;
+ private CacheSPI<K, V> cache;
private Configuration config;
private boolean registerInterceptors = true;
private final AtomicInteger listenerCount = new AtomicInteger(0);
@@ -86,7 +78,7 @@
private String notificationServiceName;
private boolean registered;
private boolean disableStateChangeNotifications;
-
+
// Legacy config support
private Element buddyReplConfig;
@@ -140,12 +132,12 @@
public String printCacheDetails()
{
- return cache == null ? "Cache is null" : cache.printDetails();
+ return cache == null ? "Cache is null" : CachePrinter.printCacheDetails(cache);
}
public String printCacheDetailsAsHtml()
{
- return cache == null ? "Cache is null" : formatHtml(cache.printDetails());
+ return cache == null ? "Cache is null" : formatHtml(CachePrinter.printCacheDetails(cache));
}
public CacheStatus getCacheStatus()
@@ -201,12 +193,12 @@
public String printLockInfo()
{
- return cache == null ? "Cache is null" : cache.printLockInfo();
+ return cache == null ? "Cache is null" : CachePrinter.printCacheLockingInfo(cache);
}
public String printLockInfoAsHtml()
{
- return cache == null ? "Cache is null" : formatHtml(cache.printLockInfo());
+ return cache == null ? "Cache is null" : formatHtml(CachePrinter.printCacheLockingInfo(cache));
}
public boolean getRegisterInterceptors()
@@ -397,7 +389,7 @@
public void setCacheLoaderConfiguration(Element config)
{
log.warn("MBean attribute 'CacheLoaderConfiguration' is deprecated; " +
- "use 'CacheLoaderConfig'");
+ "use 'CacheLoaderConfig'");
setCacheLoaderConfig(config);
}
@@ -452,7 +444,7 @@
public void setUseInterceptorMbeans(boolean use)
{
log.warn("MBean attribute 'UseInterceptorMbeans' is deprecated; " +
- "use 'ExposeManagementStatistics'");
+ "use 'ExposeManagementStatistics'");
setExposeManagementStatistics(use);
}
@@ -606,7 +598,7 @@
cacheStatus = CacheStatus.STARTING;
int startingState = getState();
sendStateChangeNotification(oldState, startingState, getClass().getSimpleName() + " starting", null);
-
+
cache.start();
registerInterceptors();
@@ -636,7 +628,7 @@
cacheStatus = CacheStatus.STOPPING;
int stoppingState = getState();
sendStateChangeNotification(oldState, stoppingState, getClass().getSimpleName() + " stopping", null);
-
+
cache.stop();
if (cache.getCacheStatus() == CacheStatus.DESTROYED)
@@ -654,7 +646,7 @@
if (failed)
{
log.warn("Attempted to stop() from FAILED state, " +
- "but caught exception; try calling destroy()", t);
+ "but caught exception; try calling destroy()", t);
}
handleLifecycleTransitionFailure(t);
}
@@ -673,7 +665,7 @@
catch (CacheException e)
{
log.warn("Needed to call stop() before destroying but stop() " +
- "threw exception. Proceeding to destroy", e);
+ "threw exception. Proceeding to destroy", e);
}
}
else
@@ -737,7 +729,7 @@
public void postRegister(Boolean registrationDone)
{
if (Boolean.TRUE.equals(registrationDone))
- {
+ {
log.debug("Registered in JMX under " + cacheObjectName);
if (cache != null && CacheStatus.STARTED.equals(cache.getCacheStatus()))
@@ -751,7 +743,7 @@
log.error("Caught exception registering cache interceptors with JMX", e);
}
}
-
+
registered = true;
}
}
@@ -796,14 +788,13 @@
public void setCache(Cache<K, V> cache)
{
if (cacheStatus != CacheStatus.INSTANTIATED
- && cacheStatus != CacheStatus.CREATING
- && cacheStatus != CacheStatus.DESTROYED)
+ && cacheStatus != CacheStatus.CREATING
+ && cacheStatus != CacheStatus.DESTROYED)
{
throw new IllegalStateException("Cannot set underlying cache after call to create()");
}
- // FIXME -- having to cast is ugly!!
- this.cache = (CacheImpl<K, V>) cache;
+ this.cache = (CacheSPI<K, V>) cache;
this.config = (cache == null ? null : cache.getConfiguration());
synchronized (listenerCount)
{
@@ -836,7 +827,7 @@
/**
* Gets whether sending of JMX notifications for this mbean's
* start/stop lifecycle changes is disabled.
- *
+ *
* @see #setDisableStateChangeNotifications(boolean)
*/
public boolean isDisableStateChangeNotifications()
@@ -847,8 +838,9 @@
/**
* Hook to allow PojoCacheJmxWrapper to suppress state change
* notifications from this mbean in lieu of its own.
- *
+ *
* @param disableStateChangeNotifications
+ *
*/
public void setDisableStateChangeNotifications(boolean disableStateChangeNotifications)
{
@@ -1050,12 +1042,12 @@
* @throws Error
*/
private void handleLifecycleTransitionFailure(Throwable t)
- throws CacheException, RuntimeException, Error
+ throws RuntimeException, Error
{
int oldState = getState();
cacheStatus = CacheStatus.FAILED;
sendStateChangeNotification(oldState, getState(), getClass().getSimpleName() + " failed", t);
-
+
if (t instanceof CacheException)
throw (CacheException) t;
else if (t instanceof RuntimeException)
@@ -1065,7 +1057,7 @@
else
throw new CacheException(t);
}
-
+
/**
* Helper for sending out state change notifications
*/
@@ -1073,17 +1065,17 @@
{
if (isDisableStateChangeNotifications())
return;
-
+
long now = System.currentTimeMillis();
-
+
AttributeChangeNotification stateChangeNotification = new AttributeChangeNotification(
- this,
- getNextNotificationSequenceNumber(), now, msg,
- "State", "java.lang.Integer",
- Integer.valueOf(oldState), Integer.valueOf(newState)
- );
+ this,
+ getNextNotificationSequenceNumber(), now, msg,
+ "State", "java.lang.Integer",
+ Integer.valueOf(oldState), Integer.valueOf(newState)
+ );
stateChangeNotification.setUserData(t);
-
- sendNotification(stateChangeNotification);
+
+ sendNotification(stateChangeNotification);
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/loader/AbstractCacheLoader.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -92,12 +92,13 @@
// no persistent state sent across; return?
return;
}
- if (objectFromStream instanceof NodeDataExceptionMarker){
- NodeDataExceptionMarker ndem = (NodeDataExceptionMarker) objectFromStream;
- throw new CacheException("State provider cacheloader at node " + ndem.getCacheNodeIdentity()
- + " threw exception during loadState (see Caused by)", ndem.getCause());
+ if (objectFromStream instanceof NodeDataExceptionMarker)
+ {
+ NodeDataExceptionMarker ndem = (NodeDataExceptionMarker) objectFromStream;
+ throw new CacheException("State provider cacheloader at node " + ndem.getCacheNodeIdentity()
+ + " threw exception during loadState (see Caused by)", ndem.getCause());
}
-
+
List nodeData = (List) objectFromStream;
//for (nd = (NodeData) in.readObject(); nd != null && !nd.isMarker(); nd = (NodeData) in.readObject())
@@ -110,7 +111,7 @@
{
NodeDataExceptionMarker ndem = (NodeDataExceptionMarker) nd;
throw new CacheException("State provider cacheloader at node " + ndem.getCacheNodeIdentity()
- + " threw exception during loadState (see Caused by)", ndem.getCause());
+ + " threw exception during loadState (see Caused by)", ndem.getCause());
}
if (moveToBuddy)
@@ -190,7 +191,7 @@
protected void getNodeDataList(Fqn fqn, List<NodeData> list) throws Exception
{
Map<Object, Object> attrs;
- Set<? extends Object> children_names;
+ Set<?> children_names;
String child_name;
Fqn tmp_fqn;
NodeData nd;
Modified: core/trunk/src/main/java/org/jboss/cache/loader/C3p0ConnectionFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/C3p0ConnectionFactory.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/loader/C3p0ConnectionFactory.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -63,7 +63,7 @@
if (log.isDebugEnabled())
{
log.debug(property + "=" + sysPropertyValue + " defined as system property. It will override the value defined in XML which was: " + xmlPropertyValue);
- };
+ }
}
}
}
@@ -86,7 +86,10 @@
public Connection checkoutConnection() throws SQLException
{
Connection connection = ds.getConnection();
- if (log.isTraceEnabled()) { log.trace("Connection checked out: " + connection); }
+ if (log.isTraceEnabled())
+ {
+ log.trace("Connection checked out: " + connection);
+ }
return connection;
}
@@ -95,8 +98,12 @@
try
{
DataSources.destroy(ds);
- if (log.isDebugEnabled()) { log.debug("Pooled datasource destroyed."); }
- } catch (SQLException sqle)
+ if (log.isDebugEnabled())
+ {
+ log.debug("Pooled datasource destroyed.");
+ }
+ }
+ catch (SQLException sqle)
{
log.warn("Could not destroy C3P0 connection pool: " + ds, sqle);
}
Modified: core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/loader/CacheLoaderManager.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -14,6 +14,7 @@
import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig;
+import org.jboss.cache.factories.annotations.Inject;
import java.util.ArrayList;
import java.util.Iterator;
@@ -71,18 +72,22 @@
* @param cache
* @throws CacheException
*/
+ @Inject
public void setConfig(CacheLoaderConfig config, CacheSPI cache) throws CacheException
{
this.config = config == null ? new CacheLoaderConfig() : config;
this.cache = cache;
- try
+ if (config != null)
{
- loader = createCacheLoader();
+ try
+ {
+ loader = createCacheLoader();
+ }
+ catch (Exception e)
+ {
+ throw new CacheException("Unable to create cache loaders", e);
+ }
}
- catch (Exception e)
- {
- throw new CacheException("Unable to create cache loaders", e);
- }
}
/**
@@ -100,7 +105,7 @@
// don't use a chaining cache loader at all.
ArrayList<IndividualCacheLoaderConfig> finalConfigs =
- new ArrayList<IndividualCacheLoaderConfig>();
+ new ArrayList<IndividualCacheLoaderConfig>();
// also if we are using passivation then just directly use the first cache loader.
if (config.useChainingCacheLoader())
@@ -193,7 +198,7 @@
* underlying cacheloader can be set. */
if (decorator instanceof AbstractDelegatingCacheLoader)
{
- AbstractDelegatingCacheLoader singletonDecorator = (AbstractDelegatingCacheLoader)decorator;
+ AbstractDelegatingCacheLoader singletonDecorator = (AbstractDelegatingCacheLoader) decorator;
/* set the cache loader to where calls will be delegated by the class providing the singleton
* store functionality. */
singletonDecorator.setCacheLoader(tmpLoader);
@@ -225,12 +230,12 @@
* Sets the cache instance associated with the given cache loader. This method was created for testing purpouses
* so that it can be overriden in the mock version of the CacheLoaderManager.
*
- * @param c instance of cache to be set in cache loader
+ * @param c instance of cache to be set in cache loader
* @param loader cache loader to which assign the cache instance
*/
protected void setCacheInLoader(CacheSPI c, CacheLoader loader)
{
- loader.setCache(c);
+ loader.setCache(c);
}
private CacheLoader createInstance(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException
@@ -401,7 +406,7 @@
{
CacheLoaderConfig.IndividualCacheLoaderConfig first = getCacheLoaderConfig().getFirstCacheLoaderConfig();
if (force ||
- (first != null && first.isPurgeOnStartup()))
+ (first != null && first.isPurgeOnStartup()))
{
loader.remove(Fqn.ROOT);
}
Modified: core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoader.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/loader/LocalDelegatingCacheLoader.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -6,14 +6,15 @@
*/
package org.jboss.cache.loader;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.util.HashMap;
+import java.util.Collections;
import java.util.Map;
import java.util.Set;
@@ -37,13 +38,13 @@
{
IndividualCacheLoaderConfig config;
- CacheImpl delegate = null;
+ CacheSPI delegate = null;
public LocalDelegatingCacheLoader()
{
}
- public LocalDelegatingCacheLoader(CacheImpl delegate)
+ public LocalDelegatingCacheLoader(CacheSPI delegate)
{
this.delegate = delegate;
}
@@ -60,8 +61,11 @@
public Set<?> getChildrenNames(Fqn fqn) throws Exception
{
- Set cn = delegate.getChildrenNames(fqn);
+ Node node = delegate.getRoot().getChild(fqn);
+ if (node == null) return null;
+ Set cn = node.getChildrenNames();
+
// the cache loader contract is a bit different from the cache when it comes to dealing with childrenNames
if (cn.isEmpty()) return null;
return cn;
@@ -69,17 +73,17 @@
public Map<Object, Object> get(Fqn name) throws Exception
{
- NodeSPI n = (NodeSPI) delegate.get(name);
+ NodeSPI n = (NodeSPI) delegate.getRoot().getChild(name);
if (n == null) return null;
// after this stage we know that the node exists. So never return a null - at worst, an empty map.
- Map m = n.getDataDirect();
- if (m == null) m = new HashMap(0);
+ Map<Object, Object> m = n.getDataDirect();
+ if (m == null) m = Collections.emptyMap();
return m;
}
public boolean exists(Fqn name) throws Exception
{
- return delegate.exists(name);
+ return delegate.peek(name, false, false) != null;
}
public Object put(Fqn name, Object key, Object value) throws Exception
@@ -99,15 +103,16 @@
public void remove(Fqn fqn) throws Exception
{
- delegate.remove(fqn);
+ delegate.removeNode(fqn);
}
public void removeData(Fqn fqn) throws Exception
{
- delegate.removeData(fqn);
+ Node node = delegate.getRoot().getChild(fqn);
+ if (node != null) node.clearData();
}
- protected void setDelegateCache(CacheImpl delegate)
+ protected void setDelegateCache(CacheSPI delegate)
{
this.delegate = delegate;
}
Modified: core/trunk/src/main/java/org/jboss/cache/loader/tcp/TcpCacheServer.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/tcp/TcpCacheServer.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/loader/tcp/TcpCacheServer.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -54,10 +54,6 @@
static Log log = LogFactory.getLog(TcpCacheServer.class);
- public TcpCacheServer()
- {
- }
-
public String getBindAddress()
{
return bind_addr != null ? bind_addr.toString() : "n/a";
@@ -118,8 +114,8 @@
if (cache == null)
{
throw new CacheException("cache cannot be obtained from CacheJmxWrapperMBean;" +
- " be sure start() is invoked on wrapper before it is invoked on the" +
- " TcpCacheServer");
+ " be sure start() is invoked on wrapper before it is invoked on the" +
+ " TcpCacheServer");
}
}
else if (config != null)
Modified: core/trunk/src/main/java/org/jboss/cache/lock/IdentityLock.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/IdentityLock.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/lock/IdentityLock.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -128,9 +128,9 @@
* Return a copy of the reader lock owner in List. Size is zero is not available. Note that this list
* is synchronized.
*
- * @return Set of readers
+ * @return Collection<Object> of readers
*/
- public Set<Object> getReaderOwners()
+ public Collection<Object> getReaderOwners()
{
return map_.readerOwners();
}
@@ -213,7 +213,7 @@
release(caller);// bug fix: remember to release the read lock before throwing the exception
map_.removeReader(caller);
String errStr = "upgrade lock for " + getFqn() + " could not be acquired after " + timeout + " ms." +
- " Lock map ownership " + map_.printInfo() + " (caller=" + caller + ", lock info: " + toString(true) + ')';
+ " Lock map ownership " + map_.printInfo() + " (caller=" + caller + ", lock info: " + toString(true) + ')';
log.trace(errStr);
throw new UpgradeException(errStr);
}
@@ -239,7 +239,7 @@
if (!rc)
{
String errStr = "write lock for " + getFqn() + " could not be acquired after " + timeout + " ms. " +
- "Locks: " + map_.printInfo() + " (caller=" + caller + ", lock info: " + toString(true) + ')';
+ "Locks: " + map_.printInfo() + " (caller=" + caller + ", lock info: " + toString(true) + ')';
log.trace(errStr);
throw new TimeoutException(errStr);
}
Modified: core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -6,10 +6,10 @@
*/
package org.jboss.cache.lock;
-import org.jboss.cache.util.concurrent.ConcurrentHashSet;
-
+import java.util.Collection;
import java.util.Collections;
-import java.util.Set;
+import java.util.LinkedList;
+import java.util.List;
/**
* Provide lock ownership mapping.
@@ -25,13 +25,9 @@
private Object writeOwner_ = null;
- // This is more efficient (lower CPU utilisation and better concurrency) than a CopyOnWriteArraySet.
- private final Set<Object> readOwnerList_ = new ConcurrentHashSet<Object>();
+ // This is more efficient (lower CPU utilisation and better concurrency) than a CopyOnWriteArraySet or ConcurrentHashSet.
+ private final List<Object> readOwnerList_ = Collections.synchronizedList(new LinkedList<Object>());
- public LockMap()
- {
- }
-
/**
* Check whether this owner has reader or writer ownership.
*
@@ -116,9 +112,9 @@
/**
* Returns an unmodifiable set of reader owner objects.
*/
- public Set<Object> readerOwners()
+ public Collection<Object> readerOwners()
{
- return Collections.unmodifiableSet(readOwnerList_);
+ return Collections.unmodifiableList(readOwnerList_);
}
public void releaseReaderOwners(LockStrategy lock)
Modified: core/trunk/src/main/java/org/jboss/cache/lock/NodeLock.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/NodeLock.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/lock/NodeLock.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -1,10 +1,11 @@
package org.jboss.cache.lock;
+import java.util.Collection;
import java.util.Set;
/**
- * Interface for a lock for nodes.
+ * Interface for a lock for nodes.
*/
public interface NodeLock
{
@@ -15,13 +16,13 @@
}
/**
- * Returns a copy of the reader lock owner in List.
+ * Returns a copy of the reader lock owner in List.
* Size is zero is not available. Note that this list
* is synchronized.
*
- * @return Set of readers
+ * @return Collection<Object> of readers
*/
- Set getReaderOwners();
+ Collection<Object> getReaderOwners();
/**
* Returns the writer lock owner object. Null if not available.
@@ -98,8 +99,9 @@
/**
* Recursively acquire locks for this node and all subnodes.
- * @param caller lock owner
- * @param timeout time to wait
+ *
+ * @param caller lock owner
+ * @param timeout time to wait
* @param lock_type type of lock
* @return locks acquired
* @throws LockingException
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-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -12,6 +12,8 @@
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
import org.jboss.cache.buddyreplication.BuddyManager;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.transaction.GlobalTransaction;
import java.io.ByteArrayOutputStream;
@@ -39,6 +41,12 @@
*/
private Map<GlobalTransaction, Fqn> transactions = new ConcurrentHashMap<GlobalTransaction, Fqn>(16);
+ @Inject
+ private void injectDependencies(RegionManager regionManager, Configuration configuration)
+ {
+ init(regionManager, configuration.isInactiveOnStartup(), configuration.isUseRegionBasedMarshalling());
+ }
+
protected void init(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling)
{
this.useRegionBasedMarshalling = useRegionBasedMarshalling;
@@ -135,7 +143,7 @@
case MethodDeclarations.dataGravitationMethod_id:
case MethodDeclarations.evictNodeMethodLocal_id:
case MethodDeclarations.evictVersionedNodeMethodLocal_id:
- case MethodDeclarations.invalidateMethodLocal_id:
+ case MethodDeclarations.invalidateMethodLocal_id:
case MethodDeclarations.getChildrenNamesMethodLocal_id:
case MethodDeclarations.getDataMapMethodLocal_id:
case MethodDeclarations.getKeysMethodLocal_id:
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-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller200.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -67,6 +67,10 @@
// this is pretty nasty, and may need more thought.
protected final ThreadLocal<Fqn> regionForCall = new ThreadLocal<Fqn>();
+ public CacheMarshaller200()
+ {
+ }
+
public CacheMarshaller200(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling)
{
init(manager, defaultInactive, useRegionBasedMarshalling);
@@ -108,7 +112,8 @@
// a Fqn region.
region = regionForCall.get();
regionForCall.remove();
- if (log.isTraceEnabled()) log.trace("Suspect this is a return value. Extract region from ThreadLocal as " + region);
+ if (log.isTraceEnabled())
+ log.trace("Suspect this is a return value. Extract region from ThreadLocal as " + region);
// otherwise, we need to marshall the retval.
}
@@ -184,7 +189,8 @@
}
if (region == null)
{
- if (log.isDebugEnabled()) log.debug("Region does not exist for Fqn " + regionFqn + " - not using a context classloader.");
+ if (log.isDebugEnabled())
+ log.debug("Region does not exist for Fqn " + regionFqn + " - not using a context classloader.");
retValue = unmarshallObject(in, refMap);
}
else
@@ -223,7 +229,7 @@
{
// No region but default inactive means region is inactive
throw new InactiveRegionException("Cannot unmarshall message for region " + fqn + ". By default region " + fqn
- + " is inactive.");
+ + " is inactive.");
}
else
{
@@ -766,6 +772,7 @@
/**
* Reads a reference from a given stream.
+ *
* @param in the stream to read from
* @return an int representing a reference in RefMap.
* @throws IOException propagated from the OIS
@@ -777,7 +784,8 @@
/**
* Writes a reference to a given object output stream.
- * @param out the stream to write to
+ *
+ * @param out the stream to write to
* @param reference the reference to write
* @throws java.io.IOException propagated from the OOS
*/
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-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CacheMarshaller210.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -18,6 +18,10 @@
*/
public class CacheMarshaller210 extends CacheMarshaller200
{
+ public CacheMarshaller210()
+ {
+ }
+
public CacheMarshaller210(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling)
{
super(manager, defaultInactive, useRegionBasedMarshalling);
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/MethodCallFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/MethodCallFactory.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/MethodCallFactory.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -16,10 +16,12 @@
*/
public class MethodCallFactory
{
+
/**
- * Creates and initialised an instance of MethodCall
+ * Creates and initialised an instance of MethodCall.
*
* @param method Method instance of the MethodCall
+ * @param target The InvocationTarget instance to invoke the call on
* @param arguments list of parameters
* @return a new instance of MethodCall with the method id initialised
*/
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/NodeDataMarker.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/NodeDataMarker.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/NodeDataMarker.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -5,11 +5,6 @@
private static final long serialVersionUID = 4851793846346021014L;
- public NodeDataMarker()
- {
- super();
- }
-
public boolean isMarker()
{
return true;
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-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -31,11 +31,11 @@
*/
public class VersionAwareMarshaller extends AbstractMarshaller
{
-
+
private static final Log log = LogFactory.getLog(VersionAwareMarshaller.class);
private static final int VERSION_200 = 20;
private static final int VERSION_210 = 21;
-
+
private RegionManager manager;
private boolean defaultInactive, useRegionBasedMarshalling;
Marshaller defaultMarshaller;
@@ -44,6 +44,11 @@
public VersionAwareMarshaller(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling, String version)
{
+ this(manager, defaultInactive, useRegionBasedMarshalling, version, null);
+ }
+
+ public VersionAwareMarshaller(RegionManager manager, boolean defaultInactive, boolean useRegionBasedMarshalling, String version, Marshaller defaultMarshaller)
+ {
this.manager = manager;
this.defaultInactive = defaultInactive;
this.useRegionBasedMarshalling = useRegionBasedMarshalling;
@@ -54,12 +59,22 @@
versionInt = toMinorVersionInt(version);
// this will cause the correct marshaller to be created and put in the map of marshallers
- defaultMarshaller = getMarshaller(versionInt);
+ if (defaultMarshaller == null)
+ {
+ this.defaultMarshaller = getMarshaller(versionInt);
+ }
+ else
+ {
+ log.debug("Using the marshaller passed in - " + defaultMarshaller);
+ this.defaultMarshaller = defaultMarshaller;
+ marshallers.put(versionInt, defaultMarshaller);
+ }
+
if (log.isDebugEnabled())
{
log.debug("Initialised with version " + version + " and versionInt " + versionInt);
- log.debug("Using default marshaller " + defaultMarshaller.getClass());
+ log.debug("Using default marshaller class " + this.defaultMarshaller.getClass());
}
}
@@ -68,6 +83,11 @@
this(regionManager, configuration.isInactiveOnStartup(), configuration.isUseRegionBasedMarshalling(), configuration.getReplVersionString());
}
+ 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/>
@@ -195,13 +215,14 @@
if (marshaller == null)
{
marshaller = new CacheMarshaller200(manager, defaultInactive, useRegionBasedMarshalling);
- marshallers.put(VERSION_210, marshaller);
+ marshallers.put(VERSION_200, marshaller);
}
break;
case VERSION_210:
knownVersion = true;
default:
- if (!knownVersion) log.warn("Unknown replication version String. Falling back to the default marshaller, which is Version 2.1.0.");
+ if (!knownVersion)
+ log.warn("Unknown replication version String. Falling back to the default marshaller, which is Version 2.1.0.");
marshaller = marshallers.get(VERSION_210);
if (marshaller == null)
{
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-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -13,6 +13,7 @@
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.notifications.annotation.*;
import org.jboss.cache.notifications.event.*;
import static org.jboss.cache.notifications.event.Event.Type.*;
@@ -45,17 +46,27 @@
private static Class emptyMap = Collections.emptyMap().getClass();
private static Class singletonMap = Collections.singletonMap(null, null).getClass();
private static final Class[] allowedMethodAnnotations =
- {
- CacheStarted.class, CacheStopped.class, CacheBlocked.class, CacheUnblocked.class, NodeCreated.class, NodeRemoved.class, NodeVisited.class, NodeModified.class, NodeMoved.class,
- NodeActivated.class, NodePassivated.class, NodeLoaded.class, NodeEvicted.class, TransactionRegistered.class, TransactionCompleted.class, ViewChanged.class
- };
+ {
+ CacheStarted.class, CacheStopped.class, CacheBlocked.class, CacheUnblocked.class, NodeCreated.class, NodeRemoved.class, NodeVisited.class, NodeModified.class, NodeMoved.class,
+ NodeActivated.class, NodePassivated.class, NodeLoaded.class, NodeEvicted.class, TransactionRegistered.class, TransactionCompleted.class, ViewChanged.class
+ };
private static final Class[] parameterTypes =
- {
- CacheStartedEvent.class, CacheStoppedEvent.class, CacheBlockedEvent.class, CacheUnblockedEvent.class, NodeCreatedEvent.class, NodeRemovedEvent.class, NodeVisitedEvent.class, NodeModifiedEvent.class, NodeMovedEvent.class,
- NodeActivatedEvent.class, NodePassivatedEvent.class, NodeLoadedEvent.class, NodeEvictedEvent.class, TransactionRegisteredEvent.class, TransactionCompletedEvent.class, ViewChangedEvent.class
- };
+ {
+ CacheStartedEvent.class, CacheStoppedEvent.class, CacheBlockedEvent.class, CacheUnblockedEvent.class, NodeCreatedEvent.class, NodeRemovedEvent.class, NodeVisitedEvent.class, NodeModifiedEvent.class, NodeMovedEvent.class,
+ NodeActivatedEvent.class, NodePassivatedEvent.class, NodeLoadedEvent.class, NodeEvictedEvent.class, TransactionRegisteredEvent.class, TransactionCompletedEvent.class, ViewChangedEvent.class
+ };
final Map<Class, List<ListenerInvocation>> listenerInvocations = new ConcurrentHashMap<Class, List<ListenerInvocation>>();
+ public Notifier()
+ {
+ }
+
+ @Inject
+ private void injectDependencies(Cache cache)
+ {
+ this.cache = cache;
+ }
+
public Notifier(Cache cache)
{
this.cache = cache;
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferGenerator.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -8,7 +8,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
@@ -31,11 +31,11 @@
private Log log = LogFactory.getLog(getClass().getName());
- private CacheImpl cache;
+ private CacheSPI cache;
private Set<Fqn> internalFqns;
- protected DefaultStateTransferGenerator(CacheImpl cache)
+ protected DefaultStateTransferGenerator(CacheSPI cache)
{
this.cache = cache;
this.internalFqns = cache.getInternalFqns();
@@ -179,10 +179,4 @@
{
// no-op in this base class
}
-
- protected CacheImpl getTreeCache()
- {
- return cache;
- }
-
}
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferIntegrator.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -9,18 +9,18 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.Node;
import org.jboss.cache.NodeFactory;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.Region;
-import org.jboss.cache.RegionManager;
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.eviction.EvictedEventNode;
import org.jboss.cache.eviction.NodeEventType;
import org.jboss.cache.loader.CacheLoader;
+import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.marshall.NodeData;
import org.jboss.cache.marshall.NodeDataExceptionMarker;
import org.jboss.cache.marshall.NodeDataMarker;
@@ -40,7 +40,7 @@
protected Log log = LogFactory.getLog(getClass().getName());
- private CacheImpl cache;
+ private CacheSPI cache;
private Fqn targetFqn;
@@ -50,14 +50,14 @@
private Set<Fqn> internalFqns;
- public DefaultStateTransferIntegrator(Fqn targetFqn, CacheImpl cache)
+ public DefaultStateTransferIntegrator(Fqn targetFqn, CacheSPI cache)
{
this.targetFqn = targetFqn;
this.cache = cache;
this.factory = cache.getConfiguration().getRuntimeConfig().getNodeFactory();
this.nodeType = cache.getConfiguration().isNodeLockingOptimistic()
- ? NodeFactory.NodeType.VERSIONED_NODE
- : NodeFactory.NodeType.UNVERSIONED_NODE;
+ ? NodeFactory.NodeType.VERSIONED_NODE
+ : NodeFactory.NodeType.UNVERSIONED_NODE;
this.internalFqns = cache.getInternalFqns();
}
@@ -91,13 +91,13 @@
notifyAllNodesCreated(cache.getInvocationContext(), target);
}
catch (Exception e)
- {
+ {
throw new CacheException(e);
}
finally
{
if (!transientSet)
- {
+ {
target.clearDataDirect();
target.removeChildrenDirect();
}
@@ -121,8 +121,8 @@
protected void integratePersistentState(ObjectInputStream in) throws Exception
{
- CacheLoader loader = cache.getCacheLoader();
- if (loader == null)
+ CacheLoaderManager loaderManager = cache.getCacheLoaderManager();
+ if (loaderManager == null)
{
if (log.isTraceEnabled())
{
@@ -131,6 +131,7 @@
}
else
{
+ CacheLoader loader = loaderManager.getCacheLoader();
if (log.isTraceEnabled())
{
log.trace("integrating persistent state using " + loader.getClass().getName());
@@ -152,7 +153,7 @@
catch (ClassCastException cce)
{
log.error("Failed integrating persistent state. One of cacheloaders is not"
- + " adhering to state stream format. See JBCACHE-738.");
+ + " adhering to state stream format. See JBCACHE-738.");
throw cce;
}
finally
@@ -173,11 +174,6 @@
}
}
- protected CacheImpl getCache()
- {
- return cache;
- }
-
protected NodeFactory getFactory()
{
return factory;
@@ -201,13 +197,13 @@
{
if (curr == null) return;
ctx.setOriginLocal(false);
- getCache().getNotifier().notifyNodeCreated(curr.getFqn(), true, ctx);
- getCache().getNotifier().notifyNodeCreated(curr.getFqn(), false, ctx);
+ cache.getNotifier().notifyNodeCreated(curr.getFqn(), true, ctx);
+ cache.getNotifier().notifyNodeCreated(curr.getFqn(), false, ctx);
// AND notify that they have been modified!!
if (!curr.getKeysDirect().isEmpty())
{
- getCache().getNotifier().notifyNodeModified(curr.getFqn(), true, NodeModifiedEvent.ModificationType.PUT_MAP, Collections.emptyMap(), ctx);
- getCache().getNotifier().notifyNodeModified(curr.getFqn(), false, NodeModifiedEvent.ModificationType.PUT_MAP, curr.getDataDirect(), ctx);
+ cache.getNotifier().notifyNodeModified(curr.getFqn(), true, NodeModifiedEvent.ModificationType.PUT_MAP, Collections.emptyMap(), ctx);
+ cache.getNotifier().notifyNodeModified(curr.getFqn(), false, NodeModifiedEvent.ModificationType.PUT_MAP, curr.getDataDirect(), ctx);
}
ctx.setOriginLocal(true);
@@ -268,7 +264,7 @@
Fqn tferFqn = nd.getFqn();
Fqn tgtFqn = target.getFqn();
boolean move = tgtFqn.isChildOrEquals(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN)
- && !tferFqn.isChildOrEquals(tgtFqn);
+ && !tferFqn.isChildOrEquals(tgtFqn);
// If it is an integration, calculate how many levels of offset
int offset = move ? tgtFqn.size() - tferFqn.size() : 0;
@@ -346,7 +342,7 @@
if (region != null && region.getEvictionPolicy() != null)
{
region.putNodeEvent(new EvictedEventNode(fqn, NodeEventType.ADD_NODE_EVENT,
- attrs == null ? 0 : attrs.size()));
+ attrs == null ? 0 : attrs.size()));
}
// Recursively call, which will walk down the tree
@@ -357,7 +353,7 @@
{
NodeDataExceptionMarker ndem = (NodeDataExceptionMarker) nd;
throw new CacheException("State provider node " + ndem.getCacheNodeIdentity()
- + " threw exception during loadState", ndem.getCause());
+ + " threw exception during loadState", ndem.getCause());
}
return null;
}
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferFactory.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferFactory.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -6,7 +6,7 @@
*/
package org.jboss.cache.statetransfer;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Version;
@@ -31,8 +31,7 @@
* @return the {@link StateTransferGenerator}
* @throws IllegalStateException if the cache's ReplicationVersion is < 2.0.0
*/
- public static StateTransferGenerator
- getStateTransferGenerator(CacheImpl cache)
+ public static StateTransferGenerator getStateTransferGenerator(CacheSPI cache)
{
short version = cache.getConfiguration().getReplicationVersion();
@@ -44,10 +43,10 @@
return new DefaultStateTransferGenerator(cache); // current default
}
- public static StateTransferIntegrator getStateTransferIntegrator(ObjectInputStream in, Fqn fqn, CacheImpl cache)
- throws Exception
+ public static StateTransferIntegrator getStateTransferIntegrator(ObjectInputStream in, Fqn fqn, CacheSPI cache)
+ throws Exception
{
- short version = 0;
+ short version;
try
{
version = (Short) cache.getMarshaller().objectFromObjectStream(in);
@@ -59,7 +58,9 @@
{
in.close();
}
- catch (IOException ignored) {}
+ catch (IOException ignored)
+ {
+ }
throw new IllegalStateException("Stream corrupted ", io);
}
@@ -70,5 +71,4 @@
else
return new DefaultStateTransferIntegrator(fqn, cache); // current default
}
-
}
Modified: core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -9,9 +9,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheImpl;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.lock.TimeoutException;
@@ -30,16 +31,21 @@
public static final String PARTIAL_STATE_DELIMITER = "_PARTIAL_STATE_DELIMITER";
- private final CacheImpl cache;
+ private CacheSPI cache;
- public StateTransferManager(CacheImpl cache)
+ public StateTransferManager()
{
+ }
+
+ @Inject
+ private void injectDependencies(CacheSPI cache)
+ {
this.cache = cache;
}
- public CacheImpl getTreeCache()
+ public StateTransferManager(CacheSPI cache)
{
- return cache;
+ this.cache = cache;
}
/**
@@ -64,7 +70,7 @@
public void getState(ObjectOutputStream out, Fqn fqn, long timeout, boolean force, boolean suppressErrors) throws Throwable
{
// can't give state for regions currently being activated/inactivated
- boolean canProvideState = (!cache.getRegionManager().isInactive(fqn) && cache.findNode(fqn) != null);
+ boolean canProvideState = (!cache.getRegionManager().isInactive(fqn) && cache.peek(fqn, false, false) != null);
boolean fetchTransientState = cache.getConfiguration().isFetchInMemoryState();
CacheLoaderManager cacheLoaderManager = cache.getCacheLoaderManager();
@@ -76,7 +82,7 @@
StateTransferGenerator generator = getStateTransferGenerator();
Object owner = getOwnerForLock();
long startTime = System.currentTimeMillis();
- NodeSPI rootNode = cache.findNode(fqn);
+ NodeSPI rootNode = cache.peek(fqn, false, false);
try
{
@@ -108,7 +114,7 @@
{
exceptionMessage += " Region for fqn " + fqn + " is inactive.";
}
- if (cache.findNode(fqn) == null)
+ if (cache.peek(fqn, false, false) == null)
{
exceptionMessage += " There is no cache node at fqn " + fqn;
}
@@ -141,17 +147,16 @@
*/
public void setState(ObjectInputStream in, Fqn targetRoot) throws Exception
{
- CacheImpl cache = getTreeCache();
- NodeSPI target = cache.findNode(targetRoot);
+ NodeSPI target = cache.peek(targetRoot, false, false);
if (target == null)
{
// Create the integration root, but do not replicate
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
-
+
//needed for BR state transfers
cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true);
cache.put(targetRoot, null);
- target = cache.findNode(targetRoot);
+ target = cache.peek(targetRoot, false, false);
}
Object o = cache.getMarshaller().objectFromObjectStream(in);
Boolean hasState = (Boolean) o;
@@ -162,7 +167,7 @@
else
{
throw new CacheException("Cache instance at " + cache.getLocalAddress()
- + " cannot integrate state since state provider could not provide state due to " + cache.getMarshaller().objectFromObjectStream(in));
+ + " cannot integrate state since state provider could not provide state due to " + cache.getMarshaller().objectFromObjectStream(in));
}
}
@@ -246,7 +251,7 @@
catch (TimeoutException te)
{
log.error("Caught TimeoutException acquiring locks on region " +
- root.getFqn(), te);
+ root.getFqn(), te);
if (force)
{
// Until we have FLUSH in place, don't force locks
@@ -289,12 +294,12 @@
protected StateTransferGenerator getStateTransferGenerator()
{
- return StateTransferFactory.getStateTransferGenerator(getTreeCache());
+ return StateTransferFactory.getStateTransferGenerator(cache);
}
protected StateTransferIntegrator getStateTransferIntegrator(ObjectInputStream istream, Fqn fqn) throws Exception
{
- return StateTransferFactory.getStateTransferIntegrator(istream, fqn, getTreeCache());
+ return StateTransferFactory.getStateTransferIntegrator(istream, fqn, cache);
}
/**
@@ -303,7 +308,7 @@
*/
private Object getOwnerForLock()
{
- Object owner = getTreeCache().getCurrentTransaction();
+ Object owner = cache.getCurrentTransaction();
if (owner == null)
{
owner = Thread.currentThread();
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/BatchModeTransactionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/BatchModeTransactionManager.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/BatchModeTransactionManager.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -6,31 +6,32 @@
/**
* Not really a transaction manager in the truest sense of the word. Only used to batch up operations. Proper
* transactional symantics of rollbacks and recovery are NOT used here. This is used by PojoCache.
- *
+ *
* @author bela
* @version $Revision$
* Date: May 15, 2003
* Time: 4:11:37 PM
*/
-public class BatchModeTransactionManager extends DummyBaseTransactionManager {
- static BatchModeTransactionManager instance=null;
- static Log log=LogFactory.getLog(BatchModeTransactionManager.class);
- private static final long serialVersionUID = 5656602677430350961L;
+public class BatchModeTransactionManager extends DummyBaseTransactionManager
+{
+ static BatchModeTransactionManager instance = null;
+ static Log log = LogFactory.getLog(BatchModeTransactionManager.class);
+ private static final long serialVersionUID = 5656602677430350961L;
- public BatchModeTransactionManager() {
- }
-
- public static BatchModeTransactionManager getInstance() {
- if(instance == null) {
- instance=new BatchModeTransactionManager();
+ public static BatchModeTransactionManager getInstance()
+ {
+ if (instance == null)
+ {
+ instance = new BatchModeTransactionManager();
}
return instance;
}
- public static void destroy() {
- if(instance == null) return;
+ public static void destroy()
+ {
+ if (instance == null) return;
instance.setTransaction(null);
- instance=null;
+ instance = null;
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/DummyContextFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/DummyContextFactory.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/DummyContextFactory.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -10,12 +10,13 @@
* Date: May 15, 2003
* Time: 6:22:02 PM
*/
-public class DummyContextFactory implements InitialContextFactory {
+public class DummyContextFactory implements InitialContextFactory
+{
- static Context instance=null;
+ static Context instance = null;
- public DummyContextFactory() {
- ;
+ public DummyContextFactory()
+ {
}
/**
@@ -34,9 +35,10 @@
* interface.
* @throws NamingException If cannot create an initial context.
*/
- public Context getInitialContext(Hashtable environment) throws NamingException {
- if(instance == null)
- instance=new DummyContext();
+ public Context getInitialContext(Hashtable environment) throws NamingException
+ {
+ if (instance == null)
+ instance = new DummyContext();
return instance;
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/DummyTransactionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/DummyTransactionManager.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/DummyTransactionManager.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -1,14 +1,13 @@
package org.jboss.cache.transaction;
-import java.util.Properties;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import java.util.Properties;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
/**
* Simple transaction manager implementation that maintains transaction state
* in memory only.
@@ -27,10 +26,6 @@
private static final long serialVersionUID = 4396695354693176535L;
- public DummyTransactionManager()
- {
- }
-
public static DummyTransactionManager getInstance()
{
if (instance == null)
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/JBossTransactionManagerLookup.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/JBossTransactionManagerLookup.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/JBossTransactionManagerLookup.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -11,13 +11,12 @@
* @author Bela Ban, Aug 26 2003
* @version $Id$
*/
-public class JBossTransactionManagerLookup implements TransactionManagerLookup {
+public class JBossTransactionManagerLookup implements TransactionManagerLookup
+{
- public JBossTransactionManagerLookup() {
+ public TransactionManager getTransactionManager() throws Exception
+ {
+ return (TransactionManager) new InitialContext().lookup("java:/TransactionManager");
}
- public TransactionManager getTransactionManager() throws Exception {
- return (TransactionManager)new InitialContext().lookup("java:/TransactionManager");
- }
-
}
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/OptimisticTransactionEntry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/OptimisticTransactionEntry.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/OptimisticTransactionEntry.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -21,10 +21,6 @@
{
private TransactionWorkspace transactionWorkSpace = new TransactionWorkspaceImpl();
- public OptimisticTransactionEntry()
- {
- }
-
public String toString()
{
StringBuffer sb = new StringBuffer(super.toString());
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/TransactionEntry.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -96,13 +96,6 @@
private List<Fqn> removedNodes = new LinkedList<Fqn>();
/**
- * Constructs a new TransactionEntry.
- */
- public TransactionEntry()
- {
- }
-
- /**
* Adds a modification to the modification list.
*/
public void addModification(MethodCall m)
Modified: core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java 2007-12-11 17:26:38 UTC (rev 4833)
+++ core/trunk/src/main/java/org/jboss/cache/transaction/TransactionTable.java 2007-12-11 17:28:33 UTC (rev 4834)
@@ -45,13 +45,6 @@
private static final Log log = LogFactory.getLog(TransactionTable.class);
/**
- * Constructs a new table.
- */
- public TransactionTable()
- {
- }
-
- /**
* Returns the number of local transactions.
*/
public int getNumLocalTransactions()
@@ -279,7 +272,7 @@
/**
* Add the lock to the list of locks maintained for this transaction
* (needed for release of locks on commit or rollback)
- */
+ */
public void recordNodeLock(GlobalTransaction gtx, NodeLock lock)
{
try
17 years, 3 months
JBoss Cache SVN: r4833 - in core/trunk/src/main/java/org/jboss/cache: remoting and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2007-12-11 12:26:38 -0500 (Tue, 11 Dec 2007)
New Revision: 4833
Added:
core/trunk/src/main/java/org/jboss/cache/remoting/
core/trunk/src/main/java/org/jboss/cache/remoting/jgroups/
core/trunk/src/main/java/org/jboss/cache/remoting/jgroups/CacheMessageListener.java
Modified:
core/trunk/src/main/java/org/jboss/cache/Cache.java
core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
core/trunk/src/main/java/org/jboss/cache/CacheSPI.java
core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/RegionManager.java
core/trunk/src/main/java/org/jboss/cache/util/BeanUtils.java
Log:
Initial check in of injection and aop code
Modified: core/trunk/src/main/java/org/jboss/cache/Cache.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Cache.java 2007-12-11 17:25:09 UTC (rev 4832)
+++ core/trunk/src/main/java/org/jboss/cache/Cache.java 2007-12-11 17:26:38 UTC (rev 4833)
@@ -155,6 +155,18 @@
V put(Fqn<?> fqn, K key, V value);
/**
+ * Convenience method that takes a string representation of an Fqn. Otherwise identical to {@link #put(Fqn, Object, Object)}
+ *
+ * @param fqn String representation of the Fqn
+ * @param key key with which the specified value is to be associated.
+ * @param value value to be associated with the specified key.
+ * @return previous value associated with specified key, or <code>null</code> if there was no mapping for key.
+ * A <code>null</code> return can also indicate that the Node previously associated <code>null</code> with the specified key, if the implementation supports null values.
+ */
+
+ V put(String fqn, K key, V value);
+
+ /**
* Under special operating behavior, associates the value with the specified key for a node identified by the Fqn passed in.
* <ul>
* <li> Only goes through if the node specified does not exist; no-op otherwise.</i>
@@ -189,6 +201,11 @@
void put(Fqn<?> fqn, Map<K, V> data);
/**
+ * Convenience method that takes a string representation of an Fqn. Otherwise identical to {@link #put(Fqn, java.util.Map)}
+ */
+ void put(String fqn, Map<K, V> data);
+
+ /**
* Removes the mapping for this key from a Node.
* Returns the value to which the Node previously associated the key, or
* <code>null</code> if the Node contained no mapping for this key.
@@ -200,6 +217,11 @@
V remove(Fqn<?> fqn, K key);
/**
+ * Convenience method that takes a string representation of an Fqn. Otherwise identical to {@link #remove(Fqn, Object)}
+ */
+ V remove(String fqn, K key);
+
+ /**
* Removes a {@link Node} indicated by absolute {@link Fqn}.
*
* @param fqn {@link Node} to remove
@@ -208,6 +230,25 @@
boolean removeNode(Fqn<?> fqn);
/**
+ * Convenience method that takes a string representation of an Fqn. Otherwise identical to {@link #removeNode(Fqn)}
+ */
+ boolean removeNode(String fqn);
+
+ /**
+ * A convenience method to retrieve a node directly from the cache. Equivalent to calling cache.getRoot().getChild(fqn).
+ *
+ * @param fqn fqn of the node to retrieve
+ * @return a Node object, or a null if the node does not exist.
+ */
+ Node getNode(Fqn<?> fqn);
+
+ /**
+ * Convenience method that takes a string representation of an Fqn. Otherwise identical to {@link #getNode(Fqn)}
+ */
+ Node getNode(String fqn);
+
+
+ /**
* Convenience method that allows for direct access to the data in a {@link Node}.
*
* @param fqn <b><i>absolute</i></b> {@link Fqn} to the {@link Node} to be accessed.
@@ -217,6 +258,11 @@
V get(Fqn<?> fqn, K key);
/**
+ * Convenience method that takes a string representation of an Fqn. Otherwise identical to {@link #get(Fqn, Object)}
+ */
+ V get(String fqn, K key);
+
+ /**
* Eviction call that evicts the specified {@link Node} from memory.
*
* @param fqn <b><i>absolute</i></b> {@link Fqn} to the {@link Node} to be evicted.
@@ -225,6 +271,13 @@
void evict(Fqn<?> fqn, boolean recursive);
/**
+ * Eviction call that evicts the specified {@link Node} from memory. Not recursive.
+ *
+ * @param fqn <b><i>absolute</i></b> {@link Fqn} to the {@link Node} to be evicted.
+ */
+ void evict(Fqn<?> fqn);
+
+ /**
* Retrieves a {@link Region} for a given {@link Fqn}. If the region does not exist,
* and <li>createIfAbsent</li> is true, then one is created.
* <p/>
@@ -364,10 +417,58 @@
void move(Fqn<?> nodeToMove, Fqn<?> newParent) throws NodeNotExistsException;
/**
+ * Convenience method that takes in string representations of Fqns. Otherwise identical to {@link #move(Fqn, Fqn)}
+ */
+ void move(String nodeToMove, String newParent) throws NodeNotExistsException;
+
+ /**
* Returns the version of the cache as a string.
*
* @return the version string of the cache.
* @see Version#printVersion
*/
String getVersion();
+
+ /**
+ * Retrieves a defensively copied data map of the underlying node. A convenience method to retrieving a node and
+ * getting data from the node directly.
+ *
+ * @param fqn
+ * @return map of data, or an empty map
+ * @throws CacheException
+ */
+ Map<K, V> getData(Fqn<?> fqn);
+
+ /**
+ * Convenience method that takes in a String represenation of the Fqn. Otherwise identical to {@link #getKeys(Fqn)}.
+ */
+ Set<K> getKeys(String fqn);
+
+ /**
+ * Returns a set of attribute keys for the Fqn.
+ * Returns null if the node is not found, otherwise a Set.
+ * The set is a copy of the actual keys for this node.
+ * <p/>
+ * A convenience method to retrieving a node and
+ * getting keys from the node directly.
+ *
+ * @param fqn name of the node
+ */
+ Set<K> getKeys(Fqn<?> fqn);
+
+ /**
+ * Convenience method that takes in a String represenation of the Fqn. Otherwise identical to {@link #removeData(Fqn)}.
+ */
+ void clearData(String fqn);
+
+ /**
+ * Removes the keys and properties from a named node.
+ * <p/>
+ * A convenience method to retrieving a node and
+ * getting keys from the node directly.
+ *
+ * @param fqn name of the node
+ */
+ void clearData(Fqn<?> fqn);
+
}
Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-11 17:25:09 UTC (rev 4832)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java 2007-12-11 17:26:38 UTC (rev 4833)
@@ -12,12 +12,13 @@
import org.jboss.cache.buddyreplication.BuddyManager;
import org.jboss.cache.buddyreplication.BuddyNotInitException;
import org.jboss.cache.buddyreplication.GravitateResult;
-import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.NodeLockingScheme;
import org.jboss.cache.config.Option;
import org.jboss.cache.config.RuntimeConfig;
+import org.jboss.cache.factories.ComponentRegistry;
import org.jboss.cache.factories.InterceptorChainFactory;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.CacheLoaderManager;
@@ -33,41 +34,33 @@
import org.jboss.cache.marshall.MethodCallFactory;
import org.jboss.cache.marshall.MethodDeclarations;
import org.jboss.cache.marshall.NodeData;
-import org.jboss.cache.marshall.VersionAwareMarshaller;
import org.jboss.cache.notifications.Notifier;
import org.jboss.cache.notifications.event.NodeModifiedEvent;
import org.jboss.cache.optimistic.DataVersion;
+import org.jboss.cache.remoting.jgroups.CacheMessageListener;
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.OptimisticTransactionEntry;
import org.jboss.cache.transaction.TransactionEntry;
import org.jboss.cache.transaction.TransactionManagerLookup;
import org.jboss.cache.transaction.TransactionTable;
-import org.jboss.cache.util.ExposedByteArrayOutputStream;
import org.jboss.cache.util.ThreadGate;
import org.jboss.cache.util.concurrent.ConcurrentHashSet;
-import org.jboss.util.stream.MarshalledValueInputStream;
-import org.jboss.util.stream.MarshalledValueOutputStream;
import org.jgroups.*;
import org.jgroups.blocks.GroupRequest;
import org.jgroups.blocks.RpcDispatcher;
import org.jgroups.blocks.RspFilter;
import org.jgroups.util.Rsp;
import org.jgroups.util.RspList;
-import org.jgroups.util.Util;
import javax.management.MBeanServerFactory;
import javax.transaction.Status;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
import java.io.NotSerializableException;
-import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
/**
* The default implementation class of {@link org.jboss.cache.Cache} and {@link org.jboss.cache.CacheSPI}. This class
@@ -83,7 +76,7 @@
* @author Daniel Huang (dhuang(a)jboss.org)
* @see org.jboss.cache.Cache
*/
-public class CacheImpl<K, V> implements CacheSPI<K, V>
+public class CacheImpl
{
/**
@@ -99,7 +92,7 @@
/**
* Root node.
*/
- private NodeSPI<K, V> root;
+ private NodeSPI root;
/**
* Cache's region manager.
@@ -129,38 +122,23 @@
/**
* JGroups message listener.
*/
- private MessageListenerAdaptor ml = new MessageListenerAdaptor();
+ private CacheMessageListener messageListener;
/**
* Maintains mapping of transactions (keys) and Modifications/Undo-Operations
*/
- private final TransactionTable tx_table = new TransactionTable();
+ private TransactionTable transactionTable;
/**
- * HashMap<Thread, List<Lock>, maintains locks acquired by threads (used when no TXs are used)
- */
- private Map<Thread, List<NodeLock>> lock_table;
-
- /**
* Set<Fqn> of Fqns of the topmost node of internal regions that should
* not included in standard state transfers.
*/
private Set<Fqn> internalFqns = new ConcurrentHashSet<Fqn>();
/**
- * True if state was initialized during start-up.
- */
- private volatile boolean isStateSet = false;
-
- /**
- * Class name used to handle evictions.
- */
- private String evictionInterceptorClass = "org.jboss.cache.interceptors.EvictionInterceptor";
-
- /**
* Marshaller if register to handle marshalling
*/
- private Marshaller marshaller_ = null;
+ private Marshaller marshaller = null;
/**
* {@link #invokeMethod(org.jboss.cache.marshall.MethodCall,boolean)} will dispatch to this chain of interceptors.
@@ -177,7 +155,7 @@
/**
* Used to get the Transaction associated with the current thread
*/
- private TransactionManager tm = null;
+ private TransactionManager transactionManager = null;
/**
* Cache loader manager.
@@ -218,33 +196,49 @@
}
};
- private Configuration configuration;
+ private final Configuration configuration;
+ private final ComponentRegistry componentRegistry;
+ private NodeFactory nodeFactory;
+ private CacheSPI spi;
/**
* Constructs an uninitialized CacheImpl.
*/
protected CacheImpl() throws Exception
{
- configuration = new Configuration(this);
- notifier = new Notifier(this);
- regionManager = new RegionManager(this);
- cacheStatus = CacheStatus.INSTANTIATED;
+ this(new Configuration());
}
- public StateTransferManager getStateTransferManager()
+ /**
+ * Constructs an uninitialized CacheImpl.
+ */
+ protected CacheImpl(Configuration configuration) throws Exception
{
- if (stateTransferManager == null)
- {
- stateTransferManager = new StateTransferManager(this);
- }
- return stateTransferManager;
+ this.configuration = configuration;
+ this.componentRegistry = new ComponentRegistry(configuration);
+ this.cacheStatus = CacheStatus.INSTANTIATED;
}
- public void setStateTransferManager(StateTransferManager manager)
+ protected ComponentRegistry getComponentRegistry()
{
- this.stateTransferManager = manager;
+ return componentRegistry;
}
+ @Inject
+ private void injectDependencies(Notifier notifier, RegionManager regionManager, TransactionManager transactionManager,
+ TransactionTable transactionTable, StateTransferManager stateTransferManager, NodeFactory nodeFactory,
+ CacheSPI spi, CacheMessageListener messageListener)
+ {
+ this.notifier = notifier;
+ this.regionManager = regionManager;
+ this.transactionManager = transactionManager;
+ this.transactionTable = transactionTable;
+ this.stateTransferManager = stateTransferManager;
+ this.nodeFactory = nodeFactory;
+ this.spi = spi;
+ this.messageListener = messageListener;
+ }
+
public Configuration getConfiguration()
{
return configuration;
@@ -261,7 +255,7 @@
/**
* Returns the root node.
*/
- public NodeSPI<K, V> getRoot()
+ public NodeSPI getRoot()
{
return root;
}
@@ -299,27 +293,15 @@
*/
public TransactionTable getTransactionTable()
{
- return tx_table;
+ return transactionTable;
}
/**
- * Returns the lock table.
- */
- public Map<Thread, List<NodeLock>> getLockTable()
- {
- if (lock_table == null)
- {
- lock_table = new ConcurrentHashMap<Thread, List<NodeLock>>();
- }
- return lock_table;
- }
-
- /**
* Returns the contents of the TransactionTable as a string.
*/
public String dumpTransactionTable()
{
- return tx_table.toString(true);
+ return transactionTable.toString(true);
}
/**
@@ -348,11 +330,6 @@
return cacheLoaderManager.getCacheLoader();
}
- public String getEvictionInterceptorClass()
- {
- return this.evictionInterceptorClass;
- }
-
private void setUseReplQueue(boolean flag)
{
if (flag)
@@ -406,7 +383,7 @@
*/
public TransactionManager getTransactionManager()
{
- return tm;
+ return transactionManager;
}
/**
@@ -430,13 +407,13 @@
}
}
- void fetchPartialState(List<Address> sources, Fqn sourceTarget, Fqn integrationTarget) throws Exception
+ public void fetchPartialState(List<Address> sources, Fqn sourceTarget, Fqn integrationTarget) throws Exception
{
String encodedStateId = sourceTarget + StateTransferManager.PARTIAL_STATE_DELIMITER + integrationTarget;
fetchPartialState(sources, encodedStateId);
}
- void fetchPartialState(List<Address> sources, Fqn subtree) throws Exception
+ public void fetchPartialState(List<Address> sources, Fqn subtree) throws Exception
{
if (subtree == null)
{
@@ -455,7 +432,7 @@
if (log.isWarnEnabled())
{
log.warn("Cannot fetch partial state, targets are " + sources +
- " and stateId is " + stateId);
+ " and stateId is " + stateId);
}
return;
}
@@ -478,13 +455,13 @@
for (Address target : targets)
{
log.debug("Node " + getLocalAddress() + " fetching partial state " + stateId + " from member " + target);
- isStateSet = false;
+ messageListener.setStateSet(false);
successfulTransfer = channel.getState(target, stateId, configuration.getStateRetrievalTimeout());
if (successfulTransfer)
{
try
{
- ml.waitForState();
+ messageListener.waitForState();
}
catch (Exception transferFailed)
{
@@ -538,7 +515,7 @@
* @throws Error
*/
private void handleLifecycleTransitionFailure(Throwable t)
- throws CacheException, RuntimeException, Error
+ throws RuntimeException, Error
{
cacheStatus = CacheStatus.FAILED;
if (t instanceof CacheException)
@@ -562,23 +539,23 @@
configureLogCategory();
// initialise the node factory and set this in the runtime.
- NodeFactory<K, V> nf;
- if ((nf = configuration.getRuntimeConfig().getNodeFactory()) == null)
- {
- nf = new NodeFactory<K, V>(this);
- configuration.getRuntimeConfig().setNodeFactory(nf);
- }
- else
- {
- // don't create a new one each and every time. After stopping and starting the cache, the old NodeFactory may still be valid.
- nf.init();
- }
+// NodeFactory nf;
+// if ((nf = configuration.getRuntimeConfig().getNodeFactory()) == null)
+// {
+// nf = new NodeFactory(this);
+// configuration.getRuntimeConfig().setNodeFactory(nf);
+// }
+// else
+// {
+// // don't create a new one each and every time. After stopping and starting the cache, the old NodeFactory may still be valid.
+// nf.init();
+// }
- if (notifier == null)
- notifier = new Notifier(this);
+// if (notifier == null)
+// notifier = new Notifier(this);
// create a new root temporarily.
- NodeSPI<K, V> tempRoot = nf.createRootDataNode();
+ NodeSPI tempRoot = nodeFactory.createRootDataNode();
// if we don't already have a root or the new (temp) root is of a different class (optimistic vs pessimistic) to
// the current root, then we use the new one. Helps preserve data between cache restarts.
if (root == null || !root.getClass().equals(tempRoot.getClass()))
@@ -589,29 +566,28 @@
initialiseCacheLoaderManager();
}
// first set up the Buddy Manager and an RPCManager
- if (configuration.getCacheMode() != Configuration.CacheMode.LOCAL)
- {
- getConfiguration().getRuntimeConfig().setRPCManager(new RPCManagerImpl(this));
- setBuddyReplicationConfig(configuration.getBuddyReplicationConfig());
- }
+// if (configuration.getCacheMode() != Configuration.CacheMode.LOCAL)
+// {
+ //getConfiguration().getRuntimeConfig().setRPCManager(new RPCManagerImpl(this));
+// setBuddyReplicationConfig(configuration.getBuddyReplicationConfig());
+// }
// build interceptor chain
- try
- {
- interceptor_chain = InterceptorChainFactory.getInstance().buildInterceptorChain(this);
- }
- catch (Exception e)
- {
- throw new CacheException("Unable to build interceptor chain", e);
- }
+// try
+// {
+// interceptor_chain = InterceptorChainFactory.getInstance().buildInterceptorChain(configuration, componentRegistry);
+// }
+// catch (Exception e)
+// {
+// throw new CacheException("Unable to build interceptor chain", e);
+// }
setUseReplQueue(configuration.isUseReplQueue());
setIsolationLevel(configuration.getIsolationLevel());
- getRegionManager();// make sure we create one
createEvictionPolicy();
- getRegionManager().setDefaultInactive(configuration.isInactiveOnStartup());
+ regionManager.setDefaultInactive(configuration.isInactiveOnStartup());
cacheStatus = CacheStatus.CREATED;
}
@@ -619,8 +595,8 @@
private void createTransactionManager()
{
// See if we had a TransactionManager injected into our config
- this.tm = configuration.getRuntimeConfig().getTransactionManager();
- if (tm == null)
+ this.transactionManager = configuration.getRuntimeConfig().getTransactionManager();
+ if (transactionManager == null)
{
// Nope. See if we can look it up from JNDI
if (this.tm_lookup == null && configuration.getTransactionManagerLookupClass() != null)
@@ -640,8 +616,8 @@
{
if (tm_lookup != null)
{
- tm = tm_lookup.getTransactionManager();
- configuration.getRuntimeConfig().setTransactionManager(tm);
+ transactionManager = tm_lookup.getTransactionManager();
+ configuration.getRuntimeConfig().setTransactionManager(transactionManager);
}
else
{
@@ -706,7 +682,7 @@
{
cacheStatus = CacheStatus.STARTING;
- createTransactionManager();
+// createTransactionManager();
// cache loaders should be initialised *before* any state transfers take place to prevent
// exceptions involving cache loaders not being started. - Manik
@@ -716,7 +692,7 @@
cacheLoaderManager.startCacheLoader();
}
// now that we have a TM we can init the interceptor chain
- InterceptorChainFactory.getInstance().initialiseInterceptors(interceptor_chain, this);
+// InterceptorChainFactory.getInstance().initialiseInterceptors(interceptor_chain, this);
switch (configuration.getCacheMode())
{
@@ -738,15 +714,15 @@
long start = System.currentTimeMillis();
channel.connect(configuration.getClusterName(), null, null, configuration.getStateRetrievalTimeout());
//if I am not the only and the first member than wait for a state to arrive
- if (getMembers().size()>1)
+ if (getMembers().size() > 1)
{
- ml.waitForState();
+ messageListener.waitForState();
}
if (log.isDebugEnabled())
{
log.debug("connected, state was retrieved successfully (in " + (System.currentTimeMillis() - start)
- + " milliseconds)");
+ + " milliseconds)");
}
}
catch (StateTransferException ste)
@@ -784,7 +760,8 @@
}
if (buddyManager != null)
{
- buddyManager.init(this);
+ //buddyManager.init(this);
+ buddyManager.init();
if (configuration.isUseReplQueue())
{
log.warn("Replication queue not supported when using buddy replication. Disabling repliction queue.");
@@ -809,7 +786,7 @@
regionManager.startEvictionThread();
}
- notifier.notifyCacheStarted(this, getInvocationContext());
+ notifier.notifyCacheStarted(spi, getInvocationContext());
addShutdownHook();
@@ -833,7 +810,7 @@
}
};
- Runtime.getRuntime().addShutdownHook(shutdownHook);
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
}
else
{
@@ -857,7 +834,7 @@
catch (CacheException e)
{
log.warn("Needed to call stop() before destroying but stop() " +
- "threw exception. Proceeding to destroy", e);
+ "threw exception. Proceeding to destroy", e);
}
}
else
@@ -906,7 +883,7 @@
configuration.getRuntimeConfig().setChannel(null);
}
disp = null;
- tm = null;
+ transactionManager = null;
}
/**
@@ -931,7 +908,7 @@
if (failed)
{
log.warn("Attempted to stop() from FAILED state, " +
- "but caught exception; try calling destroy()", t);
+ "but caught exception; try calling destroy()", t);
}
handleLifecycleTransitionFailure(t);
}
@@ -990,12 +967,12 @@
if (notifier != null)
{
- notifier.notifyCacheStopped(this, getInvocationContext());
+ notifier.notifyCacheStopped(spi, getInvocationContext());
notifier.removeAllCacheListeners();
}
// unset transaction manager reference
- tm = null;
+ transactionManager = null;
cacheStatus = CacheStatus.STOPPED;
@@ -1018,21 +995,21 @@
*
* @param config
*/
- private void setBuddyReplicationConfig(BuddyReplicationConfig config)
- {
- if (config != null)
- {
- buddyManager = new BuddyManager(config);
- if (!buddyManager.isEnabled())
- {
- buddyManager = null;
- }
- else
- {
- internalFqns.add(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN);
- }
- }
- }
+// private void setBuddyReplicationConfig(BuddyReplicationConfig config)
+// {
+// if (config != null)
+// {
+// buddyManager = new BuddyManager(config);
+// if (!buddyManager.isEnabled())
+// {
+// buddyManager = null;
+// }
+// else
+// {
+// internalFqns.add(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN);
+// }
+// }
+// }
/**
* Retrieves the Buddy Manager configured.
@@ -1062,7 +1039,7 @@
protected void createEvictionPolicy()
{
if (configuration.getEvictionConfig() != null
- && configuration.getEvictionConfig().isValidConfig())
+ && configuration.getEvictionConfig().isValidConfig())
{
regionManager.setEvictionConfig(configuration.getEvictionConfig());
regionManager.setUsingEvictions(true);
@@ -1149,10 +1126,10 @@
Fqn<Object> tmp = new Fqn<Object>(subtree, s);
_remove(null, // no tx
- tmp,
- false, // no undo ops
- false, // no nodeEvent
- true);// is an eviction
+ tmp,
+ false, // no undo ops
+ false, // no nodeEvent
+ true);// is an eviction
}
}
@@ -1161,7 +1138,7 @@
}
- private void removeLocksForDeadMembers(NodeSPI<K, V> node, List deadMembers)
+ private void removeLocksForDeadMembers(NodeSPI node, List deadMembers)
{
Set<GlobalTransaction> deadOwners = new HashSet<GlobalTransaction>();
NodeLock lock = node.getLock();
@@ -1188,14 +1165,14 @@
if (broken && log.isTraceEnabled())
{
log.trace("Broke lock for node " + node.getFqn() +
- " held by " + deadOwner);
+ " held by " + deadOwner);
}
}
// Recursively unlock children
- for (NodeSPI<K, V> child : node.getChildrenDirect())
+ for (Object child : node.getChildrenDirect())
{
- removeLocksForDeadMembers(child, deadMembers);
+ removeLocksForDeadMembers((NodeSPI) child, deadMembers);
}
}
@@ -1229,16 +1206,16 @@
*
* @param fqn name of the DataNode to retreive
*/
- public Node<K, V> get(Fqn<?> fqn) throws CacheException
+ public Node get(Fqn<?> fqn) throws CacheException
{
MethodCall m = MethodCallFactory.create(MethodDeclarations.getNodeMethodLocal, fqn);
- return (Node<K, V>) invokeMethod(m, true);
+ return (Node) invokeMethod(m, true);
}
/**
* Returns the raw data of the node; called externally internally.
*/
- public Node<K, V> _get(Fqn<?> fqn) throws CacheException
+ public Node _get(Fqn<?> fqn) throws CacheException
{
return findNode(fqn);
}
@@ -1254,53 +1231,27 @@
}
/**
- * Returns a set of attribute keys for the Fqn.
- * Returns null if the node is not found, otherwise a Set.
- * The set is a copy of the actual keys for this node.
- *
- * @param fqn name of the node
- */
- public Set getKeys(String fqn) throws CacheException
- {
- return getKeys(Fqn.fromString(fqn));
- }
-
- /**
- * Returns a set of attribute keys for the Fqn.
- * Returns null if the node is not found, otherwise a Set.
- * The set is a copy of the actual keys for this node.
- *
- * @param fqn name of the node
- */
- public Set<K> getKeys(Fqn<?> fqn) throws CacheException
- {
- MethodCall m = MethodCallFactory.create(MethodDeclarations.getKeysMethodLocal, fqn);
- return (Set<K>) invokeMethod(m, true);
- }
-
-
- /**
* Retrieves a defensively copied data map of the underlying node.
*
* @param fqn
* @return map of data, or an empty map
* @throws CacheException
*/
- public Map<K, V> getData(Fqn<?> fqn) throws CacheException
+ public Map getData(Fqn<?> fqn) throws CacheException
{
MethodCall m = MethodCallFactory.create(MethodDeclarations.getDataMapMethodLocal, fqn);
- return (Map<K, V>) invokeMethod(m, true);
+ return (Map) invokeMethod(m, true);
}
public Set _getKeys(Fqn<?> fqn) throws CacheException
{
- NodeSPI<K, V> n = findNode(fqn);
+ NodeSPI n = findNode(fqn);
if (n == null)
{
return null;
}
- Set<K> keys = n.getKeysDirect();
- return new HashSet<K>(keys);
+ Set keys = n.getKeysDirect();
+ return new HashSet(keys);
}
/**
@@ -1310,7 +1261,7 @@
* @param fqn The fully qualified name of the node.
* @param key The key.
*/
- public V get(String fqn, K key) throws CacheException
+ public Object get(String fqn, Object key) throws CacheException
{
return get(Fqn.fromString(fqn), key);
}
@@ -1323,21 +1274,21 @@
* @param fqn The fully qualified name of the node.
* @param key The key.
*/
- public V get(Fqn<?> fqn, K key) throws CacheException
+ public Object get(Fqn<?> fqn, Object key) throws CacheException
{
return get(fqn, key, true);
}
- public V _get(Fqn<?> fqn, K key, boolean sendNodeEvent) throws CacheException
+ public Object _get(Fqn<?> fqn, Object key, boolean sendNodeEvent) throws CacheException
{
InvocationContext ctx = getInvocationContext();
if (log.isTraceEnabled())
{
log.trace(new StringBuffer("_get(").append("\"").append(fqn).append("\", \"").append(key).append("\", \"").
- append(sendNodeEvent).append("\")"));
+ append(sendNodeEvent).append("\")"));
}
if (sendNodeEvent) notifier.notifyNodeVisited(fqn, true, ctx);
- NodeSPI<K, V> n = findNode(fqn);
+ NodeSPI n = findNode(fqn);
if (n == null)
{
log.trace("node not found");
@@ -1348,10 +1299,10 @@
}
- protected V get(Fqn<?> fqn, K key, boolean sendNodeEvent) throws CacheException
+ protected Object get(Fqn<?> fqn, Object key, boolean sendNodeEvent) throws CacheException
{
MethodCall m = MethodCallFactory.create(MethodDeclarations.getKeyValueMethodLocal, fqn, key, sendNodeEvent);
- return (V) invokeMethod(m, true);
+ return invokeMethod(m, true);
}
/**
@@ -1384,15 +1335,15 @@
return n != null;
}
- public NodeSPI<K, V> peek(Fqn<?> fqn, boolean includeDeletedNodes)
+ public NodeSPI peek(Fqn<?> fqn, boolean includeDeletedNodes)
{
return peek(fqn, includeDeletedNodes, false);
}
- public NodeSPI<K, V> peek(Fqn<?> fqn, boolean includeDeletedNodes, boolean includeInvalidNodes)
+ public NodeSPI peek(Fqn<?> fqn, boolean includeDeletedNodes, boolean includeInvalidNodes)
{
if (fqn == null || fqn.size() == 0) return root;
- NodeSPI<K, V> n = root;
+ NodeSPI n = root;
int fqnSize = fqn.size();
for (int i = 0; i < fqnSize; i++)
{
@@ -1463,12 +1414,12 @@
* @param fqn The fully qualified name of the new node
* @param data The new data. May be null if no data should be set in the node.
*/
- public void put(Fqn<?> fqn, Map<K, V> data) throws CacheException
+ public void put(Fqn<?> fqn, Map data) throws CacheException
{
put(fqn, data, false);
}
- public void put(Fqn<?> fqn, Map<K, V> data, boolean erase) throws CacheException
+ public void put(Fqn<?> fqn, Map data, boolean erase) throws CacheException
{
GlobalTransaction tx = getCurrentTransaction();
MethodCall m;
@@ -1493,7 +1444,7 @@
* @param value The value
* @return Object The previous value (if any), if node was present
*/
- public V put(String fqn, K key, V value) throws CacheException
+ public Object put(String fqn, Object key, Object value) throws CacheException
{
return put(Fqn.fromString(fqn), key, value);
}
@@ -1508,11 +1459,11 @@
* @param value The value
* @return Object The previous value (if any), if node was present
*/
- public V put(Fqn<?> fqn, K key, V value) throws CacheException
+ public Object put(Fqn<?> fqn, Object key, Object value) throws CacheException
{
GlobalTransaction tx = getCurrentTransaction();
MethodCall m = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, tx, fqn, key, value, true);
- return (V) invokeMethod(m, true);
+ return invokeMethod(m, true);
}
/**
@@ -1594,7 +1545,7 @@
* @param key The key to be removed
* @return The previous value, or null if none was associated with the given key
*/
- public V remove(String fqn, K key) throws CacheException
+ public Object remove(String fqn, Object key) throws CacheException
{
return remove(Fqn.fromString(fqn), key);
}
@@ -1606,32 +1557,14 @@
* @param key The key to be removed
* @return The previous value, or null if none was associated with the given key
*/
- public V remove(Fqn<?> fqn, K key) throws CacheException
+ public Object remove(Fqn<?> fqn, Object key) throws CacheException
{
GlobalTransaction tx = getCurrentTransaction();
MethodCall m = MethodCallFactory.create(MethodDeclarations.removeKeyMethodLocal, tx, fqn, key, true);
- return (V) invokeMethod(m, true);
+ return invokeMethod(m, true);
}
/**
- * Removes the keys and properties from a node.
- */
- public void removeData(String fqn) throws CacheException
- {
- removeData(Fqn.fromString(fqn));
- }
-
- /**
- * Removes the keys and properties from a named node.
- */
- public void removeData(Fqn fqn) throws CacheException
- {
- GlobalTransaction tx = getCurrentTransaction();
- MethodCall m = MethodCallFactory.create(MethodDeclarations.removeDataMethodLocal, tx, fqn, true);
- invokeMethod(m, true);
- }
-
- /**
* Lock a given node (or the entire subtree starting at this node)
* @param fqn The FQN of the node
* @param owner The owner. This is simply a key into a hashtable, and can be anything, e.g.
@@ -1716,23 +1649,7 @@
}
}
-
/**
- * Returns all children of a given node.
- * Returns null of the parent node was not found, or if there are no
- * children.
- * The set is unmodifiable.
- *
- * @param fqn The fully qualified name of the node
- * @return Set A list of child names (as Strings)
- * @see #getChildrenNames(Fqn)
- */
- public Set getChildrenNames(String fqn) throws CacheException
- {
- return getChildrenNames(Fqn.fromString(fqn));
- }
-
- /**
* Returns all children of a given node. Returns an empty set if there are no children.
* The set is unmodifiable.
*
@@ -1754,7 +1671,7 @@
@SuppressWarnings("unchecked")
public <E> Set<E> _getChildrenNames(Fqn<E> fqn) throws CacheException
{
- NodeSPI<K, V> n = findNode(fqn);
+ NodeSPI n = findNode(fqn);
if (n == null) return null;
Set<E> childNames = new HashSet<E>();
Map childrenMap = n.getChildrenMapDirect();
@@ -1810,9 +1727,9 @@
{
if (root == null)
return sb.toString();
- for (NodeSPI n : root.getChildrenDirect())
+ for (Object n : root.getChildrenDirect())
{
- n.print(sb, indent);
+ ((NodeSPI) n).print(sb, indent);
sb.append("\n");
}
}
@@ -1841,9 +1758,9 @@
StringBuffer sb = new StringBuffer("\n");
int indent = 0;
- for (NodeSPI n : root.getChildrenDirect())
+ for (Object n : root.getChildrenDirect())
{
- n.getLock().printLockInfo(sb, indent);
+ ((NodeSPI) n).getLock().printLockInfo(sb, indent);
sb.append("\n");
}
return sb.toString();
@@ -1857,17 +1774,20 @@
return numLocks(root);
}
- private int numLocks(NodeSPI<K, V> n)
+ private int numLocks(NodeSPI n)
{
int num = 0;
- if (n.getLock().isLocked())
+ if (n != null)
{
- num++;
+ if (n.getLock().isLocked())
+ {
+ num++;
+ }
+ for (Object cn : n.getChildrenDirect(true))
+ {
+ num += numLocks((NodeSPI) cn);
+ }
}
- for (NodeSPI<K, V> cn : n.getChildrenDirect(true))
- {
- num += numLocks(cn);
- }
return num;
}
@@ -1882,12 +1802,15 @@
return numNodes(root) - 1;
}
- private int numNodes(NodeSPI<K, V> n)
+ private int numNodes(NodeSPI n)
{
int count = 1;// for n
- for (NodeSPI<K, V> child : n.getChildrenDirect())
+ if (n != null)
{
- count += numNodes(child);
+ for (Object child : n.getChildrenDirect())
+ {
+ count += numNodes((NodeSPI) child);
+ }
}
return count;
}
@@ -1914,12 +1837,12 @@
return numAttributes(findNode(fqn));
}
- private int numAttributes(NodeSPI<K, V> n)
+ private int numAttributes(NodeSPI n)
{
int count = 0;
- for (NodeSPI<K, V> child : n.getChildrenDirect())
+ for (Object child : n.getChildrenDirect())
{
- count += numAttributes(child);
+ count += numAttributes((NodeSPI) child);
}
count += n.getDataDirect().size();
return count;
@@ -1940,14 +1863,14 @@
@Deprecated
public List callRemoteMethods(List<Address> mbrs, MethodCall method_call,
boolean synchronous, boolean exclude_self, long timeout)
- throws Exception
+ throws Exception
{
return callRemoteMethods(mbrs, method_call, synchronous ? GroupRequest.GET_ALL : GroupRequest.GET_NONE, exclude_self, timeout);
}
@Deprecated
public List callRemoteMethods(List<Address> mbrs, MethodCall method_call, int mode, boolean exclude_self, long timeout)
- throws Exception
+ throws Exception
{
return callRemoteMethods(mbrs, method_call, mode, exclude_self, timeout, null);
}
@@ -1966,7 +1889,7 @@
*/
@Deprecated
public List callRemoteMethods(List<Address> mbrs, MethodCall method_call, int mode, boolean exclude_self, long timeout, RspFilter rspFilter)
- throws Exception
+ throws Exception
{
int modeToUse = mode;
int preferredMode;
@@ -1974,7 +1897,6 @@
modeToUse = preferredMode;
RspList rsps = null;
- Rsp rsp;
List retval;
Vector<Address> validMembers;
@@ -2022,8 +1944,8 @@
throw new TimeoutException("State retrieval timed out waiting for flush unblock.");
}
rsps = rspFilter == null
- ? disp.callRemoteMethods(validMembers, method_call, modeToUse, timeout, buddyManager != null && buddyManager.isEnabled())
- : disp.callRemoteMethods(validMembers, method_call, modeToUse, timeout, buddyManager != null && buddyManager.isEnabled(), false, rspFilter);
+ ? disp.callRemoteMethods(validMembers, method_call, modeToUse, timeout, buddyManager != null && buddyManager.isEnabled())
+ : disp.callRemoteMethods(validMembers, method_call, modeToUse, timeout, buddyManager != null && buddyManager.isEnabled(), false, rspFilter);
// a null response is 99% likely to be due to a marshalling problem - we throw a NSE, this needs to be changed when
// JGroups supports http://jira.jboss.com/jira/browse/JGRP-193
@@ -2043,9 +1965,9 @@
}
retval = new ArrayList(rsps.size());
- for (int i = 0; i < rsps.size(); i++)
+
+ for (Rsp rsp : rsps.values())
{
- rsp = (Rsp) rsps.elementAt(i);
if (rsp.wasSuspected() || !rsp.wasReceived())
{
CacheException ex;
@@ -2063,7 +1985,8 @@
{
if (rsp.getValue() instanceof Exception)
{
- if (log.isTraceEnabled()) log.trace("Recieved exception'" + rsp.getValue() + "' from " + rsp.getSender());
+ if (log.isTraceEnabled())
+ log.trace("Recieved exception'" + rsp.getValue() + "' from " + rsp.getSender());
throw (Exception) rsp.getValue();
}
retval.add(rsp.getValue());
@@ -2086,7 +2009,7 @@
@Deprecated
public List callRemoteMethods(List<Address> members, Method method, Object[] args,
boolean synchronous, boolean exclude_self, long timeout)
- throws Exception
+ throws Exception
{
return callRemoteMethods(members, MethodCallFactory.create(method, args), synchronous, exclude_self, timeout);
}
@@ -2107,7 +2030,7 @@
public List callRemoteMethods(Vector<Address> members, String method_name,
Class[] types, Object[] args,
boolean synchronous, boolean exclude_self, long timeout)
- throws Exception
+ throws Exception
{
Method method = getClass().getDeclaredMethod(method_name, types);
return callRemoteMethods(members, method, args, synchronous, exclude_self, timeout);
@@ -2119,22 +2042,22 @@
/* ----- These are VERSIONED callbacks to facilitate JBCACHE-843. Also see docs/design/DataVersion.txt --- */
- public void _putForExternalRead(GlobalTransaction gtx, Fqn fqn, K key, V value, DataVersion dv) throws CacheException
+ public void _putForExternalRead(GlobalTransaction gtx, Fqn fqn, Object key, Object value, DataVersion dv) throws CacheException
{
_putForExternalRead(gtx, fqn, key, value);
}
- public void _put(GlobalTransaction tx, Fqn fqn, Map<K, V> data, boolean create_undo_ops, DataVersion dv) throws CacheException
+ public void _put(GlobalTransaction tx, Fqn fqn, Map data, boolean create_undo_ops, DataVersion dv) throws CacheException
{
_put(tx, fqn, data, create_undo_ops, false, dv);
}
- public void _put(GlobalTransaction tx, Fqn fqn, Map<K, V> data, boolean create_undo_ops, boolean erase_contents, DataVersion dv) throws CacheException
+ public void _put(GlobalTransaction tx, Fqn fqn, Map data, boolean create_undo_ops, boolean erase_contents, DataVersion dv) throws CacheException
{
_put(tx, fqn, data, create_undo_ops, erase_contents);
}
- public Object _put(GlobalTransaction tx, Fqn fqn, K key, V value, boolean create_undo_ops, DataVersion dv) throws CacheException
+ public Object _put(GlobalTransaction tx, Fqn fqn, Object key, Object value, boolean create_undo_ops, DataVersion dv) throws CacheException
{
return _put(tx, fqn, key, value, create_undo_ops);
}
@@ -2144,7 +2067,7 @@
return _remove(tx, fqn, create_undo_ops, true);
}
- public Object _remove(GlobalTransaction tx, Fqn fqn, K key, boolean create_undo_ops, DataVersion dv) throws CacheException
+ public Object _remove(GlobalTransaction tx, Fqn fqn, Object key, boolean create_undo_ops, DataVersion dv) throws CacheException
{
return _remove(tx, fqn, key, create_undo_ops);
}
@@ -2172,8 +2095,8 @@
* @param create_undo_ops If true, undo operations will be created (default is true).
* Otherwise they will not be created (used by rollback()).
*/
- public void _put(GlobalTransaction tx, String fqn, Map<K, V> data, boolean create_undo_ops)
- throws CacheException
+ public void _put(GlobalTransaction tx, String fqn, Map data, boolean create_undo_ops)
+ throws CacheException
{
_put(tx, Fqn.fromString(fqn), data, create_undo_ops);
}
@@ -2194,8 +2117,8 @@
* @param create_undo_ops If true, undo operations will be created (default is true).
* Otherwise they will not be created (used by rollback()).
*/
- public void _put(GlobalTransaction tx, Fqn fqn, Map<K, V> data, boolean create_undo_ops)
- throws CacheException
+ public void _put(GlobalTransaction tx, Fqn fqn, Map data, boolean create_undo_ops)
+ throws CacheException
{
_put(tx, fqn, data, create_undo_ops, false);
}
@@ -2216,8 +2139,8 @@
* @param erase_contents Clear the existing hashmap before putting the new data into it
* Otherwise they will not be created (used by rollback()).
*/
- public void _put(GlobalTransaction tx, Fqn fqn, Map<K, V> data, boolean create_undo_ops, boolean erase_contents)
- throws CacheException
+ public void _put(GlobalTransaction tx, Fqn fqn, Map data, boolean create_undo_ops, boolean erase_contents)
+ throws CacheException
{
if (log.isTraceEnabled())
{
@@ -2225,8 +2148,8 @@
}
InvocationContext ctx = getInvocationContext();
boolean isRollback = checkIsRollingBack(ctx.getTransaction());
- NodeSPI<K, V> n = findNodeCheck(tx, fqn, isRollback);
- Map<K, V> rawData = n.getDataDirect();
+ NodeSPI n = findNodeCheck(tx, fqn, isRollback);
+ Map rawData = n.getDataDirect();
if (!isRollback) notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.PUT_MAP, rawData, ctx);
// create a compensating method call (reverting the effect of
@@ -2234,8 +2157,8 @@
if (tx != null && create_undo_ops)
{
// erase and set to previous hashmap contents
- MethodCall undo_op = MethodCallFactory.create(MethodDeclarations.putDataEraseMethodLocal, tx, fqn, new HashMap<K, V>(rawData), false, true);
- tx_table.addUndoOperation(tx, undo_op);
+ MethodCall undo_op = MethodCallFactory.create(MethodDeclarations.putDataEraseMethodLocal, tx, fqn, new HashMap(rawData), false, true);
+ transactionTable.addUndoOperation(tx, undo_op);
}
if (erase_contents)
@@ -2251,8 +2174,8 @@
*
* @return Previous value (if any)
*/
- public Object _put(GlobalTransaction tx, String fqn, K key, V value, boolean create_undo_ops)
- throws CacheException
+ public Object _put(GlobalTransaction tx, String fqn, Object key, Object value, boolean create_undo_ops)
+ throws CacheException
{
return _put(tx, Fqn.fromString(fqn), key, value, create_undo_ops);
}
@@ -2262,9 +2185,9 @@
try
{
return tx != null && (
- tx.getStatus() == javax.transaction.Status.STATUS_ROLLEDBACK ||
- tx.getStatus() == javax.transaction.Status.STATUS_ROLLING_BACK ||
- tx.getStatus() == javax.transaction.Status.STATUS_MARKED_ROLLBACK);
+ tx.getStatus() == javax.transaction.Status.STATUS_ROLLEDBACK ||
+ tx.getStatus() == javax.transaction.Status.STATUS_ROLLING_BACK ||
+ tx.getStatus() == javax.transaction.Status.STATUS_MARKED_ROLLBACK);
}
catch (Exception e)
{
@@ -2278,13 +2201,13 @@
*
* @return Previous value (if any)
*/
- public Object _put(GlobalTransaction tx, Fqn fqn, K key, V value, boolean create_undo_ops)
- throws CacheException
+ public Object _put(GlobalTransaction tx, Fqn fqn, Object key, Object value, boolean create_undo_ops)
+ throws CacheException
{
if (log.isTraceEnabled())
{
log.trace(new StringBuffer("_put(").append(tx).append(", \"").
- append(fqn).append("\", k=").append(key).append(", v=").append(value).append(")"));
+ append(fqn).append("\", k=").append(key).append(", v=").append(value).append(")"));
}
@@ -2292,12 +2215,12 @@
// if this is a rollback then don't fire notifications.
boolean isRollback = checkIsRollingBack(ctx.getTransaction());
- NodeSPI<K, V> n = findNodeCheck(tx, fqn, isRollback);
- Map<K, V> rawData = n.getDataDirect();
+ NodeSPI n = findNodeCheck(tx, fqn, isRollback);
+ Map rawData = n.getDataDirect();
if (!isRollback)
notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.PUT_DATA, rawData, ctx);
- V old_value = n.putDirect(key, value);
+ Object old_value = n.putDirect(key, value);
// create a compensating method call (reverting the effect of
// this modification) and put it into the TX's undo list.
@@ -2313,13 +2236,13 @@
undo_op = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, tx, fqn, key, old_value, false);
}
// 1. put undo-op in TX' undo-operations list (needed to rollback TX)
- tx_table.addUndoOperation(tx, undo_op);
+ transactionTable.addUndoOperation(tx, undo_op);
}
- Map<K, V> newData = Collections.singletonMap(key, value);
+ Map newData = Collections.singletonMap(key, value);
if (!isRollback)
notifier.notifyNodeModified(fqn, false, NodeModifiedEvent.ModificationType.PUT_DATA, newData, ctx);
-
+
return old_value;
}
@@ -2340,7 +2263,7 @@
}
public boolean _remove(GlobalTransaction tx, Fqn fqn, boolean create_undo_ops, boolean sendNodeEvent)
- throws CacheException
+ throws CacheException
{
return _remove(tx, fqn, create_undo_ops, sendNodeEvent, false);
}
@@ -2354,7 +2277,7 @@
* @param sendNodeEvent
*/
public boolean _remove(GlobalTransaction tx, Fqn fqn, boolean create_undo_ops, boolean sendNodeEvent, boolean eviction)
- throws CacheException
+ throws CacheException
{
return _remove(tx, fqn, create_undo_ops, sendNodeEvent, eviction, null);
}
@@ -2374,11 +2297,11 @@
* @throws CacheException
*/
public boolean _remove(GlobalTransaction tx, Fqn fqn, boolean create_undo_ops, boolean sendNodeEvent, boolean eviction, DataVersion version)
- throws CacheException
+ throws CacheException
{
- NodeSPI<K, V> n;
- NodeSPI<K, V> parent_node;
+ NodeSPI n;
+ NodeSPI parent_node;
MethodCall undo_op = null;
if (log.isTraceEnabled())
@@ -2458,7 +2381,7 @@
undo_op = MethodCallFactory.create(MethodDeclarations.addChildMethodLocal, tx, parent_node.getFqn(), n.getFqn().getLastElement(), n, false);
// 1. put undo-op in TX' undo-operations list (needed to rollback TX)
- tx_table.addUndoOperation(tx, undo_op);
+ transactionTable.addUndoOperation(tx, undo_op);
}
if (!isRollback)
@@ -2483,8 +2406,8 @@
* @param key
* @return Object
*/
- public V _remove(GlobalTransaction tx, String fqn, K key, boolean create_undo_ops)
- throws CacheException
+ public Object _remove(GlobalTransaction tx, String fqn, Object key, boolean create_undo_ops)
+ throws CacheException
{
return _remove(tx, Fqn.fromString(fqn), key, create_undo_ops);
}
@@ -2496,11 +2419,11 @@
* @param key
* @return Object
*/
- public V _remove(GlobalTransaction tx, Fqn fqn, K key, boolean create_undo_ops)
- throws CacheException
+ public Object _remove(GlobalTransaction tx, Fqn fqn, Object key, boolean create_undo_ops)
+ throws CacheException
{
MethodCall undo_op = null;
- V old_value = null;
+ Object old_value = null;
if (log.isTraceEnabled())
{
@@ -2509,7 +2432,7 @@
// Find the node. This will lock it (if <tt>locking</tt> is true) and
// add the temporarily created parent nodes to the TX's node list if tx != null)
- NodeSPI<K, V> n = findNode(fqn);
+ NodeSPI n = findNode(fqn);
if (n == null)
{
log.warn("node " + fqn + " not found");
@@ -2528,10 +2451,10 @@
{
undo_op = MethodCallFactory.create(MethodDeclarations.putKeyValMethodLocal, tx, fqn, key, old_value, false);
// 1. put undo-op in TX' undo-operations list (needed to rollback TX)
- tx_table.addUndoOperation(tx, undo_op);
+ transactionTable.addUndoOperation(tx, undo_op);
}
- Map<K, V> removedData = Collections.singletonMap(key, old_value);
+ Map removedData = Collections.singletonMap(key, old_value);
if (!isRollback)
notifier.notifyNodeModified(fqn, false, NodeModifiedEvent.ModificationType.REMOVE_DATA, removedData, ctx);
@@ -2542,7 +2465,7 @@
* Internal method to remove data from a node.
*/
public void _removeData(GlobalTransaction tx, String fqn, boolean create_undo_ops)
- throws CacheException
+ throws CacheException
{
_removeData(tx, Fqn.fromString(fqn), create_undo_ops);
}
@@ -2551,7 +2474,7 @@
* Internal method to remove data from a node.
*/
public void _removeData(GlobalTransaction tx, Fqn fqn, boolean create_undo_ops)
- throws CacheException
+ throws CacheException
{
_removeData(tx, fqn, create_undo_ops, true);
}
@@ -2560,7 +2483,7 @@
* Internal method to remove data from a node.
*/
public void _removeData(GlobalTransaction tx, Fqn fqn, boolean create_undo_ops, boolean sendNodeEvent)
- throws CacheException
+ throws CacheException
{
_removeData(tx, fqn, create_undo_ops, sendNodeEvent, false);
}
@@ -2569,7 +2492,7 @@
* Internal method to remove data from a node.
*/
public void _removeData(GlobalTransaction tx, Fqn fqn, boolean create_undo_ops, boolean sendNodeEvent, boolean eviction)
- throws CacheException
+ throws CacheException
{
_removeData(tx, fqn, create_undo_ops, sendNodeEvent, eviction, null);
}
@@ -2578,7 +2501,7 @@
* Internal method to remove data from a node.
*/
public void _removeData(GlobalTransaction tx, Fqn fqn, boolean create_undo_ops, boolean sendNodeEvent, boolean eviction, DataVersion version)
- throws CacheException
+ throws CacheException
{
MethodCall undo_op = null;
@@ -2589,14 +2512,14 @@
// Find the node. This will lock it (if <tt>locking</tt> is true) and
// add the temporarily created parent nodes to the TX's node list if tx != null)
- NodeSPI<K, V> n = findNode(fqn, version);
+ NodeSPI n = findNode(fqn, version);
if (n == null)
{
log.warn("node " + fqn + " not found");
return;
}
- Map<K, V> data = n.getDataDirect();
+ Map data = n.getDataDirect();
InvocationContext ctx = getInvocationContext();
boolean isRollback = checkIsRollingBack(ctx.getTransaction());
// create a compensating method call (reverting the effect of
@@ -2606,7 +2529,7 @@
if (!data.isEmpty())
{
undo_op = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal,
- tx, fqn, new HashMap<K, V>(data), false);
+ tx, fqn, new HashMap(data), false);
}
}
@@ -2650,7 +2573,7 @@
// put undo-op in TX' undo-operations list (needed to rollback TX)
if (tx != null && create_undo_ops)
{
- tx_table.addUndoOperation(tx, undo_op);
+ transactionTable.addUndoOperation(tx, undo_op);
}
}
@@ -2733,7 +2656,7 @@
*/
public void invalidate(Fqn fqn, DataVersion versionToInvalidate)
{
- Node<K, V> node = get(fqn); // force interceptor chain, load if necessary from cache loader.
+ Node node = get(fqn); // force interceptor chain, load if necessary from cache loader.
if (node == null)
{
@@ -2746,7 +2669,7 @@
{
log.trace("Node doesn't exist; creating a tombstone");
// create the node we need.
- Map<K, V> m = Collections.emptyMap();
+ Map m = Collections.emptyMap();
InvocationContext ic = getInvocationContext();
boolean origCacheModeLocal = ic.getOptionOverrides().isCacheModeLocal();
ic.getOptionOverrides().setCacheModeLocal(true);
@@ -2770,7 +2693,7 @@
}
node = nodeSPI;
}
-
+
if (configuration.isNodeLockingOptimistic())
_removeData(null, fqn, false, false, true, versionToInvalidate);
else
@@ -2806,7 +2729,7 @@
* Compensating method to {@link #_remove(GlobalTransaction,Fqn,boolean)}.
*/
public void _addChild(GlobalTransaction gtx, Fqn parent_fqn, Object child_name, Node cn, boolean undoOps)
- throws CacheException
+ throws CacheException
{
NodeSPI childNode = (NodeSPI) cn;
if (log.isTraceEnabled())
@@ -2841,7 +2764,7 @@
if (gtx != null && undoOps)
{
// 1. put undo-op in TX' undo-operations list (needed to rollback TX)
- tx_table.addUndoOperation(gtx, MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, gtx, fqn, false));
+ transactionTable.addUndoOperation(gtx, MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, gtx, fqn, false));
}
if (!isRollback) notifier.notifyNodeCreated(fqn, false, ctx);
@@ -2872,9 +2795,10 @@
catch (Throwable ex)
{
if (method_call.getMethodId() != MethodDeclarations.putForExternalReadMethodLocal_id
- || method_call.getMethodId() != MethodDeclarations.putForExternalReadVersionedMethodLocal_id )
+ || method_call.getMethodId() != MethodDeclarations.putForExternalReadVersionedMethodLocal_id)
{
- if (!MethodDeclarations.isBuddyGroupOrganisationMethod(method_call.getMethodId()) && log.isWarnEnabled()) log.warn("replication failure with method_call " + method_call + " exception", ex);
+ if (!MethodDeclarations.isBuddyGroupOrganisationMethod(method_call.getMethodId()) && log.isWarnEnabled())
+ log.warn("replication failure with method_call " + method_call + " exception", ex);
throw ex;
}
else return null;
@@ -2944,7 +2868,7 @@
* @return a GravitateResult which contains the data for the gravitation
*/
public GravitateResult gravitateData(Fqn fqn, boolean searchSubtrees)
- throws CacheException
+ throws CacheException
{
// we need to get the state for this Fqn and its sub-nodes.
@@ -2959,7 +2883,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<K, V> actualNode = get(fqn);
+ Node actualNode = get(fqn);
ctx.getOptionOverrides().setSkipDataGravitation(false);
if (log.isTraceEnabled()) log.trace("In local tree, this is " + actualNode);
@@ -2985,7 +2909,8 @@
ctx.getOptionOverrides().setSkipDataGravitation(true);
actualNode = get(backupNodeFqn);
ctx.getOptionOverrides().setSkipDataGravitation(false);
- if (log.isTraceEnabled()) log.trace("Looking for " + backupNodeFqn + ". Search result: " + actualNode);
+ if (log.isTraceEnabled())
+ log.trace("Looking for " + backupNodeFqn + ". Search result: " + actualNode);
if (actualNode != null) break;
}
}
@@ -3007,7 +2932,7 @@
backupNodeFqn = BuddyManager.getBackupFqn(BuddyManager.getGroupNameFromAddress(getLocalAddress()), fqn);
}
- List<NodeData> list = getNodeData(new LinkedList<NodeData>(), (NodeSPI<K, V>) actualNode);
+ List<NodeData> list = getNodeData(new LinkedList<NodeData>(), (NodeSPI) actualNode);
return GravitateResult.subtreeResult(list, backupNodeFqn);
}
@@ -3017,13 +2942,13 @@
}
}
- private List<NodeData> getNodeData(List<NodeData> list, NodeSPI<K, V> node)
+ private List<NodeData> getNodeData(List<NodeData> list, NodeSPI node)
{
NodeData data = new NodeData(BuddyManager.getActualFqn(node.getFqn()), node.getDataDirect());
list.add(data);
- for (NodeSPI<K, V> childNode : node.getChildrenDirect())
+ for (Object childNode : node.getChildrenDirect())
{
- getNodeData(list, childNode);
+ getNodeData(list, (NodeSPI) childNode);
}
return list;
}
@@ -3062,8 +2987,8 @@
{
if (log.isTraceEnabled())
log.trace("DataGravitationCleanup: Removing primary (" + primary + ") and backup (" + backup + ")");
- primaryDataCleanup = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, null, primary, false);
- backupDataCleanup = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, null, backup, false);
+ primaryDataCleanup = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, primary, false);
+ backupDataCleanup = MethodCallFactory.create(MethodDeclarations.removeNodeMethodLocal, backup, false);
}
else
{
@@ -3117,7 +3042,7 @@
*/
public void _releaseAllLocks(Fqn fqn)
{
- NodeSPI<K, V> n;
+ NodeSPI n;
try
{
@@ -3135,11 +3060,11 @@
}
}
- private void releaseAll(NodeSPI<K, V> n)
+ private void releaseAll(NodeSPI n)
{
- for (NodeSPI<K, V> child : n.getChildrenDirect())
+ for (Object child : n.getChildrenDirect())
{
- releaseAll(child);
+ releaseAll((NodeSPI) child);
}
n.getLock().releaseAll();
}
@@ -3167,7 +3092,7 @@
* Should not be called.
*/
public void _lock(Fqn fqn, NodeLock.LockType lock_type, boolean recursive)
- throws TimeoutException, LockingException
+ throws TimeoutException, LockingException
{
throw new UnsupportedOperationException("method _lock() should not be invoked on CacheImpl");
}
@@ -3211,7 +3136,7 @@
*/
public void addUndoOperation(GlobalTransaction gtx, MethodCall undo_op)
{
- tx_table.addUndoOperation(gtx, undo_op);
+ transactionTable.addUndoOperation(gtx, undo_op);
}
/**
@@ -3230,12 +3155,6 @@
this.cacheLoaderManager = cacheLoaderManager;
}
- public void setConfiguration(Configuration configuration)
- {
- this.configuration = configuration;
- configuration.setCacheImpl(this);
- }
-
/**
* @return an instance of {@link Notifier} which has been configured with this instance of CacheImpl.
*/
@@ -3281,14 +3200,14 @@
public void _move(Fqn nodeToMoveFqn, Fqn newParentFqn)
{
// the actual move algorithm.
- NodeSPI<K, V> newParent = findNode(newParentFqn);
+ NodeSPI newParent = findNode(newParentFqn);
if (newParent == null)
{
throw new NodeNotExistsException("New parent node " + newParentFqn + " does not exist when attempting to move node!!");
}
- NodeSPI<K, V> node = findNode(nodeToMoveFqn);
+ NodeSPI node = findNode(nodeToMoveFqn);
if (node == null)
{
@@ -3320,7 +3239,7 @@
if (ctx.getTransaction() != null)
{
MethodCall undo = MethodCallFactory.create(MethodDeclarations.moveMethodLocal, new Fqn(newParentFqn, nodeToMoveFqn.getLastElement()), oldParent.getFqn());
- tx_table.addUndoOperation(ctx.getGlobalTransaction(), undo);
+ transactionTable.addUndoOperation(ctx.getGlobalTransaction(), undo);
}
}
@@ -3372,339 +3291,6 @@
}
}
- protected class MessageListenerAdaptor implements ExtendedMessageListener
- {
- /**
- * Reference to an exception that was raised during
- * state installation on this node.
- */
- protected volatile Exception setStateException;
- private final Object stateLock = new Object();
-
- protected MessageListenerAdaptor()
- {
- }
-
- public void waitForState() throws Exception
- {
- synchronized (stateLock)
- {
- while (!isStateSet)
- {
- if (setStateException != null)
- {
- throw setStateException;
- }
-
- try
- {
- stateLock.wait();
- }
- catch (InterruptedException iex)
- {
- }
- }
- }
- }
-
- protected void stateReceivedSuccess()
- {
- isStateSet = true;
- setStateException = null;
- }
-
- protected void stateReceivingFailed(Throwable t)
- {
- if (t instanceof CacheException)
- {
- log.debug(t);
- }
- else
- {
- log.error("failed setting state", t);
- }
- if (t instanceof Exception)
- {
- setStateException = (Exception) t;
- }
- else
- {
- setStateException = new Exception(t);
- }
- }
-
- protected void stateProducingFailed(Throwable t)
- {
- if (t instanceof CacheException)
- {
- log.debug(t);
- }
- else
- {
- log.error("Caught " + t.getClass().getName()
- + " while responding to state transfer request", t);
- }
- }
-
- /**
- * Callback, does nothing.
- */
- public void receive(Message msg)
- {
- }
-
- public byte[] getState()
- {
- MarshalledValueOutputStream out = null;
- byte[] result = null;
- ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(16 * 1024);
- try
- {
- out = new MarshalledValueOutputStream(baos);
-
- getStateTransferManager().getState(out, Fqn.ROOT, configuration.getStateRetrievalTimeout(), true, true);
- }
- catch (Throwable t)
- {
- stateProducingFailed(t);
- }
- finally
- {
- result = baos.getRawBuffer();
- Util.close(out);
- }
- return result;
- }
-
- public void setState(byte[] new_state)
- {
- if (new_state == null)
- {
- log.debug("transferred state is null (may be first member in cluster)");
- return;
- }
- ByteArrayInputStream bais = new ByteArrayInputStream(new_state);
- MarshalledValueInputStream in = null;
- try
- {
- in = new MarshalledValueInputStream(bais);
- getStateTransferManager().setState(in, Fqn.ROOT);
- stateReceivedSuccess();
- }
- catch (Throwable t)
- {
- stateReceivingFailed(t);
- }
- finally
- {
- Util.close(in);
- synchronized (stateLock)
- {
- // Notify wait that state has been set.
- stateLock.notifyAll();
- }
- }
- }
-
- public byte[] getState(String state_id)
- {
- MarshalledValueOutputStream out = null;
- String sourceRoot = state_id;
- byte[] result = null;
-
- boolean hasDifferentSourceAndIntegrationRoots = state_id.indexOf(StateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
- if (hasDifferentSourceAndIntegrationRoots)
- {
- sourceRoot = state_id.split(StateTransferManager.PARTIAL_STATE_DELIMITER)[0];
- }
-
- ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(16 * 1024);
- try
- {
- out = new MarshalledValueOutputStream(baos);
-
- getStateTransferManager().getState(out, Fqn.fromString(sourceRoot),
- configuration.getStateRetrievalTimeout(), true, true);
- }
- catch (Throwable t)
- {
- stateProducingFailed(t);
- }
- finally
- {
- result = baos.getRawBuffer();
- Util.close(out);
- }
- return result;
- }
-
- public void getState(OutputStream ostream)
- {
- MarshalledValueOutputStream out = null;
- try
- {
- out = new MarshalledValueOutputStream(ostream);
- getStateTransferManager().getState(out, Fqn.ROOT, configuration.getStateRetrievalTimeout(), true, true);
- }
- catch (Throwable t)
- {
- stateProducingFailed(t);
- }
- finally
- {
- Util.close(out);
- }
- }
-
- public void getState(String state_id, OutputStream ostream)
- {
- String sourceRoot = state_id;
- MarshalledValueOutputStream out = null;
- boolean hasDifferentSourceAndIntegrationRoots = state_id.indexOf(StateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
- if (hasDifferentSourceAndIntegrationRoots)
- {
- sourceRoot = state_id.split(StateTransferManager.PARTIAL_STATE_DELIMITER)[0];
- }
- try
- {
- out = new MarshalledValueOutputStream(ostream);
- getStateTransferManager().getState(out, Fqn.fromString(sourceRoot), configuration.getStateRetrievalTimeout(), true, true);
- }
- catch (Throwable t)
- {
- stateProducingFailed(t);
- }
- finally
- {
- Util.close(out);
- }
- }
-
- public void setState(InputStream istream)
- {
- if (istream == null)
- {
- log.debug("stream is null (may be first member in cluster)");
- return;
- }
- MarshalledValueInputStream in = null;
- try
- {
- in = new MarshalledValueInputStream(istream);
- getStateTransferManager().setState(in, Fqn.ROOT);
- stateReceivedSuccess();
- }
- catch (Throwable t)
- {
- stateReceivingFailed(t);
- }
- finally
- {
- Util.close(in);
- synchronized (stateLock)
- {
- // Notify wait that state has been set.
- stateLock.notifyAll();
- }
- }
- }
-
- public void setState(String state_id, byte[] state)
- {
- if (state == null)
- {
- log.debug("partial transferred state is null");
- return;
- }
-
- MarshalledValueInputStream in = null;
- String targetRoot = state_id;
- boolean hasDifferentSourceAndIntegrationRoots = state_id.indexOf(StateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
- if (hasDifferentSourceAndIntegrationRoots)
- {
- targetRoot = state_id.split(StateTransferManager.PARTIAL_STATE_DELIMITER)[1];
- }
- try
- {
- log.debug("Setting received partial state for subroot " + state_id);
- Fqn subroot = Fqn.fromString(targetRoot);
-// Region region = regionManager.getRegion(subroot, false);
-// ClassLoader cl = null;
-// if (region != null)
-// {
-// // If a classloader is registered for the node's region, use it
-// cl = region.getClassLoader();
-// }
- ByteArrayInputStream bais = new ByteArrayInputStream(state);
- in = new MarshalledValueInputStream(bais);
- //getStateTransferManager().setState(in, subroot, cl);
- getStateTransferManager().setState(in, subroot);
- stateReceivedSuccess();
- }
- catch (Throwable t)
- {
- stateReceivingFailed(t);
- }
- finally
- {
- Util.close(in);
- synchronized (stateLock)
- {
- // Notify wait that state has been set.
- stateLock.notifyAll();
- }
- }
- }
-
- public void setState(String state_id, InputStream istream)
- {
- String targetRoot = state_id;
- MarshalledValueInputStream in = null;
- boolean hasDifferentSourceAndIntegrationRoots = state_id.indexOf(StateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
- if (hasDifferentSourceAndIntegrationRoots)
- {
- targetRoot = state_id.split(StateTransferManager.PARTIAL_STATE_DELIMITER)[1];
- }
- if (istream == null)
- {
- log.debug("stream is null (may be first member in cluster). State is not set");
- return;
- }
-
- try
- {
- log.debug("Setting received partial state for subroot " + state_id);
- in = new MarshalledValueInputStream(istream);
- Fqn subroot = Fqn.fromString(targetRoot);
-// Region region = regionManager.getRegion(subroot, false);
-// ClassLoader cl = null;
-// if (region != null)
-// {
-// // If a classloader is registered for the node's region, use it
-// cl = region.getClassLoader();
-// }
- //getStateTransferManager().setState(in, subroot, cl);
- getStateTransferManager().setState(in, subroot);
- stateReceivedSuccess();
- }
- catch (Throwable t)
- {
- stateReceivingFailed(t);
- }
- finally
- {
- Util.close(in);
- synchronized (stateLock)
- {
- // Notify wait that state has been set.
- stateLock.notifyAll();
- }
- }
- }
- }
-
- /*-------------------- End of MessageListener ----------------------*/
-
/*----------------------- MembershipListener ------------------------*/
protected class MembershipListenerAdaptor implements ExtendedMembershipListener
@@ -3805,13 +3391,13 @@
*/
protected Transaction getLocalTransaction()
{
- if (tm == null)
+ if (transactionManager == null)
{
return null;
}
try
{
- return tm.getTransaction();
+ return transactionManager.getTransaction();
}
catch (Throwable t)
{
@@ -3914,15 +3500,15 @@
// operate on the transaction at one time so no concern about 2 threads trying to call
// this method for the same Transaction instance at the same time
//
- GlobalTransaction gtx = tx_table.get(tx);
+ GlobalTransaction gtx = transactionTable.get(tx);
if (gtx == null && createIfNotExists)
{
Address addr = getLocalAddress();
gtx = GlobalTransaction.create(addr);
- tx_table.put(tx, gtx);
+ transactionTable.put(tx, gtx);
TransactionEntry ent = configuration.isNodeLockingOptimistic() ? new OptimisticTransactionEntry() : new TransactionEntry();
ent.setTransaction(tx);
- tx_table.put(gtx, ent);
+ transactionTable.put(gtx, ent);
if (log.isTraceEnabled())
{
log.trace("created new GTX: " + gtx + ", local TX=" + tx);
@@ -3957,70 +3543,7 @@
*/
protected Object invokeMethod(MethodCall m, boolean originLocal) throws CacheException
{
- // don't create a new one; get it from ThreadLocal just this once, in case a user has added any overrides.
- InvocationContext ctx = getInvocationContext();
-
- // BR methods should NOT block on the cache being started, since the cache depends on these completing to start.
- if (!MethodDeclarations.isBuddyGroupOrganisationMethod(m.getMethodId()) && !cacheStatus.allowInvocations() && !ctx.getOptionOverrides().isSkipCacheStatusCheck())
- {
- // only throw an exception if this is a locally originating call - JBCACHE-1179
- if (originLocal)
- {
- throw new IllegalStateException("Cache not in STARTED state!");
- }
- else
- {
- if (getCacheStatus() == CacheStatus.STARTING)
- {
- try
- {
- blockUntilCacheStarts();
- }
- catch (InterruptedException e)
- {
- Thread.currentThread().interrupt();
- }
-
- // if the cache STILL can't take invocations...
- if (!cacheStatus.allowInvocations()) throw new IllegalStateException("Cache not in STARTED state!");
- }
- else
- {
- log.warn("Received a remote call but the cache is not in STARTED state - ignoring call.");
- return null;
- }
- }
- }
-
-
- MethodCall oldCall = null;
- try
- {
- // check if we had a method call lurking around
- oldCall = ctx.getMethodCall();
- ctx.setMethodCall(m);
- // only set this if originLocal is EXPLICITLY passed in as FALSE. Otherwise leave it as a default.
- if (!originLocal) ctx.setOriginLocal(false);
- return interceptor_chain.invoke(ctx);
- }
- catch (CacheException e)
- {
- throw e;
- }
- catch (RuntimeException e)
- {
- throw e;
- }
- catch (Throwable t)
- {
- throw new CacheException(t);
- }
- finally
- {
- if (!originLocal) ctx.setOriginLocal(true);
- // reset old method call
- ctx.setMethodCall(oldCall);
- }
+ throw new UnsupportedOperationException("DEPRECATED and should not be used!!");
}
/**
@@ -4054,7 +3577,7 @@
* @param fqn Fully qualified name for the corresponding node.
* @return DataNode
*/
- public NodeSPI<K, V> findNode(Fqn fqn)
+ public NodeSPI findNode(Fqn fqn)
{
try
{
@@ -4067,9 +3590,9 @@
}
}
- private NodeSPI<K, V> findNodeCheck(GlobalTransaction tx, Fqn fqn, boolean includeInvalid)
+ private NodeSPI findNodeCheck(GlobalTransaction tx, Fqn fqn, boolean includeInvalid)
{
- NodeSPI<K, V> n = findNode(fqn, null, includeInvalid);
+ NodeSPI n = findNode(fqn, null, includeInvalid);
if (n == null)
{
String errStr = "node " + fqn + " not found (gtx=" + tx + ", caller=" + Thread.currentThread() + ")";
@@ -4131,16 +3654,16 @@
/**
* Finds a node given a fully qualified name and DataVersion. Does not include invalid nodes.
*/
- private NodeSPI<K, V> findNode(Fqn fqn, DataVersion version)
+ private NodeSPI findNode(Fqn fqn, DataVersion version)
{
return findNode(fqn, version, false);
}
- private NodeSPI<K, V> findNode(Fqn fqn, DataVersion version, boolean includeInvalidNodes)
+ private NodeSPI findNode(Fqn fqn, DataVersion version, boolean includeInvalidNodes)
{
if (fqn == null) return null;
- NodeSPI<K, V> toReturn = peek(fqn, false, includeInvalidNodes);
+ NodeSPI toReturn = peek(fqn, false, includeInvalidNodes);
if (toReturn != null && version != null && configuration.isNodeLockingOptimistic())
{
@@ -4159,54 +3682,13 @@
return toReturn;
}
- public synchronized RegionManager getRegionManager()
- {
- if (regionManager == null)
- {
- regionManager = new RegionManager(this);
- }
- return regionManager;
- }
-
-
- public Marshaller getMarshaller()
- {
- if (marshaller_ == null)
- {
- synchronized (this)
- {
- if (marshaller_ == null)
- {
- if (configuration.getMarshallerClass() == null || configuration.getMarshallerClass().equals(VersionAwareMarshaller.class.getName()))
- {
- marshaller_ = new VersionAwareMarshaller(getRegionManager(), configuration);
- }
- else
- {
- try
- {
- marshaller_ = (Marshaller) org.jboss.cache.util.Util.loadClass(configuration.getMarshallerClass()).newInstance();
- }
- catch (Exception e)
- {
- log.error("Unable to load marshaller " + configuration.getMarshallerClass() + ". Falling back to default (" + VersionAwareMarshaller.class.getName() + ")");
- marshaller_ = new VersionAwareMarshaller(getRegionManager(), configuration);
- }
- }
- if (log.isTraceEnabled()) log.trace("Using marshaller " + marshaller_.getClass().getName());
- }
- }
- }
- return marshaller_;
- }
-
private void initialiseCacheLoaderManager() throws CacheException
{
if (cacheLoaderManager == null)
{
cacheLoaderManager = new CacheLoaderManager();
}
- cacheLoaderManager.setConfig(configuration.getCacheLoaderConfig(), this);
+ cacheLoaderManager.setConfig(configuration.getCacheLoaderConfig(), spi);
}
/**
@@ -4258,7 +3740,7 @@
if (log.isDebugEnabled())
{
log.debug("Created Multiplexer Channel for cache cluster " + configuration.getClusterName() +
- " using stack " + configuration.getMultiplexerStack());
+ " using stack " + configuration.getMultiplexerStack());
}
}
else
@@ -4295,11 +3777,11 @@
// always use the InactiveRegionAwareRpcDispatcher - exceptions due to regions not being active should not propagate to remote
// nodes as errors. - Manik
- disp = new InactiveRegionAwareRpcDispatcher(channel, ml, new MembershipListenerAdaptor(), this);
+ disp = new InactiveRegionAwareRpcDispatcher(channel, messageListener, new MembershipListenerAdaptor(), this);
// disp = new RpcDispatcher(channel, ml, this, this);
- disp.setRequestMarshaller(getMarshaller());
- disp.setResponseMarshaller(getMarshaller());
+ disp.setRequestMarshaller(marshaller);
+ disp.setResponseMarshaller(marshaller);
}
private JChannel getMultiplexerChannel() throws CacheException
@@ -4371,12 +3853,12 @@
{
List<Interceptor> interceptors = getInterceptors();
- i.setCache(this);
+ InterceptorChainFactory factory = InterceptorChainFactory.getInstance();
interceptors.add(position, i);
// now correct the chaining of interceptors...
- Interceptor linkedChain = InterceptorChainFactory.getInstance().correctInterceptorChaining(interceptors);
+ Interceptor linkedChain = factory.correctInterceptorChaining(interceptors, configuration, componentRegistry);
setInterceptorChain(linkedChain);
}
@@ -4385,7 +3867,7 @@
{
List<Interceptor> i = getInterceptors();
i.remove(position);
- setInterceptorChain(InterceptorChainFactory.getInstance().correctInterceptorChaining(i));
+ setInterceptorChain(InterceptorChainFactory.getInstance().correctInterceptorChaining(i, configuration, componentRegistry));
}
public RPCManager getRPCManager()
@@ -4401,7 +3883,7 @@
public void evict(Fqn<?> fqn, boolean recursive)
{
//this method should be called by eviction thread only, so no transaction - expected (sec param is false)
- Node<K, V> node = peek(fqn, false);
+ Node node = peek(fqn, false);
if (node != null && node.isResident())
{
return;
@@ -4410,7 +3892,7 @@
{
if (node != null)
{
- evictChildren((NodeSPI<K, V>) node);
+ evictChildren((NodeSPI) node);
}
}
else
@@ -4419,23 +3901,23 @@
}
}
- private void evictChildren(NodeSPI<K, V> n)
+ private void evictChildren(NodeSPI n)
{
- for (NodeSPI<K, V> child : n.getChildrenDirect())
+ for (Object child : n.getChildrenDirect())
{
- evictChildren(child);
+ evictChildren((NodeSPI) child);
}
evict(n.getFqn());
}
public Region getRegion(Fqn<?> fqn, boolean createIfAbsent)
{
- return getRegionManager().getRegion(fqn, createIfAbsent);
+ return regionManager.getRegion(fqn, createIfAbsent);
}
public boolean removeRegion(Fqn<?> fqn)
{
- return getRegionManager().removeRegion(fqn);
+ return regionManager.removeRegion(fqn);
}
public boolean removeNode(Fqn<?> fqn)
@@ -4443,7 +3925,7 @@
return remove(fqn);
}
- public void putForExternalRead(Fqn<?> fqn, K key, V value)
+ public void putForExternalRead(Fqn<?> fqn, Object key, Object value)
{
// if the node exists then this should be a no-op.
if (!exists(fqn))
@@ -4460,7 +3942,7 @@
}
}
- public void _putForExternalRead(GlobalTransaction gtx, Fqn fqn, K key, V value)
+ public void _putForExternalRead(GlobalTransaction gtx, Fqn fqn, Object key, Object value)
{
_put(gtx, fqn, key, value, true);
}
@@ -4469,10 +3951,4 @@
{
return getCacheStatus() == CacheStatus.STARTED;
}
-
- protected void setMessageListener(MessageListenerAdaptor ml)
- {
- this.ml = ml;
- }
-
}
Modified: core/trunk/src/main/java/org/jboss/cache/CacheSPI.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheSPI.java 2007-12-11 17:25:09 UTC (rev 4832)
+++ core/trunk/src/main/java/org/jboss/cache/CacheSPI.java 2007-12-11 17:26:38 UTC (rev 4833)
@@ -18,11 +18,13 @@
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionTable;
+import org.jgroups.Address;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* A more detailed interface to {@link Cache}, which is used when writing plugins for or extending JBoss Cache. A reference
@@ -52,12 +54,20 @@
/**
* Retrieves a reference to a running {@link javax.transaction.TransactionManager}, if one is configured.
+ * <p/>
+ * From 2.1.0, Interceptor authors should obtain this by injection rather than this method. See the
+ * {@link org.jboss.cache.factories.annotations.Inject} annotation.
*
* @return a TransactionManager
*/
TransactionManager getTransactionManager();
/**
+ * Retrieves the current Interceptor chain.
+ * <p/>
+ * From 2.1.0, Interceptor authors should obtain this by injection rather than this method. See the
+ * {@link org.jboss.cache.factories.annotations.Inject} annotation.
+ *
* @return an immutable {@link List} of {@link Interceptor}s configured for this cache, or
* <code>null</code> if {@link Cache#create() create()} has not been invoked
* and the interceptors thus do not exist.
@@ -65,6 +75,22 @@
List<Interceptor> getInterceptorChain();
/**
+ * Retrieves an instance of a {@link Marshaller}, which is capable of
+ * converting Java objects to bytestreams and back in an efficient manner, which is
+ * also interoperable with bytestreams produced/consumed by other versions of JBoss
+ * Cache.
+ * <p/>
+ * The use of this marshaller is the <b>recommended</b> way of creating efficient,
+ * compatible, byte streams from objects.
+ * <p/>
+ * From 2.1.0, Interceptor authors should obtain this by injection rather than this method. See the
+ * {@link org.jboss.cache.factories.annotations.Inject} annotation.
+ *
+ * @return an instance of {@link Marshaller}
+ */
+ Marshaller getMarshaller();
+
+ /**
* Adds a custom interceptor to the interceptor chain, at specified position, where the first interceptor in the chain
* is at position 0 and the last one at getInterceptorChain().size() - 1.
*
@@ -82,33 +108,78 @@
void removeInterceptor(int position);
/**
+ * Retrieves the current CacheCacheLoaderManager instance associated with the current Cache instance.
+ * <p/>
+ * From 2.1.0, Interceptor authors should obtain this by injection rather than this method. See the
+ * {@link org.jboss.cache.factories.annotations.Inject} annotation.
+ *
* @return Retrieves a reference to the currently configured {@link org.jboss.cache.loader.CacheLoaderManager} if one or more cache loaders are configured, null otherwise.
*/
CacheLoaderManager getCacheLoaderManager();
/**
+ * Retrieves the current BuddyManager instance associated with the current Cache instance.
+ * <p/>
+ * From 2.1.0, Interceptor authors should obtain this by injection rather than this method. See the
+ * {@link org.jboss.cache.factories.annotations.Inject} annotation.
+ *
* @return an instance of {@link BuddyManager} if buddy replication is enabled, null otherwise.
*/
BuddyManager getBuddyManager();
/**
+ * Retrieves the current TransactionTable instance associated with the current Cache instance.
+ * <p/>
+ * From 2.1.0, Interceptor authors should obtain this by injection rather than this method. See the
+ * {@link org.jboss.cache.factories.annotations.Inject} annotation.
+ *
* @return the current {@link TransactionTable}
*/
TransactionTable getTransactionTable();
/**
* Gets a handle of the RPC manager.
+ * <p/>
+ * From 2.1.0, Interceptor authors should obtain this by injection rather than this method. See the
+ * {@link org.jboss.cache.factories.annotations.Inject} annotation.
*
* @return the {@link org.jboss.cache.RPCManager} configured.
*/
RPCManager getRPCManager();
/**
+ * Retrieves the current StateTransferManager instance associated with the current Cache instance.
+ * <p/>
+ * From 2.1.0, Interceptor authors should obtain this by injection rather than this method. See the
+ * {@link org.jboss.cache.factories.annotations.Inject} annotation.
+ *
* @return the current {@link org.jboss.cache.statetransfer.StateTransferManager}
*/
StateTransferManager getStateTransferManager();
/**
+ * Retrieves the current RegionManager instance associated with the current Cache instance.
+ * <p/>
+ * From 2.1.0, Interceptor authors should obtain this by injection rather than this method. See the
+ * {@link org.jboss.cache.factories.annotations.Inject} annotation.
+ *
+ * @return the {@link org.jboss.cache.RegionManager}
+ */
+ RegionManager getRegionManager();
+
+
+ /**
+ * Retrieves the current Notifier instance associated with the current Cache instance.
+ * <p/>
+ * From 2.1.0, Interceptor authors should obtain this by injection rather than this method. See the
+ * {@link org.jboss.cache.factories.annotations.Inject} annotation.
+ *
+ * @return the notifier attached with this instance of the cache. See {@link Notifier}, a class
+ * that is responsible for emitting notifications to registered CacheListeners.
+ */
+ Notifier getNotifier();
+
+ /**
* @return the name of the cluster. Null if running in local mode.
*/
String getClusterName();
@@ -131,11 +202,6 @@
Map<Thread, List<NodeLock>> getLockTable();
/**
- * @return the {@link org.jboss.cache.RegionManager}
- */
- RegionManager getRegionManager();
-
- /**
* Returns the global transaction for this local transaction.
* Optionally creates a new global transaction if it does not exist.
*
@@ -146,13 +212,21 @@
GlobalTransaction getCurrentTransaction(Transaction tx, boolean createIfNotExists);
/**
- * @return the notifier attached with this instance of the cache. See {@link Notifier}, a class
- * that is responsible for emitting notifications to registered CacheListeners.
+ * Returns the transaction associated with the current thread.
+ * If a local transaction exists, but doesn't yet have a mapping to a
+ * GlobalTransaction, a new GlobalTransaction will be created and mapped to
+ * the local transaction. Note that if a local transaction exists, but is
+ * not ACTIVE or PREPARING, null is returned.
+ *
+ * @return A GlobalTransaction, or null if no (local) transaction was associated with the current thread
*/
- Notifier getNotifier();
+ GlobalTransaction getCurrentTransaction();
/**
- * Returns a node without accessing the interceptor chain. Does not return any nodes marked as invalid.
+ * Returns a node without accessing the interceptor chain. Does not return any nodes marked as invalid. Note that this call works
+ * directly on the cache data structure and will not pass through the interceptor chain. Hence node locking, cache
+ * loading or activation does not take place, and so the results of this call should not be treated as definitive. Concurrent node
+ * removal, passivation, etc. may affect the results of this call.
*
* @param fqn the Fqn to look up.
* @param includeDeletedNodes if you intend to see nodes marked as deleted within the current tx, set this to true
@@ -162,6 +236,10 @@
/**
* Returns a node without accessing the interceptor chain, optionally returning nodes that are marked as invalid ({@link org.jboss.cache.Node#isValid()} == false).
+ * Note that this call works
+ * directly on the cache data structure and will not pass through the interceptor chain. Hence node locking, cache
+ * loading or activation does not take place, and so the results of this call should not be treated as definitive. Concurrent node
+ * removal, passivation, etc. may affect the results of this call.
*
* @param fqn the Fqn to look up.
* @param includeDeletedNodes if you intend to see nodes marked as deleted within the current tx, set this to true
@@ -182,15 +260,55 @@
GravitateResult gravitateData(Fqn<?> fqn, boolean searchBuddyBackupSubtrees);
/**
- * Retrieves an instance of a {@link Marshaller}, which is capable of
- * converting Java objects to bytestreams and back in an efficient manner, which is
- * also interoperable with bytestreams produced/consumed by other versions of JBoss
- * Cache.
- * <p/>
- * The use of this marshaller is the <b>recommended</b> way of creating efficient,
- * compatible, byte streams from objects.
+ * Returns a Set<Fqn> of Fqns of the topmost node of internal regions that
+ * should not included in standard state transfers. Will include
+ * {@link BuddyManager#BUDDY_BACKUP_SUBTREE} if buddy replication is
+ * enabled.
*
- * @return an instance of {@link Marshaller}
+ * @return an unmodifiable Set<Fqn>. Will not return <code>null</code>.
*/
- Marshaller getMarshaller();
+ Set<Fqn> getInternalFqns();
+
+ @Deprecated
+ void fetchPartialState(List<Address> members, Fqn subtreeRoot) throws Exception;
+
+ @Deprecated
+ void fetchPartialState(List<Address> members, Fqn subtreeRoot, Fqn integrationPoint) throws Exception;
+
+ int getNumberOfLocksHeld();
+
+ /**
+ * Helper method that does a peek and ensures that the result of the peek is not null. Note that this call works
+ * directly on the cache data structure and will not pass through the interceptor chain. Hence node locking, cache
+ * loading or activation does not take place, and so the results of this call should not be treated as definitive.
+ *
+ * @param fqn Fqn to peek
+ * @return true if the peek returns a non-null value.
+ */
+ boolean exists(Fqn<?> fqn);
+
+ /**
+ * A convenience method that takes a String representation of an Fqn. Otherwise identical to {@link #exists(Fqn)}.
+ * Note that this call works
+ * directly on the cache data structure and will not pass through the interceptor chain. Hence node locking, cache
+ * loading or activation does not take place, and so the results of this call should not be treated as definitive.
+ */
+ boolean exists(String fqn);
+
+ /**
+ * Returns all children of a given node. Returns an empty set if there are no children.
+ * The set is unmodifiable.
+ *
+ * @param fqn The fully qualified name of the node
+ * @return Set an unmodifiable set of children names, Object.
+ */
+ <E> Set<E> getChildrenNames(Fqn<E> fqn);
+
+ /**
+ * Convenience method that takes a String representation of an Fqn. Otherwise identical to {@link #getChildrenNames(Fqn)}
+ *
+ * @param fqn as a string
+ * @return Set an unmodifiable set of children names, Object.
+ */
+ Set getChildrenNames(String fqn);
}
Modified: core/trunk/src/main/java/org/jboss/cache/NodeFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/NodeFactory.java 2007-12-11 17:25:09 UTC (rev 4832)
+++ core/trunk/src/main/java/org/jboss/cache/NodeFactory.java 2007-12-11 17:26:38 UTC (rev 4833)
@@ -6,6 +6,11 @@
*/
package org.jboss.cache;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.ComponentFactory;
+import org.jboss.cache.factories.ComponentRegistry;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.invocation.NodeInvocationDelegate;
import org.jboss.cache.optimistic.TransactionWorkspace;
import org.jboss.cache.optimistic.WorkspaceNode;
import org.jboss.cache.optimistic.WorkspaceNodeImpl;
@@ -17,16 +22,24 @@
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
*/
-public class NodeFactory<K, V>
+// TODO: Rethink how nodes are created. Perhaps use the component factory to create instance nodes as well, not just singletons?
+public class NodeFactory<K, V> extends ComponentFactory
{
+ private ComponentRegistry componentRegistry;
+ private CacheSPI<K, V> cache;
+ private boolean optimistic;
+ private Configuration configuration;
+
+ protected <T> T construct(String componentName, Class<T> componentType)
+ {
+ throw new UnsupportedOperationException("Should never be called!");
+ }
+
public enum NodeType
{
UNVERSIONED_NODE, VERSIONED_NODE, WORKSPACE_NODE
}
- private CacheSPI<K, V> cache;
- private boolean optimistic;
-
/**
* Constructs an instance of the factory
*/
@@ -36,12 +49,25 @@
init();
}
+ public NodeFactory()
+ {
+ }
+
+ @Inject
+ private void injectDependencies(CacheSPI<K, V> cache, Configuration configuration, ComponentRegistry componentRegistry)
+ {
+ this.cache = cache;
+ this.configuration = configuration;
+ this.componentRegistry = componentRegistry;
+ init();
+ }
+
/**
* Initialises the node factory with the configuration from the cache.
*/
public void init()
{
- optimistic = cache.getConfiguration().isNodeLockingOptimistic();
+ optimistic = configuration.isNodeLockingOptimistic();
}
@@ -60,10 +86,12 @@
*/
public NodeSPI<K, V> createDataNode(Object childName, Fqn fqn, NodeSPI<K, V> parent, Map<K, V> data, boolean mapSafe)
{
- NodeSPI<K, V> n = optimistic ? new VersionedNode<K, V>(fqn, parent, data, cache) : new UnversionedNode<K, V>(childName, fqn, data, mapSafe, cache);
+ UnversionedNode un = optimistic ? new VersionedNode<K, V>(fqn, parent, data, cache) : new UnversionedNode<K, V>(childName, fqn, data, mapSafe, cache);
// always assume that new nodes do not have data loaded
- n.setDataLoaded(false);
- return n;
+ un.setDataLoaded(false);
+ NodeInvocationDelegate<K, V> nid = new NodeInvocationDelegate(un);
+ componentRegistry.wireDependencies(nid);
+ return nid;
}
public Node<K, V> createNode(Object childName, Node<K, V> parent, Map<K, V> data)
Modified: core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2007-12-11 17:25:09 UTC (rev 4832)
+++ core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2007-12-11 17:26:38 UTC (rev 4833)
@@ -6,6 +6,7 @@
*/
package org.jboss.cache;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.marshall.MethodCall;
import org.jgroups.Address;
import org.jgroups.blocks.RspFilter;
@@ -20,7 +21,7 @@
*/
public class RPCManagerImpl implements RPCManager
{
- private CacheImpl<?, ?> c;
+ private CacheImpl c;
/**
* Empty ctor for mock object creation/unit testing
@@ -29,6 +30,12 @@
{
}
+ @Inject
+ private void setupDependencies(CacheImpl c)
+ {
+ this.c = c;
+ }
+
public RPCManagerImpl(CacheSPI c)
{
this.c = (CacheImpl) c;
Modified: core/trunk/src/main/java/org/jboss/cache/RegionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2007-12-11 17:25:09 UTC (rev 4832)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2007-12-11 17:26:38 UTC (rev 4833)
@@ -10,7 +10,9 @@
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.eviction.EvictionTimerTask;
import org.jboss.cache.eviction.RegionNameConflictException;
+import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.lock.NodeLock;
+import org.jboss.classadapter.spi.ClassAdapterFactory;
import org.jgroups.Address;
import java.util.ArrayList;
@@ -44,7 +46,7 @@
private Map<Fqn, Region> regionsRegistry = new ConcurrentHashMap<Fqn, Region>();
private boolean defaultInactive;
private Log log = LogFactory.getLog(RegionManager.class);
- private CacheImpl<?, ?> cache;
+ private CacheSPI cache;
private boolean usingEvictions;
private EvictionConfig evictionConfig;
private EvictionTimerTask evictionTimerTask = new EvictionTimerTask();
@@ -62,10 +64,8 @@
r.setActive(true);
}
- /**
- * Constructs a new instance attached to a cache.
- */
- public RegionManager(CacheImpl cache)
+ @Inject
+ private void injectDependencies(CacheSPI cache)
{
this.cache = cache;
}
@@ -152,8 +152,8 @@
// this is a very poor way of telling whether a region is a marshalling one or an eviction one. :-(
// mandates that class loaders be registered for marshalling regions.
if (type == ANY
- || (type == MARSHALLING && r.getClassLoader() != null)
- || (type == EVICTION && r.getEvictionPolicyConfig() != null))
+ || (type == MARSHALLING && r.getClassLoader() != null)
+ || (type == EVICTION && r.getEvictionPolicyConfig() != null))
{
return r;
}
@@ -186,8 +186,8 @@
// this is a very poor way of telling whether a region is a marshalling one or an eviction one. :-(
// mandates that class loaders be registered for marshalling regions.
if (type == ANY
- || (type == MARSHALLING && r.getClassLoader() != null)
- || (type == EVICTION && r.getEvictionPolicyConfig() != null))
+ || (type == MARSHALLING && r.getClassLoader() != null)
+ || (type == EVICTION && r.getEvictionPolicyConfig() != null))
{
nextBestThing = r;
}
@@ -198,7 +198,7 @@
// test if the default region has been defined. If not, and if eviction regions
// are in use, throw an exception since it is required.
if ((nextBestThing == null || nextBestThing.getFqn().isRoot() && !regionsRegistry.containsKey(Fqn.ROOT))
- && type == EVICTION)
+ && type == EVICTION)
{
throw new RuntimeException("No default eviction region defined!");
}
@@ -345,7 +345,7 @@
private void activateRegion(Fqn fqn, boolean suppressRegionNotEmptyException)
{
// Check whether the node already exists and has data
- Node subtreeRoot = cache.findNode(fqn);
+ Node subtreeRoot = cache.peek(fqn, false, false);
/*
* Commented out on Nov 16,2006 Manik&Vladimir
@@ -402,7 +402,7 @@
continue;
sources.add(buddy);
Fqn buddyRoot = BuddyManager.getBackupFqn(buddy, fqn);
- subtreeRoot = cache.findNode(buddyRoot);
+ subtreeRoot = cache.peek(buddyRoot, false, false);
if (subtreeRoot == null)
{
// We'll update this node with the state we receive
@@ -412,7 +412,7 @@
subtreeRoot = cache.getRoot().addChild(buddyRoot);
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
}
- cache.fetchPartialState(sources, fqn, subtreeRoot.getFqn());
+ cache.fetchPartialState(sources, fqn, subtreeRoot.getFqn());
}
}
else
@@ -447,7 +447,7 @@
else
{
throw new CacheException(t.getClass().getName() + " " +
- t.getLocalizedMessage(), t);
+ t.getLocalizedMessage(), t);
}
}
finally
@@ -519,7 +519,7 @@
if (buddyManager != null)
{
- Set buddies = cache.getChildrenNames(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN);
+ Set buddies = cache.peek(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN, false, false).getChildrenNames();
if (buddies != null)
{
for (Iterator it = buddies.iterator(); it.hasNext();)
@@ -535,11 +535,12 @@
for (Iterator<Fqn> it = list.iterator(); it.hasNext();)
{
Fqn subtree = it.next();
- subtreeRoot = cache.findNode(subtree);
+ subtreeRoot = cache.peek(subtree, false, false);
if (subtreeRoot != null)
{
// Acquire locks
- Object owner = cache.getOwnerForLock();
+
+ Object owner = getOwnerForLock();
subtreeLock = subtreeRoot.getLock();
subtreeLock.acquireAll(owner, stateFetchTimeout, NodeLock.LockType.WRITE);
subtreeLocked = true;
@@ -554,7 +555,8 @@
}
// Remove the subtree
- cache._evictSubtree(subtree);
+ cache.evict(subtree, true);
+ //cache._evictSubtree(subtree);
// Release locks
if (parent != null)
@@ -612,6 +614,13 @@
}
}
+ private Object getOwnerForLock()
+ {
+ Object owner = cache.getCurrentTransaction();
+ return owner == null ? Thread.currentThread() : owner;
+ }
+
+
/**
* <p/>
* This is legacy code and should not be called directly. This is a private method for now and will be refactored out.
@@ -733,7 +742,7 @@
for (Region r : regionsRegistry.values())
{
if ((type == EVICTION && r.getEvictionPolicy() != null && evictionTimerTask.isRegionRegisteredForProcessing(r)) ||
- (type == MARSHALLING && r.isActive() && r.getClassLoader() != null))
+ (type == MARSHALLING && r.isActive() && r.getClassLoader() != null))
regions.add(r);
}
}
@@ -823,11 +832,8 @@
return "RegionManager " + dumpRegions();
}
- /**
- * Returns the cache for this region manager
- */
- public CacheImpl getCache()
+ public CacheSPI getCache()
{
- return this.cache;
+ return cache;
}
}
Added: core/trunk/src/main/java/org/jboss/cache/remoting/jgroups/CacheMessageListener.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/remoting/jgroups/CacheMessageListener.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/remoting/jgroups/CacheMessageListener.java 2007-12-11 17:26:38 UTC (rev 4833)
@@ -0,0 +1,376 @@
+package org.jboss.cache.remoting.jgroups;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.statetransfer.StateTransferManager;
+import org.jboss.cache.util.ExposedByteArrayOutputStream;
+import org.jboss.util.stream.MarshalledValueInputStream;
+import org.jboss.util.stream.MarshalledValueOutputStream;
+import org.jgroups.ExtendedMessageListener;
+import org.jgroups.Message;
+import org.jgroups.util.Util;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * JGroups MessageListener
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.1.0
+ */
+public class CacheMessageListener implements ExtendedMessageListener
+{
+ /**
+ * Reference to an exception that was raised during
+ * state installation on this node.
+ */
+ protected volatile Exception setStateException;
+ private final Object stateLock = new Object();
+ private Log log = LogFactory.getLog(CacheMessageListener.class);
+ private StateTransferManager stateTransferManager;
+ private Configuration configuration;
+ /**
+ * True if state was initialized during start-up.
+ */
+ private volatile boolean isStateSet = false;
+
+ @Inject
+ private void injectDependencies(StateTransferManager stateTransferManager, Configuration configuration)
+ {
+ this.stateTransferManager = stateTransferManager;
+ this.configuration = configuration;
+ }
+
+ public boolean isStateSet()
+ {
+ return isStateSet;
+ }
+
+ public void setStateSet(boolean stateSet)
+ {
+ isStateSet = stateSet;
+ }
+
+ public void waitForState() throws Exception
+ {
+ synchronized (stateLock)
+ {
+ while (!isStateSet)
+ {
+ if (setStateException != null)
+ {
+ throw setStateException;
+ }
+
+ try
+ {
+ stateLock.wait();
+ }
+ catch (InterruptedException iex)
+ {
+ }
+ }
+ }
+ }
+
+ protected void stateReceivedSuccess()
+ {
+ isStateSet = true;
+ setStateException = null;
+ }
+
+ protected void stateReceivingFailed(Throwable t)
+ {
+ if (t instanceof CacheException)
+ {
+ log.debug(t);
+ }
+ else
+ {
+ log.error("failed setting state", t);
+ }
+ if (t instanceof Exception)
+ {
+ setStateException = (Exception) t;
+ }
+ else
+ {
+ setStateException = new Exception(t);
+ }
+ }
+
+ protected void stateProducingFailed(Throwable t)
+ {
+ if (t instanceof CacheException)
+ {
+ log.debug(t);
+ }
+ else
+ {
+ log.error("Caught " + t.getClass().getName()
+ + " while responding to state transfer request", t);
+ }
+ }
+
+ /**
+ * Callback, does nothing.
+ */
+ public void receive(Message msg)
+ {
+ }
+
+ public byte[] getState()
+ {
+ MarshalledValueOutputStream out = null;
+ byte[] result = null;
+ ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(16 * 1024);
+ try
+ {
+ out = new MarshalledValueOutputStream(baos);
+
+ stateTransferManager.getState(out, Fqn.ROOT, configuration.getStateRetrievalTimeout(), true, true);
+ }
+ catch (Throwable t)
+ {
+ stateProducingFailed(t);
+ }
+ finally
+ {
+ result = baos.getRawBuffer();
+ Util.close(out);
+ }
+ return result;
+ }
+
+ public void setState(byte[] new_state)
+ {
+ if (new_state == null)
+ {
+ log.debug("transferred state is null (may be first member in cluster)");
+ return;
+ }
+ ByteArrayInputStream bais = new ByteArrayInputStream(new_state);
+ MarshalledValueInputStream in = null;
+ try
+ {
+ in = new MarshalledValueInputStream(bais);
+ stateTransferManager.setState(in, Fqn.ROOT);
+ stateReceivedSuccess();
+ }
+ catch (Throwable t)
+ {
+ stateReceivingFailed(t);
+ }
+ finally
+ {
+ Util.close(in);
+ synchronized (stateLock)
+ {
+ // Notify wait that state has been set.
+ stateLock.notifyAll();
+ }
+ }
+ }
+
+ public byte[] getState(String state_id)
+ {
+ MarshalledValueOutputStream out = null;
+ String sourceRoot = state_id;
+ byte[] result = null;
+
+ boolean hasDifferentSourceAndIntegrationRoots = state_id.indexOf(StateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
+ if (hasDifferentSourceAndIntegrationRoots)
+ {
+ sourceRoot = state_id.split(StateTransferManager.PARTIAL_STATE_DELIMITER)[0];
+ }
+
+ ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(16 * 1024);
+ try
+ {
+ out = new MarshalledValueOutputStream(baos);
+
+ stateTransferManager.getState(out, Fqn.fromString(sourceRoot),
+ configuration.getStateRetrievalTimeout(), true, true);
+ }
+ catch (Throwable t)
+ {
+ stateProducingFailed(t);
+ }
+ finally
+ {
+ result = baos.getRawBuffer();
+ Util.close(out);
+ }
+ return result;
+ }
+
+ public void getState(OutputStream ostream)
+ {
+ MarshalledValueOutputStream out = null;
+ try
+ {
+ out = new MarshalledValueOutputStream(ostream);
+ stateTransferManager.getState(out, Fqn.ROOT, configuration.getStateRetrievalTimeout(), true, true);
+ }
+ catch (Throwable t)
+ {
+ stateProducingFailed(t);
+ }
+ finally
+ {
+ Util.close(out);
+ }
+ }
+
+ public void getState(String state_id, OutputStream ostream)
+ {
+ String sourceRoot = state_id;
+ MarshalledValueOutputStream out = null;
+ boolean hasDifferentSourceAndIntegrationRoots = state_id.indexOf(StateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
+ if (hasDifferentSourceAndIntegrationRoots)
+ {
+ sourceRoot = state_id.split(StateTransferManager.PARTIAL_STATE_DELIMITER)[0];
+ }
+ try
+ {
+ out = new MarshalledValueOutputStream(ostream);
+ stateTransferManager.getState(out, Fqn.fromString(sourceRoot), configuration.getStateRetrievalTimeout(), true, true);
+ }
+ catch (Throwable t)
+ {
+ stateProducingFailed(t);
+ }
+ finally
+ {
+ Util.close(out);
+ }
+ }
+
+ public void setState(InputStream istream)
+ {
+ if (istream == null)
+ {
+ log.debug("stream is null (may be first member in cluster)");
+ return;
+ }
+ MarshalledValueInputStream in = null;
+ try
+ {
+ in = new MarshalledValueInputStream(istream);
+ stateTransferManager.setState(in, Fqn.ROOT);
+ stateReceivedSuccess();
+ }
+ catch (Throwable t)
+ {
+ stateReceivingFailed(t);
+ }
+ finally
+ {
+ Util.close(in);
+ synchronized (stateLock)
+ {
+ // Notify wait that state has been set.
+ stateLock.notifyAll();
+ }
+ }
+ }
+
+ public void setState(String state_id, byte[] state)
+ {
+ if (state == null)
+ {
+ log.debug("partial transferred state is null");
+ return;
+ }
+
+ MarshalledValueInputStream in = null;
+ String targetRoot = state_id;
+ boolean hasDifferentSourceAndIntegrationRoots = state_id.indexOf(StateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
+ if (hasDifferentSourceAndIntegrationRoots)
+ {
+ targetRoot = state_id.split(StateTransferManager.PARTIAL_STATE_DELIMITER)[1];
+ }
+ try
+ {
+ log.debug("Setting received partial state for subroot " + state_id);
+ Fqn subroot = Fqn.fromString(targetRoot);
+// Region region = regionManager.getRegion(subroot, false);
+// ClassLoader cl = null;
+// if (region != null)
+// {
+// // If a classloader is registered for the node's region, use it
+// cl = region.getClassLoader();
+// }
+ ByteArrayInputStream bais = new ByteArrayInputStream(state);
+ in = new MarshalledValueInputStream(bais);
+ //getStateTransferManager().setState(in, subroot, cl);
+ stateTransferManager.setState(in, subroot);
+ stateReceivedSuccess();
+ }
+ catch (Throwable t)
+ {
+ stateReceivingFailed(t);
+ }
+ finally
+ {
+ Util.close(in);
+ synchronized (stateLock)
+ {
+ // Notify wait that state has been set.
+ stateLock.notifyAll();
+ }
+ }
+ }
+
+ public void setState(String state_id, InputStream istream)
+ {
+ String targetRoot = state_id;
+ MarshalledValueInputStream in = null;
+ boolean hasDifferentSourceAndIntegrationRoots = state_id.indexOf(StateTransferManager.PARTIAL_STATE_DELIMITER) > 0;
+ if (hasDifferentSourceAndIntegrationRoots)
+ {
+ targetRoot = state_id.split(StateTransferManager.PARTIAL_STATE_DELIMITER)[1];
+ }
+ if (istream == null)
+ {
+ log.debug("stream is null (may be first member in cluster). State is not set");
+ return;
+ }
+
+ try
+ {
+ log.debug("Setting received partial state for subroot " + state_id);
+ in = new MarshalledValueInputStream(istream);
+ Fqn subroot = Fqn.fromString(targetRoot);
+// Region region = regionManager.getRegion(subroot, false);
+// ClassLoader cl = null;
+// if (region != null)
+// {
+// // If a classloader is registered for the node's region, use it
+// cl = region.getClassLoader();
+// }
+ //getStateTransferManager().setState(in, subroot, cl);
+ stateTransferManager.setState(in, subroot);
+ stateReceivedSuccess();
+ }
+ catch (Throwable t)
+ {
+ stateReceivingFailed(t);
+ }
+ finally
+ {
+ Util.close(in);
+ synchronized (stateLock)
+ {
+ // Notify wait that state has been set.
+ stateLock.notifyAll();
+ }
+ }
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/util/BeanUtils.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/BeanUtils.java 2007-12-11 17:25:09 UTC (rev 4832)
+++ core/trunk/src/main/java/org/jboss/cache/util/BeanUtils.java 2007-12-11 17:26:38 UTC (rev 4833)
@@ -15,8 +15,10 @@
public class BeanUtils
{
private static Log log = LogFactory.getLog(BeanUtils.class);
+
/**
* Retrieves a setter name based on a field name passed in
+ *
* @param fieldName field name to find setter for
* @return name of setter method
*/
@@ -36,6 +38,7 @@
/**
* Returns a getter for a given class
+ *
* @param componentClass class to find getter for
* @return name of getter method
*/
@@ -47,8 +50,23 @@
}
/**
+ * Returns a setter for a given class
+ *
+ * @param componentClass class to find setter for
+ * @return name of getter method
+ */
+ public static String setterName(Class componentClass)
+ {
+ StringBuilder sb = new StringBuilder("set");
+ sb.append(componentClass.getSimpleName());
+ return sb.toString();
+ }
+
+
+ /**
* Returns a Method object corresponding to a getter that retrieves an instance of componentClass from target.
- * @param target class that the getter should exist on
+ *
+ * @param target class that the getter should exist on
* @param componentClass component to get
* @return Method object, or null of one does not exist
*/
@@ -60,8 +78,30 @@
}
catch (NoSuchMethodException e)
{
- log.trace("Unable to find method " + getterName(componentClass) + " in class " + target);
+ if (log.isTraceEnabled())
+ log.trace("Unable to find method " + getterName(componentClass) + " in class " + target);
return null;
}
}
+
+ /**
+ * Returns a Method object corresponding to a setter that sets an instance of componentClass from target.
+ *
+ * @param target class that the setter should exist on
+ * @param componentClass component to set
+ * @return Method object, or null of one does not exist
+ */
+ public static Method setterMethod(Class target, Class componentClass)
+ {
+ try
+ {
+ return target.getMethod(setterName(componentClass), componentClass);
+ }
+ catch (NoSuchMethodException e)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Unable to find method " + setterName(componentClass) + " in class " + target);
+ return null;
+ }
+ }
}
17 years, 3 months