DataGapDetector { public void setFullGapAnalysis(boolean isFullGapAnalysis) { } DataGapDetector();  DataGapDetector(IDataService dataService, IParameterService parameterService,
            ISymmetricDialect symmetricDialect, IRouterService routerService, IStatisticManager statisticManager, INodeService nodeService); void beforeRouting(); void afterRouting(); List<DataGap> getDataGaps(); DataGap getLastDataGap(); void addDataIds(List<Long> dataIds); void setIsAllDataRead(boolean isAllDataRead); void setFullGapAnalysis(boolean isFullGapAnalysis); void setFullGapAnalysis(ISqlTransaction sqlTransaction, boolean b);  }
@Test public void testNewGapFull() throws Exception { detector.setFullGapAnalysis(true); when(contextService.is(ContextConstants.ROUTING_FULL_GAP_ANALYSIS)).thenReturn(true); List<Long> dataIds = new ArrayList<Long>(); dataIds.add(100L); String sql = ArgumentMatchers.anyString(); @SuppressWarnings("unchecked") ISqlRowMapper<Long> mapper = (ISqlRowMapper<Long>) ArgumentMatchers.any(); when(sqlTemplate.query(sql, mapper, ArgumentMatchers.eq(4L), ArgumentMatchers.eq(50000004L))).thenReturn(dataIds); List<DataGap> dataGaps = new ArrayList<DataGap>(); dataGaps.add(new DataGap(3, 3)); dataGaps.add(new DataGap(4, 50000004)); runGapDetector(dataGaps, new ArrayList<Long>(), true); Set<DataGap> deleted = new HashSet<DataGap>(); deleted.add(new DataGap(4, 50000004)); Set<DataGap> inserted = new HashSet<DataGap>(); inserted.add(new DataGap(4, 99)); inserted.add(new DataGap(101, 50000100)); verify(dataService).findDataGaps(); verify(dataService).deleteDataGaps(sqlTransaction, deleted); verify(dataService).insertDataGaps(sqlTransaction, inserted); verifyNoMoreInteractions(dataService); }
@Test public void testTwoNewGapsFull() throws Exception { detector.setFullGapAnalysis(true); when(contextService.is(ContextConstants.ROUTING_FULL_GAP_ANALYSIS)).thenReturn(true); List<Long> dataIds = new ArrayList<Long>(); dataIds.add(5L); dataIds.add(8L); String sql = ArgumentMatchers.anyString(); @SuppressWarnings("unchecked") ISqlRowMapper<Long> mapper = (ISqlRowMapper<Long>) ArgumentMatchers.any(); when(sqlTemplate.query(sql, mapper, ArgumentMatchers.eq(4L), ArgumentMatchers.eq(50000004L))).thenReturn(dataIds); List<DataGap> dataGaps = new ArrayList<DataGap>(); dataGaps.add(new DataGap(3, 3)); dataGaps.add(new DataGap(4, 50000004)); runGapDetector(dataGaps, new ArrayList<Long>(), true); Set<DataGap> deleted = new HashSet<DataGap>(); deleted.add(new DataGap(4, 50000004)); Set<DataGap> inserted = new HashSet<DataGap>(); inserted.add(new DataGap(4, 4)); inserted.add(new DataGap(6, 7)); inserted.add(new DataGap(9, 50000008)); verify(dataService).findDataGaps(); verify(dataService).deleteDataGaps(sqlTransaction, deleted); verify(dataService).insertDataGaps(sqlTransaction, inserted); verifyNoMoreInteractions(dataService); }
@Test public void testGapInGapFull() throws Exception { detector.setFullGapAnalysis(true); when(contextService.is(ContextConstants.ROUTING_FULL_GAP_ANALYSIS)).thenReturn(true); String sql = ArgumentMatchers.anyString(); @SuppressWarnings("unchecked") ISqlRowMapper<Long> mapper = (ISqlRowMapper<Long>) ArgumentMatchers.any(); when(sqlTemplate.query(sql, mapper, (Object[])ArgumentMatchers.any())).thenAnswer(new Answer<List<Long>>() { public List<Long> answer(InvocationOnMock invocation) { List<Long> dataIds = new ArrayList<Long>(); long startId = (Long) invocation.getArguments()[2]; long endId = (Long) invocation.getArguments()[3]; if (startId == 5 && endId == 10) { dataIds.add(6L); } else if (startId == 15 && endId == 20) { dataIds.add(18L); } else if (startId == 21 && endId == 50000020) { dataIds.add(23L); } return dataIds; } }); List<DataGap> dataGaps = new ArrayList<DataGap>(); dataGaps.add(new DataGap(3, 3)); dataGaps.add(new DataGap(5, 10)); dataGaps.add(new DataGap(15, 20)); dataGaps.add(new DataGap(21, 50000020)); runGapDetector(dataGaps, new ArrayList<Long>(), true); Set<DataGap> deleted = new HashSet<DataGap>(); deleted.add(new DataGap(5, 10)); deleted.add(new DataGap(15, 20)); deleted.add(new DataGap(21, 50000020)); Set<DataGap> inserted = new HashSet<DataGap>(); inserted.add(new DataGap(5, 5)); inserted.add(new DataGap(7, 10)); inserted.add(new DataGap(15, 17)); inserted.add(new DataGap(19, 20)); inserted.add(new DataGap(21, 22)); inserted.add(new DataGap(24, 50000023)); verify(dataService).findDataGaps(); verify(dataService).deleteDataGaps(sqlTransaction, deleted); verify(dataService).insertDataGaps(sqlTransaction, inserted); verifyNoMoreInteractions(dataService); }
@Test public void testGapsBeforeAndAfterFull() throws Exception { detector.setFullGapAnalysis(true); when(contextService.is(ContextConstants.ROUTING_FULL_GAP_ANALYSIS)).thenReturn(true); List<Long> dataIds = new ArrayList<Long>(); dataIds.add(843L); dataIds.add(844L); String sql = ArgumentMatchers.anyString(); @SuppressWarnings("unchecked") ISqlRowMapper<Long> mapper = (ISqlRowMapper<Long>) ArgumentMatchers.any(); when(sqlTemplate.query(sql, mapper, ArgumentMatchers.eq(841L), ArgumentMatchers.eq(50000840L))).thenReturn(dataIds); List<DataGap> dataGaps1 = new ArrayList<DataGap>(); dataGaps1.add(new DataGap(841, 50000840)); List<DataGap> dataGaps2 = new ArrayList<DataGap>(); dataGaps2.add(new DataGap(841, 842)); dataGaps2.add(new DataGap(845, 50000844)); dataIds = new ArrayList<Long>(); dataIds.add(845L); runGapDetector(dataGaps1, dataGaps2, dataIds, true); Set<DataGap> deleted = new HashSet<DataGap>(); deleted.add(new DataGap(841, 50000840)); Set<DataGap> deleted2 = new HashSet<DataGap>(); deleted2.add(new DataGap(845, 50000844)); Set<DataGap> inserted = new HashSet<DataGap>(); inserted.add(new DataGap(841, 842)); inserted.add(new DataGap(845, 50000844)); Set<DataGap> inserted2 = new HashSet<DataGap>(); inserted2.add(new DataGap(846, 50000845)); verify(dataService).findDataGaps(); verify(dataService).deleteDataGaps(sqlTransaction, deleted); verify(dataService).insertDataGaps(sqlTransaction, inserted); verify(dataService).deleteDataGaps(sqlTransaction, deleted2); verify(dataService).insertDataGaps(sqlTransaction, inserted2); verifyNoMoreInteractions(dataService); }
@Test public void testGapsOverlapThenDataFull() throws Exception { detector.setFullGapAnalysis(true); when(contextService.is(ContextConstants.ROUTING_FULL_GAP_ANALYSIS)).thenReturn(true); List<Long> dataIds = new ArrayList<Long>(); dataIds.add(30953883L); String sql = ArgumentMatchers.anyString(); @SuppressWarnings("unchecked") ISqlRowMapper<Long> mapper = (ISqlRowMapper<Long>) ArgumentMatchers.any(); when(sqlTemplate.query(sql, mapper, ArgumentMatchers.eq(30953883L), ArgumentMatchers.eq(80953883L))).thenReturn(dataIds); List<DataGap> dataGaps1 = new ArrayList<DataGap>(); dataGaps1.add(new DataGap(30953883, 80953883)); dataGaps1.add(new DataGap(30953884, 80953883)); List<DataGap> dataGaps2 = new ArrayList<DataGap>(); dataGaps2.add(new DataGap(30953884, 80953883)); dataIds = new ArrayList<Long>(); dataIds.add(30953883L); runGapDetector(dataGaps1, dataGaps2, dataIds, true); Set<DataGap> deleted = new HashSet<DataGap>(); deleted.add(new DataGap(30953883, 80953883)); Set<DataGap> inserted = new HashSet<DataGap>(); inserted.add(new DataGap(30953884, 80953883)); verify(dataService).findDataGaps(); verify(dataService).deleteDataGap(sqlTransaction, new DataGap(30953884, 80953883)); verify(dataService).deleteDataGaps(sqlTransaction, deleted); verify(dataService).insertDataGaps(sqlTransaction, inserted); verifyNoMoreInteractions(dataService); }