Search in sources :

Example 6 with SubscriptionRequest

use of joynr.SubscriptionRequest in project joynr by bmwcarit.

the class TtlUpliftTest method testBroadcastSubscriptionWithoutTtlUplift.

@SuppressWarnings("unchecked")
@Test(timeout = 3000)
public void testBroadcastSubscriptionWithoutTtlUplift() throws Exception {
    long validityMs = 300;
    long toleranceMs = 50;
    long publicationTtlMs = 1000;
    OnChangeSubscriptionQos qos = new OnChangeSubscriptionQos();
    qos.setMinIntervalMs(0);
    qos.setValidityMs(validityMs);
    qos.setPublicationTtlMs(publicationTtlMs);
    SubscriptionRequest subscriptionRequest = new BroadcastSubscriptionRequest(SUBSCRIPTION_ID, "location", null, 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);
    verifySubscriptionReplyTtl(validityMs, toleranceMs);
    verifyCleanupSchedulerDelay(validityMs, toleranceMs);
    publicationManager.broadcastOccurred(SUBSCRIPTION_ID, null, valueToPublish);
    // sending the broadcastOccurred
    verify(dispatcher, times(1)).sendSubscriptionPublication(eq(PROVIDER_PARTICIPANT_ID), (Set<String>) argThat(contains(PROXY_PARTICIPANT_ID)), any(SubscriptionPublication.class), argThat(new MessagingQosMatcher(publicationTtlMs)));
    Thread.sleep(validityMs + toleranceMs);
    reset(dispatcher);
    publicationManager.broadcastOccurred(SUBSCRIPTION_ID, null, 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) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) SubscriptionPublication(joynr.SubscriptionPublication) Test(org.junit.Test)

Example 7 with SubscriptionRequest

use of joynr.SubscriptionRequest in project joynr by bmwcarit.

the class TtlUpliftTest method testAttributeSubscriptionWithoutTtlUplift.

@SuppressWarnings("unchecked")
@Test(timeout = 3000)
public void testAttributeSubscriptionWithoutTtlUplift() throws Exception {
    long validityMs = 300;
    long publicationTtlMs = 1000;
    long toleranceMs = 50;
    OnChangeSubscriptionQos qos = new OnChangeSubscriptionQos();
    qos.setMinIntervalMs(0);
    qos.setValidityMs(validityMs);
    qos.setPublicationTtlMs(publicationTtlMs);
    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);
    verifySubscriptionReplyTtl(validityMs, toleranceMs);
    verifyCleanupSchedulerDelay(validityMs, toleranceMs);
    publicationManager.attributeValueChanged(SUBSCRIPTION_ID, valueToPublish);
    // sending initial value plus the attributeValueChanged
    verify(dispatcher, times(2)).sendSubscriptionPublication(eq(PROVIDER_PARTICIPANT_ID), (Set<String>) argThat(contains(PROXY_PARTICIPANT_ID)), any(SubscriptionPublication.class), argThat(new MessagingQosMatcher(publicationTtlMs)));
    Thread.sleep(validityMs + toleranceMs);
    reset(dispatcher);
    publicationManager.attributeValueChanged(SUBSCRIPTION_ID, 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) Test(org.junit.Test)

Example 8 with SubscriptionRequest

use of joynr.SubscriptionRequest in project joynr by bmwcarit.

the class PublicationManagerTest method broadcastPublicationNotSentWhenFiltersFail.

