Search in sources :

Example 11 with SubscriptionRequest

use of joynr.SubscriptionRequest 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 12 with SubscriptionRequest

use of joynr.SubscriptionRequest in project joynr by bmwcarit.

the class PublicationManagerTest method stopAllPublicationsFromProvider.

@SuppressWarnings("unchecked")
@Test(timeout = 3000)
public void stopAllPublicationsFromProvider() throws Exception {
    String subscriptionId1 = "subscriptionid1";
    String subscriptionId2 = "subscriptionid2";
    OnChangeSubscriptionQos qos = new OnChangeSubscriptionQos();
    qos.setMinIntervalMs(0).setValidityMs(3000).setPublicationTtlMs(1000);
    SubscriptionRequest subscriptionRequest1 = new SubscriptionRequest(subscriptionId1, "location", qos);
    SubscriptionRequest subscriptionRequest2 = new SubscriptionRequest(subscriptionId2, "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, subscriptionRequest1);
    publicationManager.addSubscriptionRequest(PROXY_PARTICIPANT_ID, PROVIDER_PARTICIPANT_ID, subscriptionRequest2);
    publicationManager.attributeValueChanged(subscriptionId1, valueToPublish);
    publicationManager.attributeValueChanged(subscriptionId2, valueToPublish);
    // sending initial values for 2 subscriptions, plus the 2 attributeValueChanged
    verify(dispatcher, times(4)).sendSubscriptionPublication(eq(PROVIDER_PARTICIPANT_ID), (Set<String>) argThat(contains(PROXY_PARTICIPANT_ID)), any(SubscriptionPublication.class), any(MessagingQos.class));
    reset(dispatcher);
    publicationManager.entryRemoved(PROVIDER_PARTICIPANT_ID);
    publicationManager.attributeValueChanged(subscriptionId1, valueToPublish);
    publicationManager.attributeValueChanged(subscriptionId2, valueToPublish);
    verify(dispatcher, timeout(300).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) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) SubscriptionPublication(joynr.SubscriptionPublication) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 13 with SubscriptionRequest

use of joynr.SubscriptionRequest 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 14 with SubscriptionRequest

use of joynr.SubscriptionRequest in project joynr by bmwcarit.

the class PublicationManagerTest method doNotDelayBroadcastPublicationBurstsForOnChangeSubscriptionsWithoutMinInterval.

@SuppressWarnings("unchecked")
@Test(timeout = 4000)
public void doNotDelayBroadcastPublicationBurstsForOnChangeSubscriptionsWithoutMinInterval() throws Exception {
    int subscriptionLength = 500;
    OnChangeSubscriptionQos qos = new OnChangeSubscriptionQos();
    qos.setMinIntervalMs(0);
    qos.setValidityMs(subscriptionLength);
    qos.setPublicationTtlMs(400);
    String subscriptionId = "subscriptionId";
    String proxyId = "proxyId";
    String providerId = "providerId";
    String broadcastName = "location";
    ProviderDirectory requestCallerDirectory = mock(ProviderDirectory.class);
    SubscriptionRequest subscriptionRequest = new BroadcastSubscriptionRequest(subscriptionId, broadcastName, new BroadcastFilterParameters(), qos);
    PublicationManager publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, requestCallerDirectory, cleanupScheduler, Mockito.mock(SubscriptionRequestStorage.class), shutdownNotifier);
    when(requestCallerDirectory.get(eq(providerId))).thenReturn(providerContainer);
    when(requestCallerDirectory.contains(eq(providerId))).thenReturn(true);
    publicationManager.addSubscriptionRequest(proxyId, providerId, subscriptionRequest);
    List<BroadcastFilter> noFilters = Lists.newArrayList();
    int nrBroadcasts = 100;
    for (int i = 0; i < nrBroadcasts; i++) {
        publicationManager.broadcastOccurred(subscriptionId, noFilters, 2 * i + 1);
    }
    Thread.sleep(subscriptionLength);
    verify(dispatcher, times(nrBroadcasts)).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));
    // (eq(subscriptionRequest), eq(proxyId), eq(providerId));
    verifyNoMoreInteractions(dispatcher);
}
Also used : SubscriptionReply(joynr.SubscriptionReply) BroadcastFilterParameters(joynr.BroadcastFilterParameters) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) Matchers.anyString(org.mockito.Matchers.anyString) SubscriptionRequest(joynr.SubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) SubscriptionPublication(joynr.SubscriptionPublication) ProviderDirectory(io.joynr.dispatching.ProviderDirectory) BroadcastFilter(io.joynr.pubsub.publication.BroadcastFilter) joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter(joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter) joynr.tests.testLocationUpdateSelectiveBroadcastFilter(joynr.tests.testLocationUpdateSelectiveBroadcastFilter) Test(org.junit.Test)

Example 15 with SubscriptionRequest

use of joynr.SubscriptionRequest 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)

Aggregations

SubscriptionRequest (joynr.SubscriptionRequest)32 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)24 Test (org.junit.Test)24 MessagingQos (io.joynr.messaging.MessagingQos)23 SubscriptionPublication (joynr.SubscriptionPublication)22 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)19 Matchers.anyString (org.mockito.Matchers.anyString)18 PeriodicSubscriptionQos (joynr.PeriodicSubscriptionQos)8 SubscriptionQos (io.joynr.pubsub.SubscriptionQos)7 BroadcastFilter (io.joynr.pubsub.publication.BroadcastFilter)6 joynr.tests.testLocationUpdateSelectiveBroadcastFilter (joynr.tests.testLocationUpdateSelectiveBroadcastFilter)6 joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter (joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter)6 ProviderDirectory (io.joynr.dispatching.ProviderDirectory)5 MulticastSubscriptionRequest (joynr.MulticastSubscriptionRequest)5 ArrayList (java.util.ArrayList)4 SubscriptionReply (joynr.SubscriptionReply)4 joynr.tests.testBroadcastInterface (joynr.tests.testBroadcastInterface)4 GpsLocation (joynr.types.Localisation.GpsLocation)4 MutableMessage (joynr.MutableMessage)3 OnChangeWithKeepAliveSubscriptionQos (joynr.OnChangeWithKeepAliveSubscriptionQos)3