java.util.concurrent.Executors Java Examples

The following examples show how to use java.util.concurrent.Executors. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PropertiesLoginModuleRaceConditionTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws FileNotFoundException, IOException {
   createUsers();
   createGroups();

   options = new HashMap<>();
   options.put("reload", "true"); // Used to simplify reproduction of the
   // race condition
   options.put("org.apache.activemq.jaas.properties.user", USERS_FILE);
   options.put("org.apache.activemq.jaas.properties.role", ROLES_FILE);
   options.put("baseDir", temp.getRoot().getAbsolutePath());

   errors = new ArrayBlockingQueue<>(processorCount());
   pool = Executors.newFixedThreadPool(processorCount(), ActiveMQThreadFactory.defaultThreadFactory());
   callback = new JaasCallbackHandler(USERNAME, PASSWORD, null);
}
 
Example #2
Source File: ScriptCallableTest.java    From commons-jexl with Apache License 2.0 6 votes vote down vote up
@Override
public Object processAnnotation(String name, Object[] args, Callable<Object> statement) throws Exception {
    if ("timeout".equals(name) && args != null && args.length > 0) {
        long ms = args[0] instanceof Number
                  ? ((Number) args[0]).longValue()
                  : Long.parseLong(args[0].toString());
        Object def = args.length > 1? args[1] : null;
        if (ms > 0) {
            ExecutorService executor = Executors.newFixedThreadPool(1);
            Future<?> future = null;
            try {
                future = executor.submit(statement);
                return future.get(ms, TimeUnit.MILLISECONDS);
            } catch (TimeoutException xtimeout) {
                if (future != null) {
                    future.cancel(true);
                }
            } finally {
                executor.shutdown();
            }

        }
        return def;
    }
    return statement.call();
}
 
Example #3
Source File: ScriptCallableTest.java    From commons-jexl with Apache License 2.0 6 votes vote down vote up
@Test
public void testCancelWait() throws Exception {
    List<Runnable> lr = null;
    JexlScript e = JEXL.createScript("wait(10)");
    Callable<Object> c = e.callable(new TestContext());

    ExecutorService executor = Executors.newFixedThreadPool(1);
    try {
        Future<?> future = executor.submit(c);
        Object t = 42;
        try {
            t = future.get(100, TimeUnit.MILLISECONDS);
            Assert.fail("should have timed out");
        } catch (TimeoutException xtimeout) {
            // ok, ignore
            future.cancel(true);
        }
        Assert.assertTrue(future.isCancelled());
        Assert.assertEquals(42, t);
    } finally {
        lr = executor.shutdownNow();
    }
    Assert.assertTrue(lr.isEmpty());
}
 
Example #4
Source File: ResourcePoolUsage.java    From banyan with MIT License 6 votes vote down vote up
public static void main(String[] args) {
    ExecutorService executor = Executors.newCachedThreadPool();
    ResourcePool pool = new ResourcePool<Integer>(15,
            Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14));
    Random random = new Random();
    for (int i = 0; i < 30; i++) {
        executor.execute(() -> {
            try {
                Object value = pool.get(60);
                System.out.println("Value taken: " + value);
                Thread.sleep(random.nextInt(5000));
                pool.release(value);
                System.out.println("Value released " + value);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
    }
    executor.shutdown();
}
 
Example #5
Source File: CrawlerTask.java    From hot-crawler with MIT License 6 votes vote down vote up
private void executeTask(List<SiteProperties.SiteCate> cateList, List<SiteProperties.SiteInfo> sites)
{
    threadPoolNum = threadPoolNum < cateList.size() ? threadPoolNum : sites.size();
    ExecutorService executorService = Executors.newFixedThreadPool(threadPoolNum);

    for (SiteProperties.SiteCate cate : cateList)
    {
        for (SiteProperties.SiteInfo site : cate.getSites()) {
            executorService.submit(() -> {
                try {
                    HotProcessor hotProcessor = null;
                    hotProcessor = (HotProcessor) baseService.getBean(Class.forName(site.getProcessorClassPath()));
                    List<Info> infoList = hotProcessor.crawlHotList();
                    infoRepository.removeByTypeId(site.getCode());
                    infoRepository.saveAll(infoList, site.getCode());
                } catch (RuntimeException | ClassNotFoundException e) {
                    log.error(e.getMessage(), e);
                }
            });
        }
    }
}
 
Example #6
Source File: HttpWorkflowStepPluginTest.java    From rundeck-http-plugin with ISC License 6 votes vote down vote up
@Test()
public void canHandleMultipleThreads() throws ExecutionException, InterruptedException {
    ExecutorService executor = Executors.newFixedThreadPool(HttpWorkflowStepPlugin.HTTP_METHODS.length);
    ArrayList<Future<Boolean>> results = new ArrayList<>();

    for(String method : HttpWorkflowStepPlugin.HTTP_METHODS) {
        results.add(executor.submit(() -> {
            HttpWorkflowStepPlugin threadedPlugin = new HttpWorkflowStepPlugin();

            try {
                threadedPlugin.executeStep(new PluginStepContextImpl(), this.getOAuthOptions(method));
                return true;
            } catch(StepException se) {
                se.printStackTrace();
                return false;
            }
        }));
    }

    assertEquals(HttpWorkflowStepPlugin.HTTP_METHODS.length, results.size());

    for(Future<Boolean> result : results) {
        assertTrue(result.get());
    }
}
 
Example #7
Source File: CompletableFutureInboundDataClientTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompleteMultithreaded() throws Exception {
  InboundDataClient client = CompletableFutureInboundDataClient.create();
  Future<Void> waitingFuture =
      Executors.newSingleThreadExecutor()
          .submit(
              () -> {
                client.awaitCompletion();
                return null;
              });

  try {
    waitingFuture.get(50, TimeUnit.MILLISECONDS);
    fail();
  } catch (TimeoutException expected) {
    // This should time out, as the client should never complete without external completion
  }

  client.complete();
  // Blocks forever if the thread does not continue
  waitingFuture.get();
}
 
Example #8
Source File: HeapMemoryMonitor.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Start a separate thread for polling the JVM for heap memory usage.
 */
private void startMemoryPoolPoller() {
  if (tenuredMemoryPoolMXBean == null) {
    return;
  }
  
  final ThreadGroup threadGroup = LogWriterImpl.createThreadGroup("HeapPoller", this.cache.getLoggerI18n());
  final ThreadFactory threadFactory = new ThreadFactory() {
    @Override
    public Thread newThread(Runnable r) {
      Thread thread = new Thread(threadGroup, r, "GemfireHeapPoller");
      thread.setDaemon(true);
      return thread;
    }
  };
  
  this.pollerExecutor = Executors.newScheduledThreadPool(1, threadFactory);
  this.pollerExecutor.scheduleAtFixedRate(new HeapPoller(), POLLER_INTERVAL, POLLER_INTERVAL, TimeUnit.MILLISECONDS);
  
  if (this.cache.getLoggerI18n().fineEnabled()) {
    this.cache.getLoggerI18n().fine("Started GemfireHeapPoller to poll the heap every " + POLLER_INTERVAL + " milliseconds");
  }
}
 
Example #9
Source File: FakeExecutor.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public ScheduledFuture<?> scheduleAtFixedRate(
    Runnable command, long initialDelay, long period, TimeUnit unit) {
  if (rejectSubmission) {
    throw new RejectedExecutionException();
  }

  AnnotatedRunnable runnable = new AnnotatedRunnable(command, initialDelay, period, unit, true);

  runnableList.add(runnable);

  FakeScheduledFuture<Unit> future =
      new FakeScheduledFuture<Unit>(Executors.callable(runnable, null));

  runnable.setFuture(future);
  outstandingTasks.put(future, future);

  return future;
}
 
Example #10
Source File: WebImageCache.java    From WeCenterMobile-Android with GNU General Public License v2.0 6 votes vote down vote up
public WebImageCache(Context context) {
    // Set up in-memory cache store
    memoryCache = new ConcurrentHashMap<String, SoftReference<Bitmap>>();

    // Set up disk cache store
    Context appContext = context.getApplicationContext();
    diskCachePath = appContext.getCacheDir().getAbsolutePath() + DISK_CACHE_PATH;

    File outFile = new File(diskCachePath);
    outFile.mkdirs();

    diskCacheEnabled = outFile.exists();

    // Set up threadpool for image fetching tasks
    writeThread = Executors.newSingleThreadExecutor();
}
 
Example #11
Source File: LocalJobRunner.java    From RDFS with Apache License 2.0 5 votes vote down vote up
public Job(JobID jobid, JobConf conf) throws IOException {
  this.doSequential =
    conf.getBoolean("mapred.localrunner.sequential", true);
  this.id = jobid;
  this.mapoutputFile = new MapOutputFile(jobid);
  this.mapoutputFile.setConf(conf);

  this.localFile = new JobConf(conf).getLocalPath(jobDir+id+".xml");
  this.localFs = FileSystem.getLocal(conf);
  persistConf(this.localFs, this.localFile, conf);

  this.job = new JobConf(localFile);
  profile = new JobProfile(job.getUser(), id, localFile.toString(), 
                           "http://localhost:8080/", job.getJobName());
  status = new JobStatus(id, 0.0f, 0.0f, JobStatus.RUNNING);

  jobs.put(id, this);

  numSlots = conf.getInt(LOCAL_RUNNER_SLOTS, DEFAULT_LOCAL_RUNNER_SLOTS);
  executor = Executors.newFixedThreadPool(numSlots);

  int handlerCount = numSlots;
  umbilicalServer =
    RPC.getServer(this, LOCALHOST, 0, handlerCount, false, conf);
  umbilicalServer.start();
  umbilicalPort = umbilicalServer.getListenerAddress().getPort();

  this.start();
}
 
Example #12
Source File: DeleteInterference.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute two tasks in a thread pool. One task loops on creating and
 * closing a WatchService, the other task deletes and re-creates the
 * directory.
 */
public static void main(String[] args) throws Exception {
    Path dir = Files.createTempDirectory("work");
    ExecutorService pool = Executors.newCachedThreadPool();
    try {
        Future<?> task1 = pool.submit(() -> openAndCloseWatcher(dir));
        Future<?> task2 = pool.submit(() -> deleteAndRecreateDirectory(dir));
        task1.get();
        task2.get();
    } finally {
        pool.shutdown();
        deleteFileTree(dir);
    }
}
 
Example #13
Source File: InMemoryRouter.java    From ambry with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an instance of InMemoryRouter.
 * @param verifiableProperties properties map that defines the behavior of this instance.
 * @param notificationSystem the notification system to use to notify creation/deletion of blobs.
 * @param clusterMap the cluster map for the cluster.
 */
public InMemoryRouter(VerifiableProperties verifiableProperties, NotificationSystem notificationSystem,
    ClusterMap clusterMap) {
  Objects.requireNonNull(clusterMap);
  setVerifiableProperties(verifiableProperties);
  operationPool = Executors.newFixedThreadPool(1);
  this.notificationSystem = notificationSystem;
  this.clusterMap = clusterMap;
}
 
Example #14
Source File: JsonFileMetricsReporter.java    From kylin with Apache License 2.0 5 votes vote down vote up
public JsonFileMetricsReporter(MetricRegistry registry, KylinConfig conf) {
    this.metricRegistry = registry;
    this.jsonWriter = new ObjectMapper()
            .registerModule(new MetricsModule(TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS, false))
            .writerWithDefaultPrettyPrinter();
    executorService = Executors.newSingleThreadScheduledExecutor();
    this.conf = conf;

    frequency = KylinConfig.getInstanceFromEnv().getMetricsReporterFrequency();
    pathString = KylinConfig.getInstanceFromEnv().getMetricsFileLocation();
    path = new Path(pathString);
}
 
Example #15
Source File: RCAFrameworkTest.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = IllegalArgumentException.class)
public void testInvalidDAGCyclicDependency() {
  Collection<Pipeline> pipelines = new ArrayList<>();
  pipelines.add(makePipeline("a", INPUT, "b"));
  pipelines.add(makePipeline("b", INPUT, "a"));
  pipelines.add(makePipeline(OUTPUT, "a", "b"));
  new RCAFramework(pipelines, Executors.newSingleThreadExecutor());
}
 
Example #16
Source File: VersionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void initServer() throws Exception {
    InetSocketAddress addr = new InetSocketAddress (0);
    s1 = HttpServer.create (addr, 0);
    HttpHandler h = new Handler();

    HttpContext c1 = s1.createContext("/", h);

    executor = Executors.newCachedThreadPool();
    s1.setExecutor(executor);
    s1.start();

    port = s1.getAddress().getPort();
    uri = new URI("http://127.0.0.1:" + Integer.toString(port) + "/foo");
    System.out.println("HTTP server port = " + port);
}
 
Example #17
Source File: ScannerSession.java    From datawave with Apache License 2.0 5 votes vote down vote up
public ScannerSession applyStats(ScanSessionStats stats) {
    if (null != stats) {
        Preconditions.checkArgument(this.stats == null);
        this.stats = stats;
        statsListener = Executors.newFixedThreadPool(1);
        addListener(new StatsListener(stats, statsListener), statsListener);
    }
    
    return this;
}
 
Example #18
Source File: ExampleAsyncEventListener.java    From geode-examples with Apache License 2.0 5 votes vote down vote up
@Override
public boolean processEvents(List<AsyncEvent> events) {
  final ExecutorService exService = Executors.newSingleThreadExecutor();
  for (AsyncEvent<Integer, String> event : events) {
    final String oldValue = event.getDeserializedValue();
    final String newValue = spellCheck(oldValue);
    exService.submit(() -> {
      Cache cache = (Cache) event.getRegion().getRegionService();
      Region<String, String> region = cache.getRegion(Example.OUTGOING_REGION_NAME);
      region.put(oldValue, newValue);
    });
  }
  return true;
}
 
Example #19
Source File: TestAvailable.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Http Server
 */
public void startHttpServer() throws IOException {
    httpServer = com.sun.net.httpserver.HttpServer.create(new InetSocketAddress(0), 0);

    // create HttpServer context
    HttpContext ctx = httpServer.createContext("/testAvailable/", new MyHandler());

    executorService = Executors.newCachedThreadPool();
    httpServer.setExecutor(executorService);
    httpServer.start();
}
 
Example #20
Source File: TinkerWorkerPool.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
public TinkerWorkerPool(final TinkerGraph graph, final TinkerMemory memory, final int numberOfWorkers) {
    this.numberOfWorkers = numberOfWorkers;
    this.workerPool = Executors.newFixedThreadPool(numberOfWorkers, THREAD_FACTORY_WORKER);
    this.completionService = new ExecutorCompletionService<>(this.workerPool);
    for (int i = 0; i < this.numberOfWorkers; i++) {
        this.workerMemoryPool.add(new TinkerWorkerMemory(memory));
        this.workerVertices.add(new ArrayList<>());
    }
    int batchSize = TinkerHelper.getVertices(graph).size() / this.numberOfWorkers;
    if (0 == batchSize)
        batchSize = 1;
    int counter = 0;
    int index = 0;

    List<Vertex> currentWorkerVertices = this.workerVertices.get(index);
    final Iterator<Vertex> iterator = graph.vertices();
    while (iterator.hasNext()) {
        final Vertex vertex = iterator.next();
        if (counter++ < batchSize || index == this.workerVertices.size() - 1) {
            currentWorkerVertices.add(vertex);
        } else {
            currentWorkerVertices = this.workerVertices.get(++index);
            currentWorkerVertices.add(vertex);
            counter = 1;
        }
    }
}
 
Example #21
Source File: SagaLibModule.java    From saga-lib with Apache License 2.0 5 votes vote down vote up
private void bindExecutor() {
    if (executor == null) {
        executor = Executors.newSingleThreadExecutor(
                r -> {
                    Thread thread = new Thread(r, "saga-lib");
                    thread.setDaemon(true);
                    return thread;
                }
        );
    }

    bind(Executor.class).toInstance(executor);
}
 
Example #22
Source File: RetryPost.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Http Server
 */
public void startHttpServer(boolean shouldRetry) throws IOException {
    httpServer = com.sun.net.httpserver.HttpServer.create(new InetSocketAddress(0), 0);
    httpHandler = new MyHandler(shouldRetry);

    HttpContext ctx = httpServer.createContext("/test/", httpHandler);

    executorService = Executors.newCachedThreadPool();
    httpServer.setExecutor(executorService);
    httpServer.start();
}
 
Example #23
Source File: AgentServiceIntegrationTest.java    From gocd with Apache License 2.0 5 votes vote down vote up
@Test
void whenMultipleThreadsUpdateAgentDetailsInDBTheAgentsCacheShouldAlwaysBeInSyncWithAgentsInDB() {
    final int numOfThreads = 30;

    ExecutorService execService = Executors.newFixedThreadPool(numOfThreads);
    Collection<Future<?>> futures = new ArrayList<>(numOfThreads);

    final Agent agent1 = AgentMother.localAgent();
    final Agent agent2 = AgentMother.localAgent();
    final Agent agent3 = AgentMother.localAgent();

    agentDao.saveOrUpdate(agent1);
    agentDao.saveOrUpdate(agent2);
    agentDao.saveOrUpdate(agent3);

    for (int i = 0; i < (numOfThreads / 2); i++) {
        futures.add(execService.submit(() -> bulkUpdateEnvironments(agent1)));
        futures.add(execService.submit(() -> bulkUpdateResources(agent1, agent2, agent3)));
        futures.add(execService.submit(() -> updateAgentHostnames(agent1)));
        futures.add(execService.submit(() -> agentService.getAgentByUUID(agent1.getUuid())));
        futures.add(execService.submit(() -> agentService.register(AgentMother.localAgent())));
    }

    joinFutures(futures, numOfThreads);

    assertThat(agentDao.fetchAgentFromDBByUUID(agent1.getUuid()), is(agentService.findAgent(agent1.getUuid()).getAgent()));
    assertThat(agentDao.fetchAgentFromDBByUUID(agent2.getUuid()), is(agentService.findAgent(agent2.getUuid()).getAgent()));
    assertThat(agentDao.fetchAgentFromDBByUUID(agent3.getUuid()), is(agentService.findAgent(agent3.getUuid()).getAgent()));
}
 
Example #24
Source File: ReadMoreResultsHandler.java    From bigtable-sql with Apache License 2.0 5 votes vote down vote up
public ReadMoreResultsHandler(ISession session)
{
   _session = session;

   _loadingGif = _session.getApplication().getResources().getIcon(SquirrelResources.IImageNames.LOADING_GIF);
   _lblLoading = new JLabel(_loadingGif);
   _lblLoading.setVisible(false);

   _executorService = Executors.newFixedThreadPool(1);

}
 
Example #25
Source File: Portmap.java    From hadoop with Apache License 2.0 5 votes vote down vote up
void start(final int idleTimeMilliSeconds, final SocketAddress tcpAddress,
    final SocketAddress udpAddress) {

  tcpServer = new ServerBootstrap(new NioServerSocketChannelFactory(
      Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
  tcpServer.setPipelineFactory(new ChannelPipelineFactory() {
    private final HashedWheelTimer timer = new HashedWheelTimer();
    private final IdleStateHandler idleStateHandler = new IdleStateHandler(
        timer, 0, 0, idleTimeMilliSeconds, TimeUnit.MILLISECONDS);

    @Override
    public ChannelPipeline getPipeline() throws Exception {
      return Channels.pipeline(RpcUtil.constructRpcFrameDecoder(),
          RpcUtil.STAGE_RPC_MESSAGE_PARSER, idleStateHandler, handler,
          RpcUtil.STAGE_RPC_TCP_RESPONSE);
    }
  });

  udpServer = new ConnectionlessBootstrap(new NioDatagramChannelFactory(
      Executors.newCachedThreadPool()));

  udpServer.setPipeline(Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER,
      handler, RpcUtil.STAGE_RPC_UDP_RESPONSE));

  tcpChannel = tcpServer.bind(tcpAddress);
  udpChannel = udpServer.bind(udpAddress);
  allChannels.add(tcpChannel);
  allChannels.add(udpChannel);

  LOG.info("Portmap server started at tcp://" + tcpChannel.getLocalAddress()
      + ", udp://" + udpChannel.getLocalAddress());
}
 
Example #26
Source File: TestGuiceBundle.java    From soabase with Apache License 2.0 5 votes vote down vote up
@Test
public void testIt() throws Exception
{
    Module module = new AbstractModule()
    {
        @Override
        protected void configure()
        {
            bind(MockGuiceInjected.class).asEagerSingleton();
        }
    };
    final MockApplication mockApplication = new MockApplication(module);

    Callable callable = new Callable()
    {
        @Override
        public Object call() throws Exception
        {
            String[] args = {"server"};
            mockApplication.run(args);
            return null;
        }
    };
    Future future = Executors.newSingleThreadExecutor().submit(callable);
    try
    {
        Assert.assertTrue(mockApplication.getStartedLatch().await(5, TimeUnit.SECONDS));
        URI uri = new URI("http://localhost:8080/test");
        String str = CharStreams.toString(new InputStreamReader(uri.toURL().openStream()));
        Assert.assertEquals("guice - hk2", str);
    }
    finally
    {
        future.cancel(true);
        ShutdownThread.getInstance().run();
    }
}
 
Example #27
Source File: B6369510.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Http Server
 */
public void startHttpServer() throws IOException {
    httpServer = com.sun.net.httpserver.HttpServer.create(new InetSocketAddress(0), 0);

    // create HttpServer context
    HttpContext ctx = httpServer.createContext("/test/", new MyHandler());

    executorService = Executors.newCachedThreadPool();
    httpServer.setExecutor(executorService);
    httpServer.start();
}
 
Example #28
Source File: WaitableExecutor.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates an executor that will use at most <var>nThreads</var> threads.
 * @param nThreads the number of threads, or zero for default count (which is number of core)
 */
public WaitableExecutor(int nThreads) {
    if (nThreads < 1) {
        nThreads = Runtime.getRuntime().availableProcessors();
    }

    mExecutorService = Executors.newFixedThreadPool(nThreads);
    mCompletionService = new ExecutorCompletionService<T>(mExecutorService);
}
 
Example #29
Source File: KafkaLocationManager.java    From nakadi with MIT License 5 votes vote down vote up
public KafkaLocationManager(final ZooKeeperHolder zkFactory, final KafkaSettings kafkaSettings) {
    this.zkFactory = zkFactory;
    this.kafkaProperties = new Properties();
    this.kafkaSettings = kafkaSettings;
    this.ipAddressChangeListeners = ConcurrentHashMap.newKeySet();
    this.updateBootstrapServers(true);
    this.scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
    this.scheduledExecutor.scheduleAtFixedRate(() -> updateBootstrapServersSafe(false), 1, 1, TimeUnit.MINUTES);
}
 
Example #30
Source File: TestHiveSplitSource.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testOutstandingSplitCount()
{
    HiveSplitSource hiveSplitSource = HiveSplitSource.allAtOnce(
            SESSION,
            "database",
            "table",
            10,
            10,
            DataSize.of(1, MEGABYTE),
            Integer.MAX_VALUE,
            new TestingHiveSplitLoader(),
            Executors.newFixedThreadPool(5),
            new CounterStat());

    // add 10 splits
    for (int i = 0; i < 10; i++) {
        hiveSplitSource.addToQueue(new TestSplit(i));
        assertEquals(hiveSplitSource.getBufferedInternalSplitCount(), i + 1);
    }

    // remove 1 split
    assertEquals(getSplits(hiveSplitSource, 1).size(), 1);
    assertEquals(hiveSplitSource.getBufferedInternalSplitCount(), 9);

    // remove 4 splits
    assertEquals(getSplits(hiveSplitSource, 4).size(), 4);
    assertEquals(hiveSplitSource.getBufferedInternalSplitCount(), 5);

    // try to remove 20 splits, and verify we only got 5
    assertEquals(getSplits(hiveSplitSource, 20).size(), 5);
    assertEquals(hiveSplitSource.getBufferedInternalSplitCount(), 0);
}