Search in sources :

Example 31 with DataGap

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

Example 32 with DataGap

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

Example 33 with DataGap

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

Example 34 with DataGap

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

Example 35 with DataGap

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

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