incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1541972 - in /sling/trunk/bundles/jcr/it-jackrabbit-oak: pom.xml src/test/java/org/apache/sling/jcr/repository/it/CommonTests.java src/test/java/org/apache/sling/jcr/repository/it/Retry.java
Date Thu, 14 Nov 2013 16:50:50 GMT
Author: bdelacretaz
Date: Thu Nov 14 16:50:50 2013
New Revision: 1541972

URL: http://svn.apache.org/r1541972
Log:
SLING-3147 - try to reproduce the observation problem (didn't succeed so far)

Added:
    sling/trunk/bundles/jcr/it-jackrabbit-oak/src/test/java/org/apache/sling/jcr/repository/it/Retry.java
Modified:
    sling/trunk/bundles/jcr/it-jackrabbit-oak/pom.xml
    sling/trunk/bundles/jcr/it-jackrabbit-oak/src/test/java/org/apache/sling/jcr/repository/it/CommonTests.java

Modified: sling/trunk/bundles/jcr/it-jackrabbit-oak/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/it-jackrabbit-oak/pom.xml?rev=1541972&r1=1541971&r2=1541972&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/it-jackrabbit-oak/pom.xml (original)
+++ sling/trunk/bundles/jcr/it-jackrabbit-oak/pom.xml Thu Nov 14 16:50:50 2013
@@ -23,9 +23,9 @@
     <inceptionYear>2013</inceptionYear>
 
     <properties>
-        <exam.version>3.2.0</exam.version>
+        <exam.version>3.3.0</exam.version>
         <url.version>1.5.2</url.version>
-        <org.ops4j.pax.logging.DefaultServiceLog.level>INFO</org.ops4j.pax.logging.DefaultServiceLog.level>
+        <org.ops4j.pax.logging.DefaultServiceLog.level>WARN</org.ops4j.pax.logging.DefaultServiceLog.level>
         <org.ops4j.pax.url.mvn.settings></org.ops4j.pax.url.mvn.settings>
         <oak.version>0.10</oak.version>
     </properties>
@@ -217,5 +217,11 @@
             <version>3.2.2</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-jcr-commons</artifactId>
+            <version>2.7.1</version>
+            <scope>test</scope>
+        </dependency>
      </dependencies>
 </project>

Modified: sling/trunk/bundles/jcr/it-jackrabbit-oak/src/test/java/org/apache/sling/jcr/repository/it/CommonTests.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/it-jackrabbit-oak/src/test/java/org/apache/sling/jcr/repository/it/CommonTests.java?rev=1541972&r1=1541971&r2=1541972&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/it-jackrabbit-oak/src/test/java/org/apache/sling/jcr/repository/it/CommonTests.java
(original)
+++ sling/trunk/bundles/jcr/it-jackrabbit-oak/src/test/java/org/apache/sling/jcr/repository/it/CommonTests.java
Thu Nov 14 16:50:50 2013
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.io.Reader;
+import java.io.StringReader;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
@@ -37,8 +39,12 @@ import javax.jcr.Property;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
+import javax.jcr.observation.EventIterator;
+import javax.jcr.observation.EventListener;
+import javax.jcr.observation.ObservationManager;
 import javax.jcr.query.Query;
 
+import org.apache.jackrabbit.commons.cnd.CndImporter;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.junit.After;
 import org.junit.Test;
@@ -71,6 +77,53 @@ public abstract class CommonTests {
     private final List<String> toDelete = new LinkedList<String>();
     private final AtomicInteger uniqueNameCounter = new AtomicInteger();
     
+    public static final String I18N_MESSAGE_CND = 
+        "<sling = 'http://sling.apache.org/jcr/sling/1.0'>\n"
+        + "[mix:language]\n"
+        + "mixin\n"
+        + "- jcr:language (string)\n"
+        + "\n"
+        + "[sling:Message]\n"
+        + "mixin\n"
+        + "- sling:key (string)\n"
+        + "- sling:message (undefined)\n"
+        + "\n"
+        + "[sling:MessageEntry] > nt:hierarchyNode, sling:Message\n"
+        ;
+    
+    protected class JcrEventsCounter implements EventListener {
+        private final Session s;
+        private int jcrEventsCounter;
+        
+        public JcrEventsCounter() throws RepositoryException {
+            s = repository.loginAdministrative(null);
+            final ObservationManager om = s.getWorkspace().getObservationManager();
+            final int eventTypes = 255; // not sure if that's a recommended value, but common
+            final boolean deep = true;
+            final String [] uuid = null;
+            final String [] nodeTypeNames = new String [] { "mix:language", "sling:Message"
};
+            final boolean noLocal = true;
+            final String root = "/";
+            om.addEventListener(this, eventTypes, root, deep, uuid, nodeTypeNames, noLocal);
+        }
+        
+        void close() {
+            s.logout();
+        }
+        
+        @Override
+        public void onEvent(EventIterator it) {
+            while(it.hasNext()) {
+                it.nextEvent();
+                jcrEventsCounter++;
+            }
+        }
+
+        int get() {
+            return jcrEventsCounter;
+        }
+    }
+    
     private <ItemType extends Item> ItemType deleteAfterTests(ItemType it) throws RepositoryException
{
         toDelete.add(it.getPath());
         return it;
@@ -104,7 +157,7 @@ public abstract class CommonTests {
     protected String uniqueName(String hint) {
         return hint + "_" + uniqueNameCounter.incrementAndGet() + "_" + System.currentTimeMillis();
     }
-
+    
     @After
     public void deleteTestItems() throws RepositoryException {
         if(toDelete.isEmpty()) {
@@ -327,4 +380,61 @@ public abstract class CommonTests {
             s.logout();
         }
     }
+    
+    @Test
+    public void testNodetypeObservation() throws Exception {
+        Session s = repository.loginAdministrative(null);
+        final Reader cnd = new StringReader(I18N_MESSAGE_CND);
+        JcrEventsCounter counter = null;
+        final String path = "/" + uniqueName("observation");
+        
+        // Add a sling:MessageEntry and verify that we get JCR events
+        try {
+            CndImporter.registerNodeTypes(cnd, s);
+            counter = new JcrEventsCounter();
+            
+            final Node n = s.getRootNode().addNode(path.substring(1), "sling:MessageEntry");

+            toDelete.add(n.getPath());
+            n.setProperty("sling:key", "foo");
+            n.setProperty("sling:message", "bar");
+            s.save();
+            
+            final JcrEventsCounter c = counter;
+            new Retry(5000) {
+                @Override
+                protected void exec() throws Exception {
+                    assertTrue("Expecting JCR events after adding " + path, c.get() >
0);
+                }
+            };
+            
+        } finally {
+            s.logout();
+            cnd.close();
+            counter.close();
+        }
+        
+        // In a separate session, modify node and verify that we get events
+        counter = new JcrEventsCounter();
+        s = repository.loginAdministrative(null);
+        try {
+            
+            final Node n = s.getNode(path); 
+            n.setProperty("sling:message", "CHANGED now");
+            s.save();
+            
+            final JcrEventsCounter c = counter;
+            new Retry(5000) {
+                @Override
+                protected void exec() throws Exception {
+                    assertTrue("Expecting JCR events after modifying " + path, c.get() >
0);
+                }
+            };
+            
+        } finally {
+            s.logout();
+            cnd.close();
+            counter.close();
+        }
+
+    }
 }
\ No newline at end of file

Added: sling/trunk/bundles/jcr/it-jackrabbit-oak/src/test/java/org/apache/sling/jcr/repository/it/Retry.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/it-jackrabbit-oak/src/test/java/org/apache/sling/jcr/repository/it/Retry.java?rev=1541972&view=auto
==============================================================================
--- sling/trunk/bundles/jcr/it-jackrabbit-oak/src/test/java/org/apache/sling/jcr/repository/it/Retry.java
(added)
+++ sling/trunk/bundles/jcr/it-jackrabbit-oak/src/test/java/org/apache/sling/jcr/repository/it/Retry.java
Thu Nov 14 16:50:50 2013
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.jcr.repository.it;
+
+import static org.junit.Assert.fail;
+
+/** Simple Retry loop for tests */
+public abstract class Retry {
+    
+    public Retry(int timeoutMsec) {
+        final long timeout = System.currentTimeMillis() + timeoutMsec;
+        Throwable lastT = null;
+        while(System.currentTimeMillis() < timeout) {
+            try {
+                lastT = null;
+                exec();
+                break;
+            } catch(Throwable t) {
+                lastT = t;
+            }
+        }
+        
+        if(lastT != null) {
+            fail("Failed after " + timeoutMsec + " msec: " + lastT);
+        }
+    }
+    
+    protected abstract void exec() throws Exception;
+}



Mime
View raw message