Search in sources :

Example 1 with SubscriptionPublication

use of joynr.SubscriptionPublication in project joynr by bmwcarit.

the class PublicationManagerImpl method sendPublicationError.

private void sendPublicationError(JoynrRuntimeException error, PublicationInformation publicationInformation) {
    SubscriptionPublication publication = new SubscriptionPublication(error, publicationInformation.getSubscriptionId());
    sendPublication(publication, publicationInformation);
}
Also used : SubscriptionPublication(joynr.SubscriptionPublication)

Example 2 with SubscriptionPublication

use of joynr.SubscriptionPublication in project joynr by bmwcarit.

the class SerializationTest method serializePublication.

@Test
public void serializePublication() throws JsonGenerationException, JsonMappingException, IOException {
    Object response = new GpsPosition(49.0065, 11.65);
    String subscriptionId = "1234";
    SubscriptionPublication publication = new SubscriptionPublication(Arrays.asList(response), subscriptionId);
    String writeValueAsString = objectMapper.writeValueAsString(publication);
    SubscriptionPublication receivedPublication = objectMapper.readValue(writeValueAsString, SubscriptionPublication.class);
    Assert.assertEquals(publication, receivedPublication);
}
Also used : SubscriptionPublication(joynr.SubscriptionPublication) GpsPosition(joynr.types.Localisation.GpsPosition) Test(org.junit.Test)

Example 3 with SubscriptionPublication

use of joynr.SubscriptionPublication in project joynr by bmwcarit.

the class TtlUpliftTest method testTtlUpliftMs_Publication.

@Test
public void testTtlUpliftMs_Publication() {
    SubscriptionPublication subscriptionPublication = new SubscriptionPublication();
    expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
    MutableMessage message = messageFactoryWithTtlUplift.createPublication(fromParticipantId, toParticipantId, subscriptionPublication, messagingQos);
    long expiryDateValue = expiryDate.getValue() + TTL_UPLIFT_MS;
    MutableMessageFactoryTest.assertExpiryDateEquals(expiryDateValue, message);
}
Also used : MutableMessage(joynr.MutableMessage) SubscriptionPublication(joynr.SubscriptionPublication) Test(org.junit.Test)

Example 4 with SubscriptionPublication

use of joynr.SubscriptionPublication in project joynr by bmwcarit.

the class PublicationManagerTest method broadcastPublicationCallsAllFiltersWithFilterParametersAndValues.

@SuppressWarnings("unchecked")
@Test
public void broadcastPublicationCallsAllFiltersWithFilterParametersAndValues() throws Exception {
    publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, providerDirectory, cleanupScheduler, Mockito.mock(SubscriptionRequestStorage.class), shutdownNotifier);
    long minInterval_ms = 0;
    long ttl = 1000;
    testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters filterParameters = new testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters();
    filterParameters.setCountry("Germany");
    filterParameters.setStartTime("4:00");
    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 eventValue = new GpsLocation();
    ArrayList<BroadcastFilter> filters = new ArrayList<BroadcastFilter>();
    testLocationUpdateSelectiveBroadcastFilter filter1 = mock(testLocationUpdateSelectiveBroadcastFilter.class);
    when(filter1.filter(any(GpsLocation.class), any(testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters.class))).thenReturn(true);
    filters.add(filter1);
    testLocationUpdateSelectiveBroadcastFilter filter2 = mock(testLocationUpdateSelectiveBroadcastFilter.class);
    when(filter2.filter(any(GpsLocation.class), any(testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters.class))).thenReturn(true);
    filters.add(filter2);
    publicationManager.broadcastOccurred(subscriptionRequest.getSubscriptionId(), filters, eventValue);
    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());
    verify(filter1).filter(eventValue, filterParameters);
    verify(filter2).filter(eventValue, filterParameters);
}
Also used : OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) ArrayList(java.util.ArrayList) GpsLocation(joynr.types.Localisation.GpsLocation) joynr.tests.testLocationUpdateSelectiveBroadcastFilter(joynr.tests.testLocationUpdateSelectiveBroadcastFilter) 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) 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 SubscriptionPublication

use of joynr.SubscriptionPublication in project joynr by bmwcarit.

the class PublicationManagerImpl method attributeValueChanged.

@Override
public void attributeValueChanged(String subscriptionId, Object value) {
    if (subscriptionId2PublicationInformation.containsKey(subscriptionId)) {
        PublicationInformation publicationInformation = subscriptionId2PublicationInformation.get(subscriptionId);
        if (isExpired(publicationInformation)) {
            removePublication(subscriptionId);
        } else {
            PublicationTimer publicationTimer = publicationTimers.get(subscriptionId);
            SubscriptionPublication publication = prepareAttributePublication(value, subscriptionId);
            if (publicationTimer != null) {
                // used by OnChangedWithKeepAlive
                publicationTimer.sendPublicationNow(publication);
            } else {
                sendPublication(publication, publicationInformation);
            }
            logger.trace("attribute changed for subscription id: {} sending publication if delay > minInterval.", subscriptionId);
        }
    } else {
        logger.trace("subscription {} has expired but attributeValueChanged has been called", subscriptionId);
    }
}
Also used : SubscriptionPublication(joynr.SubscriptionPublication)

Aggregations

SubscriptionPublication (joynr.SubscriptionPublication)12 Test (org.junit.Test)6 SubscriptionRequest (joynr.SubscriptionRequest)5 MessagingQos (io.joynr.messaging.MessagingQos)4 BroadcastFilter (io.joynr.pubsub.publication.BroadcastFilter)3 ArrayList (java.util.ArrayList)3 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)3 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)3 joynr.tests.testBroadcastInterface (joynr.tests.testBroadcastInterface)3 joynr.tests.testLocationUpdateSelectiveBroadcastFilter (joynr.tests.testLocationUpdateSelectiveBroadcastFilter)3 joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter (joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter)3 GpsLocation (joynr.types.Localisation.GpsLocation)3 Matchers.anyString (org.mockito.Matchers.anyString)3 List (java.util.List)2 MulticastSubscriptionRequest (joynr.MulticastSubscriptionRequest)2 MutableMessage (joynr.MutableMessage)2 Reply (joynr.Reply)2 Request (joynr.Request)2 Before (org.junit.Before)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1