Search in sources :

Example 1 with BroadcastSubscribeInvocation

use of io.joynr.proxy.invocation.BroadcastSubscribeInvocation in project joynr by bmwcarit.

the class ProxyInvocationHandlerImpl method executeBroadcastSubscriptionMethod.

private void executeBroadcastSubscriptionMethod(Method method, Object[] args, Future<String> future) {
    final BroadcastSubscribeInvocation broadcastSubscription = new BroadcastSubscribeInvocation(method, args, future);
    queueOrExecuteSubscriptionInvocation(broadcastSubscription, new SubscriptionAction(future) {

        @Override
        public void subscribe() {
            connector.executeSubscriptionMethod(broadcastSubscription);
        }
    });
}
Also used : BroadcastSubscribeInvocation(io.joynr.proxy.invocation.BroadcastSubscribeInvocation)

Example 2 with BroadcastSubscribeInvocation

use of io.joynr.proxy.invocation.BroadcastSubscribeInvocation in project joynr by bmwcarit.

the class ProxyTest method setUp.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Before
public void setUp() throws Exception {
    navigationProxyCreatedSemaphore = new Semaphore(0);
    navigationProxyCreatedCallback = new ProxyCreatedCallback<NavigationProxy>() {

        @Override
        public void onProxyCreationFinished(NavigationProxy result) {
            navigationProxyCreatedSemaphore.release();
        }

        @Override
        public void onProxyCreationError(JoynrRuntimeException error) {
            fail("Navigation proxy creation failed: " + error);
        }
    };
    testInterfaceProxyCreatedSemaphore = new Semaphore(0);
    testInterfaceProxyCreatedCallback = new ProxyCreatedCallback<TestInterface>() {

        @Override
        public void onProxyCreationFinished(TestInterface result) {
            testInterfaceProxyCreatedSemaphore.release();
        }

        @Override
        public void onProxyCreationError(JoynrRuntimeException error) {
            fail("TestInterface proxy creation failed: " + error);
        }
    };
    domain = "TestDomain";
    fromParticipantId = "ProxyTestFromParticipantId";
    toParticipantId = "ProxyTestToParticipantId";
    toDiscoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, toParticipantId, new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + ONE_MINUTE_IN_MS, "publicKeyId", true);
    toDiscoveryEntries = new HashSet<DiscoveryEntryWithMetaInfo>();
    toDiscoveryEntries.add(toDiscoveryEntry);
    MockitoAnnotations.initMocks(this);
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            requestStaticInjection(RpcUtils.class);
            bind(ReplyCallerDirectory.class).toInstance(replyCallerDirectory);
            bind(RequestReplyManager.class).toInstance(requestReplyManager);
            bind(SubscriptionManager.class).toInstance(subscriptionManager);
            bind(MessageRouter.class).toInstance(messageRouter);
            bind(RoutingTable.class).toInstance(routingTable);
            install(new FactoryModuleBuilder().implement(ProxyInvocationHandler.class, ProxyInvocationHandlerImpl.class).build(ProxyInvocationHandlerFactory.class));
        }

        @Provides
        @Singleton
        @Named(SystemServicesSettings.PROPERTY_DISPATCHER_ADDRESS)
        Address getDispatcherAddress() {
            return new InProcessAddress();
        }
    });
    proxyBuilderFactory = new ProxyBuilderFactoryImpl(localDiscoveryAggregator, injector.getInstance(ProxyInvocationHandlerFactory.class), MAX_TTL_MS, DISCOVERY_TIMEOUT_MS, RETRY_INTERVAL_MS);
    Mockito.doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            DiscoveryEntryWithMetaInfo[] fakeCapabilitiesResult = { toDiscoveryEntry };
            ((Callback) args[0]).resolve((Object) fakeCapabilitiesResult);
            return null;
        }
    }).when(localDiscoveryAggregator).lookup(Mockito.<Callback>any(), Mockito.<String[]>any(), Mockito.<String>any(), Mockito.<joynr.types.DiscoveryQos>any());
    Mockito.doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            AttributeSubscribeInvocation request = (AttributeSubscribeInvocation) args[2];
            if (request.getSubscriptionId() == null) {
                request.setSubscriptionId(UUID.randomUUID().toString());
            }
            request.getFuture().resolve(request.getSubscriptionId());
            return null;
        }
    }).when(subscriptionManager).registerAttributeSubscription(any(String.class), eq(Sets.newHashSet(toDiscoveryEntry)), Mockito.any(AttributeSubscribeInvocation.class));
    Mockito.doAnswer(new // TODO simulate resolve here ! subscription reply bastern ... handle subscriptionreply ausführen..
    Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            BroadcastSubscribeInvocation request = (BroadcastSubscribeInvocation) args[2];
            if (request.getSubscriptionId() == null) {
                request.setSubscriptionId(UUID.randomUUID().toString());
            }
            request.getFuture().resolve(request.getSubscriptionId());
            return null;
        }
    }).when(subscriptionManager).registerBroadcastSubscription(any(String.class), eq(Sets.newHashSet(toDiscoveryEntry)), Mockito.any(BroadcastSubscribeInvocation.class));
    Mockito.doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            MulticastSubscribeInvocation request = (MulticastSubscribeInvocation) args[2];
            if (request.getSubscriptionId() == null) {
                request.setSubscriptionId(UUID.randomUUID().toString());
            }
            request.getFuture().resolve(request.getSubscriptionId());
            return null;
        }
    }).when(subscriptionManager).registerMulticastSubscription(any(String.class), eq(Sets.newHashSet(toDiscoveryEntry)), Mockito.any(MulticastSubscribeInvocation.class));
    discoveryQos = new DiscoveryQos(10000, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE);
    messagingQos = new MessagingQos();
    doAnswer(new Answer<Set<DiscoveryEntryWithMetaInfo>>() {

        @Override
        public Set<DiscoveryEntryWithMetaInfo> answer(InvocationOnMock invocation) throws Throwable {
            return (Set<DiscoveryEntryWithMetaInfo>) invocation.getArguments()[1];
        }
    }).when(discoveryEntryVersionFilter).filter(Mockito.<Version>any(), Mockito.<Set<DiscoveryEntryWithMetaInfo>>any(), Mockito.<Map<String, Set<Version>>>any());
    Field discoveryEntryVersionFilterField = ArbitratorFactory.class.getDeclaredField("discoveryEntryVersionFilter");
    discoveryEntryVersionFilterField.setAccessible(true);
    discoveryEntryVersionFilterField.set(ArbitratorFactory.class, discoveryEntryVersionFilter);
    doAnswer(new Answer<Set<DiscoveryEntryWithMetaInfo>>() {

        @Override
        public Set<DiscoveryEntryWithMetaInfo> answer(InvocationOnMock invocation) throws Throwable {
            return (Set<DiscoveryEntryWithMetaInfo>) invocation.getArguments()[1];
        }
    }).when(discoveryEntryVersionFilter).filter(Mockito.<Version>any(), Mockito.<Set<DiscoveryEntryWithMetaInfo>>any(), Mockito.<Map<String, Set<Version>>>any());
    Field schedulerField = ArbitratorFactory.class.getDeclaredField("scheduler");
    schedulerField.setAccessible(true);
    String name = "TEST.joynr.scheduler.arbitration.arbitratorRunnable";
    ThreadFactory joynrThreadFactory = new JoynrThreadFactory(name, true);
    scheduler = Executors.newSingleThreadScheduledExecutor(joynrThreadFactory);
    schedulerField.set(ArbitratorFactory.class, scheduler);
    Field shutdownNotifierField = ArbitratorFactory.class.getDeclaredField("shutdownNotifier");
    shutdownNotifierField.setAccessible(true);
    shutdownNotifierField.set(ArbitratorFactory.class, shutdownNotifier);
    ArbitratorFactory.start();
    verify(shutdownNotifier).registerForShutdown(any(ShutdownListener.class));
}
Also used : JoynrThreadFactory(io.joynr.runtime.JoynrThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) RpcUtils(io.joynr.dispatching.rpc.RpcUtils) Set(java.util.Set) HashSet(java.util.HashSet) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) Address(joynr.system.RoutingTypes.Address) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) MulticastSubscribeInvocation(io.joynr.proxy.invocation.MulticastSubscribeInvocation) Semaphore(java.util.concurrent.Semaphore) Matchers.anyString(org.mockito.Matchers.anyString) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ShutdownListener(io.joynr.runtime.ShutdownListener) Field(java.lang.reflect.Field) MessagingQos(io.joynr.messaging.MessagingQos) BroadcastSubscribeInvocation(io.joynr.proxy.invocation.BroadcastSubscribeInvocation) JoynrVersion(io.joynr.JoynrVersion) Version(joynr.types.Version) Injector(com.google.inject.Injector) JoynrThreadFactory(io.joynr.runtime.JoynrThreadFactory) NavigationProxy(joynr.vehicle.NavigationProxy) Named(com.google.inject.name.Named) AttributeSubscribeInvocation(io.joynr.proxy.invocation.AttributeSubscribeInvocation) Provides(com.google.inject.Provides) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) AbstractModule(com.google.inject.AbstractModule) Singleton(com.google.inject.Singleton) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ProviderQos(joynr.types.ProviderQos) Before(org.junit.Before)

