You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2015/01/05 15:33:44 UTC

svn commit: r1649533 - in /sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it: ConfigInstallTest.java OsgiInstallerTestBase.java UpdateHandlerTest.java

Author: cziegeler
Date: Mon Jan  5 14:33:44 2015
New Revision: 1649533

URL: http://svn.apache.org/r1649533
Log:
Replace sleeps with waiting for condition, remove superfluous checks

Modified:
    sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/ConfigInstallTest.java
    sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/OsgiInstallerTestBase.java
    sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/UpdateHandlerTest.java

Modified: sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/ConfigInstallTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/ConfigInstallTest.java?rev=1649533&r1=1649532&r2=1649533&view=diff
==============================================================================
--- sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/ConfigInstallTest.java (original)
+++ sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/ConfigInstallTest.java Mon Jan  5 14:33:44 2015
@@ -30,6 +30,7 @@ import java.util.concurrent.atomic.Atomi
 import org.apache.sling.installer.api.InstallableResource;
 import org.apache.sling.installer.api.event.InstallationEvent;
 import org.apache.sling.installer.api.event.InstallationListener;
+import org.apache.sling.installer.api.tasks.ResourceState;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -147,7 +148,6 @@ public class ConfigInstallTest extends O
         // remove again
         installer.updateResources(URL_SCHEME, null, new String[] {rsrc[0].getId()});
         waitForConfiguration("After removing for the second time", cfgPid, TIMEOUT, false);
-
     }
 
     @Test
@@ -155,7 +155,6 @@ public class ConfigInstallTest extends O
         final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();
         cfgData.put("foo", "bar");
         final String cfgPid = getClass().getSimpleName() + "." + uniqueID();
