public AsyncQueryRunner(QueryRunner<T> baseRunner, ExecutorService executor, QueryWatcher queryWatcher) { this.baseRunner = baseRunner; this.executor = MoreExecutors.listeningDecorator(executor); this.queryWatcher = queryWatcher; }
public BackgroundCachePopulator( final ExecutorService exec, final ObjectMapper objectMapper, final CachePopulatorStats cachePopulatorStats, final long maxEntrySize ) { this.exec = MoreExecutors.listeningDecorator(exec); this.objectMapper = Preconditions.checkNotNull(objectMapper, "objectMapper"); this.cachePopulatorStats = Preconditions.checkNotNull(cachePopulatorStats, "cachePopulatorStats"); this.maxEntrySize = maxEntrySize; }
public ChainedExecutionQueryRunner( ExecutorService exec, QueryWatcher queryWatcher, Iterable<QueryRunner<T>> queryables ) { // listeningDecorator will leave PrioritizedExecutorService unchanged, // since it already implements ListeningExecutorService this.exec = MoreExecutors.listeningDecorator(exec); this.queryables = Iterables.unmodifiableIterable(queryables); this.queryWatcher = queryWatcher; }
BaseAppenderatorDriver( Appenderator appenderator, SegmentAllocator segmentAllocator, UsedSegmentChecker usedSegmentChecker, DataSegmentKiller dataSegmentKiller ) { this.appenderator = Preconditions.checkNotNull(appenderator, "appenderator"); this.segmentAllocator = Preconditions.checkNotNull(segmentAllocator, "segmentAllocator"); this.usedSegmentChecker = Preconditions.checkNotNull(usedSegmentChecker, "usedSegmentChecker"); this.dataSegmentKiller = Preconditions.checkNotNull(dataSegmentKiller, "dataSegmentKiller"); this.executor = MoreExecutors.listeningDecorator(Execs.singleThreaded("publish-%d")); }
@Inject public FileSingleStreamSpillerFactory(BlockEncodingSerde blockEncodingSerde, SpillerStats spillerStats, FeaturesConfig featuresConfig) { this( listeningDecorator(newFixedThreadPool( requireNonNull(featuresConfig, "featuresConfig is null").getSpillerThreads(), daemonThreadsNamed("binary-spiller-%s"))), blockEncodingSerde, spillerStats, requireNonNull(featuresConfig, "featuresConfig is null").getSpillerSpillPaths(), requireNonNull(featuresConfig, "featuresConfig is null").getSpillMaxUsedSpaceThreshold()); }
@BeforeClass public void setUp() { executor = MoreExecutors.listeningDecorator(newCachedThreadPool()); }
private static ListeningExecutorService buildExecutorService(int priority) { return MoreExecutors.listeningDecorator( Execs.singleThreaded( "task-runner-%d-priority-" + priority, TaskThreadPriority.getThreadPriorityFromTaskPriority(priority) ) ); }
public void testListeningDecorator_noWrapExecuteTask() { ExecutorService delegate = mock(ExecutorService.class); ListeningExecutorService service = listeningDecorator(delegate); Runnable task = new Runnable() { @Override public void run() {} }; service.execute(task); verify(delegate).execute(task); }
@BeforeMethod public void setUp() { executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()); closer.register(() -> executor.shutdownNow()); spillPath1 = Files.createTempDir(); closer.register(() -> deleteRecursively(spillPath1.toPath(), ALLOW_INSECURE)); spillPath2 = Files.createTempDir(); closer.register(() -> deleteRecursively(spillPath2.toPath(), ALLOW_INSECURE)); }
public void testListeningDecorator() throws Exception { ListeningExecutorService service = listeningDecorator(newDirectExecutorService()); assertSame(service, listeningDecorator(service)); List<Callable<String>> callables = ImmutableList.of(Callables.returning("x")); List<Future<String>> results; results = service.invokeAll(callables); assertThat(getOnlyElement(results)).isInstanceOf(TrustedListenableFutureTask.class); results = service.invokeAll(callables, 1, SECONDS); assertThat(getOnlyElement(results)).isInstanceOf(TrustedListenableFutureTask.class); /* * TODO(cpovirk): move ForwardingTestCase somewhere common, and use it to * test the forwarded methods */ }
public void testListeningDecorator_scheduleFailure() throws Exception { ScheduledThreadPoolExecutor delegate = new ScheduledThreadPoolExecutor(1); ListeningScheduledExecutorService service = listeningDecorator(delegate); RuntimeException ex = new RuntimeException(); ListenableFuture<?> future = service.schedule(new ThrowingRunnable(0, ex), 1, TimeUnit.MILLISECONDS); assertExecutionException(future, ex); assertEquals(0, delegate.getQueue().size()); }
private static ListeningExecutorService buildExecutorService(int priority) { return MoreExecutors.listeningDecorator( Execs.singleThreaded( "test-task-runner-%d-priority-" + priority, TaskThreadPriority.getThreadPriorityFromTaskPriority(priority) ) ); }
@Before public void setUp() { EmittingLogger.registerEmitter(emitter); emitter.start(); throttler = EasyMock.createMock(ReplicationThrottler.class); exec = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1)); balancerStrategy = new CostBalancerStrategyFactory().createBalancerStrategy(exec); mockBalancerStrategy = EasyMock.createMock(BalancerStrategy.class); }
public void testListeningDecorator_scheduleSuccess() throws Exception { final CountDownLatch completed = new CountDownLatch(1); ScheduledThreadPoolExecutor delegate = new ScheduledThreadPoolExecutor(1) { @Override protected void afterExecute(Runnable r, Throwable t) { completed.countDown(); } }; ListeningScheduledExecutorService service = listeningDecorator(delegate); ListenableFuture<Integer> future = service.schedule(Callables.returning(42), 1, TimeUnit.MILLISECONDS); /* * Wait not just until the Future's value is set (as in future.get()) but * also until ListeningScheduledExecutorService's wrapper task is done * executing listeners, as detected by yielding control to afterExecute. */ completed.await(); assertTrue(future.isDone()); assertThat(future.get()).isEqualTo(42); assertListenerRunImmediately(future); assertEquals(0, delegate.getQueue().size()); }
public void testListeningDecorator_schedulePeriodic() throws Exception { ScheduledThreadPoolExecutor delegate = new ScheduledThreadPoolExecutor(1); ListeningScheduledExecutorService service = listeningDecorator(delegate); RuntimeException ex = new RuntimeException(); ListenableFuture<?> future; ThrowingRunnable runnable = new ThrowingRunnable(5, ex); future = service.scheduleAtFixedRate(runnable, 1, 1, TimeUnit.MILLISECONDS); assertExecutionException(future, ex); assertEquals(5, runnable.count); assertEquals(0, delegate.getQueue().size()); runnable = new ThrowingRunnable(5, ex); future = service.scheduleWithFixedDelay(runnable, 1, 1, TimeUnit.MILLISECONDS); assertExecutionException(future, ex); assertEquals(5, runnable.count); assertEquals(0, delegate.getQueue().size()); }
@Before public void setUp() { EmittingLogger.registerEmitter(emitter); emitter.start(); taskExec = MoreExecutors.listeningDecorator(Execs.singleThreaded("realtime-index-task-test-%d")); now = DateTimes.nowUtc(); }
@Test public void testCostBalancerMultiThreadedStrategy() { List<ServerHolder> serverHolderList = setupDummyCluster(10, 20); DataSegment segment = getSegment(1000); BalancerStrategy strategy = new CostBalancerStrategy( MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(4)) ); ServerHolder holder = strategy.findNewSegmentHomeReplicator(segment, serverHolderList); Assert.assertNotNull("Should be able to find a place for new segment!!", holder); Assert.assertEquals("Best Server should be BEST_SERVER", "BEST_SERVER", holder.getServer().getName()); }
@Test public void testCostBalancerSingleThreadStrategy() { List<ServerHolder> serverHolderList = setupDummyCluster(10, 20); DataSegment segment = getSegment(1000); BalancerStrategy strategy = new CostBalancerStrategy( MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1)) ); ServerHolder holder = strategy.findNewSegmentHomeReplicator(segment, serverHolderList); Assert.assertNotNull("Should be able to find a place for new segment!!", holder); Assert.assertEquals("Best Server should be BEST_SERVER", "BEST_SERVER", holder.getServer().getName()); }
@Test public void testNormalizedCostBalancerMultiThreadedStrategy() { List<ServerHolder> serverHolderList = setupDummyCluster(10, 20); DataSegment segment = getSegment(1000); BalancerStrategy strategy = new DiskNormalizedCostBalancerStrategy( MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(4)) ); ServerHolder holder = strategy.findNewSegmentHomeReplicator(segment, serverHolderList); Assert.assertNotNull("Should be able to find a place for new segment!!", holder); Assert.assertEquals("Best Server should be BEST_SERVER", "BEST_SERVER", holder.getServer().getName()); }
@Test public void testNormalizedCostBalancerSingleThreadStrategy() { List<ServerHolder> serverHolderList = setupDummyCluster(10, 20); DataSegment segment = getSegment(1000); BalancerStrategy strategy = new DiskNormalizedCostBalancerStrategy( MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1)) ); ServerHolder holder = strategy.findNewSegmentHomeReplicator(segment, serverHolderList); Assert.assertNotNull("Should be able to find a place for new segment!!", holder); Assert.assertEquals("Best Server should be BEST_SERVER", "BEST_SERVER", holder.getServer().getName()); } }