com.google.common.util.concurrent.SettableFuture.isCancelled()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中com.google.common.util.concurrent.SettableFuture.isCancelled()方法的一些代码示例,展示了SettableFuture.isCancelled()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SettableFuture.isCancelled()方法的具体详情如下:
包路径:com.google.common.util.concurrent.SettableFuture
类名称:SettableFuture
方法名:isCancelled

SettableFuture.isCancelled介绍

暂无

代码示例

代码示例来源:origin: google/guava

public void testCancellationNotPropagatedIfAlreadyStarted() {
 serializer.submitAsync(firstCallable, directExecutor()).cancel(true);
 assertThat(firstFuture.isCancelled()).isFalse();
}

代码示例来源:origin: google/guava

public void testSetFutureSelf_cancel() {
 SettableFuture<String> orig = SettableFuture.create();
 orig.setFuture(orig);
 orig.cancel(true);
 assertTrue(orig.isCancelled());
}

代码示例来源:origin: google/guava

/** Tests the initial state of the future. */
public void testCreate() throws Exception {
 SettableFuture<Integer> future = SettableFuture.create();
 assertFalse(future.isDone());
 assertFalse(future.isCancelled());
}

代码示例来源:origin: google/guava

public void testAllAsList_resultCancelled_withSecondaryListFuture() throws Exception {
 SettableFuture<String> future1 = SettableFuture.create();
 SettableFuture<String> future2 = SettableFuture.create();
 ListenableFuture<List<String>> compound = allAsList(future1, future2);
 // This next call is "unused," but it is an important part of the test. Don't remove it!
 ListenableFuture<List<String>> unused = allAsList(future1, future2);
 assertTrue(compound.cancel(false));
 assertTrue(future1.isCancelled());
 assertFalse(future1.wasInterrupted());
 assertTrue(future2.isCancelled());
 assertFalse(future2.wasInterrupted());
}

代码示例来源:origin: google/guava

public void testFutureCancelAfterCompletion() throws Exception {
 inputFuture.set(VALID_INPUT_DATA);
 assertFalse(resultFuture.cancel(true));
 assertFalse(resultFuture.isCancelled());
 assertFalse(inputFuture.isCancelled());
 assertFalse(outputFuture.isCancelled());
 assertEquals(RESULT_DATA, resultFuture.get());
}

代码示例来源:origin: google/guava

public void testFutureCancellableBeforeOutputCompletion() throws Exception {
 inputFuture.set(SLOW_OUTPUT_VALID_INPUT_DATA);
 assertTrue(resultFuture.cancel(true));
 assertTrue(resultFuture.isCancelled());
 assertFalse(inputFuture.isCancelled());
 assertTrue(outputFuture.isCancelled());
 try {
  resultFuture.get();
  fail("Result future is cancelled and should have thrown a" + " CancellationException");
 } catch (CancellationException expected) {
 }
}

代码示例来源:origin: google/guava

public void testFutureCancelBeforeInputCompletion() throws Exception {
 assertTrue(resultFuture.cancel(true));
 assertTrue(resultFuture.isCancelled());
 assertTrue(inputFuture.isCancelled());
 assertFalse(outputFuture.isCancelled());
 try {
  resultFuture.get();
  fail("Result future is cancelled and should have thrown a" + " CancellationException");
 } catch (CancellationException expected) {
 }
}

代码示例来源:origin: google/guava

public void testCancel_innerCancelsAsync() throws Exception {
 SettableFuture<Object> async = SettableFuture.create();
 SettableFuture<Object> inner = SettableFuture.create();
 async.setFuture(inner);
 inner.cancel(true);
 assertTrue(async.isCancelled());
 try {
  async.get();
  fail("Expected CancellationException");
 } catch (CancellationException expected) {
  /* expected */
 }
}

代码示例来源:origin: google/guava

public void testSetValue_simpleThreaded() throws Exception {
 SettableFuture<Integer> future = SettableFuture.create();
 assertTrue(future.set(42));
 // Later attempts to set the future should return false.
 assertFalse(future.set(23));
 assertFalse(future.setException(new Exception("bar")));
 assertFalse(future.setFuture(SettableFuture.<Integer>create()));
 // Check that the future has been set properly.
 assertTrue(future.isDone());
 assertFalse(future.isCancelled());
 assertEquals(42, (int) future.get());
}

代码示例来源:origin: google/guava

public void testCatching_resultInterruptedBeforeFallback() throws Exception {
 SettableFuture<Integer> primary = SettableFuture.create();
 Function<Throwable, Integer> fallback = unexpectedFunction();
 ListenableFuture<Integer> derived =
   catching(primary, Throwable.class, fallback, directExecutor());
 derived.cancel(true);
 assertTrue(primary.isCancelled());
 assertTrue(primary.wasInterrupted());
}

代码示例来源:origin: google/guava

