Package org.teiid.test.framework.exception

Examples of org.teiid.test.framework.exception.TransactionRuntimeException


     
      props = PropertiesUtils.load(dsfile.getAbsolutePath());
      return props;
     
  } catch (IOException e) {
      throw new TransactionRuntimeException(
        "Error loading properties from file '" + dsfile.getAbsolutePath() + "'"
          + e.getMessage());
  }
    }
View Full Code Here


   
    DataSourceFactory factory = new DataSourceFactory(config);

    try {
      if (factory.getDatasource("model1") == null) {
        throw new TransactionRuntimeException("No datasource was not found");
      }
     

    } catch (QueryTestFailedException e) {
      e.printStackTrace();
    }
   
    factory.cleanup();
   
    ConfigPropertyLoader.reset();

   
    // the following verifies that order of "use" datasources is applied to request for datasources.
    config = ConfigPropertyLoader.getInstance();
   
    config.setProperty(ConfigPropertyNames.USE_DATASOURCES_PROP, "oracle,sqlserver");
       
    factory = new DataSourceFactory(config);

    try {
     
      DataSource dsfind = factory.getDatasource( "model2");
      if (dsfind == null) {
        throw new TransactionRuntimeException("No datasource was not found as the 2nd datasource");
       
      }
     
      if (dsfind.getConnectorType() == null) {
        throw new TransactionRuntimeException("Connector types was not defined");
      }
     
      if (!dsfind.getName().equalsIgnoreCase("sqlserver")) {
        throw new TransactionRuntimeException("Sqlserver was not found as the 2nd datasource");
       
      }
     
      dsfind = factory.getDatasource( "model1");
      if (dsfind == null) {
        throw new TransactionRuntimeException("No datasource was not found as the 2nd datasource");
       
      }
      if (!dsfind.getName().equalsIgnoreCase("oracle")) {
        throw new TransactionRuntimeException("Oracle was not found as the 2nd datasource");
       
      }
      System.out.println("Datasource :" + dsfind.getName() + " was found");
     
     
      // the following test verifies that a sqlserver datasource is not
      // returned (excluded)
      factory.cleanup();
   
      ConfigPropertyLoader.reset();


      config = ConfigPropertyLoader.getInstance();
      config.setProperty(ConfigPropertyNames.EXCLUDE_DATASBASE_TYPES_PROP, "sqlserver");

     
      factory = new DataSourceFactory(config);

      int n = factory.getNumberAvailableDataSources();
      TestLogger.log("Num avail datasources: " + n);

      for (int i=0; i<n; i++) {
       
        String k = String.valueOf(i);
        DataSource ds1 = factory.getDatasource( "model" + k);
        if (ds1 == null) {
          throw new TransactionRuntimeException("No datasource was found for: model:" + k);
         
        } if (ds1.getDBType().equalsIgnoreCase(DataSourceFactory.DataBaseTypes.SQLSERVER)) {
          throw new TransactionRuntimeException("sqlserver dbtype should have been excluded");
        }
      }
       
       
        DataSource reuse = factory.getDatasource( "model1");
        if (reuse != null) {
         
        } else {
          throw new TransactionRuntimeException("The process was not able to reassign an already used datasource");
         
        }
       
        factory.cleanup();
       
        ConfigPropertyLoader.reset();

       
        // test required database types
        // test 1 source

        config = ConfigPropertyLoader.getInstance();
       
        config.setModelAssignedToDatabaseType("pm1", DataSourceFactory.DataBaseTypes.ORACLE);
     
        factory = new DataSourceFactory(config);

        DataSource ds1 = factory.getDatasource("pm1");
        if (!ds1.getDBType().equalsIgnoreCase(DataSourceFactory.DataBaseTypes.ORACLE)) {
          throw new TransactionRuntimeException("Required DB Type of oracle for model pm1 is :" + ds1.getDBType());
        }
       
        TestLogger.log("Test1 Required DS1 " + ds1.getDBType());
        factory.cleanup();
       
        ConfigPropertyLoader.reset();

        // test required database types
        // test 2 sources, 1 required and other ANY
        config = ConfigPropertyLoader.getInstance();
     
       
        config.setModelAssignedToDatabaseType("pm2", DataSourceFactory.DataBaseTypes.SQLSERVER);
        config.setModelAssignedToDatabaseType("pm1", DataSourceFactory.DataBaseTypes.ANY);
     
        factory = new DataSourceFactory(config);

        DataSource ds2 = factory.getDatasource("pm2");
        if (!ds2.getDBType().equalsIgnoreCase(DataSourceFactory.DataBaseTypes.SQLSERVER)) {
          throw new TransactionRuntimeException("Required DB Type of sqlserver for model pm2 is :" + ds2.getDBType());
        }
        TestLogger.log("Test2 Required DS2 " + ds2.getDBType());
     
        factory.cleanup();
        ConfigPropertyLoader.reset();

       
        // test required database types
        // test 2 sources, 2 required
        config = ConfigPropertyLoader.getInstance();
     
       
        config.setModelAssignedToDatabaseType("pm2", DataSourceFactory.DataBaseTypes.SQLSERVER);
        config.setModelAssignedToDatabaseType("pm1", DataSourceFactory.DataBaseTypes.ORACLE);
     
        factory = new DataSourceFactory(config);

        DataSource ds3a = factory.getDatasource("pm2");
        if (!ds3a.getDBType().equalsIgnoreCase(DataSourceFactory.DataBaseTypes.SQLSERVER)) {
          throw new TransactionRuntimeException("Required DB Type of sqlserver for model pm12 is :" + ds3a.getDBType());
        }
       
        DataSource ds3b = factory.getDatasource("pm1");
        if (!ds3b.getDBType().equalsIgnoreCase(DataSourceFactory.DataBaseTypes.ORACLE)) {
          throw new TransactionRuntimeException("Required DB Type of oracle for model pm1  is :" + ds3b.getDBType());
        }
        TestLogger.log("Test3 Required DS3a " + ds3a.getDBType());
        TestLogger.log("Test3 Required DS3b " + ds3b.getDBType());
       
        factory.cleanup();
View Full Code Here

          xaResource.setTransactionTimeout(120);
          xaResource.start(xid, XAResource.TMNOFLAGS);
          debug("Start transaction using XID: " + xid.toString());

        } catch (Exception e) {
            throw new TransactionRuntimeException(e);
        }       
    }
