Search in sources :

Example 6 with GlobalDiscoveryEntry

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);
}
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 7 with GlobalDiscoveryEntry

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);
        }
    }
}
Also used : Address(joynr.system.RoutingTypes.Address) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry)

Example 8 with GlobalDiscoveryEntry

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);
}
Also used : Version(joynr.types.Version) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 9 with GlobalDiscoveryEntry

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);
}
Also used : GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) PromiseKeeper(io.joynr.provider.PromiseKeeper) Test(org.junit.Test)

Example 10 with GlobalDiscoveryEntry

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);
}
Also used : GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) GlobalDiscoveryEntryPersisted(io.joynr.capabilities.GlobalDiscoveryEntryPersisted)

Aggregations

GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)45 Test (org.junit.Test)28 DiscoveryEntry (joynr.types.DiscoveryEntry)21 ProviderQos (joynr.types.ProviderQos)20 Version (joynr.types.Version)19 Callback (io.joynr.proxy.Callback)15 Matchers.anyString (org.mockito.Matchers.anyString)14 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)12 ArrayList (java.util.ArrayList)12 MqttAddress (joynr.system.RoutingTypes.MqttAddress)9 DeferredVoid (io.joynr.provider.DeferredVoid)8 Address (joynr.system.RoutingTypes.Address)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)5 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)5 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)5 List (java.util.List)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 MessagingQos (io.joynr.messaging.MessagingQos)3 Promise (io.joynr.provider.Promise)3