com.google.common.util.concurrent.Callables#returning ( )源码实例Demo

下面列出了com.google.common.util.concurrent.Callables#returning ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: javaide   文件: PackageSplitAbi.java
@Override
@NonNull
public synchronized ImmutableList<ApkOutputFile> getOutputSplitFiles() {

    if (outputFiles == null) {
        ImmutableList.Builder<ApkOutputFile> builder = ImmutableList.builder();
        for (String split : splits) {
            String apkName = getApkName(split);
            ApkOutputFile apkOutput = new ApkOutputFile(
                    OutputFile.OutputType.SPLIT,
                    ImmutableList.of(FilterDataImpl.build(OutputFile.ABI, apkName)),
                    Callables.returning(new File(outputDirectory, apkName)));
            builder.add(apkOutput);
        }

        outputFiles = builder.build();
    }
    return outputFiles;
}
 
源代码2 项目: google-cloud-eclipse   文件: PluggableJobTest.java
@Test
public void testStaleFiresFutureListener() throws InterruptedException {
  Object obj = new Object();
  final PluggableJob<Object> job =
      new PluggableJob<>("name", Callables.returning(obj), unused -> true);
  assertFalse(job.getFuture().isDone());
  final boolean[] listenerRun = new boolean[] {false};
  job.getFuture().addListener(() -> {
    listenerRun[0] = true;
    assertTrue(job.getFuture().isCancelled());
  }, MoreExecutors.directExecutor());
  assertFalse(listenerRun[0]);
  job.schedule();
  job.join();
  assertTrue(listenerRun[0]);
  assertEquals("Should be CANCEL", IStatus.CANCEL, job.getResult().getSeverity());
}
 
@Test
public void testGetResultOfQueuedTaskBeforeItExecutes() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    em.submit(MutableMap.of("tag", "category1"), newLatchAwaiter(latch));
    
    BasicTask<Integer> t = new BasicTask<Integer>(Callables.returning(123));
    Future<Integer> future = em.submit(MutableMap.of("tag", "category1"), t);

    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
            latch.countDown();
        }});
    thread.start();
    assertEquals(future.get(), (Integer)123);
}
 
源代码4 项目: google-cloud-eclipse   文件: PluggableJobTest.java
@Test
public void testConstructor_nullStalenessCheck() {
  try {
    new PluggableJob<>("name", Callables.returning((Void) null), null);
    fail("Expected NPE");
  } catch (NullPointerException ex) {
  }
}
 
源代码5 项目: google-cloud-eclipse   文件: PluggableJobTest.java
@Test
public void testScheduled() throws InterruptedException, ExecutionException {
  Object obj = new Object();
  PluggableJob<Object> job = new PluggableJob<>("name", Callables.returning(obj));
  assertFalse(job.getFuture().isDone());
  assertFalse(job.getFuture().isCancelled());
  job.schedule();
  job.join();
  assertTrue(job.getFuture().isDone());
  assertFalse(job.getFuture().isCancelled());
  assertSame(obj, job.getFuture().get());
  assertEquals("Should be OK", IStatus.OK, job.getResult().getSeverity());
}
 
源代码6 项目: google-cloud-eclipse   文件: PluggableJobTest.java
@Test
public void testStaleCancelsFuture() throws InterruptedException {
  Object obj = new Object();
  PluggableJob<Object> job = new PluggableJob<>("name", Callables.returning(obj), unused -> true);
  job.schedule();
  job.join();
  assertEquals("Should be CANCEL", IStatus.CANCEL, job.getResult().getSeverity());
  assertTrue(job.getFuture().isCancelled());
}
 
源代码7 项目: google-cloud-eclipse   文件: PluggableJobTest.java
@Test
public void testCompleteness_normal() throws InterruptedException {
  Object obj = new Object();
  PluggableJob<Object> job = new PluggableJob<>("name", Callables.returning(obj));
  assertFalse(job.isComputationComplete());
  job.schedule();
  job.join();
  assertTrue(job.isComputationComplete());
  assertFalse(job.getComputationError().isPresent());
  assertTrue(job.getComputationResult().isPresent());
  assertEquals(obj, job.getComputationResult().get());
  assertEquals(obj, job.getComputation().get());
}
 
源代码8 项目: google-cloud-eclipse   文件: PluggableJobTest.java
@Test
public void testOnSuccess_normal() throws InterruptedException {
  Object obj = new Object();
  PluggableJob<Object> job = new PluggableJob<>("name", Callables.returning(obj));
  final boolean[] listenerRun = new boolean[] {false};
  job.onSuccess(MoreExecutors.directExecutor(), () -> listenerRun[0] = true);
  assertFalse(listenerRun[0]);
  job.schedule();
  job.join();
  assertTrue(listenerRun[0]);
  assertTrue(job.isComputationComplete());
}
 
