Package com.google.common.util.concurrent

Examples of com.google.common.util.concurrent.ListenableFuture


    RedisClient client = new RedisClient("localhost", 6379);
    RedisClient.Pipeline pipeline = client.pipeline();
    client.multi();

    // Use something other than dump-specific serialization to cause an error on restore
    ListenableFuture restoreResults = pipeline.restore("testing".getBytes(), 0, "foo".getBytes());
    Future<Boolean> execResults = client.exec();
    assertTrue(execResults.get());

    // The result of restore is supposed to be a ListenableFuture<StatusReply>, which I can't cast
    // to ErrorReply. Should get() throw an Exception instead?
    try {
      ErrorReply reply = (ErrorReply) restoreResults.get();
      fail("Should have thrown an exception");
    } catch (ExecutionException re) {
      Assert.assertTrue(re.getCause() instanceof RedisException);
    } catch (Exception e) {
      fail("Should have thrown an ExecutionException");
View Full Code Here


    // wait for query to register and start
    Assert.assertTrue(queryIsRegistered.await(1, TimeUnit.SECONDS));
    Assert.assertTrue(queriesStarted.await(1, TimeUnit.SECONDS));

    Assert.assertTrue(capturedFuture.hasCaptured());
    ListenableFuture future = capturedFuture.getValue();

    // wait for query to time out
    QueryInterruptedException cause = null;
    try {
      resultFuture.get();
    } catch(ExecutionException e) {
      Assert.assertTrue(e.getCause() instanceof QueryInterruptedException);
      Assert.assertEquals("Query timeout", e.getCause().getMessage());
      cause = (QueryInterruptedException)e.getCause();
    }
    Assert.assertTrue(queriesInterrupted.await(500, TimeUnit.MILLISECONDS));
    Assert.assertNotNull(cause);
    Assert.assertTrue(future.isCancelled());
    Assert.assertTrue(runner1.hasStarted);
    Assert.assertTrue(runner2.hasStarted);
    Assert.assertTrue(runner1.interrupted);
    Assert.assertTrue(runner2.interrupted);
    Assert.assertTrue(!runner3.hasStarted || runner3.interrupted);
View Full Code Here

    Assert.assertTrue(queryIsRegistered.await(1, TimeUnit.SECONDS));
    Assert.assertTrue(queriesStarted.await(1, TimeUnit.SECONDS));

    // cancel the query
    Assert.assertTrue(capturedFuture.hasCaptured());
    ListenableFuture future = capturedFuture.getValue();
    future.cancel(true);

    QueryInterruptedException cause = null;
    try {
      resultFuture.get();
    } catch(ExecutionException e) {
      Assert.assertTrue(e.getCause() instanceof QueryInterruptedException);
      cause = (QueryInterruptedException)e.getCause();
    }
    Assert.assertTrue(queriesInterrupted.await(500, TimeUnit.MILLISECONDS));
    Assert.assertNotNull(cause);
    Assert.assertTrue(future.isCancelled());
    Assert.assertTrue(runner1.hasStarted);
    Assert.assertTrue(runner2.hasStarted);
    Assert.assertTrue(runner1.interrupted);
    Assert.assertTrue(runner2.interrupted);
    Assert.assertTrue(!runner3.hasStarted || runner3.interrupted);
View Full Code Here

    public AsyncChain(List<AsyncFunction<?, ?>> functions) {
        this.functions = ImmutableList.copyOf(functions);
    }

    public ListenableFuture<O> apply(I input) throws Exception {
        ListenableFuture nextInput = new NoOpFuture<I>(input);
        for (AsyncFunction func : functions) {
            if (func instanceof AsyncFunctionWithThreadPool) {
                nextInput = Futures.transform(nextInput, func, ((AsyncFunctionWithThreadPool)func).getThreadPool());
            } else {
                nextInput = Futures.transform(nextInput, func, MoreExecutors.sameThreadExecutor());
View Full Code Here

    public void testSupervisorRejectNewTasksIfThreadPoolIsFullForIncompleteTasks() throws Exception {
        // testTask should always timeout
        TestTask testTask = new TestTask(4);
        TimedSupervisorTask supervisorTask = new TimedSupervisorTask("test", executor, 1, testTask);

        ListenableFuture a = helperExecutor.submit(supervisorTask);
        ListenableFuture b = helperExecutor.submit(supervisorTask);
        ListenableFuture c = helperExecutor.submit(supervisorTask);
        ListenableFuture d = helperExecutor.submit(supervisorTask);
        Futures.successfulAsList(a, b, c, d).get();
        Thread.sleep(500)// wait a little bit for the subtask interrupt handlers

        Assert.assertEquals(3, maxConcurrentTestTasks.get());
        Assert.assertEquals(3, testTaskCounter.get());
View Full Code Here

    GetEntriesResult entriesResult = new GetEntriesResult(0L, 0L, Collections.<Entry>emptyList());
    when(mockRaftLog.getEntriesFrom(anyLong(), anyInt())).thenReturn(entriesResult);

    ReplicaManager replicaManager = new ReplicaManager(mockClient, mockRaftLog, FOLLOWER);
    ListenableFuture f1 = replicaManager.requestUpdate();

    AppendEntries appendEntries = AppendEntries.newBuilder()
        .setLeaderId(SELF.toString())
        .setCommitIndex(0)
        .setPrevLogIndex(0)
        .setPrevLogTerm(0)
        .setTerm(1)
        .build();

    verify(mockClient, times(1)).appendEntries(FOLLOWER, appendEntries);
    verifyNoMoreInteractions(mockClient);

    verify(mockRaftLog, times(1)).getEntriesFrom(1, 1);

    assertTrue(replicaManager.isRunning());
    assertFalse(replicaManager.isRequested());
    assertEquals(1, replicaManager.getNextIndex());

    ListenableFuture f2 = replicaManager.requestUpdate();

    assertNotSame(f1, f2);
    assertTrue(replicaManager.isRunning());
    assertTrue(replicaManager.isRequested());
    assertEquals(1, replicaManager.getNextIndex());
View Full Code Here

    }

    Object loadSync(Object paramObject, int paramInt, LocalCache.LoadingValueReference paramLoadingValueReference, CacheLoader paramCacheLoader)
      throws ExecutionException
    {
      ListenableFuture localListenableFuture = paramLoadingValueReference.loadFuture(paramObject, paramCacheLoader);
      return getAndRecordStats(paramObject, paramInt, paramLoadingValueReference, localListenableFuture);
    }
View Full Code Here

      return getAndRecordStats(paramObject, paramInt, paramLoadingValueReference, localListenableFuture);
    }

    ListenableFuture loadAsync(final Object paramObject, final int paramInt, final LocalCache.LoadingValueReference paramLoadingValueReference, CacheLoader paramCacheLoader)
    {
      final ListenableFuture localListenableFuture = paramLoadingValueReference.loadFuture(paramObject, paramCacheLoader);
      localListenableFuture.addListener(new Runnable()
      {
        public void run()
        {
          try
          {
View Full Code Here

    Object refresh(Object paramObject, int paramInt, CacheLoader paramCacheLoader)
    {
      LocalCache.LoadingValueReference localLoadingValueReference = insertLoadingValueReference(paramObject, paramInt);
      if (localLoadingValueReference == null)
        return null;
      ListenableFuture localListenableFuture = loadAsync(paramObject, paramInt, localLoadingValueReference, paramCacheLoader);
      if (localListenableFuture.isDone())
        try
        {
          return Uninterruptibles.getUninterruptibly(localListenableFuture);
        }
        catch (Throwable localThrowable)
View Full Code Here

TOP

Related Classes of com.google.common.util.concurrent.ListenableFuture

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.