Search in sources :

Example 6 with ChannelAddress

use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.

the class ArbitrationTest method keyWordArbitratorMissingKeywordTest.

@Test
public void keyWordArbitratorMissingKeywordTest() throws InterruptedException {
    ProviderQos providerQos = new ProviderQos();
    CustomParameter[] qosParameters = { new CustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, "wrongkeyword") };
    providerQos.setCustomParameters(qosParameters);
    expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, expectedParticipantId, providerQos, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    ProviderQos providerQos2 = new ProviderQos();
    CustomParameter[] qosParameters2 = { new CustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, "otherKeyword") };
    providerQos2.setCustomParameters(qosParameters2);
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "wrongParticipantId", providerQos2, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    // use minimal timeout to prevent restarting arbitration
    int discoveryTimeout = 0;
    discoveryQos = new DiscoveryQos(discoveryTimeout, ArbitrationStrategy.Keyword, Long.MAX_VALUE);
    discoveryQos.addCustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, testKeyword);
    try {
        Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
        arbitrator.setArbitrationListener(arbitrationCallback);
        arbitrator.scheduleArbitration();
        assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
        verify(arbitrationCallback, times(1)).onError(any(Throwable.class));
        verify(arbitrationCallback, never()).onSuccess(any(ArbitrationResult.class));
    } catch (DiscoveryException e) {
        fail("A Joyn Arbitration Exception has been thrown");
    }
}
Also used : Version(joynr.types.Version) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) CustomParameter(joynr.types.CustomParameter) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryException(io.joynr.exceptions.DiscoveryException) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 7 with ChannelAddress

use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.

the class StaticCapabilitiesProvisioningTest method assertContainsEntryFor.

private void assertContainsEntryFor(Collection<DiscoveryEntry> entries, String interfaceName, String participantId, String url) {
    boolean found = false;
    for (DiscoveryEntry entry : entries) {
        if (entry instanceof GlobalDiscoveryEntry) {
            GlobalDiscoveryEntry globalDiscoveryEntry = (GlobalDiscoveryEntry) entry;
            if (globalDiscoveryEntry.getInterfaceName().equals(interfaceName) && (participantId == null || participantId.equals(globalDiscoveryEntry.getParticipantId()))) {
                if (url != null) {
                    Address address = CapabilityUtils.getAddressFromGlobalDiscoveryEntry(globalDiscoveryEntry);
                    assertTrue(address instanceof ChannelAddress);
                    assertEquals(url, ((ChannelAddress) address).getMessagingEndpointUrl());
                }
                found = true;
            }
        }
    }
    assertTrue("Couldn't find " + interfaceName + ((participantId == null ? "" : " / " + participantId)) + " in " + entries, found);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Address(joynr.system.RoutingTypes.Address) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress)

Example 8 with ChannelAddress

use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.

the class ServersUtil method createJsonFor.

private static String createJsonFor(String directoriesUrl) throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName");
    setObjectMapperOnCapabilitiesUtils(objectMapper);
    String channelId = "discoverydirectory_channelid";
    String participantId = "capabilitiesdirectory_participantid";
    GlobalDiscoveryEntry discoveryEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), "io.joynr", GlobalCapabilitiesDirectory.INTERFACE_NAME, participantId, new ProviderQos(), System.currentTimeMillis(), Long.MAX_VALUE, "", new ChannelAddress(directoriesUrl, channelId));
    String accessParticipantId = "domainaccesscontroller_participantid";
    GlobalDiscoveryEntry accessControlEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), "io.joynr", GlobalDomainAccessController.INTERFACE_NAME, accessParticipantId, new ProviderQos(), System.currentTimeMillis(), Long.MAX_VALUE, "", new InProcessAddress());
    List<DiscoveryEntry> entries = new ArrayList<>();
    entries.add(discoveryEntry);
    entries.add(accessControlEntry);
    return objectMapper.writeValueAsString(entries);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) Version(joynr.types.Version) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ArrayList(java.util.ArrayList) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProviderQos(joynr.types.ProviderQos)

Example 9 with ChannelAddress

