// Much better Fqn f = Fqn.fromString("/a/b/c"); for (int i=0; i
@version $Revision: 6776 $
@NodeModified
@NodeMoved
@NodeLoaded
@NodeEvicted
public synchronized void cacheChanged(NodeEvent ne) {
Fqn fqn = ne.getFqn();
if (fqn.isChildOrEquals(rootFqn)) {
listener.cacheChanged();
}
}
{
Node<Object, Object> root1 = cache1.getRoot();
Node<Object, Object> root2 = cache2.getRoot();
// this fqn is relative, but since it is from the root it may as well be absolute
Fqn fqn = Fqn.fromString("/test/fqn");
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
cache1.put(fqn, "key", "value");
assertEquals("value", cache1.get(fqn, "key"));
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
cache2.put(fqn, "key", "value");
assertEquals("value", cache2.get(fqn, "key"));
assertEquals(true, cache1.removeNode(fqn));
assertFalse(root1.hasChild(fqn));
Node<Object, Object> remoteNode = root2.getChild(fqn);
CacheLoaderInvalidationTest.checkRemoteNodeIsRemoved(remoteNode);
assertEquals(false, cache1.removeNode(fqn));
Fqn child = Fqn.fromString("/test/fqn/child");
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
cache1.put(child, "key", "value");
assertEquals("value", cache1.get(child, "key"));
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
cache2.put(child, "key", "value");
}
public void nodeResurrectionTest() throws Exception
{
// this fqn is relative, but since it is from the root it may as well be absolute
Fqn fqn = Fqn.fromString("/test/fqn1");
cache1.put(fqn, "key", "value");
assertEquals("value", cache1.get(fqn, "key"));
assertEquals(null, cache2.get(fqn, "key"));
// Change the value in order to increment the version if Optimistic is used
cache1.put(fqn, "key", "newValue");
{
Node root1 = cache1.getRoot();
Node root2 = cache2.getRoot();
// this fqn is relative, but since it is from the root it may as well be absolute
Fqn fqn = Fqn.fromString("/test/fqn");
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
root1.addChild(fqn);
assertEquals(true, root1.hasChild(fqn));
cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
root1.addChild(fqn);
assertEquals(true, root1.hasChild(fqn));
Fqn child = Fqn.fromRelativeElements(fqn, "child");
cache1.putForExternalRead(child, "key", "value");
cache2.putForExternalRead(child, "key", "value");
assertEquals("value", cache1.get(child, "key"));
assertEquals("value", cache2.get(child, "key"));
assertEquals(true, root2.hasChild(fqn));
}
public void deleteNonExistentTest() throws Exception
{
Fqn fqn = Fqn.fromString("/a/b");
assertNull("Should be null", cache1.getNode(fqn));
assertNull("Should be null", cache2.getNode(fqn));
cache1.putForExternalRead(fqn, "key", "value");
}
protected void move(boolean supressEventNotification)
{
assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
Fqn newParent = Fqn.fromString("/a");
cache.put(fqn, "key", "value");
cache.put(newParent, "key", "value");
Node<Object, Object> n1 = cache.getRoot().getChild(fqn);
Node<Object, Object> n2 = cache.getRoot().getChild(newParent);
eventLog.events.clear();// clear events
assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
if (supressEventNotification)
{
setSuppressEventNotification();
}
cache.move(n1.getFqn(), n2.getFqn());
//expected
Fqn newFqn = Fqn.fromRelativeElements(newParent, fqn.getLastElement());
List<Event> expected = new ArrayList<Event>();
if (!supressEventNotification)
{
if (optLocking)
}
public void testTxMove() throws Exception
{
assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
Fqn newParent = Fqn.fromString("/a");
cache.put(fqn, "key", "value");
cache.put(newParent, "key", "value");
Node<Object, Object> n1 = cache.getRoot().getChild(fqn);
Node<Object, Object> n2 = cache.getRoot().getChild(newParent);
eventLog.events.clear();// clear events
assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
tm.begin();
Transaction tx = tm.getTransaction();
cache.move(n1.getFqn(), n2.getFqn());
//expected
Fqn newFqn = Fqn.fromRelativeElements(newParent, fqn.getLastElement());
List<Event> expected = new ArrayList<Event>();
expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
expected.add(new EventImpl(true, cache, null, null, fqn, tx, true, newFqn, false, null, NODE_MOVED));
expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, newFqn, false, null, NODE_MOVED));
}
protected void txMove(boolean supressEventNotification) throws Exception
{
assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
Fqn newParent = Fqn.fromString("/a");
cache.put(fqn, "key", "value");
cache.put(newParent, "key", "value");
Node<Object, Object> n1 = cache.getRoot().getChild(fqn);
Node<Object, Object> n2 = cache.getRoot().getChild(newParent);
eventLog.events.clear();// clear events
assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
if (supressEventNotification)
{
setSuppressEventNotification();
}
tm.begin();
Transaction tx = tm.getTransaction();
if (supressEventNotification)
{
setSuppressEventNotification();
}
cache.move(n1.getFqn(), n2.getFqn());
//expected
Fqn newFqn = Fqn.fromRelativeElements(newParent, fqn.getLastElement());
List<Event> expected = new ArrayList<Event>();
if (!supressEventNotification)
{
expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
expected.add(new EventImpl(true, cache, null, null, fqn, tx, true, newFqn, false, null, NODE_MOVED));
{
List<CacheSPI<Object, Object>> caches = createCachesWithSharedCL(true);
cache1 = caches.get(0);
cache2 = caches.get(1);
Fqn fqn = Fqn.fromString("/a/b");
TransactionManager mgr = caches.get(0).getTransactionManager();
assertNull("Should be null", caches.get(0).get(fqn, "key"));
assertNull("Should be null", caches.get(1).get(fqn, "key"));
mgr.begin();
caches.get(0).put(fqn, "key", "value");
caches.get(0).start();
caches.get(1).start();
TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheSPI[0]), 5000);
Fqn fqn = Fqn.fromString("/a/b");
assertNull("Should be null", caches.get(0).getNode(fqn));
assertNull("Should be null", caches.get(1).getNode(fqn));
caches.get(0).put(fqn, "key", "value");
Related Classes of org.jboss.cache.Fqn
Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.