Return-Path: X-Original-To: apmail-phoenix-commits-archive@minotaur.apache.org Delivered-To: apmail-phoenix-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B0D6110B6B for ; Wed, 12 Mar 2014 22:50:46 +0000 (UTC) Received: (qmail 9427 invoked by uid 500); 12 Mar 2014 22:50:45 -0000 Delivered-To: apmail-phoenix-commits-archive@phoenix.apache.org Received: (qmail 9371 invoked by uid 500); 12 Mar 2014 22:50:45 -0000 Mailing-List: contact commits-help@phoenix.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.incubator.apache.org Delivered-To: mailing list commits@phoenix.incubator.apache.org Received: (qmail 9350 invoked by uid 99); 12 Mar 2014 22:50:44 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Mar 2014 22:50:44 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 12 Mar 2014 22:50:29 +0000 Received: (qmail 4129 invoked by uid 99); 12 Mar 2014 22:49:56 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Mar 2014 22:49:56 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id D1BA59430D0; Wed, 12 Mar 2014 22:49:55 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jamestaylor@apache.org To: commits@phoenix.incubator.apache.org Date: Wed, 12 Mar 2014 22:50:10 -0000 Message-Id: <3e9df158dd2c4e23982c7062b43df3f8@git.apache.org> In-Reply-To: <2b1c7f3dbfcd4897897bd0360a510747@git.apache.org> References: <2b1c7f3dbfcd4897897bd0360a510747@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [16/41] PHOENIX-130 Separate execution of slow (integration) tests from fast unit tests (GabrielReid) X-Virus-Checked: Checked by ClamAV on apache.org http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/34f94a64/phoenix-core/src/test/java/org/apache/phoenix/end2end/ExecuteStatementsTest.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/ExecuteStatementsTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/ExecuteStatementsTest.java deleted file mode 100644 index c8435a2..0000000 --- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/ExecuteStatementsTest.java +++ /dev/null @@ -1,301 +0,0 @@ -/* - * 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.ATABLE_NAME; -import static org.apache.phoenix.util.TestUtil.A_VALUE; -import static org.apache.phoenix.util.TestUtil.BTABLE_NAME; -import static org.apache.phoenix.util.TestUtil.B_VALUE; -import static org.apache.phoenix.util.TestUtil.PTSDB_NAME; -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.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.StringReader; -import java.math.BigDecimal; -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.Arrays; -import java.util.List; - -import org.apache.phoenix.exception.SQLExceptionCode; -import org.apache.phoenix.query.QueryConstants; -import org.apache.phoenix.util.PhoenixRuntime; -import org.junit.Test; - - -public class ExecuteStatementsTest extends BaseHBaseManagedTimeTest { - - @Test - public void testExecuteStatements() throws Exception { - String tenantId = getOrganizationId(); - initATableValues(tenantId, getDefaultSplits(tenantId)); - String statements = - "create table if not exists " + ATABLE_NAME + // Shouldn't error out b/c of if not exists clause - " (organization_id char(15) not null, \n" + - " entity_id char(15) not null,\n" + - " a_string varchar(100),\n" + - " b_string varchar(100)\n" + - " CONSTRAINT pk PRIMARY KEY (organization_id,entity_id));\n" + - "create table " + PTSDB_NAME + - " (inst varchar null,\n" + - " host varchar null,\n" + - " date date not null,\n" + - " val decimal\n" + - " CONSTRAINT pk PRIMARY KEY (inst,host,date))\n" + - " split on (?,?,?);\n" + - "alter table " + PTSDB_NAME + " add if not exists val decimal;\n" + // Shouldn't error out b/c of if not exists clause - "alter table " + PTSDB_NAME + " drop column if exists blah;\n" + // Shouldn't error out b/c of if exists clause - "drop table if exists FOO.BAR;\n" + // Shouldn't error out b/c of if exists clause - "UPSERT INTO " + PTSDB_NAME + "(date, val, host) " + - " SELECT current_date(), x_integer+2, entity_id FROM ATABLE WHERE a_integer >= ?;" + - "UPSERT INTO " + PTSDB_NAME + "(date, val, inst)\n" + - " SELECT date+1, val*10, host FROM " + PTSDB_NAME + ";"; - - Date now = new Date(System.currentTimeMillis()); - Connection conn = DriverManager.getConnection(getUrl()); - conn.setAutoCommit(true); - List binds = Arrays.asList("a","j","s", 6); - int nStatements = PhoenixRuntime.executeStatements(conn, new StringReader(statements), binds); - assertEquals(7, nStatements); - - Date then = new Date(System.currentTimeMillis() + QueryConstants.MILLIS_IN_DAY); - String query = "SELECT host,inst, date,val FROM " + PTSDB_NAME + " where inst is not null"; - PreparedStatement statement = conn.prepareStatement(query); - - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(null, rs.getString(1)); - assertEquals(ROW6, rs.getString(2)); - assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); - assertEquals(null, rs.getBigDecimal(4)); - - assertTrue (rs.next()); - assertEquals(null, rs.getString(1)); - assertEquals(ROW7, rs.getString(2)); - assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); - assertTrue(BigDecimal.valueOf(70).compareTo(rs.getBigDecimal(4)) == 0); - - assertTrue (rs.next()); - assertEquals(null, rs.getString(1)); - assertEquals(ROW8, rs.getString(2)); - assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); - assertTrue(BigDecimal.valueOf(60).compareTo(rs.getBigDecimal(4)) == 0); - - assertTrue (rs.next()); - assertEquals(null, rs.getString(1)); - assertEquals(ROW9, rs.getString(2)); - assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); - assertTrue(BigDecimal.valueOf(50).compareTo(rs.getBigDecimal(4)) == 0); - - assertFalse(rs.next()); - conn.close(); - } - - @Test - public void testCharPadding() throws Exception { - Connection conn = DriverManager.getConnection(getUrl()); - String tableName = "foo"; - String rowKey = "hello"; - String testString = "world"; - String query = "create table " + tableName + - "(a_id integer not null, \n" + - "a_string char(10) not null, \n" + - "b_string char(8) not null \n" + - "CONSTRAINT my_pk PRIMARY KEY (a_id, a_string))"; - - - PreparedStatement statement = conn.prepareStatement(query); - statement.execute(); - statement = conn.prepareStatement( - "upsert into " + tableName + - " (a_id, " + - " a_string, " + - " b_string)" + - "VALUES (?, ?, ?)"); - statement.setInt(1, 1); - statement.setString(2, rowKey); - statement.setString(3, testString); - statement.execute(); - conn.commit(); - - ensureTableCreated(getUrl(),BTABLE_NAME, null, nextTimestamp()-2); - statement = conn.prepareStatement( - "upsert into BTABLE VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); - statement.setString(1, "abc"); - statement.setString(2, "xyz"); - statement.setString(3, "x"); - statement.setInt(4, 9); - statement.setString(5, "ab"); - statement.setInt(6, 1); - statement.setInt(7, 1); - statement.setString(8, "ab"); - statement.setString(9, "morning1"); - statement.execute(); - conn.commit(); - try { - // test rowkey and non-rowkey values in select statement - query = "select a_string, b_string from " + tableName; - assertCharacterPadding(conn.prepareStatement(query), rowKey, testString); - - // test with rowkey in where clause - query = "select a_string, b_string from " + tableName + " where a_id = 1 and a_string = '" + rowKey + "'"; - assertCharacterPadding(conn.prepareStatement(query), rowKey, testString); - - // test with non-rowkey in where clause - query = "select a_string, b_string from " + tableName + " where b_string = '" + testString + "'"; - assertCharacterPadding(conn.prepareStatement(query), rowKey, testString); - - // test with rowkey and id in where clause - query = "select a_string, b_string from " + tableName + " where a_id = 1 and a_string = '" + rowKey + "'"; - assertCharacterPadding(conn.prepareStatement(query), rowKey, testString); - - // test with rowkey and id in where clause where rowkey is greater than the length of the char.len - query = "select a_string, b_string from " + tableName + " where a_id = 1 and a_string = '" + rowKey + testString + "'"; - statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - assertFalse(rs.next()); - - // test with rowkey and id in where clause where rowkey is lesser than the length of the char.len - query = "select a_string, b_string from " + tableName + " where a_id = 1 and a_string = 'he'"; - statement = conn.prepareStatement(query); - rs = statement.executeQuery(); - assertFalse(rs.next()); - - String rowKey2 = "good"; - String testString2 = "morning"; - String testString8Char = "morning1"; - String testString10Char = "morning123"; - String upsert = "UPSERT INTO " + tableName + " values (2, '" + rowKey2 + "', '" + testString2+ "') "; - statement = conn.prepareStatement(upsert); - statement.execute(); - conn.commit(); - - // test upsert statement with padding - String tenantId = getOrganizationId(); - initATableValues(tenantId, getDefaultSplits(tenantId), null, nextTimestamp()-1); - - upsert = "UPSERT INTO " + tableName + "(a_id, a_string, b_string) " + - "SELECT A_INTEGER, A_STRING, B_STRING FROM ATABLE WHERE a_string = ?"; - - statement = conn.prepareStatement(upsert); - statement.setString(1, A_VALUE); - int rowsInserted = statement.executeUpdate(); - assertEquals(4, rowsInserted); - conn.commit(); - - query = "select a_string, b_string from " + tableName + " where a_string = '" + A_VALUE+"'"; - assertCharacterPadding(conn.prepareStatement(query), A_VALUE, B_VALUE); - - upsert = "UPSERT INTO " + tableName + " values (3, '" + testString2 + "', '" + testString2+ "') "; - statement = conn.prepareStatement(upsert); - statement.execute(); - conn.commit(); - query = "select a_string, b_string from " + tableName + " where a_id = 3 and a_string = b_string"; - assertCharacterPadding(conn.prepareStatement(query), testString2, testString2); - - // compare a higher length col with lower length : a_string(10), b_string(8) - query = "select a_string, b_string from " + tableName + " where a_id = 3 and b_string = a_string"; - statement = conn.prepareStatement(query); - statement.executeQuery(); - assertCharacterPadding(conn.prepareStatement(query), testString2, testString2); - - upsert = "UPSERT INTO " + tableName + " values (4, '" + rowKey2 + "', '" + rowKey2 + "') "; - statement = conn.prepareStatement(upsert); - statement.execute(); - conn.commit(); - - // where both the columns have same value with different paddings - query = "select a_string, b_string from " + tableName + " where a_id = 4 and b_string = a_string"; - assertCharacterPadding(conn.prepareStatement(query), rowKey2, rowKey2); - - upsert = "UPSERT INTO " + tableName + " values (5, '" + testString10Char + "', '" + testString8Char + "') "; - statement = conn.prepareStatement(upsert); - statement.execute(); - conn.commit(); - - // where smaller column is the subset of larger string - query = "select a_string, b_string from " + tableName + " where a_id = 5 and b_string = a_string"; - statement = conn.prepareStatement(query); - rs = statement.executeQuery(); - assertFalse(rs.next()); - - //where selecting from a CHAR(x) and upserting into a CHAR(y) where x>y - // upsert rowkey value greater than rowkey limit - try { - - upsert = "UPSERT INTO " + tableName + "(a_id, a_string, b_string) " + - "SELECT x_integer, organization_id, b_string FROM ATABLE WHERE a_string = ?"; - - statement = conn.prepareStatement(upsert); - statement.setString(1, A_VALUE); - statement.executeUpdate(); - fail("Should fail when bigger than expected character is inserted"); - } catch (SQLException ex) { - assertEquals(SQLExceptionCode.DATA_EXCEEDS_MAX_CAPACITY.getErrorCode(), ex.getErrorCode()); - } - - // upsert non-rowkey value greater than its limit - try { - - upsert = "UPSERT INTO " + tableName + "(a_id, a_string, b_string) " + - "SELECT y_integer, a_string, entity_id FROM ATABLE WHERE a_string = ?"; - - statement = conn.prepareStatement(upsert); - statement.setString(1, A_VALUE); - statement.executeUpdate(); - fail("Should fail when bigger than expected character is inserted"); - } - catch (SQLException ex) { - assertEquals(SQLExceptionCode.DATA_EXCEEDS_MAX_CAPACITY.getErrorCode(), ex.getErrorCode()); - } - - //where selecting from a CHAR(x) and upserting into a CHAR(y) where x<=y. - upsert = "UPSERT INTO " + tableName + "(a_id, a_string, b_string) " + - "SELECT a_integer, e_string, a_id FROM BTABLE"; - - statement = conn.prepareStatement(upsert); - rowsInserted = statement.executeUpdate(); - assertEquals(1, rowsInserted); - conn.commit(); - - query = "select a_string, b_string from " + tableName + " where a_string = 'morning1'"; - assertCharacterPadding(conn.prepareStatement(query), "morning1", "xyz"); - } finally { - conn.close(); - } - } - - - private void assertCharacterPadding(PreparedStatement statement, String rowKey, String testString) throws SQLException { - ResultSet rs = statement.executeQuery(); - assertTrue(rs.next()); - assertEquals(rowKey, rs.getString(1)); - assertEquals(testString, rs.getString(2)); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/34f94a64/phoenix-core/src/test/java/org/apache/phoenix/end2end/ExtendedQueryExecTest.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/ExtendedQueryExecTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/ExtendedQueryExecTest.java deleted file mode 100644 index 7775a0c..0000000 --- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/ExtendedQueryExecTest.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * 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.TEST_PROPERTIES; -import static org.junit.Assert.*; - -import java.sql.*; -import java.util.Properties; - -import org.junit.Test; - -import org.apache.phoenix.util.PhoenixRuntime; - - - -/** - * - * Extended tests for Phoenix JDBC implementation - * - */ -public class ExtendedQueryExecTest extends BaseClientManagedTimeTest { - - @Test - public void testToDateFunctionBind() throws Exception { - long ts = nextTimestamp(); - Date date = new Date(1); - String tenantId = getOrganizationId(); - - initATableValues(tenantId, getDefaultSplits(tenantId),date, ts); - - Properties props = new Properties(TEST_PROPERTIES); - props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts+1)); - Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props); - try { - String query = "SELECT a_date FROM atable WHERE organization_id='" + tenantId + "' and a_date < TO_DATE(?)"; - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, "1970-1-1 12:00:00"); - ResultSet rs = statement.executeQuery(); - verifyDateResultSet(rs, date, 3); - } finally { - conn.close(); - } - } - - @edu.umd.cs.findbugs.annotations.SuppressWarnings( - value="RV_RETURN_VALUE_IGNORED", - justification="Test code.") - @Test - public void testTypeMismatchToDateFunctionBind() throws Exception { - long ts = nextTimestamp(); - String tenantId = getOrganizationId(); - initATableValues(tenantId, getDefaultSplits(tenantId),null, ts); - Properties props = new Properties(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props); - try { - String query = "SELECT a_date FROM atable WHERE organization_id='" + tenantId + "' and a_date < TO_DATE(?)"; - PreparedStatement statement = conn.prepareStatement(query); - statement.setDate(1, new Date(2)); - statement.executeQuery(); - fail(); - } catch (SQLException e) { - assertTrue(e.getMessage().contains("Type mismatch. expected: [VARCHAR] but was: DATE at TO_DATE")); - } finally { - conn.close(); - } - } - - /** - * Basic tests for date function - * Related bug: W-1190856 - * @throws Exception - */ - @Test - public void testDateFunctions() throws Exception { - long ts = nextTimestamp(); - Date date = new Date(1); - String tenantId = getOrganizationId(); - - initATableValues(tenantId, getDefaultSplits(tenantId),date, ts); - - Properties props = new Properties(TEST_PROPERTIES); - props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts+1)); - Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props); - try { - ResultSet rs; - String queryPrefix = "SELECT a_date FROM atable WHERE organization_id='" + tenantId + "' and "; - - String queryDateArg = "a_date < TO_DATE('1970-1-1 12:00:00')"; - rs = getResultSet(conn, queryPrefix + queryDateArg); - verifyDateResultSet(rs, date, 3); - - // TODO: Bug #1 - Result should be the same as the the case above -// queryDateArg = "a_date < TO_DATE('70-1-1 12:0:0')"; -// rs = getResultSet(conn, queryPrefix + queryDateArg); -// verifyDateResultSet(rs, date, 3); - - // TODO: Bug #2 - Exception should be generated for invalid date/time -// queryDateArg = "a_date < TO_DATE('999-13-32 24:60:60')"; -// try { -// getResultSet(conn, queryPrefix + queryDateArg); -// fail("Expected SQLException"); -// } catch (SQLException ex) { -// // expected -// } - - queryDateArg = "a_date >= TO_DATE('1970-1-2 23:59:59') and a_date <= TO_DATE('1970-1-3 0:0:1')"; - rs = getResultSet(conn, queryPrefix + queryDateArg); - verifyDateResultSet(rs, new Date(date.getTime() + (2*60*60*24*1000)), 3); - - } finally { - conn.close(); - } - } - - /** - * aggregation - group by - * @throws Exception - */ - @Test - public void testDateGroupBy() throws Exception { - long ts = nextTimestamp(); - Date date = new Date(1); - String tenantId = getOrganizationId(); - - initATableValues(tenantId, getDefaultSplits(tenantId),date, ts); - - Properties props = new Properties(TEST_PROPERTIES); - props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts+1)); - Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props); - try { - ResultSet rs; - String query = "SELECT a_date, count(1) FROM atable WHERE organization_id='" + tenantId + "' group by a_date"; - rs = getResultSet(conn, query); - - /* 3 rows in expected result: - * 1969-12-31 3 - * 1970-01-01 3 - * 1970-01-02 3 - * */ - - assertTrue(rs.next()); - assertEquals(date, rs.getDate(1)); - assertEquals(3, rs.getInt(2)); - - // the following assertions fails - assertTrue(rs.next()); - assertEquals(3, rs.getInt(2)); - assertTrue(rs.next()); - assertEquals(3, rs.getInt(2)); - assertFalse(rs.next()); - - - } finally { - conn.close(); - } - } - - private ResultSet getResultSet(Connection conn, String query) throws SQLException { - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - return rs; - } - - private void verifyDateResultSet(ResultSet rs, Date date, int rowCount) throws SQLException { - for (int i=0; i