Package com.google.common.util.concurrent

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


   }

   @Test
   void testCloserClosesExecutor() throws IOException {
      Injector i = createInjector();
      ListeningExecutorService executor = i.getInstance(Key.get(ListeningExecutorService.class,
            named(PROPERTY_USER_THREADS)));
      assert !executor.isShutdown();
      Closer closer = i.getInstance(Closer.class);
      assert closer.getState() == Closer.State.AVAILABLE;
      closer.close();
      assert executor.isShutdown();
      assert closer.getState() == Closer.State.DONE;
   }
View Full Code Here


   }

   @Test
   void testCloserPreDestroyOrder() throws IOException {
      Injector i = createInjector();
      ListeningExecutorService userExecutor = i.getInstance(Key.get(ListeningExecutorService.class,
            named(PROPERTY_USER_THREADS)));
      assert !userExecutor.isShutdown();
      ListeningExecutorService ioExecutor = i.getInstance(Key.get(ListeningExecutorService.class,
            named(PROPERTY_IO_WORKER_THREADS)));
      assert !ioExecutor.isShutdown();
      Closer closer = i.getInstance(Closer.class);
      assert closer.getState() == Closer.State.AVAILABLE;
      closer.close();
      assert userExecutor.isShutdown();
      assert ioExecutor.isShutdown();
      assert closer.getState() == Closer.State.DONE;
   }
View Full Code Here

   ProviderMetadata provider = forClientMappedToAsyncClientOnEndpoint(DelegatingApi.class, DelegatingAsyncApi.class,
         "http://mock");

   public void testApiClosesExecutorServiceOnClose() throws IOException {
      ListeningExecutorService executor = createMock(ListeningExecutorService.class);

      expect(executor.shutdownNow()).andReturn(ImmutableList.<Runnable> of()).atLeastOnce();

      replay(executor);

      DelegatingApi api = ContextBuilder.newBuilder(provider)
                                        .modules(ImmutableSet.<Module> builder()
View Full Code Here

    @BeforeMethod
    public void setUp()
            throws Exception
    {
        mockSession = new MockCassandraSession(CONNECTOR_ID);
        ListeningExecutorService executor = listeningDecorator(newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).build()));
        schemaProvider = new CachingCassandraSchemaProvider(
                CONNECTOR_ID,
                mockSession,
                executor,
                new Duration(5, TimeUnit.MINUTES),
View Full Code Here

    return prefixes;
  }

  private Collection<SingularityS3Log> getS3Logs(Collection<String> prefixes) throws InterruptedException, ExecutionException, TimeoutException {
    ListeningExecutorService es = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(Math.min(prefixes.size(), configuration.get().getMaxS3Threads()), new ThreadFactoryBuilder().setNameFormat("S3LogFetcher-%d").build()));

    List<ListenableFuture<S3Object[]>> futures = Lists.newArrayListWithCapacity(prefixes.size());

    for (final String s3Prefix : prefixes) {
      futures.add(es.submit(new Callable<S3Object[]>() {

        @Override
        public S3Object[] call() throws Exception {
          return s3.get().listObjects(configuration.get().getS3Bucket(), s3Prefix, null);
        }
      }));
    }

    final long start = System.currentTimeMillis();
    List<S3Object[]> results = Futures.allAsList(futures).get(configuration.get().getWaitForS3ListSeconds(), TimeUnit.SECONDS);

    List<S3Object> objects = Lists.newArrayListWithExpectedSize(results.size() * 2);

    for (S3Object[] s3Objects : results) {
      for (final S3Object s3Object : s3Objects) {
        objects.add(s3Object);
      }
    }

    LOG.trace("Got {} objects from S3 after {}", objects.size(), JavaUtils.duration(start));

    List<ListenableFuture<SingularityS3Log>> logFutures = Lists.newArrayListWithCapacity(objects.size());
    final Date expireAt = new Date(System.currentTimeMillis() + configuration.get().getExpireS3LinksAfterMillis());

    for (final S3Object s3Object : objects) {
      logFutures.add(es.submit(new Callable<SingularityS3Log>() {

        @Override
        public SingularityS3Log call() throws Exception {
          String getUrl = s3.get().createSignedGetUrl(configuration.get().getS3Bucket(), s3Object.getKey(), expireAt);

View Full Code Here

   }

   EventBus eventBus = new EventBus();

   public void testExitStatusZeroReturnsExecResponse() throws InterruptedException, ExecutionException {
      ListeningExecutorService userExecutor = MoreExecutors.sameThreadExecutor();
      Predicate<String> notRunningAnymore = Predicates.alwaysTrue();
      SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction")
               .addMockedMethod("getStatement").addMockedMethod("getNode").addMockedMethod("toString")
               .createStrictMock();
      InitScript initScript = createMockBuilder(InitScript.class).addMockedMethod("getInstanceName").createStrictMock();
View Full Code Here

   }

   public void testFirstExitStatusOneButSecondExitStatusZeroReturnsExecResponse() throws InterruptedException,
            ExecutionException {
      ListeningExecutorService userExecutor = MoreExecutors.sameThreadExecutor();
      Predicate<String> notRunningAnymore = Predicates.alwaysTrue();

      SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction")
               .addMockedMethod("getStatement").addMockedMethod("getNode").addMockedMethod("toString")
               .createStrictMock();
View Full Code Here

      verify(commandRunner, initScript);

   }

   public void testCancelInterruptStopsCommand() throws InterruptedException, ExecutionException {
      ListeningExecutorService userExecutor = MoreExecutors.sameThreadExecutor();
      Predicate<String> notRunningAnymore = Predicates.alwaysTrue();
      SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod(
               "refreshAndRunAction").addMockedMethod("runAction").addMockedMethod("getStatement").addMockedMethod(
               "getNode").addMockedMethod("toString").createStrictMock();
      InitScript initScript = createMockBuilder(InitScript.class).addMockedMethod("getInstanceName").createStrictMock();
View Full Code Here

   }

   public void testCancelDontInterruptLeavesCommandRunningAndReturnsLastStatus() throws InterruptedException,
            ExecutionException {
      ListeningExecutorService userExecutor = MoreExecutors.sameThreadExecutor();
      Predicate<String> notRunningAnymore = Predicates.alwaysTrue();
      SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction")
               .addMockedMethod("getStatement").addMockedMethod("getNode").addMockedMethod("toString")
               .createStrictMock();
      InitScript initScript = createMockBuilder(InitScript.class).addMockedMethod("getInstanceName").createStrictMock();
View Full Code Here

   @Test(enabled = true, dependsOnMethods = "testCompareSizes")
   public void testConcurrentUseOfComputeServiceToCreateNodes() throws Exception {
      final long timeoutMs = 20 * 60 * 1000;
      List<String> groups = Lists.newArrayList();
      List<ListenableFuture<NodeMetadata>> futures = Lists.newArrayList();
      ListeningExecutorService userExecutor = MoreExecutors.listeningDecorator(context.utils().userExecutor());

      try {
         for (int i = 0; i < 2; i++) {
            final int groupNum = i;
            final String group = "twin" + groupNum;
            groups.add(group);

            ListenableFuture<NodeMetadata> future = userExecutor.submit(new Callable<NodeMetadata>() {
               public NodeMetadata call() throws Exception {
                  NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1, inboundPorts(22, 8080)
                           .blockOnPort(22, 300 + groupNum)));
                  getAnonymousLogger().info("Started node " + node.getId());
                  return node;
View Full Code Here

TOP

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

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.