Skip to content

Commit

Permalink
Filter out foreign events in TestRSAListener
Browse files Browse the repository at this point in the history
  • Loading branch information
cschneider committed May 2, 2017
1 parent 8172c77 commit 56159ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ protected int getFreePort() throws IOException {
}
}

protected Bundle getBundle(String symName) {
Bundle serviceBundle = null;
Bundle[] bundles = bundleContext.getBundles();
for (Bundle bundle : bundles) {
if(symName.equals(bundle.getSymbolicName())) {
serviceBundle = bundle;
break;
}
}
return serviceBundle;
}

protected static Option echoTcpAPI() {
return mvn("org.apache.aries.rsa.examples.echotcp", "org.apache.aries.rsa.examples.echotcp.api");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,21 @@

import java.util.concurrent.TimeoutException;

import javax.inject.Inject;

import org.apache.aries.rsa.itests.felix.RsaTestBase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent;
import org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener;

@RunWith(PaxExam.class)
public class TestRSAListener extends RsaTestBase implements RemoteServiceAdminListener {

@Inject
BundleContext context;

private RemoteServiceAdminEvent lastEvent;

private Bundle serviceBundle;

@Configuration
public static Option[] configure() throws Exception {
Expand All @@ -58,9 +51,9 @@ public static Option[] configure() throws Exception {

@Test
public void testListener() throws Exception {
Bundle serviceBundle = getBundle("org.apache.aries.rsa.examples.echotcp.service");
serviceBundle = getBundle("org.apache.aries.rsa.examples.echotcp.service");
serviceBundle.stop();
ServiceRegistration<RemoteServiceAdminListener> sreg = context.registerService(RemoteServiceAdminListener.class, this, null);
ServiceRegistration<RemoteServiceAdminListener> sreg = bundleContext.registerService(RemoteServiceAdminListener.class, this, null);

serviceBundle.start();
assertEvent(RemoteServiceAdminEvent.EXPORT_REGISTRATION);
Expand All @@ -73,8 +66,10 @@ public void testListener() throws Exception {

@Override
public synchronized void remoteAdminEvent(RemoteServiceAdminEvent event) {
lastEvent = event;
this.notifyAll();
if (serviceBundle == event.getExportReference().getExportedService().getBundle()) {
lastEvent = event;
this.notifyAll();
}
}

private void assertEvent(int eventType) throws InterruptedException, TimeoutException {
Expand All @@ -94,16 +89,4 @@ private synchronized void waitEvent() throws InterruptedException, TimeoutExcept
}
}

private Bundle getBundle(String symName) {
Bundle serviceBundle = null;
Bundle[] bundles = context.getBundles();
for (Bundle bundle : bundles) {
if(symName.equals(bundle.getSymbolicName())) {
serviceBundle = bundle;
break;
}
}
return serviceBundle;
}

}

0 comments on commit 56159ea

Please # to comment.