use of io.joynr.arbitration.DiscoveryQos 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);
}
use of io.joynr.arbitration.DiscoveryQos 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 io.joynr.arbitration.DiscoveryQos 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 io.joynr.arbitration.DiscoveryQos 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()));
}
use of io.joynr.arbitration.DiscoveryQos in project joynr by bmwcarit.
the class LocalCapabilitiesDirectoryImpl 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.reject(new ProviderRuntimeException("Received capablities collection was null"));
} else {
deferred.resolve(capabilities.toArray(new DiscoveryEntryWithMetaInfo[capabilities.size()]));
}
}
@Override
public void onError(Throwable e) {
deferred.reject(new ProviderRuntimeException(e.toString()));
}
};
DiscoveryScope discoveryScope = DiscoveryScope.valueOf(discoveryQos.getDiscoveryScope().name());
lookup(domains, interfaceName, new DiscoveryQos(discoveryQos.getDiscoveryTimeout(), defaultDiscoveryRetryInterval, ArbitrationStrategy.NotSet, discoveryQos.getCacheMaxAge(), discoveryScope), callback);
return new Promise<>(deferred);
}
Aggregations