use of org.jumpmind.symmetric.model.DataGap in project symmetric-ds by JumpMind.
the class DataGapDetectorTest method testTwoNewGaps.
@Test
public void testTwoNewGaps() throws Exception {
List<DataGap> dataGaps = new ArrayList<DataGap>();
dataGaps.add(new DataGap(3, 3));
dataGaps.add(new DataGap(4, 50000004));
List<Long> dataIds = new ArrayList<Long>();
dataIds.add(5L);
dataIds.add(8L);
runGapDetector(dataGaps, dataIds, true);
verify(dataService).findDataGaps();
verify(dataService).deleteDataGap(sqlTransaction, new DataGap(4, 50000004));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(4, 4));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(6, 7));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(9, 50000008));
verifyNoMoreInteractions(dataService);
}
use of org.jumpmind.symmetric.model.DataGap in project symmetric-ds by JumpMind.
the class DataGapDetectorTest method testTwoNewGapsFull.
@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);
@SuppressWarnings("unchecked") ISqlRowMapper<Long> mapper = (ISqlRowMapper<Long>) Matchers.anyObject();
String sql = Matchers.anyString();
when(sqlTemplate.query(sql, mapper, Matchers.eq(4L), Matchers.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);
verify(dataService).findDataGaps();
verify(dataService).deleteDataGap(sqlTransaction, new DataGap(4, 50000004));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(4, 4));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(6, 7));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(9, 50000008));
verifyNoMoreInteractions(dataService);
}
use of org.jumpmind.symmetric.model.DataGap in project symmetric-ds by JumpMind.
the class DataGapDetectorTest method testGapsOverlapDetection.
@Test
public void testGapsOverlapDetection() throws Exception {
List<Long> dataIds = new ArrayList<Long>();
dataIds.add(31837983L);
dataIds.add(31837989L);
List<DataGap> dataGaps = new ArrayList<DataGap>();
dataGaps.add(new DataGap(31837983, 81837982));
dataGaps.add(new DataGap(31837983, 81837983));
runGapDetector(dataGaps, dataIds, true);
verify(dataService).findDataGaps();
verify(dataService).deleteDataGap(sqlTransaction, new DataGap(31837983, 81837982));
verify(dataService).deleteDataGap(sqlTransaction, new DataGap(31837983, 81837983));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(31837984, 31837988));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(31837990, 81837989));
verifyNoMoreInteractions(dataService);
}
use of org.jumpmind.symmetric.model.DataGap in project symmetric-ds by JumpMind.
the class DataGapDetectorTest method verifyInteractions.
private void verifyInteractions(List<DataGap> dataGaps, List<Long> dataIds, boolean verifyDeletes) {
int index = 0;
int lastIndex = dataGaps.size() - 1;
boolean isLastGapInserted = false;
boolean isLastGapModified = false;
for (DataGap dataGap : dataGaps) {
long lastDataId = -1;
for (Long dataId : dataIds) {
if (dataId >= dataGap.getStartId() && dataId <= dataGap.getEndId()) {
if (lastDataId == -1) {
if (verifyDeletes) {
verify(dataService).deleteDataGap(sqlTransaction, dataGap);
}
if (dataId > dataGap.getStartId()) {
verify(dataService).insertDataGap(sqlTransaction, new DataGap(dataGap.getStartId(), dataId - 1));
}
if (index == lastIndex) {
isLastGapModified = true;
}
} else if (dataId > lastDataId + 1) {
verify(dataService).insertDataGap(sqlTransaction, new DataGap(lastDataId + 1, dataId - 1));
}
lastDataId = dataId;
} else if (dataId > dataGap.getEndId()) {
break;
}
}
if (lastDataId >= dataGap.getStartId() && lastDataId < dataGap.getEndId()) {
if (index == lastIndex) {
isLastGapInserted = true;
verify(dataService).insertDataGap(sqlTransaction, new DataGap(lastDataId + 1, lastDataId + 50000000));
} else {
verify(dataService).insertDataGap(sqlTransaction, new DataGap(lastDataId + 1, dataGap.getEndId()));
}
}
index++;
}
if (!isLastGapInserted && isLastGapModified) {
DataGap lastGap = dataGaps.get(lastIndex);
if (lastGap.getEndId() - lastGap.getStartId() < 50000000 - 1) {
verify(dataService).insertDataGap(sqlTransaction, new DataGap(lastGap.getEndId() + 1, lastGap.getEndId() + 50000000));
}
}
verifyNoMoreInteractions(dataService);
}
use of org.jumpmind.symmetric.model.DataGap in project symmetric-ds by JumpMind.
the class DataGapDetectorTest method getRandomDataGaps.
private List<DataGap> getRandomDataGaps() {
List<DataGap> dataGaps = new ArrayList<DataGap>();
long startId = 0, endId = 0;
for (int i = 0; i < rand.nextInt(1, 10); i++) {
startId = rand.nextLong(endId + 1, endId + 10);
endId = rand.nextLong(startId, startId + 10);
dataGaps.add(new DataGap(startId, endId));
}
return dataGaps;
}
Aggregations