@Test
public void testCursorExhaustion() throws IOException, InterruptedException {

  // Windows semantics for rm different from unix
  Assume.assumeTrue(!OSUtils.isWindowsOS());
  File tmpdir = FileUtil.mktempdir();
  TailDirSource src = new TailDirSource(tmpdir, ".*");
  AccumulatorSink cnt = new AccumulatorSink("tailcount");
  DirectDriver drv = new DirectDriver(src, cnt);
  drv.start();
  // This blows up when there are ~2000 files
  genFiles(tmpdir, "foo", 200, 10);
  Clock.sleep(1000);
  assertEquals(2000, cnt.getCount());
  ReportEvent rpt1 = src.getMetrics();
  assertEquals(Long.valueOf(200),
      rpt1.getLongMetric(TailDirSource.A_FILESPRESENT));
  FileUtil.rmr(tmpdir); // This fails in windows because taildir keeps file
  // open
  tmpdir.mkdirs();
  Clock.sleep(1000);
  assertEquals(2000, cnt.getCount());
  ReportEvent rpt = src.getMetrics();
  assertEquals(rpt.getLongMetric(TailDirSource.A_FILESADDED),
      rpt.getLongMetric(TailDirSource.A_FILESDELETED));
  assertEquals(Long.valueOf(0),
      rpt.getLongMetric(TailDirSource.A_FILESPRESENT));
  drv.stop();
  FileUtil.rmr(tmpdir);
}