Search in sources :

Example 1 with DiscoveryQos

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

the class LocalCapabilitiesDirectoryTest method testLookupMultipleDomainsLocalThenGlobal.

@SuppressWarnings("unchecked")
@Test
public void testLookupMultipleDomainsLocalThenGlobal() {
    String[] domains = new String[] { "domain1", "domain2", "domain3" };
    String interfaceName = "interface1";
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_THEN_GLOBAL);
    discoveryQos.setCacheMaxAgeMs(ONE_DAY_IN_MS);
    CapabilitiesCallback capabilitiesCallback = mock(CapabilitiesCallback.class);
    DiscoveryEntry localEntry = new DiscoveryEntry();
    localEntry.setDomain("domain1");
    when(localDiscoveryEntryStoreMock.lookup(eq(domains), eq(interfaceName))).thenReturn(Lists.newArrayList(localEntry));
    GlobalDiscoveryEntry globalEntry = new GlobalDiscoveryEntry();
    globalEntry.setDomain("domain2");
    Collection<DiscoveryEntry> entries = Lists.newArrayList((DiscoveryEntry) globalEntry);
    when(globalDiscoveryEntryCacheMock.lookup(eq(domains), eq(interfaceName), eq(discoveryQos.getCacheMaxAgeMs()))).thenReturn(entries);
    final GlobalDiscoveryEntry remoteGlobalEntry = new GlobalDiscoveryEntry(new Version(0, 0), "domain3", 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), Mockito.<String[]>any(), anyString(), anyLong());
    localCapabilitiesDirectory.lookup(domains, interfaceName, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient).lookup(any(Callback.class), argThat(Matchers.arrayContainingInAnyOrder(new String[] { "domain3" })), eq(interfaceName), eq(discoveryQos.getDiscoveryTimeoutMs()));
    verify(capabilitiesCallback).processCapabilitiesReceived(capabilitiesCaptor.capture());
    Collection<DiscoveryEntry> captured = CapabilityUtils.convertToDiscoveryEntrySet(capabilitiesCaptor.getValue());
    assertNotNull(captured);
    assertEquals(3, captured.size());
    assertTrue(captured.contains(localEntry));
    assertTrue(captured.contains(new DiscoveryEntry(globalEntry)));
    assertTrue(captured.contains(new DiscoveryEntry(remoteGlobalEntry)));
}
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) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 2 with DiscoveryQos

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

the class LocalCapabilitiesDirectoryTest method testLookupMultipleDomainsLocalOnly.

@Test
public void testLookupMultipleDomainsLocalOnly() {
    String[] domains = new String[] { "domain1", "domain2" };
    String interfaceName = "interface1";
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_ONLY);
    CapabilitiesCallback capabilitiesCallback = mock(CapabilitiesCallback.class);
    Collection<DiscoveryEntry> entries = Lists.newArrayList(new DiscoveryEntry(new Version(0, 0), "domain1", interfaceName, "participantId1", new ProviderQos(), System.currentTimeMillis(), expiryDateMs, interfaceName), new DiscoveryEntry(new Version(0, 0), "domain2", interfaceName, "participantId2", new ProviderQos(), System.currentTimeMillis(), expiryDateMs, interfaceName));
    when(localDiscoveryEntryStoreMock.lookup(eq(domains), eq(interfaceName))).thenReturn(entries);
    localCapabilitiesDirectory.lookup(domains, interfaceName, discoveryQos, capabilitiesCallback);
    verify(capabilitiesCallback).processCapabilitiesReceived(capabilitiesCaptor.capture());
    Collection<DiscoveryEntry> discoveredEntries = CapabilityUtils.convertToDiscoveryEntryList(capabilitiesCaptor.getValue());
    assertNotNull(discoveredEntries);
    assertEquals(2, discoveredEntries.size());
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Version(joynr.types.Version) Matchers.anyString(org.mockito.Matchers.anyString) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 3 with DiscoveryQos

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

the class LocalCapabilitiesDirectoryTest method lookupWithScopeGlobalOnly.

