sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1726652 - in /sling/trunk/installer/providers/jcr/src: main/java/org/apache/sling/installer/provider/jcr/impl/ test/java/org/apache/sling/installer/provider/jcr/impl/
Date Mon, 25 Jan 2016 16:12:26 GMT
Author: bdelacretaz
Date: Mon Jan 25 16:12:25 2016
New Revision: 1726652

URL: http://svn.apache.org/viewvc?rev=1726652&view=rev
Log:
SLING-5371 - minor changes in RootFolderMoveListener + add tests, one of them ignored for
now

Added:
    sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/RootFolderMoveListenerTest.java
Modified:
    sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/RescanTimer.java
    sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/RootFolderMoveListener.java
    sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/MiscUtil.java

Modified: sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/RescanTimer.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/RescanTimer.java?rev=1726652&r1=1726651&r2=1726652&view=diff
==============================================================================
--- sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/RescanTimer.java
(original)
+++ sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/RescanTimer.java
Mon Jan 25 16:12:25 2016
@@ -24,11 +24,26 @@ package org.apache.sling.installer.provi
  */
 
 class RescanTimer {
-    public static final long SCAN_DELAY_MSEC = 500L;
+    public static final long DEFAULT_SCAN_DELAY_MSEC = 500L;
     private long nextScanTime = Long.MAX_VALUE;
+    private final long scanDelay;
+    
+    /** Create a timer with a non-default delay - this should ONLY
+     *  be used in tests for now, as the existing code makes
+     *  some assumptions about this. 
+     * @param scanDelayMsec delay in msec
+     */
+    RescanTimer(long scanDelayMsec) {
+        this.scanDelay = scanDelayMsec;
+    }
+    
+    /** Standard constructor for non-test code */
+    RescanTimer() {
+        this(DEFAULT_SCAN_DELAY_MSEC);
+    }
     
     synchronized void scheduleScan() {
-        nextScanTime = System.currentTimeMillis() + SCAN_DELAY_MSEC;
+        nextScanTime = System.currentTimeMillis() + scanDelay;
     }
     
     synchronized void reset() {

Modified: sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/RootFolderMoveListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/RootFolderMoveListener.java?rev=1726652&r1=1726651&r2=1726652&view=diff
==============================================================================
--- sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/RootFolderMoveListener.java
(original)
+++ sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/RootFolderMoveListener.java
Mon Jan 25 16:12:25 2016
@@ -62,13 +62,16 @@ class RootFolderMoveListener implements
                 observationManager.addEventListener(this, eventFilter);
                 toCleanup = this;
                 logger.info("Watching {} to detect move changes in subfolders", Arrays.toString(watchedPaths));
+            } else {
+                logger.warn("ObservationManager is not a JackrabbitObservationManager, won't
observe moves for {}", 
+                        Arrays.asList(rootFolders));
             }
         }
     }
 
     @Override
     public String toString() {
-        return getClass().getSimpleName() + " (" + watchedPaths + ")";
+        return getClass().getSimpleName() + " (" + Arrays.asList(watchedPaths) + ")";
     }
 
     void cleanup(final Session session) throws RepositoryException {

Modified: sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/MiscUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/MiscUtil.java?rev=1726652&r1=1726651&r2=1726652&view=diff
==============================================================================
--- sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/MiscUtil.java
(original)
+++ sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/MiscUtil.java
Mon Jan 25 16:12:25 2016
@@ -109,7 +109,8 @@ class MiscUtil {
         // First wait for all JCR events to be delivered
         eventHelper.waitForEvents(5000L);
         // RescanTimer causes a SCAN_DELAY_MSEC wait after JCR events are received
-        Thread.sleep(RescanTimer.SCAN_DELAY_MSEC * 4);
+        // This assumes the RescanTimer is using its default delay, as per its javadoc
+        Thread.sleep(RescanTimer.DEFAULT_SCAN_DELAY_MSEC * 4);
         // And wait for a few JcrInstaller run cycles
         MiscUtil.waitForCycles(installer, startCycles, 2, 10000L);
     }

Added: sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/RootFolderMoveListenerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/RootFolderMoveListenerTest.java?rev=1726652&view=auto
==============================================================================
--- sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/RootFolderMoveListenerTest.java
(added)
+++ sling/trunk/installer/providers/jcr/src/test/java/org/apache/sling/installer/provider/jcr/impl/RootFolderMoveListenerTest.java
Mon Jan 25 16:12:25 2016
@@ -0,0 +1,96 @@
+/*
+ * 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.installer.provider.jcr.impl;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import javax.jcr.Session;
+
+import org.apache.sling.commons.testing.jcr.RepositoryProvider;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Tests for the RootFolderMoveListener
+ */
+public class RootFolderMoveListenerTest {
+    private RootFolderMoveListener rmlt;
+    private static final long TEST_SCAN_DELAY_MSEC = 5; 
+    private final RescanTimer timer = new RescanTimer(TEST_SCAN_DELAY_MSEC);
+    private Session session;
+    
+    public static final String [] ROOTS = { "/foo", "/bar" };
+    
+    protected boolean needsTestContent() {
+        return true;
+    }
+    
+    @Before
+    public void setup() throws Exception {
+        session = RepositoryProvider.instance().getRepository().loginAdministrative(null);
+        rmlt = new RootFolderMoveListener(session, ROOTS, timer);
+    }
+    
+    @After
+    public void cleanup() {
+        session.logout();
+    }
+    
+    private void waitForScanDelay() {
+        try {
+            Thread.sleep(2 * TEST_SCAN_DELAY_MSEC);
+        } catch(InterruptedException iex) {
+            fail("Sleep failed: " + iex);
+        }
+    }
+    
+    @Test
+    public void testToString() {
+        final String str = rmlt.toString();
+        assertTrue("Expecting " + str + " to contain our list of paths", str.contains("/foo,
/bar"));
+    }
+    
+    @Test
+    public void testTimer() {
+        assertFalse(timer.expired());
+        timer.scheduleScan();
+        waitForScanDelay();
+        assertTrue(timer.expired());
+    }
+    
+    @Test
+    @Ignore("Scan is not scheduled by move??")
+    public void testMove() throws Exception {
+        session.getRootNode().addNode("foo");
+        session.getNode("/foo").addNode("one");
+        session.save();
+        
+        waitForScanDelay();
+        assertFalse("Expecting no scheduled scan before move", timer.expired());
+        
+        session.move("/foo/one", "/foo/two");
+        session.save();
+        waitForScanDelay();
+        assertTrue("Expecting scan to be triggered after move", timer.expired());
+    }
+}
\ No newline at end of file



Mime
View raw message