use of joynr.types.Version 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);
}
use of joynr.types.Version 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.Version in project joynr by bmwcarit.
the class DiscoveryEntryStorePersistedTest method createDiscoveryEntry.
private GlobalDiscoveryEntryPersisted createDiscoveryEntry(String domain, String interfaceName, String participantId) throws Exception {
ProviderQos qos = new ProviderQos();
long lastSeenDateMs = 123L;
long expiryDateMs = Long.MAX_VALUE;
String publicKeyId = "publicKeyId";
Address address = new MqttAddress("brokerUri", "topic");
String addressSerialized = new ObjectMapper().writeValueAsString(address);
GlobalDiscoveryEntryPersisted discoveryEntry = new GlobalDiscoveryEntryPersisted(new Version(47, 11), domain, interfaceName, participantId, qos, lastSeenDateMs, expiryDateMs, publicKeyId, addressSerialized, "clusterControllerId");
return discoveryEntry;
}
use of joynr.types.Version 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.Version in project joynr by bmwcarit.
the class GlobalCapabilitiesDirectoryEjbTest method setup.
@Before
public void setup() throws NoSuchFieldException, IllegalAccessException {
Field field = CapabilityUtils.class.getDeclaredField("objectMapper");
field.setAccessible(true);
field.set(CapabilityUtils.class, new ObjectMapper());
testParticpantId = "participantId";
testGlobalDiscoveryEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), "domain", "interfaceName", testParticpantId, new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 1000L, "public key ID", new MqttAddress("tcp://mqttbroker:1883", TOPIC_NAME));
}
Aggregations