Search in sources :

Example 1 with TransactionRuntimeException

use of org.teiid.test.framework.exception.TransactionRuntimeException in project teiid by teiid.

the class DataSourceFactory method main.

public static void main(String[] args) {
    // NOTE: to run this test to validate the DataSourceMgr, do the following:
    // ---  need 3 datasources,   Oracle, SqlServer and 1 other
    ConfigPropertyLoader config = ConfigPropertyLoader.getInstance();
    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();
    } catch (QueryTestFailedException e) {
        e.printStackTrace();
    }
}
Also used : QueryTestFailedException(org.teiid.test.framework.exception.QueryTestFailedException) ConfigPropertyLoader(org.teiid.test.framework.ConfigPropertyLoader) TransactionRuntimeException(org.teiid.test.framework.exception.TransactionRuntimeException)

Example 2 with TransactionRuntimeException

use of org.teiid.test.framework.exception.TransactionRuntimeException in project teiid by teiid.

the class DataSourceMgr method loadDataSourceMappings.

private void loadDataSourceMappings() throws QueryTestFailedException {
    if (ConfigPropertyLoader.getInstance().isDataStoreDisabled()) {
        TestLogger.logDebug("DataStore usage has been disabled");
        return;
    }
    String dsloc = ConfigPropertyLoader.getInstance().getProperty(ConfigPropertyNames.OVERRIDE_DATASOURCES_LOC);
    if (dsloc == null || dsloc.indexOf(UNASSIGNEDDSLOC) > -1) {
        dsloc = DEFAULT_DATASOURCES_LOC;
        TestLogger.logDebug("Using default datasource loc: " + dsloc);
    } else {
        TestLogger.logDebug("Using override for datasources loc: " + dsloc);
    }
    File[] dirs = findAllChildDirectories(dsloc);
    if (dirs == null || dirs.length == 0) {
        throw new TransactionRuntimeException("No datasource directories found at location " + dsloc);
    }
    for (int i = 0; i < dirs.length; i++) {
        File d = dirs[i];
        addDataSource(d, allDatasourcesMap);
    }
    if (allDatasourcesMap == null || allDatasourcesMap.isEmpty()) {
        throw new TransactionRuntimeException("Error: No Datasources were loaded.");
    } else if (allDatasourcesMap.size() < 2) {
        throw new TransactionRuntimeException("Error: Must load 2 Datasources, only 1 was found.");
    }
    TestLogger.logDebug("Number of total datasource mappings loaded " + allDatasourcesMap.size());
    dsfactory = new DataSourceFactory(ConfigPropertyLoader.getInstance());
    dsfactory.config(this);
}
Also used : TransactionRuntimeException(org.teiid.test.framework.exception.TransactionRuntimeException) File(java.io.File)

Example 3 with TransactionRuntimeException

use of org.teiid.test.framework.exception.TransactionRuntimeException in project teiid by teiid.

the class JNDITransaction method before.

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);
    }
}
Also used : TransactionRuntimeException(org.teiid.test.framework.exception.TransactionRuntimeException) InitialContext(javax.naming.InitialContext) TransactionRuntimeException(org.teiid.test.framework.exception.TransactionRuntimeException)

Example 4 with TransactionRuntimeException

use of org.teiid.test.framework.exception.TransactionRuntimeException in project teiid by teiid.

the class XATransaction method before.

protected void before(TransactionQueryTestCase test) {
    try {
        xid = createXid();
        XAResource xaResource = test.getConnectionStrategy().getXAConnection().getXAResource();
        xaResource.setTransactionTimeout(120);
        xaResource.start(xid, XAResource.TMNOFLAGS);
        debug("Start transaction using XID: " + xid.toString());
    } catch (Exception e) {
        throw new TransactionRuntimeException(e);
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) TransactionRuntimeException(org.teiid.test.framework.exception.TransactionRuntimeException) TransactionRuntimeException(org.teiid.test.framework.exception.TransactionRuntimeException)

Example 5 with TransactionRuntimeException

use of org.teiid.test.framework.exception.TransactionRuntimeException in project teiid by teiid.

the class PropUtils method loadProperties.

public static Properties loadProperties(String filename, Properties defaults) {
    Assert.assertNotNull(filename);
    InputStream in = null;
    Properties props = new Properties();
    if (defaults != null) {
        props.putAll(defaults);
    }
    try {
        File f = new File(filename);
        if (f.exists()) {
            return PropertiesUtils.load(filename);
        }
        in = ConfigPropertyLoader.class.getResourceAsStream("/" + filename);
        if (in != null) {
            Properties lprops = new Properties();
            lprops.load(in);
            props.putAll(lprops);
        } else {
            throw new TransactionRuntimeException("Failed to load properties from file '" + filename + "' configuration file");
        }
    } catch (IOException e) {
        throw new TransactionRuntimeException("Error loading properties from file '" + filename + "'" + e.getMessage());
    } finally {
        try {
            in.close();
        } catch (Exception e) {
        }
    }
    return props;
}
Also used : ConfigPropertyLoader(org.teiid.test.framework.ConfigPropertyLoader) InputStream(java.io.InputStream) TransactionRuntimeException(org.teiid.test.framework.exception.TransactionRuntimeException) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) IOException(java.io.IOException) TransactionRuntimeException(org.teiid.test.framework.exception.TransactionRuntimeException)

Aggregations

TransactionRuntimeException (org.teiid.test.framework.exception.TransactionRuntimeException)26 QueryTestFailedException (org.teiid.test.framework.exception.QueryTestFailedException)5 XAResource (javax.transaction.xa.XAResource)4 File (java.io.File)3 Properties (java.util.Properties)3 ConfigPropertyLoader (org.teiid.test.framework.ConfigPropertyLoader)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 XAConnection (javax.sql.XAConnection)2 TransactionContainer (org.teiid.test.framework.TransactionContainer)2 DataSource (org.teiid.test.framework.datasource.DataSource)2 InputStream (java.io.InputStream)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Collection (java.util.Collection)1 InitialContext (javax.naming.InitialContext)1 Element (org.jdom.Element)1 JDOMException (org.jdom.JDOMException)1 JNDITransaction (org.teiid.test.framework.transaction.JNDITransaction)1 LocalTransaction (org.teiid.test.framework.transaction.LocalTransaction)1