Search in sources :

Example 11 with DiscoveryException

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");
    }
}
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 12 with DiscoveryException

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);
            }
        }
    }
}
Also used : Function(com.google.common.base.Function) DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Callback(io.joynr.proxy.Callback) ArrayList(java.util.ArrayList) DeferredVoid(io.joynr.provider.DeferredVoid) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) DiscoveryException(io.joynr.exceptions.DiscoveryException)

Aggregations

DiscoveryException (io.joynr.exceptions.DiscoveryException)12 Test (org.junit.Test)9 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)7 ProviderQos (joynr.types.ProviderQos)7 Version (joynr.types.Version)7 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)6 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)4 ArrayList (java.util.ArrayList)4 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)3 MessagingQos (io.joynr.messaging.MessagingQos)3 Address (joynr.system.RoutingTypes.Address)3 CustomParameter (joynr.types.CustomParameter)3 SuppressWarnings (edu.umd.cs.findbugs.annotations.SuppressWarnings)2 JoynrCommunicationException (io.joynr.exceptions.JoynrCommunicationException)2 IOException (java.io.IOException)2 ApplicationException (joynr.exceptions.ApplicationException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Function (com.google.common.base.Function)1 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)1 DeferredVoid (io.joynr.provider.DeferredVoid)1