enhancing KarafTest - just misses eventbus now
diff --git a/geronimo-opentracing-common/pom.xml b/geronimo-opentracing-common/pom.xml
index 9fe0c60..d606f5d 100644
--- a/geronimo-opentracing-common/pom.xml
+++ b/geronimo-opentracing-common/pom.xml
@@ -35,4 +35,32 @@
<properties>
<geronimo-opentracing.Automatic-Module-Name>org.apache.geronimo.opentracing.common</geronimo-opentracing.Automatic-Module-Name>
</properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Export-Package>org.apache.geronimo.microprofile.opentracing.common.*</Export-Package>
+ <Import-Package>
+ io.opentracing,io.opentracing.propagation,
+ io.opentracing.tag,
+ javax.annotation;version="[1.0,3)",
+ javax.json.bind;version="[1.0,3)";resolution:=optional,
+ javax.servlet,
+ javax.servlet.http,
+ javax.ws.rs;version="[2,3)",
+ javax.ws.rs.client;version="[2,3)",
+ javax.ws.rs.container;version="[2,3)",
+ javax.ws.rs.core;version="[2,3)",
+ javax.ws.rs.ext;version="[2,3)",
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/geronimo-opentracing-osgi/pom.xml b/geronimo-opentracing-osgi/pom.xml
index d5b1fa7..b6e32be 100644
--- a/geronimo-opentracing-osgi/pom.xml
+++ b/geronimo-opentracing-osgi/pom.xml
@@ -36,6 +36,8 @@
<pax.exam.version>4.12.0</pax.exam.version>
<slf4j.version>1.7.25</slf4j.version>
+ <karaf.version>4.2.1</karaf.version>
+ <johnzon.version>1.1.10</johnzon.version>
</properties>
<dependencies>
@@ -87,5 +89,107 @@
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.karaf</groupId>
+ <artifactId>apache-karaf</artifactId>
+ <version>${karaf.version}</version>
+ <scope>test</scope>
+ <type>tar.gz</type>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.karaf</groupId>
+ <artifactId>org.apache.karaf.client</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.ops4j.pax.logging</groupId>
+ <artifactId>pax-logging-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tomee</groupId>
+ <artifactId>ziplock</artifactId>
+ <version>7.1.0</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
</dependencies>
+
+ <build>
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>*.xml</include>
+ </includes>
+ </testResource>
+ <testResource>
+ <directory>src/test/resources</directory>
+ <excludes>
+ <exclude>*.xml</exclude>
+ </excludes>
+ </testResource>
+ </testResources>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.22.1</version>
+ <executions>
+ <execution>
+ <id>default-test</id>
+ <phase>test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <excludes>
+ <exclude>**/Karaf*</exclude>
+ </excludes>
+ </configuration>
+ </execution>
+ <execution>
+ <id>karaf</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <includes>
+ <include>**/Karaf*</include>
+ </includes>
+ <systemPropertyVariables>
+ <karaf.version>${karaf.version}</karaf.version>
+ <project.version>${project.version}</project.version>
+ </systemPropertyVariables>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Bundle-Activator>org.apache.geronimo.microprofile.opentracing.osgi.OpenTracingActivator</Bundle-Activator>
+ <Export-Package>org.apache.geronimo.microprofile.opentracing.osgi.*</Export-Package>
+ <Import-Package>
+ io.opentracing,
+ javax.ws.rs.client;version="[2,3)",
+ javax.ws.rs.container;version="[2,3)",
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
\ No newline at end of file
diff --git a/geronimo-opentracing-osgi/src/main/java/org/apache/geronimo/microprofile/opentracing/osgi/ConfigAdminOpenTracingConfig.java b/geronimo-opentracing-osgi/src/main/java/org/apache/geronimo/microprofile/opentracing/osgi/ConfigAdminOpenTracingConfig.java
index fc4bfe9..4e87530 100644
--- a/geronimo-opentracing-osgi/src/main/java/org/apache/geronimo/microprofile/opentracing/osgi/ConfigAdminOpenTracingConfig.java
+++ b/geronimo-opentracing-osgi/src/main/java/org/apache/geronimo/microprofile/opentracing/osgi/ConfigAdminOpenTracingConfig.java
@@ -29,6 +29,7 @@
public ConfigAdminOpenTracingConfig() {
ofNullable(OpenTracingActivator.INSTANCES.get(ConfigurationAdmin.class))
+ .map(OpenTracingActivator.Tracked::getInstance)
.map(ConfigurationAdmin.class::cast)
.ifPresent(admin -> {
try {
diff --git a/geronimo-opentracing-osgi/src/main/java/org/apache/geronimo/microprofile/opentracing/osgi/OpenTracingActivator.java b/geronimo-opentracing-osgi/src/main/java/org/apache/geronimo/microprofile/opentracing/osgi/OpenTracingActivator.java
index c143d7a..b8087ce 100644
--- a/geronimo-opentracing-osgi/src/main/java/org/apache/geronimo/microprofile/opentracing/osgi/OpenTracingActivator.java
+++ b/geronimo-opentracing-osgi/src/main/java/org/apache/geronimo/microprofile/opentracing/osgi/OpenTracingActivator.java
@@ -17,6 +17,7 @@
package org.apache.geronimo.microprofile.opentracing.osgi;
import static java.util.Collections.singletonMap;
+import static java.util.Optional.ofNullable;
import java.util.ArrayList;
import java.util.Collection;
@@ -58,7 +59,7 @@
import io.opentracing.Tracer;
public class OpenTracingActivator implements BundleActivator {
- // not sure we can avoid that :(
+ // not sure we can avoid that cause of client side :(
static final Map<Class<?>, Tracked<?>> INSTANCES = new HashMap<>();
private final Collection<ServiceRegistration<?>> registrations = new ArrayList<>();
@@ -88,17 +89,15 @@
tracer.setConfig(config);
tracer.setIdGenerator(idGenerator);
tracer.setScopeManager(scopeManager);
- tracer.setFinishedSpanEvent(span -> container
- .lookup(EventAdmin.class)
- .postEvent(new Event("geronimo/microprofile/opentracing/finishedSpan", singletonMap("span", span))));
+ tracer.setFinishedSpanEvent(span -> ofNullable(container.lookup(EventAdmin.class)).ifPresent(ea ->
+ ea.sendEvent(new Event("geronimo/microprofile/opentracing/finishedSpan", singletonMap("span", span)))));
tracer.init();
final ZipkinConverter zipkinConverter = new ZipkinConverter();
zipkinConverter.setConfig(config);
zipkinConverter.setIdGenerator(idGenerator);
- zipkinConverter.setZipkinSpanEvent(span -> container
- .lookup(EventAdmin.class)
- .postEvent(new Event("geronimo/microprofile/opentracing/zipkinSpan", singletonMap("span", span))));
+ zipkinConverter.setZipkinSpanEvent(span -> ofNullable(container.lookup(EventAdmin.class)).ifPresent(ea ->
+ ea.sendEvent(new Event("geronimo/microprofile/opentracing/zipkinSpan", singletonMap("span", span)))));
zipkinConverter.init();
logger = new ZipkinLogger();
diff --git a/geronimo-opentracing-osgi/src/test/java/org/apache/geronimo/microprofile/opentracing/osgi/KarafTest.java b/geronimo-opentracing-osgi/src/test/java/org/apache/geronimo/microprofile/opentracing/osgi/KarafTest.java
index d66ac43..327e699 100644
--- a/geronimo-opentracing-osgi/src/test/java/org/apache/geronimo/microprofile/opentracing/osgi/KarafTest.java
+++ b/geronimo-opentracing-osgi/src/test/java/org/apache/geronimo/microprofile/opentracing/osgi/KarafTest.java
@@ -16,16 +16,26 @@
*/
package org.apache.geronimo.microprofile.opentracing.osgi;
+import static java.util.Objects.requireNonNull;
+import static org.apache.ziplock.JarLocation.jarLocation;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.exam.CoreOptions.maven;
import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemPackage;
import static org.ops4j.pax.exam.CoreOptions.url;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
-import static org.testng.Assert.assertNotNull;
import java.io.File;
import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Dictionary;
+import java.util.Hashtable;
import javax.inject.Inject;
@@ -37,36 +47,68 @@
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.util.Filter;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.event.EventHandler;
import io.opentracing.Tracer;
-@Ignore("likely need more love to work")
+@Ignore("event admin setup is not yet right so the test can't pass")
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class KarafTest {
@Inject
+ private BundleContext bc;
+
+ @Inject
+ @Filter("(objectClass=org.osgi.service.event.EventAdmin)")
+ private EventAdmin eventAdmin;
+
+ @Inject
+ @Filter("(objectClass=io.opentracing.Tracer)")
private Tracer tracer;
@Configuration
public Option[] config() throws MalformedURLException {
- final String karafVersion = "4.2.1";
+ final File testClasses = jarLocation(KarafTest.class);
+ final String projectVersion = System.getProperty("project.version", "1.0.1-SNAPSHOT");
+ final URL testFeature = requireNonNull(new File(testClasses, "features.xml").toURI().toURL());
return options(
karafDistributionConfiguration()
.frameworkUrl(maven()
.groupId("org.apache.karaf")
.artifactId("apache-karaf")
- .version(karafVersion)
+ .version(System.getProperty("karaf.version", "4.2.1"))
.type("tar.gz"))
.unpackDirectory(new File("target/karaf"))
.useDeployFolder(false)
.runEmbedded(true),
keepRuntimeFolder(),
- features(url(new File("src/test/resources/features.xml").toURI().toURL().toExternalForm()), "test")
+ features(url(testFeature.toExternalForm()), "test"),
+ bundle(new File(testClasses, "../../../geronimo-opentracing-common/target/geronimo-opentracing-common-" + projectVersion + ".jar").toURI().toURL().toExternalForm()),
+ bundle(new File(testClasses, "../geronimo-opentracing-osgi-" + projectVersion + ".jar").toURI().toURL().toExternalForm())
);
}
@Test
- public void ensureServicesAreRegistered() {
+ public void checkBusGetSpans() {
assertNotNull(tracer);
+
+ final Dictionary<String, Object> props = new Hashtable<>();
+ props.put(EventConstants.EVENT_TOPIC, "geronimo/microprofile/opentracing/zipkinSpan");
+ final Collection<Event> events = new ArrayList<>();
+ final ServiceRegistration<EventHandler> registration = bc.registerService(EventHandler.class, event -> {
+ synchronized (events) {
+ events.add(event);
+ }
+ }, props);
+ tracer.buildSpan("test").start().finish();
+ registration.unregister();
+
+ assertEquals(1, events.size());
}
}
diff --git a/geronimo-opentracing-osgi/src/test/resources/features.xml b/geronimo-opentracing-osgi/src/test/resources/features.xml
index ae0ed22..05d5cb6 100644
--- a/geronimo-opentracing-osgi/src/test/resources/features.xml
+++ b/geronimo-opentracing-osgi/src/test/resources/features.xml
@@ -25,12 +25,25 @@
<repository>mvn:org.ops4j.pax.cdi/pax-cdi-features/1.0.0/xml/features</repository>
<feature name="test" version="1.0.0" description="Test setup">
+ <!-- base -->
<feature prerequisite="true">wrap</feature>
<feature prerequisite="true">http-whiteboard</feature>
- <!-- todo placeholders -->
- <bundle>mvn:org.apache.servicemix.specs:org.apache.servicemix.specs.jaxrs-api-2.1:2.9.1</bundle>
- <bundle>wrap:mvn:io.opentracing/opentracing-api/0.31.0</bundle>
- <bundle>mvn:http://repo.apache.maven.org/maven2/!org.eclipse.microprofile.opentracing:microprofile-opentracing-api:1.1</bundle>
- <bundle start="true">mvn:org.apache.aries.jax.rs/org.apache.aries.jax.rs.whiteboard/1.0.1</bundle>
+ <bundle>mvn:org.apache.felix/org.apache.felix.eventadmin/1.5.0</bundle>
+
+ <!-- cause MP spec OSGi constraints are not strict enough it leaks that -->
+ <bundle>mvn:javax.interceptor/javax.interceptor-api/1.2</bundle>
+ <bundle>mvn:javax.enterprise/cdi-api/1.2</bundle>
+
+ <!-- spec API -->
+ <bundle>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jaxrs-api-2.1/2.9.1</bundle>
+ <bundle>wrap:mvn:io.opentracing/opentracing-api/${opentracing-api.version}</bundle>
+ <bundle>mvn:org.eclipse.microprofile.opentracing/microprofile-opentracing-api/${microprofile-opentracing-api.version}</bundle>
+
+ <!-- implementations + needed specs -->
+ <bundle>mvn:org.apache.geronimo.specs/geronimo-json_1.1_spec/1.1</bundle>
+ <bundle>mvn:org.apache.geronimo.specs/geronimo-jsonb_1.0_spec/1.1</bundle>
+ <bundle>mvn:org.apache.johnzon/johnzon-core/${johnzon.version}</bundle>
+ <bundle>mvn:org.apache.johnzon/johnzon-mapper/${johnzon.version}</bundle>
+ <bundle>mvn:org.apache.johnzon/johnzon-jsonb/${johnzon.version}</bundle>
</feature>
</features>
diff --git a/pom.xml b/pom.xml
index 32d243f..6c13d12 100644
--- a/pom.xml
+++ b/pom.xml
@@ -41,23 +41,28 @@
<tag>HEAD</tag>
</scm>
+ <properties>
+ <opentracing-api.version>0.31.0</opentracing-api.version>
+ <microprofile-opentracing-api.version>1.2</microprofile-opentracing-api.version>
+ </properties>
+
<dependencies>
<dependency>
<groupId>org.eclipse.microprofile.opentracing</groupId>
<artifactId>microprofile-opentracing-api</artifactId>
- <version>1.2</version>
+ <version>${microprofile-opentracing-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-api</artifactId>
- <version>0.31.0</version>
+ <version>${opentracing-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
- <version>9.0.8</version>
+ <version>9.0.12</version>
<scope>provided</scope>
</dependency>
<dependency>