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

📄 testsyncpart.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                  this.pool.release(conn);            }         }         {            try {               sql = "DROP TABLE " + this.tableName;               pool.update(sql);               Thread.sleep(500L);               conn = this.pool.reserve();               Statement st = conn.createStatement();               ResultSet rs = st.executeQuery("SELECT * from " + this.replPrefix + "items");               assertEquals("Testing DROP table '" + this.tableName + "' checking that the operation generated an entry in " + this.replPrefix + "items", true, rs.next());               String transKey = rs.getString(2);               String tableName = rs.getString(4);               String dbAction = rs.getString(6);               assertEquals("Testing the content of the action", "DROP", dbAction);               assertNotNull("Testing that the transaction is not null", transKey);               assertEquals("Testing that the table name is correct", this.dbHelper.getIdentifier(this.tableName), tableName);               this.pool.update("DELETE from " + this.replPrefix + "items");            }            catch (Exception e) {               e.printStackTrace();               assertTrue("Exception when testing operation 'DROP' should not have happened: " + e.getMessage(), false);            }            finally {               if (conn != null)                  this.pool.release(conn);            }         }      }      catch (Exception ex) {         ex.printStackTrace();         assertTrue("an exception should not occur " + ex.getMessage(), false);      }      log.info("SUCCESS");   }   /**    *    */   public final void testDateFormat() {      log.info("Start testDifferentFormats");      I_DbPool pool = (I_DbPool)info.getObject("db.pool");      assertNotNull("pool must be instantiated", pool);      Connection conn = null;      try {         conn  = pool.reserve();         conn.setAutoCommit(true);         String sql = null;         sql = "CREATE TABLE " + this.tableName + " (first DATE, PRIMARY KEY(first))";         pool.update(sql);         this.dbSpecific.readNewTable(null, this.specificHelper.getOwnSchema(this.pool), this.dbHelper.getIdentifier(this.tableName), null, true);         try {            this.pool.update("DELETE from " + this.replPrefix + "items");            // long time = System.currentTimeMillis();            // Date date = new Date(time);            // String txt = "YYYY-MM-DD HH24:MI:SS"            String txt = "2005-11-05 23:04:31.345";            DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");            long time = format.parse(txt).getTime();            Date date = new Date(time);            System.out.println("Date: '" + time + "' is '" + date.toString() + "' and again as millis: '" + date.getTime());            PreparedStatement st1 = conn.prepareStatement("INSERT INTO " + this.tableName + " VALUES (?)");            st1.setDate(1, date);            st1.executeUpdate();            st1.close();            st1 = null;            st1 = conn.prepareStatement("SELECT * FROM " + tableName);            ResultSet rs = st1.executeQuery();            rs.next();            Date date1 = rs.getDate(1);            System.out.println("Date after taking it out from DB: '" + date1.getTime() + "'");            System.out.println("Date diff: " + (date1.getTime() - date.getTime()));            rs.close();            st1.close();            Thread.sleep(500L);            Statement st2 = conn.createStatement();            rs = st2.executeQuery("SELECT * from " + this.replPrefix + "items ORDER BY repl_key");            assertEquals("Testing creation of table '" + this.tableName + "' checking that the operation generated an entry in " + this.replPrefix + "items", true, rs.next());            InputStream content = rs.getAsciiStream(9);            byte[] tmp = new byte[10000];            content.read(tmp);            String val = new String(tmp);            System.out.println("!!!!!! Result of a date is '" + val + "'");            this.pool.update("DROP TABLE " + this.tableName);            this.pool.update("DELETE from " + this.replPrefix + "items");         }         catch (Exception e) {            e.printStackTrace();            assertTrue("Exception when testing operation 'CREATE' should not have happened: " + e.getMessage(), false);         }         finally {            if (conn != null)               this.pool.release(conn);         }      }      catch (Exception ex) {         ex.printStackTrace();         assertTrue("an exception should not occur " + ex.getMessage(), false);      }      log.info("SUCCESS");   }   /**    *    */   public final void testTimestampFormat() {      log.info("Start testDifferentFormats");      I_DbPool pool = (I_DbPool)info.getObject("db.pool");      assertNotNull("pool must be instantiated", pool);      Connection conn = null;      try {         conn  = pool.reserve();         conn.setAutoCommit(true);         String sql = null;         String type = "TIMESTAMP";         // TODO remove this after testing         type = "DATE";         sql = "CREATE TABLE " + this.tableName + " (first " + type + ", PRIMARY KEY(first))";         pool.update(sql);         this.dbSpecific.readNewTable(null, this.specificHelper.getOwnSchema(this.pool), this.dbHelper.getIdentifier(this.tableName), null, true);         try {            this.pool.update("DELETE from " + this.replPrefix + "items");            // long time = System.currentTimeMillis();            // Date date = new Date(time);            // String txt = "YYYY-MM-DD HH24:MI:SS"            String txt = "2005-11-05 23:04:31";            try {               Timestamp ts = Timestamp.valueOf(txt);               long millis = ts.getTime();               long nanos = ts.getNanos();               System.out.println("'" + txt + "' gave millis='" + millis + "' and nanos='" + nanos + "'");            }            catch (IllegalArgumentException e) {               assertTrue("An exception should not occur when parsing '" + txt + "'", false);            }            txt = "2005-11-05 23:04:31.1";            try {               Timestamp ts = Timestamp.valueOf(txt);               long millis = ts.getTime();               long nanos = ts.getNanos();               System.out.println("'" + txt + "' gave millis='" + millis + "' and nanos='" + nanos + "'");            }            catch (IllegalArgumentException e) {               assertTrue("An exception should not occur when parsing '" + txt + "'", false);            }            txt = "2005-11-05 23:04:31.1000";            try {               Timestamp ts = Timestamp.valueOf(txt);               long millis = ts.getTime();               long nanos = ts.getNanos();               System.out.println("'" + txt + "' gave millis='" + millis + "' and nanos='" + nanos + "'");            }            catch (IllegalArgumentException e) {               assertTrue("An exception should not occur when parsing '" + txt + "'", false);            }            txt = "2005-11-05 23:04:31.1000000";            try {               Timestamp ts = Timestamp.valueOf(txt);               long millis = ts.getTime();               long nanos = ts.getNanos();               System.out.println("'" + txt + "' gave millis='" + millis + "' and nanos='" + nanos + "'");            }            catch (IllegalArgumentException e) {               assertTrue("An exception should not occur when parsing '" + txt + "'", false);            }            txt = "2005-11-05 23:04:31.100000000";            try {               Timestamp ts = Timestamp.valueOf(txt);               long millis = ts.getTime();               long nanos = ts.getNanos();               System.out.println("'" + txt + "' gave millis='" + millis + "' and nanos='" + nanos + "'");            }            catch (IllegalArgumentException e) {               assertTrue("An exception should not occur when parsing '" + txt + "'", false);            }            txt = "2005-11-05 23:04:31.999999999";            try {               Timestamp ts = Timestamp.valueOf(txt);               long millis = ts.getTime();               long nanos = ts.getNanos();               System.out.println("'" + txt + "' gave millis='" + millis + "' and nanos='" + nanos + "'");            }            catch (IllegalArgumentException e) {               assertTrue("An exception should not occur when parsing '" + txt + "'", false);            }            DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");            long time = format.parse(txt).getTime();            Timestamp date = new Timestamp(time);            date.setNanos(999);            System.out.println("Date: '" + time + "' is '" + date.toString() + "' and again as millis: '" + date.getTime());            PreparedStatement st1 = conn.prepareStatement("INSERT INTO " + this.tableName + " VALUES (?)");            st1.setTimestamp(1, date);            st1.executeUpdate();            st1.close();            st1 = null;            // Timestamp. timestamp = new Timestamp();            st1 = conn.prepareStatement("SELECT * FROM " + tableName);            ResultSet rs = st1.executeQuery();            rs.next();            Timestamp date1 = rs.getTimestamp(1);            System.out.println("Date after taking it out from DB: '" + date1.getTime() + "'");            System.out.println("Date diff: " + (date1.getTime() - date.getTime()));            rs.close();            st1.close();            Thread.sleep(500L);            Statement st2 = conn.createStatement();            rs = st2.executeQuery("SELECT * from " + this.replPrefix + "items ORDER BY repl_key");            assertEquals("Testing creation of table '" + this.tableName + "' checking that the operation generated an entry in " + this.replPrefix + "items", true, rs.next());            InputStream content = rs.getAsciiStream(9);            byte[] tmp = new byte[10000];            content.read(tmp);            String val = new String(tmp);            System.out.println("!!!!!! Result of a date is '" + val + "'");            this.pool.update("DROP TABLE " + this.tableName);            this.pool.update("DELETE from " + this.replPrefix + "items");         }         catch (Exception e) {            e.printStackTrace();            assertTrue("Exception when testing operation 'CREATE' should not have happened: " + e.getMessage(), false);         }         finally {            if (conn != null)               this.pool.release(conn);         }      }      catch (Exception ex) {         ex.printStackTrace();         assertTrue("an exception should not occur " + ex.getMessage(), false);      }      log.info("SUCCESS");   }   /**    * @see org.xmlBlaster.contrib.I_ContribPlugin#getUsedPropertyKeys()    */   public Set getUsedPropertyKeys() {      return new HashSet();   }   public void init(I_Info info) throws Exception {   }   public String publish(String changeKey, byte[] message, Map attrMap) throws Exception {      log.info(new String(message));      return null;   }   public boolean registerAlertListener(I_Update momCb, Map attrs) throws Exception {      return false;   }   public void shutdown() {   }   /**    * @see org.xmlBlaster.contrib.I_ChangePublisher#getJmsSession()    */   public XBSession getJmsSession() {      return null;   }}

⌨️ 快捷键说明

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