Search in sources :

Example 6 with JoynrException

use of io.joynr.exceptions.JoynrException in project joynr by bmwcarit.

the class PromiseKeeperTest method getErrorWaitsForRejection.

@Test
public void getErrorWaitsForRejection() throws InterruptedException {
    final AbstractDeferred deferred = new AbstractDeferred() {
    };
    Promise<AbstractDeferred> promise = new Promise<AbstractDeferred>(deferred);
    PromiseKeeper keeper = new PromiseKeeper();
    final JoynrRuntimeException expectedError = new JoynrRuntimeException("test exception");
    promise.then(keeper);
    executer.submit(new Runnable() {

        @Override
        public void run() {
            // give test some time to proceed, so getError runs into wait
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            // ignore
            }
            deferred.reject(expectedError);
        }
    });
    JoynrException error = keeper.getError();
    Assert.assertEquals(expectedError, error);
}
Also used : JoynrException(io.joynr.exceptions.JoynrException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 7 with JoynrException

use of io.joynr.exceptions.JoynrException in project joynr by bmwcarit.

the class RequestInterpreter method execute.

public void execute(final ProviderCallback<Reply> callback, RequestCaller requestCaller, final Request request) {
    Promise<? extends AbstractDeferred> promise;
    logger.debug("execute request on provider: {}", request);
    try {
        promise = (Promise<?>) invokeMethod(requestCaller, request);
    } catch (MethodInvocationException | ProviderRuntimeException e) {
        logger.warn("execute request on provider failed with exception: {}, request: {}", e, request);
        callback.onFailure(e);
        return;
    } catch (Exception e) {
        JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(requestCaller.getProxy().getClass(), JoynrVersion.class);
        MethodInvocationException methodInvocationException = new MethodInvocationException(e, new Version(joynrVersion.major(), joynrVersion.minor()));
        logger.warn("execute request on provider failed with exception: {}, request: {}", methodInvocationException, request);
        callback.onFailure(methodInvocationException);
        return;
    }
    promise.then(new PromiseListener() {

        @Override
        public void onRejection(JoynrException error) {
            logger.debug("execute request on provider onRejection: {}, request: {}", error, request);
            callback.onFailure(error);
        }

        @Override
        public void onFulfillment(Object... values) {
            logger.debug("execute request on provider onFulfillment: {}, request: {}", values, request);
            callback.onSuccess(createReply(request, values));
        }
    });
}
Also used : JoynrVersion(io.joynr.JoynrVersion) JoynrVersion(io.joynr.JoynrVersion) Version(joynr.types.Version) PromiseListener(io.joynr.provider.PromiseListener) JoynrException(io.joynr.exceptions.JoynrException) MethodInvocationException(joynr.exceptions.MethodInvocationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) MethodInvocationException(joynr.exceptions.MethodInvocationException) JoynrException(io.joynr.exceptions.JoynrException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Example 8 with JoynrException

use of io.joynr.exceptions.JoynrException in project joynr by bmwcarit.

the class ProviderWrapperTest method testInvokeMethodThrowingProviderRuntimeException.

@Test
public void testInvokeMethodThrowingProviderRuntimeException() throws Throwable {
    ProviderWrapper subject = createSubject();
    JoynrProvider proxy = createProxy(subject);
    Method method = TestServiceProviderInterface.class.getMethod("testThrowsProviderRuntimeException");
    Object result = subject.invoke(proxy, method, new Object[0]);
    assertNotNull(result);
    assertTrue(result instanceof Promise);
    assertTrue(((Promise<?>) result).isRejected());
    ((Promise<?>) result).then(new PromiseListener() {

        @Override
        public void onFulfillment(Object... values) {
            fail("Should never get here");
        }

        @Override
        public void onRejection(JoynrException error) {
            assertTrue(error instanceof ProviderRuntimeException);
        }
    });
}
Also used : Promise(io.joynr.provider.Promise) PromiseListener(io.joynr.provider.PromiseListener) JoynrException(io.joynr.exceptions.JoynrException) Method(java.lang.reflect.Method) JoynrProvider(io.joynr.provider.JoynrProvider) ProviderWrapper(io.joynr.jeeintegration.ProviderWrapper) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) Test(org.junit.Test)

Example 9 with JoynrException

use of io.joynr.exceptions.JoynrException in project joynr by bmwcarit.

the class ProviderWrapperTest method assertPromiseEquals.

private void assertPromiseEquals(Object result, Object value) {
    assertTrue(((Promise<?>) result).isFulfilled());
    Boolean[] ensureFulfilled = new Boolean[] { false };
    ((Promise<?>) result).then(new PromiseListener() {

        @Override
        public void onRejection(JoynrException error) {
            Assert.fail();
        }

        @Override
        public void onFulfillment(Object... values) {
            assertEquals(value, values[0]);
            ensureFulfilled[0] = true;
        }
    });
    assertTrue(ensureFulfilled[0]);
}
Also used : Promise(io.joynr.provider.Promise) PromiseListener(io.joynr.provider.PromiseListener) JoynrException(io.joynr.exceptions.JoynrException)

Example 10 with JoynrException

use of io.joynr.exceptions.JoynrException in project joynr by bmwcarit.

the class ProviderWrapperTest method testInvokeMethodThrowingApplicationException.

@Test
public void testInvokeMethodThrowingApplicationException() throws Throwable {
    ProviderWrapper subject = createSubject();
    JoynrProvider proxy = createProxy(subject);
    Method method = TestServiceProviderInterface.class.getMethod("testThrowsApplicationException");
    Object result = subject.invoke(proxy, method, new Object[0]);
    assertNotNull(result);
    assertTrue(result instanceof Promise);
    assertTrue(((Promise<?>) result).isRejected());
    ((Promise<?>) result).then(new PromiseListener() {

        @Override
        public void onFulfillment(Object... values) {
            fail("Should never get here");
        }

        @Override
        public void onRejection(JoynrException error) {
            assertTrue(error instanceof ApplicationException);
        }
    });
}
Also used : Promise(io.joynr.provider.Promise) ApplicationException(joynr.exceptions.ApplicationException) PromiseListener(io.joynr.provider.PromiseListener) JoynrException(io.joynr.exceptions.JoynrException) Method(java.lang.reflect.Method) JoynrProvider(io.joynr.provider.JoynrProvider) ProviderWrapper(io.joynr.jeeintegration.ProviderWrapper) Test(org.junit.Test)

Aggregations

JoynrException (io.joynr.exceptions.JoynrException)13 PromiseListener (io.joynr.provider.PromiseListener)8 Test (org.junit.Test)6 Promise (io.joynr.provider.Promise)5 Method (java.lang.reflect.Method)4 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)4 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)3 ProviderWrapper (io.joynr.jeeintegration.ProviderWrapper)3 DeferredVoid (io.joynr.provider.DeferredVoid)3 JoynrProvider (io.joynr.provider.JoynrProvider)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Version (joynr.types.Version)3 ApplicationException (joynr.exceptions.ApplicationException)2 DiscoveryEntry (joynr.types.DiscoveryEntry)2 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)2 ProviderQos (joynr.types.ProviderQos)2 AbstractModule (com.google.inject.AbstractModule)1 TypeLiteral (com.google.inject.TypeLiteral)1 JoynrVersion (io.joynr.JoynrVersion)1 JoynrPropertiesModule (io.joynr.common.JoynrPropertiesModule)1