Search in sources :

Example 6 with MulticastSubscribeInvocation

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);
        }
    });
}
Also used : MulticastSubscribeInvocation(io.joynr.proxy.invocation.MulticastSubscribeInvocation)

Example 7 with MulticastSubscribeInvocation

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());
}
Also used : ArbitrationResult(io.joynr.arbitration.ArbitrationResult) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) MulticastSubscribeInvocation(io.joynr.proxy.invocation.MulticastSubscribeInvocation) Method(java.lang.reflect.Method) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) Test(org.junit.Test)

Example 8 with MulticastSubscribeInvocation

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));
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) Pattern(java.util.regex.Pattern) MulticastSubscribeInvocation(io.joynr.proxy.invocation.MulticastSubscribeInvocation) Method(java.lang.reflect.Method) Matchers.anyString(org.mockito.Matchers.anyString) BroadcastSubscriptionListener(io.joynr.pubsub.subscription.BroadcastSubscriptionListener) SubscriptionRequest(joynr.SubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) MulticastSubscriptionQos(joynr.MulticastSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) HashSet(java.util.HashSet)

Aggregations

MulticastSubscribeInvocation (io.joynr.proxy.invocation.MulticastSubscribeInvocation)8 Test (org.junit.Test)5 MulticastSubscriptionQos (joynr.MulticastSubscriptionQos)4 NavigationProxy (joynr.vehicle.NavigationProxy)4 Matchers.anyString (org.mockito.Matchers.anyString)4 MessagingQos (io.joynr.messaging.MessagingQos)3 Method (java.lang.reflect.Method)3 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)3 LocationUpdateBroadcastListener (joynr.vehicle.NavigationBroadcastInterface.LocationUpdateBroadcastListener)3 SubscriptionException (io.joynr.exceptions.SubscriptionException)2 SubscriptionQos (io.joynr.pubsub.SubscriptionQos)2 HashSet (java.util.HashSet)2 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 AbstractModule (com.google.inject.AbstractModule)1 Injector (com.google.inject.Injector)1 Provides (com.google.inject.Provides)1 Singleton (com.google.inject.Singleton)1 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)1 Named (com.google.inject.name.Named)1