Search in sources :

Example 6 with CustomParameter

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

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

the class KeywordArbitrationStrategyFunction method select.

@Override
public Set<DiscoveryEntryWithMetaInfo> select(Map<String, String> parameters, Collection<DiscoveryEntryWithMetaInfo> capabilities) {
    String requestedKeyword = parameters.get(ArbitrationConstants.KEYWORD_PARAMETER);
    DiscoveryEntryWithMetaInfo capabilityWithKeyword = null;
    for (DiscoveryEntryWithMetaInfo discoveryEntry : capabilities) {
        // Search for a matching keyword parameter
        CustomParameter keywordParameter = findQosParameter(discoveryEntry, ArbitrationConstants.KEYWORD_PARAMETER);
        if (keywordParameter != null) {
            String currentKeyword = keywordParameter.getValue();
            if (currentKeyword.equals(requestedKeyword)) {
                capabilityWithKeyword = discoveryEntry;
                break;
            }
        }
    }
    return capabilityWithKeyword == null ? null : Sets.newHashSet(capabilityWithKeyword);
}
Also used : CustomParameter(joynr.types.CustomParameter) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo)

Example 8 with CustomParameter

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

Aggregations

CustomParameter (joynr.types.CustomParameter)8 ProviderQos (joynr.types.ProviderQos)7 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)4 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)4 Version (joynr.types.Version)4 Before (org.junit.Before)4 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)3 DiscoveryException (io.joynr.exceptions.DiscoveryException)3 Properties (java.util.Properties)3 Test (org.junit.Test)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DeferredVoid (io.joynr.provider.DeferredVoid)1 Callback (io.joynr.proxy.Callback)1 Field (java.lang.reflect.Field)1 DiscoveryEntry (joynr.types.DiscoveryEntry)1 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1