use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.
the class ArbitrationTest method testPriorityArbitratorWithOnlyNegativePriorities.
@Test
public void testPriorityArbitratorWithOnlyNegativePriorities() throws InterruptedException {
ProviderQos providerQos = new ProviderQos();
providerQos.setPriority(Long.MIN_VALUE);
expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
ArrayList<Address> expectedEndpointAddresses = new ArrayList<Address>();
expectedEndpointAddresses.add(expectedEndpointAddress);
capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, expectedParticipantId, providerQos, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
ProviderQos providerQos2 = new ProviderQos();
providerQos2.setPriority(Long.MIN_VALUE);
capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "wrongParticipantId", providerQos2, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
long negativePriority = Long.MIN_VALUE;
ProviderQos providerQos3 = new ProviderQos();
providerQos3.setPriority(negativePriority);
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));
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.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.
the class ArbitrationTest method testCustomArbitrationFunctionMultipleMatches.
@SuppressWarnings("unchecked")
@Test
public void testCustomArbitrationFunctionMultipleMatches() throws InterruptedException {
// Expected provider supports onChangeSubscriptions
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(47, 11), 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(arbitrationStrategyFunction, times(1)).select(eq(discoveryQos.getCustomParameters()), eq(new HashSet<DiscoveryEntryWithMetaInfo>(capabilitiesList)));
DiscoveryEntryWithMetaInfo[] expectedDiscoveryEntries = new DiscoveryEntryWithMetaInfo[capabilitiesList.size()];
ArbitrationResult expectedArbitrationResult = new ArbitrationResult(capabilitiesList.toArray(expectedDiscoveryEntries));
verify(arbitrationCallback, times(1)).onSuccess(eq(expectedArbitrationResult));
}
use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.
the class ArbitrationTest method testCustomArbitrationFunction.
@SuppressWarnings("unchecked")
@Test
public void testCustomArbitrationFunction() throws InterruptedException {
// Expected provider supports onChangeSubscriptions
ProviderQos providerQos = new ProviderQos();
expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
DiscoveryEntryWithMetaInfo discoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, expectedParticipantId, 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(Sets.newHashSet(discoveryEntry));
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(arbitrationStrategyFunction, times(1)).select(eq(discoveryQos.getCustomParameters()), eq(new HashSet<DiscoveryEntryWithMetaInfo>(capabilitiesList)));
ArbitrationResult expectedArbitrationResult = new ArbitrationResult(discoveryEntry);
verify(arbitrationCallback, times(1)).onSuccess(eq(expectedArbitrationResult));
}
use of joynr.system.RoutingTypes.ChannelAddress 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");
}
}
use of joynr.system.RoutingTypes.ChannelAddress 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