You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ya...@apache.org on 2021/01/27 19:33:33 UTC
[phoenix] 01/03: PHOENIX-5296 Ensure store file reader refcount is
zero at end of relevant unit tests
This is an automated email from the ASF dual-hosted git repository.
yanxinyi pushed a commit to branch 4.16
in repository https://gitbox.apache.org/repos/asf/phoenix.git
commit f2cc2b6ecf85880ba66c8c829eb2e6a8d4d1a254
Author: Viraj Jasani <vj...@apache.org>
AuthorDate: Wed Jan 20 13:07:25 2021 +0530
PHOENIX-5296 Ensure store file reader refcount is zero at end of relevant unit tests
---
...WALReplayWithIndexWritesAndCompressedWALIT.java | 5 +
.../org/apache/phoenix/end2end/DateTimeIT.java | 4 +-
.../org/apache/phoenix/end2end/DerivedTableIT.java | 8 +-
.../java/org/apache/phoenix/end2end/InListIT.java | 4 +-
.../end2end/IndexRepairRegionScannerIT.java | 3 +
.../end2end/IndexScrutinyToolForTenantIT.java | 6 +-
.../phoenix/end2end/IndexScrutinyToolIT.java | 3 +-
.../end2end/IndexToolForDeleteBeforeRebuildIT.java | 5 +-
.../phoenix/end2end/IndexToolTimeRangeIT.java | 6 +-
.../org/apache/phoenix/end2end/MapReduceIT.java | 4 +-
.../org/apache/phoenix/end2end/MaxLookbackIT.java | 3 +
.../MigrateSystemTablesToSystemNamespaceIT.java | 2 +
.../org/apache/phoenix/end2end/QueryTimeoutIT.java | 11 +-
.../org/apache/phoenix/end2end/SequenceIT.java | 639 +++++++++++----------
.../phoenix/end2end/SpooledTmpFileDeleteIT.java | 190 +++---
.../SystemTablesCreationOnConnectionIT.java | 53 +-
.../org/apache/phoenix/end2end/UpsertSelectIT.java | 486 ++++++++--------
.../end2end/ViewConcurrencyAndFailureIT.java | 5 +-
.../end2end/index/GlobalIndexCheckerIT.java | 2 +
.../end2end/index/IndexAsyncThresholdIT.java | 30 +-
.../java/org/apache/phoenix/query/BaseTest.java | 41 +-
.../apache/phoenix/compat/hbase/CompatUtil.java | 12 +
.../apache/phoenix/compat/hbase/CompatUtil.java | 12 +
phoenix-hbase-compat-1.5.0/pom.xml | 6 +
.../apache/phoenix/compat/hbase/CompatUtil.java | 49 ++
25 files changed, 875 insertions(+), 714 deletions(-)
diff --git a/phoenix-core/src/it/java/org/apache/hadoop/hbase/regionserver/wal/WALReplayWithIndexWritesAndCompressedWALIT.java b/phoenix-core/src/it/java/org/apache/hadoop/hbase/regionserver/wal/WALReplayWithIndexWritesAndCompressedWALIT.java
index fa248a5..65c32ea 100644
--- a/phoenix-core/src/it/java/org/apache/hadoop/hbase/regionserver/wal/WALReplayWithIndexWritesAndCompressedWALIT.java
+++ b/phoenix-core/src/it/java/org/apache/hadoop/hbase/regionserver/wal/WALReplayWithIndexWritesAndCompressedWALIT.java
@@ -19,6 +19,7 @@
package org.apache.hadoop.hbase.regionserver.wal;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -51,6 +52,7 @@ import org.apache.hadoop.hbase.util.FSUtils;
import org.apache.hadoop.hbase.wal.WAL;
import org.apache.hadoop.hbase.wal.WALFactory;
import org.apache.hadoop.hbase.wal.WALSplitter;
+import org.apache.phoenix.compat.hbase.CompatUtil;
import org.apache.phoenix.end2end.NeedsOwnMiniClusterTest;
import org.apache.phoenix.hbase.index.IndexTestingUtils;
import org.apache.phoenix.hbase.index.TableName;
@@ -151,9 +153,12 @@ public class WALReplayWithIndexWritesAndCompressedWALIT {
@After
public void tearDown() throws Exception {
+ boolean refCountLeaked = CompatUtil.isAnyStoreRefCountLeaked(
+ UTIL.getHBaseCluster().getMaster());
UTIL.shutdownMiniHBaseCluster();
UTIL.shutdownMiniDFSCluster();
UTIL.shutdownMiniZKCluster();
+ assertFalse("refCount leaked", refCountLeaked);
}
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
index 6e48d67..a1f99df 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java
@@ -203,8 +203,10 @@ public class DateTimeIT extends ParallelStatsDisabledIT {
}
@After
- public void tearDown() throws SQLException {
+ public void tearDown() throws Exception {
+ boolean refCountLeaked = isAnyStoreRefCountLeaked();
conn.close();
+ assertFalse("refCount leaked", refCountLeaked);
}
private String initAtable() throws SQLException {
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
index 979887f..e887731 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
@@ -41,10 +41,8 @@ import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
-import java.sql.Statement;
import java.util.Collection;
import java.util.List;
-import java.util.Map;
import java.util.Properties;
import org.apache.phoenix.util.PropertiesUtil;
@@ -101,8 +99,10 @@ public class DerivedTableIT extends ParallelStatsDisabledIT {
}
@After
- public void cleanUp(){
- tableName=null;
+ public void cleanUp() throws Exception {
+ boolean refCountLeaked = isAnyStoreRefCountLeaked();
+ tableName = null;
+ assertFalse("refCount leaked", refCountLeaked);
}
@Parameters(name="DerivedTableIT_{index}") // name is used by failsafe as file name in reports
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java
index 3f53910..d2fc9c7 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java
@@ -74,13 +74,15 @@ public class InListIT extends ParallelStatsDisabledIT {
}
@After
- public void cleanUp() throws SQLException {
+ public void cleanUp() throws Exception {
+ boolean refCountLeaked = isAnyStoreRefCountLeaked();
deleteTenantData(descViewName);
deleteTenantData(viewName1);
deleteTenantData(viewName2);
deleteTenantData(ascViewName);
deleteTenantData(tableName);
deleteTenantData(tableName2);
+ assertFalse("refCount leaked", refCountLeaked);
}
@Test
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexRepairRegionScannerIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexRepairRegionScannerIT.java
index fbea615..8524627 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexRepairRegionScannerIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexRepairRegionScannerIT.java
@@ -88,6 +88,7 @@ import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -149,6 +150,7 @@ public class IndexRepairRegionScannerIT extends ParallelStatsDisabledIT {
@After
public void cleanup() throws Exception {
+ boolean refCountLeaked = isAnyStoreRefCountLeaked();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
deleteAllRows(conn,
@@ -158,6 +160,7 @@ public class IndexRepairRegionScannerIT extends ParallelStatsDisabledIT {
}
EnvironmentEdgeManager.reset();
resetIndexRegionObserverFailPoints();
+ assertFalse("refCount leaked", refCountLeaked);
}
private void setIndexRowStatusesToVerified(Connection conn, String dataTableFullName, String indexTableFullName) throws Exception {
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexScrutinyToolForTenantIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexScrutinyToolForTenantIT.java
index f4e1ce7..5852b0e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexScrutinyToolForTenantIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexScrutinyToolForTenantIT.java
@@ -46,6 +46,7 @@ import static org.apache.phoenix.mapreduce.index.PhoenixScrutinyJobCounters.INVA
import static org.apache.phoenix.mapreduce.index.PhoenixScrutinyJobCounters.VALID_ROW_COUNT;
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;
/**
@@ -94,13 +95,16 @@ public class IndexScrutinyToolForTenantIT extends IndexScrutinyToolBaseIT {
connGlobal.commit();
}
- @After public void teardown() throws SQLException {
+ @After
+ public void teardown() throws Exception {
+ boolean refCountLeaked = isAnyStoreRefCountLeaked();
if (connGlobal != null) {
connGlobal.close();
}
if (connTenant != null) {
connTenant.close();
}
+ assertFalse("refCount leaked", refCountLeaked);
}
/**
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexScrutinyToolIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexScrutinyToolIT.java
index 03b6bba..78b8450 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexScrutinyToolIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexScrutinyToolIT.java
@@ -168,7 +168,8 @@ public class IndexScrutinyToolIT extends IndexScrutinyToolBaseIT {
}
- @After public void teardown() throws SQLException {
+ @After
+ public void teardown() throws Exception {
if (conn != null) {
conn.close();
}
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolForDeleteBeforeRebuildIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolForDeleteBeforeRebuildIT.java
index 4992504..a1d370c 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolForDeleteBeforeRebuildIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolForDeleteBeforeRebuildIT.java
@@ -49,6 +49,7 @@ import java.util.UUID;
import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
public class IndexToolForDeleteBeforeRebuildIT extends ParallelStatsDisabledIT {
private Connection conn;
@@ -120,9 +121,11 @@ public class IndexToolForDeleteBeforeRebuildIT extends ParallelStatsDisabledIT {
}
@After
- public void teardown() throws SQLException {
+ public void teardown() throws Exception {
if (conn != null) {
+ boolean refCountLeaked = isAnyStoreRefCountLeaked();
conn.close();
+ assertFalse("refCount leaked", refCountLeaked);
}
}
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolTimeRangeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolTimeRangeIT.java
index d6eff3a..3500893 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolTimeRangeIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolTimeRangeIT.java
@@ -34,12 +34,14 @@ import org.apache.phoenix.util.SchemaUtil;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Assume;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import com.google.common.collect.Maps;
+import static org.junit.Assert.assertFalse;
+
public class IndexToolTimeRangeIT extends BaseUniqueNamesOwnClusterIT {
private static final String
CREATE_TABLE_DDL = "CREATE TABLE %s (ID INTEGER NOT NULL PRIMARY KEY, "
@@ -219,6 +221,8 @@ public class IndexToolTimeRangeIT extends BaseUniqueNamesOwnClusterIT {
@AfterClass
public static synchronized void teardown() {
+ boolean refCountLeaked = isAnyStoreRefCountLeaked();
tearDownMiniCluster(2);
+ assertFalse("refCount leaked", refCountLeaked);
}
}
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MapReduceIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MapReduceIT.java
index 2460cd2..aeb00e5 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MapReduceIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MapReduceIT.java
@@ -85,8 +85,10 @@ public class MapReduceIT extends ParallelStatsDisabledIT {
}
@After
- public void clearCountersForScanGrouper() {
+ public void clearCountersForScanGrouper() throws Exception {
+ boolean refCountLeaked = isAnyStoreRefCountLeaked();
TestingMapReduceParallelScanGrouper.clearNumCallsToGetRegionBoundaries();
+ assertFalse("refCount leaked", refCountLeaked);
}
@Test
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MaxLookbackIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MaxLookbackIT.java
index b97b210..79ced6b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MaxLookbackIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MaxLookbackIT.java
@@ -57,6 +57,7 @@ import static org.apache.phoenix.util.TestUtil.assertRowExistsAtSCN;
import static org.apache.phoenix.util.TestUtil.assertRowHasExpectedValueAtSCN;
import static org.apache.phoenix.util.TestUtil.assertTableHasTtl;
import static org.apache.phoenix.util.TestUtil.assertTableHasVersions;
+import static org.junit.Assert.assertFalse;
@NeedsOwnMiniClusterTest
public class MaxLookbackIT extends BaseUniqueNamesOwnClusterIT {
@@ -90,7 +91,9 @@ public class MaxLookbackIT extends BaseUniqueNamesOwnClusterIT {
@AfterClass
public static synchronized void afterClass() {
+ boolean refCountLeaked = isAnyStoreRefCountLeaked();
EnvironmentEdgeManager.reset();
+ assertFalse("refCount leaked", refCountLeaked);
}
@Test
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MigrateSystemTablesToSystemNamespaceIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MigrateSystemTablesToSystemNamespaceIT.java
index b6f061e..caacb4b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MigrateSystemTablesToSystemNamespaceIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MigrateSystemTablesToSystemNamespaceIT.java
@@ -97,8 +97,10 @@ public class MigrateSystemTablesToSystemNamespaceIT extends BaseTest {
public void tearDownMiniCluster() {
try {
if (testUtil != null) {
+ boolean refCountLeaked = isAnyStoreRefCountLeaked();
testUtil.shutdownMiniCluster();
testUtil = null;
+ assertFalse("refCount leaked", refCountLeaked);
}
} catch (Exception e) {
// ignore
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryTimeoutIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryTimeoutIT.java
index 500dd94..fb0d6b6 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryTimeoutIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryTimeoutIT.java
@@ -69,14 +69,13 @@ public class QueryTimeoutIT extends BaseUniqueNamesOwnClusterIT {
}
@After
- public void assertNoUnfreedMemory() throws SQLException {
- Connection conn = DriverManager.getConnection(getUrl());
- try {
+ public void assertNoUnfreedMemory() throws Exception {
+ boolean refCountLeaked = isAnyStoreRefCountLeaked();
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
long unfreedBytes = conn.unwrap(PhoenixConnection.class).getQueryServices().clearCache();
- assertEquals(0,unfreedBytes);
- } finally {
- conn.close();
+ assertEquals(0, unfreedBytes);
}
+ assertFalse("refCount leaked", refCountLeaked);
}
@Test
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java
index 830c734..8568043 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java
@@ -64,42 +64,44 @@ import com.google.common.collect.Lists;
public class SequenceIT extends ParallelStatsDisabledIT {
private static final String SELECT_NEXT_VALUE_SQL = "SELECT NEXT VALUE FOR %s";
private static final String SCHEMA_NAME = "S";
-
+
private Connection conn;
-
+
private static String generateTableNameWithSchema() {
- return SchemaUtil.getTableName(SCHEMA_NAME, generateUniqueName());
+ return SchemaUtil.getTableName(SCHEMA_NAME, generateUniqueName());
}
-
+
private static String generateSequenceNameWithSchema() {
return SchemaUtil.getTableName(SCHEMA_NAME, generateUniqueSequenceName());
}
-
+
@Before
public void init() throws Exception {
- createConnection();
+ createConnection();
}
-
+
@After
public void tearDown() throws Exception {
// close any open connection between tests, so that connections are not leaked
- if (conn != null) {
- conn.close();
- }
+ if (conn != null) {
+ boolean refCountLeaked = isAnyStoreRefCountLeaked();
+ conn.close();
+ assertFalse("refCount leaked", refCountLeaked);
+ }
}
- @Test
- public void testSystemTable() throws Exception {
- conn.createStatement().execute("CREATE SEQUENCE " + generateSequenceNameWithSchema());
- String query = "SELECT sequence_schema, sequence_name, current_value, increment_by FROM \"SYSTEM\".\"SEQUENCE\"";
- ResultSet rs = conn.prepareStatement(query).executeQuery();
- assertTrue(rs.next());
- }
+ @Test
+ public void testSystemTable() throws Exception {
+ conn.createStatement().execute("CREATE SEQUENCE " + generateSequenceNameWithSchema());
+ String query = "SELECT sequence_schema, sequence_name, current_value, increment_by FROM \"SYSTEM\".\"SEQUENCE\"";
+ ResultSet rs = conn.prepareStatement(query).executeQuery();
+ assertTrue(rs.next());
+ }
private static class MyClock extends EnvironmentEdge {
public volatile long time;
- public MyClock (long time) {
+ public MyClock(long time) {
this.time = time;
}
@@ -109,20 +111,20 @@ public class SequenceIT extends ParallelStatsDisabledIT {
}
}
- @Test
- public void testDuplicateSequences() throws Exception {
+ @Test
+ public void testDuplicateSequences() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
-
- conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 4\n");
- try {
- conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 4\n");
- Assert.fail("Duplicate sequences");
- } catch (SequenceAlreadyExistsException e){
- }
- }
+ conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 4\n");
+
+ try {
+ conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 4\n");
+ Assert.fail("Duplicate sequences");
+ } catch (SequenceAlreadyExistsException e) {
+
+ }
+ }
@Test
public void testDuplicateSequencesAtSameTimestamp() throws Exception {
@@ -130,15 +132,14 @@ public class SequenceIT extends ParallelStatsDisabledIT {
EnvironmentEdgeManager.injectEdge(clock);
try {
String sequenceName = generateSequenceNameWithSchema();
-
-
+
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 4\n");
-
+
try {
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 4\n");
Assert.fail("Duplicate sequences");
- } catch (SequenceAlreadyExistsException e){
-
+ } catch (SequenceAlreadyExistsException e) {
+
}
} finally {
EnvironmentEdgeManager.reset();
@@ -146,19 +147,18 @@ public class SequenceIT extends ParallelStatsDisabledIT {
}
@Test
- public void testSequenceNotFound() throws Exception {
+ public void testSequenceNotFound() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
-
- String query = "SELECT NEXT value FOR " + sequenceName ;
- try {
- conn.prepareStatement(query).executeQuery();
- fail("Sequence not found");
- }catch(SequenceNotFoundException e){
-
- }
- }
-
+
+ String query = "SELECT NEXT value FOR " + sequenceName;
+ try {
+ conn.prepareStatement(query).executeQuery();
+ fail("Sequence not found");
+ } catch (SequenceNotFoundException e) {
+
+ }
+ }
+
@Test
public void testCreateSequenceWhenNamespaceEnabled() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
@@ -169,7 +169,7 @@ public class SequenceIT extends ParallelStatsDisabledIT {
String sequenceSchemaName = getSchemaName(sequenceName);
try {
- nsConn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 4");
+ nsConn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 4");
fail();
} catch (SchemaNotFoundException e) {
// expected
@@ -192,23 +192,23 @@ public class SequenceIT extends ParallelStatsDisabledIT {
assertEquals(4, rs.getInt("increment_by"));
assertFalse(rs.next());
try {
- nsConn.createStatement().execute(
+ nsConn.createStatement().execute(
"CREATE SEQUENCE " + sequenceSchemaName + "." + sequenceName + " START WITH 2 INCREMENT BY 4");
fail();
} catch (SequenceAlreadyExistsException e) {
}
}
-
- @Test
- public void testCreateSequence() throws Exception {
+
+ @Test
+ public void testCreateSequence() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
String sequenceNameWithoutSchema = getNameWithoutSchema(sequenceName);
String schemaName = getSchemaName(sequenceName);
-
+
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 4");
int bucketNum = PhoenixRuntime.getTableNoCache(conn, SYSTEM_CATALOG_SCHEMA + "." + TYPE_SEQUENCE).getBucketNum();
- assertEquals("Salt bucket for SYSTEM.SEQUENCE should be test default",bucketNum , QueryServicesTestImpl.DEFAULT_SEQUENCE_TABLE_SALT_BUCKETS);
+ assertEquals("Salt bucket for SYSTEM.SEQUENCE should be test default", bucketNum, QueryServicesTestImpl.DEFAULT_SEQUENCE_TABLE_SALT_BUCKETS);
String query = "SELECT sequence_schema, sequence_name, current_value, increment_by FROM \"SYSTEM\".\"SEQUENCE\" WHERE sequence_name='" + sequenceNameWithoutSchema + "'";
ResultSet rs = conn.prepareStatement(query).executeQuery();
assertTrue(rs.next());
@@ -217,40 +217,40 @@ public class SequenceIT extends ParallelStatsDisabledIT {
assertEquals(2, rs.getInt("current_value"));
assertEquals(4, rs.getInt("increment_by"));
assertFalse(rs.next());
- }
-
+ }
+
@Test
public void testCurrentValueFor() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
ResultSet rs;
-
+
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 4");
-
+
try {
- rs = conn.createStatement().executeQuery("SELECT CURRENT VALUE FOR " + sequenceName );
+ rs = conn.createStatement().executeQuery("SELECT CURRENT VALUE FOR " + sequenceName);
rs.next();
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.CANNOT_CALL_CURRENT_BEFORE_NEXT_VALUE.getErrorCode(), e.getErrorCode());
- assertTrue(e.getNextException()==null);
+ assertTrue(e.getNextException() == null);
}
-
- rs = conn.createStatement().executeQuery("SELECT NEXT VALUE FOR " + sequenceName );
+
+ rs = conn.createStatement().executeQuery("SELECT NEXT VALUE FOR " + sequenceName);
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
- rs = conn.createStatement().executeQuery("SELECT CURRENT VALUE FOR " + sequenceName );
+ rs = conn.createStatement().executeQuery("SELECT CURRENT VALUE FOR " + sequenceName);
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
- }
+ }
@Test
public void testDropSequence() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
String sequenceNameWithoutSchema = getNameWithoutSchema(sequenceName);
String schemaName = getSchemaName(sequenceName);
-
+
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 4");
- String query = "SELECT sequence_schema, sequence_name, current_value, increment_by FROM \"SYSTEM\".\"SEQUENCE\" WHERE sequence_name='"+ sequenceNameWithoutSchema +"'";
+ String query = "SELECT sequence_schema, sequence_name, current_value, increment_by FROM \"SYSTEM\".\"SEQUENCE\" WHERE sequence_name='" + sequenceNameWithoutSchema + "'";
ResultSet rs = conn.prepareStatement(query).executeQuery();
assertTrue(rs.next());
assertEquals(schemaName, rs.getString("sequence_schema"));
@@ -271,45 +271,45 @@ public class SequenceIT extends ParallelStatsDisabledIT {
}
}
- @Test
- public void testSelectNextValueFor() throws Exception {
+ @Test
+ public void testSelectNextValueFor() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
- conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY 2");
+ conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY 2");
assertSequenceValuesForSingleRow(sequenceName, 3, 5, 7);
- }
+ }
- @Test
- public void testInsertNextValueFor() throws Exception {
+ @Test
+ public void testInsertNextValueFor() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
String tableName = generateTableNameWithSchema();
-
+
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 1");
- conn.createStatement().execute("CREATE TABLE " + tableName + " ( id INTEGER NOT NULL PRIMARY KEY)");
- conn.createStatement().execute("UPSERT INTO " + tableName + " (id) VALUES (NEXT VALUE FOR " + sequenceName + ")");
- conn.createStatement().execute("UPSERT INTO " + tableName + " (id) VALUES (NEXT VALUE FOR " + sequenceName + ")");
- conn.commit();
- String query = "SELECT id FROM " + tableName;
- ResultSet rs = conn.prepareStatement(query).executeQuery();
- assertTrue(rs.next());
- assertEquals(2, rs.getInt(1));
+ conn.createStatement().execute("CREATE TABLE " + tableName + " ( id INTEGER NOT NULL PRIMARY KEY)");
+ conn.createStatement().execute("UPSERT INTO " + tableName + " (id) VALUES (NEXT VALUE FOR " + sequenceName + ")");
+ conn.createStatement().execute("UPSERT INTO " + tableName + " (id) VALUES (NEXT VALUE FOR " + sequenceName + ")");
+ conn.commit();
+ String query = "SELECT id FROM " + tableName;
+ ResultSet rs = conn.prepareStatement(query).executeQuery();
+ assertTrue(rs.next());
+ assertEquals(2, rs.getInt(1));
assertTrue(rs.next());
assertEquals(3, rs.getInt(1));
- }
+ }
@Test
public void testSequenceCreation() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
String sequenceNameWithoutSchema = getNameWithoutSchema(sequenceName);
String schemaName = getSchemaName(sequenceName);
-
+
conn.createStatement()
.execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 3 MINVALUE 0 MAXVALUE 10 CYCLE CACHE 5");
-
+ "CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 3 MINVALUE 0 MAXVALUE 10 CYCLE CACHE 5");
+
ResultSet rs =
conn.createStatement()
.executeQuery(
- "SELECT start_with, current_value, increment_by, cache_size, min_value, max_value, cycle_flag, sequence_schema, sequence_name FROM \"SYSTEM\".\"SEQUENCE\" WHERE SEQUENCE_SCHEMA='" + schemaName + "' AND SEQUENCE_NAME='" + sequenceNameWithoutSchema + "'");
+ "SELECT start_with, current_value, increment_by, cache_size, min_value, max_value, cycle_flag, sequence_schema, sequence_name FROM \"SYSTEM\".\"SEQUENCE\" WHERE SEQUENCE_SCHEMA='" + schemaName + "' AND SEQUENCE_NAME='" + sequenceNameWithoutSchema + "'");
assertTrue(rs.next());
assertEquals(2, rs.getLong("start_with"));
assertEquals(2, rs.getInt("current_value"));
@@ -324,16 +324,16 @@ public class SequenceIT extends ParallelStatsDisabledIT {
rs =
conn.createStatement()
.executeQuery(
- "SELECT NEXT VALUE FOR " + sequenceName + ", CURRENT VALUE FOR " + sequenceName );
+ "SELECT NEXT VALUE FOR " + sequenceName + ", CURRENT VALUE FOR " + sequenceName);
assertTrue(rs.next());
assertEquals(2, rs.getLong(1));
assertEquals(2, rs.getLong(2));
-
+
assertFalse(rs.next());
rs =
conn.createStatement()
.executeQuery(
- "SELECT CURRENT VALUE FOR " + sequenceName + ", NEXT VALUE FOR " + sequenceName );
+ "SELECT CURRENT VALUE FOR " + sequenceName + ", NEXT VALUE FOR " + sequenceName);
assertTrue(rs.next());
assertEquals(5, rs.getLong(1));
assertEquals(5, rs.getLong(2));
@@ -343,9 +343,9 @@ public class SequenceIT extends ParallelStatsDisabledIT {
@Test
public void testSameMultipleSequenceValues() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 4 INCREMENT BY 7");
- String query = "SELECT NEXT VALUE FOR " + sequenceName + ", NEXT VALUE FOR " + sequenceName ;
+ String query = "SELECT NEXT VALUE FOR " + sequenceName + ", NEXT VALUE FOR " + sequenceName;
ResultSet rs = conn.prepareStatement(query).executeQuery();
assertTrue(rs.next());
assertEquals(4, rs.getInt(1));
@@ -358,33 +358,33 @@ public class SequenceIT extends ParallelStatsDisabledIT {
public void testMultipleSequenceValues() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
String alternateSequenceName = generateSequenceNameWithSchema();
-
+
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 4 INCREMENT BY 7");
conn.createStatement().execute("CREATE SEQUENCE " + alternateSequenceName + " START WITH 9 INCREMENT BY 2");
-
+
String query = "SELECT NEXT VALUE FOR " + sequenceName + ", NEXT VALUE FOR " + alternateSequenceName + " FROM " + PhoenixDatabaseMetaData.SYSTEM_SEQUENCE + " LIMIT 2";
ResultSet rs = conn.prepareStatement(query).executeQuery();
assertTrue(rs.next());
assertEquals(4, rs.getInt(1));
assertEquals(9, rs.getInt(2));
assertTrue(rs.next());
- assertEquals(4+7, rs.getInt(1));
- assertEquals(9+2, rs.getInt(2));
+ assertEquals(4 + 7, rs.getInt(1));
+ assertEquals(9 + 2, rs.getInt(2));
assertFalse(rs.next());
// Test that sequences don't have gaps (if no other client request the same sequence before we close it)
Connection conn2 = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES));
rs = conn2.prepareStatement(query).executeQuery();
assertTrue(rs.next());
- assertEquals(4+7*2, rs.getInt(1));
- assertEquals(9+2*2, rs.getInt(2));
+ assertEquals(4 + 7 * 2, rs.getInt(1));
+ assertEquals(9 + 2 * 2, rs.getInt(2));
assertTrue(rs.next());
- assertEquals(4+7*3, rs.getInt(1));
- assertEquals(9+2*3, rs.getInt(2));
+ assertEquals(4 + 7 * 3, rs.getInt(1));
+ assertEquals(9 + 2 * 3, rs.getInt(2));
assertFalse(rs.next());
conn2.close();
}
-
+
@Test
public void testMultipleSequencesNoCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
@@ -394,9 +394,9 @@ public class SequenceIT extends ParallelStatsDisabledIT {
String alternatesequenceNameWithoutSchema = getNameWithoutSchema(alternateSequenceName);
conn.createStatement().execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 4 INCREMENT BY 7 MAXVALUE 24");
+ "CREATE SEQUENCE " + sequenceName + " START WITH 4 INCREMENT BY 7 MAXVALUE 24");
conn.createStatement().execute(
- "CREATE SEQUENCE " + alternateSequenceName + " START WITH 9 INCREMENT BY -2 MINVALUE 5");
+ "CREATE SEQUENCE " + alternateSequenceName + " START WITH 9 INCREMENT BY -2 MINVALUE 5");
String query =
"SELECT NEXT VALUE FOR " + sequenceName + ", NEXT VALUE FOR " + alternateSequenceName + " FROM " + PhoenixDatabaseMetaData.SYSTEM_SEQUENCE + " LIMIT 2";
ResultSet rs = conn.prepareStatement(query).executeQuery();
@@ -407,7 +407,7 @@ public class SequenceIT extends ParallelStatsDisabledIT {
assertEquals(4 + 7, rs.getInt(1));
assertEquals(9 - 2, rs.getInt(2));
assertFalse(rs.next());
-
+
rs = conn.prepareStatement(query).executeQuery();
assertTrue(rs.next());
assertEquals(4 + 7 * 2, rs.getInt(1));
@@ -418,27 +418,27 @@ public class SequenceIT extends ParallelStatsDisabledIT {
} catch (SQLException e) {
SQLException sqlEx1 =
SequenceUtil.getException(schemaName, sequenceNameWithoutSchema,
- SQLExceptionCode.SEQUENCE_VAL_REACHED_MAX_VALUE);
+ SQLExceptionCode.SEQUENCE_VAL_REACHED_MAX_VALUE);
SQLException sqlEx2 =
SequenceUtil.getException(schemaName, alternatesequenceNameWithoutSchema,
- SQLExceptionCode.SEQUENCE_VAL_REACHED_MIN_VALUE);
+ SQLExceptionCode.SEQUENCE_VAL_REACHED_MIN_VALUE);
verifyExceptions(e, Lists.newArrayList(sqlEx1.getMessage(), sqlEx2.getMessage()));
}
conn.close();
}
-
+
@Test
public void testMultipleSequencesCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
String alternateSequenceName = generateSequenceNameWithSchema();
-
+
conn.createStatement().execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 4 INCREMENT BY 7 MINVALUE 4 MAXVALUE 19 CYCLE");
+ "CREATE SEQUENCE " + sequenceName + " START WITH 4 INCREMENT BY 7 MINVALUE 4 MAXVALUE 19 CYCLE");
conn.createStatement().execute(
- "CREATE SEQUENCE " + alternateSequenceName + " START WITH 9 INCREMENT BY -2 MINVALUE 5 MAXVALUE 9 CYCLE");
-
+ "CREATE SEQUENCE " + alternateSequenceName + " START WITH 9 INCREMENT BY -2 MINVALUE 5 MAXVALUE 9 CYCLE");
+
String query =
- "SELECT NEXT VALUE FOR " + sequenceName + ", NEXT VALUE FOR " + alternateSequenceName + " FROM " + PhoenixDatabaseMetaData.SYSTEM_SEQUENCE + " LIMIT 2";
+ "SELECT NEXT VALUE FOR " + sequenceName + ", NEXT VALUE FOR " + alternateSequenceName + " FROM " + PhoenixDatabaseMetaData.SYSTEM_SEQUENCE + " LIMIT 2";
ResultSet rs = conn.prepareStatement(query).executeQuery();
assertTrue(rs.next());
assertEquals(4, rs.getInt(1));
@@ -447,7 +447,7 @@ public class SequenceIT extends ParallelStatsDisabledIT {
assertEquals(4 + 7, rs.getInt(1));
assertEquals(9 - 2, rs.getInt(2));
assertFalse(rs.next());
-
+
rs = conn.prepareStatement(query).executeQuery();
assertTrue(rs.next());
assertEquals(4 + 7 * 2, rs.getInt(1));
@@ -456,38 +456,38 @@ public class SequenceIT extends ParallelStatsDisabledIT {
assertEquals(4, rs.getInt(1));
assertEquals(9, rs.getInt(2));
}
-
- @Test
- public void testCompilerOptimization() throws Exception {
+
+ @Test
+ public void testCompilerOptimization() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
String tableName = generateTableNameWithSchema();
-
- conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY 2");
- conn.createStatement().execute("CREATE TABLE " + tableName + " (k INTEGER NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) IMMUTABLE_ROWS=true");
-
+
+ conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY 2");
+ conn.createStatement().execute("CREATE TABLE " + tableName + " (k INTEGER NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) IMMUTABLE_ROWS=true");
+
conn.createStatement().execute("CREATE INDEX " + generateUniqueName() + " ON " + tableName + "(v1) INCLUDE (v2)");
-
+
PhoenixStatement stmt = conn.createStatement().unwrap(PhoenixStatement.class);
stmt.optimizeQuery("SELECT k, NEXT VALUE FOR " + sequenceName + " FROM " + tableName + " WHERE v1 = 'bar'");
- }
-
- @Test
- public void testSelectRowAndSequence() throws Exception {
+ }
+
+ @Test
+ public void testSelectRowAndSequence() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
String tableName = generateTableNameWithSchema();
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 1 INCREMENT BY 4");
- conn.createStatement().execute("CREATE TABLE " + tableName + " ( id INTEGER NOT NULL PRIMARY KEY)");
-
- conn.createStatement().execute("UPSERT INTO " + tableName + " (id) VALUES (NEXT VALUE FOR " + sequenceName + ")");
- conn.commit();
-
- String query = "SELECT NEXT VALUE FOR " + sequenceName + ", id FROM " + tableName;
- ResultSet rs = conn.prepareStatement(query).executeQuery();
- assertTrue(rs.next());
- assertEquals(5, rs.getInt(1));
- assertEquals(1, rs.getInt(2));
+ conn.createStatement().execute("CREATE TABLE " + tableName + " ( id INTEGER NOT NULL PRIMARY KEY)");
+
+ conn.createStatement().execute("UPSERT INTO " + tableName + " (id) VALUES (NEXT VALUE FOR " + sequenceName + ")");
+ conn.commit();
+
+ String query = "SELECT NEXT VALUE FOR " + sequenceName + ", id FROM " + tableName;
+ ResultSet rs = conn.prepareStatement(query).executeQuery();
+ assertTrue(rs.next());
+ assertEquals(5, rs.getInt(1));
+ assertEquals(1, rs.getInt(2));
assertFalse(rs.next());
- }
+ }
@Test
public void testSelectNextValueForOverMultipleBatches() throws Exception {
@@ -496,13 +496,13 @@ public class SequenceIT extends ParallelStatsDisabledIT {
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName);
conn.createStatement().execute("CREATE TABLE " + tableName + " (k BIGINT NOT NULL PRIMARY KEY)");
-
+
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES(NEXT VALUE FOR " + sequenceName + ")");
- for (int i = 0; i < DEFAULT_SEQUENCE_CACHE_SIZE * 2 + 1; i++) {
+ for (int i = 0; i < DEFAULT_SEQUENCE_CACHE_SIZE * 2 + 1; i++) {
stmt.execute();
}
conn.commit();
-
+
ResultSet rs = conn.createStatement().executeQuery("SELECT count(*),max(k) FROM " + tableName);
assertTrue(rs.next());
assertEquals(DEFAULT_SEQUENCE_CACHE_SIZE * 2 + 1, rs.getInt(1));
@@ -514,11 +514,11 @@ public class SequenceIT extends ParallelStatsDisabledIT {
String sequenceName = generateSequenceNameWithSchema();
String tableName1 = generateTableNameWithSchema();
String tableName2 = generateTableNameWithSchema();
-
+
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName);
conn.createStatement().execute("CREATE TABLE " + tableName1 + " (k BIGINT NOT NULL PRIMARY KEY, v VARCHAR)");
- conn.createStatement().execute("CREATE TABLE "+ tableName2 + " (k BIGINT NOT NULL PRIMARY KEY, v VARCHAR)");
-
+ conn.createStatement().execute("CREATE TABLE " + tableName2 + " (k BIGINT NOT NULL PRIMARY KEY, v VARCHAR)");
+
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName1 + " VALUES(NEXT VALUE FOR " + sequenceName + ", ?)");
stmt.setString(1, "a");
stmt.execute();
@@ -531,8 +531,8 @@ public class SequenceIT extends ParallelStatsDisabledIT {
stmt.setString(1, "c");
stmt.execute();
conn.commit();
-
- ResultSet rs = conn.createStatement().executeQuery("SELECT k from " + tableName1 );
+
+ ResultSet rs = conn.createStatement().executeQuery("SELECT k from " + tableName1);
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertTrue(rs.next());
@@ -545,10 +545,11 @@ public class SequenceIT extends ParallelStatsDisabledIT {
assertEquals(5, rs.getInt(1));
assertFalse(rs.next());
-
- conn.setAutoCommit(true);;
+
+ conn.setAutoCommit(true);
+ ;
conn.createStatement().execute("UPSERT INTO " + tableName2 + " SELECT NEXT VALUE FOR " + sequenceName + ",v FROM " + tableName1 + " GROUP BY v");
-
+
rs = conn.createStatement().executeQuery("SELECT * from " + tableName2);
assertTrue(rs.next());
assertEquals(6, rs.getInt(1));
@@ -572,11 +573,11 @@ public class SequenceIT extends ParallelStatsDisabledIT {
Connection conn1 = conn;
PreparedStatement stmt1 = conn1.prepareStatement("UPSERT INTO " + tableName + " VALUES(NEXT VALUE FOR " + sequenceName + ")");
- for (int i = 0; i < DEFAULT_SEQUENCE_CACHE_SIZE+ 1; i++) {
+ for (int i = 0; i < DEFAULT_SEQUENCE_CACHE_SIZE + 1; i++) {
stmt1.execute();
}
conn1.commit();
-
+
Connection conn2 = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES));
PreparedStatement stmt2 = conn2.prepareStatement("UPSERT INTO " + tableName + " VALUES(NEXT VALUE FOR " + sequenceName + ")");
stmt2.execute();
@@ -586,12 +587,12 @@ public class SequenceIT extends ParallelStatsDisabledIT {
}
conn2.commit();
conn2.close();
-
+
// No gaps exist even when sequences were generated from different connections
ResultSet rs = conn.createStatement().executeQuery("SELECT k FROM " + tableName);
- for (int i = 0; i < (DEFAULT_SEQUENCE_CACHE_SIZE+ 1)*2; i++) {
+ for (int i = 0; i < (DEFAULT_SEQUENCE_CACHE_SIZE + 1) * 2; i++) {
assertTrue(rs.next());
- assertEquals(i+1, rs.getInt(1));
+ assertEquals(i + 1, rs.getInt(1));
}
assertFalse(rs.next());
}
@@ -600,16 +601,16 @@ public class SequenceIT extends ParallelStatsDisabledIT {
public void testSelectNextValueForMultipleConnWithStmtClose() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
String tableName = generateTableNameWithSchema();
-
+
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName);
conn.createStatement().execute("CREATE TABLE " + tableName + " (k BIGINT NOT NULL PRIMARY KEY)");
PreparedStatement stmt1 = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES(NEXT VALUE FOR " + sequenceName + " )");
- for (int i = 0; i < DEFAULT_SEQUENCE_CACHE_SIZE+ 1; i++) {
+ for (int i = 0; i < DEFAULT_SEQUENCE_CACHE_SIZE + 1; i++) {
stmt1.execute();
}
conn.commit();
stmt1.close();
-
+
Connection conn2 = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES));
PreparedStatement stmt2 = conn2.prepareStatement("UPSERT INTO " + tableName + " VALUES(NEXT VALUE FOR " + sequenceName + " )");
for (int i = 0; i < DEFAULT_SEQUENCE_CACHE_SIZE + 1; i++) {
@@ -617,11 +618,11 @@ public class SequenceIT extends ParallelStatsDisabledIT {
}
conn2.commit();
conn2.close();
-
+
ResultSet rs = conn.createStatement().executeQuery("SELECT k FROM " + tableName);
- for (int i = 0; i < 2*(DEFAULT_SEQUENCE_CACHE_SIZE + 1); i++) {
+ for (int i = 0; i < 2 * (DEFAULT_SEQUENCE_CACHE_SIZE + 1); i++) {
assertTrue(rs.next());
- assertEquals(i+1, rs.getInt(1));
+ assertEquals(i + 1, rs.getInt(1));
}
assertFalse(rs.next());
}
@@ -630,28 +631,29 @@ public class SequenceIT extends ParallelStatsDisabledIT {
public void testSelectNextValueForMultipleConnWithConnClose() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
String tableName = generateTableNameWithSchema();
-
+
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName);
conn.createStatement().execute("CREATE TABLE " + tableName + " (k BIGINT NOT NULL PRIMARY KEY)");
PreparedStatement stmt1 = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES(NEXT VALUE FOR " + sequenceName + " )");
- for (int i = 0; i < DEFAULT_SEQUENCE_CACHE_SIZE+ 1; i++) {
+ for (int i = 0; i < DEFAULT_SEQUENCE_CACHE_SIZE + 1; i++) {
stmt1.execute();
}
conn.commit();
- Connection conn2 = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES));;
+ Connection conn2 = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES));
+ ;
PreparedStatement stmt2 = conn2.prepareStatement("UPSERT INTO " + tableName + " VALUES(NEXT VALUE FOR " + sequenceName + " )");
for (int i = 0; i < DEFAULT_SEQUENCE_CACHE_SIZE + 1; i++) {
stmt2.execute();
}
conn2.commit();
conn2.close();
-
+
ResultSet rs = conn.createStatement().executeQuery("SELECT k FROM " + tableName);
- for (int i = 0; i < 2*(DEFAULT_SEQUENCE_CACHE_SIZE + 1); i++) {
+ for (int i = 0; i < 2 * (DEFAULT_SEQUENCE_CACHE_SIZE + 1); i++) {
assertTrue(rs.next());
- assertEquals(i+1, rs.getInt(1));
+ assertEquals(i + 1, rs.getInt(1));
}
assertFalse(rs.next());
}
@@ -660,37 +662,38 @@ public class SequenceIT extends ParallelStatsDisabledIT {
public void testDropCachedSeq1() throws Exception {
testDropCachedSeq(false);
}
-
+
@Test
public void testDropCachedSeq2() throws Exception {
testDropCachedSeq(true);
}
-
+
private void testDropCachedSeq(boolean detectDeleteSeqInEval) throws Exception {
String sequenceName = generateSequenceNameWithSchema();
String alternateSequenceName = generateSequenceNameWithSchema();
String tableName = generateTableNameWithSchema();
-
+
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName);
conn.createStatement().execute("CREATE SEQUENCE " + alternateSequenceName + " START WITH 101");
conn.createStatement().execute("CREATE TABLE " + tableName + " (k BIGINT NOT NULL PRIMARY KEY)");
-
+
String stmtStr1a = "UPSERT INTO " + tableName + " VALUES(NEXT VALUE FOR " + sequenceName + " )";
PreparedStatement stmt1a = conn.prepareStatement(stmtStr1a);
stmt1a.execute();
stmt1a.execute();
- String stmtStr1b = "UPSERT INTO " + tableName + " VALUES(NEXT VALUE FOR "+ alternateSequenceName +")";
+ String stmtStr1b = "UPSERT INTO " + tableName + " VALUES(NEXT VALUE FOR " + alternateSequenceName + ")";
PreparedStatement stmt1b = conn.prepareStatement(stmtStr1b);
stmt1b.execute();
stmt1b.execute();
stmt1b.execute();
conn.commit();
-
- Connection conn2 = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES));;
+
+ Connection conn2 = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES));
+ ;
PreparedStatement stmt2 = conn2.prepareStatement("UPSERT INTO " + tableName + " VALUES(NEXT VALUE FOR " + alternateSequenceName + ")");
stmt2.execute();
conn2.commit();
-
+
ResultSet rs = conn.createStatement().executeQuery("SELECT k FROM " + tableName + "");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
@@ -705,15 +708,15 @@ public class SequenceIT extends ParallelStatsDisabledIT {
assertTrue(rs.next());
assertEquals(104, rs.getInt(1));
assertFalse(rs.next());
-
+
conn.createStatement().execute("DROP SEQUENCE " + alternateSequenceName);
-
+
stmt1a = conn.prepareStatement(stmtStr1a);
stmt1a.execute();
if (!detectDeleteSeqInEval) {
stmt1a.execute(); // Will allocate new batch for " + sequenceName + " and get error for bar.bas, but ignore it
}
-
+
stmt1b = conn.prepareStatement(stmtStr1b);
try {
stmt1b.execute(); // Will try to get new batch, but fail b/c sequence has been dropped
@@ -728,30 +731,30 @@ public class SequenceIT extends ParallelStatsDisabledIT {
String sequenceName = generateSequenceNameWithSchema();
String sequenceNameWithoutSchema = getNameWithoutSchema(sequenceName);
String tableName = generateTableNameWithSchema();
-
+
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName);
conn.createStatement().execute("CREATE TABLE " + tableName + " (k BIGINT NOT NULL PRIMARY KEY)");
-
+
Connection conn2 = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES));
String query = "SELECT NEXT VALUE FOR " + sequenceName + " FROM " + tableName;
ExplainPlan plan = conn.prepareStatement(query)
- .unwrap(PhoenixPreparedStatement.class).optimizeQuery()
- .getExplainPlan();
+ .unwrap(PhoenixPreparedStatement.class).optimizeQuery()
+ .getExplainPlan();
ExplainPlanAttributes explainPlanAttributes =
- plan.getPlanStepsAsAttributes();
+ plan.getPlanStepsAsAttributes();
assertEquals("PARALLEL 1-WAY",
- explainPlanAttributes.getIteratorTypeAndScanSize());
+ explainPlanAttributes.getIteratorTypeAndScanSize());
assertEquals("FULL SCAN ",
- explainPlanAttributes.getExplainScanType());
+ explainPlanAttributes.getExplainScanType());
assertEquals(tableName, explainPlanAttributes.getTableName());
assertEquals("SERVER FILTER BY FIRST KEY ONLY",
- explainPlanAttributes.getServerWhereFilter());
+ explainPlanAttributes.getServerWhereFilter());
assertEquals(1,
- explainPlanAttributes.getClientSequenceCount().intValue());
+ explainPlanAttributes.getClientSequenceCount().intValue());
ResultSet rs = conn.createStatement().executeQuery(
- "SELECT sequence_name, current_value FROM \"SYSTEM\".\"SEQUENCE\" WHERE sequence_name='"
- + sequenceNameWithoutSchema + "'");
+ "SELECT sequence_name, current_value FROM \"SYSTEM\".\"SEQUENCE\" WHERE sequence_name='"
+ + sequenceNameWithoutSchema + "'");
assertTrue(rs.next());
assertEquals(sequenceNameWithoutSchema, rs.getString(1));
assertEquals(1, rs.getInt(2));
@@ -765,10 +768,10 @@ public class SequenceIT extends ParallelStatsDisabledIT {
}
conn.close();
}
-
+
@Test
public void testSelectNextValueAsInput() throws Exception {
-
+
String sequenceName = generateSequenceName();
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY 2");
String query = "SELECT LPAD(ENCODE(NEXT VALUE FOR " + sequenceName + " ,'base62'),5,'0') FROM \"SYSTEM\".\"SEQUENCE\"";
@@ -776,17 +779,17 @@ public class SequenceIT extends ParallelStatsDisabledIT {
assertTrue(rs.next());
assertEquals("00003", rs.getString(1));
}
-
+
private String generateSequenceName() {
- return generateUniqueSequenceName();
+ return generateUniqueSequenceName();
}
-
+
@Test
public void testSelectNextValueInArithmetic() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY 2");
-
+
String query = "SELECT NEXT VALUE FOR " + sequenceName + " +1";
ResultSet rs = conn.prepareStatement(query).executeQuery();
assertTrue(rs.next());
@@ -794,46 +797,46 @@ public class SequenceIT extends ParallelStatsDisabledIT {
}
private void createConnection() throws Exception {
- Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
conn = DriverManager.getConnection(getUrl(), props);
}
-
+
@Test
public void testSequenceDefault() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName);
-
+
assertSequenceValuesForSingleRow(sequenceName, 1, 2, 3);
conn.createStatement().execute("DROP SEQUENCE " + sequenceName);
-
+
sequenceName = generateSequenceNameWithSchema();
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " INCREMENT BY -1");
-
+
assertSequenceValuesForSingleRow(sequenceName, 1, 0, -1);
conn.createStatement().execute("DROP SEQUENCE " + sequenceName);
-
+
sequenceName = generateSequenceNameWithSchema();
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " MINVALUE 10");
-
+
assertSequenceValuesForSingleRow(sequenceName, 10, 11, 12);
conn.createStatement().execute("DROP SEQUENCE " + sequenceName);
-
+
sequenceName = generateSequenceNameWithSchema();
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " INCREMENT BY -1 MINVALUE 10 ");
-
+
assertSequenceValuesForSingleRow(sequenceName, Long.MAX_VALUE, Long.MAX_VALUE - 1, Long.MAX_VALUE - 2);
conn.createStatement().execute("DROP SEQUENCE " + sequenceName);
-
+
sequenceName = generateSequenceNameWithSchema();
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " MAXVALUE 0");
-
+
assertSequenceValuesForSingleRow(sequenceName, Long.MIN_VALUE, Long.MIN_VALUE + 1, Long.MIN_VALUE + 2);
conn.createStatement().execute("DROP SEQUENCE " + sequenceName);
-
+
sequenceName = generateSequenceNameWithSchema();
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " INCREMENT BY -1 MAXVALUE 0");
-
+
assertSequenceValuesForSingleRow(sequenceName, 0, -1, -2);
}
@@ -841,24 +844,24 @@ public class SequenceIT extends ParallelStatsDisabledIT {
public void testSequenceValidateStartValue() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
String alternateSequenceName = generateSequenceNameWithSchema();
-
+
try {
conn.createStatement().execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 1 INCREMENT BY 1 MINVALUE 2 MAXVALUE 3");
+ "CREATE SEQUENCE " + sequenceName + " START WITH 1 INCREMENT BY 1 MINVALUE 2 MAXVALUE 3");
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.STARTS_WITH_MUST_BE_BETWEEN_MIN_MAX_VALUE.getErrorCode(),
- e.getErrorCode());
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
try {
conn.createStatement().execute(
- "CREATE SEQUENCE " + alternateSequenceName + " START WITH 4 INCREMENT BY 1 MINVALUE 2 MAXVALUE 3");
+ "CREATE SEQUENCE " + alternateSequenceName + " START WITH 4 INCREMENT BY 1 MINVALUE 2 MAXVALUE 3");
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.STARTS_WITH_MUST_BE_BETWEEN_MIN_MAX_VALUE.getErrorCode(),
- e.getErrorCode());
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
}
@@ -866,13 +869,13 @@ public class SequenceIT extends ParallelStatsDisabledIT {
@Test
public void testSequenceValidateMinValue() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
try {
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " MINVALUE abc");
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.MINVALUE_MUST_BE_CONSTANT.getErrorCode(),
- e.getErrorCode());
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
}
@@ -880,13 +883,13 @@ public class SequenceIT extends ParallelStatsDisabledIT {
@Test
public void testSequenceValidateMaxValue() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
try {
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " MAXVALUE null");
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.MAXVALUE_MUST_BE_CONSTANT.getErrorCode(),
- e.getErrorCode());
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
}
@@ -894,15 +897,15 @@ public class SequenceIT extends ParallelStatsDisabledIT {
@Test
public void testSequenceValidateMinValueLessThanOrEqualToMaxValue() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
-
+
+
try {
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " MINVALUE 2 MAXVALUE 1");
fail();
} catch (SQLException e) {
assertEquals(
- SQLExceptionCode.MINVALUE_MUST_BE_LESS_THAN_OR_EQUAL_TO_MAXVALUE.getErrorCode(),
- e.getErrorCode());
+ SQLExceptionCode.MINVALUE_MUST_BE_LESS_THAN_OR_EQUAL_TO_MAXVALUE.getErrorCode(),
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
}
@@ -910,13 +913,13 @@ public class SequenceIT extends ParallelStatsDisabledIT {
@Test
public void testSequenceValidateIncrementConstant() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
try {
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " INCREMENT null");
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.INCREMENT_BY_MUST_BE_CONSTANT.getErrorCode(),
- e.getErrorCode());
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
}
@@ -924,48 +927,48 @@ public class SequenceIT extends ParallelStatsDisabledIT {
@Test
public void testSequenceValidateIncrementNotEqualToZero() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
try {
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " INCREMENT 0");
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.INCREMENT_BY_MUST_NOT_BE_ZERO.getErrorCode(),
- e.getErrorCode());
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
}
-
+
@Test
public void testSequenceStartWithMinMaxSameValueIncreasingCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
conn.createStatement()
.execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY 1 MINVALUE 3 MAXVALUE 3 CYCLE CACHE 1");
-
+ "CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY 1 MINVALUE 3 MAXVALUE 3 CYCLE CACHE 1");
+
assertSequenceValuesForSingleRow(sequenceName, 3, 3, 3);
}
-
+
@Test
public void testSequenceStartWithMinMaxSameValueDecreasingCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
conn.createStatement()
.execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY -1 MINVALUE 3 MAXVALUE 3 CYCLE CACHE 2");
-
+ "CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY -1 MINVALUE 3 MAXVALUE 3 CYCLE CACHE 2");
+
assertSequenceValuesForSingleRow(sequenceName, 3, 3, 3);
}
-
+
@Test
public void testSequenceStartWithMinMaxSameValueIncreasingNoCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
-
+
+
conn.createStatement()
.execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY 1 MINVALUE 3 MAXVALUE 3 CACHE 1");
-
+ "CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY 1 MINVALUE 3 MAXVALUE 3 CACHE 1");
+
assertSequenceValuesForSingleRow(sequenceName, 3);
try {
ResultSet rs = conn.createStatement().executeQuery(String.format(SELECT_NEXT_VALUE_SQL, sequenceName));
@@ -973,19 +976,19 @@ public class SequenceIT extends ParallelStatsDisabledIT {
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.SEQUENCE_VAL_REACHED_MAX_VALUE.getErrorCode(),
- e.getErrorCode());
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
}
-
+
@Test
public void testSequenceStartWithMinMaxSameValueDecreasingNoCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
conn.createStatement()
.execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY -1 MINVALUE 3 MAXVALUE 3 CACHE 2");
-
+ "CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY -1 MINVALUE 3 MAXVALUE 3 CACHE 2");
+
assertSequenceValuesForSingleRow(sequenceName, 3);
try {
ResultSet rs = conn.createStatement().executeQuery(String.format(SELECT_NEXT_VALUE_SQL, sequenceName));
@@ -993,7 +996,7 @@ public class SequenceIT extends ParallelStatsDisabledIT {
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.SEQUENCE_VAL_REACHED_MIN_VALUE.getErrorCode(),
- e.getErrorCode());
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
}
@@ -1001,31 +1004,31 @@ public class SequenceIT extends ParallelStatsDisabledIT {
@Test
public void testSequenceIncreasingCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
conn.createStatement()
.execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 3 MINVALUE 1 MAXVALUE 10 CYCLE CACHE 2");
+ "CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 3 MINVALUE 1 MAXVALUE 10 CYCLE CACHE 2");
assertSequenceValuesForSingleRow(sequenceName, 2, 5, 8, 1, 4, 7, 10, 1, 4);
}
@Test
public void testSequenceDecreasingCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
conn.createStatement()
.execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY -2 MINVALUE 1 MAXVALUE 10 CYCLE CACHE 2");
+ "CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY -2 MINVALUE 1 MAXVALUE 10 CYCLE CACHE 2");
assertSequenceValuesForSingleRow(sequenceName, 3, 1, 10, 8, 6, 4, 2, 10, 8);
}
@Test
public void testSequenceIncreasingNoCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
-
+
+
// client throws exception
conn.createStatement().execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 3 MINVALUE 1 MAXVALUE 10 CACHE 100");
+ "CREATE SEQUENCE " + sequenceName + " START WITH 2 INCREMENT BY 3 MINVALUE 1 MAXVALUE 10 CACHE 100");
assertSequenceValuesForSingleRow(sequenceName, 2, 5, 8);
try {
ResultSet rs = conn.createStatement().executeQuery(String.format(SELECT_NEXT_VALUE_SQL, sequenceName));
@@ -1033,7 +1036,7 @@ public class SequenceIT extends ParallelStatsDisabledIT {
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.SEQUENCE_VAL_REACHED_MAX_VALUE.getErrorCode(),
- e.getErrorCode());
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
}
@@ -1041,10 +1044,10 @@ public class SequenceIT extends ParallelStatsDisabledIT {
@Test
public void testSequenceIncreasingUsingMaxValueNoCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
// server throws exception
conn.createStatement().execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 8 INCREMENT BY 2 MINVALUE 1 MAXVALUE 10 CACHE 2");
+ "CREATE SEQUENCE " + sequenceName + " START WITH 8 INCREMENT BY 2 MINVALUE 1 MAXVALUE 10 CACHE 2");
assertSequenceValuesForSingleRow(sequenceName, 8, 10);
try {
ResultSet rs = conn.createStatement().executeQuery(String.format(SELECT_NEXT_VALUE_SQL, sequenceName));
@@ -1052,7 +1055,7 @@ public class SequenceIT extends ParallelStatsDisabledIT {
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.SEQUENCE_VAL_REACHED_MAX_VALUE.getErrorCode(),
- e.getErrorCode());
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
}
@@ -1060,11 +1063,11 @@ public class SequenceIT extends ParallelStatsDisabledIT {
@Test
public void testSequenceDecreasingNoCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
// client will throw exception
conn.createStatement()
.execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 4 INCREMENT BY -2 MINVALUE 1 MAXVALUE 10 CACHE 100");
+ "CREATE SEQUENCE " + sequenceName + " START WITH 4 INCREMENT BY -2 MINVALUE 1 MAXVALUE 10 CACHE 100");
assertSequenceValuesForSingleRow(sequenceName, 4, 2);
try {
ResultSet rs = conn.createStatement().executeQuery(String.format(SELECT_NEXT_VALUE_SQL, sequenceName));
@@ -1072,7 +1075,7 @@ public class SequenceIT extends ParallelStatsDisabledIT {
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.SEQUENCE_VAL_REACHED_MIN_VALUE.getErrorCode(),
- e.getErrorCode());
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
}
@@ -1080,10 +1083,10 @@ public class SequenceIT extends ParallelStatsDisabledIT {
@Test
public void testSequenceDecreasingUsingMinValueNoCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
// server will throw exception
conn.createStatement().execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY -2 MINVALUE 1 MAXVALUE 10 CACHE 2");
+ "CREATE SEQUENCE " + sequenceName + " START WITH 3 INCREMENT BY -2 MINVALUE 1 MAXVALUE 10 CACHE 2");
assertSequenceValuesForSingleRow(sequenceName, 3, 1);
try {
ResultSet rs = conn.createStatement().executeQuery(String.format(SELECT_NEXT_VALUE_SQL, sequenceName));
@@ -1091,7 +1094,7 @@ public class SequenceIT extends ParallelStatsDisabledIT {
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.SEQUENCE_VAL_REACHED_MIN_VALUE.getErrorCode(),
- e.getErrorCode());
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
}
@@ -1099,11 +1102,11 @@ public class SequenceIT extends ParallelStatsDisabledIT {
@Test
public void testSequenceIncreasingOverflowNoCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
// start with Long.MAX_VALUE
conn.createStatement().execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 9223372036854775807 INCREMENT BY 1 CACHE 10");
-
+ "CREATE SEQUENCE " + sequenceName + " START WITH 9223372036854775807 INCREMENT BY 1 CACHE 10");
+
assertSequenceValuesForSingleRow(sequenceName, Long.MAX_VALUE);
try {
ResultSet rs = conn.createStatement().executeQuery(String.format(SELECT_NEXT_VALUE_SQL, sequenceName));
@@ -1111,7 +1114,7 @@ public class SequenceIT extends ParallelStatsDisabledIT {
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.SEQUENCE_VAL_REACHED_MAX_VALUE.getErrorCode(),
- e.getErrorCode());
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
}
@@ -1119,22 +1122,22 @@ public class SequenceIT extends ParallelStatsDisabledIT {
@Test
public void testSequenceIncreasingOverflowCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
// start with Long.MAX_VALUE
conn.createStatement()
.execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 9223372036854775807 INCREMENT BY 9223372036854775807 CYCLE CACHE 10");
+ "CREATE SEQUENCE " + sequenceName + " START WITH 9223372036854775807 INCREMENT BY 9223372036854775807 CYCLE CACHE 10");
assertSequenceValuesForSingleRow(sequenceName, Long.MAX_VALUE, Long.MIN_VALUE, -1, Long.MAX_VALUE - 1,
- Long.MIN_VALUE, -1);
+ Long.MIN_VALUE, -1);
}
@Test
public void testSequenceDecreasingOverflowNoCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
// start with Long.MIN_VALUE + 1
conn.createStatement().execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH -9223372036854775807 INCREMENT BY -1 CACHE 10");
+ "CREATE SEQUENCE " + sequenceName + " START WITH -9223372036854775807 INCREMENT BY -1 CACHE 10");
assertSequenceValuesForSingleRow(sequenceName, Long.MIN_VALUE + 1, Long.MIN_VALUE);
try {
ResultSet rs = conn.createStatement().executeQuery(String.format(SELECT_NEXT_VALUE_SQL, sequenceName));
@@ -1142,7 +1145,7 @@ public class SequenceIT extends ParallelStatsDisabledIT {
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.SEQUENCE_VAL_REACHED_MIN_VALUE.getErrorCode(),
- e.getErrorCode());
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
}
@@ -1150,22 +1153,22 @@ public class SequenceIT extends ParallelStatsDisabledIT {
@Test
public void testSequenceDecreasingOverflowCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
-
+
// start with Long.MIN_VALUE + 1
conn.createStatement()
.execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH -9223372036854775807 INCREMENT BY -9223372036854775807 CYCLE CACHE 10");
+ "CREATE SEQUENCE " + sequenceName + " START WITH -9223372036854775807 INCREMENT BY -9223372036854775807 CYCLE CACHE 10");
assertSequenceValuesForSingleRow(sequenceName, Long.MIN_VALUE + 1, Long.MAX_VALUE, 0, Long.MIN_VALUE + 1,
- Long.MAX_VALUE, 0);
+ Long.MAX_VALUE, 0);
}
@Test
public void testMultipleSequenceValuesNoCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
String alternateSequenceName = generateSequenceNameWithSchema();
-
+
conn.createStatement().execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 1 INCREMENT BY 2 MINVALUE 1 MAXVALUE 10 CACHE 2");
+ "CREATE SEQUENCE " + sequenceName + " START WITH 1 INCREMENT BY 2 MINVALUE 1 MAXVALUE 10 CACHE 2");
conn.createStatement().execute("CREATE SEQUENCE " + alternateSequenceName);
assertSequenceValuesMultipleSeq(sequenceName, 1, 3);
assertSequenceValuesMultipleSeq(sequenceName, 5, 7);
@@ -1180,7 +1183,7 @@ public class SequenceIT extends ParallelStatsDisabledIT {
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.SEQUENCE_VAL_REACHED_MAX_VALUE.getErrorCode(),
- e.getErrorCode());
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
@@ -1189,7 +1192,7 @@ public class SequenceIT extends ParallelStatsDisabledIT {
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.SEQUENCE_VAL_REACHED_MAX_VALUE.getErrorCode(),
- e.getErrorCode());
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
}
@@ -1197,10 +1200,10 @@ public class SequenceIT extends ParallelStatsDisabledIT {
@Test
public void testMultipleSequenceValuesCycle() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
- String alternateSequenceName = generateSequenceNameWithSchema();
- conn.createStatement()
+ String alternateSequenceName = generateSequenceNameWithSchema();
+ conn.createStatement()
.execute(
- "CREATE SEQUENCE " + sequenceName + " START WITH 1 INCREMENT BY 2 MINVALUE 1 MAXVALUE 10 CYCLE CACHE 2");
+ "CREATE SEQUENCE " + sequenceName + " START WITH 1 INCREMENT BY 2 MINVALUE 1 MAXVALUE 10 CYCLE CACHE 2");
conn.createStatement().execute("CREATE SEQUENCE " + alternateSequenceName);
assertSequenceValuesMultipleSeq(sequenceName, 1, 3);
assertSequenceValuesMultipleSeq(sequenceName, 5, 7);
@@ -1216,17 +1219,17 @@ public class SequenceIT extends ParallelStatsDisabledIT {
String sequenceName = generateSequenceNameWithSchema();
String tableName1 = generateTableNameWithSchema();
String tableName2 = generateTableNameWithSchema();
-
+
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName);
conn.createStatement()
.execute(
- "CREATE TABLE " + tableName1 + "(event_id BIGINT NOT NULL PRIMARY KEY, user_id char(15), val BIGINT )");
+ "CREATE TABLE " + tableName1 + "(event_id BIGINT NOT NULL PRIMARY KEY, user_id char(15), val BIGINT )");
conn.createStatement()
.execute(
- "CREATE TABLE " + tableName2 + " (metric_id char(15) NOT NULL PRIMARY KEY, agg_id char(15), metric_val INTEGER )");
+ "CREATE TABLE " + tableName2 + " (metric_id char(15) NOT NULL PRIMARY KEY, agg_id char(15), metric_val INTEGER )");
+
-
// 2 rows for user1, 3 rows for user2 and 1 row for user3
insertEvent(tableName1, 1, "user1", 1);
insertEvent(tableName1, 2, "user2", 1);
@@ -1238,7 +1241,7 @@ public class SequenceIT extends ParallelStatsDisabledIT {
conn.createStatement()
.execute(
- "UPSERT INTO " + tableName2 + " SELECT 'METRIC_'||(LPAD(ENCODE(NEXT VALUE FOR " + sequenceName + ",'base62'),5,'0')), user_id, sum(val) FROM " + tableName1 + " GROUP BY user_id ORDER BY user_id");
+ "UPSERT INTO " + tableName2 + " SELECT 'METRIC_'||(LPAD(ENCODE(NEXT VALUE FOR " + sequenceName + ",'base62'),5,'0')), user_id, sum(val) FROM " + tableName1 + " GROUP BY user_id ORDER BY user_id");
conn.commit();
PreparedStatement stmt =
@@ -1258,7 +1261,7 @@ public class SequenceIT extends ParallelStatsDisabledIT {
assertEquals(1, rs.getLong("metric_val"));
assertFalse(rs.next());
}
-
+
@Test
/**
* Test to validate that the bug discovered in PHOENIX-2149 has been fixed. There was an issue
@@ -1270,7 +1273,7 @@ public class SequenceIT extends ParallelStatsDisabledIT {
String sequenceName = generateSequenceNameWithSchema();
// Create Sequence
conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 4990 MINVALUE 4990 MAXVALUE 5000 CACHE 10");
-
+
// Call NEXT VALUE FOR 1 time more than available values in the Sequence. We expected the final time
// to throw an error as we will have reached the max value
try {
@@ -1279,12 +1282,12 @@ public class SequenceIT extends ParallelStatsDisabledIT {
ResultSet rs = conn.createStatement().executeQuery(String.format(SELECT_NEXT_VALUE_SQL, sequenceName));
rs.next();
val = rs.getLong(1);
-
+
}
fail("Expect to fail as we have arrived at the max sequence value " + val);
} catch (SQLException e) {
assertEquals(SQLExceptionCode.SEQUENCE_VAL_REACHED_MAX_VALUE.getErrorCode(),
- e.getErrorCode());
+ e.getErrorCode());
assertTrue(e.getNextException() == null);
}
}
@@ -1299,6 +1302,7 @@ public class SequenceIT extends ParallelStatsDisabledIT {
/**
* Helper to verify the sequence values returned in multiple ResultSets each containing one row
+ *
* @param seqVals expected sequence values (one per ResultSet)
*/
private void assertSequenceValuesForSingleRow(String sequenceName, long... seqVals)
@@ -1316,6 +1320,7 @@ public class SequenceIT extends ParallelStatsDisabledIT {
/**
* Helper to verify the sequence values returned in a single ResultSet containing multiple row
+ *
* @param seqVals expected sequence values (from one ResultSet)
*/
private void assertSequenceValuesMultipleSeq(String sequenceName, long... seqVals) throws SQLException {
@@ -1343,19 +1348,19 @@ public class SequenceIT extends ParallelStatsDisabledIT {
+ unexpectedExceptions + " missing exceptions : " + missingExceptions);
}
}
-
+
@Test
public void testValidateBeforeReserve() throws Exception {
-
+
String tableName = generateTableNameWithSchema();
String seqName = generateSequenceNameWithSchema();
-
+
conn.createStatement().execute(
"CREATE TABLE " + tableName + " (k VARCHAR PRIMARY KEY, l BIGINT)");
conn.createStatement().execute(
- "CREATE SEQUENCE " + seqName);
-
-
+ "CREATE SEQUENCE " + seqName);
+
+
ResultSet rs = conn.createStatement().executeQuery("EXPLAIN SELECT NEXT VALUE FOR " + seqName + " FROM " + tableName);
assertTrue(rs.next());
conn.createStatement().execute(
@@ -1363,20 +1368,20 @@ public class SequenceIT extends ParallelStatsDisabledIT {
conn.createStatement().execute(
"UPSERT INTO " + tableName + " VALUES ('b', NEXT VALUE FOR " + seqName + ")");
conn.commit();
-
+
rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName);
assertTrue(rs.next());
- assertEquals("a",rs.getString(1));
- assertEquals(1,rs.getLong(2));
+ assertEquals("a", rs.getString(1));
+ assertEquals(1, rs.getLong(2));
assertTrue(rs.next());
- assertEquals("b",rs.getString(1));
- assertEquals(2,rs.getLong(2));
+ assertEquals("b", rs.getString(1));
+ assertEquals(2, rs.getLong(2));
assertFalse(rs.next());
-
-
+
+
PreparedStatement stmt = conn.prepareStatement("SELECT NEXT VALUE FOR " + seqName + " FROM " + tableName);
ParameterMetaData md = stmt.getParameterMetaData();
- assertEquals(0,md.getParameterCount());
+ assertEquals(0, md.getParameterCount());
rs = stmt.executeQuery();
assertTrue(rs.next());
assertEquals(3, rs.getLong(1));
@@ -1384,14 +1389,14 @@ public class SequenceIT extends ParallelStatsDisabledIT {
assertEquals(4, rs.getLong(1));
assertFalse(rs.next());
}
-
+
@Test
public void testNoFromClause() throws Exception {
String sequenceName = generateSequenceNameWithSchema();
String alternateSequenceName = generateSequenceNameWithSchema();
-
+
ResultSet rs;
-
+
String seqName = sequenceName;
String secondSeqName = alternateSequenceName;
conn.createStatement().execute("CREATE SEQUENCE " + seqName + " START WITH 1 INCREMENT BY 1");
@@ -1399,12 +1404,12 @@ public class SequenceIT extends ParallelStatsDisabledIT {
String query = "SELECT NEXT VALUE FOR " + seqName;
ExplainPlan plan = conn.prepareStatement(query)
- .unwrap(PhoenixPreparedStatement.class).optimizeQuery()
- .getExplainPlan();
+ .unwrap(PhoenixPreparedStatement.class).optimizeQuery()
+ .getExplainPlan();
ExplainPlanAttributes explainPlanAttributes =
- plan.getPlanStepsAsAttributes();
+ plan.getPlanStepsAsAttributes();
assertEquals(new Integer(1),
- explainPlanAttributes.getClientSequenceCount());
+ explainPlanAttributes.getClientSequenceCount());
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
@@ -1412,11 +1417,11 @@ public class SequenceIT extends ParallelStatsDisabledIT {
query = "SELECT CURRENT VALUE FOR " + seqName;
plan = conn.prepareStatement(query)
- .unwrap(PhoenixPreparedStatement.class).optimizeQuery()
- .getExplainPlan();
+ .unwrap(PhoenixPreparedStatement.class).optimizeQuery()
+ .getExplainPlan();
explainPlanAttributes = plan.getPlanStepsAsAttributes();
assertEquals(new Integer(1),
- explainPlanAttributes.getClientSequenceCount());
+ explainPlanAttributes.getClientSequenceCount());
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
@@ -1428,15 +1433,15 @@ public class SequenceIT extends ParallelStatsDisabledIT {
rs = conn.createStatement().executeQuery("SELECT CURRENT VALUE FOR " + seqName + ", NEXT VALUE FOR " + secondSeqName);
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
- assertEquals(5, rs.getInt(2));
+ assertEquals(5, rs.getInt(2));
}
-
+
private static String getSchemaName(String tableName) {
- return tableName.substring(0, tableName.indexOf("."));
+ return tableName.substring(0, tableName.indexOf("."));
}
-
+
private static String getNameWithoutSchema(String tableName) {
- return tableName.substring(tableName.indexOf(".") + 1, tableName.length());
- }
+ return tableName.substring(tableName.indexOf(".") + 1);
+ }
}
\ No newline at end of file
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledTmpFileDeleteIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledTmpFileDeleteIT.java
index e63c3f6..60925df 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledTmpFileDeleteIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SpooledTmpFileDeleteIT.java
@@ -37,9 +37,9 @@ import org.junit.Test;
import com.google.common.io.Files;
public class SpooledTmpFileDeleteIT extends ParallelStatsDisabledIT {
- private static final String PRINCIPAL = "noRenewLease";
+ private static final String PRINCIPAL = "noRenewLease";
private File spoolDir;
- private String tableName;
+ private String tableName;
private Connection getConnection() throws Exception {
Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
@@ -53,99 +53,101 @@ public class SpooledTmpFileDeleteIT extends ParallelStatsDisabledIT {
String url = QueryUtil.getConnectionUrl(props, config, PRINCIPAL);
return DriverManager.getConnection(url, props);
}
-
- @Before
- public void setup() throws Exception {
- tableName = generateUniqueName();
- spoolDir = Files.createTempDir();
+
+ @Before
+ public void setup() throws Exception {
+ tableName = generateUniqueName();
+ spoolDir = Files.createTempDir();
try (Connection conn = getConnection()) {
- Statement stmt = conn.createStatement();
- stmt.execute("CREATE TABLE " + tableName + " (ID varchar NOT NULL PRIMARY KEY) SPLIT ON ('EA','EZ')");
- stmt.execute("UPSERT INTO " + tableName + " VALUES ('AA')");
- stmt.execute("UPSERT INTO " + tableName + " VALUES ('EB')");
- stmt.execute("UPSERT INTO " + tableName + " VALUES ('FA')");
- stmt.close();
- conn.commit();
+ Statement stmt = conn.createStatement();
+ stmt.execute("CREATE TABLE " + tableName + " (ID varchar NOT NULL PRIMARY KEY) SPLIT ON ('EA','EZ')");
+ stmt.execute("UPSERT INTO " + tableName + " VALUES ('AA')");
+ stmt.execute("UPSERT INTO " + tableName + " VALUES ('EB')");
+ stmt.execute("UPSERT INTO " + tableName + " VALUES ('FA')");
+ stmt.close();
+ conn.commit();
+ }
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ boolean refCountLeaked = isAnyStoreRefCountLeaked();
+ if (spoolDir != null) {
+ spoolDir.delete();
}
- }
-
- @After
- public void tearDown() throws Exception {
- if (spoolDir != null) {
- spoolDir.delete();
- }
- }
-
- @Test
- public void testDeleteAllSpooledTmpFiles() throws SQLException, Throwable {
- File dir = new File(spoolDir.getPath());
- File[] files = null;
-
- class FilenameFilter implements FileFilter {
- @Override
- public boolean accept(File dir) {
- return dir.getName().toLowerCase().endsWith(".bin") &&
- dir.getName().startsWith("ResultSpooler");
- }
- }
-
- FilenameFilter fnameFilter = new FilenameFilter();
-
- // clean up first
- files = dir.listFiles(fnameFilter);
- for (File file : files) {
- file.delete();
- }
-
- String query = "select * from " + tableName;
- Connection conn = getConnection();
- Statement statement = conn.createStatement();
- ResultSet rs = statement.executeQuery(query);
- assertTrue(rs.next());
- files = dir.listFiles(fnameFilter);
- assertTrue(files.length > 0);
- List<String> fileNames = new ArrayList<String>();
- for (File file : files) {
- fileNames.add(file.getName());
- }
-
- String preparedQuery = "select * from " + tableName + " where id = ?";
- PreparedStatement pstmt = conn.prepareStatement(preparedQuery);
- pstmt.setString(1, "EB");
- ResultSet prs = pstmt.executeQuery(preparedQuery);
- assertTrue(prs.next());
- files = dir.listFiles(fnameFilter);
- assertTrue(files.length > 0);
- for (File file : files) {
- fileNames.add(file.getName());
- }
-
- Connection conn2 = getConnection();
- String query2 = "select * from " + tableName + "";
- Statement statement2 = conn2.createStatement();
- ResultSet rs2 = statement2.executeQuery(query2);
- assertTrue(rs2.next());
- files = dir.listFiles(fnameFilter);
- assertTrue(files.length > 0);
-
- String preparedQuery2 = "select * from " + tableName + " where id = ?";
- PreparedStatement pstmt2 = conn2.prepareStatement(preparedQuery2);
- pstmt2.setString(1, "EB");
- ResultSet prs2 = pstmt2.executeQuery(preparedQuery2);
- assertTrue(prs2.next());
- files = dir.listFiles(fnameFilter);
- assertTrue(files.length > 0);
-
- conn.close();
-
- files = dir.listFiles(fnameFilter);
-
- for (File file : files) {
- assertFalse(fileNames.contains(file.getName()));
- }
- conn2.close();
- files = dir.listFiles(fnameFilter);
- assertTrue(files.length == 0);
- }
+ assertFalse("refCount leaked", refCountLeaked);
+ }
+
+ @Test
+ public void testDeleteAllSpooledTmpFiles() throws SQLException, Throwable {
+ File dir = new File(spoolDir.getPath());
+ File[] files = null;
+
+ class FilenameFilter implements FileFilter {
+ @Override
+ public boolean accept(File dir) {
+ return dir.getName().toLowerCase().endsWith(".bin") &&
+ dir.getName().startsWith("ResultSpooler");
+ }
+ }
+
+ FilenameFilter fnameFilter = new FilenameFilter();
+
+ // clean up first
+ files = dir.listFiles(fnameFilter);
+ for (File file : files) {
+ file.delete();
+ }
+
+ String query = "select * from " + tableName;
+ Connection conn = getConnection();
+ Statement statement = conn.createStatement();
+ ResultSet rs = statement.executeQuery(query);
+ assertTrue(rs.next());
+ files = dir.listFiles(fnameFilter);
+ assertTrue(files.length > 0);
+ List<String> fileNames = new ArrayList<String>();
+ for (File file : files) {
+ fileNames.add(file.getName());
+ }
+
+ String preparedQuery = "select * from " + tableName + " where id = ?";
+ PreparedStatement pstmt = conn.prepareStatement(preparedQuery);
+ pstmt.setString(1, "EB");
+ ResultSet prs = pstmt.executeQuery(preparedQuery);
+ assertTrue(prs.next());
+ files = dir.listFiles(fnameFilter);
+ assertTrue(files.length > 0);
+ for (File file : files) {
+ fileNames.add(file.getName());
+ }
+
+ Connection conn2 = getConnection();
+ String query2 = "select * from " + tableName + "";
+ Statement statement2 = conn2.createStatement();
+ ResultSet rs2 = statement2.executeQuery(query2);
+ assertTrue(rs2.next());
+ files = dir.listFiles(fnameFilter);
+ assertTrue(files.length > 0);
+
+ String preparedQuery2 = "select * from " + tableName + " where id = ?";
+ PreparedStatement pstmt2 = conn2.prepareStatement(preparedQuery2);
+ pstmt2.setString(1, "EB");
+ ResultSet prs2 = pstmt2.executeQuery(preparedQuery2);
+ assertTrue(prs2.next());
+ files = dir.listFiles(fnameFilter);
+ assertTrue(files.length > 0);
+
+ conn.close();
+
+ files = dir.listFiles(fnameFilter);
+
+ for (File file : files) {
+ assertFalse(fileNames.contains(file.getName()));
+ }
+ conn2.close();
+ files = dir.listFiles(fnameFilter);
+ assertTrue(files.length == 0);
+ }
}
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemTablesCreationOnConnectionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemTablesCreationOnConnectionIT.java
index e477068..d83c38d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemTablesCreationOnConnectionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemTablesCreationOnConnectionIT.java
@@ -49,6 +49,7 @@ import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.NamespaceNotFoundException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.phoenix.compat.hbase.CompatUtil;
import org.apache.phoenix.coprocessor.MetaDataProtocol;
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.exception.UpgradeRequiredException;
@@ -68,9 +69,15 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
@Category(NeedsOwnMiniClusterTest.class)
public class SystemTablesCreationOnConnectionIT {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(
+ SystemTablesCreationOnConnectionIT.class);
+
private HBaseTestingUtility testUtil = null;
private Set<String> hbaseTables;
private static boolean setOldTimestampToInduceUpgrade = false;
@@ -81,7 +88,7 @@ public class SystemTablesCreationOnConnectionIT {
private static final String PHOENIX_NAMESPACE_MAPPED_SYSTEM_CATALOG = "SYSTEM:CATALOG";
private static final String PHOENIX_SYSTEM_CATALOG = "SYSTEM.CATALOG";
private static final String EXECUTE_UPGRADE_COMMAND = "EXECUTE UPGRADE";
- private static final String MODIFIED_MAX_VERSIONS ="5";
+ private static final String MODIFIED_MAX_VERSIONS = "5";
private static final String CREATE_TABLE_STMT = "CREATE TABLE %s"
+ " (k1 VARCHAR NOT NULL, k2 VARCHAR, CONSTRAINT PK PRIMARY KEY(K1,K2))";
private static final String SELECT_STMT = "SELECT * FROM %s";
@@ -91,17 +98,17 @@ public class SystemTablesCreationOnConnectionIT {
private static final String QUERY_SYSTEM_CATALOG = "SELECT * FROM SYSTEM.CATALOG LIMIT 1";
private static final Set<String> PHOENIX_SYSTEM_TABLES = new HashSet<>(Arrays.asList(
- "SYSTEM.CATALOG", "SYSTEM.SEQUENCE", "SYSTEM.STATS", "SYSTEM.FUNCTION",
- "SYSTEM.MUTEX", "SYSTEM.LOG", "SYSTEM.CHILD_LINK", "SYSTEM.TASK"));
+ "SYSTEM.CATALOG", "SYSTEM.SEQUENCE", "SYSTEM.STATS", "SYSTEM.FUNCTION",
+ "SYSTEM.MUTEX", "SYSTEM.LOG", "SYSTEM.CHILD_LINK", "SYSTEM.TASK"));
private static final Set<String> PHOENIX_NAMESPACE_MAPPED_SYSTEM_TABLES = new HashSet<>(
- Arrays.asList("SYSTEM:CATALOG", "SYSTEM:SEQUENCE", "SYSTEM:STATS", "SYSTEM:FUNCTION",
- "SYSTEM:MUTEX", "SYSTEM:LOG", "SYSTEM:CHILD_LINK", "SYSTEM:TASK"));
+ Arrays.asList("SYSTEM:CATALOG", "SYSTEM:SEQUENCE", "SYSTEM:STATS", "SYSTEM:FUNCTION",
+ "SYSTEM:MUTEX", "SYSTEM:LOG", "SYSTEM:CHILD_LINK", "SYSTEM:TASK"));
private static class PhoenixSysCatCreationServices extends ConnectionQueryServicesImpl {
PhoenixSysCatCreationServices(QueryServices services,
- PhoenixEmbeddedDriver.ConnectionInfo connectionInfo, Properties info) {
+ PhoenixEmbeddedDriver.ConnectionInfo connectionInfo, Properties info) {
super(services, connectionInfo, info);
}
@@ -123,7 +130,7 @@ public class SystemTablesCreationOnConnectionIT {
@Override
protected PhoenixConnection upgradeSystemCatalogIfRequired(PhoenixConnection metaConnection,
- long currentServerSideTableTimeStamp) throws InterruptedException, SQLException,
+ long currentServerSideTableTimeStamp) throws InterruptedException, SQLException,
TimeoutException, IOException {
PhoenixConnection newMetaConnection = super.upgradeSystemCatalogIfRequired(
metaConnection, currentServerSideTableTimeStamp);
@@ -144,7 +151,7 @@ public class SystemTablesCreationOnConnectionIT {
@Override // public for testing
public synchronized ConnectionQueryServices getConnectionQueryServices(String url,
- Properties info) throws SQLException {
+ Properties info) throws SQLException {
if (cqs == null) {
cqs = new PhoenixSysCatCreationServices(new QueryServicesTestImpl(getDefaultProps(),
overrideProps), ConnectionInfo.create(url), info);
@@ -164,7 +171,6 @@ public class SystemTablesCreationOnConnectionIT {
}
}
-
@Before
public void resetVariables() {
setOldTimestampToInduceUpgrade = false;
@@ -173,20 +179,27 @@ public class SystemTablesCreationOnConnectionIT {
}
@After
- public void tearDownMiniCluster() {
+ public synchronized void tearDownMiniCluster() {
try {
if (testUtil != null) {
+ boolean isMasterAvailable =
+ testUtil.getHBaseCluster().getMaster() != null;
+ boolean refCountLeaked = false;
+ if (isMasterAvailable) {
+ refCountLeaked = CompatUtil.isAnyStoreRefCountLeaked(
+ testUtil.getHBaseCluster().getMaster());
+ }
testUtil.shutdownMiniCluster();
testUtil = null;
+ assertFalse("refCount leaked", refCountLeaked);
}
} catch (Exception e) {
// ignore
}
}
-
- // Conditions: isDoNotUpgradePropSet is true
- // Expected: We do not create SYSTEM.CATALOG even if this is the first connection to the server
+ // Conditions: isDoNotUpgradePropSet is true
+ // Expected: We do not create SYSTEM.CATALOG even if this is the first connection to the server
@Test
public void testFirstConnectionDoNotUpgradePropSet() throws Exception {
startMiniClusterWithToggleNamespaceMapping(Boolean.FALSE.toString());
@@ -498,7 +511,7 @@ public class SystemTablesCreationOnConnectionIT {
DriverManager.registerDriver(PhoenixDriver.INSTANCE);
startMiniClusterWithToggleNamespaceMapping(Boolean.FALSE.toString());
try (Connection ignored = DriverManager.getConnection(getJdbcUrl());
- HBaseAdmin admin = testUtil.getHBaseAdmin()) {
+ HBaseAdmin admin = testUtil.getHBaseAdmin()) {
HTableDescriptor htd = admin.getTableDescriptor(SYSTEM_MUTEX_HBASE_TABLE_NAME);
HColumnDescriptor hColDesc = htd.getFamily(SYSTEM_MUTEX_FAMILY_NAME_BYTES);
assertEquals("Did not find the correct TTL for SYSTEM.MUTEX", TTL_FOR_MUTEX,
@@ -543,6 +556,7 @@ public class SystemTablesCreationOnConnectionIT {
/**
* Return all created HBase tables
+ *
* @return Set of HBase table name strings
* @throws IOException if there is a problem listing all HBase tables
*/
@@ -566,6 +580,7 @@ public class SystemTablesCreationOnConnectionIT {
/**
* Alter the table metadata and return modified value
+ *
* @param driver testing Phoenix driver
* @return value of VERSIONS option for the table
* @throws Exception if there is an error modifying the HBase metadata for SYSTEM.CATALOG
@@ -592,6 +607,7 @@ public class SystemTablesCreationOnConnectionIT {
/**
* Start the mini-cluster with server-side namespace mapping property specified
+ *
* @param isNamespaceMappingEnabled true if namespace mapping is enabled
* @throws Exception if there is an error starting the minicluster
*/
@@ -607,6 +623,7 @@ public class SystemTablesCreationOnConnectionIT {
/**
* Get the connection string for the mini-cluster
+ *
* @return Phoenix connection string
*/
private String getJdbcUrl() {
@@ -615,12 +632,13 @@ public class SystemTablesCreationOnConnectionIT {
/**
* Set namespace mapping related properties for the client connection
- * @param nsMappingEnabled true if namespace mapping is enabled
+ *
+ * @param nsMappingEnabled true if namespace mapping is enabled
* @param systemTableMappingEnabled true if we are mapping SYSTEM tables to their own namespace
* @return Properties object
*/
private Properties getClientProperties(boolean nsMappingEnabled,
- boolean systemTableMappingEnabled) {
+ boolean systemTableMappingEnabled) {
Properties clientProps = new Properties();
clientProps.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED,
Boolean.valueOf(nsMappingEnabled).toString());
@@ -631,6 +649,7 @@ public class SystemTablesCreationOnConnectionIT {
/**
* Initiate the first connection to the server with provided auto-upgrade property
+ *
* @param isAutoUpgradeEnabled true if auto-upgrade is enabled
* @return Phoenix JDBC driver
* @throws Exception if starting the minicluster fails
@@ -681,7 +700,7 @@ public class SystemTablesCreationOnConnectionIT {
// Expected: If this is the first connection to the server, we should be able to create all
// namespace mapped system tables i.e. SYSTEM:.*
private PhoenixSysCatCreationTestingDriver firstConnNSMappingServerEnabledClientEnabled()
- throws Exception {
+ throws Exception {
startMiniClusterWithToggleNamespaceMapping(Boolean.TRUE.toString());
Properties clientProps = getClientProperties(true, true);
PhoenixSysCatCreationTestingDriver driver =
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
index cf624c3..f5efc56 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
@@ -81,13 +81,13 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
// An hour - inherited from ParallelStatsDisabledIT
props.put(ScanInfoUtil.PHOENIX_MAX_LOOKBACK_AGE_CONF_KEY,
- Integer.toString(60 * 60));
+ Integer.toString(60 * 60));
// Postpone scans of SYSTEM.TASK indefinitely so as to prevent
// any addition to GLOBAL_OPEN_PHOENIX_CONNECTIONS
props.put(QueryServices.TASK_HANDLING_INTERVAL_MS_ATTRIB,
- Long.toString(Long.MAX_VALUE));
+ Long.toString(Long.MAX_VALUE));
props.put(QueryServices.TASK_HANDLING_INITIAL_DELAY_MS_ATTRIB,
- Long.toString(Long.MAX_VALUE));
+ Long.toString(Long.MAX_VALUE));
setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
}
@@ -104,27 +104,29 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
}
@After
- public void assertNoConnLeak() {
+ public void assertNoConnLeak() throws Exception {
+ boolean refCountLeaked = isAnyStoreRefCountLeaked();
assertTrue(PhoenixRuntime.areGlobalClientMetricsBeingCollected());
assertEquals(0, GLOBAL_OPEN_PHOENIX_CONNECTIONS.getMetric().getValue());
+ assertFalse("refCount leaked", refCountLeaked);
}
// name is used by failsafe as file name in reports
- @Parameters(name="UpsertSelecttIT_allowServerSideMutations={0}")
+ @Parameters(name = "UpsertSelecttIT_allowServerSideMutations={0}")
public static synchronized Object[] data() {
- return new Object[] {"true", "false"};
+ return new Object[]{"true", "false"};
}
-
+
@Test
public void testUpsertSelectWithNoIndex() throws Exception {
testUpsertSelect(false, false);
}
-
+
@Test
public void testUpsertSelectWithIndex() throws Exception {
testUpsertSelect(true, false);
}
-
+
@Test
public void testUpsertSelectWithIndexWithSalt() throws Exception {
testUpsertSelect(true, true);
@@ -140,13 +142,13 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
byte[][] splits = getDefaultSplits(tenantId);
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
String aTable = initATableValues(tenantId, saltTable ? null : splits, null,
null, getUrl(), saltTable ? "salt_buckets = 2" : null);
String customEntityTable = generateUniqueName();
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
String ddl = "create table " + customEntityTable +
" (organization_id char(15) not null, \n" +
" key_prefix char(3) not null,\n" +
@@ -176,16 +178,16 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
" b.val9 varchar\n" +
" CONSTRAINT pk PRIMARY KEY " +
"(organization_id, key_prefix, custom_entity_data_id)) " +
- (saltTable ? "salt_buckets = 2" : "");
+ (saltTable ? "salt_buckets = 2" : "");
stmt.execute(ddl);
}
String indexName = generateUniqueName();
if (createIndex) {
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("CREATE INDEX IF NOT EXISTS " + indexName +
- " ON " + aTable + "(a_string)" );
+ " ON " + aTable + "(a_string)");
}
}
// Trigger multiple batches
@@ -198,7 +200,7 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
"a_string FROM " + aTable + " WHERE ?=a_string";
if (createIndex) { // Confirm index is used
try (PreparedStatement upsertStmt =
- conn.prepareStatement("EXPLAIN " + upsert)) {
+ conn.prepareStatement("EXPLAIN " + upsert)) {
upsertStmt.setString(1, tenantId);
ResultSet ers = upsertStmt.executeQuery();
assertTrue(ers.next());
@@ -218,26 +220,26 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
String query = "SELECT key_prefix, substr(custom_entity_data_id, 1, 1), created_by FROM " +
customEntityTable + " WHERE organization_id = ? ";
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement statement = conn.prepareStatement(query)) {
+ PreparedStatement statement = conn.prepareStatement(query)) {
statement.setString(1, tenantId);
ResultSet rs = statement.executeQuery();
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals("00A", rs.getString(1));
assertEquals("1", rs.getString(2));
assertEquals(A_VALUE, rs.getString(3));
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals("00A", rs.getString(1));
assertEquals("2", rs.getString(2));
assertEquals(A_VALUE, rs.getString(3));
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals("00A", rs.getString(1));
assertEquals("3", rs.getString(2));
assertEquals(A_VALUE, rs.getString(3));
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals("00A", rs.getString(1));
assertEquals("4", rs.getString(2));
assertEquals(A_VALUE, rs.getString(3));
@@ -264,32 +266,32 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
query = "SELECT key_prefix, substr(custom_entity_data_id, 1, 1), created_by, " +
"last_update_by, division FROM " + customEntityTable + " WHERE organization_id = ?";
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement statement = conn.prepareStatement(query)) {
+ PreparedStatement statement = conn.prepareStatement(query)) {
statement.setString(1, tenantId);
ResultSet rs = statement.executeQuery();
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals("00A", rs.getString(1));
assertEquals("1", rs.getString(2));
assertEquals(A_VALUE, rs.getString(3));
assertEquals(A_VALUE, rs.getString(4));
assertTrue(BigDecimal.valueOf(1.0).compareTo(rs.getBigDecimal(5)) == 0);
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals("00A", rs.getString(1));
assertEquals("2", rs.getString(2));
assertEquals(A_VALUE, rs.getString(3));
assertEquals(A_VALUE, rs.getString(4));
assertTrue(BigDecimal.valueOf(1.0).compareTo(rs.getBigDecimal(5)) == 0);
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals("00A", rs.getString(1));
assertEquals("3", rs.getString(2));
assertEquals(A_VALUE, rs.getString(3));
assertEquals(A_VALUE, rs.getString(4));
assertTrue(BigDecimal.valueOf(1.0).compareTo(rs.getBigDecimal(5)) == 0);
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals("00A", rs.getString(1));
assertEquals("4", rs.getString(2));
assertEquals(A_VALUE, rs.getString(3));
@@ -309,7 +311,7 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
ensureTableCreated(getUrl(), ptsdbTable, PTSDB_NAME);
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
String upsert;
ResultSet rs;
int rowsInserted;
@@ -329,32 +331,32 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
String query = "SELECT inst,host,\"DATE\",val FROM " + ptsdbTable;
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement statement = conn.prepareStatement(query)) {
+ PreparedStatement statement = conn.prepareStatement(query)) {
rs = statement.executeQuery();
Date now = new Date(EnvironmentEdgeManager.currentTimeMillis());
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(null, rs.getString(1));
assertEquals(ROW6, rs.getString(2));
- assertTrue(rs.getDate(3).before(now) );
+ assertTrue(rs.getDate(3).before(now));
assertEquals(null, rs.getBigDecimal(4));
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(null, rs.getString(1));
assertEquals(ROW7, rs.getString(2));
- assertTrue(rs.getDate(3).before(now) );
+ assertTrue(rs.getDate(3).before(now));
assertTrue(BigDecimal.valueOf(7).compareTo(rs.getBigDecimal(4)) == 0);
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(null, rs.getString(1));
assertEquals(ROW8, rs.getString(2));
- assertTrue(rs.getDate(3).before(now) );
+ assertTrue(rs.getDate(3).before(now));
assertTrue(BigDecimal.valueOf(6).compareTo(rs.getBigDecimal(4)) == 0);
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(null, rs.getString(1));
assertEquals(ROW9, rs.getString(2));
- assertTrue(rs.getDate(3).before(now) );
+ assertTrue(rs.getDate(3).before(now));
assertTrue(BigDecimal.valueOf(5).compareTo(rs.getBigDecimal(4)) == 0);
assertFalse(rs.next());
@@ -375,27 +377,27 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
query = "SELECT host,inst, \"DATE\",val FROM " + ptsdbTable + " where inst is not null";
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement statement = conn.prepareStatement(query)) {
+ PreparedStatement statement = conn.prepareStatement(query)) {
rs = statement.executeQuery();
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(null, rs.getString(1));
assertEquals(ROW6, rs.getString(2));
assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then));
assertEquals(null, rs.getBigDecimal(4));
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(null, rs.getString(1));
assertEquals(ROW7, rs.getString(2));
assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then));
assertTrue(BigDecimal.valueOf(70).compareTo(rs.getBigDecimal(4)) == 0);
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(null, rs.getString(1));
assertEquals(ROW8, rs.getString(2));
assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then));
assertTrue(BigDecimal.valueOf(60).compareTo(rs.getBigDecimal(4)) == 0);
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(null, rs.getString(1));
assertEquals(ROW9, rs.getString(2));
assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then));
@@ -415,53 +417,53 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
conn.commit();
}
- query = "SELECT * FROM " + ptsdbTable ;
+ query = "SELECT * FROM " + ptsdbTable;
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement statement = conn.prepareStatement(query)) {
+ PreparedStatement statement = conn.prepareStatement(query)) {
rs = statement.executeQuery();
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(null, rs.getString(1));
assertEquals(ROW6, rs.getString(2));
- assertTrue(rs.getDate(3).before(now) );
+ assertTrue(rs.getDate(3).before(now));
assertEquals(null, rs.getBigDecimal(4));
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(null, rs.getString(1));
assertEquals(ROW7, rs.getString(2));
- assertTrue(rs.getDate(3).before(now) );
+ assertTrue(rs.getDate(3).before(now));
assertTrue(BigDecimal.valueOf(7).compareTo(rs.getBigDecimal(4)) == 0);
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(null, rs.getString(1));
assertEquals(ROW8, rs.getString(2));
- assertTrue(rs.getDate(3).before(now) );
+ assertTrue(rs.getDate(3).before(now));
assertTrue(BigDecimal.valueOf(6).compareTo(rs.getBigDecimal(4)) == 0);
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(null, rs.getString(1));
assertEquals(ROW9, rs.getString(2));
- assertTrue(rs.getDate(3).before(now) );
+ assertTrue(rs.getDate(3).before(now));
assertTrue(BigDecimal.valueOf(5).compareTo(rs.getBigDecimal(4)) == 0);
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(ROW6, rs.getString(1));
assertEquals(null, rs.getString(2));
assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then));
assertEquals(null, rs.getBigDecimal(4));
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(ROW7, rs.getString(1));
assertEquals(null, rs.getString(2));
assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then));
assertTrue(BigDecimal.valueOf(70).compareTo(rs.getBigDecimal(4)) == 0);
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(ROW8, rs.getString(1));
assertEquals(null, rs.getString(2));
assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then));
assertTrue(BigDecimal.valueOf(60).compareTo(rs.getBigDecimal(4)) == 0);
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(ROW9, rs.getString(1));
assertEquals(null, rs.getString(2));
assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then));
@@ -475,12 +477,12 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
public void testUpsertSelectForAggAutoCommit() throws Exception {
testUpsertSelectForAgg(true);
}
-
+
@Test
public void testUpsertSelectForAgg() throws Exception {
testUpsertSelectForAgg(false);
}
-
+
private void testUpsertSelectForAgg(boolean autoCommit) throws Exception {
String tenantId = getOrganizationId();
String aTable = initATableValues(tenantId, getDefaultSplits(tenantId));
@@ -488,7 +490,7 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
ensureTableCreated(getUrl(), ptsdbTable, PTSDB_NAME);
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
conn.setAutoCommit(autoCommit);
String upsert = "UPSERT INTO " + ptsdbTable + "(\"DATE\", val, host) " +
@@ -502,29 +504,29 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
conn.commit();
}
}
-
+
String query = "SELECT inst,host,\"DATE\",val FROM " + ptsdbTable;
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement statement = conn.prepareStatement(query)) {
+ PreparedStatement statement = conn.prepareStatement(query)) {
ResultSet rs = statement.executeQuery();
Date now = new Date(EnvironmentEdgeManager.currentTimeMillis());
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(null, rs.getString(1));
assertEquals(A_VALUE, rs.getString(2));
- assertTrue(rs.getDate(3).before(now) );
+ assertTrue(rs.getDate(3).before(now));
assertTrue(BigDecimal.valueOf(10).compareTo(rs.getBigDecimal(4)) == 0);
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(null, rs.getString(1));
assertEquals(B_VALUE, rs.getString(2));
- assertTrue(rs.getDate(3).before(now) );
+ assertTrue(rs.getDate(3).before(now));
assertTrue(BigDecimal.valueOf(26).compareTo(rs.getBigDecimal(4)) == 0);
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals(null, rs.getString(1));
assertEquals(C_VALUE, rs.getString(2));
- assertTrue(rs.getDate(3).before(now) );
+ assertTrue(rs.getDate(3).before(now));
assertTrue(BigDecimal.valueOf(9).compareTo(rs.getBigDecimal(4)) == 0);
assertFalse(rs.next());
}
@@ -544,14 +546,14 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
query = "SELECT inst,host,\"DATE\",val FROM " + ptsdbTable + " WHERE inst='x'";
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement statement = conn.prepareStatement(query)) {
+ PreparedStatement statement = conn.prepareStatement(query)) {
ResultSet rs = statement.executeQuery();
Date now = new Date(EnvironmentEdgeManager.currentTimeMillis());
- assertTrue (rs.next());
+ assertTrue(rs.next());
assertEquals("x", rs.getString(1));
assertEquals(C_VALUE, rs.getString(2));
- assertTrue(rs.getDate(3).before(now) );
+ assertTrue(rs.getDate(3).before(now));
assertTrue(BigDecimal.valueOf(26).compareTo(rs.getBigDecimal(4)) == 0);
assertFalse(rs.next());
}
@@ -559,19 +561,19 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
@Test
public void testUpsertSelectLongToInt() throws Exception {
- byte[][] splits = new byte[][] { PInteger.INSTANCE.toBytes(1),
+ byte[][] splits = new byte[][]{PInteger.INSTANCE.toBytes(1),
PInteger.INSTANCE.toBytes(2), PInteger.INSTANCE.toBytes(3),
PInteger.INSTANCE.toBytes(4)};
String tableName = generateUniqueName();
ensureTableCreated(getUrl(), tableName, "IntKeyTest", splits, null);
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
String upsert = "UPSERT INTO " + tableName + " VALUES(1)";
int rowsInserted;
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement upsertStmt = conn.prepareStatement(upsert)) {
+ PreparedStatement upsertStmt = conn.prepareStatement(upsert)) {
rowsInserted = upsertStmt.executeUpdate();
assertEquals(1, rowsInserted);
conn.commit();
@@ -579,7 +581,7 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
upsert = "UPSERT INTO " + tableName + " select i+1 from " + tableName;
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement upsertStmt = conn.prepareStatement(upsert)) {
+ PreparedStatement upsertStmt = conn.prepareStatement(upsert)) {
rowsInserted = upsertStmt.executeUpdate();
assertEquals(1, rowsInserted);
conn.commit();
@@ -587,19 +589,19 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
String select = "SELECT i FROM " + tableName;
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery(select);
assertTrue(rs.next());
- assertEquals(1,rs.getInt(1));
+ assertEquals(1, rs.getInt(1));
assertTrue(rs.next());
- assertEquals(2,rs.getInt(1));
+ assertEquals(2, rs.getInt(1));
assertFalse(rs.next());
}
}
@Test
public void testUpsertSelectRunOnServer() throws Exception {
- byte[][] splits = new byte[][] { PInteger.INSTANCE.toBytes(1),
+ byte[][] splits = new byte[][]{PInteger.INSTANCE.toBytes(1),
PInteger.INSTANCE.toBytes(2), PInteger.INSTANCE.toBytes(3),
PInteger.INSTANCE.toBytes(4)};
String tableName = generateUniqueName();
@@ -607,13 +609,13 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
" (i integer not null primary key desc, j integer)", splits, null);
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
ResultSet rs;
int rowsInserted;
String upsert = "UPSERT INTO " + tableName + " VALUES(1, 1)";
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement upsertStmt = conn.prepareStatement(upsert)) {
+ PreparedStatement upsertStmt = conn.prepareStatement(upsert)) {
rowsInserted = upsertStmt.executeUpdate();
assertEquals(1, rowsInserted);
conn.commit();
@@ -621,11 +623,11 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
String select = "SELECT i,j+1 FROM " + tableName;
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
rs = stmt.executeQuery(select);
assertTrue(rs.next());
- assertEquals(1,rs.getInt(1));
- assertEquals(2,rs.getInt(2));
+ assertEquals(1, rs.getInt(1));
+ assertEquals(2, rs.getInt(2));
assertFalse(rs.next());
}
@@ -640,10 +642,10 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
select = "SELECT j FROM " + tableName;
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
rs = stmt.executeQuery(select);
assertTrue(rs.next());
- assertEquals(2,rs.getInt(1));
+ assertEquals(2, rs.getInt(1));
assertFalse(rs.next());
}
@@ -658,17 +660,17 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
select = "SELECT j FROM " + tableName;
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
rs = stmt.executeQuery(select);
assertTrue(rs.next());
- assertEquals(1,rs.getInt(1));
+ assertEquals(1, rs.getInt(1));
assertFalse(rs.next());
}
}
@Test
public void testUpsertSelectOnDescToAsc() throws Exception {
- byte[][] splits = new byte[][] { PInteger.INSTANCE.toBytes(1),
+ byte[][] splits = new byte[][]{PInteger.INSTANCE.toBytes(1),
PInteger.INSTANCE.toBytes(2), PInteger.INSTANCE.toBytes(3),
PInteger.INSTANCE.toBytes(4)};
String tableName = generateUniqueName();
@@ -676,13 +678,13 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
" (i integer not null primary key desc, j integer)", splits, null);
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
ResultSet rs;
int rowsInserted;
String upsert = "UPSERT INTO " + tableName + " VALUES(1, 1)";
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement upsertStmt = conn.prepareStatement(upsert)) {
+ PreparedStatement upsertStmt = conn.prepareStatement(upsert)) {
rowsInserted = upsertStmt.executeUpdate();
assertEquals(1, rowsInserted);
conn.commit();
@@ -700,34 +702,34 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
String select = "SELECT i,j FROM " + tableName;
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
rs = stmt.executeQuery(select);
assertTrue(rs.next());
- assertEquals(2,rs.getInt(1));
- assertEquals(2,rs.getInt(2));
+ assertEquals(2, rs.getInt(1));
+ assertEquals(2, rs.getInt(2));
assertTrue(rs.next());
- assertEquals(1,rs.getInt(1));
- assertEquals(1,rs.getInt(2));
+ assertEquals(1, rs.getInt(1));
+ assertEquals(1, rs.getInt(2));
assertFalse(rs.next());
}
}
@Test
public void testUpsertSelectRowKeyMutationOnSplitedTable() throws Exception {
- byte[][] splits = new byte[][] { PInteger.INSTANCE.toBytes(1),
+ byte[][] splits = new byte[][]{PInteger.INSTANCE.toBytes(1),
PInteger.INSTANCE.toBytes(2), PInteger.INSTANCE.toBytes(3),
PInteger.INSTANCE.toBytes(4)};
String tableName = generateUniqueName();
ensureTableCreated(getUrl(), tableName, "IntKeyTest", splits, null, null);
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
int rowsInserted;
ResultSet rs;
String upsert = "UPSERT INTO " + tableName + " VALUES(?)";
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement upsertStmt = conn.prepareStatement(upsert)) {
+ PreparedStatement upsertStmt = conn.prepareStatement(upsert)) {
upsertStmt.setInt(1, 1);
upsertStmt.executeUpdate();
upsertStmt.setInt(1, 3);
@@ -749,33 +751,33 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
String select = "SELECT i FROM " + tableName;
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
rs = stmt.executeQuery(select);
assertTrue(rs.next());
- assertEquals(1,rs.getInt(1));
+ assertEquals(1, rs.getInt(1));
assertTrue(rs.next());
assertTrue(rs.next());
assertTrue(rs.next());
- assertEquals(4,rs.getInt(1));
+ assertEquals(4, rs.getInt(1));
assertFalse(rs.next());
}
}
-
+
@Test
public void testUpsertSelectWithLimit() throws Exception {
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
String tableName = generateUniqueName();
ResultSet rs;
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("create table " + tableName +
" (id varchar(10) not null primary key, val varchar(10), ts timestamp)");
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("upsert into " + tableName +
" values ('aaa', 'abc', current_date())");
stmt.execute("upsert into " + tableName +
@@ -786,29 +788,29 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
rs = stmt.executeQuery("select * from " + tableName);
assertTrue(rs.next());
- assertEquals("aaa",rs.getString(1));
- assertEquals("abc",rs.getString(2));
+ assertEquals("aaa", rs.getString(1));
+ assertEquals("abc", rs.getString(2));
assertNotNull(rs.getDate(3));
assertTrue(rs.next());
- assertEquals("bbb",rs.getString(1));
- assertEquals("bcd",rs.getString(2));
+ assertEquals("bbb", rs.getString(1));
+ assertEquals("bcd", rs.getString(2));
assertNotNull(rs.getDate(3));
assertTrue(rs.next());
- assertEquals("ccc",rs.getString(1));
- assertEquals("cde",rs.getString(2));
+ assertEquals("ccc", rs.getString(1));
+ assertEquals("cde", rs.getString(2));
assertNotNull(rs.getDate(3));
assertFalse(rs.next());
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("upsert into " + tableName +
" (id, ts) select id, CAST(null AS timestamp) from " + tableName +
" where id <= 'bbb' limit 1");
@@ -816,38 +818,38 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
rs = stmt.executeQuery("select * from " + tableName);
assertTrue(rs.next());
- assertEquals("aaa",rs.getString(1));
- assertEquals("abc",rs.getString(2));
+ assertEquals("aaa", rs.getString(1));
+ assertEquals("abc", rs.getString(2));
assertNull(rs.getDate(3));
assertTrue(rs.next());
- assertEquals("bbb",rs.getString(1));
- assertEquals("bcd",rs.getString(2));
+ assertEquals("bbb", rs.getString(1));
+ assertEquals("bcd", rs.getString(2));
assertNotNull(rs.getDate(3));
assertTrue(rs.next());
- assertEquals("ccc",rs.getString(1));
- assertEquals("cde",rs.getString(2));
+ assertEquals("ccc", rs.getString(1));
+ assertEquals("cde", rs.getString(2));
assertNotNull(rs.getDate(3));
assertFalse(rs.next());
}
}
-
+
@Test
public void testUpsertSelectWithSequence() throws Exception {
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
String t1 = generateUniqueName();
String t2 = generateUniqueName();
String seq = generateUniqueName();
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("create table " + t1 +
" (id bigint not null primary key, v varchar)");
stmt.execute("create table " + t2 + " (k varchar primary key)");
@@ -855,7 +857,7 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("upsert into " + t2 + " values ('a')");
stmt.execute("upsert into " + t2 + " values ('b')");
stmt.execute("upsert into " + t2 + " values ('c')");
@@ -863,47 +865,47 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("upsert into " + t1 + " select next value for " +
seq + " , k from " + t2);
conn.commit();
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select * from " + t1);
assertTrue(rs.next());
- assertEquals(1,rs.getLong(1));
- assertEquals("a",rs.getString(2));
+ assertEquals(1, rs.getLong(1));
+ assertEquals("a", rs.getString(2));
assertTrue(rs.next());
- assertEquals(2,rs.getLong(1));
- assertEquals("b",rs.getString(2));
+ assertEquals(2, rs.getLong(1));
+ assertEquals("b", rs.getString(2));
assertTrue(rs.next());
- assertEquals(3,rs.getLong(1));
- assertEquals("c",rs.getString(2));
+ assertEquals(3, rs.getLong(1));
+ assertEquals("c", rs.getString(2));
assertFalse(rs.next());
}
}
-
+
@Test
public void testUpsertSelectWithSequenceAndOrderByWithSalting() throws Exception {
int numOfRecords = 200;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
String t1 = generateUniqueName();
String t2 = generateUniqueName();
- String ddl = "CREATE TABLE IF NOT EXISTS " + t1 + "(ORGANIZATION_ID CHAR(15) NOT NULL, " +
+ String ddl = "CREATE TABLE IF NOT EXISTS " + t1 + "(ORGANIZATION_ID CHAR(15) NOT NULL, " +
"QUERY_ID CHAR(15) NOT NULL, CURSOR_ORDER BIGINT NOT NULL, K1 INTEGER, " +
"V1 INTEGER " + "CONSTRAINT MAIN_PK PRIMARY KEY (ORGANIZATION_ID, QUERY_ID, " +
"CURSOR_ORDER) " + ") SALT_BUCKETS = 4";
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute(ddl);
stmt.execute(
"CREATE TABLE " + t2 + "(ORGANIZATION_ID CHAR(15) NOT NULL, k1 integer " +
@@ -913,7 +915,7 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
for (int i = 0; i < numOfRecords; i++) {
stmt.execute("UPSERT INTO " + t2 +
" values ('00Dxx0000001gEH'," + i + "," + (i + 2) + ")");
@@ -922,7 +924,7 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
conn.setAutoCommit(true);
stmt.execute("UPSERT INTO " + t1 +
" SELECT '00Dxx0000001gEH', 'MyQueryId', NEXT VALUE FOR S, k1, v1 FROM " +
@@ -931,7 +933,7 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select count(*) from " + t1);
assertTrue(rs.next());
@@ -951,14 +953,14 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
stmt.execute("drop sequence s");
}
}
-
+
@Test
public void testUpsertSelectWithRowtimeStampColumn() throws Exception {
String t1 = generateUniqueName();
String t2 = generateUniqueName();
String t3 = generateUniqueName();
try (Connection conn = DriverManager.getConnection(getUrl());
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("CREATE TABLE " + t1 +
" (PK1 VARCHAR NOT NULL, PK2 DATE NOT NULL, KV1 VARCHAR CONSTRAINT PK " +
"PRIMARY KEY(PK1, PK2 DESC ROW_TIMESTAMP " + ")) ");
@@ -969,27 +971,27 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
"PK2 DATE NOT NULL, KV1 VARCHAR CONSTRAINT PK " +
"PRIMARY KEY(PK1, PK2 DESC ROW_TIMESTAMP " + ")) ");
}
-
+
// The timestamp of the put will be the value of the row_timestamp column.
long rowTimestamp = EnvironmentEdgeManager.currentTimeMillis();
Date rowTimestampDate = new Date(rowTimestamp);
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + t1 +
- " (PK1, PK2, KV1) VALUES(?, ?, ?)")) {
+ PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + t1 +
+ " (PK1, PK2, KV1) VALUES(?, ?, ?)")) {
stmt.setString(1, "PK1");
stmt.setDate(2, rowTimestampDate);
stmt.setString(3, "KV1");
stmt.executeUpdate();
conn.commit();
}
-
+
// Upsert select data into table T2. The connection needs to be at a timestamp beyond the
// row timestamp. Otherwise it won't see the data from table T1.
try (Connection conn = DriverManager.getConnection(getUrl());
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.executeUpdate("UPSERT INTO " + t2 + " SELECT * FROM " + t1);
conn.commit();
// Verify the data upserted in T2. Note that we can use the same connection here because
@@ -1007,23 +1009,23 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
}
}
-
+
// Verify that you can't see the data in T2 if the connection is at a timestamp
// lower than the row timestamp.
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(rowTimestamp-1));
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(rowTimestamp - 1));
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("SELECT * FROM " + t2 +
- " WHERE PK1 = ? AND PK2 = ?")) {
+ PreparedStatement stmt = conn.prepareStatement("SELECT * FROM " + t2 +
+ " WHERE PK1 = ? AND PK2 = ?")) {
stmt.setString(1, "PK1");
stmt.setDate(2, rowTimestampDate);
ResultSet rs = stmt.executeQuery();
assertFalse(rs.next());
}
-
+
// Upsert select data into table T3. The connection needs to be at a timestamp beyond the
// row timestamp. Otherwise it won't see the data from table T1.
try (Connection conn = DriverManager.getConnection(getUrl());
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.executeUpdate("UPSERT INTO " + t3 + " SELECT * FROM " + t1);
conn.commit();
// Verify the data upserted in T3. Note that we can use the same connection here
@@ -1040,27 +1042,27 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
assertEquals("KV1", rs.getString("KV1"));
}
}
-
+
// Verify that you can't see the data in T2 if the connection is at next timestamp
// (which is lower than the row timestamp).
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("SELECT * FROM " + t3 +
- " WHERE PK1 = ? AND PK2 = ?")) {
+ PreparedStatement stmt = conn.prepareStatement("SELECT * FROM " + t3 +
+ " WHERE PK1 = ? AND PK2 = ?")) {
stmt.setString(1, "PK1");
stmt.setDate(2, rowTimestampDate);
ResultSet rs = stmt.executeQuery();
assertFalse(rs.next());
}
}
-
+
@Test
public void testUpsertSelectSameTableWithRowTimestampColumn() throws Exception {
String tableName = generateUniqueName();
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("CREATE TABLE " + tableName +
" (PK1 INTEGER NOT NULL, PK2 DATE NOT NULL, KV1 VARCHAR CONSTRAINT PK " +
"PRIMARY KEY(PK1, PK2 ROW_TIMESTAMP)) ");
@@ -1070,8 +1072,8 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
long rowTimestamp = 100;
Date rowTimestampDate = new Date(rowTimestamp);
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName +
- " (PK1, PK2, KV1) VALUES(?, ?, ?)")) {
+ PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName +
+ " (PK1, PK2, KV1) VALUES(?, ?, ?)")) {
stmt.setInt(1, 1);
stmt.setDate(2, rowTimestampDate);
stmt.setString(3, "KV1");
@@ -1080,37 +1082,37 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
}
String seq = generateUniqueName();
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("CREATE SEQUENCE " + seq);
}
// Upsert select data into table. The connection needs to be at a timestamp beyond the
// row timestamp. Otherwise it won't see the data from table.
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.executeUpdate("UPSERT INTO " + tableName +
" SELECT NEXT VALUE FOR " + seq + ", PK2 FROM " + tableName);
conn.commit();
}
-
+
// Upsert select using sequences.
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
conn.setAutoCommit(true);
for (int i = 0; i < 10; i++) {
int count = stmt.executeUpdate("UPSERT INTO " + tableName +
" SELECT NEXT VALUE FOR " + seq + ", PK2 FROM " + tableName);
- assertEquals((int)Math.pow(2, i), count);
+ assertEquals((int) Math.pow(2, i), count);
}
}
}
-
+
@Test
public void testAutomaticallySettingRowtimestamp() throws Exception {
String table1 = generateUniqueName();
String table2 = generateUniqueName();
String table3 = generateUniqueName();
try (Connection conn = DriverManager.getConnection(getUrl());
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("CREATE TABLE " + table1 +
" (T1PK1 VARCHAR NOT NULL, T1PK2 DATE NOT NULL, T1KV1 VARCHAR, T1KV2 VARCHAR " +
"CONSTRAINT PK PRIMARY KEY(T1PK1, T1PK2 DESC ROW_TIMESTAMP)) ");
@@ -1124,10 +1126,10 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
long startTime = EnvironmentEdgeManager.currentTimeMillis();
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table1 +
- " (T1PK1, T1KV1, T1KV2) VALUES (?, ?, ?)")) {
+ PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table1 +
+ " (T1PK1, T1KV1, T1KV2) VALUES (?, ?, ?)")) {
// Upsert values where row_timestamp column PK2 is not set and the column names
// are specified. This should upsert data with the value for PK2 as server timestamp
stmt.setString(1, "PK1");
@@ -1137,10 +1139,10 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
conn.commit();
}
long endTime = EnvironmentEdgeManager.currentTimeMillis();
-
+
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("SELECT T1KV1, T1KV2 FROM " +
- table1 + " WHERE T1PK1 = ? AND T1PK2 >= ? AND T1PK2 <= ?")) {
+ PreparedStatement stmt = conn.prepareStatement("SELECT T1KV1, T1KV2 FROM " +
+ table1 + " WHERE T1PK1 = ? AND T1PK2 >= ? AND T1PK2 <= ?")) {
// Now query for data that was upserted above. If the row key was generated correctly
// then we should be able to see the data in this query.
stmt.setString(1, "PK1");
@@ -1152,21 +1154,21 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
assertEquals("KV2", rs.getString(2));
assertFalse(rs.next());
}
-
+
startTime = EnvironmentEdgeManager.currentTimeMillis();
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table2 +
- " (T2PK1, T2KV1, T2KV2) SELECT T1PK1, T1KV1, T1KV2 FROM " + table1)) {
+ PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table2 +
+ " (T2PK1, T2KV1, T2KV2) SELECT T1PK1, T1KV1, T1KV2 FROM " + table1)) {
// Upsert select into table2 by not selecting the row timestamp column. In this case,
// the rowtimestamp column would end up being set to the server timestamp
stmt.executeUpdate();
conn.commit();
}
endTime = EnvironmentEdgeManager.currentTimeMillis();
-
+
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("SELECT T2KV1, T2KV2 FROM " +
- table2 + " WHERE T2PK1 = ? AND T2PK2 >= ? AND T2PK2 <= ?")) {
+ PreparedStatement stmt = conn.prepareStatement("SELECT T2KV1, T2KV2 FROM " +
+ table2 + " WHERE T2PK1 = ? AND T2PK2 >= ? AND T2PK2 <= ?")) {
// Now query for data that was upserted above. If the row key was generated correctly
// then we should be able to see the data in this query.
stmt.setString(1, "PK1");
@@ -1178,21 +1180,21 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
assertEquals("KV2", rs.getString(2));
assertFalse(rs.next());
}
-
+
startTime = EnvironmentEdgeManager.currentTimeMillis();
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table3 +
- " (T3PK1, T3KV1, T3KV2) SELECT T2PK1, T2KV1, T2KV2 FROM " + table2)) {
+ PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table3 +
+ " (T3PK1, T3KV1, T3KV2) SELECT T2PK1, T2KV1, T2KV2 FROM " + table2)) {
// Upsert select into table3 by not selecting the row timestamp column. In this case,
// the rowtimestamp column would end up being set to the server timestamp
stmt.executeUpdate();
conn.commit();
}
endTime = EnvironmentEdgeManager.currentTimeMillis();
-
+
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("SELECT T3KV1, T3KV2 FROM " +
- table3 + " WHERE T3PK1 = ? AND T3PK2 >= ? AND T3PK2 <= ?")) {
+ PreparedStatement stmt = conn.prepareStatement("SELECT T3KV1, T3KV2 FROM " +
+ table3 + " WHERE T3PK1 = ? AND T3PK2 >= ? AND T3PK2 <= ?")) {
// Now query for data that was upserted above. If the row key was generated correctly
// then we should be able to see the data in this query.
stmt.setString(1, "PK1");
@@ -1205,16 +1207,16 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
assertFalse(rs.next());
}
}
-
+
@Test
public void testUpsertSelectAutoCommitWithRowTimestampColumn() throws Exception {
String tableName1 = generateUniqueName();
String tableName2 = generateUniqueName();
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("CREATE TABLE " + tableName1 +
" (PK1 INTEGER NOT NULL, PK2 DATE NOT NULL, PK3 INTEGER NOT NULL, KV1 VARCHAR" +
" CONSTRAINT PK PRIMARY KEY(PK1, PK2 ROW_TIMESTAMP, PK3)) ");
@@ -1229,8 +1231,8 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
long rowTimestamp1 = 100;
Date rowTimestampDate = new Date(rowTimestamp1);
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " +
- tableName + " (PK1, PK2, PK3, KV1) VALUES(?, ?, ?, ?)")) {
+ PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " +
+ tableName + " (PK1, PK2, PK3, KV1) VALUES(?, ?, ?, ?)")) {
stmt.setInt(1, 1);
stmt.setDate(2, rowTimestampDate);
stmt.setInt(3, 3);
@@ -1241,7 +1243,7 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
long startTime = EnvironmentEdgeManager.currentTimeMillis();
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
conn.setAutoCommit(true);
// Upsert select in the same table with the row_timestamp column PK2 not specified.
// This will end up creating a new row whose timestamp is the server time stamp
@@ -1250,10 +1252,10 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
" (PK1, PK3, KV1) SELECT PK1, PK3, KV1 FROM " + tableName);
}
long endTime = EnvironmentEdgeManager.currentTimeMillis();
-
+
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("SELECT * FROM " + tableName +
- " WHERE PK1 = ? AND PK2 >= ? AND PK2<= ? AND PK3 = ?")) {
+ PreparedStatement stmt = conn.prepareStatement("SELECT * FROM " + tableName +
+ " WHERE PK1 = ? AND PK2 >= ? AND PK2<= ? AND PK3 = ?")) {
// Verify the row that was upserted above
stmt.setInt(1, 1);
stmt.setDate(2, new Date(startTime));
@@ -1274,7 +1276,7 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
conn.setAutoCommit(true);
// Upsert select in the same table with the row_timestamp column PK2 specified.
// This will not end up creating a new row because the destination pk columns,
@@ -1283,7 +1285,7 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
" (PK1, PK2, PK3, KV1) SELECT PK1, PK2, PK3, KV1 FROM " + tableName);
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
// Verify that two rows were created. One with rowtimestamp1 and the other
// with rowtimestamp2
ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM " + tableName);
@@ -1291,7 +1293,7 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
assertEquals(2, rs.getInt(1));
assertFalse(rs.next());
}
-
+
}
}
@@ -1305,9 +1307,9 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("CREATE IMMUTABLE TABLE " + baseTable +
" (TENANT_ID CHAR(15) NOT NULL, PK2 DATE NOT NULL, PK3 INTEGER NOT NULL, " +
"KV1 VARCHAR, KV2 VARCHAR, KV3 VARCHAR CONSTRAINT PK PRIMARY KEY(TENANT_ID, " +
@@ -1317,10 +1319,10 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
stmt.execute("CREATE VIEW " + globalView + " AS SELECT * FROM " +
baseTable + " WHERE KV1 = 'KV1'");
}
-
+
String tenantId = "tenant1";
try (Connection conn = getTenantConnection(tenantId);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("CREATE VIEW " + tenantView + " AS SELECT * FROM " +
baseTable);
stmt.execute("CREATE INDEX " + tenantViewIdx + " ON " +
@@ -1330,8 +1332,8 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
// upsert data into base table without specifying the row timestamp column PK2
long startTime = EnvironmentEdgeManager.currentTimeMillis();
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + baseTable +
- " (TENANT_ID, PK3, KV1, KV2, KV3) VALUES (?, ?, ?, ?, ?)")) {
+ PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + baseTable +
+ " (TENANT_ID, PK3, KV1, KV2, KV3) VALUES (?, ?, ?, ?, ?)")) {
// Upsert select in the same table with the row_timestamp column PK2 not specified.
// This will end up creating a new row whose timestamp is the latest timestamp
// (which will be used for the row key too)
@@ -1398,8 +1400,8 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
// Verify that data can be queried using tenant view and tenant view index
try (Connection tenantConn = getTenantConnection(tenantId);
- PreparedStatement stmt = tenantConn.prepareStatement("SELECT * FROM " +
- tenantView + " WHERE PK2 >= ? AND PK2 <= ? AND PK3 = ?")) {
+ PreparedStatement stmt = tenantConn.prepareStatement("SELECT * FROM " +
+ tenantView + " WHERE PK2 >= ? AND PK2 <= ? AND PK3 = ?")) {
// Query the tenant view
stmt.setDate(1, new Date(startTime));
stmt.setDate(2, new Date(endTime));
@@ -1505,11 +1507,11 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
assertFalse(rs.next());
}
}
-
+
// Verify that the data upserted using the tenant view can now be queried using tenant view
try (Connection tenantConn = getTenantConnection(tenantId);
- PreparedStatement stmt = tenantConn.prepareStatement("SELECT * FROM " +
- tenantView + " WHERE (PK2, PK3) IN ((?, ?), (?, ?)) ORDER BY KV1")) {
+ PreparedStatement stmt = tenantConn.prepareStatement("SELECT * FROM " +
+ tenantView + " WHERE (PK2, PK3) IN ((?, ?), (?, ?)) ORDER BY KV1")) {
// Query the base table
stmt.setDate(1, upsertedDate);
stmt.setInt(2, 33);
@@ -1521,7 +1523,7 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
assertTrue(rs.next());
assertEquals("KV14", rs.getString("KV1"));
assertFalse(rs.next());
-
+
//TODO: uncomment the code after PHOENIX-2277 is fixed
// // Query using the index on the tenantView
// stmt = tenantConn.prepareStatement("SELECT KV1 FROM " + tenantView +
@@ -1540,16 +1542,16 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
// assertFalse(rs.next());
}
}
-
+
@Test
public void testDisallowNegativeValuesForRowTsColumn() throws Exception {
String tableName = generateUniqueName();
String tableName2 = generateUniqueName();
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("CREATE TABLE " + tableName +
" (PK1 BIGINT NOT NULL PRIMARY KEY ROW_TIMESTAMP, KV1 VARCHAR)");
stmt.execute("CREATE TABLE " + tableName2 +
@@ -1557,52 +1559,52 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
}
long upsertedTs = 100;
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName +
- " VALUES (?, ?)")) {
+ PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName +
+ " VALUES (?, ?)")) {
stmt.setLong(1, upsertedTs);
stmt.setString(2, "KV1");
stmt.executeUpdate();
conn.commit();
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName2 +
- " SELECT (PK1 - 500), KV1 FROM " + tableName)) {
+ PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName2 +
+ " SELECT (PK1 - 500), KV1 FROM " + tableName)) {
stmt.executeUpdate();
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.ILLEGAL_DATA.getErrorCode(), e.getErrorCode());
}
}
-
+
@Test
public void testUpsertSelectWithFixedWidthNullByteSizeArray() throws Exception {
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
String t1 = generateUniqueName();
ResultSet rs;
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("create table " + t1 +
" (id bigint not null primary key, ca char(3)[])");
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("upsert into " + t1 + " values (1, ARRAY['aaa', 'bbb'])");
conn.commit();
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("upsert into " + t1 + " (id, ca) select id, " +
"ARRAY['ccc', 'ddd'] from " + t1 + " WHERE id = 1");
conn.commit();
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
rs = stmt.executeQuery("select * from " + t1);
assertTrue(rs.next());
assertEquals(1, rs.getLong(1));
@@ -1612,26 +1614,26 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
String t2 = generateUniqueName();
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("create table " + t2 +
" (id bigint not null primary key, ba binary(4)[])");
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("upsert into " + t2 + " values (2, ARRAY[1, 27])");
conn.commit();
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
stmt.execute("upsert into " + t2 + " (id, ba) select id, " +
"ARRAY[54, 1024] from " + t2 + " WHERE id = 2");
conn.commit();
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
rs = stmt.executeQuery("select * from " + t2);
assertTrue(rs.next());
assertEquals(2, rs.getLong(1));
@@ -1652,28 +1654,28 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
private void testUpsertSelectWithMultiByteChars(boolean autoCommit) throws Exception {
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
String t1 = generateUniqueName();
String validValue = "澴粖蟤य褻酃岤豦팑薰鄩脼ժ끦碉碉碉碉碉碉";
String invalidValue = "澴粖蟤य褻酃岤豦팑薰鄩脼ժ끦碉碉碉碉碉碉碉";
String columnTypeInfo = "VARCHAR(20)";
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
conn.setAutoCommit(autoCommit);
stmt.execute("create table " + t1 +
" (id bigint not null primary key, v varchar(20))");
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
conn.setAutoCommit(autoCommit);
stmt.execute("upsert into " + t1 + " values (1, 'foo')");
conn.commit();
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
conn.setAutoCommit(autoCommit);
stmt.execute("upsert into " + t1 + " (id, v) select id, "
+ "'" + validValue + "' from " + t1 + " WHERE id = 1");
@@ -1681,7 +1683,7 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
conn.setAutoCommit(autoCommit);
ResultSet rs = stmt.executeQuery("select * from " + t1);
@@ -1691,7 +1693,7 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
conn.setAutoCommit(autoCommit);
stmt.execute("upsert into " + t1 + " (id, v) select id, "
+ "'" + invalidValue + "' from " + t1 + " WHERE id = 1");
@@ -1716,7 +1718,7 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
String seq = generateUniqueName();
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
conn.setAutoCommit(false);
stmt.execute("CREATE SEQUENCE " + seq);
@@ -1727,10 +1729,10 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
}
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
for (int i = 0; i < 100; i++) {
stmt.execute("UPSERT INTO " + t1 +
- " VALUES (NEXT VALUE FOR " + seq + ", " + (i%10) + ")");
+ " VALUES (NEXT VALUE FOR " + seq + ", " + (i % 10) + ")");
}
conn.commit();
}
@@ -1740,7 +1742,7 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
try (Statement stmt = conn.createStatement()) {
int upsertCount = stmt.executeUpdate("UPSERT INTO " + t2 +
" SELECT pk, val FROM " + t1);
- assertEquals(100,upsertCount);
+ assertEquals(100, upsertCount);
}
}
}
@@ -1751,9 +1753,9 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
String indexName = generateUniqueName();
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement statement = conn.createStatement()) {
+ Statement statement = conn.createStatement()) {
statement.execute("CREATE IMMUTABLE TABLE " + tableName +
" (k1 TIMESTAMP not null, k2 bigint not null, v bigint, constraint pk " +
"primary key (k1 row_timestamp, k2)) SALT_BUCKETS = 9");
@@ -1823,9 +1825,9 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
String tableName2 = generateUniqueName();
Properties props = new Properties();
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
try (Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement()) {
+ Statement stmt = conn.createStatement()) {
conn.setAutoCommit(true);
stmt.execute("create table " + tableName1 +
"(name varchar(160) primary key, id varchar(120), address varchar(160))");
@@ -1844,13 +1846,13 @@ public class UpsertSelectIT extends ParallelStatsDisabledIT {
assertFalse(rs.next());
}
}
-
+
private Connection getTenantConnection(String tenantId) throws Exception {
Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
props.setProperty(QueryServices.ENABLE_SERVER_SIDE_UPSERT_MUTATIONS,
- allowServerSideMutations);
+ allowServerSideMutations);
props.setProperty(TENANT_ID_ATTRIB, tenantId);
return DriverManager.getConnection(getUrl(), props);
}
-
+
}
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewConcurrencyAndFailureIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewConcurrencyAndFailureIT.java
index f69f217..721f9e5 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewConcurrencyAndFailureIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewConcurrencyAndFailureIT.java
@@ -23,6 +23,7 @@ import static org.apache.phoenix.coprocessor.PhoenixMetaDataCoprocessorHost
import static org.apache.phoenix.exception.SQLExceptionCode.CANNOT_MUTATE_TABLE;
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.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -142,11 +143,13 @@ public class ViewConcurrencyAndFailureIT extends SplitSystemCatalogIT {
}
@After
- public void cleanup() {
+ public void cleanup() throws Exception {
+ boolean refCountLeaked = isAnyStoreRefCountLeaked();
latch1 = null;
latch2 = null;
throwExceptionInChildLinkPreHook = false;
slowDownAddingChildLink = false;
+ assertFalse("refCount leaked", refCountLeaked);
}
@Test
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexCheckerIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexCheckerIT.java
index 985e182..d9cf8a2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexCheckerIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/GlobalIndexCheckerIT.java
@@ -116,9 +116,11 @@ public class GlobalIndexCheckerIT extends BaseUniqueNamesOwnClusterIT {
@After
public void unsetFailForTesting() {
+ boolean refCountLeaked = isAnyStoreRefCountLeaked();
IndexRegionObserver.setFailPreIndexUpdatesForTesting(false);
IndexRegionObserver.setFailDataTableUpdatesForTesting(false);
IndexRegionObserver.setFailPostIndexUpdatesForTesting(false);
+ assertFalse("refCount leaked", refCountLeaked);
}
public static void assertExplainPlan(Connection conn, String selectSql,
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexAsyncThresholdIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexAsyncThresholdIT.java
index 6cd2eaf..0098f98 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexAsyncThresholdIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexAsyncThresholdIT.java
@@ -52,6 +52,7 @@ import java.util.Map;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
@@ -69,12 +70,12 @@ public class IndexAsyncThresholdIT extends BaseTest {
private final boolean overThreshold;
private final Mode mode;
- enum Mode{
+ enum Mode {
NORMAL,
ASYNC,
COVERED,
FUNCTIONAL
- }
+ }
public IndexAsyncThresholdIT(Long threshold, Long rows, Long columns, Long overThreshold,
Long mode)
@@ -90,7 +91,7 @@ public class IndexAsyncThresholdIT extends BaseTest {
}
@Parameterized.Parameters
- public static synchronized Collection<Long[]> primeNumbers() {
+ public static synchronized Collection<Long[]> primeNumbers() {
return Arrays.asList(new Long[][]{
{100000L, 5000L, 10L, 0L, 0L},
{Long.MAX_VALUE, 200L, 100L, 1L, 0L},
@@ -109,11 +110,12 @@ public class IndexAsyncThresholdIT extends BaseTest {
Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
props.put(QueryServices.CLIENT_INDEX_ASYNC_THRESHOLD, Long.toString(threshold));
url = setUpTestCluster(conf, new ReadOnlyProps(props.entrySet().iterator()));
- driver = initAndRegisterTestDriver(url, new ReadOnlyProps(props.entrySet().iterator()));
+ driver = initAndRegisterTestDriver(url, new ReadOnlyProps(props.entrySet().iterator()));
}
@AfterParam
public static synchronized void tearDownMiniCluster() throws Exception {
+ boolean refCountLeaked = isAnyStoreRefCountLeaked();
destroyDriver(driver);
try {
HBaseTestingUtility u = new HBaseTestingUtility();
@@ -123,6 +125,7 @@ public class IndexAsyncThresholdIT extends BaseTest {
} finally {
ConnectionFactory.shutdown();
}
+ assertFalse("refCount leaked", refCountLeaked);
}
@Test
@@ -140,16 +143,14 @@ public class IndexAsyncThresholdIT extends BaseTest {
SQLException exception = null;
try {
String statement = "create index " + indexName + " ON " + this.tableName;
- if (this.mode == Mode.NORMAL || this.mode == Mode.ASYNC){
+ if (this.mode == Mode.NORMAL || this.mode == Mode.ASYNC) {
statement += " (col2, col5, col6, col7, col8)";
- if(this.mode == Mode.ASYNC){
+ if (this.mode == Mode.ASYNC) {
statement += " ASYNC";
}
- }
- else if(this.mode == Mode.COVERED){
+ } else if (this.mode == Mode.COVERED) {
statement += " (col2) INCLUDE(col5, col6, col7, col8)";
- }
- else { // mode == Functional
+ } else { // mode == Functional
statement += " (UPPER(col2 || col4))";
}
@@ -163,10 +164,9 @@ public class IndexAsyncThresholdIT extends BaseTest {
PMetaData metaCache = connection.unwrap(PhoenixConnection.class).getMetaDataCache();
List<PTable> indexes = metaCache.getTableRef(key).getTable().getIndexes();
if (!overThreshold) {
- if(this.mode == Mode.ASYNC){
+ if (this.mode == Mode.ASYNC) {
assertEquals(PIndexState.BUILDING, indexes.get(0).getIndexState());
- }
- else {
+ } else {
assertEquals(PIndexState.ACTIVE, indexes.get(0).getIndexState());
}
assertNull(exception);
@@ -185,7 +185,7 @@ public class IndexAsyncThresholdIT extends BaseTest {
Statement stmt = conn.createStatement();
StringBuilder ddl = new StringBuilder("CREATE TABLE " + fullTableName
+ " (col1 varchar primary key");
- for (int i = 2; i< columns; i++){
+ for (int i = 2; i < columns; i++) {
ddl.append(", col").append(i).append(" varchar");
}
ddl.append(")");
@@ -195,7 +195,7 @@ public class IndexAsyncThresholdIT extends BaseTest {
StringBuilder dml = new StringBuilder("upsert into " + fullTableName + " values (");
for (int j = 1; j < columns; j++) {
dml.append("'col").append(j).append("VAL").append(i).append("'");
- if(j < columns -1){
+ if (j < columns - 1) {
dml.append(", ");
}
}
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 bd3025e..94e82e3 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
@@ -135,6 +135,12 @@ import org.apache.hadoop.hbase.regionserver.RSRpcServices;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
import org.apache.phoenix.SystemExitRule;
+import org.apache.phoenix.compat.hbase.CompatUtil;
+import org.apache.phoenix.end2end.NeedsOwnMiniClusterTest;
+import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
+import org.apache.phoenix.end2end.ParallelStatsDisabledTest;
+import org.apache.phoenix.end2end.ParallelStatsEnabledIT;
+import org.apache.phoenix.end2end.ParallelStatsEnabledTest;
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.exception.SQLExceptionInfo;
import org.apache.phoenix.jdbc.PhoenixConnection;
@@ -176,10 +182,10 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder;
* when one runs mvn verify or mvn install.
*
* For tests needing connectivity to a cluster, please use
- * {@link ParallelStatsDisabledIt} or {@link ParallelStatsEnabledIt}.
+ * {@link ParallelStatsDisabledIT} or {@link ParallelStatsEnabledIT}.
*
* In the case when a test can't share the same mini cluster as the
- * ones used by {@link ParallelStatsDisabledIt} or {@link ParallelStatsEnabledIt},
+ * ones used by {@link ParallelStatsDisabledIT} or {@link ParallelStatsEnabledIT},
* one could extend this class and spin up your own mini cluster. Please
* make sure to annotate such classes with {@link NeedsOwnMiniClusterTest} and
* shutdown the mini cluster in a method annotated by @AfterClass.
@@ -457,8 +463,8 @@ public abstract class BaseTest {
}
}
}
-
- protected static void dropNonSystemTables() throws Exception {
+
+ protected synchronized static void dropNonSystemTables() throws Exception {
try {
disableAndDropNonSystemTables();
} finally {
@@ -779,15 +785,15 @@ public abstract class BaseTest {
if (TABLE_COUNTER.get() > TEARDOWN_THRESHOLD) {
int numTables = TABLE_COUNTER.get();
TABLE_COUNTER.set(0);
- if(isDistributedClusterModeEnabled(config)) {
- LOGGER.info(
- "Deleting old tables on distributed cluster because number of tables is likely greater than "
- + TEARDOWN_THRESHOLD);
+ if (isDistributedClusterModeEnabled(config)) {
+ LOGGER.info("Deleting old tables on distributed cluster because "
+ + "number of tables is likely greater than {}",
+ TEARDOWN_THRESHOLD);
deletePriorMetaData(HConstants.LATEST_TIMESTAMP, url);
} else {
- LOGGER.info(
- "Clearing all HBase tables in minicluster because number of tables on this mini cluster is likely greater than "
- + TEARDOWN_THRESHOLD);
+ LOGGER.info("Shutting down mini cluster because number of tables"
+ + " on this mini cluster is likely greater than {}",
+ TEARDOWN_THRESHOLD);
resetHbase();
}
}
@@ -2032,4 +2038,17 @@ public abstract class BaseTest {
thread.setDaemon(true);
thread.start();
}
+
+ /**
+ * Confirms that no storeFile under any region has refCount leakage
+ *
+ * @return true if any region has refCount leakage
+ */
+ protected synchronized static boolean isAnyStoreRefCountLeaked() {
+ if (getUtility() != null) {
+ return CompatUtil.isAnyStoreRefCountLeaked(getUtility()
+ .getHBaseCluster().getMaster());
+ }
+ return false;
+ }
}
diff --git a/phoenix-hbase-compat-1.3.0/src/main/java/org/apache/phoenix/compat/hbase/CompatUtil.java b/phoenix-hbase-compat-1.3.0/src/main/java/org/apache/phoenix/compat/hbase/CompatUtil.java
index f1b7595..2880b7d 100644
--- a/phoenix-hbase-compat-1.3.0/src/main/java/org/apache/phoenix/compat/hbase/CompatUtil.java
+++ b/phoenix-hbase-compat-1.3.0/src/main/java/org/apache/phoenix/compat/hbase/CompatUtil.java
@@ -18,6 +18,7 @@
package org.apache.phoenix.compat.hbase;
import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.master.HMaster;
public class CompatUtil {
@@ -39,4 +40,15 @@ public class CompatUtil {
public static Scan setSingleRow(Scan scan, byte[] indexRowKey) {
return scan.setStartRow(indexRowKey).setStopRow(indexRowKey);
}
+
+ /**
+ * HBase 1.5+ has storeRefCount available in RegionMetrics
+ *
+ * @param master Active HMaster instance
+ * @return true if any region has refCount leakage
+ */
+ public static boolean isAnyStoreRefCountLeaked(HMaster master) {
+ return false;
+ }
+
}
diff --git a/phoenix-hbase-compat-1.4.0/src/main/java/org/apache/phoenix/compat/hbase/CompatUtil.java b/phoenix-hbase-compat-1.4.0/src/main/java/org/apache/phoenix/compat/hbase/CompatUtil.java
index 1ce3427..765ed7b 100644
--- a/phoenix-hbase-compat-1.4.0/src/main/java/org/apache/phoenix/compat/hbase/CompatUtil.java
+++ b/phoenix-hbase-compat-1.4.0/src/main/java/org/apache/phoenix/compat/hbase/CompatUtil.java
@@ -18,6 +18,7 @@
package org.apache.phoenix.compat.hbase;
import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.metrics.Gauge;
import org.apache.hadoop.hbase.metrics.impl.MetricRegistriesImpl;
@@ -33,4 +34,15 @@ public abstract class CompatUtil {
public static Scan setSingleRow(Scan scan, byte[] indexRowKey) {
return scan.withStartRow(indexRowKey, true).withStopRow(indexRowKey, true);
}
+
+ /**
+ * HBase 1.5+ has storeRefCount available in RegionMetrics
+ *
+ * @param master Active HMaster instance
+ * @return true if any region has refCount leakage
+ */
+ public static boolean isAnyStoreRefCountLeaked(HMaster master) {
+ return false;
+ }
+
}
diff --git a/phoenix-hbase-compat-1.5.0/pom.xml b/phoenix-hbase-compat-1.5.0/pom.xml
index 8864f5b..79e5310 100644
--- a/phoenix-hbase-compat-1.5.0/pom.xml
+++ b/phoenix-hbase-compat-1.5.0/pom.xml
@@ -102,6 +102,12 @@
<version>${hbase15.version}</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/phoenix-hbase-compat-1.5.0/src/main/java/org/apache/phoenix/compat/hbase/CompatUtil.java b/phoenix-hbase-compat-1.5.0/src/main/java/org/apache/phoenix/compat/hbase/CompatUtil.java
index 1ce3427..e0ac22f 100644
--- a/phoenix-hbase-compat-1.5.0/src/main/java/org/apache/phoenix/compat/hbase/CompatUtil.java
+++ b/phoenix-hbase-compat-1.5.0/src/main/java/org/apache/phoenix/compat/hbase/CompatUtil.java
@@ -17,11 +17,20 @@
*/
package org.apache.phoenix.compat.hbase;
+import org.apache.hadoop.hbase.RegionLoad;
+import org.apache.hadoop.hbase.ServerLoad;
import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.metrics.Gauge;
import org.apache.hadoop.hbase.metrics.impl.MetricRegistriesImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public abstract class CompatUtil {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(
+ CompatUtil.class);
+
public static Class[] getMrMetricsClasses() {
return new Class[] { Gauge.class, MetricRegistriesImpl.class };
}
@@ -33,4 +42,44 @@ public abstract class CompatUtil {
public static Scan setSingleRow(Scan scan, byte[] indexRowKey) {
return scan.withStartRow(indexRowKey, true).withStopRow(indexRowKey, true);
}
+
+ /**
+ * HBase 1.5+ has storeRefCount available in RegionMetrics
+ *
+ * @param master Active HMaster instance
+ * @return true if any region has refCount leakage
+ */
+ public synchronized static boolean isAnyStoreRefCountLeaked(HMaster master) {
+ int retries = 5;
+ while (retries > 0) {
+ boolean isStoreRefCountLeaked = isStoreRefCountLeaked(master);
+ if (!isStoreRefCountLeaked) {
+ return false;
+ }
+ retries--;
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ LOGGER.error("Interrupted while sleeping", e);
+ break;
+ }
+ }
+ return true;
+ }
+
+ private static boolean isStoreRefCountLeaked(HMaster master) {
+ for (ServerLoad serverLoad : master.getServerManager().getOnlineServers().values()) {
+ for (RegionLoad regionLoad : serverLoad.getRegionsLoad().values()) {
+ int regionTotalRefCount = regionLoad.getStoreRefCount();
+ if (regionTotalRefCount > 0) {
+ LOGGER.error("Region {} has refCount leak. Total refCount"
+ + " of all storeFiles combined for the region: {}",
+ regionLoad.getNameAsString(), regionTotalRefCount);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
}