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;
}
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;
}
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);
}
}
}
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();
}
}
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());
}
}
Aggregations