Package org.teiid.test.framework.query

Examples of org.teiid.test.framework.query.AbstractQueryTransactionTest


     * Batching = Full Processing, Single Connector Batch
     * result = commit
     */
    @Test
    public void testMultipleSourcePreparedUpdate() throws Exception {
        AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourcePreparedUpdate") {
            public void testCase() throws Exception {
                Integer value = new Integer(500);
                execute("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2) values(?,?,?,?)", new Object[] {value, value.toString(), value, value.toString()});
            }
        };       
       
        // run test
        getTransactionContainter().runTransaction(userTxn);      
       
        // now verify the results
        AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
        test.execute("select * from g1 where e1 = 500");
        test.assertRowCount(1);
       
        test = new QueryExecution(userTxn.getSource("pm2"));
        test.execute("select * from g1 where e1 = 500");
        test.assertRowCount(1);
     
    }   
View Full Code Here


     * Batching = Full Processing, Single Connector Batch
     * result = commit
     */
    @Test
    public void testMultipleSourceMultipleCommands() throws Exception {
        AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourceMultipleCommands") {
            public void testCase() throws Exception {
                execute("delete from pm1.g2 where e1 >= ?", new Object[] {new Integer(100)});
                execute("delete from pm1.g1 where e1 >= ?", new Object[] {new Integer(100)});
                execute("delete from pm2.g2 where e1 >= ?", new Object[] {new Integer(100)});
                execute("delete from pm2.g1 where e1 >= ?", new Object[] {new Integer(100)});
               
                execute("select * from pm1.g1");
                assertRowCount(100);
               
                for (int i = 100; i < 115; i++) {
                    Integer val = new Integer(i);
                    execute("insert into pm1.g1 (e1, e2) values(?,?)", new Object[] {val, val.toString()});
                    execute("insert into pm1.g2 (e1, e2) values(?,?)", new Object[] {val, val.toString()});
                   
                    execute("insert into pm2.g1 (e1, e2) values(?,?)", new Object[] {val, val.toString()});
                    execute("insert into pm2.g2 (e1, e2) values(?,?)", new Object[] {val, val.toString()});                   
                }
               
                execute("update pm1.g1 set e2='blah' where e1 > 100");
            }
        };       
       
        // run test
        getTransactionContainter().runTransaction(userTxn);     

        // now verify the results
        AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1")) {
      protected boolean compareCaseSensitive() {
    return false;
      }
        };
        test.execute("select * from g1 where e1 >= 100 and e1 < 115");
        test.assertRowCount(15);
        test.execute("select * from g2 where e1 >= 100 and e1 < 115");
        test.assertRowCount(15);
        test.execute("select distinct e2 from g1 where e1 > 100");
       
        // NOTE:  if this is an oracle source, it failes because it return varchar2
        if (userTxn.getSource("pm1").getMetaData().getDatabaseProductName().toLowerCase().indexOf("oracle") > -1) {
            test.assertResultsSetEquals(new String[] {"e2[varchar2]", "blah"});
        } else {
            test.assertResultsSetEquals(new String[] {"e2[varchar]", "blah"});
        }
    
View Full Code Here

     * Batching = Full Processing, Single Connector Batch
     * result = commit
     */
    @Test
    public void testMultipleSourceMultipleVirtualCommands() throws Exception {
        AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourceMultipleVirtualCommands") {
            public void testCase() throws Exception {

                for (int i = 200; i < 207; i++) {
                    Integer val = new Integer(i);
                    execute("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2) values(?,?,?,?)", new Object[] {val, val.toString(), val, val.toString()});
                    execute("insert into vm.g2 (pm1e1, pm1e2, pm2e1, pm2e2) values(?,?,?,?)", new Object[] {val, val.toString(), val, val.toString()});                   
                }
               
                execute("update vm.g1 set pm1e2='blah' where pm1e1 >= 200");
               
                execute("delete from vm.g2 where vm.g2.pm1e1 >= 205");
                execute("delete from vm.g1 where vm.g1.pm1e1 >= 205");
               
                execute("select * from vm.g1 where pm1e1 >= 200 and pm1e1 < 207");
                assertRowCount(5);
            }
        };       
       
        // run test
        getTransactionContainter().runTransaction(userTxn);     

        // now verify the results
        AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1")){
      protected boolean compareCaseSensitive() {
    return false;
      }
        };
        test.execute("select * from g1 where e1 >= 200 and e1 < 207");
