Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 95937 invoked from network); 10 Sep 2008 15:02:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Sep 2008 15:02:41 -0000 Received: (qmail 88412 invoked by uid 500); 10 Sep 2008 15:02:38 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 88382 invoked by uid 500); 10 Sep 2008 15:02:38 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 88372 invoked by uid 99); 10 Sep 2008 15:02:38 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Sep 2008 08:02:38 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Sep 2008 15:01:48 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5B186238896D; Wed, 10 Sep 2008 08:02:20 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r693865 - in /incubator/sling/trunk/extensions/jcrinstall/src: main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ Date: Wed, 10 Sep 2008 15:02:19 -0000 To: sling-commits@incubator.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080910150220.5B186238896D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bdelacretaz Date: Wed Sep 10 08:02:18 2008 New Revision: 693865 URL: http://svn.apache.org/viewvc?rev=693865&view=rev Log: SLING-646 - fix failing tests Added: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MockRepositoryObserver.java (with props) Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ContentHelper.java incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MiscHelper.java incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java?rev=693865&r1=693864&r2=693865&view=diff ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java (original) +++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java Wed Sep 10 08:02:18 2008 @@ -53,16 +53,16 @@ */ public class RepositoryObserver implements Runnable { - private Set folders; + protected Set folders; private RegexpFilter folderNameFilter; private RegexpFilter filenameFilter; private boolean running; /** @scr.reference */ - private OsgiController osgiController; + protected OsgiController osgiController; /** @scr.reference */ - private SlingRepository repository; + protected SlingRepository repository; private Session session; @@ -76,7 +76,7 @@ public static final String DEFAULT_FILENAME_REGEXP = "[a-zA-Z0-9].*\\.[a-zA-Z][a-zA-Z][a-zA-Z]?"; /** Scan delay for watched folders */ - private final long scanDelayMsec = 1000L; + protected long scanDelayMsec = 1000L; protected static final Logger log = LoggerFactory.getLogger(WatchedFolder.class); @@ -225,9 +225,8 @@ log.warn("IllegalArgumentException in " + getClass().getSimpleName(), ie); } catch (RepositoryException re) { log.warn("RepositoryException in " + getClass().getSimpleName(), re); - } catch (Throwable t) { - log.error("Unhandled Throwable in runOneCycle() - " - + getClass().getSimpleName() + " thread will be stopped", t); + } catch (Exception e) { + log.error("Unhandled Exception in runOneCycle()", e); } finally { try { Thread.sleep(1000L); Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java?rev=693865&r1=693864&r2=693865&view=diff ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java (original) +++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java Wed Sep 10 08:02:18 2008 @@ -63,10 +63,11 @@ this.scanDelayMsec = scanDelayMsec; session = repository.loginAdministrative(repository.getDefaultWorkspace()); - // observe any changes in our folder, but not recursively + // observe any changes in our folder (and under it, as changes to properties + // might be lower in the hierarchy) final int eventTypes = Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED; - final boolean isDeep = false; + final boolean isDeep = true; final boolean noLocal = true; session.getWorkspace().getObservationManager().addEventListener(this, eventTypes, path, isDeep, null, null, noLocal); Modified: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ContentHelper.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ContentHelper.java?rev=693865&r1=693864&r2=693865&view=diff ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ContentHelper.java (original) +++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ContentHelper.java Wed Sep 10 08:02:18 2008 @@ -100,6 +100,7 @@ c.setTimeInMillis(lastModified); res.setProperty(JCR_LASTMODIFIED, c); res.setProperty(JCR_DATA, data); + f.getParent().save(); } } \ No newline at end of file Modified: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java?rev=693865&r1=693864&r2=693865&view=diff ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java (original) +++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java Wed Sep 10 08:02:18 2008 @@ -67,34 +67,34 @@ public void testInitialFind() throws Exception { contentHelper.setupContent(); - final RepositoryObserver ro = MiscHelper.createRepositoryObserver(repo, osgiController); + final MockRepositoryObserver ro = new MockRepositoryObserver(repo, osgiController); ro.activate(null); - final Set wfSet = MiscHelper.getWatchedFolders(ro); + final Set wfSet = ro.getWatchedFolders(); assertEquals("activate() must find all watched folders", contentHelper.WATCHED_FOLDERS.length, wfSet.size()); for(String folder : contentHelper.WATCHED_FOLDERS) { assertTrue("Folder " + folder + " must be watched (watched=" + wfSet + ")", - MiscHelper.folderIsWatched(ro, folder)); + ro.folderIsWatched(folder)); } } public void testNewWatchedFolderDetection() throws Exception { contentHelper.setupContent(); - final RepositoryObserver ro = MiscHelper.createRepositoryObserver(repo, osgiController); + final MockRepositoryObserver ro = new MockRepositoryObserver(repo, osgiController); ro.activate(null); final String newPaths [] = { "libs/tnwf/install", "apps/tnwf/install" }; for(String newPath : newPaths) { - assertFalse(newPath + " must not be watched before test", MiscHelper.folderIsWatched(ro, newPath)); + assertFalse(newPath + " must not be watched before test", ro.folderIsWatched(newPath)); // Create folder, wait for observation event and check that // it is detected contentHelper.createFolder(newPath); eventHelper.waitForEvents(5000L); - assertFalse(newPath + " must not be watched before calling addNewWatchedFolders()", MiscHelper.folderIsWatched(ro, newPath)); + assertFalse(newPath + " must not be watched before calling addNewWatchedFolders()", ro.folderIsWatched(newPath)); ro.addNewWatchedFolders(); - assertTrue(newPath + " must be watched before calling addNewWatchedFolders()", MiscHelper.folderIsWatched(ro, newPath)); + assertTrue(newPath + " must be watched before calling addNewWatchedFolders()", ro.folderIsWatched(newPath)); } } } \ No newline at end of file Modified: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MiscHelper.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MiscHelper.java?rev=693865&r1=693864&r2=693865&view=diff ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MiscHelper.java (original) +++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MiscHelper.java Wed Sep 10 08:02:18 2008 @@ -21,38 +21,9 @@ import java.lang.reflect.Field; import java.util.Set; -import org.apache.sling.jcr.api.SlingRepository; -import org.apache.sling.jcr.jcrinstall.osgi.OsgiController; - /** Miscellaneous test helper functions */ class MiscHelper { - static boolean folderIsWatched(RepositoryObserver ro, String path) throws Exception { - boolean result = false; - final Set wfSet = getWatchedFolders(ro); - for(WatchedFolder wf : wfSet) { - if(wf.getPath().equals("/" + path)) { - result = true; - break; - } - } - return result; - } - - @SuppressWarnings("unchecked") - static Set getWatchedFolders(RepositoryObserver ro) throws Exception { - final Field f = ro.getClass().getDeclaredField("folders"); - f.setAccessible(true); - return (Set)f.get(ro); - } - - static RepositoryObserver createRepositoryObserver(SlingRepository repo, OsgiController c) throws Exception { - final RepositoryObserver result = new RepositoryObserver(); - setField(result, "repository", repo); - setField(result, "osgiController", c); - return result; - } - - static void setField(Object target, String name, Object value) throws Exception, IllegalAccessException { + static void XXsetField(Object target, String name, Object value) throws Exception, IllegalAccessException { final Field f = target.getClass().getDeclaredField(name); f.setAccessible(true); f.set(target, value); Added: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MockRepositoryObserver.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MockRepositoryObserver.java?rev=693865&view=auto ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MockRepositoryObserver.java (added) +++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MockRepositoryObserver.java Wed Sep 10 08:02:18 2008 @@ -0,0 +1,54 @@ +/* + * 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.jcrinstall.jcr.impl; + +import java.util.Set; + +import org.apache.sling.jcr.api.SlingRepository; +import org.apache.sling.jcr.jcrinstall.osgi.OsgiController; + +/** Slightly customized RepositoryObserver + * used for testing. + */ +public class MockRepositoryObserver extends RepositoryObserver { + MockRepositoryObserver(SlingRepository repo, final OsgiController c) { + repository = repo; + osgiController = c; + scanDelayMsec = 0; + } + + public void run() { + // Do not run the observation cycle - we do that ourselves in testing + } + + Set getWatchedFolders() { + return folders; + } + + boolean folderIsWatched(String path) throws Exception { + boolean result = false; + for(WatchedFolder wf : folders) { + if(wf.getPath().equals("/" + path)) { + result = true; + break; + } + } + return result; + } +} Propchange: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MockRepositoryObserver.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MockRepositoryObserver.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Modified: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java?rev=693865&r1=693864&r2=693865&view=diff ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java (original) +++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java Wed Sep 10 08:02:18 2008 @@ -108,7 +108,7 @@ inSequence(sequence); }}); - final RepositoryObserver ro = MiscHelper.createRepositoryObserver(repo, c); + final RepositoryObserver ro = new MockRepositoryObserver(repo, c); ro.activate(null); // Add two files, run one cycle must install the bundles @@ -156,7 +156,7 @@ one(c).installOrUpdate(with(equal(resources[2])), with(equal(lastModifiedA)), with(any(InputStream.class))); }}); - final RepositoryObserver ro = MiscHelper.createRepositoryObserver(repo, c); + final RepositoryObserver ro = new MockRepositoryObserver(repo, c); ro.activate(null); // Add two files, run one cycle must install the bundles @@ -197,7 +197,7 @@ one(c).installOrUpdate(with(equal(resources[2])), with(equal(lastModifiedA)), with(any(InputStream.class))); }}); - final RepositoryObserver ro = MiscHelper.createRepositoryObserver(repo, c); + final RepositoryObserver ro = new MockRepositoryObserver(repo, c); ro.activate(null); for(String file : resources) { @@ -220,7 +220,7 @@ installedUri.add("/libs/foo/bar/install/dummy.cfg"); final OsgiController c = mockery.mock(OsgiController.class); - final RepositoryObserver ro = MiscHelper.createRepositoryObserver(repo, c); + final RepositoryObserver ro = new MockRepositoryObserver(repo, c); mockery.checking(new Expectations() {{ allowing(c).getInstalledUris(); will(returnValue(installedUri)); Modified: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java?rev=693865&r1=693864&r2=693865&view=diff ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java (original) +++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java Wed Sep 10 08:02:18 2008 @@ -37,6 +37,7 @@ import org.jmock.Sequence; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; +import org.osgi.service.packageadmin.PackageAdmin; /** Test the BundleResourceProcessor */ public class BundleResourceProcessorTest { @@ -67,7 +68,8 @@ final OsgiControllerImpl c = new OsgiControllerImpl(); final BundleContext bc = mockery.mock(BundleContext.class); - final BundleResourceProcessor p = new BundleResourceProcessor(bc); + final PackageAdmin pa = mockery.mock(PackageAdmin.class); + final BundleResourceProcessor p = new BundleResourceProcessor(bc, pa); Utilities.setProcessors(c, p); final TestStorage s = new TestStorage(Utilities.getTestFile()); Utilities.setStorage(c, s); @@ -80,6 +82,8 @@ // We'll try installing a bundle, re-installing to cause // it to be updated, and removing mockery.checking(new Expectations() {{ + allowing(pa).refreshPackages(null); + allowing(pa).resolveBundles(null); allowing(b).getBundleId() ; will(returnValue(bundleId)); @@ -129,6 +133,7 @@ // Fill the pending bundles queue with one bundle in each of the // possible states, process the queue and verify results + final PackageAdmin pa = mockery.mock(PackageAdmin.class); final BundleContext bc = mockery.mock(BundleContext.class); final Bundle [] b = new Bundle[6]; for(int i = 0; i < b.length; i++) { @@ -136,6 +141,9 @@ }; mockery.checking(new Expectations() {{ + allowing(pa).refreshPackages(null); + allowing(pa).resolveBundles(null); + allowing(bc).getBundle(0L); will(returnValue(b[0])); allowing(bc).getBundle(1L); will(returnValue(b[1])); allowing(bc).getBundle(2L); will(returnValue(b[2])); @@ -167,7 +175,7 @@ one(b[5]).start(); }}); - final BundleResourceProcessor p = new BundleResourceProcessor(bc); + final BundleResourceProcessor p = new BundleResourceProcessor(bc, pa); final Map pendingBundles = new HashMap(); Utilities.setField(p, "pendingBundles", pendingBundles);