use of org.jumpmind.symmetric.model.NodeChannel 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.NodeChannel 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.NodeChannel 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());
}
}
use of org.jumpmind.symmetric.model.NodeChannel in project symmetric-ds by JumpMind.
the class AbstractRouterServiceTest method testMultiChannelRoutingToEveryone.
public void testMultiChannelRoutingToEveryone() {
resetBatches();
TriggerRouter trigger1 = getTestRoutingTableTrigger(TEST_TABLE_1);
getTriggerRouterService().saveTriggerRouter(trigger1);
TriggerRouter trigger2 = getTestRoutingTableTrigger(TEST_TABLE_2);
getTriggerRouterService().saveTriggerRouter(trigger2);
getTriggerRouterService().syncTriggers();
NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
NodeChannel otherChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID_OTHER, false);
Assert.assertEquals(50, testChannel.getMaxBatchSize());
Assert.assertEquals(1, otherChannel.getMaxBatchSize());
/*
* Should be 1 batch for table 1 on the testchannel w/ max batch size of
* 50
*/
insert(TEST_TABLE_1, 5, false);
/* this should generate 15 batches because the max batch size is 1 */
insert(TEST_TABLE_2, 15, false);
insert(TEST_TABLE_1, 50, true);
getRouterService().routeData(true);
final int EXPECTED_BATCHES = getDbDialect().supportsTransactionId() ? 16 : 17;
OutgoingBatches batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false);
filterForChannels(batches, testChannel, otherChannel);
Assert.assertEquals(EXPECTED_BATCHES, batches.getBatches().size());
Assert.assertEquals(getDbDialect().supportsTransactionId() ? 1 : 2, countBatchesForChannel(batches, testChannel));
Assert.assertEquals(15, countBatchesForChannel(batches, otherChannel));
batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_2.getNodeId(), false);
filterForChannels(batches, testChannel, otherChannel);
// Node 2 has sync disabled
Assert.assertEquals(0, batches.getBatches().size());
batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_3.getNodeId(), false);
filterForChannels(batches, testChannel, otherChannel);
Assert.assertEquals(EXPECTED_BATCHES, batches.getBatches().size());
resetBatches();
// should be 2 batches for table 1 on the testchannel w/ max batch size
// of 50
insert(TEST_TABLE_1, 50, false);
// this should generate 1 batches because the max batch size is 1, but
// the batch is transactional
insert(TEST_TABLE_2, 15, true);
insert(TEST_TABLE_1, 50, false);
getRouterService().routeData(true);
batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false);
filterForChannels(batches, testChannel, otherChannel);
Assert.assertEquals(getDbDialect().supportsTransactionId() ? 3 : 17, batches.getBatches().size());
Assert.assertEquals(2, countBatchesForChannel(batches, testChannel));
Assert.assertEquals(getDbDialect().supportsTransactionId() ? 1 : 15, countBatchesForChannel(batches, otherChannel));
}
use of org.jumpmind.symmetric.model.NodeChannel in project symmetric-ds by JumpMind.
the class AbstractRouterServiceTest method testColumnMatchSubtableRoutingToNode1.
public void testColumnMatchSubtableRoutingToNode1() {
NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
testChannel.setMaxBatchToSend(10000);
testChannel.setBatchAlgorithm("transactional");
getConfigurationService().saveChannel(testChannel, true);
TriggerRouter trigger2 = getTestRoutingTableTrigger(TEST_SUBTABLE);
trigger2.getRouter().setRouterType("column");
trigger2.getRouter().setRouterExpression("EXTERNAL_DATA=:NODE_ID");
String name = getPlatform().getName();
if (name.equals(DatabaseNamesConstants.DERBY) || name.equals(DatabaseNamesConstants.MSSQL2000) || name.equals(DatabaseNamesConstants.MSSQL2005) || name.equals(DatabaseNamesConstants.MSSQL2008) || name.equals(DatabaseNamesConstants.ASE) || name.equals(DatabaseNamesConstants.SQLANYWHERE)) {
// TODO could not get subselect to work in trigger text for derby or
// mssql. probably need to work on derby's support of
// external_select a bit more
trigger2.getTrigger().setExternalSelect("'" + NODE_GROUP_NODE_1.getNodeId() + "'");
} else {
trigger2.getTrigger().setExternalSelect("select routing_varchar from " + TEST_TABLE_1 + " where pk=$(curTriggerValue).$(curColumnPrefix)FK");
}
getTriggerRouterService().saveTriggerRouter(trigger2);
getTriggerRouterService().syncTriggers();
insert(TEST_TABLE_1, 1, true);
getRouterService().routeData(true);
resetBatches();
int pk = getSqlTemplate().queryForInt("select pk from " + TEST_TABLE_1 + " where routing_varchar='" + NODE_GROUP_NODE_1.getNodeId() + "'");
getSqlTemplate().update("insert into " + TEST_SUBTABLE + " (fk) values(?)", pk);
Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
getRouterService().routeData(true);
Assert.assertEquals(1, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_2.getNodeId(), false), testChannel));
Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_3.getNodeId(), false), testChannel));
resetBatches();
Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
execute("delete from " + TEST_SUBTABLE, null);
Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_2.getNodeId(), false), testChannel));
Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_3.getNodeId(), false), testChannel));
getRouterService().routeData(true);
Assert.assertEquals(1, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_2.getNodeId(), false), testChannel));
Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_3.getNodeId(), false), testChannel));
resetBatches();
}
Aggregations