Search in sources :

Example 1 with ProviderQos

use of joynr.types.ProviderQos 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 ProviderQos

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

the class LocalCapabilitiesDirectoryTest method setUp.

@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
    channelAddress = new ChannelAddress(TEST_URL, "testChannelId");
    ObjectMapper objectMapper = new ObjectMapper();
    channelAddressSerialized = objectMapper.writeValueAsString(channelAddress);
    Field objectMapperField = CapabilityUtils.class.getDeclaredField("objectMapper");
    objectMapperField.setAccessible(true);
    objectMapperField.set(CapabilityUtils.class, objectMapper);
    Answer<Void> answer = new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            ((Callback<Void>) args[0]).onSuccess(null);
            return null;
        }
    };
    doAnswer(answer).when(globalCapabilitiesClient).add(any(Callback.class), any(GlobalDiscoveryEntry.class));
    String discoveryDirectoriesDomain = "io.joynr";
    String capabilitiesDirectoryParticipantId = "capDir_participantId";
    String capabiltitiesDirectoryChannelId = "dirchannelId";
    String domainAccessControllerParticipantId = "domainAccessControllerParticipantId";
    String domainAccessControllerChannelId = "domainAccessControllerChannelId";
    DiscoveryEntry globalCapabilitiesDirectoryDiscoveryEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), discoveryDirectoriesDomain, GlobalCapabilitiesDirectory.INTERFACE_NAME, capabilitiesDirectoryParticipantId, new ProviderQos(), System.currentTimeMillis(), expiryDateMs, domainAccessControllerChannelId, new ChannelAddress(TEST_URL, capabiltitiesDirectoryChannelId));
    DiscoveryEntry domainAccessControllerDiscoveryEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), discoveryDirectoriesDomain, GlobalDomainAccessController.INTERFACE_NAME, domainAccessControllerParticipantId, new ProviderQos(), System.currentTimeMillis(), expiryDateMs, domainAccessControllerChannelId, new ChannelAddress(TEST_URL, domainAccessControllerChannelId));
    when(capabilitiesProvisioning.getDiscoveryEntries()).thenReturn(Sets.newHashSet(globalCapabilitiesDirectoryDiscoveryEntry, domainAccessControllerDiscoveryEntry));
    // use default freshnessUpdateIntervalMs: 3600000ms (1h)
    localCapabilitiesDirectory = new LocalCapabilitiesDirectoryImpl(capabilitiesProvisioning, globalAddressProvider, localDiscoveryEntryStoreMock, globalDiscoveryEntryCacheMock, messageRouter, globalCapabilitiesClient, expiredDiscoveryEntryCacheCleaner, 3600000, capabilitiesFreshnessUpdateExecutor, defaultDiscoveryRetryIntervalMs, shutdownNotifier);
    verify(expiredDiscoveryEntryCacheCleaner).scheduleCleanUpForCaches(Mockito.<ExpiredDiscoveryEntryCacheCleaner.CleanupAction>any(), argThat(new DiscoveryEntryStoreVarargMatcher(globalDiscoveryEntryCacheMock, localDiscoveryEntryStoreMock)));
    verify(capabilitiesFreshnessUpdateExecutor).scheduleAtFixedRate(runnableCaptor.capture(), anyLong(), anyLong(), eq(TimeUnit.MILLISECONDS));
    ProviderQos providerQos = new ProviderQos();
    CustomParameter[] parameterList = { new CustomParameter("key1", "value1"), new CustomParameter("key2", "value2") };
    providerQos.setCustomParameters(parameterList);
    String participantId = "testParticipantId";
    String domain = "domain";
    discoveryEntry = new DiscoveryEntry(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, participantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId);
    globalDiscoveryEntry = new GlobalDiscoveryEntry(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, participantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId, channelAddressSerialized);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) Matchers.anyString(org.mockito.Matchers.anyString) Field(java.lang.reflect.Field) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) Callback(io.joynr.proxy.Callback) Version(joynr.types.Version) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DeferredVoid(io.joynr.provider.DeferredVoid) CustomParameter(joynr.types.CustomParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProviderQos(joynr.types.ProviderQos) Before(org.junit.Before)

Example 3 with ProviderQos

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

the class LocalCapabilitiesDirectoryTest method testLookupMultipleDomainsLocalThenGlobal.

@SuppressWarnings("unchecked")
@Test
public void testLookupMultipleDomainsLocalThenGlobal() {
    String[] domains = new String[] { "domain1", "domain2", "domain3" };
    String interfaceName = "interface1";
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_THEN_GLOBAL);
    discoveryQos.setCacheMaxAgeMs(ONE_DAY_IN_MS);
    CapabilitiesCallback capabilitiesCallback = mock(CapabilitiesCallback.class);
    DiscoveryEntry localEntry = new DiscoveryEntry();
    localEntry.setDomain("domain1");
    when(localDiscoveryEntryStoreMock.lookup(eq(domains), eq(interfaceName))).thenReturn(Lists.newArrayList(localEntry));
    GlobalDiscoveryEntry globalEntry = new GlobalDiscoveryEntry();
    globalEntry.setDomain("domain2");
    Collection<DiscoveryEntry> entries = Lists.newArrayList((DiscoveryEntry) globalEntry);
    when(globalDiscoveryEntryCacheMock.lookup(eq(domains), eq(interfaceName), eq(discoveryQos.getCacheMaxAgeMs()))).thenReturn(entries);
    final GlobalDiscoveryEntry remoteGlobalEntry = new GlobalDiscoveryEntry(new Version(0, 0), "domain3", interfaceName, "participantIdRemote", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 10000L, "publicKeyId", channelAddressSerialized);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            Callback<List<GlobalDiscoveryEntry>> callback = (Callback<List<GlobalDiscoveryEntry>>) invocation.getArguments()[0];
            callback.onSuccess(Lists.newArrayList(remoteGlobalEntry));
            return null;
        }
    }).when(globalCapabilitiesClient).lookup(any(Callback.class), Mockito.<String[]>any(), anyString(), anyLong());
    localCapabilitiesDirectory.lookup(domains, interfaceName, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient).lookup(any(Callback.class), argThat(Matchers.arrayContainingInAnyOrder(new String[] { "domain3" })), eq(interfaceName), eq(discoveryQos.getDiscoveryTimeoutMs()));
    verify(capabilitiesCallback).processCapabilitiesReceived(capabilitiesCaptor.capture());
    Collection<DiscoveryEntry> captured = CapabilityUtils.convertToDiscoveryEntrySet(capabilitiesCaptor.getValue());
    assertNotNull(captured);
    assertEquals(3, captured.size());
    assertTrue(captured.contains(localEntry));
    assertTrue(captured.contains(new DiscoveryEntry(globalEntry)));
    assertTrue(captured.contains(new DiscoveryEntry(remoteGlobalEntry)));
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Matchers.anyString(org.mockito.Matchers.anyString) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) Callback(io.joynr.proxy.Callback) Version(joynr.types.Version) InvocationOnMock(org.mockito.invocation.InvocationOnMock) List(java.util.List) ArrayList(java.util.ArrayList) DeferredVoid(io.joynr.provider.DeferredVoid) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 4 with ProviderQos

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

