Search in sources :

Example 6 with ProviderQos

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

the class LocalCapabilitiesDirectoryTest method lookupWithScopeGlobalOnly.

@SuppressWarnings("unchecked")
@Test(timeout = 1000)
public void lookupWithScopeGlobalOnly() throws InterruptedException {
    List<GlobalDiscoveryEntry> caps = new ArrayList<GlobalDiscoveryEntry>();
    String domain1 = "domain1";
    String interfaceName1 = "interfaceName1";
    DiscoveryQos discoveryQos = new DiscoveryQos(30000, ArbitrationStrategy.HighestPriority, 1000, DiscoveryScope.GLOBAL_ONLY);
    CapabilitiesCallback capabilitiesCallback = mock(CapabilitiesCallback.class);
    when(globalDiscoveryEntryCacheMock.lookup(eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getCacheMaxAgeMs()))).thenReturn(new ArrayList<DiscoveryEntry>());
    doAnswer(createAnswer(caps)).when(globalCapabilitiesClient).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(1)).lookup(any(Callback.class), any(String[].class), any(String.class), eq(discoveryQos.getDiscoveryTimeoutMs()));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(0)));
    verify(capabilitiesCallback, times(0)).processCapabilitiesReceived(argThat(hasNEntries(1)));
    reset(capabilitiesCallback);
    // add local entry
    ProviderQos providerQos = new ProviderQos();
    providerQos.setScope(ProviderScope.LOCAL);
    DiscoveryEntry discoveryEntry = new DiscoveryEntry(new Version(47, 11), domain1, interfaceName1, "localParticipant", providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId);
    localCapabilitiesDirectory.add(discoveryEntry);
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(2)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(0)));
    verify(capabilitiesCallback, times(0)).processCapabilitiesReceived(argThat(hasNEntries(1)));
    reset(capabilitiesCallback);
    // even deleting local cap entries shall have no effect, the global cap dir shall be invoked
    localCapabilitiesDirectory.remove(discoveryEntry);
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(3)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(0)));
    verify(capabilitiesCallback, times(0)).processCapabilitiesReceived(argThat(hasNEntries(1)));
    reset(capabilitiesCallback);
    // add global entry
    GlobalDiscoveryEntry capInfo = new GlobalDiscoveryEntry(new Version(47, 11), domain1, interfaceName1, "globalParticipant", new ProviderQos(), System.currentTimeMillis(), expiryDateMs, publicKeyId, channelAddressSerialized);
    caps.add(capInfo);
    doAnswer(createAnswer(caps)).when(globalCapabilitiesClient).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(4)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    verify(capabilitiesCallback, times(0)).processCapabilitiesReceived(argThat(hasNEntries(0)));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(1)));
    reset(capabilitiesCallback);
    // now, another lookup call shall take the cached for the global cap call, and no longer call the global cap dir
    // (as long as the cache is not expired)
    reset(globalDiscoveryEntryCacheMock);
    when(globalDiscoveryEntryCacheMock.lookup(eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getCacheMaxAgeMs()))).thenReturn(Lists.newArrayList((DiscoveryEntry) capInfo));
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(4)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    verify(capabilitiesCallback, times(0)).processCapabilitiesReceived(argThat(hasNEntries(0)));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(1)));
    reset(capabilitiesCallback);
    // and now, invalidate the existing cached global values, resulting in another call to glocalcapclient
    discoveryQos.setCacheMaxAgeMs(0);
    Thread.sleep(1);
    // now, another lookup call shall call the globalCapabilitiesClient, as the global cap dir is expired
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(5)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    verify(capabilitiesCallback, times(0)).processCapabilitiesReceived(argThat(hasNEntries(0)));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(1)));
    reset(capabilitiesCallback);
    reset(globalCapabilitiesClient);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Callback(io.joynr.proxy.Callback) Version(joynr.types.Version) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 7 with ProviderQos

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

the class LocalCapabilitiesDirectoryTest method lookupWithScopeLocalAndGlobal.

