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 2016/05/01 07:37:43 UTC

[1/2] phoenix git commit: PHOENIX-2872 Find usages of server time in BaseClientManagedTimeIT immediately

Repository: phoenix
Updated Branches:
  refs/heads/master cd9fad10e -> 99713a61c


PHOENIX-2872 Find usages of server time in BaseClientManagedTimeIT immediately


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/d11aaeeb
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/d11aaeeb
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/d11aaeeb

Branch: refs/heads/master
Commit: d11aaeeb3c97b0698e86dee46d489ce0f81971e4
Parents: cd9fad1
Author: James Taylor <ja...@apache.org>
Authored: Sat Apr 30 22:34:02 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Sat Apr 30 22:34:02 2016 -0700

----------------------------------------------------------------------
 .gitignore                                      |   1 +
 .../org/apache/phoenix/end2end/ArrayIT.java     |  55 ++++++++-
 .../BaseHBaseManagedTimeTableReuseIT.java       |  44 +++-----
 .../apache/phoenix/end2end/DistinctCountIT.java |  76 ++++++-------
 .../apache/phoenix/end2end/DynamicColumnIT.java | 112 +++++++++----------
 .../apache/phoenix/end2end/DynamicUpsertIT.java |  11 +-
 .../phoenix/end2end/InMemoryOrderByIT.java      |   6 +-
 .../org/apache/phoenix/end2end/OrderByIT.java   |  11 +-
 .../apache/phoenix/end2end/PercentileIT.java    |  76 +++----------
 .../phoenix/end2end/SpooledOrderByIT.java       |   4 +-
 .../phoenix/end2end/ToCharFunctionIT.java       |  28 ++---
 .../java/org/apache/phoenix/query/BaseTest.java |  24 +++-
 12 files changed, 231 insertions(+), 217 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/d11aaeeb/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index b918d76..803e8ea 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@
 
 # python
 *.pyc
