Search in sources :

Example 41 with GlobalDiscoveryEntry

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

the class LocalCapabilitiesDirectoryTest method testLookupByParticipantId_cachedEntry_DiscoveryEntryWithMetaInfoContainsExpectedIsLocalValue.

@Test
public void testLookupByParticipantId_cachedEntry_DiscoveryEntryWithMetaInfoContainsExpectedIsLocalValue() {
    String participantId = "participantId";
    String interfaceName = "interfaceName";
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_THEN_GLOBAL);
    // cached global DiscoveryEntry
    String globalDomain = "globalDomain";
    GlobalDiscoveryEntry cachedGlobalEntry = new GlobalDiscoveryEntry();
    cachedGlobalEntry.setDomain(globalDomain);
    cachedGlobalEntry.setInterfaceName(interfaceName);
    cachedGlobalEntry.setParticipantId(participantId);
    when(globalDiscoveryEntryCacheMock.lookup(eq(participantId), eq(discoveryQos.getCacheMaxAgeMs()))).thenReturn(cachedGlobalEntry);
    DiscoveryEntryWithMetaInfo capturedCachedGlobalEntry = localCapabilitiesDirectory.lookup(participantId, discoveryQos);
    DiscoveryEntryWithMetaInfo cachedGlobalEntryWithMetaInfo = CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(false, cachedGlobalEntry);
    assertEquals(cachedGlobalEntryWithMetaInfo, capturedCachedGlobalEntry);
}
Also used : GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Matchers.anyString(org.mockito.Matchers.anyString) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) Test(org.junit.Test)

Example 42 with GlobalDiscoveryEntry

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

the class LocalCapabilitiesDirectoryTest method testLookup_DiscoveryEntriesWithMetaInfoContainExpectedIsLocalValue.

@Test
public void testLookup_DiscoveryEntriesWithMetaInfoContainExpectedIsLocalValue() {
    String globalDomain = "globaldomain";
    String remoteGlobalDomain = "remoteglobaldomain";
    String[] domains = new String[] { "localdomain", globalDomain, remoteGlobalDomain };
    String interfaceName = "interfaceName";
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_THEN_GLOBAL);
    CapabilitiesCallback capabilitiesCallback = mock(CapabilitiesCallback.class);
    // local DiscoveryEntry
    DiscoveryEntry localEntry = new DiscoveryEntry();
    localEntry.setDomain(domains[0]);
    when(localDiscoveryEntryStoreMock.lookup(eq(domains), eq(interfaceName))).thenReturn(Lists.newArrayList(localEntry));
    // cached global DiscoveryEntry
    GlobalDiscoveryEntry cachedGlobalEntry = new GlobalDiscoveryEntry();
    cachedGlobalEntry.setDomain(globalDomain);
    Collection<DiscoveryEntry> cachedEntries = Lists.newArrayList((DiscoveryEntry) cachedGlobalEntry);
    when(globalDiscoveryEntryCacheMock.lookup(eq(domains), eq(interfaceName), eq(discoveryQos.getCacheMaxAgeMs()))).thenReturn(cachedEntries);
    // remote global DiscoveryEntry
    final GlobalDiscoveryEntry remoteGlobalEntry = new GlobalDiscoveryEntry(new Version(0, 0), remoteGlobalDomain, interfaceName, "participantIdRemote", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 10000L, "publicKeyId", channelAddressSerialized);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            Callback<List<GlobalDiscoveryEntry>> callback = (Callback<List<GlobalDiscoveryEntry>>) invocation.getArguments()[0];
            callback.onSuccess(Lists.newArrayList(remoteGlobalEntry));
            return null;
        }
    }).when(globalCapabilitiesClient).lookup(any(Callback.class), eq(new String[] { remoteGlobalDomain }), eq(interfaceName), anyLong());
    localCapabilitiesDirectory.lookup(domains, interfaceName, discoveryQos, capabilitiesCallback);
    verify(capabilitiesCallback).processCapabilitiesReceived(capabilitiesCaptor.capture());
    Collection<DiscoveryEntryWithMetaInfo> captured = capabilitiesCaptor.getValue();
    assertNotNull(captured);
    assertEquals(3, captured.size());
    DiscoveryEntryWithMetaInfo localEntryWithMetaInfo = CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(true, localEntry);
    assertTrue(captured.contains(localEntryWithMetaInfo));
    DiscoveryEntryWithMetaInfo cachedGlobalEntryWithMetaInfo = CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(false, cachedGlobalEntry);
    assertTrue(captured.contains(cachedGlobalEntryWithMetaInfo));
    DiscoveryEntryWithMetaInfo remoteGlobalEntryWithMetaInfo = CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(false, remoteGlobalEntry);
    assertTrue(captured.contains(remoteGlobalEntryWithMetaInfo));
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Matchers.anyString(org.mockito.Matchers.anyString) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) Callback(io.joynr.proxy.Callback) Version(joynr.types.Version) InvocationOnMock(org.mockito.invocation.InvocationOnMock) List(java.util.List) ArrayList(java.util.ArrayList) DeferredVoid(io.joynr.provider.DeferredVoid) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 43 with GlobalDiscoveryEntry

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

