[exo-jcr-commits] exo-jcr SVN: r1313 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Jan 6 07:19:48 EST 2010


Author: nzamosenchuk
Date: 2010-01-06 07:19:48 -0500 (Wed, 06 Jan 2010)
New Revision: 1313

Modified:
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavQueryTest.java
Log:
EXOJCR-340: Added timeout between ADD and SEARCH.

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavQueryTest.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavQueryTest.java	2010-01-06 11:11:39 UTC (rev 1312)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavQueryTest.java	2010-01-06 12:19:48 UTC (rev 1313)
@@ -58,6 +58,11 @@
    public static final String MIME_TEXT_HTML = "text/html";
 
    /**
+    * Delay between adding nodes and querying repository (in ms) 
+    */
+   public static final int SLEEP_BEFORE_QUERY = 6000;
+
+   /**
     * Full-text query tests
     */
    public void testFullTextSearch() throws Exception
@@ -93,20 +98,22 @@
       {
          conn.addNode(entry.getKey(), entry.getValue().getBytes(), MIME_TEXT_PLAIN);
       }
+      // wait for indexer to flush volatile index
+      sleep();
 
       // map containing test-case: <SQL query> : <expected nodes>
       Map<String, String[]> sqlCases = new HashMap<String, String[]>();
       sqlCases.put("SELECT * FROM nt:base WHERE CONTAINS(*,'tailored')", new String[]{"JCR_Overview"});
       sqlCases.put("SELECT * FROM nt:base WHERE CONTAINS(*,'XPathQuery')", new String[]{"JCR_Queries"});
       sqlCases.put("SELECT * FROM nt:resource WHERE CONTAINS(*,'API')", new String[]{"JCR_Structure", "JCR_Overview"});
-      assertQuery(conn, sqlCases, Query.SQL);
+      assertQuery(sqlCases, Query.SQL);
 
       // map containing test-case: <XPATH query> : <expected nodes>
       Map<String, String[]> xpathCases = new HashMap<String, String[]>();
       xpathCases.put("//element(*, nt:base)[jcr:contains(.,'tailored')]", new String[]{"JCR_Overview"});
       xpathCases.put("//element(*, nt:base)[jcr:contains(.,'XPathQuery')]", new String[]{"JCR_Queries"});
       xpathCases.put("//element(*, nt:resource)[jcr:contains(.,'API')]", new String[]{"JCR_Structure", "JCR_Overview"});
-      assertQuery(conn, xpathCases, Query.XPATH);
+      assertQuery(xpathCases, Query.XPATH);
       // remove created nodes
       for (Entry<String, String> entry : nodes.entrySet())
       {
@@ -134,20 +141,23 @@
       {
          conn.addNode(testLocalRootName + "/" + name, "_data_".getBytes());
       }
+      // wait for indexer to flush volatile index
+      sleep();
+
       // map containing test-case: <SQL query> : <expected nodes>
       Map<String, String[]> sqlCases = new HashMap<String, String[]>();
       sqlCases.put("SELECT * FROM nt:base WHERE jcr:path LIKE '/" + testLocalRootName
          + "[%]/%' AND NOT jcr:path LIKE '/" + testLocalRootName + "[%]/%/%' ", expected.toArray(new String[expected
          .size()]));
       sqlCases.put("SELECT * FROM nt:base WHERE fn:name() = 'exoString'", new String[]{"exoString"});
-      assertQuery(conn, sqlCases, Query.SQL);
+      assertQuery(sqlCases, Query.SQL);
 
       // map containing test-case: <XPATH query> : <expected nodes>
       Map<String, String[]> xpathCases = new HashMap<String, String[]>();
       xpathCases.put("/jcr:root/" + testLocalRootName + "/ element(*, nt:base)", expected.toArray(new String[expected
          .size()]));
       xpathCases.put("//element(*,nt:file)[fn:name() = 'exoString']", new String[]{"exoString"});
-      assertQuery(conn, xpathCases, Query.XPATH);
+      assertQuery(xpathCases, Query.XPATH);
 
       conn.removeNode(testLocalRootName);
    }
