RollingFileSystemSink implements MetricsSink, Closeable { @VisibleForTesting protected void updateFlushTime(Date now) { int millis = (int) (((now.getTime() - nextFlush.getTimeInMillis()) / rollIntervalMillis + 1) * rollIntervalMillis); nextFlush.add(Calendar.MILLISECOND, millis); } RollingFileSystemSink(); @VisibleForTesting protected  RollingFileSystemSink(long flushIntervalMillis,
      long flushOffsetIntervalMillis); @Override void init(SubsetConfiguration metrics2Properties); @Override void putMetrics(MetricsRecord record); @Override void flush(); @Override void close();  }
@Test public void testUpdateRollTime() { RollingFileSystemSink rfsSink = new RollingFileSystemSink(1000, 0); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MILLISECOND, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.DAY_OF_YEAR, 1); calendar.set(Calendar.YEAR, 2016); rfsSink.nextFlush = Calendar.getInstance(); rfsSink.nextFlush.setTime(calendar.getTime()); rfsSink.updateFlushTime(calendar.getTime()); assertEquals("The next roll time should have been 1 second in the future", calendar.getTimeInMillis() + 1000, rfsSink.nextFlush.getTimeInMillis()); rfsSink.nextFlush.setTime(calendar.getTime()); calendar.add(Calendar.MILLISECOND, 10); rfsSink.updateFlushTime(calendar.getTime()); assertEquals("The next roll time should have been 990 ms in the future", calendar.getTimeInMillis() + 990, rfsSink.nextFlush.getTimeInMillis()); rfsSink.nextFlush.setTime(calendar.getTime()); calendar.add(Calendar.SECOND, 2); calendar.add(Calendar.MILLISECOND, 10); rfsSink.updateFlushTime(calendar.getTime()); assertEquals("The next roll time should have been 990 ms in the future", calendar.getTimeInMillis() + 990, rfsSink.nextFlush.getTimeInMillis()); }