ControlServer implements TailerListener { @Override public void handle(String command) { try { ControlCommand controlCommand = ControlCommand.valueOf(command.trim().toUpperCase()); switch (controlCommand) { case SHUTDOWN: logger.log(Level.INFO, "Control file: Received shutdown command. Shutting down."); eventBus.post(controlCommand); controlFileTailer.stop(); break; case RELOAD: logger.log(Level.INFO, "Control file: Received reload command. Reloading config ..."); eventBus.post(controlCommand); break; default: throw new RuntimeException("This command should have been handled."); } } catch (Exception e) { logger.log(Level.WARNING, "Control file: Ignoring unknown command: " + command, e); } } ControlServer(); @Deprecated  ControlServer(File ctrlFile, Tailer ctrTailer, LocalEventBus eventBus); void enterLoop(); @Override void fileNotFound(); @Override void handle(String command); @Override void handle(Exception e); @Override void init(Tailer tailer); @Override void fileRotated();  }
@Test public void testHandleShutdown() { ctrlServer.handle("SHUTDOWN"); verifyZeroInteractions(ctrlFile); verify(eventBus).post(ControlCommand.SHUTDOWN); verifyNoMoreInteractions(eventBus); verify(ctrlFileTailer).stop(); verifyNoMoreInteractions(ctrlFileTailer); }
@Test public void testHandleReload() { ctrlServer.handle("RELOAD"); verifyZeroInteractions(ctrlFile); verifyZeroInteractions(ctrlFileTailer); verify(eventBus).post(ControlCommand.RELOAD); verifyNoMoreInteractions(eventBus); }
@Test public void testHandleUnknownCommand() { ctrlServer.handle("UnknownCommand"); verifyZeroInteractions(ctrlFile); verifyZeroInteractions(ctrlFileTailer); verifyZeroInteractions(eventBus); }
@Test(expected = RuntimeException.class) public void testHandle() { ctrlServer.handle(new Exception()); }