use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.
the class AbstractRouterServiceTest method testLargeNumberOfEventsToManyNodes.
public void testLargeNumberOfEventsToManyNodes() {
resetBatches();
TriggerRouter trigger1 = getTestRoutingTableTrigger(TEST_TABLE_1);
trigger1.getRouter().setRouterType("column");
// set up a constant to force the data to be routed through the column
// data matcher, but to everyone
trigger1.getRouter().setRouterExpression("ROUTING_VARCHAR=00001");
getTriggerRouterService().saveTriggerRouter(trigger1);
getTriggerRouterService().syncTriggers();
NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
testChannel.setMaxBatchToSend(10000);
testChannel.setMaxBatchSize(10000);
testChannel.setBatchAlgorithm("default");
getConfigurationService().saveChannel(testChannel, true);
final int ROWS_TO_INSERT = 1000;
final int NODES_TO_INSERT = 10;
logger.info(String.format("About to insert %s nodes", NODES_TO_INSERT));
for (int i = 0; i < 1000; i++) {
String nodeId = String.format("100%s", i);
getRegistrationService().openRegistration(TestConstants.TEST_CLIENT_NODE_GROUP, nodeId);
Node node = getNodeService().findNode(nodeId);
node.setSyncEnabled(true);
getNodeService().save(node);
}
logger.info(String.format("Done inserting %s nodes", NODES_TO_INSERT));
logger.info(String.format("About to insert %s rows", ROWS_TO_INSERT));
insert(TEST_TABLE_1, ROWS_TO_INSERT, false);
logger.info(String.format("Done inserting %s rows", ROWS_TO_INSERT));
logger.info("About to route data");
getRouterService().routeData(true);
logger.info("Done routing data");
}
use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.
the class AbstractRouterServiceTest method testColumnMatchTransactionalOnlyRoutingToNode1.
public void testColumnMatchTransactionalOnlyRoutingToNode1() {
resetBatches();
TriggerRouter trigger1 = getTestRoutingTableTrigger(TEST_TABLE_1);
trigger1.getRouter().setRouterType("column");
trigger1.getRouter().setRouterExpression("ROUTING_VARCHAR=:NODE_ID");
getTriggerRouterService().saveTriggerRouter(trigger1);
getTriggerRouterService().syncTriggers();
NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
testChannel.setMaxBatchToSend(10000);
testChannel.setBatchAlgorithm("transactional");
getConfigurationService().saveChannel(testChannel, true);
// should be 51 batches for table 1
insert(TEST_TABLE_1, 500, true);
insert(TEST_TABLE_1, 50, false);
getRouterService().routeData(true);
final int EXPECTED_BATCHES = getDbDialect().supportsTransactionId() ? 51 : 550;
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();
Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
execute("delete from " + TEST_TABLE_1, null);
Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
getRouterService().routeData(true);
Assert.assertEquals(getDbDialect().supportsTransactionId() ? 1 : 705, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
resetBatches();
}
use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.
the class AbstractRouterServiceTest method testBshTransactionalRoutingOnUpdate.
public void testBshTransactionalRoutingOnUpdate() {
resetBatches();
TriggerRouter trigger1 = getTestRoutingTableTrigger(TEST_TABLE_1);
trigger1.getRouter().setRouterType("bsh");
trigger1.getRouter().setRouterExpression("targetNodes.add(ROUTING_VARCHAR); targetNodes.add(OLD_ROUTING_VARCHAR);");
getTriggerRouterService().saveTriggerRouter(trigger1);
getTriggerRouterService().syncTriggers();
NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
testChannel.setMaxBatchToSend(1000);
testChannel.setMaxBatchSize(5);
testChannel.setBatchAlgorithm("transactional");
getConfigurationService().saveChannel(testChannel, true);
long ts = System.currentTimeMillis();
ISqlTransaction transaction = null;
int count = 0;
try {
transaction = getSqlTemplate().startSqlTransaction();
count = transaction.prepareAndExecute(String.format("update %s set routing_varchar=?", TEST_TABLE_1), NODE_GROUP_NODE_3.getNodeId());
transaction.commit();
} finally {
transaction.close();
}
logger.info("Just recorded a change to " + count + " rows in " + TEST_TABLE_1 + " in " + (System.currentTimeMillis() - ts) + "ms");
ts = System.currentTimeMillis();
getRouterService().routeData(true);
logger.info("Just routed " + count + " rows in " + TEST_TABLE_1 + " in " + (System.currentTimeMillis() - ts) + "ms");
OutgoingBatches batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false);
filterForChannels(batches, testChannel);
Assert.assertEquals(getDbDialect().supportsTransactionId() ? 1 : 510, batches.getBatches().size());
Assert.assertEquals(getDbDialect().supportsTransactionId() ? count : 1, (int) batches.getBatches().get(0).getDataEventCount());
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);
Assert.assertEquals(getDbDialect().supportsTransactionId() ? 1 : 510, batches.getBatches().size());
Assert.assertEquals(getDbDialect().supportsTransactionId() ? count : 1, (int) batches.getBatches().get(0).getDataEventCount());
resetBatches();
}
use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.
the class AbstractRouterServiceTest method testBshRoutingDeletesToNode3.
public void testBshRoutingDeletesToNode3() {
resetBatches();
TriggerRouter trigger1 = getTestRoutingTableTrigger(TEST_TABLE_1);
trigger1.getRouter().setRouterType("bsh");
trigger1.getRouter().setRouterExpression("targetNodes.add(ROUTING_VARCHAR); if (OLD_ROUTING_VARCHAR != void) { targetNodes.add(OLD_ROUTING_VARCHAR); }");
getTriggerRouterService().saveTriggerRouter(trigger1);
getTriggerRouterService().syncTriggers();
NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
testChannel.setMaxBatchToSend(10000);
final int MAX_BATCH_SIZE = 100;
testChannel.setMaxBatchSize(MAX_BATCH_SIZE);
testChannel.setBatchAlgorithm("nontransactional");
getConfigurationService().saveChannel(testChannel, true);
int count = getSqlTemplate().update(String.format("delete from %s", TEST_TABLE_1));
getRouterService().routeData(true);
OutgoingBatches batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_3.getNodeId(), false);
filterForChannels(batches, testChannel);
Assert.assertEquals(count / MAX_BATCH_SIZE + (count % MAX_BATCH_SIZE > 0 ? 1 : 0), batches.getBatches().size());
batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_2.getNodeId(), false);
// Node 2 has sync disabled
Assert.assertEquals(0, batches.getBatches().size());
batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false);
filterForChannels(batches, testChannel);
// Batch was targeted only at node 3
Assert.assertEquals(0, batches.getBatches().size());
resetBatches();
}
use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.
the class AbstractRouterServiceTest method testColumnMatchOnNotNull.
public void testColumnMatchOnNotNull() {
NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
TriggerRouter trigger = getTestRoutingTableTrigger(TEST_TABLE_1);
trigger.getRouter().setRouterType("column");
trigger.getRouter().setRouterExpression("ROUTING_VARCHAR!=NULL");
getTriggerRouterService().saveTriggerRouter(trigger);
getTriggerRouterService().syncTriggers();
resetBatches();
update(TEST_TABLE_1, "Not Routed");
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));
resetBatches();
update(TEST_TABLE_1, null);
Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
getRouterService().routeData(true);
Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
}
Aggregations