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 DataGapRouteReaderTest method testTransactionalOrderingWithGaps.
@SuppressWarnings("unchecked")
@Test
public void testTransactionalOrderingWithGaps() throws Exception {
nodeChannel.setBatchAlgorithm(DefaultBatchAlgorithm.NAME);
nodeChannel.setMaxDataToRoute(100);
when(parameterService.getInt(ParameterConstants.ROUTING_PEEK_AHEAD_WINDOW)).thenReturn(2);
List<DataGap> dataGaps = new ArrayList<DataGap>();
dataGaps.add(new DataGap(0, 3));
dataGaps.add(new DataGap(4, Long.MAX_VALUE));
List<Data> data = new ArrayList<Data>();
data.add(new Data(1, null, null, null, TABLE1, null, null, null, TRAN1, null));
data.add(new Data(2, null, null, null, TABLE1, null, null, null, TRAN1, null));
data.add(new Data(3, null, null, null, TABLE1, null, null, null, TRAN2, null));
data.add(new Data(4, null, null, null, TABLE1, null, null, null, TRAN1, null));
data.add(new Data(5, null, null, null, TABLE1, null, null, null, TRAN2, null));
when(sqlTemplate.queryForCursor((String) any(), (ISqlRowMapper<Data>) any(), (Object[]) any(), (int[]) any())).thenReturn(new ListReadCursor(data));
DataGapRouteReader dataGapRouteReader = buildReader(50, dataGaps);
dataGapRouteReader.execute();
BlockingQueue<Data> queue = dataGapRouteReader.getDataQueue();
assertEquals(6, queue.size());
Iterator<Data> iter = queue.iterator();
int index = 0;
long[] ids = { 1, 2, 4, 3, 5, -1 };
while (iter.hasNext()) {
Data d = iter.next();
assertEquals(ids[index], d.getDataId());
index++;
}
}
use of org.jumpmind.symmetric.model.DataGap in project symmetric-ds by JumpMind.
the class DataGapRouteReaderTest method testNonTransactionalChannelMaxDataToRoute.
@Test
public void testNonTransactionalChannelMaxDataToRoute() throws Exception {
nodeChannel.setBatchAlgorithm(NonTransactionalBatchAlgorithm.NAME);
nodeChannel.setMaxDataToRoute(3);
when(parameterService.getInt(ParameterConstants.ROUTING_PEEK_AHEAD_WINDOW)).thenReturn(2);
List<DataGap> dataGaps = new ArrayList<DataGap>();
dataGaps.add(new DataGap(0, Long.MAX_VALUE));
List<Data> data = new ArrayList<Data>();
data.add(new Data(1, null, null, null, TABLE1, null, null, null, TRAN1, null));
data.add(new Data(2, null, null, null, TABLE1, null, null, null, TRAN1, null));
data.add(new Data(3, null, null, null, TABLE1, null, null, null, TRAN2, null));
data.add(new Data(4, null, null, null, TABLE1, null, null, null, TRAN1, null));
data.add(new Data(5, null, null, null, TABLE1, null, null, null, TRAN2, null));
ISqlRowMapper<Data> mapper = any();
when(sqlTemplate.queryForCursor((String) any(), mapper, (Object[]) any(), (int[]) any())).thenReturn(new ListReadCursor(data));
DataGapRouteReader dataGapRouteReader = buildReader(50, dataGaps);
dataGapRouteReader.execute();
BlockingQueue<Data> queue = dataGapRouteReader.getDataQueue();
assertEquals(4, queue.size());
Iterator<Data> iter = queue.iterator();
int index = 0;
long[] ids = { 1, 2, 4, -1 };
while (iter.hasNext()) {
Data d = iter.next();
assertEquals(ids[index], d.getDataId());
index++;
}
}
use of org.jumpmind.symmetric.model.DataGap in project symmetric-ds by JumpMind.
the class DataGapRouteReaderTest method testDontPeekAheadWhenPeekAheadQueueIsAlreadyFull.
@Test
public void testDontPeekAheadWhenPeekAheadQueueIsAlreadyFull() throws Exception {
nodeChannel.setBatchAlgorithm(TransactionalBatchAlgorithm.NAME);
nodeChannel.setMaxDataToRoute(100);
when(parameterService.getInt(ParameterConstants.ROUTING_PEEK_AHEAD_WINDOW)).thenReturn(5);
List<DataGap> dataGaps = new ArrayList<DataGap>();
dataGaps.add(new DataGap(0, Long.MAX_VALUE));
List<Data> data = new ArrayList<Data>();
for (int i = 0; i < 100; i++) {
data.add(new Data(i, null, null, null, TABLE1, null, null, null, Integer.toString(i % 2 == 0 ? i : i - 1), null));
}
ISqlRowMapper<Data> mapper = any();
when(sqlTemplate.queryForCursor((String) any(), mapper, (Object[]) any(), (int[]) any())).thenReturn(new ListReadCursor(data));
DataGapRouteReader dataGapRouteReader = buildReader(100, dataGaps);
dataGapRouteReader.execute();
/*
* Test that the peek ahead queue size doesn't get bigger than twice the peek ahead size
*/
assertEquals(10, dataGapRouteReader.context.getMaxPeekAheadQueueSize());
assertEquals(21, dataGapRouteReader.context.getPeekAheadFillCount());
BlockingQueue<Data> queue = dataGapRouteReader.getDataQueue();
assertEquals(101, queue.size());
Iterator<Data> iter = queue.iterator();
int index = 0;
while (iter.hasNext()) {
Data d = iter.next();
assertEquals(index < 100 ? index : -1, d.getDataId());
index++;
}
}
Aggregations