⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testtimestamp.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
         log.info("Delete one row");         this.dbPool.update("DELETE FROM TEST_TS WHERE ICAO_ID='EDDI'");         changeDetector.checkAgain(null);         sleep(500);         assertEquals("Number of message is wrong", 0, this.updateMap.size());         // TODO: We don't know that EDDI was deleted         //String xml = (String)this.updateMap.get("db.change.event.${groupColValue}");         //assertNotNull("xml returned is null", xml);         //assertEquals("", xml);         this.updateMap.clear();         changeDetector.checkAgain(null);         sleep(500);         assertEquals("Number of message is wrong", 0, this.updateMap.size());      }      {         log.info("Drop a table");         this.dbPool.update("DROP TABLE TEST_TS");         changeDetector.checkAgain(null);         sleep(500);         assertEquals("Number of message is wrong", 1, this.updateMap.size());         String xml = (String)this.updateMap.get("db.change.event.${groupColValue}");         assertNotNull("xml returned is null", xml);         assertEquals("", xml);         this.updateMap.clear();         changeDetector.checkAgain(null);         sleep(500);         assertEquals("Number of message is wrong", 0, this.updateMap.size());      }      log.info("SUCCESS");   }   /**    * Checks if the conversion of the special token ${currentDate} is correct    */   public final void testReplaceDate() throws Exception {      // time='1157049798000' gives '2006-08-31 20:43:18.0'      // String       // '2005-11-25 12:48:00.0' "yyyy-MM-dd HH:mm:ss.0"      long refTime = 1157049798000L;      String format = "yyyy-MM-dd HH:mm:ss.0";            String txt = "${currentDate}=" + format;      SimpleDateFormat dateFormatter = new SimpleDateFormat(format);      txt = "${currentDate}=yyyy-MM-dd HH:mm:ss.0";      String res = TimestampChangeDetector.modifyMinStrIfDate(txt, refTime);      assertEquals("date conversion is wrong", "2006-08-31 20:43:18.0", res);      txt = "${currentDate}= " + format;      res = TimestampChangeDetector.modifyMinStrIfDate(txt, refTime);      assertEquals("date conversion is wrong", " 2006-08-31 20:43:18.0", res);            txt = "${currentDate}";      res = TimestampChangeDetector.modifyMinStrIfDate(txt, refTime);      assertEquals("date conversion is wrong", "1157049798000", res);            txt = "${currentDate}=";      res = TimestampChangeDetector.modifyMinStrIfDate(txt, refTime);      assertEquals("date conversion is wrong", "", res);            txt = "currentDate";      res = TimestampChangeDetector.modifyMinStrIfDate(txt, refTime);      assertEquals("date conversion is wrong", "currentDate", res);            txt = null;      res = TimestampChangeDetector.modifyMinStrIfDate(txt, refTime);      assertNull("must be null", res);      txt = "${currentDate}=" + format;      res = TimestampChangeDetector.modifyMinStrIfDate(txt, 0L);      long currentTime = dateFormatter.parse(res).getTime();      String res2 = TimestampChangeDetector.modifyMinStrIfDate(txt, currentTime);      assertEquals("Wrong data conversion", res, res2);      log.info("SUCCESS");   }      /**    * Check detection of changes on a table and deliver the change as XML.     * @throws Exception Any type is possible    */   public final void testQueryMeatTableStates() throws Exception {      log.info("Start testQueryMeatTableStates()");      this.prefs.put("changeDetector.class", "org.xmlBlaster.contrib.dbwatcher.detector.TimestampChangeDetector");      this.prefs.put("changeDetector.detectStatement", "SELECT MAX(TO_CHAR(ts, 'YYYY-MM-DD HH24:MI:SSXFF')) FROM TEST_TS");      this.prefs.put("changeDetector.timestampColName", "ts");      this.prefs.put("alertScheduler.pollInterval", "0"); // switch off      this.prefs.put("changeDetector.groupColName", "ICAO_ID");      this.prefs.put("converter.rootName", "myRootTag");      this.prefs.put("converter.addMeta", ""+true);      this.prefs.put("db.queryMeatStatement", "SELECT * FROM TEST_TS WHERE TO_CHAR(ts, 'YYYY-MM-DD HH24:MI:SSXFF') > '${oldTimestamp}' ORDER BY ICAO_ID");      this.prefs.put("mom.topicName", "db.change.event.${groupColValue}");            this.processor = createTest(new Info(prefs), this.updateMap);      I_ChangeDetector changeDetector = processor.getChangeDetector();            for (int i=0; i<2; i++) {         log.info("Testing no table ...");         changeDetector.checkAgain(null);         sleep(500);         assertEquals("Number of message is wrong", 0, this.updateMap.size());      }      {      log.info("Now testing an empty table ...");      this.dbPool.update("CREATE TABLE TEST_TS (ts TIMESTAMP(9), colKey NUMBER(10,3), col1 VARCHAR(20), col2 NUMBER(12), ICAO_ID VARCHAR(10))");      changeDetector.checkAgain(null);      sleep(500);      assertEquals("Number of message is wrong", 1, this.updateMap.size());      String xml = (String)this.updateMap.get("db.change.event.${groupColValue}");      assertNotNull("No db.change.event.${groupColValue} message has arrived", xml);      assertXpathNotExists("/myRootTag/row[@num='0']", xml);      assertXpathEvaluatesTo("CREATE", "/myRootTag/desc/command/text()", xml);      this.updateMap.clear();      changeDetector.checkAgain(null);      sleep(500);      assertEquals("Number of message is wrong", 0, this.updateMap.size());      }      {      log.info("Insert one row");      this.dbPool.update("INSERT INTO TEST_TS VALUES (CURRENT_TIMESTAMP, '1.1', '<Bla', '9000', 'EDDI')");      changeDetector.checkAgain(null);      sleep(500);      assertEquals("Number of message is wrong", 1, this.updateMap.size());      String xml = (String)this.updateMap.get("db.change.event.EDDI");      assertNotNull("xml returned is null", xml);      assertXpathEvaluatesTo("UPDATE", "/myRootTag/desc/command/text()", xml);      assertXpathEvaluatesTo("<Bla", "/myRootTag/row[@num='0']/col[@name='COL1']/text()", xml);      //assertTrue(xml.indexOf("Bla-1.1") != -1);      this.updateMap.clear();      writeToFile("db.change.event.INSERT", xml);      changeDetector.checkAgain(null);      sleep(500);      assertEquals("Number of message is wrong", 0, this.updateMap.size());      }      {         log.info("Update one row");         this.dbPool.update("UPDATE TEST_TS SET ts=CURRENT_TIMESTAMP, colKey='4.44' WHERE ICAO_ID='EDDI'");         changeDetector.checkAgain(null);         Thread.sleep(500);         assertEquals("Number of message is wrong", 1, this.updateMap.size());         String xml = (String)this.updateMap.get("db.change.event.EDDI");         assertNotNull("xml returned is null", xml);         assertXpathEvaluatesTo("UPDATE", "/myRootTag/desc/command/text()", xml);         assertXpathEvaluatesTo("4.44", "/myRootTag/row[@num='0']/col[@name='COLKEY']/text()", xml);         this.updateMap.clear();         writeToFile("db.change.event.UPDATE", xml);         changeDetector.checkAgain(null);         sleep(500);         assertEquals("Number of message is wrong", 0, this.updateMap.size());      }      // Is not detected by Timestamp poller!      {         log.info("Delete one row");         this.dbPool.update("DELETE FROM TEST_TS WHERE ICAO_ID='EDDI'");         changeDetector.checkAgain(null);         sleep(500);         assertEquals("Number of message is wrong", 0, this.updateMap.size());         // TODO: We don't know that EDDI was deleted         //String xml = (String)this.updateMap.get("db.change.event.${groupColValue}");         //assertNotNull("xml returned is null", xml);         this.updateMap.clear();         changeDetector.checkAgain(null);         sleep(500);         assertEquals("Number of message is wrong", 0, this.updateMap.size());      }      {         log.info("Drop a table");         this.dbPool.update("DROP TABLE TEST_TS");         changeDetector.checkAgain(null);         sleep(500);         assertEquals("Number of message is wrong", 1, this.updateMap.size());         String xml = (String)this.updateMap.get("db.change.event.${groupColValue}");         assertNotNull("xml returned is null", xml);         assertXpathEvaluatesTo("DROP", "/myRootTag/desc/command/text()", xml);         assertXpathNotExists("/myRootTag/row[@num='0']", xml);         this.updateMap.clear();         writeToFile("db.change.event.DROP", xml);         changeDetector.checkAgain(null);         sleep(500);         assertEquals("Number of message is wrong", 0, this.updateMap.size());      }      log.info("SUCCESS");   }   /**    * Dump to file.     * @param topic The file name body    * @param xml The file content    * @throws Exception IOException    */   public static void writeToFile(String topic, String xml) throws Exception {      java.io.File f = new java.io.File(System.getProperty("java.io.tmpdir")+System.getProperty("file.separator")+topic+".xml");      java.io.FileOutputStream to = new java.io.FileOutputStream(f);      to.write(xml.getBytes());      to.close();   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -