Search in sources :

Example 1 with BroadcastFilterParameters

use of joynr.BroadcastFilterParameters 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 2 with BroadcastFilterParameters

use of joynr.BroadcastFilterParameters 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 3 with BroadcastFilterParameters

use of joynr.BroadcastFilterParameters in project joynr by bmwcarit.

the class ConnectorTest method subscribeToBroadcastCallCallsSubscriptionManagerWithCorrectArguments.

@Test
public void subscribeToBroadcastCallCallsSubscriptionManagerWithCorrectArguments() {
    TestBroadcastListener listener = new TestBroadcastInterface.TestBroadcastAdapter();
    OnChangeSubscriptionQos subscriptionQos = new OnChangeSubscriptionQos();
    ConnectorInvocationHandler connector = createConnector();
    assertNotNull(connector);
    try {
        Method method = TestBroadcastInterface.class.getDeclaredMethod("subscribeToTestBroadcast", TestBroadcastListener.class, OnChangeSubscriptionQos.class, BroadcastFilterParameters.class);
        BroadcastSubscribeInvocation invocation = new BroadcastSubscribeInvocation(method, new Object[] { listener, subscriptionQos, new BroadcastFilterParameters() }, null);
        connector.executeSubscriptionMethod(invocation);
        verify(subscriptionManager, times(1)).registerBroadcastSubscription(fromParticipantId, toDiscoveryEntries, invocation);
    } catch (Exception e) {
        fail("Unexpected exception from broadcast subscribe call: " + e);
    }
}
Also used : BroadcastFilterParameters(joynr.BroadcastFilterParameters) BroadcastSubscribeInvocation(io.joynr.proxy.invocation.BroadcastSubscribeInvocation) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) TestBroadcastListener(io.joynr.proxy.ConnectorTest.TestBroadcastInterface.TestBroadcastListener) Method(java.lang.reflect.Method) SubscriptionException(io.joynr.exceptions.SubscriptionException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) Test(org.junit.Test)

Example 4 with BroadcastFilterParameters

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

BroadcastFilterParameters (joynr.BroadcastFilterParameters)4 BroadcastFilter (io.joynr.pubsub.publication.BroadcastFilter)3 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)3 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)3 Test (org.junit.Test)3 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 ProviderDirectory (io.joynr.dispatching.ProviderDirectory)2 SubscriptionException (io.joynr.exceptions.SubscriptionException)2 MessagingQos (io.joynr.messaging.MessagingQos)2 Method (java.lang.reflect.Method)2 SubscriptionPublication (joynr.SubscriptionPublication)2 SubscriptionReply (joynr.SubscriptionReply)2 SubscriptionRequest (joynr.SubscriptionRequest)2 joynr.tests.testLocationUpdateSelectiveBroadcastFilter (joynr.tests.testLocationUpdateSelectiveBroadcastFilter)2 joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter (joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter)2 Matchers.anyString (org.mockito.Matchers.anyString)2 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1 JoynrException (io.joynr.exceptions.JoynrException)1 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)1 JoynrMessageNotSentException (io.joynr.exceptions.JoynrMessageNotSentException)1