@SuppressWarnings("unchecked")
@Test(timeout = 1000)
public void lookupWithScopeLocalAndGlobal() throws InterruptedException {
    List<GlobalDiscoveryEntry> caps = new ArrayList<GlobalDiscoveryEntry>();
    String domain1 = "domain1";
    String interfaceName1 = "interfaceName1";
    DiscoveryQos discoveryQos = new DiscoveryQos(30000, ArbitrationStrategy.HighestPriority, 500, DiscoveryScope.LOCAL_AND_GLOBAL);
    CapabilitiesCallback capabilitiesCallback = Mockito.mock(CapabilitiesCallback.class);
    Mockito.doAnswer(createAnswer(caps)).when(globalCapabilitiesClient).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(1)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(0)));
    verify(capabilitiesCallback, times(0)).processCapabilitiesReceived(argThat(hasNEntries(1)));
    // add local entry
    ProviderQos providerQos = new ProviderQos();
    providerQos.setScope(ProviderScope.LOCAL);
    DiscoveryEntry discoveryEntry = new DiscoveryEntry(new Version(47, 11), domain1, interfaceName1, "localParticipant", providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId);
    when(localDiscoveryEntryStoreMock.lookup(eq(new String[] { domain1 }), eq(interfaceName1))).thenReturn(Lists.newArrayList(discoveryEntry));
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(2)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(0)));
    verify(capabilitiesCallback, times(1)).processCapabilitiesReceived(argThat(hasNEntries(1)));
    // add global entry
    GlobalDiscoveryEntry capInfo = new GlobalDiscoveryEntry(new Version(47, 11), domain1, interfaceName1, "globalParticipant", new ProviderQos(), System.currentTimeMillis(), expiryDateMs, publicKeyId, channelAddressSerialized);
    caps.add(capInfo);
    Mockito.doAnswer(createAnswer(caps)).when(globalCapabilitiesClient).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(3)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    // now, another lookup call shall take the cached for the global cap call, and no longer call the global cap dir
    // (as long as the cache is not expired)
    when(globalDiscoveryEntryCacheMock.lookup(eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getCacheMaxAgeMs()))).thenReturn(Lists.newArrayList((DiscoveryEntry) capInfo));
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(3)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    // and now, invalidate the existing cached global values, resulting in another call to glocalcapclient
    discoveryQos.setCacheMaxAgeMs(0);
    Thread.sleep(1);
    // now, another lookup call shall take the cached for the global cap call, and no longer call the global cap dir
    // (as long as the cache is not expired)
    localCapabilitiesDirectory.lookup(new String[] { domain1 }, interfaceName1, discoveryQos, capabilitiesCallback);
    verify(globalCapabilitiesClient, times(4)).lookup(any(Callback.class), eq(new String[] { domain1 }), eq(interfaceName1), eq(discoveryQos.getDiscoveryTimeoutMs()));
    reset(globalCapabilitiesClient);
    reset(capabilitiesCallback);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Callback(io.joynr.proxy.Callback) Version(joynr.types.Version) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 8 with ProviderQos

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

the class JoynrIntegrationBean method registerProviders.

private void registerProviders(Set<Bean<?>> serviceProviderBeans, JoynrRuntime runtime) {
    Set<ProviderQosFactory> providerQosFactories = getProviderQosFactories();
    for (Bean<?> bean : serviceProviderBeans) {
        Class<?> beanClass = bean.getBeanClass();
        ServiceProvider providerService = beanClass.getAnnotation(ServiceProvider.class);
        Class<?> serviceInterface = serviceProviderDiscovery.getProviderInterfaceFor(providerService.serviceInterface());
        if (LOG.isDebugEnabled()) {
            LOG.debug(format("Registering %s as provider with joynr runtime for service interface %s.", bean, serviceInterface));
        }
        Object provider = Proxy.newProxyInstance(beanClass.getClassLoader(), new Class<?>[] { serviceInterface }, new ProviderWrapper(bean, beanManager, joynrRuntimeFactory.getInjector()));
        ProviderQos providerQos = null;
        for (ProviderQosFactory factory : providerQosFactories) {
            if (factory.providesFor(serviceInterface)) {
                providerQos = factory.create();
                break;
            }
        }
        if (providerQos == null) {
            providerQos = new ProviderQos();
        }
        runtime.registerProvider(getDomainForProvider(beanClass), provider, providerQos);
        registeredProviders.add(provider);
    }
}
Also used : ProviderQosFactory(io.joynr.jeeintegration.api.ProviderQosFactory) ServiceProvider(io.joynr.jeeintegration.api.ServiceProvider) ProviderQos(joynr.types.ProviderQos)

