Search in sources :

Example 51 with ProviderQos

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

the class ArbitrationTest method testPriorityArbitrator.

@Test
public void testPriorityArbitrator() throws InterruptedException {
    ProviderQos providerQos = new ProviderQos();
    providerQos.setPriority(testPriority);
    expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
    DiscoveryEntryWithMetaInfo expectedDiscoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, expectedParticipantId, providerQos, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true);
    capabilitiesList.add(expectedDiscoveryEntry);
    long lessPrior = 1;
    ProviderQos providerQos2 = new ProviderQos();
    providerQos2.setPriority(lessPrior);
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "wrongParticipantId", providerQos2, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    long negativePriority = -10;
    ProviderQos providerQos3 = new ProviderQos();
    providerQos3.setPriority(negativePriority);
    Address thirdEndpointAddress = new ChannelAddress("http://testUrl", "thirdChannelId");
    ArrayList<Address> thirdEndpointAddresses = new ArrayList<Address>();
    thirdEndpointAddresses.add(thirdEndpointAddress);
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "thirdParticipantId", providerQos3, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    discoveryQos = new DiscoveryQos(ARBITRATION_TIMEOUT, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE);
    try {
        Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
        arbitrator.setArbitrationListener(arbitrationCallback);
        arbitrator.scheduleArbitration();
        assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
        ArbitrationResult expectedArbitrationResult = new ArbitrationResult(expectedDiscoveryEntry);
        verify(arbitrationCallback, times(1)).onSuccess(eq(expectedArbitrationResult));
    } catch (DiscoveryException e) {
        fail("A Joyn Arbitration Exception has been thrown");
    }
}
Also used : Address(joynr.system.RoutingTypes.Address) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) Version(joynr.types.Version) ArrayList(java.util.ArrayList) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryException(io.joynr.exceptions.DiscoveryException) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 52 with ProviderQos

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

the class ArbitrationTest method testMultiDomainIncompatibleVersionsReported.

@Test
public void testMultiDomainIncompatibleVersionsReported() throws InterruptedException {
    final Version incompatibleVersion = new Version(100, 100);
    final String domain1 = "domain1";
    final String domain2 = "domain2";
    final DiscoveryEntryWithMetaInfo discoveryEntry1 = new DiscoveryEntryWithMetaInfo(incompatibleVersion, domain1, interfaceName, "participant1", new ProviderQos(), System.currentTimeMillis(), NO_EXPIRY, "public-key-1", true);
    final DiscoveryEntryWithMetaInfo discoveryEntry2 = new DiscoveryEntryWithMetaInfo(incompatibleVersion, domain2, interfaceName, "participant2", new ProviderQos(), System.currentTimeMillis(), NO_EXPIRY, "public-key-2", true);
    final Collection<DiscoveryEntryWithMetaInfo> discoveryEntries = Lists.newArrayList(discoveryEntry1, discoveryEntry2);
    ArbitrationStrategyFunction arbitrationStrategyFunction = mock(ArbitrationStrategyFunction.class);
    when(arbitrationStrategyFunction.select(Mockito.<Map<String, String>>any(), Mockito.<Collection<DiscoveryEntryWithMetaInfo>>any())).thenReturn(new HashSet<DiscoveryEntryWithMetaInfo>());
    doAnswer(new Answer<Set<DiscoveryEntry>>() {

        @SuppressWarnings("unchecked")
        @Override
        public Set<DiscoveryEntry> answer(InvocationOnMock invocation) throws Throwable {
            Set<DiscoveryEntry> discoveryEntries = (Set<DiscoveryEntry>) invocation.getArguments()[1];
            Map<String, Set<Version>> filteredVersions = (Map<String, Set<Version>>) invocation.getArguments()[2];
            filteredVersions.put(domain1, Sets.newHashSet(discoveryEntry1.getProviderVersion()));
            filteredVersions.put(domain2, Sets.newHashSet(discoveryEntry2.getProviderVersion()));
            discoveryEntries.clear();
            return new HashSet<>();
        }
    }).when(discoveryEntryVersionFilter).filter(Mockito.<Version>any(), Mockito.<Set<DiscoveryEntryWithMetaInfo>>any(), Mockito.<Map<String, Set<Version>>>any());
    DiscoveryQos discoveryQos = new DiscoveryQos(10L, arbitrationStrategyFunction, 0L);
    reset(localDiscoveryAggregator);
    doAnswer(new Answer<Object>() {

        @SuppressWarnings("unchecked")
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            ((Callback<DiscoveryEntryWithMetaInfo[]>) invocation.getArguments()[0]).resolve((Object) discoveryEntries.toArray(new DiscoveryEntryWithMetaInfo[2]));
            localDiscoveryAggregatorSemaphore.release();
            return null;
        }
    }).when(localDiscoveryAggregator).lookup(Mockito.<Callback<DiscoveryEntryWithMetaInfo[]>>any(), any(String[].class), eq(interfaceName), Mockito.<joynr.types.DiscoveryQos>any());
    Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain1, domain2), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
    arbitrator.setArbitrationListener(arbitrationCallback);
    arbitrator.scheduleArbitration();
    assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
    Set<Version> discoveredVersions = Sets.newHashSet(incompatibleVersion);
    ArgumentCaptor<MultiDomainNoCompatibleProviderFoundException> noCompatibleProviderFoundExceptionCaptor = ArgumentCaptor.forClass(MultiDomainNoCompatibleProviderFoundException.class);
    verify(arbitrationCallback).onError(noCompatibleProviderFoundExceptionCaptor.capture());
    assertEquals(discoveredVersions, noCompatibleProviderFoundExceptionCaptor.getValue().getDiscoveredVersionsForDomain(domain2));
    assertEquals(discoveredVersions, noCompatibleProviderFoundExceptionCaptor.getValue().getDiscoveredVersionsForDomain(domain1));
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) Set(java.util.Set) HashSet(java.util.HashSet) MultiDomainNoCompatibleProviderFoundException(io.joynr.exceptions.MultiDomainNoCompatibleProviderFoundException) Version(joynr.types.Version) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) Map(java.util.Map) HashMap(java.util.HashMap) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 53 with ProviderQos

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

