use of org.jumpmind.symmetric.model.TriggerRouter 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.TriggerRouter 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();
}
use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.
the class AbstractTriggerRouterServiceTest method test13BinaryColumnTypesForDerby.
@Test
public void test13BinaryColumnTypesForDerby() {
ISymmetricDialect dialect = getDbDialect();
if (DatabaseNamesConstants.DERBY.equals(dialect.getName())) {
try {
getSqlTemplate().update("drop table test_derby_binary_types");
} catch (Exception e) {
}
getSqlTemplate().update("create table test_derby_binary_types (id integer, data VARCHAR (100) FOR BIT DATA, data2 CHAR(12) FOR BIT DATA)");
TriggerRouter trouter = new TriggerRouter();
Trigger trigger = trouter.getTrigger();
trigger.setSourceTableName("test_derby_binary_types");
trigger.setChannelId(TestConstants.TEST_CHANNEL_ID);
Router router = trouter.getRouter();
router.getNodeGroupLink().setSourceNodeGroupId(TestConstants.TEST_ROOT_NODE_GROUP);
router.getNodeGroupLink().setTargetNodeGroupId(TestConstants.TEST_ROOT_NODE_GROUP);
getTriggerRouterService().saveTriggerRouter(trouter);
ITriggerRouterService triggerService = getTriggerRouterService();
triggerService.syncTriggers();
Assert.assertEquals("Some triggers must have failed to build.", 0, triggerService.getFailedTriggers().size());
getSqlTemplate().update("insert into test_derby_binary_types values (?, ?, ?)", new Object[] { 23, "test 1 2 3".getBytes(), "test 1 2 3".getBytes() });
String csvString = getNextDataRow();
Assert.assertEquals("\"23\",\"dGVzdCAxIDIgMw==\",\"dGVzdCAxIDIgMyAg\"", csvString);
}
}
use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.
the class AbstractRouterServiceTest method getTestRoutingTableTrigger.
protected TriggerRouter getTestRoutingTableTrigger(String tableName) {
TriggerRouter trigger = null;
Set<TriggerRouter> triggerRouters = getTriggerRouterService().getTriggerRouterForTableForCurrentNode(null, null, tableName, true);
if (triggerRouters == null || triggerRouters.size() == 0) {
trigger = new TriggerRouter();
trigger.getTrigger().setSourceTableName(tableName);
trigger.getTrigger().setTriggerId(tableName);
trigger.getRouter().setNodeGroupLink(new NodeGroupLink(TestConstants.TEST_ROOT_NODE_GROUP, TestConstants.TEST_CLIENT_NODE_GROUP));
if (tableName.equals(TEST_TABLE_2)) {
trigger.getTrigger().setChannelId(TestConstants.TEST_CHANNEL_ID_OTHER);
} else {
trigger.getTrigger().setChannelId(TestConstants.TEST_CHANNEL_ID);
}
} else {
trigger = triggerRouters.iterator().next();
}
return trigger;
}
use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.
the class AbstractTriggerRouterServiceTest method test06InitialLoadSql.
@Test
public void test06InitialLoadSql() throws Exception {
ITriggerRouterService triggerRouterService = getTriggerRouterService();
IParameterService parameterService = getParameterService();
parameterService.saveParameter(ParameterConstants.INITIAL_LOAD_CONCAT_CSV_IN_SQL_ENABLED, true, "unittest");
TriggerRouter triggerRouter = triggerRouterService.getTriggerRouterForTableForCurrentNode(null, null, TEST_TRIGGERS_TABLE, true).iterator().next();
Table table = getDbDialect().getPlatform().getTableFromCache(triggerRouter.getTrigger().getSourceTableName(), true);
Trigger trigger = triggerRouter.getTrigger();
String sql = getDbDialect().createInitialLoadSqlFor(new Node("1", null, "1.0"), triggerRouter, table, triggerRouterService.getNewestTriggerHistoryForTrigger(trigger.getTriggerId(), trigger.getSourceCatalogName(), trigger.getSourceSchemaName(), trigger.getSourceTableName()), getConfigurationService().getChannel(triggerRouter.getTrigger().getChannelId()), null);
List<String> csvStrings = getSqlTemplate().query(sql, new StringMapper());
assertTrue(csvStrings.size() > 0);
String csvString = csvStrings.get(0);
// DB2 captures decimal differently
csvString = csvString.replaceFirst("\"00001\\.\"", "\"1\"");
// Informix captures decimal differently
csvString = csvString.replaceFirst("\"1.0000000000000000\"", "\"1\"");
// ASA captures decimal differently
csvString = csvString.replaceFirst("\"1.000000\"", "\"1\"");
assertTrue(csvString.endsWith(EXPECTED_INSERT1_CSV_ENDSWITH), "Received " + csvString + ", Expected the string to end with " + EXPECTED_INSERT1_CSV_ENDSWITH);
}
Aggregations