Search in sources :

Example 16 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.

the class AbstractSubscriptionEnd2EndTest method registerSubscriptionForListAndReceiveUpdates.

@SuppressWarnings("unchecked")
@Test
public void registerSubscriptionForListAndReceiveUpdates() throws InterruptedException, ApplicationException {
    final Semaphore onReceiveSemaphore = new Semaphore(0);
    AttributeSubscriptionListener<Integer[]> integersListener = mock(AttributeSubscriptionListener.class);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            onReceiveSemaphore.release();
            return null;
        }
    }).when(integersListener).onReceive(any(Integer[].class));
    provider.setTestAttribute(42);
    int periods = 2;
    long subscriptionDuration = (PERIOD_MS * periods) + EXPECTED_LATENCY_MS;
    PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
    subscriptionQos.setPeriodMs(PERIOD_MS);
    subscriptionQos.setValidityMs(subscriptionDuration);
    subscriptionQos.setAlertAfterIntervalMs(0);
    subscriptionQos.setPublicationTtlMs(0);
    Future<String> subscriptionId = proxy.subscribeToListOfInts(integersListener, subscriptionQos);
    assertTrue(onReceiveSemaphore.tryAcquire(periods, subscriptionDuration + 1000, TimeUnit.MILLISECONDS));
    verify(integersListener, times(0)).onError(null);
    verify(integersListener, times(1)).onReceive(eq(new Integer[] { 42 }));
    verify(integersListener, times(1)).onReceive(eq(new Integer[] { 42, 43 }));
    proxy.unsubscribeFromListOfInts(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) Semaphore(java.util.concurrent.Semaphore) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) Test(org.junit.Test)

