use of joynr.types.GlobalDiscoveryEntry 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);
}
use of joynr.types.GlobalDiscoveryEntry in project joynr by bmwcarit.
the class LocalCapabilitiesDirectoryImpl method registerIncomingEndpoints.
private void registerIncomingEndpoints(Collection<GlobalDiscoveryEntry> caps) {
for (GlobalDiscoveryEntry ce : caps) {
// TODO when are entries purged from the messagingEndpointDirectory?
if (ce.getParticipantId() != null && ce.getAddress() != null) {
Address address = CapabilityUtils.getAddressFromGlobalDiscoveryEntry(ce);
final boolean isGloballyVisible = (ce.getQos().getScope() == ProviderScope.GLOBAL);
final boolean isSticky = false;
final long expiryDateMs = Long.MAX_VALUE;
// Always trust the discovery directory.
final boolean allowUpdate = true;
messageRouter.addNextHop(ce.getParticipantId(), address, isGloballyVisible, expiryDateMs, isSticky, allowUpdate);
}
}
}
use of joynr.types.GlobalDiscoveryEntry in project joynr by bmwcarit.
the class CapabilitiesDirectoryTest method setUp.
@Before
public void setUp() throws Exception {
channelAddresSerialized = new ObjectMapper().writeValueAsString(channelAddres);
String participantId1 = "testParticipantId1_" + UUID.randomUUID().toString();
String participantId2 = "testParticipantId2_" + UUID.randomUUID().toString();
String participantId3 = "testParticipantId3_" + UUID.randomUUID().toString();
String publicKeyId = "publicKeyId";
long lastSeenDateMs = System.currentTimeMillis();
long expiryDateMs = System.currentTimeMillis() + ONE_DAY_IN_MS;
disoveryEntry1 = new GlobalDiscoveryEntry(new Version(47, 11), domain, interface1, participantId1, providerQos, lastSeenDateMs, expiryDateMs, publicKeyId, channelAddresSerialized);
discoveryEntry2 = new GlobalDiscoveryEntry(new Version(47, 11), domain, interface2, participantId2, providerQos, lastSeenDateMs, expiryDateMs, publicKeyId, channelAddresSerialized);
dicoveryEntry3 = new GlobalDiscoveryEntry(new Version(47, 11), domain, interface3, participantId3, providerQos, lastSeenDateMs, expiryDateMs, publicKeyId, channelAddresSerialized);
}
use of joynr.types.GlobalDiscoveryEntry in project joynr by bmwcarit.
the class CapabilitiesDirectoryTest method registerMultipleCapabilitiesAsArray.
@Test
public void registerMultipleCapabilitiesAsArray() throws InterruptedException {
GlobalDiscoveryEntry[] interfaces2And3 = { discoveryEntry2, dicoveryEntry3 };
capabilitiesDirectory.add(interfaces2And3);
PromiseKeeper lookupCapInfo2 = new PromiseKeeper();
capabilitiesDirectory.lookup(new String[] { domain }, interface2).then(lookupCapInfo2);
assertDiscoveryEntriesEqual(new GlobalDiscoveryEntry[] { discoveryEntry2 }, (GlobalDiscoveryEntry[]) lookupCapInfo2.getValues()[0]);
PromiseKeeper lookupCapInfo3 = new PromiseKeeper();
capabilitiesDirectory.lookup(new String[] { domain }, interface3).then(lookupCapInfo3);
GlobalDiscoveryEntry[] passedDiscoveryEntries = (GlobalDiscoveryEntry[]) lookupCapInfo3.getValues()[0];
assertDiscoveryEntriesEqual(new GlobalDiscoveryEntry[] { dicoveryEntry3 }, passedDiscoveryEntries);
}
use of joynr.types.GlobalDiscoveryEntry in project joynr by bmwcarit.
the class GlobalCapabilitiesDirectoryEjb method lookup.
@Override
public GlobalDiscoveryEntry lookup(String participantId) {
logger.debug("Looking up global discovery entry for participant ID {}", participantId);
GlobalDiscoveryEntryPersisted queryResult = entityManager.find(GlobalDiscoveryEntryPersisted.class, participantId);
logger.debug("Found entry {}", queryResult);
return queryResult == null ? null : new GlobalDiscoveryEntry(queryResult);
}
Aggregations