use of io.joynr.proxy.Future in project joynr by bmwcarit.
the class LocalDiscoveryTest method testLocalDiscoveryEntries.
@Test
public void testLocalDiscoveryEntries() {
String testDomain = "testDomain";
String interfaceName = testProxy.INTERFACE_NAME;
Collection<DiscoveryEntry> discoveryEntries = new HashSet<>();
DiscoveryEntry discoveryEntry = new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantId", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId");
discoveryEntries.add(discoveryEntry);
when(localDiscoveryEntryStoreMock.lookup(any(String[].class), eq(interfaceName))).thenReturn(discoveryEntries);
ProxyBuilder<testProxy> proxyBuilder = runtime.getProxyBuilder(testDomain, testProxy.class);
final Future<Void> future = new Future<Void>();
DiscoveryQos discoveryQos = new DiscoveryQos();
discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_ONLY);
proxyBuilder.setDiscoveryQos(discoveryQos).build(new ProxyCreatedCallback<testProxy>() {
@Override
public void onProxyCreationFinished(testProxy result) {
future.onSuccess(null);
}
@Override
public void onProxyCreationError(JoynrRuntimeException error) {
future.onFailure(error);
}
});
try {
future.get(5000);
verify(joynrMessagingConnectorFactoryMock).create(anyString(), discoveryEntryWithMetaInfoArgumentCaptor.capture(), any(MessagingQos.class));
assertDiscoveryEntryEqualsCaptured(discoveryEntry);
} catch (Exception e) {
Assert.fail("Unexpected exception from ProxyCreatedCallback: " + e);
}
}
use of io.joynr.proxy.Future in project joynr by bmwcarit.
the class AbstractProviderProxyEnd2EndTest method testVoidOperation.
@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void testVoidOperation() throws DiscoveryException, JoynrIllegalStateException, InterruptedException, JoynrWaitExpiredException, ApplicationException {
ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
final Future<Boolean> future = new Future<Boolean>();
proxy.voidOperation(new Callback<Void>() {
@Override
public void onSuccess(Void result) {
future.onSuccess(true);
}
@Override
public void onFailure(JoynrRuntimeException error) {
future.onFailure(error);
}
});
Boolean reply = future.get(8000);
assertTrue(reply);
}
use of io.joynr.proxy.Future in project joynr by bmwcarit.
the class AccessControllerEnd2EndTest method createProxy.
private testProxy createProxy(JoynrRuntime runtime) {
DiscoveryQos discoveryQos = new DiscoveryQos();
discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_ONLY);
discoveryQos.setArbitrationStrategy(ArbitrationStrategy.HighestPriority);
discoveryQos.setDiscoveryTimeoutMs(DISCOVERY_TIMEOUT);
MessagingQos messagingQos = new MessagingQos();
messagingQos.setTtl_ms(MESSAGING_TTL);
final Future<Void> future = new Future<Void>();
testProxy testProxy;
testProxy = runtime.getProxyBuilder(TEST_DOMAIN, testProxy.class).setDiscoveryQos(discoveryQos).setMessagingQos(messagingQos).build(new ProxyCreatedCallback<testProxy>() {
@Override
public void onProxyCreationFinished(testProxy result) {
future.onSuccess(null);
}
@Override
public void onProxyCreationError(JoynrRuntimeException error) {
future.onFailure(error);
}
});
try {
future.get(5000);
} catch (Exception e) {
Assert.fail("Unexpected exception from ProxyCreatedCallback: " + e);
}
return testProxy;
}
use of io.joynr.proxy.Future in project joynr by bmwcarit.
the class LocalCapabilitiesDirectoryTest method createAddAnswerWithError.
private Answer<Future<Void>> createAddAnswerWithError() {
return new Answer<Future<Void>>() {
@SuppressWarnings("unchecked")
@Override
public Future<Void> answer(InvocationOnMock invocation) throws Throwable {
Future<Void> result = new Future<Void>();
Object[] args = invocation.getArguments();
((Callback<Void>) args[0]).onFailure(new JoynrRuntimeException("Simulating a JoynrRuntimeException on callback"));
result.onSuccess(null);
return result;
}
};
}
Aggregations