use of org.eclipse.equinox.concurrent.future.IFuture in project ecf by eclipse.
the class SSLRemoteServiceTrackerTest method testServiceListener.
public void testServiceListener() throws Exception {
final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
done = false;
final Object lock = new Object();
adapters[1].addRemoteServiceListener(new IRemoteServiceListener() {
public void handleServiceEvent(IRemoteServiceEvent event) {
if (event instanceof IRemoteServiceRegisteredEvent) {
IRemoteServiceRegisteredEvent e = (IRemoteServiceRegisteredEvent) event;
IRemoteServiceReference ref = e.getReference();
remoteService = adapters[1].getRemoteService(ref);
assertNotNull(remoteService);
synchronized (lock) {
done = true;
lock.notify();
}
}
}
});
// Now register service on server (adapters[0]). This should result in
// notification on client (adapters[1])
// in above handleServiceEvent
adapters[0].registerRemoteService(new String[] { IConcatService.class.getName() }, createService(), customizeProperties(null));
// wait until block above called asynchronously
int count = 0;
synchronized (lock) {
while (!done && count++ < 10) {
try {
lock.wait(1000);
} catch (InterruptedException e) {
fail();
}
}
}
assertTrue(done);
if (remoteService == null)
return;
// We've got the remote service, so we're good to go
assertTrue(remoteService != null);
traceCallStart("callAsynchResult");
final IFuture result = remoteService.callAsync(createRemoteConcat("ECF AsynchResults ", "are cool"));
traceCallEnd("callAsynch");
assertNotNull(result);
Thread.sleep(SLEEPTIME);
}
use of org.eclipse.equinox.concurrent.future.IFuture in project ecf by eclipse.
the class TwitterRemoteServiceTest method testAsyncCall.
public void testAsyncCall() {
IRemoteService restClientService = getRemoteServiceClientContainerAdapter(container).getRemoteService(registration.getReference());
IFuture future = restClientService.callAsync(RestCallFactory.createRestCall(IUserTimeline.class.getName() + ".getUserStatuses"));
try {
Object response = future.get();
assertTrue(response instanceof IUserStatus[]);
} catch (OperationCanceledException e) {
fail(e.getMessage());
} catch (InterruptedException e) {
fail(e.getMessage());
}
}
use of org.eclipse.equinox.concurrent.future.IFuture in project ecf by eclipse.
the class AbstractRemoteServiceAccessTest method testCallFuture.
public void testCallFuture() throws Exception {
createServiceTrackerAndRegister();
// Client - Get service references from service tracker
final ServiceReference[] remoteReferences = st.getServiceReferences();
assertReferencesValid(remoteReferences);
final Object o = remoteReferences[0].getProperty(RemoteConstants.SERVICE_IMPORTED);
assertNotNull(o);
assertTrue(o instanceof IRemoteService);
final IRemoteService rs = (IRemoteService) o;
// Call asynchronously
final IFuture futureResult = rs.callAsync(createRemoteCall());
// now get result from futureResult
final Object result = futureResult.get();
Trace.trace(Activator.PLUGIN_ID, "callSync.doStuff1 result=" + result);
assertStringResultValid(result, TestServiceInterface1.TEST_SERVICE_STRING1);
}
use of org.eclipse.equinox.concurrent.future.IFuture in project ecf by eclipse.
the class AbstractRemoteServiceAccessTest method testCallFuture.
public void testCallFuture() throws Exception {
startTest("testCallFuture");
createServiceTrackerAndRegister();
// Client - Get service references from service tracker
final ServiceReference[] remoteReferences = st.getServiceReferences();
assertReferencesValid(remoteReferences);
final Object o = remoteReferences[0].getProperty(SERVICE_IMPORTED);
assertNotNull(o);
assertTrue(o instanceof IRemoteService);
final IRemoteService rs = (IRemoteService) o;
// Call asynchronously
final IFuture futureResult = rs.callAsync(createRemoteCall());
// now get result from futureResult
final Object result = futureResult.get();
Trace.trace(Activator.PLUGIN_ID, "callSync.doStuff1 result=" + result);
assertStringResultValid(result, TestServiceInterface1.TEST_SERVICE_STRING1);
endTest("testCallFuture");
}
use of org.eclipse.equinox.concurrent.future.IFuture in project ecf by eclipse.
the class DiscoveryTest method testGetAsyncServices.
/**
* Test method for
* {@link org.eclipse.ecf.discovery.IDiscoveryLocator#getAsyncServices()}.
* @throws ContainerConnectException
* @throws InterruptedException
* @throws OperationCanceledException
*/
public void testGetAsyncServices() throws ContainerConnectException, OperationCanceledException, InterruptedException {
registerService();
final IFuture aFuture = discoveryLocator.getAsyncServices();
final Object object = aFuture.get();
assertTrue(object instanceof IServiceInfo[]);
final IServiceInfo[] services = (IServiceInfo[]) object;
assertTrue("Found: " + services.length + Arrays.asList(services), services.length == eventsToExpect);
for (int i = 0; i < services.length; i++) {
IServiceInfo iServiceInfo = services[i];
if (comparator.compare(iServiceInfo, serviceInfo) == 0) {
return;
}
}
fail("Self registered service not found");
}
Aggregations