### Question:
LockingFollowingJournalReader extends MultiFileJournalReader { @Override public synchronized void shutdown() throws JournalException { super.shutdown(); notifyAll(); } LockingFollowingJournalReader(Map<String, String> parameters,
                                         String role,
                                         JournalRecoveryLog recoveryLog,
                                         ServerInterface server); @Override synchronized void shutdown();  }### Answer:
@Test public void testSimpleNoLocking() { try { createJournalFileFromString(getSimpleIngestString()); createJournalFileFromString(getSimpleIngestString()); createJournalFileFromString(getSimpleIngestString()); JournalConsumer consumer = new JournalConsumer(parameters, role, server); startConsumerThread(consumer); waitWhileThreadRuns(WAIT_INTERVAL); consumer.shutdown(); assertEquals("Expected to see 3 ingests", 3, delegate .getCallCount()); assertEquals("Journal files not all gone", 0, howManyFilesInDirectory(journalDirectory)); assertEquals("Wrong number of archive files", 3, howManyFilesInDirectory(archiveDirectory)); } catch (Throwable e) { processException(e); } }
@Test public void testLockWhileProcessingAndResume() throws Exception { createJournalFileFromString(getSimpleIngestString()); createJournalFileFromString(getSimpleIngestString()); createJournalFileFromString(getSimpleIngestString()); delegate.setIngestOperation(new LockAfterSecondIngest()); JournalConsumer consumer = new JournalConsumer(parameters, role, server); startConsumerThread(consumer); waitForLockAccepted(); waitWhileThreadRuns(WAIT_INTERVAL); assertEquals("We should stop after the second ingest", 2, delegate .getCallCount()); assertEquals("One Journal file should not be processed", 1, howManyFilesInDirectory(journalDirectory)); assertEquals("Only two Journal files should be processed", 2, howManyFilesInDirectory(archiveDirectory)); int lockMessageIndex = assertLockMessageInLog(); removeLockRequest(); waitForLockReleased(); waitWhileThreadRuns(WAIT_INTERVAL); consumer.shutdown(); assertEquals("Expected to see 3 ingests", 3, delegate .getCallCount()); assertEquals("Journal files not all gone", 0, howManyFilesInDirectory(journalDirectory)); assertEquals("Wrong number of archive files", 3, howManyFilesInDirectory(archiveDirectory)); assertUnlockMessageInLog(lockMessageIndex); }