use of io.joynr.exceptions.DiscoveryException 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");
}
}
use of io.joynr.exceptions.DiscoveryException in project joynr by bmwcarit.
the class LocalCapabilitiesDirectoryImpl method shutdown.
@Override
public void shutdown(boolean unregisterAllRegisteredCapabilities) {
freshnessUpdateScheduler.shutdownNow();
if (unregisterAllRegisteredCapabilities) {
Set<DiscoveryEntry> allDiscoveryEntries = localDiscoveryEntryStore.getAllDiscoveryEntries();
List<DiscoveryEntry> discoveryEntries = new ArrayList<>(allDiscoveryEntries.size());
for (DiscoveryEntry capabilityEntry : allDiscoveryEntries) {
if (capabilityEntry.getQos().getScope() == ProviderScope.GLOBAL) {
discoveryEntries.add(capabilityEntry);
}
}
if (discoveryEntries.size() > 0) {
try {
Function<? super DiscoveryEntry, String> transfomerFct = new Function<DiscoveryEntry, String>() {
@Override
public String apply(DiscoveryEntry input) {
return input != null ? input.getParticipantId() : null;
}
};
Callback<Void> callback = new Callback<Void>() {
@Override
public void onFailure(JoynrRuntimeException error) {
}
@Override
public void onSuccess(Void result) {
}
};
globalCapabilitiesDirectoryClient.remove(callback, Lists.newArrayList(Collections2.transform(discoveryEntries, transfomerFct)));
} catch (DiscoveryException e) {
logger.debug("error removing discovery entries", e);
}
}
}
}
Aggregations