View Full Code Here

     * Batching = Full Processing, Single Connector Batch
     * result = rollback
     */   
    @Test
    public void testMultipleSourceMultipleCommandsCancel() throws Exception {
        AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourceMultipleCommandsCancel") {
           
            public void testCase() throws Exception {
                Thread t = new Thread("Cancel Thread") {
                    public void run() {
                        try {
                            try {
                                Thread.sleep(500);
                                cancelQuery();
                            } catch (SQLException e) {
                         //       debug(e.getMessage());
                            }
                        } catch (InterruptedException e) {}
                    }
                };
                t.start();
                executeBatch(getMultipleSourceBatch());
            }
          

            public boolean exceptionExpected() {
                return true;
            }
        };
        getTransactionContainter().runTransaction(userTxn);
               
        // now verify the results (this may finish under one second, then this test is not valid)
        AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
        test.execute("select * from g1 where e1 >= 600 and e1 < 650");
        test.assertRowCount(0);
        test.execute("select * from g2 where e1 >= 600 and e1 < 650");
        test.assertRowCount(0);
        test.execute("select distinct e2 from g1 where e1 >= 600 and e1 < 650");
View Full Code Here

     * Batching = Full Processing, Single Connector Batch
     * result = rollback
     */   
    @Test
    public void testMultipleSourceTimeout() throws Exception{
        AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourceTimeout") {
            public void testCase() throws Exception {
                executeBatch(getMultipleSourceBatch(), 1); // time out after 1 sec
            }
           
            public boolean exceptionExpected() {
                return true;
            }           
           
            public void after() {
                if (!exceptionOccurred()) {
                     Assert.assertTrue("should have failed with time out exception", false );
                }
                else {
                    if (getLastException() != null) {
                                                       
                  String msg = "NA";
                   SQLException s = getLastException();
                  
                   Throwable t = s.getCause();
                   if (t instanceof TimeoutException) {
                      msg = t.getMessage();
                   } else if (s instanceof TeiidSQLException) {
                      TeiidSQLException mm = (TeiidSQLException) t;
                        if (mm.getNextException() != null) {
                      SQLException next = mm.getNextException();
                      msg = next.getMessage();
                        } else {
                      msg = mm.getMessage();
                        }
                   } else {
                  
                       msg = s.getMessage();
                   }
                   boolean isfound = (msg.indexOf("Operation timed out before completion") != -1 ? true : false);

                   Assert.assertTrue("Exception Message didnt match 'Operation timed out before completion' found: " + msg, isfound );
                    } else {
                  Assert.assertTrue("Program Error: it indicates exception occured, but no exception is found", false );
                    }
                }
            }            
        };
        getTransactionContainter().runTransaction(userTxn);
       
        // now verify the results (this may finish under one second, then this test is not valid)
        AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
        test.execute("select * from g1 where e1 >= 600 and e1 < 750");
        test.assertRowCount(0);
        test.execute("select * from g2 where e1 >= 600 and e1 < 750");
        test.assertRowCount(0);
        test.execute("select distinct e2 from g1 where e1 >= 600 and e1 < 750");
View Full Code Here

     * Note: This is producing the below error some times; however this is SQL Server issue.
     * http://support.microsoft.com/?kbid=834849
     */
    @Test
    public void testMultipleSourcePartialProcessingUsingLimit() throws Exception {
        AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourcePartialProcessingUsingLimit") {
            public void testCase() throws Exception {
                execute("select * from vm.g1 where pm1e1 < 100 limit 10");
                assertRowCount(10);
            }
        };       
View Full Code Here

     * Note: This is producing the below error some times; however this is SQL Server issue.
     * http://support.microsoft.com/?kbid=834849
     */
    @Test
    public void testMultipleSourcePartialProcessingUsingMakedep() throws Exception {
        AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest("testMultipleSourcePartialProcessingUsingMakedep") {
            public void testCase() throws Exception {
                execute("select pm1.g1.e1, pm1.g1.e2 from pm1.g1 LEFT OUTER JOIN pm2.g1 MAKENOTDEP ON pm1.g1.e2 = pm2.g1.e2 where pm2.g1.e1 >= 50 and pm2.g1.e1 < 100");
                assertRowCount(50);
            }
        };       
View Full Code Here

     * Single Connector Batch result = rollback
     */
    @Test
    public void testSingleSourceMultipleCommandsReferentialIntegrityRollback()
      throws Exception {
  AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest(
    "testSingleSourceMultipleCommandsReferentialIntegrityRollback") {
      public void testCase() throws Exception {
    for (int i = 200; i < 210; i++) {
        Integer val = new Integer(i);
        execute("insert into pm1.g1 (e1, e2) values(?,?)",
          new Object[] { val, val.toString() });
        execute("insert into pm1.g2 (e1, e2) values(?,?)",
          new Object[] { val, val.toString() });
    }

    // try to rollback, however since this autocommit=on above two
    // are already commited
    execute("insert into pm1.g2 (e1, e2) values(?,?)",
      new Object[] { new Integer(9999), "9999" });
      }

      public boolean exceptionExpected() {
    return true;
      }
  };

  // run test
  getTransactionContainter().runTransaction(userTxn);

  // now verify the results
  AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
  test.execute("select * from g1 where e1 >= 200 and e1 < 210");
  test.assertRowCount(10);
  test.execute("select * from g2 where e1 = 9999");
  test.assertRowCount(0);
    }
View Full Code Here

     * Single Connector Batch result = rollback
     */
    @Test
    public void testSingleSourceBatchCommandReferentialIntegrityRollback()
      throws Exception {
  AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest(
    "testSingleSourceBatchCommandReferentialIntegrityRollback") {
      public void testCase() throws Exception {
    ArrayList list = new ArrayList();
    for (int i = 200; i < 210; i++) {
        list.add("insert into pm1.g1 (e1, e2) values(" + i + ",'"
          + i + "')");
    }

    // try to rollback, since we are in single batch it must
    // rollback
    list.add("insert into pm1.g2 (e1, e2) values(9999,'9999')");
    executeBatch((String[]) list.toArray(new String[list.size()]));
      }

      public boolean exceptionExpected() {
    return true;
      }
  };

  // run test
  getTransactionContainter().runTransaction(userTxn);

  // now verify the results
  AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
  test.execute("select * from g1 where e1 >= 200 and e1 < 210");
  test.assertRowCount(0);
  test.execute("select * from g2 where e1 = 9999");
  test.assertRowCount(0);
    }
View Full Code Here

     * Sources = 2 Commands = 1, Update Batching = Full Processing, Single
     * Connector Batch result = commit
     */
    @Test
    public void testMultipleSourceBulkRowInsertRollback() throws Exception {
  AbstractQueryTransactionTest userTxn = new AbstractQueryTransactionTest(
    "testMultipleSourceBulkRowInsertRollback") {
      ArrayList<String> list = new ArrayList<String>();

      @Override
      public void testCase() throws Exception {
    for (int i = 100; i < 110; i++) {
        list.add("insert into vm.g1 (pm1e1, pm1e2, pm2e1, pm2e2) values("
            + i + ",'" + i + "'," + i + ",'" + i + "')");
    }
    list.add("select pm1.g1.e1, pm1.g1.e2 into pm2.g2 from pm1.g1 where pm1.g1.e1 >= 100");

    // force the rollback by trying to insert an invalid row.
    list.add("insert into pm1.g2 (e1, e2) values(9999,'9999')");

    executeBatch((String[]) list.toArray(new String[list.size()]));
      }

      @Override
      public boolean exceptionExpected() {
    return true;
      }
  };

  // run test
  getTransactionContainter().runTransaction(userTxn);

  // now verify the results
  AbstractQueryTest test = new QueryExecution(userTxn.getSource("pm1"));
  test.execute("select * from g1 where e1 >= 100 and e1 < 110");
  test.assertRowCount(0);

  test = new QueryExecution(userTxn.getSource("pm2"));
  test.execute("select * from g1 where e1 >= 100 and e1 < 110");
  test.assertRowCount(0);
  test.execute("select * from g2 where e1 >= 100 and e1 < 110");
  test.assertRowCount(0);
    }
View Full Code Here

TOP

Related Classes of org.teiid.test.framework.query.AbstractQueryTransactionTest

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.