+.checkstyle
 
 # eclipse stuffs
 .settings/*

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d11aaeeb/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java
index 846507b..4a21864 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java
@@ -1891,10 +1891,16 @@ public class ArrayIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testArrayConstructorWithMultipleRows1() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
+        long ts = nextTimestamp();
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
+        Connection conn = DriverManager.getConnection(getUrl(), props);
         String ddl = "CREATE TABLE regions1 (region_name VARCHAR PRIMARY KEY, a INTEGER, b INTEGER)";
         conn.createStatement().execute(ddl);
         conn.commit();
+        conn.close();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 20));
+        conn = DriverManager.getConnection(getUrl(), props);
         PreparedStatement stmt = conn.prepareStatement("UPSERT INTO regions1(region_name, a, b) VALUES('a', 6,3)");
         stmt.execute();
         stmt = conn.prepareStatement("UPSERT INTO regions1(region_name, a, b) VALUES('b', 2,4)");
@@ -1902,6 +1908,9 @@ public class ArrayIT extends BaseClientManagedTimeIT {
         stmt = conn.prepareStatement("UPSERT INTO regions1(region_name, a, b) VALUES('c', 6,3)");
         stmt.execute();
         conn.commit();
+        conn.close();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
+        conn = DriverManager.getConnection(getUrl(), props);
         ResultSet rs;
         rs = conn.createStatement().executeQuery("SELECT COUNT(DISTINCT ARRAY[a,b]) from regions1");
         assertTrue(rs.next());
@@ -1910,10 +1919,16 @@ public class ArrayIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testArrayConstructorWithMultipleRows2() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
+        long ts = nextTimestamp();
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
+        Connection conn = DriverManager.getConnection(getUrl(), props);
         String ddl = "CREATE TABLE regions2 (region_name VARCHAR PRIMARY KEY, a INTEGER, b INTEGER)";
         conn.createStatement().execute(ddl);
         conn.commit();
+        conn.close();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 20));
+        conn = DriverManager.getConnection(getUrl(), props);
         PreparedStatement stmt = conn.prepareStatement("UPSERT INTO regions2(region_name, a, b) VALUES('a', 6,3)");
         stmt.execute();
         stmt = conn.prepareStatement("UPSERT INTO regions2(region_name, a, b) VALUES('b', 2,4)");
@@ -1921,6 +1936,9 @@ public class ArrayIT extends BaseClientManagedTimeIT {
         stmt = conn.prepareStatement("UPSERT INTO regions2(region_name, a, b) VALUES('c', 6,3)");
         stmt.execute();
         conn.commit();
+        conn.close();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
+        conn = DriverManager.getConnection(getUrl(), props);
         ResultSet rs;
         rs = conn.createStatement().executeQuery("SELECT ARRAY[a,b] from regions2");
         assertTrue(rs.next());
@@ -1937,10 +1955,16 @@ public class ArrayIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testArrayConstructorWithMultipleRows3() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
+        long ts = nextTimestamp();
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
+        Connection conn = DriverManager.getConnection(getUrl(), props);
         String ddl = "CREATE TABLE regions3 (region_name VARCHAR PRIMARY KEY, a VARCHAR, b VARCHAR)";
         conn.createStatement().execute(ddl);
         conn.commit();
+        conn.close();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 20));
+        conn = DriverManager.getConnection(getUrl(), props);
         PreparedStatement stmt = conn.prepareStatement("UPSERT INTO regions3(region_name, a, b) VALUES('a', 'foo', 'abc')");
         stmt.execute();
         stmt = conn.prepareStatement("UPSERT INTO regions3(region_name, a, b) VALUES('b', 'abc', 'dfg')");
@@ -1948,6 +1972,9 @@ public class ArrayIT extends BaseClientManagedTimeIT {
         stmt = conn.prepareStatement("UPSERT INTO regions3(region_name, a, b) VALUES('c', 'foo', 'abc')");
         stmt.execute();
         conn.commit();
+        conn.close();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
+        conn = DriverManager.getConnection(getUrl(), props);
         ResultSet rs;
         rs = conn.createStatement().executeQuery("SELECT ARRAY[a,b] from regions3");
         assertTrue(rs.next());
@@ -1964,10 +1991,16 @@ public class ArrayIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testArrayConstructorWithMultipleRows4() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
+        long ts = nextTimestamp();
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
+        Connection conn = DriverManager.getConnection(getUrl(), props);
         String ddl = "CREATE TABLE regions4 (region_name VARCHAR PRIMARY KEY, a VARCHAR, b VARCHAR)";
         conn.createStatement().execute(ddl);
         conn.commit();
+        conn.close();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 20));
+        conn = DriverManager.getConnection(getUrl(), props);
         PreparedStatement stmt = conn.prepareStatement("UPSERT INTO regions4(region_name, a, b) VALUES('a', 'foo', 'abc')");
         stmt.execute();
         stmt = conn.prepareStatement("UPSERT INTO regions4(region_name, a, b) VALUES('b', 'abc', 'dfg')");
@@ -1975,6 +2008,9 @@ public class ArrayIT extends BaseClientManagedTimeIT {
         stmt = conn.prepareStatement("UPSERT INTO regions4(region_name, a, b) VALUES('c', 'foo', 'abc')");
         stmt.execute();
         conn.commit();
+        conn.close();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
+        conn = DriverManager.getConnection(getUrl(), props);
         ResultSet rs;
         rs = conn.createStatement().executeQuery("SELECT COUNT(DISTINCT ARRAY[a,b]) from regions4");
         assertTrue(rs.next());
@@ -1983,10 +2019,16 @@ public class ArrayIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testArrayConstructorWithMultipleRows5() throws Exception {
-        Connection conn = DriverManager.getConnection(getUrl());
+        long ts = nextTimestamp();
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
+        Connection conn = DriverManager.getConnection(getUrl(), props);
         String ddl = "CREATE TABLE regions5 (region_name VARCHAR PRIMARY KEY, a VARCHAR, b VARCHAR)";
         conn.createStatement().execute(ddl);
         conn.commit();
+        conn.close();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 20));
+        conn = DriverManager.getConnection(getUrl(), props);
         PreparedStatement stmt = conn.prepareStatement("UPSERT INTO regions5(region_name, a, b) VALUES('a', 'foo', 'abc')");
         stmt.execute();
         stmt = conn.prepareStatement("UPSERT INTO regions5(region_name, a, b) VALUES('b', 'abc', 'dfg')");
@@ -1994,6 +2036,9 @@ public class ArrayIT extends BaseClientManagedTimeIT {
         stmt = conn.prepareStatement("UPSERT INTO regions5(region_name, a, b) VALUES('c', 'foo', 'abc')");
         stmt.execute();
         conn.commit();
+        conn.close();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
+        conn = DriverManager.getConnection(getUrl(), props);
         ResultSet rs;
         rs = conn.createStatement().executeQuery("SELECT ARRAY_APPEND(ARRAY[a,b], 'oo') from regions5");
         assertTrue(rs.next());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d11aaeeb/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTableReuseIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTableReuseIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTableReuseIT.java
index 26c2f3c..7bd6ec9 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTableReuseIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseHBaseManagedTimeTableReuseIT.java
@@ -1,6 +1,7 @@
 package org.apache.phoenix.end2end;
 
-import org.apache.hadoop.conf.Configuration;
+import javax.annotation.concurrent.NotThreadSafe;
+
 import org.apache.phoenix.query.BaseTest;
 import org.apache.phoenix.util.ReadOnlyProps;
 import org.junit.After;
@@ -8,10 +9,6 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.experimental.categories.Category;
 
-import javax.annotation.concurrent.NotThreadSafe;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
 /**
  * Base class for tests that let HBase set timestamps.
  * We need to separate these from tests that rely on clients
@@ -33,26 +30,21 @@ import java.util.concurrent.locks.ReentrantLock;
 @Category(HBaseManagedTimeTableReuseTest.class)
 public class BaseHBaseManagedTimeTableReuseIT extends BaseTest {
 
-  protected static Configuration getTestClusterConfig() {
-    // don't want callers to modify config.
-    return new Configuration(config);
-  }
-
-  @BeforeClass
-  public static void doSetup() throws Exception {
-    setUpTestDriver(ReadOnlyProps.EMPTY_PROPS);
-  }
-
-  @AfterClass
-  public static void doTeardown() throws Exception {
-    // no teardown since we are creating unique table names
-    // just destroy our test driver
-    destroyDriver();
-  }
-
-  @After
-  public void cleanUpAfterTest() throws Exception {
-    // no cleanup since we are using unique table names
-  }
+    @BeforeClass
+    public static void doSetup() throws Exception {
+        setUpTestDriver(ReadOnlyProps.EMPTY_PROPS);
+    }
+
+    @AfterClass
+    public static void doTeardown() throws Exception {
+        // no teardown since we are creating unique table names
+        // just destroy our test driver
+        destroyDriver();
+    }
+
+    @After
+    public void cleanUpAfterTest() throws Exception {
+        // no cleanup since we are using unique table names
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d11aaeeb/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctCountIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctCountIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctCountIT.java
index 523e83c..500998b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctCountIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctCountIT.java
@@ -226,8 +226,7 @@ public class DistinctCountIT extends BaseClientManagedTimeIT {
         String query = "SELECT count(DISTINCT A_STRING), count(DISTINCT B_STRING) FROM aTable";
 
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at
-                                                                                     // timestamp 2
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
         Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             PreparedStatement statement = conn.prepareStatement(query);
@@ -273,8 +272,7 @@ public class DistinctCountIT extends BaseClientManagedTimeIT {
         String query = "SELECT count(DISTINCT 1) FROM aTable";
 
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at
-                                                                                     // timestamp 2
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
         Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             PreparedStatement statement = conn.prepareStatement(query);
@@ -461,45 +459,47 @@ public class DistinctCountIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testDistinctCountOnIndexTab() throws Exception {
+        long ts = nextTimestamp();
         String ddl = "create table personal_details (id integer not null, first_name char(15),\n"
                 + "    last_name char(15), CONSTRAINT pk PRIMARY KEY (id))";
         Properties props = new Properties();
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
         Connection conn = DriverManager.getConnection(getUrl(), props);
-        try {
-            PreparedStatement stmt = conn.prepareStatement(ddl);
-            stmt.execute(ddl);
-            conn.createStatement().execute("CREATE INDEX personal_details_idx ON personal_details(first_name)");
-        } catch (TableAlreadyExistsException e) {
-
-        } finally {
-            conn.close();
-        }
-
+        PreparedStatement stmt = conn.prepareStatement(ddl);
+        stmt.execute(ddl);
+        conn.close();
+        
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 20));
         conn = DriverManager.getConnection(getUrl(), props);
-        try {
-            PreparedStatement stmt = conn.prepareStatement("upsert into personal_details(id, first_name, "
-                    + "last_name) VALUES (?, ?, ?)");
-            stmt.setInt(1, 1);
-            stmt.setString(2, "NAME1");
-            stmt.setString(3, "LN");
-            stmt.execute();
-            stmt.setInt(1, 2);
-            stmt.setString(2, "NAME1");
-            stmt.setString(3, "LN2");
-            stmt.execute();
-            stmt.setInt(1, 3);
-            stmt.setString(2, "NAME2");
-            stmt.setString(3, "LN3");
-            stmt.execute();
-            conn.commit();
+        conn.createStatement().execute("CREATE INDEX personal_details_idx ON personal_details(first_name)");
+        conn.close();
 
-            String query = "SELECT COUNT (DISTINCT first_name) FROM personal_details";
-            PreparedStatement statement = conn.prepareStatement(query);
-            ResultSet rs = statement.executeQuery();
-            assertTrue(rs.next());
-            assertEquals(2, rs.getInt(1));
-        } finally {
-            conn.close();
-        }
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
+        conn = DriverManager.getConnection(getUrl(), props);
+        stmt = conn.prepareStatement("upsert into personal_details(id, first_name, "
+                + "last_name) VALUES (?, ?, ?)");
+        stmt.setInt(1, 1);
+        stmt.setString(2, "NAME1");
+        stmt.setString(3, "LN");
+        stmt.execute();
+        stmt.setInt(1, 2);
+        stmt.setString(2, "NAME1");
+        stmt.setString(3, "LN2");
+        stmt.execute();
+        stmt.setInt(1, 3);
+        stmt.setString(2, "NAME2");
+        stmt.setString(3, "LN3");
+        stmt.execute();
+        conn.commit();
+        conn.close();
+
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
+        conn = DriverManager.getConnection(getUrl(), props);
+        String query = "SELECT COUNT (DISTINCT first_name) FROM personal_details";
+        PreparedStatement statement = conn.prepareStatement(query);
+        ResultSet rs = statement.executeQuery();
+        assertTrue(rs.next());
+        assertEquals(2, rs.getInt(1));
+        conn.close();
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d11aaeeb/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java
index 263a6ea..31b0dd7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java
@@ -19,7 +19,6 @@
 package org.apache.phoenix.end2end;
 
 import static org.apache.phoenix.util.TestUtil.HBASE_DYNAMIC_COLUMNS;
-import static org.apache.phoenix.util.TestUtil.HBASE_DYNAMIC_COLUMNS_SCHEMA_NAME;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -33,17 +32,22 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
 
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.client.HTableInterface;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.Row;
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.query.ConnectionQueryServices;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.schema.ColumnAlreadyExistsException;
 import org.apache.phoenix.schema.ColumnFamilyNotFoundException;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.SchemaUtil;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -55,58 +59,59 @@ import org.junit.Test;
  */
 
 
