Search in sources :

Example 56 with DiscoveryEntryWithMetaInfo

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

the class DummyCapabilitiesDirectory method lookup.

@Override
public Promise<Lookup2Deferred> lookup(String participantId) {
    Lookup2Deferred deferred = new Lookup2Deferred();
    DiscoveryEntryWithMetaInfo discoveryEntry = lookup(participantId, DiscoveryQos.NO_FILTER);
    deferred.resolve(discoveryEntry);
    return new Promise<Lookup2Deferred>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo)

Example 57 with DiscoveryEntryWithMetaInfo

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

the class DummyCapabilitiesDirectory method lookup.

@Override
public Promise<Lookup1Deferred> lookup(String[] domains, String interfaceName, joynr.types.DiscoveryQos discoveryQos) {
    final Lookup1Deferred deferred = new Lookup1Deferred();
    CapabilitiesCallback callback = new CapabilitiesCallback() {

        @Override
        public void processCapabilitiesReceived(@CheckForNull Collection<DiscoveryEntryWithMetaInfo> capabilities) {
            if (capabilities != null) {
                deferred.resolve(capabilities.toArray(new DiscoveryEntryWithMetaInfo[0]));
            } else {
                deferred.reject(new ProviderRuntimeException("Received capabilities list was null"));
            }
        }

        @Override
        public void onError(Throwable e) {
            deferred.reject(new ProviderRuntimeException(e.toString()));
        }
    };
    DiscoveryScope discoveryScope = DiscoveryScope.valueOf(discoveryQos.getDiscoveryScope().name());
    lookup(domains, interfaceName, new DiscoveryQos(30000, ArbitrationStrategy.NotSet, discoveryQos.getCacheMaxAge(), discoveryScope), callback);
    return new Promise<Lookup1Deferred>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DiscoveryScope(io.joynr.arbitration.DiscoveryScope) CheckForNull(javax.annotation.CheckForNull) Collection(java.util.Collection) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos)

Example 58 with DiscoveryEntryWithMetaInfo

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

the class LocalCapabilitiesDirectoryTest method lookupByParticipantIdWithScopeLocalSync.

@Test(timeout = 1000)
public void lookupByParticipantIdWithScopeLocalSync() throws InterruptedException {
    String domain1 = "domain1";
    String interfaceName1 = "interfaceName1";
    String participantId1 = "participantId1";
    DiscoveryQos discoveryQos = new DiscoveryQos(30000, ArbitrationStrategy.HighestPriority, 10000, DiscoveryScope.LOCAL_ONLY);
    // add local entry
    ProviderQos providerQos = new ProviderQos();
    providerQos.setScope(ProviderScope.LOCAL);
    DiscoveryEntry discoveryEntry = new DiscoveryEntry(new Version(47, 11), domain1, interfaceName1, participantId1, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId);
    DiscoveryEntryWithMetaInfo expectedDiscoveryEntry = CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(true, discoveryEntry);
    when(localDiscoveryEntryStoreMock.lookup(eq(participantId1), eq(discoveryQos.getCacheMaxAgeMs()))).thenReturn(discoveryEntry);
    DiscoveryEntry retrievedCapabilityEntry = localCapabilitiesDirectory.lookup(participantId1, discoveryQos);
    assertEquals(expectedDiscoveryEntry, retrievedCapabilityEntry);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Version(joynr.types.Version) Matchers.anyString(org.mockito.Matchers.anyString) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 59 with DiscoveryEntryWithMetaInfo

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

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

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