Search in sources :

Example 31 with OnChangeSubscriptionQos

use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.

the class SerializationTest method serializeBroadcastSubscriptionRequest.

@Test
public void serializeBroadcastSubscriptionRequest() throws JsonGenerationException, JsonMappingException, IOException {
    String subscriptionId = "1234";
    String subscribedToName = "myEvent";
    testBroadcastInterface.LocationUpdateWithSpeedSelectiveBroadcastFilterParameters filterParameters = new testBroadcastInterface.LocationUpdateWithSpeedSelectiveBroadcastFilterParameters();
    filterParameters.setCountry("Germany");
    filterParameters.setStartTime("4:00");
    OnChangeSubscriptionQos qos = new OnChangeSubscriptionQos().setMinIntervalMs(0).setValidityMs(60000).setPublicationTtlMs(1000);
    BroadcastSubscriptionRequest broadcastSubscription = new BroadcastSubscriptionRequest(subscriptionId, subscribedToName, filterParameters, qos);
    String writeValueAsString = objectMapper.writeValueAsString(broadcastSubscription);
    System.out.println(writeValueAsString);
    BroadcastSubscriptionRequest receivedbroadcastSubscription = objectMapper.readValue(writeValueAsString, BroadcastSubscriptionRequest.class);
    Assert.assertEquals(broadcastSubscription, receivedbroadcastSubscription);
}
Also used : OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) joynr.tests.testBroadcastInterface(joynr.tests.testBroadcastInterface) Test(org.junit.Test)

Example 32 with OnChangeSubscriptionQos

use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.

the class AbstractBroadcastEnd2EndTest method subscribeToSelectiveBroadcast_FilterTrue.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void subscribeToSelectiveBroadcast_FilterTrue() throws InterruptedException {
    final Semaphore broadcastReceived = new Semaphore(0);
    final LocationUpdateSelectiveBroadcastFilterParameters testFilterParameters = new LocationUpdateSelectiveBroadcastFilterParameters();
    testFilterParameters.setCountry("Germany");
    testFilterParameters.setStartTime("4.00 pm");
    testLocationUpdateSelectiveBroadcastFilter filter1 = new testLocationUpdateSelectiveBroadcastFilter() {

        @Override
        public boolean filter(GpsLocation location, LocationUpdateSelectiveBroadcastFilterParameters filterParameters) {
            assertEquals(testFilterParameters, filterParameters);
            return true;
        }
    };
    testLocationUpdateSelectiveBroadcastFilter filter2 = new testLocationUpdateSelectiveBroadcastFilter() {

        @Override
        public boolean filter(GpsLocation location, LocationUpdateSelectiveBroadcastFilterParameters filterParameters) {
            assertEquals(testFilterParameters, filterParameters);
            return true;
        }
    };
    getSubscriptionTestsPublisher().addBroadcastFilter(filter1);
    getSubscriptionTestsPublisher().addBroadcastFilter(filter2);
    OnChangeSubscriptionQos subscriptionQos = createDefaultOnChangeSubscriptionQos();
    proxy.subscribeToLocationUpdateSelectiveBroadcast(new testBroadcastInterface.LocationUpdateSelectiveBroadcastAdapter() {

        @Override
        public void onReceive(GpsLocation location) {
            assertEquals(expectedLocation, location);
            broadcastReceived.release();
        }
    }, subscriptionQos, testFilterParameters);
    Thread.sleep(300);
    provider.fireLocationUpdateSelective(expectedLocation);
    broadcastReceived.acquire();
}
Also used : OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) GpsLocation(joynr.types.Localisation.GpsLocation) LocationUpdateSelectiveBroadcastFilterParameters(joynr.tests.testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters) joynr.tests.testLocationUpdateSelectiveBroadcastFilter(joynr.tests.testLocationUpdateSelectiveBroadcastFilter) Semaphore(java.util.concurrent.Semaphore) joynr.tests.testBroadcastInterface(joynr.tests.testBroadcastInterface) Test(org.junit.Test)

Example 33 with OnChangeSubscriptionQos

use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.

the class AbstractLocalCommunicationTest method registerSubscriptionOnChangeAndReceiveUpdatesForLongTime.