-public class DynamicColumnIT extends BaseClientManagedTimeIT {
-    private static final byte[] HBASE_DYNAMIC_COLUMNS_BYTES = SchemaUtil.getTableNameAsBytes(null, HBASE_DYNAMIC_COLUMNS);
-    private static final byte[] FAMILY_NAME = Bytes.toBytes(SchemaUtil.normalizeIdentifier("A"));
-    private static final byte[] FAMILY_NAME2 = Bytes.toBytes(SchemaUtil.normalizeIdentifier("B"));
+public class DynamicColumnIT extends BaseHBaseManagedTimeIT {
+    private static final byte[] FAMILY_NAME_A = Bytes.toBytes(SchemaUtil.normalizeIdentifier("A"));
+    private static final byte[] FAMILY_NAME_B = Bytes.toBytes(SchemaUtil.normalizeIdentifier("B"));
 
     @BeforeClass
     public static void doBeforeTestSetup() throws Exception {
-        HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).getAdmin();
-        try {
-            try {
-                admin.disableTable(HBASE_DYNAMIC_COLUMNS_BYTES);
-                admin.deleteTable(HBASE_DYNAMIC_COLUMNS_BYTES);
-            } catch (org.apache.hadoop.hbase.TableNotFoundException e) {}
-            ensureTableCreated(getUrl(), HBASE_DYNAMIC_COLUMNS);
-            initTableValues();
-        } finally {
-            admin.close();
+        try (PhoenixConnection pconn = DriverManager.getConnection(getUrl()).unwrap(PhoenixConnection.class)) {
+            ConnectionQueryServices services = pconn.getQueryServices();
+            try (HBaseAdmin admin = services.getAdmin()) {
+                HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(HBASE_DYNAMIC_COLUMNS));
+                htd.addFamily(new HColumnDescriptor(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES));
+                htd.addFamily(new HColumnDescriptor(FAMILY_NAME_A));
+                htd.addFamily(new HColumnDescriptor(FAMILY_NAME_B));
+                admin.createTable(htd);
+            }
         }
     }
-
+    
     @SuppressWarnings("deprecation")
-    private static void initTableValues() throws Exception {
-        ConnectionQueryServices services = driver.getConnectionQueryServices(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES));
-        HTableInterface hTable = services.getTable(SchemaUtil.getTableNameAsBytes(HBASE_DYNAMIC_COLUMNS_SCHEMA_NAME,HBASE_DYNAMIC_COLUMNS));
-        try {
-            // Insert rows using standard HBase mechanism with standard HBase "types"
-            List<Row> mutations = new ArrayList<Row>();
-            byte[] dv = Bytes.toBytes("DV");
-            byte[] first = Bytes.toBytes("F");
-            byte[] f1v1 = Bytes.toBytes("F1V1");
-            byte[] f1v2 = Bytes.toBytes("F1V2");
-            byte[] f2v1 = Bytes.toBytes("F2V1");
-            byte[] f2v2 = Bytes.toBytes("F2V2");
-            byte[] key = Bytes.toBytes("entry1");
-
-            Put put = new Put(key);
-            put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, dv, Bytes.toBytes("default"));
-            put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, first, Bytes.toBytes("first"));
-            put.add(FAMILY_NAME, f1v1, Bytes.toBytes("f1value1"));
-            put.add(FAMILY_NAME, f1v2, Bytes.toBytes("f1value2"));
-            put.add(FAMILY_NAME2, f2v1, Bytes.toBytes("f2value1"));
-            put.add(FAMILY_NAME2, f2v2, Bytes.toBytes("f2value2"));
-            mutations.add(put);
-
-            hTable.batch(mutations);
-
-        } finally {
-            hTable.close();
+    @Before
+    public void createTable() throws Exception {
+        try (PhoenixConnection pconn = DriverManager.getConnection(getUrl()).unwrap(PhoenixConnection.class)) {
+            ConnectionQueryServices services = pconn.getQueryServices();
+            HTableInterface hTable = services.getTable(Bytes.toBytes(HBASE_DYNAMIC_COLUMNS));
+            try {
+                // Insert rows using standard HBase mechanism with standard HBase "types"
+                List<Row> mutations = new ArrayList<Row>();
+                byte[] dv = Bytes.toBytes("DV");
+                byte[] first = Bytes.toBytes("F");
+                byte[] f1v1 = Bytes.toBytes("F1V1");
+                byte[] f1v2 = Bytes.toBytes("F1V2");
+                byte[] f2v1 = Bytes.toBytes("F2V1");
+                byte[] f2v2 = Bytes.toBytes("F2V2");
+                byte[] key = Bytes.toBytes("entry1");
+    
+                Put put = new Put(key);
+                put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, dv, Bytes.toBytes("default"));
+                put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, first, Bytes.toBytes("first"));
+                put.add(FAMILY_NAME_A, f1v1, Bytes.toBytes("f1value1"));
+                put.add(FAMILY_NAME_A, f1v2, Bytes.toBytes("f1value2"));
+                put.add(FAMILY_NAME_B, f2v1, Bytes.toBytes("f2value1"));
+                put.add(FAMILY_NAME_B, f2v2, Bytes.toBytes("f2value2"));
+                mutations.add(put);
+    
+                hTable.batch(mutations);
+    
+                // Create Phoenix table after HBase table was created through the native APIs
+                // The timestamp of the table creation must be later than the timestamp of the data
+                ensureTableCreated(getUrl(), HBASE_DYNAMIC_COLUMNS);
+            } finally {
+                hTable.close();
+            }
         }
