Search in sources :

Example 6 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.

the class PublicationManagerTest method removeQueuedSubscriptionsProperly.

@SuppressWarnings("unchecked")
@Test(timeout = 3000)
public void removeQueuedSubscriptionsProperly() throws Exception {
    int period = 200;
    String subscriptionId1 = "subscriptionid_removeQueuedSubscriptionsProperly";
    SubscriptionQos qosNoExpiry = new PeriodicSubscriptionQos().setPeriodMs(100).setExpiryDateMs(SubscriptionQos.NO_EXPIRY_DATE).setAlertAfterIntervalMs(500).setPublicationTtlMs(1000);
    SubscriptionRequest subscriptionRequest1 = new SubscriptionRequest(subscriptionId1, "location", qosNoExpiry);
    publicationManager.addSubscriptionRequest(PROXY_PARTICIPANT_ID, PROVIDER_PARTICIPANT_ID, subscriptionRequest1);
    publicationManager.stopPublication(subscriptionId1);
    publicationManager.entryAdded(PROVIDER_PARTICIPANT_ID, providerContainer);
    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));
}
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)

Example 7 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.

the class PublicationManagerTest method persistedSubscriptionRequestsAreQueued.

@SuppressWarnings("unchecked")
@Test(timeout = 3000000)
public void persistedSubscriptionRequestsAreQueued() throws Exception {
    String persistenceFileName = "target/" + PublicationManagerTest.class.getCanonicalName() + ".test_persistenceSubscriptionRequests";
    String providerParticipantId = "providerParticipantId";
    String proxyParticipantId = "proxyParticipantId";
    int period = 200;
    int times = 5;
    int validityMs = (period * times) + period;
    long publicationTtl = validityMs;
    SubscriptionQos qos = new PeriodicSubscriptionQos().setPeriodMs(period).setValidityMs(validityMs).setPublicationTtlMs(publicationTtl);
    SubscriptionRequest subscriptionRequest = new SubscriptionRequest(SUBSCRIPTION_ID, "location", qos);
    new File(persistenceFileName).delete();
    // pre-fill the persistence file
    FileSubscriptionRequestStorage fileSubscriptionRequestStorage = new FileSubscriptionRequestStorage(persistenceFileName);
    assertEquals(0, fileSubscriptionRequestStorage.getSavedSubscriptionRequests().size());
    // no providers are currently registered
    ProviderDirectory myProviderDirectory = new ProviderDirectory();
    publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, myProviderDirectory, cleanupScheduler, fileSubscriptionRequestStorage, shutdownNotifier);
    publicationManager.addSubscriptionRequest(proxyParticipantId, providerParticipantId, subscriptionRequest);
    assertEquals(1, fileSubscriptionRequestStorage.getSavedSubscriptionRequests().size());
    publicationManager.shutdown();
    // open the persistence file that should now contain one element
    fileSubscriptionRequestStorage = new FileSubscriptionRequestStorage(persistenceFileName);
    assertEquals(1, fileSubscriptionRequestStorage.getSavedSubscriptionRequests().size());
    publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, myProviderDirectory, cleanupScheduler, fileSubscriptionRequestStorage, shutdownNotifier);
    // when the provider is registered, persisted subscription requests should be activated
    myProviderDirectory.add(providerParticipantId, providerContainer);
    verify(dispatcher, timeout(validityMs).atLeast(times)).sendSubscriptionPublication(any(String.class), any(Set.class), any(SubscriptionPublication.class), any(MessagingQos.class));
    ;
    Thread.sleep(validityMs + 1000);
    publicationManager.shutdown();
    // Start again with the same file, that should now be empty as all persisted subscriptions were already queued
    reset(dispatcher);
    fileSubscriptionRequestStorage = new FileSubscriptionRequestStorage(persistenceFileName);
    publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, myProviderDirectory, cleanupScheduler, fileSubscriptionRequestStorage, shutdownNotifier);
    verifyNoMoreInteractions(dispatcher);
    fileSubscriptionRequestStorage = new FileSubscriptionRequestStorage(persistenceFileName);
    assertEquals(0, fileSubscriptionRequestStorage.getSavedSubscriptionRequests().size());
}
Also used : Set(java.util.Set) Matchers.anyString(org.mockito.Matchers.anyString) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) SubscriptionRequest(joynr.SubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) SubscriptionPublication(joynr.SubscriptionPublication) ProviderDirectory(io.joynr.dispatching.ProviderDirectory) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) File(java.io.File) Test(org.junit.Test)

Example 8 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.

the class PublicationManagerTest method modifySubscriptionTypeForExistingSubscription.

