Search in sources :

Example 11 with DiscoveryEntry

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

Example 12 with DiscoveryEntry

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);
    }
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) DiscoveryEntry(joynr.types.DiscoveryEntry)

Example 13 with DiscoveryEntry

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

Example 14 with DiscoveryEntry

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));
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) Callback(io.joynr.proxy.Callback) Version(joynr.types.Version) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 15 with 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));
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) Callback(io.joynr.proxy.Callback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Mockito.anyString(org.mockito.Mockito.anyString) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryQos(joynr.types.DiscoveryQos) Test(org.junit.Test)

Aggregations

DiscoveryEntry (joynr.types.DiscoveryEntry)60 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)43 Test (org.junit.Test)30 ProviderQos (joynr.types.ProviderQos)25 Version (joynr.types.Version)22 Callback (io.joynr.proxy.Callback)18 Matchers.anyString (org.mockito.Matchers.anyString)17 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)16 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)15 ArrayList (java.util.ArrayList)14 HashSet (java.util.HashSet)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)9 DeferredVoid (io.joynr.provider.DeferredVoid)7 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)6 MqttAddress (joynr.system.RoutingTypes.MqttAddress)6 Injector (com.google.inject.Injector)5 MessagingQos (io.joynr.messaging.MessagingQos)4 Future (io.joynr.proxy.Future)4 CheckForNull (javax.annotation.CheckForNull)4 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)4