-        // Create Phoenix table after HBase table was created through the native APIs
-        // The timestamp of the table creation must be later than the timestamp of the data
-        ensureTableCreated(getUrl(), HBASE_DYNAMIC_COLUMNS);
     }
 
     /**
@@ -115,9 +120,8 @@ public class DynamicColumnIT extends BaseClientManagedTimeIT {
     @Test
     public void testDynamicColums() throws Exception {
         String query = "SELECT * FROM HBASE_DYNAMIC_COLUMNS (DV varchar)";
-        String url = getUrl() + ";";
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        Connection conn = DriverManager.getConnection(url, props);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             PreparedStatement statement = conn.prepareStatement(query);
             ResultSet rs = statement.executeQuery();
@@ -140,9 +144,8 @@ public class DynamicColumnIT extends BaseClientManagedTimeIT {
     @Test
     public void testDynamicColumsFamily() throws Exception {
         String query = "SELECT * FROM HBASE_DYNAMIC_COLUMNS (DV varchar,B.F2V2 varchar)";
-        String url = getUrl() + ";";
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        Connection conn = DriverManager.getConnection(url, props);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             PreparedStatement statement = conn.prepareStatement(query);
             ResultSet rs = statement.executeQuery();
@@ -167,9 +170,8 @@ public class DynamicColumnIT extends BaseClientManagedTimeIT {
     @Test
     public void testDynamicColumsSpecificQuery() throws Exception {
         String query = "SELECT entry,F2V2 FROM HBASE_DYNAMIC_COLUMNS (DV varchar,B.F2V2 varchar)";
-        String url = getUrl() + ";";
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        Connection conn = DriverManager.getConnection(url, props);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             PreparedStatement statement = conn.prepareStatement(query);
             ResultSet rs = statement.executeQuery();
@@ -188,9 +190,8 @@ public class DynamicColumnIT extends BaseClientManagedTimeIT {
     @Test(expected = ColumnAlreadyExistsException.class)
     public void testAmbiguousStaticSelect() throws Exception {
         String upsertquery = "Select * FROM HBASE_DYNAMIC_COLUMNS(A.F1V1 INTEGER)";
-        String url = getUrl() + ";";
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        Connection conn = DriverManager.getConnection(url, props);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             PreparedStatement statement = conn.prepareStatement(upsertquery);
             statement.executeQuery();
@@ -205,9 +206,8 @@ public class DynamicColumnIT extends BaseClientManagedTimeIT {
     @Test(expected = ColumnFamilyNotFoundException.class)
     public void testFakeCFDynamicUpsert() throws Exception {
         String upsertquery = "Select * FROM HBASE_DYNAMIC_COLUMNS(fakecf.DynCol VARCHAR)";
-        String url = getUrl() + ";";
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        Connection conn = DriverManager.getConnection(url, props);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             PreparedStatement statement = conn.prepareStatement(upsertquery);
             statement.executeQuery();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d11aaeeb/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java
index fe0d8b1..0852859 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java
@@ -31,9 +31,11 @@ import java.sql.SQLException;
 import java.util.Properties;
 
 import org.apache.phoenix.exception.SQLExceptionCode;
+import org.apache.phoenix.query.BaseTest;
 import org.apache.phoenix.schema.ColumnAlreadyExistsException;
 import org.apache.phoenix.schema.ColumnFamilyNotFoundException;
 import org.apache.phoenix.util.PropertiesUtil;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -45,13 +47,12 @@ import org.junit.Test;
  */
 
 
