Search in sources :

Example 21 with GlobalDiscoveryEntry

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

the class DiscoveryEntryStoreInMemory method lookup.

@Override
public Collection<DiscoveryEntry> lookup(final String[] domains, final String interfaceName, long cacheMaxAge) {
    ArrayList<DiscoveryEntry> capabilitiesList = new ArrayList<DiscoveryEntry>();
    synchronized (storeLock) {
        for (String domain : domains) {
            String domainInterfacekey = domainInterfaceKey(domain, interfaceName);
            List<String> matchingDiscoveryEntries = interfaceAddressToCapabilityMapping.get(domainInterfacekey);
            if (matchingDiscoveryEntries != null) {
                // check that sure cache age is OK
                for (String capId : matchingDiscoveryEntries) {
                    DiscoveryEntry discoveryEntry = capabilityKeyToCapabilityMapping.get(capId);
                    if (discoveryEntry instanceof GlobalDiscoveryEntry && !checkAge(registeredCapabilitiesTime.get(capId), cacheMaxAge)) {
                        continue;
                    }
                    capabilitiesList.add(discoveryEntry);
                }
            }
        }
    }
    logger.debug("Capabilities found: {}", capabilitiesList.toString());
    return capabilitiesList;
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ArrayList(java.util.ArrayList)

Example 22 with GlobalDiscoveryEntry

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

the class LocalDiscoveryTest method testMixedLocalCachedRemoteDiscoveryEntries.

@SuppressWarnings("unchecked")
@Test
public void testMixedLocalCachedRemoteDiscoveryEntries() {
    String testDomain = "testDomain";
    String remoteDomain = "remoteDomain";
    Set<String> testDomains = new HashSet<>();
    testDomains.add(testDomain);
    testDomains.add(remoteDomain);
    String interfaceName = testProxy.INTERFACE_NAME;
    final Collection<DiscoveryEntry> localDiscoveryEntries = new HashSet<>();
    final Collection<DiscoveryEntry> cachedDiscoveryEntries = new HashSet<>();
    final List<GlobalDiscoveryEntry> remoteDiscoveryEntries = new ArrayList<>();
    DiscoveryEntry discoveryEntry = new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantIdLocal", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId");
    DiscoveryEntry cachedDiscoveryEntry = new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantIdCached", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId");
    GlobalDiscoveryEntry remoteDiscoveryEntry = CapabilityUtils.discoveryEntry2GlobalDiscoveryEntry(new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), remoteDomain, interfaceName, "participantIdRemote", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId"), new MqttAddress());
    localDiscoveryEntries.add(discoveryEntry);
    cachedDiscoveryEntries.add(cachedDiscoveryEntry);
    remoteDiscoveryEntries.add(remoteDiscoveryEntry);
    Set<DiscoveryEntryWithMetaInfo> discoveryEntriesWithMetaInfo = CapabilityUtils.convertToDiscoveryEntryWithMetaInfoSet(true, localDiscoveryEntries);
    discoveryEntriesWithMetaInfo.add(CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(false, cachedDiscoveryEntry));
    discoveryEntriesWithMetaInfo.add(CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(false, remoteDiscoveryEntry));
    when(localDiscoveryEntryStoreMock.lookup(any(String[].class), eq(interfaceName))).thenReturn(localDiscoveryEntries);
    when(globalDiscoveryEntryCacheMock.lookup(any(String[].class), eq(interfaceName), anyLong())).thenReturn(cachedDiscoveryEntries);
    Mockito.doAnswer(new Answer<Object>() {

        @SuppressWarnings("rawtypes")
        @Override
        public List<GlobalDiscoveryEntry> answer(InvocationOnMock invocation) throws Throwable {
            Object[] arguments = invocation.getArguments();
            assert (arguments[0] instanceof Callback);
            ((Callback) arguments[0]).resolve((Object) remoteDiscoveryEntries);
            return null;
        }
    }).when(globalCapabilitiesDirectoryClientMock).lookup(any(Callback.class), any(String[].class), eq(interfaceName), anyLong());
    ProxyBuilder<testProxy> proxyBuilder = runtime.getProxyBuilder(testDomains, testProxy.class);
    final Future<Void> future = new Future<Void>();
    ArbitrationStrategyFunction arbitrationStrategyFunction = new ArbitrationStrategyFunction() {

        @Override
        public Set<DiscoveryEntryWithMetaInfo> select(Map<String, String> parameters, Collection<DiscoveryEntryWithMetaInfo> capabilities) {
            return Sets.newHashSet(capabilities);
        }
    };
    DiscoveryQos discoveryQos = new DiscoveryQos(30000, arbitrationStrategyFunction, 0, DiscoveryScope.LOCAL_AND_GLOBAL);
    proxyBuilder.setDiscoveryQos(discoveryQos).build(new ProxyCreatedCallback<testProxy>() {

        @Override
        public void onProxyCreationFinished(testProxy result) {
            future.onSuccess(null);
        }

        @Override
        public void onProxyCreationError(JoynrRuntimeException error) {
            future.onFailure(error);
        }
    });
    try {
        future.get(5000);
        verify(joynrMessagingConnectorFactoryMock).create(anyString(), eq(discoveryEntriesWithMetaInfo), any(MessagingQos.class));
    } catch (Exception e) {
        Assert.fail("Unexpected exception from ProxyCreatedCallback: " + e);
    }
}
Also used : GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) MessagingQos(io.joynr.messaging.MessagingQos) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MqttAddress(joynr.system.RoutingTypes.MqttAddress) DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) joynr.tests.testProxy(joynr.tests.testProxy) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Callback(io.joynr.proxy.Callback) ProxyCreatedCallback(io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Future(io.joynr.proxy.Future) Collection(java.util.Collection) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ArbitrationStrategyFunction(io.joynr.arbitration.ArbitrationStrategyFunction) Map(java.util.Map) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 23 with GlobalDiscoveryEntry

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

the class ServersUtil method createJsonFor.

private static String createJsonFor(String directoriesUrl) throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName");
    setObjectMapperOnCapabilitiesUtils(objectMapper);
    String channelId = "discoverydirectory_channelid";
    String participantId = "capabilitiesdirectory_participantid";
    GlobalDiscoveryEntry discoveryEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), "io.joynr", GlobalCapabilitiesDirectory.INTERFACE_NAME, participantId, new ProviderQos(), System.currentTimeMillis(), Long.MAX_VALUE, "", new ChannelAddress(directoriesUrl, channelId));
    String accessParticipantId = "domainaccesscontroller_participantid";
    GlobalDiscoveryEntry accessControlEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), "io.joynr", GlobalDomainAccessController.INTERFACE_NAME, accessParticipantId, new ProviderQos(), System.currentTimeMillis(), Long.MAX_VALUE, "", new InProcessAddress());
    List<DiscoveryEntry> entries = new ArrayList<>();
    entries.add(discoveryEntry);
    entries.add(accessControlEntry);
    return objectMapper.writeValueAsString(entries);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) Version(joynr.types.Version) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ArrayList(java.util.ArrayList) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProviderQos(joynr.types.ProviderQos)

