Search in sources :

Example 16 with DiscoveryQos

use of io.joynr.arbitration.DiscoveryQos in project joynr by bmwcarit.

the class GlobalDomainAccessControllerClient method getGlobalDomainAccessControlListEditorProxy.

private GlobalDomainAccessControlListEditorProxy getGlobalDomainAccessControlListEditorProxy(long ttl) {
    ProxyBuilder<GlobalDomainAccessControlListEditorProxy> accessControlListEditorProxyBuilder = proxyBuilderFactory.get(domain, GlobalDomainAccessControlListEditorProxy.class);
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.GLOBAL_ONLY);
    discoveryQos.setCacheMaxAgeMs(DiscoveryQos.NO_MAX_AGE);
    MessagingQos messagingQos = new MessagingQos(ttl);
    return accessControlListEditorProxyBuilder.setDiscoveryQos(discoveryQos).setMessagingQos(messagingQos).build();
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) GlobalDomainAccessControlListEditorProxy(joynr.infrastructure.GlobalDomainAccessControlListEditorProxy) DiscoveryQos(io.joynr.arbitration.DiscoveryQos)

Example 17 with DiscoveryQos

use of io.joynr.arbitration.DiscoveryQos in project joynr by bmwcarit.

the class LocalDiscoveryTest method testMixedLocalCachedRemoteDiscoveryEntries.