/* This is a manual test that subscribes for 30 seconds, and checks if all subscriptions arrive. In this case,
     * the test expect publication in case of value change
     */
@Test
@Ignore
public void registerSubscriptionOnChangeAndReceiveUpdatesForLongTime() throws InterruptedException {
    final int times = 5;
    final int initialValue = 42;
    int period = lengthInMS / times;
    provider.ATTRIBUTEWITHCAPITALLETTERSChanged(initialValue);
    OnChangeSubscriptionQos subscriptionQos = new OnChangeSubscriptionQos();
    subscriptionQos.setMinIntervalMs(lengthInMS / 4).setValidityMs(lengthInMS).setPublicationTtlMs(lengthInMS / 4);
    new Timer().scheduleAtFixedRate(new TimerTask() {

        int value = initialValue;

        @Override
        public void run() {
            value++;
            if (value < initialValue + times) {
                provider.ATTRIBUTEWITHCAPITALLETTERSChanged(value);
            }
        }
    }, period, period);
    proxy.subscribeToATTRIBUTEWITHCAPITALLETTERS(listener, subscriptionQos);
    // - (System.currentTimeMillis() - currentTime));
    Thread.sleep(lengthInMS + 100);
    verify(listener, times(0)).onError(null);
    verify(listener, times(times)).onReceive(anyInt());
    // TODO verify publications shipped correct data
    for (int i = 42; i < 42 + times; i++) {
        verify(listener, times(1)).onReceive(eq(i));
    }
    verifyNoMoreInteractions(listener);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 34 with OnChangeSubscriptionQos

use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.

the class TtlUpliftTest method testAttributeSubscriptionWithTtlUpliftWithLargeExpiryDate.

@SuppressWarnings("unchecked")
@Test(timeout = 3000)
public void testAttributeSubscriptionWithTtlUpliftWithLargeExpiryDate() throws Exception {
    long validityMs = 300;
    long publicationTtlMs = 1000;
    OnChangeSubscriptionQos qos = new OnChangeSubscriptionQos();
    qos.setMinIntervalMs(0);
    qos.setExpiryDateMs(LARGE_EXPIRY_DATE_MS - SUBSCRIPTION_UPLIFT_MS + 1);
    qos.setPublicationTtlMs(publicationTtlMs);
    long expectedSubscriptionReplyTtl = qos.getExpiryDateMs() - System.currentTimeMillis();
    long expectedPublicationTtlMs = publicationTtlMs;
    testAttributeSubscriptionWithTtlUplift(qos, validityMs, expectedSubscriptionReplyTtl, expectedPublicationTtlMs);
    publicationManagerWithTtlUplift.attributeValueChanged(SUBSCRIPTION_ID, valueToPublish);
    verify(dispatcher, timeout(300).times(1)).sendSubscriptionPublication(eq(PROVIDER_PARTICIPANT_ID), (Set<String>) argThat(contains(PROXY_PARTICIPANT_ID)), any(SubscriptionPublication.class), argThat(new MessagingQosMatcher(expectedPublicationTtlMs)));
}
Also used : OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) SubscriptionPublication(joynr.SubscriptionPublication) Test(org.junit.Test)

Example 35 with OnChangeSubscriptionQos

use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.

the class PublicationManagerTest method broadcastPublicationIsSentWhenFiltersPass.

@SuppressWarnings("unchecked")
@Test
public void broadcastPublicationIsSentWhenFiltersPass() 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);
    float speed = 100;
    ArrayList<BroadcastFilter> filters = new ArrayList<BroadcastFilter>();
    testLocationUpdateWithSpeedSelectiveBroadcastFilter filterTrue = mock(testLocationUpdateWithSpeedSelectiveBroadcastFilter.class);
    when(filterTrue.filter(any(GpsLocation.class), any(Float.class), any(testBroadcastInterface.LocationUpdateWithSpeedSelectiveBroadcastFilterParameters.class))).thenReturn(true);
    filters.add(filterTrue);
    publicationManager.broadcastOccurred(subscriptionRequest.getSubscriptionId(), filters, 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));
}
Also used : OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) ArrayList(java.util.ArrayList) GpsLocation(joynr.types.Localisation.GpsLocation) joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter(joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter) 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)

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