Example 3 with BroadcastSubscribeInvocation

use of io.joynr.proxy.invocation.BroadcastSubscribeInvocation in project joynr by bmwcarit.

the class SubscriptionManagerTest method registerBroadcastSubscription.

@Test
public void registerBroadcastSubscription() throws JoynrSendBufferFullException, JoynrMessageNotSentException, JsonGenerationException, JsonMappingException, IOException {
    String broadcastName = "broadcastName";
    BroadcastSubscriptionListener broadcastSubscriptionListener = mock(LocationUpdateBroadcastListener.class);
    BroadcastSubscribeInvocation subscriptionRequest = new BroadcastSubscribeInvocation(broadcastName, broadcastSubscriptionListener, onChangeQos, future);
    subscriptionManager.registerBroadcastSubscription(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), subscriptionRequest);
    subscriptionId = subscriptionRequest.getSubscriptionId();
    verify(broadcastSubscriptionDirectory).put(Mockito.anyString(), Mockito.eq(broadcastSubscriptionListener));
    verify(subscriptionStates).put(Mockito.anyString(), Mockito.any(PubSubState.class));
    verify(cleanupScheduler).schedule(Mockito.any(Runnable.class), Mockito.eq(onChangeQos.getExpiryDateMs()), Mockito.eq(TimeUnit.MILLISECONDS));
    verify(subscriptionEndFutures, Mockito.times(1)).put(Mockito.eq(subscriptionId), Mockito.any(ScheduledFuture.class));
    verify(dispatcher).sendSubscriptionRequest(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), any(SubscriptionRequest.class), any(MessagingQos.class));
}
Also used : SubscriptionRequest(joynr.SubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) BroadcastSubscribeInvocation(io.joynr.proxy.invocation.BroadcastSubscribeInvocation) Matchers.anyString(org.mockito.Matchers.anyString) BroadcastSubscriptionListener(io.joynr.pubsub.subscription.BroadcastSubscriptionListener) ScheduledFuture(java.util.concurrent.ScheduledFuture) Test(org.junit.Test)

