You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2014/03/12 22:31:46 UTC
[19/41] PHOENIX-130 Separate execution of slow (integration) tests
from fast unit tests (Gabriel Reid)
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8d6e2a58/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseConnectedQueryTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseConnectedQueryTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseConnectedQueryTest.java
deleted file mode 100644
index fe3e3a3..0000000
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseConnectedQueryTest.java
+++ /dev/null
@@ -1,760 +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.PhoenixRuntime.CURRENT_SCN_ATTRIB;
-import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL;
-import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR;
-import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_TERMINATOR;
-import static org.apache.phoenix.util.PhoenixRuntime.PHOENIX_TEST_DRIVER_URL_PARAM;
-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.B_VALUE;
-import static org.apache.phoenix.util.TestUtil.C_VALUE;
-import static org.apache.phoenix.util.TestUtil.ENTITYHISTID1;
-import static org.apache.phoenix.util.TestUtil.ENTITYHISTID2;
-import static org.apache.phoenix.util.TestUtil.ENTITYHISTID3;
-import static org.apache.phoenix.util.TestUtil.ENTITYHISTID4;
-import static org.apache.phoenix.util.TestUtil.ENTITYHISTID5;
-import static org.apache.phoenix.util.TestUtil.ENTITYHISTID6;
-import static org.apache.phoenix.util.TestUtil.ENTITYHISTID7;
-import static org.apache.phoenix.util.TestUtil.ENTITYHISTID8;
-import static org.apache.phoenix.util.TestUtil.ENTITYHISTID9;
-import static org.apache.phoenix.util.TestUtil.ENTITY_HISTORY_SALTED_TABLE_NAME;
-import static org.apache.phoenix.util.TestUtil.ENTITY_HISTORY_TABLE_NAME;
-import static org.apache.phoenix.util.TestUtil.E_VALUE;
-import static org.apache.phoenix.util.TestUtil.LOCALHOST;
-import static org.apache.phoenix.util.TestUtil.MILLIS_IN_DAY;
-import static org.apache.phoenix.util.TestUtil.PARENTID1;
-import static org.apache.phoenix.util.TestUtil.PARENTID2;
-import static org.apache.phoenix.util.TestUtil.PARENTID3;
-import static org.apache.phoenix.util.TestUtil.PARENTID4;
-import static org.apache.phoenix.util.TestUtil.PARENTID5;
-import static org.apache.phoenix.util.TestUtil.PARENTID6;
-import static org.apache.phoenix.util.TestUtil.PARENTID7;
-import static org.apache.phoenix.util.TestUtil.PARENTID8;
-import static org.apache.phoenix.util.TestUtil.PARENTID9;
-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 java.math.BigDecimal;
-import java.sql.Array;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.Date;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.Types;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Properties;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HConstants;
-import org.apache.hadoop.hbase.IntegrationTestingUtility;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
-import org.apache.phoenix.query.BaseTest;
-import org.apache.phoenix.query.HBaseFactoryProvider;
-import org.apache.phoenix.schema.PTableType;
-import org.apache.phoenix.util.PhoenixRuntime;
-import org.apache.phoenix.util.SchemaUtil;
-import org.apache.phoenix.util.TestUtil;
-import org.junit.BeforeClass;
-
-
-/**
- *
- * Base class for tests that need to be connected to an HBase server
- *
- *
- * @since 0.1
- */
-public abstract class BaseConnectedQueryTest extends BaseTest {
- protected static byte[][] getDefaultSplits(String tenantId) {
- return new byte[][] {
- Bytes.toBytes(tenantId + "00A"),
- Bytes.toBytes(tenantId + "00B"),
- Bytes.toBytes(tenantId + "00C"),
- };
- }
-
- protected static String getUrl() {
- Configuration conf = HBaseFactoryProvider.getConfigurationFactory().getConfiguration();
- boolean isDistributedCluster = false;
- isDistributedCluster =
- Boolean.parseBoolean(System.getProperty(IntegrationTestingUtility.IS_DISTRIBUTED_CLUSTER,
- "false"));
- if (!isDistributedCluster) {
- isDistributedCluster =
- conf.getBoolean(IntegrationTestingUtility.IS_DISTRIBUTED_CLUSTER, false);
- }
- // reconstruct url when running against a live cluster
- if (isDistributedCluster) {
- return JDBC_PROTOCOL + JDBC_PROTOCOL_SEPARATOR + conf.get(HConstants.ZOOKEEPER_QUORUM, LOCALHOST)
- + JDBC_PROTOCOL_SEPARATOR
- + conf.getInt(HConstants.ZOOKEEPER_CLIENT_PORT, HConstants.DEFAULT_ZOOKEPER_CLIENT_PORT)
- + JDBC_PROTOCOL_SEPARATOR
- + conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT, HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT)
- + JDBC_PROTOCOL_TERMINATOR + PHOENIX_TEST_DRIVER_URL_PARAM;
- } else {
- return TestUtil.PHOENIX_JDBC_URL;
- }
- }
-
- @BeforeClass
- public static void doSetup() throws Exception {
- startServer(getUrl());
- }
-
- protected static void deletePriorTables(long ts) throws Exception {
- deletePriorTables(ts, (String)null);
- }
-
- protected static void deletePriorTables(long ts, String tenantId) throws Exception {
- Properties props = new Properties();
- if (ts != HConstants.LATEST_TIMESTAMP) {
- props.setProperty(CURRENT_SCN_ATTRIB, Long.toString(ts));
- }
- Connection conn = null;
- conn = DriverManager.getConnection(getUrl(), props);
- try {
- deletePriorTables(ts, conn);
- deletePriorSequences(ts, conn);
- }
- finally {
- conn.close();
- }
- }
-
- private static void deletePriorTables(long ts, Connection globalConn) throws Exception {
- DatabaseMetaData dbmd = globalConn.getMetaData();
- // Drop VIEWs first, as we don't allow a TABLE with views to be dropped
- // Tables are sorted by TENANT_ID
- List<String[]> tableTypesList = Arrays.asList(new String[] {PTableType.VIEW.toString()}, new String[] {PTableType.TABLE.toString()});
- for (String[] tableTypes: tableTypesList) {
- ResultSet rs = dbmd.getTables(null, null, null, tableTypes);
- String lastTenantId = null;
- Connection conn = globalConn;
- while (rs.next()) {
- String fullTableName = SchemaUtil.getEscapedTableName(
- rs.getString(PhoenixDatabaseMetaData.TABLE_SCHEM),
- rs.getString(PhoenixDatabaseMetaData.TABLE_NAME));
- String ddl = "DROP " + rs.getString(PhoenixDatabaseMetaData.TABLE_TYPE) + " " + fullTableName;
- String tenantId = rs.getString(1);
- if (tenantId != null && !tenantId.equals(lastTenantId)) {
- if (lastTenantId != null) {
- conn.close();
- }
- // Open tenant-specific connection when we find a new one
- Properties props = new Properties(globalConn.getClientInfo());
- props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
- conn = DriverManager.getConnection(getUrl(), props);
- lastTenantId = tenantId;
- }
- conn.createStatement().executeUpdate(ddl);
- }
- if (lastTenantId != null) {
- conn.close();
- }
- }
- }
-
- private static void deletePriorSequences(long ts, Connection conn) throws Exception {
- // TODO: drop tenant-specific sequences too
- ResultSet rs = conn.createStatement().executeQuery("SELECT "
- + PhoenixDatabaseMetaData.SEQUENCE_SCHEMA + ","
- + PhoenixDatabaseMetaData.SEQUENCE_NAME
- + " FROM " + PhoenixDatabaseMetaData.SEQUENCE_TABLE_NAME);
- while (rs.next()) {
- conn.createStatement().execute("DROP SEQUENCE " + SchemaUtil.getTableName(rs.getString(1), rs.getString(2)));
- }
- }
-
- protected static void initSumDoubleValues(byte[][] splits) throws Exception {
- ensureTableCreated(getUrl(), "SumDoubleTest", splits);
- Properties props = new Properties();
- Connection conn = DriverManager.getConnection(getUrl(), props);
- try {
- // Insert all rows at ts
- PreparedStatement stmt = conn.prepareStatement(
- "upsert into " +
- "SumDoubleTest(" +
- " id, " +
- " d, " +
- " f, " +
- " ud, " +
- " uf) " +
- "VALUES (?, ?, ?, ?, ?)");
- stmt.setString(1, "1");
- stmt.setDouble(2, 0.001);
- stmt.setFloat(3, 0.01f);
- stmt.setDouble(4, 0.001);
- stmt.setFloat(5, 0.01f);
- stmt.execute();
-
- stmt.setString(1, "2");
- stmt.setDouble(2, 0.002);
- stmt.setFloat(3, 0.02f);
- stmt.setDouble(4, 0.002);
- stmt.setFloat(5, 0.02f);
- stmt.execute();
-
- stmt.setString(1, "3");
- stmt.setDouble(2, 0.003);
- stmt.setFloat(3, 0.03f);
- stmt.setDouble(4, 0.003);
- stmt.setFloat(5, 0.03f);
- stmt.execute();
-
- stmt.setString(1, "4");
- stmt.setDouble(2, 0.004);
- stmt.setFloat(3, 0.04f);
- stmt.setDouble(4, 0.004);
- stmt.setFloat(5, 0.04f);
- stmt.execute();
-
- stmt.setString(1, "5");
- stmt.setDouble(2, 0.005);
- stmt.setFloat(3, 0.05f);
- stmt.setDouble(4, 0.005);
- stmt.setFloat(5, 0.05f);
- stmt.execute();
-
- conn.commit();
- } finally {
- conn.close();
- }
- }
-
- protected static void initATableValues(String tenantId, byte[][] splits) throws Exception {
- initATableValues(tenantId, splits, null);
- }
-
- protected static void initATableValues(String tenantId, byte[][] splits, Date date) throws Exception {
- initATableValues(tenantId, splits, date, null);
- }
-
- protected static void initTablesWithArrays(String tenantId, Date date, Long ts, boolean useNull) throws Exception {
- Properties props = new Properties();
- if (ts != null) {
- props.setProperty(CURRENT_SCN_ATTRIB, ts.toString());
- }
- Connection conn = DriverManager.getConnection(getUrl(), props);
- try {
- // Insert all rows at ts
- PreparedStatement stmt = conn.prepareStatement(
- "upsert into " +
- "TABLE_WITH_ARRAY(" +
- " ORGANIZATION_ID, " +
- " ENTITY_ID, " +
- " a_string_array, " +
- " B_STRING, " +
- " A_INTEGER, " +
- " A_DATE, " +
- " X_DECIMAL, " +
- " x_long_array, " +
- " X_INTEGER," +
- " a_byte_array," +
- " A_SHORT," +
- " A_FLOAT," +
- " a_double_array," +
- " A_UNSIGNED_FLOAT," +
- " A_UNSIGNED_DOUBLE)" +
- "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
- stmt.setString(1, tenantId);
- stmt.setString(2, ROW1);
- // Need to support primitive
- String[] strArr = new String[4];
- strArr[0] = "ABC";
- if (useNull) {
- strArr[1] = null;
- } else {
- strArr[1] = "CEDF";
- }
- strArr[2] = "XYZWER";
- strArr[3] = "AB";
- Array array = conn.createArrayOf("VARCHAR", strArr);
- stmt.setArray(3, array);
- stmt.setString(4, B_VALUE);
- stmt.setInt(5, 1);
- stmt.setDate(6, date);
- stmt.setBigDecimal(7, null);
- // Need to support primitive
- Long[] longArr = new Long[2];
- longArr[0] = 25l;
- longArr[1] = 36l;
- array = conn.createArrayOf("BIGINT", longArr);
- stmt.setArray(8, array);
- stmt.setNull(9, Types.INTEGER);
- // Need to support primitive
- Byte[] byteArr = new Byte[2];
- byteArr[0] = 25;
- byteArr[1] = 36;
- array = conn.createArrayOf("TINYINT", byteArr);
- stmt.setArray(10, array);
- stmt.setShort(11, (short) 128);
- stmt.setFloat(12, 0.01f);
- // Need to support primitive
- Double[] doubleArr = new Double[4];
- doubleArr[0] = 25.343;
- doubleArr[1] = 36.763;
- doubleArr[2] = 37.56;
- doubleArr[3] = 386.63;
- array = conn.createArrayOf("DOUBLE", doubleArr);
- stmt.setArray(13, array);
- stmt.setFloat(14, 0.01f);
- stmt.setDouble(15, 0.0001);
- stmt.execute();
-
- conn.commit();
- } finally {
- conn.close();
- }
- }
-
- protected static void initATableValues(String tenantId, byte[][] splits, Date date, Long ts) throws Exception {
- if (ts == null) {
- ensureTableCreated(getUrl(), ATABLE_NAME, splits);
- } else {
- ensureTableCreated(getUrl(), ATABLE_NAME, splits, ts-5);
- }
-
- Properties props = new Properties();
- if (ts != null) {
- props.setProperty(CURRENT_SCN_ATTRIB, Long.toString(ts-3));
- }
- Connection conn = DriverManager.getConnection(getUrl(), props);
- try {
- // Insert all rows at ts
- PreparedStatement stmt = conn.prepareStatement(
- "upsert into " +
- "ATABLE(" +
- " ORGANIZATION_ID, " +
- " ENTITY_ID, " +
- " A_STRING, " +
- " B_STRING, " +
- " A_INTEGER, " +
- " A_DATE, " +
- " X_DECIMAL, " +
- " X_LONG, " +
- " X_INTEGER," +
- " Y_INTEGER," +
- " A_BYTE," +
- " A_SHORT," +
- " A_FLOAT," +
- " A_DOUBLE," +
- " A_UNSIGNED_FLOAT," +
- " A_UNSIGNED_DOUBLE)" +
- "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
- stmt.setString(1, tenantId);
- stmt.setString(2, ROW1);
- stmt.setString(3, A_VALUE);
- stmt.setString(4, B_VALUE);
- stmt.setInt(5, 1);
- stmt.setDate(6, date);
- stmt.setBigDecimal(7, null);
- stmt.setNull(8, Types.BIGINT);
- stmt.setNull(9, Types.INTEGER);
- stmt.setNull(10, Types.INTEGER);
- stmt.setByte(11, (byte)1);
- stmt.setShort(12, (short) 128);
- stmt.setFloat(13, 0.01f);
- stmt.setDouble(14, 0.0001);
- stmt.setFloat(15, 0.01f);
- stmt.setDouble(16, 0.0001);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, ROW2);
- stmt.setString(3, A_VALUE);
- stmt.setString(4, C_VALUE);
- stmt.setInt(5, 2);
- stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1));
- stmt.setBigDecimal(7, null);
- stmt.setNull(8, Types.BIGINT);
- stmt.setNull(9, Types.INTEGER);
- stmt.setNull(10, Types.INTEGER);
- stmt.setByte(11, (byte)2);
- stmt.setShort(12, (short) 129);
- stmt.setFloat(13, 0.02f);
- stmt.setDouble(14, 0.0002);
- stmt.setFloat(15, 0.02f);
- stmt.setDouble(16, 0.0002);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, ROW3);
- stmt.setString(3, A_VALUE);
- stmt.setString(4, E_VALUE);
- stmt.setInt(5, 3);
- stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2));
- stmt.setBigDecimal(7, null);
- stmt.setNull(8, Types.BIGINT);
- stmt.setNull(9, Types.INTEGER);
- stmt.setNull(10, Types.INTEGER);
- stmt.setByte(11, (byte)3);
- stmt.setShort(12, (short) 130);
- stmt.setFloat(13, 0.03f);
- stmt.setDouble(14, 0.0003);
- stmt.setFloat(15, 0.03f);
- stmt.setDouble(16, 0.0003);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, ROW4);
- stmt.setString(3, A_VALUE);
- stmt.setString(4, B_VALUE);
- stmt.setInt(5, 4);
- stmt.setDate(6, date == null ? null : date);
- stmt.setBigDecimal(7, null);
- stmt.setNull(8, Types.BIGINT);
- stmt.setNull(9, Types.INTEGER);
- stmt.setNull(10, Types.INTEGER);
- stmt.setByte(11, (byte)4);
- stmt.setShort(12, (short) 131);
- stmt.setFloat(13, 0.04f);
- stmt.setDouble(14, 0.0004);
- stmt.setFloat(15, 0.04f);
- stmt.setDouble(16, 0.0004);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, ROW5);
- stmt.setString(3, B_VALUE);
- stmt.setString(4, C_VALUE);
- stmt.setInt(5, 5);
- stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1));
- stmt.setBigDecimal(7, null);
- stmt.setNull(8, Types.BIGINT);
- stmt.setNull(9, Types.INTEGER);
- stmt.setNull(10, Types.INTEGER);
- stmt.setByte(11, (byte)5);
- stmt.setShort(12, (short) 132);
- stmt.setFloat(13, 0.05f);
- stmt.setDouble(14, 0.0005);
- stmt.setFloat(15, 0.05f);
- stmt.setDouble(16, 0.0005);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, ROW6);
- stmt.setString(3, B_VALUE);
- stmt.setString(4, E_VALUE);
- stmt.setInt(5, 6);
- stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2));
- stmt.setBigDecimal(7, null);
- stmt.setNull(8, Types.BIGINT);
- stmt.setNull(9, Types.INTEGER);
- stmt.setNull(10, Types.INTEGER);
- stmt.setByte(11, (byte)6);
- stmt.setShort(12, (short) 133);
- stmt.setFloat(13, 0.06f);
- stmt.setDouble(14, 0.0006);
- stmt.setFloat(15, 0.06f);
- stmt.setDouble(16, 0.0006);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, ROW7);
- stmt.setString(3, B_VALUE);
- stmt.setString(4, B_VALUE);
- stmt.setInt(5, 7);
- stmt.setDate(6, date == null ? null : date);
- stmt.setBigDecimal(7, BigDecimal.valueOf(0.1));
- stmt.setLong(8, 5L);
- stmt.setInt(9, 5);
- stmt.setNull(10, Types.INTEGER);
- stmt.setByte(11, (byte)7);
- stmt.setShort(12, (short) 134);
- stmt.setFloat(13, 0.07f);
- stmt.setDouble(14, 0.0007);
- stmt.setFloat(15, 0.07f);
- stmt.setDouble(16, 0.0007);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, ROW8);
- stmt.setString(3, B_VALUE);
- stmt.setString(4, C_VALUE);
- stmt.setInt(5, 8);
- stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1));
- stmt.setBigDecimal(7, BigDecimal.valueOf(3.9));
- long l = Integer.MIN_VALUE - 1L;
- assert(l < Integer.MIN_VALUE);
- stmt.setLong(8, l);
- stmt.setInt(9, 4);
- stmt.setNull(10, Types.INTEGER);
- stmt.setByte(11, (byte)8);
- stmt.setShort(12, (short) 135);
- stmt.setFloat(13, 0.08f);
- stmt.setDouble(14, 0.0008);
- stmt.setFloat(15, 0.08f);
- stmt.setDouble(16, 0.0008);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, ROW9);
- stmt.setString(3, C_VALUE);
- stmt.setString(4, E_VALUE);
- stmt.setInt(5, 9);
- stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2));
- stmt.setBigDecimal(7, BigDecimal.valueOf(3.3));
- l = Integer.MAX_VALUE + 1L;
- assert(l > Integer.MAX_VALUE);
- stmt.setLong(8, l);
- stmt.setInt(9, 3);
- stmt.setInt(10, 300);
- stmt.setByte(11, (byte)9);
- stmt.setShort(12, (short) 0);
- stmt.setFloat(13, 0.09f);
- stmt.setDouble(14, 0.0009);
- stmt.setFloat(15, 0.09f);
- stmt.setDouble(16, 0.0009);
- stmt.execute();
-
- conn.commit();
- } finally {
- conn.close();
- }
- }
- protected static void initEntityHistoryTableValues(String tenantId, byte[][] splits) throws Exception {
- initEntityHistoryTableValues(tenantId, splits, null);
- }
-
- protected static void initEntityHistoryTableValues(String tenantId, byte[][] splits, Date date) throws Exception {
- initEntityHistoryTableValues(tenantId, splits, date, null);
- }
-
- protected static void initEntityHistoryTableValues(String tenantId, byte[][] splits, Date date, Long ts) throws Exception {
- if (ts == null) {
- ensureTableCreated(getUrl(), ENTITY_HISTORY_TABLE_NAME, splits);
- } else {
- ensureTableCreated(getUrl(), ENTITY_HISTORY_TABLE_NAME, splits, ts-2);
- }
-
- Properties props = new Properties();
- if (ts != null) {
- props.setProperty(CURRENT_SCN_ATTRIB, ts.toString());
- }
- Connection conn = DriverManager.getConnection(getUrl(), props);
- try {
- // Insert all rows at ts
- PreparedStatement stmt = conn.prepareStatement(
- "upsert into " +
- ENTITY_HISTORY_TABLE_NAME+
- "(" +
- " ORGANIZATION_ID, " +
- " PARENT_ID, " +
- " CREATED_DATE, " +
- " ENTITY_HISTORY_ID, " +
- " OLD_VALUE, " +
- " NEW_VALUE) " +
- "VALUES (?, ?, ?, ?, ?, ?)");
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID1);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID1);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID2);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID2);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
-
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID3);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID3);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID4);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID4);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID5);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID5);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID6);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID6);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID7);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID7);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID8);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID8);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID9);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID9);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
- conn.commit();
- } finally {
- conn.close();
- }
- }
-
- protected static void initSaltedEntityHistoryTableValues(String tenantId, byte[][] splits, Date date, Long ts) throws Exception {
- if (ts == null) {
- ensureTableCreated(getUrl(), ENTITY_HISTORY_SALTED_TABLE_NAME, splits);
- } else {
- ensureTableCreated(getUrl(), ENTITY_HISTORY_SALTED_TABLE_NAME, splits, ts-2);
- }
-
- Properties props = new Properties();
- if (ts != null) {
- props.setProperty(CURRENT_SCN_ATTRIB, ts.toString());
- }
- Connection conn = DriverManager.getConnection(getUrl(), props);
- try {
- // Insert all rows at ts
- PreparedStatement stmt = conn.prepareStatement(
- "upsert into " +
- ENTITY_HISTORY_SALTED_TABLE_NAME+
- "(" +
- " ORGANIZATION_ID, " +
- " PARENT_ID, " +
- " CREATED_DATE, " +
- " ENTITY_HISTORY_ID, " +
- " OLD_VALUE, " +
- " NEW_VALUE) " +
- "VALUES (?, ?, ?, ?, ?, ?)");
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID1);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID1);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID2);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID2);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
-
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID3);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID3);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID4);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID4);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID5);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID5);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID6);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID6);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID7);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID7);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID8);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID8);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
- stmt.setString(1, tenantId);
- stmt.setString(2, PARENTID9);
- stmt.setDate(3, date);
- stmt.setString(4, ENTITYHISTID9);
- stmt.setString(5, A_VALUE);
- stmt.setString(6, B_VALUE);
- stmt.execute();
-
- conn.commit();
- } finally {
- conn.close();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8d6e2a58/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTest.java
deleted file mode 100644
index 81c0a36..0000000
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTest.java
+++ /dev/null
@@ -1,41 +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 org.apache.hadoop.hbase.HConstants;
-import org.junit.Before;
-
-/**
- *
- * Base class for tests that have HBase manage the time stamps.
- * We need to separate these from tests that manged the time stamp
- * themselves, because we create/destroy the Phoenix tables
- * between tests and only allow a table time stamp to increase.
- * If we let HBase set the time stamps, then our client time stamps
- * will usually be smaller than these time stamps and the table
- * deletion/creation would fail.
- *
- *
- * @since 0.1
- */
-public abstract class BaseHBaseManagedTimeTest extends BaseConnectedQueryTest {
- @Before
- public void doTestSetup() throws Exception {
- deletePriorTables(HConstants.LATEST_TIMESTAMP);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8d6e2a58/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseParallelIteratorsRegionSplitterTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseParallelIteratorsRegionSplitterTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseParallelIteratorsRegionSplitterTest.java
deleted file mode 100644
index 8371e75..0000000
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseParallelIteratorsRegionSplitterTest.java
+++ /dev/null
@@ -1,92 +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.STABLE_NAME;
-import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.phoenix.jdbc.PhoenixConnection;
-import org.apache.phoenix.query.QueryServices;
-import org.apache.phoenix.schema.PTableKey;
-import org.apache.phoenix.schema.TableRef;
-import org.apache.phoenix.util.PhoenixRuntime;
-import org.apache.phoenix.util.ReadOnlyProps;
-import org.junit.BeforeClass;
-
-import com.google.common.collect.Maps;
-
-
-public class BaseParallelIteratorsRegionSplitterTest extends BaseClientManagedTimeTest {
-
- protected static final byte[] KMIN = new byte[] {'!'};
- protected static final byte[] KMIN2 = new byte[] {'.'};
- protected static final byte[] K1 = new byte[] {'a'};
- protected static final byte[] K3 = new byte[] {'c'};
- protected static final byte[] K4 = new byte[] {'d'};
- protected static final byte[] K5 = new byte[] {'e'};
- protected static final byte[] K6 = new byte[] {'f'};
- protected static final byte[] K9 = new byte[] {'i'};
- protected static final byte[] K11 = new byte[] {'k'};
- protected static final byte[] K12 = new byte[] {'l'};
- protected static final byte[] KMAX = new byte[] {'~'};
- protected static final byte[] KMAX2 = new byte[] {'z'};
-
- @BeforeClass
- public static void doSetup() throws Exception {
- int targetQueryConcurrency = 3;
- int maxQueryConcurrency = 5;
- Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
- props.put(QueryServices.MAX_QUERY_CONCURRENCY_ATTRIB, Integer.toString(maxQueryConcurrency));
- props.put(QueryServices.TARGET_QUERY_CONCURRENCY_ATTRIB, Integer.toString(targetQueryConcurrency));
- props.put(QueryServices.MAX_INTRA_REGION_PARALLELIZATION_ATTRIB, Integer.toString(Integer.MAX_VALUE));
- // Must update config before starting server
- startServer(getUrl(), new ReadOnlyProps(props.entrySet().iterator()));
- }
-
- protected void initTableValues(long ts) throws Exception {
- byte[][] splits = new byte[][] {K3,K4,K9,K11};
- ensureTableCreated(getUrl(),STABLE_NAME,splits, ts-2);
- String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + ts;
- Properties props = new Properties(TEST_PROPERTIES);
- Connection conn = DriverManager.getConnection(url, props);
- PreparedStatement stmt = conn.prepareStatement(
- "upsert into " + STABLE_NAME + " VALUES (?, ?)");
- stmt.setString(1, new String(KMIN));
- stmt.setInt(2, 1);
- stmt.execute();
- stmt.setString(1, new String(KMAX));
- stmt.setInt(2, 2);
- stmt.execute();
- conn.commit();
- conn.close();
- }
-
- protected static TableRef getTableRef(Connection conn, long ts) throws SQLException {
- PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
- TableRef table = new TableRef(null,pconn.getMetaDataCache().getTable(new PTableKey(pconn.getTenantId(), STABLE_NAME)),ts, false);
- return table;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8d6e2a58/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseTenantSpecificTablesTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseTenantSpecificTablesTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseTenantSpecificTablesTest.java
deleted file mode 100644
index 7e4b99f..0000000
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseTenantSpecificTablesTest.java
+++ /dev/null
@@ -1,69 +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.PhoenixRuntime.TENANT_ID_ATTRIB;
-
-import java.sql.SQLException;
-
-import org.junit.Before;
-
-/**
- * Describe your class here.
- *
- *
- * @since 2.2
- */
-public abstract class BaseTenantSpecificTablesTest extends BaseClientManagedTimeTest {
- protected static final String TENANT_ID = "ZZTop";
- protected static final String TENANT_TYPE_ID = "abc";
- protected static final String PHOENIX_JDBC_TENANT_SPECIFIC_URL = getUrl() + ';' + TENANT_ID_ATTRIB + '=' + TENANT_ID;
-
- protected static final String PARENT_TABLE_NAME = "PARENT_TABLE";
- protected static final String PARENT_TABLE_DDL = "CREATE TABLE " + PARENT_TABLE_NAME + " ( \n" +
- " user VARCHAR ,\n" +
- " tenant_id VARCHAR(5) NOT NULL,\n" +
- " tenant_type_id VARCHAR(3) NOT NULL, \n" +
- " id INTEGER NOT NULL\n" +
- " CONSTRAINT pk PRIMARY KEY (tenant_id, tenant_type_id, id)) MULTI_TENANT=true";
-
- protected static final String TENANT_TABLE_NAME = "TENANT_TABLE";
- protected static final String TENANT_TABLE_DDL = "CREATE VIEW " + TENANT_TABLE_NAME + " ( \n" +
- " tenant_col VARCHAR) AS SELECT *\n" +
- " FROM " + PARENT_TABLE_NAME + " WHERE tenant_type_id= '" + TENANT_TYPE_ID + "'";
-
- protected static final String PARENT_TABLE_NAME_NO_TENANT_TYPE_ID = "PARENT_TABLE_NO_TENANT_TYPE_ID";
- protected static final String PARENT_TABLE_DDL_NO_TENANT_TYPE_ID = "CREATE TABLE " + PARENT_TABLE_NAME_NO_TENANT_TYPE_ID + " ( \n" +
- " user VARCHAR ,\n" +
- " tenant_id VARCHAR(5) NOT NULL,\n" +
- " id INTEGER NOT NULL,\n" +
- " CONSTRAINT pk PRIMARY KEY (tenant_id, id)) MULTI_TENANT=true";
-
- protected static final String TENANT_TABLE_NAME_NO_TENANT_TYPE_ID = "TENANT_TABLE_NO_TENANT_TYPE_ID";
- protected static final String TENANT_TABLE_DDL_NO_TENANT_TYPE_ID = "CREATE VIEW " + TENANT_TABLE_NAME_NO_TENANT_TYPE_ID + " ( \n" +
- " tenant_col VARCHAR) AS SELECT *\n" +
- " FROM " + PARENT_TABLE_NAME_NO_TENANT_TYPE_ID;
-
- @Before
- public void createTables() throws SQLException {
- createTestTable(getUrl(), PARENT_TABLE_DDL, null, nextTimestamp());
- createTestTable(getUrl(), PARENT_TABLE_DDL_NO_TENANT_TYPE_ID, null, nextTimestamp());
- createTestTable(PHOENIX_JDBC_TENANT_SPECIFIC_URL, TENANT_TABLE_DDL, null, nextTimestamp());
- createTestTable(PHOENIX_JDBC_TENANT_SPECIFIC_URL, TENANT_TABLE_DDL_NO_TENANT_TYPE_ID, null, nextTimestamp());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8d6e2a58/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseTenantSpecificViewIndexTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseTenantSpecificViewIndexTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseTenantSpecificViewIndexTest.java
deleted file mode 100644
index c454104..0000000
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseTenantSpecificViewIndexTest.java
+++ /dev/null
@@ -1,156 +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 com.google.common.collect.Sets.newHashSet;
-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.ResultSet;
-import java.sql.SQLException;
-import java.util.Properties;
-import java.util.Set;
-
-import org.apache.hadoop.hbase.util.Pair;
-import org.apache.phoenix.util.PhoenixRuntime;
-import org.apache.phoenix.util.QueryUtil;
-import org.junit.After;
-
-public class BaseTenantSpecificViewIndexTest extends BaseHBaseManagedTimeTest {
-
- public static final String TENANT1_ID = "tenant1";
- public static final String TENANT2_ID = "tenant2";
-
- protected Set<Pair<String, String>> tenantViewsToDelete = newHashSet();
-
- protected void testUpdatableView(Integer saltBuckets) throws Exception {
- createBaseTable("t", saltBuckets);
- Connection conn = createTenantConnection(TENANT1_ID);
- try {
- createAndPopulateTenantView(conn, TENANT1_ID, "t", "");
- createAndVerifyIndex(conn, saltBuckets, TENANT1_ID, "");
- verifyViewData(conn, "");
- } finally {
- try { conn.close();} catch (Exception ignored) {}
- }
- }
-
- protected void testUpdatableViewsWithSameNameDifferentTenants(Integer saltBuckets) throws Exception {
- createBaseTable("t2", saltBuckets);
- Connection conn1 = createTenantConnection(TENANT1_ID);
- Connection conn2 = createTenantConnection(TENANT2_ID);
- try {
- String prefixForTenant1Data = "TI";
- String prefixForTenant2Data = "TII";
-
- // tenant views with same name for two different tables
- createAndPopulateTenantView(conn1, TENANT1_ID, "t2", prefixForTenant1Data);
- createAndPopulateTenantView(conn2, TENANT2_ID, "t2", prefixForTenant2Data);
-
- createAndVerifyIndex(conn1, saltBuckets, TENANT1_ID, prefixForTenant1Data);
- createAndVerifyIndex(conn2, saltBuckets, TENANT2_ID, prefixForTenant2Data);
-
- verifyViewData(conn1, prefixForTenant1Data);
- verifyViewData(conn2, prefixForTenant2Data);
- } finally {
- try { conn1.close();} catch (Exception ignored) {}
- try { conn2.close();} catch (Exception ignored) {}
- }
- }
-
- private void createBaseTable(String tableName, Integer saltBuckets) throws SQLException {
- Connection conn = DriverManager.getConnection(getUrl());
- String ddl = "CREATE TABLE " + tableName + " (t_id VARCHAR NOT NULL,\n" +
- "k1 INTEGER NOT NULL,\n" +
- "k2 INTEGER NOT NULL,\n" +
- "v1 VARCHAR,\n" +
- "CONSTRAINT pk PRIMARY KEY (t_id, k1, k2))\n" +
- "multi_tenant=true" + (saltBuckets == null ? "" : (",salt_buckets="+saltBuckets));
- conn.createStatement().execute(ddl);
- conn.close();
- }
-
- private void createAndPopulateTenantView(Connection conn, String tenantId, String baseTable, String valuePrefix) throws SQLException {
- String ddl = "CREATE VIEW v(v2 VARCHAR) AS SELECT * FROM " + baseTable + " WHERE k1 = 1";
- conn.createStatement().execute(ddl);
- tenantViewsToDelete.add(new Pair<String, String>(tenantId, "v"));
- for (int i = 0; i < 10; i++) {
- conn.createStatement().execute("UPSERT INTO v(k2,v1,v2) VALUES(" + i + ",'" + valuePrefix + "v1-" + (i%5) + "','" + valuePrefix + "v2-" + (i%2) + "')");
- }
- conn.commit();
- }
-
- private void createAndVerifyIndex(Connection conn, Integer saltBuckets, String tenantId, String valuePrefix) throws SQLException {
- conn.createStatement().execute("CREATE INDEX i ON v(v2)");
- conn.createStatement().execute("UPSERT INTO v(k2,v1,v2) VALUES (-1, 'blah', 'superblah')"); // sanity check that we can upsert after index is there
- conn.commit();
- ResultSet rs = conn.createStatement().executeQuery("EXPLAIN SELECT k1, k2, v2 FROM v WHERE v2='" + valuePrefix + "v2-1'");
- assertEquals(saltBuckets == null ?
- "CLIENT PARALLEL 1-WAY RANGE SCAN OVER I ['" + tenantId + "',-32768,'" + valuePrefix + "v2-1']" :
- "CLIENT PARALLEL 4-WAY SKIP SCAN ON 3 KEYS OVER I [0,'" + tenantId + "',-32768,'" + valuePrefix + "v2-1'] - [2,'" + tenantId + "',-32768,'" + valuePrefix + "v2-1']\n" +
- "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
- }
-
- private Connection createTenantConnection(String tenantId) throws SQLException {
- Properties props = new Properties();
- props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
- return DriverManager.getConnection(getUrl(), props);
- }
-
- private void verifyViewData(Connection conn, String valuePrefix) throws SQLException {
- String query = "SELECT k1, k2, v2 FROM v WHERE v2='" + valuePrefix + "v2-1'";
- ResultSet rs = conn.createStatement().executeQuery(query);
- assertTrue(rs.next());
- assertEquals(1, rs.getInt(1));
- assertEquals(1, rs.getInt(2));
- assertEquals(valuePrefix + "v2-1", rs.getString(3));
- assertTrue(rs.next());
- assertEquals(1, rs.getInt(1));
- assertEquals(3, rs.getInt(2));
- assertEquals(valuePrefix + "v2-1", rs.getString(3));
- assertTrue(rs.next());
- assertEquals(1, rs.getInt(1));
- assertEquals(5, rs.getInt(2));
- assertEquals(valuePrefix + "v2-1", rs.getString(3));
- assertTrue(rs.next());
- assertEquals(1, rs.getInt(1));
- assertEquals(7, rs.getInt(2));
- assertEquals(valuePrefix + "v2-1", rs.getString(3));
- assertTrue(rs.next());
- assertEquals(1, rs.getInt(1));
- assertEquals(9, rs.getInt(2));
- assertEquals(valuePrefix + "v2-1", rs.getString(3));
- assertFalse(rs.next());
- }
-
- @After
- public void deleteTenantViews() throws Exception {
- for (Pair<String,String> tenantView : tenantViewsToDelete) {
- try {
- Connection conn = createTenantConnection(tenantView.getFirst());
- conn.createStatement().executeUpdate("drop view " + tenantView.getSecond());
- conn.close();
- }
- catch (Exception ignored) {}
- }
- tenantViewsToDelete.clear();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8d6e2a58/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseViewTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseViewTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseViewTest.java
deleted file mode 100644
index d9d9255..0000000
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseViewTest.java
+++ /dev/null
@@ -1,133 +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.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.math.BigDecimal;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.util.Map;
-
-import org.apache.phoenix.query.QueryServices;
-import org.apache.phoenix.util.QueryUtil;
-import org.apache.phoenix.util.ReadOnlyProps;
-import org.junit.BeforeClass;
-
-import com.google.common.collect.Maps;
-
-public class BaseViewTest extends BaseHBaseManagedTimeTest {
-
- @BeforeClass
- public static void doSetup() throws Exception {
- Map<String,String> props = Maps.newHashMapWithExpectedSize(1);
- // Don't split intra region so we can more easily know that the n-way parallelization is for the explain plan
- props.put(QueryServices.MAX_INTRA_REGION_PARALLELIZATION_ATTRIB, Integer.toString(1));
- // Must update config before starting server
- startServer(getUrl(), new ReadOnlyProps(props.entrySet().iterator()));
- }
-
- protected void testUpdatableViewWithIndex(Integer saltBuckets) throws Exception {
- testUpdatableView(saltBuckets);
- testUpdatableViewIndex(saltBuckets);
- }
-
- protected void testUpdatableView(Integer saltBuckets) throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- String ddl = "CREATE TABLE t (k1 INTEGER NOT NULL, k2 INTEGER NOT NULL, k3 DECIMAL, s VARCHAR CONSTRAINT pk PRIMARY KEY (k1, k2, k3))" + (saltBuckets == null ? "" : (" SALT_BUCKETS="+saltBuckets));
- conn.createStatement().execute(ddl);
- ddl = "CREATE VIEW v AS SELECT * FROM t WHERE k1 = 1";
- conn.createStatement().execute(ddl);
- for (int i = 0; i < 10; i++) {
- conn.createStatement().execute("UPSERT INTO t VALUES(" + (i % 4) + "," + (i+100) + "," + (i > 5 ? 2 : 1) + ")");
- }
- conn.commit();
- ResultSet rs;
-
- rs = conn.createStatement().executeQuery("SELECT count(*) FROM t");
- assertTrue(rs.next());
- assertEquals(10, rs.getInt(1));
- rs = conn.createStatement().executeQuery("SELECT count(*) FROM v");
- assertTrue(rs.next());
- assertEquals(3, rs.getInt(1));
- rs = conn.createStatement().executeQuery("SELECT k1, k2, k3 FROM v");
- assertTrue(rs.next());
- assertEquals(1, rs.getInt(1));
- assertEquals(101, rs.getInt(2));
- assertEquals(1, rs.getInt(3));
- assertTrue(rs.next());
- assertEquals(1, rs.getInt(1));
- assertEquals(105, rs.getInt(2));
- assertEquals(1, rs.getInt(3));
- assertTrue(rs.next());
- assertEquals(1, rs.getInt(1));
- assertEquals(109, rs.getInt(2));
- assertEquals(2, rs.getInt(3));
- assertFalse(rs.next());
-
- conn.createStatement().execute("UPSERT INTO v(k2,S,k3) VALUES(120,'foo',50.0)");
- conn.createStatement().execute("UPSERT INTO v(k2,S,k3) VALUES(121,'bar',51.0)");
- conn.commit();
- rs = conn.createStatement().executeQuery("SELECT k1, k2 FROM v WHERE k2 >= 120");
- assertTrue(rs.next());
- assertEquals(1, rs.getInt(1));
- assertEquals(120, rs.getInt(2));
- assertTrue(rs.next());
- assertEquals(1, rs.getInt(1));
- assertEquals(121, rs.getInt(2));
- assertFalse(rs.next());
- }
-
- protected void testUpdatableViewIndex(Integer saltBuckets) throws Exception {
- ResultSet rs;
- Connection conn = DriverManager.getConnection(getUrl());
- conn.createStatement().execute("CREATE INDEX i1 on v(k3) include (s)");
- String query = "SELECT k1, k2, k3, s FROM v WHERE k3 = 51.0";
- rs = conn.createStatement().executeQuery(query);
- assertTrue(rs.next());
- assertEquals(1, rs.getInt(1));
- assertEquals(121, rs.getInt(2));
- assertTrue(BigDecimal.valueOf(51.0).compareTo(rs.getBigDecimal(3))==0);
- assertEquals("bar", rs.getString(4));
- assertFalse(rs.next());
- rs = conn.createStatement().executeQuery("EXPLAIN " + query);
- assertEquals(saltBuckets == null
- ? "CLIENT PARALLEL 1-WAY RANGE SCAN OVER I1 [" + Short.MIN_VALUE + ",51]"
- : "CLIENT PARALLEL " + saltBuckets + "-WAY SKIP SCAN ON 3 KEYS OVER I1 [0," + Short.MIN_VALUE + ",51] - [2," + Short.MIN_VALUE + ",51]\nCLIENT MERGE SORT",
- QueryUtil.getExplainPlan(rs));
-
- conn.createStatement().execute("CREATE INDEX i2 on v(s)");
- query = "SELECT k1, k2, s FROM v WHERE s = 'foo'";
- rs = conn.createStatement().executeQuery(query);
- assertTrue(rs.next());
- assertEquals(1, rs.getInt(1));
- assertEquals(120, rs.getInt(2));
- assertEquals("foo", rs.getString(3));
- assertFalse(rs.next());
- rs = conn.createStatement().executeQuery("EXPLAIN " + query);
- assertEquals(saltBuckets == null
- ? "CLIENT PARALLEL 1-WAY RANGE SCAN OVER I2 [" + (Short.MIN_VALUE+1) + ",'foo']"
- : "CLIENT PARALLEL " + saltBuckets + "-WAY SKIP SCAN ON 3 KEYS OVER I2 [0," + (Short.MIN_VALUE+1) + ",'foo'] - [2," + (Short.MIN_VALUE+1) + ",'foo']\nCLIENT MERGE SORT",
- QueryUtil.getExplainPlan(rs));
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8d6e2a58/phoenix-core/src/test/java/org/apache/phoenix/end2end/BinaryRowKeyTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BinaryRowKeyTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/BinaryRowKeyTest.java
deleted file mode 100644
index 86a3b8c..0000000
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BinaryRowKeyTest.java
+++ /dev/null
@@ -1,147 +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.TEST_PROPERTIES;
-import static org.junit.Assert.*;
-
-import java.sql.*;
-import java.util.Properties;
-
-import org.junit.Test;
-
-public class BinaryRowKeyTest extends BaseHBaseManagedTimeTest {
-
- private static void initTableValues() throws SQLException {
- Properties props = new Properties(TEST_PROPERTIES);
- Connection conn = DriverManager.getConnection(getUrl(), props);
- conn.setAutoCommit(false);
-
- try {
- String ddl = "CREATE TABLE test_table" +
- " (a_binary binary(10) not null, \n" +
- " a_string varchar not null, \n" +
- " b_binary varbinary \n" +
- " CONSTRAINT pk PRIMARY KEY (a_binary, a_string))\n";
- createTestTable(getUrl(), ddl);
-
- String query;
- PreparedStatement stmt;
-
- query = "UPSERT INTO test_table"
- + "(a_binary, a_string) "
- + "VALUES(?,?)";
- stmt = conn.prepareStatement(query);
-
- stmt.setBytes(1, new byte[] {0,0,0,0,0,0,0,0,0,1});
- stmt.setString(2, "a");
- stmt.execute();
-
- stmt.setBytes(1, new byte[] {0,0,0,0,0,0,0,0,0,2});
- stmt.setString(2, "b");
- stmt.execute();
- conn.commit();
-
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testInsertPaddedBinaryValue() throws SQLException {
- Properties props = new Properties(TEST_PROPERTIES);
- Connection conn = DriverManager.getConnection(getUrl(), props);
- try {
- initTableValues();
- conn.setAutoCommit(true);
- conn.createStatement().execute("DELETE FROM test_table");
-
- String query = "UPSERT INTO test_table"
- + "(a_binary, a_string) "
- + "VALUES(?,?)";
- PreparedStatement stmt = conn.prepareStatement(query);
- stmt.setBytes(1, new byte[] {0,0,0,0,0,0,0,0,1});
- stmt.setString(2, "a");
- stmt.execute();
-
- ResultSet rs = conn.createStatement().executeQuery("SELECT a_string FROM test_table");
- assertTrue(rs.next());
- assertEquals("a",rs.getString(1));
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testSelectValues() throws SQLException {
- Properties props = new Properties(TEST_PROPERTIES);
- Connection conn = DriverManager.getConnection(getUrl(), props);
-
- try {
- initTableValues();
-
- String query = "SELECT * FROM test_table";
- PreparedStatement stmt = conn.prepareStatement(query);
- ResultSet rs = stmt.executeQuery();
-
- assertTrue(rs.next());
- assertArrayEquals(new byte[] {0,0,0,0,0,0,0,0,0,1}, rs.getBytes(1));
- assertEquals("a", rs.getString(2));
-
- assertTrue(rs.next());
- assertArrayEquals(new byte[] {0,0,0,0,0,0,0,0,0,2}, rs.getBytes(1));
- assertEquals("b", rs.getString(2));
-
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testUpsertSelectValues() throws SQLException {
- Properties props = new Properties(TEST_PROPERTIES);
- Connection conn = DriverManager.getConnection(getUrl(), props);
-
- try {
- initTableValues();
-
- String query = "UPSERT INTO test_table (a_binary, a_string, b_binary) "
- + " SELECT a_binary, a_string, a_binary FROM test_table";
- PreparedStatement stmt = conn.prepareStatement(query);
- stmt.execute();
- conn.commit();
-
- query = "SELECT a_binary, b_binary FROM test_table";
- stmt = conn.prepareStatement(query);
- ResultSet rs = stmt.executeQuery();
-
- assertTrue(rs.next());
- assertArrayEquals(new byte[] {0,0,0,0,0,0,0,0,0,1}, rs.getBytes(1));
- assertArrayEquals(new byte[] {0,0,0,0,0,0,0,0,0,1}, rs.getBytes(2));
-
- assertTrue(rs.next());
- assertArrayEquals(new byte[] {0,0,0,0,0,0,0,0,0,2}, rs.getBytes(1));
- assertArrayEquals(new byte[] {0,0,0,0,0,0,0,0,0,2}, rs.getBytes(2));
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-}