Search in sources :

Example 16 with DiscoveryEntryWithMetaInfo

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

the class LocalDiscoveryAggregatorTest method findsProvisionedEntryForMultipleDomains.

@SuppressWarnings("unchecked")
@Test
public void findsProvisionedEntryForMultipleDomains() throws Exception {
    discoveryProviderEntries = new DiscoveryEntryWithMetaInfo[] { anotherDiscoveryProviderEntry };
    allDomains = new String[] { systemServicesDomain, anotherDomain };
    String[] missingDomains = new String[] { anotherDomain };
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_ONLY);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Callback<DiscoveryEntryWithMetaInfo[]> callback = (Callback<DiscoveryEntryWithMetaInfo[]>) invocation.getArguments()[0];
            callback.onSuccess(discoveryProviderEntries);
            return null;
        }
    }).when(discoveryProxyMock).lookup(any(Callback.class), any(String[].class), anyString(), any(DiscoveryQos.class));
    Future<DiscoveryEntryWithMetaInfo[]> discoveryEntriesFuture = localDiscoveryAggregator.lookup(lookupCallback, allDomains, Discovery.INTERFACE_NAME, discoveryQos);
    assertNotNull(discoveryEntriesFuture);
    DiscoveryEntry[] result = discoveryEntriesFuture.get();
    logger.info("Got discovery entries: " + Arrays.toString(result));
    assertNotNull(result);
    assertEquals(2, result.length);
    assertTrue(containsByInterfaceDomain(result, discoveryProviderEntry.getInterfaceName(), discoveryProviderEntry.getDomain()));
    assertTrue(containsByInterfaceDomain(result, anotherDiscoveryProviderEntry.getInterfaceName(), anotherDiscoveryProviderEntry.getDomain()));
    verify(discoveryProxyMock).lookup(any(Callback.class), eq(missingDomains), eq(Discovery.INTERFACE_NAME), eq(discoveryQos));
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) Callback(io.joynr.proxy.Callback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Mockito.anyString(org.mockito.Mockito.anyString) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryQos(joynr.types.DiscoveryQos) Test(org.junit.Test)

Example 17 with DiscoveryEntryWithMetaInfo

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

the class RequestReplyManagerTest method setUp.

@Before
public void setUp() throws NoSuchMethodException, SecurityException, JsonGenerationException, IOException {
    requestCallerFactory = new RequestCallerFactory();
    testOneWayRecipientParticipantId = "testOneWayRecipientParticipantId";
    testOneWayRecipientDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
    testOneWayRecipientDiscoveryEntry.setParticipantId(testOneWayRecipientParticipantId);
    testOneWayRecipientDiscoveryEntries = Sets.newHashSet(testOneWayRecipientDiscoveryEntry);
    testMessageResponderParticipantId = "testMessageResponderParticipantId";
    testMessageResponderDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
    testMessageResponderDiscoveryEntry.setParticipantId(testMessageResponderParticipantId);
    testSenderParticipantId = "testSenderParticipantId";
    testResponderUnregisteredParticipantId = "testResponderUnregisteredParticipantId";
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            install(new JoynrMessageScopeModule());
            bind(MessageSender.class).toInstance(messageSenderMock);
            bind(MessageRouter.class).toInstance(messageRouterMock);
            bind(RequestReplyManager.class).to(RequestReplyManagerImpl.class);
            requestStaticInjection(RpcUtils.class, Request.class, JoynrMessagingConnectorFactory.class);
            ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("joynr.Cleanup-%d").build();
            ScheduledExecutorService cleanupExecutor = Executors.newSingleThreadScheduledExecutor(namedThreadFactory);
            bind(ScheduledExecutorService.class).annotatedWith(Names.named(JOYNR_SCHEDULER_CLEANUP)).toInstance(cleanupExecutor);
            Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
            });
        }
    });
    objectMapper = injector.getInstance(ObjectMapper.class);
    objectMapper.registerSubtypes(Request.class, OneWayRequest.class);
    requestReplyManager = injector.getInstance(RequestReplyManager.class);
    providerDirectory = injector.getInstance(ProviderDirectory.class);
    replyCallerDirectory = injector.getInstance(ReplyCallerDirectory.class);
    requestReplyManager = injector.getInstance(RequestReplyManager.class);
    // dispatcher.addListener(testOneWayRecipientParticipantId, testListener);
    // jsonRequestString1 = "{\"_typeName\":\"Request\", \"methodName\":\"respond\",\"params\":{\"payload\": \""
    // + payload1 + "\"}}";
    // jsonRequestString2 = "{\"_typeName\":\"Request\", \"methodName\":\"respond\",\"params\":{\"payload\": \""
    // + payload2 + "\"}}";
    Object[] params1 = new Object[] { payload1 };
    Object[] params2 = new Object[] { payload2 };
    // MethodMetaInformation methodMetaInformation = new
    // MethodMetaInformation(TestRequestCaller.class.getMethod("respond", new Class[]{ Object.class }));
    Method method = TestProvider.class.getMethod("methodWithStrings", new Class[] { String.class });
    request1 = new Request(method.getName(), params1, method.getParameterTypes());
    request2 = new Request(method.getName(), params2, method.getParameterTypes());
    request3 = new Request("unknownMethodName", params2, method.getParameterTypes());
    Method fireAndForgetMethod = TestOneWayRecipient.class.getMethod("fireAndForgetMethod", new Class[] { String.class });
    oneWay1 = new OneWayRequest(fireAndForgetMethod.getName(), new Object[] { payload1 }, fireAndForgetMethod.getParameterTypes());
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) RpcUtils(io.joynr.dispatching.rpc.RpcUtils) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) OneWayRequest(joynr.OneWayRequest) Request(joynr.Request) Method(java.lang.reflect.Method) AbstractModule(com.google.inject.AbstractModule) JoynrMessageScopeModule(io.joynr.context.JoynrMessageScopeModule) OneWayRequest(joynr.OneWayRequest) TypeLiteral(com.google.inject.TypeLiteral) ReplyCallerDirectory(io.joynr.dispatching.rpc.ReplyCallerDirectory) Injector(com.google.inject.Injector) JoynrMessagingConnectorFactory(io.joynr.proxy.JoynrMessagingConnectorFactory) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 18 with DiscoveryEntryWithMetaInfo

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