Example 17 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos 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");
}
Also used : joynr.tests.testProxy(joynr.tests.testProxy) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) MessagingQos(io.joynr.messaging.MessagingQos) ApplicationException(joynr.exceptions.ApplicationException) DiscoveryException(io.joynr.exceptions.DiscoveryException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.

the class AbstractSubscriptionEnd2EndTest method subscribeToAttributeWithProviderRuntimeException.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void subscribeToAttributeWithProviderRuntimeException() throws InterruptedException, ApplicationException {
    Semaphore onErrorSemaphore = new Semaphore(0);
    ProviderRuntimeException expectedException = new ProviderRuntimeException(SubscriptionTestsProviderImpl.MESSAGE_PROVIDERRUNTIMEEXCEPTION);
    AttributeSubscriptionListener<Integer> listener = prepareOnErrorListenerMock(onErrorSemaphore, expectedException);
    int periods = 2;
    int subscriptionDuration = (PERIOD_MS * periods);
    PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
    subscriptionQos.setPeriodMs(PERIOD_MS);
    subscriptionQos.setValidityMs(subscriptionDuration);
    subscriptionQos.setAlertAfterIntervalMs(1000);
    subscriptionQos.setPublicationTtlMs(0);
    Future<String> subscriptionId = proxy.subscribeToAttributeWithProviderRuntimeException(listener, subscriptionQos);
    long timeBeforeTest = System.currentTimeMillis();
    long timeout = subscriptionDuration + EXPECTED_LATENCY_MS;
    // expect at least #periods errors
    assertTrue(onErrorSemaphore.tryAcquire(periods, timeout, TimeUnit.MILLISECONDS));
    // expect at most #periods+1 errors
    timeout = Math.max(timeout - (System.currentTimeMillis() - timeBeforeTest), 100);
    assertFalse(onErrorSemaphore.tryAcquire(2, timeout, TimeUnit.MILLISECONDS));
    // expect no successful subscription callback
    verify(listener, times(0)).onReceive(anyInt());
    proxy.unsubscribeFromAttributeWithProviderRuntimeException(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
}
Also used : Semaphore(java.util.concurrent.Semaphore) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) Test(org.junit.Test)

Example 19 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.

the class AbstractSubscriptionEnd2EndTest method subscribeToAttributeWithThrownException.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void subscribeToAttributeWithThrownException() throws InterruptedException, ApplicationException {
    Semaphore onErrorSemaphore = new Semaphore(0);
    ProviderRuntimeException expectedException = new ProviderRuntimeException(new IllegalArgumentException(SubscriptionTestsProviderImpl.MESSAGE_THROWN_PROVIDERRUNTIMEEXCEPTION).toString());
    AttributeSubscriptionListener<Integer> listener = prepareOnErrorListenerMock(onErrorSemaphore, expectedException);
    int periods = 2;
    int subscriptionDuration = (PERIOD_MS * periods);
    PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
    subscriptionQos.setPeriodMs(PERIOD_MS);
    subscriptionQos.setValidityMs(subscriptionDuration);
    subscriptionQos.setAlertAfterIntervalMs(1000);
    subscriptionQos.setPublicationTtlMs(0);
    Future<String> subscriptionId = proxy.subscribeToAttributeWithThrownException(listener, subscriptionQos);
    long timeBeforeTest = System.currentTimeMillis();
    long timeout = subscriptionDuration + EXPECTED_LATENCY_MS;
    // expect at least #periods errors
    assertTrue(onErrorSemaphore.tryAcquire(periods, timeout, TimeUnit.MILLISECONDS));
    // expect at most #periods+1 errors
    timeout = Math.max(timeout - (System.currentTimeMillis() - timeBeforeTest), 100);
    assertFalse(onErrorSemaphore.tryAcquire(2, timeout, TimeUnit.MILLISECONDS));
    // expect no successful subscription callback
    verify(listener, times(0)).onReceive(anyInt());
    proxy.unsubscribeFromAttributeWithThrownException(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
}
Also used : Semaphore(java.util.concurrent.Semaphore) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) Test(org.junit.Test)

Example 20 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.

the class MutableMessageFactoryTest method setUp.

@Before
public void setUp() throws NoSuchMethodException, SecurityException {
    fromParticipantId = "sender";
    toParticipantId = "receiver";
    Injector injector = Guice.createInjector(new JoynrPropertiesModule(new Properties()), new JsonMessageSerializerModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_TTL_UPLIFT_MS)).toInstance(NO_TTL_UPLIFT);
            requestStaticInjection(Request.class);
            Multibinder<JoynrMessageProcessor> joynrMessageProcessorMultibinder = Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
            });
            joynrMessageProcessorMultibinder.addBinding().toInstance(new JoynrMessageProcessor() {

                @Override
                public MutableMessage processOutgoing(MutableMessage joynrMessage) {
                    joynrMessage.getCustomHeaders().put("test", "test");
                    return joynrMessage;
                }

                @Override
                public ImmutableMessage processIncoming(ImmutableMessage joynrMessage) {
                    return joynrMessage;
                }
            });
        }
    });
    objectMapper = injector.getInstance(ObjectMapper.class);
    payload = "payload";
    Method method = TestProvider.class.getMethod("methodWithStrings", new Class[] { String.class });
    request = new Request(method.getName(), new String[] { payload }, method.getParameterTypes());
    String requestReplyId = request.getRequestReplyId();
    reply = new Reply(requestReplyId, objectMapper.<JsonNode>valueToTree(payload));
    messagingQos = new MessagingQos(TTL);
    expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
    String subscriptionId = "subscription";
    String attributeName = "attribute";
    PeriodicSubscriptionQos subscriptionqos = new PeriodicSubscriptionQos();
    subscriptionqos.setPeriodMs(1000).setValidityMs(10).setAlertAfterIntervalMs(1500).setPublicationTtlMs(1000);
    subscriptionRequest = new SubscriptionRequest(subscriptionId, attributeName, subscriptionqos);
    String response = "response";
    publication = new SubscriptionPublication(Arrays.asList(response), subscriptionId);
    mutableMessageFactory = injector.getInstance(MutableMessageFactory.class);
}
Also used : Multibinder(com.google.inject.multibindings.Multibinder) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) SubscriptionRequest(joynr.SubscriptionRequest) Request(joynr.Request) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) JsonNode(com.fasterxml.jackson.databind.JsonNode) Method(java.lang.reflect.Method) Properties(java.util.Properties) AbstractModule(com.google.inject.AbstractModule) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) MessagingQos(io.joynr.messaging.MessagingQos) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) SubscriptionRequest(joynr.SubscriptionRequest) TypeLiteral(com.google.inject.TypeLiteral) MutableMessage(joynr.MutableMessage) Injector(com.google.inject.Injector) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) SubscriptionPublication(joynr.SubscriptionPublication) ImmutableMessage(joynr.ImmutableMessage) Reply(joynr.Reply) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Aggregations

PeriodicSubscriptionQos (joynr.PeriodicSubscriptionQos)23 Test (org.junit.Test)20 MessagingQos (io.joynr.messaging.MessagingQos)10 SubscriptionPublication (joynr.SubscriptionPublication)8 SubscriptionRequest (joynr.SubscriptionRequest)8 Matchers.anyString (org.mockito.Matchers.anyString)7 Semaphore (java.util.concurrent.Semaphore)6 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)6 SubscriptionQos (io.joynr.pubsub.SubscriptionQos)5 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 AttributeSubscribeInvocation (io.joynr.proxy.invocation.AttributeSubscribeInvocation)3 Ignore (org.junit.Ignore)3 ProviderDirectory (io.joynr.dispatching.ProviderDirectory)2 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)2 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)2 AttributeSubscriptionAdapter (io.joynr.pubsub.subscription.AttributeSubscriptionAdapter)2 Method (java.lang.reflect.Method)2 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)2 PublicationMissedException (joynr.exceptions.PublicationMissedException)2