Search in sources :

Example 36 with DiscoveryQos

use of io.joynr.arbitration.DiscoveryQos 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 37 with DiscoveryQos

use of io.joynr.arbitration.DiscoveryQos in project joynr by bmwcarit.

the class LocalCapabilitiesDirectoryTest method testLookupMultipleDomainsGlobalOnly.

@SuppressWarnings("unchecked")
@Test
public void testLookupMultipleDomainsGlobalOnly() {
    String[] domains = new String[] { "domain1", "domain2" };
    String interfaceName = "interface1";
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.GLOBAL_ONLY);
    CapabilitiesCallback capabilitiesCallback = mock(CapabilitiesCallback.class);
    when(globalDiscoveryEntryCacheMock.lookup(eq(domains), eq(interfaceName), eq(discoveryQos.getCacheMaxAgeMs()))).thenReturn(Lists.<DiscoveryEntry>newArrayList());
    localCapabilitiesDirectory.lookup(domains, interfaceName, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient).lookup(any(Callback.class), argThat(Matchers.arrayContainingInAnyOrder(domains)), eq(interfaceName), eq(discoveryQos.getDiscoveryTimeoutMs()));
}
Also used : Callback(io.joynr.proxy.Callback) Matchers.anyString(org.mockito.Matchers.anyString) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) Test(org.junit.Test)

Example 38 with DiscoveryQos

use of io.joynr.arbitration.DiscoveryQos 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 39 with DiscoveryQos

use of io.joynr.arbitration.DiscoveryQos in project joynr by bmwcarit.

the class LocalCapabilitiesDirectoryTest method lookupWithScopeLocalThenGlobal.

@SuppressWarnings("unchecked")
@Test(timeout = 1000)
public void lookupWithScopeLocalThenGlobal() throws InterruptedException {
    List<GlobalDiscoveryEntry> caps = new ArrayList<GlobalDiscoveryEntry>();
    String domain1 = "domain1";
    String interfaceName1 = "interfaceName1";
    DiscoveryQos discoveryQos = new DiscoveryQos(30000, ArbitrationStrategy.HighestPriority, 1000, DiscoveryScope.LOCAL_THEN_GLOBAL);
    CapabilitiesCallback capabilitiesCallback = Mockito.mock(CapabilitiesCallback.class);
    Mockito.doAnswer(createAnswer(caps)).when(globalCapabilitiesClient).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(1)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(0)));
    verify(capabilitiesCallback, times(0)).processCapabilitiesReceived(argThat(hasNEntries(1)));
    // add local entry
    ProviderQos providerQos = new ProviderQos();
    providerQos.setScope(ProviderScope.LOCAL);
    DiscoveryEntry discoveryEntry = new DiscoveryEntry(new Version(47, 11), domain1, interfaceName1, "localParticipant", providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId);
    reset(localDiscoveryEntryStoreMock);
    when(localDiscoveryEntryStoreMock.lookup(eq(new String[] { domain1 }), eq(interfaceName1))).thenReturn(Lists.newArrayList(discoveryEntry));
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(1)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(0)));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(1)));
    // add global entry
    GlobalDiscoveryEntry capInfo = new GlobalDiscoveryEntry(new Version(47, 11), domain1, interfaceName1, "globalParticipant", new ProviderQos(), System.currentTimeMillis(), expiryDateMs, publicKeyId, channelAddressSerialized);
    caps.add(capInfo);
    Mockito.doAnswer(createAnswer(caps)).when(globalCapabilitiesClient).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(1)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    // now, another lookup call shall take the cached for the global cap call, and no longer call the global cap dir
    // (as long as the cache is not expired)
    reset(localDiscoveryEntryStoreMock);
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(2)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    // now, another lookup call shall take the cached for the global cap call, and no longer call the global cap dir
    // (as long as the cache is not expired)
    when(globalDiscoveryEntryCacheMock.lookup(eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getCacheMaxAgeMs()))).thenReturn(Lists.newArrayList((DiscoveryEntry) capInfo));
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(2)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    // and now, invalidate the existing cached global values, resulting in another call to glocalcapclient
    discoveryQos.setCacheMaxAgeMs(0);
    Thread.sleep(1);
    // now, another lookup call shall take the cached for the global cap call, and no longer call the global cap dir
    // (as long as the cache is not expired)
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(3)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    reset(globalCapabilitiesClient);
    reset(capabilitiesCallback);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Callback(io.joynr.proxy.Callback) Version(joynr.types.Version) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 40 with DiscoveryQos

use of io.joynr.arbitration.DiscoveryQos in project joynr by bmwcarit.

the class LocalCapabilitiesDirectoryTest method testLookupMultipleDomainsGlobalOnlyOneCached.

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

Aggregations

DiscoveryQos (io.joynr.arbitration.DiscoveryQos)46 MessagingQos (io.joynr.messaging.MessagingQos)23 Test (org.junit.Test)23 ProviderQos (joynr.types.ProviderQos)20 Matchers.anyString (org.mockito.Matchers.anyString)19 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)16 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)14 DiscoveryEntry (joynr.types.DiscoveryEntry)14 Callback (io.joynr.proxy.Callback)11 joynr.tests.testProxy (joynr.tests.testProxy)11 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)10 Properties (java.util.Properties)9 Version (joynr.types.Version)9 ArrayList (java.util.ArrayList)8 Before (org.junit.Before)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 Future (io.joynr.proxy.Future)5 ProxyCreatedCallback (io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback)5 HashSet (java.util.HashSet)5 IOException (java.io.IOException)4