use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class LocalDiscoveryTest method testRemoteGlobalDiscoveryEntries.
@SuppressWarnings("unchecked")
@Test
public void testRemoteGlobalDiscoveryEntries() {
String testDomain = "testDomain";
String interfaceName = testProxy.INTERFACE_NAME;
final Collection<DiscoveryEntry> discoveryEntries = new HashSet<>();
final List<GlobalDiscoveryEntry> globalDiscoveryEntries = new ArrayList<>();
DiscoveryEntry discoveryEntry = new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantId", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId");
discoveryEntries.add(discoveryEntry);
globalDiscoveryEntries.add(CapabilityUtils.discoveryEntry2GlobalDiscoveryEntry(discoveryEntry, new MqttAddress()));
when(globalDiscoveryEntryCacheMock.lookup(any(String[].class), eq(interfaceName), anyLong())).thenReturn(new HashSet<DiscoveryEntry>());
Mockito.doAnswer(new Answer<Object>() {
@SuppressWarnings("rawtypes")
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
assert (arguments[0] instanceof Callback);
((Callback) arguments[0]).resolve((Object) globalDiscoveryEntries);
return null;
}
}).when(globalCapabilitiesDirectoryClientMock).lookup(any(Callback.class), any(String[].class), eq(interfaceName), anyLong());
ProxyBuilder<testProxy> proxyBuilder = runtime.getProxyBuilder(testDomain, testProxy.class);
final Future<Void> future = new Future<Void>();
DiscoveryQos discoveryQos = new DiscoveryQos();
discoveryQos.setDiscoveryScope(DiscoveryScope.GLOBAL_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.exceptions.JoynrRuntimeException 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.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class ProxyErrorsTest method setUp.
@Before
public void setUp() {
// the error callback and NoCompatibleProviderFoundException will each increment the permits.
// The test will wait until 2 permits are available, or fail in the junit test timeout time.
waitOnExceptionAndErrorCallbackSemaphore = new Semaphore(-1, true);
domain = "domain-" + UUID.randomUUID().toString();
domain2 = "domain2-" + UUID.randomUUID().toString();
Properties joynrConfig = new Properties();
joynrConfig.setProperty(MessagingPropertyKeys.CHANNELID, "discoverydirectory_channelid");
// provider and proxy using same runtime to allow local-only communications
runtime = getRuntime(joynrConfig);
ProviderQos providerQos = new ProviderQos();
providerQos.setScope(ProviderScope.LOCAL);
runtime.registerProvider(domain, provider, providerQos);
runtime.registerProvider(domain2, provider, providerQos);
discoveryQos = new DiscoveryQos();
discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_ONLY);
discoveryQos.setDiscoveryTimeoutMs(1000);
discoveryQos.setRetryIntervalMs(100);
callback = new ProxyCreatedCallback<ProxyErrorsTest.TestProxyWrongVersion>() {
@Override
public void onProxyCreationFinished(TestProxyWrongVersion result) {
fail("proxy creation should fail with a version exception");
}
@Override
public void onProxyCreationError(JoynrRuntimeException error) {
// adds 1 of 2 permits to the semaphore. The other is provided when the exception is caught
waitOnExceptionAndErrorCallbackSemaphore.release();
}
};
}
use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class AbstractProviderProxyEnd2EndTest method syncMethodCallReturnsErrorEnum.
@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void syncMethodCallReturnsErrorEnum() {
ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
try {
proxy.methodWithErrorEnum();
fail("Should throw ApplicationException");
} catch (JoynrRuntimeException e) {
fail(e.toString());
} catch (ApplicationException e) {
ApplicationException expected = new ApplicationException(ErrorEnumBase.BASE_ERROR_TYPECOLLECTION);
assertEquals(expected, e);
}
}
use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class AbstractProviderProxyEnd2EndTest method asyncMethodCallReturnsExtendedErrorEnum.
@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void asyncMethodCallReturnsExtendedErrorEnum() {
ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
ApplicationException expected = new ApplicationException(MethodWithErrorEnumExtendedErrorEnum.IMPLICIT_ERROR_TYPECOLLECTION);
Future<Void> future = proxy.methodWithErrorEnumExtended(callbackWithApplicationExceptionMethodWithErrorEnumExtendedErrorEnum);
try {
future.get();
fail("Should throw ApplicationException");
} catch (JoynrRuntimeException | InterruptedException e) {
fail(e.toString());
} catch (ApplicationException e) {
assertEquals(expected, e);
}
verify(callbackWithApplicationExceptionMethodWithErrorEnumExtendedErrorEnum).onFailure((MethodWithErrorEnumExtendedErrorEnum) (expected.getError()));
}
Aggregations