Search in sources :

Example 36 with OnChangeSubscriptionQos

use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.

the class PublicationManagerTest method addPublicationWithExpiryDate.

@SuppressWarnings("unchecked")
@Test(timeout = 3000)
public void addPublicationWithExpiryDate() throws Exception {
    long pubicationActiveForMs = 300;
    OnChangeSubscriptionQos qos = new OnChangeSubscriptionQos();
    qos.setMinIntervalMs(0);
    qos.setValidityMs(pubicationActiveForMs);
    qos.setPublicationTtlMs(1000);
    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);
    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), any(MessagingQos.class));
    Thread.sleep(pubicationActiveForMs);
    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) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 37 with OnChangeSubscriptionQos

use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.

the class PublicationManagerTest method delayBroadcastPublicationBurstsForOnChangeSubscriptions.

@SuppressWarnings("unchecked")
@Test(timeout = 4000)
public void delayBroadcastPublicationBurstsForOnChangeSubscriptions() throws Exception {
    int subscriptionLength = 500;
    int minIntervalMs = 100;
    OnChangeSubscriptionQos qos = new OnChangeSubscriptionQos();
    qos.setMinIntervalMs(minIntervalMs);
    qos.setValidityMs(subscriptionLength);
    qos.setPublicationTtlMs(400);
    String subscriptionId = "subscriptionId";
    String proxyId = "proxyId";
    String providerId = "providerId";
    String broadcastName = "location";
    ProviderDirectory providerDirectory = mock(ProviderDirectory.class);
    SubscriptionRequest subscriptionRequest = new BroadcastSubscriptionRequest(subscriptionId, broadcastName, new BroadcastFilterParameters(), 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);
    List<BroadcastFilter> noFilters = Lists.newArrayList();
    publicationManager.broadcastOccurred(subscriptionId, noFilters, 0);
    int nrIterations = 10;
    for (int i = 1; i <= nrIterations; i++) {
        publicationManager.broadcastOccurred(subscriptionId, noFilters, i);
    }
    Thread.sleep(minIntervalMs);
    publicationManager.broadcastOccurred(subscriptionId, noFilters, nrIterations + 1);
    verify(dispatcher, times(2)).sendSubscriptionPublication(eq(providerId), (Set<String>) argThat(contains(proxyId)), any(SubscriptionPublication.class), any(MessagingQos.class));
    verify(dispatcher).sendSubscriptionReply(anyString(), anyString(), any(SubscriptionReply.class), any(MessagingQos.class));
    Thread.sleep(subscriptionLength);
    verifyNoMoreInteractions(dispatcher);
    reset(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 38 with OnChangeSubscriptionQos

use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.

the class PublicationManagerTest method delayAttributePublicationBurstsForOnChangeSubscriptions.

@SuppressWarnings("unchecked")
@Test(timeout = 4000)
public void delayAttributePublicationBurstsForOnChangeSubscriptions() throws Exception {
    int subscriptionLength = 500;
    OnChangeSubscriptionQos qos = new OnChangeSubscriptionQos();
    qos.setMinIntervalMs(400);
    qos.setValidityMs(subscriptionLength);
    qos.setPublicationTtlMs(400);
    String subscriptionId = "subscriptionId";
    String proxyId = "proxyId";
    String providerId = "providerId";
    String attributeName = "location";
    ProviderDirectory providerDirectory = 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);
    final Semaphore onReceiveSemaphore = new Semaphore(0);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            onReceiveSemaphore.release();
            return null;
        }
    }).when(dispatcher).sendSubscriptionPublication(eq(providerId), (Set<String>) argThat(contains(proxyId)), any(SubscriptionPublication.class), any(MessagingQos.class));
    publicationManager.addSubscriptionRequest(proxyId, providerId, subscriptionRequest);
    /* a burst of attribute changes only leads to one publication send out */
    for (int i = 0; i < 3; i++) {
        publicationManager.attributeValueChanged(subscriptionId, i);
    }
    assertTrue(onReceiveSemaphore.tryAcquire(2, subscriptionLength + 1000, TimeUnit.MILLISECONDS));
    assertFalse(onReceiveSemaphore.tryAcquire(1, Math.max(subscriptionLength, 200), TimeUnit.MILLISECONDS));
}
Also used : OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) Matchers.anyString(org.mockito.Matchers.anyString) Semaphore(java.util.concurrent.Semaphore) SubscriptionRequest(joynr.SubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SubscriptionPublication(joynr.SubscriptionPublication) ProviderDirectory(io.joynr.dispatching.ProviderDirectory) Test(org.junit.Test)

Example 39 with OnChangeSubscriptionQos

use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.

the class PublicationManagerTest method broadcastPublicationIsSent.

@SuppressWarnings("unchecked")
@Test
public void broadcastPublicationIsSent() throws Exception {
    publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, providerDirectory, cleanupScheduler, Mockito.mock(SubscriptionRequestStorage.class), shutdownNotifier);
    long minInterval_ms = 0;
    long ttl = 1000;
    testBroadcastInterface.LocationUpdateWithSpeedSelectiveBroadcastFilterParameters filterParameters = new testBroadcastInterface.LocationUpdateWithSpeedSelectiveBroadcastFilterParameters();
    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 location = new GpsLocation(1.0, 2.0, 3.0, GpsFixEnum.MODE2D, 4.0, 5.0, 6.0, 7.0, 9l, 10l, 11);
    double speed = 100;
    publicationManager.broadcastOccurred(subscriptionRequest.getSubscriptionId(), new ArrayList<BroadcastFilter>(), location, speed);
    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());
    List<?> response = (List<?>) publicationCaptured.getValue().getResponse();
    assertEquals(location, response.get(0));
    assertEquals(speed, response.get(1));
    assertEquals(ttl, qosCaptured.getValue().getRoundTripTtl_ms());
}
Also used : OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) GpsLocation(joynr.types.Localisation.GpsLocation) 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) List(java.util.List) ArrayList(java.util.ArrayList) BroadcastFilter(io.joynr.pubsub.publication.BroadcastFilter) joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter(joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter) joynr.tests.testLocationUpdateSelectiveBroadcastFilter(joynr.tests.testLocationUpdateSelectiveBroadcastFilter) Test(org.junit.Test)

