use of io.joynr.exceptions.JoynrException in project joynr by bmwcarit.
the class LocalCapabilitiesDirectoryTest method addGlobalCapSucceeds_NextAddShallNotAddGlobalAgain.
@SuppressWarnings("unchecked")
@Test(timeout = 1000)
public void addGlobalCapSucceeds_NextAddShallNotAddGlobalAgain() throws InterruptedException {
ProviderQos providerQos = new ProviderQos();
providerQos.setScope(ProviderScope.GLOBAL);
String participantId = LocalCapabilitiesDirectoryTest.class.getName() + ".addGlobalCapSucceeds_NextAddShallNotAddGlobalAgain";
String domain = "testDomain";
final DiscoveryEntry discoveryEntry = new DiscoveryEntry(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, participantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId);
globalDiscoveryEntry = new GlobalDiscoveryEntry(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, participantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId, channelAddressSerialized);
Promise<DeferredVoid> promise = localCapabilitiesDirectory.add(discoveryEntry);
promise.then(new PromiseListener() {
@Override
public void onFulfillment(Object... values) {
Mockito.doAnswer(createAddAnswerWithSuccess()).when(globalCapabilitiesClient).add(any(Callback.class), eq(globalDiscoveryEntry));
verify(globalDiscoveryEntryCacheMock).add(eq(globalDiscoveryEntry));
verify(globalCapabilitiesClient).add(any(Callback.class), eq(globalDiscoveryEntry));
reset(globalCapabilitiesClient);
localCapabilitiesDirectory.add(discoveryEntry);
verify(globalCapabilitiesClient, timeout(200).never()).add(any(Callback.class), eq(globalDiscoveryEntry));
}
@Override
public void onRejection(JoynrException error) {
Assert.fail("adding capability failed: " + error);
}
});
}
use of io.joynr.exceptions.JoynrException in project joynr by bmwcarit.
the class ProviderWrapperTest method testInvokeMultiOutMethod.
@Test
public void testInvokeMultiOutMethod() throws Throwable {
ProviderWrapper subject = createSubject();
JoynrProvider proxy = createProxy(subject);
Method method = TestServiceProviderInterface.class.getMethod("testMultiOutMethod");
Object result = subject.invoke(proxy, method, new Object[0]);
assertTrue(result instanceof Promise);
Promise<?> promise = (Promise<?>) result;
assertTrue(promise.isFulfilled());
promise.then(new PromiseListener() {
@Override
public void onFulfillment(Object... values) {
assertArrayEquals(new Object[] { "one", "two" }, values);
}
@Override
public void onRejection(JoynrException error) {
fail("Shouldn't be here.");
}
});
}
use of io.joynr.exceptions.JoynrException in project joynr by bmwcarit.
the class ProviderWrapper method invoke.
/**
* When a method is invoked via a joynr call, then it is delegated to an instance of the bean with which this
* instance was initialised, if the method is part of the business interface and to this instance if it was part of
* the {@link JoynrProvider} interface or the <code>Object</code> class.
*
* @param proxy
* the proxy object on which the method was called.
* @param method
* the specific method which was called.
* @param args
* the arguments with which the method was called.
*
* @return the result of the delegate method call on the EJB, but wrapped in a promise, as all the provider methods
* in joynr are declared that way.
*/
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
boolean isProviderMethod = matchesJoynrProviderMethod(method);
Method delegateToMethod = getMethodFromInterfaces(bean.getBeanClass(), method, isProviderMethod);
Object delegate = createDelegateForMethod(method, isProviderMethod);
Object result = null;
try {
if (isProviderMethod(method, delegateToMethod)) {
JoynrJeeMessageContext.getInstance().activate();
copyMessageCreatorInfo();
copyMessageContext();
}
JoynrException joynrException = null;
try {
result = delegateToMethod.invoke(delegate, args);
} catch (InvocationTargetException e) {
joynrException = getJoynrExceptionFromInvocationException(e);
}
if (delegate != this) {
AbstractDeferred deferred = createAndResolveOrRejectDeferred(method, result, joynrException);
Promise<AbstractDeferred> promiseResult = new Promise<>(deferred);
return promiseResult;
}
} finally {
if (isProviderMethod(method, delegateToMethod)) {
JoynrJeeMessageContext.getInstance().deactivate();
}
}
return result;
}
use of io.joynr.exceptions.JoynrException in project joynr by bmwcarit.
the class PublicationManagerImpl method triggerPublication.
private void triggerPublication(final PublicationInformation publicationInformation, ProviderContainer providerContainer, Method method) {
try {
Promise<?> attributeGetterPromise = attributePollInterpreter.execute(providerContainer, method);
attributeGetterPromise.then(new PromiseListener() {
@Override
public void onRejection(JoynrException error) {
if (error instanceof JoynrRuntimeException) {
sendPublicationError((JoynrRuntimeException) error, publicationInformation);
} else {
sendPublicationError(new ProviderRuntimeException("Unexpected exception while calling getter for attribute " + publicationInformation.getSubscribedToName()), publicationInformation);
}
}
@Override
public void onFulfillment(Object... values) {
// attribute getters only return a single value
sendPublication(prepareAttributePublication(values[0], publicationInformation.getSubscriptionId()), publicationInformation);
}
});
} catch (JoynrRuntimeException error) {
sendPublicationError(error, publicationInformation);
}
}
use of io.joynr.exceptions.JoynrException in project joynr by bmwcarit.
the class RpcAsyncRequestReplyCaller method error.
@Override
public void error(Throwable error) {
JoynrException joynrException;
// wrap non-joynr exceptions in a JoynrRuntimeException
if (error instanceof JoynrException) {
joynrException = (JoynrException) error;
} else {
joynrException = new JoynrRuntimeException(error);
}
errorCallback(joynrException);
if (future != null) {
future.onFailure(joynrException);
}
}
Aggregations