You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2009/09/11 13:33:12 UTC
svn commit: r813780 - in
/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it:
BundleInstallStressTest.java EventsDetector.java
Author: bdelacretaz
Date: Fri Sep 11 11:33:11 2009
New Revision: 813780
URL: http://svn.apache.org/viewvc?rev=813780&view=rev
Log:
SLING-1078 - EventsDetector added
Added:
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/EventsDetector.java (with props)
Modified:
sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallStressTest.java
Modified: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallStressTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallStressTest.java?rev=813780&r1=813779&r2=813780&view=diff
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallStressTest.java (original)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallStressTest.java Fri Sep 11 11:33:11 2009
@@ -36,7 +36,13 @@
import org.osgi.service.log.LogService;
/** Repeatedly install/remove/reinstall semi-random sets
- * of bundles, to stress-test the installer and framework.
+ * of bundles, to stress-test the installer and framework.
+ *
+ * Randomly selects bundles to remove and reinstall in a folder
+ * containing from 4 to N bundles - by supplying a folder with many
+ * bundles, and increasing the number of cycles executed (via
+ * system properties, see pom.xml) the test can be turned into a
+ * long-running stress test.
*/
@RunWith(JUnit4TestRunner.class)
public class BundleInstallStressTest extends OsgiInstallerTestBase {
@@ -61,6 +67,10 @@
/** Timeout for expectBundles() */
private long expectBundlesTimeoutMsec;
+ /** Synchronize (somewhat) with OSGi operations, to be fair */
+ private EventsDetector eventsDetector;
+ public static final long MSEC_WITHOUT_EVENTS = 1000L;
+
@org.ops4j.pax.exam.junit.Configuration
public static Option[] configuration() {
return defaultConfiguration();
@@ -112,11 +122,13 @@
}
random = new Random(42 + cycleCount);
+ eventsDetector = new EventsDetector(bundleContext);
}
@After
public void tearDown() {
super.tearDown();
+ eventsDetector.close();
}
@Test
@@ -125,7 +137,6 @@
fail("Cycle count (" + cycleCount + ") should be >= 1");
}
-
final int initialBundleCount = bundleContext.getBundles().length;
log(LogService.LOG_INFO,"Initial bundle count=" + initialBundleCount);
logInstalledBundles();
@@ -137,6 +148,7 @@
1, expectBundlesTimeoutMsec);
expectBundleCount("After installing all test bundles", initialBundleCount + testBundles.size());
+ // And run a number of cycles where randomly selected bundles are removed and reinstalled
for(int i=0; i < cycleCount; i++) {
final long start = System.currentTimeMillis();
log(LogService.LOG_DEBUG, "Test cycle " + i + ", semi-randomly selecting a subset of our test bundles");
@@ -145,8 +157,7 @@
install(toInstall);
waitForInstallerAction("At cycle " + i, OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER,
1, expectBundlesTimeoutMsec);
- // TODO this sleep shouldn't be needed, probably hides a bug in OsgiInstallerImpl
- sleep(2500L);
+ eventsDetector.waitForNoEvents(MSEC_WITHOUT_EVENTS, expectBundlesTimeoutMsec);
expectBundleCount("At cycle " + i, initialBundleCount + toInstall.size());
log(LogService.LOG_INFO,"Test cycle " + i + " successful, "
+ toInstall.size() + " bundles, "
Added: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/EventsDetector.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/EventsDetector.java?rev=813780&view=auto
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/EventsDetector.java (added)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/EventsDetector.java Fri Sep 11 11:33:11 2009
@@ -0,0 +1,85 @@
+/*
+ * 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.osgi.installer.it;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationEvent;
+import org.osgi.service.cm.ConfigurationListener;
+
+/** Utility that waits for no OSGi events to happen in a given amount
+ * of time.
+ */
+class EventsDetector implements FrameworkListener, BundleListener, ConfigurationListener, ServiceListener {
+
+ private long lastEvent;
+ private final ServiceRegistration configReg;
+ private final BundleContext ctx;
+
+ EventsDetector(BundleContext ctx) {
+ this.ctx = ctx;
+ ctx.addBundleListener(this);
+ ctx.addFrameworkListener(this);
+ ctx.addServiceListener(this);
+ configReg = ctx.registerService(ConfigurationListener.class.getName(), this, null);
+ }
+
+ void close() {
+ configReg.unregister();
+ ctx.removeServiceListener(this);
+ ctx.removeFrameworkListener(this);
+ ctx.removeBundleListener(this);
+ }
+
+ void waitForNoEvents(long timeWithoutEventsMsec, long timeoutMsec) throws InterruptedException {
+ final long endTime = System.currentTimeMillis() + timeoutMsec;
+ final long exitTime = lastEvent + timeWithoutEventsMsec;
+ while(System.currentTimeMillis() < endTime) {
+ if(System.currentTimeMillis() >= exitTime) {
+ return;
+ }
+ Thread.sleep(100L);
+ }
+ throw new IllegalStateException("Did not get " + timeWithoutEventsMsec + " msec without events after waiting " + timeoutMsec);
+ }
+
+ private void recordLastEvent() {
+ lastEvent = System.currentTimeMillis();
+ }
+
+ public void frameworkEvent(FrameworkEvent arg0) {
+ recordLastEvent();
+ }
+
+ public void bundleChanged(BundleEvent arg0) {
+ recordLastEvent();
+ }
+
+ public void configurationEvent(ConfigurationEvent arg0) {
+ recordLastEvent();
+ }
+
+ public void serviceChanged(ServiceEvent arg0) {
+ recordLastEvent();
+ }
+}
Propchange: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/EventsDetector.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/EventsDetector.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL