Java Code Examples for java.util.concurrent.ExecutionException#printStackTrace()
The following examples show how to use
java.util.concurrent.ExecutionException#printStackTrace() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnswerSyncerTest.java From NLIWOD with GNU Affero General Public License v3.0 | 6 votes |
@Test public void prefixResolverTest() { String query = "PREFIX dbo: <http://dbpedia.org/ontology/> PREFIX res: <http://dbpedia.org/resource/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT DISTINCT ?uri ?string WHERE { ?uri rdf:type dbo:FormulaOneRacer . ?uri dbo:races ?x . OPTIONAL { ?uri rdfs:label ?string. FILTER (lang(?string) = 'en') } } ORDER BY DESC(?x) OFFSET 0 LIMIT 1"; String answer = "http://dbpedia.org/resource/Michael_Schumacher"; IQuestion question = new Question(); question.setSparqlQuery(query); try { AnswerSyncer.syncAnswers(question, SPARQLEndpoints.DBPEDIA_ORG); } catch (ExecutionException e) { e.printStackTrace(); Assert.fail(); } ArrayList<String> answers = Lists.newArrayList(question.getGoldenAnswers()); Assert.assertTrue("More than one answer or no answer", answers.size() == 1); Assert.assertTrue("Answer is not correct", answer.equals(answers.get(0))); log.debug("Answer: \n" + answers.get(0)); }
Example 2
Source File: ProtocolBaseTestFile.java From KodeBeagle with Apache License 2.0 | 6 votes |
public void testStupidlyLargeSetAndSizeOverride() throws Exception { Random r = new Random(); SerializingTranscoder st = new SerializingTranscoder(Integer.MAX_VALUE); st.setCompressionThreshold(Integer.MAX_VALUE); byte[] data = new byte[21 * 1024 * 1024]; r.nextBytes(data); try { client.set("bigassthing", 60, data, st).get(); fail("Didn't fail setting bigass thing."); } catch (ExecutionException e) { System.err.println("Successful failure setting bigassthing. Ass size " + data.length + " bytes doesn't fit."); e.printStackTrace(); OperationException oe = (OperationException) e.getCause(); assertSame(OperationErrorType.SERVER, oe.getType()); } // But I should still be able to do something. client.set("k", 5, "Blah"); assertEquals("Blah", client.get("k")); }
Example 3
Source File: ComputeEncryptedRow.java From incubator-retired-pirk with Apache License 2.0 | 6 votes |
public static List<Tuple2<Long,BigInteger>> computeEncRow(BigInteger part, Query query, int rowIndex, int colIndex) throws IOException { List<Tuple2<Long,BigInteger>> returnPairs = new ArrayList<>(); // Pull the corresponding encrypted row query BigInteger rowQuery = query.getQueryElement(rowIndex); // Initialize the column counter long colCounter = colIndex; // Update the associated column values BigInteger exp = null; try { exp = expCache.get(new Tuple3<>(rowQuery, part, query.getNSquared())); } catch (ExecutionException e) { e.printStackTrace(); } returnPairs.add(new Tuple2<>(colCounter, exp)); ++colCounter; return returnPairs; }
Example 4
Source File: ForkJoinTaskDemo.java From JavaCommon with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws InterruptedException { long startTime = System.currentTimeMillis(); int count = 0; for (int i = 1; i < 10; i++) { count = count + i; Thread.sleep(1000); } System.out.println(count); long endTime = System.currentTimeMillis(); // 获取结束时间 System.out.println("程序运行时间: " + (startTime - endTime) + "ms"); long startTime1 = System.currentTimeMillis(); CountTask countTask = new CountTask(1, 10); ForkJoinPool forkJoinPool = new ForkJoinPool(); Future<Integer> futureTask = forkJoinPool.submit(countTask); try { System.out.println(futureTask.get()); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } long endTime1 = System.currentTimeMillis(); // 获取结束时间 System.out.println("程序运行时间: " + (startTime1 - endTime1) + "ms"); }
Example 5
Source File: SimpleQuantityRanker.java From NLIWOD with GNU Affero General Public License v3.0 | 6 votes |
/** * For property, counts how many relations with this property exist. The one * with the most relations is returned. For classes, counts how many * subtypes of this class are existing. the one with the most subtypes is * returned. If properties and classes are among the uris, the one with the * biggest count is returned. * * @param uris * @return */ public String rank(final Collection<String> uris) { Map<Integer, String> uriToQuantity = new HashMap<>(); for (String it : uris) { ArrayList<RDFNode> answers; try { answers = new ArrayList<>(sparql.sparql(constructQuery(it))); System.out.println(constructQuery(it)); RDFNode node = answers.get(0); uriToQuantity.put(((Integer) node.asLiteral().getValue()), it); } catch (ExecutionException e) { e.printStackTrace(); } } List<Integer> sorted = new ArrayList<>(uriToQuantity.keySet()); Collections.sort(sorted); return uriToQuantity.get(Iterables.getLast(sorted)); }
Example 6
Source File: CompletableFutureTest.java From light-eventuate-4j with Apache License 2.0 | 6 votes |
@Test public void exploreHandleAsync() throws ExecutionException, InterruptedException { CompletableFuture<Void> f = new CompletableFuture<>(); CompletableFuture<Void> f2 = f.handleAsync((r, t) -> { throw new RuntimeException("y", t); }); CompletableFuture<Void> f3 = f2.handleAsync((r, t) -> { throw new RuntimeException("z", t); }); f.completeExceptionally(new RuntimeException("x")); try { f3.get(); fail(); } catch (ExecutionException e ) { e.printStackTrace(); assertTrue(e.getCause() instanceof RuntimeException); assertEquals("z", e.getCause().getMessage()); } }
Example 7
Source File: TestAsyncSingleRequestRpcRetryingCaller.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testOperationTimeout() throws IOException, InterruptedException { long startNs = System.nanoTime(); try { CONN.callerFactory.single().table(TABLE_NAME).row(ROW).operationTimeout(1, TimeUnit.SECONDS) .pause(100, TimeUnit.MILLISECONDS).maxAttempts(Integer.MAX_VALUE) .action((controller, loc, stub) -> failedFuture()).call().get(); fail(); } catch (ExecutionException e) { e.printStackTrace(); assertThat(e.getCause(), instanceOf(RetriesExhaustedException.class)); } long costNs = System.nanoTime() - startNs; assertTrue(costNs >= TimeUnit.SECONDS.toNanos(1)); assertTrue(costNs < TimeUnit.SECONDS.toNanos(2)); }
Example 8
Source File: ComputeEncryptedRow.java From incubator-retired-pirk with Apache License 2.0 | 5 votes |
/** * Method to compute the encrypted row elements for a query from extracted data partitions in the form of ArrayList<<BigInteger>> * <p> * For each row (as indicated by key = hash(selector)), iterates over the dataPartitions and calculates the column values. * <p> * Uses a static LRU cache for the modular exponentiation * <p> * Caller is responsible for keeping track of the colIndex and the the maxHitsPerSelector values * <p> * Emits {@code Tuple2<<colNum, colVal>>} */ public static List<Tuple2<Long,BigInteger>> computeEncRow(List<BigInteger> dataPartitions, Query query, int rowIndex, int colIndex) throws IOException { List<Tuple2<Long,BigInteger>> returnPairs = new ArrayList<>(); // Pull the corresponding encrypted row query BigInteger rowQuery = query.getQueryElement(rowIndex); // Initialize the column counter long colCounter = colIndex; logger.debug("dataPartitions.size() = {} rowIndex = {} colCounter = {}", dataPartitions, rowIndex, colCounter); // Update the associated column values for (int i = 0; i < dataPartitions.size(); ++i) { BigInteger part = dataPartitions.get(i); BigInteger exp; try { exp = expCache.get(new Tuple3<>(rowQuery, part, query.getNSquared())); } catch (ExecutionException e) { e.printStackTrace(); break; } logger.debug("rowIndex = {} colCounter = {} part = {} part binary = {} exp = {} i = {} partition = {} = {}", rowIndex, colCounter, part.toString(), part.toString(2), exp, i, dataPartitions.get(i), dataPartitions.get(i).toString(2)); returnPairs.add(new Tuple2<>(colCounter, exp)); ++colCounter; } return returnPairs; }
Example 9
Source File: EventUtilTest.java From oneops with Apache License 2.0 | 5 votes |
@Test public void shouldNotifyFalseAndExceptionInGettingAttribValue() throws OpampException { CiChangeStateEvent ciEvent = new CiChangeStateEvent(); ciEvent.setCiId(12345); ciEvent.setNewState(CiOpsState.notify.getName()); ciEvent.setOldState(CiOpsState.notify.getName()); OpsBaseEvent obe = new OpsBaseEvent(); obe.setCiId(12345); obe.setManifestId(6789); obe.setBucket("mockBucket"); obe.setSource("p1-compute-load"); obe.setStatus(Status.EXISTING); Gson gson = new Gson(); ciEvent.setPayLoad(gson.toJson(obe)); WatchedByAttributeCache cacheWithNotifyOnlyOnStateChangeTrue = mock(WatchedByAttributeCache.class); LoadingCache<String, String> cache = mock(LoadingCache.class); eventUtil.setCache(cacheWithNotifyOnlyOnStateChangeTrue); try { when(cache.get(eventUtil.getKey(obe))).thenThrow(new ExecutionException(null)); when(cacheWithNotifyOnlyOnStateChangeTrue.instance()).thenReturn(cache); } catch (ExecutionException e) { e.printStackTrace(); } boolean actualValue = eventUtil.shouldNotify(ciEvent, obe); Assert.assertEquals(actualValue, false); }
Example 10
Source File: GitManagerImpl.java From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Repository getRepository(String spaceKey) { try { return repoCache.get(spaceKey); } catch (ExecutionException e) { e.printStackTrace(); } return null; }
Example 11
Source File: SyntaxColoringLabel.java From statecharts with Eclipse Public License 1.0 | 5 votes |
@Override public Dimension getTextExtents(String draw, Font f) { try { return cache.get(draw); } catch (ExecutionException e) { e.printStackTrace(); return super.getTextExtents(draw, f); } }
Example 12
Source File: SchemaCache.java From tx-lcn with Apache License 2.0 | 5 votes |
private Schema<?> get(final Class<?> cls, Cache<Class<?>, Schema<?>> cache) { try { return cache.get(cls, () -> RuntimeSchema.createFrom(cls,idStrategy)); } catch (ExecutionException e) { e.printStackTrace(); return null; } }
Example 13
Source File: Memoizer.java From tomee with Apache License 2.0 | 5 votes |
public V compute(final K key) throws InterruptedException { while (true) { Future<V> future = cache.get(key); if (future == null) { final Callable<V> eval = new Callable<V>() { public V call() throws Exception { return c.compute(key); } }; final FutureTask<V> futureTask = new FutureTask<>(eval); future = cache.putIfAbsent(key, futureTask); if (future == null) { future = futureTask; futureTask.run(); } } try { return future.get(); } catch (final ExecutionException e) { if (e.getCause() != null && NoClassDefFoundError.class.isInstance(e.getCause())) { return null; } e.printStackTrace(); } } }
Example 14
Source File: TestGuavaChache.java From albert with MIT License | 5 votes |
private String getCallableCache(final String userName) { try { //Callable只有在缓存值不存在时,才会调用 return cacheFormCallable.get(userName, new Callable<String>() { @Override public String call() throws Exception { System.out.println(userName+" from db"); return "hello "+userName+"!"; } }); } catch (ExecutionException e) { e.printStackTrace(); return null; } }
Example 15
Source File: ComputeEncryptedRow.java From incubator-retired-pirk with Apache License 2.0 | 5 votes |
/** * Method to compute the encrypted row elements for a query from extracted data partitions in the form of BytesArrayWritable * <p> * For each row (as indicated by key = hash(selector)), iterates over the dataPartitions and calculates the column values. * <p> * Uses a static LRU cache for the modular exponentiation * <p> * Caller is responsible for keeping track of the colIndex and the the maxHitsPerSelector values * <p> * Emits {@code Tuple2<<colNum, colVal>>} */ public static List<Tuple2<Long,BigInteger>> computeEncRow(BytesArrayWritable dataPartitions, Query query, int rowIndex, int colIndex) throws IOException { List<Tuple2<Long,BigInteger>> returnPairs = new ArrayList<>(); // Pull the corresponding encrypted row query BigInteger rowQuery = query.getQueryElement(rowIndex); // Initialize the column counter long colCounter = colIndex; logger.debug("dataPartitions.size() = {} rowIndex = {} colCounter = {}", dataPartitions.size(), rowIndex, colCounter); // Update the associated column values for (int i = 0; i < dataPartitions.size(); ++i) { BigInteger part = dataPartitions.getBigInteger(i); BigInteger exp = null; try { exp = expCache.get(new Tuple3<>(rowQuery, part, query.getNSquared())); } catch (ExecutionException e) { e.printStackTrace(); } logger.debug("rowIndex = {} colCounter = {} part = {} part binary = {} exp = {} i = {} partition = {} = {}", rowIndex, colCounter, part.toString(), part.toString(2), exp, i, dataPartitions.getBigInteger(i), dataPartitions.getBigInteger(i).toString(2)); returnPairs.add(new Tuple2<>(colCounter, exp)); ++colCounter; } return returnPairs; }
Example 16
Source File: Environment.java From uncc2014watsonsim with GNU General Public License v2.0 | 5 votes |
/** * Run a vanilla boolean Lucene query * @param query * @param count * @return */ public ScoreDoc[] simpleLuceneQuery(String query, int count) { if (query.length() < 3) return new ScoreDoc[0]; try { return recent_lucene_searches.get(query, () -> forcedSimpleLuceneQuery(query, count)); } catch (ExecutionException e) { e.printStackTrace(); return new ScoreDoc[0]; } }
Example 17
Source File: ComputeEncryptedRow.java From incubator-retired-pirk with Apache License 2.0 | 4 votes |
/** * Method to compute the encrypted row elements for a query from extracted data partitions in the form of Iterable{@link <BytesArrayWritable>} * <p> * For each row (as indicated by key = hash(selector)), iterates over the dataPartitions and calculates the column values. * <p> * Optionally uses a static LRU cache for the modular exponentiation * <p> * Emits {@code Tuple2<<colNum, colVal>>} */ public static List<Tuple2<Long,BigInteger>> computeEncRow(Iterable<BytesArrayWritable> dataPartitionsIter, Query query, int rowIndex, boolean limitHitsPerSelector, int maxHitsPerSelector, boolean useCache) throws IOException { List<Tuple2<Long,BigInteger>> returnPairs = new ArrayList<>(); // Pull the corresponding encrypted row query BigInteger rowQuery = query.getQueryElement(rowIndex); long colCounter = 0; int elementCounter = 0; for (BytesArrayWritable dataPartitions : dataPartitionsIter) { logger.debug("rowIndex = {} elementCounter = {}", rowIndex, elementCounter); if (limitHitsPerSelector) { if (elementCounter >= maxHitsPerSelector) { break; } } logger.debug("dataPartitions.size() = {} rowIndex = {} colCounter = {}", dataPartitions.size(), rowIndex, colCounter); // Update the associated column values for (int i = 0; i < dataPartitions.size(); ++i) { BigInteger part = dataPartitions.getBigInteger(i); BigInteger exp = null; try { if (useCache) { exp = expCache.get(new Tuple3<>(rowQuery, part, query.getNSquared())); } else { exp = ModPowAbstraction.modPow(rowQuery, part, query.getNSquared()); } } catch (ExecutionException e) { e.printStackTrace(); } logger.debug("rowIndex = {} colCounter = {} part = {} part binary = {} exp = {} i = {} partition = {} = {}", rowIndex, colCounter, part.toString(), part.toString(2), exp, i, dataPartitions.getBigInteger(i), dataPartitions.getBigInteger(i).toString(2)); returnPairs.add(new Tuple2<>(colCounter, exp)); ++colCounter; } ++elementCounter; } return returnPairs; }
Example 18
Source File: RequestQueueTest.java From jus with Apache License 2.0 | 4 votes |
@Test public void responseTransformerTest() throws InterruptedException { MockHttpStack httpStack = new MockHttpStack(); HttpNetwork network = new HttpNetwork(httpStack); RequestQueue queue = new RequestQueue(new NoCache(), network, 3, mDelivery); final AtomicReference<String> argRef = new AtomicReference<>(); final CountDownLatch latch1 = new CountDownLatch(2); final CountDownLatch latch2 = new CountDownLatch(1); queue.addResponseTransformer(new Transformer.ResponseTransformer(new RequestQueue .RequestFilter() { @Override public boolean apply(Request<?> request) { if ("trans".equals(request.getTag())) { latch1.countDown(); return true; } latch2.countDown(); return false; } }) { @Override public NetworkResponse transform(NetworkResponse networkResponse) { latch1.countDown(); return NetworkResponse.Builder.from(networkResponse) .addHeader("header1", "val1").build(); } }); httpStack.setResponseToReturn(new NetworkResponse(200, new byte[0], Headers.of(new HashMap<String, String>()), 0)); queue.start(); Request req = new MockRequest().setTag("trans").addMarkerListener( new RequestListener.MarkerListener() { @Override public void onMarker(Marker marker, Object... args) { if (Request.EVENT_NETWORK_HTTP_COMPLETE.equals(marker.name)) { argRef.set(((NetworkResponse) args[0]).headers.get("header1")); } } }); queue.add(req); try { req.getFuture().get(); } catch (ExecutionException e) { e.printStackTrace(); } assertTrue(latch1.await(2, SECONDS)); assertEquals("val1", argRef.get()); queue.add(new MockRequest()); assertTrue(latch2.await(2, SECONDS)); queue.stop(); }
Example 19
Source File: BatchOwlLoader.java From SciGraph with Apache License 2.0 | 4 votes |
public void loadOntology() throws InterruptedException, ExecutionException { CompletionService<Long> completionService = new ExecutorCompletionService<Long>(exec); Set<Future<?>> futures = new HashSet<>(); if (!ontologies.isEmpty()) { for (int i = 0; i < numConsumers; i++) { futures.add(completionService.submit(consumerProvider.get())); } for (int i = 0; i < numProducers; i++) { futures.add(completionService.submit(producerProvider.get())); } for (OntologySetup ontology : ontologies) { urlQueue.offer(ontology); } for (int i = 0; i < numProducers; i++) { urlQueue.offer(POISON_STR); } } while (futures.size() > 0) { Future<?> completedFuture = completionService.take(); futures.remove(completedFuture); try { completedFuture.get(); } catch (ExecutionException e) { logger.log(Level.SEVERE, "Stopping batchLoading due to: " + e.getMessage(), e); e.printStackTrace(); exec.shutdownNow(); throw new InterruptedException(e.getCause().getMessage()); } } exec.shutdown(); exec.awaitTermination(10, TimeUnit.DAYS); graph.shutdown(); logger.info("Postprocessing..."); postprocessorProvider.get().postprocess(); if (anonymousNodeProperty.isPresent()) { postprocessorProvider.runAnonymousNodeTagger(anonymousNodeProperty.get()); } if (cliqueConfiguration.isPresent()) { postprocessorProvider.runCliquePostprocessor(cliqueConfiguration.get()); } if (addEdgeLabel.orElse(false)) { postprocessorProvider.runEdgeLabelerPostprocessor(); } if (allNodesLabel.isPresent()) { postprocessorProvider.runAllNodesLabeler(allNodesLabel.get()); } postprocessorProvider.shutdown(); }
Example 20
Source File: ComputeEncryptedRow.java From incubator-retired-pirk with Apache License 2.0 | 4 votes |
/** * Method to compute the encrypted row elements for a query from extracted data partitions in the form of Iterable{@link List<BigInteger> * * * * } * <p> * For each row (as indicated by key = hash(selector)), iterates over the dataPartitions and calculates the column values. * <p> * Optionally uses a static LRU cache for the modular exponentiation * <p> * Emits {@code Tuple2<<colNum, colVal>>} */ public static List<Tuple2<Long,BigInteger>> computeEncRowBI(Iterable<List<BigInteger>> dataPartitionsIter, Query query, int rowIndex, boolean limitHitsPerSelector, int maxHitsPerSelector, boolean useCache) throws IOException { List<Tuple2<Long,BigInteger>> returnPairs = new ArrayList<>(); // Pull the corresponding encrypted row query BigInteger rowQuery = query.getQueryElement(rowIndex); long colCounter = 0; int elementCounter = 0; for (List<BigInteger> dataPartitions : dataPartitionsIter) { // long startTime = System.currentTimeMillis(); logger.debug("rowIndex = {} elementCounter = {}", rowIndex, elementCounter); if (limitHitsPerSelector) { if (elementCounter >= maxHitsPerSelector) { logger.debug("maxHits: rowIndex = " + rowIndex + " elementCounter = " + elementCounter); break; } } logger.debug("dataPartitions.size() = {} rowIndex = {} colCounter = {}", dataPartitions.size(), rowIndex, colCounter); // Update the associated column values for (int i = 0; i < dataPartitions.size(); ++i) { BigInteger part = dataPartitions.get(i); BigInteger exp = null; try { if (useCache) { exp = expCache.get(new Tuple3<>(rowQuery, part, query.getNSquared())); } else { exp = ModPowAbstraction.modPow(rowQuery, part, query.getNSquared()); } } catch (ExecutionException e) { e.printStackTrace(); } logger.debug("rowIndex = {} colCounter = {} part = {} part binary = {} exp = {} i = {}", rowIndex, colCounter, part.toString(), part.toString(2), exp, i); returnPairs.add(new Tuple2<>(colCounter, exp)); ++colCounter; } // long endTime = System.currentTimeMillis(); // logger.debug("Completed encrypting row data element = " + rowIndex + " duration = " + (endTime - startTime)); ++elementCounter; } logger.debug("totalHits: rowIndex = " + rowIndex + " elementCounter = " + elementCounter); return returnPairs; }