Example 24 with GlobalDiscoveryEntry

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

the class LocalDiscoveryTest method testRemoteGlobalDiscoveryEntries.

@SuppressWarnings("unchecked")
@Test
public void testRemoteGlobalDiscoveryEntries() {
    String testDomain = "testDomain";
    String interfaceName = testProxy.INTERFACE_NAME;
    final Collection<DiscoveryEntry> discoveryEntries = new HashSet<>();
    final List<GlobalDiscoveryEntry> globalDiscoveryEntries = new ArrayList<>();
    DiscoveryEntry discoveryEntry = new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantId", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId");
    discoveryEntries.add(discoveryEntry);
    globalDiscoveryEntries.add(CapabilityUtils.discoveryEntry2GlobalDiscoveryEntry(discoveryEntry, new MqttAddress()));
    when(globalDiscoveryEntryCacheMock.lookup(any(String[].class), eq(interfaceName), anyLong())).thenReturn(new HashSet<DiscoveryEntry>());
    Mockito.doAnswer(new Answer<Object>() {

        @SuppressWarnings("rawtypes")
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object[] arguments = invocation.getArguments();
            assert (arguments[0] instanceof Callback);
            ((Callback) arguments[0]).resolve((Object) globalDiscoveryEntries);
            return null;
        }
    }).when(globalCapabilitiesDirectoryClientMock).lookup(any(Callback.class), any(String[].class), eq(interfaceName), anyLong());
    ProxyBuilder<testProxy> proxyBuilder = runtime.getProxyBuilder(testDomain, testProxy.class);
    final Future<Void> future = new Future<Void>();
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.GLOBAL_ONLY);
    proxyBuilder.setDiscoveryQos(discoveryQos).build(new ProxyCreatedCallback<testProxy>() {

        @Override
        public void onProxyCreationFinished(testProxy result) {
            future.onSuccess(null);
        }

        @Override
        public void onProxyCreationError(JoynrRuntimeException error) {
            future.onFailure(error);
        }
    });
    try {
        future.get(5000);
        verify(joynrMessagingConnectorFactoryMock).create(anyString(), discoveryEntryWithMetaInfoArgumentCaptor.capture(), any(MessagingQos.class));
        assertDiscoveryEntryEqualsCaptured(discoveryEntry);
    } catch (Exception e) {
        Assert.fail("Unexpected exception from ProxyCreatedCallback: " + e);
    }
}
Also used : GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) MessagingQos(io.joynr.messaging.MessagingQos) HashSet(java.util.HashSet) MqttAddress(joynr.system.RoutingTypes.MqttAddress) DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) joynr.tests.testProxy(joynr.tests.testProxy) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Callback(io.joynr.proxy.Callback) ProxyCreatedCallback(io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Future(io.joynr.proxy.Future) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 25 with GlobalDiscoveryEntry

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

the class SerializationTest method serializeAndDeserializeGlobalDiscoveryEntryTest.

@Test
public void serializeAndDeserializeGlobalDiscoveryEntryTest() throws Exception {
    ProviderQos qos = new ProviderQos();
    String channelAddress = "channelId";
    final GlobalDiscoveryEntry[] capInfos = { new GlobalDiscoveryEntry(new Version(47, 11), "domain", "interface", "participantId", qos, System.currentTimeMillis(), expiryDateMs, publicKeyId, channelAddress) };
    String writeValueAsString = null;
    writeValueAsString = objectMapper.writeValueAsString(capInfos);
    System.err.println(writeValueAsString);
    assertTrue(writeValueAsString.startsWith("[{\"_typeName\":\"joynr.types.GlobalDiscoveryEntry\""));
    GlobalDiscoveryEntry[] readValue = objectMapper.readValue(writeValueAsString, GlobalDiscoveryEntry[].class);
    assertArrayEquals(capInfos, readValue);
    GlobalDiscoveryEntry globalDiscoveryEntry = new GlobalDiscoveryEntry(new Version(47, 11), "domain", "interface", "participantId", qos, System.currentTimeMillis(), expiryDateMs, publicKeyId, channelAddress);
    writeValueAsString = objectMapper.writeValueAsString(globalDiscoveryEntry);
    System.err.println(writeValueAsString);
    GlobalDiscoveryEntry readCapInfo = objectMapper.readValue(writeValueAsString, GlobalDiscoveryEntry.class);
    assertEquals(globalDiscoveryEntry, readCapInfo);
}
Also used : Version(joynr.types.Version) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Aggregations

GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)45 Test (org.junit.Test)28 DiscoveryEntry (joynr.types.DiscoveryEntry)21 ProviderQos (joynr.types.ProviderQos)20 Version (joynr.types.Version)19 Callback (io.joynr.proxy.Callback)15 Matchers.anyString (org.mockito.Matchers.anyString)14 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)12 ArrayList (java.util.ArrayList)12 MqttAddress (joynr.system.RoutingTypes.MqttAddress)9 DeferredVoid (io.joynr.provider.DeferredVoid)8 Address (joynr.system.RoutingTypes.Address)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)5 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)5 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)5 List (java.util.List)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 MessagingQos (io.joynr.messaging.MessagingQos)3 Promise (io.joynr.provider.Promise)3