MCPcopy Create free account
hub / github.com/BoltsFramework/Bolts-Java / testWhenAllCancel

Method testWhenAllCancel

BoltsTest/src/bolts/TaskTest.java:314–353  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

312 }
313
314 public void testWhenAllCancel() {
315 runTaskTest(new Callable<Task<?>>() {
316 @Override
317 public Task<?> call() throws Exception {
318 final ArrayList<Task<Void>> tasks = new ArrayList<Task<Void>>();
319 for (int i = 0; i < 20; i++) {
320 final Task<Void>.TaskCompletionSource tcs = Task.create();
321
322 final int number = i;
323 Task.callInBackground(new Callable<Void>() {
324 @Override
325 public Void call() throws Exception {
326 Thread.sleep((long) (Math.random() * 1000));
327 if (number == 10) {
328 tcs.setCancelled();
329 } else {
330 tcs.setResult(null);
331 }
332 return null;
333 }
334 });
335
336 tasks.add(tcs.getTask());
337 }
338 return Task.whenAll(tasks).continueWith(new Continuation<Void, Void>() {
339 @Override
340 public Void then(Task<Void> task) {
341 assertTrue(task.isCompleted());
342 assertFalse(task.isFaulted());
343 assertTrue(task.isCancelled());
344
345 for (Task<Void> t : tasks) {
346 assertTrue(t.isCompleted());
347 }
348 return null;
349 }
350 });
351 }
352 });
353 }
354
355 public void testAsyncChaining() {
356 runTaskTest(new Callable<Task<?>>() {

Callers

nothing calls this directly

Calls 1

runTaskTestMethod · 0.95

Tested by

no test coverage detected