@SuppressWarnings("unchecked")
@Test(timeout = 1000)
public void lookupWithScopeGlobalOnly() throws InterruptedException {
    List<GlobalDiscoveryEntry> caps = new ArrayList<GlobalDiscoveryEntry>();
    String domain1 = "domain1";
    String interfaceName1 = "interfaceName1";
    DiscoveryQos discoveryQos = new DiscoveryQos(30000, ArbitrationStrategy.HighestPriority, 1000, DiscoveryScope.GLOBAL_ONLY);
    CapabilitiesCallback capabilitiesCallback = mock(CapabilitiesCallback.class);
    when(globalDiscoveryEntryCacheMock.lookup(eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getCacheMaxAgeMs()))).thenReturn(new ArrayList<DiscoveryEntry>());
    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), any(String[].class), any(String.class), eq(discoveryQos.getDiscoveryTimeoutMs()));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(0)));
    verify(capabilitiesCallback, times(0)).processCapabilitiesReceived(argThat(hasNEntries(1)));
    reset(capabilitiesCallback);
    // 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);
    localCapabilitiesDirectory.add(discoveryEntry);
    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()));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(0)));
    verify(capabilitiesCallback, times(0)).processCapabilitiesReceived(argThat(hasNEntries(1)));
    reset(capabilitiesCallback);
    // even deleting local cap entries shall have no effect, the global cap dir shall be invoked
    localCapabilitiesDirectory.remove(discoveryEntry);
    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()));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(0)));
    verify(capabilitiesCallback, times(0)).processCapabilitiesReceived(argThat(hasNEntries(1)));
    reset(capabilitiesCallback);
    // add global entry
    GlobalDiscoveryEntry capInfo = new GlobalDiscoveryEntry(new Version(47, 11), domain1, interfaceName1, "globalParticipant", new ProviderQos(), System.currentTimeMillis(), expiryDateMs, publicKeyId, channelAddressSerialized);
    caps.add(capInfo);
    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(4)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    verify(capabilitiesCallback, times(0)).processCapabilitiesReceived(argThat(hasNEntries(0)));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(1)));
    reset(capabilitiesCallback);
    // 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(globalDiscoveryEntryCacheMock);
    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(4)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    verify(capabilitiesCallback, times(0)).processCapabilitiesReceived(argThat(hasNEntries(0)));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(1)));
    reset(capabilitiesCallback);
    // 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 call the globalCapabilitiesClient, as the global cap dir is expired
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(5)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    verify(capabilitiesCallback, times(0)).processCapabilitiesReceived(argThat(hasNEntries(0)));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(1)));
    reset(capabilitiesCallback);
    reset(globalCapabilitiesClient);
}
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 4 with DiscoveryQos

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

the class LocalCapabilitiesDirectoryTest method lookupWithScopeLocalAndGlobal.

@SuppressWarnings("unchecked")
@Test(timeout = 1000)
public void lookupWithScopeLocalAndGlobal() throws InterruptedException {
    List<GlobalDiscoveryEntry> caps = new ArrayList<GlobalDiscoveryEntry>();
    String domain1 = "domain1";
    String interfaceName1 = "interfaceName1";
    DiscoveryQos discoveryQos = new DiscoveryQos(30000, ArbitrationStrategy.HighestPriority, 500, DiscoveryScope.LOCAL_AND_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);
    when(localDiscoveryEntryStoreMock.lookup(eq(new String[] { domain1 }), eq(interfaceName1))).thenReturn(Lists.newArrayList(discoveryEntry));
    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()));
    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(3)).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(3)).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(4)).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 5 with DiscoveryQos

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

the class LocalCapabilitiesDirectoryTest method testLookupByParticipantId_localEntry_DiscoveryEntryWithMetaInfoContainsExpectedIsLocalValue.

@Test
public void testLookupByParticipantId_localEntry_DiscoveryEntryWithMetaInfoContainsExpectedIsLocalValue() {
    String participantId = "participantId";
    String interfaceName = "interfaceName";
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_THEN_GLOBAL);
    // local DiscoveryEntry
    String localDomain = "localDomain";
    DiscoveryEntry localEntry = new DiscoveryEntry();
    localEntry.setDomain(localDomain);
    localEntry.setInterfaceName(interfaceName);
    localEntry.setParticipantId(participantId);
    when(localDiscoveryEntryStoreMock.lookup(eq(participantId), eq(discoveryQos.getCacheMaxAgeMs()))).thenReturn(localEntry);
    DiscoveryEntryWithMetaInfo capturedLocalEntry = localCapabilitiesDirectory.lookup(participantId, discoveryQos);
    DiscoveryEntryWithMetaInfo localEntryWithMetaInfo = CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(true, localEntry);
    assertEquals(localEntryWithMetaInfo, capturedLocalEntry);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Matchers.anyString(org.mockito.Matchers.anyString) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) 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