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);
}
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;
}
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);
}
}
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);
}
Aggregations