Search in sources :

Example 6 with BroadcastFilter

use of io.joynr.pubsub.publication.BroadcastFilter 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 7 with BroadcastFilter

use of io.joynr.pubsub.publication.BroadcastFilter 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 8 with BroadcastFilter

use of io.joynr.pubsub.publication.BroadcastFilter in project joynr by bmwcarit.

the class SubscriptionPublisherTest method unregisteredBroadcastListenerNotCalledOnBroadcast.

@Test
public void unregisteredBroadcastListenerNotCalledOnBroadcast() throws Exception {
    String broadcastName = "mybroadcast";
    String value1 = "value1";
    String value2 = "value2";
    MySubscriptionPublisher subscriptionPublisher = new MySubscriptionPublisher();
    BroadcastListener broadcastListener = mock(BroadcastListener.class);
    subscriptionPublisher.registerBroadcastListener(broadcastName, broadcastListener);
    subscriptionPublisher.unregisterBroadcastListener(broadcastName, broadcastListener);
    List<BroadcastFilter> broadcastFilters = new ArrayList<BroadcastFilter>();
    BroadcastFilter broadcastFilter = mock(BroadcastFilter.class);
    broadcastFilters.add(broadcastFilter);
    subscriptionPublisher.fireBroadcast(broadcastName, broadcastFilters, value1, value2);
    verify(broadcastListener, never()).broadcastOccurred(eq(broadcastFilters), eq(value1), eq(value2));
}
Also used : BroadcastListener(io.joynr.pubsub.publication.BroadcastListener) ArrayList(java.util.ArrayList) BroadcastFilter(io.joynr.pubsub.publication.BroadcastFilter) Test(org.junit.Test)

Example 9 with BroadcastFilter

use of io.joynr.pubsub.publication.BroadcastFilter in project joynr by bmwcarit.

the class SubscriptionPublisherTest method registeredBroadcastListenerIsCalledOnBroadcast.

@Test
public void registeredBroadcastListenerIsCalledOnBroadcast() throws Exception {
    String broadcastName = "mybroadcast";
    String value1 = "value1";
    String value2 = "value2";
    MySubscriptionPublisher subscriptionPublisher = new MySubscriptionPublisher();
    BroadcastListener broadcastListener = mock(BroadcastListener.class);
    subscriptionPublisher.registerBroadcastListener(broadcastName, broadcastListener);
    List<BroadcastFilter> broadcastFilters = new ArrayList<BroadcastFilter>();
    BroadcastFilter broadcastFilter = mock(BroadcastFilter.class);
    broadcastFilters.add(broadcastFilter);
    subscriptionPublisher.fireBroadcast(broadcastName, broadcastFilters, value1, value2);
    verify(broadcastListener).broadcastOccurred(eq(broadcastFilters), eq(value1), eq(value2));
}
Also used : BroadcastListener(io.joynr.pubsub.publication.BroadcastListener) ArrayList(java.util.ArrayList) BroadcastFilter(io.joynr.pubsub.publication.BroadcastFilter) Test(org.junit.Test)

Aggregations

BroadcastFilter (io.joynr.pubsub.publication.BroadcastFilter)9 Test (org.junit.Test)8 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)7 MessagingQos (io.joynr.messaging.MessagingQos)6 ArrayList (java.util.ArrayList)6 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)6 SubscriptionPublication (joynr.SubscriptionPublication)6 SubscriptionRequest (joynr.SubscriptionRequest)6 joynr.tests.testLocationUpdateSelectiveBroadcastFilter (joynr.tests.testLocationUpdateSelectiveBroadcastFilter)6 joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter (joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter)6 Matchers.anyString (org.mockito.Matchers.anyString)6 joynr.tests.testBroadcastInterface (joynr.tests.testBroadcastInterface)4 GpsLocation (joynr.types.Localisation.GpsLocation)4 BroadcastFilterParameters (joynr.BroadcastFilterParameters)3 ProviderDirectory (io.joynr.dispatching.ProviderDirectory)2 BroadcastListener (io.joynr.pubsub.publication.BroadcastListener)2 List (java.util.List)2 SubscriptionReply (joynr.SubscriptionReply)2 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1