@SuppressWarnings("unchecked")
@Test(timeout = 3000)
public void modifySubscriptionTypeForExistingSubscription() throws Exception {
    publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, providerDirectory, cleanupScheduler, Mockito.mock(SubscriptionRequestStorage.class), shutdownNotifier);
    int period = 200;
    int testLengthMax = 3000;
    long validityMs = testLengthMax;
    long publicationTtl = testLengthMax;
    SubscriptionQos qos = new PeriodicSubscriptionQos().setPeriodMs(period).setValidityMs(validityMs).setPublicationTtlMs(publicationTtl);
    SubscriptionRequest subscriptionRequest = new SubscriptionRequest(SUBSCRIPTION_ID, "location", qos);
    when(providerDirectory.get(eq(PROVIDER_PARTICIPANT_ID))).thenReturn(providerContainer);
    when(providerDirectory.contains(eq(PROVIDER_PARTICIPANT_ID))).thenReturn(true);
    publicationManager.addSubscriptionRequest(PROXY_PARTICIPANT_ID, PROVIDER_PARTICIPANT_ID, subscriptionRequest);
    verify(dispatcher, timeout(period * 5).times(6)).sendSubscriptionPublication(eq(PROVIDER_PARTICIPANT_ID), (Set<String>) argThat(contains(PROXY_PARTICIPANT_ID)), any(SubscriptionPublication.class), any(MessagingQos.class));
    qos = new OnChangeSubscriptionQos().setMinIntervalMs(0).setValidityMs(validityMs).setPublicationTtlMs(publicationTtl);
    subscriptionRequest = new SubscriptionRequest(SUBSCRIPTION_ID, "location", qos);
    when(providerDirectory.get(eq(PROVIDER_PARTICIPANT_ID))).thenReturn(providerContainer);
    when(providerDirectory.contains(eq(PROVIDER_PARTICIPANT_ID))).thenReturn(true);
    publicationManager.addSubscriptionRequest(PROXY_PARTICIPANT_ID, PROVIDER_PARTICIPANT_ID, subscriptionRequest);
    reset(dispatcher);
    publicationManager.attributeValueChanged(SUBSCRIPTION_ID, valueToPublish);
    verify(dispatcher, timeout(testLengthMax).times(1)).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) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) Matchers.anyString(org.mockito.Matchers.anyString) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) Test(org.junit.Test)

Example 9 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.

the class AbstractLocalCommunicationTest method registerPeriodicSubscriptionAndReceiveUpdatesForLongTime.

// This is a manual test that subscribes for 30 seconds, and checks if all subscriptions arrive. This should also
// work
// when connection is lost during subscription. It will most likely not work, when connection is not present during
// startup.
@Test
@Ignore
public void registerPeriodicSubscriptionAndReceiveUpdatesForLongTime() throws InterruptedException {
    int times = 5;
    final int initialValue = 42;
    int period = lengthInMS / times;
    provider.setATTRIBUTEWITHCAPITALLETTERS(initialValue);
    PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
    subscriptionQos.setPeriodMs(period).setValidityMs(lengthInMS);
    subscriptionQos.setAlertAfterIntervalMs(lengthInMS).setPublicationTtlMs(lengthInMS / 4);
    proxy.subscribeToATTRIBUTEWITHCAPITALLETTERS(listener, subscriptionQos);
    new Timer().scheduleAtFixedRate(new TimerTask() {

        int value = initialValue;

        @Override
        public void run() {
            value++;
            provider.setATTRIBUTEWITHCAPITALLETTERS(value);
        }
    }, period, period);
    // - (System.currentTimeMillis() - currentTime));
    Thread.sleep(lengthInMS);
    verify(listener, times(0)).onError(null);
    // TODO verify publications shipped correct data
    for (int i = 42; i < 42 + times; i++) {
        verify(listener, times(1)).onReceive(eq(i));
    }
    verifyNoMoreInteractions(listener);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.

the class PublicationTimersTest method publicationsSentUntilExpiryDate.

@SuppressWarnings("unchecked")
@Test(timeout = 4000)
public void publicationsSentUntilExpiryDate() throws InterruptedException, JoynrSendBufferFullException, JoynrMessageNotSentException, JsonGenerationException, JsonMappingException, IOException {
    LOG.debug("Starting PublicationTimersTest.timerIsStoppedWhenEnddateIsReached test");
    int period = 500;
    int subscriptionLength = 1100;
    PeriodicSubscriptionQos qos = new PeriodicSubscriptionQos();
    qos.setPeriodMs(period).setValidityMs(subscriptionLength).setPublicationTtlMs(1000);
    String subscriptionId = "subscriptionId";
    String proxyId = "proxyId";
    String providerId = "providerId";
    ProviderDirectory providerDirectory = Mockito.mock(ProviderDirectory.class);
    SubscriptionRequest subscriptionRequest = new SubscriptionRequest(subscriptionId, attributeName, qos);
    PublicationManager publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, providerDirectory, cleanupScheduler, Mockito.mock(SubscriptionRequestStorage.class), shutdownNotifier);
    when(providerDirectory.get(eq(providerId))).thenReturn(providerContainer);
    when(providerDirectory.contains(eq(providerId))).thenReturn(true);
    publicationManager.addSubscriptionRequest(proxyId, providerId, subscriptionRequest);
    Thread.sleep(subscriptionLength + period / 2);
    int publicationTimes = 1 + (subscriptionLength / period);
    verify(dispatcher, times(publicationTimes)).sendSubscriptionPublication(eq(providerId), (Set<String>) argThat(contains(proxyId)), any(SubscriptionPublication.class), any(MessagingQos.class));
    Thread.sleep(subscriptionLength);
    verify(dispatcher).sendSubscriptionReply(eq(providerId), eq(proxyId), any(SubscriptionReply.class), any(MessagingQos.class));
    verifyNoMoreInteractions(dispatcher);
}
Also used : SubscriptionReply(joynr.SubscriptionReply) SubscriptionRequest(joynr.SubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) SubscriptionPublication(joynr.SubscriptionPublication) ProviderDirectory(io.joynr.dispatching.ProviderDirectory) 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