Search in sources :

Example 1 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 2 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 3 with DataGap

use of org.jumpmind.symmetric.model.DataGap in project symmetric-ds by JumpMind.

the class DataGapDetectorTest method testGapsOverlapDetection.

@Test
public void testGapsOverlapDetection() throws Exception {
    List<Long> dataIds = new ArrayList<Long>();
    dataIds.add(31837983L);
    dataIds.add(31837989L);
    List<DataGap> dataGaps = new ArrayList<DataGap>();
    dataGaps.add(new DataGap(31837983, 81837982));
    dataGaps.add(new DataGap(31837983, 81837983));
    runGapDetector(dataGaps, dataIds, true);
    verify(dataService).findDataGaps();
    verify(dataService).deleteDataGap(sqlTransaction, new DataGap(31837983, 81837982));
    verify(dataService).deleteDataGap(sqlTransaction, new DataGap(31837983, 81837983));
    verify(dataService).insertDataGap(sqlTransaction, new DataGap(31837984, 31837988));
    verify(dataService).insertDataGap(sqlTransaction, new DataGap(31837990, 81837989));
    verifyNoMoreInteractions(dataService);
}
Also used : DataGap(org.jumpmind.symmetric.model.DataGap) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with DataGap

use of org.jumpmind.symmetric.model.DataGap in project symmetric-ds by JumpMind.

the class DataGapDetectorTest method verifyInteractions.

private void verifyInteractions(List<DataGap> dataGaps, List<Long> dataIds, boolean verifyDeletes) {
    int index = 0;
    int lastIndex = dataGaps.size() - 1;
    boolean isLastGapInserted = false;
    boolean isLastGapModified = false;
    for (DataGap dataGap : dataGaps) {
        long lastDataId = -1;
        for (Long dataId : dataIds) {
            if (dataId >= dataGap.getStartId() && dataId <= dataGap.getEndId()) {
                if (lastDataId == -1) {
                    if (verifyDeletes) {
                        verify(dataService).deleteDataGap(sqlTransaction, dataGap);
                    }
                    if (dataId > dataGap.getStartId()) {
                        verify(dataService).insertDataGap(sqlTransaction, new DataGap(dataGap.getStartId(), dataId - 1));
                    }
                    if (index == lastIndex) {
                        isLastGapModified = true;
                    }
                } else if (dataId > lastDataId + 1) {
                    verify(dataService).insertDataGap(sqlTransaction, 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;
                verify(dataService).insertDataGap(sqlTransaction, new DataGap(lastDataId + 1, lastDataId + 50000000));
            } else {
                verify(dataService).insertDataGap(sqlTransaction, new DataGap(lastDataId + 1, dataGap.getEndId()));
            }
        }
        index++;
    }
    if (!isLastGapInserted && isLastGapModified) {
        DataGap lastGap = dataGaps.get(lastIndex);
        if (lastGap.getEndId() - lastGap.getStartId() < 50000000 - 1) {
            verify(dataService).insertDataGap(sqlTransaction, new DataGap(lastGap.getEndId() + 1, lastGap.getEndId() + 50000000));
        }
    }
    verifyNoMoreInteractions(dataService);
}
Also used : DataGap(org.jumpmind.symmetric.model.DataGap)

Example 5 with DataGap

use of org.jumpmind.symmetric.model.DataGap in project symmetric-ds by JumpMind.

the class DataGapDetectorTest method getRandomDataGaps.

private List<DataGap> getRandomDataGaps() {
    List<DataGap> dataGaps = new ArrayList<DataGap>();
    long startId = 0, endId = 0;
    for (int i = 0; i < rand.nextInt(1, 10); i++) {
        startId = rand.nextLong(endId + 1, endId + 10);
        endId = rand.nextLong(startId, startId + 10);
        dataGaps.add(new DataGap(startId, endId));
    }
    return dataGaps;
}
Also used : DataGap(org.jumpmind.symmetric.model.DataGap) ArrayList(java.util.ArrayList)

Aggregations

DataGap (org.jumpmind.symmetric.model.DataGap)50 ArrayList (java.util.ArrayList)31 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 List (java.util.List)3 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)3 HashSet (java.util.HashSet)2 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 RuntimeMXBean (java.lang.management.RuntimeMXBean)1 Calendar (java.util.Calendar)1