@Override public void waitForTermination(final long timeoutInMs) throws InterruptedException { this.writerController.waitForTermination(timeoutInMs); }
@Override public void waitForTermination(final long timeoutInMs) throws InterruptedException { this.writerController.waitForTermination(timeoutInMs); }
@Test @SuppressFBWarnings("SIC_INNER_SHOULD_BE_STATIC_ANON") // @SuppressFBWarnings("SIC") public void testBlockOnFailedInsertBehavior() throws Exception { final Configuration configuration = new Configuration(); configuration.setProperty(ConfigurationKeys.WRITER_CLASSNAME, DumpWriter.class.getName()); configuration.setProperty(WriterController.PREFIX + WriterController.RECORD_QUEUE_FQN, MpscArrayQueue.class.getName()); configuration.setProperty(WriterController.PREFIX + WriterController.RECORD_QUEUE_SIZE, "1"); configuration.setProperty(WriterController.PREFIX + WriterController.RECORD_QUEUE_INSERT_BEHAVIOR, "1"); final WriterController writerController = new WriterController(configuration); final Thread thread = new Thread(new Runnable() { @Override public void run() { // the first element fits into the queue writerController.newMonitoringRecord(new EmptyRecord()); // the second element exceeds the queue's capacity and triggers // the blocking wait writerController.newMonitoringRecord(new EmptyRecord()); } }); thread.start(); Await.awaitThreadState(thread, State.WAITING, THREAD_STATE_CHANGE_TIMEOUT_IN_MS); writerController.init(); // starts the queue consumer Await.awaitThreadState(thread, State.TERMINATED, THREAD_STATE_CHANGE_TIMEOUT_IN_MS); writerController.cleanup(); // triggers the termination of the queue // consumer writerController.waitForTermination(CONTROLLER_TIMEOUT_IN_MS); Assert.assertThat(writerController.getStateOfMonitoringWriterThread(), CoreMatchers.is(State.TERMINATED)); }