-        assertNull("Config " + cfgPid + " must not be found before test", findConfiguration(cfgPid));
 
         // install config
         final InstallableResource rsrc = new InstallableResource("/configA/" + cfgPid,
@@ -163,8 +162,7 @@ public class ConfigInstallTest extends O
         installer.updateResources(URL_SCHEME, new InstallableResource[] {rsrc}, null);
 
         // get config
-        final Configuration cfg = waitForConfiguration("After installing", cfgPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bar", cfg.getProperties().get("foo"));
+        waitForConfigValue("After installing", cfgPid, TIMEOUT, "foo", "bar");
 
         // create second configuration
         final Dictionary<String, Object> secondData = new Hashtable<String, Object>();
@@ -173,19 +171,13 @@ public class ConfigInstallTest extends O
                 null, secondData, null, InstallableResource.TYPE_PROPERTIES, 20);
         installer.updateResources(URL_SCHEME, new InstallableResource[] {rsrc2}, null);
 
-        sleep(200); // TODO replace with wait condition
-
         // get updated config
-        final Configuration secondCfg = waitForConfiguration("After updating", cfgPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bla", secondCfg.getProperties().get("foo"));
+        waitForConfigValue("After updating", cfgPid, TIMEOUT, "foo", "bla");
 
         // remove config
         installer.updateResources(URL_SCHEME, null, new String[] {"/configB/" + cfgPid});
 
-        sleep(200); // TODO replace with wait condition
-
-        final Configuration origCfg = waitForConfiguration("After deleting", cfgPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bar", origCfg.getProperties().get("foo"));
+        waitForConfigValue("After deleting", cfgPid, TIMEOUT, "foo", "bar");
     }
 
     @Test
@@ -194,7 +186,6 @@ public class ConfigInstallTest extends O
         cfgData.put("foo", "bar");
         cfgData.put(InstallableResource.RESOURCE_IS_TEMPLATE, "true");
         final String cfgPid = getClass().getSimpleName() + "." + uniqueID();
-        assertNull("Config " + cfgPid + " must not be found before test", findConfiguration(cfgPid));
 
         // install config
         final InstallableResource rsrc = new InstallableResource("/configA/" + cfgPid,
@@ -202,8 +193,7 @@ public class ConfigInstallTest extends O
         installer.updateResources(URL_SCHEME, new InstallableResource[] {rsrc}, null);
 
         // get config
-        final Configuration cfg = waitForConfiguration("After installing", cfgPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bar", cfg.getProperties().get("foo"));
+        waitForConfigValue("After installing", cfgPid, TIMEOUT, "foo", "bar");
 
         // create second configuration
         final Dictionary<String, Object> secondData = new Hashtable<String, Object>();
@@ -212,19 +202,13 @@ public class ConfigInstallTest extends O
                 null, secondData, null, InstallableResource.TYPE_PROPERTIES, 20);
         installer.updateResources(URL_SCHEME, new InstallableResource[] {rsrc2}, null);
 
-        sleep(200); // TODO replace with wait condition
-
         // get updated config
-        final Configuration secondCfg = waitForConfiguration("After updating", cfgPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bla", secondCfg.getProperties().get("foo"));
+        waitForConfigValue("After updating", cfgPid, TIMEOUT, "foo", "bla");
 
         // remove config
         installer.updateResources(URL_SCHEME, null, new String[] {"/configB/" + cfgPid});
 
-        sleep(200); // TODO replace with wait condition
-
-        final Configuration noCfg = waitForConfiguration("After deleting", cfgPid, TIMEOUT, false);
-        assertNull("Configuration should be removed", noCfg);
+        waitForConfiguration("After deleting", cfgPid, TIMEOUT, false);
     }
 
     @Test
@@ -233,7 +217,6 @@ public class ConfigInstallTest extends O
         cfgData.put("foo", "bar");
         final String cfgFactoryPid = getClass().getSimpleName() + "." + uniqueID();
         final String alias = "alias" + uniqueID();
-        assertNull("Factory config " + cfgFactoryPid + " must not be found before test", findFactoryConfiguration(cfgFactoryPid));
 
         // install factory config
         final InstallableResource rsrc = new InstallableResource("/configA/" + cfgFactoryPid + "-" + alias,
@@ -241,8 +224,7 @@ public class ConfigInstallTest extends O
         installer.updateResources(URL_SCHEME, new InstallableResource[] {rsrc}, null);
 
         // get factory config
-        final Configuration cfg = waitForFactoryConfiguration("After installing", cfgFactoryPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bar", cfg.getProperties().get("foo"));
+        waitForFactoryConfigValue("After installing", cfgFactoryPid, TIMEOUT, "foo", "bar");
 
         // create second factory configuration with same alias
         final Dictionary<String, Object> secondData = new Hashtable<String, Object>();
@@ -251,19 +233,13 @@ public class ConfigInstallTest extends O
                 null, secondData, null, InstallableResource.TYPE_PROPERTIES, 20);
         installer.updateResources(URL_SCHEME, new InstallableResource[] {rsrc2}, null);
 
-        sleep(200); // TODO replace with wait condition
-
         // get updated factory config
-        final Configuration secondCfg = waitForFactoryConfiguration("After updating", cfgFactoryPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bla", secondCfg.getProperties().get("foo"));
+        waitForFactoryConfigValue("After updating", cfgFactoryPid, TIMEOUT, "foo", "bla");
 
         // remove factory config
         installer.updateResources(URL_SCHEME, null, new String[] {"/configB/" + cfgFactoryPid + "-" + alias});
 
-        sleep(200); // TODO replace with wait condition
-
-        final Configuration origCfg = waitForFactoryConfiguration("After deleting", cfgFactoryPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bar", origCfg.getProperties().get("foo"));
+        waitForFactoryConfigValue("After updating", cfgFactoryPid, TIMEOUT, "foo", "bar");
     }
 
     @Test
@@ -273,7 +249,6 @@ public class ConfigInstallTest extends O
         cfgData.put(InstallableResource.RESOURCE_IS_TEMPLATE, "true");
         final String cfgFactoryPid = getClass().getSimpleName() + "." + uniqueID();
         final String alias = "alias" + uniqueID();
-        assertNull("Factory config " + cfgFactoryPid + " must not be found before test", findFactoryConfiguration(cfgFactoryPid));
 
         // install factory config
         final InstallableResource rsrc = new InstallableResource("/configA/" + cfgFactoryPid + "-" + alias,
@@ -281,8 +256,7 @@ public class ConfigInstallTest extends O
         installer.updateResources(URL_SCHEME, new InstallableResource[] {rsrc}, null);
 
         // get factory config
-        final Configuration cfg = waitForFactoryConfiguration("After installing", cfgFactoryPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bar", cfg.getProperties().get("foo"));
+        waitForFactoryConfigValue("After installing", cfgFactoryPid, TIMEOUT, "foo", "bar");
 
         // create second factory configuration
         final Dictionary<String, Object> secondData = new Hashtable<String, Object>();
@@ -291,19 +265,13 @@ public class ConfigInstallTest extends O
                 null, secondData, null, InstallableResource.TYPE_PROPERTIES, 20);
         installer.updateResources(URL_SCHEME, new InstallableResource[] {rsrc2}, null);
 
-        sleep(200); // TODO replace with wait condition
-
         // get updated factory config
-        final Configuration secondCfg = waitForFactoryConfiguration("After updating", cfgFactoryPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bla", secondCfg.getProperties().get("foo"));
+        waitForFactoryConfigValue("After updating", cfgFactoryPid, TIMEOUT, "foo", "bla");
 
         // remove config
         installer.updateResources(URL_SCHEME, null, new String[] {"/configB/" + cfgFactoryPid + "-" + alias});
 
-        sleep(200); // TODO replace with wait condition
-
-        final Configuration noCfg = waitForFactoryConfiguration("After deleting", cfgFactoryPid, TIMEOUT, false);
-        assertNull("Factory configuration should be removed", noCfg);
+        waitForFactoryConfiguration("After deleting", cfgFactoryPid, TIMEOUT, false);
     }
 
     @Test
@@ -311,7 +279,6 @@ public class ConfigInstallTest extends O
         final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();
         cfgData.put("foo", "bar");
         final String cfgPid = getClass().getSimpleName() + "." + uniqueID();
-        assertNull("Config " + cfgPid + " must not be found before test", findConfiguration(cfgPid));
 
         // install config
         final InstallableResource rsrc = new InstallableResource("/configA/" + cfgPid,
@@ -319,27 +286,24 @@ public class ConfigInstallTest extends O
         installer.updateResources(URL_SCHEME, new InstallableResource[] {rsrc}, null);
 
         // get config
-        final Configuration cfg = waitForConfiguration("After installing", cfgPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bar", cfg.getProperties().get("foo"));
+        final Configuration cfg = waitForConfigValue("After installing", cfgPid, TIMEOUT, "foo", "bar");
 
         // update configuration
         final Dictionary<String, Object> secondData = new Hashtable<String, Object>();
         secondData.put("foo", "bla");
         cfg.update(secondData);
 
-        sleep(200); // TODO replace with wait condition
+        waitForResource(URL_SCHEME + ":/configA/" + cfgPid, ResourceState.IGNORED, TIMEOUT);
 
         // get updated config
-        final Configuration secondCfg = waitForConfiguration("After updating", cfgPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bla", secondCfg.getProperties().get("foo"));
+        final Configuration secondCfg = waitForConfigValue("After updating", cfgPid, TIMEOUT, "foo", "bla");
 
         // remove config
         secondCfg.delete();
 
-        sleep(200); // TODO replace with wait condition
+        waitForResource(URL_SCHEME + ":/configA/" + cfgPid, ResourceState.INSTALLED, TIMEOUT);
 
-        final Configuration origCfg = waitForConfiguration("After deleting", cfgPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bar", origCfg.getProperties().get("foo"));
+        waitForConfigValue("After deleting", cfgPid, TIMEOUT, "foo", "bar");
     }
 
     @Test
@@ -348,7 +312,6 @@ public class ConfigInstallTest extends O
         cfgData.put("foo", "bar");
         cfgData.put(InstallableResource.RESOURCE_IS_TEMPLATE, "true");
         final String cfgPid = getClass().getSimpleName() + "." + uniqueID();
-        assertNull("Config " + cfgPid + " must not be found before test", findConfiguration(cfgPid));
 
         // install config
         final InstallableResource rsrc = new InstallableResource("/configA/" + cfgPid,
@@ -356,27 +319,25 @@ public class ConfigInstallTest extends O
         installer.updateResources(URL_SCHEME, new InstallableResource[] {rsrc}, null);
 
         // get config
-        final Configuration cfg = waitForConfiguration("After installing", cfgPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bar", cfg.getProperties().get("foo"));
+        final Configuration cfg = waitForConfigValue("After installing", cfgPid, TIMEOUT, "foo", "bar");
 
         // update configuration
         final Dictionary<String, Object> secondData = new Hashtable<String, Object>();
         secondData.put("foo", "bla");
         cfg.update(secondData);
 
-        sleep(200); // TODO replace with wait condition
+        waitForResource(URL_SCHEME + ":/configA/" + cfgPid, ResourceState.IGNORED, TIMEOUT);
 
         // get updated config
-        final Configuration secondCfg = waitForConfiguration("After updating", cfgPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bla", secondCfg.getProperties().get("foo"));
+        final Configuration secondCfg = waitForConfigValue("After updating", cfgPid, TIMEOUT, "foo", "bla");
 
         // remove config
         secondCfg.delete();
 
-        sleep(200); // TODO replace with wait condition
+        sleep(200); // we have to wait here as no state change is happening
+        waitForResource(URL_SCHEME + ":/configA/" + cfgPid, ResourceState.IGNORED, TIMEOUT);
 
-        final Configuration noCfg = waitForConfiguration("After deleting", cfgPid, TIMEOUT, false);
-        assertNull("Configuration should be removed", noCfg);
+        waitForConfiguration("After deleting", cfgPid, TIMEOUT, false);
     }
 
     @Test
@@ -385,7 +346,6 @@ public class ConfigInstallTest extends O
         cfgData.put("foo", "bar");
         final String cfgFactoryPid = getClass().getSimpleName() + "." + uniqueID();
         final String alias = "alias" + uniqueID();
-        assertNull("Factory config " + cfgFactoryPid + " must not be found before test", findFactoryConfiguration(cfgFactoryPid));
 
         // install factory config
         final InstallableResource rsrc = new InstallableResource("/configA/" + cfgFactoryPid + "-" + alias,
@@ -393,26 +353,23 @@ public class ConfigInstallTest extends O
         installer.updateResources(URL_SCHEME, new InstallableResource[] {rsrc}, null);
 
         // get factory config
-        final Configuration cfg = waitForFactoryConfiguration("After installing", cfgFactoryPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bar", cfg.getProperties().get("foo"));
+        final Configuration cfg = waitForFactoryConfigValue("After installing", cfgFactoryPid, TIMEOUT, "foo", "bar");
 
         // update configuration
         final Dictionary<String, Object> secondData = new Hashtable<String, Object>();
         secondData.put("foo", "bla");
         cfg.update(secondData);
 
-        sleep(200); // TODO replace with wait condition
+        waitForResource(URL_SCHEME + ":/configA/" + cfgFactoryPid + "-" + alias, ResourceState.IGNORED, TIMEOUT);
 
         // get updated factory config
-        final Configuration secondCfg = waitForFactoryConfiguration("After updating", cfgFactoryPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bla", secondCfg.getProperties().get("foo"));
+        final Configuration secondCfg = waitForFactoryConfigValue("After updating", cfgFactoryPid, TIMEOUT, "foo", "bla");
 
         // remove factory config
         secondCfg.delete();
-        sleep(200); // TODO replace with wait condition
+        waitForResource(URL_SCHEME + ":/configA/" + cfgFactoryPid + "-" + alias, ResourceState.INSTALLED, TIMEOUT);
 
-        final Configuration origCfg = waitForFactoryConfiguration("After deleting", cfgFactoryPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bar", origCfg.getProperties().get("foo"));
+        waitForFactoryConfigValue("After deleting", cfgFactoryPid, TIMEOUT, "foo", "bar");
     }
 
     @Test
@@ -422,7 +379,6 @@ public class ConfigInstallTest extends O
         cfgData.put(InstallableResource.RESOURCE_IS_TEMPLATE, "true");
         final String cfgFactoryPid = getClass().getSimpleName() + "." + uniqueID();
         final String alias = "alias" + uniqueID();
-        assertNull("Factory config " + cfgFactoryPid + " must not be found before test", findFactoryConfiguration(cfgFactoryPid));
 
         // install factory config
         final InstallableResource rsrc = new InstallableResource("/configA/" + cfgFactoryPid + "-" + alias,
@@ -430,26 +386,24 @@ public class ConfigInstallTest extends O
         installer.updateResources(URL_SCHEME, new InstallableResource[] {rsrc}, null);
 
         // get factory config
-        final Configuration cfg = waitForFactoryConfiguration("After installing", cfgFactoryPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bar", cfg.getProperties().get("foo"));
+        final Configuration cfg = waitForFactoryConfigValue("After installing", cfgFactoryPid, TIMEOUT, "foo", "bar");
 
         // update configuration
         final Dictionary<String, Object> secondData = new Hashtable<String, Object>();
         secondData.put("foo", "bla");
         cfg.update(secondData);
 
-        sleep(200); // TODO replace with wait condition
+        waitForResource(URL_SCHEME + ":/configA/" + cfgFactoryPid + "-" + alias, ResourceState.IGNORED, TIMEOUT);
 
         // get updated factory config
-        final Configuration secondCfg = waitForFactoryConfiguration("After updating", cfgFactoryPid, TIMEOUT, true);
-        assertEquals("Config value must match", "bla", secondCfg.getProperties().get("foo"));
+        final Configuration secondCfg = waitForFactoryConfigValue("After updating", cfgFactoryPid, TIMEOUT, "foo", "bla");
 
         // remove config
         secondCfg.delete();
-        sleep(200); // TODO replace with wait condition
+        sleep(200); // we have to wait here as no state change is happening
 
-        final Configuration noCfg = waitForFactoryConfiguration("After deleting", cfgFactoryPid, TIMEOUT, false);
-        assertNull("Factory configuration should be removed", noCfg);
+        waitForResource(URL_SCHEME + ":/configA/" + cfgFactoryPid + "-" + alias, ResourceState.IGNORED, TIMEOUT);
+        waitForFactoryConfiguration("After deleting", cfgFactoryPid, TIMEOUT, false);
     }
 
     @Test

Modified: sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/OsgiInstallerTestBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/OsgiInstallerTestBase.java?rev=1649533&r1=1649532&r2=1649533&view=diff
==============================================================================
--- sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/OsgiInstallerTestBase.java (original)
+++ sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/OsgiInstallerTestBase.java Mon Jan  5 14:33:44 2015
@@ -40,6 +40,12 @@ import javax.inject.Inject;
 
 import org.apache.sling.installer.api.InstallableResource;
 import org.apache.sling.installer.api.OsgiInstaller;
+import org.apache.sling.installer.api.ResourceChangeListener;
+import org.apache.sling.installer.api.info.InfoProvider;
+import org.apache.sling.installer.api.info.InstallationState;
+import org.apache.sling.installer.api.info.Resource;
+import org.apache.sling.installer.api.info.ResourceGroup;
+import org.apache.sling.installer.api.tasks.ResourceState;
 import org.junit.Before;
 import org.ops4j.pax.exam.Option;
 import org.osgi.framework.Bundle;
@@ -66,10 +72,14 @@ public class OsgiInstallerTestBase imple
     private final static String CONFIG_VERSION = System.getProperty("installer.configuration.version", "INSTALLER_VERSION_NOT_SET");
 
 	public final static String JAR_EXT = ".jar";
-	private int packageRefreshEventsCount;
-	private ServiceTracker configAdminTracker;
+	private volatile int packageRefreshEventsCount;
+	private volatile ServiceTracker configAdminTracker;
 
-	protected OsgiInstaller installer;
+	protected volatile OsgiInstaller installer;
+
+    protected volatile ResourceChangeListener resourceChangeListener;
+
+    protected volatile InfoProvider infoProvider;
 
     public static final long WAIT_FOR_ACTION_TIMEOUT_MSEC = 6000;
     public static final String BUNDLE_BASE_NAME = "org.apache.sling.installer.it-" + POM_VERSION;
@@ -101,6 +111,8 @@ public class OsgiInstallerTestBase imple
     /** Set up the installer service. */
     protected void setupInstaller() {
         installer = getService(OsgiInstaller.class);
+        resourceChangeListener = getService(ResourceChangeListener.class);
+        infoProvider = getService(InfoProvider.class);
     }
 
     @Before
@@ -249,52 +261,74 @@ public class OsgiInstallerTestBase imple
         fail("WaitForCondition failed: " + info);
     }
 
-    protected void waitForConfigValue(String info, String pid, long timeoutMsec, String key, String value) throws Exception {
+    protected Configuration waitForFactoryConfigValue(final String info,
+            final String factoryPid,
+            final long timeoutMsec,
+            final String key,
+            final String value)
+    throws Exception {
+        final long end = System.currentTimeMillis() + timeoutMsec;
+        do {
+            final Configuration c = waitForFactoryConfiguration(info, factoryPid, timeoutMsec, true);
+            if (value.equals(c.getProperties().get(key))) {
+                return c;
+            }
+            sleep(100L);
+        } while(System.currentTimeMillis() < end);
+        fail("Did not get " + key + "=" + value + " for factory config " + factoryPid);
+        return null;
+    }
+
+    protected Configuration waitForConfigValue(final String info,
+            final String pid,
+            final long timeoutMsec,
+            final String key,
+            final String value)
+    throws Exception {
         final long end = System.currentTimeMillis() + timeoutMsec;
         do {
         	final Configuration c = waitForConfiguration(info, pid, timeoutMsec, true);
-        	if(value.equals(c.getProperties().get(key))) {
-        		return;
+        	if (value.equals(c.getProperties().get(key))) {
+        		return c;
         	}
         	sleep(100L);
         } while(System.currentTimeMillis() < end);
         fail("Did not get " + key + "=" + value + " for config " + pid);
+        return null;
     }
 
-    protected Configuration waitForConfiguration(String info, String pid, long timeoutMsec, boolean shouldBePresent) throws Exception {
-        if (info == null) {
-            info = "";
-        } else {
-            info += ": ";
-        }
-
-        Configuration result = null;
-        final long start = System.currentTimeMillis();
-        final long end = start + timeoutMsec;
-        log(LogService.LOG_DEBUG, "Starting config check at " + start + "; ending by " + end);
-        do {
-            result = findConfiguration(pid);
-            if ((shouldBePresent && result != null) ||
-                    (!shouldBePresent && result == null)) {
-                break;
-            }
-            log(LogService.LOG_DEBUG, "Config check failed at " + System.currentTimeMillis() + "; sleeping");
-            sleep(25);
-        } while(System.currentTimeMillis() < end);
-
-        if (shouldBePresent && result == null) {
-            fail(info + "Configuration not found (" + pid + ")");
-        } else if (!shouldBePresent && result != null) {
-            fail(info + "Configuration is still present (" + pid + ")");
-        }
-        return result;
+    /**
+     * Wait for a configuration.
+     */
+    protected Configuration waitForConfiguration(final String info,
+            final String pid,
+            final long timeoutMsec,
+            final boolean shouldBePresent)
+    throws Exception {
+        return this.waitForConfiguration(info, pid,  null, timeoutMsec, shouldBePresent);
     }
 
+    /**
+     * Wait for a factory configuration.
+     */
     protected Configuration waitForFactoryConfiguration(final String info,
             final String factoryPid,
             final long timeoutMsec,
             final boolean shouldBePresent)
     throws Exception {
+        return this.waitForConfiguration(info, null,  factoryPid, timeoutMsec, shouldBePresent);
+    }
+
+    /**
+     * Internal method to wait for a configuration
+     */
+    private Configuration waitForConfiguration(final String info,
+            final String pid,
+            final String factoryPid,
+            final long timeoutMsec,
+            final boolean shouldBePresent)
+    throws Exception {
+        final String logKey = factoryPid == null ? "config" : "factory config";
         String msg;
         if (info == null) {
             msg = "";
@@ -305,21 +339,25 @@ public class OsgiInstallerTestBase imple
         Configuration result = null;
         final long start = System.currentTimeMillis();
         final long end = start + timeoutMsec;
-        log(LogService.LOG_DEBUG, "Starting factory config check at " + start + "; ending by " + end);
+        log(LogService.LOG_DEBUG, "Starting " + logKey + " check at " + start + "; ending by " + end);
         do {
-            result = findFactoryConfiguration(factoryPid);
+            if ( factoryPid != null ) {
+                result = findFactoryConfiguration(factoryPid);
+            } else {
+                result = findConfiguration(pid);
+            }
             if ((shouldBePresent && result != null) ||
                     (!shouldBePresent && result == null)) {
                 break;
             }
-            log(LogService.LOG_DEBUG, "Config check failed at " + System.currentTimeMillis() + "; sleeping");
+            log(LogService.LOG_DEBUG, logKey + " check failed at " + System.currentTimeMillis() + "; sleeping");
             sleep(25);
         } while(System.currentTimeMillis() < end);
 
         if (shouldBePresent && result == null) {
-            fail(msg + "Factory Configuration not found (" + factoryPid + ")");
+            fail(msg + logKey + " not found (" + (factoryPid != null ? factoryPid : pid) + ")");
         } else if (!shouldBePresent && result != null) {
-            fail(msg + "Factory Configuration is still present (" + factoryPid + ")");
+            fail(msg + logKey + " is still present (" + (factoryPid != null ? factoryPid : pid) + ")");
         }
         return result;
     }
@@ -553,6 +591,28 @@ public class OsgiInstallerTestBase imple
         }
     }
 
+    protected Resource waitForResource(final String url,
+            final ResourceState state,
+            final long timeout) {
+        final long start = System.currentTimeMillis();
+        final long end = start + timeout;
+
+        do {
+            final InstallationState is = this.infoProvider.getInstallationState();
+            for(final ResourceGroup rg : is.getInstalledResources()) {
+                for(final Resource rsrc : rg.getResources()) {
+                    if ( url.equals(rsrc.getURL()) ) {
+                        if ( rsrc.getState() == state ) {
+                            return rsrc;
+                        }
+                    }
+                }
+            }
+            sleep(50);
+        } while ( System.currentTimeMillis() < end);
+        fail("Resource " + url + " not found with state " + state);
+        return null;
+    }
     private final class BundleEventListener implements SynchronousBundleListener {
 
         private final List<BundleEvent> events = new ArrayList<BundleEvent>();

Modified: sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/UpdateHandlerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/UpdateHandlerTest.java?rev=1649533&r1=1649532&r2=1649533&view=diff
==============================================================================
--- sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/UpdateHandlerTest.java (original)
+++ sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/UpdateHandlerTest.java Mon Jan  5 14:33:44 2015
@@ -32,7 +32,6 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
 import org.apache.sling.installer.api.InstallableResource;
-import org.apache.sling.installer.api.ResourceChangeListener;
 import org.apache.sling.installer.api.UpdateHandler;
 import org.apache.sling.installer.api.UpdateResult;
 import org.apache.sling.installer.api.event.InstallationEvent;
@@ -206,17 +205,15 @@ public class UpdateHandlerTest extends O
 
         assertNotNull("Resource should be installed: " + installed, installed.get(TYPE) + ":a");
 
-        final ResourceChangeListener rcl = (ResourceChangeListener)this.installer;
-
         final Dictionary<String, Object> newData = new Hashtable<String, Object>();
         data.put("bar", "foo");
-        rcl.resourceAddedOrUpdated(TYPE, "a", null, newData, null);
+        this.resourceChangeListener.resourceAddedOrUpdated(TYPE, "a", null, newData, null);
 
         final UpdateResult ur = up.waitForUpdate();
         assertNotNull(ur);
         assertEquals(TYPE + ":/resource/b/a." + TYPE, ur.getURL());
 
-        rcl.resourceRemoved(TYPE, "a");
+        this.resourceChangeListener.resourceRemoved(TYPE, "a");
         final UpdateResult r2 = up.waitForUpdate();
         assertNotNull(r2);
         assertEquals(TYPE + ":/resource/b/a." + TYPE, r2.getURL());