Search in sources :

Example 51 with TriggerRouter

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

the class AbstractRouterServiceTest method testSyncOnColumnChange.

public void testSyncOnColumnChange() {
    NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
    testChannel.setMaxBatchToSend(10000);
    testChannel.setBatchAlgorithm("transactional");
    getConfigurationService().saveChannel(testChannel, true);
    TriggerRouter trigger1 = getTestRoutingTableTrigger(TEST_TABLE_1);
    trigger1.getRouter().setRouterType("bsh");
    trigger1.getRouter().setRouterExpression("ROUTING_INT != null && !ROUTING_INT.equals(OLD_ROUTING_INT)");
    getTriggerRouterService().saveTriggerRouter(trigger1);
    getTriggerRouterService().syncTriggers();
    resetBatches();
    Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
    insert(TEST_TABLE_1, 1, true);
    getRouterService().routeData(true);
    Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
    resetBatches();
    int pk = getSqlTemplate().queryForInt("select pk from " + TEST_TABLE_1 + " where routing_varchar='" + NODE_GROUP_NODE_1.getNodeId() + "'");
    getSqlTemplate().update("update " + TEST_TABLE_1 + " set routing_int=1 where pk=?", pk);
    getRouterService().routeData(true);
    Assert.assertEquals(1, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
    resetBatches();
    getSqlTemplate().update("update " + TEST_TABLE_1 + " set routing_int=1 where pk=?", new Object[] { pk });
    getRouterService().routeData(true);
    Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
    resetBatches();
    getSqlTemplate().update("update " + TEST_TABLE_1 + " set routing_int=10 where pk=?", new Object[] { pk });
    getRouterService().routeData(true);
    Assert.assertEquals(1, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
}
Also used : TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Example 52 with TriggerRouter

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

the class AbstractRouterServiceTest method testSubSelectNonTransactionalRoutingToNode1.

public void testSubSelectNonTransactionalRoutingToNode1() {
    resetBatches();
    TriggerRouter trigger1 = getTestRoutingTableTrigger(TEST_TABLE_1);
    trigger1.getRouter().setRouterType("subselect");
    trigger1.getRouter().setRouterExpression("c.node_id=:ROUTING_VARCHAR");
    getTriggerRouterService().saveTriggerRouter(trigger1);
    getTriggerRouterService().syncTriggers();
    NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
    testChannel.setMaxBatchToSend(1000);
    testChannel.setMaxBatchSize(5);
    testChannel.setBatchAlgorithm("nontransactional");
    getConfigurationService().saveChannel(testChannel, true);
    // should be 100 batches for table 1, even though we committed the
    // changes as part of a transaction
    insert(TEST_TABLE_1, 500, true);
    getRouterService().routeData(true);
    final int EXPECTED_BATCHES = 100;
    OutgoingBatches batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false);
    filterForChannels(batches, testChannel);
    Assert.assertEquals(EXPECTED_BATCHES, batches.getBatches().size());
    Assert.assertEquals(EXPECTED_BATCHES, countBatchesForChannel(batches, testChannel));
    batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_2.getNodeId(), false);
    filterForChannels(batches, testChannel);
    // Node 2 has sync disabled
    Assert.assertEquals(0, batches.getBatches().size());
    batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_3.getNodeId(), false);
    filterForChannels(batches, testChannel);
    // Batch was targeted only at node 1
    Assert.assertEquals(0, batches.getBatches().size());
    resetBatches();
}
Also used : TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches) NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Example 53 with TriggerRouter

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

the class AbstractRouterServiceTest method testSyncIncomingBatchWhenUnrouted.