the class LocalCapabilitiesDirectoryTest method testLookupByParticipantId_globalEntry_DiscoveryEntryWithMetaInfoContainsExpectedIsLocalValue.

@Test
public void testLookupByParticipantId_globalEntry_DiscoveryEntryWithMetaInfoContainsExpectedIsLocalValue() {
    String participantId = "participantId";
    String interfaceName = "interfaceName";
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_THEN_GLOBAL);
    // remote global DiscoveryEntry
    String remoteGlobalDomain = "remoteglobaldomain";
    final GlobalDiscoveryEntry remoteGlobalEntry = new GlobalDiscoveryEntry(new Version(0, 0), remoteGlobalDomain, interfaceName, participantId, new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 10000L, "publicKeyId", channelAddressSerialized);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            Callback<GlobalDiscoveryEntry> callback = (Callback<GlobalDiscoveryEntry>) invocation.getArguments()[0];
            callback.onSuccess(remoteGlobalEntry);
            return null;
        }
    }).when(globalCapabilitiesClient).lookup(any(Callback.class), eq(participantId), anyLong());
    DiscoveryEntryWithMetaInfo capturedRemoteGlobalEntry = localCapabilitiesDirectory.lookup(participantId, discoveryQos);
    DiscoveryEntryWithMetaInfo remoteGlobalEntryWithMetaInfo = CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(false, remoteGlobalEntry);
    assertEquals(remoteGlobalEntryWithMetaInfo, capturedRemoteGlobalEntry);
}
Also used : Callback(io.joynr.proxy.Callback) Version(joynr.types.Version) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Matchers.anyString(org.mockito.Matchers.anyString) DeferredVoid(io.joynr.provider.DeferredVoid) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 44 with GlobalDiscoveryEntry

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

the class LocalCapabilitiesDirectoryTest method testLookupMultipleDomainsGlobalOnlyAllCached.

@SuppressWarnings("unchecked")
@Test
public void testLookupMultipleDomainsGlobalOnlyAllCached() {
    String[] domains = new String[] { "domain1", "domain2" };
    String interfaceName = "interface1";
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.GLOBAL_ONLY);
    CapabilitiesCallback capabilitiesCallback = mock(CapabilitiesCallback.class);
    List<DiscoveryEntry> entries = new ArrayList<>();
    for (String domain : domains) {
        GlobalDiscoveryEntry entry = new GlobalDiscoveryEntry();
        entry.setDomain(domain);
        entries.add(entry);
    }
    when(globalDiscoveryEntryCacheMock.lookup(eq(domains), eq(interfaceName), eq(discoveryQos.getCacheMaxAgeMs()))).thenReturn(entries);
    localCapabilitiesDirectory.lookup(domains, interfaceName, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(0)).lookup(any(Callback.class), argThat(Matchers.arrayContainingInAnyOrder(domains)), eq(interfaceName), eq(discoveryQos.getDiscoveryTimeoutMs()));
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Callback(io.joynr.proxy.Callback) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) Test(org.junit.Test)

Example 45 with GlobalDiscoveryEntry

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

the class LocalCapabilitiesDirectoryImpl method registerGlobal.

private void registerGlobal(final DiscoveryEntry discoveryEntry, final DeferredVoid deferred) {
    synchronized (globalAddressLock) {
        try {
            globalAddress = globalAddressProvider.get();
        } catch (Exception e) {
            logger.debug("error getting global address", e);
            globalAddress = null;
        }
        if (globalAddress == null) {
            queuedDiscoveryEntries.add(new QueuedDiscoveryEntry(discoveryEntry, deferred));
            globalAddressProvider.registerGlobalAddressesReadyListener(this);
            return;
        }
    }
    final GlobalDiscoveryEntry globalDiscoveryEntry = CapabilityUtils.discoveryEntry2GlobalDiscoveryEntry(discoveryEntry, globalAddress);
    if (globalDiscoveryEntry != null) {
        logger.info("starting global registration for " + globalDiscoveryEntry.getDomain() + " : " + globalDiscoveryEntry.getInterfaceName());
        globalCapabilitiesDirectoryClient.add(new Callback<Void>() {

            @Override
            public void onSuccess(Void nothing) {
                logger.info("global registration for " + globalDiscoveryEntry.getDomain() + " : " + globalDiscoveryEntry.getInterfaceName() + " completed");
                deferred.resolve();
                globalDiscoveryEntryCache.add(CapabilityUtils.discoveryEntry2GlobalDiscoveryEntry(discoveryEntry, globalAddress));
            }

            @Override
            public void onFailure(JoynrRuntimeException exception) {
                deferred.reject(new ProviderRuntimeException(exception.toString()));
            }
        }, globalDiscoveryEntry);
    }
}
Also used : GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) DeferredVoid(io.joynr.provider.DeferredVoid) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) DiscoveryException(io.joynr.exceptions.DiscoveryException) ApplicationException(joynr.exceptions.ApplicationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

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