Search in sources :

Example 6 with BroadcastSubscriptionRequest

use of joynr.BroadcastSubscriptionRequest in project joynr by bmwcarit.

the class MutableMessageFactory method createSubscriptionRequest.

public MutableMessage createSubscriptionRequest(String fromParticipantId, String toParticipantId, SubscriptionRequest subscriptionRequest, MessagingQos messagingQos) {
    String messageType;
    if (subscriptionRequest instanceof BroadcastSubscriptionRequest) {
        messageType = Message.VALUE_MESSAGE_TYPE_BROADCAST_SUBSCRIPTION_REQUEST;
    } else if (subscriptionRequest instanceof MulticastSubscriptionRequest) {
        messageType = Message.VALUE_MESSAGE_TYPE_MULTICAST_SUBSCRIPTION_REQUEST;
    } else {
        messageType = Message.VALUE_MESSAGE_TYPE_SUBSCRIPTION_REQUEST;
    }
    MutableMessage msg = createMessage(messageType, fromParticipantId, toParticipantId, subscriptionRequest, messagingQos);
    addRequestReplyIdCustomHeader(msg, subscriptionRequest.getSubscriptionId());
    return msg;
}
Also used : MutableMessage(joynr.MutableMessage) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest)

Example 7 with BroadcastSubscriptionRequest

use of joynr.BroadcastSubscriptionRequest 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 8 with BroadcastSubscriptionRequest

use of joynr.BroadcastSubscriptionRequest in project joynr by bmwcarit.

the class TtlUpliftTest method testBroadcastSubscriptionWithTtlUplift.

@SuppressWarnings("unchecked")
private void testBroadcastSubscriptionWithTtlUplift(OnChangeSubscriptionQos qos, long sleepDurationMs, long expectedSubscriptionReplyTtl, long expectedPublicationTtlMs) throws InterruptedException {
    final long toleranceMs = 50;
    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);
    publicationManagerWithTtlUplift.addSubscriptionRequest(PROXY_PARTICIPANT_ID, PROVIDER_PARTICIPANT_ID, subscriptionRequest);
    verifySubscriptionReplyTtl(expectedSubscriptionReplyTtl, toleranceMs);
    if (qos.getExpiryDateMs() != SubscriptionQos.NO_EXPIRY_DATE) {
        verifyCleanupSchedulerDelay(expectedSubscriptionReplyTtl, toleranceMs);
    } else {
        verify(cleanupSchedulerSpy, times(0)).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class));
    }
    publicationManagerWithTtlUplift.broadcastOccurred(SUBSCRIPTION_ID, null, valueToPublish);
    Thread.sleep(sleepDurationMs + toleranceMs);
    publicationManagerWithTtlUplift.broadcastOccurred(SUBSCRIPTION_ID, null, valueToPublish);
    // sending 2 times the broadcastOccurred
    verify(dispatcher, times(2)).sendSubscriptionPublication(eq(PROVIDER_PARTICIPANT_ID), (Set<String>) argThat(contains(PROXY_PARTICIPANT_ID)), any(SubscriptionPublication.class), argThat(new MessagingQosMatcher(expectedPublicationTtlMs)));
    Thread.sleep(SUBSCRIPTION_UPLIFT_MS);
    reset(dispatcher);
}
Also used : SubscriptionRequest(joynr.SubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) SubscriptionPublication(joynr.SubscriptionPublication) TimeUnit(java.util.concurrent.TimeUnit)

Example 9 with BroadcastSubscriptionRequest

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

Example 10 with BroadcastSubscriptionRequest

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

Aggregations

BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)11 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)8 SubscriptionPublication (joynr.SubscriptionPublication)8 SubscriptionRequest (joynr.SubscriptionRequest)8 Test (org.junit.Test)8 MessagingQos (io.joynr.messaging.MessagingQos)7 BroadcastFilter (io.joynr.pubsub.publication.BroadcastFilter)7 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)5 ArrayList (java.util.ArrayList)4 GpsLocation (joynr.types.Localisation.GpsLocation)4 BroadcastFilterParameters (joynr.BroadcastFilterParameters)3 ProviderDirectory (io.joynr.dispatching.ProviderDirectory)2 List (java.util.List)2 SubscriptionReply (joynr.SubscriptionReply)2 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 JoynrException (io.joynr.exceptions.JoynrException)1