Search in sources :

Example 1 with BroadcastFilter

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

the class PublicationManagerTest method broadcastPublicationNotSentWhenFiltersFail.

@SuppressWarnings("unchecked")
@Test
public void broadcastPublicationNotSentWhenFiltersFail() 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();
    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 filterTrue = mock(testLocationUpdateSelectiveBroadcastFilter.class);
    when(filterTrue.filter(any(GpsLocation.class), any(testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters.class))).thenReturn(true);
    filters.add(filterTrue);
    testLocationUpdateSelectiveBroadcastFilter filterFalse = mock(testLocationUpdateSelectiveBroadcastFilter.class);
    when(filterFalse.filter(any(GpsLocation.class), any(testBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters.class))).thenReturn(false);
    filters.add(filterFalse);
    publicationManager.broadcastOccurred(subscriptionRequest.getSubscriptionId(), filters, eventValue);
    verify(dispatcher, never()).sendSubscriptionPublication(any(String.class), any(Set.class), any(SubscriptionPublication.class), any(MessagingQos.class));
}
Also used : Set(java.util.Set) 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 2 with BroadcastFilter

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

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

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

the class PublicationManagerImpl method processFilterChain.

private boolean processFilterChain(PublicationInformation publicationInformation, List<BroadcastFilter> filters, Object[] values) {
    if (filters != null && filters.size() > 0) {
        BroadcastSubscriptionRequest subscriptionRequest = (BroadcastSubscriptionRequest) publicationInformation.subscriptionRequest;
        BroadcastFilterParameters filterParameters = subscriptionRequest.getFilterParameters();
        for (BroadcastFilter filter : filters) {
            Method filterMethod = null;
            try {
                Method[] methodsOfFilterClass = filter.getClass().getMethods();
                for (Method method : methodsOfFilterClass) {
                    if (method.getName().equals("filter")) {
                        filterMethod = method;
                        break;
                    }
                }
                if (filterMethod == null) {
                    // no filtering
                    return true;
                }
                if (!filterMethod.isAccessible()) {
                    filterMethod.setAccessible(true);
                }
                Class<?> filterParametersType = filterMethod.getParameterTypes()[values.length];
                BroadcastFilterParameters filterParametersDerived = (BroadcastFilterParameters) filterParametersType.newInstance();
                filterParametersDerived.setFilterParameters(filterParameters.getFilterParameters());
                Object[] args = Arrays.copyOf(values, values.length + 1);
                args[args.length - 1] = filterParametersDerived;
                if ((Boolean) filterMethod.invoke(filter, args) == false) {
                    return false;
                }
            } catch (Exception e) {
                logger.error("processFilterChain error: {}", e.getMessage());
                throw new IllegalStateException("processFilterChain: Error in reflection calling filters.", e);
            }
        }
    }
    return true;
}
Also used : BroadcastFilterParameters(joynr.BroadcastFilterParameters) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) Method(java.lang.reflect.Method) BroadcastFilter(io.joynr.pubsub.publication.BroadcastFilter) JoynrException(io.joynr.exceptions.JoynrException) SubscriptionException(io.joynr.exceptions.SubscriptionException) JoynrSendBufferFullException(io.joynr.exceptions.JoynrSendBufferFullException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JoynrMessageNotSentException(io.joynr.exceptions.JoynrMessageNotSentException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) IOException(java.io.IOException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Example 5 with BroadcastFilter

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

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