Search in sources :

Example 26 with DataGap

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++;
    }
}
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 27 with DataGap

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++;
    }
}
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 28 with DataGap

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

Example 29 with DataGap

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

Example 30 with DataGap

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