JBoss Cache SVN: r6009 - core/trunk/src/test/java/org/jboss/cache/notifications.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-23 13:32:56 -0400 (Mon, 23 Jun 2008)
New Revision: 6009
Modified:
core/trunk/src/test/java/org/jboss/cache/notifications/CacheListenerPassivationTest.java
Log:
Un-javadoc
Modified: core/trunk/src/test/java/org/jboss/cache/notifications/CacheListenerPassivationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/notifications/CacheListenerPassivationTest.java 2008-06-23 17:12:53 UTC (rev 6008)
+++ core/trunk/src/test/java/org/jboss/cache/notifications/CacheListenerPassivationTest.java 2008-06-23 17:32:56 UTC (rev 6009)
@@ -27,12 +27,6 @@
import java.util.List;
import java.util.Map;
-/**
- * // TODO: MANIK: Document this
- *
- * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @since 3.0
- */
@Test(groups = "functional")
public class CacheListenerPassivationTest
{
16 years, 6 months
JBoss Cache SVN: r6008 - in core/trunk/src: test/java/org/jboss/cache/notifications and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-23 13:12:53 -0400 (Mon, 23 Jun 2008)
New Revision: 6008
Added:
core/trunk/src/test/java/org/jboss/cache/notifications/CacheListenerPassivationTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
core/trunk/src/test/java/org/jboss/cache/notifications/EventLog.java
core/trunk/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java
Log:
JBCACHE-1375 - added tests and patch
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-06-23 17:01:25 UTC (rev 6007)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-06-23 17:12:53 UTC (rev 6008)
@@ -12,7 +12,12 @@
import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
import org.jboss.cache.commands.tx.PrepareCommand;
import org.jboss.cache.commands.write.ClearDataCommand;
-import org.jboss.cache.commands.write.*;
+import org.jboss.cache.commands.write.MoveCommand;
+import org.jboss.cache.commands.write.PutDataMapCommand;
+import org.jboss.cache.commands.write.PutForExternalReadCommand;
+import org.jboss.cache.commands.write.PutKeyValueCommand;
+import org.jboss.cache.commands.write.RemoveKeyCommand;
+import org.jboss.cache.commands.write.RemoveNodeCommand;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.transaction.GlobalTransaction;
@@ -21,7 +26,6 @@
import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -180,13 +184,13 @@
if (result)
{
log.debug("children all initialized");
- remove(ctx, fqn);
+ remove(fqn);
}
}
else if (loaderNoChildren(fqn))
{
if (log.isDebugEnabled()) log.debug("no children " + n);
- remove(ctx, fqn);
+ remove(fqn);
}
}
}
@@ -235,9 +239,8 @@
return retval;
}
- private void remove(InvocationContext ctx, Fqn fqn) throws Exception
+ private void remove(Fqn fqn) throws Exception
{
- notifier.notifyNodeActivated(fqn, true, Collections.emptyMap(), ctx);
loader.remove(fqn);
if (getStatisticsEnabled()) activations++;
}
@@ -294,7 +297,7 @@
}
List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
- builder.visitCollection(null, entry.getModifications());
+ builder.visitCollection(ctx, entry.getModifications());
if (cacheLoaderModifications.size() > 0)
{
loader.prepare(gtx, cacheLoaderModifications, false);
@@ -323,6 +326,14 @@
return null;
}
+ @Override
+ public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
+ {
+ Fqn fqn = command.getFqn();
+ handlePutCommand(ctx, fqn);
+ return null;
+ }
+
// On the way out, remove the node from the cache loader.
// Only remove the node if it exists in memory, its attributes have
// been initialized, its children have been loaded
@@ -355,13 +366,6 @@
}
}
-
- @Override
- public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand putKeyValueCommand) throws Throwable
- {
- return super.visitPutKeyValueCommand(ctx, putKeyValueCommand);
- }
-
private boolean loaderNoChildren(Fqn fqn) throws Exception
{
return loader.getChildrenNames(fqn) != null;
Added: core/trunk/src/test/java/org/jboss/cache/notifications/CacheListenerPassivationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/notifications/CacheListenerPassivationTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/notifications/CacheListenerPassivationTest.java 2008-06-23 17:12:53 UTC (rev 6008)
@@ -0,0 +1,214 @@
+package org.jboss.cache.notifications;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.loader.DummyInMemoryCacheLoader;
+import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.notifications.event.Event;
+import static org.jboss.cache.notifications.event.Event.Type.*;
+import org.jboss.cache.notifications.event.EventImpl;
+import static org.jboss.cache.notifications.event.NodeModifiedEvent.ModificationType.PUT_DATA;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import org.jboss.cache.util.TestingUtil;
+import static org.testng.AssertJUnit.assertEquals;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+@Test(groups = "functional")
+public class CacheListenerPassivationTest
+{
+ private Cache<Object, Object> cache;
+ private EventLog eventLog = new EventLog();
+ private TransactionManager tm;
+ private Fqn<String> fqn = Fqn.fromString("/test");
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws Exception
+ {
+ Configuration c = new Configuration();
+ c.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+
+ CacheLoaderConfig clc = new CacheLoaderConfig();
+ IndividualCacheLoaderConfig iclc = new IndividualCacheLoaderConfig();
+ iclc.setClassName(DummyInMemoryCacheLoader.class.getName());
+ clc.addIndividualCacheLoaderConfig(iclc);
+ clc.setPassivation(true);
+
+ c.setCacheLoaderConfig(clc);
+ cache = new DefaultCacheFactory().createCache(c);
+ eventLog.events.clear();
+ cache.addCacheListener(eventLog);
+ tm = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void tearDown() throws Exception
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testActivationAndPassivation() throws Exception
+ {
+ assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ cache.put(fqn, "key", "value");
+ Map<Object, Object> data = new HashMap<Object, Object>();
+ data.put("key", "value");
+
+ List<Event> expected = new ArrayList<Event>();
+
+ // now evict the node - which should cause a passivation
+ eventLog.events.clear();
+ cache.evict(fqn);
+ expected.add(new EventImpl(true, cache, null, data, fqn, null, true, null, false, null, NODE_PASSIVATED));
+ expected.add(new EventImpl(false, cache, null, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_PASSIVATED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null, false, null, NODE_EVICTED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false, null, NODE_EVICTED));
+ assertEquals(expected, eventLog.events);
+
+ // now load the node.
+ expected.clear();
+ eventLog.events.clear();
+ cache.get(fqn, "DOES_NOT_EXIST");
+ expected.add(new EventImpl(true, cache, null, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_ACTIVATED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null, false, null, NODE_CREATED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false, null, NODE_CREATED));
+ expected.add(new EventImpl(false, cache, null, data, fqn, null, true, null, false, null, NODE_ACTIVATED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null, false, null, NODE_VISITED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false, null, NODE_VISITED));
+
+ assertEquals(expected, eventLog.events);
+ }
+
+ public void testActivationAndPassivationTxNoMods() throws Exception
+ {
+ assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ cache.put(fqn, "key", "value");
+ Map<Object, Object> data = new HashMap<Object, Object>();
+ data.put("key", "value");
+
+ List<Event> expected = new ArrayList<Event>();
+
+ // now evict the node - which should cause a passivation
+ eventLog.events.clear();
+ cache.evict(fqn);
+ expected.add(new EventImpl(true, cache, null, data, fqn, null, true, null, false, null, NODE_PASSIVATED));
+ expected.add(new EventImpl(false, cache, null, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_PASSIVATED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null, false, null, NODE_EVICTED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false, null, NODE_EVICTED));
+ assertEquals(expected, eventLog.events);
+
+ // now load the node.
+ expected.clear();
+ eventLog.events.clear();
+ tm.begin();
+ Transaction tx = tm.getTransaction();
+ cache.get(fqn, "DOES_NOT_EXIST");
+ tm.commit();
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(true, cache, null, Collections.emptyMap(), fqn, tx, true, null, false, null, NODE_ACTIVATED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
+ expected.add(new EventImpl(false, cache, null, data, fqn, tx, true, null, false, null, NODE_ACTIVATED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, tx, true, null, false, null, NODE_VISITED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, null, false, null, NODE_VISITED));
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
+ assertEquals(expected, eventLog.events);
+ }
+
+ public void testActivationAndPassivationTxMods() throws Exception
+ {
+ assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ cache.put(fqn, "key", "value");
+ Map<Object, Object> data = new HashMap<Object, Object>();
+ data.put("key", "value");
+
+ List<Event> expected = new ArrayList<Event>();
+
+ // now evict the node - which should cause a passivation
+ eventLog.events.clear();
+ cache.evict(fqn);
+ expected.add(new EventImpl(true, cache, null, data, fqn, null, true, null, false, null, NODE_PASSIVATED));
+ expected.add(new EventImpl(false, cache, null, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_PASSIVATED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null, false, null, NODE_EVICTED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false, null, NODE_EVICTED));
+ assertEquals(expected, eventLog.events);
+
+ // now load the node.
+ expected.clear();
+ eventLog.events.clear();
+ tm.begin();
+ Transaction tx = tm.getTransaction();
+ cache.put(fqn, "key2", "value2");
+ tm.commit();
+ 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, null, false, null, NODE_CREATED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
+ expected.add(new EventImpl(true, cache, null, Collections.emptyMap(), fqn, tx, true, null, false, null, NODE_ACTIVATED));
+ expected.add(new EventImpl(false, cache, null, data, fqn, tx, true, null, false, null, NODE_ACTIVATED));
+ expected.add(new EventImpl(true, cache, PUT_DATA, data, fqn, tx, true, null, false, null, NODE_MODIFIED));
+ expected.add(new EventImpl(false, cache, PUT_DATA, Collections.singletonMap("key2", "value2"), fqn, tx, true, null, false, null, NODE_MODIFIED));
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
+ assertEquals(expected, eventLog.events);
+
+ assert cache.get(fqn, "key").equals("value");
+ assert cache.get(fqn, "key2").equals("value2");
+ }
+
+ public void testActivationAndPassivationTxModsWithChildren() throws Exception
+ {
+ assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ cache.put(fqn, "key", "value");
+ cache.put(Fqn.fromRelativeElements(fqn, "child"), "key3", "value3");
+ Map<Object, Object> data = new HashMap<Object, Object>();
+ data.put("key", "value");
+
+ List<Event> expected = new ArrayList<Event>();
+
+ // now evict the node - which should cause a passivation
+ eventLog.events.clear();
+ cache.evict(fqn);
+ expected.add(new EventImpl(true, cache, null, data, fqn, null, true, null, false, null, NODE_PASSIVATED));
+ expected.add(new EventImpl(false, cache, null, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_PASSIVATED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null, false, null, NODE_EVICTED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false, null, NODE_EVICTED));
+ assertEquals(expected, eventLog.events);
+
+ // now load the node.
+ expected.clear();
+ eventLog.events.clear();
+ tm.begin();
+ Transaction tx = tm.getTransaction();
+ cache.put(fqn, "key2", "value2");
+ tm.commit();
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(true, cache, null, Collections.emptyMap(), fqn, tx, true, null, false, null, NODE_ACTIVATED));
+ expected.add(new EventImpl(false, cache, null, data, fqn, tx, true, null, false, null, NODE_ACTIVATED));
+ expected.add(new EventImpl(true, cache, PUT_DATA, data, fqn, tx, true, null, false, null, NODE_MODIFIED));
+ expected.add(new EventImpl(false, cache, PUT_DATA, Collections.singletonMap("key2", "value2"), fqn, tx, true, null, false, null, NODE_MODIFIED));
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
+ assertEquals(expected, eventLog.events);
+
+ assert cache.get(fqn, "key").equals("value");
+ assert cache.get(fqn, "key2").equals("value2");
+ }
+}
Modified: core/trunk/src/test/java/org/jboss/cache/notifications/EventLog.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/notifications/EventLog.java 2008-06-23 17:01:25 UTC (rev 6007)
+++ core/trunk/src/test/java/org/jboss/cache/notifications/EventLog.java 2008-06-23 17:12:53 UTC (rev 6008)
@@ -1,19 +1,12 @@
package org.jboss.cache.notifications;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.cache.notifications.annotation.CacheListener;
-import org.jboss.cache.notifications.annotation.NodeCreated;
-import org.jboss.cache.notifications.annotation.NodeModified;
-import org.jboss.cache.notifications.annotation.NodeMoved;
-import org.jboss.cache.notifications.annotation.NodeRemoved;
-import org.jboss.cache.notifications.annotation.NodeVisited;
-import org.jboss.cache.notifications.annotation.TransactionCompleted;
-import org.jboss.cache.notifications.annotation.TransactionRegistered;
+import org.jboss.cache.notifications.annotation.*;
import org.jboss.cache.notifications.event.Event;
import org.jboss.cache.notifications.event.EventImpl;
+import java.util.ArrayList;
+import java.util.List;
+
@CacheListener
public class EventLog
{
@@ -26,6 +19,9 @@
@NodeMoved
@TransactionCompleted
@TransactionRegistered
+ @NodeEvicted
+ @NodePassivated
+ @NodeActivated
public void callback(Event e)
{
events.add(e);
@@ -34,8 +30,8 @@
public String toString()
{
return "EventLog{" +
- "events=" + events +
- '}';
+ "events=" + events +
+ '}';
}
/**
Modified: core/trunk/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java 2008-06-23 17:01:25 UTC (rev 6007)
+++ core/trunk/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java 2008-06-23 17:12:53 UTC (rev 6008)
@@ -29,63 +29,66 @@
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
-import org.jboss.cache.util.TestingUtil;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.parsing.XmlConfigurationParserOld;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.eviction.LRUConfiguration;
+import org.jboss.cache.eviction.LRUPolicy;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
+import org.jboss.cache.loader.DummySharedInMemoryCacheLoader;
import org.jboss.cache.notifications.annotation.CacheListener;
import org.jboss.cache.notifications.annotation.NodeActivated;
import org.jboss.cache.notifications.annotation.NodeLoaded;
import org.jboss.cache.notifications.annotation.NodePassivated;
import org.jboss.cache.notifications.event.NodeEvent;
+import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.fail;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.w3c.dom.Element;
-/**
- * @author Ben Wang, Feb 11, 2004
- */
-@Test(groups = {"functional", "jgroups"})
+import java.util.LinkedList;
+import java.util.List;
+
+@Test(groups = "functional")
public class ReplicatedPassivationIntegrationTest
{
- private CacheSPI<String, String> cache_;
- private CacheSPI<String, String> cache1_;
+ private CacheSPI<String, String> cache1;
+ private CacheSPI<String, String> cache2;
protected final static Log log = LogFactory.getLog(ReplicatedPassivationIntegrationTest.class);
- int wakeupIntervalMillis_ = 0;
- PassivationListener listener_;
+ int wakeupIntervalMillis = 0;
+ PassivationListener listener;
+ Fqn base = Fqn.fromString("/org/jboss/test/data");
public ReplicatedPassivationIntegrationTest()
{
- listener_ = new ReplicatedPassivationIntegrationTest.PassivationListener();
+ listener = new ReplicatedPassivationIntegrationTest.PassivationListener();
}
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
CacheFactory<String, String> instance = new DefaultCacheFactory();
- cache_ = (CacheSPI<String, String>) instance.createCache(getCfg(), false);
- cache_.getConfiguration().setUseRegionBasedMarshalling(true);
- cache_.start();
+ cache1 = (CacheSPI<String, String>) instance.createCache(getCfg(), false);
+ cache1.getConfiguration().setUseRegionBasedMarshalling(true);
+ cache1.start();
- cache1_ = (CacheSPI<String, String>) instance.createCache(getCfg(), false);
- cache1_.getConfiguration().setUseRegionBasedMarshalling(true);
+ cache2 = (CacheSPI<String, String>) instance.createCache(getCfg(), false);
+ cache2.getConfiguration().setUseRegionBasedMarshalling(true);
- cache1_.start();
- cache1_.getNotifier().addCacheListener(listener_);
- listener_.resetCounter();
+ cache2.start();
+ cache2.getNotifier().addCacheListener(listener);
+ listener.resetCounter();
- wakeupIntervalMillis_ = cache1_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
- log("wakeupInterval is " + wakeupIntervalMillis_);
- if (wakeupIntervalMillis_ <= 0)
+ wakeupIntervalMillis = cache2.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
+ log("wakeupInterval is " + wakeupIntervalMillis);
+ if (wakeupIntervalMillis <= 0)
{
- fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
+ fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis);
}
}
@@ -101,74 +104,66 @@
private CacheLoaderConfig buildCacheLoaderConfig() throws Exception
{
- String xml = " <attribute name=\"CacheLoaderConfiguration\">\n" +
- " <config>\n" +
- " <passivation>true</passivation>\n" +
- " <preload>/</preload>\n" +
- " <shared>false</shared>\n" +
- " <cacheloader>\n" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
- " <properties>\n" +
- " </properties>\n" +
- " <async>false</async>\n" +
- " <fetchPersistentState>true</fetchPersistentState>\n" +
- " <ignoreModifications>false</ignoreModifications>\n" +
- " </cacheloader>\n" +
- " </config>\n" +
- " </attribute>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseCacheLoaderConfig(element);
-
+ CacheLoaderConfig clc = new CacheLoaderConfig();
+ IndividualCacheLoaderConfig iclc = new IndividualCacheLoaderConfig();
+ iclc.setClassName(DummySharedInMemoryCacheLoader.class.getName());
+ clc.addIndividualCacheLoaderConfig(iclc);
+ clc.setPassivation(true);
+ return clc;
}
private EvictionConfig buildEvictionConfig() throws Exception
{
- String xml = " <attribute name=\"EvictionPolicyConfig\">\n" +
- " <config>\n" +
- " <attribute name=\"wakeUpIntervalSeconds\">5</attribute>\n" +
- " <attribute name=\"eventQueueSize\">200000</attribute>\n" +
- " <attribute name=\"policyClass\">org.jboss.cache.eviction.LRUPolicy</attribute>\n" +
- " <region name=\"/_default_\">\n" +
- " <attribute name=\"maxNodes\">5000</attribute>\n" +
- " <attribute name=\"timeToLiveSeconds\">3</attribute>\n" +
- " </region>\n" +
- " <region name=\"/org/jboss/test/data\">\n" +
- " <attribute name=\"maxNodes\">100</attribute>\n" +
- " <attribute name=\"timeToLiveSeconds\">3</attribute>\n" +
- " </region>\n" +
- " </config>\n" +
- " </attribute>";
- Element element = XmlConfigHelper.stringToElement(xml);
- return XmlConfigurationParserOld.parseEvictionConfig(element);
+ EvictionConfig cfg = new EvictionConfig();
+ cfg.setWakeupIntervalSeconds(1);
+ cfg.setDefaultEventQueueSize(200000);
+ cfg.setDefaultEvictionPolicyClass(LRUPolicy.class.getName());
+ List<EvictionRegionConfig> erc = new LinkedList<EvictionRegionConfig>();
+ cfg.setEvictionRegionConfigs(erc);
+ EvictionRegionConfig region1 = new EvictionRegionConfig();
+ region1.setRegionFqn(Fqn.ROOT);
+ LRUConfiguration epc1 = new LRUConfiguration();
+ epc1.setMaxNodes(5000);
+ epc1.setTimeToLiveSeconds(3);
+ region1.setEvictionPolicyConfig(epc1);
+
+ EvictionRegionConfig region2 = new EvictionRegionConfig();
+ region2.setRegionFqn(base);
+ LRUConfiguration epc2 = new LRUConfiguration();
+ epc2.setMaxNodes(100);
+ epc2.setTimeToLiveSeconds(3);
+ region2.setEvictionPolicyConfig(epc2);
+
+ erc.add(region1);
+ erc.add(region2);
+
+ return cfg;
}
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
- cache_.stop();
- cache1_.stop();
+ cache1.stop();
+ cache2.stop();
}
- /**
- */
public void testActivationEvent() throws Exception
{
- String rootStr = "/org/jboss/test/data/";
- String rootStr1 = "/__JBossInternal__/5c4o12-pzhlhj-esnuy3sg-1-esnuy3sg-2";
- String str = rootStr + "0";
- cache_.removeNode(Fqn.ROOT);
+ Fqn internalFqn = Fqn.fromString("/__JBossInternal__/5c4o12-pzhlhj-esnuy3sg-1-esnuy3sg-2");
+ Fqn fqn = Fqn.fromRelativeElements(base, "0");
+ cache1.removeNode(Fqn.ROOT);
- cache_.put(str, str, str);
- cache_.put(rootStr1, str, str);
+ cache1.put(fqn, fqn.toString(), fqn.toString());
+ cache1.put(internalFqn, fqn.toString(), fqn.toString());
- TestingUtil.sleepThread(11000);
- Node n = cache1_.peek(Fqn.fromString(str), false, false);
- assert n == null || !n.getKeys().contains(str) : "UnversionedNode should not exist";
+ TestingUtil.sleepThread(wakeupIntervalMillis + 100);
+ Node n = cache2.peek(fqn, false);
+ assert n == null || !n.getKeys().contains(fqn) : "UnversionedNode should not exist";
String val;
- val = cache1_.get(str, str);
- val = cache1_.get(rootStr1, str);
- assertNotNull("DataNode should be activated ", val);
+ val = cache2.get(fqn, fqn.toString());
+ val = cache2.get(internalFqn, fqn.toString());
+ assertNotNull("Node should be activated ", val);
}
void log(String msg)
16 years, 6 months
JBoss Cache SVN: r6007 - in core/branches/2.2.X/src: test/java/org/jboss/cache/notifications and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-06-23 13:01:25 -0400 (Mon, 23 Jun 2008)
New Revision: 6007
Added:
core/branches/2.2.X/src/test/java/org/jboss/cache/notifications/CacheListenerPassivationTest.java
Modified:
core/branches/2.2.X/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
core/branches/2.2.X/src/test/java/org/jboss/cache/notifications/EventLog.java
core/branches/2.2.X/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java
Log:
Fixes and tests for JBCACHE-1375
Modified: core/branches/2.2.X/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-06-23 08:03:03 UTC (rev 6006)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java 2008-06-23 17:01:25 UTC (rev 6007)
@@ -12,7 +12,12 @@
import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
import org.jboss.cache.commands.tx.PrepareCommand;
import org.jboss.cache.commands.write.ClearDataCommand;
-import org.jboss.cache.commands.write.*;
+import org.jboss.cache.commands.write.MoveCommand;
+import org.jboss.cache.commands.write.PutDataMapCommand;
+import org.jboss.cache.commands.write.PutForExternalReadCommand;
+import org.jboss.cache.commands.write.PutKeyValueCommand;
+import org.jboss.cache.commands.write.RemoveKeyCommand;
+import org.jboss.cache.commands.write.RemoveNodeCommand;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.transaction.GlobalTransaction;
@@ -21,7 +26,6 @@
import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -180,13 +184,13 @@
if (result)
{
log.debug("children all initialized");
- remove(ctx, fqn);
+ remove(fqn);
}
}
else if (loaderNoChildren(fqn))
{
if (log.isDebugEnabled()) log.debug("no children " + n);
- remove(ctx, fqn);
+ remove(fqn);
}
}
}
@@ -235,9 +239,8 @@
return retval;
}
- private void remove(InvocationContext ctx, Fqn fqn) throws Exception
+ private void remove(Fqn fqn) throws Exception
{
- notifier.notifyNodeActivated(fqn, true, Collections.emptyMap(), ctx);
loader.remove(fqn);
if (getStatisticsEnabled()) activations++;
}
@@ -294,7 +297,7 @@
}
List<Modification> cacheLoaderModifications = new ArrayList<Modification>();
- builder.visitCollection(null, entry.getModifications());
+ builder.visitCollection(ctx, entry.getModifications());
if (cacheLoaderModifications.size() > 0)
{
loader.prepare(gtx, cacheLoaderModifications, false);
@@ -323,6 +326,14 @@
return null;
}
+ @Override
+ public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
+ {
+ Fqn fqn = command.getFqn();
+ handlePutCommand(ctx, fqn);
+ return null;
+ }
+
// On the way out, remove the node from the cache loader.
// Only remove the node if it exists in memory, its attributes have
// been initialized, its children have been loaded
@@ -355,13 +366,6 @@
}
}
-
- @Override
- public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand putKeyValueCommand) throws Throwable
- {
- return super.visitPutKeyValueCommand(ctx, putKeyValueCommand);
- }
-
private boolean loaderNoChildren(Fqn fqn) throws Exception
{
return loader.getChildrenNames(fqn) != null;
Added: core/branches/2.2.X/src/test/java/org/jboss/cache/notifications/CacheListenerPassivationTest.java
===================================================================
--- core/branches/2.2.X/src/test/java/org/jboss/cache/notifications/CacheListenerPassivationTest.java (rev 0)
+++ core/branches/2.2.X/src/test/java/org/jboss/cache/notifications/CacheListenerPassivationTest.java 2008-06-23 17:01:25 UTC (rev 6007)
@@ -0,0 +1,214 @@
+package org.jboss.cache.notifications;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.loader.DummyInMemoryCacheLoader;
+import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.notifications.event.Event;
+import static org.jboss.cache.notifications.event.Event.Type.*;
+import org.jboss.cache.notifications.event.EventImpl;
+import static org.jboss.cache.notifications.event.NodeModifiedEvent.ModificationType.PUT_DATA;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import org.jboss.cache.util.TestingUtil;
+import static org.testng.AssertJUnit.assertEquals;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+@Test(groups = "functional")
+public class CacheListenerPassivationTest
+{
+ private Cache<Object, Object> cache;
+ private EventLog eventLog = new EventLog();
+ private TransactionManager tm;
+ private Fqn<String> fqn = Fqn.fromString("/test");
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws Exception
+ {
+ Configuration c = new Configuration();
+ c.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+
+ CacheLoaderConfig clc = new CacheLoaderConfig();
+ IndividualCacheLoaderConfig iclc = new IndividualCacheLoaderConfig();
+ iclc.setClassName(DummyInMemoryCacheLoader.class.getName());
+ clc.addIndividualCacheLoaderConfig(iclc);
+ clc.setPassivation(true);
+
+ c.setCacheLoaderConfig(clc);
+ cache = new DefaultCacheFactory().createCache(c);
+ eventLog.events.clear();
+ cache.addCacheListener(eventLog);
+ tm = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void tearDown() throws Exception
+ {
+ TestingUtil.killCaches(cache);
+ }
+
+ public void testActivationAndPassivation() throws Exception
+ {
+ assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ cache.put(fqn, "key", "value");
+ Map<Object, Object> data = new HashMap<Object, Object>();
+ data.put("key", "value");
+
+ List<Event> expected = new ArrayList<Event>();
+
+ // now evict the node - which should cause a passivation
+ eventLog.events.clear();
+ cache.evict(fqn);
+ expected.add(new EventImpl(true, cache, null, data, fqn, null, true, null, false, null, NODE_PASSIVATED));
+ expected.add(new EventImpl(false, cache, null, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_PASSIVATED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null, false, null, NODE_EVICTED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false, null, NODE_EVICTED));
+ assertEquals(expected, eventLog.events);
+
+ // now load the node.
+ expected.clear();
+ eventLog.events.clear();
+ cache.get(fqn, "DOES_NOT_EXIST");
+ expected.add(new EventImpl(true, cache, null, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_ACTIVATED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null, false, null, NODE_CREATED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false, null, NODE_CREATED));
+ expected.add(new EventImpl(false, cache, null, data, fqn, null, true, null, false, null, NODE_ACTIVATED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null, false, null, NODE_VISITED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false, null, NODE_VISITED));
+
+ assertEquals(expected, eventLog.events);
+ }
+
+ public void testActivationAndPassivationTxNoMods() throws Exception
+ {
+ assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ cache.put(fqn, "key", "value");
+ Map<Object, Object> data = new HashMap<Object, Object>();
+ data.put("key", "value");
+
+ List<Event> expected = new ArrayList<Event>();
+
+ // now evict the node - which should cause a passivation
+ eventLog.events.clear();
+ cache.evict(fqn);
+ expected.add(new EventImpl(true, cache, null, data, fqn, null, true, null, false, null, NODE_PASSIVATED));
+ expected.add(new EventImpl(false, cache, null, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_PASSIVATED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null, false, null, NODE_EVICTED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false, null, NODE_EVICTED));
+ assertEquals(expected, eventLog.events);
+
+ // now load the node.
+ expected.clear();
+ eventLog.events.clear();
+ tm.begin();
+ Transaction tx = tm.getTransaction();
+ cache.get(fqn, "DOES_NOT_EXIST");
+ tm.commit();
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(true, cache, null, Collections.emptyMap(), fqn, tx, true, null, false, null, NODE_ACTIVATED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
+ expected.add(new EventImpl(false, cache, null, data, fqn, tx, true, null, false, null, NODE_ACTIVATED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, tx, true, null, false, null, NODE_VISITED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, null, false, null, NODE_VISITED));
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
+ assertEquals(expected, eventLog.events);
+ }
+
+ public void testActivationAndPassivationTxMods() throws Exception
+ {
+ assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ cache.put(fqn, "key", "value");
+ Map<Object, Object> data = new HashMap<Object, Object>();
+ data.put("key", "value");
+
+ List<Event> expected = new ArrayList<Event>();
+
+ // now evict the node - which should cause a passivation
+ eventLog.events.clear();
+ cache.evict(fqn);
+ expected.add(new EventImpl(true, cache, null, data, fqn, null, true, null, false, null, NODE_PASSIVATED));
+ expected.add(new EventImpl(false, cache, null, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_PASSIVATED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null, false, null, NODE_EVICTED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false, null, NODE_EVICTED));
+ assertEquals(expected, eventLog.events);
+
+ // now load the node.
+ expected.clear();
+ eventLog.events.clear();
+ tm.begin();
+ Transaction tx = tm.getTransaction();
+ cache.put(fqn, "key2", "value2");
+ tm.commit();
+ 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, null, false, null, NODE_CREATED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, tx, true, null, false, null, NODE_CREATED));
+ expected.add(new EventImpl(true, cache, null, Collections.emptyMap(), fqn, tx, true, null, false, null, NODE_ACTIVATED));
+ expected.add(new EventImpl(false, cache, null, data, fqn, tx, true, null, false, null, NODE_ACTIVATED));
+ expected.add(new EventImpl(true, cache, PUT_DATA, data, fqn, tx, true, null, false, null, NODE_MODIFIED));
+ expected.add(new EventImpl(false, cache, PUT_DATA, Collections.singletonMap("key2", "value2"), fqn, tx, true, null, false, null, NODE_MODIFIED));
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
+ assertEquals(expected, eventLog.events);
+
+ assert cache.get(fqn, "key").equals("value");
+ assert cache.get(fqn, "key2").equals("value2");
+ }
+
+ public void testActivationAndPassivationTxModsWithChildren() throws Exception
+ {
+ assertEquals("Event log should be empty", Collections.emptyList(), eventLog.events);
+ cache.put(fqn, "key", "value");
+ cache.put(Fqn.fromRelativeElements(fqn, "child"), "key3", "value3");
+ Map<Object, Object> data = new HashMap<Object, Object>();
+ data.put("key", "value");
+
+ List<Event> expected = new ArrayList<Event>();
+
+ // now evict the node - which should cause a passivation
+ eventLog.events.clear();
+ cache.evict(fqn);
+ expected.add(new EventImpl(true, cache, null, data, fqn, null, true, null, false, null, NODE_PASSIVATED));
+ expected.add(new EventImpl(false, cache, null, Collections.emptyMap(), fqn, null, true, null, false, null, NODE_PASSIVATED));
+ expected.add(new EventImpl(true, cache, null, null, fqn, null, true, null, false, null, NODE_EVICTED));
+ expected.add(new EventImpl(false, cache, null, null, fqn, null, true, null, false, null, NODE_EVICTED));
+ assertEquals(expected, eventLog.events);
+
+ // now load the node.
+ expected.clear();
+ eventLog.events.clear();
+ tm.begin();
+ Transaction tx = tm.getTransaction();
+ cache.put(fqn, "key2", "value2");
+ tm.commit();
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, false, null, TRANSACTION_REGISTERED));
+ expected.add(new EventImpl(true, cache, null, Collections.emptyMap(), fqn, tx, true, null, false, null, NODE_ACTIVATED));
+ expected.add(new EventImpl(false, cache, null, data, fqn, tx, true, null, false, null, NODE_ACTIVATED));
+ expected.add(new EventImpl(true, cache, PUT_DATA, data, fqn, tx, true, null, false, null, NODE_MODIFIED));
+ expected.add(new EventImpl(false, cache, PUT_DATA, Collections.singletonMap("key2", "value2"), fqn, tx, true, null, false, null, NODE_MODIFIED));
+ expected.add(new EventImpl(false, cache, null, null, null, tx, true, null, true, null, TRANSACTION_COMPLETED));
+ assertEquals(expected, eventLog.events);
+
+ assert cache.get(fqn, "key").equals("value");
+ assert cache.get(fqn, "key2").equals("value2");
+ }
+}
Modified: core/branches/2.2.X/src/test/java/org/jboss/cache/notifications/EventLog.java
===================================================================
--- core/branches/2.2.X/src/test/java/org/jboss/cache/notifications/EventLog.java 2008-06-23 08:03:03 UTC (rev 6006)
+++ core/branches/2.2.X/src/test/java/org/jboss/cache/notifications/EventLog.java 2008-06-23 17:01:25 UTC (rev 6007)
@@ -1,19 +1,12 @@
package org.jboss.cache.notifications;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.cache.notifications.annotation.CacheListener;
-import org.jboss.cache.notifications.annotation.NodeCreated;
-import org.jboss.cache.notifications.annotation.NodeModified;
-import org.jboss.cache.notifications.annotation.NodeMoved;
-import org.jboss.cache.notifications.annotation.NodeRemoved;
-import org.jboss.cache.notifications.annotation.NodeVisited;
-import org.jboss.cache.notifications.annotation.TransactionCompleted;
-import org.jboss.cache.notifications.annotation.TransactionRegistered;
+import org.jboss.cache.notifications.annotation.*;
import org.jboss.cache.notifications.event.Event;
import org.jboss.cache.notifications.event.EventImpl;
+import java.util.ArrayList;
+import java.util.List;
+
@CacheListener
public class EventLog
{
@@ -26,6 +19,9 @@
@NodeMoved
@TransactionCompleted
@TransactionRegistered
+ @NodeEvicted
+ @NodePassivated
+ @NodeActivated
public void callback(Event e)
{
events.add(e);
@@ -34,8 +30,8 @@
public String toString()
{
return "EventLog{" +
- "events=" + events +
- '}';
+ "events=" + events +
+ '}';
}
/**
Modified: core/branches/2.2.X/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java
===================================================================
--- core/branches/2.2.X/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java 2008-06-23 08:03:03 UTC (rev 6006)
+++ core/branches/2.2.X/src/test/java/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java 2008-06-23 17:01:25 UTC (rev 6007)
@@ -29,63 +29,66 @@
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
-import org.jboss.cache.util.TestingUtil;
-import org.jboss.cache.xml.XmlHelper;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.eviction.LRUConfiguration;
+import org.jboss.cache.eviction.LRUPolicy;
import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
+import org.jboss.cache.loader.DummySharedInMemoryCacheLoader;
import org.jboss.cache.notifications.annotation.CacheListener;
import org.jboss.cache.notifications.annotation.NodeActivated;
import org.jboss.cache.notifications.annotation.NodeLoaded;
import org.jboss.cache.notifications.annotation.NodePassivated;
import org.jboss.cache.notifications.event.NodeEvent;
+import org.jboss.cache.util.TestingUtil;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.fail;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.w3c.dom.Element;
-/**
- * @author Ben Wang, Feb 11, 2004
- */
-@Test(groups = {"functional", "jgroups"})
+import java.util.LinkedList;
+import java.util.List;
+
+@Test(groups = "functional")
public class ReplicatedPassivationIntegrationTest
{
- private CacheSPI<String, String> cache_;
- private CacheSPI<String, String> cache1_;
+ private CacheSPI<String, String> cache1;
+ private CacheSPI<String, String> cache2;
protected final static Log log = LogFactory.getLog(ReplicatedPassivationIntegrationTest.class);
- int wakeupIntervalMillis_ = 0;
- PassivationListener listener_;
+ int wakeupIntervalMillis = 0;
+ PassivationListener listener;
+ Fqn base = Fqn.fromString("/org/jboss/test/data");
public ReplicatedPassivationIntegrationTest()
{
- listener_ = new ReplicatedPassivationIntegrationTest.PassivationListener();
+ listener = new ReplicatedPassivationIntegrationTest.PassivationListener();
}
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception
{
CacheFactory<String, String> instance = new DefaultCacheFactory();
- cache_ = (CacheSPI<String, String>) instance.createCache(getCfg(), false);
- cache_.getConfiguration().setUseRegionBasedMarshalling(true);
- cache_.start();
+ cache1 = (CacheSPI<String, String>) instance.createCache(getCfg(), false);
+ cache1.getConfiguration().setUseRegionBasedMarshalling(true);
+ cache1.start();
- cache1_ = (CacheSPI<String, String>) instance.createCache(getCfg(), false);
- cache1_.getConfiguration().setUseRegionBasedMarshalling(true);
+ cache2 = (CacheSPI<String, String>) instance.createCache(getCfg(), false);
+ cache2.getConfiguration().setUseRegionBasedMarshalling(true);
- cache1_.start();
- cache1_.getNotifier().addCacheListener(listener_);
- listener_.resetCounter();
+ cache2.start();
+ cache2.getNotifier().addCacheListener(listener);
+ listener.resetCounter();
- wakeupIntervalMillis_ = cache1_.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
- log("wakeupInterval is " + wakeupIntervalMillis_);
- if (wakeupIntervalMillis_ <= 0)
+ wakeupIntervalMillis = cache2.getConfiguration().getEvictionConfig().getWakeupIntervalSeconds() * 1000;
+ log("wakeupInterval is " + wakeupIntervalMillis);
+ if (wakeupIntervalMillis <= 0)
{
- fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis_);
+ fail("testEviction(): eviction thread wake up interval is illegal " + wakeupIntervalMillis);
}
}
@@ -101,74 +104,66 @@
private CacheLoaderConfig buildCacheLoaderConfig() throws Exception
{
- String xml = " <attribute name=\"CacheLoaderConfiguration\">\n" +
- " <config>\n" +
- " <passivation>true</passivation>\n" +
- " <preload>/</preload>\n" +
- " <shared>false</shared>\n" +
- " <cacheloader>\n" +
- " <class>org.jboss.cache.loader.FileCacheLoader</class>\n" +
- " <properties>\n" +
- " </properties>\n" +
- " <async>false</async>\n" +
- " <fetchPersistentState>true</fetchPersistentState>\n" +
- " <ignoreModifications>false</ignoreModifications>\n" +
- " </cacheloader>\n" +
- " </config>\n" +
- " </attribute>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
-
+ CacheLoaderConfig clc = new CacheLoaderConfig();
+ IndividualCacheLoaderConfig iclc = new IndividualCacheLoaderConfig();
+ iclc.setClassName(DummySharedInMemoryCacheLoader.class.getName());
+ clc.addIndividualCacheLoaderConfig(iclc);
+ clc.setPassivation(true);
+ return clc;
}
private EvictionConfig buildEvictionConfig() throws Exception
{
- String xml = " <attribute name=\"EvictionPolicyConfig\">\n" +
- " <config>\n" +
- " <attribute name=\"wakeUpIntervalSeconds\">5</attribute>\n" +
- " <attribute name=\"eventQueueSize\">200000</attribute>\n" +
- " <attribute name=\"policyClass\">org.jboss.cache.eviction.LRUPolicy</attribute>\n" +
- " <region name=\"/_default_\">\n" +
- " <attribute name=\"maxNodes\">5000</attribute>\n" +
- " <attribute name=\"timeToLiveSeconds\">3</attribute>\n" +
- " </region>\n" +
- " <region name=\"/org/jboss/test/data\">\n" +
- " <attribute name=\"maxNodes\">100</attribute>\n" +
- " <attribute name=\"timeToLiveSeconds\">3</attribute>\n" +
- " </region>\n" +
- " </config>\n" +
- " </attribute>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseEvictionConfig(element);
+ EvictionConfig cfg = new EvictionConfig();
+ cfg.setWakeupIntervalSeconds(1);
+ cfg.setDefaultEventQueueSize(200000);
+ cfg.setDefaultEvictionPolicyClass(LRUPolicy.class.getName());
+ List<EvictionRegionConfig> erc = new LinkedList<EvictionRegionConfig>();
+ cfg.setEvictionRegionConfigs(erc);
+ EvictionRegionConfig region1 = new EvictionRegionConfig();
+ region1.setRegionFqn(Fqn.ROOT);
+ LRUConfiguration epc1 = new LRUConfiguration();
+ epc1.setMaxNodes(5000);
+ epc1.setTimeToLiveSeconds(3);
+ region1.setEvictionPolicyConfig(epc1);
+
+ EvictionRegionConfig region2 = new EvictionRegionConfig();
+ region2.setRegionFqn(base);
+ LRUConfiguration epc2 = new LRUConfiguration();
+ epc2.setMaxNodes(100);
+ epc2.setTimeToLiveSeconds(3);
+ region2.setEvictionPolicyConfig(epc2);
+
+ erc.add(region1);
+ erc.add(region2);
+
+ return cfg;
}
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception
{
- cache_.stop();
- cache1_.stop();
+ cache1.stop();
+ cache2.stop();
}
- /**
- */
public void testActivationEvent() throws Exception
{
- String rootStr = "/org/jboss/test/data/";
- String rootStr1 = "/__JBossInternal__/5c4o12-pzhlhj-esnuy3sg-1-esnuy3sg-2";
- String str = rootStr + "0";
- cache_.removeNode(Fqn.ROOT);
+ Fqn internalFqn = Fqn.fromString("/__JBossInternal__/5c4o12-pzhlhj-esnuy3sg-1-esnuy3sg-2");
+ Fqn fqn = Fqn.fromRelativeElements(base, "0");
+ cache1.removeNode(Fqn.ROOT);
- cache_.put(str, str, str);
- cache_.put(rootStr1, str, str);
+ cache1.put(fqn, fqn.toString(), fqn.toString());
+ cache1.put(internalFqn, fqn.toString(), fqn.toString());
- TestingUtil.sleepThread(11000);
- Node n = cache1_.peek(Fqn.fromString(str), false, false);
- assert n == null || !n.getKeys().contains(str) : "UnversionedNode should not exist";
+ TestingUtil.sleepThread(wakeupIntervalMillis + 100);
+ Node n = cache2.peek(fqn, false);
+ assert n == null || !n.getKeys().contains(fqn) : "UnversionedNode should not exist";
String val;
- val = cache1_.get(str, str);
- val = cache1_.get(rootStr1, str);
- assertNotNull("DataNode should be activated ", val);
+ val = cache2.get(fqn, fqn.toString());
+ val = cache2.get(internalFqn, fqn.toString());
+ assertNotNull("Node should be activated ", val);
}
void log(String msg)
16 years, 6 months
JBoss Cache SVN: r6006 - searchable/trunk/src/test/java/org/jboss/cache/search.
by jbosscache-commits@lists.jboss.org
Author: navssurtani
Date: 2008-06-23 04:03:03 -0400 (Mon, 23 Jun 2008)
New Revision: 6006
Added:
searchable/trunk/src/test/java/org/jboss/cache/search/NodeModifiedTransactionContextTest.java
searchable/trunk/src/test/java/org/jboss/cache/search/SearchableCacheFactoryTest.java
searchable/trunk/src/test/java/org/jboss/cache/search/SearchableListenerTest.java
Modified:
searchable/trunk/src/test/java/org/jboss/cache/search/BlackBoxTest.java
Log:
Javadocced stuff.
Modified: searchable/trunk/src/test/java/org/jboss/cache/search/BlackBoxTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/BlackBoxTest.java 2008-06-20 01:27:44 UTC (rev 6005)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/BlackBoxTest.java 2008-06-23 08:03:03 UTC (rev 6006)
@@ -22,8 +22,8 @@
sc.put(Fqn.fromString("/a/b/c"), "Navin", p1);
// try and search for navin
- // TODO: Create a dummy lucene query
- //sc.createQuery(new LQ)
+ // TODO: Create a dummy lucene query
+ //sc.createQuery(new Query);
// TODO: Test should search on name, as well as blurb. Try both cases.
// TODO: Also test with stuff in different Fqns.
// TODO; test if the indexes get updated. Try changing the values of a Person object and put it back in the cache.
Added: searchable/trunk/src/test/java/org/jboss/cache/search/NodeModifiedTransactionContextTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/NodeModifiedTransactionContextTest.java (rev 0)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/NodeModifiedTransactionContextTest.java 2008-06-23 08:03:03 UTC (rev 6006)
@@ -0,0 +1,8 @@
+package org.jboss.cache.search;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ */
+public class NodeModifiedTransactionContextTest
+{
+}
Added: searchable/trunk/src/test/java/org/jboss/cache/search/SearchableCacheFactoryTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/SearchableCacheFactoryTest.java (rev 0)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/SearchableCacheFactoryTest.java 2008-06-23 08:03:03 UTC (rev 6006)
@@ -0,0 +1,28 @@
+package org.jboss.cache.search;
+
+import org.jboss.cache.Cache;
+import org.testng.annotations.Test;
+
+import java.util.Properties;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ */
+
+@Test
+public class SearchableCacheFactoryTest
+{
+
+ private Cache cache;
+ private Properties properties;
+ private Class[] classes;
+ private SearchableCacheFactory scf = new SearchableCacheFactory();
+
+ public void testCreateSearchableCache()
+ {
+ cache.start();
+ SearchableCache sc = scf.createSearchableCache(cache, properties, classes);
+
+ }
+
+}
Added: searchable/trunk/src/test/java/org/jboss/cache/search/SearchableListenerTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/SearchableListenerTest.java (rev 0)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/SearchableListenerTest.java 2008-06-23 08:03:03 UTC (rev 6006)
@@ -0,0 +1,14 @@
+package org.jboss.cache.search;
+
+import org.testng.annotations.Test;
+
+/**
+ * @author Navin Surtani - navin(a)surtani.org
+ */
+
+@Test
+public class SearchableListenerTest
+{
+
+
+}
16 years, 6 months
JBoss Cache SVN: r6005 - in core/branches/2.2.X/src: test/java/org/jboss/cache/buddyreplication and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: bstansberry(a)jboss.com
Date: 2008-06-19 21:27:44 -0400 (Thu, 19 Jun 2008)
New Revision: 6005
Modified:
core/branches/2.2.X/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java
core/branches/2.2.X/src/test/java/org/jboss/cache/buddyreplication/BuddyFqnTransformerTest.java
Log:
[JBCACHE-1374] BuddyFqnTransformer.getBackupRootFromFqn() handles "_BUDDY_BACKUP_"
Modified: core/branches/2.2.X/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java
===================================================================
--- core/branches/2.2.X/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java 2008-06-19 22:23:38 UTC (rev 6004)
+++ core/branches/2.2.X/src/main/java/org/jboss/cache/buddyreplication/BuddyFqnTransformer.java 2008-06-20 01:27:44 UTC (rev 6005)
@@ -145,7 +145,7 @@
*/
public Fqn getBackupRootFromFqn(Fqn fqn)
{
- if (isBackupFqn(fqn))
+ if (isBackupFqn(fqn) && fqn.size() > 1)
{
return fqn.getSubFqn(0, isDeadBackupFqn(fqn) ? 3 : 2);
}
Modified: core/branches/2.2.X/src/test/java/org/jboss/cache/buddyreplication/BuddyFqnTransformerTest.java
===================================================================
--- core/branches/2.2.X/src/test/java/org/jboss/cache/buddyreplication/BuddyFqnTransformerTest.java 2008-06-19 22:23:38 UTC (rev 6004)
+++ core/branches/2.2.X/src/test/java/org/jboss/cache/buddyreplication/BuddyFqnTransformerTest.java 2008-06-20 01:27:44 UTC (rev 6005)
@@ -34,4 +34,9 @@
{
assert Fqn.ROOT == buddyFqnTransformer.getActualFqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN);
}
+
+ public void testBackupRootFromFqnOnBuddyBackupRoot()
+ {
+ assert Fqn.ROOT == buddyFqnTransformer.getBackupRootFromFqn(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN);
+ }
}
16 years, 6 months
JBoss Cache SVN: r6004 - in searchable/trunk/src: test/java and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: navssurtani
Date: 2008-06-19 18:23:38 -0400 (Thu, 19 Jun 2008)
New Revision: 6004
Removed:
searchable/trunk/src/test/java/TransformerTest.java
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java
searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
searchable/trunk/src/main/java/org/jboss/cache/search/InvalidFqnException.java
searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.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
Log:
Javadocced stuff.
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java 2008-06-19 05:09:21 UTC (rev 6003)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQuery.java 2008-06-19 22:23:38 UTC (rev 6004)
@@ -6,7 +6,9 @@
/**
@author Navin Surtani - navin(a)surtani.org
- */
+
+
+*/
// TODO: Can we remove this?
public interface CacheQuery
{
@@ -23,7 +25,7 @@
/**
* Allows to use lucene filters.
- * Semi-deprecated? a preferred way is to use the @FullTextFilterDef approach
+ * A preferred way is to use the @FullTextFilterDef approach
*
* @param filter The lucene filter.
* @return this for method chaining
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-06-19 05:09:21 UTC (rev 6003)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/CacheQueryImpl.java 2008-06-19 22:23:38 UTC (rev 6004)
@@ -34,10 +34,11 @@
/**
* @author Navin Surtani - navin(a)surtani.org
+ *
+ * Implementation class of the FullTextQuery interface in Hibernate Search.
*/
public class CacheQueryImpl implements FullTextQuery
{
- //TODO: Javadoc all these methods
private Cache cache;
private Class[] classes;
private Sort sort;
@@ -69,18 +70,35 @@
}
+ /**
+ *Allows to let lucene sort the results.
+ *
+ *
+ * @param sort
+ * @return
+ */
public FullTextQuery setSort(Sort sort)
{
this.sort = sort;
return this;
}
+ /**
+ * Allows to use lucene filters.
+ *
+ * @param filter
+ * @return
+ */
public FullTextQuery setFilter(Filter filter)
{
this.filter = filter;
return this;
}
+ /**
+ *
+ * @return The result size of the query.
+ */
public int getResultSize()
{
if (resultSize == null)
@@ -113,7 +131,7 @@
}
catch (SearchException e)
{
- log.warn("Unable to properly close searcher during lucene query: " + e);
+ log.warn("Unable to properly close searcher during lucene query: " + e);
}
}
}
@@ -121,24 +139,45 @@
return this.resultSize;
}
+ /**
+ * Defines the Database Query used to load the Lucene results
+ *
+ * @param criteria
+ * @return
+ */
public FullTextQuery setCriteriaQuery(Criteria criteria)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * Defines the Lucene field names projected and returned in a query result Each field is converted back to it's object representation,
+ * an Object[] being returned for each "row" (similar to an HQL or a Criteria API projection).
+ * @param strings
+ * @return
+ */
public FullTextQuery setProjection(String... strings)
{
- return null; //TODO: Generated method. Do we need this method?
+
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
- private void closeSearcher(Searcher searcher, ReaderProvider readerProvider) {
- Set<IndexReader> indexReaders = getIndexReaders( searcher );
+ private void closeSearcher(Searcher searcher, ReaderProvider readerProvider)
+ {
+ Set<IndexReader> indexReaders = getIndexReaders(searcher);
- for (IndexReader indexReader : indexReaders) {
- readerProvider.closeReader( indexReader );
+ for (IndexReader indexReader : indexReaders)
+ {
+ readerProvider.closeReader(indexReader);
}
}
+ /**
+ * Enable a given filter by its name.
+ *
+ * @param name
+ * @return
+ */
public FullTextFilter enableFullTextFilter(String name)
{
if (filterDefinitions == null)
@@ -159,11 +198,21 @@
return filterDefinition;
}
+ /**
+ * Disable a given filter by its name.
+ *
+ * @param name
+ */
public void disableFullTextFilter(String name)
{
filterDefinitions.remove(name);
}
+ /**
+ *
+ * @param firstResult
+ * @return
+ */
public FullTextQuery setFirstResult(int firstResult)
{
if (firstResult < 0)
@@ -174,380 +223,711 @@
return this;
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setReadOnly(boolean b)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setCacheable(boolean b)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setCacheRegion(String s)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setTimeout(int i)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public String getQueryString()
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public Type[] getReturnTypes() throws HibernateException
{
- return new Type[0]; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public String[] getReturnAliases() throws HibernateException
{
- return new String[0]; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public String[] getNamedParameters() throws HibernateException
{
- return new String[0]; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public Iterator iterate() throws HibernateException
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public ScrollableResults scroll() throws HibernateException
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public List list() throws HibernateException
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public Object uniqueResult() throws HibernateException
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public int executeUpdate() throws HibernateException
{
- return 0; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
- public FullTextQuery setMaxResults(int maxResults) {
- if ( maxResults < 0 ) {
- throw new IllegalArgumentException( "'max' pagination parameter less than 0" );
+ public FullTextQuery setMaxResults(int maxResults)
+ {
+ if (maxResults < 0)
+ {
+ throw new IllegalArgumentException("'max' pagination parameter less than 0");
}
this.maxResults = maxResults;
return this;
}
- public FullTextQuery setFetchSize(int fetchSize) {
- if ( fetchSize <= 0 ) {
- throw new IllegalArgumentException( "'fetch size' parameter less than or equals to 0" );
+ public FullTextQuery setFetchSize(int fetchSize)
+ {
+ if (fetchSize <= 0)
+ {
+ throw new IllegalArgumentException("'fetch size' parameter less than or equals to 0");
}
this.fetchSize = fetchSize;
return this;
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setLockMode(String s, LockMode lockMode)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setComment(String s)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setFlushMode(FlushMode flushMode)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setCacheMode(CacheMode cacheMode)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setParameter(int i, Object o, Type type)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setParameter(String s, Object o, Type type)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setParameter(int i, Object o) throws HibernateException
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setParameter(String s, Object o) throws HibernateException
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setParameters(Object[] objects, Type[] types) throws HibernateException
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setParameterList(String s, Collection collection, Type type) throws HibernateException
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setParameterList(String s, Collection collection) throws HibernateException
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setParameterList(String s, Object[] objects, Type type) throws HibernateException
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setParameterList(String s, Object[] objects) throws HibernateException
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setProperties(Object o) throws HibernateException
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setProperties(Map map) throws HibernateException
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setString(int i, String s)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setCharacter(int i, char c)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setBoolean(int i, boolean b)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setByte(int i, byte b)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setShort(int i, short i1)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setInteger(int i, int i1)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setLong(int i, long l)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setFloat(int i, float v)
{
throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setDouble(int i, double v)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setBinary(int i, byte[] bytes)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setText(int i, String s)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setSerializable(int i, Serializable serializable)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setLocale(int i, Locale locale)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setBigDecimal(int i, BigDecimal bigDecimal)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setBigInteger(int i, BigInteger bigInteger)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setDate(int i, Date date)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setTime(int i, Date date)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setTimestamp(int i, Date date)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setCalendar(int i, Calendar calendar)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setCalendarDate(int i, Calendar calendar)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setString(String s, String s1)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setCharacter(String s, char c)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setBoolean(String s, boolean b)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setByte(String s, byte b)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
+
public org.hibernate.Query setShort(String s, short i)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setInteger(String s, int i)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setLong(String s, long l)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
public org.hibernate.Query setFloat(String s, float v)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setDouble(String s, double v)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setBinary(String s, byte[] bytes)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setText(String s, String s1)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setSerializable(String s, Serializable serializable)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setLocale(String s, Locale locale)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setBigDecimal(String s, BigDecimal bigDecimal)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setBigInteger(String s, BigInteger bigInteger)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setDate(String s, Date date)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setTime(String s, Date date)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setTimestamp(String s, Date date)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setCalendar(String s, Calendar calendar)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setCalendarDate(String s, Calendar calendar)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setEntity(int i, Object o)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public org.hibernate.Query setEntity(String s, Object o)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
+ /**
+ * This method is not supported in JBossCache Searchable and hence should not be called.
+ *
+ */
public FullTextQuery setResultTransformer(ResultTransformer resultTransformer)
{
- return null; //TODO: Generated method. Do we need this method?
+ throw new UnsupportedOperationException("Not supported in SearchableCache!");
}
private IndexSearcher buildSearcher(SearchFactoryImplementor searchFactoryImplementor)
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/InvalidFqnException.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/InvalidFqnException.java 2008-06-19 05:09:21 UTC (rev 6003)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/InvalidFqnException.java 2008-06-19 22:23:38 UTC (rev 6004)
@@ -4,6 +4,8 @@
/**
* @author Navin Surtani - navin(a)surtani.org
+ *
+ * Thrown when an invalid Fqn is passed into the generateId method in Transformer
*/
public class InvalidFqnException extends CacheException
{
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java 2008-06-19 05:09:21 UTC (rev 6003)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/NodeModifiedTransactionContext.java 2008-06-19 22:23:38 UTC (rev 6004)
@@ -7,12 +7,16 @@
import javax.transaction.Transaction;
/**
-@author Navin Surtani - navin(a)surtani.org
+ * @author Navin Surtani - navin(a)surtani.org
+
+ This class implements the TransactionContext interface in org.hibernate.search.transaction.
+
+ It is used by the SearchableListener so that a TransactionContext instance can be created.
+
*/
public class NodeModifiedTransactionContext implements TransactionContext
{
- //TODO: Javadoc all these methods
NodeModifiedEvent event;
public NodeModifiedTransactionContext(NodeModifiedEvent event)
@@ -20,16 +24,31 @@
this.event = event;
}
+ /**
+ * Returns a boolean value whether or not a transaction is in progress (JTA transaction and in this case *not*
+ * an org.hibernate transaction).
+ * @return
+ */
public boolean isTxInProgress()
{
return (event.getTransaction() != null);
}
+ /**
+ * Returns a JTA transaction as an object.
+ * @return
+ */
+
public Object getTransactionIdentifier()
{
return event.getTransaction();
}
+ /**
+ * Registers a synchronization from one passed as a parameter.
+ *
+ * @param synchronization
+ */
public void registerSynchronization(Synchronization synchronization)
{
Transaction transaction = event.getTransaction();
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java 2008-06-19 05:09:21 UTC (rev 6003)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCache.java 2008-06-19 22:23:38 UTC (rev 6004)
@@ -6,17 +6,31 @@
/**
@author Navin Surtani - navin(a)surtani.org
+
+ This will be the most used interface in JBossCache searchable. It extends Cache and therefore will have
+ the standard get(), put() and remove() methods. The additional method is the createQuery method which people
+ will use to build their Hibernate Search queries from a luceneQuery - Hibernate Search users will be very familiar
+ with this.
+
*/
public interface SearchableCache extends Cache
{
/**
+ * Creates a FullTextQuery object from a luceneQuery.
*
* @param luceneQuery
* @return
*/
public FullTextQuery createQuery(Query luceneQuery);
+ /**
+ * Creates a FullTextQuery from a lucene query and a class array.
+ *
+ * @param luceneQuery
+ * @param classes
+ * @return
+ */
public FullTextQuery createQuery(Query luceneQuery, Class... classes);
}
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java 2008-06-19 05:09:21 UTC (rev 6003)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java 2008-06-19 22:23:38 UTC (rev 6004)
@@ -12,14 +12,28 @@
*/
public class SearchableCacheFactory
{
- //TODO: Javadoc everything.
private SearchFactoryImpl searchFactory;
+ /**
+ * Creates a searchable cache from a cache object and a class array, without the properties object.
+ *
+ * @param c
+ * @param classes
+ * @return
+ */
public SearchableCache createSearchableCache (Cache c, Class... classes)
{
return createSearchableCache(c, null, classes);
}
+ /**
+ * This method creates a searchable cache as well but requires the properties object.
+ *
+ * @param c
+ * @param properties
+ * @param classes
+ * @return
+ */
public SearchableCache createSearchableCache (Cache c, Properties properties, Class... classes)
{
// assume cache is already created and running.
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-06-19 05:09:21 UTC (rev 6003)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheImpl.java 2008-06-19 22:23:38 UTC (rev 6004)
@@ -20,6 +20,8 @@
/**
@author Navin Surtani - navin(a)surtani.org
+
+ Implementation class for the SearchableCache interface.
*/
public class SearchableCacheImpl implements SearchableCache
{
@@ -27,7 +29,7 @@
private Cache cache;
private SearchFactoryImpl searchFactory;
- //TODO: Javadoc all these methods
+ //TODO: Does the impl class have to be javadocced?
public SearchableCacheImpl(Cache cache, SearchFactoryImpl searchFactory)
{
@@ -35,6 +37,7 @@
this.searchFactory = searchFactory;
}
+
public FullTextQuery createQuery(Query luceneQuery)
{
return new CacheQueryImpl(luceneQuery, searchFactory, cache);
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-06-19 05:09:21 UTC (rev 6003)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableListener.java 2008-06-19 22:23:38 UTC (rev 6004)
@@ -12,14 +12,23 @@
/**
* @author Navin Surtani - navin(a)surtani.org
+ *
+ * Class that listens for changes made to the cache so that the Lucene indexes can be updated.
*/
@CacheListener
public class SearchableListener
{
- //TODO: Javadoc everything
private SearchFactoryImpl searchFactory;
+ /**
+ * Takes in a NodeModifiedEvent and updates the Lucene indexes using methods on the NodeModifiedEvent class.
+ *
+ *
+ * @param event
+ */
+
+
@NodeModified
public void updateLuceneIndexes(NodeModifiedEvent event)
{
@@ -38,6 +47,12 @@
}
}
+ /**
+ * 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
+ */
void handlePutData(NodeModifiedEvent event)
{
Map dataMap = event.getData();
@@ -55,6 +70,12 @@
}
+ /**
+ * If the modification type is DELETE_DATA then this method will be called.
+ * Takes in the event as a parameter
+ *
+ * @param event
+ */
void handleDeleteData(NodeModifiedEvent event)
{
Map dataMap = event.getData();
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-06-19 05:09:21 UTC (rev 6003)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-06-19 22:23:38 UTC (rev 6004)
@@ -4,10 +4,24 @@
/**
@author Navin Surtani - navin(a)surtani.org
- */
+
+* This class is one that does all the 'conversion' work between JBossCache and Hibernate Search. This is where
+* users can switch from Fqn and key to a documentId and vice versa.
+*
+* If the Fqn is in the form /a/b/c and the key - which has to be a String - is keystring; the documentId - which is also
+* a String - will be "Fqn=[/a/b/c]Key=[keystring]"
+*
+*/
public class Transformer
{
- //TODO: Javadoc everything
+ /**
+ * Takes in the documentId string from the user and will return the key from the Fqn, key combination.
+ *
+ *
+ * @param docId
+ * @return
+ */
+
public static String getKey(String docId)
{
//docID comes in the format "Fqn=[/a/b/c]Key=[key]"
@@ -28,6 +42,14 @@
return key;
}
+ /**
+ * Takes in the documentId string from the user and will return the Fqn from the Fqn, key combination.
+ *
+ * @param docId
+ * @return
+ */
+
+
public static Fqn getFqn(String docId)
{
//docId comes in the format "Fqn=[/a/b/c]Key=[key]"
@@ -46,6 +68,16 @@
return fqn;
}
+ /**
+ * Generates the documentId from an Fqn, key combination.
+ *
+ *
+ * @param fqn
+ * @param key
+ * @return
+ * @throws InvalidFqnException
+ */
+
public static String generateId(Fqn fqn, String key) throws InvalidFqnException
{
if (key == null) throw new InvalidFqnException("Key passed in cannot be null!");
Deleted: searchable/trunk/src/test/java/TransformerTest.java
===================================================================
--- searchable/trunk/src/test/java/TransformerTest.java 2008-06-19 05:09:21 UTC (rev 6003)
+++ searchable/trunk/src/test/java/TransformerTest.java 2008-06-19 22:23:38 UTC (rev 6004)
@@ -1,53 +0,0 @@
-import org.jboss.cache.Fqn;
-import org.jboss.cache.search.Transformer;
-import org.testng.annotations.Test;
-
-/**
- * Created by IntelliJ IDEA.
- * User: navin
- * Date: Jun 4, 2008
- * Time: 3:52:58 PM
- * To change this template use File | Settings | File Templates.
- */
-
-@Test
-public class TransformerTest
-{
- public void testGenerateId()
- {
-
- Fqn fqn = Fqn.fromString("/a/b/c");
- String key = "key";
-
- String generatedId = Transformer.generateId(fqn, key);
-
- assert generatedId.contentEquals("Fqn=[/a/b/c]Key=[key]");
-
- assert ! generatedId.contentEquals("/ab/c/d");
- }
-
- public void testGetFqn()
- {
- Fqn fqn = Transformer.getFqn("Fqn=[/cat/dog/person]Key=[key]");
-
- Fqn expectedFqn = Fqn.fromString("/cat/dog/person");
-
- assert fqn.equals(expectedFqn);
-
- expectedFqn = Fqn.fromString("/dog/cat/person");
-
- assert !fqn.equals(expectedFqn);
-
- }
-
- public void testGetKey()
- {
- String key = Transformer.getKey("Fqn=[/a/b/c]Key=[thisIsMyKey]");
-
- assert key.contentEquals("thisIsMyKey");
-
- assert ! key.contentEquals("thisIsNotMyKey");
-
- }
-
-}
Modified: searchable/trunk/src/test/java/org/jboss/cache/search/TransformerTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/TransformerTest.java 2008-06-19 05:09:21 UTC (rev 6003)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/TransformerTest.java 2008-06-19 22:23:38 UTC (rev 6004)
@@ -5,12 +5,20 @@
/**
@author Navin Surtani - navin(a)surtani.org
+
+ Unit-test class for the Transformer class.
*/
@Test
public class TransformerTest
+ //TODO: How best to javadoc the exception methods?
+
{
- //TODO: Javadoc everything
+ /**
+ * Tests the generateId method.
+ *
+ */
+
public void testGenerateId()
{
@@ -24,6 +32,10 @@
assert ! generatedId.contentEquals("/ab/c/d");
}
+ /**
+ * Tests the getFqn method.
+ *
+ */
public void testGetFqn()
{
Fqn fqn = Transformer.getFqn("Fqn=[/cat/dog/person]Key=[key]");
@@ -38,6 +50,9 @@
}
+ /**
+ * Tests the getKey method.
+ */
public void testGetKey()
{
String key = Transformer.getKey("Fqn=[/a/b/c]Key=[thisIsMyKey]");
16 years, 6 months
JBoss Cache SVN: r6003 - in pojo/trunk/src: main/java/org/jboss/cache/pojo/impl and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-06-19 01:09:21 -0400 (Thu, 19 Jun 2008)
New Revision: 6003
Modified:
pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedObjectArray.java
pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/CacheListenerAdaptor.java
pojo/trunk/src/test/java/org/jboss/cache/pojo/ArrayTest.java
Log:
Add notification support for arrays
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedObjectArray.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedObjectArray.java 2008-06-17 23:59:38 UTC (rev 6002)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CachedObjectArray.java 2008-06-19 05:09:21 UTC (rev 6003)
@@ -23,6 +23,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.pojo.impl.ArrayInterceptable;
+import org.jboss.cache.pojo.impl.InternalConstant;
import org.jboss.cache.pojo.impl.PojoCacheImpl;
import org.jboss.cache.pojo.util.AopUtil;
import org.jboss.cache.pojo.util.Null;
@@ -49,6 +50,7 @@
Fqn<?> fqn = AopUtil.constructFqn(this.fqn, IntegerCache.toString(index));
cache.attach(fqn, Null.toNullObject(element), null, arraySource);
+ cache.getCache().put(fqn, InternalConstant.POJOCACHE_OPERATION, "SET");
}
public Object get(int index)
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/CacheListenerAdaptor.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/CacheListenerAdaptor.java 2008-06-17 23:59:38 UTC (rev 6002)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/CacheListenerAdaptor.java 2008-06-19 05:09:21 UTC (rev 6003)
@@ -22,10 +22,10 @@
package org.jboss.cache.pojo.impl;
+import static org.jboss.cache.notifications.event.Event.Type.TRANSACTION_COMPLETED;
+import static org.jboss.cache.notifications.event.Event.Type.TRANSACTION_REGISTERED;
import static org.jboss.cache.pojo.impl.InternalConstant.POJOCACHE_OPERATION;
import static org.jboss.cache.pojo.impl.InternalConstant.POJOCACHE_STATUS;
-import static org.jboss.cache.notifications.event.Event.Type.TRANSACTION_COMPLETED;
-import static org.jboss.cache.notifications.event.Event.Type.TRANSACTION_REGISTERED;
import java.lang.reflect.Field;
import java.util.Collection;
@@ -50,6 +50,7 @@
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.interceptors.PojoTxLockInterceptor;
import org.jboss.cache.pojo.notification.NotificationContext;
+import org.jboss.cache.pojo.notification.event.ArrayModifiedEvent;
import org.jboss.cache.pojo.notification.event.AttachedEvent;
import org.jboss.cache.pojo.notification.event.DetachedEvent;
import org.jboss.cache.pojo.notification.event.Event;
@@ -220,6 +221,11 @@
Object value = cache.find(fqn.toString());
sendNotification(new MapModifiedEvent(createContext(event), (Map) collection, operation, fqn.getLastElement(), value, isLocal), matched);
}
+ else if (collection instanceof Object[]) {
+ int i = Integer.parseInt(fqn.getLastElementAsString());
+ Object value = cache.find(fqn.toString());
+ sendNotification(new ArrayModifiedEvent(createContext(event), collection, i, value, isLocal), matched);
+ }
}
else if ("ATTACHED".equals(cache.getCache().get(fqn, POJOCACHE_STATUS)))
{
Modified: pojo/trunk/src/test/java/org/jboss/cache/pojo/ArrayTest.java
===================================================================
--- pojo/trunk/src/test/java/org/jboss/cache/pojo/ArrayTest.java 2008-06-17 23:59:38 UTC (rev 6002)
+++ pojo/trunk/src/test/java/org/jboss/cache/pojo/ArrayTest.java 2008-06-19 05:09:21 UTC (rev 6003)
@@ -9,6 +9,8 @@
import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Queue;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -24,6 +26,9 @@
import org.jboss.cache.notifications.event.NodeEvent;
import org.jboss.cache.notifications.event.NodeModifiedEvent;
import org.jboss.cache.notifications.event.NodeVisitedEvent;
+import org.jboss.cache.pojo.notification.annotation.ArrayModified;
+import org.jboss.cache.pojo.notification.annotation.PojoCacheListener;
+import org.jboss.cache.pojo.notification.event.ArrayModifiedEvent;
import org.jboss.cache.pojo.test.ArrayObject;
import org.jboss.cache.pojo.test.ArrayObject.Person;
import org.testng.AssertJUnit;
@@ -47,11 +52,11 @@
{
log.info("setUp() ....");
cache1 = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
- cache1.getCache().addCacheListener(new MyCacheListener(false));
+ //cache1.getCache().addCacheListener(new MyCacheListener(false));
cache1.start();
cache2 = PojoCacheFactory.createCache(UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC), false);
- cache2.getCache().addCacheListener(new MyCacheListener(true));
+ //cache2.getCache().addCacheListener(new MyCacheListener(false));
cache2.start();
}
@@ -99,6 +104,36 @@
AssertJUnit.assertEquals(4, obj.getNum(5));
}
+ public void testArrayNotifications() throws Exception
+ {
+
+ ArrayObject ao = new ArrayObject();
+ Person joe = new Person();
+ joe.setName("Joe");
+ joe.setAge(19);
+
+ Person ben = new Person();
+ ben.setName("Ben");
+ ben.setAge(19);
+ cache1.attach("/ao", ao);
+
+ ArrayListener listener = new ArrayListener();
+ cache1.addListener(listener);
+ ao.setPerson(0, joe);
+ ao.setPerson(1, ben);
+
+ ArrayModifiedEvent event = listener.take();
+ AssertJUnit.assertSame(ao.getTeam(), event.getSource());
+ AssertJUnit.assertSame(joe, event.getValue());
+ AssertJUnit.assertEquals(0, event.getIndex());
+
+ event = listener.take();
+ AssertJUnit.assertSame(ao.getTeam(), event.getSource());
+ AssertJUnit.assertSame(ben, event.getValue());
+ AssertJUnit.assertEquals(1, event.getIndex());
+ cache1.removeListener(listener);
+ }
+
public void testMulti() throws Exception
{
log.info("testMulti() ....");
@@ -133,8 +168,25 @@
AssertJUnit.assertSame(ao.getMultiPerson(1, 1, 5), ao.getMultiPerson(2, 1, 4));
}
+ @PojoCacheListener
+ public static class ArrayListener
+ {
+ private Queue<ArrayModifiedEvent> events = new LinkedList<ArrayModifiedEvent>();
+
+ @ArrayModified
+ public void record(ArrayModifiedEvent event)
+ {
+ events.offer(event);
+ }
+
+ public ArrayModifiedEvent take()
+ {
+ return events.poll();
+ }
+ }
+
@CacheListener
- public class MyCacheListener
+ public static class MyCacheListener
{
private boolean visits;
16 years, 6 months