Search in sources :

Example 1 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.

the class CreateSubscriptionTask method subscribeToLocation.

private void subscribeToLocation(GpsProxy proxy) {
    // defines how often an update may be sent
    long minInterval_ms = 1000;
    // defines how long to wait before sending an update even if the value did not
    long periodMs = 10000;
    // change or when onChange is false
    // subscribe for one hour
    long validityMs = 1 * 60 * 60 * 1000;
    // defines how long to wait for an update before publicationMissed is called
    long alertIntervalMs = 20000;
    // time to live for publication messages
    long publicationTtlMs = 20000;
    SubscriptionQos subscriptionQos = new PeriodicSubscriptionQos().setPeriodMs(periodMs).setValidityMs(validityMs).setAlertAfterIntervalMs(alertIntervalMs).setPublicationTtlMs(publicationTtlMs);
    AttributeSubscriptionAdapter<GpsLocation> listener = new AttributeSubscriptionAdapter<GpsLocation>() {

        @Override
        public void onReceive(GpsLocation value) {
            logToOutput("Received subscription update: " + value.toString());
        }

        @Override
        public void onError(JoynrRuntimeException error) {
            logToOutput("error in subscription: " + error.getMessage());
        }
    };
    proxy.subscribeToLocation(listener, subscriptionQos);
}
Also used : AttributeSubscriptionAdapter(io.joynr.pubsub.subscription.AttributeSubscriptionAdapter) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) GpsLocation(joynr.types.Localisation.GpsLocation) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos)

Example 2 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.

the class ConnectorTest method subscriptionMethodCallWithNoExpiryDate.

@Test
public void subscriptionMethodCallWithNoExpiryDate() throws JoynrIllegalStateException {
    ConnectorInvocationHandler connector = createConnector();
    assertNotNull(connector);
    try {
        Future<String> future = new Future<String>();
        String subscriptionId = "subscriptionId";
        PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
        subscriptionQos.setPeriodMs(1000).setExpiryDateMs(0).setAlertAfterIntervalMs(1000);
        AttributeSubscriptionListener<GpsPosition> listener = new AttributeSubscriptionAdapter<GpsPosition>();
        Object[] args = new Object[] { listener, subscriptionQos, subscriptionId };
        Method method = LocalisationSubscriptionInterface.class.getDeclaredMethod("subscribeToGPSPosition", String.class, AttributeSubscriptionListener.class, SubscriptionQos.class);
        AttributeSubscribeInvocation attributeSubscription = new AttributeSubscribeInvocation(method, args, future);
        connector.executeSubscriptionMethod(attributeSubscription);
        verify(subscriptionManager, times(1)).registerAttributeSubscription(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), eq(attributeSubscription));
    } catch (Exception e) {
        // This is what is supposed to happen -> no error handling
        fail("Calling a subscription method with no expiry date throws an exception.");
    }
}
Also used : AttributeSubscriptionAdapter(io.joynr.pubsub.subscription.AttributeSubscriptionAdapter) GpsPosition(joynr.types.Localisation.GpsPosition) 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) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) Test(org.junit.Test)

Example 3 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.

the class AbstractSubscriptionEnd2EndTest method registerSubscriptionForComplexDatatype.

@SuppressWarnings("unchecked")
@Test
public void registerSubscriptionForComplexDatatype() throws InterruptedException, ApplicationException {
    final Semaphore onReceiveSemaphore = new Semaphore(0);
    AttributeSubscriptionListener<GpsLocation> gpsListener = mock(AttributeSubscriptionListener.class);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            onReceiveSemaphore.release();
            return null;
        }
    }).when(gpsListener).onReceive(eq(provider.getComplexTestAttributeSync()));
    int periods = 2;
    long subscriptionDuration = (PERIOD_MS * periods) + EXPECTED_LATENCY_MS;
    PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
    subscriptionQos.setPeriodMs(PERIOD_MS);
    subscriptionQos.setValidityMs(subscriptionDuration);
    subscriptionQos.setAlertAfterIntervalMs(500);
    subscriptionQos.setPublicationTtlMs(0);
    Future<String> subscriptionId = proxy.subscribeToComplexTestAttribute(gpsListener, subscriptionQos);
    assertTrue(onReceiveSemaphore.tryAcquire(periods, subscriptionDuration + 1000, TimeUnit.MILLISECONDS));
    verify(gpsListener, times(0)).onError(null);
    proxy.unsubscribeFromComplexTestAttribute(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) GpsLocation(joynr.types.Localisation.GpsLocation) Semaphore(java.util.concurrent.Semaphore) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) Test(org.junit.Test)

