protected IAsyncResultHandler<Void> latchedResultHandler(CountDownLatch latch, Set<Throwable> errorHolder) { return result -> { if (result.isError()) { errorHolder.add(result.getError()); } latch.countDown(); }; }
@Override public void handle(IAsyncResult<Void> result) { if (result.isError()) { errorHolder.add(result.getError()); } } });
protected IAsyncResultHandler<Void> latchedResultHandler(CountDownLatch latch, Set<Throwable> errorHolder) { return result -> { if (result.isError()) { errorHolder.add(result.getError()); } latch.countDown(); }; }
@Override public void handle(IAsyncResult<Void> result) { if (result.isError()) { errorHolder.add(result.getError()); } } });
private IAsyncResultHandler<Void> handleAnyFailure() { return result -> { if (result.isError()) { failAll(result.getError()); throw new RuntimeException(result.getError()); } }; }
@Override public void handle(IAsyncResult<Void> result) { if (result.isError()) { log.error("Error {0}", result.getError()); throw new RuntimeException(result.getError()); } } }
private IAsyncResultHandler<Void> handleAnyFailure() { return result -> { if (result.isError()) { failAll(result.getError()); throw new RuntimeException(result.getError()); } }; }
@Override public void publish(Api api) throws PublishingException, NotAuthorizedException { registry.publishApi(api, (IAsyncResultHandler<Void>) result -> { if (result.isError()) { throwError(result.getError()); } }); }
private IAsyncResultHandler<Void> handleAnyFailure() { return result -> { if (result.isError()) { log.error(result.getError()); failAll(result.getError()); } }; }
@Override public void handle(IAsyncResult<IJdbcConnection> result) { if (result.isError()) { handler.handle(AsyncResultImpl.create(result.getError(), Boolean.class)); } else { validate(result.getResult(), query, queryUsername, queryPassword, context, config, handler); } } });
@Override public void handle(IAsyncResult<T> result) { if (result.isError()) { errorHandler.handle(AsyncResultImpl.<Q>create(result.getError())); } else { successHandler.handle(result.getResult()); } } };
@Override public void retire(String organizationId, String apiId, String version) throws RegistrationException, NotAuthorizedException { Api api = new Api(); api.setOrganizationId(organizationId); api.setApiId(apiId); api.setVersion(version); registry.retireApi(api, (IAsyncResultHandler<Void>) result -> { if (result.isError()) { throwError(result.getError()); } }); }
@Override public void handle(IAsyncResult<RateLimitResponse> result) { if (result.isError()) { chain.throwError(result.getError()); } else { RateLimitResponse rtr = result.getResult(); context.setAttribute(RATE_LIMIT_RESPONSE_ATTR, rtr); if (!rtr.isAccepted()) { doQuotaExceededFailure(context, config, chain, rtr); } else { chain.doApply(request); } } } });
@Override public void handle(IAsyncResult<ISignalReadStream<ApiResponse>> result) { if (result.isError()) { chain.throwError(result.getError()); } else { ISignalReadStream<ApiResponse> cacheEntry = result.getResult(); if (cacheEntry != null) { context.setConnectorInterceptor(new CacheConnectorInterceptor(cacheEntry)); context.setAttribute(SHOULD_CACHE_ATTR, Boolean.FALSE); context.setAttribute(CACHED_RESPONSE, cacheEntry.getHead()); } chain.doApply(request); } } });
protected <T> void handleError(IAsyncResult<IHttpClientResponse> result, IAsyncResultHandler<T> handler) { if (result.isError()) { handler.handle(AsyncResultImpl.<T> create(result.getError())); } else if (result.getResult().getResponseCode() != 200) { handler.handle(AsyncResultImpl.<T> create(new InfluxException("Influx: " //$NON-NLS-1$ + result.getResult().getResponseCode() + " " + result.getResult().getResponseMessage()))); //$NON-NLS-1$ } }
protected <T> void handleError(IAsyncResult<IHttpClientResponse> result, IAsyncResultHandler<T> handler) { if (result.isError()) { handler.handle(AsyncResultImpl.<T> create(result.getError())); } else if (result.getResult().getResponseCode() != 200) { handler.handle(AsyncResultImpl.<T> create(new InfluxException("Influx: " //$NON-NLS-1$ + result.getResult().getResponseCode() + " " + result.getResult().getResponseMessage()))); //$NON-NLS-1$ } }
@Test public void testExceptionInExecuteBlock(TestContext context) { Async async = context.async(); executeBlockingComponent.executeBlocking(future -> { throw new ExampleException("Desroches"); }, result -> { context.assertFalse(result.isSuccess()); context.assertTrue(result.isError()); context.assertTrue(result.getError() instanceof ExampleException); context.assertEquals(result.getError().getMessage(), "Desroches"); context.assertNull(result.getResult()); async.complete(); }); }
@Test public void testFailedExecution(TestContext context) { Async async = context.async(); executeBlockingComponent.executeBlocking(future -> { future.fail(new ExampleException("Silhoutte")); }, result -> { context.assertFalse(result.isSuccess()); context.assertTrue(result.isError()); context.assertTrue(result.getError() instanceof ExampleException); context.assertEquals(result.getError().getMessage(), "Silhoutte"); context.assertNull(result.getResult()); async.complete(); }); }
@Test public void testSuccessfulExecution(TestContext context) { Async async = context.async(); executeBlockingComponent.executeBlocking(future -> { future.completed("The Farquhar Islands"); }, result -> { context.assertTrue(result.isSuccess()); context.assertFalse(result.isError()); context.assertEquals(result.getResult(), "The Farquhar Islands"); context.assertNull(result.getError()); async.complete(); }); }
@Test public void shouldFailWhenUidInvalid() throws InterruptedException { config.setBindDn("uid=tacos,ou=system"); config.setBindPassword("secret"); TestCompletion completion = TestSuite.create("").test("", context -> { Async async = context.async(); ldapClientComponent.bind(config, result -> { if (result.isError()) result.getError().printStackTrace(System.out); context.assertTrue(result.isSuccess()); context.assertTrue(result.getResult().getResultCode().equals(LdapResultCode.INVALID_CREDENTIALS)); async.complete(); }); async.awaitSuccess(); }).run(); completion.awaitSuccess(); }