public static PhoenixTestDriver registerDriver(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; }
// Close and unregister the driver. protected static boolean destroyDriver(Driver driver) { if (driver != null) { assert (driver instanceof PhoenixTestDriver); PhoenixTestDriver pdriver = (PhoenixTestDriver) driver; try { try { pdriver.close(); return true; } finally { DriverManager.deregisterDriver(driver); } } catch (Exception e) { logger.warn("Unable to close registered driver: " + driver, e); } } return false; }