RevisionsCommand implements Command { private void collect(final RevisionsOptions options, Closer closer) throws IOException { VersionGarbageCollector gc = bootstrapVGC(options, closer); ExecutorService executor = Executors.newSingleThreadExecutor(); final Semaphore finished = new Semaphore(0); try { if (options.isContinuous()) { final AtomicBoolean running = new AtomicBoolean(true); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { System.out.println("Detected QUIT signal."); System.out.println("Stopping Revision GC..."); running.set(false); finished.acquireUninterruptibly(); System.out.println("Stopped Revision GC."); } })); while (running.get()) { long lastRun = System.currentTimeMillis(); collectOnce(gc, options, executor); waitWhile(running, lastRun + 5000); } } else { collectOnce(gc, options, executor); } } finally { finished.release(); executor.shutdownNow(); } }  @Override void execute(String... args);  }
@Test public void collect() throws Exception { ns.dispose(); String output = captureSystemOut(new RevisionsCmd("collect")); assertTrue(output.contains("starting gc collect")); }