JBoss Cache SVN: r6167 - core/trunk/src/test/java/org/jboss/cache/factories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-03 16:09:26 -0400 (Thu, 03 Jul 2008)
New Revision: 6167
Modified:
core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java
Log:
Proper preloading
Modified: core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java 2008-07-03 20:03:42 UTC (rev 6166)
+++ core/trunk/src/test/java/org/jboss/cache/factories/UnitTestCacheConfigurationFactory.java 2008-07-03 20:09:26 UTC (rev 6167)
@@ -93,6 +93,7 @@
clc.addIndividualCacheLoaderConfig(iclc);
clc.setPassivation(passivation);
clc.setShared(shared);
+ clc.setPreload(preload);
return clc;
}
16 years, 6 months
JBoss Cache SVN: r6166 - core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-03 16:03:42 -0400 (Thu, 03 Jul 2008)
New Revision: 6166
Modified:
core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java
Log:
Deal with cache.getRoot()
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 2008-07-03 19:58:15 UTC (rev 6165)
+++ core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java 2008-07-03 20:03:42 UTC (rev 6166)
@@ -11,13 +11,14 @@
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
+import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.util.TestingUtil;
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;
import java.util.HashMap;
import java.util.Map;
@@ -42,6 +43,7 @@
private CacheSPI<String, String> cache1;
private CacheSPI<String, String> cache2;
+ private NodeSPI<String, String> root1, root2;
private Fqn fqn = Fqn.fromString("/a");
private String key = "key";
@@ -69,44 +71,17 @@
cache2.getConfiguration().setNodeLockingScheme(nodeLockingScheme);
cache2.getConfiguration().setCacheMode(cacheMode);
cache2.start();
+
+ root1 = cache1.getRoot();
+ root2 = cache2.getRoot();
}
@AfterMethod(alwaysRun = true)
public void tearDown()
{
- if (cache1 != null)
- {
- cache1.stop();
- flushTxs(cache1.getTransactionManager());
- cache1 = null;
- }
-
- if (cache2 != null)
- {
- cache2.stop();
- flushTxs(cache2.getTransactionManager());
- cache2 = null;
- }
+ TestingUtil.killCaches(cache1, cache2);
}
- private void flushTxs(TransactionManager mgr)
- {
- if (mgr != null)
- {
- try
- {
- if (mgr.getTransaction() != null)
- {
- mgr.rollback();
- }
- }
- catch (SystemException e)
- {
- // do nothing
- }
- }
- }
-
public void testPutKeyValue() throws Exception
{
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
@@ -158,7 +133,7 @@
public void testPutKeyValueViaNodeAPI() throws Exception
{
- Node node1 = cache1.getRoot().addChild(fqn);
+ Node node1 = root1.addChild(fqn);
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
node1.put(key, "value");
delay();
@@ -187,7 +162,7 @@
// now cache2
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- Node node2 = cache2.getRoot().addChild(fqn);
+ Node node2 = root2.addChild(fqn);
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
node2.put(key, "value2");
delay();
@@ -264,7 +239,7 @@
Map<String, String> map = new HashMap<String, String>();
map.put(key, "value");
- Node node1 = cache1.getRoot().addChild(fqn);
+ Node node1 = root1.addChild(fqn);
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
node1.putAll(map);
delay();
@@ -291,7 +266,7 @@
// now cache2
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- Node node2 = cache2.getRoot().addChild(fqn);
+ Node node2 = root2.addChild(fqn);
map.put(key, "value2");
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
node2.putAll(map);
@@ -387,7 +362,7 @@
}
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- cache1.getRoot().removeChild(fqn);
+ root1.removeChild(fqn);
delay();
// should be removed in cache1
@@ -417,7 +392,7 @@
// now try again with passing the default options
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
- cache1.getRoot().removeChild(fqn);
+ root1.removeChild(fqn);
delay();
// both should be null
@@ -483,7 +458,7 @@
public void testRemoveKeyViaNodeAPI() throws Exception
{
// put some stuff in the cache first
- Node node1 = cache1.getRoot().addChild(fqn);
+ Node node1 = root1.addChild(fqn);
cache1.getInvocationContext().setOptionOverrides(null);
node1.put(key, "value");
delay();
@@ -652,7 +627,7 @@
public void testTransactionalBehaviourViaNodeAPI() throws Exception
{
- Node node1 = cache1.getRoot().addChild(fqn);
+ Node node1 = root1.addChild(fqn);
TransactionManager mgr = cache1.getTransactionManager();
mgr.begin();
cache1.getInvocationContext().getOptionOverrides().reset();
@@ -695,7 +670,7 @@
}
// now cache2
- Node node2 = cache2.getRoot().addChild(fqn);
+ Node node2 = root2.addChild(fqn);
mgr = cache2.getTransactionManager();
mgr.begin();
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
@@ -738,25 +713,25 @@
public void testAddChild() throws Exception
{
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- cache1.getRoot().addChild(fqn);
+ root1.addChild(fqn);
delay();
// cache1 should still have this
- assertTrue(cache1.getRoot().hasChild(fqn));
+ assertTrue(root1.hasChild(fqn));
// cache 2 should not
- Node node2 = cache2.getRoot().getChild(fqn);
+ Node node2 = root2.getChild(fqn);
assertTrue("Should be null", node2 == null || (isInvalidation && !node2.isValid()));
// now try again with passing the default options
- cache1.getRoot().removeChild(fqn);
+ root1.removeChild(fqn);
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
- cache1.getRoot().addChild(fqn);
+ root1.addChild(fqn);
delay();
// cache1 should still have this
- assertTrue(cache1.getRoot().hasChild(fqn));
+ assertTrue(root1.hasChild(fqn));
// cache 2 should as well
if (!isInvalidation)
{
- assertTrue(cache2.getRoot().hasChild(fqn));
+ assertTrue(root2.hasChild(fqn));
}
else
{
16 years, 6 months
JBoss Cache SVN: r6165 - core/trunk/src/test/java/org/jboss/cache/marshall.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-03 15:58:15 -0400 (Thu, 03 Jul 2008)
New Revision: 6165
Modified:
core/trunk/src/test/java/org/jboss/cache/marshall/AsyncReplTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java
Log:
Updated to deal with legacy commands
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/AsyncReplTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/AsyncReplTest.java 2008-07-03 19:57:53 UTC (rev 6164)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/AsyncReplTest.java 2008-07-03 19:58:15 UTC (rev 6165)
@@ -13,7 +13,7 @@
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
-import org.jboss.cache.commands.write.PutKeyValueCommand;
+import org.jboss.cache.commands.legacy.write.PessPutKeyValueCommand;
import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.marshall.data.Address;
@@ -25,7 +25,13 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import javax.transaction.*;
+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;
/**
@@ -109,11 +115,11 @@
}
if (useMarshalledValues) Thread.currentThread().setContextClassLoader(cla);
- replListener2.expect(PutKeyValueCommand.class);
+ replListener2.expect(PessPutKeyValueCommand.class);
cache1.put(aop, "person", ben);
replListener2.waitForReplicationToOccur(500);
- replListener2.expect(PutKeyValueCommand.class);
+ replListener2.expect(PessPutKeyValueCommand.class);
cache1.put(Fqn.fromString("/alias"), "person", ben);
replListener2.waitForReplicationToOccur(500);
@@ -138,7 +144,7 @@
// Set it back to the cache
// Can't cast it to Person. CCE will resutl.
if (useMarshalledValues) Thread.currentThread().setContextClassLoader(clb);
- replListener1.expect(PutKeyValueCommand.class);
+ replListener1.expect(PessPutKeyValueCommand.class);
cache2.put(aop, "person", ben2);
replListener1.waitForReplicationToOccur(1000);
if (useMarshalledValues) resetContextClassLoader();
@@ -168,14 +174,14 @@
if (useMarshalledValues) Thread.currentThread().setContextClassLoader(cla);
- replListener2.expect(PutKeyValueCommand.class);
+ replListener2.expect(PessPutKeyValueCommand.class);
cache1.put(Fqn.fromString("/aop/1"), "person", ben);
replListener2.waitForReplicationToOccur(1000);
- replListener2.expect(PutKeyValueCommand.class);
+ replListener2.expect(PessPutKeyValueCommand.class);
cache1.put(Fqn.fromString("/aop/2"), "person", scopedBen1);
replListener2.waitForReplicationToOccur(1000);
-
+
if (useMarshalledValues) resetContextClassLoader();
Object ben2 = null;
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java 2008-07-03 19:57:53 UTC (rev 6164)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/CacheMarshallerTestBase.java 2008-07-03 19:58:15 UTC (rev 6165)
@@ -9,8 +9,8 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.RegionManager;
import org.jboss.cache.commands.ReplicableCommand;
+import org.jboss.cache.commands.legacy.write.PessPutKeyValueCommand;
import org.jboss.cache.commands.remote.ReplicateCommand;
-import org.jboss.cache.commands.write.PutKeyValueCommand;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.ComponentRegistry;
import org.jboss.cache.invocation.CacheInvocationDelegate;
@@ -112,7 +112,7 @@
public void testMethodCall() throws Exception
{
Fqn fqn = Fqn.fromElements(3, false);
- ReplicableCommand cmd = new PutKeyValueCommand(null, fqn, "key", "value");
+ ReplicableCommand cmd = new PessPutKeyValueCommand(null, fqn, "key", "value");
byte[] asBytes = marshaller.objectToByteBuffer(cmd);
Object o2 = marshaller.objectFromByteBuffer(asBytes);
@@ -125,7 +125,7 @@
public void testNestedMethodCall() throws Exception
{
Fqn fqn = Fqn.fromElements(3, false);
- ReplicableCommand cmd = new PutKeyValueCommand(null, fqn, "key", "value");
+ ReplicableCommand cmd = new PessPutKeyValueCommand(null, fqn, "key", "value");
ReplicableCommand replicateCmd = new ReplicateCommand(cmd);
byte[] asBytes = marshaller.objectToByteBuffer(replicateCmd);
Object o2 = marshaller.objectFromByteBuffer(asBytes);
@@ -215,12 +215,12 @@
Fqn f = Fqn.fromElements("BlahBlah", 3, false);
String k = "key", v = "value";
- ReplicableCommand cmd = new PutKeyValueCommand(null, f, k, v);
+ ReplicableCommand cmd = new PessPutKeyValueCommand(null, f, k, v);
ReplicableCommand replCmd = new ReplicateCommand(cmd);
calls.add(replCmd);
- cmd = new PutKeyValueCommand(null, f, k, v);
+ cmd = new PessPutKeyValueCommand(null, f, k, v);
replCmd = new ReplicateCommand(cmd);
calls.add(replCmd);
16 years, 6 months
JBoss Cache SVN: r6164 - core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-03 15:57:53 -0400 (Thu, 03 Jul 2008)
New Revision: 6164
Removed:
core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/RepeatableReadTestBase.java
Log:
Sync commit and rollback phases
Deleted: core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/RepeatableReadTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/RepeatableReadTestBase.java 2008-07-03 15:27:48 UTC (rev 6163)
+++ core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/RepeatableReadTestBase.java 2008-07-03 19:57:53 UTC (rev 6164)
@@ -1,88 +0,0 @@
-package org.jboss.cache.api.mvcc.repeatable_read;
-
-import org.jboss.cache.api.mvcc.LockTestBase;
-
-import javax.transaction.Transaction;
-
-public abstract class RepeatableReadTestBase extends LockTestBase
-{
- protected RepeatableReadTestBase()
- {
- repeatableRead = true;
- }
-
- public void testRepeatableReadWithRemove() throws Exception
- {
- cache.put(AB, "k", "v");
-
- tm.begin();
- assert cache.getNode(AB) != null;
- Transaction reader = tm.suspend();
-
- tm.begin();
- assert cache.removeNode(AB);
- assert cache.getNode(AB) == null;
- tm.commit();
-
- assert cache.getNode(AB) == null;
-
- tm.resume(reader);
- assert cache.getNode(AB) != null;
- assert "v".equals(cache.get(AB, "k"));
- tm.commit();
-
- assert cache.getNode(AB) == null;
- assertNoLocks();
- }
-
- public void testRepeatableReadWithEvict() throws Exception
- {
- cache.put(AB, "k", "v");
-
- tm.begin();
- assert cache.getNode(AB) != null;
- Transaction reader = tm.suspend();
-
- tm.begin();
- cache.evict(AB);
- assert cache.getNode(AB) == null;
- tm.commit();
-
- assert cache.getNode(AB) == null;
-
- tm.resume(reader);
- assert cache.getNode(AB) != null;
- assert "v".equals(cache.get(AB, "k"));
- tm.commit();
-
- assert cache.getNode(AB) == null;
- assertNoLocks();
- }
-
- public void testRepeatableReadWithNull() throws Exception
- {
- assert cache.getNode(AB) == null;
-
- tm.begin();
- assert cache.getNode(AB) == null;
- Transaction reader = tm.suspend();
-
- tm.begin();
- cache.put(AB, "k", "v");
- assert cache.getNode(AB) != null;
- assert "v".equals(cache.get(AB, "k"));
- tm.commit();
-
- assert cache.getNode(AB) != null;
- assert "v".equals(cache.get(AB, "k"));
-
- tm.resume(reader);
- assert cache.getNode(AB) == null;
- assert cache.get(AB, "k") == null;
- tm.commit();
-
- assert cache.getNode(AB) != null;
- assert "v".equals(cache.get(AB, "k"));
- assertNoLocks();
- }
-}
16 years, 6 months
JBoss Cache SVN: r6163 - searchable/trunk/src/main/java/org/jboss/cache/search.
by jbosscache-commits@lists.jboss.org
Author: navssurtani
Date: 2008-07-03 11:27:48 -0400 (Thu, 03 Jul 2008)
New Revision: 6163
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java
Log:
line 64 in SCF changed. Only constructs a Core listener
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java 2008-07-03 15:04:40 UTC (rev 6162)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java 2008-07-03 15:27:48 UTC (rev 6163)
@@ -59,7 +59,9 @@
boolean isPojoCache = c instanceof PojoCache;
// Step 2: Add cache listener to listen for events happening in the cache.
- SearchableListener listener = isPojoCache ? new SearchablePojoListener(searchFactory) : new SearchableCoreListener(searchFactory);
+ //SearchableListener listener = isPojoCache ? new SearchablePojoListener(searchFactory) : new SearchableCoreListener(searchFactory);
+
+ SearchableCoreListener listener = new SearchableCoreListener(searchFactory);
c.addCacheListener(listener);
16 years, 6 months
JBoss Cache SVN: r6162 - core/trunk/src/test/java/org/jboss/cache/api.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-03 11:04:40 -0400 (Thu, 03 Jul 2008)
New Revision: 6162
Modified:
core/trunk/src/test/java/org/jboss/cache/api/SyncReplTxTest.java
Log:
Sync commit and rollback phases
Modified: core/trunk/src/test/java/org/jboss/cache/api/SyncReplTxTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/SyncReplTxTest.java 2008-07-03 14:40:16 UTC (rev 6161)
+++ core/trunk/src/test/java/org/jboss/cache/api/SyncReplTxTest.java 2008-07-03 15:04:40 UTC (rev 6162)
@@ -44,20 +44,23 @@
protected NodeLockingScheme nodeLockingScheme = NodeLockingScheme.PESSIMISTIC;
@BeforeMethod(alwaysRun = true)
- public void setUp()
+ public void setUp() throws CloneNotSupportedException
{
System.out.println("*** In setUp()");
caches = new ArrayList<CacheSPI<Object, Object>>();
CacheSPI<Object, Object> cache1 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
- CacheSPI<Object, Object> cache2 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
cache1.getConfiguration().setNodeLockingScheme(nodeLockingScheme);
- cache2.getConfiguration().setNodeLockingScheme(nodeLockingScheme);
+ cache1.getConfiguration().setSyncCommitPhase(true);
+ cache1.getConfiguration().setSyncRollbackPhase(true);
+ cache1.getConfiguration().setFetchInMemoryState(false);
configure(cache1.getConfiguration());
- configure(cache2.getConfiguration());
cache1.start();
+
+ CacheSPI<Object, Object> cache2 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(cache1.getConfiguration().clone(), false);
+
cache2.start();
caches.add(cache1);
16 years, 6 months
JBoss Cache SVN: r6161 - in core/trunk/src: main/java/org/jboss/cache/commands/write and 7 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-03 10:40:16 -0400 (Thu, 03 Jul 2008)
New Revision: 6161
Added:
core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockAssert.java
core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/RepeatableReadLockTest.java
core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/WriteSkewTest.java
Removed:
core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/RepeatableReadNoWriteSkewLockTest.java
core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/RepeatableReadWriteSkewLockTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessRemoveNodeCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveNodeCommand.java
core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java
core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java
core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java
core/trunk/src/test/java/org/jboss/cache/api/CacheAPITest.java
core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java
core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockTestBase.java
core/trunk/src/test/java/org/jboss/cache/api/mvcc/read_committed/NodeMoveMvccTest.java
core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/NodeMoveMvccTest.java
core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/RemoveNodeCommandTest.java
Log:
Lots more MVCC fixes
Modified: core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessRemoveNodeCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessRemoveNodeCommand.java 2008-07-03 14:05:31 UTC (rev 6160)
+++ core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessRemoveNodeCommand.java 2008-07-03 14:40:16 UTC (rev 6161)
@@ -33,6 +33,12 @@
@Override
public Object perform(InvocationContext ctx)
{
+ NodeSPI targetNode = peekVersioned(ctx);
+ if (targetNode != null)
+ {
+ Map data = targetNode.getDataDirect();
+ if (data != null && !data.isEmpty()) originalData = new HashMap(data);
+ }
boolean found = (Boolean) super.perform(ctx);
// now record rollback info.
Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java 2008-07-03 14:05:31 UTC (rev 6160)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java 2008-07-03 14:40:16 UTC (rev 6161)
@@ -102,7 +102,7 @@
if (trace) log.trace("Moving " + fqn + " to sit under " + to);
- NodeSPI oldParent = (NodeSPI) node.getParent();
+ NodeSPI oldParent = node.getParentDirect();
Object nodeName = toMoveFqn.getLastElement();
// now that we have the parent and target nodes:
Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveNodeCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveNodeCommand.java 2008-07-03 14:05:31 UTC (rev 6160)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/RemoveNodeCommand.java 2008-07-03 14:40:16 UTC (rev 6161)
@@ -56,6 +56,9 @@
boolean found = targetNode.isValid() && !targetNode.isDeleted();
targetNode.markAsDeleted(true, true);
+ // make sure we clear all data on this node!
+ targetNode.clearDataDirect();
+
notifyAfterRemove(ctx);
return found;
}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java 2008-07-03 14:05:31 UTC (rev 6160)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/MVCCLockingInterceptor.java 2008-07-03 14:40:16 UTC (rev 6161)
@@ -169,6 +169,8 @@
if (rcn != null)
{
rcn.copyNodeForUpdate(dataContainer, allowWriteSkew, ctx, nodeFactory);
+ ReadCommittedNode parent = (ReadCommittedNode) ctx.lookUpNode(fqn.getParent());
+ parent.addChildDirect(nodeFactory.createNodeInvocationDelegate((InternalNode) rcn.getDelegationTarget()));
if (isRecursive)
{
@@ -343,7 +345,7 @@
{
// for each of these, swap refs
ReadCommittedNode rcn = (ReadCommittedNode) ctx.lookUpNode(fqnsToUnlock[i]);
- if (rcn != null) rcn.commitUpdate(dataContainer, nodeFactory); // could be null with read-committed
+ if (rcn != null) rcn.commitUpdate(dataContainer, nodeFactory, ctx); // could be null with read-committed
// and then unlock
lockManager.unlock(fqnsToUnlock[i], owner);
}
@@ -373,7 +375,7 @@
if (commit)
{
// for each of these, swap refs
- rcn.commitUpdate(dataContainer, nodeFactory);
+ rcn.commitUpdate(dataContainer, nodeFactory, ctx);
}
else
{
@@ -431,7 +433,7 @@
InternalNode node = dataContainer.peekInternalNode(f, false);
if (node != null)
{
- lockManager.lock(f, WRITE, ctx);
+ lock(ctx, f);
NodeSPI wrapped = nodeFactory.createMvccNode(node);
ctx.putLookedUpNode(f, wrapped);
}
@@ -467,6 +469,12 @@
n.copyNodeForUpdate(dataContainer, allowWriteSkew, context, nodeFactory);
}
if (trace) log.trace("Retrieving wrapped node " + fqn);
+ if (n.isDeleted() && createIfAbsent)
+ {
+ if (trace) log.trace("Node is deleted in current scope. Need to un-delete.");
+ n.markAsDeleted(false);
+ n.setValid(true, false);
+ }
return n;
}
Modified: core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java 2008-07-03 14:05:31 UTC (rev 6160)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java 2008-07-03 14:40:16 UTC (rev 6161)
@@ -40,32 +40,25 @@
node.setVersion(newVersion);
}
- public void commitUpdate(DataContainer container, NodeFactory nf)
+ public void commitUpdate(DataContainer container, NodeFactory nf, InvocationContext ctx)
{
if (changed)
{
- updateNode(container, nf);
+ updateNode(container, nf, ctx);
changed = false;
backup = null;
}
}
- protected void updateNode(DataContainer container, NodeFactory nf)
+ protected void updateNode(DataContainer container, NodeFactory nf, InvocationContext ctx)
{
if (isDeleted())
{
Fqn fqn = getFqn();
if (!fqn.isRoot())
{
- NodeSPI parent = container.peek(fqn.getParent());
- if (parent != null)
- {
- parent.removeChildDirect(fqn.getLastElement());
- }
- else
- {
- if (trace) log.trace("Parent is null in the underlying cache; cannot remove.");
- }
+ NodeSPI parent = ctx.lookUpNode(fqn.getParent()); // this will be there since parent nodes are locked when a child is removed.
+ parent.removeChildDirect(fqn.getLastElement());
}
else
{
Modified: core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java 2008-07-03 14:05:31 UTC (rev 6160)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java 2008-07-03 14:40:16 UTC (rev 6161)
@@ -51,7 +51,7 @@
}
@Override
- protected void updateNode(DataContainer dataContainer, NodeFactory nf)
+ protected void updateNode(DataContainer dataContainer, NodeFactory nf, InvocationContext ctx)
{
if (trace)
log.trace("Updating RepeatableReadNode. IsDeleted? " + isDeleted() + " isValid? " + isValid() + " isChanged? " + isChanged());
Modified: core/trunk/src/test/java/org/jboss/cache/api/CacheAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/CacheAPITest.java 2008-07-03 14:05:31 UTC (rev 6160)
+++ core/trunk/src/test/java/org/jboss/cache/api/CacheAPITest.java 2008-07-03 14:40:16 UTC (rev 6161)
@@ -167,10 +167,14 @@
assertEquals(true, cache.removeNode(fqn));
assertFalse(cache.getRoot().hasChild(fqn));
+ // remove should REALLY remove though and not just mark as deleted/invalid.
+ NodeSPI n = cache.peek(fqn, true, true);
+ assert n == null;
+
assertEquals(false, cache.removeNode(fqn));
// remove should REALLY remove though and not just mark as deleted/invalid.
- NodeSPI n = cache.peek(fqn, true, true);
+ n = cache.peek(fqn, true, true);
assert n == null;
System.out.println("Cache: " + CachePrinter.printCacheDetails(cache));
Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java 2008-07-03 14:05:31 UTC (rev 6160)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java 2008-07-03 14:40:16 UTC (rev 6161)
@@ -50,6 +50,8 @@
// start a single cache instance
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache("configs/local-tx.xml", false);
cache.getConfiguration().setNodeLockingScheme(nodeLockingScheme);
+ cache.getConfiguration().setFetchInMemoryState(false);
+ cache.getConfiguration().setEvictionConfig(null);
configure(cache.getConfiguration());
cache.start();
rootNode = cache.getRoot();
@@ -401,14 +403,22 @@
cache.move(nodeC.getFqn(), nodeB.getFqn());
- assertEquals("ROOT should have a RL, nodeC should have a RL, nodeA should have a RL, nodeB should have a WL", 4, cache.getNumberOfLocksHeld());
+ checkLocks();
tm.commit();
+ assertNoLocks();
+ }
+ protected void checkLocks()
+ {
+ assertEquals("ROOT should have a RL, nodeC should have a RL, nodeA should have a RL, nodeB should have a WL", 4, cache.getNumberOfLocksHeld());
+ }
+
+ protected void assertNoLocks()
+ {
assertEquals(0, cache.getNumberOfLocksHeld());
}
-
@Test(groups = {"functional"})
public void testConcurrency() throws InterruptedException
{
Added: core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockAssert.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockAssert.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockAssert.java 2008-07-03 14:40:16 UTC (rev 6161)
@@ -0,0 +1,36 @@
+package org.jboss.cache.api.mvcc;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.invocation.InvocationContextContainer;
+import org.jboss.cache.lock.LockManager;
+import org.jboss.cache.lock.MVCCLockManager.LockContainer;
+import org.jboss.cache.util.TestingUtil;
+
+/**
+ * Helper class to assert lock status in MVCC
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class LockAssert
+{
+ public static void assertLocked(Fqn fqn, LockManager lockManager, InvocationContextContainer icc)
+ {
+ assert lockManager.isLocked(fqn) : fqn + " not locked!";
+ assert icc.get().getLocks().contains(fqn) : "Lock not recorded for " + fqn;
+ }
+
+ public static void assertNotLocked(Fqn fqn, LockManager lockManager, InvocationContextContainer icc)
+ {
+ // can't rely on the negative test since other nodes may share the same lock with lock striping.
+// assert !lockManager.isLocked(fqn) : fqn + " is locked!";
+ assert !icc.get().getLocks().contains(fqn) : fqn + " lock recorded!";
+ }
+
+ public static void assertNoLocks(LockManager lockManager, InvocationContextContainer icc)
+ {
+ LockContainer lc = (LockContainer) TestingUtil.extractField(lockManager, "lockContainer");
+ assert lc.getNumLocksHeld() == 0 : "Stale locks exist! NumLocksHeld is " + lc.getNumLocksHeld() + " and lock info is " + lockManager.printLockInfo();
+ assert icc.get().getLocks().isEmpty() : "Stale (?) locks recorded! " + icc.get().getLocks();
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockTestBase.java 2008-07-03 14:05:31 UTC (rev 6160)
+++ core/trunk/src/test/java/org/jboss/cache/api/mvcc/LockTestBase.java 2008-07-03 14:40:16 UTC (rev 6161)
@@ -9,7 +9,6 @@
import org.jboss.cache.invocation.InvocationContextContainer;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.LockManager;
-import org.jboss.cache.lock.MVCCLockManager.LockContainer;
import org.jboss.cache.lock.TimeoutException;
import org.jboss.cache.transaction.DummyTransactionManagerLookup;
import org.jboss.cache.util.TestingUtil;
@@ -17,14 +16,9 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
-import java.util.Collection;
import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.CountDownLatch;
/**
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
@@ -42,7 +36,6 @@
protected LockManager lockManager;
protected InvocationContextContainer icc;
protected boolean repeatableRead = true;
- protected boolean allowWriteSkew = false;
@BeforeMethod
public void setUp()
@@ -51,7 +44,6 @@
cache.getConfiguration().setNodeLockingScheme(NodeLockingScheme.MVCC);
cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
cache.getConfiguration().setIsolationLevel(repeatableRead ? IsolationLevel.REPEATABLE_READ : IsolationLevel.READ_COMMITTED);
- cache.getConfiguration().setAllowWriteSkew(allowWriteSkew);
// reduce lock acquisition timeout so this doesn't take forever to run
cache.getConfiguration().setLockAcquisitionTimeout(200); // 200 ms
cache.start();
@@ -68,22 +60,17 @@
protected void assertLocked(Fqn fqn)
{
- assert lockManager.isLocked(fqn) : fqn + " not locked!";
- assert icc.get().getLocks().contains(fqn) : "Lock not recorded for " + fqn;
+ LockAssert.assertLocked(fqn, lockManager, icc);
}
protected void assertNotLocked(Fqn fqn)
{
- // can't rely on the negative test since other nodes may share the same lock with lock striping.
-// assert !lockManager.isLocked(fqn) : fqn + " is locked!";
- assert !icc.get().getLocks().contains(fqn) : fqn + " lock recorded!";
+ LockAssert.assertNotLocked(fqn, lockManager, icc);
}
protected void assertNoLocks()
{
- LockContainer lc = (LockContainer) TestingUtil.extractField(lockManager, "lockContainer");
- assert lc.getNumLocksHeld() == 0 : "Stale locks exist! NumLocksHeld is " + lc.getNumLocksHeld() + " and lock info is " + lockManager.printLockInfo();
- assert icc.get().getLocks().isEmpty() : "Stale (?) locks recorded! " + icc.get().getLocks();
+ LockAssert.assertNoLocks(lockManager, icc);
}
public void testLocksOnPutKeyVal() throws Exception
@@ -463,120 +450,4 @@
assert null == cache.getNode(AB);
assertNoLocks();
}
-
- public void testWriteSkew() throws Exception
- {
- if (repeatableRead)
- {
- cache.put(AB, "k", "v");
- final Set<Exception> w1exceptions = new HashSet<Exception>();
- final Set<Exception> w2exceptions = new HashSet<Exception>();
- final CountDownLatch w1Signal = new CountDownLatch(1);
- final CountDownLatch w2Signal = new CountDownLatch(1);
- final CountDownLatch threadSignal = new CountDownLatch(2);
-
- Thread w1 = new Thread("Writer-1")
- {
- public void run()
- {
- boolean didCoundDown = false;
- try
- {
- tm.begin();
- assert "v".equals(cache.get(AB, "k"));
- threadSignal.countDown();
- didCoundDown = true;
- w1Signal.await();
- cache.put(AB, "k", "v2");
- tm.commit();
- }
- catch (Exception e)
- {
- w1exceptions.add(e);
- }
- finally
- {
- if (!didCoundDown) threadSignal.countDown();
- }
- }
- };
-
- Thread w2 = new Thread("Writer-2")
- {
- public void run()
- {
- boolean didCoundDown = false;
- try
- {
- tm.begin();
- assert "v".equals(cache.get(AB, "k"));
- threadSignal.countDown();
- didCoundDown = true;
- w2Signal.await();
- cache.put(AB, "k", "v3");
- tm.commit();
- }
- catch (Exception e)
- {
- w2exceptions.add(e);
- // the exception will be thrown when doing a cache.put(). We should make sure we roll back the tx to release locks.
- if (!allowWriteSkew)
- {
- try
- {
- tm.rollback();
- }
- catch (SystemException e1)
- {
- // do nothing.
- }
- }
- }
- finally
- {
- if (!didCoundDown) threadSignal.countDown();
- }
- }
- };
-
- w1.start();
- w2.start();
-
- threadSignal.await();
- // now. both txs have read.
- // let tx1 start writing
- w1Signal.countDown();
- w1.join();
-
- w2Signal.countDown();
- w2.join();
-
- if (allowWriteSkew)
- {
- // should have no exceptions!!
- throwExceptions(w1exceptions, w2exceptions);
- assert w2exceptions.size() == 0;
- assert w1exceptions.size() == 0;
- assert "v3".equals(cache.get(AB, "k")) : "W2 should have overwritten W1's work!";
- }
- else
- {
- // there should be a single exception from w2.
- assert w2exceptions.size() == 1;
- throwExceptions(w1exceptions);
- assert w1exceptions.size() == 0;
- assert "v2".equals(cache.get(AB, "k")) : "W2 should NOT have overwritten W1's work!";
- }
-
- assertNoLocks();
- }
- }
-
- protected void throwExceptions(Collection<Exception>... exceptions) throws Exception
- {
- for (Collection<Exception> ce : exceptions)
- {
- for (Exception e : ce) throw e;
- }
- }
}
Modified: core/trunk/src/test/java/org/jboss/cache/api/mvcc/read_committed/NodeMoveMvccTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/mvcc/read_committed/NodeMoveMvccTest.java 2008-07-03 14:05:31 UTC (rev 6160)
+++ core/trunk/src/test/java/org/jboss/cache/api/mvcc/read_committed/NodeMoveMvccTest.java 2008-07-03 14:40:16 UTC (rev 6161)
@@ -6,10 +6,16 @@
*/
package org.jboss.cache.api.mvcc.read_committed;
+import org.jboss.cache.Fqn;
import org.jboss.cache.api.NodeMoveAPITest;
+import org.jboss.cache.api.mvcc.LockAssert;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.NodeLockingScheme;
+import org.jboss.cache.factories.ComponentRegistry;
+import org.jboss.cache.invocation.InvocationContextContainer;
import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.lock.LockManager;
+import org.jboss.cache.util.TestingUtil;
import org.testng.annotations.Test;
@Test(groups = {"functional", "mvcc"})
@@ -25,4 +31,27 @@
{
c.setIsolationLevel(IsolationLevel.READ_COMMITTED);
}
+
+ @Override
+ protected void checkLocks()
+ {
+ ComponentRegistry cr = TestingUtil.extractComponentRegistry(cache);
+ LockManager lm = cr.getComponent(LockManager.class);
+ InvocationContextContainer icc = cr.getComponent(InvocationContextContainer.class);
+
+ LockAssert.assertNotLocked(A, lm, icc);
+ LockAssert.assertLocked(Fqn.ROOT, lm, icc);
+ LockAssert.assertLocked(C, lm, icc);
+ LockAssert.assertLocked(Fqn.fromRelativeFqn(A, B), lm, icc);
+ LockAssert.assertLocked(Fqn.fromRelativeFqn(B, C), lm, icc);
+ }
+
+ @Override
+ protected void assertNoLocks()
+ {
+ ComponentRegistry cr = TestingUtil.extractComponentRegistry(cache);
+ LockManager lm = cr.getComponent(LockManager.class);
+ InvocationContextContainer icc = cr.getComponent(InvocationContextContainer.class);
+ LockAssert.assertNoLocks(lm, icc);
+ }
}
\ No newline at end of file
Modified: core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/NodeMoveMvccTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/NodeMoveMvccTest.java 2008-07-03 14:05:31 UTC (rev 6160)
+++ core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/NodeMoveMvccTest.java 2008-07-03 14:40:16 UTC (rev 6161)
@@ -6,10 +6,16 @@
*/
package org.jboss.cache.api.mvcc.repeatable_read;
+import org.jboss.cache.Fqn;
import org.jboss.cache.api.NodeMoveAPITest;
+import org.jboss.cache.api.mvcc.LockAssert;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Configuration.NodeLockingScheme;
+import org.jboss.cache.factories.ComponentRegistry;
+import org.jboss.cache.invocation.InvocationContextContainer;
import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.lock.LockManager;
+import org.jboss.cache.util.TestingUtil;
import org.testng.annotations.Test;
@Test(groups = {"functional", "mvcc"})
@@ -25,4 +31,27 @@
{
c.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
}
+
+ @Override
+ protected void checkLocks()
+ {
+ ComponentRegistry cr = TestingUtil.extractComponentRegistry(cache);
+ LockManager lm = cr.getComponent(LockManager.class);
+ InvocationContextContainer icc = cr.getComponent(InvocationContextContainer.class);
+
+ LockAssert.assertNotLocked(A, lm, icc);
+ LockAssert.assertLocked(Fqn.ROOT, lm, icc);
+ LockAssert.assertLocked(C, lm, icc);
+ LockAssert.assertLocked(Fqn.fromRelativeFqn(A, B), lm, icc);
+ LockAssert.assertLocked(Fqn.fromRelativeFqn(B, C), lm, icc);
+ }
+
+ @Override
+ protected void assertNoLocks()
+ {
+ ComponentRegistry cr = TestingUtil.extractComponentRegistry(cache);
+ LockManager lm = cr.getComponent(LockManager.class);
+ InvocationContextContainer icc = cr.getComponent(InvocationContextContainer.class);
+ LockAssert.assertNoLocks(lm, icc);
+ }
}
Copied: core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/RepeatableReadLockTest.java (from rev 6157, core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/RepeatableReadTestBase.java)
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/RepeatableReadLockTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/RepeatableReadLockTest.java 2008-07-03 14:40:16 UTC (rev 6161)
@@ -0,0 +1,90 @@
+package org.jboss.cache.api.mvcc.repeatable_read;
+
+import org.jboss.cache.api.mvcc.LockTestBase;
+import org.testng.annotations.Test;
+
+import javax.transaction.Transaction;
+
+@Test(groups = {"functional", "mvcc"})
+public class RepeatableReadLockTest extends LockTestBase
+{
+ public RepeatableReadLockTest()
+ {
+ repeatableRead = true;
+ }
+
+ public void testRepeatableReadWithRemove() throws Exception
+ {
+ cache.put(AB, "k", "v");
+
+ tm.begin();
+ assert cache.getNode(AB) != null;
+ Transaction reader = tm.suspend();
+
+ tm.begin();
+ assert cache.removeNode(AB);
+ assert cache.getNode(AB) == null;
+ tm.commit();
+
+ assert cache.getNode(AB) == null;
+
+ tm.resume(reader);
+ assert cache.getNode(AB) != null;
+ assert "v".equals(cache.get(AB, "k"));
+ tm.commit();
+
+ assert cache.getNode(AB) == null;
+ assertNoLocks();
+ }
+
+ public void testRepeatableReadWithEvict() throws Exception
+ {
+ cache.put(AB, "k", "v");
+
+ tm.begin();
+ assert cache.getNode(AB) != null;
+ Transaction reader = tm.suspend();
+
+ tm.begin();
+ cache.evict(AB);
+ assert cache.getNode(AB) == null;
+ tm.commit();
+
+ assert cache.getNode(AB) == null;
+
+ tm.resume(reader);
+ assert cache.getNode(AB) != null;
+ assert "v".equals(cache.get(AB, "k"));
+ tm.commit();
+
+ assert cache.getNode(AB) == null;
+ assertNoLocks();
+ }
+
+ public void testRepeatableReadWithNull() throws Exception
+ {
+ assert cache.getNode(AB) == null;
+
+ tm.begin();
+ assert cache.getNode(AB) == null;
+ Transaction reader = tm.suspend();
+
+ tm.begin();
+ cache.put(AB, "k", "v");
+ assert cache.getNode(AB) != null;
+ assert "v".equals(cache.get(AB, "k"));
+ tm.commit();
+
+ assert cache.getNode(AB) != null;
+ assert "v".equals(cache.get(AB, "k"));
+
+ tm.resume(reader);
+ assert cache.getNode(AB) == null;
+ assert cache.get(AB, "k") == null;
+ tm.commit();
+
+ assert cache.getNode(AB) != null;
+ assert "v".equals(cache.get(AB, "k"));
+ assertNoLocks();
+ }
+}
Deleted: core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/RepeatableReadNoWriteSkewLockTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/RepeatableReadNoWriteSkewLockTest.java 2008-07-03 14:05:31 UTC (rev 6160)
+++ core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/RepeatableReadNoWriteSkewLockTest.java 2008-07-03 14:40:16 UTC (rev 6161)
@@ -1,12 +0,0 @@
-package org.jboss.cache.api.mvcc.repeatable_read;
-
-import org.testng.annotations.Test;
-
-@Test(groups = {"functional", "mvcc"})
-public class RepeatableReadNoWriteSkewLockTest extends RepeatableReadTestBase
-{
- public RepeatableReadNoWriteSkewLockTest()
- {
- allowWriteSkew = false;
- }
-}
Deleted: core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/RepeatableReadWriteSkewLockTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/RepeatableReadWriteSkewLockTest.java 2008-07-03 14:05:31 UTC (rev 6160)
+++ core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/RepeatableReadWriteSkewLockTest.java 2008-07-03 14:40:16 UTC (rev 6161)
@@ -1,12 +0,0 @@
-package org.jboss.cache.api.mvcc.repeatable_read;
-
-import org.testng.annotations.Test;
-
-@Test(groups = {"functional", "mvcc"})
-public class RepeatableReadWriteSkewLockTest extends RepeatableReadTestBase
-{
- public RepeatableReadWriteSkewLockTest()
- {
- allowWriteSkew = true;
- }
-}
Added: core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/WriteSkewTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/WriteSkewTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/api/mvcc/repeatable_read/WriteSkewTest.java 2008-07-03 14:40:16 UTC (rev 6161)
@@ -0,0 +1,199 @@
+package org.jboss.cache.api.mvcc.repeatable_read;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.api.mvcc.LockAssert;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.config.Configuration.NodeLockingScheme;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.invocation.InvocationContextContainer;
+import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.lock.LockManager;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import org.jboss.cache.util.TestingUtil;
+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.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+
+@Test(groups = {"functional", "mvcc"})
+public class WriteSkewTest
+{
+ protected Cache<String, String> cache;
+ protected TransactionManager tm;
+ protected Fqn A = Fqn.fromString("/a");
+ protected Fqn AB = Fqn.fromString("/a/b");
+ protected Fqn ABC = Fqn.fromString("/a/b/c");
+ protected Fqn ABCD = Fqn.fromString("/a/b/c/d");
+ protected LockManager lockManager;
+ protected InvocationContextContainer icc;
+ protected boolean repeatableRead = true;
+
+ @BeforeMethod
+ public void setUp()
+ {
+ cache = new DefaultCacheFactory<String, String>().createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.LOCAL), false);
+ cache.getConfiguration().setNodeLockingScheme(NodeLockingScheme.MVCC);
+ cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ cache.getConfiguration().setIsolationLevel(repeatableRead ? IsolationLevel.REPEATABLE_READ : IsolationLevel.READ_COMMITTED);
+ // reduce lock acquisition timeout so this doesn't take forever to run
+ cache.getConfiguration().setLockAcquisitionTimeout(200); // 200 ms
+ }
+
+ @AfterMethod
+ public void tearDown()
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ private void postStart()
+ {
+ lockManager = TestingUtil.extractComponentRegistry(cache).getComponent(LockManager.class);
+ icc = TestingUtil.extractComponentRegistry(cache).getComponent(InvocationContextContainer.class);
+ tm = TestingUtil.extractComponentRegistry(cache).getComponent(TransactionManager.class);
+ }
+
+ protected void assertNoLocks()
+ {
+ LockAssert.assertNoLocks(lockManager, icc);
+ }
+
+ public void testAllowWriteSkew() throws Exception
+ {
+ cache.getConfiguration().setAllowWriteSkew(true);
+ cache.start();
+ postStart();
+ doTest(true);
+ }
+
+ public void testDontAllowWriteSkew() throws Exception
+ {
+ cache.getConfiguration().setAllowWriteSkew(false);
+ cache.start();
+ postStart();
+ doTest(false);
+ }
+
+ private void doTest(final boolean allowWriteSkew) throws Exception
+ {
+ if (repeatableRead)
+ {
+ cache.put(AB, "k", "v");
+ final Set<Exception> w1exceptions = new HashSet<Exception>();
+ final Set<Exception> w2exceptions = new HashSet<Exception>();
+ final CountDownLatch w1Signal = new CountDownLatch(1);
+ final CountDownLatch w2Signal = new CountDownLatch(1);
+ final CountDownLatch threadSignal = new CountDownLatch(2);
+
+ Thread w1 = new Thread("Writer-1")
+ {
+ public void run()
+ {
+ boolean didCoundDown = false;
+ try
+ {
+ tm.begin();
+ assert "v".equals(cache.get(AB, "k"));
+ threadSignal.countDown();
+ didCoundDown = true;
+ w1Signal.await();
+ cache.put(AB, "k", "v2");
+ tm.commit();
+ }
+ catch (Exception e)
+ {
+ w1exceptions.add(e);
+ }
+ finally
+ {
+ if (!didCoundDown) threadSignal.countDown();
+ }
+ }
+ };
+
+ Thread w2 = new Thread("Writer-2")
+ {
+ public void run()
+ {
+ boolean didCoundDown = false;
+ try
+ {
+ tm.begin();
+ assert "v".equals(cache.get(AB, "k"));
+ threadSignal.countDown();
+ didCoundDown = true;
+ w2Signal.await();
+ cache.put(AB, "k", "v3");
+ tm.commit();
+ }
+ catch (Exception e)
+ {
+ w2exceptions.add(e);
+ // the exception will be thrown when doing a cache.put(). We should make sure we roll back the tx to release locks.
+ if (!allowWriteSkew)
+ {
+ try
+ {
+ tm.rollback();
+ }
+ catch (SystemException e1)
+ {
+ // do nothing.
+ }
+ }
+ }
+ finally
+ {
+ if (!didCoundDown) threadSignal.countDown();
+ }
+ }
+ };
+
+ w1.start();
+ w2.start();
+
+ threadSignal.await();
+ // now. both txs have read.
+ // let tx1 start writing
+ w1Signal.countDown();
+ w1.join();
+
+ w2Signal.countDown();
+ w2.join();
+
+ if (allowWriteSkew)
+ {
+ // should have no exceptions!!
+ throwExceptions(w1exceptions, w2exceptions);
+ assert w2exceptions.size() == 0;
+ assert w1exceptions.size() == 0;
+ assert "v3".equals(cache.get(AB, "k")) : "W2 should have overwritten W1's work!";
+ }
+ else
+ {
+ // there should be a single exception from w2.
+ assert w2exceptions.size() == 1;
+ throwExceptions(w1exceptions);
+ assert w1exceptions.size() == 0;
+ assert "v2".equals(cache.get(AB, "k")) : "W2 should NOT have overwritten W1's work!";
+ }
+
+ assertNoLocks();
+ }
+ }
+
+ private void throwExceptions(Collection<Exception>... exceptions) throws Exception
+ {
+ for (Collection<Exception> ce : exceptions)
+ {
+ for (Exception e : ce) throw e;
+ }
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/RemoveNodeCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/RemoveNodeCommandTest.java 2008-07-03 14:05:31 UTC (rev 6160)
+++ core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/RemoveNodeCommandTest.java 2008-07-03 14:40:16 UTC (rev 6161)
@@ -27,6 +27,8 @@
public void testNonExistentNode()
{
expect(container.peek(fqn)).andReturn(null);
+ // again
+ expect(container.peek(fqn)).andReturn(null);
control.replay();
assert Boolean.FALSE == command.perform(ctx) : "nonexistent node was not remove; false expected";
}
@@ -41,6 +43,8 @@
//check perform
expect(container.peek(fqn)).andReturn(nodes.adfNode);
+ // again
+ expect(container.peek(fqn)).andReturn(nodes.adfNode);
control.replay();
assert Boolean.TRUE == command.perform(ctx);
assert nodes.adfgNode.isDeleted();
@@ -64,6 +68,8 @@
nodes.adfNode.setVersion(dataVersion);
expect(container.peek(fqn)).andReturn(nodes.adfNode);
+ // again
+ expect(container.peek(fqn)).andReturn(nodes.adfNode);
control.replay();
assert Boolean.FALSE == command.perform(ctx);
assert nodes.adfgNode.isDeleted();
@@ -77,6 +83,8 @@
nodes.adfNode.setVersion(dataVersion);
expect(container.peek(fqn)).andReturn(nodes.adfNode);
+ // again
+ expect(container.peek(fqn)).andReturn(nodes.adfNode);
notifier.notifyNodeRemoved(fqn, true, nodes.adfNode.getDataDirect(), ctx);
notifier.notifyNodeRemoved(fqn, false, null, ctx);
control.replay();
16 years, 6 months
JBoss Cache SVN: r6160 - in searchable/trunk: src/main/java/org/jboss/cache/search and 5 other directories.
by jbosscache-commits@lists.jboss.org
Author: navssurtani
Date: 2008-07-03 10:05:31 -0400 (Thu, 03 Jul 2008)
New Revision: 6160
Added:
searchable/trunk/TODO.txt
searchable/trunk/src/main/java/org/jboss/cache/search/InvalidKeyException.java
searchable/trunk/src/main/java/org/jboss/cache/search/PojoTransactionContext.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCoreListener.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java
searchable/trunk/src/test/java/org/jboss/cache/search/helper/
searchable/trunk/src/test/java/org/jboss/cache/search/helper/IndexCleanUp.java
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java
searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
searchable/trunk/src/test/java/org/jboss/cache/search/TransformerTest.java
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/ClusteredCacheTest.java
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalCacheTest.java
searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java
searchable/trunk/src/test/java/org/jboss/cache/search/test/Person.java
searchable/trunk/src/test/resources/log4j.xml
Log:
Tried writing up POJO listener. Needs to be able to take out Fqn and Key from an Object when event.getSource() is called.
Added: searchable/trunk/TODO.txt
===================================================================
--- searchable/trunk/TODO.txt (rev 0)
+++ searchable/trunk/TODO.txt 2008-07-03 14:05:31 UTC (rev 6160)
@@ -0,0 +1,13 @@
+1 - Fix POJO cache listener.
+
+The class needs to be able to get the Fqn and Key from the object so that Lucene can be updated.
+
+2 - Lazy iterator.
+
+So that when a large amount of hits are there, they can be loaded when required.
+
+3 - Deal with Lucene Filters and Sorting.
+
+4 - Non-string keys.
+
+Think.
\ No newline at end of file
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java 2008-07-03 13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityId.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -74,7 +74,7 @@
*/
- public String getDocumentId()
+ public String getDocumentId() throws InvalidKeyException
{
if (key == null || fqn == null)
{
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java 2008-07-03 13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheEntityLoader.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -1,6 +1,8 @@
package org.jboss.cache.search;
import org.jboss.cache.Cache;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import java.util.List;
import java.util.ArrayList;
@@ -12,7 +14,8 @@
*/
public class CacheEntityLoader
{
- Cache cache;
+ Cache cache;
+ private static final Log log = LogFactory.getLog(CacheEntityLoader.class);
public CacheEntityLoader(Cache cache)
{
@@ -32,6 +35,7 @@
for (CacheEntityId id: ids)
{
retVal.add( cache.get(id.getFqn(), id.getKey()) );
+ if(log.isTraceEnabled()) log.trace("Created list of return values. Size is " + retVal.size() );
}
return retVal;
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-07-03 13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -35,7 +35,8 @@
/**
* Implementation class of the CacheQuery interface.
- * <p />
+ * <p/>
+ *
* @author Navin Surtani - navin(a)surtani.org
*/
public class CacheQueryImpl implements CacheQuery
@@ -123,8 +124,6 @@
}
-
-
private void closeSearcher(Searcher searcher, ReaderProvider readerProvider)
{
Set<IndexReader> indexReaders = getIndexReaders(searcher);
@@ -188,7 +187,7 @@
//TODO How do we deal with this if the parameter is too high.
}
-
+
public QueryResultIterator iterator() throws HibernateException
{
List<CacheEntityId> ids = null;
@@ -248,10 +247,12 @@
try
{
hits = getHits(searcher);
+ if(log.isTraceEnabled()) log.trace("Number of hits are " + hits.length());
int first = first();
int max = max(first, hits);
int size = max - first + 1 < 0 ? 0 : max - first + 1;
+
List<CacheEntityId> ids = new ArrayList<CacheEntityId>(size);
DocumentExtractor extractor = new DocumentExtractor(searchFactory, indexProjection);
@@ -291,17 +292,17 @@
private int max(int first, Hits hits)
{
return maxResults == null ?
- hits.length() - 1 :
- maxResults + first < hits.length() ?
- first + maxResults - 1 :
- hits.length() - 1;
+ hits.length() - 1 :
+ maxResults + first < hits.length() ?
+ first + maxResults - 1 :
+ hits.length() - 1;
}
private int first()
{
return firstResult != null ?
- firstResult :
- 0;
+ firstResult :
+ 0;
}
public void setMaxResults(int maxResults)
@@ -354,7 +355,9 @@
{
DocumentBuilder builder = builders.get(clazz);
if (builder == null)
+ {
throw new HibernateException("Not a mapped entity (don't forget to add @Indexed): " + clazz);
+ }
final DirectoryProvider[] directoryProviders = builder.getDirectoryProviderSelectionStrategy().getDirectoryProvidersForAllShards();
searcherSimilarity = checkSimilarity(searcherSimilarity, builder);
@@ -516,25 +519,25 @@
catch (IllegalAccessException e)
{
throw new SearchException("Unable to access @Key method: "
- + def.getImpl().getName() + "." + def.getKeyMethod().getName());
+ + def.getImpl().getName() + "." + def.getKeyMethod().getName());
}
catch (InvocationTargetException e)
{
throw new SearchException("Unable to access @Key method: "
- + def.getImpl().getName() + "." + def.getKeyMethod().getName());
+ + def.getImpl().getName() + "." + def.getKeyMethod().getName());
}
catch (ClassCastException e)
{
throw new SearchException("@Key method does not return FilterKey: "
- + def.getImpl().getName() + "." + def.getKeyMethod().getName());
+ + def.getImpl().getName() + "." + def.getKeyMethod().getName());
}
}
key.setImpl(def.getImpl());
}
Filter filter = def.isCache() ?
- searchFactory.getFilterCachingStrategy().getCachedFilter(key) :
- null;
+ searchFactory.getFilterCachingStrategy().getCachedFilter(key) :
+ null;
if (filter == null)
{
if (def.getFactoryMethod() != null)
@@ -546,17 +549,17 @@
catch (IllegalAccessException e)
{
throw new SearchException("Unable to access @Factory method: "
- + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
+ + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
}
catch (InvocationTargetException e)
{
throw new SearchException("Unable to access @Factory method: "
- + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
+ + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
}
catch (ClassCastException e)
{
throw new SearchException("@Key method does not return a org.apache.lucene.search.Filter class: "
- + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
+ + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
}
}
else
@@ -568,11 +571,13 @@
catch (ClassCastException e)
{
throw new SearchException("@Key method does not return a org.apache.lucene.search.Filter class: "
- + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
+ + def.getImpl().getName() + "." + def.getFactoryMethod().getName());
}
}
if (def.isCache())
+ {
searchFactory.getFilterCachingStrategy().addCachedFilter(key, filter);
+ }
}
chainedFilter.addFilter(filter);
}
Added: searchable/trunk/src/main/java/org/jboss/cache/search/InvalidKeyException.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/InvalidKeyException.java (rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/InvalidKeyException.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -0,0 +1,28 @@
+package org.jboss.cache.search;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ */
+public class InvalidKeyException extends Exception
+{
+
+ public InvalidKeyException()
+ {
+ }
+
+ public InvalidKeyException(String s)
+ {
+ super(s);
+ }
+
+ public InvalidKeyException(String s, Throwable throwable)
+ {
+ super(s, throwable);
+ }
+
+ public InvalidKeyException(Throwable throwable)
+ {
+ super(throwable);
+ }
+
+}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java 2008-07-03 13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -63,10 +63,11 @@
*/
public void registerSynchronization(Synchronization synchronization)
{
+ if (synchronization == null) throw new NullPointerException("Synchronization passed in is null!");
+
Transaction transaction = event.getTransaction();
if (transaction != null)
{
- if (synchronization == null) throw new NullPointerException("Synchronization passed in is null!");
try
{
transaction.registerSynchronization(synchronization);
Added: searchable/trunk/src/main/java/org/jboss/cache/search/PojoTransactionContext.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/PojoTransactionContext.java (rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/PojoTransactionContext.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -0,0 +1,50 @@
+//package org.jboss.cache.search;
+//
+//import org.hibernate.search.transaction.TransactionContext;
+//import org.jboss.cache.pojo.notification.event.Event;
+//
+//import javax.transaction.Synchronization;
+//import javax.transaction.Transaction;
+//
+///**
+// * @author Navin Surtani - navin(a)surtani.org
+// */
+//public class PojoTransactionContext implements TransactionContext
+//{
+// Event event;
+//
+// public PojoTransactionContext(Event event)
+// {
+// if (event == null) throw new NullPointerException("event cannot be null");
+// this.event = event;
+//
+// }
+// public boolean isTxInProgress()
+// {
+// return (event.getContext().getTransaction() != null);
+//
+// }
+//
+// public Object getTransactionIdentifier()
+// {
+// return event.getContext().getTransaction();
+// }
+//
+// public void registerSynchronization(Synchronization synchronization)
+// {
+// Transaction transaction = event.getContext().getTransaction();
+//
+// if (transaction != null)
+// {
+//
+// try
+// {
+// transaction.registerSynchronization(synchronization);
+// }
+// catch (Exception e)
+// {
+// throw new RuntimeException(e);
+// }
+// }
+// }
+//}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java 2008-07-03 13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -1,10 +1,10 @@
package org.jboss.cache.search;
-import org.hibernate.cfg.Configuration;
import org.hibernate.search.impl.SearchFactoryImpl;
import org.hibernate.search.cfg.Cfg;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheStatus;
+import org.jboss.cache.pojo.PojoCache;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -51,20 +51,20 @@
if (log.isWarnEnabled()) log.warn("You haven't passed in any classes to index. Is this an error?");
}
- // step 1: create hibernate search searchImpl
+ // step 1: create hibernate search searchFactory
Cfg cfg = new SearchableCacheCfgImpl(classes, properties);
// set classes in the cfg
- SearchFactoryImpl searchImpl = new SearchFactoryImpl(cfg);
+ SearchFactoryImpl searchFactory = new SearchFactoryImpl(cfg);
+ boolean isPojoCache = c instanceof PojoCache;
-
// Step 2: Add cache listener to listen for events happening in the cache.
- SearchableListener listener = new SearchableListener(searchImpl);
+ SearchableListener listener = isPojoCache ? new SearchablePojoListener(searchFactory) : new SearchableCoreListener(searchFactory);
c.addCacheListener(listener);
// step 3: create the searchable cache delegate.
- SearchableCache sc = new SearchableCacheImpl(c, searchImpl);
+ SearchableCache sc = new SearchableCacheImpl(c, searchFactory);
return sc;
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-07-03 13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -27,11 +27,9 @@
// this is the ACTUAL cache. that does all the work.
private Cache<K, V> cache;
- //TODO: Will this barf because of searchFactory being null or does it not matter to us?
private SearchFactoryImpl searchFactory;
- //TODO: javadoc!!
public SearchableCacheImpl(Cache<K, V> cache, SearchFactoryImpl searchFactory)
{
if (cache == null) throw new NullPointerException("Blah");
@@ -43,7 +41,7 @@
/**
* Creates a CacheQuery object from a given Lucene Query.
*
- * @param luceneQuery
+ * @param luceneQuery - for lucene
* @return CacheQuery object
*/
@@ -55,8 +53,8 @@
/**
* Creates a CacheQuery object from a Lucene Query and a class array.
*
- * @param luceneQuery
- * @param classes
+ * @param luceneQuery - for lucene
+ * @param classes array
* @return CacheQuery object.
*/
Added: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCoreListener.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCoreListener.java (rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCoreListener.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -0,0 +1,134 @@
+package org.jboss.cache.search;
+
+import org.hibernate.search.impl.SearchFactoryImpl;
+import org.hibernate.search.transaction.TransactionContext;
+import org.hibernate.search.backend.Work;
+import org.hibernate.search.backend.WorkType;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.NodeModified;
+import org.jboss.cache.notifications.event.NodeModifiedEvent;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Map;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ *
+ * Listener class for changes made to the cache. This listener makes changes if it is a org.jboss.cache being used.
+ */
+@CacheListener
+public class SearchableCoreListener extends SearchableListener
+{
+ private SearchFactoryImpl searchFactory;
+ private static final Log log = LogFactory.getLog(SearchableCoreListener.class);
+
+ public SearchableCoreListener(SearchFactoryImpl searchFactory)
+ {
+
+ this.searchFactory = searchFactory;
+ }
+
+ /**
+ * Takes in a NodeModifiedEvent and updates the Lucene indexes using methods on the NodeModifiedEvent class.
+ *
+ * @param event that has occured - or a node that has been changed. {@link org.jboss.cache.notifications.event.NodeModifiedEvent}
+ * @throws InvalidKeyException if an invalid key is passed in.
+ */
+
+ @NodeModified
+ public void updateLuceneIndexes(NodeModifiedEvent event) throws InvalidKeyException
+ {
+
+ if (log.isTraceEnabled()) log.trace("You have entered the SearchableListener");
+ if (!event.isPre())
+ {
+ if (log.isTraceEnabled()) log.trace("event.isPre is false. Going to start updating indexes");
+ switch (event.getModificationType())
+ {
+ case PUT_MAP:
+ case PUT_DATA:
+ if (log.isTraceEnabled()) log.trace("put() has been called on cache. Going to handle the data.");
+ handlePutData(event, searchFactory);
+ break;
+ case REMOVE_DATA:
+ handleDeleteData(event, searchFactory);
+ break;
+ }
+ }
+ }
+
+ /**
+ * If the modification type is PUT_MAP or PUT_DATA then this method will be called.
+ * Takes in the event as a parameter
+ *
+ * @param event that has occured - or a node that has been changed. {@link org.jboss.cache.notifications.event.NodeModifiedEvent}
+ * @param searchFactory - a SearchFactoryImpl instance.
+ * @throws InvalidKeyException
+ */
+
+
+ protected void handlePutData(NodeModifiedEvent event, SearchFactoryImpl searchFactory) throws InvalidKeyException
+ {
+ Map dataMap = event.getData();
+ if (log.isTraceEnabled()) log.trace("Called event.getData() and saved to a Map");
+
+
+ TransactionContext ctx = new NodeModifiedTransactionContext(event);
+
+ for (Object key : dataMap.keySet())
+ {
+ CacheEntityId cacheEntityId = new CacheEntityId(event.getFqn(), (String) key);
+ if (log.isTraceEnabled()) log.trace("Created new CacheEntityId");
+
+ String fqnString = cacheEntityId.getFqn().toString(); // Vars for logging
+ String keyString = (String) key;
+
+
+ searchFactory.getWorker().performWork(new Work(dataMap.get(key), cacheEntityId.getDocumentId(), WorkType.DELETE), ctx);
+ searchFactory.getWorker().performWork(new Work(dataMap.get(key), cacheEntityId.getDocumentId(), WorkType.ADD), ctx);
+
+
+ if (log.isTraceEnabled())
+ {
+ log.debug("Added your object into Lucene with Fqn " + fqnString + " and key " + keyString);
+ }
+
+
+ }
+
+ }
+
+
+
+ /**
+ * If the modification type is DELETE_DATA then this method will be called.
+ * Takes in the event as a parameter
+ *
+ * @param event that has occured - or a node that has been changed. {@link org.jboss.cache.notifications.event.NodeModifiedEvent}
+ * @param searchFactory - a SearchFactoryImpl instance.
+ * @throws InvalidKeyException
+ */
+ protected void handleDeleteData(NodeModifiedEvent event, SearchFactoryImpl searchFactory) throws InvalidKeyException
+ {
+ Map dataMap = event.getData();
+
+ TransactionContext ctx = new NodeModifiedTransactionContext(event);
+
+ for (Object key : dataMap.keySet())
+ {
+ CacheEntityId cacheEntityId = new CacheEntityId(event.getFqn(), (String) key);
+
+ String fqnString = cacheEntityId.getFqn().toString();
+ String keyString = (String) key;
+
+
+ searchFactory.getWorker().performWork(new Work(dataMap.get(key), cacheEntityId.getDocumentId(), WorkType.DELETE), ctx);
+ if (log.isTraceEnabled()) log.trace("Deleted your object from Lucene with Fqn " + fqnString + " and key " + keyString);
+
+
+ }
+
+ }
+
+}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-07-03 13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -7,92 +7,23 @@
import org.jboss.cache.notifications.annotation.CacheListener;
import org.jboss.cache.notifications.annotation.NodeModified;
import org.jboss.cache.notifications.event.NodeModifiedEvent;
+import org.jboss.cache.Fqn;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import java.util.Map;
/**
* @author Navin Surtani - navin(a)surtani.org
* <p/>
- * Class that listens for changes made to the cache so that the Lucene indexes can be updated.
+ * Abstract class that listens for changes made to the cache so that the Lucene indexes can be updated.
*/
@CacheListener
-public class SearchableListener
+public abstract class SearchableListener
{
- private SearchFactoryImpl searchFactory;
+ private static final Log log = LogFactory.getLog(SearchableListener.class);
- public SearchableListener(SearchFactoryImpl searchFactory)
- {
- this.searchFactory = searchFactory;
- }
+
- /**
- * Takes in a NodeModifiedEvent and updates the Lucene indexes using methods on the NodeModifiedEvent class.
- *
- * @param event that has occured - or a node that has been changed. {@link org.jboss.cache.notifications.event.NodeModifiedEvent}
- */
-
-
- @NodeModified
- public void updateLuceneIndexes(NodeModifiedEvent event)
- {
- if (!event.isPre())
- {
- switch (event.getModificationType())
- {
- case PUT_MAP:
- case PUT_DATA:
- handlePutData(event);
- break;
- case REMOVE_DATA:
- handleDeleteData(event);
- break;
- }
- }
- }
-
- /**
- * If the modification type is PUT_MAP or PUT_DATA then this method will be called.
- * Takes in the event as a parameter
- *
- * @param event that has occured - or a node that has been changed. {@link org.jboss.cache.notifications.event.NodeModifiedEvent}
- */
- void handlePutData(NodeModifiedEvent event)
- {
- Map dataMap = event.getData();
-
- TransactionContext ctx = new NodeModifiedTransactionContext(event);
-
- for (Object key : dataMap.keySet())
- {
- CacheEntityId cacheEntityId = new CacheEntityId(event.getFqn(), (String) key);
-
- searchFactory.getWorker().performWork(new Work(dataMap.get(key), cacheEntityId.getDocumentId(), WorkType.DELETE), ctx);
- searchFactory.getWorker().performWork(new Work(dataMap.get(key), cacheEntityId.getDocumentId(), WorkType.ADD), ctx);
- }
-
- }
-
- /**
- * If the modification type is DELETE_DATA then this method will be called.
- * Takes in the event as a parameter
- *
- * @param event that has occured - or a node that has been changed. {@link org.jboss.cache.notifications.event.NodeModifiedEvent}
- */
- void handleDeleteData(NodeModifiedEvent event)
- {
- Map dataMap = event.getData();
-
- TransactionContext ctx = new NodeModifiedTransactionContext(event);
-
- for (Object key : dataMap.keySet())
- {
- CacheEntityId cacheEntityId = new CacheEntityId(event.getFqn(), (String) key);
-
- searchFactory.getWorker().performWork(new Work(dataMap.get(key), cacheEntityId.getDocumentId(), WorkType.DELETE), ctx);
-
- }
-
- }
-
}
Added: searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java (rev 0)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchablePojoListener.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -0,0 +1,72 @@
+//package org.jboss.cache.search;
+//
+//import org.hibernate.search.impl.SearchFactoryImpl;
+//import org.jboss.cache.notifications.event.NodeModifiedEvent;
+//import org.jboss.cache.pojo.notification.annotation.*;
+//import org.jboss.cache.pojo.notification.event.AttachedEvent;
+//import org.apache.commons.logging.Log;
+//import org.apache.commons.logging.LogFactory;
+//
+//import javax.transaction.Transaction;
+//
+///**
+// * @author Navin Surtani - navin(a)surtani.org
+// */
+//
+//@PojoCacheListener
+//public class SearchablePojoListener extends SearchableListener
+//{
+// private SearchFactoryImpl searchFactory;
+// private static final Log log = LogFactory.getLog(SearchablePojoListener.class);
+//
+// public SearchablePojoListener(SearchFactoryImpl searchFactory)
+// {
+// this.searchFactory = searchFactory;
+// }
+//
+// /**
+// * Takes in a NodeModifiedEvent and updates the Lucene indexes using methods on the NodeModifiedEvent class.
+// *
+// * @param event that has occured - or a node that has been changed. {@link org.jboss.cache.notifications.event.NodeModifiedEvent}
+// * @throws InvalidKeyException if an invalid key is given.
+// */
+//
+// @Attached
+// public void handleAttach(AttachedEvent event)
+// {
+// Object added = event.getSource();
+//
+//
+//
+// }
+//
+//
+// @Detached
+// @FieldModified
+// @ListModified
+// @ArrayModified
+// @SetModified
+// @MapModified
+// public void updateLuceneIndexes(NodeModifiedEvent event) throws InvalidKeyException
+// {
+//
+// if (log.isTraceEnabled()) log.trace("You have entered the SearchableListener");
+// if (!event.isPre())
+// {
+// if (log.isTraceEnabled()) log.trace("event.isPre is false. Going to start updating indexes");
+// switch (event.getModificationType())
+// {
+// case PUT_MAP:
+// case PUT_DATA:
+// if (log.isTraceEnabled()) log.trace("put() has been called on cache. Going to handle the data.");
+// handlePutData(event, searchFactory);
+// break;
+// case REMOVE_DATA:
+// handleDeleteData(event, searchFactory);
+// break;
+// }
+// }
+// }
+//
+//
+//}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-07-03 13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -72,15 +72,23 @@
* Generates the documentId from an Fqn, key combination.
*
*
- * @param fqn
- * @param key
+ * @param fqn - standard call Fqn.fromString()
+ * @param key - cannot be an object.
* @return documentId String to be given to Lucene.
* @throws InvalidFqnException
*/
- public static String generateId(Fqn fqn, String key) throws InvalidFqnException
+ public static String generateId(Fqn fqn, String key) throws InvalidFqnException, InvalidKeyException
{
- if (key == null) throw new InvalidFqnException("Key passed in cannot be null!");
+ if (key == null) throw new NullPointerException("Key passed in cannot be null!");
+
+ if (key.startsWith("Fqn")) throw new InvalidKeyException("Invalid key passed in - 'Fqn[' is not allowed");
+ if (key.startsWith("]Key=[")) throw new InvalidKeyException("Invalid key passed in - ']Key=[' is not allowed");
+
+ if (fqn == null) throw new NullPointerException("Fqn cannot be null");
+
+ if(fqn.toString().startsWith("/Fqn")) throw new InvalidFqnException("Invalid Fqn passed in.");
+ if (fqn.toString().startsWith("/]Key")) throw new InvalidFqnException("Invalid Fqn passed in.");
StringBuilder sb = new StringBuilder();
sb.append("Fqn=[");
Modified: searchable/trunk/src/test/java/org/jboss/cache/search/TransformerTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/TransformerTest.java 2008-07-03 13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/TransformerTest.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -17,7 +17,7 @@
* Tests the generateId method.
*/
- public void testGenerateId()
+ public void testGenerateId() throws InvalidKeyException
{
Fqn fqn = Fqn.fromString("/a/b/c");
@@ -67,43 +67,43 @@
}
@Test(expectedExceptions = InvalidFqnException.class)
- public void testGenerateIdWithHackedString()
+ public void testGenerateIdWithHackedString() throws InvalidKeyException
{
Transformer.generateId(Fqn.fromString("/Fqn=[/a/b/c"), "x");
}
@Test(expectedExceptions = InvalidFqnException.class)
- public void testGenerateIdWithHackedFqn()
+ public void testGenerateIdWithHackedFqn() throws InvalidKeyException
{
Transformer.generateId(Fqn.fromString("/Fqn=[/a/b/c"), "x");
}
@Test(expectedExceptions = InvalidFqnException.class)
- public void testGenerateIdWithHackedFqn2()
+ public void testGenerateIdWithHackedFqn2() throws InvalidKeyException
{
Transformer.generateId(Fqn.fromString("/]Key=[/a/b/c"), "x");
}
- @Test(expectedExceptions = InvalidFqnException.class)
- public void testGenerateIdWithHackedKey()
+ @Test(expectedExceptions = InvalidKeyException.class)
+ public void testGenerateIdWithHackedKey() throws InvalidKeyException
{
Transformer.generateId(Fqn.fromString("/a/b/c"), "]Key=[");
}
- @Test(expectedExceptions = InvalidFqnException.class)
- public void testGenerateIdWithHackedKey2()
+ @Test(expectedExceptions = InvalidKeyException.class)
+ public void testGenerateIdWithHackedKey2() throws InvalidKeyException
{
Transformer.generateId(Fqn.fromString("/a/b/c"), "Fqn=[");
}
- @Test(expectedExceptions = InvalidFqnException.class)
- public void testGenerateIdWithNullKey()
+ @Test(expectedExceptions = NullPointerException.class)
+ public void testGenerateIdWithNullKey() throws InvalidKeyException
{
Transformer.generateId(Fqn.fromString("/a/b/c"), null);
}
- @Test(expectedExceptions = InvalidFqnException.class)
- public void testGenerateIdWithNullFqn()
+ @Test(expectedExceptions = NullPointerException.class)
+ public void testGenerateIdWithNullFqn() throws InvalidKeyException
{
Transformer.generateId(null, "x");
}
Modified: searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/ClusteredCacheTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/ClusteredCacheTest.java 2008-07-03 13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/ClusteredCacheTest.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -4,12 +4,16 @@
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Query;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Cache;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Configuration;
import org.jboss.cache.search.CacheQuery;
import org.jboss.cache.search.SearchableCache;
import org.jboss.cache.search.SearchableCacheFactory;
+import org.jboss.cache.search.helper.IndexCleanUp;
import org.jboss.cache.search.test.Person;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -33,34 +37,66 @@
Query luceneQuery;
CacheQuery cacheQuery;
List found;
+ String key1 = "Navin";
+ String key2 = "BigGoat";
+ String key3 = "MiniGoat";
+ private static final Log log = LogFactory.getLog(Person.class);
+
@BeforeMethod
- public void setUp()
+ public void setUp() throws CloneNotSupportedException
{
- cache1 = new DefaultCacheFactory().createCache();
+ Configuration cacheCfg = new Configuration();
+ cacheCfg.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ cacheCfg.setFetchInMemoryState(false);
+ cache1 = new DefaultCacheFactory().createCache(cacheCfg.clone());
searchableCache1 = new SearchableCacheFactory().createSearchableCache(cache1, Person.class);
- cache2 = new DefaultCacheFactory().createCache();
+ cache2 = new DefaultCacheFactory().createCache(cacheCfg.clone());
searchableCache2 = new SearchableCacheFactory().createSearchableCache(cache2, Person.class);
+ // wait until both caches are started and can see each other on the network.
+ long giveUpTime = System.currentTimeMillis() + (60 * 1000); // give up after 1 minute of waiting
+ boolean wait = true;
+ while (wait && System.currentTimeMillis() < giveUpTime)
+ {
+ wait = !((cache1.getMembers().size() == 2) && (cache2.getMembers().size() == 2));
+ // spin-lock
+ try
+ {
+ Thread.sleep(100);
+ }
+ catch (InterruptedException e)
+ {
+ // do nothing
+ }
+ }
+
+ if (wait)
+ {
+ // we still haven't got the cache views we want!!
+ throw new RuntimeException("Unable to initialise cluster!");
+ }
+
+
person1 = new Person();
person1.setName("Navin Surtani");
person1.setBlurb("Likes playing WoW");
person2 = new Person();
person2.setName("BigGoat");
- person2.setName("Eats grass");
+ person2.setBlurb("Eats grass");
person3 = new Person();
person3.setName("MiniGoat");
- person3.setBlurb("Makes cheese");
+ person3.setBlurb("Eats cheese");
//Put the 3 created objects in the searchableCache1.
- searchableCache1.put(Fqn.fromString("/a/b/c"), "Navin", person1);
- searchableCache1.put(Fqn.fromString("/a/b/d"), "BigGoat", person2);
- searchableCache1.put(Fqn.fromString("/a/b/c"), "MiniGoat", person3);
+ searchableCache1.put(Fqn.fromString("/a/b/c"), key1, person1);
+ searchableCache1.put(Fqn.fromString("/a/b/d"), key2, person2);
+ searchableCache1.put(Fqn.fromString("/a/b/c"), key3, person3);
}
@@ -71,24 +107,45 @@
if (searchableCache1 != null) searchableCache1.stop();
if (searchableCache2 != null) searchableCache2.stop();
+ IndexCleanUp.cleanUpIndexes();
+
}
public void testSimple() throws ParseException
{
- queryParser = new QueryParser("field", new StandardAnalyzer());
+ queryParser = new QueryParser("blurb", new StandardAnalyzer());
luceneQuery = queryParser.parse("playing");
cacheQuery = searchableCache2.createQuery(luceneQuery);
found = cacheQuery.list();
assert found.size() == 1;
+
+ if(found.get(0) == null)
+ {
+ if(log.isTraceEnabled()) log.warn("found.get(0) is null");
+ Person p1 = (Person) searchableCache2.get("/a/b/c", key1);
+ http://wiki.jboss.org/wiki/JBossCacheSearchable
+ if(p1 == null)
+ {
+ if(log.isTraceEnabled()) log.warn("Person p1 is null in sc2 and cannot actually see the data of person1 in sc1");
+ }
+
+ else
+ {
+ if(log.isTraceEnabled()) log.trace("p1 name is " + p1.getName());
+
+ }
+ }
+
+
assert found.get(0).equals(person1);
}
public void testModified() throws ParseException
{
- queryParser = new QueryParser("field", new StandardAnalyzer());
+ queryParser = new QueryParser("blurb", new StandardAnalyzer());
luceneQuery = queryParser.parse("playing");
cacheQuery = searchableCache2.createQuery(luceneQuery);
@@ -101,8 +158,8 @@
searchableCache1.put(Fqn.fromString("/a/b/c/"), "Navin", person1);
- queryParser = new QueryParser("field", new StandardAnalyzer());
- luceneQuery = queryParser.parse("playing");
+ queryParser = new QueryParser("blurb", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("pizza");
cacheQuery = searchableCache2.createQuery(luceneQuery);
found = cacheQuery.list();
@@ -113,21 +170,26 @@
public void testAdded() throws ParseException
{
- luceneQuery = queryParser.parse("Goat");
+ queryParser = new QueryParser("blurb", new StandardAnalyzer());
+
+ luceneQuery = queryParser.parse("eats");
cacheQuery = searchableCache2.createQuery(luceneQuery);
found = cacheQuery.list();
+ System.out.println("found.size() is " + found.size());
+
assert found.size() == 2 : "Size of list should be 2";
assert found.contains(person2);
assert found.contains(person3);
assert !found.contains(person4) : "This should not contain object person4";
- person4.setName("MightyGoat");
+ person4 = new Person();
+ person4.setName("Mighty Goat");
person4.setBlurb("Also eats grass");
searchableCache1.put(Fqn.fromString("/r/a/m/"), "Ram", person4);
- luceneQuery = queryParser.parse("Goat");
+ luceneQuery = queryParser.parse("eats");
cacheQuery = searchableCache2.createQuery(luceneQuery);
found = cacheQuery.list();
@@ -139,7 +201,8 @@
public void testRemoved() throws ParseException
{
- luceneQuery = queryParser.parse("Goat");
+ queryParser = new QueryParser("blurb", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("eats");
cacheQuery = searchableCache2.createQuery(luceneQuery);
found = cacheQuery.list();
@@ -147,9 +210,10 @@
assert found.contains(person2);
assert found.contains(person3) : "This should still contain object person3";
- searchableCache1.remove(Fqn.fromString("/a/b/c/"), person3);
+ searchableCache1.remove(Fqn.fromString("/a/b/c/"), key3);
- luceneQuery = queryParser.parse("Goat");
+ queryParser = new QueryParser("blurb", new StandardAnalyzer());
+ luceneQuery = queryParser.parse("eats");
cacheQuery = searchableCache2.createQuery(luceneQuery);
found = cacheQuery.list();
Modified: searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalCacheTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalCacheTest.java 2008-07-03 13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalCacheTest.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -4,6 +4,8 @@
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Query;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Cache;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
@@ -11,12 +13,15 @@
import org.jboss.cache.search.QueryResultIterator;
import org.jboss.cache.search.SearchableCache;
import org.jboss.cache.search.SearchableCacheFactory;
+import org.jboss.cache.search.helper.IndexCleanUp;
import org.jboss.cache.search.test.Person;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.List;
+import java.util.Iterator;
+import java.io.File;
/**
* @author Navin Surtani - navin(a)surtani.org
@@ -30,10 +35,14 @@
Person person2;
Person person3;
Person person4;
+ Person person5;
QueryParser queryParser;
Query luceneQuery;
CacheQuery cacheQuery;
List found;
+ String key1 = "Navin";
+ String key2 = "BigGoat";
+ String key3 = "MiniGoat";
@BeforeMethod
public void setUp()
@@ -46,25 +55,29 @@
person1.setBlurb("Likes playing WoW");
person2 = new Person();
- person2.setName("BigGoat");
- person2.setName("Eats grass");
+ person2.setName("Big Goat");
+ person2.setBlurb("Eats grass");
person3 = new Person();
- person3.setName("MiniGoat");
- person3.setBlurb("Makes cheese");
+ person3.setName("Mini Goat");
+ person3.setBlurb("Eats cheese");
+ person5 = new Person();
+ person5.setName("Smelly Cat");
+ person5.setBlurb("Eats fish");
+
//Put the 3 created objects in the searchableCache.
+ searchableCache.put(Fqn.fromString("/a/b/c"), key1, person1);
+ searchableCache.put(Fqn.fromString("/a/b/d"), key2, person2);
+ searchableCache.put(Fqn.fromString("/a/b/c"), key3, person3);
- searchableCache.put(Fqn.fromString("/a/b/c"), "Navin", person1);
- searchableCache.put(Fqn.fromString("/a/b/d"), "BigGoat", person2);
- searchableCache.put(Fqn.fromString("/a/b/c"), "MiniGoat", person3);
-
}
@AfterMethod
public void tearDown()
{
if (searchableCache != null) searchableCache.stop();
+ IndexCleanUp.cleanUpIndexes();
}
public void testSimple() throws ParseException
@@ -87,21 +100,23 @@
QueryResultIterator found = cacheQuery.iterator();
- assert found.equals(person1);
+ assert found.isFirst();
+ assert found.isLast();
}
public void testMultipleResults() throws ParseException
{
+
queryParser = new QueryParser("name", new StandardAnalyzer());
- luceneQuery = queryParser.parse("Goat");
+ luceneQuery = queryParser.parse("goat");
cacheQuery = searchableCache.createQuery(luceneQuery);
found = cacheQuery.list();
assert found.size() == 2;
- assert !found.get(1).equals(person2);
- assert !found.get(0).equals(person3);
+ assert found.get(0) == person2;
+ assert found.get(1) == person3;
}
@@ -117,9 +132,9 @@
assert found.get(0).equals(person1);
person1.setBlurb("Likes pizza");
- searchableCache.put(Fqn.fromString("/a/b/c/"), "Navin", person1);
+ searchableCache.put(Fqn.fromString("/a/b/c/"), key1, person1);
- queryParser = new QueryParser("field", new StandardAnalyzer());
+ queryParser = new QueryParser("blurb", new StandardAnalyzer());
luceneQuery = queryParser.parse("pizza");
cacheQuery = searchableCache.createQuery(luceneQuery);
@@ -142,7 +157,8 @@
assert found.contains(person3);
assert !found.contains(person4) : "This should not contain object person4";
- person4.setName("MightyGoat");
+ person4 = new Person();
+ person4.setName("Mighty Goat");
person4.setBlurb("Also eats grass");
searchableCache.put(Fqn.fromString("/r/a/m/"), "Ram", person4);
@@ -169,7 +185,7 @@
assert found.contains(person2);
assert found.contains(person3) : "This should still contain object person3";
- searchableCache.remove(Fqn.fromString("/a/b/c/"), person3);
+ searchableCache.remove(Fqn.fromString("/a/b/c/"), key3);
luceneQuery = queryParser.parse("Goat");
cacheQuery = searchableCache.createQuery(luceneQuery);
Modified: searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java 2008-07-03 13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/blackbox/LocalPOJOCacheTest.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -1,182 +1,202 @@
-package org.jboss.cache.search.blackbox;
-
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.search.Query;
-import org.jboss.cache.Cache;
-import org.jboss.cache.DefaultCacheFactory;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.pojo.PojoCache;
-import org.jboss.cache.pojo.PojoCacheFactory;
-import org.jboss.cache.search.CacheQuery;
-import org.jboss.cache.search.SearchableCache;
-import org.jboss.cache.search.SearchableCacheFactory;
-import org.jboss.cache.search.test.Person;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import java.util.List;
-
-/**
- * Same as LocalCacheTest except that you will use a POJO Cache instead and use pojoCache.attach() ad pojoCache.detach()
- * instead of cache.put() and cache.remove().
- * <p/>
- *
- * @author Navin Surtani - navin(a)surtani.org
- */
-
-@Test(groups = "functional")
-public class LocalPOJOCacheTest
-{
- SearchableCache searchableCache;
- PojoCache pojo;
- Person person1;
- Person person2;
- Person person3;
- Person person4;
- QueryParser queryParser;
- Query luceneQuery;
- CacheQuery cacheQuery;
- List found;
-
-
- @BeforeMethod
- public void setUp()
- {
- Configuration config = new Configuration();
- PojoCache pojo = PojoCacheFactory.createCache(config, true);
- Cache coreCache = new DefaultCacheFactory().createCache();
- searchableCache = new SearchableCacheFactory().createSearchableCache(coreCache, Person.class);
-
- person1 = new Person();
- person1.setName("Navin Surtani");
- person1.setBlurb("Likes playing WoW");
-
- person2 = new Person();
- person2.setName("BigGoat");
- person2.setName("Eats grass");
-
- person3 = new Person();
- person3.setName("MiniGoat");
- person3.setBlurb("Makes cheese");
-
- pojo.attach(Fqn.fromString("/a/b/c"), person1);
- pojo.attach(Fqn.fromString("/a/b/d"), person2);
- pojo.attach(Fqn.fromString("/a/b/c"), person3);
-
-
- }
-
- @AfterMethod
- public void tearDown()
- {
-
- if (pojo != null) pojo.stop();
- if (searchableCache != null) searchableCache.stop();
- }
-
- public void testSimple() throws ParseException
- {
- queryParser = new QueryParser("field", new StandardAnalyzer());
- luceneQuery = queryParser.parse("playing");
- cacheQuery = searchableCache.createQuery(luceneQuery);
-
- found = cacheQuery.list();
-
- assert found.size() == 1;
- assert found.get(0).equals(person1);
- }
-
- public void testMultipleResults() throws ParseException
- {
- luceneQuery = queryParser.parse("Goat");
- cacheQuery = searchableCache.createQuery(luceneQuery);
- found = cacheQuery.list();
-
- assert found.size() == 2;
- assert !found.get(1).equals(person2);
- assert !found.get(0).equals(person3);
-
- }
-
- public void testModified() throws ParseException
- {
- queryParser = new QueryParser("field", new StandardAnalyzer());
- luceneQuery = queryParser.parse("playing");
- cacheQuery = searchableCache.createQuery(luceneQuery);
-
- found = cacheQuery.list();
-
- assert found.size() == 1;
- assert found.get(0).equals(person1);
-
- person1.setBlurb("Likes pizza");
-
- pojo.attach(Fqn.fromString("/a/b/c/"), person1);
-
- queryParser = new QueryParser("field", new StandardAnalyzer());
- luceneQuery = queryParser.parse("pizza");
- cacheQuery = searchableCache.createQuery(luceneQuery);
-
- found = cacheQuery.list();
-
- assert found.size() == 1;
- assert found.get(0).equals(person1);
- }
-
- public void testAdded() throws ParseException
- {
- luceneQuery = queryParser.parse("Goat");
- cacheQuery = searchableCache.createQuery(luceneQuery);
- found = cacheQuery.list();
-
- assert found.size() == 2 : "Size of list should be 2";
- assert found.contains(person2);
- assert found.contains(person3);
- assert !found.contains(person4) : "This should not contain object person4";
-
- person4.setName("MightyGoat");
- person4.setBlurb("Also eats grass");
-
- pojo.attach(Fqn.fromString("/r/a/m/"), person4);
-
- luceneQuery = queryParser.parse("Goat");
- cacheQuery = searchableCache.createQuery(luceneQuery);
- found = cacheQuery.list();
-
- assert found.size() == 3 : "Size of list should be 3";
- assert found.contains(person2);
- assert found.contains(person3);
- assert found.contains(person4) : "This should now contain object person4";
- }
-
- public void testRemoved() throws ParseException
- {
- luceneQuery = queryParser.parse("Goat");
- cacheQuery = searchableCache.createQuery(luceneQuery);
- found = cacheQuery.list();
-
- assert found.size() == 2;
- assert found.contains(person2);
- assert found.contains(person3) : "This should still contain object person3";
-
- pojo.detach(Fqn.fromString("/a/b/c/"));
-
- luceneQuery = queryParser.parse("Goat");
- cacheQuery = searchableCache.createQuery(luceneQuery);
- found = cacheQuery.list();
-
- assert found.size() == 1;
- assert found.contains(person2);
- assert !found.contains(person3) : "The search should not return person3";
-
-
- }
-
-}
-
-
-
+//package org.jboss.cache.search.blackbox;
+//
+//import org.apache.lucene.analysis.standard.StandardAnalyzer;
+//import org.apache.lucene.queryParser.ParseException;
+//import org.apache.lucene.queryParser.QueryParser;
+//import org.apache.lucene.search.Query;
+//import org.apache.commons.logging.Log;
+//import org.apache.commons.logging.LogFactory;
+//import org.jboss.cache.Cache;
+//import org.jboss.cache.DefaultCacheFactory;
+//import org.jboss.cache.Fqn;
+//import org.jboss.cache.config.Configuration;
+//import org.jboss.cache.pojo.PojoCache;
+//import org.jboss.cache.pojo.PojoCacheFactory;
+//import org.jboss.cache.search.CacheQuery;
+//import org.jboss.cache.search.SearchableCache;
+//import org.jboss.cache.search.SearchableCacheFactory;
+//import org.jboss.cache.search.helper.IndexCleanUp;
+//import org.jboss.cache.search.test.Person;
+//import org.testng.annotations.AfterMethod;
+//import org.testng.annotations.BeforeMethod;
+//import org.testng.annotations.Test;
+//
+//import java.util.List;
+//
+///**
+// * Same as LocalCacheTest except that you will use a POJO Cache instead and use pojoCache.attach() ad pojoCache.detach()
+// * instead of cache.put() and cache.remove().
+// * <p/>
+// *
+// * @author Navin Surtani - navin(a)surtani.org
+// */
+//
+//@Test(groups = "functional")
+//public class LocalPOJOCacheTest
+//{
+// SearchableCache searchableCache;
+// PojoCache pojo;
+// Person person1;
+// Person person2;
+// Person person3;
+// Person person4;
+// QueryParser queryParser;
+// Query luceneQuery;
+// CacheQuery cacheQuery;
+// List found;
+// private static final Log log = LogFactory.getLog(LocalPOJOCacheTest.class);
+//
+//
+// @BeforeMethod
+// public void setUp()
+// {
+// boolean toStart = false;
+// pojo = PojoCacheFactory.createCache(new Configuration(), toStart);
+// pojo.start(); // if toStart above is true, it will starts the cache automatically.
+// searchableCache = new SearchableCacheFactory().createSearchableCache(pojo.getCache(), Person.class);
+//
+// person1 = new Person();
+// person1.setName("Navin Surtani");
+// person1.setBlurb("Likes playing WoW");
+//
+// person2 = new Person();
+// person2.setName("BigGoat");
+// person2.setBlurb("Eats grass");
+//
+// person3 = new Person();
+// person3.setName("MiniGoat");
+// person3.setBlurb("Eats cheese");
+//
+// pojo.attach(Fqn.fromString("/a/b/c"), person1);
+// pojo.attach(Fqn.fromString("/a/b/d"), person2);
+// pojo.attach(Fqn.fromString("/a/b/c"), person3);
+//
+//
+// }
+//
+// @AfterMethod
+// public void tearDown()
+// {
+// if (pojo != null) pojo.stop();
+// if (searchableCache != null) searchableCache.stop();
+// IndexCleanUp.cleanUpIndexes();
+// }
+//
+// public void testSimple() throws ParseException
+// {
+// queryParser = new QueryParser("blurb", new StandardAnalyzer());
+// luceneQuery = queryParser.parse("playing");
+// cacheQuery = searchableCache.createQuery(luceneQuery);
+//
+// found = cacheQuery.list();
+//
+// assert found.size() == 1;
+//
+// if (found.get(0) == null)
+// {
+// if (log.isTraceEnabled()) log.warn("found.get(0) is null");
+//
+// }
+//
+// if (person1 == null)
+// {
+// if (log.isTraceEnabled()) log.warn("person1 is null");
+// }
+//
+// // assert person1.equals(found.get(0));
+// }
+//
+// public void testMultipleResults() throws ParseException
+// {
+// queryParser = new QueryParser("blurb", new StandardAnalyzer());
+// luceneQuery = queryParser.parse("Eats");
+// cacheQuery = searchableCache.createQuery(luceneQuery);
+// found = cacheQuery.list();
+//
+// assert found.size() == 2;
+// assert !found.get(1).equals(person2);
+// assert !found.get(0).equals(person3);
+//
+// }
+//
+// public void testModified() throws ParseException
+// {
+// queryParser = new QueryParser("blurb", new StandardAnalyzer());
+// luceneQuery = queryParser.parse("playing");
+// cacheQuery = searchableCache.createQuery(luceneQuery);
+//
+// found = cacheQuery.list();
+//
+// assert found.size() == 1;
+//// assert found.get(0).equals(person1);
+//
+// person1.setBlurb("Likes pizza");
+//
+// pojo.attach(Fqn.fromString("/a/b/c/"), person1);
+//
+// queryParser = new QueryParser("blurb", new StandardAnalyzer());
+// luceneQuery = queryParser.parse("pizza");
+// cacheQuery = searchableCache.createQuery(luceneQuery);
+//
+// found = cacheQuery.list();
+//
+// assert found.size() == 1;
+//// assert found.get(0).equals(person1);
+// }
+//
+// public void testAdded() throws ParseException
+// {
+// queryParser = new QueryParser("blurb", new StandardAnalyzer());
+// luceneQuery = queryParser.parse("eats");
+// cacheQuery = searchableCache.createQuery(luceneQuery);
+// found = cacheQuery.list();
+//
+// assert found.size() == 2 : "Size of list should be 2";
+// assert found.contains(person2);
+// assert found.contains(person3);
+// assert !found.contains(person4) : "This should not contain object person4";
+//
+// person4 = new Person();
+// person4.setName("MightyGoat");
+// person4.setBlurb("Also eats grass");
+//
+// pojo.attach(Fqn.fromString("/r/a/m/"), person4);
+//
+// luceneQuery = queryParser.parse("eats");
+// cacheQuery = searchableCache.createQuery(luceneQuery);
+// found = cacheQuery.list();
+//
+// assert found.size() == 3 : "Size of list should be 3";
+// assert found.contains(person2);
+// assert found.contains(person3);
+// assert found.contains(person4) : "This should now contain object person4";
+// }
+//
+// public void testRemoved() throws ParseException
+// {
+// queryParser = new QueryParser("blurb", new StandardAnalyzer());
+// luceneQuery = queryParser.parse("eats");
+// cacheQuery = searchableCache.createQuery(luceneQuery);
+// found = cacheQuery.list();
+//
+// assert found.size() == 2;
+// assert found.contains(person2);
+// assert found.contains(person3) : "This should still contain object person3";
+//
+// pojo.detach("/a/b/d");
+//
+// luceneQuery = queryParser.parse("eats");
+// cacheQuery = searchableCache.createQuery(luceneQuery);
+// found = cacheQuery.list();
+//
+// assert found.size() == 1;
+// assert found.contains(person2);
+// assert !found.contains(person3) : "The search should not return person3";
+//
+//
+// }
+//
+//}
+//
+//
+//
Added: searchable/trunk/src/test/java/org/jboss/cache/search/helper/IndexCleanUp.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/helper/IndexCleanUp.java (rev 0)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/helper/IndexCleanUp.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -0,0 +1,41 @@
+package org.jboss.cache.search.helper;
+
+import org.jboss.cache.search.test.Person;
+
+import java.io.File;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ */
+public class IndexCleanUp
+{
+
+ public static void cleanUpIndexes()
+ {
+ Class[] knownClasses = {Person.class};
+ for (Class c : knownClasses)
+ {
+ String dirName = c.getName();
+ File file = new File(dirName);
+ if (file.exists())
+ {
+ recursiveDelete(file);
+ }
+ }
+ }
+
+ private static void recursiveDelete(File f)
+ {
+ if (f.isDirectory())
+ {
+ File[] files = f.listFiles();
+ for (File file : files) recursiveDelete(file);
+ }
+ else
+ {
+ f.delete();
+ }
+ }
+
+}
+
Modified: searchable/trunk/src/test/java/org/jboss/cache/search/test/Person.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/test/Person.java 2008-07-03 13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/test/Person.java 2008-07-03 14:05:31 UTC (rev 6160)
@@ -1,19 +1,29 @@
package org.jboss.cache.search.test;
+
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.ProvidedId;
+import org.hibernate.search.annotations.Store;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.pojo.annotation.Replicable;
+import java.io.Serializable;
+
/**
* @author Navin Surtani - navin(a)surtani.org
*/
@ProvidedId
@Indexed
-public class Person
+public class Person implements Serializable
{
- @Field
+ private static final Log log = LogFactory.getLog(Person.class);
+
+
+ @Field (store = Store.YES)
private String name;
- @Field
+ @Field (store = Store.YES)
private String blurb;
public String getName()
@@ -35,4 +45,34 @@
{
this.blurb = blurb;
}
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Person person = (Person) o;
+
+ if (blurb != null ? !blurb.equals(person.blurb) : person.blurb != null) return false;
+ if (name != null ? !name.equals(person.name) : person.name != null) return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = (name != null ? name.hashCode() : 0);
+ result = 31 * result + (blurb != null ? blurb.hashCode() : 0);
+ return result;
+ }
+
+
+ public String toString()
+ {
+ return "Person{" +
+ "name='" + name + '\'' +
+ ", blurb='" + blurb + '\'' +
+ '}';
+ }
}
Modified: searchable/trunk/src/test/resources/log4j.xml
===================================================================
--- searchable/trunk/src/test/resources/log4j.xml 2008-07-03 13:20:58 UTC (rev 6159)
+++ searchable/trunk/src/test/resources/log4j.xml 2008-07-03 14:05:31 UTC (rev 6160)
@@ -63,11 +63,15 @@
<!-- ================ -->
<category name="org.jboss.cache.search">
- <priority value="WARN"/>
+ <priority value="TRACE"/>
</category>
+ <category name="org.hibernate.search">
+ <priority value="TRACE"/>
+ </category>
+
<category name="org.jboss.cache">
- <priority value="WARN"/>
+ <priority value="INFO"/>
</category>
<category name="org.jboss.cache.factories">
@@ -87,8 +91,8 @@
<!-- ======================= -->
<root>
- <!--<appender-ref ref="CONSOLE"/>-->
- <appender-ref ref="FILE"/>
+ <appender-ref ref="CONSOLE"/>
+ <!--<appender-ref ref="FILE"/>-->
</root>
</log4j:configuration>
16 years, 6 months
JBoss Cache SVN: r6159 - in core/trunk/src: main/java/org/jboss/cache/buddyreplication and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-03 09:20:58 -0400 (Thu, 03 Jul 2008)
New Revision: 6159
Modified:
core/trunk/src/main/java/org/jboss/cache/RegionManager.java
core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java
Log:
Fixed failing BR tests
Modified: core/trunk/src/main/java/org/jboss/cache/RegionManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2008-07-03 12:20:17 UTC (rev 6158)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManager.java 2008-07-03 13:20:58 UTC (rev 6159)
@@ -486,8 +486,9 @@
// We'll update this node with the state we receive
// need to obtain all necessary locks.
// needs to be a LOCAL call!
+ NodeSPI root = cache.getRoot();
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- subtreeRoot = cache.getRoot().addChild(buddyRoot);
+ subtreeRoot = root.addChild(buddyRoot);
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
}
rpcManager.fetchPartialState(sources, fqn, subtreeRoot.getFqn());
Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2008-07-03 12:20:17 UTC (rev 6158)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java 2008-07-03 13:20:58 UTC (rev 6159)
@@ -595,7 +595,7 @@
o = cache.getInvocationContext().getOptionOverrides();
o.setCacheModeLocal(true);
o.setSkipCacheStatusCheck(true);
- cache.getRoot().addChild(Fqn.fromElements(BUDDY_BACKUP_SUBTREE, newGroup.getGroupName()));
+ dataContainer.getRoot().addChild(Fqn.fromElements(BUDDY_BACKUP_SUBTREE, newGroup.getGroupName()));
}
else
{
@@ -1061,7 +1061,7 @@
// where N is a number.
Fqn<String> defunctRoot = buddyFqnTransformer.getDeadBackupRoot(dataOwner);
cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- Node defunctRootNode = cache.getRoot().addChild(defunctRoot);
+ Node defunctRootNode = dataContainer.getRoot().addChild(defunctRoot);
SortedSet childrenNames = new TreeSet(defunctRootNode.getChildrenNames()); // will be naturally sorted.
Integer childName = 1;
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java 2008-07-03 12:20:17 UTC (rev 6158)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/CommandAwareRpcDispatcher.java 2008-07-03 13:20:58 UTC (rev 6159)
@@ -146,6 +146,7 @@
protected Object executeCommand(ReplicableCommand cmd, Message req) throws Throwable
{
+ if (cmd == null) throw new NullPointerException("Unable to execute a null command! Message was " + req);
if (trace) log.trace("Executing command: " + cmd + " [sender=" + req.getSrc() + "]");
if (cmd instanceof VisitableCommand)
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java 2008-07-03 12:20:17 UTC (rev 6158)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyManagerTest.java 2008-07-03 13:20:58 UTC (rev 6159)
@@ -40,12 +40,12 @@
public void testConstruction1() throws Exception
{
String xmlConfig =
- " <buddyReplication enabled=\"true\" buddyPoolName=\"groupOne\">\n" +
- " <buddyLocator>\n" +
+ " <buddy enabled=\"true\" poolName=\"groupOne\">\n" +
+ " <locator>\n" +
" <properties>\n" +
" numBuddies = 3\n" +
" </properties>\n" +
- " </buddyLocator>\n" +
+ " </locator>\n" +
" </buddyReplication>";
BuddyReplicationConfig config = getBuddyReplicationConfig(xmlConfig);
BuddyManager mgr = new BuddyManager(config);
@@ -74,12 +74,12 @@
public void testConstruction2() throws Exception
{
String xmlConfig =
- " <buddyReplication enabled=\"true\" buddyPoolName=\"groupOne\">\n" +
- " <buddyLocator class=\"org.i.dont.exist.PhantomBuddyLocator\">\n" +
+ " <buddy enabled=\"true\" poolName=\"groupOne\">\n" +
+ " <locator class=\"org.i.dont.exist.PhantomBuddyLocator\">\n" +
" <properties>\n" +
" numBuddies = 3\n" +
" </properties>\n" +
- " </buddyLocator>\n" +
+ " </locator>\n" +
" </buddyReplication>";
BuddyReplicationConfig config = getBuddyReplicationConfig(xmlConfig);
BuddyManager mgr = new BuddyManager(config);
@@ -101,7 +101,7 @@
*/
public void testConstruction3() throws Exception
{
- String xmlConfig = "<buddyReplication enabled=\"false\"/>";
+ String xmlConfig = "<buddy enabled=\"false\"/>";
BuddyReplicationConfig config = getBuddyReplicationConfig(xmlConfig);
BuddyManager mgr = new BuddyManager(config);
assertTrue(!mgr.isEnabled());
@@ -114,7 +114,7 @@
*/
public void testConstruction4() throws Exception
{
- String xmlConfig = "<buddyReplication enabled=\"true\"/>";
+ String xmlConfig = "<buddy enabled=\"true\"/>";
BuddyReplicationConfig config = getBuddyReplicationConfig(xmlConfig);
BuddyManager mgr = new BuddyManager(config);
@@ -132,7 +132,7 @@
BuddyManager bm = null;
try
{
- String xmlConfig = "<buddyReplication enabled=\"false\"/>";
+ String xmlConfig = "<buddy enabled=\"false\"/>";
BuddyReplicationConfig config = getBuddyReplicationConfig(xmlConfig);
bm = new BuddyManager(config);
bm.injectDependencies(null, null, null, null, null, null, null, null, new BuddyFqnTransformer());
Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java 2008-07-03 12:20:17 UTC (rev 6158)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/BuddyReplicationConfigTest.java 2008-07-03 13:20:58 UTC (rev 6159)
@@ -11,11 +11,11 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.config.BuddyReplicationConfig;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
import org.jboss.cache.config.parsing.XmlConfigurationParser;
+import org.jboss.cache.config.parsing.element.BuddyElementParser;
import org.jboss.cache.interceptors.DataGravitatorInterceptor;
import org.jboss.cache.interceptors.base.CommandInterceptor;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
-import org.jboss.cache.config.parsing.element.BuddyElementParser;
import static org.testng.AssertJUnit.*;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
@@ -47,7 +47,7 @@
public void testDisabledConfig() throws Exception
{
- String xmlConfig = "<buddyReplication enabled=\"false\"/>";
+ String xmlConfig = "<buddy enabled=\"false\"/>";
BuddyReplicationConfig config = getBuddyReplicationConfig(xmlConfig);
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
cache.getConfiguration().setBuddyReplicationConfig(config);
@@ -56,7 +56,7 @@
public void testBasicConfig() throws Exception
{
- String xmlConfig = "<buddyReplication enabled=\"true\"/>";
+ String xmlConfig = "<buddy enabled=\"true\"/>";
BuddyReplicationConfig config = getBuddyReplicationConfig(xmlConfig);
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
cache.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
@@ -112,8 +112,8 @@
public void testLocalModeConfig() throws Exception
{
- String xmlConfig = "<buddyReplication enabled=\"true\"/>";
- BuddyReplicationConfig config = getBuddyReplicationConfig(xmlConfig);
+ String xmlConfig = "<buddy enabled=\"true\"/>";
+ BuddyReplicationConfig config = getBuddyReplicationConfig(xmlConfig);
cache = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(false);
cache.getConfiguration().setBuddyReplicationConfig(config);
cache.create();
16 years, 6 months
JBoss Cache SVN: r6158 - in core/trunk/src: main/java/org/jboss/cache/commands/legacy and 8 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-07-03 08:20:17 -0400 (Thu, 03 Jul 2008)
New Revision: 6158
Added:
core/trunk/src/main/java/org/jboss/cache/commands/legacy/
core/trunk/src/main/java/org/jboss/cache/commands/legacy/ReversibleCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/
core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/LegacyEvictCommand.java
core/trunk/src/main/java/org/jboss/cache/factories/OptimisticCommandsFactoryImpl.java
core/trunk/src/test/java/org/jboss/cache/commands/legacy/
core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/
Removed:
core/trunk/src/main/java/org/jboss/cache/commands/legacy/ReversibleCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/
core/trunk/src/main/java/org/jboss/cache/commands/pessimistic/
core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/
core/trunk/src/test/java/org/jboss/cache/commands/pessimistic/
Modified:
core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessClearDataCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessCreateNodeCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessMoveCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessPutDataMapCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessPutForExternalReadCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessPutKeyValueCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessRemoveKeyCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessRemoveNodeCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/write/EvictCommand.java
core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactoryImpl.java
core/trunk/src/main/java/org/jboss/cache/factories/CommandsMetaFactory.java
core/trunk/src/main/java/org/jboss/cache/factories/PessimisticCommandsFactoryImpl.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/ClearDataCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/CreateNodeCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/MoveCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/PutDataMapCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/PutKeyValueCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/RemoveKeyCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/RemoveNodeCommandTest.java
core/trunk/src/test/java/org/jboss/cache/commands/write/EvictCommandTest.java
Log:
Introduced new command factory for opt locking.
renamed commands.pessimistic pkg to commands.legacy
created new LegacyEvictCommand
Copied: core/trunk/src/main/java/org/jboss/cache/commands/legacy (from rev 6152, core/trunk/src/main/java/org/jboss/cache/commands/pessimistic)
Deleted: core/trunk/src/main/java/org/jboss/cache/commands/legacy/ReversibleCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/pessimistic/ReversibleCommand.java 2008-07-02 12:01:41 UTC (rev 6152)
+++ core/trunk/src/main/java/org/jboss/cache/commands/legacy/ReversibleCommand.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -1,20 +0,0 @@
-package org.jboss.cache.commands.pessimistic;
-
-import org.jboss.cache.commands.WriteCommand;
-
-/**
- * A write command that can be reversed by calling a rollback.
- *
- * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @since 3.0
- */
-public interface ReversibleCommand extends WriteCommand
-{
- /**
- * Reverses a command that has already been invoked.
- * <p/>
- * <b>Important</b>: this method will be invoked at the end of interceptors chain. It should never be called directly from
- * a custom interceptor.
- */
- void rollback();
-}
Copied: core/trunk/src/main/java/org/jboss/cache/commands/legacy/ReversibleCommand.java (from rev 6157, core/trunk/src/main/java/org/jboss/cache/commands/pessimistic/ReversibleCommand.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/legacy/ReversibleCommand.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/commands/legacy/ReversibleCommand.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -0,0 +1,20 @@
+package org.jboss.cache.commands.legacy;
+
+import org.jboss.cache.commands.WriteCommand;
+
+/**
+ * A write command that can be reversed by calling a rollback.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public interface ReversibleCommand extends WriteCommand
+{
+ /**
+ * Reverses a command that has already been invoked.
+ * <p/>
+ * <b>Important</b>: this method will be invoked at the end of interceptors chain. It should never be called directly from
+ * a custom interceptor.
+ */
+ void rollback();
+}
Copied: core/trunk/src/main/java/org/jboss/cache/commands/legacy/write (from rev 6157, core/trunk/src/main/java/org/jboss/cache/commands/pessimistic/write)
Added: core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/LegacyEvictCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/LegacyEvictCommand.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/LegacyEvictCommand.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -0,0 +1,39 @@
+package org.jboss.cache.commands.legacy.write;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.commands.write.EvictCommand;
+import org.jboss.cache.invocation.InvocationContext;
+
+import java.util.Collection;
+
+/**
+ * Evict command for legacy locking schemes like OL and PL.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class LegacyEvictCommand extends EvictCommand
+{
+ public LegacyEvictCommand(Fqn fqn)
+ {
+ super(fqn);
+ }
+
+ public LegacyEvictCommand()
+ {
+ }
+
+ @Override
+ protected NodeSPI lookupForEviction(InvocationContext ctx, Fqn fqn)
+ {
+ return dataContainer.peek(fqn, false, true);
+ }
+
+ @Override
+ protected Collection<Fqn> getRecursiveEvictionNodes()
+ {
+ return dataContainer.getNodesForEviction(fqn, true);
+ }
+
+}
Modified: core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessClearDataCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/pessimistic/write/PessClearDataCommand.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessClearDataCommand.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -1,8 +1,8 @@
-package org.jboss.cache.commands.pessimistic.write;
+package org.jboss.cache.commands.legacy.write;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
-import org.jboss.cache.commands.pessimistic.ReversibleCommand;
+import org.jboss.cache.commands.legacy.ReversibleCommand;
import org.jboss.cache.commands.write.ClearDataCommand;
import org.jboss.cache.invocation.InvocationContext;
import org.jboss.cache.transaction.GlobalTransaction;
Modified: core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessCreateNodeCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/pessimistic/write/PessCreateNodeCommand.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessCreateNodeCommand.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -1,7 +1,7 @@
-package org.jboss.cache.commands.pessimistic.write;
+package org.jboss.cache.commands.legacy.write;
import org.jboss.cache.Fqn;
-import org.jboss.cache.commands.pessimistic.ReversibleCommand;
+import org.jboss.cache.commands.legacy.ReversibleCommand;
import org.jboss.cache.commands.write.CreateNodeCommand;
import java.util.List;
Modified: core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessMoveCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/pessimistic/write/PessMoveCommand.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessMoveCommand.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -1,7 +1,7 @@
-package org.jboss.cache.commands.pessimistic.write;
+package org.jboss.cache.commands.legacy.write;
import org.jboss.cache.Fqn;
-import org.jboss.cache.commands.pessimistic.ReversibleCommand;
+import org.jboss.cache.commands.legacy.ReversibleCommand;
import org.jboss.cache.commands.write.MoveCommand;
/**
Modified: core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessPutDataMapCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/pessimistic/write/PessPutDataMapCommand.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessPutDataMapCommand.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -1,8 +1,8 @@
-package org.jboss.cache.commands.pessimistic.write;
+package org.jboss.cache.commands.legacy.write;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
-import org.jboss.cache.commands.pessimistic.ReversibleCommand;
+import org.jboss.cache.commands.legacy.ReversibleCommand;
import org.jboss.cache.commands.write.PutDataMapCommand;
import org.jboss.cache.invocation.InvocationContext;
import org.jboss.cache.transaction.GlobalTransaction;
Modified: core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessPutForExternalReadCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/pessimistic/write/PessPutForExternalReadCommand.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessPutForExternalReadCommand.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -1,9 +1,9 @@
-package org.jboss.cache.commands.pessimistic.write;
+package org.jboss.cache.commands.legacy.write;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
-import org.jboss.cache.commands.pessimistic.ReversibleCommand;
+import org.jboss.cache.commands.legacy.ReversibleCommand;
import org.jboss.cache.commands.write.PutForExternalReadCommand;
import org.jboss.cache.invocation.InvocationContext;
import org.jboss.cache.transaction.GlobalTransaction;
Modified: core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessPutKeyValueCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/pessimistic/write/PessPutKeyValueCommand.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessPutKeyValueCommand.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -1,9 +1,9 @@
-package org.jboss.cache.commands.pessimistic.write;
+package org.jboss.cache.commands.legacy.write;
import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
-import org.jboss.cache.commands.pessimistic.ReversibleCommand;
+import org.jboss.cache.commands.legacy.ReversibleCommand;
import org.jboss.cache.commands.write.PutKeyValueCommand;
import org.jboss.cache.invocation.InvocationContext;
import org.jboss.cache.transaction.GlobalTransaction;
Modified: core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessRemoveKeyCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/pessimistic/write/PessRemoveKeyCommand.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessRemoveKeyCommand.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -1,8 +1,8 @@
-package org.jboss.cache.commands.pessimistic.write;
+package org.jboss.cache.commands.legacy.write;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
-import org.jboss.cache.commands.pessimistic.ReversibleCommand;
+import org.jboss.cache.commands.legacy.ReversibleCommand;
import org.jboss.cache.commands.write.RemoveKeyCommand;
import org.jboss.cache.invocation.InvocationContext;
import org.jboss.cache.transaction.GlobalTransaction;
Modified: core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessRemoveNodeCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/pessimistic/write/PessRemoveNodeCommand.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/PessRemoveNodeCommand.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -1,8 +1,8 @@
-package org.jboss.cache.commands.pessimistic.write;
+package org.jboss.cache.commands.legacy.write;
import org.jboss.cache.Fqn;
import org.jboss.cache.NodeSPI;
-import org.jboss.cache.commands.pessimistic.ReversibleCommand;
+import org.jboss.cache.commands.legacy.ReversibleCommand;
import org.jboss.cache.commands.write.RemoveNodeCommand;
import org.jboss.cache.invocation.InvocationContext;
import org.jboss.cache.transaction.GlobalTransaction;
Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/EvictCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/EvictCommand.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/EvictCommand.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -30,7 +30,6 @@
protected Notifier notifier;
private static final Log log = LogFactory.getLog(EvictCommand.class);
private static final boolean trace = log.isTraceEnabled();
- private boolean isUsingMvcc;
private List<Fqn> nodesToEvict;
public EvictCommand(Fqn fqn)
@@ -42,11 +41,10 @@
{
}
- public void initialize(Notifier notifier, DataContainer dataContainer, boolean isUsingMvcc)
+ public void initialize(Notifier notifier, DataContainer dataContainer)
{
super.initialize(dataContainer);
this.notifier = notifier;
- this.isUsingMvcc = isUsingMvcc;
}
public List<Fqn> getNodesToEvict()
@@ -69,7 +67,6 @@
*/
public Object perform(InvocationContext ctx)
{
- // TODO: remove this ugly hack
NodeSPI node = lookupForEviction(ctx, fqn);
if (node == null || node.isDeleted())
{
@@ -98,16 +95,11 @@
}
}
- private Collection<Fqn> getRecursiveEvictionNodes()
+ protected Collection<Fqn> getRecursiveEvictionNodes()
{
- if (isUsingMvcc)
- {
- Collections.sort(nodesToEvict);
- Collections.reverse(nodesToEvict);
- return nodesToEvict;
- }
- else
- return dataContainer.getNodesForEviction(fqn, true);
+ Collections.sort(nodesToEvict);
+ Collections.reverse(nodesToEvict);
+ return nodesToEvict;
}
boolean evictNode(Fqn fqn, InvocationContext ctx, NodeSPI node)
@@ -144,17 +136,9 @@
}
}
- private NodeSPI lookupForEviction(InvocationContext ctx, Fqn fqn)
+ protected NodeSPI lookupForEviction(InvocationContext ctx, Fqn fqn)
{
- // TODO: do something about this nasty hack
- if (isUsingMvcc)
- {
- return ctx.lookUpNode(fqn);
- }
- else
- {
- return dataContainer.peek(fqn, false, true);
- }
+ return ctx.lookUpNode(fqn);
}
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
Modified: core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactoryImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactoryImpl.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/main/java/org/jboss/cache/factories/CommandsFactoryImpl.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -40,9 +40,7 @@
import org.jboss.cache.commands.write.RemoveNodeCommand;
import org.jboss.cache.commands.write.VersionedInvalidateCommand;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.Configuration.NodeLockingScheme;
import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.interceptors.InterceptorChain;
import org.jboss.cache.notifications.Notifier;
import org.jboss.cache.transaction.GlobalTransaction;
@@ -69,7 +67,6 @@
protected Configuration configuration;
protected TransactionManager txManager;
protected BuddyFqnTransformer buddyFqnTransformer;
- private boolean usingMvcc;
public CommandsFactoryImpl()
{
@@ -92,12 +89,6 @@
this.buddyFqnTransformer = buddyFqnTransformer;
}
- @Start
- public void start()
- {
- usingMvcc = configuration.getNodeLockingScheme() == NodeLockingScheme.MVCC;
- }
-
public PutDataMapCommand buildPutDataMapCommand(GlobalTransaction gtx, Fqn fqn, Map data)
{
PutDataMapCommand cmd = new PutDataMapCommand(gtx, fqn, data);
@@ -165,7 +156,7 @@
public EvictCommand buildEvictFqnCommand(Fqn fqn)
{
EvictCommand command = new EvictCommand(fqn);
- command.initialize(notifier, dataContainer, usingMvcc);
+ command.initialize(notifier, dataContainer);
return command;
}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/CommandsMetaFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/CommandsMetaFactory.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/main/java/org/jboss/cache/factories/CommandsMetaFactory.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -1,6 +1,6 @@
package org.jboss.cache.factories;
-import org.jboss.cache.config.Configuration.NodeLockingScheme;
+import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.factories.annotations.DefaultFactoryFor;
/**
@@ -15,9 +15,15 @@
@SuppressWarnings("unchecked")
protected <T> T construct(Class<T> componentType)
{
- if (configuration.getNodeLockingScheme() == NodeLockingScheme.PESSIMISTIC)
- return (T) new PessimisticCommandsFactoryImpl();
- else
- return (T) new CommandsFactoryImpl();
+ switch (configuration.getNodeLockingScheme())
+ {
+ case MVCC:
+ return (T) new CommandsFactoryImpl();
+ case OPTIMISTIC:
+ return (T) new OptimisticCommandsFactoryImpl();
+ case PESSIMISTIC:
+ return (T) new PessimisticCommandsFactoryImpl();
+ }
+ throw new ConfigurationException("Unknown locking scheme " + configuration.getNodeLockingScheme());
}
}
Added: core/trunk/src/main/java/org/jboss/cache/factories/OptimisticCommandsFactoryImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/OptimisticCommandsFactoryImpl.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/factories/OptimisticCommandsFactoryImpl.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -0,0 +1,22 @@
+package org.jboss.cache.factories;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.legacy.write.LegacyEvictCommand;
+import org.jboss.cache.commands.write.EvictCommand;
+
+/**
+ * Extends the default commands factory impl for optimistic locking.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class OptimisticCommandsFactoryImpl extends CommandsFactoryImpl
+{
+ @Override
+ public EvictCommand buildEvictFqnCommand(Fqn fqn)
+ {
+ EvictCommand command = new LegacyEvictCommand(fqn);
+ command.initialize(notifier, dataContainer);
+ return command;
+ }
+}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/PessimisticCommandsFactoryImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/PessimisticCommandsFactoryImpl.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/main/java/org/jboss/cache/factories/PessimisticCommandsFactoryImpl.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -2,14 +2,14 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.commands.ReplicableCommand;
-import org.jboss.cache.commands.pessimistic.write.PessClearDataCommand;
-import org.jboss.cache.commands.pessimistic.write.PessCreateNodeCommand;
-import org.jboss.cache.commands.pessimistic.write.PessMoveCommand;
-import org.jboss.cache.commands.pessimistic.write.PessPutDataMapCommand;
-import org.jboss.cache.commands.pessimistic.write.PessPutForExternalReadCommand;
-import org.jboss.cache.commands.pessimistic.write.PessPutKeyValueCommand;
-import org.jboss.cache.commands.pessimistic.write.PessRemoveKeyCommand;
-import org.jboss.cache.commands.pessimistic.write.PessRemoveNodeCommand;
+import org.jboss.cache.commands.legacy.write.PessClearDataCommand;
+import org.jboss.cache.commands.legacy.write.PessCreateNodeCommand;
+import org.jboss.cache.commands.legacy.write.PessMoveCommand;
+import org.jboss.cache.commands.legacy.write.PessPutDataMapCommand;
+import org.jboss.cache.commands.legacy.write.PessPutForExternalReadCommand;
+import org.jboss.cache.commands.legacy.write.PessPutKeyValueCommand;
+import org.jboss.cache.commands.legacy.write.PessRemoveKeyCommand;
+import org.jboss.cache.commands.legacy.write.PessRemoveNodeCommand;
import org.jboss.cache.commands.write.ClearDataCommand;
import org.jboss.cache.commands.write.CreateNodeCommand;
import org.jboss.cache.commands.write.MoveCommand;
@@ -27,10 +27,10 @@
* pessimistic commands where appropriate, with the ability to roll back.
*
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @see org.jboss.cache.commands.pessimistic.ReversibleCommand
+ * @see org.jboss.cache.commands.legacy.ReversibleCommand
* @since 3.0
*/
-public class PessimisticCommandsFactoryImpl extends CommandsFactoryImpl
+public class PessimisticCommandsFactoryImpl extends OptimisticCommandsFactoryImpl
{
@Override
public PutDataMapCommand buildPutDataMapCommand(GlobalTransaction gtx, Fqn fqn, Map data)
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -12,7 +12,7 @@
import org.jboss.cache.commands.DataCommand;
import org.jboss.cache.commands.VisitableCommand;
import org.jboss.cache.commands.WriteCommand;
-import org.jboss.cache.commands.pessimistic.ReversibleCommand;
+import org.jboss.cache.commands.legacy.ReversibleCommand;
import org.jboss.cache.commands.read.GetChildrenNamesCommand;
import org.jboss.cache.commands.read.GetKeyValueCommand;
import org.jboss.cache.commands.read.GetKeysCommand;
Copied: core/trunk/src/test/java/org/jboss/cache/commands/legacy (from rev 6152, core/trunk/src/test/java/org/jboss/cache/commands/pessimistic)
Copied: core/trunk/src/test/java/org/jboss/cache/commands/legacy/write (from rev 6157, core/trunk/src/test/java/org/jboss/cache/commands/pessimistic/write)
Modified: core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/ClearDataCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/pessimistic/write/ClearDataCommandTest.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/ClearDataCommandTest.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -1,4 +1,4 @@
-package org.jboss.cache.commands.pessimistic.write;
+package org.jboss.cache.commands.legacy.write;
import static org.easymock.EasyMock.expect;
import org.jboss.cache.commands.write.AbstractVersionedDataCommand;
Modified: core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/CreateNodeCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/pessimistic/write/CreateNodeCommandTest.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/CreateNodeCommandTest.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -1,4 +1,4 @@
-package org.jboss.cache.commands.pessimistic.write;
+package org.jboss.cache.commands.legacy.write;
import static org.easymock.EasyMock.*;
import org.jboss.cache.commands.read.AbstractDataCommandTest;
Modified: core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/MoveCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/pessimistic/write/MoveCommandTest.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/MoveCommandTest.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -1,4 +1,4 @@
-package org.jboss.cache.commands.pessimistic.write;
+package org.jboss.cache.commands.legacy.write;
import static org.easymock.EasyMock.createStrictControl;
import static org.easymock.EasyMock.expect;
Modified: core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/PutDataMapCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/pessimistic/write/PutDataMapCommandTest.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/PutDataMapCommandTest.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -1,4 +1,4 @@
-package org.jboss.cache.commands.pessimistic.write;
+package org.jboss.cache.commands.legacy.write;
import static org.easymock.EasyMock.createStrictControl;
import static org.easymock.EasyMock.expect;
Modified: core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/PutKeyValueCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/pessimistic/write/PutKeyValueCommandTest.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/PutKeyValueCommandTest.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -1,4 +1,4 @@
-package org.jboss.cache.commands.pessimistic.write;
+package org.jboss.cache.commands.legacy.write;
import static org.easymock.EasyMock.expect;
import org.jboss.cache.NodeNotExistsException;
Modified: core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/RemoveKeyCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/pessimistic/write/RemoveKeyCommandTest.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/RemoveKeyCommandTest.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -1,4 +1,4 @@
-package org.jboss.cache.commands.pessimistic.write;
+package org.jboss.cache.commands.legacy.write;
import static org.easymock.EasyMock.expect;
import org.jboss.cache.commands.write.AbstractVersionedDataCommand;
Modified: core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/RemoveNodeCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/pessimistic/write/RemoveNodeCommandTest.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/test/java/org/jboss/cache/commands/legacy/write/RemoveNodeCommandTest.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -1,4 +1,4 @@
-package org.jboss.cache.commands.pessimistic.write;
+package org.jboss.cache.commands.legacy.write;
import static org.easymock.EasyMock.expect;
import org.jboss.cache.commands.write.AbstractVersionedDataCommand;
Modified: core/trunk/src/test/java/org/jboss/cache/commands/write/EvictCommandTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/commands/write/EvictCommandTest.java 2008-07-03 12:04:30 UTC (rev 6157)
+++ core/trunk/src/test/java/org/jboss/cache/commands/write/EvictCommandTest.java 2008-07-03 12:20:17 UTC (rev 6158)
@@ -5,6 +5,7 @@
import org.easymock.IMocksControl;
import org.jboss.cache.DataContainer;
import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.legacy.write.LegacyEvictCommand;
import org.jboss.cache.commands.read.AbstractDataCommandTest;
import org.jboss.cache.mock.MockNodesFixture;
import org.jboss.cache.notifications.Notifier;
@@ -32,8 +33,8 @@
control = createStrictControl();
notifier = control.createMock(Notifier.class);
container = control.createMock(DataContainer.class);
- command = new EvictCommand(testFqn);
- command.initialize(notifier, container, false);
+ command = new LegacyEvictCommand(testFqn);
+ command.initialize(notifier, container);
nodes = new MockNodesFixture();
}
16 years, 6 months