Search in sources :

Example 6 with Future

use of io.joynr.proxy.Future 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 7 with Future

use of io.joynr.proxy.Future in project joynr by bmwcarit.

the class AbstractProviderProxyEnd2EndTest method testVoidOperation.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void testVoidOperation() throws DiscoveryException, JoynrIllegalStateException, InterruptedException, JoynrWaitExpiredException, ApplicationException {
    ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
    testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    final Future<Boolean> future = new Future<Boolean>();
    proxy.voidOperation(new Callback<Void>() {

        @Override
        public void onSuccess(Void result) {
            future.onSuccess(true);
        }

        @Override
        public void onFailure(JoynrRuntimeException error) {
            future.onFailure(error);
        }
    });
    Boolean reply = future.get(8000);
    assertTrue(reply);
}
Also used : joynr.tests.testProxy(joynr.tests.testProxy) Future(io.joynr.proxy.Future) DeferredVoid(io.joynr.provider.DeferredVoid) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 8 with Future

use of io.joynr.proxy.Future in project joynr by bmwcarit.

the class AccessControllerEnd2EndTest method createProxy.

private testProxy createProxy(JoynrRuntime runtime) {
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_ONLY);
    discoveryQos.setArbitrationStrategy(ArbitrationStrategy.HighestPriority);
    discoveryQos.setDiscoveryTimeoutMs(DISCOVERY_TIMEOUT);
    MessagingQos messagingQos = new MessagingQos();
    messagingQos.setTtl_ms(MESSAGING_TTL);
    final Future<Void> future = new Future<Void>();
    testProxy testProxy;
    testProxy = runtime.getProxyBuilder(TEST_DOMAIN, testProxy.class).setDiscoveryQos(discoveryQos).setMessagingQos(messagingQos).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);
    } catch (Exception e) {
        Assert.fail("Unexpected exception from ProxyCreatedCallback: " + e);
    }
    return testProxy;
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) joynr.tests.testProxy(joynr.tests.testProxy) Future(io.joynr.proxy.Future) ProxyCreatedCallback(io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) JoynrMessageNotSentException(io.joynr.exceptions.JoynrMessageNotSentException) ExpectedException(org.junit.rules.ExpectedException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException)

Example 9 with Future

use of io.joynr.proxy.Future in project joynr by bmwcarit.

the class LocalCapabilitiesDirectoryTest method createAddAnswerWithError.

private Answer<Future<Void>> createAddAnswerWithError() {
    return new Answer<Future<Void>>() {

        @SuppressWarnings("unchecked")
        @Override
        public Future<Void> answer(InvocationOnMock invocation) throws Throwable {
            Future<Void> result = new Future<Void>();
            Object[] args = invocation.getArguments();
            ((Callback<Void>) args[0]).onFailure(new JoynrRuntimeException("Simulating a JoynrRuntimeException on callback"));
            result.onSuccess(null);
            return result;
        }
    };
}
Also used : Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) Callback(io.joynr.proxy.Callback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Future(io.joynr.proxy.Future) DeferredVoid(io.joynr.provider.DeferredVoid) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException)

Aggregations

JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)9 Future (io.joynr.proxy.Future)9 joynr.tests.testProxy (joynr.tests.testProxy)6 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)5 MessagingQos (io.joynr.messaging.MessagingQos)5 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 Callback (io.joynr.proxy.Callback)4 DiscoveryEntry (joynr.types.DiscoveryEntry)4 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)4 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)4 ProviderQos (joynr.types.ProviderQos)4 Matchers.anyString (org.mockito.Matchers.anyString)4 ProxyCreatedCallback (io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 DeferredVoid (io.joynr.provider.DeferredVoid)2 ArrayList (java.util.ArrayList)2 MqttAddress (joynr.system.RoutingTypes.MqttAddress)2 ArbitrationStrategyFunction (io.joynr.arbitration.ArbitrationStrategyFunction)1 JoynrMessageNotSentException (io.joynr.exceptions.JoynrMessageNotSentException)1