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/09 16:46:05 UTC
svn commit: r1650572 -
/sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/ConfigInstallTest.java
Author: cziegeler
Date: Fri Jan 9 15:46:05 2015
New Revision: 1650572
URL: http://svn.apache.org/r1650572
Log:
SLING-1794 : ConfigInstallTest fails semi-randomly: Configuration is still present
Modified:
sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/ConfigInstallTest.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=1650572&r1=1650571&r2=1650572&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 Fri Jan 9 15:46:05 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.InstallTaskFactory;
import org.apache.sling.installer.api.tasks.ResourceState;
import org.junit.After;
import org.junit.Before;
@@ -38,11 +39,14 @@ import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.cm.ConfigurationEvent;
import org.osgi.service.cm.ConfigurationListener;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
@RunWith(PaxExam.class)
@@ -441,11 +445,45 @@ public class ConfigInstallTest extends O
@Test
public void testDeferredConfigRemove() throws Exception {
+ final AtomicInteger factoryCount = new AtomicInteger();
+
+ final ServiceTracker st = new ServiceTracker(bundleContext, InstallTaskFactory.class.getName(), new ServiceTrackerCustomizer() {
+
+ public void removedService(ServiceReference reference, Object service) {
+ bundleContext.ungetService(reference);
+ factoryCount.decrementAndGet();
+ }
+
+ public void modifiedService(ServiceReference reference, Object service) {
+ }
+
+ public Object addingService(ServiceReference reference) {
+ factoryCount.incrementAndGet();
+ return bundleContext.getService(reference);
+ }
+ });
+ st.open();
+
// get config admin bundle and wait for service
final Bundle configAdmin = this.getConfigAdminBundle();
assertNotNull("ConfigAdmin bundle must be found", configAdmin);
waitForConfigAdmin(true);
+ // when everything is up and running, we have two factories
+ waitForCondition("Task Factories should be 2", new Condition() {
+
+ @Override
+ boolean isTrue() throws Exception {
+ return factoryCount.get() == 2;
+ }
+
+ @Override
+ String additionalInfo() {
+ return "Task Factories is " + String.valueOf(factoryCount.get());
+ }
+
+ });
+
// check that configuration is not available
final String cfgPid = getClass().getSimpleName() + ".deferred." + uniqueID();
assertNull("Config " + cfgPid + " must not be found before test", findConfiguration(cfgPid));
@@ -462,6 +500,21 @@ public class ConfigInstallTest extends O
configAdmin.stop();
waitForConfigAdmin(false);
+ // only bundle task factory
+ waitForCondition("Task Factories should be 1", new Condition() {
+
+ @Override
+ boolean isTrue() throws Exception {
+ return factoryCount.get() == 1;
+ }
+
+ @Override
+ String additionalInfo() {
+ return "Task Factories is " + String.valueOf(factoryCount.get());
+ }
+
+ });
+
// remove configuration
installationEvents = 0;
installer.updateResources(URL_SCHEME, null, new String[] {rsrc[0].getId()});
@@ -469,8 +522,26 @@ public class ConfigInstallTest extends O
configAdmin.start();
waitForConfigAdmin(true);
+
+ // when everything is up and running, we have two factories
+ waitForCondition("Task Factories should be 2", new Condition() {
+
+ @Override
+ boolean isTrue() throws Exception {
+ return factoryCount.get() == 2;
+ }
+
+ @Override
+ String additionalInfo() {
+ return "Task Factories is " + String.valueOf(factoryCount.get());
+ }
+
+ });
+
waitForConfiguration("Config must be removed once ConfigurationAdmin restarts",
cfgPid, false);
+
+ st.close();
}
@Test