[jbosscache-commits] JBoss Cache SVN: r6008 - in core/trunk/src: test/java/org/jboss/cache/notifications and 1 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Mon Jun 23 13:12:53 EDT 2008


Author: manik.surtani at 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 at jboss.org">manik at jboss.org</a>)
+ * @since 3.0
+ */
+ at 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
- */
- at Test(groups = {"functional", "jgroups"})
+import java.util.LinkedList;
+import java.util.List;
+
+ at 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)




More information about the jbosscache-commits mailing list