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);
}
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));
}
});
}
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);
}
});
}
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]);
}
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);
}
});
}
Aggregations