Example 9 with ProviderQos

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

the class MyRadioProviderApplication method run.

@Override
public void run() {
    provider = new MyRadioProvider();
    provider.addBroadcastFilter(new TrafficServiceBroadcastFilter());
    provider.addBroadcastFilter(new GeocastBroadcastFilter(jsonSerializer));
    ProviderQos providerQos = new ProviderQos();
    providerQos.setPriority(System.currentTimeMillis());
    providerQos.setScope(providerScope);
    runtime.registerProvider(localDomain, provider, providerQos);
    ConsoleReader console;
    try {
        console = new ConsoleReader();
        int key;
        while ((key = console.readCharacter()) != 'q') {
            switch(key) {
                case 's':
                    provider.shuffleStations();
                    break;
                case 'p':
                    provider.fireWeakSignalEventWithPartition();
                    break;
                case 'w':
                    provider.fireWeakSignalEvent();
                    break;
                case 'n':
                    provider.fireNewStationDiscoveredEvent();
                    break;
                default:
                    LOG.info("\n\nUSAGE press\n" + " q\tto quit\n" + " s\tto shuffle stations\n" + " w\tto fire weak signal event\n" + " p\tto fire weak signal event with country of current station as partition\n" + " n\tto fire station discovered event\n");
                    break;
            }
        }
    } catch (IOException e) {
        LOG.error("error reading input from console", e);
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) IOException(java.io.IOException) ProviderQos(joynr.types.ProviderQos)

Example 10 with ProviderQos

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

the class DiscoveryEntryStorePersistedTest method createDiscoveryEntry.

private GlobalDiscoveryEntryPersisted createDiscoveryEntry(String domain, String interfaceName, String participantId) throws Exception {
    ProviderQos qos = new ProviderQos();
    long lastSeenDateMs = 123L;
    long expiryDateMs = Long.MAX_VALUE;
    String publicKeyId = "publicKeyId";
    Address address = new MqttAddress("brokerUri", "topic");
    String addressSerialized = new ObjectMapper().writeValueAsString(address);
    GlobalDiscoveryEntryPersisted discoveryEntry = new GlobalDiscoveryEntryPersisted(new Version(47, 11), domain, interfaceName, participantId, qos, lastSeenDateMs, expiryDateMs, publicKeyId, addressSerialized, "clusterControllerId");
    return discoveryEntry;
}
Also used : MqttAddress(joynr.system.RoutingTypes.MqttAddress) Address(joynr.system.RoutingTypes.Address) Version(joynr.types.Version) ProviderQos(joynr.types.ProviderQos) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MqttAddress(joynr.system.RoutingTypes.MqttAddress)

Aggregations

ProviderQos (joynr.types.ProviderQos)69 Version (joynr.types.Version)43 Test (org.junit.Test)37 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)27 DiscoveryEntry (joynr.types.DiscoveryEntry)25 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)24 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)21 Matchers.anyString (org.mockito.Matchers.anyString)16 ArrayList (java.util.ArrayList)15 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)13 Before (org.junit.Before)13 Callback (io.joynr.proxy.Callback)12 HashSet (java.util.HashSet)11 MqttAddress (joynr.system.RoutingTypes.MqttAddress)10 InvocationOnMock (org.mockito.invocation.InvocationOnMock)10 Address (joynr.system.RoutingTypes.Address)9 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)8 MessagingQos (io.joynr.messaging.MessagingQos)8 Properties (java.util.Properties)8 DiscoveryException (io.joynr.exceptions.DiscoveryException)7