@@ -181,6 +191,8 @@
       {
          conn.addNode(entry.getKey(), "content".getBytes(), entry.getValue());
       }
+      // wait for indexer to flush volatile index
+      sleep();
 
       // map containing test-case: <SQL query> : <expected nodes>
       Map<String, String[]> sqlCases = new HashMap<String, String[]>();
@@ -190,7 +202,7 @@
          MIME_TEXT_HTML));
       sqlCases.put("SELECT * FROM nt:resource WHERE jcr:mimeType LIKE 'text%'", nodes.keySet().toArray(
          new String[nodes.size()]));
-      assertQuery(conn, sqlCases, Query.SQL);
+      assertQuery(sqlCases, Query.SQL);
 
       // map containing test-case: <XPATH query> : <expected nodes>
       Map<String, String[]> xpathCases = new HashMap<String, String[]>();
@@ -200,7 +212,7 @@
          MIME_TEXT_HTML));
       xpathCases.put("//element(*,nt:resource)[jcr:like(@jcr:mimeType, 'text%')]", nodes.keySet().toArray(
          new String[nodes.size()]));
-      assertQuery(conn, xpathCases, Query.XPATH);
+      assertQuery(xpathCases, Query.XPATH);
 
       // remove created nodes
       for (Entry<String, String> entry : nodes.entrySet())
@@ -222,21 +234,24 @@
     * @throws XMLStreamException
     * @throws FactoryConfigurationError
     */
-   private void assertQuery(JCRWebdavConnection conn, Map<String, String[]> queryCases, String lang)
-      throws IOException, ModuleException, XMLStreamException, FactoryConfigurationError
+   private void assertQuery(Map<String, String[]> queryCases, String lang) throws IOException, ModuleException,
+      XMLStreamException, FactoryConfigurationError
    {
       if (lang.equals(Query.SQL) || lang.equals(Query.XPATH))
       {
-         for (Entry<String, String[]> entry : queryCases.entrySet())
+         for (JCRWebdavConnection connection : getConnections())
          {
-            HTTPResponse response =
-               lang.equals(Query.SQL) ? conn.sqlQuery(entry.getKey()) : conn.xpathQuery(entry.getKey());
-            assertEquals(207, response.getStatusCode());
-            List<String> found;
-            assertEquals(207, response.getStatusCode());
-            found = parseNodeNames(response.getData());
-            assertTrue("Lists are not equals:\n*found:\t" + found + "\n*expected:\t" + entry.getValue(), compareLists(
-               Arrays.asList(entry.getValue()), found));
+            for (Entry<String, String[]> entry : queryCases.entrySet())
+            {
+               HTTPResponse response =
+                  lang.equals(Query.SQL) ? connection.sqlQuery(entry.getKey()) : connection.xpathQuery(entry.getKey());
+               assertEquals(207, response.getStatusCode());
+               List<String> found;
+               assertEquals(207, response.getStatusCode());
+               found = parseNodeNames(response.getData());
+               assertTrue("Lists are not equals:\n*found:\t" + found + "\n*expected:\t" + entry.getValue(),
+                  compareLists(Arrays.asList(entry.getValue()), found));
+            }
          }
       }
       else
@@ -342,4 +357,19 @@
       }
       return new ArrayList<String>(nodes);
    }
+
+   /**
+    * Sleep for SLEEP_BEFORE_QUERY seconds. This is needed because Indexer is asynchronous and 
+    * volatile index can be flushed after some time. 
+    */
+   private void sleep()
+   {
+      try
+      {
+         Thread.sleep(SLEEP_BEFORE_QUERY);
+      }
+      catch (InterruptedException e)
+      {
+      }
+   }
 }



More information about the exo-jcr-commits mailing list