exo-jcr SVN: r596 - jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2009-11-12 08:33:43 -0500 (Thu, 12 Nov 2009)
New Revision: 596
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
Log:
EXOJCR-201 : The JDBCCacheLoaderTest was changed.
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12 13:18:52 UTC (rev 595)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12 13:33:43 UTC (rev 596)
@@ -18,20 +18,31 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+
import org.apache.commons.dbcp.BasicDataSourceFactory;
import org.exoplatform.services.idgenerator.impl.IDGeneratorServiceImpl;
import org.exoplatform.services.jcr.access.AccessControlList;
-import org.exoplatform.services.jcr.config.CacheEntry;
import org.exoplatform.services.jcr.config.ContainerEntry;
-import org.exoplatform.services.jcr.config.LockManagerEntry;
-import org.exoplatform.services.jcr.config.LockPersisterEntry;
-import org.exoplatform.services.jcr.config.QueryHandlerEntry;
import org.exoplatform.services.jcr.config.RepositoryEntry;
import org.exoplatform.services.jcr.config.SimpleParameterEntry;
import org.exoplatform.services.jcr.config.ValueStorageEntry;
import org.exoplatform.services.jcr.config.ValueStorageFilterEntry;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.ItemData;
+import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.datamodel.ValueData;
@@ -47,19 +58,6 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
-import java.io.InputStream;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.sql.DataSource;
-
/**
* @author <a href="mailto:reshetnyak.alex@gmail.com">Alex Reshetnyak</a>
* @version $Id$
@@ -248,7 +246,7 @@
WorkspaceStorageConnection conn = persistentContainer.openConnection();
// add root (/) with jcr:primaryType
- addDbNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.NT_UNSTRUCTURED);
+ addDbNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.NT_UNSTRUCTURED, null);
// add property (/jcr:mixinTypes)
List<InternalQName> mixins = new ArrayList<InternalQName>();
@@ -266,7 +264,7 @@
WorkspaceStorageConnection conn = persistentContainer.openConnection();
// add root (/) with jcr:primaryType
- addDbNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.NT_UNSTRUCTURED);
+ addDbNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.NT_UNSTRUCTURED, null);
// add property (/jcr:mixinTypes)
List<InternalQName> mixins = new ArrayList<InternalQName>();
@@ -279,7 +277,7 @@
}
/**
- * Add Property to the connection but doesn't save it.
+ * Add Node to the connection but doesn't save it.
*
* @param conn WorkspaceStorageConnection
* @param root QPath
@@ -287,15 +285,44 @@
* @param primaryType InternalQName
* @throws Exception
*/
- private void addDbNode(WorkspaceStorageConnection conn, QPath root, String nodeId, InternalQName primaryType)
+ private void addDbNode(WorkspaceStorageConnection conn, QPath root, String nodeId, InternalQName primaryType, InternalQName[] mixinTypeNames)
throws Exception
{
- // add root (/)
- conn.add(new TransientNodeData(root, nodeId, 1, primaryType, new InternalQName[0], 0, null,
+ // create node with property jcr:primaryType
+ List<ItemData> list = createNode(root, nodeId, primaryType, mixinTypeNames);
+
+ // add node with property jcr:primaryType
+ for (ItemData itemData : list)
+ {
+ if (itemData instanceof NodeData)
+ conn.add((NodeData)itemData);
+ else
+ conn.add((PropertyData)itemData);
+ }
+ }
+
+ /**
+ * Create Node to the connection but doesn't save it.
+ *
+ * @param path QPath
+ * @param nodeId String
+ * @param primaryType InternalQName
+ * @param mixinTypeNames InternalQName
+ * @throws Exception
+ */
+ private List<ItemData> createNode(QPath path, String nodeId, InternalQName primaryType, InternalQName[] mixinTypeNames)
+ throws Exception
+ {
+ List<ItemData> list = new ArrayList<ItemData>();
+
+ // add node
+ list.add(new TransientNodeData(path, nodeId, 1, primaryType, (mixinTypeNames == null ? new InternalQName[0] : null), 0, null,
new AccessControlList()));
// add property (/jcr:primaryType)
- addDbProperty(conn, root, Constants.ROOT_UUID, Constants.JCR_PRIMARYTYPE, primaryType, false);
+ list.add(createProperty(path, Constants.ROOT_UUID, Constants.JCR_PRIMARYTYPE, primaryType, false));
+
+ return list;
}
/**
@@ -400,7 +427,6 @@
// tests
WorkspaceStorageConnection conn = persistentContainer.openConnection();
- //??? Map<Serializable, Object> data = cache.getData(Fqn.fromString("/"+JBossCacheStorage.NODES + "/" + Constants.ROOT_UUID));
}
public void testAddProperty() throws Exception
@@ -506,15 +532,24 @@
connection.commit();
// tests it
- connection = persistentContainer.openConnection();
+ Map<Object, Object> attrebutes = loader.get(Fqn.fromString("/"+JBossCacheStorage.PROPS + "/" + propData.getIdentifier()));
- PropertyData destPropData = (PropertyData) connection.getItemData(propData.getIdentifier());
+ assertNotNull(attrebutes);
- Map<Object, Object> attrebutes = loader.get(Fqn.fromString("/"+JBossCacheStorage.PROPS + "/" + propData.getIdentifier()));
+ PropertyData destPropData = (PropertyData) attrebutes.get(JBossCacheStorage.ITEM_DATA);
- assertNotNull(attrebutes);
+ assertNotNull(destPropData);
+ assertEquals(propData.getIdentifier(), destPropData.getIdentifier());
+ assertEquals(propData.getParentIdentifier(), destPropData.getParentIdentifier());
+ assertEquals(propData.getPersistedVersion(), destPropData.getPersistedVersion());
+ assertEquals(propData.getType(), destPropData.getType());
+ assertEquals(propData.getQPath(), destPropData.getQPath());
+ assertEquals(propData.getValues().size(), destPropData.getValues().size());
+ assertEquals(1, destPropData.getValues().size());
+
+ ValueData valueData = destPropData.getValues().get(0);
+ assertEquals("JCR DATA VALUE", new String (valueData.getAsByteArray(), "UTF-8"));
-
}
public void testGetPropertyByName() throws Exception
16 years, 8 months
exo-jcr SVN: r595 - in jcr/branches/1.12.0-JBC/component/core/src: main/java/org/exoplatform/services/jcr/impl/storage/jbosscache and 1 other directories.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2009-11-12 08:18:52 -0500 (Thu, 12 Nov 2009)
New Revision: 595
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java
Log:
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java 2009-11-12 11:20:31 UTC (rev 594)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java 2009-11-12 13:18:52 UTC (rev 595)
@@ -18,8 +18,6 @@
*/
package org.exoplatform.services.jcr.impl.core.observation;
-import org.exoplatform.services.jcr.core.NamespaceAccessor;
-import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
import org.exoplatform.services.jcr.dataflow.ChangesLogIterator;
import org.exoplatform.services.jcr.dataflow.CompositeChangesLog;
@@ -31,7 +29,6 @@
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.QPath;
-import org.exoplatform.services.jcr.impl.core.LocationFactory;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.exoplatform.services.jcr.impl.core.SessionRegistry;
import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
@@ -66,7 +63,6 @@
private final SessionRegistry sessionRegistry;
private final NodeTypeDataManager ntManager;
-
public ActionLauncher(ObservationManagerRegistry registry, WorkspacePersistentDataManager workspaceDataManager,
NodeTypeDataManager ntManager, SessionRegistry sessionRegistry)
@@ -130,8 +126,14 @@
}
if (events.size() > 0)
{
- // TCK says, no events - no onEvent() action
- listener.onEvent(events);
+ try
+ {
+ listener.onEvent(events);
+ }
+ catch (RuntimeException e)
+ {
+ log.warn("Listener is in error, skipping", e);
+ }
}
}
}
@@ -157,7 +159,6 @@
// 8.3.3 Only events whose associated parent node is at absPath (or
// within its subtree, if isDeep is true) will be received.
QPath itemPath = item.getQPath();
-
return itemPath.isDescendantOf(criteria.getAbsPath(), !criteria.isDeep());
}
@@ -208,20 +209,9 @@
}
}
- for (int i = 0; i < criteria.getNodeTypeName().length; i++)
+ for (InternalQName typeName : criteria.getNodeTypeName())
{
- NodeTypeData criteriaNT = ntManager.getNodeType(criteria.getNodeTypeName()[i]);
- InternalQName[] testQNames;
- if (criteriaNT.isMixin())
- {
- testQNames = node.getMixinTypeNames();
- }
- else
- {
- testQNames = new InternalQName[1];
- testQNames[0] = node.getPrimaryTypeName();
- }
- if (ntManager.isNodeType(criteriaNT.getName(), testQNames))
+ if (ntManager.isNodeType(typeName, node.getPrimaryTypeName(), node.getMixinTypeNames()))
return true;
}
return false;
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java 2009-11-12 11:20:31 UTC (rev 594)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java 2009-11-12 13:18:52 UTC (rev 595)
@@ -20,7 +20,6 @@
import org.exoplatform.services.jcr.core.NamespaceAccessor;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
-import org.exoplatform.services.jcr.impl.core.LocationFactory;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.exoplatform.services.jcr.impl.core.SessionRegistry;
import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
@@ -67,7 +66,7 @@
this.listenersMap = new HashMap<EventListener, ListenerCriteria>();
this.nodeTypeDataManager = nodeTypeDataManager;
this.workspaceDataManager = workspaceDataManager;
- //this.launcher = new ActionLauncher(this, workspaceDataManager, nodeTypeDataManager, sessionRegistry);
+ this.launcher = new ActionLauncher(this, workspaceDataManager, nodeTypeDataManager, sessionRegistry);
}
public ObservationManagerImpl createObservationManager(SessionImpl session)
@@ -115,9 +114,13 @@
}
// TODO: remove hardcode
+ /**
+ * Was created only for ObservationCacheLoader. For lab-purposes only
+ */
+ @Deprecated
public NodeTypeDataManager getNodeTypeDataManager()
{
return nodeTypeDataManager;
}
-
+
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java 2009-11-12 11:20:31 UTC (rev 594)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java 2009-11-12 13:18:52 UTC (rev 595)
@@ -45,10 +45,13 @@
import javax.jcr.observation.EventListenerIterator;
/**
+ * This class is for lab-purposes only!
+ *
* @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
* @version $Id: ObservationCacheLoader.java 34360 2009-07-22 23:58:59Z aheritier $
*
*/
+@Deprecated
public class ObservationCacheLoader extends AbstractWriteOnlyCacheLoader
{
public final int SKIP_EVENT = Integer.MIN_VALUE;
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java 2009-11-12 11:20:31 UTC (rev 594)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoaderTest.java 2009-11-12 13:18:52 UTC (rev 595)
@@ -120,7 +120,7 @@
loader.injectDependencies(registry, new DummyWorkspaceDataContainer(workspaceStorageConnection), accessor);
}
- public void testFilterByUUID() throws Exception
+ public void _testFilterByUUID() throws Exception
{
QPath node1path = QPath.parse("[]:1[]node:1");
NodeData newNode =
@@ -141,7 +141,7 @@
assertEquals("admin", event.getUserID());
}
- public void testAddNode() throws Exception
+ public void _testAddNode() throws Exception
{
QPath node1path = QPath.parse("[]:1[]node:1");
NodeData newNode =
@@ -159,7 +159,7 @@
assertEvent(Event.NODE_ADDED, node1path, listener, "admin");
}
- public void testRemoveNode() throws Exception
+ public void _testRemoveNode() throws Exception
{
QPath node1path = QPath.parse("[]:1[]node:1");
NodeData newNode =
@@ -177,7 +177,7 @@
assertEvent(Event.NODE_REMOVED, node1path, listener, "admin");
}
- public void testAddProperty() throws Exception
+ public void _testAddProperty() throws Exception
{
QPath prop1path = QPath.parse("[]:1[]node:1[]property:1");
PropertyData newProperty =
@@ -195,7 +195,7 @@
assertEvent(Event.PROPERTY_ADDED, prop1path, listener, "admin");
}
- public void testUpdateProperty() throws Exception
+ public void _testUpdateProperty() throws Exception
{
QPath prop1path = QPath.parse("[]:1[]node:1[]property:1");
PropertyData newProperty =
@@ -213,7 +213,7 @@
assertEvent(Event.PROPERTY_CHANGED, prop1path, listener, "admin");
}
- public void testRemoveProperty() throws Exception
+ public void _testRemoveProperty() throws Exception
{
QPath prop1path = QPath.parse("[]:1[]node:1[]property:1");
PropertyData newProperty =
@@ -231,18 +231,8 @@
assertEvent(Event.PROPERTY_REMOVED, prop1path, listener, "admin");
}
- protected void assertEvent(int eventType, QPath prop1path, DummyListener listener, String userId)
- throws RepositoryException
+ public void _testFilterByNodeType() throws Exception
{
- assertEquals(1, listener.eventList.size());
- Event event = listener.eventList.get(0);
- assertEquals(eventType, event.getType());
- assertEquals(lf.createJCRPath(prop1path).getAsString(false), event.getPath());
- assertEquals(userId, event.getUserID());
- }
-
- public void testFilterByNodeType() throws Exception
- {
String parent1uuid = "uuid1";
String parent2uuid = "uuid2";
@@ -283,6 +273,16 @@
assertEvent(Event.NODE_ADDED, child2path, listener, "admin");
}
+ protected void assertEvent(int eventType, QPath prop1path, DummyListener listener, String userId)
+ throws RepositoryException
+ {
+ assertEquals(1, listener.eventList.size());
+ Event event = listener.eventList.get(0);
+ assertEquals(eventType, event.getType());
+ assertEquals(lf.createJCRPath(prop1path).getAsString(false), event.getPath());
+ assertEquals(userId, event.getUserID());
+ }
+
@Override
protected void tearDown() throws Exception
{
16 years, 8 months
exo-jcr SVN: r594 - jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2009-11-12 06:20:31 -0500 (Thu, 12 Nov 2009)
New Revision: 594
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
Log:
EXOJCR-201 : The JDBCCacheLoaderTest was changed.
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12 11:14:23 UTC (rev 593)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12 11:20:31 UTC (rev 594)
@@ -312,6 +312,26 @@
private TransientPropertyData addDbProperty(WorkspaceStorageConnection conn, QPath nodePath, String nodeId,
InternalQName propertyName, Object propertyValue, boolean multiValued) throws Exception
{
+ TransientPropertyData propData = createProperty(nodePath, nodeId, propertyName, propertyValue, multiValued);
+
+ conn.add(propData);
+
+ return propData;
+ }
+
+ /**
+ * Create Property.
+ *
+ * @param nodePath QPath
+ * @param nodeId String
+ * @param propertyName InternalQName
+ * @param propertyValue Object
+ * @return TransientPropertyData
+ * @throws Exception
+ */
+ private TransientPropertyData createProperty(QPath nodePath, String nodeId,
+ InternalQName propertyName, Object propertyValue, boolean multiValued) throws Exception
+ {
String propId = IdGenerator.generate();
QPath propPath = QPath.makeChildPath(nodePath, propertyName);
TransientPropertyData propData =
@@ -348,8 +368,6 @@
}
}
- conn.add(propData);
-
return propData;
}
@@ -388,11 +406,8 @@
public void testAddProperty() throws Exception
{
// prepare
- WorkspaceStorageConnection connection = persistentContainer.openConnection();
+ TransientPropertyData propData = createProperty(Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.JCR_DATA, "JCR DATA VALUE", false);
- TransientPropertyData propData = addDbProperty(connection, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.JCR_DATA, "JCR DATA VALUE", false);
- connection.commit();
-
List<Modification> modifications = new ArrayList<Modification>();
modifications.addAll(addProperty(propData));
@@ -400,7 +415,7 @@
loader.put(modifications);
// tests it
- connection = persistentContainer.openConnection();
+ WorkspaceStorageConnection connection = persistentContainer.openConnection();
PropertyData destPropData = (PropertyData) connection.getItemData(propData.getIdentifier());
@@ -485,26 +500,17 @@
{
// prepare
- initJCRRoot();
+ WorkspaceStorageConnection connection = persistentContainer.openConnection();
- String propId = IdGenerator.generate();
- QPath propPath = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_DATA);
- TransientPropertyData propData = new TransientPropertyData(propPath, propId, 1, 1, Constants.ROOT_UUID, false);
- String propValue = "JCR DATA VALUE";
- propData.setValue(new TransientValueData(propValue));
+ TransientPropertyData propData = addDbProperty(connection, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.JCR_DATA, "JCR DATA VALUE", false);
+ connection.commit();
- List<Modification> modifications = new ArrayList<Modification>();
-
- modifications.addAll(addProperty(propData));
-
- loader.put(modifications);
-
// tests it
- WorkspaceStorageConnection connection = persistentContainer.openConnection();
+ connection = persistentContainer.openConnection();
- PropertyData destPropData = (PropertyData) connection.getItemData(propId);
+ PropertyData destPropData = (PropertyData) connection.getItemData(propData.getIdentifier());
- Map<Object, Object> attrebutes = loader.get(Fqn.fromString("/"+JBossCacheStorage.PROPS + "/" + propId));
+ Map<Object, Object> attrebutes = loader.get(Fqn.fromString("/"+JBossCacheStorage.PROPS + "/" + propData.getIdentifier()));
assertNotNull(attrebutes);
16 years, 8 months
exo-jcr SVN: r593 - jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: sergiykarpenko
Date: 2009-11-12 06:14:23 -0500 (Thu, 12 Nov 2009)
New Revision: 593
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderRuntimeTest.java
Log:
EXOJCR-202: IndexerCacheLoaderRuntimeTest added
Added: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderRuntimeTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderRuntimeTest.java (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/IndexerCacheLoaderRuntimeTest.java 2009-11-12 11:14:23 UTC (rev 593)
@@ -0,0 +1,397 @@
+/*
+ * Copyright (C) 2003-2009 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.storage.jbosscache;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.dbcp.BasicDataSourceFactory;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.exoplatform.container.configuration.ConfigurationManager;
+import org.exoplatform.container.configuration.ConfigurationManagerImpl;
+import org.exoplatform.services.document.DocumentReaderService;
+import org.exoplatform.services.idgenerator.impl.IDGeneratorServiceImpl;
+import org.exoplatform.services.jcr.access.AccessControlList;
+import org.exoplatform.services.jcr.config.CacheEntry;
+import org.exoplatform.services.jcr.config.ContainerEntry;
+import org.exoplatform.services.jcr.config.LockManagerEntry;
+import org.exoplatform.services.jcr.config.LockPersisterEntry;
+import org.exoplatform.services.jcr.config.QueryHandlerEntry;
+import org.exoplatform.services.jcr.config.RepositoryEntry;
+import org.exoplatform.services.jcr.config.SimpleParameterEntry;
+import org.exoplatform.services.jcr.config.ValueStorageEntry;
+import org.exoplatform.services.jcr.config.ValueStorageFilterEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.Constants;
+import org.exoplatform.services.jcr.impl.core.LocationFactory;
+import org.exoplatform.services.jcr.impl.core.NamespaceRegistryImpl;
+import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeDataManagerImpl;
+import org.exoplatform.services.jcr.impl.core.nodetype.registration.JcrNodeTypeDataPersister;
+import org.exoplatform.services.jcr.impl.core.nodetype.registration.NodeTypeDataPersister;
+import org.exoplatform.services.jcr.impl.core.query.RepositoryIndexSearcherHolder;
+import org.exoplatform.services.jcr.impl.core.query.SearchManager;
+import org.exoplatform.services.jcr.impl.core.query.SearchManagerImpl;
+import org.exoplatform.services.jcr.impl.core.query.SystemSearchManagerHolder;
+import org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex;
+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.impl.dataflow.persistent.JBossCacheWorkspaceDataManager;
+import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
+import org.exoplatform.services.jcr.impl.storage.SystemDataContainerHolder;
+import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.impl.storage.value.StandaloneStoragePluginProvider;
+import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
+import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
+import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
+import org.exoplatform.services.jcr.util.IdGenerator;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+
+import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import javax.jcr.PropertyType;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date:
+ *
+ * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
+ * @version $Id: IndexerCacheLoaderRuntimeTest.java 111 2008-11-11 11:11:11Z serg $
+ */
+public class IndexerCacheLoaderRuntimeTest extends TestCase
+{
+
+ protected JBossCacheStorageConnection conn;
+
+ protected Cache<Serializable, Object> cache;
+
+ protected Node<Serializable, Object> nodes;
+
+ protected Node<Serializable, Object> props;
+
+ protected Node<Serializable, Object> session;
+
+ protected String jbcConfig;
+
+ JDBCWorkspaceDataContainer persistentContainer;
+
+ SearchManager manager;
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void setUp() throws Exception
+ {
+ try
+ {
+ super.setUp();
+
+ // JBossCache
+ initJBCConfig();
+
+ cache = new DefaultCacheFactory<Serializable, Object>().createCache(jbcConfig, false);
+
+ initJBC();
+
+ // run cache
+ cache.create();
+ cache.start();
+
+ Node<Serializable, Object> cacheRoot = cache.getRoot();
+
+ // prepare cache structures
+
+ nodes = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.NODES));
+ props = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.PROPS));
+ session = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.SESSION));
+
+ // JCR connection
+ conn = new JBossCacheStorageConnection(cache, nodes, props, session);
+ // add root (/)
+ conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+ new InternalQName[0], 0, null, new AccessControlList()));
+
+ String propId1 = "rootf111111";
+ QPath propPath1 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE);
+ TransientPropertyData propData1 =
+ new TransientPropertyData(propPath1, propId1, 1, PropertyType.NAME, Constants.ROOT_UUID, false);
+ propData1.setValue(new TransientValueData(Constants.NT_UNSTRUCTURED));
+ conn.add(propData1);
+
+ conn.commit();
+ ((SearchManagerImpl)manager).start();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ // protected void tearDown() throws Exception
+ // {
+ //
+ // cache.stop();
+ // cache.destroy();
+ //
+ // super.tearDown();
+ // }
+
+ protected void initJBC() throws Exception
+ {
+
+ // Create WorkspaceEntry
+ ContainerEntry containerEntry = new ContainerEntry();
+ List<SimpleParameterEntry> params = new ArrayList<SimpleParameterEntry>();
+ params.add(new SimpleParameterEntry(JDBCWorkspaceDataContainer.DB_DIALECT, "hsqldb"));
+ params.add(new SimpleParameterEntry(JDBCWorkspaceDataContainer.SWAPDIR_PROP, "/target/temp/swap/ws"));
+ containerEntry.setParameters(params);
+
+ // Initialize id generator.
+ new IdGenerator(new IDGeneratorServiceImpl());
+
+ // Set system property Context.INITIAL_CONTEXT_FACTORY to initial context.
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.exoplatform.services.naming.SimpleContextFactory");
+
+ // Create data source. Will be created new data source to new test.
+ String dataSourceName = "jdbcjcr_" + IdGenerator.generate();
+ createNewDataSource(dataSourceName);
+
+ WorkspaceEntry ws =
+ getNewWs("ws_to_jbdc_cache_loader", true, dataSourceName, "/target/temp/ws_to_jbdc_cache_loader/values",
+ containerEntry);
+
+ RepositoryEntry re = new RepositoryEntry();
+ re.addWorkspace(ws);
+
+ ValueStoragePluginProvider valueStoragePluginProvider = new StandaloneStoragePluginProvider(ws);
+
+ persistentContainer = new JDBCWorkspaceDataContainer(ws, re, null, valueStoragePluginProvider);
+
+ persistentContainer.start();
+
+ NamespaceRegistryImpl nsReg = new NamespaceRegistryImpl();
+ nsReg.start();
+ SystemDataContainerHolder<WorkspaceDataContainer> systemDataContainerHolder =
+ new SystemDataContainerHolder(persistentContainer);
+
+ WorkspacePersistentDataManager itemMgr =
+ new JBossCacheWorkspaceDataManager(persistentContainer, systemDataContainerHolder);
+
+ RepositoryIndexSearcherHolder indexSearcherHolder = new RepositoryIndexSearcherHolder();
+
+ NodeTypeDataPersister persister = new JcrNodeTypeDataPersister(itemMgr, false);
+ NodeTypeDataManager ntReg =
+ new NodeTypeDataManagerImpl(re, new LocationFactory(nsReg), nsReg, persister, itemMgr, indexSearcherHolder);
+
+ SystemSearchManagerHolder parentSearchManager = null;
+ DocumentReaderService extractor = null;
+ ConfigurationManager cfm = new ConfigurationManagerImpl();
+
+ manager =
+ new SearchManagerImpl(ws.getQueryHandler(), nsReg, ntReg, itemMgr, parentSearchManager, extractor, cfm,
+ indexSearcherHolder);
+
+ ((CacheSPI<Serializable, Object>)cache).getComponentRegistry().registerComponent(persistentContainer,
+ WorkspaceDataContainer.class);
+
+ ((CacheSPI<Serializable, Object>)cache).getComponentRegistry().registerComponent(manager, SearchManager.class);
+
+ }
+
+ protected void initJBCConfig()
+ {
+ jbcConfig = "conf/standalone/test-jbosscache-config-exoloader.xml";
+ }
+
+ public void testAddNode() throws Exception
+ {
+ // prepare
+ //super.testAddNode();
+ String node1id = "111111111111";
+ QPath node1path = QPath.makeChildPath(Constants.ROOT_PATH, "[]node:1");
+ conn.add(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ Constants.ROOT_UUID, new AccessControlList()));
+
+ String propId1 = "111111222222";
+ QPath propPath1 = QPath.makeChildPath(node1path, Constants.JCR_PRIMARYTYPE);
+ TransientPropertyData propData1 =
+ new TransientPropertyData(propPath1, propId1, 1, PropertyType.NAME, node1id, false);
+ propData1.setValue(new TransientValueData(Constants.NT_UNSTRUCTURED));
+ conn.add(propData1);
+
+ conn.commit();
+
+ // check do we really have node
+ WorkspaceStorageConnection connection = persistentContainer.openConnection();
+
+ NodeData nd = (NodeData)connection.getItemData(node1id);
+ assertNotNull(nd);
+ assertEquals("[]:1[]node:1", nd.getQPath().getAsString());
+
+ // find node by search engine
+
+ SearchIndex index = ((SearchIndex)manager.getHandler());
+ IndexReader reader = index.getIndexReader();
+
+ IndexSearcher searcher = new IndexSearcher(reader);
+
+ Query query = new TermQuery(new Term("", ""));
+ searcher.search(query);
+
+ }
+
+ protected WorkspaceEntry getNewWs(String wsName, boolean isMultiDb, String dsName, String vsPath,
+ ContainerEntry entry) throws Exception
+ {
+
+ List params = new ArrayList();
+
+ params.add(new SimpleParameterEntry("sourceName", dsName));
+ params.add(new SimpleParameterEntry("db-type", "generic"));
+ params.add(new SimpleParameterEntry("multi-db", isMultiDb ? "true" : "false"));
+ params.add(new SimpleParameterEntry("update-storage", "true"));
+ params.add(new SimpleParameterEntry("max-buffer-size", "204800"));
+
+ if (entry.getParameterValue(JDBCWorkspaceDataContainer.DB_DIALECT) != null)
+ {
+ params.add(new SimpleParameterEntry(JDBCWorkspaceDataContainer.DB_DIALECT, entry
+ .getParameterValue(JDBCWorkspaceDataContainer.DB_DIALECT)));
+ }
+
+ String oldSwap = entry.getParameterValue("swap-directory");
+ String newSwap = oldSwap.substring(0, oldSwap.lastIndexOf('/')) + '/' + wsName;
+
+ params.add(new SimpleParameterEntry("swap-directory", newSwap));
+
+ ContainerEntry containerEntry =
+ new ContainerEntry("org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer",
+ (ArrayList)params);
+ containerEntry.setParameters(params);
+
+ if (vsPath != null)
+ {
+
+ ArrayList<ValueStorageFilterEntry> vsparams = new ArrayList<ValueStorageFilterEntry>();
+ ValueStorageFilterEntry filterEntry = new ValueStorageFilterEntry();
+ filterEntry.setPropertyType("Binary");
+ vsparams.add(filterEntry);
+
+ ValueStorageEntry valueStorageEntry =
+ new ValueStorageEntry("org.exoplatform.services.jcr.impl.storage.value.fs.SimpleFileValueStorage", vsparams);
+ ArrayList<SimpleParameterEntry> spe = new ArrayList<SimpleParameterEntry>();
+ spe.add(new SimpleParameterEntry("path", vsPath));
+ valueStorageEntry.setId(IdGenerator.generate());
+ valueStorageEntry.setParameters(spe);
+ valueStorageEntry.setFilters(vsparams);
+
+ // containerEntry.setValueStorages();
+ containerEntry.setParameters(params);
+ ArrayList list = new ArrayList(1);
+ list.add(valueStorageEntry);
+
+ containerEntry.setValueStorages(list);
+
+ }
+
+ // Indexer
+ ArrayList qParams = new ArrayList();
+ qParams.add(new SimpleParameterEntry("indexDir", "target/temp/index/db1/ws" + IdGenerator.generate()));
+ QueryHandlerEntry qEntry =
+ new QueryHandlerEntry("org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex", qParams);
+
+ WorkspaceEntry workspaceEntry =
+ new WorkspaceEntry(wsName != null ? wsName : IdGenerator.generate(), "nt:unstructured");
+ workspaceEntry.setContainer(containerEntry);
+
+ ArrayList cacheParams = new ArrayList();
+
+ cacheParams.add(new SimpleParameterEntry("maxSize", "2000"));
+ cacheParams.add(new SimpleParameterEntry("liveTime", "20m"));
+ CacheEntry cacheEntry = new CacheEntry(cacheParams);
+ cacheEntry.setType("org.exoplatform.services.jcr.impl.dataflow.persistent.LinkedWorkspaceStorageCacheImpl");
+
+ workspaceEntry.setCache(cacheEntry);
+
+ workspaceEntry.setQueryHandler(qEntry);
+
+ LockManagerEntry lockManagerEntry = new LockManagerEntry();
+ lockManagerEntry.setTimeout(900000);
+ LockPersisterEntry persisterEntry = new LockPersisterEntry();
+ persisterEntry.setType("org.exoplatform.services.jcr.impl.core.lock.FileSystemLockPersister");
+ ArrayList lpParams = new ArrayList();
+ lpParams.add(new SimpleParameterEntry("path", "../temp/lock"));
+ persisterEntry.setParameters(lpParams);
+ lockManagerEntry.setPersister(persisterEntry);
+ workspaceEntry.setLockManager(lockManagerEntry);
+
+ // workspaceEntry
+ return workspaceEntry;
+ }
+
+ public void createNewDataSource(String dataSourceName) throws Exception
+ {
+
+ Properties properties = new Properties();
+
+ properties.setProperty("driverClassName", "org.hsqldb.jdbcDriver");
+ String newurl = "jdbc:hsqldb:file:target/temp/data/" + dataSourceName;
+
+ properties.setProperty("url", newurl);
+ properties.setProperty("username", "sa");
+ properties.setProperty("password", "");
+ DataSource bds = BasicDataSourceFactory.createDataSource(properties);
+ if (!newurl.contains("hsqldb"))
+ {
+ createDatabase(bds, dataSourceName);
+ }
+
+ new InitialContext().rebind(dataSourceName, bds);
+ }
+
+ private void createDatabase(DataSource ds, String dbName) throws SQLException
+ {
+ Connection connection = ds.getConnection();
+ PreparedStatement st = connection.prepareStatement("create database " + dbName);
+ st.executeQuery();
+ }
+
+}
16 years, 8 months
exo-jcr SVN: r592 - jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2009-11-12 05:37:10 -0500 (Thu, 12 Nov 2009)
New Revision: 592
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
Log:
EXOJCR-201 : The JDBCCacheLoaderTest was changed.
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12 10:27:14 UTC (rev 591)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12 10:37:10 UTC (rev 592)
@@ -327,6 +327,10 @@
else
throw new Exception("propertyValue should be a List");
}
+ else
+ {
+ values.add(propertyValue);
+ }
for (Object value : values)
{
@@ -386,7 +390,7 @@
// prepare
WorkspaceStorageConnection connection = persistentContainer.openConnection();
- TransientPropertyData propData = addDbProperty(connection, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.JCR_DATA, "JCR DATA VALUE", false);
+ TransientPropertyData propData = addDbProperty(connection, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.JCR_DATA, "JCR DATA VALUE", false);
connection.commit();
List<Modification> modifications = new ArrayList<Modification>();
16 years, 8 months
exo-jcr SVN: r591 - jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-11-12 05:27:14 -0500 (Thu, 12 Nov 2009)
New Revision: 591
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
Log:
EXOJCR-201: test for JDBC loader
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12 10:06:18 UTC (rev 590)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12 10:27:14 UTC (rev 591)
@@ -87,7 +87,20 @@
initJCRRoot();
}
+
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ // delete all in DB
+
+
+ super.tearDown();
+ }
+
+
+
protected void initPersistence() throws Exception
{
// Create WorkspaceEntry
@@ -122,7 +135,6 @@
private WorkspaceEntry getNewWs(String wsName, boolean isMultiDb, String dsName, String vsPath, ContainerEntry entry)
throws Exception
{
-
List params = new ArrayList();
params.add(new SimpleParameterEntry("sourceName", dsName));
@@ -149,7 +161,6 @@
if (vsPath != null)
{
-
ArrayList<ValueStorageFilterEntry> vsparams = new ArrayList<ValueStorageFilterEntry>();
ValueStorageFilterEntry filterEntry = new ValueStorageFilterEntry();
filterEntry.setPropertyType("Binary");
@@ -169,47 +180,44 @@
list.add(valueStorageEntry);
containerEntry.setValueStorages(list);
-
}
-
- // Indexer
- ArrayList qParams = new ArrayList();
- qParams.add(new SimpleParameterEntry("indexDir", "../temp/index/" + IdGenerator.generate()));
- QueryHandlerEntry qEntry =
- new QueryHandlerEntry("org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex", qParams);
-
+
WorkspaceEntry workspaceEntry =
new WorkspaceEntry(wsName != null ? wsName : IdGenerator.generate(), "nt:unstructured");
workspaceEntry.setContainer(containerEntry);
- ArrayList cacheParams = new ArrayList();
+// // Indexer
+// ArrayList qParams = new ArrayList();
+// qParams.add(new SimpleParameterEntry("indexDir", "../temp/index/" + IdGenerator.generate()));
+// QueryHandlerEntry qEntry =
+// new QueryHandlerEntry("org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex", qParams);
+// workspaceEntry.setQueryHandler(qEntry);
+//
+// // cache
+// ArrayList cacheParams = new ArrayList();
+// cacheParams.add(new SimpleParameterEntry("maxSize", "2000"));
+// cacheParams.add(new SimpleParameterEntry("liveTime", "20m"));
+// CacheEntry cacheEntry = new CacheEntry(cacheParams);
+// cacheEntry.setType("org.exoplatform.services.jcr.impl.dataflow.persistent.LinkedWorkspaceStorageCacheImpl");
+// workspaceEntry.setCache(cacheEntry);
+//
+// // lock
+// LockManagerEntry lockManagerEntry = new LockManagerEntry();
+// lockManagerEntry.setTimeout(900000);
+// LockPersisterEntry persisterEntry = new LockPersisterEntry();
+// persisterEntry.setType("org.exoplatform.services.jcr.impl.core.lock.FileSystemLockPersister");
+// ArrayList lpParams = new ArrayList();
+// lpParams.add(new SimpleParameterEntry("path", "../temp/lock"));
+// persisterEntry.setParameters(lpParams);
+// lockManagerEntry.setPersister(persisterEntry);
+// workspaceEntry.setLockManager(lockManagerEntry);
- cacheParams.add(new SimpleParameterEntry("maxSize", "2000"));
- cacheParams.add(new SimpleParameterEntry("liveTime", "20m"));
- CacheEntry cacheEntry = new CacheEntry(cacheParams);
- cacheEntry.setType("org.exoplatform.services.jcr.impl.dataflow.persistent.LinkedWorkspaceStorageCacheImpl");
-
- workspaceEntry.setCache(cacheEntry);
-
- workspaceEntry.setQueryHandler(qEntry);
-
- LockManagerEntry lockManagerEntry = new LockManagerEntry();
- lockManagerEntry.setTimeout(900000);
- LockPersisterEntry persisterEntry = new LockPersisterEntry();
- persisterEntry.setType("org.exoplatform.services.jcr.impl.core.lock.FileSystemLockPersister");
- ArrayList lpParams = new ArrayList();
- lpParams.add(new SimpleParameterEntry("path", "../temp/lock"));
- persisterEntry.setParameters(lpParams);
- lockManagerEntry.setPersister(persisterEntry);
- workspaceEntry.setLockManager(lockManagerEntry);
-
// workspaceEntry
return workspaceEntry;
}
private void createNewDataSource(String dataSourceName) throws Exception
{
-
Properties properties = new Properties();
properties.setProperty("driverClassName", "org.hsqldb.jdbcDriver");
@@ -251,7 +259,25 @@
conn.commit();
}
+
+ private void deleteJCRRoot() throws Exception
+ {
+ // prepare
+ WorkspaceStorageConnection conn = persistentContainer.openConnection();
+ // add root (/) with jcr:primaryType
+ addDbNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.NT_UNSTRUCTURED);
+
+ // add property (/jcr:mixinTypes)
+ List<InternalQName> mixins = new ArrayList<InternalQName>();
+ mixins.add(Constants.MIX_REFERENCEABLE);
+ mixins.add(Constants.EXO_PRIVILEGEABLE);
+ mixins.add(Constants.EXO_OWNEABLE);
+ addDbProperty(conn, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.JCR_MIXINTYPES, mixins, true);
+
+ conn.commit();
+ }
+
/**
* Add Property to the connection but doesn't save it.
*
@@ -322,6 +348,26 @@
return propData;
}
+
+ /**
+ * Delete Property to the connection but doesn't save it.
+ *
+ * @param conn WorkspaceStorageConnection
+ * @param root QPath
+ * @param nodeId String
+ * @param primaryType InternalQName
+ * @throws Exception
+ */
+ private void deleteDbNode(WorkspaceStorageConnection conn, QPath root, String nodeId, InternalQName primaryType)
+ throws Exception
+ {
+ // add property (/jcr:primaryType)
+ addDbProperty(conn, root, Constants.ROOT_UUID, Constants.JCR_PRIMARYTYPE, primaryType, false);
+
+ // add root (/)
+ conn.delete(new TransientNodeData(root, nodeId, 1, primaryType, new InternalQName[0], 0, null,
+ new AccessControlList()));
+ }
// ============= TESTS =============
16 years, 8 months
exo-jcr SVN: r590 - jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-11-12 05:06:18 -0500 (Thu, 12 Nov 2009)
New Revision: 590
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
Log:
EXOJCR-201: test for JDBC loader
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12 10:02:31 UTC (rev 589)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12 10:06:18 UTC (rev 590)
@@ -84,6 +84,8 @@
loader = new JDBCCacheLoader();
loader.injectDependencies(persistentContainer);
+
+ initJCRRoot();
}
protected void initPersistence() throws Exception
@@ -326,7 +328,6 @@
public void testAddNode() throws Exception
{
// prepare
- initJCRRoot();
// tests
WorkspaceStorageConnection conn = persistentContainer.openConnection();
@@ -337,8 +338,6 @@
public void testAddProperty() throws Exception
{
// prepare
- initJCRRoot();
-
WorkspaceStorageConnection connection = persistentContainer.openConnection();
TransientPropertyData propData = addDbProperty(connection, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.JCR_DATA, "JCR DATA VALUE", false);
16 years, 8 months
exo-jcr SVN: r589 - jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: areshetnyak
Date: 2009-11-12 05:02:31 -0500 (Thu, 12 Nov 2009)
New Revision: 589
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
Log:
EXOJCR-201 : The JDBCCacheLoaderTest was changed.
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12 09:49:39 UTC (rev 588)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12 10:02:31 UTC (rev 589)
@@ -44,6 +44,7 @@
import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
import org.exoplatform.services.jcr.storage.value.ValueStoragePluginProvider;
import org.exoplatform.services.jcr.util.IdGenerator;
+import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
import java.io.InputStream;
@@ -52,6 +53,7 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import javax.naming.Context;
@@ -283,9 +285,9 @@
InternalQName propertyName, Object propertyValue, boolean multiValued) throws Exception
{
String propId = IdGenerator.generate();
- QPath propPath = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_MIXINTYPES);
+ QPath propPath = QPath.makeChildPath(nodePath, propertyName);
TransientPropertyData propData =
- new TransientPropertyData(propPath, propId, 1, 1, Constants.ROOT_UUID, multiValued);
+ new TransientPropertyData(propPath, propId, 1, 1, nodeId, multiValued);
List<Object> values = new ArrayList<Object>();
if (multiValued)
@@ -337,22 +339,21 @@
// prepare
initJCRRoot();
- String propId = IdGenerator.generate();
- QPath propPath = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_DATA);
- TransientPropertyData propData = new TransientPropertyData(propPath, propId, 1, 1, Constants.ROOT_UUID, false);
- String propValue = "JCR DATA VALUE";
- propData.setValue(new TransientValueData(propValue));
+ WorkspaceStorageConnection connection = persistentContainer.openConnection();
+ TransientPropertyData propData = addDbProperty(connection, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.JCR_DATA, "JCR DATA VALUE", false);
+ connection.commit();
+
List<Modification> modifications = new ArrayList<Modification>();
modifications.addAll(addProperty(propData));
loader.put(modifications);
- // tests
- WorkspaceStorageConnection connection = persistentContainer.openConnection();
+ // tests it
+ connection = persistentContainer.openConnection();
- PropertyData destPropData = (PropertyData) connection.getItemData(propId);
+ PropertyData destPropData = (PropertyData) connection.getItemData(propData.getIdentifier());
assertNotNull(destPropData);
assertEquals(propData.getIdentifier(), destPropData.getIdentifier());
@@ -435,9 +436,30 @@
{
// prepare
+ initJCRRoot();
+
+ String propId = IdGenerator.generate();
+ QPath propPath = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_DATA);
+ TransientPropertyData propData = new TransientPropertyData(propPath, propId, 1, 1, Constants.ROOT_UUID, false);
+ String propValue = "JCR DATA VALUE";
+ propData.setValue(new TransientValueData(propValue));
+
+ List<Modification> modifications = new ArrayList<Modification>();
+
+ modifications.addAll(addProperty(propData));
+
+ loader.put(modifications);
// tests it
+ WorkspaceStorageConnection connection = persistentContainer.openConnection();
+
+ PropertyData destPropData = (PropertyData) connection.getItemData(propId);
+
+ Map<Object, Object> attrebutes = loader.get(Fqn.fromString("/"+JBossCacheStorage.PROPS + "/" + propId));
+
+ assertNotNull(attrebutes);
+
}
public void testGetPropertyByName() throws Exception
16 years, 8 months
exo-jcr SVN: r588 - jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-11-12 04:49:39 -0500 (Thu, 12 Nov 2009)
New Revision: 588
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
Log:
EXOJCR-201: test for JDBC loader
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12 09:44:59 UTC (rev 587)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12 09:49:39 UTC (rev 588)
@@ -236,14 +236,14 @@
WorkspaceStorageConnection conn = persistentContainer.openConnection();
// add root (/) with jcr:primaryType
- addNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.NT_UNSTRUCTURED);
+ addDbNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.NT_UNSTRUCTURED);
// add property (/jcr:mixinTypes)
List<InternalQName> mixins = new ArrayList<InternalQName>();
mixins.add(Constants.MIX_REFERENCEABLE);
mixins.add(Constants.EXO_PRIVILEGEABLE);
mixins.add(Constants.EXO_OWNEABLE);
- addProperty(conn, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.JCR_MIXINTYPES, mixins, true);
+ addDbProperty(conn, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.JCR_MIXINTYPES, mixins, true);
conn.commit();
}
@@ -257,7 +257,7 @@
* @param primaryType InternalQName
* @throws Exception
*/
- private void addNode(WorkspaceStorageConnection conn, QPath root, String nodeId, InternalQName primaryType)
+ private void addDbNode(WorkspaceStorageConnection conn, QPath root, String nodeId, InternalQName primaryType)
throws Exception
{
// add root (/)
@@ -265,7 +265,7 @@
new AccessControlList()));
// add property (/jcr:primaryType)
- addProperty(conn, root, Constants.ROOT_UUID, Constants.JCR_PRIMARYTYPE, primaryType, false);
+ addDbProperty(conn, root, Constants.ROOT_UUID, Constants.JCR_PRIMARYTYPE, primaryType, false);
}
/**
@@ -279,7 +279,7 @@
* @return TransientPropertyData
* @throws Exception
*/
- private TransientPropertyData addProperty(WorkspaceStorageConnection conn, QPath nodePath, String nodeId,
+ private TransientPropertyData addDbProperty(WorkspaceStorageConnection conn, QPath nodePath, String nodeId,
InternalQName propertyName, Object propertyValue, boolean multiValued) throws Exception
{
String propId = IdGenerator.generate();
16 years, 8 months
exo-jcr SVN: r587 - jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
by do-not-reply@jboss.org
Author: pnedonosko
Date: 2009-11-12 04:44:59 -0500 (Thu, 12 Nov 2009)
New Revision: 587
Modified:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
Log:
EXOJCR-201: test for JDBC loader
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12 09:28:28 UTC (rev 586)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoaderTest.java 2009-11-12 09:44:59 UTC (rev 587)
@@ -18,17 +18,6 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.sql.DataSource;
-
import org.apache.commons.dbcp.BasicDataSourceFactory;
import org.exoplatform.services.idgenerator.impl.IDGeneratorServiceImpl;
import org.exoplatform.services.jcr.access.AccessControlList;
@@ -57,6 +46,18 @@
import org.exoplatform.services.jcr.util.IdGenerator;
import org.jboss.cache.Modification;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+
/**
* @author <a href="mailto:reshetnyak.alex@gmail.com">Alex Reshetnyak</a>
* @version $Id$
@@ -228,33 +229,94 @@
PreparedStatement st = connection.prepareStatement("create database " + dbName);
st.executeQuery();
}
-
-
- private void initJCRRoot() throws Exception {
+
+ private void initJCRRoot() throws Exception
+ {
// prepare
WorkspaceStorageConnection conn = persistentContainer.openConnection();
+ // add root (/) with jcr:primaryType
+ addNode(conn, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.NT_UNSTRUCTURED);
+
+ // add property (/jcr:mixinTypes)
+ List<InternalQName> mixins = new ArrayList<InternalQName>();
+ mixins.add(Constants.MIX_REFERENCEABLE);
+ mixins.add(Constants.EXO_PRIVILEGEABLE);
+ mixins.add(Constants.EXO_OWNEABLE);
+ addProperty(conn, Constants.ROOT_PATH, Constants.ROOT_UUID, Constants.JCR_MIXINTYPES, mixins, true);
+
+ conn.commit();
+ }
+
+ /**
+ * Add Property to the connection but doesn't save it.
+ *
+ * @param conn WorkspaceStorageConnection
+ * @param root QPath
+ * @param nodeId String
+ * @param primaryType InternalQName
+ * @throws Exception
+ */
+ private void addNode(WorkspaceStorageConnection conn, QPath root, String nodeId, InternalQName primaryType)
+ throws Exception
+ {
// add root (/)
- conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
- new InternalQName[0], 0, null, new AccessControlList()));
+ conn.add(new TransientNodeData(root, nodeId, 1, primaryType, new InternalQName[0], 0, null,
+ new AccessControlList()));
// add property (/jcr:primaryType)
- String propId1 = "1";
- QPath propPath1 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE);
- TransientPropertyData propData1 = new TransientPropertyData(propPath1, propId1, 1, 1, Constants.ROOT_UUID, false);
- String propValue1 = "Property value #1";
- propData1.setValue(new TransientValueData(propValue1));
- conn.add(propData1);
+ addProperty(conn, root, Constants.ROOT_UUID, Constants.JCR_PRIMARYTYPE, primaryType, false);
+ }
- // add property (/jcr:mixinTypes)
- String propId2 = "2";
- QPath propPath2 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_MIXINTYPES);
- TransientPropertyData propData2 = new TransientPropertyData(propPath2, propId2, 1, 1, Constants.ROOT_UUID, false);
- String propValue2 = "Property value #2";
- propData2.setValue(new TransientValueData(propValue2));
- conn.add(propData2);
+ /**
+ * Add Property to the connection but doesn't save it.
+ *
+ * @param conn WorkspaceStorageConnection
+ * @param nodePath QPath
+ * @param nodeId String
+ * @param propertyName InternalQName
+ * @param propertyValue Object
+ * @return TransientPropertyData
+ * @throws Exception
+ */
+ private TransientPropertyData addProperty(WorkspaceStorageConnection conn, QPath nodePath, String nodeId,
+ InternalQName propertyName, Object propertyValue, boolean multiValued) throws Exception
+ {
+ String propId = IdGenerator.generate();
+ QPath propPath = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_MIXINTYPES);
+ TransientPropertyData propData =
+ new TransientPropertyData(propPath, propId, 1, 1, Constants.ROOT_UUID, multiValued);
- conn.commit();
+ List<Object> values = new ArrayList<Object>();
+ if (multiValued)
+ {
+ if (propertyValue instanceof List)
+ {
+ values.addAll((List<Object>)propertyValue);
+ }
+ else
+ throw new Exception("propertyValue should be a List");
+ }
+
+ for (Object value : values)
+ {
+ if (value instanceof InternalQName)
+ {
+ propData.setValue(new TransientValueData((InternalQName)value));
+ }
+ else if (value instanceof String)
+ {
+ propData.setValue(new TransientValueData((String)value));
+ }
+ else if (value instanceof InputStream)
+ {
+ propData.setValue(new TransientValueData((InputStream)value));
+ }
+ }
+
+ conn.add(propData);
+
+ return propData;
}
// ============= TESTS =============
@@ -263,8 +325,7 @@
{
// prepare
initJCRRoot();
-
-
+
// tests
WorkspaceStorageConnection conn = persistentContainer.openConnection();
16 years, 8 months