+ " SELECT NEXT VALUE FOR "+ tableName + "_seq, val FROM " + tableName); Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); for (int i=0; i<12; i++) { try {
@Test public void testFirstConnectionWhenPropsHasTenantId() throws Exception { Properties props = new Properties(); final String tenantId = "00Dxx0000001234"; props.put(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId); Connection connection = new PhoenixTestDriver().connect(getUrl(), props); assertEquals(tenantId, connection.getClientInfo(PhoenixRuntime.TENANT_ID_ATTRIB)); }
@Override public synchronized QueryServices getQueryServices() { checkClosed(); return queryServices; }
public UpsertTask() throws SQLException { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); conn = driver.connect(url, props); }
protected static synchronized PhoenixTestDriver initDriver(ReadOnlyProps props) throws Exception { if (driver == null) { driver = new PhoenixTestDriver(props); DriverManager.registerDriver(driver); } return driver; }
@Override public boolean acceptsURL(String url) throws SQLException { // Accept the url only if test=true attribute set return super.acceptsURL(url) && isTestUrl(url); }
public PhoenixTestDriver(ReadOnlyProps props) { overrideProps = props; queryServices = new QueryServicesTestImpl(getDefaultProps(), overrideProps); }
private static void setDefaultTestConfig(Configuration conf, ReadOnlyProps overrideProps) throws Exception { ConfigUtil.setReplicationConfigIfAbsent(conf); QueryServices services = newTestDriver(overrideProps).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(RSRpcServices.REGION_SERVER_RPC_SCHEDULER_FACTORY_CLASS, DEFAULT_RPC_SCHEDULER_FACTORY); conf.setLong(HConstants.ZK_SESSION_TIMEOUT, 10 * HConstants.DEFAULT_ZK_SESSION_TIMEOUT); conf.setLong(HConstants.ZOOKEEPER_TICK_TIME, 6 * 1000); // override any defaults based on overrideProps for (Entry<String,String> entry : overrideProps) { conf.set(entry.getKey(), entry.getValue()); } }
@AfterClass public static void doTeardown() throws Exception { if (driver != null) { try { driver.close(); } finally { PhoenixTestDriver driver = BaseConnectionlessQueryTest.driver; BaseConnectionlessQueryTest.driver = null; DriverManager.deregisterDriver(driver); } } }
@Override public Boolean call() { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, String.valueOf(isNamespaceMapped)); try (Connection conn = driver.connect(url, props)) { // In case of disable index on failure policy, INDEX will be in PENDING_DISABLE on first retry // but will // become active if retry is successfull PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES(?,?,?)"); stmt.setString(1, "b"); stmt.setString(2, "y"); stmt.setString(3, "2"); stmt.execute(); if (!leaveIndexActiveOnFailure && !transactional) { FailingRegionObserver.FAIL_WRITE = true; FailingRegionObserver.TOGGLE_FAIL_WRITE_FOR_RETRY = true; } conn.commit(); } catch (SQLException e) { return false; } return true; } };
private static PhoenixTestDriver newTestDriver(ReadOnlyProps props) throws Exception { PhoenixTestDriver newDriver; String driverClassName = props.get(DRIVER_CLASS_NAME_ATTRIB); if (driverClassName == null) { newDriver = new PhoenixTestDriver(props); } else { Class<?> clazz = Class.forName(driverClassName); Constructor constr = clazz.getConstructor(ReadOnlyProps.class); newDriver = (PhoenixTestDriver)constr.newInstance(props); } return newDriver; } /**
protected void testSplitDuringIndexScan(boolean isReverse) throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(QueryServices.SCAN_CACHE_SIZE_ATTRIB, Integer.toString(2)); props.setProperty(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB, Boolean.toString(false)); Connection conn1 = getConnection(props); String tableName = "TBL_" + generateUniqueName(); String indexName = "IDX_" + generateUniqueName(); Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); try{ String[] strings = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}; createTableAndLoadData(conn1, tableName, indexName, strings, isReverse); ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM " + tableName); assertTrue(rs.next()); splitDuringScan(conn1, tableName, indexName, strings, admin, isReverse); } finally { if(conn1 != null) conn1.close(); if(admin != null) admin.close(); } }
@Before public void setup() throws Exception { SlowBatchRegionObserver.SLOW_MUTATE = false; props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.put(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2); dataTable = generateUniqueName(); index = "IDX_" + dataTable; try (Connection conn = driver.connect(url, props)) { conn.createStatement().execute("CREATE TABLE " + dataTable + " (k INTEGER NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)"); // create the index and ensure its empty as well conn.createStatement().execute("CREATE INDEX " + index + " ON " + dataTable + " (v1)"); PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + dataTable + " VALUES(?,?,?)"); conn.setAutoCommit(false); for (int i = 0; i < 100; i++) { stmt.setInt(1, i); stmt.setString(2, "v1" + i); stmt.setString(3, "v2" + i); stmt.execute(); } conn.commit(); } }
globalConn.close(); tenantConn = new PhoenixTestDriver().connect(getUrl() + ";TenantId=acme", new Properties()).unwrap( PhoenixConnection.class);
@Override public synchronized Connection connect(String url, Properties info) throws SQLException { checkClosed(); return super.connect(url, info); }
@Test public void testFirstConnectionWhenUrlHasTenantId() throws Exception { final String tenantId = "00Dxx0000001234"; String url = getUrl() + ";" + PhoenixRuntime.TENANT_ID_ATTRIB + "=" + tenantId; Driver driver = new PhoenixTestDriver(); driver.connect(url, new Properties()); }
ResultSet rs = conn1.createStatement().executeQuery("EXPLAIN "+ query); Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); int numRegions = admin.getTableRegions(physicalTableName).size();
@Test public void testMetadataQos() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = driver.connect(getUrl(), props); try { // create the table conn.createStatement().execute("CREATE TABLE " + dataTableFullName + " (k VARCHAR NOT NULL PRIMARY KEY, v VARCHAR)"); // verify that that metadata queue is used at least once Mockito.verify(TestPhoenixIndexRpcSchedulerFactory.getMetadataRpcExecutor(), Mockito.atLeastOnce()).dispatch(Mockito.any(CallRunner.class)); } finally { conn.close(); } }
@Override // public for testing public synchronized ConnectionQueryServices getConnectionQueryServices(String url, Properties info) throws SQLException { checkClosed(); if (connectionQueryServices != null) { return connectionQueryServices; } ConnectionInfo connInfo = ConnectionInfo.create(url); if (connInfo.isConnectionless()) { connectionQueryServices = new ConnectionlessQueryServicesImpl(queryServices, connInfo, info); } else { connectionQueryServices = new ConnectionQueryServicesTestImpl(queryServices, connInfo, info); } connectionQueryServices.init(url, info); return connectionQueryServices; }
@Test public void testCreateTableColumnFamilyHBaseAttribs8() throws Exception { String tableName = generateUniqueName(); String ddl = "create table IF NOT EXISTS " + tableName + " (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " col2 bigint NOT NULL," + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)" + " ) BLOOMFILTER = 'ROW', SALT_BUCKETS = 4"; Properties props = new Properties(); Connection conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute(ddl); Admin admin = driver.getConnectionQueryServices(getUrl(), props).getAdmin(); ColumnFamilyDescriptor[] columnFamilies = admin.getDescriptor(TableName.valueOf(tableName)).getColumnFamilies(); assertEquals(BloomType.ROW, columnFamilies[0].getBloomFilterType()); }