use of org.jumpmind.symmetric.model.DataGap in project symmetric-ds by JumpMind.
the class DataGapDetectorTest method testGapExpireBusyChannel.
@Test
public void testGapExpireBusyChannel() throws Exception {
List<DataGap> dataGaps = new ArrayList<DataGap>();
dataGaps.add(new DataGap(3, 3));
dataGaps.add(new DataGap(5, 6));
dataGaps.add(new DataGap(7, 50000006));
when(symmetricDialect.supportsTransactionViews()).thenReturn(true);
when(symmetricDialect.getDatabaseTime()).thenReturn(System.currentTimeMillis() + 60001L);
when(dataService.countDataInRange(4, 7)).thenReturn(1);
detector.setLastBusyExpireRunTime(System.currentTimeMillis() - 61000);
runGapDetector(dataGaps, new ArrayList<Long>(), false);
verify(dataService).findDataGaps();
verify(dataService).countDataInRange(2, 4);
verify(dataService).countDataInRange(4, 7);
verify(dataService).deleteDataGap(sqlTransaction, new DataGap(3, 3));
verifyNoMoreInteractions(dataService);
}
use of org.jumpmind.symmetric.model.DataGap in project symmetric-ds by JumpMind.
the class DataGapDetectorTest method testGapInGapFull.
@Test
public void testGapInGapFull() throws Exception {
detector.setFullGapAnalysis(true);
when(contextService.is(ContextConstants.ROUTING_FULL_GAP_ANALYSIS)).thenReturn(true);
@SuppressWarnings("unchecked") ISqlRowMapper<Long> mapper = (ISqlRowMapper<Long>) Matchers.anyObject();
when(sqlTemplate.query(Matchers.anyString(), mapper, (Object[]) Matchers.anyVararg())).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);
verify(dataService).findDataGaps();
verify(dataService).deleteDataGap(sqlTransaction, new DataGap(5, 10));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(5, 5));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(7, 10));
verify(dataService).deleteDataGap(sqlTransaction, new DataGap(15, 20));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(15, 17));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(19, 20));
verify(dataService).deleteDataGap(sqlTransaction, new DataGap(21, 50000020));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(21, 22));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(24, 50000023));
verifyNoMoreInteractions(dataService);
}
use of org.jumpmind.symmetric.model.DataGap in project symmetric-ds by JumpMind.
the class DataGapDetectorTest method testGapExpireOracle.
@Test
public void testGapExpireOracle() throws Exception {
List<DataGap> dataGaps = new ArrayList<DataGap>();
dataGaps.add(new DataGap(3, 3));
dataGaps.add(new DataGap(5, 6));
dataGaps.add(new DataGap(7, 50000006));
when(symmetricDialect.supportsTransactionViews()).thenReturn(true);
when(symmetricDialect.getEarliestTransactionStartTime()).thenReturn(new Date(System.currentTimeMillis() + 60001L));
runGapDetector(dataGaps, new ArrayList<Long>(), true);
verify(dataService).findDataGaps();
verify(dataService).deleteDataGap(sqlTransaction, new DataGap(3, 3));
verify(dataService).deleteDataGap(sqlTransaction, new DataGap(5, 6));
verifyNoMoreInteractions(dataService);
}
use of org.jumpmind.symmetric.model.DataGap in project symmetric-ds by JumpMind.
the class DataGapDetectorTest method testNewGap.
@Test
public void testNewGap() 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(100L);
runGapDetector(dataGaps, dataIds, true);
verify(dataService).findDataGaps();
verify(dataService).deleteDataGap(sqlTransaction, new DataGap(4, 50000004));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(4, 99));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(101, 50000100));
verifyNoMoreInteractions(dataService);
}
use of org.jumpmind.symmetric.model.DataGap in project symmetric-ds by JumpMind.
the class DataGapDetectorTest method verifyInteractionsInMemory.
private void verifyInteractionsInMemory(List<DataGap> dataGaps, List<Long> dataIds, List<DataGap> outDataGaps) {
int index = 0;
int lastIndex = dataGaps.size() - 1;
boolean isLastGapInserted = false;
boolean isLastGapModified = false;
HashSet<DataGap> allGaps = new HashSet<DataGap>(outDataGaps);
for (DataGap dataGap : dataGaps) {
long lastDataId = -1;
for (Long dataId : dataIds) {
if (dataId >= dataGap.getStartId() && dataId <= dataGap.getEndId()) {
if (lastDataId == -1) {
checkDeleteGapInMemory(allGaps, dataGap);
if (dataId > dataGap.getStartId()) {
checkInsertGapInMemory(allGaps, new DataGap(dataGap.getStartId(), dataId - 1));
}
if (index == lastIndex) {
isLastGapModified = true;
}
} else if (dataId > lastDataId + 1) {
checkInsertGapInMemory(allGaps, 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;
checkInsertGapInMemory(allGaps, new DataGap(lastDataId + 1, lastDataId + 50000000));
} else {
checkInsertGapInMemory(allGaps, new DataGap(lastDataId + 1, dataGap.getEndId()));
}
}
index++;
}
if (!isLastGapInserted && isLastGapModified) {
DataGap lastGap = dataGaps.get(lastIndex);
if (lastGap.getEndId() - lastGap.getStartId() < 50000000 - 1) {
checkInsertGapInMemory(allGaps, new DataGap(lastGap.getEndId() + 1, lastGap.getEndId() + 50000000));
}
}
verify(dataService).deleteAllDataGaps(sqlTransaction);
verify(dataService).insertDataGap(sqlTransaction, new DataGap(outDataGaps.get(0).getStartId(), outDataGaps.get(outDataGaps.size() - 1).getEndId()));
verifyNoMoreInteractions(dataService);
}
Aggregations