public void testSyncIncomingBatchWhenUnrouted() throws Exception {
    resetBatches();
    TriggerRouter triggerRouter = getTestRoutingTableTrigger(TEST_TABLE_1);
    triggerRouter.getTrigger().setSyncOnIncomingBatch(true);
    triggerRouter.getRouter().setRouterType("bsh");
    triggerRouter.getRouter().setRouterExpression("return " + NODE_GROUP_NODE_1.getNodeId());
    getTriggerRouterService().saveTriggerRouter(triggerRouter);
    NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
    testChannel.setMaxBatchToSend(1000);
    testChannel.setMaxBatchSize(50);
    testChannel.setBatchAlgorithm("default");
    getConfigurationService().saveChannel(testChannel, true);
    getTriggerRouterService().syncTriggers();
    insert(TEST_TABLE_1, 10, true, NODE_GROUP_NODE_1.getNodeId());
    int unroutedCount = countUnroutedBatches();
    getRouterService().routeData(true);
    OutgoingBatches batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false);
    filterForChannels(batches, testChannel);
    Assert.assertEquals("Should have been 0.  We did the insert as if the data had come from node 1.", 0, batches.getBatches().size());
    Assert.assertTrue(countUnroutedBatches() > unroutedCount);
    resetBatches();
}
Also used : TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches) NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Example 54 with TriggerRouter

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

the class AbstractRouterServiceTest method testLookupTableRouting.

public void testLookupTableRouting() {
    getDbDialect().truncateTable("test_lookup_table");
    getSqlTemplate().update("insert into test_lookup_table values ('A',?)", NODE_GROUP_NODE_1.getExternalId());
    getSqlTemplate().update("insert into test_lookup_table values ('B',?)", NODE_GROUP_NODE_1.getExternalId());
    getSqlTemplate().update("insert into test_lookup_table values ('C',?)", NODE_GROUP_NODE_3.getExternalId());
    getSqlTemplate().update("insert into test_lookup_table values ('D',?)", NODE_GROUP_NODE_3.getExternalId());
    getSqlTemplate().update("insert into test_lookup_table values ('D',?)", NODE_GROUP_NODE_1.getExternalId());
    TriggerRouter triggerRouter = getTestRoutingTableTrigger(TEST_TABLE_1);
    triggerRouter.getRouter().setRouterType("lookuptable");
    triggerRouter.getRouter().setRouterExpression("LOOKUP_TABLE=test_lookup_table\nKEY_COLUMN=routing_varchar\nLOOKUP_KEY_COLUMN=column_one\nEXTERNAL_ID_COLUMN=column_two");
    getTriggerRouterService().saveTriggerRouter(triggerRouter);
    getTriggerRouterService().syncTriggers();
    getRouterService().routeData(true);
    resetBatches();
    insert(TEST_TABLE_1, 5, true, null, "A");
    int unroutedCount = countUnroutedBatches();
    getRouterService().routeData(true);
    Assert.assertEquals(1, getSqlTemplate().queryForInt(SELECT_COUNT_FROM_SYM_OUTGOING_BATCH, NODE_GROUP_NODE_1.getNodeId()));
    Assert.assertEquals(0, getSqlTemplate().queryForInt(SELECT_COUNT_FROM_SYM_OUTGOING_BATCH_WHERE_NOT, NODE_GROUP_NODE_1.getNodeId()));
    Assert.assertEquals(unroutedCount, countUnroutedBatches());
    resetBatches();
    insert(TEST_TABLE_1, 5, true, null, "B");
    getRouterService().routeData(true);
    Assert.assertEquals(1, getSqlTemplate().queryForInt(SELECT_COUNT_FROM_SYM_OUTGOING_BATCH, NODE_GROUP_NODE_1.getNodeId()));
    Assert.assertEquals(0, getSqlTemplate().queryForInt(SELECT_COUNT_FROM_SYM_OUTGOING_BATCH_WHERE_NOT, NODE_GROUP_NODE_1.getNodeId()));
    Assert.assertEquals(unroutedCount, countUnroutedBatches());
    resetBatches();
    insert(TEST_TABLE_1, 10, true, null, "C");
    getRouterService().routeData(true);
    Assert.assertEquals(1, getSqlTemplate().queryForInt(SELECT_COUNT_FROM_SYM_OUTGOING_BATCH, NODE_GROUP_NODE_3.getNodeId()));
    Assert.assertEquals(0, getSqlTemplate().queryForInt(SELECT_COUNT_FROM_SYM_OUTGOING_BATCH_WHERE_NOT, NODE_GROUP_NODE_3.getNodeId()));
    Assert.assertEquals(unroutedCount, countUnroutedBatches());
    resetBatches();
    insert(TEST_TABLE_1, 5, true, null, "D");
    getRouterService().routeData(true);
    Assert.assertEquals(1, getSqlTemplate().queryForInt(SELECT_COUNT_FROM_SYM_OUTGOING_BATCH, NODE_GROUP_NODE_1.getNodeId()));
    Assert.assertEquals(1, getSqlTemplate().queryForInt(SELECT_COUNT_FROM_SYM_OUTGOING_BATCH, NODE_GROUP_NODE_3.getNodeId()));
    Assert.assertEquals(0, getSqlTemplate().queryForInt("select count(*) from sym_outgoing_batch where status = 'NE' and node_id not in (?,?)", NODE_GROUP_NODE_1.getNodeId(), NODE_GROUP_NODE_3.getNodeId()));
    Assert.assertEquals(unroutedCount, countUnroutedBatches());
    resetBatches();
    insert(TEST_TABLE_1, 1, true, null, "F");
    getRouterService().routeData(true);
    Assert.assertEquals(0, getSqlTemplate().queryForInt(SELECT_COUNT_FROM_SYM_OUTGOING_BATCH, NODE_GROUP_NODE_1.getNodeId()));
    Assert.assertEquals(0, getSqlTemplate().queryForInt(SELECT_COUNT_FROM_SYM_OUTGOING_BATCH, NODE_GROUP_NODE_3.getNodeId()));
    Assert.assertEquals(1, countUnroutedBatches() - unroutedCount);
    resetBatches();
}
Also used : TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter)

