Search in sources :

Example 1 with ProviderDirectory

use of io.joynr.dispatching.ProviderDirectory 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 2 with ProviderDirectory

use of io.joynr.dispatching.ProviderDirectory 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 3 with ProviderDirectory

use of io.joynr.dispatching.ProviderDirectory 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)

Example 4 with ProviderDirectory

use of io.joynr.dispatching.ProviderDirectory 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 5 with ProviderDirectory

use of io.joynr.dispatching.ProviderDirectory 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)

Aggregations

ProviderDirectory (io.joynr.dispatching.ProviderDirectory)5 MessagingQos (io.joynr.messaging.MessagingQos)5 SubscriptionPublication (joynr.SubscriptionPublication)5 SubscriptionRequest (joynr.SubscriptionRequest)5 Test (org.junit.Test)5 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)4 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)4 Matchers.anyString (org.mockito.Matchers.anyString)4 SubscriptionReply (joynr.SubscriptionReply)3 BroadcastFilter (io.joynr.pubsub.publication.BroadcastFilter)2 BroadcastFilterParameters (joynr.BroadcastFilterParameters)2 PeriodicSubscriptionQos (joynr.PeriodicSubscriptionQos)2 joynr.tests.testLocationUpdateSelectiveBroadcastFilter (joynr.tests.testLocationUpdateSelectiveBroadcastFilter)2 joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter (joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter)2 SubscriptionQos (io.joynr.pubsub.SubscriptionQos)1 File (java.io.File)1 Set (java.util.Set)1 Semaphore (java.util.concurrent.Semaphore)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1