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");
}
}
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);
}
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");
}
}
Aggregations