Example 55 with TriggerRouter

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

the class AbstractRouterServiceTest method testDontSelectOldDataDuringRouting.

public void testDontSelectOldDataDuringRouting() throws Exception {
    NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
    testChannel.setUseOldDataToRoute(false);
    testChannel.setMaxBatchSize(50);
    testChannel.setBatchAlgorithm("nontransactional");
    getConfigurationService().saveChannel(testChannel, true);
    TriggerRouter trigger = getTestRoutingTableTrigger(TEST_TABLE_1);
    trigger.getRouter().setRouterType("column");
    trigger.getRouter().setRouterExpression("ROUTING_VARCHAR=:NODE_ID");
    getTriggerRouterService().saveTriggerRouter(trigger);
    // clean setup
    deleteAll(TEST_TABLE_1);
    insert(TEST_TABLE_1, 100, true);
    getRouterService().routeData(true);
    resetBatches();
    // delete
    deleteAll(TEST_TABLE_1);
    ISqlTransaction transaction = getSqlTemplate().startSqlTransaction();
    ChannelRouterContext context = new ChannelRouterContext(TestConstants.TEST_ROOT_EXTERNAL_ID, testChannel, transaction);
    context.setDataGaps(engine.getDataService().findDataGaps());
    DataGapRouteReader reader = new DataGapRouteReader(context, engine);
    reader.run();
    List<Data> list = new ArrayList<Data>();
    do {
        Data data = reader.take();
        if (data != null) {
            list.add(data);
        } else {
            break;
        }
    } while (true);
    transaction.close();
    Assert.assertEquals(100, list.size());
    for (Data data : list) {
        Assert.assertNull(data.toParsedOldData());
        Assert.assertNotNull(data.toParsedPkData());
    }
}
Also used : DataGapRouteReader(org.jumpmind.symmetric.route.DataGapRouteReader) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) ChannelRouterContext(org.jumpmind.symmetric.route.ChannelRouterContext) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) ArrayList(java.util.ArrayList) Data(org.jumpmind.symmetric.model.Data) NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Aggregations

TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)64 ArrayList (java.util.ArrayList)22 Trigger (org.jumpmind.symmetric.model.Trigger)20 Router (org.jumpmind.symmetric.model.Router)18 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)14 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)13 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)12 Test (org.junit.Test)12 List (java.util.List)10 Node (org.jumpmind.symmetric.model.Node)8 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)7 OutgoingBatches (org.jumpmind.symmetric.model.OutgoingBatches)7 Table (org.jumpmind.db.model.Table)6 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 Data (org.jumpmind.symmetric.model.Data)5 TableReloadRequest (org.jumpmind.symmetric.model.TableReloadRequest)5 ConfigurationChangedDataRouter (org.jumpmind.symmetric.route.ConfigurationChangedDataRouter)4 FileSyncDataRouter (org.jumpmind.symmetric.route.FileSyncDataRouter)4