</goals>
<configuration>
<wait>false</wait>
- <!-- <pause>30000</pause>-->
<argsToAppend>
<arg>-clean</arg>
</argsToAppend>
org.argeo.slc.server.services,
org.argeo.slc.server.jms,
org.argeo.slc.webapp,
- org.argeo.slc.ria
+ org.argeo.slc.ria
</slc.osgi.start>
</systemProperties>
</configuration>
<version.equinox>3.4.2.R34x_v20080826-1230</version.equinox>
<version.maven-bundle-plugin>2.0.0</version.maven-bundle-plugin>
<version.activemq>5.2.0.0006</version.activemq>
- <version.maven-argeo-osgi>0.1.10</version.maven-argeo-osgi>
+ <version.maven-argeo-osgi>0.1.11-SNAPSHOT</version.maven-argeo-osgi>
</properties>
<scm>
<connection>scm:svn:https://www.argeo.org/svn/slc/trunk/org.argeo.slc</connection>
startBundles(bundlesToStart);
}
- public void startBundles(String bundlesToStart) throws Exception {
- if (bundlesToStart == null)
+ public void startBundles(String bundlesToStartStr) throws Exception {
+ if (bundlesToStartStr == null)
return;
- StringTokenizer st = new StringTokenizer(bundlesToStart, ",");
- Map<String, Bundle> bundles = getBundles();
+ StringTokenizer st = new StringTokenizer(bundlesToStartStr, ",");
+ List bundlesToStart = new ArrayList();
while (st.hasMoreTokens()) {
String name = st.nextToken().trim();
+ bundlesToStart.add(name);
+ }
+ startBundles(bundlesToStart);
+ }
+
+ public void startBundles(List bundlesToStart) throws Exception {
+ if (bundlesToStart.size() == 0)
+ return;
+
+ Map<String, Bundle> bundles = getBundles();
+ for (int i = 0; i < bundlesToStart.size(); i++) {
+ String name = bundlesToStart.get(i).toString();
Bundle bundle = bundles.get(name);
if (bundle != null)
try {
}
}
} else {
- warn("Not a directory: " + newFullPath);
+ //warn("Not a directory: " + newFullPath);
}
}
}
for (int i = 0; i < urls.size(); i++)
System.out.println(urls.get(i));
assertEquals(3, urls.size());
+
+ List jarUrls = osgiBoot.getBundlesUrls(baseUrl,
+ "src/test/bundles/jars;in=*.jar");
+ for (int i = 0; i < jarUrls.size(); i++)
+ System.out.println(jarUrls.get(i));
+ assertEquals(1, jarUrls.size());
}
}
}
protected BundleContext startRuntime() throws Exception {
- String[] args = { "-console" };
+ String[] args = { "-console", "-clean" };
BundleContext bundleContext = EclipseStarter.startup(args, null);
return bundleContext;
}
EclipseStarter.shutdown();
}
- public void setUp() throws Exception{
+ public void setUp() throws Exception {
BundleContext bundleContext = startRuntime();
osgiBoot = new OsgiBoot(bundleContext);
}
-
- public void tearDown() throws Exception{
+
+ public void tearDown() throws Exception {
osgiBoot = null;
stopRuntime();
}
protected class PingThread extends Thread {
public void run() {
+
+ // FIXME: temporary hack so that the ping starts after the server
+ // has been properly started.
+ try {
+ Thread.sleep(5 * 1000);
+ } catch (InterruptedException e1) {
+ // silent
+ }
+
log.info("Start pinging agents.");
while (pingThreadActive) {
List<SlcAgentDescriptor> lst = slcAgentDescriptorDao
<groupId>org.springframework.osgi</groupId>
<artifactId>org.springframework.osgi.core</artifactId>
</dependency>
-
- <dependency>
- <groupId>org.eclipse.osgi</groupId>
- <artifactId>org.eclipse.osgi</artifactId>
- </dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<groupId>org.objectweb.asm</groupId>
<artifactId>com.springsource.org.objectweb.asm.attrs</artifactId>
</dependency>
-
- <!-- TEST -->
- <dependency>
- <groupId>org.springframework.osgi</groupId>
- <artifactId>org.springframework.osgi.test</artifactId>
- <scope>test</scope>
- </dependency>
+
<dependency>
<groupId>org.argeo.slc.runtime</groupId>
<artifactId>org.argeo.slc.osgiboot</artifactId>
- <scope>test</scope>
</dependency>
-
+
</dependencies>
</project>
+++ /dev/null
-package org.argeo.slc.osgi.test;
-
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.osgiboot.OsgiBoot;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.springframework.osgi.test.platform.EquinoxPlatform;
-import org.springframework.osgi.test.platform.OsgiPlatform;
-import org.springframework.osgi.util.OsgiStringUtils;
-
-public abstract class AbstractOsgiRuntimeTest extends TestCase {
- private final static Log log = LogFactory
- .getLog(AbstractOsgiRuntimeTest.class);
-
- protected OsgiBoot osgiBoot = null;
- protected OsgiPlatform osgiPlatform = null;
-
- protected OsgiPlatform createOsgiPlatform() {
- return new EquinoxPlatform() {
-
- public Properties getConfigurationProperties() {
- Properties props = super.getConfigurationProperties();
- props.setProperty("osgi.configuration.area", "target/slc/conf");
- return props;
- }
- };
- }
-
- protected void postStart() throws Exception {
-
- }
-
- public void setUp() throws Exception {
- // To avoid xerces from the classpath being detected as the provider
- System
- .setProperty("javax.xml.parsers.DocumentBuilderFactory",
- "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
- System.setProperty("javax.xml.parsers.SAXParserFactory",
- "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
-
- osgiPlatform = createOsgiPlatform();
- osgiPlatform.start();
- osgiBoot = new OsgiBoot(osgiPlatform.getBundleContext());
- log.info("OSGi platform " + osgiPlatform + " started.");
- postStart();
- }
-
- public void tearDown() throws Exception {
- osgiBoot = null;
- osgiPlatform.stop();
- osgiPlatform = null;
- log.info("OSGi platform " + osgiPlatform + " stopped.");
- }
-
- protected void listInstalledBundles() {
- BundleContext bundleContext = osgiPlatform.getBundleContext();
- Bundle[] bundles = bundleContext.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- System.out
- .println(OsgiStringUtils.nullSafeSymbolicName(bundles[i]));
- }
-
- }
-}
--- /dev/null
+package org.argeo.slc.osgi.test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.osgiboot.OsgiBoot;
+import org.eclipse.core.runtime.adaptor.EclipseStarter;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.springframework.context.ApplicationContext;
+import org.springframework.osgi.util.OsgiStringUtils;
+
+public abstract class AbstractOsgiRuntimeTestCase extends TestCase {
+ private final static Log log = LogFactory
+ .getLog(AbstractOsgiRuntimeTestCase.class);
+
+ protected OsgiBoot osgiBoot = null;
+
+ protected void installBundles() throws Exception {
+
+ }
+
+ public void setUp() throws Exception {
+ // To avoid xerces from the classpath being detected as the provider
+ System
+ .setProperty("javax.xml.parsers.DocumentBuilderFactory",
+ "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
+ System.setProperty("javax.xml.parsers.SAXParserFactory",
+ "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
+
+ BundleContext bundleContext = startRuntime();
+ osgiBoot = new OsgiBoot(bundleContext);
+ log.info("OSGi runtime started.");
+
+ installBundles();
+
+ List<String> bundlesToStart = getBundlesToStart();
+ osgiBoot.startBundles(bundlesToStart);
+ waitAllBundlesOk(bundlesToStart);
+ if (log.isTraceEnabled())
+ listInstalledBundles();
+ }
+
+ public void tearDown() throws Exception {
+ osgiBoot = null;
+ stopRuntime();
+ log.info("OSGi runtime stopped.");
+ }
+
+ protected BundleContext startRuntime() throws Exception {
+ String[] args = { "-console", "-clean" };
+ BundleContext bundleContext = EclipseStarter.startup(args, null);
+ return bundleContext;
+ }
+
+ protected void stopRuntime() throws Exception {
+ EclipseStarter.shutdown();
+ }
+
+ protected List<String> getBundlesToStart() {
+ return new ArrayList<String>();
+ }
+
+ protected void listInstalledBundles() {
+ BundleContext bundleContext = osgiBoot.getBundleContext();
+ Bundle[] bundles = bundleContext.getBundles();
+ for (int i = 0; i < bundles.length; i++) {
+ System.out.println(OsgiStringUtils.nullSafeSymbolicName(bundles[i])
+ + " [" + OsgiStringUtils.bundleStateAsString(bundles[i])
+ + "] " + bundles[i].getLocation());
+ }
+
+ }
+
+ protected Map<Bundle, ApplicationContext> getOsgiApplicationContexts()
+ throws Exception {
+ Map<Bundle, ApplicationContext> map = new HashMap<Bundle, ApplicationContext>();
+ BundleContext bundleContext = osgiBoot.getBundleContext();
+ ServiceReference[] srs = bundleContext.getServiceReferences(
+ ApplicationContext.class.getName(), null);
+ for (ServiceReference sr : srs) {
+ ApplicationContext context = (ApplicationContext) bundleContext
+ .getService(sr);
+ map.put(sr.getBundle(), context);
+ }
+ return map;
+ }
+
+ /** Wait for all bundles to be either RESOLVED or ACTIVE. */
+ protected void waitAllBundlesOk(List<String> bundlesToStart) {
+ BundleContext bundleContext = osgiBoot.getBundleContext();
+ long begin = System.currentTimeMillis();
+ long duration = 0;
+ boolean allBundlesOk = true;
+ while (duration < getResolvedTimeout()) {
+ for (Bundle bundle : bundleContext.getBundles()) {
+ if (bundle.getSymbolicName() != null
+ && bundle.getSymbolicName().startsWith(
+ "org.eclipse.jdt")) {
+ // don't check Eclipse SDK bundles
+ continue;
+ }
+
+ if (bundle.getState() == Bundle.INSTALLED) {
+ allBundlesOk = false;
+ break;// for
+ }
+
+ if (bundlesToStart.contains(bundle.getSymbolicName())
+ && bundle.getState() != Bundle.ACTIVE) {
+ allBundlesOk = false;
+ break;// for
+ }
+ }
+
+ if (allBundlesOk)
+ break;// while
+
+ sleep(1000);
+
+ duration = System.currentTimeMillis() - begin;
+ }
+
+ if (!allBundlesOk) {
+ listInstalledBundles();
+ throw new SlcException("Some bundles are in INSTALLED status");
+ }
+ }
+
+ /**
+ * Make sure that the application context of the started bundles starting
+ * with this prefix are properly initialized
+ */
+ protected void assertStartedBundlesApplicationContext(
+ String bundleSymbolicNamesPrefix) {
+ List<String> bundlesToStart = getBundlesToStart();
+ for (String bundleSName : bundlesToStart) {
+ if (bundleSName.startsWith(bundleSymbolicNamesPrefix))
+ assertBundleApplicationContext(bundleSName);
+ }
+ }
+
+ /**
+ * Make sure that the application context of this bundle is properly
+ * initialized
+ */
+ protected void assertBundleApplicationContext(String bundleSymbolicName) {
+ String filter = "(Bundle-SymbolicName=" + bundleSymbolicName + ")";
+ // Wait for application context to be ready
+ try {
+ ServiceReference[] srs = getServiceRefSynchronous(
+ ApplicationContext.class.getName(), filter);
+ if (srs == null)
+ throw new SlcException("No application context for "
+ + bundleSymbolicName);
+ } catch (InvalidSyntaxException e) {
+ throw new SlcException(
+ "Unexpected exception when looking for applicaiton context for bundle "
+ + bundleSymbolicName, e);
+ }
+ log.info("Application context of bundle " + bundleSymbolicName
+ + " is initalized.");
+ }
+
+ protected ServiceReference[] getServiceRefSynchronous(String clss,
+ String filter) throws InvalidSyntaxException {
+ // FIXME: factorize
+ if (log.isTraceEnabled())
+ log.debug("Filter: '" + filter + "'");
+ ServiceReference[] sfs = null;
+ boolean waiting = true;
+ long begin = System.currentTimeMillis();
+ do {
+ sfs = getBundleContext().getServiceReferences(clss, filter);
+
+ if (sfs != null)
+ waiting = false;
+
+ sleep(100);
+ if (System.currentTimeMillis() - begin > getDefaultTimeout())
+ throw new SlcException("Search of services " + clss
+ + " with filter " + filter + " timed out.");
+ } while (waiting);
+
+ return sfs;
+ }
+
+ protected BundleContext getBundleContext() {
+ return osgiBoot.getBundleContext();
+ }
+
+ /** Default is 120s */
+ protected long getResolvedTimeout() {
+ return 120 * 1000l;
+ }
+
+ /** Default is 10s */
+ protected long getDefaultTimeout() {
+ return 10 * 1000l;
+ }
+
+ final protected void sleep(long duration) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // silent
+ }
+ }
+}
package org.argeo.slc.osgi.test;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
import org.argeo.slc.osgiboot.OsgiBoot;
-public class HelloTest extends AbstractOsgiRuntimeTest {
+public class HelloTest extends AbstractOsgiRuntimeTestCase {
public void testHello() throws Exception {
Thread.sleep(2000);
}
- protected void postStart() throws Exception {
+ protected void installBundles() throws Exception {
osgiBoot.installUrls(osgiBoot.getLocationsUrls(
OsgiBoot.DEFAULT_BASE_URL, System
.getProperty("java.class.path")));
osgiBoot.installUrls(osgiBoot.getBundlesUrls(OsgiBoot.DEFAULT_BASE_URL,
"src/test/bundles;in=*"));
- listInstalledBundles();
- String bundlesToStart = "org.springframework.osgi.extender,org.argeo.slc.support.osgi.test.hello";
- osgiBoot.startBundles(bundlesToStart);
+// Map<String, String> sysProps = new TreeMap(System.getProperties());
+// for (String key : sysProps.keySet()) {
+// System.out.println(key + "=" + sysProps.get(key));
+// }
+ }
+ protected List<String> getBundlesToStart() {
+ List<String> bundlesToStart = new ArrayList<String>();
+ // bundlesToStart.add("org.springframework.osgi.extender");
+ bundlesToStart.add("org.argeo.slc.support.osgi.test.hello");
+ return bundlesToStart;
}
}
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
-public class PlatformStartStopTest extends AbstractOsgiRuntimeTest {
+public class PlatformStartStopTest extends AbstractOsgiRuntimeTestCase {
public void testStartStop() {
- BundleContext bundleContext = osgiPlatform.getBundleContext();
+ BundleContext bundleContext = osgiBoot.getBundleContext();
System.out.println(bundleContext
.getProperty(Constants.FRAMEWORK_VENDOR));
System.out.println(bundleContext