public void testBasicInvocation() throws Exception {
Thread.currentThread().setContextClassLoader(JAXRSClientFactoryBean.class.getClassLoader());
bundleContext.registerService(new String[]{"javax.ws.rs.ext.MessageBodyReader"},
new AegisElementProvider(), new Hashtable());
Server server1 = null;
Server server2 = null;
ServiceTracker tracker = null;
try {
server1 = startServer(ADDRESS1,
GreeterService.class, new GreeterServiceImpl());
server2 = startServer(ADDRESS2,
GreeterService.class, new GreeterServiceImpl());
tracker = new ServiceTracker(bundleContext,
GreeterService.class.getName(), null) {
@Override
public Object addingService(final ServiceReference reference) {
Object result = super.addingService(reference);
FutureTask<GreeterInfo> future =
new FutureTask<GreeterInfo>(new Callable<GreeterInfo>() {
public GreeterInfo call() {
return useService(reference);
}});
future.run();
synchronized (mutex1) {
synchronized (mutex2) {
if (task1 == null) {
task1 = future;
mutex1.notify();
} else if (task2 == null) {
task2 = future;
mutex2.notify();
}
}
}
return result;
}
};
tracker.open();
// sleep for a bit
Thread.sleep(2000);
installDswIfNeeded();
verifyGreeterResponse(task1, mutex1);
verifyGreeterResponse(task2, mutex2);
} finally {
if (tracker != null) {
tracker.close();
}
if (server1 != null) {
server1.getDestination().shutdown();
server1.stop();
}
if (server2 != null) {
server2.getDestination().shutdown();
server2.stop();
}
}
}