Author: nzamosenchuk
Date: 2009-12-23 03:59:41 -0500 (Wed, 23 Dec 2009)
New Revision: 1150
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestFullSearchPrepare.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestLoadIndexerWriter.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestQueryPrepare.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestFullSearchAssert.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestLoadIndexerQuery.java
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestQueryAssert.java
Log:
EXOJCR-325: Manual tests for indexer in cluster ported from JBC branch.
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestFullSearchPrepare.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestFullSearchPrepare.java
(rev 0)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestFullSearchPrepare.java 2009-12-23
08:59:41 UTC (rev 1150)
@@ -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-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestFullSearchPrepare.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestLoadIndexerWriter.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestLoadIndexerWriter.java
(rev 0)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestLoadIndexerWriter.java 2009-12-23
08:59:41 UTC (rev 1150)
@@ -0,0 +1,199 @@
+/*
+ * 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.core.CredentialsImpl;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
+
+import java.util.Random;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * @author <a href="mailto:nikolazius@gmail.com">Nikolay
Zamosenchuk</a>
+ * @version $Id: TestLoadIndexerWriter.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ *
+ */
+public class TestLoadIndexerWriter extends JcrAPIBaseTest
+{
+ public static final String COUNT = "count";
+
+ public static final String CONTENT = "Content";
+
+ public static final String STATISTIC = "Statistic";
+
+ private boolean stop = false;
+
+ private int threadCount = 1;
+
+ private static final String[] words =
+ new String[]{"private", "branch", "final",
"string", "logging", "bottle", "property",
"node", "repository",
+ "exception", "cycle", "value", "index",
"meaning", "strange", "words", "hello",
"outline", "finest",
+ "basetest", "writer"};
+
+ public void testWrite() throws RepositoryException
+ {
+ log.info("Creating threads...");
+ for (int i = 0; i < threadCount; i++)
+ {
+ // create new thread and start it
+ new Thread(new WriterTask(i)).start();
+ log.info("Thread#" + i + " created and started.");
+ }
+
+ // wait 4 minutes
+ try
+ {
+ Thread.sleep(60000 * 4);
+ }
+ catch (InterruptedException e)
+ {
+ log.error(e);
+ }
+
+ stop = true;
+ }
+
+ private class WriterTask implements Runnable
+ {
+
+ private int id;
+
+ private SessionImpl sessionLocal;
+
+ private Node statisticNode;
+
+ private Node contentNode;
+
+ private Random random;
+
+ public WriterTask(int id) throws RepositoryException
+ {
+ this.id = id;
+ // login
+ CredentialsImpl credentials = new CredentialsImpl("admin",
"admin".toCharArray());
+ sessionLocal = (SessionImpl)repository.login(credentials, "ws");
+ // prepare nodes
+ Node root = sessionLocal.getRootNode();
+ Node threadNode = root.addNode("Thread" + id);
+ statisticNode = threadNode.addNode(STATISTIC);
+ contentNode = threadNode.addNode(CONTENT);
+ random = new Random();
+ sessionLocal.save();
+ }
+
+ /**
+ * @see java.lang.Runnable#run()
+ */
+ public void run()
+ {
+ try
+ {
+ while (!stop)
+ {
+ // get any word
+ int i = random.nextInt(words.length);
+ String word = words[i] + id; // "hello12" if thread#12 is
creating it
+ // update statistic
+ updateStatistic(word);
+ // add actual node
+ createTree().addNode(word);
+ sessionLocal.save();
+ System.out.print("#");
+
+ try
+ {
+ Thread.sleep(300);
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+ }
+ catch (RepositoryException e)
+ {
+ log.error(e);
+ }
+ }
+
+ /**
+ * increments property in JCR: "./statistic/[word].count"
+ *
+ * @param word
+ * @throws RepositoryException
+ */
+ private void updateStatistic(String word) throws RepositoryException
+ {
+ Node wordNode;
+ long count = 0;
+ if (statisticNode.hasNode(word))
+ {
+ wordNode = statisticNode.getNode(word);
+ count = wordNode.getProperty(COUNT).getLong();
+ }
+ else
+ {
+ wordNode = statisticNode.addNode(word);
+ }
+ wordNode.setProperty(COUNT, count + 1);
+ }
+
+ /**
+ * Created node tree like: "./content/n123456/n1234567/n12345678"
+ * based on current time
+ *
+ * @return
+ * @throws RepositoryException
+ */
+ private Node createTree() throws RepositoryException
+ {
+ // created node tree like: "./content/n123456/n1234567/n12345678"
+ Node end;
+ long time = System.currentTimeMillis();
+ long child1 = time / 100000; // each 100s new node
+ long child2 = time / 10000; // each 10s new node
+ long child3 = time / 1000; // each 1s new node
+ end = addOrCreate("n" + child1, contentNode);
+ end = addOrCreate("n" + child2, end);
+ end = addOrCreate("n" + child3, end);
+ return end;
+ }
+
+ /**
+ * Gets or creates node
+ *
+ * @param name
+ * @param parent
+ * @return
+ * @throws RepositoryException
+ */
+ private Node addOrCreate(String name, Node parent) throws RepositoryException
+ {
+ if (parent.hasNode(name))
+ {
+ return parent.getNode(name);
+ }
+ else
+ return parent.addNode(name);
+ }
+ }
+
+}
Property changes on:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestLoadIndexerWriter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestQueryPrepare.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestQueryPrepare.java
(rev 0)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/prepare/TestQueryPrepare.java 2009-12-23
08:59:41 UTC (rev 1150)
@@ -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-JBCCACHE/exo.jcr.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-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestFullSearchAssert.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestFullSearchAssert.java
(rev 0)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestFullSearchAssert.java 2009-12-23
08:59:41 UTC (rev 1150)
@@ -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-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestFullSearchAssert.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestLoadIndexerQuery.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestLoadIndexerQuery.java
(rev 0)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestLoadIndexerQuery.java 2009-12-23
08:59:41 UTC (rev 1150)
@@ -0,0 +1,145 @@
+/*
+ * 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 junit.framework.AssertionFailedError;
+
+import org.exoplatform.services.jcr.JcrAPIBaseTest;
+import org.exoplatform.services.jcr.core.CredentialsImpl;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.jcr.lab.cluster.prepare.TestLoadIndexerWriter;
+
+import java.util.Random;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+
+/**
+ * @author <a href="mailto:nikolazius@gmail.com">Nikolay
Zamosenchuk</a>
+ * @version $Id: TestLoadIndexerQuery.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ *
+ */
+public class TestLoadIndexerQuery extends JcrAPIBaseTest
+{
+ private boolean stop = false;
+
+ private int threadCount = 1;
+
+ public void testQuery() throws RepositoryException
+ {
+ log.info("Creating threads...");
+ for (int i = 0; i < threadCount; i++)
+ {
+ // create new thread and start it
+ new Thread(new QueryTask()).start();
+ log.info("Thread#" + i + " created and started.");
+ }
+
+ // wait 4 minutes
+ try
+ {
+ Thread.sleep(60000 * 4);
+ }
+ catch (InterruptedException e)
+ {
+ log.error(e);
+ }
+
+ stop = true;
+ }
+
+ private class QueryTask implements Runnable
+ {
+ private SessionImpl sessionLocal;
+
+ private Node rootLocal;
+
+ private Random random;
+
+ public QueryTask() throws RepositoryException
+ {
+ // login
+ CredentialsImpl credentials = new CredentialsImpl("admin",
"admin".toCharArray());
+ sessionLocal = (SessionImpl)repository.login(credentials, "ws");
+ // prepare nodes
+ rootLocal = sessionLocal.getRootNode();
+ random = new Random();
+ }
+
+ /**
+ * @see java.lang.Runnable#run()
+ */
+ public void run()
+ {
+ try
+ {
+ while (!stop)
+ {
+ Node threadNode = getRandomChild(rootLocal, "Thread*");
+ if (threadNode != null)
+ {
+ Node statisticNode =
threadNode.getNode(TestLoadIndexerWriter.STATISTIC);
+ Node wordNode = getRandomChild(statisticNode, "*");
+ if (wordNode != null)
+ {
+ String word = wordNode.getName();
+ Long count =
wordNode.getProperty(TestLoadIndexerWriter.COUNT).getLong();
+
+ QueryManager qman = sessionLocal.getWorkspace().getQueryManager();
+
+ Query q = qman.createQuery("SELECT * FROM nt:base WHERE
fn:name() = '" + word + "'", Query.SQL);
+ QueryResult res = q.execute();
+ long sqlsize = res.getNodes().getSize();
+ try
+ {
+ assertTrue("Exp: "+count+"\t found:"+sqlsize,
sqlsize >= count);
+ System.out.print("+("+sqlsize+")");
+ }
+ catch (AssertionFailedError e)
+ {
+ System.out.println("-"+e.getMessage());
+ }
+ }
+ }
+ }
+
+ }
+ catch (RepositoryException e)
+ {
+ log.error(e);
+ }
+ }
+
+ private Node getRandomChild(Node parent, String pattern) throws
RepositoryException
+ {
+ NodeIterator iterator = parent.getNodes(pattern);
+ if (iterator.getSize() < 1)
+ {
+ return null;
+ }
+ int i = random.nextInt((int)iterator.getSize());
+ iterator.skip(i);
+ return iterator.nextNode();
+ }
+ }
+}
Property changes on:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestLoadIndexerQuery.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestQueryAssert.java
===================================================================
---
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestQueryAssert.java
(rev 0)
+++
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestQueryAssert.java 2009-12-23
08:59:41 UTC (rev 1150)
@@ -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-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/cluster/test/TestQueryAssert.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain