org.apache.phoenix.jdbc.PhoenixEmbeddedDriver Java Examples

The following examples show how to use org.apache.phoenix.jdbc.PhoenixEmbeddedDriver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
protected static boolean destroyDriver(Driver driver) {
    if (driver != null) {
        assert(driver instanceof PhoenixEmbeddedDriver);
        PhoenixEmbeddedDriver pdriver = (PhoenixEmbeddedDriver)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;
}
 
Example #2
Source File: BaseTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
protected static boolean destroyDriver(Driver driver) {
    if (driver != null) {
        assert(driver instanceof PhoenixEmbeddedDriver);
        PhoenixEmbeddedDriver pdriver = (PhoenixEmbeddedDriver)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;
}
 
Example #3
Source File: PhoenixClientModule.java    From presto with Apache License 2.0 5 votes vote down vote up
public static Properties getConnectionProperties(PhoenixConfig config)
        throws SQLException
{
    Configuration resourcesConfig = readConfig(config);
    Properties connectionProperties = new Properties();
    for (Map.Entry<String, String> entry : resourcesConfig) {
        connectionProperties.put(entry.getKey(), entry.getValue());
    }

    PhoenixEmbeddedDriver.ConnectionInfo connectionInfo = PhoenixEmbeddedDriver.ConnectionInfo.create(config.getConnectionUrl());
    connectionProperties.putAll(connectionInfo.asProps().asMap());
    return connectionProperties;
}
 
Example #4
Source File: AbstractPhoenixConnectionlessTest.java    From ambari-metrics with Apache License 2.0 5 votes vote down vote up
private static void startServer(String url) throws Exception {
  assertNull(driver);
  // only load the test driver if we are testing locally - for integration tests, we want to
  // test on a wider scale
  if (PhoenixEmbeddedDriver.isTestUrl(url)) {
    driver = initDriver(ReadOnlyProps.EMPTY_PROPS);
    assertTrue(DriverManager.getDriver(url) == driver);
    driver.connect(url, PropertiesUtil.deepCopy(TEST_PROPERTIES));
  }
}
 
Example #5
Source File: BaseConnectionlessQueryTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static void startServer(String url) throws Exception {
    assertNull(driver);
    // only load the test driver if we are testing locally - for integration tests, we want to
    // test on a wider scale
    if (PhoenixEmbeddedDriver.isTestUrl(url)) {
        driver = initDriver(ReadOnlyProps.EMPTY_PROPS);
        assertTrue(DriverManager.getDriver(url) == driver);
        driver.connect(url, PropertiesUtil.deepCopy(TEST_PROPERTIES));
    }
}
 
Example #6
Source File: BaseConnectionlessQueryTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static void startServer(String url) throws Exception {
    assertNull(driver);
    // only load the test driver if we are testing locally - for integration tests, we want to
    // test on a wider scale
    if (PhoenixEmbeddedDriver.isTestUrl(url)) {
        driver = initDriver(ReadOnlyProps.EMPTY_PROPS);
        assertTrue(DriverManager.getDriver(url) == driver);
        driver.connect(url, PropertiesUtil.deepCopy(TEST_PROPERTIES));
    }
}
 
Example #7
Source File: QueryUtil.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private static String getUrlInternal(String zkQuorum, Integer port, String znodeParent, String principal) {
    return new PhoenixEmbeddedDriver.ConnectionInfo(zkQuorum, port, znodeParent, principal, null).toUrl()
            + PhoenixRuntime.JDBC_PROTOCOL_TERMINATOR;
}
 
Example #8
Source File: UpdateCacheIT.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private static void helpTestUpdateCache(String fullTableName, int[] expectedRPCs,
           boolean skipUpsertForIndexes) throws Exception {
    String tableName = SchemaUtil.getTableNameFromFullName(fullTableName);
    String schemaName = SchemaUtil.getSchemaNameFromFullName(fullTableName);
	String selectSql = "SELECT * FROM "+fullTableName;
	// use a spyed ConnectionQueryServices so we can verify calls to getTable
	ConnectionQueryServices connectionQueryServices = Mockito.spy(driver.getConnectionQueryServices(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)));
	Properties props = new Properties();
	props.putAll(PhoenixEmbeddedDriver.DEFAULT_PROPS.asMap());
	Connection conn = connectionQueryServices.connect(getUrl(), props);
	try {
		conn.setAutoCommit(false);
           if (!skipUpsertForIndexes) {
               String upsert = "UPSERT INTO " + fullTableName + "(varchar_pk, char_pk, int_pk, long_pk, decimal_pk, date_pk) VALUES(?, ?, ?, ?, ?, ?)";
               PreparedStatement stmt = conn.prepareStatement(upsert);
               // upsert three rows
               for (int i=0; i<3; i++) {
                   TestUtil.setRowKeyColumns(stmt, i);
                   stmt.execute();
               }
               conn.commit();
               int numUpsertRpcs = expectedRPCs[0];
               // verify only 0 or 1 rpc to fetch table metadata,
               verify(connectionQueryServices, times(numUpsertRpcs)).getTable((PName) isNull(),
                       eq(PVarchar.INSTANCE.toBytes(schemaName)), eq(PVarchar.INSTANCE.toBytes(tableName)),
                       anyLong(), anyLong());
               reset(connectionQueryServices);
           }
           validateSelectRowKeyCols(conn, selectSql, skipUpsertForIndexes);
           validateSelectRowKeyCols(conn, selectSql, skipUpsertForIndexes);
           validateSelectRowKeyCols(conn, selectSql, skipUpsertForIndexes);

        // for non-transactional tables without a scn : verify one rpc to getTable occurs *per* query
           // for non-transactional tables with a scn : verify *only* one rpc occurs
           // for transactional tables : verify *only* one rpc occurs
        // for non-transactional, system tables : verify no rpc occurs
           int numRpcs = skipUpsertForIndexes ? expectedRPCs[0] : expectedRPCs[1];
           verify(connectionQueryServices, times(numRpcs)).getTable((PName) isNull(),
               eq(PVarchar.INSTANCE.toBytes(schemaName)), eq(PVarchar.INSTANCE.toBytes(tableName)),
               anyLong(), anyLong());
	}
       finally {
       	conn.close();
       }
}
 
Example #9
Source File: SystemCatalogCreationOnConnectionIT.java    From phoenix with Apache License 2.0 4 votes vote down vote up
PhoenixSysCatCreationServices(QueryServices services, PhoenixEmbeddedDriver.ConnectionInfo connectionInfo, Properties info) {
    super(services, connectionInfo, info);
}
 
Example #10
Source File: RebuildIndexConnectionPropsIT.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Test
public void testRebuildIndexConnectionProperties() throws Exception {
    try (PhoenixConnection rebuildIndexConnection =
            MetaDataRegionObserver.getRebuildIndexConnection(hbaseTestUtil.getMiniHBaseCluster().getConfiguration())) {
        try (PhoenixConnection regularConnection =
                DriverManager.getConnection(url).unwrap(PhoenixConnection.class)) {
            String rebuildUrl = rebuildIndexConnection.getURL();
            // assert that we are working with non-test urls
            assertFalse(PhoenixEmbeddedDriver.isTestUrl(url));
            assertFalse(PhoenixEmbeddedDriver.isTestUrl(rebuildUrl));
            // assert that the url ends with expected string
            assertTrue(
                rebuildUrl.contains(MetaDataRegionObserver.REBUILD_INDEX_APPEND_TO_URL_STRING));
            // assert that the url for regular connection vs the rebuild connection is different
            assertFalse(rebuildUrl.equals(regularConnection.getURL()));
            Configuration rebuildQueryServicesConfig =
                    rebuildIndexConnection.getQueryServices().getConfiguration();
            // assert that the properties are part of the query services config
            assertEquals(
                Long.toString(QueryServicesOptions.DEFAULT_INDEX_REBUILD_QUERY_TIMEOUT),
                rebuildQueryServicesConfig.get(QueryServices.THREAD_TIMEOUT_MS_ATTRIB));
            assertEquals(
                Long.toString(
                    QueryServicesOptions.DEFAULT_INDEX_REBUILD_CLIENT_SCANNER_TIMEOUT),
                rebuildQueryServicesConfig.get(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD));
            assertEquals(Long.toString(QueryServicesOptions.DEFAULT_INDEX_REBUILD_RPC_TIMEOUT),
                rebuildQueryServicesConfig.get(HConstants.HBASE_RPC_TIMEOUT_KEY));
            assertEquals(
                Long.toString(NUM_RPC_RETRIES),
                rebuildQueryServicesConfig.get(HConstants.HBASE_CLIENT_RETRIES_NUMBER));
            ConnectionQueryServices rebuildQueryServices = rebuildIndexConnection.getQueryServices();
            Connection rebuildIndexHConnection =
                    (Connection) Whitebox.getInternalState(rebuildQueryServices,
                        "connection");
            Connection regularHConnection =
                    (Connection) Whitebox.getInternalState(
                        regularConnection.getQueryServices(), "connection");
            // assert that a new HConnection was created
            assertFalse(
                regularHConnection.toString().equals(rebuildIndexHConnection.toString()));
            Configuration rebuildHConnectionConfig = rebuildIndexHConnection.getConfiguration();
            // assert that the HConnection has the desired properties needed for rebuilding
            // indices
            assertEquals(
                Long.toString(
                    QueryServicesOptions.DEFAULT_INDEX_REBUILD_CLIENT_SCANNER_TIMEOUT),
                rebuildHConnectionConfig.get(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD));
            assertEquals(Long.toString(QueryServicesOptions.DEFAULT_INDEX_REBUILD_RPC_TIMEOUT),
                rebuildHConnectionConfig.get(HConstants.HBASE_RPC_TIMEOUT_KEY));
            assertEquals(
                Long.toString(NUM_RPC_RETRIES),
                rebuildHConnectionConfig.get(HConstants.HBASE_CLIENT_RETRIES_NUMBER));
        }
    }
}