📄 testhelperclasses.java
字号:
String key3 = "table..schema3.table3"; String key4 = "table.table4"; String key5 = "table...table5"; String key6 = " table. catalog6 . schema6 . table6 "; String key7 = " table. schema7 . table7 "; String key8 = " table. . schema8 . table8 "; String key9 = " table. table9"; String key10 = " table. . . table10 "; try { tableToWatchInfo.assignFromInfoPair(key1, null); assertEquals("catalog for key1", "catalog1", tableToWatchInfo.getCatalog()); assertEquals("schema for key1", "schema1", tableToWatchInfo.getSchema()); assertEquals("catalog for key1", "table1", tableToWatchInfo.getTable()); } catch (Exception ex) { ex.printStackTrace(); assertTrue("an exception should not happen when testing key1 '" + key1 + "'", false); } try { tableToWatchInfo.assignFromInfoPair(key2, null); assertEquals("catalog for key2", " ", tableToWatchInfo.getCatalog()); assertEquals("schema for key2", "schema2", tableToWatchInfo.getSchema()); assertEquals("catalog for key2", "table2", tableToWatchInfo.getTable()); } catch (Exception ex) { ex.printStackTrace(); assertTrue("an exception should not happen when testing key2 '" + key2 + "'", false); } try { tableToWatchInfo.assignFromInfoPair(key3, null); assertEquals("catalog for key3", " ", tableToWatchInfo.getCatalog()); assertEquals("schema for key3", "schema3", tableToWatchInfo.getSchema()); assertEquals("catalog for key3", "table3", tableToWatchInfo.getTable()); } catch (Exception ex) { ex.printStackTrace(); assertTrue("an exception should not happen when testing key3 '" + key3 + "'", false); } try { tableToWatchInfo.assignFromInfoPair(key4, null); assertEquals("catalog for key4", " ", tableToWatchInfo.getCatalog()); assertEquals("schema for key4", " ", tableToWatchInfo.getSchema()); assertEquals("catalog for key4", "table4", tableToWatchInfo.getTable()); } catch (Exception ex) { ex.printStackTrace(); assertTrue("an exception should not happen when testing key4 '" + key4 + "'", false); } try { tableToWatchInfo.assignFromInfoPair(key5, null); assertEquals("catalog for key5", " ", tableToWatchInfo.getCatalog()); assertEquals("schema for key5", " ", tableToWatchInfo.getSchema()); assertEquals("catalog for key5", "table5", tableToWatchInfo.getTable()); } catch (Exception ex) { ex.printStackTrace(); assertTrue("an exception should not happen when testing key5 '" + key5 + "'", false); } try { tableToWatchInfo.assignFromInfoPair(key6, null); assertEquals("catalog for key6", "catalog6", tableToWatchInfo.getCatalog()); assertEquals("schema for key6", "schema6", tableToWatchInfo.getSchema()); assertEquals("catalog for key6", "table6", tableToWatchInfo.getTable()); } catch (Exception ex) { ex.printStackTrace(); assertTrue("an exception should not happen when testing key6 '" + key6 + "'", false); } try { tableToWatchInfo.assignFromInfoPair(key7, null); assertEquals("catalog for key7", " ", tableToWatchInfo.getCatalog()); assertEquals("schema for key7", "schema7", tableToWatchInfo.getSchema()); assertEquals("catalog for key7", "table7", tableToWatchInfo.getTable()); } catch (Exception ex) { ex.printStackTrace(); assertTrue("an exception should not happen when testing key7 '" + key7 + "'", false); } try { tableToWatchInfo.assignFromInfoPair(key8, null); assertEquals("catalog for key8", " ", tableToWatchInfo.getCatalog()); assertEquals("schema for key8", "schema8", tableToWatchInfo.getSchema()); assertEquals("catalog for key8", "table8", tableToWatchInfo.getTable()); } catch (Exception ex) { ex.printStackTrace(); assertTrue("an exception should not happen when testing key8 '" + key8 + "'", false); } try { tableToWatchInfo.assignFromInfoPair(key9, null); assertEquals("catalog for key9", " ", tableToWatchInfo.getCatalog()); assertEquals("schema for key9", " ", tableToWatchInfo.getSchema()); assertEquals("catalog for key9", "table9", tableToWatchInfo.getTable()); } catch (Exception ex) { ex.printStackTrace(); assertTrue("an exception should not happen when testing key9 '" + key9 + "'", false); } try { tableToWatchInfo.assignFromInfoPair(key10, null); assertEquals("catalog for key10", " ", tableToWatchInfo.getCatalog()); assertEquals("schema for key10", " ", tableToWatchInfo.getSchema()); assertEquals("catalog for key10", "table10", tableToWatchInfo.getTable()); } catch (Exception ex) { ex.printStackTrace(); assertTrue("an exception should not happen when testing key10 '" + key10 + "'", false); } log.info("SUCCESS"); } /** * */ public final void testInfoHelper() { log.info("Start testInfoHelper"); PropertiesInfo info = new PropertiesInfo(new Properties()); info.put("replication.mapper.schema.testSchema", "testSchema1"); info.put("replication.mapper.schema.testSchema1", "testSchema2"); info.put("replication.mapper.schema2.testSchema100", "testSchema2"); info.put("replication.mapper.sch.testSchema100", "testSchema2"); Map map = InfoHelper.getPropertiesStartingWith("replication.mapper.schema.", info, null); assertEquals("testing amount", 2, map.size()); assertEquals("testing 1/2", "testSchema1", (String)map.get("testSchema")); assertEquals("testing 1/2", "testSchema2", (String)map.get("testSchema1")); map = InfoHelper.getPropertiesStartingWith(null, info, null); assertEquals("testing complete info size", 4, map.size()); log.info("SUCCESS"); } /** * */ public final void testTableMapper() { log.info("Start testTableMapper"); PropertiesInfo info = new PropertiesInfo(new Properties()); info.put("replication.mapper.schema.AIS", "AIS1"); info.put("replication.mapper.table.AIS.C_OUTS", "C_INS"); info.put("replication.mapper.column.AIS.C_OUTS.COM_MESSAGEID", "COM_RECORDID"); DefaultMapper mapper = new DefaultMapper(); try { mapper.init(info); } catch (Exception ex) { ex.printStackTrace(); assertTrue("An exception should not occur when initiating the mapper '" + ex.getMessage(), false); } { String catalog = null; String schema = "AIS"; String table = "C_OUTS"; String column = "COM_MESSAGEID"; String res = mapper.getMappedSchema(catalog, schema, table, column, schema); assertEquals("checking schema", "AIS1", res); res = mapper.getMappedTable(catalog, schema, table, column, table); assertEquals("checking table", "C_INS", res); res = mapper.getMappedColumn(catalog, schema, table, column, column); assertEquals("checking column", "COM_RECORDID", res); } { String catalog = null; String schema = "AIS"; String table = "C_OUTS"; String column = "COM_RECORDID"; String res = mapper.getMappedSchema(catalog, schema, table, column, schema); assertEquals("checking schema", "AIS1", res); res = mapper.getMappedTable(catalog, schema, table, column, table); assertEquals("checking table", "C_INS", res); res = mapper.getMappedColumn(catalog, schema, table, column, column); assertEquals("checking column", "COM_RECORDID", res); String xmlTxt = "<?xml version='1.0' encoding='UTF-8' ?>\n" + "<sql>\n" + " <desc>\n" + " <command>REPLICATION</command>\n" + " <ident>16</ident>\n" + " </desc>\n" + " <row num='0'>\n" + " <col name='COM_MESSAGEID'></col>\n" + " <col name='COM_RECORDID'>55</col>\n" + " <col name='COM_TABLE' encoding='base64'>TjF8Mg==</col>\n" + " <col name='COM_COMMAND' encoding='base64'>RA==</col>\n" + " <col name='COM_TXT1'></col>\n" + " <col name='COM_TXTL' encoding='base64'>OTg0NTA5AwM=</col>\n" + " <col name='COM_CHANNEL'></col>\n" + " <col name='COM_DEBUG'></col>\n" + " <attr name='replKey'>16</attr>\n" + " <attr name='action'>INSERT</attr>\n" + " <attr name='transaction'>4.24.2232</attr>\n" + " <attr name='guid'>AAAT0EAAGAAAAKsAAA</attr>\n" + " <attr name='tableName'>C_OUTS</attr>\n" + " <attr name='schema'>AIS</attr>\n" + " <attr name='dbId'>NULL</attr>\n" + " <attr name='version'>0.0</attr>\n" + " </row>\n" + "</sql>\n"; try { String oldName = "COM_RECORDID"; String newName = "COM_MESSAGEID"; SqlInfoParser parser = new SqlInfoParser(); parser.init(info); SqlInfo sqlInfo = parser.parse(xmlTxt); List rows = sqlInfo.getRows(); assertEquals("The number of rows is wrong", 1, rows.size()); SqlRow row = (SqlRow)rows.get(0); log.info(row.toXml("")); row.renameColumn(oldName, newName); log.info(row.toXml("")); } catch (Exception ex) { ex.printStackTrace(); assertTrue("An Exception should not occur when testing renaming of columns " + ex.getMessage(), false); } } { String catalog = null; String schema = "AIS"; String table = "OTHER"; String column = "COM_MESSAGEID"; String res = mapper.getMappedSchema(catalog, schema, table, column, schema); assertEquals("checking schema", "AIS1", res); res = mapper.getMappedTable(catalog, schema, table, column, table); assertEquals("checking table", "OTHER", res); res = mapper.getMappedColumn(catalog, schema, table, column, column); assertEquals("checking column", "COM_MESSAGEID", res); } log.info("SUCCESS"); } /** * */ public final void testTableToWatchInfoValues() { log.info("Start testTableToWatchInfoValues"); String key = "table.catalog.schema.table"; try { String val1 = null; TableToWatchInfo tableToWatchInfo = new TableToWatchInfo(); tableToWatchInfo.assignFromInfoPair(key, val1); assertEquals("replicate for val1", true, tableToWatchInfo.isReplicate()); assertEquals("trigger for val1", (String)null, tableToWatchInfo.getTrigger()); assertEquals("replKey for val1", -1L, tableToWatchInfo.getReplKey()); String val2 = ""; tableToWatchInfo = new TableToWatchInfo(); tableToWatchInfo.assignFromInfoPair(key, val2); assertEquals("replicate for val2", true, tableToWatchInfo.isReplicate()); assertEquals("trigger for val2", (String)null, tableToWatchInfo.getTrigger()); assertEquals("replKey for val2", -1L, tableToWatchInfo.getReplKey()); String val3 = ",,"; tableToWatchInfo = new TableToWatchInfo(); tableToWatchInfo.assignFromInfoPair(key, val3); assertEquals("replicate for val3", true, tableToWatchInfo.isReplicate()); assertEquals("trigger for val3", (String)null, tableToWatchInfo.getTrigger()); assertEquals("replKey for val3", -1L, tableToWatchInfo.getReplKey()); String val4 = " , , "; tableToWatchInfo = new TableToWatchInfo(); tableToWatchInfo.assignFromInfoPair(key, val4); assertEquals("replicate for val4", true, tableToWatchInfo.isReplicate()); assertEquals("trigger for val4", (String)null, tableToWatchInfo.getTrigger()); assertEquals("replKey for val4", -1L, tableToWatchInfo.getReplKey()); String val5 = "actions=IDU,trigger=trigger,sequence=10"; tableToWatchInfo = new TableToWatchInfo(); tableToWatchInfo.assignFromInfoPair(key, val5); assertEquals("replicate for val5", true, tableToWatchInfo.isReplicate()); assertEquals("trigger for val5", "trigger", tableToWatchInfo.getTrigger()); assertEquals("replKey for val5", 10L, tableToWatchInfo.getReplKey()); String val6 = "actions = IDU , trigger = trigger , sequence = 10"; tableToWatchInfo = new TableToWatchInfo(); tableToWatchInfo.assignFromInfoPair(key, val6); assertEquals("replicate for val6", true, tableToWatchInfo.isReplicate()); assertEquals("trigger for val6", "trigger", tableToWatchInfo.getTrigger()); assertEquals("replKey for val6", 10L, tableToWatchInfo.getReplKey()); String val7 = "actions=,trigger=trigger,sequence=10"; tableToWatchInfo = new TableToWatchInfo(); tableToWatchInfo.assignFromInfoPair(key, val7); assertEquals("replicate for val7", false, tableToWatchInfo.isReplicate()); assertEquals("trigger for val7", "trigger", tableToWatchInfo.getTrigger()); assertEquals("replKey for val7", 10L, tableToWatchInfo.getReplKey()); String val8 = "actions = , trigger = trigger , sequence = 10"; tableToWatchInfo = new TableToWatchInfo(); tableToWatchInfo.assignFromInfoPair(key, val8); assertEquals("replicate for val8", false, tableToWatchInfo.isReplicate()); assertEquals("trigger for val8", "trigger", tableToWatchInfo.getTrigger()); assertEquals("replKey for val8", 10L, tableToWatchInfo.getReplKey()); String val9 = "actions=IDU,sequence=10"; tableToWatchInfo = new TableToWatchInfo(); tableToWatchInfo.assignFromInfoPair(key, val9); assertEquals("replicate for val9", true, tableToWatchInfo.isReplicate()); assertEquals("trigger for val9", (String)null, tableToWatchInfo.getTrigger()); assertEquals("replKey for val9", 10L, tableToWatchInfo.getReplKey()); String val10 = " actions = IDU , sequence = 10";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -