Search in sources :

Example 1 with PhoenixTestDriver

use of org.apache.phoenix.jdbc.PhoenixTestDriver in project phoenix by apache.

the class BaseTest method initAndRegisterTestDriver.

/**
     * Create a {@link PhoenixTestDriver} and register it.
     * @return an initialized and registered {@link PhoenixTestDriver} 
     */
public static PhoenixTestDriver initAndRegisterTestDriver(String url, ReadOnlyProps props) throws Exception {
    PhoenixTestDriver newDriver = new PhoenixTestDriver(props);
    DriverManager.registerDriver(newDriver);
    Driver oldDriver = DriverManager.getDriver(url);
    if (oldDriver != newDriver) {
        destroyDriver(oldDriver);
    }
    Properties driverProps = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = newDriver.connect(url, driverProps);
    conn.close();
    return newDriver;
}
Also used : PhoenixTestDriver(org.apache.phoenix.jdbc.PhoenixTestDriver) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) Connection(java.sql.Connection) Driver(java.sql.Driver) PhoenixTestDriver(org.apache.phoenix.jdbc.PhoenixTestDriver) PhoenixEmbeddedDriver(org.apache.phoenix.jdbc.PhoenixEmbeddedDriver) Properties(java.util.Properties)

Example 2 with PhoenixTestDriver

use of org.apache.phoenix.jdbc.PhoenixTestDriver in project phoenix by apache.

the class BaseConnectionlessQueryTest method initDriver.

protected static synchronized PhoenixTestDriver initDriver(ReadOnlyProps props) throws Exception {
    if (driver == null) {
        driver = new PhoenixTestDriver(props);
        DriverManager.registerDriver(driver);
    }
    return driver;
}
Also used : PhoenixTestDriver(org.apache.phoenix.jdbc.PhoenixTestDriver)

Example 3 with PhoenixTestDriver

use of org.apache.phoenix.jdbc.PhoenixTestDriver in project phoenix by apache.

the class BaseConnectionlessQueryTest method doTeardown.

@AfterClass
public static void doTeardown() throws Exception {
    if (driver != null) {
        try {
            driver.close();
        } finally {
            PhoenixTestDriver driver = BaseConnectionlessQueryTest.driver;
            BaseConnectionlessQueryTest.driver = null;
            DriverManager.deregisterDriver(driver);
        }
    }
}
Also used : PhoenixTestDriver(org.apache.phoenix.jdbc.PhoenixTestDriver) AfterClass(org.junit.AfterClass)

Example 4 with PhoenixTestDriver

use of org.apache.phoenix.jdbc.PhoenixTestDriver in project phoenix by apache.

the class CSVCommonsLoaderIT method testCSVCommonsUpsert_MultiTenant.

@Test
public void testCSVCommonsUpsert_MultiTenant() throws Exception {
    CSVParser parser = null;
    PhoenixConnection globalConn = null;
    PhoenixConnection tenantConn = null;
    try {
        String stockTableMultiName = generateUniqueName();
        // Create table using the global connection
        String statements = "CREATE TABLE IF NOT EXISTS " + stockTableMultiName + "(TENANT_ID VARCHAR NOT NULL, SYMBOL VARCHAR NOT NULL, COMPANY VARCHAR," + " CONSTRAINT PK PRIMARY KEY(TENANT_ID,SYMBOL)) MULTI_TENANT = true;";
        globalConn = DriverManager.getConnection(getUrl()).unwrap(PhoenixConnection.class);
        PhoenixRuntime.executeStatements(globalConn, new StringReader(statements), null);
        globalConn.close();
        tenantConn = new PhoenixTestDriver().connect(getUrl() + ";TenantId=acme", new Properties()).unwrap(PhoenixConnection.class);
        // Upsert CSV file
        CSVCommonsLoader csvUtil = new CSVCommonsLoader(tenantConn, stockTableMultiName, Collections.<String>emptyList(), true);
        csvUtil.upsert(new StringReader(STOCK_CSV_VALUES_WITH_HEADER));
        // Compare Phoenix ResultSet with CSV file content
        PreparedStatement statement = tenantConn.prepareStatement("SELECT SYMBOL, COMPANY FROM " + stockTableMultiName);
        ResultSet phoenixResultSet = statement.executeQuery();
        parser = new CSVParser(new StringReader(STOCK_CSV_VALUES_WITH_HEADER), csvUtil.getFormat());
        for (CSVRecord record : parser) {
            assertTrue(phoenixResultSet.next());
            int i = 0;
            for (String value : record) {
                assertEquals(value, phoenixResultSet.getString(i + 1));
                i++;
            }
        }
        assertFalse(phoenixResultSet.next());
    } finally {
        if (parser != null)
            parser.close();
        if (tenantConn != null)
            tenantConn.close();
    }
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) PhoenixTestDriver(org.apache.phoenix.jdbc.PhoenixTestDriver) CSVParser(org.apache.commons.csv.CSVParser) StringReader(java.io.StringReader) CSVCommonsLoader(org.apache.phoenix.util.CSVCommonsLoader) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) CSVRecord(org.apache.commons.csv.CSVRecord) Properties(java.util.Properties) Test(org.junit.Test)

Example 5 with PhoenixTestDriver

use of org.apache.phoenix.jdbc.PhoenixTestDriver in project phoenix by apache.

the class BaseTest method setDefaultTestConfig.

private static void setDefaultTestConfig(Configuration conf, ReadOnlyProps overrideProps) {
    ConfigUtil.setReplicationConfigIfAbsent(conf);
    QueryServices services = new PhoenixTestDriver().getQueryServices();
    for (Entry<String, String> entry : services.getProps()) {
        conf.set(entry.getKey(), entry.getValue());
    }
    //no point doing sanity checks when running tests.
    conf.setBoolean("hbase.table.sanity.checks", false);
    // set the server rpc controller and rpc scheduler factory, used to configure the cluster
    conf.set(RpcControllerFactory.CUSTOM_CONTROLLER_CONF_KEY, DEFAULT_SERVER_RPC_CONTROLLER_FACTORY);
    conf.set(RSRpcServices.REGION_SERVER_RPC_SCHEDULER_FACTORY_CLASS, DEFAULT_RPC_SCHEDULER_FACTORY);
    // override any defaults based on overrideProps
    for (Entry<String, String> entry : overrideProps) {
        conf.set(entry.getKey(), entry.getValue());
    }
}
Also used : PhoenixTestDriver(org.apache.phoenix.jdbc.PhoenixTestDriver)

Aggregations

PhoenixTestDriver (org.apache.phoenix.jdbc.PhoenixTestDriver)5 Properties (java.util.Properties)2 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)2 StringReader (java.io.StringReader)1 Connection (java.sql.Connection)1 Driver (java.sql.Driver)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 CSVParser (org.apache.commons.csv.CSVParser)1 CSVRecord (org.apache.commons.csv.CSVRecord)1 PhoenixEmbeddedDriver (org.apache.phoenix.jdbc.PhoenixEmbeddedDriver)1 CSVCommonsLoader (org.apache.phoenix.util.CSVCommonsLoader)1 AfterClass (org.junit.AfterClass)1 Test (org.junit.Test)1