use of io.joynr.proxy.invocation.MulticastSubscribeInvocation in project joynr by bmwcarit.
the class ProxyInvocationHandlerImpl method executeMulticastSubscriptionMethod.
private void executeMulticastSubscriptionMethod(Method method, Object[] args, Future<String> future) {
final MulticastSubscribeInvocation multicastSubscription = new MulticastSubscribeInvocation(method, args, future);
queueOrExecuteSubscriptionInvocation(multicastSubscription, new SubscriptionAction(future) {
@Override
public void subscribe() {
connector.executeSubscriptionMethod(multicastSubscription);
}
});
}
use of io.joynr.proxy.invocation.MulticastSubscribeInvocation in project joynr by bmwcarit.
the class ProxyInvocationHandlerTest method testPartitionsPassedToMulticastSubscription.
@Test
public void testPartitionsPassedToMulticastSubscription() throws NoSuchMethodException, ApplicationException {
ConnectorInvocationHandler connectorInvocationHandler = mock(ConnectorInvocationHandler.class);
when(connectorFactory.create(Mockito.anyString(), Mockito.<ArbitrationResult>any(), Mockito.eq(messagingQos))).thenReturn(connectorInvocationHandler);
MyBroadcastSubscriptionListener broadcastSubscriptionListener = mock(MyBroadcastSubscriptionListener.class);
SubscriptionQos subscriptionQos = mock(SubscriptionQos.class);
Method subscribeMethod = MyBroadcastInterface.class.getMethod("subscribeToMyMulticast", MyBroadcastSubscriptionListener.class, SubscriptionQos.class, String[].class);
Object[] args = new Object[] { broadcastSubscriptionListener, subscriptionQos, new String[] { "one", "two", "three" } };
ArbitrationResult arbitrationResult = new ArbitrationResult();
DiscoveryEntryWithMetaInfo discoveryEntry = new DiscoveryEntryWithMetaInfo();
discoveryEntry.setParticipantId("participantId");
arbitrationResult.setDiscoveryEntries(Sets.newHashSet(discoveryEntry));
proxyInvocationHandler.createConnector(arbitrationResult);
proxyInvocationHandler.invoke(subscribeMethod, args);
ArgumentCaptor<MulticastSubscribeInvocation> captor = ArgumentCaptor.forClass(MulticastSubscribeInvocation.class);
verify(connectorInvocationHandler).executeSubscriptionMethod(captor.capture());
MulticastSubscribeInvocation multicastSubscribeInvocation = captor.getValue();
assertNotNull(multicastSubscribeInvocation);
assertArrayEquals(new String[] { "one", "two", "three" }, multicastSubscribeInvocation.getPartitions());
}
use of io.joynr.proxy.invocation.MulticastSubscribeInvocation in project joynr by bmwcarit.
the class SubscriptionManagerTest method testRegisterMulticastSubscription.
@SuppressWarnings("unchecked")
private void testRegisterMulticastSubscription(String subscriptionId, String... partitions) throws Exception {
Method method = TestMulticastSubscriptionInterface.class.getMethod("subscribeToMyMulticast", new Class[0]);
BroadcastSubscriptionListener listener = spy(new BroadcastSubscriptionListener() {
@Override
public void onError(SubscriptionException error) {
}
@Override
public void onSubscribed(String subscriptionId) {
}
@SuppressWarnings("unused")
public void onReceive() {
}
});
SubscriptionQos subscriptionQos = mock(MulticastSubscriptionQos.class);
Object[] args;
if (subscriptionId == null) {
args = new Object[] { listener, subscriptionQos, partitions };
} else {
args = new Object[] { subscriptionId, listener, subscriptionQos, partitions };
}
String multicastId = MulticastIdUtil.createMulticastId(toParticipantId, "myMulticast", partitions);
Set<String> subscriptionIdSet = new HashSet<>();
Pattern multicastIdPattern = Pattern.compile(multicastId);
multicastSubscribersDirectory.put(multicastIdPattern, subscriptionIdSet);
when(multicastWildcardRegexFactory.createIdPattern(multicastId)).thenReturn(multicastIdPattern);
MulticastSubscribeInvocation invocation = new MulticastSubscribeInvocation(method, args, future);
DiscoveryEntryWithMetaInfo toDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
toDiscoveryEntry.setParticipantId(toParticipantId);
subscriptionManager.registerMulticastSubscription(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), invocation);
verify(multicastSubscribersDirectory).put(any(Pattern.class), anySet());
assertEquals(1, subscriptionIdSet.size());
if (subscriptionId != null) {
assertEquals(subscriptionId, subscriptionIdSet.iterator().next());
}
verify(dispatcher).sendSubscriptionRequest(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), any(SubscriptionRequest.class), any(MessagingQos.class));
}
Aggregations