Search in sources :

Example 1 with DiscoveryEntryWithMetaInfo

use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.

the class AccessControllerTest method setup.

@Before
public void setup() {
    String discoveryProviderParticipantId = "";
    String routingProviderParticipantId = "";
    accessController = new AccessControllerImpl(localCapabilitiesDirectory, localDomainAccessController, new CapabilitiesProvisioning() {

        @Override
        public Collection<DiscoveryEntry> getDiscoveryEntries() {
            return new ArrayList<DiscoveryEntry>();
        }
    }, discoveryProviderParticipantId, routingProviderParticipantId);
    when(messageMock.getType()).thenReturn(Message.VALUE_MESSAGE_TYPE_REQUEST);
    when(messageMock.getRecipient()).thenReturn(toParticipantId);
    when(messageMock.getSender()).thenReturn(fromParticipantId);
    when(messageMock.getCreatorUserId()).thenReturn(DUMMY_USERID);
    when(messageMock.getId()).thenReturn("someId");
    final DiscoveryEntryWithMetaInfo discoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(47, 11), testDomain, testInterface, toParticipantId, new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + ONE_MINUTE_IN_MS, testPublicKeyId, false);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            CapabilityCallback callback = (CapabilityCallback) invocation.getArguments()[2];
            callback.processCapabilityReceived(discoveryEntry);
            return null;
        }
    }).when(localCapabilitiesDirectory).lookup(eq(toParticipantId), any(DiscoveryQos.class), any(CapabilityCallback.class));
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) CapabilityCallback(io.joynr.capabilities.CapabilityCallback) ArrayList(java.util.ArrayList) CapabilitiesProvisioning(io.joynr.capabilities.CapabilitiesProvisioning) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) Version(joynr.types.Version) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ProviderQos(joynr.types.ProviderQos) Before(org.junit.Before)

Example 2 with DiscoveryEntryWithMetaInfo

use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.

the class LocalCapabilitiesDirectoryTest method testLookupByParticipantId_localEntry_DiscoveryEntryWithMetaInfoContainsExpectedIsLocalValue.

@Test
public void testLookupByParticipantId_localEntry_DiscoveryEntryWithMetaInfoContainsExpectedIsLocalValue() {
    String participantId = "participantId";
    String interfaceName = "interfaceName";
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_THEN_GLOBAL);
    // local DiscoveryEntry
    String localDomain = "localDomain";
    DiscoveryEntry localEntry = new DiscoveryEntry();
    localEntry.setDomain(localDomain);
    localEntry.setInterfaceName(interfaceName);
    localEntry.setParticipantId(participantId);
    when(localDiscoveryEntryStoreMock.lookup(eq(participantId), eq(discoveryQos.getCacheMaxAgeMs()))).thenReturn(localEntry);
    DiscoveryEntryWithMetaInfo capturedLocalEntry = localCapabilitiesDirectory.lookup(participantId, discoveryQos);
    DiscoveryEntryWithMetaInfo localEntryWithMetaInfo = CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(true, localEntry);
    assertEquals(localEntryWithMetaInfo, capturedLocalEntry);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Matchers.anyString(org.mockito.Matchers.anyString) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) Test(org.junit.Test)

Example 3 with DiscoveryEntryWithMetaInfo

use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.

the class LocalCapabilitiesDirectoryImpl method lookup.

@Override
public Promise<Lookup2Deferred> lookup(String participantId) {
    Lookup2Deferred deferred = new Lookup2Deferred();
    DiscoveryEntryWithMetaInfo discoveryEntry = lookup(participantId, DiscoveryQos.NO_FILTER);
    deferred.resolve(discoveryEntry);
    return new Promise<>(deferred);
}
Also used : Promise(io.joynr.provider.Promise) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo)

Example 4 with DiscoveryEntryWithMetaInfo

use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.

the class LocalCapabilitiesDirectoryImpl method lookup.

@Override
@CheckForNull
public DiscoveryEntryWithMetaInfo lookup(String participantId, DiscoveryQos discoveryQos) {
    final Future<DiscoveryEntryWithMetaInfo> lookupFuture = new Future<>();
    lookup(participantId, discoveryQos, new CapabilityCallback() {

        @Override
        public void processCapabilityReceived(DiscoveryEntryWithMetaInfo capability) {
            lookupFuture.onSuccess(capability);
        }

        @Override
        public void onError(Throwable e) {
            lookupFuture.onFailure(new JoynrRuntimeException(e));
        }
    });
    DiscoveryEntryWithMetaInfo retrievedCapabilitiyEntry = null;
    try {
        retrievedCapabilitiyEntry = lookupFuture.get();
    } catch (InterruptedException e1) {
        logger.error("interrupted while retrieving capability entry by participant ID", e1);
    } catch (ApplicationException e1) {
        // should not be reachable since ApplicationExceptions are not used internally
        logger.error("ApplicationException while retrieving capability entry by participant ID", e1);
    }
    return retrievedCapabilitiyEntry;
}
Also used : ApplicationException(joynr.exceptions.ApplicationException) Future(io.joynr.proxy.Future) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) CheckForNull(javax.annotation.CheckForNull)

Example 5 with DiscoveryEntryWithMetaInfo

use of joynr.types.DiscoveryEntryWithMetaInfo in project joynr by bmwcarit.

the class LocalCapabilitiesDirectoryImpl method addEntriesForDomain.

private boolean addEntriesForDomain(Collection<DiscoveryEntryWithMetaInfo> discoveryEntries, Collection<DiscoveryEntryWithMetaInfo> addTo, String domain) {
    boolean domainMatched = false;
    for (DiscoveryEntryWithMetaInfo discoveryEntry : discoveryEntries) {
        if (discoveryEntry.getDomain().equals(domain)) {
            addTo.add(discoveryEntry);
            domainMatched = true;
        }
    }
    return domainMatched;
}
Also used : DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo)

Aggregations

DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)66 Test (org.junit.Test)32 Version (joynr.types.Version)29 ProviderQos (joynr.types.ProviderQos)24 DiscoveryEntry (joynr.types.DiscoveryEntry)16 HashSet (java.util.HashSet)14 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)13 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)11 Matchers.anyString (org.mockito.Matchers.anyString)10 InvocationOnMock (org.mockito.invocation.InvocationOnMock)10 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)9 Before (org.junit.Before)9 DiscoveryException (io.joynr.exceptions.DiscoveryException)7 MessagingQos (io.joynr.messaging.MessagingQos)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 Set (java.util.Set)7 Callback (io.joynr.proxy.Callback)6 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)5 Collection (java.util.Collection)5