本文整理汇总了Java中java.util.concurrent.ExecutionException类的典型用法代码示例。如果您正苦于以下问题:Java ExecutionException类的具体用法?Java ExecutionException怎么用?Java ExecutionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExecutionException类属于java.util.concurrent包,在下文中一共展示了ExecutionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import java.util.concurrent.ExecutionException; //导入依赖的package包/类
private static Future<AdProviderReader> validate(final Future<AdProviderReader> a, final Future<AdProviderReader> b) {
try {
if (b.get() == null) {
return a;
}
if (a.get() == null) {
return b;
}
if (FloatComparator.greaterThanWithPrecision(a.get().getPriceEur(), b.get().getPriceEur())) {
return a;
}
} catch (final InterruptedException | ExecutionException e) {
log.error(e.getMessage());
}
return b;
}
示例2: testRead
import java.util.concurrent.ExecutionException; //导入依赖的package包/类
/**
* Test of read method, of class BaseConsole.
*
* @throws java.lang.InterruptedException
* @throws java.util.concurrent.ExecutionException
* @throws java.util.concurrent.TimeoutException
*/
@Test
public void testRead() throws InterruptedException, ExecutionException, TimeoutException {
assert !Platform.isFxApplicationThread();
new JFXPanel();
FutureTask<Void> futureTask = new FutureTask<>(() -> {
console.write('a');
char output = console.read();
assertEquals("BaseConsole does not work properly.", 'a', output);
console.write('\n');
output = console.read();
assertEquals("BaseConsole does not work properly.", '\n', output);
return null;
});
Platform.runLater(futureTask);
futureTask.get(5, TimeUnit.SECONDS);
}
示例3: shouldThrowIfNotOK
import java.util.concurrent.ExecutionException; //导入依赖的package包/类
@Test
public void shouldThrowIfNotOK() throws Exception {
when(client.send(any(Request.class)))
.thenReturn(CompletableFuture.completedFuture(Response.forStatus(Status.BAD_REQUEST)));
try {
RktCommandHelper.sendRequest(client,
"http://localhost:8080/rkt/gc",
GcOptions
.builder()
.markOnly(true)
.build(),
GcOutput.class)
.toCompletableFuture().get();
fail();
} catch (ExecutionException e) {
assertSame(RktLauncherRemoteHttpException.class, e.getCause().getClass());
assertEquals(400, ((RktLauncherRemoteHttpException) e.getCause()).getCode());
}
}
示例4: testBulkLoadUncheckedException
import java.util.concurrent.ExecutionException; //导入依赖的package包/类
public void testBulkLoadUncheckedException() throws ExecutionException {
Exception e = new RuntimeException();
CacheLoader<Object, Object> loader = exceptionLoader(e);
LoadingCache<Object, Object> cache = CacheBuilder.newBuilder()
.recordStats()
.build(bulkLoader(loader));
CacheStats stats = cache.stats();
assertEquals(0, stats.missCount());
assertEquals(0, stats.loadSuccessCount());
assertEquals(0, stats.loadExceptionCount());
assertEquals(0, stats.hitCount());
try {
cache.getAll(asList(new Object()));
fail();
} catch (UncheckedExecutionException expected) {
assertSame(e, expected.getCause());
}
stats = cache.stats();
assertEquals(1, stats.missCount());
assertEquals(0, stats.loadSuccessCount());
assertEquals(1, stats.loadExceptionCount());
assertEquals(0, stats.hitCount());
}
示例5: callAsync
import java.util.concurrent.ExecutionException; //导入依赖的package包/类
/**
* This method is used to formulate an asynchronous api call on the base of the
* given parameters and return a {@link HttpResponse}
*
* @param httpRequest,
* a prepared {@link HttpRequest} used for api call
* @param consumerOnSuccess,
* the consumer used to handle success response
* @param consumerOnError,
* the consumer used to handle error response
* @param attempts,
* the number of attempts to test if an error occurs during the api
* call
* @throws ExecutionException
* if a problem occurred during the retrieving of REST client
*/
public static void callAsync(HttpRequest httpRequest, Consumer<HttpResponse> consumerOnSuccess,
Consumer<Throwable> consumerOnError, int attempts) throws ExecutionException {
// prepare the call
Call<ResponseBody> call = prepareCall(httpRequest);
if (call == null) {
LOGGER.error("Call cannot be null");
return;
}
if (consumerOnSuccess == null) {
LOGGER.error("Async consumer on success cannot be null");
return;
}
Date startTime = new Date();
// make asynchronous http request and get http response
enqueueCall(call, consumerOnSuccess, consumerOnError, attempts, startTime);
}
示例6: testProducerFencedException
import java.util.concurrent.ExecutionException; //导入依赖的package包/类
@Test(expected = ExecutionException.class)
public void testProducerFencedException() throws InterruptedException, ExecutionException {
final long pid = 13131L;
final short epoch = 1;
doInitTransactions(pid, epoch);
transactionManager.beginTransaction();
transactionManager.maybeAddPartitionToTransaction(tp0);
Future<RecordMetadata> responseFuture = accumulator.append(tp0, time.milliseconds(), "key".getBytes(),
"value".getBytes(), Record.EMPTY_HEADERS, null, MAX_BLOCK_TIMEOUT).future;
assertFalse(responseFuture.isDone());
prepareAddPartitionsToTxnResponse(Errors.NONE, tp0, epoch, pid);
prepareProduceResponse(Errors.INVALID_PRODUCER_EPOCH, pid, epoch);
sender.run(time.milliseconds()); // Add partitions.
sender.run(time.milliseconds()); // send produce.
assertTrue(responseFuture.isDone());
assertTrue(transactionManager.hasError());
responseFuture.get();
}
示例7: testCoordinationLifecycle
import java.util.concurrent.ExecutionException; //导入依赖的package包/类
@Test
public void testCoordinationLifecycle() throws InterruptedException, ExecutionException {
CarService carService = getCarService("em");
assertNoCars(carService);
Runnable carLifeCycle = getService(Runnable.class, "(type=carCoordinated)");
carLifeCycle.run();
ExecutorService exec = Executors.newFixedThreadPool(20);
List<Future<?>> futures = new ArrayList<Future<?>>();
for (int c=0; c<100; c++) {
futures.add(exec.submit(carLifeCycle));
}
exec.shutdown();
exec.awaitTermination(30, TimeUnit.SECONDS);
for (Future<?> future : futures) {
future.get();
}
assertNoCars(carService);
}
示例8: testSeparateWrites
import java.util.concurrent.ExecutionException; //导入依赖的package包/类
@Test
public void testSeparateWrites() throws InterruptedException, TimeoutException, ExecutionException {
DataBroker dataBroker = testContext.getDataBroker();
final SettableFuture<AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject>> eventFuture =
SettableFuture.create();
dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, DEEP_WILDCARDED_PATH,
dataChangeEvent -> eventFuture.set(dataChangeEvent), DataChangeScope.SUBTREE);
final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_CWU_PATH, CWU, true);
transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_0_LVU_PATH, LVU, true);
transaction.put(LogicalDatastoreType.OPERATIONAL, NODE_1_LVU_PATH, LVU, true);
transaction.submit().get(5, TimeUnit.SECONDS);
AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = eventFuture.get(1000, TimeUnit.MILLISECONDS);
validateEvent(event);
}
示例9: main
import java.util.concurrent.ExecutionException; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException, IOException, ExecutionException {
setGlobalUncaughtExceptionHandler();
String conf = System.getProperty("canal-es.properties", "classpath:canal-es.properties");
Properties properties = getProperties(conf);
TotoroBootStrap canalScheduler = new TotoroBootStrap(properties);
canalScheduler.start();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
logger.info("## stop the totoro server");
canalScheduler.stop();
} catch (Throwable e) {
logger.warn("##something goes wrong when stopping totoro Server:", e);
} finally {
logger.info("## totoro server is down.");
}
}));
}
示例10: loadProjectList_callback_registers_exception_on_ack_future
import java.util.concurrent.ExecutionException; //导入依赖的package包/类
@Test
public void loadProjectList_callback_registers_exception_on_ack_future( ) throws Exception {
// Setup
when( _mockRequestController.sendRequest( getApiVersion( ), "projects", ProjectList.class ) )
.thenReturn( Futures.immediateFailedFuture( new RuntimeException( "Unexpected test exception" ) ) );
// Exercise
final ListenableFuture<Void> ackFuture = _apiController.loadProjectList( );
// Verify
try {
ackFuture.get( );
} catch ( ExecutionException e ) {
if ( e.getCause( ).getClass( ) == RuntimeException.class && e.getCause( ).getMessage( ).equals( "Unexpected test exception" ) )
return;
}
TestCase.fail( );
}
示例11: testGetAllJobStatusChangesObservableEmitsExpectedEventsWhenAborted
import java.util.concurrent.ExecutionException; //导入依赖的package包/类
@Test
public void testGetAllJobStatusChangesObservableEmitsExpectedEventsWhenAborted() throws InterruptedException, ExecutionException, TimeoutException {
final JobExecutionResult executorResult = new JobExecutionResult(ABORTED);
final JobExecutor executor = MockJobExecutor.thatResolvesWith(executorResult);
final JobManager jobManager = createManagerWith(executor);
final List<JobStatus> statusesEmitted = new ArrayList<>();
jobManager.allJobStatusChanges()
.map(JobEvent::getNewStatus)
.subscribe(statusesEmitted::add);
final Pair<JobId, CancelablePromise<FinalizedJob>> ret =
jobManager.submit(STANDARD_VALID_REQUEST);
ret.getRight().get(DEFAULT_TIMEOUT, MILLISECONDS);
assertThat(statusesEmitted).isEqualTo(asList(SUBMITTED, RUNNING, ABORTED));
}
示例12: compute
import java.util.concurrent.ExecutionException; //导入依赖的package包/类
@Override protected Double compute() {
if (endPos <= startPos) {
return 0.0;
}
if (endPos - startPos == 1) {
if (splits[startPos] != null) {
return splits[startPos].squaredNorm();
} else {
return 0.0;
}
} else {
int middle = (startPos + endPos) / 2;
SquaredNormOp opLeft = new SquaredNormOp(splits, startPos, middle);
SquaredNormOp opRight = new SquaredNormOp(splits, middle, endPos);
invokeAll(opLeft, opRight);
try {
return opLeft.get() + opRight.get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("NNZCounterOp failed " + e.getMessage());
return 0.0;
}
}
}
示例13: testBulkLoadNull
import java.util.concurrent.ExecutionException; //导入依赖的package包/类
public void testBulkLoadNull() throws ExecutionException {
LoadingCache<Object, Object> cache = CacheBuilder.newBuilder()
.recordStats()
.build(bulkLoader(constantLoader(null)));
CacheStats stats = cache.stats();
assertEquals(0, stats.missCount());
assertEquals(0, stats.loadSuccessCount());
assertEquals(0, stats.loadExceptionCount());
assertEquals(0, stats.hitCount());
try {
cache.getAll(asList(new Object()));
fail();
} catch (InvalidCacheLoadException expected) {}
stats = cache.stats();
assertEquals(1, stats.missCount());
assertEquals(0, stats.loadSuccessCount());
assertEquals(1, stats.loadExceptionCount());
assertEquals(0, stats.hitCount());
}
示例14: submitTransaction
import java.util.concurrent.ExecutionException; //导入依赖的package包/类
@Override
public Future<Transaction> submitTransaction(Transaction transaction) {
TransactionTask transactionTask = new TransactionTask(transaction, channelManager);
final Future<List<Transaction>> listFuture =
TransactionExecutor.instance.submitTransaction(transactionTask);
pendingState.addPendingTransaction(transaction);
return new FutureAdapter<Transaction, List<Transaction>>(listFuture) {
@Override
protected Transaction adapt(List<Transaction> adapteeResult) throws ExecutionException {
return adapteeResult.get(0);
}
};
}
示例15: testMintingLarge2
import java.util.concurrent.ExecutionException; //导入依赖的package包/类
@Test
public void testMintingLarge2() throws ExecutionException, InterruptedException {
dataBtc(1).dataBtc(2);
rateBtc(101, 1_050_001);
rateBtc(102, 7);
int current = 0;
current = minting.mint(current, 100, 0, 1 * 100_000_000, 0, "w1");
Assert.assertEquals(0, current);
current = minting.mint(current, 102, 0, 1 * 100_000_000, 0, "w2");
Assert.assertEquals(14, current);
Iterator<Token> it = tokenRepository.findAllByOrderByWalletAddress().iterator();
Assert.assertEquals(14, it.next().getAmount().intValue());
}