use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.

the class RoutingProviderImplTest method setUp.

@Before
public void setUp() {
    expectedMqttAddress = new MqttAddress("mqtt://test-broker-uri", "test-topic");
    expectedMqttAddressString = RoutingTypesUtil.toAddressString(expectedMqttAddress);
    expectedChannelAddress = new ChannelAddress("http://test-bounceproxy-url", "test-channelId");
    expectedChannelAddressString = RoutingTypesUtil.toAddressString(expectedChannelAddress);
    routingProvider = new RoutingProviderImpl(mockMessageRouter, mockGlobalAddressProvider, mockReplyToAddressProvider);
    routingProvider.setSubscriptionPublisher(mockRoutingSubscriptionPublisher);
    getGlobalAddressOnFulfillmentSemaphore = new Semaphore(0);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            getGlobalAddressOnFulfillmentSemaphore.release();
            return null;
        }
    }).when(mockGlobalAddressPromiseListener).onFulfillment(anyString());
    globalAddressChangedSemaphore = new Semaphore(0);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            globalAddressChangedSemaphore.release();
            return null;
        }
    }).when(mockRoutingSubscriptionPublisher).globalAddressChanged(anyString());
    getReplyToAddressOnFulfillmentSemaphore = new Semaphore(0);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            getReplyToAddressOnFulfillmentSemaphore.release();
            return null;
        }
    }).when(mockReplyToAddressPromiseListener).onFulfillment(anyString());
    replyToAddressChangedSemaphore = new Semaphore(0);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            replyToAddressChangedSemaphore.release();
            return null;
        }
    }).when(mockRoutingSubscriptionPublisher).replyToAddressChanged(anyString());
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) Semaphore(java.util.concurrent.Semaphore) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Before(org.junit.Before)

Example 10 with ChannelAddress

use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.

the class ArbitrationTest method testVersionFilterUsed.

@SuppressWarnings("unchecked")
@Test
public void testVersionFilterUsed() throws InterruptedException {
    ProviderQos providerQos = new ProviderQos();
    String publicKeyId = "publicKeyId";
    expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
    String[] participantIds = new String[] { "first-participant", "second-participant" };
    for (int index = 0; index < participantIds.length; index++) {
        DiscoveryEntryWithMetaInfo discoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(index, index), domain, TestInterface.INTERFACE_NAME, participantIds[index], providerQos, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true);
        capabilitiesList.add(discoveryEntry);
    }
    ArbitrationStrategyFunction arbitrationStrategyFunction = mock(ArbitrationStrategyFunction.class);
    when(arbitrationStrategyFunction.select(any(Map.class), any(Collection.class))).thenReturn(new HashSet<DiscoveryEntryWithMetaInfo>(capabilitiesList));
    discoveryQos = new DiscoveryQos(ARBITRATION_TIMEOUT, arbitrationStrategyFunction, Long.MAX_VALUE);
    Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
    arbitrator.setArbitrationListener(arbitrationCallback);
    arbitrator.scheduleArbitration();
    assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
    verify(discoveryEntryVersionFilter).filter(interfaceVersion, new HashSet<DiscoveryEntryWithMetaInfo>(capabilitiesList), new HashMap<String, Set<Version>>());
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) Version(joynr.types.Version) Collection(java.util.Collection) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) Map(java.util.Map) HashMap(java.util.HashMap) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Aggregations

ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)22 ProviderQos (joynr.types.ProviderQos)12 Version (joynr.types.Version)12 Test (org.junit.Test)12 Address (joynr.system.RoutingTypes.Address)10 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)9 DiscoveryException (io.joynr.exceptions.DiscoveryException)6 MqttAddress (joynr.system.RoutingTypes.MqttAddress)6 HashSet (java.util.HashSet)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 CustomParameter (joynr.types.CustomParameter)4 DiscoveryEntry (joynr.types.DiscoveryEntry)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 FailureAction (io.joynr.messaging.FailureAction)3 SuccessAction (io.joynr.messaging.SuccessAction)3 InProcessAddress (io.joynr.messaging.inprocess.InProcessAddress)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3