-public class DynamicUpsertIT extends BaseClientManagedTimeIT {
-
-    private static final String TABLE = "DynamicUpserts";
-    //private static final byte[] TABLE_BYTES = Bytes.toBytes(TABLE);
+public class DynamicUpsertIT extends BaseHBaseManagedTimeTableReuseIT {
+    private static String TABLE;
 
     @BeforeClass
     public static void doBeforeTestSetup() throws Exception {
+    	TABLE = BaseTest.generateRandomString();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);
         String ddl = "create table if not exists  " + TABLE + "   (entry varchar not null primary key,"
@@ -59,7 +60,7 @@ public class DynamicUpsertIT extends BaseClientManagedTimeIT {
         conn.createStatement().execute(ddl);
         conn.close();
     }
-
+    
     /**
      * Test a simple upsert with a dynamic Column
      */

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d11aaeeb/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java
index cc3b45f..232f76f 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java
@@ -23,6 +23,8 @@ import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.ReadOnlyProps;
 import org.junit.BeforeClass;
 
+import com.google.common.collect.Maps;
+
 
 public class InMemoryOrderByIT extends OrderByIT {
 
@@ -30,9 +32,9 @@ public class InMemoryOrderByIT extends OrderByIT {
     }
 
     @BeforeClass
-    @Shadower(classBeingShadowed = BaseClientManagedTimeIT.class)
+    @Shadower(classBeingShadowed = BaseHBaseManagedTimeIT.class)
     public static void doSetup() throws Exception {
-        Map<String,String> props = getDefaultProps();
+        Map<String,String> props = Maps.newHashMapWithExpectedSize(1);
         props.put(QueryServices.SPOOL_THRESHOLD_BYTES_ATTRIB, Integer.toString(1024*1024));
         // Must update config before starting server
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d11aaeeb/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
index 9fc3003..1d31eee 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
@@ -39,21 +39,18 @@ 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 {
+public class OrderByIT extends BaseHBaseManagedTimeIT {
 
     @Test
     public void testMultiOrderByExpr() throws Exception {
-        long ts = nextTimestamp();
         String tenantId = getOrganizationId();
-        initATableValues(tenantId, getDefaultSplits(tenantId), null, ts);
+        initATableValues(tenantId, getDefaultSplits(tenantId), getUrl());
         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);
@@ -86,12 +83,10 @@ public class OrderByIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testDescMultiOrderByExpr() throws Exception {
-        long ts = nextTimestamp();
         String tenantId = getOrganizationId();
-        initATableValues(tenantId, getDefaultSplits(tenantId), null, ts);
+        initATableValues(tenantId, getDefaultSplits(tenantId), getUrl());
         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);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d11aaeeb/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java
index fe8e5c3..c896a93 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java
@@ -56,19 +56,16 @@ import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
 
 
-public class PercentileIT extends BaseClientManagedTimeIT {
+public class PercentileIT extends BaseHBaseManagedTimeIT {
 
     @Test
     public void testPercentile() throws Exception {
-        long ts = nextTimestamp();
         String tenantId = getOrganizationId();
-        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null);
 
         String query = "SELECT PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM aTable";
 
         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);
@@ -85,15 +82,12 @@ public class PercentileIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testPercentileDesc() throws Exception {
-        long ts = nextTimestamp();
         String tenantId = getOrganizationId();
-        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null);
 
         String query = "SELECT PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY A_INTEGER DESC) FROM aTable";
 
         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);
@@ -110,15 +104,12 @@ public class PercentileIT extends BaseClientManagedTimeIT {
     
     @Test
     public void testPercentileWithGroupby() throws Exception {
-        long ts = nextTimestamp();
         String tenantId = getOrganizationId();
-        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null);
 
         String query = "SELECT A_STRING, PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM aTable GROUP BY A_STRING";
 
         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);
@@ -146,15 +137,12 @@ public class PercentileIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testPercentileWithGroupbyAndOrderBy() throws Exception {
-        long ts = nextTimestamp();
         String tenantId = getOrganizationId();
-        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null);
 
         String query = "SELECT A_STRING, PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY A_INTEGER ASC) AS PC FROM aTable GROUP BY A_STRING ORDER BY PC";
 
         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);
@@ -182,16 +170,12 @@ public class PercentileIT extends BaseClientManagedTimeIT {
 
     @Test
 	public void testPercentileDiscAsc() throws Exception {
-		long ts = nextTimestamp();
 		String tenantId = getOrganizationId();
-		initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+		initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null);
 
 		String query = "SELECT PERCENTILE_DISC(0.9) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM aTable";
 
 		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);
@@ -207,16 +191,12 @@ public class PercentileIT extends BaseClientManagedTimeIT {
 	
 	@Test
 	public void testPercentileDiscDesc() throws Exception {
-		long ts = nextTimestamp();
 		String tenantId = getOrganizationId();
-		initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+		initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null);
 
 		String query = "SELECT PERCENTILE_DISC(0.9) WITHIN GROUP (ORDER BY A_INTEGER DESC) FROM aTable";
 
 		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);
@@ -232,15 +212,12 @@ public class PercentileIT extends BaseClientManagedTimeIT {
     
     @Test
     public void testPercentileDiscWithGroupby() throws Exception {
-        long ts = nextTimestamp();
         String tenantId = getOrganizationId();
-        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null);
 
         String query = "SELECT A_STRING, PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM aTable GROUP BY A_STRING";
 
         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);
@@ -265,15 +242,12 @@ public class PercentileIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testPercentileDiscWithGroupbyAndOrderBy() throws Exception {
-        long ts = nextTimestamp();
         String tenantId = getOrganizationId();
-        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null);
 
         String query = "SELECT A_STRING, PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM aTable GROUP BY A_STRING ORDER BY A_STRING 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);
@@ -298,15 +272,12 @@ public class PercentileIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testPercentRank() throws Exception {
-        long ts = nextTimestamp();
         String tenantId = getOrganizationId();
-        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null);
 
         String query = "SELECT PERCENT_RANK(5) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM aTable";
 
         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);
@@ -323,15 +294,12 @@ public class PercentileIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testPercentRankWithNegativeNumeric() throws Exception {
-        long ts = nextTimestamp();
         String tenantId = getOrganizationId();
-        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null);
 
         String query = "SELECT PERCENT_RANK(-2) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM aTable";
 
         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);
@@ -348,15 +316,12 @@ public class PercentileIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testPercentRankDesc() throws Exception {
-        long ts = nextTimestamp();
         String tenantId = getOrganizationId();
-        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null);
 
         String query = "SELECT PERCENT_RANK(8.9) WITHIN GROUP (ORDER BY A_INTEGER DESC) FROM aTable";
 
         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);
@@ -373,15 +338,12 @@ public class PercentileIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testPercentRankDescOnVARCHARColumn() throws Exception {
-        long ts = nextTimestamp();
         String tenantId = getOrganizationId();
-        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null);
 
         String query = "SELECT PERCENT_RANK('ba') WITHIN GROUP (ORDER BY A_STRING DESC) FROM aTable";
 
         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);
@@ -398,15 +360,12 @@ public class PercentileIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testPercentRankDescOnDECIMALColumn() throws Exception {
-        long ts = nextTimestamp();
         String tenantId = getOrganizationId();
-        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null);
 
         String query = "SELECT PERCENT_RANK(2) WITHIN GROUP (ORDER BY x_decimal ASC) FROM aTable";
 
         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);
