use of org.jumpmind.symmetric.model.DataGap in project symmetric-ds by JumpMind.
the class DataGapRouteReaderTest method testTransactionalChannelTwoTransactionsRouted.
@Test
public void testTransactionalChannelTwoTransactionsRouted() throws Exception {
nodeChannel.setBatchAlgorithm(TransactionalBatchAlgorithm.NAME);
nodeChannel.setMaxDataToRoute(100);
when(parameterService.getInt(ParameterConstants.ROUTING_PEEK_AHEAD_WINDOW)).thenReturn(100);
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, TRAN2, null));
data.add(new Data(5, null, null, null, TABLE1, null, null, null, TRAN1, null));
data.add(new Data(6, null, null, null, TABLE1, null, null, null, TRAN1, 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(7, queue.size());
Iterator<Data> iter = queue.iterator();
int index = 0;
long[] ids = { 1, 2, 5, 6, 3, 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 testTransactionalChannelReachMaxPeekAheadSizeThreshold.
@Test
public void testTransactionalChannelReachMaxPeekAheadSizeThreshold() throws Exception {
nodeChannel.setBatchAlgorithm(TransactionalBatchAlgorithm.NAME);
nodeChannel.setMaxDataToRoute(100);
when(parameterService.getInt(ParameterConstants.ROUTING_PEEK_AHEAD_WINDOW)).thenReturn(100);
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));
data.add(new Data(6, null, null, null, TABLE1, null, null, null, TRAN1, null));
data.add(new Data(7, 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(0, dataGaps);
dataGapRouteReader.execute();
BlockingQueue<Data> queue = dataGapRouteReader.getDataQueue();
assertEquals(5, queue.size());
Iterator<Data> iter = queue.iterator();
int index = 0;
long[] ids = { 1, 2, 4, 6, -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 DataGapDetectorTest method testGapBusyExpireRunMultiple.
@Test
public void testGapBusyExpireRunMultiple() throws Exception {
List<DataGap> dataGaps = new ArrayList<DataGap>();
when(symmetricDialect.supportsTransactionViews()).thenReturn(true);
when(symmetricDialect.getDatabaseTime()).thenReturn(System.currentTimeMillis() + 60001L);
when(parameterService.getLong(ParameterConstants.ROUTING_STALE_GAP_BUSY_EXPIRE_TIME)).thenReturn(61000L);
runGapDetector(dataGaps, new ArrayList<Long>(), false);
Assert.assertTrue(detector.getLastBusyExpireRunTime() != 0);
verify(dataService).findDataGaps();
verifyNoMoreInteractions(dataService);
runGapDetector(dataGaps, new ArrayList<Long>(), false);
Assert.assertTrue(detector.getLastBusyExpireRunTime() != 0);
verifyNoMoreInteractions(dataService);
runGapDetector(dataGaps, new ArrayList<Long>(), true);
Assert.assertTrue(detector.getLastBusyExpireRunTime() == 0);
verifyNoMoreInteractions(dataService);
dataGaps.add(new DataGap(3, 3));
dataGaps.add(new DataGap(5, 6));
dataGaps.add(new DataGap(7, 50000006));
runGapDetector(dataGaps, new ArrayList<Long>(), false);
Assert.assertTrue(detector.getLastBusyExpireRunTime() != 0);
verifyNoMoreInteractions(dataService);
detector.setLastBusyExpireRunTime(System.currentTimeMillis() - 61000);
runGapDetector(dataGaps, new ArrayList<Long>(), false);
verify(dataService).countDataInRange(2, 4);
verify(dataService).countDataInRange(4, 7);
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 testGapsOverlapAfterLastGap.
@Test
public void testGapsOverlapAfterLastGap() throws Exception {
List<Long> dataIds = new ArrayList<Long>();
dataIds.add(30953883L);
List<DataGap> dataGaps = new ArrayList<DataGap>();
dataGaps.add(new DataGap(30953883, 80953883));
dataGaps.add(new DataGap(30953884, 80953883));
dataGaps.add(new DataGap(30953885, 81953883));
dataGaps.add(new DataGap(30953885, 30953885));
runGapDetector(dataGaps, dataIds, true);
verify(dataService).findDataGaps();
verify(dataService).deleteDataGap(sqlTransaction, new DataGap(30953884, 80953883));
verify(dataService).deleteDataGap(sqlTransaction, new DataGap(30953885, 81953883));
verify(dataService).deleteDataGap(sqlTransaction, new DataGap(30953885, 30953885));
verify(dataService).deleteDataGap(sqlTransaction, new DataGap(30953883, 80953883));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(30953884, 80953883));
verifyNoMoreInteractions(dataService);
}
use of org.jumpmind.symmetric.model.DataGap in project symmetric-ds by JumpMind.
the class DataGapDetectorTest method testNewGapFull.
@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);
@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, 99));
verify(dataService).insertDataGap(sqlTransaction, new DataGap(101, 50000100));
verifyNoMoreInteractions(dataService);
}
Aggregations