the class ArbitrationTest method keywordArbitratorTest.

@Test
public void keywordArbitratorTest() throws InterruptedException {
    ProviderQos providerQos = new ProviderQos();
    CustomParameter[] qosParameters = { new CustomParameter(ArbitrationConstants.KEYWORD_PARAMETER, testKeyword) };
    providerQos.setCustomParameters(qosParameters);
    expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
    DiscoveryEntryWithMetaInfo expectedDiscoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, expectedParticipantId, providerQos, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true);
    capabilitiesList.add(expectedDiscoveryEntry);
    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));
    discoveryQos = new DiscoveryQos(ARBITRATION_TIMEOUT, 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));
        ArbitrationResult expectedArbitrationResult = new ArbitrationResult(expectedDiscoveryEntry);
        verify(arbitrationCallback, times(1)).onSuccess(eq(expectedArbitrationResult));
    } 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 54 with ProviderQos

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

the class ArbitrationTest method testPriorityArbitratorOnChangeSubscriptions.

@Test
public void testPriorityArbitratorOnChangeSubscriptions() throws InterruptedException {
    // Expected provider supports onChangeSubscriptions
    ProviderQos providerQos = new ProviderQos();
    providerQos.setPriority(testPriority);
    providerQos.setSupportsOnChangeSubscriptions(true);
    expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
    DiscoveryEntryWithMetaInfo expectedDiscoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, expectedParticipantId, providerQos, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true);
    capabilitiesList.add(expectedDiscoveryEntry);
    // A provider with a higher priority that does not support onChangeSubscriptions
    ProviderQos providerQos2 = new ProviderQos();
    providerQos2.setPriority(testPriority + 1);
    providerQos2.setSupportsOnChangeSubscriptions(false);
    Address otherEndpointAddress = new ChannelAddress("http://testUrl", "otherChannelId");
    ArrayList<Address> otherEndpointAddresses = new ArrayList<Address>();
    otherEndpointAddresses.add(otherEndpointAddress);
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "wrongParticipantId", providerQos2, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    // A provider with a higher priority that does not support onChangeSubscriptions
    ProviderQos providerQos3 = new ProviderQos();
    providerQos3.setPriority(testPriority + 2);
    providerQos3.setSupportsOnChangeSubscriptions(false);
    Address thirdEndpointAddress = new ChannelAddress("http://testUrl", "thirdChannelId");
    ArrayList<Address> thirdEndpointAddresses = new ArrayList<Address>();
    thirdEndpointAddresses.add(thirdEndpointAddress);
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "thirdParticipantId", providerQos3, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    discoveryQos = new DiscoveryQos(ARBITRATION_TIMEOUT, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE);
    discoveryQos.setProviderMustSupportOnChange(true);
    try {
        Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
        arbitrator.setArbitrationListener(arbitrationCallback);
        arbitrator.scheduleArbitration();
        assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
        ArbitrationResult expectedArbitrationResult = new ArbitrationResult(expectedDiscoveryEntry);
        verify(arbitrationCallback, times(1)).onSuccess(eq(expectedArbitrationResult));
    } catch (DiscoveryException e) {
        fail("A Joyn Arbitration Exception has been thrown");
    }
}
Also used : Address(joynr.system.RoutingTypes.Address) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) Version(joynr.types.Version) ArrayList(java.util.ArrayList) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryException(io.joynr.exceptions.DiscoveryException) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 55 with ProviderQos

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

the class GlobalDomainAccessControllerLauncher method run.

@Override
public void run() {
    ProviderQos providerQos = new ProviderQos();
    runtime.registerProvider(localDomain, globalDomainAccessSyncProvider, providerQos);
    runtime.registerProvider(localDomain, globalDomainRoleSyncProvider, providerQos);
    runtime.registerProvider(localDomain, globalDomainAccessControlListEditorSyncProvider, providerQos);
}
Also used : ProviderQos(joynr.types.ProviderQos)

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