phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject [2/4] phoenix git commit: PHOENIX-4180 Modify tests to generate unique table names and not use CURRENT_SCN (Rahul Shrivastava)
Date Wed, 13 Sep 2017 23:10:43 GMT
http://git-wip-us.apache.org/repos/asf/phoenix/blob/933a5b1f/phoenix-core/src/it/java/org/apache/phoenix/end2end/ClientTimeArithmeticQueryIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ClientTimeArithmeticQueryIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ClientTimeArithmeticQueryIT.java
index 52044a8..46dd598 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ClientTimeArithmeticQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ClientTimeArithmeticQueryIT.java
@@ -47,7 +47,6 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Properties;
 
-import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -616,27 +615,22 @@ public class ClientTimeArithmeticQueryIT extends BaseQueryIT {
       ResultSet rs;
       String tName = generateUniqueName();
 
-      long ts = nextTimestamp();
       Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
       conn = DriverManager.getConnection(getUrl(), props);
       conn.createStatement()
               .execute(
                       "create table " + tName + " (ts timestamp primary key)");
       conn.close();
 
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
       conn = DriverManager.getConnection(getUrl(), props);
       stmt = conn.prepareStatement("upsert into " + tName + " values (?)");
       stmt.setTimestamp(1, new Timestamp(1995 - 1900, 4, 2, 1, 1, 1, 1));
       stmt.execute();
       conn.commit();
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 60));
       conn = DriverManager.getConnection(getUrl(), props);
       rs = conn.createStatement().executeQuery("SELECT ts FROM " + tName + "");
       assertTrue(rs.next());
       assertEquals("1995-05-02 01:01:01.000000001",rs.getTimestamp(1).toString());
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 70));
       conn = DriverManager.getConnection(getUrl(), props);
       rs = conn.createStatement().executeQuery("SELECT ts + 1 FROM " + tName + "");
       assertTrue(rs.next());
@@ -649,27 +643,22 @@ public class ClientTimeArithmeticQueryIT extends BaseQueryIT {
       PreparedStatement stmt;
       ResultSet rs;
       String tName = generateUniqueName();
-      long ts = nextTimestamp();
       Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
       conn = DriverManager.getConnection(getUrl(), props);
       conn.createStatement()
               .execute(
                       "create table " + tName + " (ts timestamp primary key)");
       conn.close();
 
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
       conn = DriverManager.getConnection(getUrl(), props);
       stmt = conn.prepareStatement("upsert into " + tName + " values (?)");
       stmt.setTimestamp(1, new Timestamp(1995 - 1900, 4, 2, 1, 1, 1, 1));
       stmt.execute();
       conn.commit();
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 60));
       conn = DriverManager.getConnection(getUrl(), props);
       rs = conn.createStatement().executeQuery("SELECT ts FROM " + tName);
       assertTrue(rs.next());
       assertEquals("1995-05-02 01:01:01.000000001",rs.getTimestamp(1).toString());
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 70));
       conn = DriverManager.getConnection(getUrl(), props);
       rs = conn.createStatement().executeQuery("SELECT ts - 1 FROM " + tName);
       assertTrue(rs.next());
@@ -683,28 +672,23 @@ public class ClientTimeArithmeticQueryIT extends BaseQueryIT {
       ResultSet rs;
       String tName = generateUniqueName();
 
-      long ts = nextTimestamp();
       Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
       conn = DriverManager.getConnection(getUrl(), props);
       conn.createStatement()
               .execute(
                       "create table " + tName + " (ts time primary key)");
       conn.close();
 
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
       conn = DriverManager.getConnection(getUrl(), props);
       stmt = conn.prepareStatement("upsert into " + tName + " values (?)");
       Time time = new Time(1995 - 1900, 4, 2);
       stmt.setTime(1, time);
       stmt.execute();
       conn.commit();
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 60));
       conn = DriverManager.getConnection(getUrl(), props);
       rs = conn.createStatement().executeQuery("SELECT ts FROM " + tName);
       assertTrue(rs.next());
       assertEquals(time.getTime(),rs.getTimestamp(1).getTime());
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 70));
       conn = DriverManager.getConnection(getUrl(), props);
       rs = conn.createStatement().executeQuery("SELECT ts + 1 FROM " + tName);
       assertTrue(rs.next());