@SuppressWarnings("unchecked")
@Test
public void broadcastPublicationNotSentWhenFiltersFail() throws Exception {
    publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, providerDirectory, cleanupScheduler, Mockito.mock(SubscriptionRequestStorage.class), shutdownNotifier);
    long minInterval_ms = 0;
    long ttl = 1000;
    testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters filterParameters = new testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters();
    OnChangeSubscriptionQos qos = new OnChangeSubscriptionQos().setMinIntervalMs(minInterval_ms).setExpiryDateMs(SubscriptionQos.NO_EXPIRY_DATE).setPublicationTtlMs(ttl);
    SubscriptionRequest subscriptionRequest = new BroadcastSubscriptionRequest(SUBSCRIPTION_ID, "subscribedToName", filterParameters, 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);
    GpsLocation eventValue = new GpsLocation();
    ArrayList<BroadcastFilter> filters = new ArrayList<BroadcastFilter>();
    testLocationUpdateSelectiveBroadcastFilter filterTrue = mock(testLocationUpdateSelectiveBroadcastFilter.class);
    when(filterTrue.filter(any(GpsLocation.class), any(testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters.class))).thenReturn(true);
    filters.add(filterTrue);
    testLocationUpdateSelectiveBroadcastFilter filterFalse = mock(testLocationUpdateSelectiveBroadcastFilter.class);
    when(filterFalse.filter(any(GpsLocation.class), any(testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters.class))).thenReturn(false);
    filters.add(filterFalse);
    publicationManager.broadcastOccurred(subscriptionRequest.getSubscriptionId(), filters, eventValue);
    verify(dispatcher, never()).sendSubscriptionPublication(any(String.class), any(Set.class), any(SubscriptionPublication.class), any(MessagingQos.class));
}
Also used : Set(java.util.Set) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) ArrayList(java.util.ArrayList) GpsLocation(joynr.types.Localisation.GpsLocation) joynr.tests.testLocationUpdateSelectiveBroadcastFilter(joynr.tests.testLocationUpdateSelectiveBroadcastFilter) Matchers.anyString(org.mockito.Matchers.anyString) joynr.tests.testBroadcastInterface(joynr.tests.testBroadcastInterface) SubscriptionRequest(joynr.SubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) SubscriptionPublication(joynr.SubscriptionPublication) BroadcastFilter(io.joynr.pubsub.publication.BroadcastFilter) joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter(joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter) joynr.tests.testLocationUpdateSelectiveBroadcastFilter(joynr.tests.testLocationUpdateSelectiveBroadcastFilter) Test(org.junit.Test)

Example 9 with SubscriptionRequest

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

Example 10 with SubscriptionRequest

use of joynr.SubscriptionRequest in project joynr by bmwcarit.

the class PublicationManagerTest method broadcastPublicationCallsAllFiltersWithFilterParametersAndValues.

@SuppressWarnings("unchecked")
@Test
public void broadcastPublicationCallsAllFiltersWithFilterParametersAndValues() throws Exception {
    publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, providerDirectory, cleanupScheduler, Mockito.mock(SubscriptionRequestStorage.class), shutdownNotifier);
    long minInterval_ms = 0;
    long ttl = 1000;
    testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters filterParameters = new testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters();
    filterParameters.setCountry("Germany");
    filterParameters.setStartTime("4:00");
    OnChangeSubscriptionQos qos = new OnChangeSubscriptionQos().setMinIntervalMs(minInterval_ms).setExpiryDateMs(SubscriptionQos.NO_EXPIRY_DATE).setPublicationTtlMs(ttl);
    SubscriptionRequest subscriptionRequest = new BroadcastSubscriptionRequest(SUBSCRIPTION_ID, "subscribedToName", filterParameters, 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);
    GpsLocation eventValue = new GpsLocation();
    ArrayList<BroadcastFilter> filters = new ArrayList<BroadcastFilter>();
    testLocationUpdateSelectiveBroadcastFilter filter1 = mock(testLocationUpdateSelectiveBroadcastFilter.class);
    when(filter1.filter(any(GpsLocation.class), any(testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters.class))).thenReturn(true);
    filters.add(filter1);
    testLocationUpdateSelectiveBroadcastFilter filter2 = mock(testLocationUpdateSelectiveBroadcastFilter.class);
    when(filter2.filter(any(GpsLocation.class), any(testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters.class))).thenReturn(true);
    filters.add(filter2);
    publicationManager.broadcastOccurred(subscriptionRequest.getSubscriptionId(), filters, eventValue);
    ArgumentCaptor<SubscriptionPublication> publicationCaptured = ArgumentCaptor.forClass(SubscriptionPublication.class);
    ArgumentCaptor<MessagingQos> qosCaptured = ArgumentCaptor.forClass(MessagingQos.class);
    verify(dispatcher).sendSubscriptionPublication(eq(PROVIDER_PARTICIPANT_ID), (Set<String>) argThat(contains(PROXY_PARTICIPANT_ID)), publicationCaptured.capture(), qosCaptured.capture());
    verify(filter1).filter(eventValue, filterParameters);
    verify(filter2).filter(eventValue, filterParameters);
}
Also used : OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) ArrayList(java.util.ArrayList) GpsLocation(joynr.types.Localisation.GpsLocation) joynr.tests.testLocationUpdateSelectiveBroadcastFilter(joynr.tests.testLocationUpdateSelectiveBroadcastFilter) Matchers.anyString(org.mockito.Matchers.anyString) joynr.tests.testBroadcastInterface(joynr.tests.testBroadcastInterface) SubscriptionRequest(joynr.SubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) SubscriptionPublication(joynr.SubscriptionPublication) BroadcastFilter(io.joynr.pubsub.publication.BroadcastFilter) joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter(joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter) joynr.tests.testLocationUpdateSelectiveBroadcastFilter(joynr.tests.testLocationUpdateSelectiveBroadcastFilter) 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