Example 40 with OnChangeSubscriptionQos

use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.

the class SubscriptionManagerTest method setUp.

@Before
public void setUp() {
    subscriptionManager = new SubscriptionManagerImpl(attributeSubscriptionDirectory, broadcastSubscriptionDirectory, multicastSubscribersDirectory, subscriptionStates, missedPublicationTimers, subscriptionEndFutures, subscriptionAttributeTypes, unicastBroadcastTypes, multicastBroadcastTypes, subscriptionFutureMap, cleanupScheduler, dispatcher, multicastWildcardRegexFactory);
    subscriptionId = "testSubscription";
    attributeName = "testAttribute";
    attributeSubscriptionCallback = new AttributeSubscriptionAdapter<Integer>();
    long minInterval_ms = 100;
    long maxInterval_ms = 5000;
    long subscriptionDuration = 20000;
    long alertInterval_ms = 6000;
    long publicationTtl_ms = 1000;
    qos = new PeriodicSubscriptionQos();
    qos.setPeriodMs(maxInterval_ms);
    qos.setValidityMs(subscriptionDuration);
    qos.setAlertAfterIntervalMs(alertInterval_ms);
    qos.setPublicationTtlMs(publicationTtl_ms);
    onChangeQos = new OnChangeSubscriptionQos();
    onChangeQos.setMinIntervalMs(minInterval_ms);
    onChangeQos.setValidityMs(subscriptionDuration);
    onChangeQos.setPublicationTtlMs(publicationTtl_ms);
    qosWithoutExpiryDate = new PeriodicSubscriptionQos();
    qosWithoutExpiryDate.setPeriodMs(maxInterval_ms);
    qosWithoutExpiryDate.setValidityMs(SubscriptionQos.IGNORE_VALUE);
    qosWithoutExpiryDate.setAlertAfterIntervalMs(alertInterval_ms);
    qosWithoutExpiryDate.setPublicationTtlMs(publicationTtl_ms);
    missedPublicationTimer = new MissedPublicationTimer(System.currentTimeMillis() + subscriptionDuration, maxInterval_ms, alertInterval_ms, attributeSubscriptionCallback, subscriptionState, subscriptionId);
    qosSettings = new MessagingQos();
    fromParticipantId = "fromParticipantId";
    toParticipantId = "toParticipantId";
    toDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
    toDiscoveryEntry.setParticipantId(toParticipantId);
    future = new Future<String>();
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) Matchers.anyString(org.mockito.Matchers.anyString) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) Before(org.junit.Before)

Aggregations

OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)40 Test (org.junit.Test)35 MessagingQos (io.joynr.messaging.MessagingQos)20 SubscriptionPublication (joynr.SubscriptionPublication)18 SubscriptionRequest (joynr.SubscriptionRequest)16 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)15 Matchers.anyString (org.mockito.Matchers.anyString)15 SubscriptionQos (io.joynr.pubsub.SubscriptionQos)9 joynr.tests.testLocationUpdateSelectiveBroadcastFilter (joynr.tests.testLocationUpdateSelectiveBroadcastFilter)8 joynr.tests.testBroadcastInterface (joynr.tests.testBroadcastInterface)7 BroadcastFilter (io.joynr.pubsub.publication.BroadcastFilter)6 joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter (joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter)6 GpsLocation (joynr.types.Localisation.GpsLocation)6 Semaphore (java.util.concurrent.Semaphore)5 OnChangeWithKeepAliveSubscriptionQos (joynr.OnChangeWithKeepAliveSubscriptionQos)5 PeriodicSubscriptionQos (joynr.PeriodicSubscriptionQos)5 Method (java.lang.reflect.Method)4 ArrayList (java.util.ArrayList)4 Ignore (org.junit.Ignore)4 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)3