DailyRollingLog implements RollingLog { @Override public long getSize() { long size = 0; for (final Log log : logs) { size += log.getSize(); } return size; } DailyRollingLog(final String name, final String path, final Log liveLog, final List<Log> pastLogs);  DailyRollingLog(final String name, final String path, final Log liveLog, final Log... pastLogs); @Override String getName(); @Override String getPath(); @Override long getSize(); @Override long getLastModified(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString(); @Override Log[] getParts(); @Override LogPointer getGlobalPointer(final String partPath, final LogPointer partPointer); @Override SizeMetric getSizeMetric();  }
@Test public void testReadingOnlyLive() throws IOException { final String log1Text = "live"; final ByteArrayLog blog = new ByteArrayLog(log1Text.getBytes()); final DailyRollingLog log = new DailyRollingLog("abc", "abc.txt", blog); Assert.assertEquals(log1Text.length(), log.getSize()); final DailyRollingLogAccess logAccess = new DailyRollingLogAccess(blog, log); final LineInputStream lis = new LineInputStream(logAccess, logAccess.getInputStream(null), "UTF-8"); Assert.assertEquals(true, lis.getPointer().isSOF()); Assert.assertEquals(false, lis.getPointer().isEOF()); Assert.assertEquals(log1Text, lis.readNextLine()); Assert.assertEquals(false, lis.getPointer().isSOF()); Assert.assertEquals(true, lis.getPointer().isEOF()); Assert.assertNull(lis.readNextLine()); lis.close(); }
@Test public void testRollingReading() throws IOException { final String liveText = "live"; final String pastText = "old-start\nold-next\n"; final DailyRollingLog log = new DailyRollingLog("abc", "abc.txt", new ByteArrayLog(liveText.getBytes()), new ByteArrayLog(pastText.getBytes())); Assert.assertEquals(liveText.length() + pastText.length(), log.getSize()); final DailyRollingLogAccess logAccess = new DailyRollingLogAccess(new ByteArrayLog(new byte[0]), log); LineInputStream lis = new LineInputStream(logAccess, logAccess.getInputStream(null), "UTF-8"); Assert.assertEquals(true, lis.getPointer().isSOF()); Assert.assertEquals(false, lis.getPointer().isEOF()); Assert.assertEquals("old-start", lis.readNextLine()); Assert.assertEquals(false, lis.getPointer().isSOF()); Assert.assertEquals(false, lis.getPointer().isEOF()); final LogPointer rollingMarkOldMiddle = lis.getPointer(); Assert.assertEquals("old-next", lis.readNextLine()); Assert.assertEquals(false, lis.getPointer().isSOF()); Assert.assertEquals(false, lis.getPointer().isEOF()); final LogPointer rollingMarkLiveStart = lis.getPointer(); Assert.assertEquals("live", lis.readNextLine()); Assert.assertEquals(false, lis.getPointer().isSOF()); Assert.assertEquals(true, lis.getPointer().isEOF()); Assert.assertNull(lis.readNextLine()); lis.close(); Assert.assertEquals(rollingMarkOldMiddle, logAccess.getFromJSON(rollingMarkOldMiddle.getJson())); lis = new LineInputStream(logAccess, logAccess.getInputStream(rollingMarkOldMiddle), "UTF-8"); Assert.assertEquals("old-next", lis.readNextLine()); Assert.assertEquals("live", lis.readNextLine()); Assert.assertNull(lis.readNextLine()); lis.close(); Assert.assertEquals(rollingMarkLiveStart, logAccess.getFromJSON(rollingMarkLiveStart.getJson())); lis = new LineInputStream(logAccess, logAccess.getInputStream(rollingMarkLiveStart), "UTF-8"); Assert.assertEquals("live", lis.readNextLine()); Assert.assertNull(lis.readNextLine()); lis.close(); }