Author: nzamosenchuk
Date: 2009-12-09 03:48:35 -0500 (Wed, 09 Dec 2009)
New Revision: 954
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestFullSearchPrepare.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestQueryPrepare.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestFullSearchAssert.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestQueryAssert.java
Removed:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/TestQueryAssert.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/TestQueryPrepare.java
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/ChangesFilterListsWrapper.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingletonStoreCacheLoader.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/
Log:
EXOJCR-291: Tests moved to separate folders, Cleaned and updated code of Changes filter
and CacheLoader-s
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/ChangesFilterListsWrapper.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/ChangesFilterListsWrapper.java 2009-12-09
08:38:07 UTC (rev 953)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/ChangesFilterListsWrapper.java 2009-12-09
08:48:35 UTC (rev 954)
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
package org.exoplatform.services.jcr.impl.core.query.jbosscache;
import java.io.Serializable;
@@ -4,7 +22,7 @@
import java.util.Set;
/**
- * FOR TESTING PURPOSES ONLY
+ * FOR TESTING PURPOSES ONLY. Used to avoid batching usage in indexer cache.
*
* @author <a href="mailto:nikolazius@gmail.com">Nikolay
Zamosenchuk</a>
* @version $Id: ChangesFilterListsWrapper.java 34360 2009-07-22 23:58:59Z nzamosenchuk
$
@@ -14,22 +32,49 @@
{
private static final long serialVersionUID = 1L;
- public Set<String> addedNodes;
+ private Set<String> addedNodes;
- public Set<String> removedNodes;
+ private Set<String> removedNodes;
- public Set<String> parentAddedNodes;
+ private Set<String> parentAddedNodes;
- public Set<String> parentRemovedNodes;
+ private Set<String> parentRemovedNodes;
+ /**
+ * Creates ChangesFilterListsWrapper data class, containing given lists.
+ *
+ * @param addedNodes
+ * @param removedNodes
+ * @param parentAddedNodes
+ * @param parentRemovedNodes
+ */
public ChangesFilterListsWrapper(Set<String> addedNodes, Set<String>
removedNodes, Set<String> parentAddedNodes,
Set<String> parentRemovedNodes)
{
- super();
this.addedNodes = addedNodes;
this.removedNodes = removedNodes;
this.parentAddedNodes = parentAddedNodes;
this.parentRemovedNodes = parentRemovedNodes;
}
+ public Set<String> getAddedNodes()
+ {
+ return addedNodes;
+ }
+
+ public Set<String> getRemovedNodes()
+ {
+ return removedNodes;
+ }
+
+ public Set<String> getParentAddedNodes()
+ {
+ return parentAddedNodes;
+ }
+
+ public Set<String> getParentRemovedNodes()
+ {
+ return parentRemovedNodes;
+ }
+
}
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java 2009-12-09
08:38:07 UTC (rev 953)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java 2009-12-09
08:48:35 UTC (rev 954)
@@ -17,6 +17,7 @@
package org.exoplatform.services.jcr.impl.core.query.jbosscache;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
import org.exoplatform.services.jcr.impl.core.query.SearchManager;
import
org.exoplatform.services.jcr.impl.storage.jbosscache.AbstractWriteOnlyCacheLoader;
import org.exoplatform.services.log.ExoLogger;
@@ -24,9 +25,12 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
+import java.io.IOException;
import java.util.List;
import java.util.Set;
+import javax.jcr.RepositoryException;
+
/**
* @author <a href="mailto:nikolazius@gmail.com">Nikolay
Zamosenchuk</a>
* @version $Id: IndexerCacheLoader.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
@@ -40,17 +44,23 @@
private SearchManager parentSearchManager;
- public void init(SearchManager searchManager, SearchManager parentSearchManager)
- throws RepositoryConfigurationException
+ private QueryHandler handler;
+
+ private QueryHandler parentHandler;
+
+ public void init(SearchManager searchManager, SearchManager parentSearchManager,
QueryHandler handler,
+ QueryHandler parentHandler) throws RepositoryConfigurationException
{
this.searchManager = searchManager;
this.parentSearchManager = parentSearchManager;
+ this.handler = handler;
+ this.parentHandler = parentHandler;
}
@Override
public void put(List<Modification> modifications) throws Exception
{
- // FOR TESTING PURPOSES
+ // FOR TESTING PURPOSES, avoid batches, use single puts.
for (Modification m : modifications)
{
switch (m.getType())
@@ -61,7 +71,7 @@
case REMOVE_DATA :
}
}
-
+ // This code was used if batching.
// if (log.isDebugEnabled())
// {
// log.info("Received list of modifications");
@@ -105,41 +115,75 @@
}
+ // Put used avoiding patching
@Override
public Object put(Fqn arg0, Object key, Object val) throws Exception
{
if (key.equals("key"))
{
ChangesFilterListsWrapper wrapper = (ChangesFilterListsWrapper)val;
- updateIndex(wrapper.addedNodes, wrapper.removedNodes, wrapper.parentAddedNodes,
wrapper.parentRemovedNodes);
+ updateIndex(wrapper.getAddedNodes(), wrapper.getRemovedNodes(),
wrapper.getParentAddedNodes(), wrapper
+ .getParentRemovedNodes());
}
return null;
}
+ /**
+ * Flushes lists of added/removed nodes to SearchManagers, starting indexing.
+ *
+ * @param addedNodes
+ * @param removedNodes
+ * @param parentAddedNodes
+ * @param parentRemovedNodes
+ */
protected void updateIndex(Set<String> addedNodes, Set<String>
removedNodes, Set<String> parentAddedNodes,
Set<String> parentRemovedNodes)
{
- if (searchManager != null && addedNodes.size() + removedNodes.size() >
0)
+ if (searchManager != null && (addedNodes.size() > 0 ||
removedNodes.size() > 0))
{
try
{
searchManager.updateIndex(removedNodes, addedNodes);
}
- catch (Exception e)
+ catch (RepositoryException e)
{
- e.printStackTrace();
+ log.error("Error indexing changes " + e, e);
}
+ catch (IOException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ try
+ {
+ handler.logErrorChanges(removedNodes, addedNodes);
+ }
+ catch (IOException ioe)
+ {
+ log.warn("Exception occure when errorLog writed. Error log is not
complete. " + ioe, ioe);
+ }
+ }
}
- if (parentSearchManager != null && addedNodes.size() + removedNodes.size()
> 0)
+ if (parentSearchManager != null && (parentAddedNodes.size() > 0 ||
parentRemovedNodes.size() > 0))
{
try
{
parentSearchManager.updateIndex(parentRemovedNodes, parentAddedNodes);
}
- catch (Exception e)
+ catch (RepositoryException e)
{
- e.printStackTrace();
+ log.error("Error indexing changes " + e, e);
}
+ catch (IOException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ try
+ {
+ parentHandler.logErrorChanges(removedNodes, addedNodes);
+ }
+ catch (IOException ioe)
+ {
+ log.warn("Exception occure when errorLog writed. Error log is not
complete. " + ioe, ioe);
+ }
+ }
}
}
}
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingletonStoreCacheLoader.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingletonStoreCacheLoader.java 2009-12-09
08:38:07 UTC (rev 953)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingletonStoreCacheLoader.java 2009-12-09
08:48:35 UTC (rev 954)
@@ -24,7 +24,6 @@
import org.jboss.cache.NodeSPI;
import org.jboss.cache.loader.SingletonStoreCacheLoader;
-import java.io.Serializable;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
@@ -78,10 +77,11 @@
final Set<String> parentRemovedNodes = new HashSet<String>();
final Set<String> parentAddedNodes = new HashSet<String>();
// merging all lists stored in memory
+ //TODO: re-write: lists are now stored in wrapper.
Collection<NodeSPI> children = cache.getRoot().getChildrenDirect();
for (NodeSPI aChildren : children)
{
- Fqn fqn = aChildren.getFqn();
+ Fqn<?> fqn = aChildren.getFqn();
Object value = cache.get(fqn, JbossCacheIndexChangesFilter.ADDED);
if (value != null && value instanceof Set<?>)
{
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java 2009-12-09
08:38:07 UTC (rev 953)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java 2009-12-09
08:48:35 UTC (rev 954)
@@ -81,7 +81,7 @@
// initialize IndexerCacheLoader
IndexerCacheLoader indexerCacheLoader = new IndexerCacheLoader();
// inject dependencies
- indexerCacheLoader.init(searchManager, parentSearchManager);
+ indexerCacheLoader.init(searchManager, parentSearchManager, handler,
parentHandler);
// set SingltonStoreCacheLoader
SingletonStoreConfig singletonStoreConfig = new SingletonStoreConfig();
singletonStoreConfig.setClassName(IndexerSingletonStoreCacheLoader.class.getName());
Property changes on:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab
___________________________________________________________________
Name: svn:ignore
+ lucene
Deleted:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/TestQueryAssert.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/TestQueryAssert.java 2009-12-09
08:38:07 UTC (rev 953)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/TestQueryAssert.java 2009-12-09
08:48:35 UTC (rev 954)
@@ -1,137 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.exoplatform.services.jcr.lab.cluster;
-
-import org.exoplatform.services.jcr.JcrAPIBaseTest;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.query.Query;
-import javax.jcr.query.QueryManager;
-import javax.jcr.query.QueryResult;
-import javax.jcr.query.Row;
-import javax.jcr.query.RowIterator;
-
-/**
- * @author <a href="mailto:nikolazius@gmail.com">Nikolay
Zamosenchuk</a>
- * @version $Id: TestQueryAssert.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
- *
- */
-public class TestQueryAssert extends JcrAPIBaseTest
-{
- public void testAssert() throws RepositoryException, IOException
- {
- System.out.println("Start asserting....");
-
- Node doc1 = root.getNode("document1");
- Node doc2 = root.getNode("document2");
-
- // make SQL query
- QueryManager qman = this.workspace.getQueryManager();
-
- Query q = qman.createQuery("SELECT * FROM nt:file ", Query.SQL);
- QueryResult res = q.execute();
- long sqlsize = res.getNodes().getSize();
- assertEquals(2, sqlsize);
- checkResult(res, new Node[]{doc1, doc2});
-
- //make XPath query
-
- Query xq = qman.createQuery("//element(*,nt:file)", Query.XPATH);
- QueryResult xres = xq.execute();
- long xpathsize = xres.getNodes().getSize();
- assertEquals(2, xpathsize);
- checkResult(xres, new Node[]{doc1, doc2});
- System.out.println("Done!");
- try
- {
- Thread.sleep(1024*1024*1024);
- }
- catch (InterruptedException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- protected void checkResult(QueryResult result, Node[] nodes) throws
RepositoryException
- {
- // collect paths
-
- String[] columnNames = result.getColumnNames();
- String[][] vals = new
String[(int)result.getNodes().getSize()][result.getColumnNames().length];
-
- RowIterator rit = result.getRows();
- int j = 0;
- while (rit.hasNext())
- {
- Row r = rit.nextRow();
- Value[] v = r.getValues();
- for (int i = 0; i < v.length; i++)
- {
- vals[j][i] = (v[i] != null) ? v[i].getString() : "null";
- }
- j++;
- }
-
- Set<String> expectedPaths = new HashSet<String>();
- for (int i = 0; i < nodes.length; i++)
- {
- expectedPaths.add(nodes[i].getPath());
- }
- Set<String> resultPaths = new HashSet<String>();
- for (NodeIterator it = result.getNodes(); it.hasNext();)
- {
- resultPaths.add(it.nextNode().getPath());
- }
-
- comparePaths(expectedPaths, resultPaths, false);
- }
-
- private void comparePaths(Set<String> expectedPaths, Set<String>
resultPaths, boolean canContainMore)
- {
- // check if all expected are in result
- for (Iterator<String> it = expectedPaths.iterator(); it.hasNext();)
- {
- String path = it.next();
- assertTrue(path + " is not part of the result set",
resultPaths.contains(path));
- }
-
- if (!canContainMore)
- {
- // check result does not contain more than expected
-
- for (Iterator<String> it = resultPaths.iterator(); it.hasNext();)
- {
- String path = it.next();
- assertTrue(path + " is not expected to be part of the result set. "
+ " Total size:" + resultPaths.size(),
- expectedPaths.contains(path));
- }
- }
- }
-}
Deleted:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/TestQueryPrepare.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/TestQueryPrepare.java 2009-12-09
08:38:07 UTC (rev 953)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/TestQueryPrepare.java 2009-12-09
08:48:35 UTC (rev 954)
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.exoplatform.services.jcr.lab.cluster;
-
-import org.exoplatform.services.jcr.JcrAPIBaseTest;
-import org.exoplatform.services.jcr.impl.core.NodeImpl;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.Calendar;
-
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-
-/**
- * @author <a href="mailto:nikolazius@gmail.com">Nikolay
Zamosenchuk</a>
- * @version $Id: TestQueryPrepare.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
- *
- */
-public class TestQueryPrepare extends JcrAPIBaseTest
-{
- public void testPrepareNodes() throws RepositoryException, IOException
- {
- System.out.println("preparing....");
-
- root.addNode("simplenode", "nt:unstructured");
-
- Node doc1 = root.addNode("document1", "nt:file");
- NodeImpl cont = (NodeImpl)doc1.addNode("jcr:content",
"nt:resource");
- cont.setProperty("jcr:mimeType", "text/plain");
- cont.setProperty("jcr:lastModified", Calendar.getInstance());
- cont.setProperty("jcr:encoding", "UTF-8");
- cont.setProperty("jcr:data", new
ByteArrayInputStream("".getBytes()));
-
- Node doc2 = root.addNode("document2", "nt:file");
- cont = (NodeImpl)doc2.addNode("jcr:content", "nt:resource");
- cont.setProperty("jcr:mimeType", "text/plain");
- cont.setProperty("jcr:lastModified", Calendar.getInstance());
- cont.setProperty("jcr:encoding", "UTF-8");
- cont.setProperty("jcr:data", new
ByteArrayInputStream("".getBytes()));
- session.save();
- System.out.println("Done!");
- try
- {
- Thread.sleep(1024*1024*1024);
- }
- catch (InterruptedException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-}
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestFullSearchPrepare.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestFullSearchPrepare.java
(rev 0)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestFullSearchPrepare.java 2009-12-09
08:48:35 UTC (rev 954)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.lab.cluster.prepare;
+
+import org.exoplatform.services.jcr.JcrAPIBaseTest;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+
+import java.util.Calendar;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * @author <a href="mailto:nikolazius@gmail.com">Nikolay
Zamosenchuk</a>
+ * @version $Id: TestFullSearchPrepare.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ *
+ */
+public class TestFullSearchPrepare extends JcrAPIBaseTest
+{
+
+ public void testFullSearch() throws RepositoryException
+ {
+ Node doc1 = root.addNode("document1", "nt:file");
+ NodeImpl cont1 = (NodeImpl)doc1.addNode("jcr:content",
"nt:resource");
+ cont1.setProperty("jcr:mimeType", "text/plain");
+ cont1.setProperty("jcr:lastModified", Calendar.getInstance());
+ cont1.setProperty("jcr:data", "The quick brown fox jump over the
lazy dog");
+ session.save();
+
+ Node doc2 = root.addNode("document2", "nt:file");
+ NodeImpl cont2 = (NodeImpl)doc2.addNode("jcr:content",
"nt:resource");
+ cont2.setProperty("jcr:mimeType", "text/plain");
+ cont2.setProperty("jcr:lastModified", Calendar.getInstance());
+ cont2.setProperty("jcr:data", "Dogs do not like cats.");
+
+ Node doc3 = root.addNode("document3", "nt:file");
+ NodeImpl cont3 = (NodeImpl)doc3.addNode("jcr:content",
"nt:resource");
+ cont3.setProperty("jcr:mimeType", "text/plain");
+ cont3.setProperty("jcr:lastModified", Calendar.getInstance());
+ cont3.setProperty("jcr:data", "Cats jumping high.");
+ session.save();
+ System.out.println("Done!");
+ try
+ {
+ Thread.sleep(60000);
+ }
+ catch (InterruptedException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ // do noting
+ }
+}
Property changes on:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestFullSearchPrepare.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestQueryPrepare.java
(from rev 948,
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/TestQueryPrepare.java)
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestQueryPrepare.java
(rev 0)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestQueryPrepare.java 2009-12-09
08:48:35 UTC (rev 954)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.lab.cluster.prepare;
+
+import org.exoplatform.services.jcr.JcrAPIBaseTest;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Calendar;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * @author <a href="mailto:nikolazius@gmail.com">Nikolay
Zamosenchuk</a>
+ * @version $Id: TestQueryPrepare.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ *
+ */
+public class TestQueryPrepare extends JcrAPIBaseTest
+{
+ public void testPrepareNodes() throws RepositoryException, IOException
+ {
+ System.out.println("preparing....");
+
+ root.addNode("simplenode", "nt:unstructured");
+
+ Node doc1 = root.addNode("document1", "nt:file");
+ NodeImpl cont = (NodeImpl)doc1.addNode("jcr:content",
"nt:resource");
+ cont.setProperty("jcr:mimeType", "text/plain");
+ cont.setProperty("jcr:lastModified", Calendar.getInstance());
+ cont.setProperty("jcr:encoding", "UTF-8");
+ cont.setProperty("jcr:data", new
ByteArrayInputStream("".getBytes()));
+
+ Node doc2 = root.addNode("document2", "nt:file");
+ cont = (NodeImpl)doc2.addNode("jcr:content", "nt:resource");
+ cont.setProperty("jcr:mimeType", "text/plain");
+ cont.setProperty("jcr:lastModified", Calendar.getInstance());
+ cont.setProperty("jcr:encoding", "UTF-8");
+ cont.setProperty("jcr:data", new
ByteArrayInputStream("".getBytes()));
+ session.save();
+ System.out.println("Done!");
+ try
+ {
+ Thread.sleep(60000);
+ }
+ catch (InterruptedException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ // do noting
+ }
+}
Property changes on:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestQueryPrepare.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestFullSearchAssert.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestFullSearchAssert.java
(rev 0)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestFullSearchAssert.java 2009-12-09
08:48:35 UTC (rev 954)
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.lab.cluster.test;
+
+import org.exoplatform.services.jcr.JcrAPIBaseTest;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+
+import java.util.Calendar;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.Row;
+import javax.jcr.query.RowIterator;
+
+/**
+ * @author <a href="mailto:nikolazius@gmail.com">Nikolay
Zamosenchuk</a>
+ * @version $Id: TestFullSearchAssert.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ *
+ */
+public class TestFullSearchAssert extends JcrAPIBaseTest
+{
+
+ public void testFullSearch() throws RepositoryException
+ {
+ Node cont1 = root.getNode("document1/jcr:content");
+ Node cont2 = root.getNode("document2/jcr:content");
+ Node cont3 = root.getNode("document3/jcr:content");
+
+ // make SQL query
+ QueryManager qman = this.workspace.getQueryManager();
+
+ Query q = qman.createQuery("SELECT * FROM nt:resource WHERE
CONTAINS(*,'do')", Query.SQL);
+ QueryResult res = q.execute();
+ long sqlsize = res.getNodes().getSize();
+ assertEquals(1, sqlsize);
+ checkResult(res, new Node[]{cont2});
+
+ //make XPath query
+ Query xq =
qman.createQuery("//element(*,nt:resource)[jcr:contains(.,'cats')]",
Query.XPATH);
+ QueryResult xres = xq.execute();
+ long xpathsize = xres.getNodes().getSize();
+ assertEquals(2, xpathsize);
+ checkResult(xres, new Node[]{cont2, cont3});
+ System.out.println("Done!");
+ try
+ {
+ Thread.sleep(60000);
+ }
+ catch (InterruptedException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ protected void checkResult(QueryResult result, Node[] nodes) throws
RepositoryException
+ {
+ // collect paths
+
+ String[] columnNames = result.getColumnNames();
+ String[][] vals = new
String[(int)result.getNodes().getSize()][result.getColumnNames().length];
+
+ RowIterator rit = result.getRows();
+ int j = 0;
+ while (rit.hasNext())
+ {
+ Row r = rit.nextRow();
+ Value[] v = r.getValues();
+ for (int i = 0; i < v.length; i++)
+ {
+ vals[j][i] = (v[i] != null) ? v[i].getString() : "null";
+ }
+ j++;
+ }
+
+ Set<String> expectedPaths = new HashSet<String>();
+ for (int i = 0; i < nodes.length; i++)
+ {
+ expectedPaths.add(nodes[i].getPath());
+ }
+ Set<String> resultPaths = new HashSet<String>();
+ for (NodeIterator it = result.getNodes(); it.hasNext();)
+ {
+ resultPaths.add(it.nextNode().getPath());
+ }
+
+ comparePaths(expectedPaths, resultPaths, false);
+ }
+
+ private void comparePaths(Set<String> expectedPaths, Set<String>
resultPaths, boolean canContainMore)
+ {
+ // check if all expected are in result
+ for (Iterator<String> it = expectedPaths.iterator(); it.hasNext();)
+ {
+ String path = it.next();
+ assertTrue(path + " is not part of the result set",
resultPaths.contains(path));
+ }
+
+ if (!canContainMore)
+ {
+ // check result does not contain more than expected
+
+ for (Iterator<String> it = resultPaths.iterator(); it.hasNext();)
+ {
+ String path = it.next();
+ assertTrue(path + " is not expected to be part of the result set. "
+ " Total size:" + resultPaths.size(),
+ expectedPaths.contains(path));
+ }
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ // do noting
+ }
+}
Property changes on:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestFullSearchAssert.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestQueryAssert.java
(from rev 949,
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/TestQueryAssert.java)
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestQueryAssert.java
(rev 0)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestQueryAssert.java 2009-12-09
08:48:35 UTC (rev 954)
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.lab.cluster.test;
+
+import org.exoplatform.services.jcr.JcrAPIBaseTest;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.Row;
+import javax.jcr.query.RowIterator;
+
+/**
+ * @author <a href="mailto:nikolazius@gmail.com">Nikolay
Zamosenchuk</a>
+ * @version $Id: TestQueryAssert.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ *
+ */
+public class TestQueryAssert extends JcrAPIBaseTest
+{
+ public void testAssert() throws RepositoryException, IOException
+ {
+ System.out.println("Start asserting....");
+
+ Node doc1 = root.getNode("document1");
+ Node doc2 = root.getNode("document2");
+
+ // make SQL query
+ QueryManager qman = this.workspace.getQueryManager();
+
+ Query q = qman.createQuery("SELECT * FROM nt:file ", Query.SQL);
+ QueryResult res = q.execute();
+ long sqlsize = res.getNodes().getSize();
+ assertEquals(2, sqlsize);
+ checkResult(res, new Node[]{doc1, doc2});
+
+ //make XPath query
+
+ Query xq = qman.createQuery("//element(*,nt:file)", Query.XPATH);
+ QueryResult xres = xq.execute();
+ long xpathsize = xres.getNodes().getSize();
+ assertEquals(2, xpathsize);
+ checkResult(xres, new Node[]{doc1, doc2});
+ System.out.println("Done!");
+ try
+ {
+ Thread.sleep(60000);
+ }
+ catch (InterruptedException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ protected void checkResult(QueryResult result, Node[] nodes) throws
RepositoryException
+ {
+ // collect paths
+
+ String[] columnNames = result.getColumnNames();
+ String[][] vals = new
String[(int)result.getNodes().getSize()][result.getColumnNames().length];
+
+ RowIterator rit = result.getRows();
+ int j = 0;
+ while (rit.hasNext())
+ {
+ Row r = rit.nextRow();
+ Value[] v = r.getValues();
+ for (int i = 0; i < v.length; i++)
+ {
+ vals[j][i] = (v[i] != null) ? v[i].getString() : "null";
+ }
+ j++;
+ }
+
+ Set<String> expectedPaths = new HashSet<String>();
+ for (int i = 0; i < nodes.length; i++)
+ {
+ expectedPaths.add(nodes[i].getPath());
+ }
+ Set<String> resultPaths = new HashSet<String>();
+ for (NodeIterator it = result.getNodes(); it.hasNext();)
+ {
+ resultPaths.add(it.nextNode().getPath());
+ }
+
+ comparePaths(expectedPaths, resultPaths, false);
+ }
+
+ private void comparePaths(Set<String> expectedPaths, Set<String>
resultPaths, boolean canContainMore)
+ {
+ // check if all expected are in result
+ for (Iterator<String> it = expectedPaths.iterator(); it.hasNext();)
+ {
+ String path = it.next();
+ assertTrue(path + " is not part of the result set",
resultPaths.contains(path));
+ }
+
+ if (!canContainMore)
+ {
+ // check result does not contain more than expected
+
+ for (Iterator<String> it = resultPaths.iterator(); it.hasNext();)
+ {
+ String path = it.next();
+ assertTrue(path + " is not expected to be part of the result set. "
+ " Total size:" + resultPaths.size(),
+ expectedPaths.contains(path));
+ }
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ // do noting
+ }
+}
Property changes on:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestQueryAssert.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain