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));
}
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();
}
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();
}
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();
}
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());
}
}
Aggregations