use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.
the class AbstractIntegrationTest method checkForFailedTriggers.
protected void checkForFailedTriggers(boolean server, boolean client) {
if (server) {
ITriggerRouterService service = getServer().getTriggerRouterService();
assertEquals(0, service.getFailedTriggers().size());
}
if (client) {
ITriggerRouterService service = getClient().getTriggerRouterService();
assertEquals(0, service.getFailedTriggers().size());
}
}
use of org.jumpmind.symmetric.service.ITriggerRouterService 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(true, 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);
}
use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.
the class AbstractTriggerRouterServiceTest method test09ExcludedColumnsFunctionality.
@Test
public void test09ExcludedColumnsFunctionality() throws Exception {
ITriggerRouterService service = getTriggerRouterService();
ISqlTemplate jdbcTemplate = getSqlTemplate();
assertEquals(1, jdbcTemplate.update("update sym_trigger set excluded_column_names='BOOLEAN_VALUE', last_update_time=? " + TEST_TRIGGER_WHERE_CLAUSE, new Object[] { new Date(System.currentTimeMillis() + 60000) }));
service.syncTriggers();
TriggerRouter triggerRouter = service.getTriggerRouterForTableForCurrentNode(true, null, null, TEST_TRIGGERS_TABLE, true).iterator().next();
assertEquals(jdbcTemplate.queryForInt("select count(*) from sym_trigger_hist where trigger_id='" + triggerRouter.getTrigger().getTriggerId() + "' and inactive_time is null"), 1, "We expected only one active record in the trigger_hist table for " + TEST_TRIGGERS_TABLE);
assertEquals(1, insert(INSERT2_VALUES, jdbcTemplate, getDbDialect()));
String csvString = getNextDataRow();
// 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\"");
boolean match = csvString.endsWith(EXPECTED_INSERT2_CSV_ENDSWITH);
assertTrue(match, "Received " + csvString + ", Expected the string to end with " + EXPECTED_INSERT2_CSV_ENDSWITH);
}
use of org.jumpmind.symmetric.service.ITriggerRouterService 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.service.ITriggerRouterService in project symmetric-ds by JumpMind.
the class SymmetricAdmin method syncTrigger.
private void syncTrigger(CommandLine line, List<String> args) throws IOException {
boolean genAlways = line.hasOption(OPTION_FORCE);
String filename = line.getOptionValue(OPTION_OUT);
String catalogName = line.getOptionValue(OPTION_CATALOG);
String schemaName = line.getOptionValue(OPTION_SCHEMA);
File file = null;
if (filename != null) {
file = new File(filename);
if (file.getParentFile() != null) {
file.getParentFile().mkdirs();
}
}
ITriggerRouterService triggerService = getSymmetricEngine().getTriggerRouterService();
StringBuilder sqlBuffer = new StringBuilder();
if (args.size() == 0) {
triggerService.syncTriggers(sqlBuffer, genAlways);
} else {
for (String tablename : args) {
Table table = platform.getTableFromCache(catalogName, schemaName, tablename, true);
if (table != null) {
triggerService.syncTriggers(table, genAlways);
} else {
System.out.println("Unable to find table " + tablename);
}
}
}
if (file != null) {
FileUtils.writeStringToFile(file, sqlBuffer.toString());
}
}
Aggregations