Package org.xmlBlaster.contrib.db

Examples of org.xmlBlaster.contrib.db.I_DbPool


    * Tests the same operations as already tested in TestSyncPart but with the complete Replication.
    *
    */
   public final void testNonAlphaCharOnTable() {
      log.info("Start testNonAlphaCharOnTable");
      I_DbPool pool = (I_DbPool)this.readerInfo.getObject("db.pool");
      assertNotNull("pool must be instantiated", pool);
      Connection conn = null;
      try {
         conn  = pool.reserve();
         conn.setAutoCommit(true);
         String sql = null;
         try {
            boolean force = false;
            String destination = null;
            boolean forceSend = false;
            TableToWatchInfo tableToWatch = new TableToWatchInfo(null, this.specificHelper.getOwnSchema(pool), tableName);
            tableToWatch.setActions("IDU");
            getDbSpecific().addTableToWatch(tableToWatch, force, new String[] { destination }, forceSend);
         }
         catch (Exception ex) {
            ex.printStackTrace();
            assertTrue("Testing if addition of table '" + tableName + "' to tables to replicate (" + this.replPrefix + "tables) succeeded: An exception should not occur here", false);
         }

         {
            try { // we explicitly choose a table without pk (to test searches)
               interceptor.clear();
               sql = "CREATE TABLE " + this.tableName + " (name VARCHAR(30), age INTEGER, address VARCHAR(30))";
               pool.update(sql);

               // Thread.sleep(this.sleepDelay);
               this.interceptor.waitOnUpdate(this.sleepDelay, 2);
               conn = pool.reserve();
               conn.setAutoCommit(true);
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
               }
               catch (Exception e) {
                  e.printStackTrace();
                  assertTrue("Testing '" + sql + "'. It resulted in an exception " + e.getMessage(), false);
               }
               assertEquals("Testing '" + sql + "' the number of columns returned", 3, rs.getMetaData().getColumnCount());
               assertEquals("Testing '" + sql + "' the table must be empty", false, rs.next());
               rs.close();
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'CREATE' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }

         {
            try {
               this.interceptor.clear();
               StringBuffer buf = new StringBuffer();
               buf.append((char)12);
               buf.append((char)13);
               String txt = buf.toString();
               sql = "INSERT INTO " + this.tableName + " (name, address) VALUES ('firstOne', '" + txt + "')";
               pool.update(sql);
               this.interceptor.waitOnUpdate(this.sleepDelay, 1);
               conn = pool.reserve();
               conn.setAutoCommit(true);
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
               }
               catch (Exception e) {
                  e.printStackTrace();
                  assertTrue("Testing '" + sql + "'. It resulted in an exception " + e.getMessage(), false);
               }
               assertEquals("Testing '" + sql + "' the number of columns returned", 3, rs.getMetaData().getColumnCount());
               assertEquals("Testing '" + sql + "' the table must not be empty", true, rs.next());
               String name = rs.getString(1);
               Object age = rs.getObject(2);
               String addr = rs.getString(3);
               assertEquals("Testing '" + sql + "' for the name of the entry", "firstOne", name);
               assertNull("Testing '" + sql + "' for the age of the entry", age);
               assertEquals("Testing '" + sql + "' for the address of the entry", txt, addr);
               rs.close();
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'INSERT' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }

         {
            try {
               this.interceptor.clear();
               sql = "DELETE FROM " + this.tableName;
               pool.update(sql);
               this.interceptor.waitOnUpdate(this.sleepDelay, 1);
               conn = pool.reserve();
               conn.setAutoCommit(true);
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
               }
               catch (Exception e) {
                  e.printStackTrace();
                  assertTrue("Testing '" + sql + "'. It resulted in an exception " + e.getMessage(), false);
               }
               assertEquals("Testing '" + sql + "' the number of columns returned", 3, rs.getMetaData().getColumnCount());
               assertEquals("Testing '" + sql + "' the table must be empty", false, rs.next());
               rs.close();
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'DELETE' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }
         {
            try {
               this.interceptor.clear();
               sql = "DROP TABLE " + this.tableName;
               pool.update(sql);
               this.interceptor.waitOnUpdate(this.sleepDelay, 1);
               conn = pool.reserve();
               conn.setAutoCommit(true);
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
                  assertTrue("Testing '" + sql + "'. It must have resulted in an exception but did not.", false);
               }
               catch (Exception e) {
               }
               finally {
                  if (rs != null)
                     rs.close();
                  rs = null;
               }
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'DROP' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }
      }
      catch (Exception ex) {
         ex.printStackTrace();
View Full Code Here


    *
    */
   public final void testAllCharBlobs() {
      log.info("Start testAllCharBlobs");
      interceptor.waitOnUpdate(sleepDelay, 1);
      I_DbPool pool = (I_DbPool)this.readerInfo.getObject("db.pool");
      assertNotNull("pool must be instantiated", pool);
      Connection conn = null;
      try {
         conn  = pool.reserve();
         conn.setAutoCommit(true);
         String sql = null;
         try {
            boolean force = false;
            String destination = null;
            boolean forceSend = false;
            TableToWatchInfo tableToWatch = new TableToWatchInfo(null, this.specificHelper.getOwnSchema(pool), tableName);
            tableToWatch.setActions("IDU");
            getDbSpecific().addTableToWatch(tableToWatch, force, new String[] { destination }, forceSend);
         }
         catch (Exception ex) {
            ex.printStackTrace();
            assertTrue("Testing if addition of table '" + tableName + "' to tables to replicate (" + this.replPrefix + "tables) succeeded: An exception should not occur here", false);
         }

         {
            try { // we explicitly choose a table without pk (to test searches)
               this.interceptor.clear();
               sql = "CREATE TABLE " + this.tableName + " (name VARCHAR(30), data BLOB)";
               pool.update(sql);
               this.interceptor.waitOnUpdate(this.sleepDelay, 1);
               conn = pool.reserve();
               conn.setAutoCommit(true);
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
               }
               catch (Exception e) {
                  e.printStackTrace();
                  assertTrue("Testing '" + sql + "'. It resulted in an exception " + e.getMessage(), false);
               }
               assertEquals("Testing '" + sql + "' the number of columns returned", 2, rs.getMetaData().getColumnCount());
               assertEquals("Testing '" + sql + "' the table must be empty", false, rs.next());
               rs.close();
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'CREATE' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }

         {
            try {
               this.interceptor.clear();
               conn = pool.reserve();
               conn.setAutoCommit(true);
               sql = "INSERT INTO " + this.tableName + " (name, data) VALUES (?, ?)";
               PreparedStatement ps = conn.prepareStatement(sql);

               ps.setString(1, "someName");
               // byte[] blob = new byte[65536];
               byte[] blob = new byte[70000];
               // byte[] blob = new byte[512];
               int length = blob.length;
               for (int i=0; i < length; i++)
                  blob[i] = (byte)i;
               ByteArrayInputStream bais = new ByteArrayInputStream(blob);
               ps.setBinaryStream(2, bais, length);
               this.interceptor.setVerbosity(1);
               ps.execute();
               this.interceptor.waitOnUpdate(1000*this.sleepDelay, 1);
               this.interceptor.setVerbosity(0);
               bais.close();
               conn = pool.reserve();
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
                  rs.next();
                  String name = rs.getString(1);
                  assertEquals("comparing the name", "someName", name);

                  InputStream is = rs.getBinaryStream(2);
                  byte[] buf = new byte[1000];
                  int val;
                  int sum = 0;
                  ByteArrayOutputStream baos = new ByteArrayOutputStream(length+128);
                  while ( (val=is.read(buf)) > -1) {
                     sum += val;
                     baos.write(buf, 0, val);
                  }
                  byte[] blob1 = baos.toByteArray();
                  is.close();
                  assertEquals("Comparing the size of the blob: ", length, sum);
                  assertEquals("Comparing the size of the blob (real compare): ", blob.length, blob1.length);
                  boolean error = false;
                  StringBuffer errBuf = new StringBuffer(1024);
                  for (int i=0; i < blob1.length; i++) {
                     if (blob1[i] != blob[i]) {
                        error = true;
                        String txt = "wrong entry at '" + i + "' is '" + blob1[i] + "' but should be '" + blob[i] + "'";
                        errBuf.append(txt).append("\n");
                        // assertTrue(txt, false);
                     }
                     if (error)
                        assertTrue(errBuf.toString(), false);
                  }
               }
               catch (Exception e) {
                  e.printStackTrace();
                  assertTrue("Testing '" + sql + "'. It resulted in an exception " + e.getMessage(), false);
               }
               rs.close();
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'INSERT' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }
         {
            try {
               this.interceptor.clear();
               sql = "DROP TABLE " + this.tableName;
               pool.update(sql);
               this.interceptor.waitOnUpdate(this.sleepDelay, 1);
               conn = pool.reserve();
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
                  assertTrue("Testing '" + sql + "'. It must have resulted in an exception but did not.", false);
               }
               catch (Exception e) {
               }
               finally {
                  if (rs != null)
                     rs.close();
                  rs = null;
               }
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'DROP' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }
      }
      catch (Exception ex) {
         ex.printStackTrace();
View Full Code Here

    *
    */
   public final void testAllCharVarchar() {
      log.info("Start testAllCharVarchar");
      interceptor.waitOnUpdate(sleepDelay, 1);
      I_DbPool pool = (I_DbPool)this.readerInfo.getObject("db.pool");
      assertNotNull("pool must be instantiated", pool);
      Connection conn = null;
      try {
         conn  = pool.reserve();
         conn.setAutoCommit(true);
         String sql = null;
         try {
            boolean force = false;
            String destination = null;
            boolean forceSend = false;
            TableToWatchInfo tableToWatch = new TableToWatchInfo(null, this.specificHelper.getOwnSchema(pool), tableName);
            tableToWatch.setActions("IDU");
            getDbSpecific().addTableToWatch(tableToWatch, force, new String[] { destination }, forceSend);
         }
         catch (Exception ex) {
            ex.printStackTrace();
            assertTrue("Testing if addition of table '" + tableName + "' to tables to replicate (" + this.replPrefix + "tables) succeeded: An exception should not occur here", false);
         }

         {
            try { // we explicitly choose a table without pk (to test searches)
               this.interceptor.clear();
               sql = "CREATE TABLE " + this.tableName + " (name VARCHAR(30), data VARCHAR(4000))";
               pool.update(sql);
               this.interceptor.waitOnUpdate(this.sleepDelay, 1);
               conn = pool.reserve();
               conn.setAutoCommit(true);
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
               }
               catch (Exception e) {
                  e.printStackTrace();
                  assertTrue("Testing '" + sql + "'. It resulted in an exception " + e.getMessage(), false);
               }
               assertEquals("Testing '" + sql + "' the number of columns returned", 2, rs.getMetaData().getColumnCount());
               assertEquals("Testing '" + sql + "' the table must be empty", false, rs.next());
               rs.close();
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'CREATE' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }

         {
            try {
               this.interceptor.clear();
               conn = pool.reserve();
               conn.setAutoCommit(true);
               sql = "INSERT INTO " + this.tableName + " (name, data) VALUES (?, ?)";
               PreparedStatement ps = conn.prepareStatement(sql);

               ps.setString(1, "someName");
               byte[] blob = new byte[2000];
               int length = blob.length;
               for (int i=0; i < length; i++) {
                  blob[i] = (byte)i;
                  if (blob[i] == 0)
                     blob[i] = 32;
               }
              
               String inString = new String(blob);
               ps.setString(2, inString);
               ps.execute();
               this.interceptor.waitOnUpdate(1000*this.sleepDelay, 1);
               conn = pool.reserve();

               Statement st = conn.createStatement();
               ResultSet rs = null;
               String refString = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName);
                  rs.next();
                  String name = rs.getString(1);
                  assertEquals("comparing the name", "someName", name);
                  refString = rs.getString(2);
                  assertEquals("Comparing the size of the blob: ", inString.length(), refString.length());
               }
               catch (Exception e) {
                  e.printStackTrace();
                  assertTrue("Testing '" + sql + "'. It resulted in an exception " + e.getMessage(), false);
               }
               rs.close();
               st.close();
              
               st = conn.createStatement();
               rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
                  rs.next();
                  String name = rs.getString(1);
                  assertEquals("comparing the name", "someName", name);

                  String outString = rs.getString(2);
                  assertEquals("Comparing the size of the blob: ", refString.length(), outString.length());
                  assertEquals("", refString, outString);
               }
               catch (Exception e) {
                  e.printStackTrace();
                  assertTrue("Testing '" + sql + "'. It resulted in an exception " + e.getMessage(), false);
               }
               rs.close();
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'INSERT' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }
         {
            try {
               this.interceptor.clear();
               sql = "DROP TABLE " + this.tableName;
               pool.update(sql);
               this.interceptor.waitOnUpdate(this.sleepDelay, 1);
               conn = pool.reserve();
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
                  assertTrue("Testing '" + sql + "'. It must have resulted in an exception but did not.", false);
               }
               catch (Exception e) {
               }
               finally {
                  if (rs != null)
                     rs.close();
                  rs = null;
               }
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'DROP' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }
      }
      catch (Exception ex) {
         ex.printStackTrace();
View Full Code Here

    *
    */
   public final void testBigBlobs() {
      log.info("Start testBigBlobs");
      interceptor.waitOnUpdate(sleepDelay, 1);
      I_DbPool pool = (I_DbPool)this.readerInfo.getObject("db.pool");
      assertNotNull("pool must be instantiated", pool);
      Connection conn = null;
      try {
         conn  = pool.reserve();
         conn.setAutoCommit(true);
         String sql = null;
         try {
            boolean force = false;
            String destination = null;
            boolean forceSend = false;
            TableToWatchInfo tableToWatch = new TableToWatchInfo(null, this.specificHelper.getOwnSchema(pool), tableName);
            tableToWatch.setActions("IDU");
            getDbSpecific().addTableToWatch(tableToWatch, force, new String[] { destination }, forceSend);
         }
         catch (Exception ex) {
            ex.printStackTrace();
            assertTrue("Testing if addition of table '" + tableName + "' to tables to replicate (" + this.replPrefix + "tables) succeeded: An exception should not occur here", false);
         }

         {
            try { // we explicitly choose a table without pk (to test searches)
               this.interceptor.clear();
               sql = "CREATE TABLE " + this.tableName + " (name VARCHAR(30), data BLOB)";
               pool.update(sql);
               this.interceptor.waitOnUpdate(this.sleepDelay, 1);
               conn = pool.reserve();
               conn.setAutoCommit(true);
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
               }
               catch (Exception e) {
                  e.printStackTrace();
                  assertTrue("Testing '" + sql + "'. It resulted in an exception " + e.getMessage(), false);
               }
               assertEquals("Testing '" + sql + "' the number of columns returned", 2, rs.getMetaData().getColumnCount());
               assertEquals("Testing '" + sql + "' the table must be empty", false, rs.next());
               rs.close();
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'CREATE' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }

         {
            try {
               this.interceptor.clear();
               conn = pool.reserve();
               conn.setAutoCommit(true);
               sql = "INSERT INTO " + this.tableName + " (name, data) VALUES (?, ?)";
               PreparedStatement ps = conn.prepareStatement(sql);

               ps.setString(1, "someName");
               byte[] blob = new byte[4096];
               int sweeps = 10240; // 40 MB

               int length = blob.length * sweeps;
               PipedInputStream pi = new PipedInputStream();
               PipedOutputStream po = new PipedOutputStream(pi);
               ps.setBinaryStream(2, pi, length);

               Pusher pusher = new Pusher(sweeps, blob, po);
               pusher.start();
               ps.execute();
               ps.close();
               pusher.join();
               ps = null;

               this.interceptor.waitOnUpdate(1000*this.sleepDelay, 1);

               conn = pool.reserve();
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
                  rs.next();
                  String name = rs.getString(1);
                  assertEquals("comparing the name", "someName", name);

                  InputStream is = rs.getBinaryStream(2);
                  byte[] buf = new byte[1000];
                  int val;
                  int sum = 0;
                  while ( (val=is.read(buf)) > -1) {
                     sum += val;
                  }
                  is.close();
                  assertEquals("Comparing the size of the blob: ", length, sum);
               }
               catch (Exception e) {
                  e.printStackTrace();
                  assertTrue("Testing '" + sql + "'. It resulted in an exception " + e.getMessage(), false);
               }
               rs.close();
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'INSERT' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }
         {
            try {
               this.interceptor.clear();
               sql = "DROP TABLE " + this.tableName;
               pool.update(sql);
               this.interceptor.waitOnUpdate(this.sleepDelay, 1);
               conn = pool.reserve();
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
                  assertTrue("Testing '" + sql + "'. It must have resulted in an exception but did not.", false);
               }
               catch (Exception e) {
               }
               finally {
                  if (rs != null)
                     rs.close();
                  rs = null;
               }
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'DROP' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }
      }
      catch (Exception ex) {
         ex.printStackTrace();
View Full Code Here

      // we use the writerInfo since this will not instantiate an publisher
      I_Info tmpInfo =  new PropertiesInfo((Properties)this.specificHelper.getProperties().clone());
      setupProperties(null, tmpInfo, extraUser);
      boolean forceCreationAndInit = true;
      I_DbSpecific dbSpecific = ReplicationConverter.getDbSpecific(tmpInfo, forceCreationAndInit);
      I_DbPool pool = (I_DbPool)tmpInfo.getObject("db.pool");

      DbInfo persistentInfo = new DbInfo(pool, "replication", tmpInfo);
      String name = readerInfo.get("replication.prefix", "repl_") + ".oldReplKey";
      persistentInfo.put(name, "0");

      Connection conn = null;
      try {
         this.dbHelper = new DbMetaHelper(pool);
         conn = pool.reserve();
         boolean doWarn = false; // we don't want warnings on SQL Exceptions here.
         log.info("setUp: going to cleanup now ...");
         this.sleepDelay = this.readerInfo.getLong("test.sleepDelay", -1L);
         if (this.sleepDelay < 0L)
            this.sleepDelay = 25000L;
         log.info("setUp: The sleep delay will be '" + this.sleepDelay + "' ms");
         try {
            dbSpecific.cleanup(conn, doWarn);
         }
         catch (Exception e) {
            e.printStackTrace();
         }
         try {
            pool.update("DROP TABLE " + this.tableName);
         }
         catch (Exception e) {
         }
         try {
            pool.update("DROP TABLE " + this.tableName2);
         }
         catch (Exception e) {
         }
         for (int i=1; i < 5; i++) { // make sure we have deleted all triggers
            try {
               pool.update("DROP TRIGGER " + this.replPrefix + i);
            }
            catch (Exception ex) {
            }
         }
         log.info("setUp: cleanup done, going to bootstrap now ...");
         boolean force = true;
         dbSpecific.bootstrap(conn, doWarn, force);
         dbSpecific.shutdown();
         dbSpecific = null;
         tmpInfo = null;
      }
      catch (Exception ex) {
         if (dbSpecific != null) {
            try {
               dbSpecific.shutdown();
               dbSpecific = null;
            }
            catch (Exception e1) {
            }
         }
         if (pool != null) {
            pool.shutdown();
            pool = null;
         }
         if (conn != null && pool != null)
            pool.release(conn);
      }

      log.info("setUp: Instantiating");
      this.agent = new ReplicationAgent();
      this.agent.init(this.readerInfo, this.writerInfo);
View Full Code Here

    */
   public final void testCreateAndInsert() throws Exception {
      log.info("Start");

      interceptor.waitOnUpdate(sleepDelay, 1);
      I_DbPool pool = (I_DbPool)this.readerInfo.getObject("db.pool");
      assertNotNull("pool must be instantiated", pool);
      Connection conn = null;
      try {
         conn  = pool.reserve();
         try {
            pool.update("DROP TABLE " + this.tableName + this.specificHelper.getCascade());
         }
         catch (Exception ex) {
            conn = pool.reserve();
         }
         try {
            pool.update("DROP TABLE " + this.tableName2 + this.specificHelper.getCascade()); // This is the replica
         }
         catch (Exception ex) {
            conn = pool.reserve();
         }

         // verifying
         try {
            ResultSet rs = conn.getMetaData().getTables(null, this.specificHelper.getOwnSchema(pool), this.dbHelper.getIdentifier(this.tableName), null);
            assertFalse("Testing if the tables have been cleaned up. The table '" + this.tableName + "' is still here", rs.next()); // should be empty
            rs.close();
         }
         catch (Exception ex) {
            ex.printStackTrace();
            assertTrue("Testing that the tables have been cleaned up correctly. An exception shall not occur here", false);
         }

         try {
            ResultSet rs = conn.getMetaData().getTables(null, this.specificHelper.getOwnSchema(pool), this.dbHelper.getIdentifier(this.tableName2), null);
            assertFalse("Testing if the tables have been cleaned up. The table '" + tableName2 + "' is still here", rs.next()); // should be empty
            rs.close();
         }
         catch (Exception ex) {
            ex.printStackTrace();
            assertTrue("Testing that the tables have been cleaned up correctly. An exception shall not occur here", false);
         }

         try {
            boolean force = false;
            String destination = null;
            boolean forceSend = false;
            TableToWatchInfo tableToWatch = new TableToWatchInfo(null, this.specificHelper.getOwnSchema(pool), tableName);
            tableToWatch.setActions("IDU");
            getDbSpecific().addTableToWatch(tableToWatch, force, new String[] { destination }, forceSend);
         }
         catch (Exception ex) {
            ex.printStackTrace();
            assertTrue("Testing if addition of table '" + tableName + "' to tables to replicate (" + this.replPrefix + "tables) succeeded: An exception should not occur here", false);
         }
         this.interceptor.clear();
         String sql = "CREATE TABLE " + tableName + "(name VARCHAR(20), city VARCHAR(15), PRIMARY KEY (name))";
         pool.update(sql);

         sql = "INSERT INTO " + tableName + " (name, city) VALUES ('michele', 'caslano')";
         pool.update(sql);

         /* The DbWatcher shall now detect a table creation and an insert (after maximum two seconds)
          * here the xmlBlaster must run to allow the DbWatcher publish the messages.
          * The DbWriter shall receive the messages it subscribed to and the replica shall be created and filled.
          */

         this.interceptor.waitOnUpdate(this.sleepDelay, 2);
         // a new table must have been created ...
         conn = pool.reserve();
         ResultSet rs = conn.getMetaData().getTables(null, this.specificHelper.getOwnSchema(pool), this.dbHelper.getIdentifier(this.tableName2), null);
         boolean isThere = rs.next();
         log.info("the replicated table is " + (isThere ? "" : "not ") + "there");

         assertTrue("the copy of the table has not been created", isThere);
View Full Code Here

    */
   public final void testPerformAllOperationsOnTable() {

      log.info("Start testPerformAllOperationsOnTable");
      interceptor.waitOnUpdate(sleepDelay, 1);
      I_DbPool pool = (I_DbPool)this.readerInfo.getObject("db.pool");
      assertNotNull("pool must be instantiated", pool);
      Connection conn = null;
      try {
         conn  = pool.reserve();
         conn.setAutoCommit(true);
         String sql = null;
         try {
            boolean force = false;
            String destination = null;
            boolean forceSend = false;
            TableToWatchInfo tableToWatch = new TableToWatchInfo(null, this.specificHelper.getOwnSchema(pool), tableName);
            tableToWatch.setActions("IDU");
            getDbSpecific().addTableToWatch(tableToWatch, force, new String[] { destination }, forceSend);
         }
         catch (Exception ex) {
            ex.printStackTrace();
            assertTrue("Testing if addition of table '" + tableName + "' to tables to replicate (" + this.replPrefix + "tables) succeeded: An exception should not occur here", false);
         }

         {
            try {
               this.interceptor.clear();
               sql = "CREATE TABLE " + this.tableName + " (name VARCHAR(20), age INTEGER, PRIMARY KEY(name))";
               pool.update(sql);
               this.interceptor.waitOnUpdate(this.sleepDelay, 1);
               conn = pool.reserve();
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
               }
               catch (Exception e) {
                  e.printStackTrace();
                  assertTrue("Testing '" + sql + "'. It resulted in an exception " + e.getMessage(), false);
               }
               assertEquals("Testing '" + sql + "' the number of columns returned", 2, rs.getMetaData().getColumnCount());
               assertEquals("Testing '" + sql + "' the table must be empty", false, rs.next());
               rs.close();
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'CREATE' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }

         {
            try {
               this.interceptor.clear();
               sql = "INSERT INTO " + this.tableName + " VALUES ('first', 44)";
               pool.update(sql);
               this.interceptor.waitOnUpdate(this.sleepDelay, 1);
               conn = pool.reserve();
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
               }
               catch (Exception e) {
                  e.printStackTrace();
                  assertTrue("Testing '" + sql + "'. It resulted in an exception " + e.getMessage(), false);
               }
               assertEquals("Testing '" + sql + "' the number of columns returned", 2, rs.getMetaData().getColumnCount());
               assertEquals("Testing '" + sql + "' the table must not be empty", true, rs.next());
               String name = rs.getString(1);
               int age = rs.getInt(2);
               assertEquals("Testing '" + sql + "' for the name of the entry", "first", name);
               assertEquals("Testing '" + sql + "' for the age of the entry", 44, age);
               rs.close();
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'INSERT' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }

         {
            try {
               this.interceptor.clear();
               sql = "UPDATE " + this.tableName + " SET age=33 WHERE name='first'";
               pool.update(sql);
               this.interceptor.waitOnUpdate(this.sleepDelay, 1);
               conn = pool.reserve();
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
               }
               catch (Exception e) {
                  e.printStackTrace();
                  assertTrue("Testing '" + sql + "'. It resulted in an exception " + e.getMessage(), false);
               }
               assertEquals("Testing '" + sql + "' the number of columns returned", 2, rs.getMetaData().getColumnCount());
               assertEquals("Testing '" + sql + "' the table must not be empty", true, rs.next());
               String name = rs.getString(1);
               int age = rs.getInt(2);
               assertEquals("Testing '" + sql + "' for the name of the entry", "first", name);
               assertEquals("Testing '" + sql + "' for the age of the entry", 33, age);
               rs.close();
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'UPDATE' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }

         {
            try {
               this.interceptor.clear();
               sql = "DELETE FROM " + this.tableName;
               pool.update(sql);
               this.interceptor.waitOnUpdate(this.sleepDelay, 1);
               conn = pool.reserve();
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
               }
               catch (Exception e) {
                  e.printStackTrace();
                  assertTrue("Testing '" + sql + "'. It resulted in an exception " + e.getMessage(), false);
               }
               assertEquals("Testing '" + sql + "' the number of columns returned", 2, rs.getMetaData().getColumnCount());
               assertEquals("Testing '" + sql + "' the table must be empty", false, rs.next());
               rs.close();
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'DELETE' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }

         {
            try {
               this.interceptor.clear();
               sql = "ALTER TABLE " + this.tableName + " ADD (city VARCHAR(30))";
               pool.update(sql);
               this.interceptor.waitOnUpdate(this.sleepDelay, 1);
               conn = pool.reserve();
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
               }
               catch (Exception e) {
                  e.printStackTrace();
                  assertTrue("Testing '" + sql + "'. It resulted in an exception " + e.getMessage(), false);
               }
               // TODO ACTIVATE THIS ONCE ALTER IS IMPLEMENTED ON THE WRITER
               // assertEquals("Testing '" + sql + "' the number of columns returned", 2, rs.getMetaData().getColumnCount());
               assertEquals("Testing '" + sql + "' the table must be empty", false, rs.next());
               rs.close();
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'ALTER' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }
         {
            try {
               this.interceptor.clear();
               sql = "DROP TABLE " + this.tableName;
               pool.update(sql);
               this.interceptor.waitOnUpdate(this.sleepDelay, 1);
               conn = pool.reserve();
               Statement st = conn.createStatement();
               ResultSet rs = null;
               try {
                  rs = st.executeQuery("SELECT * from " + this.tableName2);
                  assertTrue("Testing '" + sql + "'. It must have resulted in an exception but did not.", false);
               }
               catch (Exception e) {
               }
               finally {
                  if (rs != null)
                     rs.close();
                  rs = null;
               }
               st.close();
            }
            catch (Exception e) {
               e.printStackTrace();
               assertTrue("Exception when testing operation 'DROP' should not have happened: " + e.getMessage(), false);
            }
            finally {
               if (conn != null)
                  pool.release(conn);
            }
         }
      }
      catch (Exception ex) {
         ex.printStackTrace();
View Full Code Here

      String txt = "testTableToWatchInfoForAllToken";
      log.info("Start " + txt);
      try {
         SpecificHelper specificHelper = new SpecificHelper(System.getProperties());
         I_Info info = new PropertiesInfo(specificHelper.getProperties());
         I_DbPool dbPool = setUpDbPool(info);
         Connection conn = dbPool.reserve();
         info.put("table.XMLBLASTER.*", "");
         TableToWatchInfo[] tables = TableToWatchInfo.getTablesToWatch(conn, info);
         assertTrue("wrong number of tables", tables.length > 0);
         for (int i=0; i < tables.length; i++) {
            log.info(tables[i].toXml());
         }
         dbPool.release(conn);
      }
      catch (Exception ex) {
         ex.printStackTrace();
         fail("An exception should not occur in " + txt);
      }
View Full Code Here

TOP

Related Classes of org.xmlBlaster.contrib.db.I_DbPool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.