View Full Code Here

              commit = true;
            }
            delistSuccessful = true;
        } catch (Exception e) {
          exception = true;
            throw new TransactionRuntimeException(e);           
        } finally {
            try {
                if (!delistSuccessful || test.rollbackAllways()|| test.exceptionOccurred()) {
                  xaResource.rollback(xid);
                }
                else if (commit) {
                  xaResource.commit(xid, true);
                }           
            } catch (Exception e) {
              if (!exception) {
                throw new TransactionRuntimeException(e);
              }
            }
        }
    }   
View Full Code Here

    }
   
    protected void before(TransactionQueryTestCase test) {
  String jndi = test.getConnectionStrategy().getEnvironment().getProperty(ConfigPropertyNames.CONNECTION_STRATEGY_PROPS.JNDINAME_USERTXN);
  if (jndi == null) {
            throw new TransactionRuntimeException("No JNDI name found for the User Transaction to look up in application server");
        }

        try {         
            // begin the transaction
            InitialContext ctx = new InitialContext();
            this.userTxn = (UserTransaction)ctx.lookup(jndi);
             this.userTxn.begin();
        } catch (Exception e) {
            throw new TransactionRuntimeException(e);
        }       
    }
View Full Code Here

                    this.userTxn.commit();
                }
                this.userTxn = null;
            }
        } catch (Exception e) {
            throw new TransactionRuntimeException(e);           
        }
    }   
View Full Code Here

          xid = createXid();
          XAResource xaResource = test.getConnectionStrategy().getXAConnection().getXAResource();
           xaResource.setTransactionTimeout(120);
          xaResource.start(xid, XAResource.TMNOFLAGS);
        } catch (Exception e) {
            throw new TransactionRuntimeException(e);
        }       
    }
View Full Code Here

            if (!test.exceptionExpected() && xaResource.prepare(xid) == XAResource.XA_OK) {
              commit = true;
            }
            delistSuccessful = true;
        } catch (Exception e) {
            throw new TransactionRuntimeException(e);           
        } finally {
            try {
                if (!delistSuccessful || test.rollbackAllways()|| test.exceptionOccurred()) {
                    test.getConnectionStrategy().getXAConnection().getXAResource().rollback(xid);
                 }
                else if (commit) {
                    test.getConnectionStrategy().getXAConnection().getXAResource().commit(xid, true);
                }           
            } catch (Exception e) {
                throw new TransactionRuntimeException(e);           
            }
        }
    }   
View Full Code Here

 
        try {
           debug("Autocommit: " + test.getConnectionStrategy().getAutocommit());
            test.getConnection().setAutoCommit(test.getConnectionStrategy().getAutocommit());
        } catch (SQLException e) {
            throw new TransactionRuntimeException(e);
        }       
    }
View Full Code Here

          try {
            test.getConnection().rollback();
          } catch (Exception e) {
            // do nothing
          }
            throw new TransactionRuntimeException(se);
           
           
        } finally {
          // if an exception occurs and the autocommit is set to true - while doing a transaction
          // will generate a new exception overriding the first exception
          if (!exception) {
              try {
                  test.getConnection().setAutoCommit(true);
              } catch (SQLException e) {
                  throw new TransactionRuntimeException(e);
              }
          }
        }
    }  
View Full Code Here

TOP

Related Classes of org.teiid.test.framework.exception.TransactionRuntimeException

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.