List of usage examples for java.util.concurrent ExecutionException getCause
public synchronized Throwable getCause()
From source file:org.jboss.test.cluster.defaultcfg.web.test.CleanShutdownTestCase.java
public void testShutdown() throws Exception { ExecutorService executor = Executors.newFixedThreadPool(MAX_THREADS); try {//from w w w .j av a 2 s. c o m // Make sure a normal request will succeed Assert.assertEquals(200, new RequestTask(0).call().intValue()); // Send a long request - in parallel Future<Integer> future = executor.submit(new RequestTask(REQUEST_DURATION)); // Make sure long request has started Thread.sleep(1000); // Shutdown server this.server.invoke(this.name, SHUTDOWN_METHOD, null, null); // Get result of long request // This request should succeed since it initiated before server shutdown try { Assert.assertEquals(200, future.get().intValue()); } catch (ExecutionException e) { e.printStackTrace(System.err); Assert.fail(e.getCause().getMessage()); } // Subsequent request should return 404 Assert.assertEquals(404, new RequestTask(0).call().intValue()); } finally { executor.shutdownNow(); } }
From source file:com.streamsets.pipeline.stage.processor.mongodb.MongoDBProcessor.java
@Override protected void process(Record record, SingleLaneBatchMaker batchMaker) throws StageException { // Construct a document for lookup filter Document query = new Document(); for (MongoDBFieldColumnMapping mapping : configBean.fieldMapping) { // if record doesn't have a field specified in the mapping, or value is null, // exclude the field from filter, instead of sending to error. if (record.has(mapping.sdcField) && record.get(mapping.sdcField) != null) { query.append(mapping.keyName, record.get(mapping.sdcField).getValue()); }//from ww w .j a v a 2 s. c o m } // If all of the filters are missing in record, we cannot perform lookup. if (query.isEmpty()) { throw new OnRecordErrorException(Errors.MONGODB_42, record); } Optional<List<Map<String, Field>>> entry; try { entry = cache.get(query); } catch (ExecutionException e) { Throwables.propagateIfPossible(e.getCause(), StageException.class); throw new IllegalStateException(e); // The cache loader shouldn't throw anything that isn't a StageException. } if (entry.isPresent()) { List<Map<String, Field>> values = entry.get(); switch (configBean.multipleValuesBehavior) { case FIRST_ONLY: setFieldsInRecord(record, values.get(0)); batchMaker.addRecord(record); break; case SPLIT_INTO_MULTIPLE_RECORDS: for (Map<String, Field> lookupItem : values) { Record newRecord = getContext().cloneRecord(record); setFieldsInRecord(newRecord, lookupItem); batchMaker.addRecord(newRecord); } break; default: throw new IllegalStateException( "Unknown multiple value behavior: " + configBean.multipleValuesBehavior); } } else { // No results switch (configBean.missingValuesBehavior) { case SEND_TO_ERROR: LOG.error(Errors.MONGODB_40.getMessage(), query.toJson()); errorRecordHandler.onError(new OnRecordErrorException(record, Errors.MONGODB_40, query.toJson())); break; case PASS_RECORD_ON: batchMaker.addRecord(record); break; default: throw new IllegalStateException( "Unknown missing value behavior: " + configBean.missingValuesBehavior); } } }
From source file:io.ventu.rpc.integration.rest.TestRestInvocationRoundtrip.java
@Test public void invoke_basicRoundtrip_server401_error() throws InterruptedException, TimeoutException, ExecutionException { RemoteInvoker invoker = HttpRestInvoker.host("localhost").port(23332).ssl(false).build(); try {/*from ww w .java 2s. c o m*/ CompletableFuture<Res> future = invoker.invoke(new Req(25), Res.class); exception.expect(ExecutionException.class); future.get(500, TimeUnit.MILLISECONDS); } catch (ExecutionException ex) { HttpException cause = (HttpException) ex.getCause(); assertEquals(401, cause.getStatusCode()); throw ex; } finally { invoker.close().get(500, TimeUnit.MILLISECONDS); } }
From source file:io.ventu.rpc.integration.rest.TestRestInvocationRoundtrip.java
@Test public void invoke_basicRoundtrip_server500_error() throws InterruptedException, TimeoutException, ExecutionException { RemoteInvoker invoker = HttpRestInvoker.host("localhost").port(23332).header("APIKEY", "123").ssl(false) .build();//from w w w .ja v a2s. c o m try { CompletableFuture<Res> future = invoker.invoke(new Unsupported(25), Res.class); exception.expect(ExecutionException.class); future.get(500, TimeUnit.MILLISECONDS); } catch (ExecutionException ex) { HttpException cause = (HttpException) ex.getCause(); assertEquals(500, cause.getStatusCode()); throw ex; } finally { invoker.close().get(500, TimeUnit.MILLISECONDS); } }
From source file:com.asakusafw.runtime.stage.temporary.TemporaryFileOutputHelper.java
private void flushBuffer() throws IOException, InterruptedException { if (running == null) { return;//from w w w. ja v a 2 s.c o m } Result result; try { result = running.get(); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof IOException) { throw new IOException("Exception occurred while writing contents", cause); } else if (cause instanceof InterruptedException) { throw (InterruptedException) cause; } else if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } else if (cause instanceof Error) { throw (Error) cause; } throw new IllegalStateException(cause); } finally { running = null; } this.positionInBlock = result.positionInBlock; // releases the written buffer this.available.addFirst(result.buffer); }
From source file:com.example.AzureADAuthenticationFilter.java
private AuthenticationResult getAccessTokenFromClientCredentials() throws Throwable { AuthenticationContext context = null; AuthenticationResult result = null;//from w w w. jav a2s . c o m ExecutorService service = null; try { service = Executors.newFixedThreadPool(1); context = new AuthenticationContext(authority + tenant + "/", true, service); Future<AuthenticationResult> future = context.acquireToken("https://graph.windows.net", new ClientCredential(clientId, clientSecret), null); result = future.get(); } catch (ExecutionException e) { throw e.getCause(); } finally { service.shutdown(); } if (result == null) { throw new ServiceUnavailableException("authentication result was null"); } return result; }
From source file:io.ventu.rpc.integration.rest.TestRestInvocationRoundtrip.java
@Test public void invoke_basicRoundtrip_responseValidator_error() throws InterruptedException, TimeoutException, ExecutionException { RemoteInvoker invoker = HttpRestInvoker.host("localhost").port(23332).header("APIKEY", "123").ssl(false) .responseValidator(new Validator() { @Override/*from w ww.j ava 2 s . c o m*/ public <RS> void validate(RS value) throws ApiException, IllegalArgumentException { throw new ApiException("boom"); } }).build(); try { CompletableFuture<Res> future = invoker.invoke(new Req(25), Res.class); exception.expect(ExecutionException.class); future.get(500, TimeUnit.MILLISECONDS); } catch (ExecutionException ex) { ApiException cause = (ApiException) ex.getCause(); assertEquals("boom", cause.getMessage()); throw ex; } finally { invoker.close().get(500, TimeUnit.MILLISECONDS); } }
From source file:com.example.AzureADAuthenticationFilter.java
private AuthenticationResult getAccessTokenFromRefreshToken(String refreshToken, String currentUri) throws Throwable { AuthenticationContext context = null; AuthenticationResult result = null;/*from w ww. j a va 2 s .com*/ ExecutorService service = null; try { service = Executors.newFixedThreadPool(1); context = new AuthenticationContext(authority + tenant + "/", true, service); Future<AuthenticationResult> future = context.acquireTokenByRefreshToken(refreshToken, new ClientCredential(clientId, clientSecret), null, null); result = future.get(); } catch (ExecutionException e) { throw e.getCause(); } finally { service.shutdown(); } if (result == null) { throw new ServiceUnavailableException("authentication result was null"); } return result; }
From source file:io.dropwizard.primer.auth.PrimerAuthenticatorRequestFilter.java
@Override @Metered(name = "primer") public void filter(ContainerRequestContext requestContext) throws IOException { if (!configuration.isEnabled()) { return;/*from www . j ava 2s . c om*/ } //Short circuit for all white listed urls if (PrimerAuthorizationRegistry.isWhilisted(requestContext.getUriInfo().getPath())) { return; } Optional<String> token = getToken(requestContext); if (!token.isPresent()) { requestContext .abortWith(Response.status(Response.Status.BAD_REQUEST) .entity(objectMapper.writeValueAsBytes( PrimerError.builder().errorCode("PR000").message("Bad request").build())) .build()); } else { try { JsonWebToken webToken = authorize(requestContext, token.get()); //Stamp authorization headers for downstream services which can // use this to stop token forgery & misuse stampHeaders(requestContext, webToken); } catch (ExecutionException e) { if (e.getCause() instanceof PrimerException) { handleException(e.getCause(), requestContext, token.get()); } else { handleException(e, requestContext, token.get()); } } catch (UncheckedExecutionException e) { if (e.getCause() instanceof CompletionException) { handleException(e.getCause().getCause(), requestContext, token.get()); } else { handleException(e.getCause(), requestContext, token.get()); } } catch (Exception e) { log.error("Execution error: {}", e.getMessage()); handleError(Response.Status.INTERNAL_SERVER_ERROR, "PR000", "Error", token.get(), requestContext); } } }
From source file:org.apache.bookkeeper.stream.segment.TestBKSegmentWriter.java
@Test(timeout = 60000) public void testWriteRecordsAfterClose() throws Exception { StreamConfiguration conf = new StreamConfiguration(); conf.setSegmentWriterCommitDelayMs(0); conf.setSegmentWriterEntryBufferSize(0); String streamName = "test-write-records-after-close"; long segmentId = 1L; Pair<LedgerHandle, Segment> segmentPair = createInprogressSegment(streamName, segmentId); BKSegmentWriter writer = BKSegmentWriter.newBuilder().conf(conf).segment(segmentPair.getRight()) .ledgerHandle(segmentPair.getLeft()).scheduler(scheduler).statsLogger(NullStatsLogger.INSTANCE) .build();/* ww w. j av a 2 s .c om*/ // close ledger handle writer.close(); int numRecords = 3; List<OrderingListenableFuture<SSN>> writeFutures = new ArrayList<>(numRecords); for (int i = 0; i < numRecords; i++) { Record record = Record.newBuilder().setRecordId(i).setData(("record-" + i).getBytes(UTF_8)).build(); writeFutures.add(writer.write(record)); } for (OrderingListenableFuture<SSN> future : writeFutures) { try { future.get(); fail("Should fail writing record after writer is closed"); } catch (ExecutionException wce) { Throwable cause = wce.getCause(); assertEquals(WriteCancelledException.class, cause.getClass()); } } assertEquals(SSN.of(segmentId, -1L, -1L), writer.flush().get()); assertEquals(SSN.of(segmentId, -1L, -1L), writer.commit().get()); }