@Test public void testRepeatedCallsWithCommitOnSuccess() throws IOException { String trackerDirPath = SpoolDirectorySourceConfigurationConstants.DEFAULT_TRACKER_DIR; File trackerDir = new File(WORK_DIR, trackerDirPath); ReliableEventReader reader = new ReliableSpoolingZipFileEventReader.Builder() .spoolDirectory(WORK_DIR) .trackerDirPath(trackerDirPath) .build(); final int expectedLines = 1 + 1 + 1 + 1; int seenLines = 0; for (int i = 0; i < 10; i++) { List<Event> events = reader.readEvents(10); int numEvents = events.size(); if (numEvents > 0) { seenLines += numEvents; reader.commit(); // ensure that there are files in the trackerDir File[] files = trackerDir.listFiles(); Assert.assertNotNull(files); Assert.assertTrue( "Expected tracker files in tracker dir " + trackerDir.getAbsolutePath(), files.length > 0); } } Assert.assertEquals(expectedLines, seenLines); }
@Test public void testIgnorePattern() throws IOException { ReliableEventReader reader = new ReliableSpoolingZipFileEventReader.Builder() .spoolDirectory(WORK_DIR) .ignorePattern("^file2.zip$") .deletePolicy(DeletePolicy.IMMEDIATE.toString()) .build(); List<File> before = listFiles(WORK_DIR); Assert.assertEquals("Expected 5, not: " + before, 5, before.size()); List<Event> events; do { events = reader.readEvents(10); reader.commit(); } while (!events.isEmpty()); List<File> after = listFiles(WORK_DIR); Assert.assertEquals("Expected 1, not: " + after, 1, after.size()); Assert.assertEquals("file2.zip", after.get(0).getName()); List<File> trackerFiles = listFiles( new File(WORK_DIR, SpoolDirectorySourceConfigurationConstants.DEFAULT_TRACKER_DIR)); Assert.assertEquals("Expected 0, not: " + trackerFiles, 0, trackerFiles.size()); }
@Test public void testRepeatedCallsWithCommitAlways() throws IOException { ReliableEventReader reader = new ReliableSpoolingZipFileEventReader.Builder().spoolDirectory(WORK_DIR).build(); final int[] expectedLines = {1, 1, 1, 1}; int seenLines = 0; for (int i = 0; i < 4; i++) { List<Event> events = reader.readEvents(1); seenLines += events.size(); reader.commit(); Assert.assertEquals(expectedLines[i], events.size()); } }