use of joynr.types.Version 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);
}
use of joynr.types.Version 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);
}
use of joynr.types.Version 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));
}
use of joynr.types.Version 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);
}
use of joynr.types.Version in project joynr by bmwcarit.
the class DiscoveryEntryVersionFilter method filter.
/**
* Reduces the passed in set of {@link DiscoveryEntry discovery entries} by
* removing all of those entries which are incompatible with the specified
* caller {@link Version}.
*
* @param callerVersion the version of the caller. Must not be <code>null</code>.
* @param discoveryEntries the discovery entries which are to be filtered by versions.
* Must not be <code>null</code>.
* @param discoveredVersions a container into which the method will write all
* versions it comes across during the filtering keyed by the domain for which the version was found.
* Mainly provided so that the iteration only occurs once.
* If <code>null</code>, then it is ignored.
*
* @return the filtered discovery entry set.
*/
public Set<DiscoveryEntryWithMetaInfo> filter(Version callerVersion, Set<DiscoveryEntryWithMetaInfo> discoveryEntries, Map<String, Set<Version>> discoveredVersions) {
if (callerVersion == null || discoveryEntries == null) {
throw new IllegalArgumentException(String.format("Neither callerVersion (%s) nor discoveryEntries (%s) can be null.", callerVersion, discoveryEntries));
}
Iterator<DiscoveryEntryWithMetaInfo> iterator = discoveryEntries.iterator();
while (iterator.hasNext()) {
DiscoveryEntry discoveryEntry = iterator.next();
if (discoveredVersions != null) {
Set<Version> versionsByDomain = discoveredVersions.get(discoveryEntry.getDomain());
if (versionsByDomain == null) {
versionsByDomain = new HashSet<>();
discoveredVersions.put(discoveryEntry.getDomain(), versionsByDomain);
}
versionsByDomain.add(discoveryEntry.getProviderVersion());
}
if (!versionCompatibilityChecker.check(callerVersion, discoveryEntry.getProviderVersion())) {
iterator.remove();
}
}
return discoveryEntries;
}
Aggregations