Example 4 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.

the class AbstractSubscriptionEnd2EndTest method subscribeToEnumAttribute.

@SuppressWarnings("unchecked")
@Test
public void subscribeToEnumAttribute() throws InterruptedException, ApplicationException {
    final Semaphore onReceiveSemaphore = new Semaphore(0);
    AttributeSubscriptionListener<TestEnum> testEnumListener = mock(AttributeSubscriptionListener.class);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            onReceiveSemaphore.release();
            return null;
        }
    }).when(testEnumListener).onReceive(any(TestEnum.class));
    TestEnum expectedTestEnum = TestEnum.TWO;
    provider.setEnumAttribute(expectedTestEnum);
    int periods = 2;
    long subscriptionDuration = (PERIOD_MS * periods) + EXPECTED_LATENCY_MS;
    PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
    subscriptionQos.setPeriodMs(PERIOD_MS);
    subscriptionQos.setValidityMs(subscriptionDuration);
    subscriptionQos.setAlertAfterIntervalMs(500);
    subscriptionQos.setPublicationTtlMs(0);
    Future<String> subscriptionId = proxy.subscribeToEnumAttribute(testEnumListener, subscriptionQos);
    assertTrue(onReceiveSemaphore.tryAcquire(periods, subscriptionDuration + 1000, TimeUnit.MILLISECONDS));
    verify(testEnumListener, times(0)).onError(null);
    proxy.unsubscribeFromEnumAttribute(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) TestEnum(joynr.tests.testTypes.TestEnum) Semaphore(java.util.concurrent.Semaphore) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) Test(org.junit.Test)

Example 5 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.

the class PublicationManagerTest method restorePublications.

@SuppressWarnings("unchecked")
@Test(timeout = 3000)
public void restorePublications() throws Exception {
    int period = 200;
    String subscriptionId1 = "subscriptionid1";
    String subscriptionId2 = "subscriptionid2";
    long validityMs = 3000;
    SubscriptionQos qosNoExpiry = new PeriodicSubscriptionQos().setPeriodMs(100).setExpiryDateMs(SubscriptionQos.NO_EXPIRY_DATE).setAlertAfterIntervalMs(500).setPublicationTtlMs(1000);
    SubscriptionQos qosExpires = new PeriodicSubscriptionQos().setPeriodMs(100).setValidityMs(validityMs).setAlertAfterIntervalMs(500).setPublicationTtlMs(1000);
    SubscriptionRequest subscriptionRequest1 = new SubscriptionRequest(subscriptionId1, "location", qosNoExpiry);
    SubscriptionRequest subscriptionRequest2 = new SubscriptionRequest(subscriptionId2, "location", qosExpires);
    publicationManager.addSubscriptionRequest(PROXY_PARTICIPANT_ID, PROVIDER_PARTICIPANT_ID, subscriptionRequest1);
    publicationManager.addSubscriptionRequest(PROXY_PARTICIPANT_ID, PROVIDER_PARTICIPANT_ID, subscriptionRequest2);
    Thread.sleep(period);
    verify(dispatcher, times(0)).sendSubscriptionPublication(eq(PROVIDER_PARTICIPANT_ID), (Set<String>) argThat(contains(PROXY_PARTICIPANT_ID)), any(SubscriptionPublication.class), any(MessagingQos.class));
    publicationManager.entryAdded(PROVIDER_PARTICIPANT_ID, providerContainer);
    verify(dispatcher, timeout(period * 5).times(12)).sendSubscriptionPublication(eq(PROVIDER_PARTICIPANT_ID), (Set<String>) argThat(contains(PROXY_PARTICIPANT_ID)), any(SubscriptionPublication.class), any(MessagingQos.class));
}
Also used : SubscriptionRequest(joynr.SubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) SubscriptionPublication(joynr.SubscriptionPublication) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) Matchers.anyString(org.mockito.Matchers.anyString) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) Test(org.junit.Test)

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