Search in sources :

Example 11 with DiscoveryQos

use of io.joynr.arbitration.DiscoveryQos in project joynr by bmwcarit.

the class SubscriptionEnd2EndTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    final int port = ServletUtil.findFreePort();
    webSocketConfig = new Properties();
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_HOST, "localhost");
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PORT, "" + port);
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PROTOCOL, "ws");
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PATH, "");
    providerQos = new ProviderQos(new CustomParameter[0], System.currentTimeMillis(), ProviderScope.LOCAL, false);
    discoveryQos = new DiscoveryQos(10000, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE, DiscoveryScope.LOCAL_ONLY);
    super.setUp();
// Uncomment to log the verbose android logs to stdout
// ShadowLog.stream = System.out;
}
Also used : Properties(java.util.Properties) CustomParameter(joynr.types.CustomParameter) ProviderQos(joynr.types.ProviderQos) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) Before(org.junit.Before)

Example 12 with DiscoveryQos

use of io.joynr.arbitration.DiscoveryQos 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 13 with DiscoveryQos

use of io.joynr.arbitration.DiscoveryQos in project joynr by bmwcarit.

the class AbstractProviderProxyEnd2EndTest method asyncMethodCallWithTtlExpiring.

@Ignore
@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void asyncMethodCallWithTtlExpiring() throws DiscoveryException, JoynrIllegalStateException, InterruptedException, ApplicationException {
    ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
    long ttl = 2000L;
    MessagingQos testMessagingQos = new MessagingQos(ttl);
    DiscoveryQos testDiscoveryQos = new DiscoveryQos(30000, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE);
    testProxy proxyShortTll = proxyBuilder.setMessagingQos(testMessagingQos).setDiscoveryQos(testDiscoveryQos).build();
    // the provider waits ttl before responding, causing a ttl
    boolean timeoutExceptionThrown = false;
    // the ttl parameter tells the provider to wait this long before
    // replying, thereby forcing a ttl exception
    Future<String> waitTooLongFuture = proxyShortTll.waitTooLong(callback, ttl * 2);
    try {
        // should never have to wait
        waitTooLongFuture.get(10 * ttl);
    // this long
    // the JoynWaitExpiredException should not be thrown.
    } catch (JoynrWaitExpiredException e) {
        timeoutExceptionThrown = false;
    } catch (JoynrTimeoutException e) {
        timeoutExceptionThrown = true;
    }
    assertEquals(true, timeoutExceptionThrown);
    assertEquals(RequestStatusCode.ERROR, waitTooLongFuture.getStatus().getCode());
    verify(callback).onFailure(any(JoynrRuntimeException.class));
    verifyNoMoreInteractions(callback);
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) JoynrTimeoutException(io.joynr.exceptions.JoynrTimeoutException) joynr.tests.testProxy(joynr.tests.testProxy) JoynrWaitExpiredException(io.joynr.exceptions.JoynrWaitExpiredException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 with DiscoveryQos

use of io.joynr.arbitration.DiscoveryQos in project joynr by bmwcarit.

the class AccessControllerImpl method getCapabilityEntry.

// Get the capability entry for the given message
private void getCapabilityEntry(ImmutableMessage message, CapabilityCallback callback) {
    long cacheMaxAge = Long.MAX_VALUE;
    DiscoveryQos discoveryQos = new DiscoveryQos(DiscoveryQos.NO_MAX_AGE, ArbitrationStrategy.NotSet, cacheMaxAge, DiscoveryScope.LOCAL_THEN_GLOBAL);
    String participantId = message.getRecipient();
    localCapabilitiesDirectory.lookup(participantId, discoveryQos, callback);
}
Also used : DiscoveryQos(io.joynr.arbitration.DiscoveryQos)

Example 15 with DiscoveryQos

use of io.joynr.arbitration.DiscoveryQos in project joynr by bmwcarit.

the class GlobalDomainAccessControllerClient method getGlobalDomainAccessControllerProxy.

private GlobalDomainAccessControllerProxy getGlobalDomainAccessControllerProxy(long ttl) {
    ProxyBuilder<GlobalDomainAccessControllerProxy> accessControlProxyBuilder = proxyBuilderFactory.get(domain, GlobalDomainAccessControllerProxy.class);
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.GLOBAL_ONLY);
    discoveryQos.setCacheMaxAgeMs(DiscoveryQos.NO_MAX_AGE);
    MessagingQos messagingQos = new MessagingQos(ttl);
    return accessControlProxyBuilder.setDiscoveryQos(discoveryQos).setMessagingQos(messagingQos).build();
}
Also used : GlobalDomainAccessControllerProxy(joynr.infrastructure.GlobalDomainAccessControllerProxy) MessagingQos(io.joynr.messaging.MessagingQos) DiscoveryQos(io.joynr.arbitration.DiscoveryQos)

Aggregations

DiscoveryQos (io.joynr.arbitration.DiscoveryQos)46 MessagingQos (io.joynr.messaging.MessagingQos)23 Test (org.junit.Test)23 ProviderQos (joynr.types.ProviderQos)20 Matchers.anyString (org.mockito.Matchers.anyString)19 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)16 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)14 DiscoveryEntry (joynr.types.DiscoveryEntry)14 Callback (io.joynr.proxy.Callback)11 joynr.tests.testProxy (joynr.tests.testProxy)11 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)10 Properties (java.util.Properties)9 Version (joynr.types.Version)9 ArrayList (java.util.ArrayList)8 Before (org.junit.Before)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 Future (io.joynr.proxy.Future)5 ProxyCreatedCallback (io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback)5 HashSet (java.util.HashSet)5 IOException (java.io.IOException)4