use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.
the class DiscoveryEntryStorePersistedTest method testVersionPersistedAndRetrieved.
@Test
public void testVersionPersistedAndRetrieved() throws Exception {
GlobalDiscoveryEntryPersisted discoveryEntry = createDiscoveryEntry("domain", "interfaceName", "participantId");
logger.info("Discovery entry: " + discoveryEntry);
store.add(discoveryEntry);
entityManager.clear();
Collection<DiscoveryEntry> lookupResult = store.lookup(new String[] { discoveryEntry.getDomain() }, discoveryEntry.getInterfaceName(), CACHE_MAX_AGE);
assertNotNull(lookupResult);
assertEquals(1, lookupResult.size());
DiscoveryEntry persistedEntry = lookupResult.iterator().next();
logger.info("Persisted entry: " + persistedEntry);
assertNotEquals(System.identityHashCode(discoveryEntry), System.identityHashCode(persistedEntry));
assertNotNull(persistedEntry);
assertNotNull(persistedEntry.getProviderVersion());
assertEquals(discoveryEntry.getProviderVersion().getMajorVersion(), persistedEntry.getProviderVersion().getMajorVersion());
assertEquals(discoveryEntry.getProviderVersion().getMinorVersion(), persistedEntry.getProviderVersion().getMinorVersion());
}
use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.
the class DiscoveryEntryStorePersisted method touch.
@Override
public void touch(String clusterControllerId) {
String query = "from GlobalDiscoveryEntryPersisted where clusterControllerId=:clusterControllerId";
EntityTransaction transaction = entityManager.getTransaction();
try {
transaction.begin();
@SuppressWarnings("unchecked") List<DiscoveryEntry> capabilitiesList = entityManager.createQuery(query).setParameter("clusterControllerId", clusterControllerId).getResultList();
for (DiscoveryEntry discoveryEntry : capabilitiesList) {
logger.trace(" --> BEFORE entry {} last seen {}", discoveryEntry.getParticipantId(), discoveryEntry.getLastSeenDateMs());
((GlobalDiscoveryEntryPersisted) discoveryEntry).setLastSeenDateMs(System.currentTimeMillis());
logger.trace(" --> AFTER entry {} last seen {}", discoveryEntry.getParticipantId(), discoveryEntry.getLastSeenDateMs());
}
transaction.commit();
} catch (RuntimeException e) {
if (transaction.isActive()) {
transaction.rollback();
}
logger.error("Error updating last seen date for cluster controller with ID {}", clusterControllerId, e);
}
}
use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.
the class CapabilitiesDirectoryImpl method lookup.
@Override
public Promise<Lookup2Deferred> lookup(String forParticipantId) {
Lookup2Deferred deferred = new Lookup2Deferred();
logger.debug("Searching discovery entries for participantId: {}", forParticipantId);
DiscoveryEntry discoveryEntry = discoveryEntryStore.lookup(forParticipantId, DiscoveryQos.NO_FILTER.getCacheMaxAgeMs());
if (discoveryEntry == null) {
deferred.resolve(null);
} else {
deferred.resolve((GlobalDiscoveryEntry) discoveryEntry);
}
return new Promise<Lookup2Deferred>(deferred);
}
use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.
the class LocalDiscoveryAggregatorTest method passesUnknownEntry.
@SuppressWarnings("unchecked")
@Test
public void passesUnknownEntry() {
DiscoveryEntry discoveryEntry = new DiscoveryEntry(new Version(0, 0), "anyDomain", "anyInterface", "anyParticipant", new ProviderQos(), System.currentTimeMillis(), expiryDateMs, publicKeyId);
localDiscoveryAggregator.add(addCallback, discoveryEntry);
verify(discoveryProxyMock, times(1)).add(any(Callback.class), eq(discoveryEntry));
}
use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.
the class LocalDiscoveryAggregatorTest method findsProvisionedEntryForMultipleDomains.
@SuppressWarnings("unchecked")
@Test
public void findsProvisionedEntryForMultipleDomains() throws Exception {
discoveryProviderEntries = new DiscoveryEntryWithMetaInfo[] { anotherDiscoveryProviderEntry };
allDomains = new String[] { systemServicesDomain, anotherDomain };
String[] missingDomains = new String[] { anotherDomain };
DiscoveryQos discoveryQos = new DiscoveryQos();
discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_ONLY);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
Callback<DiscoveryEntryWithMetaInfo[]> callback = (Callback<DiscoveryEntryWithMetaInfo[]>) invocation.getArguments()[0];
callback.onSuccess(discoveryProviderEntries);
return null;
}
}).when(discoveryProxyMock).lookup(any(Callback.class), any(String[].class), anyString(), any(DiscoveryQos.class));
Future<DiscoveryEntryWithMetaInfo[]> discoveryEntriesFuture = localDiscoveryAggregator.lookup(lookupCallback, allDomains, Discovery.INTERFACE_NAME, discoveryQos);
assertNotNull(discoveryEntriesFuture);
DiscoveryEntry[] result = discoveryEntriesFuture.get();
logger.info("Got discovery entries: " + Arrays.toString(result));
assertNotNull(result);
assertEquals(2, result.length);
assertTrue(containsByInterfaceDomain(result, discoveryProviderEntry.getInterfaceName(), discoveryProviderEntry.getDomain()));
assertTrue(containsByInterfaceDomain(result, anotherDiscoveryProviderEntry.getInterfaceName(), anotherDiscoveryProviderEntry.getDomain()));
verify(discoveryProxyMock).lookup(any(Callback.class), eq(missingDomains), eq(Discovery.INTERFACE_NAME), eq(discoveryQos));
}
Aggregations