public void testCatching_resultCancelledBeforeFallback() throws Exception {
 SettableFuture<Integer> primary = SettableFuture.create();
 Function<Throwable, Integer> fallback = unexpectedFunction();
 ListenableFuture<Integer> derived =
   catching(primary, Throwable.class, fallback, directExecutor());
 derived.cancel(false);
 assertTrue(primary.isCancelled());
 assertFalse(primary.wasInterrupted());
}

代码示例来源:origin: google/guava

public void testCatchingAsync_resultInterruptedBeforeFallback() throws Exception {
 SettableFuture<Integer> primary = SettableFuture.create();
 AsyncFunction<Throwable, Integer> fallback = unexpectedAsyncFunction();
 ListenableFuture<Integer> derived =
   catchingAsync(primary, Throwable.class, fallback, directExecutor());
 derived.cancel(true);
 assertTrue(primary.isCancelled());
 assertTrue(primary.wasInterrupted());
}

代码示例来源:origin: google/guava

public void testCatchingAsync_resultCancelledBeforeFallback() throws Exception {
 SettableFuture<Integer> primary = SettableFuture.create();
 AsyncFunction<Throwable, Integer> fallback = unexpectedAsyncFunction();
 ListenableFuture<Integer> derived =
   catchingAsync(primary, Throwable.class, fallback, directExecutor());
 derived.cancel(false);
 assertTrue(primary.isCancelled());
 assertFalse(primary.wasInterrupted());
}

代码示例来源:origin: google/guava

public void testAllAsList_resultInterrupted() throws Exception {
 SettableFuture<String> future1 = SettableFuture.create();
 SettableFuture<String> future2 = SettableFuture.create();
 @SuppressWarnings("unchecked") // array is never modified
 ListenableFuture<List<String>> compound = allAsList(future1, future2);
 future2.set(DATA2);
 assertFalse(compound.isDone());
 assertTrue(compound.cancel(true));
 assertTrue(compound.isCancelled());
 assertTrue(future1.isCancelled());
 assertTrue(future1.wasInterrupted());
}

代码示例来源:origin: google/guava

public void testAllAsList_resultCancelled() throws Exception {
 SettableFuture<String> future1 = SettableFuture.create();
 SettableFuture<String> future2 = SettableFuture.create();
 @SuppressWarnings("unchecked") // array is never modified
 ListenableFuture<List<String>> compound = allAsList(future1, future2);
 future2.set(DATA2);
 assertFalse(compound.isDone());
 assertTrue(compound.cancel(false));
 assertTrue(compound.isCancelled());
 assertTrue(future1.isCancelled());
 assertFalse(future1.wasInterrupted());
}

代码示例来源:origin: google/guava

public void testCancel_multipleBeforeSetFuture_noInterruptFirst() throws Exception {
 SettableFuture<Object> async = SettableFuture.create();
 async.cancel(false);
 async.cancel(true);
 SettableFuture<Object> inner = SettableFuture.create();
 assertFalse(async.setFuture(inner));
 assertTrue(inner.isCancelled());
 assertFalse(inner.wasInterrupted());
}

代码示例来源:origin: google/guava

public void testCancel_multipleBeforeSetFuture_interruptFirst() throws Exception {
  SettableFuture<Object> async = SettableFuture.create();
  async.cancel(true);
  async.cancel(false);
  SettableFuture<Object> inner = SettableFuture.create();
  assertFalse(async.setFuture(inner));
  assertTrue(inner.isCancelled());
  assertTrue(inner.wasInterrupted());
 }
}

代码示例来源:origin: google/guava

public void testSuccessfulAsList_resultCancelled() throws Exception {
 SettableFuture<String> future1 = SettableFuture.create();
 SettableFuture<String> future2 = SettableFuture.create();
 @SuppressWarnings("unchecked") // array is never modified
 ListenableFuture<List<String>> compound = successfulAsList(future1, future2);
 future2.set(DATA2);
 assertFalse(compound.isDone());
 assertTrue(compound.cancel(false));
 assertTrue(compound.isCancelled());
 assertTrue(future1.isCancelled());
 assertFalse(future1.wasInterrupted());
}

代码示例来源:origin: google/guava

public void testSuccessfulAsList_resultInterrupted() throws Exception {
 SettableFuture<String> future1 = SettableFuture.create();
 SettableFuture<String> future2 = SettableFuture.create();
 @SuppressWarnings("unchecked") // array is never modified
 ListenableFuture<List<String>> compound = successfulAsList(future1, future2);
 future2.set(DATA2);
 assertFalse(compound.isDone());
 assertTrue(compound.cancel(true));
 assertTrue(compound.isCancelled());
 assertTrue(future1.isCancelled());
 assertTrue(future1.wasInterrupted());
}

代码示例来源:origin: google/guava

public void testNonCancellationPropagating_doesNotPropagate() throws Exception {
 SettableFuture<Foo> input = SettableFuture.create();
 ListenableFuture<Foo> wrapper = nonCancellationPropagating(input);
 assertTrue(wrapper.cancel(true));
 assertTrue(wrapper.isCancelled());
 assertTrue(wrapper.isDone());
 assertFalse(input.isCancelled());
 assertFalse(input.isDone());
}

相关文章