use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class IltConsumerAsyncMethodTest method callMethodWithMultipleStructParametersAsync.
@Test
public void callMethodWithMultipleStructParametersAsync() {
LOG.info(name.getMethodName() + "");
try {
// setup input parameters
ExtendedStructOfPrimitives extendedStructOfPrimitivesArg = IltUtil.createExtendedStructOfPrimitives();
BaseStruct baseStructArg = IltUtil.createBaseStruct();
MethodWithMultipleStructParametersCallback callback = new MethodWithMultipleStructParametersCallback() {
@Override
public void onSuccess(BaseStructWithoutElements baseStructWithoutElementsOut, ExtendedExtendedBaseStruct extendedExtendedBaseStructOut) {
// check results
if (!IltUtil.checkBaseStructWithoutElements(baseStructWithoutElementsOut)) {
methodWithMultipleStructParametersAsyncCallbackResult = false;
methodWithMultipleStructParametersAsyncCallbackDone = true;
LOG.info(name.getMethodName() + " - callback - invalid baseStructWithoutElementsOut");
LOG.info(name.getMethodName() + " - FAILED");
return;
}
if (!IltUtil.checkExtendedExtendedBaseStruct(extendedExtendedBaseStructOut)) {
methodWithMultipleStructParametersAsyncCallbackResult = false;
methodWithMultipleStructParametersAsyncCallbackDone = true;
LOG.info(name.getMethodName() + " - callback - invalid extendedExtendedBaseStructOut");
LOG.info(name.getMethodName() + " - FAILED");
return;
}
methodWithMultipleStructParametersAsyncCallbackResult = true;
methodWithMultipleStructParametersAsyncCallbackDone = true;
}
@Override
public void onFailure(JoynrRuntimeException error) {
methodWithMultipleStructParametersAsyncCallbackResult = false;
methodWithMultipleStructParametersAsyncCallbackDone = true;
if (error instanceof JoynrRuntimeException) {
LOG.info(name.getMethodName() + " - callback - caught exception " + ((JoynrRuntimeException) error).getMessage());
} else {
LOG.info(name.getMethodName() + " - callback - caught exception");
}
LOG.info(name.getMethodName() + " - FAILED");
}
};
MethodWithMultipleStructParametersFuture future = testInterfaceProxy.methodWithMultipleStructParameters(callback, extendedStructOfPrimitivesArg, baseStructArg);
try {
long timeoutInMilliseconds = 8000;
LOG.info(name.getMethodName() + " - about to call future.get");
MethodWithMultipleStructParametersReturned result = future.get(timeoutInMilliseconds);
if (result == null) {
fail(name.getMethodName() + " - FAILED - got no result");
return;
}
LOG.info(name.getMethodName() + " - returned from future.get");
// check results from future
if (!IltUtil.checkBaseStructWithoutElements(result.baseStructWithoutElementsOut)) {
fail(name.getMethodName() + " - FAILED - got invalid result - baseStructWithoutElementsOut");
return;
}
if (!IltUtil.checkExtendedExtendedBaseStruct(result.extendedExtendedBaseStructOut)) {
fail(name.getMethodName() + " - FAILED - got invalid result - extendedExtendedBaseStructOut");
return;
}
LOG.info(name.getMethodName() + " - future result checks OK");
// should have been called ahead anyway
if (methodWithMultipleStructParametersAsyncCallbackDone == false) {
LOG.info(name.getMethodName() + " - about to wait for a second for callback");
Thread.sleep(1000);
LOG.info(name.getMethodName() + " - wait for callback is over");
} else {
LOG.info(name.getMethodName() + " - callback already done");
}
if (methodWithMultipleStructParametersAsyncCallbackDone == false) {
fail(name.getMethodName() + " - FAILED - callback NOT done");
return;
}
if (methodWithMultipleStructParametersAsyncCallbackResult == false) {
fail(name.getMethodName() + " - FAILED - callback reported error");
return;
}
LOG.info(name.getMethodName() + " - callback has set OK flags");
} catch (InterruptedException | JoynrRuntimeException | ApplicationException e) {
fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
return;
}
} catch (Exception e) {
fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
return;
}
LOG.info(name.getMethodName() + " - OK");
}
use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class IltConsumerAttributeSubscriptionTest method callSubscribeAttributeWithExceptionFromGetter.
@Test
public void callSubscribeAttributeWithExceptionFromGetter() {
Future<String> subscriptionIdFuture;
String subscriptionId;
int minIntervalMs = 0;
int maxIntervalMs = 10000;
long validityMs = 60000;
int alertAfterIntervalMs = 20000;
int publicationTtlMs = 5000;
OnChangeWithKeepAliveSubscriptionQos subscriptionQos = new OnChangeWithKeepAliveSubscriptionQos().setMinIntervalMs(minIntervalMs).setMaxIntervalMs(maxIntervalMs).setValidityMs(validityMs).setAlertAfterIntervalMs(alertAfterIntervalMs).setPublicationTtlMs(publicationTtlMs);
boolean result;
LOG.info(name.getMethodName() + "");
try {
subscriptionIdFuture = testInterfaceProxy.subscribeToAttributeWithExceptionFromGetter(new AttributeSubscriptionAdapter<Boolean>() {
@Override
public void onReceive(Boolean value) {
LOG.info(name.getMethodName() + " - callback - got unexpected publication");
subscribeAttributeWithExceptionFromGetterCallbackResult = false;
subscribeAttributeWithExceptionFromGetterCallbackDone = true;
}
@Override
public void onError(JoynrRuntimeException error) {
if (error instanceof ProviderRuntimeException) {
if (((ProviderRuntimeException) error).getMessage().equals("Exception from getAttributeWithExceptionFromGetter")) {
LOG.info(name.getMethodName() + " - callback - got expected exception " + ((JoynrRuntimeException) error).getMessage());
subscribeAttributeWithExceptionFromGetterCallbackResult = true;
subscribeAttributeWithExceptionFromGetterCallbackDone = true;
return;
}
LOG.info(name.getMethodName() + " - callback - caught invalid exception " + ((JoynrRuntimeException) error).getMessage());
} else if (error instanceof JoynrRuntimeException) {
LOG.info(name.getMethodName() + " - callback - caught invalid exception " + ((JoynrRuntimeException) error).getMessage());
} else {
LOG.info(name.getMethodName() + " - callback - caught invalid exception ");
}
subscribeAttributeWithExceptionFromGetterCallbackResult = false;
subscribeAttributeWithExceptionFromGetterCallbackDone = true;
}
}, subscriptionQos);
subscriptionId = subscriptionIdFuture.get(10000);
LOG.info(name.getMethodName() + " - subscription successful, subscriptionId = " + subscriptionId);
// should have been called ahead anyway
if (subscribeAttributeWithExceptionFromGetterCallbackDone == false) {
LOG.info(name.getMethodName() + " - about to wait for a second for callback");
Thread.sleep(1000);
LOG.info(name.getMethodName() + " - wait for callback is over");
} else {
LOG.info(name.getMethodName() + " - callback already done");
}
if (!subscribeAttributeWithExceptionFromGetterCallbackDone) {
fail(name.getMethodName() + " - FAILED - callback did not get called in time");
result = false;
} else if (subscribeAttributeWithExceptionFromGetterCallbackResult) {
LOG.info(name.getMethodName() + " - callback got called and received expected exception");
result = true;
} else {
fail(name.getMethodName() + " - FAILED - callback got called but received unexpected result");
result = false;
}
// try to unsubscribe in any case
try {
testInterfaceProxy.unsubscribeFromAttributeWithExceptionFromGetter(subscriptionId);
LOG.info(name.getMethodName() + " - unsubscribe successful");
} catch (Exception e) {
fail(name.getMethodName() + " - FAILED - caught unexpected exception on unsubscribe: " + e.getMessage());
result = false;
}
if (!result) {
LOG.info(name.getMethodName() + " - FAILED");
} else {
LOG.info(name.getMethodName() + " - OK");
}
return;
} catch (Exception e) {
// also catches InterruptedException from Thread.sleep() call
LOG.info(name.getMethodName() + " - caught unexpected exception");
LOG.info(name.getMethodName() + " - FAILED");
fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
return;
}
}
use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class IltConsumerTest method setupConsumerRuntime.
protected static void setupConsumerRuntime(boolean msgQosCompressed) throws DiscoveryException, JoynrIllegalStateException, InterruptedException {
LOG.info("setupConsumerRuntime: Entering");
final String configFileName = "ilt-consumer-test.settings";
InputStream resourceStream;
try {
resourceStream = new FileInputStream("src/main/resources/" + configFileName);
} catch (IOException e) {
LOG.error("setupConsumerRuntime: Error", e);
resourceStream = null;
}
Properties joynrConfig = new Properties();
try {
if (resourceStream != null) {
LOG.info("setupConsumerRuntime: resources from " + configFileName);
joynrConfig.load(resourceStream);
}
} catch (IOException ex) {
LOG.info("setupConsumerRuntime: not load the configuration file: " + configFileName + ": " + ex);
}
joynrConfig.setProperty(MessagingPropertyKeys.PERSISTENCE_FILE, STATIC_PERSISTENCE_FILE);
joynrConfig.setProperty(AbstractJoynrApplication.PROPERTY_JOYNR_DOMAIN_LOCAL, "inter_language_test_consumer_local_domain");
consumerRuntime = getRuntime(joynrConfig);
DiscoveryQos discoveryQos = new DiscoveryQos();
discoveryQos.setDiscoveryTimeoutMs(10000);
discoveryQos.setCacheMaxAgeMs(Long.MAX_VALUE);
discoveryQos.setArbitrationStrategy(ArbitrationStrategy.HighestPriority);
ProxyBuilder<TestInterfaceProxy> proxyBuilder = consumerRuntime.getProxyBuilder(providerDomain, TestInterfaceProxy.class);
MessagingQos messagingQos = new MessagingQos(10000);
messagingQos.setCompress(msgQosCompressed);
LOG.info("setupConsumerRuntime: msgQosCompression = " + msgQosCompressed);
testInterfaceProxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build(new ProxyCreatedCallback<TestInterfaceProxy>() {
@Override
public void onProxyCreationFinished(TestInterfaceProxy result) {
LOG.info("proxy created");
proxyCreated.release();
}
@Override
public void onProxyCreationError(JoynrRuntimeException error) {
LOG.info("error creating proxy");
}
});
if (testInterfaceProxy == null) {
LOG.info("setupConsumerRuntime: proxy = null");
} else {
LOG.info("setupConsumerRuntime: proxy is set != null");
}
// wait until proxy creation is finished or discovery timeout +
// 1 second grace period have passed
proxyCreated.tryAcquire(11000, TimeUnit.MILLISECONDS);
}
use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class HttpBridgeEndpointRegistryClient method scheduleWithRetries.
/**
* This method uses the {@link #scheduledExecutorService} in order to schedule an attempt to register the
* endpointUrl and channelId (topic) with the registration service HTTP ReST endpoint. If there is a problem with
* the attempt, then up-to 'remainingRetries' attempts will be made, by calling this method again from within the
* scheduled action.<br>
* Once the registration is successful or the number of retries runs out, then the passed in
* <code>CompletableFuture</code> is completed, so that any subsequent actions / error handling can be triggered.
*
* @param result
* the completable future which will be completed upon success or we run out of retries.
* @param delay
* the delay for scheduling the action with the {@link #scheduledExecutorService}.
* @param remainingRetries
* the remaining number of retries we can attempt on any errors during registration.
* @param endpointUrl
* the endpoint URL to be registered.
* @param channelId
* the channel ID to be registered.
*/
private void scheduleWithRetries(CompletableFuture<Void> result, long delay, int remainingRetries, String endpointUrl, String channelId) {
if (remainingRetries <= 0) {
result.completeExceptionally(new JoynrRuntimeException("Unable to register channel. Too many unsuccessful retries."));
} else {
LOG.debug("Scheduling execution of HTTP post for registering endpoint {} for channel {}.", endpointUrl, channelId);
scheduledExecutorService.schedule(() -> {
String topic = channelId;
HttpPost message = new HttpPost(endpointRegistryUri);
message.addHeader("Content-Type", MediaType.APPLICATION_JSON);
try {
HttpEntity entity = new StringEntity(format("{\"endpointUrl\": \"%s\", \"topic\": \"%s\"}", endpointUrl, topic));
message.setEntity(entity);
boolean executionResult = executeRequest(message);
if (executionResult) {
result.complete(null);
return;
}
} catch (IOException e) {
LOG.error(format("Unable to register endpoint %s / channel ID %s with broker at %s.", endpointUrl, channelId, endpointRegistryUri), e);
}
scheduleWithRetries(result, 10L, remainingRetries - 1, endpointUrl, channelId);
}, delay, TimeUnit.SECONDS);
}
}
use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class PromiseKeeperTest method keeperStateIsCorrectOnRejection.
@Test
public void keeperStateIsCorrectOnRejection() {
AbstractDeferred deferred = new AbstractDeferred() {
};
Promise<AbstractDeferred> promise = new Promise<AbstractDeferred>(deferred);
PromiseKeeper keeper = new PromiseKeeper();
promise.then(keeper);
Assert.assertFalse(keeper.isSettled());
Assert.assertFalse(keeper.isRejected());
Assert.assertFalse(keeper.isFulfilled());
deferred.reject(new JoynrRuntimeException());
Assert.assertTrue(keeper.isSettled());
Assert.assertTrue(keeper.isRejected());
Assert.assertFalse(keeper.isFulfilled());
}
Aggregations