Search in sources :

Example 26 with DiscoveryQos

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

the class JeeJoynrServiceLocatorTest method testGetWithMessagingAndDiscoveryQos.

@Test
public void testGetWithMessagingAndDiscoveryQos() {
    MessagingQos messagingQos = new MessagingQos();
    DiscoveryQos discoveryQos = new DiscoveryQos();
    MyServiceSync result = subject.get(MyServiceSync.class, "local", messagingQos, discoveryQos);
    assertNotNull(result);
    String callResult = result.callMe("one");
    assertNotNull(callResult);
    assertEquals("two", callResult);
    verify(myJoynrProxy).callMe("one");
    verify(proxyBuilder).setMessagingQos(messagingQos);
    verify(proxyBuilder).setDiscoveryQos(discoveryQos);
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) Matchers.anyString(org.mockito.Matchers.anyString) MyServiceSync(joynr.jeeintegration.servicelocator.MyServiceSync) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) Test(org.junit.Test)

Example 27 with DiscoveryQos

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

the class LocalDiscoveryTest method testRemoteGlobalDiscoveryEntries.

@SuppressWarnings("unchecked")
@Test
public void testRemoteGlobalDiscoveryEntries() {
    String testDomain = "testDomain";
    String interfaceName = testProxy.INTERFACE_NAME;
    final Collection<DiscoveryEntry> discoveryEntries = new HashSet<>();
    final List<GlobalDiscoveryEntry> globalDiscoveryEntries = new ArrayList<>();
    DiscoveryEntry discoveryEntry = new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantId", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId");
    discoveryEntries.add(discoveryEntry);
    globalDiscoveryEntries.add(CapabilityUtils.discoveryEntry2GlobalDiscoveryEntry(discoveryEntry, new MqttAddress()));
    when(globalDiscoveryEntryCacheMock.lookup(any(String[].class), eq(interfaceName), anyLong())).thenReturn(new HashSet<DiscoveryEntry>());
    Mockito.doAnswer(new Answer<Object>() {

        @SuppressWarnings("rawtypes")
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object[] arguments = invocation.getArguments();
            assert (arguments[0] instanceof Callback);
            ((Callback) arguments[0]).resolve((Object) globalDiscoveryEntries);
            return null;
        }
    }).when(globalCapabilitiesDirectoryClientMock).lookup(any(Callback.class), any(String[].class), eq(interfaceName), anyLong());
    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(), discoveryEntryWithMetaInfoArgumentCaptor.capture(), any(MessagingQos.class));
        assertDiscoveryEntryEqualsCaptured(discoveryEntry);
    } 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) 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) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 28 with DiscoveryQos

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

the class LocalDiscoveryTest method testLocalDiscoveryEntries.

@Test
public void testLocalDiscoveryEntries() {
    String testDomain = "testDomain";
    String interfaceName = testProxy.INTERFACE_NAME;
    Collection<DiscoveryEntry> discoveryEntries = new HashSet<>();
    DiscoveryEntry discoveryEntry = new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantId", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId");
    discoveryEntries.add(discoveryEntry);
    when(localDiscoveryEntryStoreMock.lookup(any(String[].class), eq(interfaceName))).thenReturn(discoveryEntries);
    ProxyBuilder<testProxy> proxyBuilder = runtime.getProxyBuilder(testDomain, testProxy.class);
    final Future<Void> future = new Future<Void>();
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_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(), discoveryEntryWithMetaInfoArgumentCaptor.capture(), any(MessagingQos.class));
        assertDiscoveryEntryEqualsCaptured(discoveryEntry);
    } 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) ProviderQos(joynr.types.ProviderQos) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 29 with DiscoveryQos

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

the class ShutdownTest method testProxyCallAfterShutdown.

@Test(expected = JoynrShutdownException.class)
@Ignore
public // test is taking too long because it is attempting to send deregister requests that are not implemented in the mocks
void testProxyCallAfterShutdown() throws DiscoveryException, JoynrIllegalStateException, InterruptedException {
    Mockito.when(messageReceiverMock.getChannelId()).thenReturn("ShutdownTestChannelId");
    dummyApplication.getRuntime().registerProvider("ShutdownTestdomain", provider, providerQos);
    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)

Example 30 with DiscoveryQos

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

the class ProxyErrorsTest method setUp.

@Before
public void setUp() {
    // the error callback and NoCompatibleProviderFoundException will each increment the permits.
    // The test will wait until 2 permits are available, or fail in the junit test timeout time.
    waitOnExceptionAndErrorCallbackSemaphore = new Semaphore(-1, true);
    domain = "domain-" + UUID.randomUUID().toString();
    domain2 = "domain2-" + UUID.randomUUID().toString();
    Properties joynrConfig = new Properties();
    joynrConfig.setProperty(MessagingPropertyKeys.CHANNELID, "discoverydirectory_channelid");
    // provider and proxy using same runtime to allow local-only communications
    runtime = getRuntime(joynrConfig);
    ProviderQos providerQos = new ProviderQos();
    providerQos.setScope(ProviderScope.LOCAL);
    runtime.registerProvider(domain, provider, providerQos);
    runtime.registerProvider(domain2, provider, providerQos);
    discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_ONLY);
    discoveryQos.setDiscoveryTimeoutMs(1000);
    discoveryQos.setRetryIntervalMs(100);
    callback = new ProxyCreatedCallback<ProxyErrorsTest.TestProxyWrongVersion>() {

        @Override
        public void onProxyCreationFinished(TestProxyWrongVersion result) {
            fail("proxy creation should fail with a version exception");
        }

        @Override
        public void onProxyCreationError(JoynrRuntimeException error) {
            // adds 1 of 2 permits to the semaphore. The other is provided when the exception is caught
            waitOnExceptionAndErrorCallbackSemaphore.release();
        }
    };
}
Also used : Semaphore(java.util.concurrent.Semaphore) Properties(java.util.Properties) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ProviderQos(joynr.types.ProviderQos) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) Before(org.junit.Before)

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