@SuppressWarnings("unchecked")
@Test
public void testMixedLocalCachedRemoteDiscoveryEntries() {
    String testDomain = "testDomain";
    String remoteDomain = "remoteDomain";
    Set<String> testDomains = new HashSet<>();
    testDomains.add(testDomain);
    testDomains.add(remoteDomain);
    String interfaceName = testProxy.INTERFACE_NAME;
    final Collection<DiscoveryEntry> localDiscoveryEntries = new HashSet<>();
    final Collection<DiscoveryEntry> cachedDiscoveryEntries = new HashSet<>();
    final List<GlobalDiscoveryEntry> remoteDiscoveryEntries = new ArrayList<>();
    DiscoveryEntry discoveryEntry = new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantIdLocal", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId");
    DiscoveryEntry cachedDiscoveryEntry = new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantIdCached", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId");
    GlobalDiscoveryEntry remoteDiscoveryEntry = CapabilityUtils.discoveryEntry2GlobalDiscoveryEntry(new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), remoteDomain, interfaceName, "participantIdRemote", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId"), new MqttAddress());
    localDiscoveryEntries.add(discoveryEntry);
    cachedDiscoveryEntries.add(cachedDiscoveryEntry);
    remoteDiscoveryEntries.add(remoteDiscoveryEntry);
    Set<DiscoveryEntryWithMetaInfo> discoveryEntriesWithMetaInfo = CapabilityUtils.convertToDiscoveryEntryWithMetaInfoSet(true, localDiscoveryEntries);
    discoveryEntriesWithMetaInfo.add(CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(false, cachedDiscoveryEntry));
    discoveryEntriesWithMetaInfo.add(CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(false, remoteDiscoveryEntry));
    when(localDiscoveryEntryStoreMock.lookup(any(String[].class), eq(interfaceName))).thenReturn(localDiscoveryEntries);
    when(globalDiscoveryEntryCacheMock.lookup(any(String[].class), eq(interfaceName), anyLong())).thenReturn(cachedDiscoveryEntries);
    Mockito.doAnswer(new Answer<Object>() {

        @SuppressWarnings("rawtypes")
        @Override
        public List<GlobalDiscoveryEntry> answer(InvocationOnMock invocation) throws Throwable {
            Object[] arguments = invocation.getArguments();
            assert (arguments[0] instanceof Callback);
            ((Callback) arguments[0]).resolve((Object) remoteDiscoveryEntries);
            return null;
        }
    }).when(globalCapabilitiesDirectoryClientMock).lookup(any(Callback.class), any(String[].class), eq(interfaceName), anyLong());
    ProxyBuilder<testProxy> proxyBuilder = runtime.getProxyBuilder(testDomains, testProxy.class);
    final Future<Void> future = new Future<Void>();
    ArbitrationStrategyFunction arbitrationStrategyFunction = new ArbitrationStrategyFunction() {

        @Override
        public Set<DiscoveryEntryWithMetaInfo> select(Map<String, String> parameters, Collection<DiscoveryEntryWithMetaInfo> capabilities) {
            return Sets.newHashSet(capabilities);
        }
    };
    DiscoveryQos discoveryQos = new DiscoveryQos(30000, arbitrationStrategyFunction, 0, DiscoveryScope.LOCAL_AND_GLOBAL);
    proxyBuilder.setDiscoveryQos(discoveryQos).build(new ProxyCreatedCallback<testProxy>() {

        @Override
        public void onProxyCreationFinished(testProxy result) {
            future.onSuccess(null);
        }

        @Override
        public void onProxyCreationError(JoynrRuntimeException error) {
            future.onFailure(error);
        }
    });
    try {
        future.get(5000);
        verify(joynrMessagingConnectorFactoryMock).create(anyString(), eq(discoveryEntriesWithMetaInfo), any(MessagingQos.class));
    } catch (Exception e) {
        Assert.fail("Unexpected exception from ProxyCreatedCallback: " + e);
    }
}
Also used : GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) MessagingQos(io.joynr.messaging.MessagingQos) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MqttAddress(joynr.system.RoutingTypes.MqttAddress) DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) joynr.tests.testProxy(joynr.tests.testProxy) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Callback(io.joynr.proxy.Callback) ProxyCreatedCallback(io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Future(io.joynr.proxy.Future) Collection(java.util.Collection) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ArbitrationStrategyFunction(io.joynr.arbitration.ArbitrationStrategyFunction) Map(java.util.Map) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 18 with DiscoveryQos

use of io.joynr.arbitration.DiscoveryQos in project joynr by bmwcarit.

the class LocalDiscoveryTest method testCachedGlobalDiscoveryEntries.

@Test
public void testCachedGlobalDiscoveryEntries() {
    String testDomain = "testDomain";
    String interfaceName = testProxy.INTERFACE_NAME;
    Collection<DiscoveryEntry> discoveryEntries = new HashSet<>();
    discoveryEntries.add(new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantId", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId"));
    Set<DiscoveryEntryWithMetaInfo> discoveryEntriesWithMetaInfo = CapabilityUtils.convertToDiscoveryEntryWithMetaInfoSet(false, discoveryEntries);
    when(globalDiscoveryEntryCacheMock.lookup(any(String[].class), eq(interfaceName), anyLong())).thenReturn(discoveryEntries);
    ProxyBuilder<testProxy> proxyBuilder = runtime.getProxyBuilder(testDomain, testProxy.class);
    final Future<Void> future = new Future<Void>();
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.GLOBAL_ONLY);
    proxyBuilder.setDiscoveryQos(discoveryQos).build(new ProxyCreatedCallback<testProxy>() {

        @Override
        public void onProxyCreationFinished(testProxy result) {
            future.onSuccess(null);
        }

        @Override
        public void onProxyCreationError(JoynrRuntimeException error) {
            future.onFailure(error);
        }
    });
    try {
        future.get(5000);
        verify(joynrMessagingConnectorFactoryMock).create(anyString(), eq(discoveryEntriesWithMetaInfo), any(MessagingQos.class));
    } catch (Exception e) {
        Assert.fail("Unexpected exception from ProxyCreatedCallback: " + e);
    }
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) joynr.tests.testProxy(joynr.tests.testProxy) Matchers.anyString(org.mockito.Matchers.anyString) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) MessagingQos(io.joynr.messaging.MessagingQos) Future(io.joynr.proxy.Future) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ProviderQos(joynr.types.ProviderQos) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with DiscoveryQos

use of io.joynr.arbitration.DiscoveryQos in project joynr by bmwcarit.

the class RoutingTableOverwriteEnd2EndTest method testProviderAddressCanBeOverwrittenAfterDiscovery.