the class LocalCapabilitiesDirectoryTest method testLookupMultipleDomainsLocalOnly.

@Test
public void testLookupMultipleDomainsLocalOnly() {
    String[] domains = new String[] { "domain1", "domain2" };
    String interfaceName = "interface1";
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_ONLY);
    CapabilitiesCallback capabilitiesCallback = mock(CapabilitiesCallback.class);
    Collection<DiscoveryEntry> entries = Lists.newArrayList(new DiscoveryEntry(new Version(0, 0), "domain1", interfaceName, "participantId1", new ProviderQos(), System.currentTimeMillis(), expiryDateMs, interfaceName), new DiscoveryEntry(new Version(0, 0), "domain2", interfaceName, "participantId2", new ProviderQos(), System.currentTimeMillis(), expiryDateMs, interfaceName));
    when(localDiscoveryEntryStoreMock.lookup(eq(domains), eq(interfaceName))).thenReturn(entries);
    localCapabilitiesDirectory.lookup(domains, interfaceName, discoveryQos, capabilitiesCallback);
    verify(capabilitiesCallback).processCapabilitiesReceived(capabilitiesCaptor.capture());
    Collection<DiscoveryEntry> discoveredEntries = CapabilityUtils.convertToDiscoveryEntryList(capabilitiesCaptor.getValue());
    assertNotNull(discoveredEntries);
    assertEquals(2, discoveredEntries.size());
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Version(joynr.types.Version) Matchers.anyString(org.mockito.Matchers.anyString) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 5 with ProviderQos

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