源代码9 项目: google-cloud-eclipse   文件: PluggableJobTest.java
@Test
public void testOnSuccess_abandon() throws InterruptedException {
  Object obj = new Object();
  PluggableJob<Object> job =
      new PluggableJob<>("name", Callables.returning(obj), unused -> true);
  final boolean[] listenerRun = new boolean[] {false};
  job.onSuccess(MoreExecutors.directExecutor(), () -> listenerRun[0] = true);
  assertFalse(listenerRun[0]);
  job.schedule(); // should be stale and cancelled
  job.join();
  assertFalse("onSuccess should not have been called", listenerRun[0]);
}
 
源代码10 项目: google-cloud-eclipse   文件: PluggableJobTest.java
@Test
public void testIsCurrent_abandon() throws InterruptedException {
  Object obj = new Object();
  PluggableJob<Object> job = new PluggableJob<>("name", Callables.returning(obj));
  assertTrue(job.isCurrent());
  job.schedule(); // should be stale and cancelled
  job.join();
  assertTrue(job.isCurrent());
  job.abandon();
  assertFalse("Abandoned jobs should not be current", job.isCurrent());
}
 
源代码11 项目: google-cloud-eclipse   文件: PluggableJobTest.java
@Test
public void testIsCurrent_stale() throws InterruptedException {
  Object obj = new Object();
  final boolean[] isStale = new boolean[] { false };
  PluggableJob<Object> job = new PluggableJob<>("name", Callables.returning(obj),
      unused -> isStale[0]);
  assertTrue(job.isCurrent());
  job.schedule(); // should self-cancel
  job.join();
  assertTrue(job.isCurrent());
  isStale[0] = true;
  // should now be stale 
  assertFalse("Stale jobs should not be current", job.isCurrent());
}
 
源代码12 项目: brooklyn-server   文件: ValueResolverTest.java
public void testTaskFactoryGet() {
    TaskFactory<TaskAdaptable<String>> taskFactory = new TaskFactory<TaskAdaptable<String>>() {
        @Override public TaskAdaptable<String> newTask() {
            return new BasicTask<>(Callables.returning("myval"));
        }
    };
    String result = Tasks.resolving(taskFactory).as(String.class).context(app).get();
    assertEquals(result, "myval");
}
 
源代码13 项目: brooklyn-server   文件: ValueResolverTest.java
public void testTaskFactoryGetImmediately() {
    TaskFactory<TaskAdaptable<String>> taskFactory = new TaskFactory<TaskAdaptable<String>>() {
        @Override public TaskAdaptable<String> newTask() {
            return new BasicTask<>(Callables.returning("myval"));
        }
    };
    String result = Tasks.resolving(taskFactory).as(String.class).context(app).immediately(true).get();
    assertEquals(result, "myval");
}
 
@Test
public void testGetResultOfQueuedTaskBeforeItExecutesWithTimeout() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    em.submit(MutableMap.of("tag", "category1"), newLatchAwaiter(latch));
    
    BasicTask<Integer> t = new BasicTask<Integer>(Callables.returning(123));
    Future<Integer> future = em.submit(MutableMap.of("tag", "category1"), t);

    try {
        assertEquals(future.get(10, TimeUnit.MILLISECONDS), (Integer)123);
        fail();
    } catch (TimeoutException e) {
        // success
    }
}
 
@Test
public void testGetResultOfQueuedTaskAfterItExecutes() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    em.submit(MutableMap.of("tag", "category1"), newLatchAwaiter(latch));
    
    BasicTask<Integer> t = new BasicTask<Integer>(Callables.returning(123));
    Future<Integer> future = em.submit(MutableMap.of("tag", "category1"), t);

    latch.countDown();
    assertEquals(future.get(), (Integer)123);
}
 
源代码16 项目: brooklyn-server   文件: BasicTaskExecutionTest.java
@Test
public void cancelAfterRun() throws Exception {
    BasicTask<Integer> t = new BasicTask<Integer>(Callables.returning(42));
    em.submit(MutableMap.of("tag", "A"), t);

    assertEquals(t.get(), (Integer)42);
    t.cancel(true);
    assertFalse(t.isCancelled());
    assertFalse(t.isError());
    assertTrue(t.isDone());
}
 
源代码17 项目: javaide   文件: PostCompilationData.java
public void setInputFiles(@Nullable List<File> inputFiles) {
    this.inputFiles = Callables.returning(inputFiles);
}
 
源代码18 项目: javaide   文件: PostCompilationData.java
public void setInputDir(@NonNull File inputDir) {
    this.inputDir = Callables.returning(inputDir);
}
 
源代码19 项目: javaide   文件: PostCompilationData.java
public void setJavaResourcesInputDir(@NonNull File javaResourcesInputDir) {
    this.javaResourcesInputDir = Callables.returning(javaResourcesInputDir);
}
 
源代码20 项目: javaide   文件: PostCompilationData.java
public void setInputLibraries(@NonNull List<File> inputLibraries) {
    this.inputLibraries = Callables.returning(inputLibraries);
}