@@ -717,28 +701,23 @@ public class ClientTimeArithmeticQueryIT extends BaseQueryIT {
       PreparedStatement stmt;
       ResultSet rs;
       String tName = generateUniqueName();
-      long ts = nextTimestamp();
       Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
       conn = DriverManager.getConnection(getUrl(), props);
       conn.createStatement()
               .execute(
                       "create table " + tName + " (ts time primary key)");
       conn.close();
 
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
       conn = DriverManager.getConnection(getUrl(), props);
       stmt = conn.prepareStatement("upsert into " + tName + " values (?)");
       Time time = new Time(1995 - 1900, 4, 2);
       stmt.setTime(1, time);
       stmt.execute();
       conn.commit();
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 60));
       conn = DriverManager.getConnection(getUrl(), props);
       rs = conn.createStatement().executeQuery("SELECT ts FROM " + tName + "");
       assertTrue(rs.next());
       assertEquals(time.getTime(),rs.getTimestamp(1).getTime());
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 70));
       conn = DriverManager.getConnection(getUrl(), props);
       rs = conn.createStatement().executeQuery("SELECT ts - 1 FROM " + tName);
       assertTrue(rs.next());
@@ -752,27 +731,22 @@ public class ClientTimeArithmeticQueryIT extends BaseQueryIT {
       ResultSet rs;
       String tName = generateUniqueName();
 
-      long ts = nextTimestamp();
       Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
       conn = DriverManager.getConnection(getUrl(), props);
       conn.createStatement()
               .execute(
                       "create table " + tName + " (ts date primary key)");
       conn.close();
 
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
       conn = DriverManager.getConnection(getUrl(), props);
       stmt = conn.prepareStatement("upsert into " + tName + " values (?)");
       stmt.setDate(1, new Date(1995 - 1900, 4, 2));
       stmt.execute();
       conn.commit();
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 60));
       conn = DriverManager.getConnection(getUrl(), props);
       rs = conn.createStatement().executeQuery("SELECT ts FROM " + tName);
       assertTrue(rs.next());
       assertEquals("1995-05-02",rs.getDate(1).toString());
-      props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 70));
       conn = DriverManager.getConnection(getUrl(), props);
       rs = conn.createStatement().executeQuery("SELECT ts - 1 FROM " + tName);
       assertTrue(rs.next());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/933a5b1f/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
index 423ad23..d777027 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
@@ -52,7 +52,6 @@ import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.schema.types.PInteger;
 import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.types.PVarchar;
-import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.SchemaUtil;
 import org.junit.Test;
@@ -61,12 +60,10 @@ public class ColumnProjectionOptimizationIT extends ParallelStatsDisabledIT
{
 
     @Test
     public void testSelect() throws Exception {
-        long ts = nextTimestamp();
         String tenantId = getOrganizationId();
-        String tableName = initATableValues(tenantId, getDefaultSplits(tenantId), null, ts);
+        String tableName = initATableValues(tenantId, getDefaultSplits(tenantId));
 
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2));
         Connection conn = DriverManager.getConnection(getUrl(), props);
 
         // Table wildcard query
@@ -228,9 +225,7 @@ public class ColumnProjectionOptimizationIT extends ParallelStatsDisabledIT
{
         }
         admin.createTable(descriptor);
 
-        long ts = nextTimestamp();
         Properties props = new Properties();
-        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 5));
         Connection conn1 = DriverManager.getConnection(getUrl(), props);
 
         String createStmt = "create view " + table + " (id integer not null primary key,"