Example 4 with BroadcastSubscribeInvocation

use of io.joynr.proxy.invocation.BroadcastSubscribeInvocation 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 5 with BroadcastSubscribeInvocation

use of io.joynr.proxy.invocation.BroadcastSubscribeInvocation in project joynr by bmwcarit.

the class ProxyTest method createProxySubscribeAndUnsubscribeFromSelectiveBroadcast.

@Test
public void createProxySubscribeAndUnsubscribeFromSelectiveBroadcast() throws Exception {
    NavigationProxy proxy = getNavigationProxy();
    long minInterval_ms = 0;
    long expiryDate = System.currentTimeMillis() + 30000;
    long publicationTtl_ms = 5000;
    OnChangeSubscriptionQos subscriptionQos = new OnChangeSubscriptionQos().setMinIntervalMs(minInterval_ms).setExpiryDateMs(expiryDate).setPublicationTtlMs(publicationTtl_ms);
    LocationUpdateSelectiveBroadcastFilterParameters filterParameter = new LocationUpdateSelectiveBroadcastFilterParameters();
    Future<String> subscriptionId = proxy.subscribeToLocationUpdateSelectiveBroadcast(mock(LocationUpdateSelectiveBroadcastListener.class), subscriptionQos, filterParameter);
    ArgumentCaptor<BroadcastSubscribeInvocation> subscriptionRequest = ArgumentCaptor.forClass(BroadcastSubscribeInvocation.class);
    verify(subscriptionManager, times(1)).registerBroadcastSubscription(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), subscriptionRequest.capture());
    assertEquals("locationUpdateSelective", subscriptionRequest.getValue().getBroadcastName());
    // now, let's remove the previous subscriptionRequest
    proxy.unsubscribeFromGuidanceActive(subscriptionId.get(100L));
    verify(subscriptionManager, times(1)).unregisterSubscription(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), eq(subscriptionId.get()), any(MessagingQos.class));
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) BroadcastSubscribeInvocation(io.joynr.proxy.invocation.BroadcastSubscribeInvocation) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) LocationUpdateSelectiveBroadcastListener(joynr.vehicle.NavigationBroadcastInterface.LocationUpdateSelectiveBroadcastListener) NavigationProxy(joynr.vehicle.NavigationProxy) LocationUpdateSelectiveBroadcastFilterParameters(joynr.vehicle.NavigationBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

BroadcastSubscribeInvocation (io.joynr.proxy.invocation.BroadcastSubscribeInvocation)5 MessagingQos (io.joynr.messaging.MessagingQos)3 Test (org.junit.Test)3 Matchers.anyString (org.mockito.Matchers.anyString)3 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)2 NavigationProxy (joynr.vehicle.NavigationProxy)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 JoynrVersion (io.joynr.JoynrVersion)1 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)1 RpcUtils (io.joynr.dispatching.rpc.RpcUtils)1 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)1 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)1 SubscriptionException (io.joynr.exceptions.SubscriptionException)1 InProcessAddress (io.joynr.messaging.inprocess.InProcessAddress)1