@Override protected final void init() { LOGGER.debug("Initializing Writer Controller"); if (this.monitoringWriterThread != null) { this.monitoringWriterThread.start(); } }
@Override protected final void init() { if (LOG.isDebugEnabled()) { LOG.debug("Initializing Writer Controller"); } if (this.monitoringWriterThread != null) { this.monitoringWriterThread.start(); } }
@Test public void testTermination() throws Exception { final Configuration configuration = new Configuration(); final AbstractMonitoringWriter writer = new DumpWriter(configuration); final BlockingQueue<IMonitoringRecord> writerQueue = new LinkedBlockingQueue<IMonitoringRecord>(); writerQueue.add(new EmptyRecord()); final MonitoringWriterThread thread = new MonitoringWriterThread(writer, writerQueue); thread.start(); while (!writerQueue.isEmpty()) { Thread.yield(); } // thread terminates before the timeout has been reached, i.e., // it correctly writes out the EmptyRecord from the writerQueue thread.terminate(); thread.join(THREAD_STATE_CHANGE_TIMEOUT_IN_MS); Assert.assertThat(thread.getState(), CoreMatchers.is(State.TERMINATED)); }
@Test public void testBlocking() throws Exception { final Configuration configuration = new Configuration(); final AbstractMonitoringWriter writer = new DumpWriter(configuration); final BlockingQueue<IMonitoringRecord> writerQueue = new LinkedBlockingQueue<IMonitoringRecord>(); final MonitoringWriterThread thread = new MonitoringWriterThread(writer, writerQueue); thread.start(); Await.awaitThreadState(thread, State.WAITING, THREAD_STATE_CHANGE_TIMEOUT_IN_MS); thread.terminate(); thread.join(THREAD_STATE_CHANGE_TIMEOUT_IN_MS); Assert.assertThat(thread.getState(), CoreMatchers.is(State.TERMINATED)); } }