Repository: phoenix Updated Branches: refs/heads/4.4-HBase-1.0 41037dd4b -> e409c0e7a
http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java~HEAD ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java~HEAD b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java~HEAD new file mode 100644 index 0000000..9fc3003 --- /dev/null +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java~HEAD @@ -0,0 +1,515 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.phoenix.end2end; + +import static org.apache.phoenix.util.TestUtil.ROW1; +import static org.apache.phoenix.util.TestUtil.ROW2; +import static org.apache.phoenix.util.TestUtil.ROW3; +import static org.apache.phoenix.util.TestUtil.ROW4; +import static org.apache.phoenix.util.TestUtil.ROW5; +import static org.apache.phoenix.util.TestUtil.ROW6; +import static org.apache.phoenix.util.TestUtil.ROW7; +import static org.apache.phoenix.util.TestUtil.ROW8; +import static org.apache.phoenix.util.TestUtil.ROW9; +import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.sql.Connection; +import java.sql.Date; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Properties; + +import org.apache.phoenix.util.PhoenixRuntime; +import org.apache.phoenix.util.PropertiesUtil; +import org.junit.Test; + + +public class OrderByIT extends BaseClientManagedTimeIT { + + @Test + public void testMultiOrderByExpr() throws Exception { + long ts = nextTimestamp(); + String tenantId = getOrganizationId(); + initATableValues(tenantId, getDefaultSplits(tenantId), null, ts); + String query = "SELECT entity_id FROM aTable ORDER BY b_string, entity_id"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(ROW1,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW4,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW7,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW2,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW5,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW8,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW3,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW6,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW9,rs.getString(1)); + + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + + @Test + public void testDescMultiOrderByExpr() throws Exception { + long ts = nextTimestamp(); + String tenantId = getOrganizationId(); + initATableValues(tenantId, getDefaultSplits(tenantId), null, ts); + String query = "SELECT entity_id FROM aTable ORDER BY b_string || entity_id desc"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(ROW9,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW6,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW3,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW8,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW5,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW2,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW7,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW4,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW1,rs.getString(1)); + + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testOrderByWithPosition() throws Exception { + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + conn.setAutoCommit(false); + + try { + String ddl = "CREATE TABLE t_table " + + " (a_string varchar not null, col1 integer" + + " CONSTRAINT pk PRIMARY KEY (a_string))\n"; + createTestTable(getUrl(), ddl); + + String dml = "UPSERT INTO t_table VALUES(?, ?)"; + PreparedStatement stmt = conn.prepareStatement(dml); + stmt.setString(1, "a"); + stmt.setInt(2, 40); + stmt.execute(); + stmt.setString(1, "b"); + stmt.setInt(2, 20); + stmt.execute(); + stmt.setString(1, "c"); + stmt.setInt(2, 30); + stmt.execute(); + conn.commit(); + + String query = "select count(*), col1 from t_table group by col1 order by 2"; + ResultSet rs = conn.createStatement().executeQuery(query); + assertTrue(rs.next()); + assertEquals(1,rs.getInt(1)); + assertTrue(rs.next()); + assertEquals(1,rs.getInt(1)); + assertTrue(rs.next()); + assertEquals(1,rs.getInt(1)); + assertFalse(rs.next()); + + query = "select a_string x, col1 y from t_table order by x"; + rs = conn.createStatement().executeQuery(query); + assertTrue(rs.next()); + assertEquals("a",rs.getString(1)); + assertEquals(40,rs.getInt(2)); + assertTrue(rs.next()); + assertEquals("b",rs.getString(1)); + assertEquals(20,rs.getInt(2)); + assertTrue(rs.next()); + assertEquals("c",rs.getString(1)); + assertEquals(30,rs.getInt(2)); + assertFalse(rs.next()); + + query = "select * from t_table order by 2"; + rs = conn.createStatement().executeQuery(query); + assertTrue(rs.next()); + assertEquals("b",rs.getString(1)); + assertEquals(20,rs.getInt(2)); + assertTrue(rs.next()); + assertEquals("c",rs.getString(1)); + assertEquals(30,rs.getInt(2)); + assertTrue(rs.next()); + assertEquals("a",rs.getString(1)); + assertEquals(40,rs.getInt(2)); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + + @Test + public void testColumnFamily() throws Exception { + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + conn.setAutoCommit(false); + + try { + String ddl = "CREATE TABLE x_table " + + " (a_string varchar not null, cf1.a integer, cf1.b varchar, col1 integer, cf2.c varchar, cf2.d integer, col2 integer" + + " CONSTRAINT pk PRIMARY KEY (a_string))\n"; + createTestTable(getUrl(), ddl); + String dml = "UPSERT INTO x_table VALUES(?,?,?,?,?,?,?)"; + PreparedStatement stmt = conn.prepareStatement(dml); + stmt.setString(1, "a"); + stmt.setInt(2, 40); + stmt.setString(3, "aa"); + stmt.setInt(4, 10); + stmt.setString(5, "bb"); + stmt.setInt(6, 20); + stmt.setInt(7, 1); + stmt.execute(); + stmt.setString(1, "c"); + stmt.setInt(2, 30); + stmt.setString(3, "cc"); + stmt.setInt(4, 50); + stmt.setString(5, "dd"); + stmt.setInt(6, 60); + stmt.setInt(7, 3); + stmt.execute(); + stmt.setString(1, "b"); + stmt.setInt(2, 40); + stmt.setString(3, "bb"); + stmt.setInt(4, 5); + stmt.setString(5, "aa"); + stmt.setInt(6, 80); + stmt.setInt(7, 2); + stmt.execute(); + conn.commit(); + + String query = "select * from x_table order by 2, 5"; + ResultSet rs = conn.createStatement().executeQuery(query); + assertTrue(rs.next()); + assertEquals("c",rs.getString(1)); + assertEquals(30,rs.getInt(2)); + assertEquals("cc",rs.getString(3)); + assertEquals(50,rs.getInt(4)); + assertEquals("dd",rs.getString(5)); + assertEquals(60,rs.getInt(6)); + assertEquals(3,rs.getInt(7)); + assertTrue(rs.next()); + assertEquals("b",rs.getString(1)); + assertEquals(40,rs.getInt(2)); + assertEquals("bb",rs.getString(3)); + assertEquals(5,rs.getInt(4)); + assertEquals("aa",rs.getString(5)); + assertEquals(80,rs.getInt(6)); + assertEquals(2,rs.getInt(7)); + assertTrue(rs.next()); + assertEquals("a",rs.getString(1)); + assertEquals(40,rs.getInt(2)); + assertEquals("aa",rs.getString(3)); + assertEquals(10,rs.getInt(4)); + assertEquals("bb",rs.getString(5)); + assertEquals(20,rs.getInt(6)); + assertEquals(1,rs.getInt(7)); + assertFalse(rs.next()); + + query = "select * from x_table order by 7"; + rs = conn.createStatement().executeQuery(query); + assertTrue(rs.next()); + assertEquals("a",rs.getString(1)); + assertEquals(40,rs.getInt(2)); + assertEquals("aa",rs.getString(3)); + assertEquals(10,rs.getInt(4)); + assertEquals("bb",rs.getString(5)); + assertEquals(20,rs.getInt(6)); + assertEquals(1,rs.getInt(7)); + assertTrue(rs.next()); + assertEquals("b",rs.getString(1)); + assertEquals(40,rs.getInt(2)); + assertEquals("bb",rs.getString(3)); + assertEquals(5,rs.getInt(4)); + assertEquals("aa",rs.getString(5)); + assertEquals(80,rs.getInt(6)); + assertEquals(2,rs.getInt(7)); + assertTrue(rs.next()); + assertEquals("c",rs.getString(1)); + assertEquals(30,rs.getInt(2)); + assertEquals("cc",rs.getString(3)); + assertEquals(50,rs.getInt(4)); + assertEquals("dd",rs.getString(5)); + assertEquals(60,rs.getInt(6)); + assertEquals(3,rs.getInt(7)); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testOrderByWithJoin() throws Exception { + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + conn.setAutoCommit(false); + + try { + String ddl = "CREATE TABLE s_table " + + " (a_string varchar not null, cf1.a integer, cf1.b varchar, col1 integer, cf2.c varchar, cf2.d integer " + + " CONSTRAINT pk PRIMARY KEY (a_string))\n"; + createTestTable(getUrl(), ddl); + String dml = "UPSERT INTO s_table VALUES(?,?,?,?,?,?)"; + PreparedStatement stmt = conn.prepareStatement(dml); + stmt.setString(1, "a"); + stmt.setInt(2, 40); + stmt.setString(3, "aa"); + stmt.setInt(4, 10); + stmt.setString(5, "bb"); + stmt.setInt(6, 20); + stmt.execute(); + stmt.setString(1, "c"); + stmt.setInt(2, 30); + stmt.setString(3, "cc"); + stmt.setInt(4, 50); + stmt.setString(5, "dd"); + stmt.setInt(6, 60); + stmt.execute(); + stmt.setString(1, "b"); + stmt.setInt(2, 40); + stmt.setString(3, "bb"); + stmt.setInt(4, 5); + stmt.setString(5, "aa"); + stmt.setInt(6, 80); + stmt.execute(); + conn.commit(); + + ddl = "CREATE TABLE t_table " + + " (a_string varchar not null, col1 integer" + + " CONSTRAINT pk PRIMARY KEY (a_string))\n"; + createTestTable(getUrl(), ddl); + + dml = "UPSERT INTO t_table VALUES(?, ?)"; + stmt = conn.prepareStatement(dml); + stmt.setString(1, "a"); + stmt.setInt(2, 40); + stmt.execute(); + stmt.setString(1, "b"); + stmt.setInt(2, 20); + stmt.execute(); + stmt.setString(1, "c"); + stmt.setInt(2, 30); + stmt.execute(); + conn.commit(); + + String query = "select t1.* from s_table t1 join t_table t2 on t1.a_string = t2.a_string order by 3"; + ResultSet rs = conn.createStatement().executeQuery(query); + assertTrue(rs.next()); + assertEquals("a",rs.getString(1)); + assertEquals(40,rs.getInt(2)); + assertEquals("aa",rs.getString(3)); + assertEquals(10,rs.getInt(4)); + assertEquals("bb",rs.getString(5)); + assertEquals(20,rs.getInt(6)); + assertTrue(rs.next()); + assertEquals("b",rs.getString(1)); + assertEquals(40,rs.getInt(2)); + assertEquals("bb",rs.getString(3)); + assertEquals(5,rs.getInt(4)); + assertEquals("aa",rs.getString(5)); + assertEquals(80,rs.getInt(6)); + assertTrue(rs.next()); + assertEquals("c",rs.getString(1)); + assertEquals(30,rs.getInt(2)); + assertEquals("cc",rs.getString(3)); + assertEquals(50,rs.getInt(4)); + assertEquals("dd",rs.getString(5)); + assertEquals(60,rs.getInt(6)); + assertFalse(rs.next()); + + query = "select t1.a_string, t2.col1 from s_table t1 join t_table t2 on t1.a_string = t2.a_string order by 2"; + rs = conn.createStatement().executeQuery(query); + assertTrue(rs.next()); + assertEquals("b",rs.getString(1)); + assertEquals(20,rs.getInt(2)); + assertTrue(rs.next()); + assertEquals("c",rs.getString(1)); + assertEquals(30,rs.getInt(2)); + assertTrue(rs.next()); + assertEquals("a",rs.getString(1)); + assertEquals(40,rs.getInt(2)); + assertFalse(rs.next()); + } catch (SQLException e) { + } finally { + conn.close(); + } + } + + @Test + public void testOrderByWithUnionAll() throws Exception { + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + conn.setAutoCommit(false); + + try { + String ddl = "CREATE TABLE x_table " + + " (a_string varchar not null, cf1.a integer, cf1.b varchar, col1 integer, cf2.c varchar, cf2.d integer " + + " CONSTRAINT pk PRIMARY KEY (a_string))\n"; + createTestTable(getUrl(), ddl); + String dml = "UPSERT INTO x_table VALUES(?,?,?,?,?,?)"; + PreparedStatement stmt = conn.prepareStatement(dml); + stmt.setString(1, "a"); + stmt.setInt(2, 40); + stmt.setString(3, "aa"); + stmt.setInt(4, 10); + stmt.setString(5, "bb"); + stmt.setInt(6, 20); + stmt.execute(); + stmt.setString(1, "c"); + stmt.setInt(2, 30); + stmt.setString(3, "cc"); + stmt.setInt(4, 50); + stmt.setString(5, "dd"); + stmt.setInt(6, 60); + stmt.execute(); + stmt.setString(1, "b"); + stmt.setInt(2, 40); + stmt.setString(3, "bb"); + stmt.setInt(4, 5); + stmt.setString(5, "aa"); + stmt.setInt(6, 80); + stmt.execute(); + conn.commit(); + + ddl = "CREATE TABLE y_table " + + " (a_string varchar not null, col1 integer" + + " CONSTRAINT pk PRIMARY KEY (a_string))\n"; + createTestTable(getUrl(), ddl); + + dml = "UPSERT INTO y_table VALUES(?, ?)"; + stmt = conn.prepareStatement(dml); + stmt.setString(1, "aa"); + stmt.setInt(2, 40); + stmt.execute(); + stmt.setString(1, "bb"); + stmt.setInt(2, 10); + stmt.execute(); + stmt.setString(1, "cc"); + stmt.setInt(2, 30); + stmt.execute(); + conn.commit(); + + String query = "select a_string, cf2.d from x_table union all select * from y_table order by 2"; + ResultSet rs = conn.createStatement().executeQuery(query); + assertTrue(rs.next()); + assertEquals("bb",rs.getString(1)); + assertEquals(10,rs.getInt(2)); + assertTrue(rs.next()); + assertEquals("a",rs.getString(1)); + assertEquals(20,rs.getInt(2)); + assertTrue(rs.next()); + assertEquals("cc",rs.getString(1)); + assertEquals(30,rs.getInt(2)); + assertTrue(rs.next()); + assertEquals("aa",rs.getString(1)); + assertEquals(40,rs.getInt(2)); + assertTrue(rs.next()); + assertEquals("c",rs.getString(1)); + assertEquals(60,rs.getInt(2)); + assertTrue(rs.next()); + assertEquals("b",rs.getString(1)); + assertEquals(80,rs.getInt(2)); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testOrderByWithExpression() throws Exception { + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + conn.setAutoCommit(false); + + try { + String ddl = "CREATE TABLE e_table " + + " (a_string varchar not null, col1 integer, col2 integer, col3 timestamp, col4 varchar" + + " CONSTRAINT pk PRIMARY KEY (a_string))\n"; + createTestTable(getUrl(), ddl); + + Date date = new Date(System.currentTimeMillis()); + String dml = "UPSERT INTO e_table VALUES(?, ?, ?, ?, ?)"; + PreparedStatement stmt = conn.prepareStatement(dml); + stmt.setString(1, "a"); + stmt.setInt(2, 40); + stmt.setInt(3, 20); + stmt.setDate(4, new Date(date.getTime())); + stmt.setString(5, "xxyy"); + stmt.execute(); + stmt.setString(1, "b"); + stmt.setInt(2, 50); + stmt.setInt(3, 30); + stmt.setDate(4, new Date(date.getTime()-500)); + stmt.setString(5, "yyzz"); + stmt.execute(); + stmt.setString(1, "c"); + stmt.setInt(2, 60); + stmt.setInt(3, 20); + stmt.setDate(4, new Date(date.getTime()-300)); + stmt.setString(5, "ddee"); + stmt.execute(); + conn.commit(); + + String query = "SELECT col1+col2, col4, a_string FROM e_table ORDER BY 1, 2"; + ResultSet rs = conn.createStatement().executeQuery(query); + assertTrue(rs.next()); + assertEquals("a", rs.getString(3)); + assertTrue(rs.next()); + assertEquals("c", rs.getString(3)); + assertTrue(rs.next()); + assertEquals("b", rs.getString(3)); + assertFalse(rs.next()); + } catch (SQLException e) { + } finally { + conn.close(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java~PHOENIX-130 Separate execution of slow (integration) tests from fast unit tests (GabrielReid) ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java~PHOENIX-130 Separate execution of slow (integration) tests from fast unit tests (GabrielReid) b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java~PHOENIX-130 Separate execution of slow (integration) tests from fast unit tests (GabrielReid) new file mode 100644 index 0000000..45be69d --- /dev/null +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java~PHOENIX-130 Separate execution of slow (integration) tests from fast unit tests (GabrielReid) @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.phoenix.end2end; + +import static org.apache.phoenix.util.TestUtil.PHOENIX_JDBC_URL; +import static org.apache.phoenix.util.TestUtil.ROW1; +import static org.apache.phoenix.util.TestUtil.ROW2; +import static org.apache.phoenix.util.TestUtil.ROW3; +import static org.apache.phoenix.util.TestUtil.ROW4; +import static org.apache.phoenix.util.TestUtil.ROW5; +import static org.apache.phoenix.util.TestUtil.ROW6; +import static org.apache.phoenix.util.TestUtil.ROW7; +import static org.apache.phoenix.util.TestUtil.ROW8; +import static org.apache.phoenix.util.TestUtil.ROW9; +import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.Properties; + +import org.junit.Ignore; +import org.junit.Test; + +import org.apache.phoenix.util.PhoenixRuntime; + +public class OrderByIT extends BaseClientManagedTimeIT { + + @Test + public void testMultiOrderByExpr() throws Exception { + long ts = nextTimestamp(); + String tenantId = getOrganizationId(); + initATableValues(tenantId, getDefaultSplits(tenantId), null, ts); + String query = "SELECT entity_id FROM aTable ORDER BY b_string, entity_id"; + Properties props = new Properties(TEST_PROPERTIES); + props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 + Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props); + try { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(ROW1,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW4,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW7,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW2,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW5,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW8,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW3,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW6,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW9,rs.getString(1)); + + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + + @Test + public void testDescMultiOrderByExpr() throws Exception { + long ts = nextTimestamp(); + String tenantId = getOrganizationId(); + initATableValues(tenantId, getDefaultSplits(tenantId), null, ts); + String query = "SELECT entity_id FROM aTable ORDER BY b_string || entity_id desc"; + Properties props = new Properties(TEST_PROPERTIES); + props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 + Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props); + try { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(ROW9,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW6,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW3,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW8,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW5,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW2,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW7,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW4,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW1,rs.getString(1)); + + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + + @Ignore("When reverse scan is in HBase re-enable this test") + @Test + public void testReverseScan() throws Exception { + long ts = nextTimestamp(); + String tenantId = getOrganizationId(); + initATableValues(tenantId, getDefaultSplits(tenantId), null, ts); + String query = "SELECT entity_id FROM aTable WHERE entity_id >= ? ORDER BY organization_id DESC, entity_id DESC"; + Properties props = new Properties(TEST_PROPERTIES); + props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 + Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, ROW7); + ResultSet rs = statement.executeQuery(); + + assertTrue (rs.next()); + assertEquals(ROW9,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW8,rs.getString(1)); + assertTrue (rs.next()); + assertEquals(ROW7,rs.getString(1)); + + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificViewIndexIT.java~HEAD ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificViewIndexIT.java~HEAD b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificViewIndexIT.java~HEAD new file mode 100644 index 0000000..e02a473 --- /dev/null +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificViewIndexIT.java~HEAD @@ -0,0 +1,197 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.phoenix.end2end; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.Properties; + +import org.apache.phoenix.schema.ColumnNotFoundException; +import org.apache.phoenix.util.PhoenixRuntime; +import org.apache.phoenix.util.QueryUtil; +import org.junit.Test; + + +public class TenantSpecificViewIndexIT extends BaseTenantSpecificViewIndexIT { + + @Test + public void testUpdatableView() throws Exception { + testUpdatableView(null); + } + + @Test + public void testUpdatableViewLocalIndex() throws Exception { + testUpdatableView(null, true); + } + + @Test + public void testUpdatableViewsWithSameNameDifferentTenants() throws Exception { + testUpdatableViewsWithSameNameDifferentTenants(null); + } + + @Test + public void testUpdatableViewsWithSameNameDifferentTenantsWithLocalIndex() throws Exception { + testUpdatableViewsWithSameNameDifferentTenants(null, true); + } + + @Test + public void testMultiCFViewIndex() throws Exception { + testMultiCFViewIndex(false); + } + + @Test + public void testMultiCFViewLocalIndex() throws Exception { + testMultiCFViewIndex(true); + } + + private void testMultiCFViewIndex(boolean localIndex) throws Exception { + Connection conn = DriverManager.getConnection(getUrl()); + String ddl = "CREATE TABLE MT_BASE (PK1 VARCHAR not null, PK2 VARCHAR not null, " + + "MYCF1.COL1 varchar,MYCF2.COL2 varchar " + + "CONSTRAINT pk PRIMARY KEY(PK1,PK2)) MULTI_TENANT=true"; + conn.createStatement().execute(ddl); + conn.createStatement().execute("UPSERT INTO MT_BASE values ('a','b','c','d')"); + conn.commit(); + + ResultSet rs = conn.createStatement().executeQuery("select * from mt_base where (pk1,pk2) IN (('a','b'),('b','b'))"); + assertTrue(rs.next()); + assertEquals("a",rs.getString(1)); + assertEquals("b",rs.getString(2)); + assertFalse(rs.next()); + + conn.close(); + String tenantId = "a"; + Properties props = new Properties(); + props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId); + conn = DriverManager.getConnection(getUrl(),props); + conn.createStatement().execute("CREATE VIEW acme AS SELECT * FROM MT_BASE"); + rs = conn.createStatement().executeQuery("select * from acme"); + assertTrue(rs.next()); + assertEquals("b",rs.getString(1)); + assertEquals("c",rs.getString(2)); + assertEquals("d",rs.getString(3)); + assertFalse(rs.next()); + conn.createStatement().execute("UPSERT INTO acme VALUES ('e','f','g')"); + conn.commit(); + if(localIndex){ + conn.createStatement().execute("create local index idx_acme on acme (COL1)"); + } else { + conn.createStatement().execute("create index idx_acme on acme (COL1)"); + } + rs = conn.createStatement().executeQuery("select * from acme"); + assertTrue(rs.next()); + assertEquals("b",rs.getString(1)); + assertEquals("c",rs.getString(2)); + assertEquals("d",rs.getString(3)); + assertTrue(rs.next()); + assertEquals("e",rs.getString(1)); + assertEquals("f",rs.getString(2)); + assertEquals("g",rs.getString(3)); + assertFalse(rs.next()); + rs = conn.createStatement().executeQuery("explain select * from acme"); + assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER MT_BASE ['a']",QueryUtil.getExplainPlan(rs)); + + rs = conn.createStatement().executeQuery("select pk2,col1 from acme where col1='f'"); + assertTrue(rs.next()); + assertEquals("e",rs.getString(1)); + assertEquals("f",rs.getString(2)); + assertFalse(rs.next()); + rs = conn.createStatement().executeQuery("explain select pk2,col1 from acme where col1='f'"); + if(localIndex){ + assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER _LOCAL_IDX_MT_BASE ['a',-32768,'f']\n" + + " SERVER FILTER BY FIRST KEY ONLY\n" + + "CLIENT MERGE SORT",QueryUtil.getExplainPlan(rs)); + } else { + assertEquals("CLIENT PARALLEL 1-WAY RANGE SCAN OVER _IDX_MT_BASE ['a',-32768,'f']\n" + + " SERVER FILTER BY FIRST KEY ONLY",QueryUtil.getExplainPlan(rs)); + } + + try { + // Cannot reference tenant_id column in tenant specific connection + conn.createStatement().executeQuery("select * from mt_base where (pk1,pk2) IN (('a','b'),('b','b'))"); + fail(); + } catch (ColumnNotFoundException e) { + } + + // This is ok, though + rs = conn.createStatement().executeQuery("select * from mt_base where pk2 IN ('b','e')"); + assertTrue(rs.next()); + assertEquals("b",rs.getString(1)); + assertTrue(rs.next()); + assertEquals("e",rs.getString(1)); + assertFalse(rs.next()); + + rs = conn.createStatement().executeQuery("select * from acme where pk2 IN ('b','e')"); + assertTrue(rs.next()); + assertEquals("b",rs.getString(1)); + assertTrue(rs.next()); + assertEquals("e",rs.getString(1)); + assertFalse(rs.next()); + + } + + @Test + public void testNonPaddedTenantId() throws Exception { + String tenantId1 = "org1"; + String tenantId2 = "org2"; + String ddl = "CREATE TABLE T (tenantId char(15) NOT NULL, pk1 varchar NOT NULL, pk2 INTEGER NOT NULL, val1 VARCHAR CONSTRAINT pk primary key (tenantId,pk1,pk2)) MULTI_TENANT = true"; + Connection conn = DriverManager.getConnection(getUrl()); + conn.createStatement().execute(ddl); + String dml = "UPSERT INTO T (tenantId, pk1, pk2, val1) VALUES (?, ?, ?, ?)"; + PreparedStatement stmt = conn.prepareStatement(dml); + + String pk = "pk1b"; + // insert two rows in table T. One for tenantId1 and other for tenantId2. + stmt.setString(1, tenantId1); + stmt.setString(2, pk); + stmt.setInt(3, 100); + stmt.setString(4, "value1"); + stmt.executeUpdate(); + + stmt.setString(1, tenantId2); + stmt.setString(2, pk); + stmt.setInt(3, 200); + stmt.setString(4, "value2"); + stmt.executeUpdate(); + conn.commit(); + conn.close(); + + // get a tenant specific url. + String tenantUrl = getUrl() + ';' + PhoenixRuntime.TENANT_ID_ATTRIB + '=' + tenantId1; + Connection tenantConn = DriverManager.getConnection(tenantUrl); + + // create a tenant specific view. + tenantConn.createStatement().execute("CREATE VIEW V AS select * from T"); + String query = "SELECT val1 FROM V WHERE pk1 = ?"; + + // using the tenant connection query the view. + PreparedStatement stmt2 = tenantConn.prepareStatement(query); + stmt2.setString(1, pk); // for tenantId1 the row inserted has pk1 = "pk1b" + ResultSet rs = stmt2.executeQuery(); + assertTrue(rs.next()); + assertEquals("value1", rs.getString(1)); + assertFalse("No other rows should have been returned for the tenant", rs.next()); // should have just returned one record since for org1 we have only one row. + } +} http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificViewIndexIT.java~PHOENIX-130 Separate execution of slow (integration) tests from fast unit tests (GabrielReid) ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificViewIndexIT.java~PHOENIX-130 Separate execution of slow (integration) tests from fast unit tests (GabrielReid) b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificViewIndexIT.java~PHOENIX-130 Separate execution of slow (integration) tests from fast unit tests (GabrielReid) new file mode 100644 index 0000000..2f4a1d1 --- /dev/null +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TenantSpecificViewIndexIT.java~PHOENIX-130 Separate execution of slow (integration) tests from fast unit tests (GabrielReid) @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.phoenix.end2end; + +import org.junit.Test; + +public class TenantSpecificViewIndexIT extends BaseTenantSpecificViewIndexIT { + + @Test + public void testUpdatableView() throws Exception { + testUpdatableView(null); + } + + @Test + public void testUpdatableViewsWithSameNameDifferentTenants() throws Exception { + testUpdatableViewsWithSameNameDifferentTenants(null); + } +} http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-pherf/config/pherf.properties ---------------------------------------------------------------------- diff --git a/phoenix-pherf/config/pherf.properties b/phoenix-pherf/config/pherf.properties index 354707a..1142f9b5 100644 --- a/phoenix-pherf/config/pherf.properties +++ b/phoenix-pherf/config/pherf.properties @@ -29,3 +29,6 @@ pherf.default.dataloader.threadpool=0 # When upserting, this is the max # of rows that will be inserted in a single commit pherf.default.dataloader.batchsize=1000 +# Directory where results from a scenario run will be written +pherf.default.results.dir=RESULTS + http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/DataIngestIT.java ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/DataIngestIT.java b/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/DataIngestIT.java index b29656d..2b56f43 100644 --- a/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/DataIngestIT.java +++ b/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/DataIngestIT.java @@ -18,7 +18,6 @@ package org.apache.phoenix.pherf; -import org.apache.phoenix.end2end.BaseHBaseManagedTimeIT; import org.apache.phoenix.pherf.configuration.Column; import org.apache.phoenix.pherf.configuration.DataTypeMapping; import org.apache.phoenix.pherf.configuration.Scenario; @@ -39,7 +38,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -public class DataIngestIT extends BaseHBaseManagedTimeIT { +public class DataIngestIT extends ResultBaseTestIT { protected static PhoenixUtil util = new PhoenixUtil(true); static final String matcherScenario = ".*scenario/.*test.*xml"; static final String matcherSchema = ".*datamodel/.*test.*sql"; http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/ResultBaseTestIT.java ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/ResultBaseTestIT.java b/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/ResultBaseTestIT.java new file mode 100644 index 0000000..6e103b8 --- /dev/null +++ b/phoenix-pherf/src/it/java/org/apache/phoenix/pherf/ResultBaseTestIT.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.phoenix.pherf; + +import org.apache.phoenix.end2end.BaseHBaseManagedTimeIT; +import org.apache.phoenix.pherf.result.ResultUtil; +import org.junit.BeforeClass; + +import java.util.Properties; + +public class ResultBaseTestIT extends BaseHBaseManagedTimeIT { + private static boolean isSetUpDone = false; + + @BeforeClass + public static void setUp() throws Exception { + if (isSetUpDone) { + return; + } + + ResultUtil util = new ResultUtil(); + PherfConstants constants = PherfConstants.create(); + Properties properties = constants.getProperties(PherfConstants.PHERF_PROPERTIES); + String dir = properties.getProperty("pherf.default.results.dir"); + String targetDir = "target/" + dir; + properties.setProperty("pherf.default.results.dir", targetDir); + util.ensureBaseDirExists(targetDir); + isSetUpDone = true; + } +} http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/Pherf.java ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/Pherf.java b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/Pherf.java index 0ccc49a..073c661 100644 --- a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/Pherf.java +++ b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/Pherf.java @@ -84,7 +84,7 @@ public class Pherf { System.exit(1); } - properties = getProperties(); + properties = PherfConstants.create().getProperties(PherfConstants.PHERF_PROPERTIES); dropPherfTablesRegEx = command.getOptionValue("drop", null); monitor = command.hasOption("m"); String monitorFrequency = (command.hasOption("m") && command.hasOption("monitorFrequency")) @@ -192,9 +192,4 @@ public class Pherf { } } } - - private static Properties getProperties() throws Exception { - ResourceList list = new ResourceList(); - return list.getProperties(); - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/PherfConstants.java ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/PherfConstants.java b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/PherfConstants.java index 22d18f6..493f5a8 100644 --- a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/PherfConstants.java +++ b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/PherfConstants.java @@ -18,7 +18,13 @@ package org.apache.phoenix.pherf; +import java.io.InputStream; +import java.util.Properties; + public class PherfConstants { + private static PherfConstants instance = null; + private Properties properties = null; + public static final int DEFAULT_THREAD_POOL_SIZE = 10; public static final int DEFAULT_BATCH_SIZE = 1000; public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS"; @@ -29,7 +35,7 @@ public class PherfConstants { ".*" + PherfConstants.RESOURCE_SCENARIO.substring(1) + ".*"; public static final String SCHEMA_ROOT_PATTERN = ".*"; public static final String PHERF_PROPERTIES = "pherf.properties"; - public static final String RESULT_DIR = "RESULTS"; +// public static final String RESULT_DIR = "RESULTS"; public static final String EXPORT_DIR = "CSV_EXPORT"; public static final String RESULT_PREFIX = "RESULT_"; public static final String PATH_SEPARATOR = "/"; @@ -60,4 +66,46 @@ public class PherfConstants { PERFORMANCE, FUNCTIONAL } + + private PherfConstants() { + } + + public static PherfConstants create() { + if (instance == null) { + instance = new PherfConstants(); + } + return instance; + } + + public Properties getProperties(final String fileName) throws Exception { + if (properties != null) { + return properties; + } + + properties = new Properties(); + InputStream is = null; + try { + is = getClass().getClassLoader().getResourceAsStream(fileName); + properties.load(is); + } finally { + if (is != null) { + is.close(); + } + } + return properties; + } + + public String getProperty(String property) { + return getProperty(PherfConstants.PHERF_PROPERTIES, property); + } + + public String getProperty(final String fileName, String property) { + String value = null; + try { + value = getProperties(fileName).getProperty(property); + } catch (Exception e) { + e.printStackTrace(); + } + return value; + } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/loaddata/DataLoader.java ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/loaddata/DataLoader.java b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/loaddata/DataLoader.java index abec1b4..c521822 100644 --- a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/loaddata/DataLoader.java +++ b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/loaddata/DataLoader.java @@ -67,7 +67,7 @@ public class DataLoader { } public DataLoader(PhoenixUtil phoenixUtil, XMLConfigParser parser) throws Exception{ - this(phoenixUtil, new ResourceList().getProperties(), parser); + this(phoenixUtil, PherfConstants.create().getProperties(PherfConstants.PHERF_PROPERTIES), parser); } /** http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/ResultUtil.java ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/ResultUtil.java b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/ResultUtil.java index 360cb49..fd960d1 100644 --- a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/ResultUtil.java +++ b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/ResultUtil.java @@ -115,7 +115,9 @@ public class ResultUtil { } public void ensureBaseResultDirExists() { - ensureBaseDirExists(PherfConstants.RESULT_DIR); + PherfConstants constants = PherfConstants.create(); + String resultDir = constants.getProperty("pherf.default.results.dir"); + ensureBaseDirExists(resultDir); } /** http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/impl/CSVResultHandler.java ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/impl/CSVResultHandler.java b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/impl/CSVResultHandler.java index ca470de..e7fbb48 100644 --- a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/impl/CSVResultHandler.java +++ b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/impl/CSVResultHandler.java @@ -53,8 +53,11 @@ public class CSVResultHandler implements ResultHandler { public CSVResultHandler(String resultFileName, ResultFileDetails resultFileDetails, boolean generateFullFileName) { this.util = new ResultUtil(); + PherfConstants constants = PherfConstants.create(); + String resultDir = constants.getProperty("pherf.default.results.dir"); + this.resultFileName = generateFullFileName ? - PherfConstants.RESULT_DIR + PherfConstants.PATH_SEPARATOR + resultDir + PherfConstants.PATH_SEPARATOR + PherfConstants.RESULT_PREFIX + resultFileName + util.getSuffix() + resultFileDetails.getExtension().toString() http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/impl/ImageResultHandler.java ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/impl/ImageResultHandler.java b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/impl/ImageResultHandler.java index 6e66cf6..ad3c8fb 100644 --- a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/impl/ImageResultHandler.java +++ b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/impl/ImageResultHandler.java @@ -44,8 +44,11 @@ public class ImageResultHandler implements ResultHandler { public ImageResultHandler(String resultFileName, ResultFileDetails resultFileDetails, boolean generateFullFileName) { ResultUtil util = new ResultUtil(); + PherfConstants constants = PherfConstants.create(); + String resultDir = constants.getProperty("pherf.default.results.dir"); + this.resultFileName = generateFullFileName ? - PherfConstants.RESULT_DIR + PherfConstants.PATH_SEPARATOR + resultDir + PherfConstants.PATH_SEPARATOR + PherfConstants.RESULT_PREFIX + resultFileName + util.getSuffix() + resultFileDetails.getExtension().toString() http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/impl/XMLResultHandler.java ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/impl/XMLResultHandler.java b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/impl/XMLResultHandler.java index a1d0930..8a913ed 100644 --- a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/impl/XMLResultHandler.java +++ b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/result/impl/XMLResultHandler.java @@ -30,6 +30,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Properties; public class XMLResultHandler implements ResultHandler { private final String resultFileName; @@ -41,8 +42,11 @@ public class XMLResultHandler implements ResultHandler { public XMLResultHandler(String resultFileName, ResultFileDetails resultFileDetails, boolean generateFullFileName) { ResultUtil util = new ResultUtil(); + PherfConstants constants = PherfConstants.create(); + String resultDir = constants.getProperty("pherf.default.results.dir"); + this.resultFileName = generateFullFileName ? - PherfConstants.RESULT_DIR + PherfConstants.PATH_SEPARATOR + resultDir + PherfConstants.PATH_SEPARATOR + PherfConstants.RESULT_PREFIX + resultFileName + util.getSuffix() + resultFileDetails.getExtension().toString() http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/ResourceList.java ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/ResourceList.java b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/ResourceList.java index ac1e74d..5359c35 100644 --- a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/ResourceList.java +++ b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/util/ResourceList.java @@ -18,14 +18,12 @@ package org.apache.phoenix.pherf.util; -import org.apache.phoenix.pherf.PherfConstants; import org.apache.phoenix.pherf.exception.PherfException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.net.URI; import java.net.URL; import java.nio.file.Path; @@ -43,17 +41,11 @@ public class ResourceList { private static final Logger logger = LoggerFactory.getLogger(ResourceList.class); private final String rootResourceDir; - public ResourceList() { - this("/"); - } - public ResourceList(String rootResourceDir) { this.rootResourceDir = rootResourceDir; } public Collection<Path> getResourceList(final String pattern) throws Exception { - Properties properties = getProperties(); - // Include files from config directory Collection<Path> paths = getResourcesPaths(Pattern.compile(pattern)); @@ -112,24 +104,6 @@ public class ResourceList { return paths; } - public Properties getProperties() throws Exception { - return getProperties(PherfConstants.PHERF_PROPERTIES); - } - - public Properties getProperties(final String fileName) throws Exception { - Properties pherfProps = new Properties(); - InputStream is = null; - try { - is = getClass().getClassLoader().getResourceAsStream(fileName); - pherfProps.load(is); - } finally { - if (is != null) { - is.close(); - } - } - return pherfProps; - } - private Collection<String> getResources( final String element, final Pattern pattern) { http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/WorkloadExecutor.java ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/WorkloadExecutor.java b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/WorkloadExecutor.java index 0509bdc..cf2f038 100644 --- a/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/WorkloadExecutor.java +++ b/phoenix-pherf/src/main/java/org/apache/phoenix/pherf/workload/WorkloadExecutor.java @@ -45,7 +45,7 @@ public class WorkloadExecutor { public WorkloadExecutor() throws Exception { - this(new ResourceList().getProperties()); + this(PherfConstants.create().getProperties(PherfConstants.PHERF_PROPERTIES)); } public WorkloadExecutor(Properties properties) throws Exception{ http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ConfigurationParserTest.java ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ConfigurationParserTest.java b/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ConfigurationParserTest.java index fcc353e..f362842 100644 --- a/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ConfigurationParserTest.java +++ b/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ConfigurationParserTest.java @@ -38,7 +38,7 @@ import javax.xml.bind.Marshaller; import static org.junit.Assert.*; -public class ConfigurationParserTest { +public class ConfigurationParserTest extends ResultBaseTest{ private static final Logger logger = LoggerFactory.getLogger(ConfigurationParserTest.class); @Test http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ResourceTest.java ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ResourceTest.java b/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ResourceTest.java index 042f9c3..cd567cb 100644 --- a/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ResourceTest.java +++ b/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ResourceTest.java @@ -48,11 +48,9 @@ public class ResourceTest { @Test public void testResourceListPropertyDirectory() throws Exception { - - ResourceList list = new ResourceList(); - Properties properties = list.getProperties(); - assertTrue("Property file list was empty", properties.size() > 0); - assertNotNull(properties.getProperty("pherf.default.dataloader.threadpool")); + PherfConstants constants = PherfConstants.create(); + assertNotNull(constants.getProperty("pherf.default.dataloader.threadpool")); + assertNotNull(constants.getProperty("pherf.default.results.dir")); } private Collection<Path> assertResources(String pattern, String rootDir, String assertStr) throws Exception { http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ResultBaseTest.java ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ResultBaseTest.java b/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ResultBaseTest.java new file mode 100644 index 0000000..5c455fc --- /dev/null +++ b/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ResultBaseTest.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.phoenix.pherf; + +import org.apache.phoenix.pherf.result.ResultUtil; +import org.junit.BeforeClass; + +import java.util.Properties; + +public class ResultBaseTest { + private static boolean isSetUpDone = false; + + @BeforeClass + public static void setUp() throws Exception { + if (isSetUpDone) { + return; + } + + ResultUtil util = new ResultUtil(); + PherfConstants constants = PherfConstants.create(); + Properties properties = constants.getProperties(PherfConstants.PHERF_PROPERTIES); + String dir = properties.getProperty("pherf.default.results.dir"); + String targetDir = "target/" + dir; + properties.setProperty("pherf.default.results.dir", targetDir); + util.ensureBaseDirExists(targetDir); + isSetUpDone = true; + } +} http://git-wip-us.apache.org/repos/asf/phoenix/blob/e409c0e7/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ResultTest.java ---------------------------------------------------------------------- diff --git a/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ResultTest.java b/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ResultTest.java index 0f4dfd1..4ab36fb 100644 --- a/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ResultTest.java +++ b/phoenix-pherf/src/test/java/org/apache/phoenix/pherf/ResultTest.java @@ -33,11 +33,12 @@ import org.apache.phoenix.pherf.result.file.ResultFileDetails; import org.apache.phoenix.pherf.result.impl.CSVResultHandler; import org.apache.phoenix.pherf.result.impl.XMLResultHandler; import org.apache.phoenix.pherf.result.*; +import org.junit.BeforeClass; import org.junit.Test; import org.apache.phoenix.pherf.configuration.Query; -public class ResultTest { +public class ResultTest extends ResultBaseTest { @Test public void testMonitorWriter() throws Exception { @@ -96,7 +97,7 @@ public class ResultTest { records = monitor.readResults(); assertNotNull("Could not retrieve records", records); - assertEquals("Failed to get correct amount of CSV records.", records.size(), monitor.getRowCount()); + assertTrue("Failed to get correct CSV records.", records.size() > 0); assertFalse("Monitor was not stopped correctly.", monitor.isRunning()); }