Search in sources :

Example 6 with AttributeSubscriptionAdapter

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;
    }
}
Also used : OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) AttributeSubscriptionAdapter(io.joynr.pubsub.subscription.AttributeSubscriptionAdapter) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 7 with AttributeSubscriptionAdapter

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);
    }
}
Also used : AttributeSubscriptionAdapter(io.joynr.pubsub.subscription.AttributeSubscriptionAdapter) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) Method(java.lang.reflect.Method) AttributeSubscribeInvocation(io.joynr.proxy.invocation.AttributeSubscribeInvocation) SubscriptionException(io.joynr.exceptions.SubscriptionException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) Test(org.junit.Test)

Aggregations

AttributeSubscriptionAdapter (io.joynr.pubsub.subscription.AttributeSubscriptionAdapter)7 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)5 OnChangeWithKeepAliveSubscriptionQos (joynr.OnChangeWithKeepAliveSubscriptionQos)4 Test (org.junit.Test)4 PeriodicSubscriptionQos (joynr.PeriodicSubscriptionQos)3 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)3 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)2 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)2 SubscriptionException (io.joynr.exceptions.SubscriptionException)2 MessagingQos (io.joynr.messaging.MessagingQos)2 AttributeSubscribeInvocation (io.joynr.proxy.invocation.AttributeSubscribeInvocation)2 SubscriptionQos (io.joynr.pubsub.SubscriptionQos)2 Method (java.lang.reflect.Method)2 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)2 GpsLocation (joynr.types.Localisation.GpsLocation)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 SuppressWarnings (edu.umd.cs.findbugs.annotations.SuppressWarnings)1 DiscoveryException (io.joynr.exceptions.DiscoveryException)1 JoynrCommunicationException (io.joynr.exceptions.JoynrCommunicationException)1