TimestampBasedStreamSource implements StreamSource, DbHostInfo { static String findLastFileStartLeTimestamp(long targetTimestamp, List<String> binlogFiles, ExtractValidBeginTimestampFunction beginTimestampFunction) { int max = binlogFiles.size() - 1; if (beginTimestampFunction.extract(binlogFiles.get(max)) <= targetTimestamp) { return binlogFiles.get(max); } if (max > 0 && targetTimestamp + TimeUnit.HOURS.toSeconds(3) >= System.currentTimeMillis()) { max--; if (beginTimestampFunction.extract(binlogFiles.get(max)) <= targetTimestamp) { return binlogFiles.get(max); } } int min = 0; if (max == 0 || !(beginTimestampFunction.extract(binlogFiles.get(min)) <= targetTimestamp)) { return null; } int mid; while ((mid = (min + max) / 2) > min) { if (beginTimestampFunction.extract(binlogFiles.get(mid)) <= targetTimestamp) { min = mid; } else { max = mid; } } return binlogFiles.get(mid); }  @Override void openStream(BinlogPosition binlogPos); @Override ValidBinlogOutput readValidInfo(); @Override String getHostUrl(); @Override String getUserName(); @Override String getPassword(); @Override void release(); @Override boolean isOpen(); TransportConfig getTransportConfig(); void setTransportConfig(TransportConfig transportConfig); int getServerId(); void setServerId(int serverId); int getMaxMaxPacketSize(); void setMaxMaxPacketSize(int maxMaxPacketSize); TableFilter getTableFilter(); void setTableFilter(TableFilter tableFilter); DbHostInfoSupplier getDbHostInfoSupplier(); void setDbHostInfoSupplier(DbHostInfoSupplier dbHostInfoSupplier); int getAdvanceSecondsToAvoidMistake(); void setAdvanceSecondsToAvoidMistake(int advanceSecondsToAvoidMistake);  }
@Test public void testFindLastFileStartLeTimestampGtLastFile() { Assert.assertEquals("mysql-bin.005596", findLastFileStartLeTimestamp(151L, binlogFiles, extractValidBeginTimestampFunction)); }
@Test public void testFindLastFileStartLeTimestampEqLastFile() { Assert.assertEquals("mysql-bin.005596", findLastFileStartLeTimestamp(150L, binlogFiles, extractValidBeginTimestampFunction)); }
@Test public void testFindLastFileStartLeTimestampEqFirstFile() { Assert.assertEquals("mysql-bin.005591", findLastFileStartLeTimestamp(100L, binlogFiles, extractValidBeginTimestampFunction)); }
@Test public void testFindLastFileStartLeTimestampLtFirstFile() { Assert.assertEquals(null, findLastFileStartLeTimestamp(99L, binlogFiles, extractValidBeginTimestampFunction)); }
@Test public void testFindLastFileStartLeTimestampEqSecondFile() { Assert.assertEquals("mysql-bin.005592", findLastFileStartLeTimestamp(110L, binlogFiles, extractValidBeginTimestampFunction)); }
@Test public void testFindLastFileStartLeTimestampGtFirstFileLtSecondFile() { Assert.assertEquals("mysql-bin.005591", findLastFileStartLeTimestamp(105L, binlogFiles, extractValidBeginTimestampFunction)); }