@Test
public void testProviderAddressCanBeOverwrittenAfterDiscovery() throws Exception {
    // Tests that if a provider's address is changed in the discovery directory and a new proxy is
    // created for the provider, the routing table of the proxy's runtime will also be updated as long as
    // a new arbitration (cache max age = 0) is performed.
    final String providerDomain = "testDomain";
    final Properties fixedParticipantIdProperty = createFixedParticipantIdProperties(providerDomain, DefaulttestProvider.class, "fixedParticipantId");
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setArbitrationStrategy(ArbitrationStrategy.HighestPriority);
    discoveryQos.setCacheMaxAgeMs(0);
    JoynrRuntime runtimeProxy = createRuntime("proxy", null);
    JoynrRuntime runtimeProvider1 = createRuntime("provider_initial", fixedParticipantIdProperty);
    DefaulttestProvider provider1 = Mockito.spy(DefaulttestProvider.class);
    runtimeProvider1.registerProvider(providerDomain, provider1, createProviderQos()).get();
    testProxy proxy1 = runtimeProxy.getProxyBuilder(providerDomain, testProxy.class).setMessagingQos(new MessagingQos(2000)).setDiscoveryQos(discoveryQos).build();
    proxy1.addNumbers(1, 2, 3);
    verify(provider1).addNumbers(1, 2, 3);
    reset(provider1);
    JoynrRuntime runtimeProvider2 = createRuntime("provider_override", fixedParticipantIdProperty);
    DefaulttestProvider provider2 = Mockito.spy(DefaulttestProvider.class);
    runtimeProvider2.registerProvider(providerDomain, provider2, createProviderQos()).get();
    testProxy proxy2 = runtimeProxy.getProxyBuilder(providerDomain, testProxy.class).setMessagingQos(new MessagingQos(2000)).setDiscoveryQos(discoveryQos).build();
    proxy2.addNumbers(1, 2, 3);
    verify(provider1, never()).addNumbers(1, 2, 3);
    verify(provider2).addNumbers(1, 2, 3);
}
Also used : JoynrRuntime(io.joynr.runtime.JoynrRuntime) MessagingQos(io.joynr.messaging.MessagingQos) DefaulttestProvider(joynr.tests.DefaulttestProvider) joynr.tests.testProxy(joynr.tests.testProxy) Properties(java.util.Properties) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) Test(org.junit.Test)

Example 20 with DiscoveryQos

use of io.joynr.arbitration.DiscoveryQos in project joynr by bmwcarit.

the class ShutdownTest method testProxyCreationAfterShutdown.

@Ignore
@Test(expected = JoynrShutdownException.class)
public void testProxyCreationAfterShutdown() throws DiscoveryException, JoynrIllegalStateException, InterruptedException {
    // TODO
    // Arbitration does not check if the runtime is already shutting down. A test like this would fail.
    ProxyBuilder<testProxy> proxyBuilder = dummyApplication.getRuntime().getProxyBuilder("ShutdownTestdomain", testProxy.class);
    testProxy proxy = proxyBuilder.setDiscoveryQos(new DiscoveryQos(30000, ArbitrationStrategy.HighestPriority, 0)).build();
    dummyApplication.shutdown();
    proxy.getFirstPrime();
}
Also used : joynr.tests.testProxy(joynr.tests.testProxy) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

DiscoveryQos (io.joynr.arbitration.DiscoveryQos)46 MessagingQos (io.joynr.messaging.MessagingQos)23 Test (org.junit.Test)23 ProviderQos (joynr.types.ProviderQos)20 Matchers.anyString (org.mockito.Matchers.anyString)19 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)16 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)14 DiscoveryEntry (joynr.types.DiscoveryEntry)14 Callback (io.joynr.proxy.Callback)11 joynr.tests.testProxy (joynr.tests.testProxy)11 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)10 Properties (java.util.Properties)9 Version (joynr.types.Version)9 ArrayList (java.util.ArrayList)8 Before (org.junit.Before)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 Future (io.joynr.proxy.Future)5 ProxyCreatedCallback (io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback)5 HashSet (java.util.HashSet)5 IOException (java.io.IOException)4