use of joynr.exceptions.ApplicationException in project joynr by bmwcarit.
the class AbstractSubscriptionEnd2EndTest method testSubscribeToNonExistentDomain.
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "NP_NULL_ON_SOME_PATH_EXCEPTION", justification = "NPE in test would fail test")
@SuppressWarnings("unchecked")
@Ignore
@Test
public void testSubscribeToNonExistentDomain() throws InterruptedException {
AttributeSubscriptionListener<Integer> integerListener = mock(AttributeSubscriptionListener.class);
testProxy proxyToNonexistentDomain = null;
try {
ProxyBuilder<testProxy> proxyBuilder;
String nonExistentDomain = UUID.randomUUID().toString() + "-domaindoesnotexist-end2end";
MessagingQos messagingQos = new MessagingQos(20000);
DiscoveryQos discoveryQos = new DiscoveryQos(50000, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE);
proxyBuilder = consumerRuntime.getProxyBuilder(nonExistentDomain, testProxy.class);
proxyToNonexistentDomain = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
} catch (DiscoveryException e) {
logger.error(e.getMessage(), e);
} catch (JoynrIllegalStateException e) {
logger.error(e.getMessage(), e);
}
// This should not cause an exception
PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
subscriptionQos.setPeriodMs(PERIOD_MS);
subscriptionQos.setValidityMs(30000);
subscriptionQos.setAlertAfterIntervalMs(0);
subscriptionQos.setPublicationTtlMs(0);
Future<String> subscriptionId = proxyToNonexistentDomain.subscribeToTestAttribute(integerListener, subscriptionQos);
Thread.sleep(4000);
try {
proxyToNonexistentDomain.unsubscribeFromTestAttribute(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
} catch (JoynrRuntimeException | ApplicationException e) {
assertTrue(e.getMessage(), e != null);
}
getSubscriptionTestsPublisher().waitForAttributeUnsubscription("testAttribute");
}
use of joynr.exceptions.ApplicationException in project joynr by bmwcarit.
the class ProxyTest method createProxyAndCallSyncMethodFailWithApplicationError.
@Test
public void createProxyAndCallSyncMethodFailWithApplicationError() throws Exception {
String requestReplyId = "createProxyAndCallSyncMethod_requestReplyId";
Mockito.when(requestReplyManager.sendSyncRequest(Mockito.<String>any(), Mockito.<DiscoveryEntryWithMetaInfo>any(), Mockito.<Request>any(), Mockito.<SynchronizedReplyCaller>any(), Mockito.<MessagingQos>any())).thenReturn(new Reply(requestReplyId, new ApplicationException(ApplicationErrors.ERROR_VALUE_2, "syncMethodCallApplicationException")));
ProxyBuilder<TestInterface> proxyBuilder = getProxyBuilder(TestInterface.class);
TestInterface proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
ApplicationException exception = null;
try {
proxy.methodWithApplicationError();
Assert.fail("Should throw ApplicationException");
} catch (ApplicationException e) {
exception = e;
}
Assert.assertEquals(new ApplicationException(ApplicationErrors.ERROR_VALUE_2, "syncMethodCallApplicationException"), exception);
}
use of joynr.exceptions.ApplicationException in project joynr by bmwcarit.
the class ProxyTest method createProxyAndCallAsyncMethodFailWithApplicationError.
@SuppressWarnings({ "unchecked" })
@Test
public void createProxyAndCallAsyncMethodFailWithApplicationError() throws Exception {
final ApplicationException expected = new ApplicationException(ApplicationErrors.ERROR_VALUE_3, "TEST: createProxyAndCallAsyncMethodFailWithApplicationError");
TestInterface proxy = getTestInterfaceProxy();
// when joynrMessageSender1.sendRequest is called, get the replyCaller from the mock dispatcher and call
// messageCallback on it.
Mockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws JsonParseException, JsonMappingException, IOException {
// capture the replyCaller passed into the dispatcher for calling later
ArgumentCaptor<ReplyCaller> replyCallerCaptor = ArgumentCaptor.forClass(ReplyCaller.class);
verify(replyCallerDirectory).addReplyCaller(anyString(), replyCallerCaptor.capture(), any(ExpiryDate.class));
String requestReplyId = "createProxyAndCallAsyncMethodSuccess_requestReplyId";
// pass the response to the replyCaller
replyCallerCaptor.getValue().messageCallBack(new Reply(requestReplyId, expected));
return null;
}
}).when(requestReplyManager).sendRequest(Mockito.<String>any(), Mockito.<DiscoveryEntryWithMetaInfo>any(), Mockito.<Request>any(), Mockito.<MessagingQos>any());
CallbackWithModeledError<String, Enum<?>> callbackWithApplicationException = Mockito.mock(CallbackWithModeledError.class);
final Future<String> future = proxy.asyncMethodWithApplicationError(callbackWithApplicationException);
// the test usually takes only 200 ms, so if we wait 1 sec, something has gone wrong
try {
future.get(1000);
Assert.fail("Should throw ApplicationException");
} catch (ApplicationException e) {
Assert.assertEquals(expected, e);
}
verify(callbackWithApplicationException).onFailure(expected.getError());
Assert.assertEquals(RequestStatusCode.ERROR, future.getStatus().getCode());
}
use of joynr.exceptions.ApplicationException in project joynr by bmwcarit.
the class SerializationTest method serializeReplyWithJoynrApplicationException.
@Test
public void serializeReplyWithJoynrApplicationException() throws IOException {
ApplicationException error = new ApplicationException(TestEnum.ONE, "detail message");
Reply reply = new Reply(UUID.randomUUID().toString(), error);
String writeValueAsString = objectMapper.writeValueAsString(reply);
System.out.println(writeValueAsString);
Reply receivedReply = objectMapper.readValue(writeValueAsString, Reply.class);
Assert.assertEquals(reply, receivedReply);
}
use of joynr.exceptions.ApplicationException in project joynr by bmwcarit.
the class AbstractBroadcastEnd2EndTest method subscribeAndUnsubscribeFromBroadcast.
@Ignore
@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void subscribeAndUnsubscribeFromBroadcast() throws InterruptedException {
final Semaphore broadcastReceived = new Semaphore(0);
Future<String> subscriptionId = proxy.subscribeToLocationUpdateWithSpeedBroadcast(new testBroadcastInterface.LocationUpdateWithSpeedBroadcastAdapter() {
@Override
public void onReceive(GpsLocation location, Float speed) {
assertEquals(expectedLocation, location);
assertEquals(expectedSpeed, speed);
broadcastReceived.release();
}
}, new MulticastSubscriptionQos());
Thread.sleep(300);
provider.fireLocationUpdateWithSpeed(expectedLocation, expectedSpeed);
broadcastReceived.acquire();
// unsubscribe correct subscription -> now, no more broadcast shall be received
proxy.unsubscribeFromLocationUpdateWithSpeedBroadcast(UUID.randomUUID().toString());
provider.fireLocationUpdateWithSpeed(expectedLocation, expectedSpeed);
broadcastReceived.acquire();
// unsubscribe correct subscription -> now, no more broadcast shall be received
try {
proxy.unsubscribeFromLocationUpdateWithSpeedBroadcast(subscriptionId.get());
} catch (JoynrRuntimeException | ApplicationException e) {
logger.error(e.getMessage());
}
Thread.sleep(300);
provider.fireLocationUpdateWithSpeed(expectedLocation, expectedSpeed);
assertFalse(broadcastReceived.tryAcquire(300, TimeUnit.MILLISECONDS));
}
Aggregations