Search in sources :

Example 46 with DataGap

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

the class AbstractRouterServiceTest method testGapRouting.

public void testGapRouting() throws Exception {
    try {
        if (getDbDialect().canGapsOccurInCapturedDataIds()) {
            setUpDefaultTriggerRouterForTable1();
            resetBatches();
            Assert.assertEquals(1, getDataService().findDataGaps().size());
            // route again to make sure we still only have one gap
            getRouterService().routeData(true);
            Assert.assertEquals(1, getDataService().findDataGaps().size());
            insertGaps(2, 1, 2);
            getRouterService().routeData(true);
            // route again to calculate gaps
            getRouterService().routeData(true);
            Assert.assertEquals(1, getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false).getBatches().size());
            List<DataGap> gaps = getDataService().findDataGaps();
            Assert.assertEquals(2, gaps.size());
            DataGap gap = gaps.get(0);
            Assert.assertEquals(0, gap.getEndId() - gap.getStartId());
            // route again to make sure the gaps don't disappear
            getRouterService().routeData(true);
            getRouterService().routeData(true);
            gaps = getDataService().findDataGaps();
            Assert.assertEquals(2, gaps.size());
            gap = gaps.get(0);
            Assert.assertEquals(0, gap.getEndId() - gap.getStartId());
        }
    } catch (Exception ex) {
        logger.error("", ex);
        throw ex;
    }
}
Also used : DataGap(org.jumpmind.symmetric.model.DataGap)

Example 47 with DataGap

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

the class AbstractRouterServiceTest method testGapWithGapAtEnd.

public void testGapWithGapAtEnd() {
    if (getDbDialect().canGapsOccurInCapturedDataIds()) {
        setUpDefaultTriggerRouterForTable1();
        resetBatches();
        Assert.assertEquals(1, getDataService().findDataGaps().size());
        long startId = getSqlTemplate().queryForLong("select max(start_id) from sym_data_gap");
        getSqlTemplate().update("update sym_data_gap set status='OK'");
        getDataService().insertDataGap(new DataGap(startId, startId + 10));
        getDataService().insertDataGap(new DataGap(startId + 11, startId + 11 + getParameterService().getLong(ParameterConstants.ROUTING_LARGEST_GAP_SIZE)));
        insertGaps(8, 0, 1);
        routeAndCreateGaps();
        Assert.assertEquals(1, getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false).getBatches().size());
        List<DataGap> gaps = getDataService().findDataGaps();
        Assert.assertEquals(2, gaps.size());
        DataGap gap = gaps.get(0);
        Assert.assertEquals(startId + 8, gap.getStartId());
        routeAndCreateGaps();
    }
}
Also used : DataGap(org.jumpmind.symmetric.model.DataGap)

Example 48 with DataGap

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

the class AbstractRouterServiceTest method testGapWithGapAtBegining.

public void testGapWithGapAtBegining() {
    if (getDbDialect().canGapsOccurInCapturedDataIds()) {
        setUpDefaultTriggerRouterForTable1();
        resetBatches();
        List<DataGap> gaps = getDataService().findDataGaps();
        Assert.assertEquals(1, gaps.size());
        // evidently, derby only leaves a gap of one, no matter how many
        // rows you insert
        String name = getPlatform().getName();
        int gapsize = name.equals(DatabaseNamesConstants.DERBY) ? 1 : 10;
        insert(TEST_TABLE_1, gapsize, true, null, NODE_GROUP_NODE_1.getNodeId(), true);
        insert(TEST_TABLE_1, 10, true, null, NODE_GROUP_NODE_1.getNodeId(), false);
        routeAndCreateGaps();
        Assert.assertEquals(1, getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false).getBatches().size());
        gaps = getDataService().findDataGaps();
        Assert.assertEquals(2, gaps.size());
        DataGap gap = gaps.get(0);
        Assert.assertEquals("The gap's start id was " + gap.getStartId() + " end id was " + gap.getEndId(), gapsize - 1, gap.getEndId() - gap.getStartId());
        routeAndCreateGaps();
        gaps = getDataService().findDataGaps();
        Assert.assertEquals(2, gaps.size());
        gap = gaps.get(0);
        Assert.assertEquals(gapsize - 1, gap.getEndId() - gap.getStartId());
    }
}
Also used : DataGap(org.jumpmind.symmetric.model.DataGap)

Example 49 with DataGap

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

the class AbstractRouterServiceTest method testDataGapExpired.

public void testDataGapExpired() throws Exception {
    if (getDbDialect().canGapsOccurInCapturedDataIds()) {
        resetGaps();
        testGapRouting();
        List<DataGap> gaps = getDataService().findDataGaps();
        Assert.assertEquals(2, gaps.size());
        DataGap gap = gaps.get(0);
        Assert.assertEquals(0, gap.getEndId() - gap.getStartId());
        Calendar time = Calendar.getInstance();
        time.add(Calendar.DATE, -10);
        getSqlTemplate().update("update sym_data_gap set create_time=?", time.getTime());
        routeAndCreateGaps();
        ;
        gaps = getDataService().findDataGaps();
        Assert.assertEquals("Gap should have expired", 2, gaps.size());
    }
}
Also used : DataGap(org.jumpmind.symmetric.model.DataGap) Calendar(java.util.Calendar)

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