@@ -238,7 +233,6 @@ public class ColumnProjectionOptimizationIT extends ParallelStatsDisabledIT
{
         conn1.createStatement().execute(createStmt);
         conn1.close();
 
-        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 6));
         PhoenixConnection conn2 = DriverManager.getConnection(getUrl(), props).unwrap(PhoenixConnection.class);
         byte[] c1 = Bytes.toBytes("COL1");
         byte[] c2 = Bytes.toBytes("COL2");
@@ -247,24 +241,23 @@ public class ColumnProjectionOptimizationIT extends ParallelStatsDisabledIT
{
         try {
             htable = conn2.getQueryServices().getTable(htableName);
             Put put = new Put(PInteger.INSTANCE.toBytes(1));
-            put.add(cfB, c1, ts + 6, PInteger.INSTANCE.toBytes(1));
-            put.add(cfC, c2, ts + 6, PLong.INSTANCE.toBytes(2));
+            put.add(cfB, c1, PInteger.INSTANCE.toBytes(1));
+            put.add(cfC, c2, PLong.INSTANCE.toBytes(2));
             htable.put(put);
 
             put = new Put(PInteger.INSTANCE.toBytes(2));
-            put.add(cfC, c2, ts + 6, PLong.INSTANCE.toBytes(10));
-            put.add(cfC, c3, ts + 6, PVarchar.INSTANCE.toBytes("abcd"));
+            put.add(cfC, c2, PLong.INSTANCE.toBytes(10));
+            put.add(cfC, c3, PVarchar.INSTANCE.toBytes("abcd"));
             htable.put(put);
 
             put = new Put(PInteger.INSTANCE.toBytes(3));
-            put.add(cfB, c1, ts + 6, PInteger.INSTANCE.toBytes(3));
-            put.add(cfC, c2, ts + 6, PLong.INSTANCE.toBytes(10));
-            put.add(cfC, c3, ts + 6, PVarchar.INSTANCE.toBytes("abcd"));
+            put.add(cfB, c1, PInteger.INSTANCE.toBytes(3));
+            put.add(cfC, c2, PLong.INSTANCE.toBytes(10));
+            put.add(cfC, c3, PVarchar.INSTANCE.toBytes("abcd"));
             htable.put(put);
 
             conn2.close();
 
-            props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
             Connection conn7 = DriverManager.getConnection(getUrl(), props);
             String select = "SELECT id, b.col1 FROM " + table + " WHERE c.col2=?";
             PreparedStatement ps = conn7.prepareStatement(select);
@@ -311,11 +304,10 @@ public class ColumnProjectionOptimizationIT extends ParallelStatsDisabledIT
{
     }
 
     
-    private static String initMultiCFTable(long ts) throws Exception {
+    private static String initMultiCFTable() throws Exception {
         String url = getUrl();
         String tableName = generateUniqueName();
         Properties props = new Properties();
-        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
         String ddl = "create table " + tableName +
                 "   (id char(15) not null primary key,\n" +
                 "    a.unique_user_count integer,\n" +
@@ -329,7 +321,6 @@ public class ColumnProjectionOptimizationIT extends ParallelStatsDisabledIT
{
             conn.createStatement().execute(ddl);
         }
         props = new Properties();
-        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2));
         Connection conn = DriverManager.getConnection(url, props);
         try {
             PreparedStatement stmt = conn.prepareStatement(
@@ -360,11 +351,9 @@ public class ColumnProjectionOptimizationIT extends ParallelStatsDisabledIT
{
 
     @Test
     public void testSelectWithConditionOnMultiCF() throws Exception {
-        long ts = nextTimestamp();
-        String tableName = initMultiCFTable(ts);
+        String tableName = initMultiCFTable();
         
         Properties props = new Properties();
-        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 5));
         Connection conn = DriverManager.getConnection(getUrl(), props);
         try {
             String query = "SELECT c.db_cpu_utilization FROM " + tableName + " WHERE a.unique_user_count
= ? and b.unique_org_count = ?";

http://git-wip-us.apache.org/repos/asf/phoenix/blob/933a5b1f/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConcurrentMutationsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConcurrentMutationsIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConcurrentMutationsIT.java
index 6d327f7..e5f22da 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConcurrentMutationsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConcurrentMutationsIT.java
@@ -25,8 +25,10 @@ import static org.junit.Assert.assertTrue;
 import java.io.IOException;
 import java.sql.Connection;
 import java.sql.DriverManager;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Timestamp;
 import java.util.Properties;
 import java.util.Random;
 import java.util.concurrent.CountDownLatch;
@@ -34,8 +36,6 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.hadoop.hbase.DoNotRetryIOException;
 import org.apache.hadoop.hbase.HBaseIOException;
-import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.client.Mutation;
 import org.apache.hadoop.hbase.coprocessor.ObserverContext;
 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
@@ -43,14 +43,14 @@ import org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver;
 import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.jdbc.PhoenixConnection;
-import org.apache.phoenix.query.ConnectionQueryServices;
-import org.apache.phoenix.query.QueryServicesOptions;
+import org.apache.phoenix.util.EnvironmentEdge;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
 import org.apache.phoenix.util.IndexScrutiny;
-import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.Repeat;
 import org.apache.phoenix.util.RunUntilFailure;
 import org.apache.phoenix.util.TestUtil;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -62,36 +62,27 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
     private static final int ROW_LOCK_WAIT_TIME = 10000;
     
     private final Object lock = new Object();
-    private long scn = 100;
-
-    private static void addDelayingCoprocessor(Connection conn, String tableName) throws
Exception {
-        int priority = QueryServicesOptions.DEFAULT_COPROCESSOR_PRIORITY + 100;
-        ConnectionQueryServices services = conn.unwrap(PhoenixConnection.class).getQueryServices();
-        HTableDescriptor descriptor = services.getTableDescriptor(Bytes.toBytes(tableName));
-        descriptor.addCoprocessor(DelayingRegionObserver.class.getName(), null, priority,
null);
-        int numTries = 10;
-        try (HBaseAdmin admin = services.getAdmin()) {
-            admin.modifyTable(Bytes.toBytes(tableName), descriptor);
-            while (!admin.getTableDescriptor(Bytes.toBytes(tableName)).equals(descriptor)
-                    && numTries > 0) {
-                numTries--;
-                if (numTries == 0) {
-                    throw new Exception(
-                            "Check to detect if delaying co-processor was added failed after
"
-                                    + numTries + " retries.");
-                }
-                Thread.sleep(1000);
-            }
+
+    private static class MyClock extends EnvironmentEdge {
+        public volatile long time;
+
+        public MyClock (long time) {
+            this.time = time;
+        }
+
+        @Override
+        public long currentTime() {
+            return time;
         }
     }
-    
+
     @Test
     public void testSynchronousDeletesAndUpsertValues() throws Exception {
         final String tableName = generateUniqueName();
         final String indexName = generateUniqueName();
         Connection conn = DriverManager.getConnection(getUrl());
         conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 INTEGER NOT NULL,
k2 INTEGER NOT NULL, v1 INTEGER, CONSTRAINT pk PRIMARY KEY (k1,k2)) COLUMN_ENCODED_BYTES =
0");
-        addDelayingCoprocessor(conn, tableName);
+        TestUtil.addCoprocessor(conn, tableName, DelayingRegionObserver.class);
         conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName +
"(v1)");
         final CountDownLatch doneSignal = new CountDownLatch(2);
         Runnable r1 = new Runnable() {
@@ -103,10 +94,8 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
                     for (int i = 0; i < 50; i++) {
                         Thread.sleep(20);
                         synchronized (lock) {
-                            scn += 10;
                             PhoenixConnection conn = null;
                             try {
-                                props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(scn));
                                 conn = DriverManager.getConnection(getUrl(), props).unwrap(PhoenixConnection.class);
                                 conn.setAutoCommit(true);
                                 conn.createStatement().execute("DELETE FROM " + tableName);
@@ -135,10 +124,8 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
                     int nRowsToUpsert = 1000;
                     for (int i = 0; i < nRowsToUpsert; i++) {
                         synchronized(lock) {
-                            scn += 10;
                             PhoenixConnection conn = null;
                             try {
-                                props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(scn));
                                 conn = DriverManager.getConnection(getUrl(), props).unwrap(PhoenixConnection.class);
                                 conn.createStatement().execute("UPSERT INTO " + tableName
+ " VALUES (" + (i % 10) + ", 0, 1)");
                                 if ((i % 20) == 0 || i == nRowsToUpsert-1 ) {
@@ -163,9 +150,7 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
         t2.start();
         
         doneSignal.await(60, TimeUnit.SECONDS);
-        long count1 = getRowCount(conn, tableName);
-        long count2 = getRowCount(conn, indexName);
-        assertTrue("Expected table row count ( " + count1 + ") to match index row count ("
+ count2 + ")", count1 == count2);
+        IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
     }
 
     @Test
@@ -174,7 +159,7 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
         final String indexName = generateUniqueName();
         Connection conn = DriverManager.getConnection(getUrl());
         conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 INTEGER NOT NULL,
k2 INTEGER NOT NULL, v1 INTEGER, CONSTRAINT pk PRIMARY KEY (k1,k2))");
-        addDelayingCoprocessor(conn, tableName);
+        TestUtil.addCoprocessor(conn, tableName, DelayingRegionObserver.class);
         conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName +
"(v1)");
         final CountDownLatch doneSignal = new CountDownLatch(2);
         Runnable r1 = new Runnable() {
@@ -226,9 +211,7 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
         t2.start();
         
         doneSignal.await(60, TimeUnit.SECONDS);
-        long count1 = getRowCount(conn, tableName);
-        long count2 = getRowCount(conn, indexName);
-        assertTrue("Expected table row count ( " + count1 + ") to match index row count ("
+ count2 + ")", count1 == count2);
+        IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
     }
     
     @Test
@@ -242,7 +225,7 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
         final String indexName = generateUniqueName();
         Connection conn = DriverManager.getConnection(getUrl());
         conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 INTEGER NOT NULL,
k2 INTEGER NOT NULL, v1 INTEGER, CONSTRAINT pk PRIMARY KEY (k1,k2))  COLUMN_ENCODED_BYTES
= 0, VERSIONS=1");
-        addDelayingCoprocessor(conn, tableName);
+        TestUtil.addCoprocessor(conn, tableName, DelayingRegionObserver.class);
         conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName +
"(v1)");
         final CountDownLatch doneSignal = new CountDownLatch(nThreads);
         Runnable[] runnables = new Runnable[nThreads];
@@ -288,7 +271,7 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
         Connection conn = DriverManager.getConnection(getUrl());
         
         conn.createStatement().execute("CREATE TABLE " + tableName + "(k VARCHAR PRIMARY
KEY, v INTEGER) COLUMN_ENCODED_BYTES = 0");
-        addDelayingCoprocessor(conn, tableName);
+        TestUtil.addCoprocessor(conn, tableName, DelayingRegionObserver.class);
         conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName +
"(v)");
         final CountDownLatch doneSignal = new CountDownLatch(2);
         final String[] failedMsg = new String[1];
@@ -335,6 +318,8 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
         
         doneSignal.await(ROW_LOCK_WAIT_TIME + 5000, TimeUnit.SECONDS);
         assertNull(failedMsg[0], failedMsg[0]);
+        long actualRowCount = IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
+        assertEquals(1, actualRowCount);
     }
 
     @Test
@@ -346,7 +331,7 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
         conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName +
"(v,k)");
         conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES ('foo',0)");
         conn.commit();
-        addDelayingCoprocessor(conn, tableName);
+        TestUtil.addCoprocessor(conn, tableName, DelayingRegionObserver.class);
         final CountDownLatch doneSignal = new CountDownLatch(2);
         final String[] failedMsg = new String[1];
         Runnable r1 = new Runnable() {
@@ -389,27 +374,8 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
         t2.start();
         
         doneSignal.await(ROW_LOCK_WAIT_TIME + 5000, TimeUnit.SECONDS);
-        
-        TestUtil.dumpTable(conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(tableName)));
-        TestUtil.dumpTable(conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(indexName)));
-
-        long count1 = getRowCount(conn, tableName);
-        long count2 = getRowCount(conn, indexName);
-        assertTrue("Expected table row count ( " + count1 + ") to match index row count ("
+ count2 + ")", count1 == count2);
-        
-        ResultSet rs1 = conn.createStatement().executeQuery("SELECT * FROM " + indexName);
-        assertTrue(rs1.next());
-        ResultSet rs2 = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ * FROM
" + tableName + " WHERE k = '" + rs1.getString(2) + "'");
-        assertTrue("Could not find row in table where k = '" + rs1.getString(2) + "'", rs2.next());
-        assertEquals(rs1.getInt(1), rs2.getInt(2));
-        assertFalse(rs1.next());
-        assertFalse(rs2.next());
-    }
-
-    private static long getRowCount(Connection conn, String tableName) throws SQLException
{
-        ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ count(*)
FROM " + tableName);
-        assertTrue(rs.next());
-        return rs.getLong(1);
+        long actualRowCount = IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
+        assertEquals(1, actualRowCount);
     }
 
     public static class DelayingRegionObserver extends SimpleRegionObserver {
@@ -445,4 +411,320 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
             
         }
     }
+
+    @Test
+    @Ignore("PHOENIX-4058 Generate correct index updates when DeleteColumn processed before
Put with same timestamp")
+    public void testSetIndexedColumnToNullAndValueAtSameTS() throws Exception {
+        try {
+            final MyClock clock = new MyClock(1000);
+            EnvironmentEdgeManager.injectEdge(clock);
+            String tableName = generateUniqueName();
+            String indexName = generateUniqueName();
+            Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+            long ts = 1000;
+            clock.time = ts;
+            Connection conn = DriverManager.getConnection(getUrl(), props);     
+            conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT
NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, V VARCHAR, V2 VARCHAR, CONSTRAINT pk PRIMARY KEY
(k1,k2)) COLUMN_ENCODED_BYTES = 0");
+            conn.close();
+
+            ts = 1010;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);
+            conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName
+ "(k2,k1,ts) INCLUDE (V, v2)");
+            conn.close();
+
+            ts = 1020;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);        
+            PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + "
VALUES('aa','aa',?, '0')");
+            stmt.setTimestamp(1, new Timestamp(1000L));
+            stmt.executeUpdate();
+            conn.commit();
+            conn.close();
+
+            Timestamp expectedTimestamp;
+            ts = 1040;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);
+            stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?,
null)");
+            expectedTimestamp = null;
+            stmt.setTimestamp(1, expectedTimestamp);
+            stmt.executeUpdate();
+            conn.commit();
+            stmt.setTimestamp(1, new Timestamp(3000L));
+            stmt.executeUpdate();
+            conn.commit();
+            conn.close();
+
+            ts = 1050;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);
+
+            IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);        
+
+            ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ ts,v
FROM " + tableName);
+            assertTrue(rs.next());
+            assertEquals(expectedTimestamp, rs.getTimestamp(1));
+            assertEquals(null, rs.getString(2));
+            assertFalse(rs.next());
+
+            rs = conn.createStatement().executeQuery("SELECT \"0:TS\", \"0:V\" FROM " + indexName);
+            assertTrue(rs.next());
+            assertEquals(expectedTimestamp, rs.getTimestamp(1));
+            assertEquals(null, rs.getString(2));
+            assertFalse(rs.next());
+
+            conn.close();
+        } finally {
+            EnvironmentEdgeManager.injectEdge(null);
+        }
+    }
+
+    @Test
+    public void testSetIndexedColumnToNullAndValueAtSameTSWithStoreNulls1() throws Exception
{
+        try {
+            final MyClock clock = new MyClock(1000);
+            EnvironmentEdgeManager.injectEdge(clock);
+            String tableName = generateUniqueName();
+            String indexName = generateUniqueName();
+            Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+            long ts = 1000;
+            clock.time = ts;
+            Connection conn = DriverManager.getConnection(getUrl(), props);     
+            conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT
NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, V VARCHAR, V2 VARCHAR, CONSTRAINT pk PRIMARY KEY
(k1,k2)) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
+            conn.close();
+
+            ts = 1010;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);
+            conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName
+ "(k2,k1,ts) INCLUDE (V, v2)");
+            conn.close();
+
+            ts = 1020;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);        
+            PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + "
VALUES('aa','aa',?, '0')");
+            stmt.setTimestamp(1, new Timestamp(1000L));
+            stmt.executeUpdate();
+            conn.commit();
+            conn.close();
+
+            Timestamp expectedTimestamp;
+            ts = 1040;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);
+            stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?,
null)");
+            expectedTimestamp = null;
+            stmt.setTimestamp(1, expectedTimestamp);
+            stmt.executeUpdate();
+            conn.commit();
+            expectedTimestamp = new Timestamp(3000L);
+            stmt.setTimestamp(1, expectedTimestamp);
+            stmt.executeUpdate();
+            conn.commit();
+            conn.close();
+
+            ts = 1050;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);
+
+            IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);        
+
+            ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ ts,v
FROM " + tableName);
+            assertTrue(rs.next());
+            assertEquals(expectedTimestamp, rs.getTimestamp(1));
+            assertEquals(null, rs.getString(2));
+            assertFalse(rs.next());
+
+            rs = conn.createStatement().executeQuery("SELECT \"0:TS\", \"0:V\" FROM " + indexName);
+            assertTrue(rs.next());
+            assertEquals(expectedTimestamp, rs.getTimestamp(1));
+            assertEquals(null, rs.getString(2));
+            assertFalse(rs.next());
+
+            conn.close();
+        } finally {
+            EnvironmentEdgeManager.injectEdge(null);
+        }
+    }
+
+    @Test
+    public void testSetIndexedColumnToNullAndValueAtSameTSWithStoreNulls2() throws Exception
{
+        try {
+            final MyClock clock = new MyClock(1000);
+            EnvironmentEdgeManager.injectEdge(clock);
+            String tableName = generateUniqueName();
+            String indexName = generateUniqueName();
+            Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+            long ts = 1000;
+            clock.time = ts;
+            Connection conn = DriverManager.getConnection(getUrl(), props);     
+            conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT
NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, V VARCHAR, V2 VARCHAR, CONSTRAINT pk PRIMARY KEY
(k1,k2)) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
+            conn.close();
+
+            ts = 1010;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);
+            conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName
+ "(k2,k1,ts) INCLUDE (V, v2)");
+            conn.close();
+
+            ts = 1020;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);        
+            PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + "
VALUES('aa','aa',?, '0')");
+            stmt.setTimestamp(1, new Timestamp(1000L));
+            stmt.executeUpdate();
+            conn.commit();
+            conn.close();
+
+            Timestamp expectedTimestamp;
+            ts = 1040;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);
+            stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?,
null)");
+            expectedTimestamp = new Timestamp(3000L);
+            stmt.setTimestamp(1, expectedTimestamp);
+            stmt.executeUpdate();
+            conn.commit();
+            expectedTimestamp = null;
+            stmt.setTimestamp(1, expectedTimestamp);
+            stmt.executeUpdate();
+            conn.commit();
+            conn.close();
+
+            ts = 1050;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);
+
+            IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);        
+
+            ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ ts,v
FROM " + tableName);
+            assertTrue(rs.next());
+            assertEquals(expectedTimestamp, rs.getTimestamp(1));
+            assertEquals(null, rs.getString(2));
+            assertFalse(rs.next());
+
+            rs = conn.createStatement().executeQuery("SELECT \"0:TS\", \"0:V\" FROM " + indexName);
+            assertTrue(rs.next());
+            assertEquals(expectedTimestamp, rs.getTimestamp(1));
+            assertEquals(null, rs.getString(2));
+            assertFalse(rs.next());
+
+            conn.close();
+        } finally {
+            EnvironmentEdgeManager.injectEdge(null);
+        }
+    }
+
+    @Test
+    public void testDeleteRowAndUpsertValueAtSameTS1() throws Exception {
+        try {
+            final MyClock clock = new MyClock(1000);
+            EnvironmentEdgeManager.injectEdge(clock);
+            String tableName = generateUniqueName();
+            String indexName = generateUniqueName();
+            Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+            long ts = 1000;
+            clock.time = ts;
+            Connection conn = DriverManager.getConnection(getUrl(), props);     
+            conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT
NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, A.V VARCHAR, B.V2 VARCHAR, CONSTRAINT pk PRIMARY
KEY (k1,k2)) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
+            conn.close();
+
+            ts = 1010;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);
+            conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName
+ "(k2,k1,ts) INCLUDE (V, v2)");
+            conn.close();
+
+            ts = 1020;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);        
+            PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + "
VALUES('aa','aa',?, '0','1')");
+            stmt.setTimestamp(1, new Timestamp(1000L));
+            stmt.executeUpdate();
+            conn.commit();
+            conn.close();
+
+            Timestamp expectedTimestamp;
+            ts = 1040;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);
+            stmt = conn.prepareStatement("DELETE FROM " + tableName + " WHERE (K1,K2) = ('aa','aa')");
+            stmt.executeUpdate();
+            conn.commit();
+            expectedTimestamp = new Timestamp(3000L);
+            stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?,
null,'3')");
+            stmt.setTimestamp(1, expectedTimestamp);
+            stmt.executeUpdate();
+            conn.commit();
+            conn.close();
+
+            ts = 1050;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);
+
+            long rowCount = IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
+            assertEquals(0,rowCount);
+
+            conn.close();
+        } finally {
+            EnvironmentEdgeManager.injectEdge(null);
+        }
+    }
+
+    @Test
+    public void testDeleteRowAndUpsertValueAtSameTS2() throws Exception {
+        try {
+            final MyClock clock = new MyClock(1000);
+            EnvironmentEdgeManager.injectEdge(clock);
+            String tableName = generateUniqueName();
+            String indexName = generateUniqueName();
+            Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+            long ts = 1000;
+            clock.time = ts;
+            Connection conn = DriverManager.getConnection(getUrl(), props);     
+            conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT
NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, V VARCHAR, V2 VARCHAR, CONSTRAINT pk PRIMARY KEY
(k1,k2)) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
+            conn.close();
+
+            ts = 1010;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);
+            conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName
+ "(k2,k1,ts) INCLUDE (V, v2)");
+            conn.close();
+
+            ts = 1020;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);        
+            PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + "
VALUES('aa','aa',?, '0')");
+            stmt.setTimestamp(1, new Timestamp(1000L));
+            stmt.executeUpdate();
+            conn.commit();
+            conn.close();
+
+            Timestamp expectedTimestamp;
+            ts = 1040;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);
+            expectedTimestamp = new Timestamp(3000L);
+            stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?,
null)");
+            stmt.setTimestamp(1, expectedTimestamp);
+            stmt.executeUpdate();
+            conn.commit();
+            stmt = conn.prepareStatement("DELETE FROM " + tableName + " WHERE (K1,K2) = ('aa','aa')");
+            stmt.executeUpdate();
+            conn.commit();
+            conn.close();
+
+            ts = 1050;
+            clock.time = ts;
+            conn = DriverManager.getConnection(getUrl(), props);
+
+            long rowCount = IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
+            assertEquals(0,rowCount);
+
+            conn.close();
+        } finally {
+            EnvironmentEdgeManager.injectEdge(null);
+        }
+    }
 }


Mime
View raw message