PHOENIX-4253 Make doSetup final to prevent errand overrides
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/5d250bb1 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/5d250bb1 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/5d250bb1 Branch: refs/heads/4.x-HBase-1.2 Commit: 5d250bb1e7bce51aca9683dac18279d872acafda Parents: 62f2b6b Author: James Taylor <[email protected]> Authored: Thu Sep 28 21:27:45 2017 -0700 Committer: James Taylor <[email protected]> Committed: Thu Sep 28 21:31:18 2017 -0700 ---------------------------------------------------------------------- .../org/apache/phoenix/end2end/BaseQueryIT.java | 15 ---- .../end2end/ExplainPlanWithStatsDisabledIT.java | 83 ++++++++++-------- .../end2end/ParallelStatsDisabledIT.java | 2 +- .../phoenix/end2end/ParallelStatsEnabledIT.java | 2 +- .../end2end/SequenceBulkAllocationIT.java | 89 +++++++++----------- .../org/apache/phoenix/end2end/SequenceIT.java | 38 +++------ .../apache/phoenix/end2end/UpsertSelectIT.java | 15 ---- .../phoenix/query/QueryServicesOptions.java | 5 ++ .../phoenix/query/QueryServicesTestImpl.java | 2 + 9 files changed, 110 insertions(+), 141 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/5d250bb1/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseQueryIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseQueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseQueryIT.java index 5477e74..15560cd 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseQueryIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseQueryIT.java @@ -26,19 +26,15 @@ import java.sql.DriverManager; import java.sql.SQLException; import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.Properties; import java.util.concurrent.atomic.AtomicInteger; import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.util.Bytes; -import org.apache.phoenix.query.QueryServices; import org.apache.phoenix.schema.PTableImpl; import org.apache.phoenix.util.ByteUtil; import org.apache.phoenix.util.PropertiesUtil; -import org.apache.phoenix.util.ReadOnlyProps; -import org.junit.BeforeClass; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; @@ -46,7 +42,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; @@ -78,16 +73,6 @@ public abstract class BaseQueryIT extends ParallelStatsDisabledIT { + " A_STRING, " + " B_STRING, " + " A_DATE) %s", "" }; - @BeforeClass - @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class) - public static void doSetup() throws Exception { - Map<String,String> props = Maps.newHashMapWithExpectedSize(5); - // Make a small batch size to test multiple calls to reserve sequences - props.put(QueryServices.SEQUENCE_CACHE_SIZE_ATTRIB, Long.toString(BATCH_SIZE)); - // Must update config before starting server - setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator())); - } - protected Date date; private String indexDDL; private String tableDDLOptions; http://git-wip-us.apache.org/repos/asf/phoenix/blob/5d250bb1/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsDisabledIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsDisabledIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsDisabledIT.java index c2d9b52..25e387f 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsDisabledIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsDisabledIT.java @@ -27,12 +27,9 @@ import java.sql.DriverManager; import java.util.List; import org.apache.phoenix.end2end.ExplainPlanWithStatsEnabledIT.Estimate; -import org.apache.phoenix.util.ReadOnlyProps; -import org.junit.BeforeClass; import org.junit.Test; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; /** * This class has tests for asserting the bytes and rows information exposed in the explain plan @@ -40,92 +37,96 @@ import com.google.common.collect.Maps; */ public class ExplainPlanWithStatsDisabledIT extends ParallelStatsDisabledIT { - private static String tableA; - private static String tableB; - - @BeforeClass - public static void doSetup() throws Exception { - setUpTestDriver(new ReadOnlyProps(Maps.<String, String> newHashMap())); - tableA = generateUniqueName(); - initData(tableA); - tableB = generateUniqueName(); - initData(tableB); - } - - private static void initData(String tableName) throws Exception { - try (Connection conn = DriverManager.getConnection(getUrl())) { - conn.createStatement().execute("CREATE TABLE " + tableName - + " ( k INTEGER, c1.a bigint,c2.b bigint CONSTRAINT pk PRIMARY KEY (k)) GUIDE_POSTS_WIDTH = 0"); - conn.createStatement().execute("upsert into " + tableName + " values (100,1,3)"); - conn.createStatement().execute("upsert into " + tableName + " values (101,2,4)"); - conn.createStatement().execute("upsert into " + tableName + " values (102,2,4)"); - conn.createStatement().execute("upsert into " + tableName + " values (103,2,4)"); - conn.createStatement().execute("upsert into " + tableName + " values (104,2,4)"); - conn.createStatement().execute("upsert into " + tableName + " values (105,2,4)"); - conn.createStatement().execute("upsert into " + tableName + " values (106,2,4)"); - conn.createStatement().execute("upsert into " + tableName + " values (107,2,4)"); - conn.createStatement().execute("upsert into " + tableName + " values (108,2,4)"); - conn.createStatement().execute("upsert into " + tableName + " values (109,2,4)"); - conn.commit(); - // Because the guide post width is set to 0, no guide post will be collected - // effectively disabling stats collection. - conn.createStatement().execute("UPDATE STATISTICS " + tableName); - } + private static void initData(Connection conn, String tableName) throws Exception { + conn.createStatement().execute("CREATE TABLE " + tableName + + " ( k INTEGER, c1.a bigint,c2.b bigint CONSTRAINT pk PRIMARY KEY (k)) GUIDE_POSTS_WIDTH = 0"); + conn.createStatement().execute("upsert into " + tableName + " values (100,1,3)"); + conn.createStatement().execute("upsert into " + tableName + " values (101,2,4)"); + conn.createStatement().execute("upsert into " + tableName + " values (102,2,4)"); + conn.createStatement().execute("upsert into " + tableName + " values (103,2,4)"); + conn.createStatement().execute("upsert into " + tableName + " values (104,2,4)"); + conn.createStatement().execute("upsert into " + tableName + " values (105,2,4)"); + conn.createStatement().execute("upsert into " + tableName + " values (106,2,4)"); + conn.createStatement().execute("upsert into " + tableName + " values (107,2,4)"); + conn.createStatement().execute("upsert into " + tableName + " values (108,2,4)"); + conn.createStatement().execute("upsert into " + tableName + " values (109,2,4)"); + conn.commit(); + // Because the guide post width is set to 0, no guide post will be collected + // effectively disabling stats collection. + conn.createStatement().execute("UPDATE STATISTICS " + tableName); } @Test public void testBytesRowsForSelect() throws Exception { + String tableA = generateUniqueName(); String sql = "SELECT * FROM " + tableA + " where k >= ?"; List<Object> binds = Lists.newArrayList(); binds.add(99); try (Connection conn = DriverManager.getConnection(getUrl())) { + initData(conn, tableA); assertEstimatesAreNull(sql, binds, conn); } } @Test public void testBytesRowsForUnion() throws Exception { + String tableA = generateUniqueName(); + String tableB = generateUniqueName(); String sql = "SELECT * FROM " + tableA + " UNION ALL SELECT * FROM " + tableB; try (Connection conn = DriverManager.getConnection(getUrl())) { + initData(conn, tableA); + initData(conn, tableB); assertEstimatesAreNull(sql, Lists.newArrayList(), conn); } } @Test public void testBytesRowsForHashJoin() throws Exception { + String tableA = generateUniqueName(); + String tableB = generateUniqueName(); String sql = "SELECT ta.c1.a, ta.c2.b FROM " + tableA + " ta JOIN " + tableB + " tb ON ta.k = tb.k"; try (Connection conn = DriverManager.getConnection(getUrl())) { + initData(conn, tableA); + initData(conn, tableB); assertEstimatesAreNull(sql, Lists.newArrayList(), conn); } } @Test public void testBytesRowsForSortMergeJoin() throws Exception { + String tableA = generateUniqueName(); + String tableB = generateUniqueName(); String sql = "SELECT /*+ USE_SORT_MERGE_JOIN */ ta.c1.a, ta.c2.b FROM " + tableA + " ta JOIN " + tableB + " tb ON ta.k = tb.k"; try (Connection conn = DriverManager.getConnection(getUrl())) { + initData(conn, tableA); + initData(conn, tableB); assertEstimatesAreNull(sql, Lists.newArrayList(), conn); } } @Test public void testBytesRowsForAggregateQuery() throws Exception { + String tableA = generateUniqueName(); String sql = "SELECT count(*) FROM " + tableA + " where k >= ?"; List<Object> binds = Lists.newArrayList(); binds.add(99); try (Connection conn = DriverManager.getConnection(getUrl())) { + initData(conn, tableA); assertEstimatesAreNull(sql, binds, conn); } } @Test public void testBytesRowsForUpsertSelectServerSide() throws Exception { + String tableA = generateUniqueName(); String sql = "UPSERT INTO " + tableA + " SELECT * FROM " + tableA; List<Object> binds = Lists.newArrayList(); try (Connection conn = DriverManager.getConnection(getUrl())) { + initData(conn, tableA); conn.setAutoCommit(true); assertEstimatesAreNull(sql, binds, conn); } @@ -133,9 +134,11 @@ public class ExplainPlanWithStatsDisabledIT extends ParallelStatsDisabledIT { @Test public void testBytesRowsForUpsertSelectClientSide() throws Exception { + String tableA = generateUniqueName(); String sql = "UPSERT INTO " + tableA + " SELECT * FROM " + tableA; List<Object> binds = Lists.newArrayList(); try (Connection conn = DriverManager.getConnection(getUrl())) { + initData(conn, tableA); conn.setAutoCommit(false); assertEstimatesAreNull(sql, binds, conn); } @@ -143,22 +146,26 @@ public class ExplainPlanWithStatsDisabledIT extends ParallelStatsDisabledIT { @Test public void testBytesRowsForUpsertValues() throws Exception { + String tableA = generateUniqueName(); String sql = "UPSERT INTO " + tableA + " VALUES (?, ?, ?)"; List<Object> binds = Lists.newArrayList(); binds.add(99); binds.add(99); binds.add(99); try (Connection conn = DriverManager.getConnection(getUrl())) { + initData(conn, tableA); assertEstimatesAreZero(sql, binds, conn); } } @Test public void testBytesRowsForDeleteServerSide() throws Exception { + String tableA = generateUniqueName(); String sql = "DELETE FROM " + tableA + " where k >= ?"; List<Object> binds = Lists.newArrayList(); binds.add(99); try (Connection conn = DriverManager.getConnection(getUrl())) { + initData(conn, tableA); conn.setAutoCommit(true); assertEstimatesAreNull(sql, binds, conn); } @@ -166,10 +173,12 @@ public class ExplainPlanWithStatsDisabledIT extends ParallelStatsDisabledIT { @Test public void testBytesRowsForDeleteClientSideExecutedSerially() throws Exception { + String tableA = generateUniqueName(); String sql = "DELETE FROM " + tableA + " where k >= ? LIMIT 2"; List<Object> binds = Lists.newArrayList(); binds.add(99); try (Connection conn = DriverManager.getConnection(getUrl())) { + initData(conn, tableA); conn.setAutoCommit(false); Estimate info = getByteRowEstimates(conn, sql, binds); assertEquals((Long) 200l, info.estimatedBytes); @@ -180,10 +189,12 @@ public class ExplainPlanWithStatsDisabledIT extends ParallelStatsDisabledIT { @Test public void testBytesRowsForPointDelete() throws Exception { + String tableA = generateUniqueName(); String sql = "DELETE FROM " + tableA + " where k = ?"; List<Object> binds = Lists.newArrayList(); binds.add(100); try (Connection conn = DriverManager.getConnection(getUrl())) { + initData(conn, tableA); conn.setAutoCommit(false); assertEstimatesAreZero(sql, binds, conn); } @@ -191,9 +202,11 @@ public class ExplainPlanWithStatsDisabledIT extends ParallelStatsDisabledIT { @Test public void testBytesRowsForSelectExecutedSerially() throws Exception { + String tableA = generateUniqueName(); String sql = "SELECT * FROM " + tableA + " LIMIT 2"; List<Object> binds = Lists.newArrayList(); try (Connection conn = DriverManager.getConnection(getUrl())) { + initData(conn, tableA); conn.setAutoCommit(false); Estimate info = getByteRowEstimates(conn, sql, binds); assertEquals((Long) 200l, info.estimatedBytes); @@ -204,8 +217,10 @@ public class ExplainPlanWithStatsDisabledIT extends ParallelStatsDisabledIT { @Test public void testEstimatesForUnionWithTablesWithNullAndLargeGpWidth() throws Exception { + String tableA = generateUniqueName(); String tableWithLargeGPWidth = generateUniqueName(); try (Connection conn = DriverManager.getConnection(getUrl())) { + initData(conn, tableA); // create a table with 1 MB guidepost width long guidePostWidth = 1000000; conn.createStatement() http://git-wip-us.apache.org/repos/asf/phoenix/blob/5d250bb1/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledIT.java index fb980a3..98939da 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsDisabledIT.java @@ -33,7 +33,7 @@ import org.junit.experimental.categories.Category; public abstract class ParallelStatsDisabledIT extends BaseTest { @BeforeClass - public static void doSetup() throws Exception { + public static final void doSetup() throws Exception { setUpTestDriver(ReadOnlyProps.EMPTY_PROPS); } http://git-wip-us.apache.org/repos/asf/phoenix/blob/5d250bb1/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledIT.java index d6b3924..3413d57 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParallelStatsEnabledIT.java @@ -38,7 +38,7 @@ import com.google.common.collect.Maps; public abstract class ParallelStatsEnabledIT extends BaseTest { @BeforeClass - public static void doSetup() throws Exception { + public static final void doSetup() throws Exception { Map<String, String> props = Maps.newHashMapWithExpectedSize(1); props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Long.toString(20)); props.put(QueryServices.STATS_UPDATE_FREQ_MS_ATTRIB, Long.toString(5)); http://git-wip-us.apache.org/repos/asf/phoenix/blob/5d250bb1/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceBulkAllocationIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceBulkAllocationIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceBulkAllocationIT.java index 2c2df73..e517401 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceBulkAllocationIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceBulkAllocationIT.java @@ -24,7 +24,6 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; -import java.util.Map; import java.util.Properties; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; @@ -34,22 +33,17 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import org.apache.phoenix.exception.SQLExceptionCode; -import org.apache.phoenix.query.QueryServices; -import org.apache.phoenix.util.PhoenixRuntime; import org.apache.phoenix.util.PropertiesUtil; import org.apache.phoenix.util.QueryUtil; -import org.apache.phoenix.util.ReadOnlyProps; import org.apache.phoenix.util.SchemaUtil; import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; /** * Suite of integration tests that validate that Bulk Allocation of Sequence values @@ -62,7 +56,6 @@ import com.google.common.collect.Maps; @RunWith(Parameterized.class) public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { - private static final long BATCH_SIZE = 3; private static final String SELECT_NEXT_VALUE_SQL = "SELECT NEXT VALUE FOR %s"; private static final String SELECT_CURRENT_VALUE_SQL = @@ -73,7 +66,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { "CREATE SEQUENCE %s START WITH %s INCREMENT BY %s MINVALUE %s MAXVALUE %s CACHE %s"; private static final String CREATE_SEQUENCE_WITH_MIN_MAX_AND_CYCLE_TEMPLATE = "CREATE SEQUENCE %s START WITH %s INCREMENT BY %s MINVALUE %s MAXVALUE %s CYCLE CACHE %s"; - + private static final String SCHEMA_NAME = "S"; private Connection conn; private String tenantId; @@ -87,16 +80,12 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { return new Object[] {null, "tenant1"}; } - private static String generateNameWithSchema() { - return SchemaUtil.getTableName(generateUniqueName(), generateUniqueName()); + private static String generateTableNameWithSchema() { + return SchemaUtil.getTableName(SCHEMA_NAME, generateUniqueName()); } - - @BeforeClass - @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class) - public static void doSetup() throws Exception { - Map<String, String> props = Maps.newHashMap(); - props.put(QueryServices.SEQUENCE_CACHE_SIZE_ATTRIB, Long.toString(BATCH_SIZE)); - setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator())); + + private static String generateSequenceNameWithSchema() { + return SchemaUtil.getTableName(SCHEMA_NAME, generateUniqueSequenceName()); } @Before @@ -114,7 +103,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { @Test public void testSequenceParseNextValuesWithNull() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); try { conn.createStatement().executeQuery( "SELECT NEXT NULL VALUES FOR " + sequenceName); @@ -128,7 +117,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { @Test public void testSequenceParseNextValuesWithNonNumber() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); try { conn.createStatement().executeQuery( "SELECT NEXT '89b' VALUES FOR " + sequenceName); @@ -143,7 +132,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { @Test public void testSequenceParseNextValuesWithNegativeNumber() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); try { conn.createStatement().executeQuery( "SELECT NEXT '-1' VALUES FOR " + sequenceName); @@ -157,7 +146,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { @Test public void testParseNextValuesSequenceWithZeroAllocated() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); try { conn.createStatement().executeQuery( "SELECT NEXT 0 VALUES FOR " + sequenceName); @@ -172,7 +161,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { @Test public void testNextValuesForSequenceWithNoAllocatedValues() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(1).startsWith(1).cacheSize(1) .numAllocated(100).build(); @@ -196,7 +185,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { */ public void testNextValuesForSequenceUsingBinds() throws Exception { // Create Sequence - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(1).startsWith(1).cacheSize(1) .numAllocated(100).build(); @@ -217,7 +206,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { @Test public void testNextValuesForSequenceWithPreviouslyAllocatedValues() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(1).startsWith(1).cacheSize(100) .numAllocated(1000).build(); @@ -247,7 +236,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { * the latest batch. */ public void testConnectionCloseReturnsSequenceValuesCorrectly() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(2).startsWith(1).cacheSize(100) .numAllocated(100).build(); @@ -279,8 +268,8 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { * Validates that calling NEXT <n> VALUES FOR <seq> works correctly with UPSERT. */ public void testNextValuesForSequenceWithUpsert() throws Exception { - String sequenceName = generateNameWithSchema(); - String tableName = generateUniqueName(); + String sequenceName = generateSequenceNameWithSchema(); + String tableName = generateTableNameWithSchema(); // Create Sequence final SequenceProperties props = @@ -318,7 +307,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { @Test public void testNextValuesForSequenceWithIncrementBy() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(3).startsWith(1).cacheSize(100) .numAllocated(1000).build(); @@ -341,7 +330,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { @Test public void testNextValuesForSequenceWithNegativeIncrementBy() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(-1).startsWith(2000).cacheSize(100) .numAllocated(1000).build(); @@ -365,7 +354,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { @Test public void testNextValuesForSequenceWithNegativeIncrementByGreaterThanOne() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(-5).startsWith(2000).cacheSize(100) .numAllocated(100).build(); @@ -397,7 +386,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { * have access to all slots requested. */ public void testNextValuesForSequenceExceedsMaxValue() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties sequenceProps = new SequenceProperties.Builder().name(sequenceName).incrementBy(1).startsWith(100).cacheSize(100) .numAllocated(1000).minValue(100).maxValue(900).build(); @@ -434,7 +423,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { * have access to all slots requested. */ public void testNextValuesForSequenceExceedsMinValue() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties sequenceProps = new SequenceProperties.Builder().name(sequenceName).incrementBy(-5).startsWith(900).cacheSize(100) .numAllocated(160).minValue(100).maxValue(900).build(); @@ -470,7 +459,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { * min and max defined. */ public void testNextValuesForSequenceWithMinMaxDefined() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(5).startsWith(100).cacheSize(100) .numAllocated(1000).minValue(100).maxValue(6000).build(); @@ -493,7 +482,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { @Test public void testNextValuesForSequenceWithDefaultMax() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(1).startsWith(100).cacheSize(100) .numAllocated(Long.MAX_VALUE - 100).build(); @@ -524,7 +513,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { * the expression is evaluated. */ public void testNextValuesForSequenceOverflowAllocation() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(1).startsWith(100).cacheSize(100) .numAllocated(Long.MAX_VALUE).build(); @@ -551,7 +540,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { * as expected. */ public void testNextValuesForSequenceAllocationLessThanCacheSize() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(5).startsWith(100).cacheSize(100) .numAllocated(50).minValue(100).maxValue(6000).build(); @@ -583,7 +572,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { * as expected if we don't have enough values in the cache to support the allocation. */ public void testNextValuesForInsufficentCacheValuesAllocationLessThanCacheSize() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(5).startsWith(100).cacheSize(100) .numAllocated(50).minValue(100).maxValue(6000).build(); @@ -618,7 +607,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { * CYCLE flag set to true. */ public void testNextValuesForSequenceWithCycles() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties sequenceProps = new SequenceProperties.Builder().name(sequenceName).incrementBy(5).startsWith(100).cacheSize(100) .numAllocated(1000).minValue(100).maxValue(900).build(); @@ -654,7 +643,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { * CURRENT VALUE FOR expression work correctly when used in the same statement. */ public void testCurrentValueForAndNextValuesForExpressionsForSameSequence() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(1).startsWith(1).cacheSize(100) .numAllocated(1000).build(); @@ -691,7 +680,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { * value for that for all expressions. */ public void testMultipleNextValuesForExpressionsForSameSequence() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(1).startsWith(1).cacheSize(100) .numAllocated(1000).build(); @@ -728,7 +717,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { * NEXT VALUE FOR <seq> is assumed to be 1. */ public void testMultipleDifferentExpressionsForSameSequence() throws Exception { - String sequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(1).startsWith(1).cacheSize(100) .numAllocated(1000).build(); @@ -779,8 +768,8 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { * sync during the sequence management process. */ public void testMultipleNextValuesForExpressionsForDifferentSequences() throws Exception { - String sequenceName = generateNameWithSchema(); - String secondSequenceName = generateNameWithSchema(); + String sequenceName = generateSequenceNameWithSchema(); + String secondSequenceName = generateSequenceNameWithSchema(); conn.createStatement().execute("CREATE SEQUENCE " + sequenceName + " START WITH 30 INCREMENT BY 3 CACHE 100"); conn.createStatement().execute("CREATE SEQUENCE " + secondSequenceName + " START WITH 100 INCREMENT BY 5 CACHE 50"); @@ -811,8 +800,8 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { * allocate any slots. */ public void testExplainPlanValidatesSequences() throws Exception { - String sequenceName = generateNameWithSchema(); - String tableName = generateUniqueName(); + String sequenceName = generateSequenceNameWithSchema(); + String tableName = generateTableNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(3).startsWith(30).cacheSize(100) .numAllocated(1000).build(); @@ -844,8 +833,8 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { @Test public void testExplainPlanForNextValuesFor() throws Exception { - String sequenceName = generateNameWithSchema(); - String tableName = generateUniqueName(); + String sequenceName = generateSequenceNameWithSchema(); + String tableName = generateTableNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(3).startsWith(30).cacheSize(100) .numAllocated(1000).build(); @@ -876,7 +865,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { * 4) Read back value from expression NEXT <n> VALUES FOR <seq> via rs.next() */ public void testNextValuesForMixedWithNextValueForMultiThreaded() throws Exception { - final String sequenceName = generateNameWithSchema(); + final String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(1).startsWith(1).cacheSize(100) .numAllocated(1000).build(); @@ -939,7 +928,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { @Test public void testMultipleNextValuesWithDiffAllocsForMultiThreaded() throws Exception { - final String sequenceName = generateNameWithSchema(); + final String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(1).startsWith(1).cacheSize(100) .numAllocated(1000).build(); @@ -1010,7 +999,7 @@ public class SequenceBulkAllocationIT extends ParallelStatsDisabledIT { @Test public void testMultipleNextValuesWithSameAllocsForMultiThreaded() throws Exception { - final String sequenceName = generateNameWithSchema(); + final String sequenceName = generateSequenceNameWithSchema(); final SequenceProperties props = new SequenceProperties.Builder().name(sequenceName).incrementBy(1).startsWith(1).cacheSize(100) .numAllocated(1000).build(); http://git-wip-us.apache.org/repos/asf/phoenix/blob/5d250bb1/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java ---------------------------------------------------------------------- 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 bcb3a40..3014e45 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 @@ -18,6 +18,7 @@ package org.apache.phoenix.end2end; +import static org.apache.phoenix.query.QueryServicesTestImpl.DEFAULT_SEQUENCE_CACHE_SIZE; import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -31,7 +32,6 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; -import java.util.Map; import java.util.Properties; import org.apache.phoenix.exception.SQLExceptionCode; @@ -45,22 +45,18 @@ import org.apache.phoenix.util.EnvironmentEdgeManager; import org.apache.phoenix.util.PhoenixRuntime; import org.apache.phoenix.util.PropertiesUtil; import org.apache.phoenix.util.QueryUtil; -import org.apache.phoenix.util.ReadOnlyProps; import org.apache.phoenix.util.SchemaUtil; import org.apache.phoenix.util.SequenceUtil; import org.junit.After; import org.junit.Assert; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; public class SequenceIT extends ParallelStatsDisabledIT { private static final String SELECT_NEXT_VALUE_SQL = "SELECT NEXT VALUE FOR %s"; - private static final long BATCH_SIZE = 3; private static final String SCHEMA_NAME = "S"; private Connection conn; @@ -73,14 +69,6 @@ public class SequenceIT extends ParallelStatsDisabledIT { return SchemaUtil.getTableName(SCHEMA_NAME, generateUniqueSequenceName()); } - @BeforeClass - @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class) - public static void doSetup() throws Exception { - Map<String, String> props = Maps.newHashMap(); - props.put(QueryServices.SEQUENCE_CACHE_SIZE_ATTRIB, Long.toString(BATCH_SIZE)); - setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator())); - } - @Before public void init() throws Exception { createConnection(); @@ -468,15 +456,15 @@ public class SequenceIT extends ParallelStatsDisabledIT { 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 < BATCH_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(BATCH_SIZE * 2 + 1, rs.getInt(1)); - assertEquals(BATCH_SIZE * 2 + 1, rs.getInt(2)); + assertEquals(DEFAULT_SEQUENCE_CACHE_SIZE * 2 + 1, rs.getInt(1)); + assertEquals(DEFAULT_SEQUENCE_CACHE_SIZE * 2 + 1, rs.getInt(2)); } @Test @@ -542,7 +530,7 @@ 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 < BATCH_SIZE+ 1; i++) { + for (int i = 0; i < DEFAULT_SEQUENCE_CACHE_SIZE+ 1; i++) { stmt1.execute(); } conn1.commit(); @@ -551,7 +539,7 @@ public class SequenceIT extends ParallelStatsDisabledIT { PreparedStatement stmt2 = conn2.prepareStatement("UPSERT INTO " + tableName + " VALUES(NEXT VALUE FOR " + sequenceName + ")"); stmt2.execute(); stmt1.close(); // Should still continue with next value, even on separate connection - for (int i = 0; i < BATCH_SIZE; i++) { + for (int i = 0; i < DEFAULT_SEQUENCE_CACHE_SIZE; i++) { stmt2.execute(); } conn2.commit(); @@ -559,7 +547,7 @@ public class SequenceIT extends ParallelStatsDisabledIT { // 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 < (BATCH_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)); } @@ -574,7 +562,7 @@ public class SequenceIT extends ParallelStatsDisabledIT { 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 < BATCH_SIZE+ 1; i++) { + for (int i = 0; i < DEFAULT_SEQUENCE_CACHE_SIZE+ 1; i++) { stmt1.execute(); } conn.commit(); @@ -582,14 +570,14 @@ public class SequenceIT extends ParallelStatsDisabledIT { 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 < BATCH_SIZE + 1; i++) { + 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*(BATCH_SIZE + 1); i++) { + for (int i = 0; i < 2*(DEFAULT_SEQUENCE_CACHE_SIZE + 1); i++) { assertTrue(rs.next()); assertEquals(i+1, rs.getInt(1)); } @@ -605,21 +593,21 @@ public class SequenceIT extends ParallelStatsDisabledIT { 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 < BATCH_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));; PreparedStatement stmt2 = conn2.prepareStatement("UPSERT INTO " + tableName + " VALUES(NEXT VALUE FOR " + sequenceName + " )"); - for (int i = 0; i < BATCH_SIZE + 1; i++) { + 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*(BATCH_SIZE + 1); i++) { + for (int i = 0; i < 2*(DEFAULT_SEQUENCE_CACHE_SIZE + 1); i++) { assertTrue(rs.next()); assertEquals(i+1, rs.getInt(1)); } http://git-wip-us.apache.org/repos/asf/phoenix/blob/5d250bb1/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java ---------------------------------------------------------------------- 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 b94e635..6bf6be5 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 @@ -42,8 +42,6 @@ import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; import java.util.Properties; import org.apache.phoenix.compile.QueryPlan; @@ -56,24 +54,11 @@ import org.apache.phoenix.util.EnvironmentEdgeManager; import org.apache.phoenix.util.PhoenixRuntime; import org.apache.phoenix.util.PropertiesUtil; import org.apache.phoenix.util.QueryUtil; -import org.apache.phoenix.util.ReadOnlyProps; import org.apache.phoenix.util.TestUtil; -import org.junit.BeforeClass; import org.junit.Test; public class UpsertSelectIT extends ParallelStatsDisabledIT { - @BeforeClass - @Shadower(classBeingShadowed = ParallelStatsDisabledIT.class) - public static void doSetup() throws Exception { - Map<String,String> props = new HashMap<>(); - props.put(QueryServices.QUEUE_SIZE_ATTRIB, Integer.toString(500)); - props.put(QueryServices.THREAD_POOL_SIZE_ATTRIB, Integer.toString(64)); - - // Must update config before starting server - setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator())); - } - @Test public void testUpsertSelectWithNoIndex() throws Exception { testUpsertSelect(false, false); http://git-wip-us.apache.org/repos/asf/phoenix/blob/5d250bb1/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java index 3f70b0a..af6a054 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/QueryServicesOptions.java @@ -789,4 +789,9 @@ public class QueryServicesOptions { return this; } + + public QueryServicesOptions setSequenceCacheSize(long sequenceCacheSize) { + config.setLong(SEQUENCE_CACHE_SIZE_ATTRIB, sequenceCacheSize); + return this; + } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/5d250bb1/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java b/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java index 3c73495..c93e56e 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/query/QueryServicesTestImpl.java @@ -62,6 +62,7 @@ public final class QueryServicesTestImpl extends BaseQueryServicesImpl { public static final int DEFAULT_HCONNECTION_POOL_MAX_SIZE = 10; public static final int DEFAULT_HTABLE_MAX_THREADS = 10; public static final long DEFAULT_INDEX_POPULATION_WAIT_TIME = 0; + public static final long DEFAULT_SEQUENCE_CACHE_SIZE = 3; public static final boolean DEFAULT_TRANSACTIONS_ENABLED = true; /* * Effectively disable running the index rebuild task by having an infinite delay @@ -84,6 +85,7 @@ public final class QueryServicesTestImpl extends BaseQueryServicesImpl { private static QueryServicesOptions getDefaultServicesOptions() { return withDefaults() + .setSequenceCacheSize(DEFAULT_SEQUENCE_CACHE_SIZE) .setTransactionsEnabled(DEFAULT_TRANSACTIONS_ENABLED) .setExplainChunkCount(DEFAULT_EXPLAIN_CHUNK_COUNT) .setExplainRowCount(DEFAULT_EXPLAIN_ROW_COUNT)
