Search in sources :

Example 16 with ProviderQos

use of joynr.types.ProviderQos 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 17 with ProviderQos

use of joynr.types.ProviderQos in project joynr by bmwcarit.

the class LocalDiscoveryAggregatorTest method passesUnknownEntry.

@SuppressWarnings("unchecked")
@Test
public void passesUnknownEntry() {
    DiscoveryEntry discoveryEntry = new DiscoveryEntry(new Version(0, 0), "anyDomain", "anyInterface", "anyParticipant", new ProviderQos(), System.currentTimeMillis(), expiryDateMs, publicKeyId);
    localDiscoveryAggregator.add(addCallback, discoveryEntry);
    verify(discoveryProxyMock, times(1)).add(any(Callback.class), eq(discoveryEntry));
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) Callback(io.joynr.proxy.Callback) Version(joynr.types.Version) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 18 with ProviderQos

use of joynr.types.ProviderQos in project joynr by bmwcarit.

the class LocalDiscoveryAggregatorTest method setUp.

@Before
public void setUp() {
    systemServicesDomain = "test.system.service.domain";
    anotherDomain = "anotherDomain";
    discoveryProviderParticipantId = "test.discovery.provider.participant";
    when(proxyBuilderFactory.get(anyString(), eq(DiscoveryProxy.class))).thenReturn(proxyBuilder);
    when(proxyBuilder.build()).thenReturn(discoveryProxyMock);
    when(proxyBuilder.setMessagingQos(any(MessagingQos.class))).thenReturn(proxyBuilder);
    localDiscoveryAggregator = new LocalDiscoveryAggregator(systemServicesDomain, discoveryProviderParticipantId, "routingProviderParticipantId", proxyBuilderFactory);
    localDiscoveryAggregator.forceQueryOfDiscoveryProxy();
    ProviderQos providerQos = new ProviderQos();
    providerQos.setScope(ProviderScope.LOCAL);
    discoveryProviderEntry = new DiscoveryEntryWithMetaInfo(new Version(0, 1), systemServicesDomain, Discovery.INTERFACE_NAME, discoveryProviderParticipantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId, true);
    anotherDiscoveryProviderEntry = new DiscoveryEntryWithMetaInfo(new Version(0, 0), anotherDomain, Discovery.INTERFACE_NAME, discoveryProviderParticipantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId, true);
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) DiscoveryProxy(joynr.system.DiscoveryProxy) Version(joynr.types.Version) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ProviderQos(joynr.types.ProviderQos) Before(org.junit.Before)

Example 19 with ProviderQos

use of joynr.types.ProviderQos in project joynr by bmwcarit.

the class SerializationTest method serializeSubtypeInCompoundType.

@Test
public void serializeSubtypeInCompoundType() throws Exception {
    MqttAddress mqttAddress = new MqttAddress("brokerUri", "topic");
    GlobalDiscoveryEntry globalDiscoveryEntry = new GlobalDiscoveryEntry(new Version(47, 11), "domain", "interface", "participantId", new ProviderQos(), System.currentTimeMillis(), expiryDateMs, publicKeyId, objectMapper.writeValueAsString(mqttAddress));
    String serializedGlobalDiscoveryEntry = objectMapper.writeValueAsString(globalDiscoveryEntry);
    GlobalDiscoveryEntry receivedDiscoveryEntry = objectMapper.readValue(serializedGlobalDiscoveryEntry, GlobalDiscoveryEntry.class);
    Assert.assertTrue(objectMapper.readValue(receivedDiscoveryEntry.getAddress(), Address.class) instanceof MqttAddress);
    Assert.assertEquals(globalDiscoveryEntry, receivedDiscoveryEntry);
}
Also used : Version(joynr.types.Version) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ProviderQos(joynr.types.ProviderQos) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Test(org.junit.Test)

Example 20 with ProviderQos

use of joynr.types.ProviderQos in project joynr by bmwcarit.

the class ArbitrationTest method keywordArbitratorOnChangeSubscriptionsTest.

// Check that the keyword arbitrator will only consider providers that support onChange subscriptions
// when this is requested by the DiscoveryQos
@Test
public void keywordArbitratorOnChangeSubscriptionsTest() throws InterruptedException {
    ProviderQos providerQos = new ProviderQos();
    CustomParameter[] qosParameters = { new CustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, testKeyword) };
    // Create a capability entry for a provider with the correct keyword but that does not support onChange subscriptions
    providerQos.setCustomParameters(qosParameters);
    providerQos.setSupportsOnChangeSubscriptions(false);
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "wrongParticipantId", providerQos, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    // Create a capability entry for a provider with the correct keyword and that also supports onChange subscriptions
    ProviderQos providerQos2 = new ProviderQos();
    CustomParameter[] qosParameters2 = { new CustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, testKeyword) };
    providerQos2.setCustomParameters(qosParameters2);
    providerQos2.setSupportsOnChangeSubscriptions(true);
    expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
    DiscoveryEntryWithMetaInfo expectedDiscoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "expectedParticipantId", providerQos2, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true);
    capabilitiesList.add(expectedDiscoveryEntry);
    discoveryQos = new DiscoveryQos(ARBITRATION_TIMEOUT, ArbitrationStrategy.Keyword, Long.MAX_VALUE);
    discoveryQos.addCustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, testKeyword);
    discoveryQos.setProviderMustSupportOnChange(true);
    try {
        Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
        arbitrator.setArbitrationListener(arbitrationCallback);
        arbitrator.scheduleArbitration();
        assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
        ArbitrationResult expectedArbitrationResult = new ArbitrationResult(expectedDiscoveryEntry);
        verify(arbitrationCallback, times(1)).onSuccess(eq(expectedArbitrationResult));
    } catch (DiscoveryException e) {
        fail("A Joyn Arbitration Exception has been thrown");
    }
}
Also used : Version(joynr.types.Version) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) CustomParameter(joynr.types.CustomParameter) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryException(io.joynr.exceptions.DiscoveryException) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Aggregations

ProviderQos (joynr.types.ProviderQos)69 Version (joynr.types.Version)43 Test (org.junit.Test)37 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)27 DiscoveryEntry (joynr.types.DiscoveryEntry)25 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)24 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)21 Matchers.anyString (org.mockito.Matchers.anyString)16 ArrayList (java.util.ArrayList)15 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)13 Before (org.junit.Before)13 Callback (io.joynr.proxy.Callback)12 HashSet (java.util.HashSet)11 MqttAddress (joynr.system.RoutingTypes.MqttAddress)10 InvocationOnMock (org.mockito.invocation.InvocationOnMock)10 Address (joynr.system.RoutingTypes.Address)9 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)8 MessagingQos (io.joynr.messaging.MessagingQos)8 Properties (java.util.Properties)8 DiscoveryException (io.joynr.exceptions.DiscoveryException)7