[exo-jcr-commits] exo-jcr SVN: r1300 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test: java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Jan 5 12:23:14 EST 2010
Author: areshetnyak
Date: 2010-01-05 12:23:13 -0500 (Tue, 05 Jan 2010)
New Revision: 1300
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestExoEvictionActionPolicy.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-exo-config.xml
Log:
EXOJCR-333 : The test TestExoEvictionActionPolicy was added.
Added: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestExoEvictionActionPolicy.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestExoEvictionActionPolicy.java (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestExoEvictionActionPolicy.java 2010-01-05 17:23:13 UTC (rev 1300)
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
+
+import java.io.Serializable;
+
+import org.exoplatform.services.cache.CacheListenerContext;
+import org.exoplatform.services.jcr.JcrImplBaseTest;
+import org.exoplatform.services.jcr.access.AccessControlList;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
+import org.exoplatform.services.jcr.util.IdGenerator;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.NodeEvicted;
+import org.jboss.cache.notifications.event.NodeEvent;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date: 2010
+ *
+ * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a>
+ * @version $Id$
+ */
+ at CacheListener
+public class TestExoEvictionActionPolicy
+ extends JcrImplBaseTest
+{
+ protected Cache<Serializable, Object> cache;
+
+ protected Fqn<String> itemsRoot;
+
+ protected Fqn<String> childNodesList;
+
+ protected Fqn<String> childPropsList;
+
+ protected String jbcConfig;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ initJBCConfig();
+
+ cache = new DefaultCacheFactory<Serializable, Object>().createCache(jbcConfig, false);
+
+ cache.create();
+ cache.start();
+
+ Node<Serializable, Object> cacheRoot = cache.getRoot();
+
+ this.itemsRoot = Fqn.fromElements(JBossCacheWorkspaceStorageCache.ITEMS);
+ cacheRoot.addChild(this.itemsRoot).setResident(true);
+
+ this.childNodesList = Fqn.fromElements(JBossCacheWorkspaceStorageCache.CHILD_NODES_LIST);
+ cacheRoot.addChild(this.childNodesList).setResident(true);
+
+ this.childPropsList = Fqn.fromElements(JBossCacheWorkspaceStorageCache.CHILD_PROPS_LIST);
+ cacheRoot.addChild(this.childPropsList).setResident(true);
+ }
+
+ protected void initJBCConfig()
+ {
+ jbcConfig = "src/test/resources/conf/standalone/test-jbosscache-exo-config.xml";
+ }
+
+ public void testEviction() throws Exception
+ {
+
+ String evictionNodeId = IdGenerator.generate();
+
+ TransientNodeData evictionNodeData = new TransientNodeData(QPath.parse("[]:1[]node:1"), evictionNodeId, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ IdGenerator.generate(), new AccessControlList());
+
+ String evictionPropId = IdGenerator.generate();
+
+ TransientPropertyData evictionPropData = new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, InternalQName.parse("[]prop1")), evictionPropId, 1, 1, evictionNodeId, false);
+ String propValue1 = "Property value #1";
+ evictionPropData.setValue(new TransientValueData(propValue1));
+
+ // add nodes who will be eviction
+ // put NodeData
+ cache.put(Fqn.fromRelativeElements(itemsRoot, evictionNodeData.getIdentifier()), JBossCacheWorkspaceStorageCache.ITEM_DATA, evictionNodeData);
+
+ // put PropertyData
+ cache.put(Fqn.fromRelativeElements(itemsRoot, evictionPropData.getIdentifier()), JBossCacheWorkspaceStorageCache.ITEM_DATA, evictionPropData);
+
+ // put to CHILD_NODES_LIST
+ cache.put(Fqn.fromRelativeElements(childNodesList, evictionNodeData.getParentIdentifier(), evictionNodeData.getIdentifier()), JBossCacheWorkspaceStorageCache.NULL_DATA);
+
+ for (int i = 0 ; i < 10; i++)
+ cache.put(Fqn.fromRelativeElements(childNodesList, evictionNodeData.getParentIdentifier(), IdGenerator.generate()), JBossCacheWorkspaceStorageCache.NULL_DATA);
+
+ // put to CHILD_PROPS_LIST
+ cache.put(Fqn.fromRelativeElements(childPropsList, evictionPropData.getParentIdentifier(), evictionPropData.getIdentifier()), JBossCacheWorkspaceStorageCache.NULL_DATA);
+
+ for (int i = 0 ; i < 10; i++)
+ cache.put(Fqn.fromRelativeElements(childPropsList, evictionPropData.getParentIdentifier(), IdGenerator.generate()), JBossCacheWorkspaceStorageCache.NULL_DATA);
+
+
+ // check for exists
+ assertEquals( 2, cache.getChildrenNames(itemsRoot).size());
+ assertNotNull(cache.getNode(Fqn.fromRelativeElements(itemsRoot, evictionNodeData.getIdentifier())));
+ assertNotNull(cache.getNode(Fqn.fromRelativeElements(itemsRoot, evictionPropData.getIdentifier())));
+
+ assertNotNull(cache.getNode(Fqn.fromRelativeElements(childNodesList, evictionNodeData.getParentIdentifier(), evictionNodeData.getIdentifier())));
+ assertNotNull(cache.getNode(Fqn.fromRelativeElements(childPropsList, evictionPropData.getParentIdentifier(), evictionPropData.getIdentifier())));
+
+ assertEquals( 11, cache.getChildrenNames(Fqn.fromRelativeElements(childNodesList, evictionNodeData.getParentIdentifier())).size());
+ assertEquals( 11, cache.getChildrenNames(Fqn.fromRelativeElements(childPropsList, evictionPropData.getParentIdentifier())).size());
+
+
+ Thread.sleep(10 * 1000);
+
+ cache.addCacheListener(this);
+
+ for (int i = 0 ; i< 50; i++)
+ {
+ TransientNodeData evicNodeData = new TransientNodeData(QPath.parse("[]:1[]node" + i + ":1"), IdGenerator.generate(), 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ Constants.ROOT_UUID, new AccessControlList());
+ cache.put(Fqn.fromRelativeElements(itemsRoot, evicNodeData.getIdentifier()), JBossCacheWorkspaceStorageCache.ITEM_DATA, evicNodeData);
+ }
+
+ Thread.sleep(15 * 1000);
+
+ // check
+ assertNull(cache.getNode(Fqn.fromRelativeElements(itemsRoot, evictionNodeData.getIdentifier())));
+ assertNull(cache.getNode(Fqn.fromRelativeElements(itemsRoot, evictionPropData.getIdentifier())));
+
+ assertNull(cache.getNode(Fqn.fromRelativeElements(childNodesList, evictionNodeData.getParentIdentifier())));
+ assertNull(cache.getNode(Fqn.fromRelativeElements(childPropsList, evictionPropData.getParentIdentifier())));
+ }
+
+ @NodeEvicted
+ public void createdNodeEvent(NodeEvent ne)
+ {
+ System.out.println("Node evicred: " + ne.getFqn());
+ }
+
+
+ public void testEvictionRecurcive() throws Exception
+ {
+ String parentId = IdGenerator.generate();
+
+ // put to CHILD_PROPS_LIST
+ cache.put(Fqn.fromRelativeElements(childPropsList, parentId, IdGenerator.generate()), JBossCacheWorkspaceStorageCache.NULL_DATA);
+
+ for (int i = 0 ; i < 10; i++)
+ cache.put(Fqn.fromRelativeElements(childPropsList, parentId, IdGenerator.generate()), JBossCacheWorkspaceStorageCache.NULL_DATA);
+
+
+ assertEquals( 11, cache.getChildrenNames(Fqn.fromRelativeElements(childPropsList, parentId)).size());
+
+ cache.evict(Fqn.fromRelativeElements(childPropsList, parentId), true);
+
+ assertNull(cache.getNode(Fqn.fromRelativeElements(childPropsList, parentId)));
+ }
+}
Property changes on: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/TestExoEvictionActionPolicy.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-exo-config.xml
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-exo-config.xml (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-exo-config.xml 2010-01-05 17:23:13 UTC (rev 1300)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:jboss:jbosscache-core:config:3.1">
+
+ <locking useLockStriping="false" concurrencyLevel="50000" lockParentForChildInsertRemove="false" lockAcquisitionTimeout="3600000"/>
+
+ <!-- Configure the TransactionManager -->
+ <transaction transactionManagerLookupClass="org.jboss.cache.transaction.JBossStandaloneJTAManagerLookup" />
+
+ <!-- Enable batching -->
+ <invocationBatching enabled="true" />
+
+ <!-- Eviction configuration -->
+ <eviction wakeUpInterval="3000">
+ <default algorithmClass="org.jboss.cache.eviction.LRUAlgorithm">
+ <property name="maxNodes" value="50" />
+ <property name="timeToLiveSeconds" value="20" />
+ </default>
+ <region name="/" algorithmClass="org.jboss.cache.eviction.LRUAlgorithm" actionPolicyClass="org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache.ExoEvictionActionPolicy" eventQueueSize="1000000">
+ <property name="maxNodes" value="50" />
+ <property name="timeToLiveSeconds" value="20" />
+ </region>
+ </eviction>
+
+</jbosscache>
Property changes on: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/resources/conf/standalone/test-jbosscache-exo-config.xml
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the exo-jcr-commits
mailing list