Search in sources :

Example 6 with DataGap

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);
}
Also used : DataGap(org.jumpmind.symmetric.model.DataGap) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with DataGap

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);
}
Also used : DataGap(org.jumpmind.symmetric.model.DataGap) ArrayList(java.util.ArrayList) ISqlRowMapper(org.jumpmind.db.sql.ISqlRowMapper) Test(org.junit.Test)

Example 8 with DataGap

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++;
    }
}
Also used : DataGap(org.jumpmind.symmetric.model.DataGap) ArrayList(java.util.ArrayList) Data(org.jumpmind.symmetric.model.Data) TransformedData(org.jumpmind.symmetric.io.data.transform.TransformedData) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with DataGap

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++;
    }
}
Also used : ArrayList(java.util.ArrayList) Data(org.jumpmind.symmetric.model.Data) TransformedData(org.jumpmind.symmetric.io.data.transform.TransformedData) DataGap(org.jumpmind.symmetric.model.DataGap) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with DataGap

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++;
    }
}
Also used : DataGap(org.jumpmind.symmetric.model.DataGap) ArrayList(java.util.ArrayList) Data(org.jumpmind.symmetric.model.Data) TransformedData(org.jumpmind.symmetric.io.data.transform.TransformedData) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

DataGap (org.jumpmind.symmetric.model.DataGap)49 ArrayList (java.util.ArrayList)32 Test (org.junit.Test)28 Data (org.jumpmind.symmetric.model.Data)7 Date (java.util.Date)6 ISqlRowMapper (org.jumpmind.db.sql.ISqlRowMapper)6 TransformedData (org.jumpmind.symmetric.io.data.transform.TransformedData)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ISqlTemplate (org.jumpmind.db.sql.ISqlTemplate)5 HashSet (java.util.HashSet)3 List (java.util.List)3 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)3 Row (org.jumpmind.db.sql.Row)2 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)2 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)1 MemoryUsage (java.lang.management.MemoryUsage)1