Package com.google.common.util.concurrent

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


   @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);
            template = buildTemplate(client.templateBuilder());
            template.getOptions().inboundPorts(22, 8080).blockOnPort(22, 300 + groupNum);
            ListenableFuture<NodeMetadata> future = userExecutor.submit(new Callable<NodeMetadata>() {
               public NodeMetadata call() throws Exception {
                  NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1, template));
                  getAnonymousLogger().info("Started node " + node.getId());
                  return node;
               }
View Full Code Here


      assertNull(module.ioExecutorFromConstructor);
   }

   @AfterClass
   private void close() throws IOException {
      ListeningExecutorService user = injector.getInstance(Key.get(ListeningExecutorService.class,
            named(PROPERTY_USER_THREADS)));
      ListeningExecutorService io = injector.getInstance(Key.get(ListeningExecutorService.class,
            named(PROPERTY_IO_WORKER_THREADS)));
      injector.getInstance(Closer.class).close();
      assertTrue(user.isShutdown());
      assertTrue(io.isShutdown());
   }
View Full Code Here

   @Test
   public void testShutdownOnClose() throws IOException {
      Injector i = Guice.createInjector();

      Closer closer = i.getInstance(Closer.class);
      ListeningExecutorService executor = createMock(ListeningExecutorService.class);
      ExecutorServiceModule.shutdownOnClose(executor, closer);

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

      replay(executor);
      closer.close();

      verify(executor);
View Full Code Here

      verify(executor);
   }

   @Test(timeOut = 5000)
   public void testExceptionInSubmitRunnableIncludesSubmissionTrace() throws Exception {
      ListeningExecutorService user = injector.getInstance(Key.get(ListeningExecutorService.class,
            named(PROPERTY_USER_THREADS)));
      ListeningExecutorService io = injector.getInstance(Key.get(ListeningExecutorService.class,
            named(PROPERTY_IO_WORKER_THREADS)));

      for (ListeningExecutorService exec : ImmutableList.of(user, io)) {
         String submission = null;
         try {
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

   }

   @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

        this.clientProvider = checkNotNull(hiveCluster, "hiveCluster is null");

        long expiresAfterWriteMillis = checkNotNull(cacheTtl, "cacheTtl is null").toMillis();
        long refreshMills = checkNotNull(refreshInterval, "refreshInterval is null").toMillis();

        ListeningExecutorService listeningExecutor = MoreExecutors.listeningDecorator(executor);

        databaseNamesCache = CacheBuilder.newBuilder()
                .expireAfterWrite(expiresAfterWriteMillis, MILLISECONDS)
                .refreshAfterWrite(refreshMills, MILLISECONDS)
                .build(new BackgroundCacheLoader<String, List<String>>(listeningExecutor)
View Full Code Here

            for (int k = 0; k < 50; k++) {
                testRoot.addNode("n" + k);
            }
            session.save();

            ListeningExecutorService executorService = MoreExecutors.listeningDecorator(
                    Executors.newCachedThreadPool());

            List<ListenableFuture<?>> futures = Lists.newArrayList();
            for (int k = 0; k < 20; k ++) {
                futures.add(executorService.submit(new Callable<Void>() {
                    @Override
                    public Void call() throws Exception {
                        for (int k = 0; k < 10000; k++) {
                            session.refresh(false);
                            NodeIterator children = testRoot.getNodes();
                            children.hasNext();
                        }
                        return null;
                    }
                }));
            }

            // Throws ExecutionException if any of the submitted task failed
            Futures.allAsList(futures).get();
            executorService.shutdown();
            executorService.awaitTermination(1, TimeUnit.DAYS);
        } finally {
            session.logout();
        }
    }
View Full Code Here

            for (int k = 0; k < 50; k++) {
                testRoot.setProperty("p" + k, k);
            }
            session.save();

            ListeningExecutorService executorService = MoreExecutors.listeningDecorator(
                    Executors.newCachedThreadPool());

            List<ListenableFuture<?>> futures = Lists.newArrayList();
            for (int k = 0; k < 20; k ++) {
                futures.add(executorService.submit(new Callable<Void>() {
                    @Override
                    public Void call() throws Exception {
                        for (int k = 0; k < 100000; k++) {
                            session.refresh(false);
                            PropertyIterator properties = testRoot.getProperties();
                            properties.hasNext();
                        }
                        return null;
                    }
                }));
            }

            // Throws ExecutionException if any of the submitted task failed
            Futures.allAsList(futures).get();
            executorService.shutdown();
            executorService.awaitTermination(1, TimeUnit.DAYS);
        } finally {
            session.logout();
        }
    }
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.