use of io.joynr.pubsub.subscription.AttributeSubscriptionAdapter in project joynr by bmwcarit.
the class IltConsumerAttributeSubscriptionTest method callSubscribeAttributeWithExceptionFromGetter.
@Test
public void callSubscribeAttributeWithExceptionFromGetter() {
Future<String> subscriptionIdFuture;
String subscriptionId;
int minIntervalMs = 0;
int maxIntervalMs = 10000;
long validityMs = 60000;
int alertAfterIntervalMs = 20000;
int publicationTtlMs = 5000;
OnChangeWithKeepAliveSubscriptionQos subscriptionQos = new OnChangeWithKeepAliveSubscriptionQos().setMinIntervalMs(minIntervalMs).setMaxIntervalMs(maxIntervalMs).setValidityMs(validityMs).setAlertAfterIntervalMs(alertAfterIntervalMs).setPublicationTtlMs(publicationTtlMs);
boolean result;
LOG.info(name.getMethodName() + "");
try {
subscriptionIdFuture = testInterfaceProxy.subscribeToAttributeWithExceptionFromGetter(new AttributeSubscriptionAdapter<Boolean>() {
@Override
public void onReceive(Boolean value) {
LOG.info(name.getMethodName() + " - callback - got unexpected publication");
subscribeAttributeWithExceptionFromGetterCallbackResult = false;
subscribeAttributeWithExceptionFromGetterCallbackDone = true;
}
@Override
public void onError(JoynrRuntimeException error) {
if (error instanceof ProviderRuntimeException) {
if (((ProviderRuntimeException) error).getMessage().equals("Exception from getAttributeWithExceptionFromGetter")) {
LOG.info(name.getMethodName() + " - callback - got expected exception " + ((JoynrRuntimeException) error).getMessage());
subscribeAttributeWithExceptionFromGetterCallbackResult = true;
subscribeAttributeWithExceptionFromGetterCallbackDone = true;
return;
}
LOG.info(name.getMethodName() + " - callback - caught invalid exception " + ((JoynrRuntimeException) error).getMessage());
} else if (error instanceof JoynrRuntimeException) {
LOG.info(name.getMethodName() + " - callback - caught invalid exception " + ((JoynrRuntimeException) error).getMessage());
} else {
LOG.info(name.getMethodName() + " - callback - caught invalid exception ");
}
subscribeAttributeWithExceptionFromGetterCallbackResult = false;
subscribeAttributeWithExceptionFromGetterCallbackDone = true;
}
}, subscriptionQos);
subscriptionId = subscriptionIdFuture.get(10000);
LOG.info(name.getMethodName() + " - subscription successful, subscriptionId = " + subscriptionId);
// should have been called ahead anyway
if (subscribeAttributeWithExceptionFromGetterCallbackDone == false) {
LOG.info(name.getMethodName() + " - about to wait for a second for callback");
Thread.sleep(1000);
LOG.info(name.getMethodName() + " - wait for callback is over");
} else {
LOG.info(name.getMethodName() + " - callback already done");
}
if (!subscribeAttributeWithExceptionFromGetterCallbackDone) {
fail(name.getMethodName() + " - FAILED - callback did not get called in time");
result = false;
} else if (subscribeAttributeWithExceptionFromGetterCallbackResult) {
LOG.info(name.getMethodName() + " - callback got called and received expected exception");
result = true;
} else {
fail(name.getMethodName() + " - FAILED - callback got called but received unexpected result");
result = false;
}
// try to unsubscribe in any case
try {
testInterfaceProxy.unsubscribeFromAttributeWithExceptionFromGetter(subscriptionId);
LOG.info(name.getMethodName() + " - unsubscribe successful");
} catch (Exception e) {
fail(name.getMethodName() + " - FAILED - caught unexpected exception on unsubscribe: " + e.getMessage());
result = false;
}
if (!result) {
LOG.info(name.getMethodName() + " - FAILED");
} else {
LOG.info(name.getMethodName() + " - OK");
}
return;
} catch (Exception e) {
// also catches InterruptedException from Thread.sleep() call
LOG.info(name.getMethodName() + " - caught unexpected exception");
LOG.info(name.getMethodName() + " - FAILED");
fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
return;
}
}
use of io.joynr.pubsub.subscription.AttributeSubscriptionAdapter in project joynr by bmwcarit.
the class ConnectorTest method subscribeToAttributeCallCallsSubscriptionManagerWithCorrectArguments.
@Test
public void subscribeToAttributeCallCallsSubscriptionManagerWithCorrectArguments() {
AttributeSubscriptionListener<String> listener = new AttributeSubscriptionAdapter<>();
SubscriptionQos subscriptionQos = new OnChangeSubscriptionQos();
ConnectorInvocationHandler connector = createConnector();
assertNotNull(connector);
try {
Method method = TestSubscriptionInterface.class.getDeclaredMethod("subscribeToTestAttribute", AttributeSubscriptionListener.class, SubscriptionQos.class);
AttributeSubscribeInvocation invocation = new AttributeSubscribeInvocation(method, new Object[] { listener, subscriptionQos }, null);
connector.executeSubscriptionMethod(invocation);
verify(subscriptionManager, times(1)).registerAttributeSubscription(fromParticipantId, toDiscoveryEntries, invocation);
} catch (Exception e) {
fail("Unexpected exception from attribute subscribe call: " + e);
}
}
Aggregations