the class SubscriptionTimersTest method setUp.

@Before
public void setUp() {
    subscriptionEndScheduler = Executors.newScheduledThreadPool(10);
    subscriptionManager = new SubscriptionManagerImpl(subscriptionEndScheduler, dispatcher, multicastWildcardRegexFactory);
    attributeName = "testAttribute";
    fromParticipantId = "fromParticipantId";
    toParticipantId = "toParticipantId";
    toDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
    toDiscoveryEntry.setParticipantId(toParticipantId);
    future = new Future<String>();
}
Also used : DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) Before(org.junit.Before)

Example 19 with DiscoveryEntryWithMetaInfo

use of joynr.types.DiscoveryEntryWithMetaInfo 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)

Example 20 with DiscoveryEntryWithMetaInfo

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

the class ArbitrationTest method keyWordArbitratorMissingKeywordTest.

@Test
public void keyWordArbitratorMissingKeywordTest() throws InterruptedException {
    ProviderQos providerQos = new ProviderQos();
    CustomParameter[] qosParameters = { new CustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, "wrongkeyword") };
    providerQos.setCustomParameters(qosParameters);
    expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, expectedParticipantId, providerQos, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    ProviderQos providerQos2 = new ProviderQos();
    CustomParameter[] qosParameters2 = { new CustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, "otherKeyword") };
    providerQos2.setCustomParameters(qosParameters2);
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "wrongParticipantId", providerQos2, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    // use minimal timeout to prevent restarting arbitration
    int discoveryTimeout = 0;
    discoveryQos = new DiscoveryQos(discoveryTimeout, ArbitrationStrategy.Keyword, Long.MAX_VALUE);
    discoveryQos.addCustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, testKeyword);
    try {
        Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
        arbitrator.setArbitrationListener(arbitrationCallback);
        arbitrator.scheduleArbitration();
        assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
        verify(arbitrationCallback, times(1)).onError(any(Throwable.class));
        verify(arbitrationCallback, never()).onSuccess(any(ArbitrationResult.class));
    } 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

DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)66 Test (org.junit.Test)32 Version (joynr.types.Version)29 ProviderQos (joynr.types.ProviderQos)24 DiscoveryEntry (joynr.types.DiscoveryEntry)16 HashSet (java.util.HashSet)14 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)13 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)11 Matchers.anyString (org.mockito.Matchers.anyString)10 InvocationOnMock (org.mockito.invocation.InvocationOnMock)10 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)9 Before (org.junit.Before)9 DiscoveryException (io.joynr.exceptions.DiscoveryException)7 MessagingQos (io.joynr.messaging.MessagingQos)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 Set (java.util.Set)7 Callback (io.joynr.proxy.Callback)6 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)5 Collection (java.util.Collection)5