the class LocalCapabilitiesDirectoryTest method addGlobalCapSucceeds_NextAddShallNotAddGlobalAgain.

@SuppressWarnings("unchecked")
@Test(timeout = 1000)
public void addGlobalCapSucceeds_NextAddShallNotAddGlobalAgain() throws InterruptedException {
    ProviderQos providerQos = new ProviderQos();
    providerQos.setScope(ProviderScope.GLOBAL);
    String participantId = LocalCapabilitiesDirectoryTest.class.getName() + ".addGlobalCapSucceeds_NextAddShallNotAddGlobalAgain";
    String domain = "testDomain";
    final DiscoveryEntry discoveryEntry = new DiscoveryEntry(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, participantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId);
    globalDiscoveryEntry = new GlobalDiscoveryEntry(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, participantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId, channelAddressSerialized);
    Promise<DeferredVoid> promise = localCapabilitiesDirectory.add(discoveryEntry);
    promise.then(new PromiseListener() {

        @Override
        public void onFulfillment(Object... values) {
            Mockito.doAnswer(createAddAnswerWithSuccess()).when(globalCapabilitiesClient).add(any(Callback.class), eq(globalDiscoveryEntry));
            verify(globalDiscoveryEntryCacheMock).add(eq(globalDiscoveryEntry));
            verify(globalCapabilitiesClient).add(any(Callback.class), eq(globalDiscoveryEntry));
            reset(globalCapabilitiesClient);
            localCapabilitiesDirectory.add(discoveryEntry);
            verify(globalCapabilitiesClient, timeout(200).never()).add(any(Callback.class), eq(globalDiscoveryEntry));
        }

        @Override
        public void onRejection(JoynrException error) {
            Assert.fail("adding capability failed: " + error);
        }
    });
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Version(joynr.types.Version) PromiseListener(io.joynr.provider.PromiseListener) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) JoynrException(io.joynr.exceptions.JoynrException) Matchers.anyString(org.mockito.Matchers.anyString) ProviderQos(joynr.types.ProviderQos) DeferredVoid(io.joynr.provider.DeferredVoid) Test(org.junit.Test)

Aggregations

ProviderQos (joynr.types.ProviderQos)69 Version (joynr.types.Version)43 Test (org.junit.Test)37 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)27 DiscoveryEntry (joynr.types.DiscoveryEntry)25 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)24 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)21 Matchers.anyString (org.mockito.Matchers.anyString)16 ArrayList (java.util.ArrayList)15 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)13 Before (org.junit.Before)13 Callback (io.joynr.proxy.Callback)12 HashSet (java.util.HashSet)11 MqttAddress (joynr.system.RoutingTypes.MqttAddress)10 InvocationOnMock (org.mockito.invocation.InvocationOnMock)10 Address (joynr.system.RoutingTypes.Address)9 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)8 MessagingQos (io.joynr.messaging.MessagingQos)8 Properties (java.util.Properties)8 DiscoveryException (io.joynr.exceptions.DiscoveryException)7