@@ -423,15 +382,12 @@ public class PercentileIT extends BaseClientManagedTimeIT {
 
     @Test
     public void testMultiplePercentRanksOnSelect() throws Exception {
-        long ts = nextTimestamp();
         String tenantId = getOrganizationId();
-        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+        initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null);
 
         String query = "SELECT PERCENT_RANK(2) WITHIN GROUP (ORDER BY x_decimal ASC), PERCENT_RANK(8.9) WITHIN GROUP (ORDER BY A_INTEGER DESC) FROM aTable";
 
         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);
@@ -552,7 +508,7 @@ public class PercentileIT extends BaseClientManagedTimeIT {
         }
     }
 
-    protected static void initATableValues(String tenantId1, String tenantId2, byte[][] splits,
+    private static void initATableValues(String tenantId1, String tenantId2, byte[][] splits,
             Date date, Long ts) throws Exception {
         if (ts == null) {
             ensureTableCreated(getUrl(), ATABLE_NAME, splits);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d11aaeeb/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledOrderByIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledOrderByIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledOrderByIT.java
index bb09793..2f0bc61 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledOrderByIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledOrderByIT.java
@@ -23,13 +23,15 @@ import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.ReadOnlyProps;
 import org.junit.BeforeClass;
 
+import com.google.common.collect.Maps;
+
 
 public class SpooledOrderByIT extends OrderByIT {
 
     @BeforeClass
     @Shadower(classBeingShadowed = BaseClientManagedTimeIT.class)
     public static void doSetup() throws Exception {
-        Map<String,String> props = getDefaultProps();
+        Map<String,String> props = Maps.newHashMapWithExpectedSize(1);
         props.put(QueryServices.SPOOL_THRESHOLD_BYTES_ATTRIB, Integer.toString(100));
         // Must update config before starting server
         setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d11aaeeb/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java
index 1cccf07..7cb4b54 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ToCharFunctionIT.java
@@ -17,7 +17,6 @@
  */
 package org.apache.phoenix.end2end;
 
-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;
@@ -34,12 +33,9 @@ import java.sql.Timestamp;
 import java.text.DateFormat;
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
-import java.util.Properties;
 import java.util.TimeZone;
 
 import org.apache.phoenix.expression.function.ToCharFunction;
-import org.apache.phoenix.util.PhoenixRuntime;
-import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -51,9 +47,9 @@ import org.junit.Test;
  * @since 0.1
  */
 
-public class ToCharFunctionIT extends BaseClientManagedTimeIT {
+public class ToCharFunctionIT extends BaseHBaseManagedTimeTableReuseIT {
     
-    public static final String TO_CHAR_TABLE_NAME = "TO_CHAR_TABLE";
+    private static String TO_CHAR_TABLE_NAME;
     
     private Date row1Date;
     private Time row1Time;
@@ -80,11 +76,17 @@ public class ToCharFunctionIT extends BaseClientManagedTimeIT {
             value="DMI_BIGDECIMAL_CONSTRUCTED_FROM_DOUBLE", 
             justification="Test code.")
     public void initTable() throws Exception {
-        long ts = nextTimestamp();
-        createTestTable(getUrl(), TO_CHAR_TABLE_DDL, null, ts-2);
-        String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + ts;
-        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        Connection conn = DriverManager.getConnection(url, props);
+        TO_CHAR_TABLE_NAME = generateRandomString();
+        String ddl = "create table " + TO_CHAR_TABLE_NAME +
+                "(pk integer not null, \n" + 
+                "col_date date, \n" +
+                "col_time date, \n" +
+                "col_timestamp timestamp, \n" +
+                "col_integer integer, \n" + 
+                "col_decimal decimal\n" + 
+                "CONSTRAINT my_pk PRIMARY KEY (pk))";
+        createTestTable(getUrl(), ddl);
+        Connection conn = DriverManager.getConnection(getUrl());
         conn.setAutoCommit(false);
         
         PreparedStatement stmt = conn.prepareStatement(
@@ -218,9 +220,7 @@ public class ToCharFunctionIT extends BaseClientManagedTimeIT {
     }
     
     private void runOneRowQueryTest(String oneRowQuery, Integer pkValue, String projectedValue) throws Exception {
-        long ts = nextTimestamp();
-        String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + ts;
-        Connection conn = DriverManager.getConnection(url);
+        Connection conn = DriverManager.getConnection(getUrl());
         try {
             PreparedStatement statement = conn.prepareStatement(oneRowQuery);
             ResultSet rs = statement.executeQuery();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d11aaeeb/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
index deb4132..d61e9fe 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
@@ -85,7 +85,7 @@ import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.apache.phoenix.util.TestUtil.TRANSACTIONAL_DATA_TABLE;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
 import static org.junit.Assert.fail;
 
 import java.io.IOException;
@@ -914,6 +914,17 @@ public abstract class BaseTest {
         try {
             deletePriorTables(ts, conn, url);
             deletePriorSequences(ts, conn);
+            
+            // Make sure all tables and views have been dropped
+            props.remove(CURRENT_SCN_ATTRIB);
+            try (Connection seeLatestConn = DriverManager.getConnection(url, props)) {
+            	DatabaseMetaData dbmd = seeLatestConn.getMetaData();
+    	        ResultSet rs = dbmd.getTables(null, null, null, new String[]{PTableType.VIEW.toString(), PTableType.TABLE.toString()});
+    	        boolean hasTables = rs.next();
+    	        if (hasTables) {
+    	        	fail("The following tables are not deleted that should be:" + getTableNames(rs));
+    	        }
+            }
         }
         finally {
             conn.close();
@@ -940,7 +951,7 @@ public abstract class BaseTest {
                         conn.close();
                     }
                     // Open tenant-specific connection when we find a new one
-                    Properties props = new Properties(globalConn.getClientInfo());
+                    Properties props = PropertiesUtil.deepCopy(globalConn.getClientInfo());
                     props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
                     conn = DriverManager.getConnection(url, props);
                     lastTenantId = tenantId;
@@ -960,6 +971,15 @@ public abstract class BaseTest {
         }
     }
     
+    private static String getTableNames(ResultSet rs) throws SQLException {
+    	StringBuilder buf = new StringBuilder();
+    	do {
+    		buf.append(" ");
+    		buf.append(SchemaUtil.getTableName(rs.getString(PhoenixDatabaseMetaData.TABLE_SCHEM), rs.getString(PhoenixDatabaseMetaData.TABLE_NAME)));
+    	} while (rs.next());
+    	return buf.toString();
+    }
+    
     private static void deletePriorSequences(long ts, Connection globalConn) throws Exception {
         // TODO: drop tenant-specific sequences too
         ResultSet rs = globalConn.createStatement().executeQuery("SELECT " 


[2/2] phoenix git commit: PHOENIX-2868 QueryServerBasicsIT.testSchemas is failing (Ankit Singhal)

Posted by ja...@apache.org.
PHOENIX-2868 QueryServerBasicsIT.testSchemas is failing (Ankit Singhal)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/99713a61
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/99713a61
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/99713a61

Branch: refs/heads/master
Commit: 99713a61cd758a8486f1b49225c5e1c6766dc7b9
Parents: d11aaee
Author: James Taylor <ja...@apache.org>
Authored: Sat Apr 30 22:37:48 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Sat Apr 30 22:37:48 2016 -0700

----------------------------------------------------------------------
 .../phoenix/end2end/QueryServerBasicsIT.java    | 41 ++++++++++++--------
 1 file changed, 24 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/99713a61/phoenix-server/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-server/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java b/phoenix-server/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java
index 3003f31..ba49bab 100644
--- a/phoenix-server/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java
+++ b/phoenix-server/src/it/java/org/apache/phoenix/end2end/QueryServerBasicsIT.java
@@ -17,14 +17,17 @@
  */
 package org.apache.phoenix.end2end;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.phoenix.query.QueryServices;
-import org.apache.phoenix.queryserver.client.ThinClientUtil;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static java.lang.String.format;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_CAT;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_CATALOG;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM;
+import static org.apache.phoenix.query.QueryConstants.SYSTEM_SCHEMA_NAME;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
@@ -32,16 +35,17 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.Statement;
+import java.util.Properties;
 import java.util.concurrent.TimeUnit;
 
-import static java.lang.String.format;
-
-import static org.apache.phoenix.query.QueryConstants.SYSTEM_SCHEMA_NAME;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_CAT;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_CATALOG;
-import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.*;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.queryserver.client.ThinClientUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
 
 /**
  * Smoke test for query server.
@@ -96,7 +100,10 @@ public class QueryServerBasicsIT extends BaseHBaseManagedTimeIT {
 
   @Test
   public void testSchemas() throws Exception {
-    try (final Connection connection = DriverManager.getConnection(CONN_STRING)) {
+      Properties props=new Properties();
+      props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(true));
+      try (final Connection connection = DriverManager.getConnection(CONN_STRING, props)) {
+      connection.createStatement().executeUpdate("CREATE SCHEMA IF NOT EXISTS " + SYSTEM_SCHEMA_NAME);
       assertThat(connection.isClosed(), is(false));
       try (final ResultSet resultSet = connection.getMetaData().getSchemas()) {
         final ResultSetMetaData metaData = resultSet.getMetaData();