Repository: drill Updated Branches: refs/heads/master 3036d3700 -> 42fc11e53
http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/TestSortSpillWithException.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/TestSortSpillWithException.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/TestSortSpillWithException.java index f6b3a8d..2694f64 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/TestSortSpillWithException.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/TestSortSpillWithException.java @@ -32,7 +32,7 @@ import org.apache.drill.exec.testing.Controls; import org.apache.drill.exec.testing.ControlsInjectionUtil; import org.apache.drill.test.ClusterFixture; import org.apache.drill.test.ClusterTest; -import org.apache.drill.test.FixtureBuilder; +import org.apache.drill.test.ClusterFixtureBuilder; import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -51,7 +51,7 @@ public class TestSortSpillWithException extends ClusterTest { @BeforeClass public static void setup() throws Exception { - FixtureBuilder builder = ClusterFixture.builder() + ClusterFixtureBuilder builder = ClusterFixture.builder() .configProperty(ExecConstants.EXTERNAL_SORT_SPILL_THRESHOLD, 1) // Unmanaged .configProperty(ExecConstants.EXTERNAL_SORT_SPILL_GROUP_SIZE, 1) // Unmanaged .sessionOption(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY, 60 * 1024 * 1024) // Spill early http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/managed/SortTestUtilities.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/managed/SortTestUtilities.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/managed/SortTestUtilities.java index f525b2a..4c90769 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/managed/SortTestUtilities.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/managed/SortTestUtilities.java @@ -62,6 +62,7 @@ public class SortTestUtilities { return makeSchema(MinorType.INT, true); } + @SuppressWarnings("resource") public static PriorityQueueCopierWrapper makeCopier(OperatorFixture fixture, String sortOrder, String nullOrder) { FieldReference expr = FieldReference.getWithQuotedRef("key"); Ordering ordering = new Ordering(sortOrder, expr, nullOrder); http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/managed/TestShortArrays.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/managed/TestShortArrays.java b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/managed/TestShortArrays.java index 1c9d49e..ba5dfce 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/managed/TestShortArrays.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/managed/TestShortArrays.java @@ -83,7 +83,7 @@ public class TestShortArrays extends SubOperatorTest { assertEquals(bHint.elementCount, bCol.estElementCountPerArray, 0.001); // Create a new batch, and new vector, using the sizer and - // intializer inferred from the previoius batch. + // initializer inferred from the previous batch. SingleRowSet empty = fixture.rowSet(schema); vi.allocateBatch(empty.container(), 100); http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestDrillbitResilience.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestDrillbitResilience.java b/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestDrillbitResilience.java index bde6764..1548d7d 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestDrillbitResilience.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/server/TestDrillbitResilience.java @@ -34,8 +34,8 @@ import org.apache.commons.math3.util.Pair; import org.apache.drill.BaseTestQuery; import org.apache.drill.QueryTestUtil; import org.apache.drill.SingleRowListener; -import org.apache.drill.common.concurrent.ExtendedLatch; import org.apache.drill.common.DrillAutoCloseables; +import org.apache.drill.common.concurrent.ExtendedLatch; import org.apache.drill.common.config.DrillConfig; import org.apache.drill.common.exceptions.UserException; import org.apache.drill.common.types.TypeProtos.MinorType; @@ -58,6 +58,7 @@ import org.apache.drill.exec.physical.impl.xsort.ExternalSortBatch; import org.apache.drill.exec.planner.sql.DrillSqlWorker; import org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint; import org.apache.drill.exec.proto.GeneralRPCProtos.Ack; +import org.apache.drill.exec.proto.UserBitShared; import org.apache.drill.exec.proto.UserBitShared.DrillPBError; import org.apache.drill.exec.proto.UserBitShared.ExceptionWrapper; import org.apache.drill.exec.proto.UserBitShared.QueryData; @@ -74,15 +75,14 @@ import org.apache.drill.exec.rpc.RpcException; import org.apache.drill.exec.rpc.user.QueryDataBatch; import org.apache.drill.exec.rpc.user.UserResultsListener; import org.apache.drill.exec.store.pojo.PojoRecordReader; -import org.apache.drill.exec.testing.ControlsInjectionUtil; import org.apache.drill.exec.testing.Controls; +import org.apache.drill.exec.testing.ControlsInjectionUtil; import org.apache.drill.exec.util.Pointer; import org.apache.drill.exec.work.foreman.Foreman; import org.apache.drill.exec.work.foreman.ForemanException; import org.apache.drill.exec.work.foreman.ForemanSetupException; import org.apache.drill.exec.work.fragment.FragmentExecutor; import org.apache.drill.test.DrillTest; -import org.apache.drill.test.OperatorFixture; import org.apache.drill.categories.SlowTest; import org.junit.After; import org.junit.AfterClass; @@ -138,7 +138,6 @@ public class TestDrillbitResilience extends DrillTest { * @param name name of the drillbit */ private static void stopDrillbit(final String name) { - @SuppressWarnings("resource") final Drillbit drillbit = drillbits.get(name); if (drillbit == null) { throw new IllegalStateException("No Drillbit named \"" + name + "\" found"); @@ -321,6 +320,19 @@ public class TestDrillbitResilience extends DrillTest { ControlsInjectionUtil.setSessionOption(drillClient, option, value); } + private static void resetSessionOption(final String option) { + try { + final List<QueryDataBatch> results = drillClient.runQuery( + UserBitShared.QueryType.SQL, String.format("ALTER session RESET `%s`", + option)); + for (final QueryDataBatch data : results) { + data.release(); + } + } catch (final RpcException e) { + fail("Could not reset option: " + e.toString()); + } + } + /** * Check that the injected exception is what we were expecting. * @@ -812,9 +824,8 @@ public class TestDrillbitResilience extends DrillTest { final String query = "SELECT sales_city, COUNT(*) cnt FROM cp.`region.json` GROUP BY sales_city"; assertCancelledWithoutException(control, new ListenerThatCancelsQueryAfterFirstBatchOfData(), query); } finally { - final OperatorFixture.TestOptionSet testOptionSet = new OperatorFixture.TestOptionSet(); - setSessionOption(SLICE_TARGET, Long.toString(SLICE_TARGET_DEFAULT)); - setSessionOption(HASHAGG.getOptionName(), testOptionSet.getDefault(HASHAGG.getOptionName()).bool_val.toString()); + resetSessionOption(SLICE_TARGET); + resetSessionOption(HASHAGG.getOptionName()); } } @@ -844,11 +855,9 @@ public class TestDrillbitResilience extends DrillTest { final long after = countAllocatedMemory(); assertEquals(String.format("We are leaking %d bytes", after - before), before, after); } finally { - final OperatorFixture.TestOptionSet testOptionSet = new OperatorFixture.TestOptionSet(); - setSessionOption(SLICE_TARGET, Long.toString(SLICE_TARGET_DEFAULT)); - setSessionOption(HASHAGG.getOptionName(), testOptionSet.getDefault(HASHAGG.getOptionName()).bool_val.toString()); - setSessionOption(PARTITION_SENDER_SET_THREADS.getOptionName(), - Long.toString(testOptionSet.getDefault(PARTITION_SENDER_SET_THREADS.getOptionName()).num_val)); + resetSessionOption(SLICE_TARGET); + resetSessionOption(HASHAGG.getOptionName()); + resetSessionOption(PARTITION_SENDER_SET_THREADS.getOptionName()); } } http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/StatusResourcesTest.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/StatusResourcesTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/StatusResourcesTest.java index bf7578f..4f4390f 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/StatusResourcesTest.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/StatusResourcesTest.java @@ -23,7 +23,7 @@ import org.apache.drill.exec.server.options.OptionDefinition; import org.apache.drill.exec.server.options.OptionValidator; import org.apache.drill.test.ClientFixture; import org.apache.drill.test.ClusterFixture; -import org.apache.drill.test.FixtureBuilder; +import org.apache.drill.test.ClusterFixtureBuilder; import org.apache.drill.test.RestClientFixture; import org.junit.Assert; import org.junit.Test; @@ -36,7 +36,7 @@ public class StatusResourcesTest { public void testRetrieveInternalOption() throws Exception { OptionDefinition optionDefinition = createMockPropOptionDefinition(); - FixtureBuilder builder = ClusterFixture.builder(). + ClusterFixtureBuilder builder = ClusterFixture.builder(). configProperty(ExecConstants.HTTP_ENABLE, true). configProperty(ExecConstants.bootDefaultFor(MOCK_PROPERTY), "a"). configProperty(ExecConstants.HTTP_PORT_HUNT, true). @@ -60,7 +60,7 @@ public class StatusResourcesTest { @Test public void testRetrievePublicOption() throws Exception { - FixtureBuilder builder = ClusterFixture.builder(). + ClusterFixtureBuilder builder = ClusterFixture.builder(). configProperty(ExecConstants.HTTP_ENABLE, true). configProperty(ExecConstants.HTTP_PORT_HUNT, true). configProperty(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE, false). http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/ParquetInternalsTest.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/ParquetInternalsTest.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/ParquetInternalsTest.java index 60e466d..0f7c213 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/ParquetInternalsTest.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/ParquetInternalsTest.java @@ -23,7 +23,7 @@ import org.apache.drill.common.types.TypeProtos; import org.apache.drill.common.types.Types; import org.apache.drill.test.ClusterFixture; import org.apache.drill.test.ClusterTest; -import org.apache.drill.test.FixtureBuilder; +import org.apache.drill.test.ClusterFixtureBuilder; import org.junit.BeforeClass; import org.junit.Test; @@ -34,7 +34,7 @@ public class ParquetInternalsTest extends ClusterTest { @BeforeClass public static void setup( ) throws Exception { - FixtureBuilder builder = ClusterFixture.builder() + ClusterFixtureBuilder builder = ClusterFixture.builder() // Set options, etc. ; startCluster(builder); http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetFilterPushDown.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetFilterPushDown.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetFilterPushDown.java index 8f56c45..cb5000f 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetFilterPushDown.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/parquet/TestParquetFilterPushDown.java @@ -292,9 +292,7 @@ public class TestParquetFilterPushDown extends PlanTestBase { testParquetFilterPD(query1, 9, 3, false); } finally { - final OperatorFixture.TestOptionSet testOptionSet = new OperatorFixture.TestOptionSet(); - test("alter session set `" + PlannerSettings.PARQUET_ROWGROUP_FILTER_PUSHDOWN_PLANNING_KEY + "` = " + - testOptionSet.getDefault(PlannerSettings.PARQUET_ROWGROUP_FILTER_PUSHDOWN_PLANNING_KEY).bool_val); + resetSessionOption(PlannerSettings.PARQUET_ROWGROUP_FILTER_PUSHDOWN_PLANNING_KEY); deleteTableIfExists(tableName); } } @@ -317,9 +315,7 @@ public class TestParquetFilterPushDown extends PlanTestBase { testParquetFilterPD(query1, 9, 3, false); } finally { - final OperatorFixture.TestOptionSet testOptionSet = new OperatorFixture.TestOptionSet(); - test("alter session set `" + PlannerSettings.PARQUET_ROWGROUP_FILTER_PUSHDOWN_PLANNING_THRESHOLD_KEY + "` = " + - testOptionSet.getDefault(PlannerSettings.PARQUET_ROWGROUP_FILTER_PUSHDOWN_PLANNING_THRESHOLD_KEY).num_val); + resetSessionOption(PlannerSettings.PARQUET_ROWGROUP_FILTER_PUSHDOWN_PLANNING_THRESHOLD_KEY); deleteTableIfExists(tableName); } } http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/exec/store/sys/TestPStoreProviders.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/sys/TestPStoreProviders.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/sys/TestPStoreProviders.java index 79a0f45..e7b150c 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/sys/TestPStoreProviders.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/sys/TestPStoreProviders.java @@ -34,7 +34,7 @@ import org.apache.drill.exec.store.sys.store.provider.LocalPersistentStoreProvid import org.apache.drill.exec.store.sys.store.provider.ZookeeperPersistentStoreProvider; import org.apache.drill.test.ClientFixture; import org.apache.drill.test.ClusterFixture; -import org.apache.drill.test.FixtureBuilder; +import org.apache.drill.test.ClusterFixtureBuilder; import org.apache.drill.testutils.DirTestWatcher; import org.apache.zookeeper.CreateMode; import org.junit.Assert; @@ -85,7 +85,7 @@ public class TestPStoreProviders extends TestWithZookeeper { org.apache.commons.io.FileUtils.copyDirectory(localOptionsResources, optionsDir); - FixtureBuilder builder = ClusterFixture.builder(). + ClusterFixtureBuilder builder = ClusterFixture.builder(). configProperty(ExecConstants.HTTP_ENABLE, false). configProperty(ExecConstants.SYS_STORE_PROVIDER_CLASS, LocalPersistentStoreProvider.class.getCanonicalName()). configProperty(ExecConstants.SYS_STORE_PROVIDER_LOCAL_PATH, String.format("file://%s", dirTestWatcher.getDirPath())). http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/exec/util/TestQueryMemoryAlloc.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/util/TestQueryMemoryAlloc.java b/exec/java-exec/src/test/java/org/apache/drill/exec/util/TestQueryMemoryAlloc.java index 2476da7..7a62ef3 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/util/TestQueryMemoryAlloc.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/util/TestQueryMemoryAlloc.java @@ -33,8 +33,8 @@ public class TestQueryMemoryAlloc extends DrillTest { @Test public void testDefaultOptions() throws Exception { OperatorFixtureBuilder builder = OperatorFixture.builder(); - builder.options().set(ExecConstants.PERCENT_MEMORY_PER_QUERY_KEY, 0.05); - builder.options().set(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY, 2 * ONE_GB); + builder.systemOption(ExecConstants.PERCENT_MEMORY_PER_QUERY_KEY, 0.05); + builder.systemOption(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY, 2 * ONE_GB); try (OperatorFixture fixture = builder.build()) { @@ -58,8 +58,8 @@ public class TestQueryMemoryAlloc extends DrillTest { @Test public void testCustomFloor() throws Exception { OperatorFixtureBuilder builder = OperatorFixture.builder(); - builder.options().set(ExecConstants.PERCENT_MEMORY_PER_QUERY_KEY, 0.05); - builder.options().set(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY, 3 * ONE_GB); + builder.systemOption(ExecConstants.PERCENT_MEMORY_PER_QUERY_KEY, 0.05); + builder.systemOption(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY, 3 * ONE_GB); try (OperatorFixture fixture = builder.build()) { @@ -83,8 +83,8 @@ public class TestQueryMemoryAlloc extends DrillTest { @Test public void testCustomPercent() throws Exception { OperatorFixtureBuilder builder = OperatorFixture.builder(); - builder.options().set(ExecConstants.PERCENT_MEMORY_PER_QUERY_KEY, 0.10); - builder.options().set(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY, 2 * ONE_GB); + builder.systemOption(ExecConstants.PERCENT_MEMORY_PER_QUERY_KEY, 0.10); + builder.systemOption(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY, 2 * ONE_GB); try (OperatorFixture fixture = builder.build()) { @@ -117,9 +117,9 @@ public class TestQueryMemoryAlloc extends DrillTest { @Test public void testOpMemory() throws Exception { OperatorFixtureBuilder builder = OperatorFixture.builder(); - builder.options().set(ExecConstants.CPU_LOAD_AVERAGE_KEY, 0.7); - builder.options().set(ExecConstants.MAX_WIDTH_PER_NODE_KEY, 10); - builder.options().set(ExecConstants.MIN_MEMORY_PER_BUFFERED_OP_KEY, 40 * ONE_MB); + builder.systemOption(ExecConstants.CPU_LOAD_AVERAGE_KEY, 0.7); + builder.systemOption(ExecConstants.MAX_WIDTH_PER_NODE_KEY, 10); + builder.systemOption(ExecConstants.MIN_MEMORY_PER_BUFFERED_OP_KEY, 40 * ONE_MB); try (OperatorFixture fixture = builder.build()) { http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestExtendedTypes.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestExtendedTypes.java b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestExtendedTypes.java index 0710818..58793a2 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestExtendedTypes.java +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/vector/complex/writer/TestExtendedTypes.java @@ -61,13 +61,8 @@ public class TestExtendedTypes extends BaseTestQuery { + "/0_0_0.json")); assertEquals(new String(originalData), new String(newData)); } finally { - final OperatorFixture.TestOptionSet testOptionSet = new OperatorFixture.TestOptionSet(); - testNoResult(String.format("ALTER SESSION SET `%s` = '%s'", - ExecConstants.OUTPUT_FORMAT_VALIDATOR.getOptionName(), - testOptionSet.getDefault(ExecConstants.OUTPUT_FORMAT_VALIDATOR.getOptionName()).getValue())); - testNoResult(String.format("ALTER SESSION SET `%s` = %s", - ExecConstants.JSON_EXTENDED_TYPES.getOptionName(), - testOptionSet.getDefault(ExecConstants.JSON_EXTENDED_TYPES.getOptionName()).getValue())); + resetSessionOption(ExecConstants.OUTPUT_FORMAT_VALIDATOR.getOptionName()); + resetSessionOption(ExecConstants.JSON_EXTENDED_TYPES.getOptionName()); } } @@ -92,13 +87,8 @@ public class TestExtendedTypes extends BaseTestQuery { String expected = "drill_timestamp_millies,bin,bin1\n2015-07-07T03:59:43.488,drill,drill\n"; Assert.assertEquals(expected, actual); } finally { - final OperatorFixture.TestOptionSet testOptionSet = new OperatorFixture.TestOptionSet(); - testNoResult(String.format("ALTER SESSION SET `%s` = '%s'", - ExecConstants.OUTPUT_FORMAT_VALIDATOR.getOptionName(), - testOptionSet.getDefault(ExecConstants.OUTPUT_FORMAT_VALIDATOR.getOptionName()).getValue())); - testNoResult(String.format("ALTER SESSION SET `%s` = %s", - ExecConstants.JSON_EXTENDED_TYPES.getOptionName(), - testOptionSet.getDefault(ExecConstants.JSON_EXTENDED_TYPES.getOptionName()).getValue())); + resetSessionOption(ExecConstants.OUTPUT_FORMAT_VALIDATOR.getOptionName()); + resetSessionOption(ExecConstants.JSON_EXTENDED_TYPES.getOptionName()); } } } http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/test/ClientFixture.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/ClientFixture.java b/exec/java-exec/src/test/java/org/apache/drill/test/ClientFixture.java index 8ad0fbb..a80d4f6 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/test/ClientFixture.java +++ b/exec/java-exec/src/test/java/org/apache/drill/test/ClientFixture.java @@ -132,14 +132,12 @@ public class ClientFixture implements AutoCloseable { * @param key */ - public void resetSystem(String key) { - String sql = "ALTER SYSTEM RESET `" + key + "`"; - runSqlSilently(sql); + public void resetSession(String key) { + runSqlSilently("ALTER SESSION RESET `" + key + "`"); } - public void resetSession(String key) { - String sql = "ALTER SESSION RESET `" + key + "`"; - runSqlSilently(sql); + public void resetSystem(String key) { + runSqlSilently("ALTER SYSTEM RESET `" + key + "`"); } /** http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java b/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java index 5d53b59..f36c193 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java +++ b/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java @@ -147,7 +147,7 @@ public class ClusterFixture extends BaseFixture implements AutoCloseable { private List<File> tempDirs = new ArrayList<>(); - ClusterFixture(FixtureBuilder builder) { + ClusterFixture(ClusterFixtureBuilder builder) { setClientProps(builder); configureZk(builder); @@ -166,9 +166,9 @@ public class ClusterFixture extends BaseFixture implements AutoCloseable { /** * Set the client properties to be used by client fixture. - * @param builder {@link FixtureBuilder#clientProps} + * @param builder {@link ClusterFixtureBuilder#clientProps} */ - private void setClientProps(FixtureBuilder builder) { + private void setClientProps(ClusterFixtureBuilder builder) { clientProps = builder.clientProps; } @@ -176,7 +176,7 @@ public class ClusterFixture extends BaseFixture implements AutoCloseable { return clientProps; } - private void configureZk(FixtureBuilder builder) { + private void configureZk(ClusterFixtureBuilder builder) { // Start ZK if requested. @@ -213,7 +213,7 @@ public class ClusterFixture extends BaseFixture implements AutoCloseable { } } - private void createConfig(FixtureBuilder builder) throws Exception { + private void createConfig(ClusterFixtureBuilder builder) throws Exception { // Create a config // Because of the way DrillConfig works, we can set the ZK @@ -235,7 +235,7 @@ public class ClusterFixture extends BaseFixture implements AutoCloseable { } } - private void startDrillbits(FixtureBuilder builder) throws Exception { + private void startDrillbits(ClusterFixtureBuilder builder) throws Exception { // // Ensure that Drill uses the log directory determined here rather than // // it's hard-coded defaults. WIP: seems to be needed some times but // // not others. @@ -319,12 +319,12 @@ public class ClusterFixture extends BaseFixture implements AutoCloseable { ((StoragePluginRegistryImpl) pluginRegistry).definePlugin(MockStorageEngineConfig.NAME, config, plugin); } - private void applyOptions(FixtureBuilder builder) throws Exception { + private void applyOptions(ClusterFixtureBuilder builder) throws Exception { // Apply system options if (builder.systemOptions != null) { - for (FixtureBuilder.RuntimeOption option : builder.systemOptions) { + for (ClusterFixtureBuilder.RuntimeOption option : builder.systemOptions) { clientFixture().alterSystem(option.key, option.value); } } @@ -332,7 +332,7 @@ public class ClusterFixture extends BaseFixture implements AutoCloseable { // Apply session options. if (builder.sessionOptions != null) { - for (FixtureBuilder.RuntimeOption option : builder.sessionOptions) { + for (ClusterFixtureBuilder.RuntimeOption option : builder.sessionOptions) { clientFixture().alterSession(option.key, option.value); } } @@ -584,8 +584,8 @@ public class ClusterFixture extends BaseFixture implements AutoCloseable { public static final String EXPLAIN_PLAN_TEXT = "text"; public static final String EXPLAIN_PLAN_JSON = "json"; - public static FixtureBuilder builder() { - FixtureBuilder builder = new FixtureBuilder() + public static ClusterFixtureBuilder builder() { + ClusterFixtureBuilder builder = new ClusterFixtureBuilder() .sessionOption(ExecConstants.MAX_WIDTH_PER_NODE_KEY, MAX_WIDTH_PER_NODE); Properties props = new Properties(); props.putAll(ClusterFixture.TEST_CONFIGURATIONS); @@ -604,8 +604,8 @@ public class ClusterFixture extends BaseFixture implements AutoCloseable { * @return a fixture builder with no default properties set */ - public static FixtureBuilder bareBuilder() { - return new FixtureBuilder(); + public static ClusterFixtureBuilder bareBuilder() { + return new ClusterFixtureBuilder(); } /** http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixtureBuilder.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixtureBuilder.java b/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixtureBuilder.java new file mode 100644 index 0000000..8295554 --- /dev/null +++ b/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixtureBuilder.java @@ -0,0 +1,326 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ +package org.apache.drill.test; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.apache.drill.exec.ExecConstants; +import org.apache.drill.exec.ZookeeperHelper; +import org.apache.drill.exec.server.options.OptionDefinition; + +/** + * Build a Drillbit and client with the options provided. The simplest + * builder starts an embedded Drillbit, with the "dfs_test" name space, + * a max width (parallelization) of 2. + */ + +public class ClusterFixtureBuilder { + + public static class RuntimeOption { + public String key; + public Object value; + + public RuntimeOption(String key, Object value) { + this.key = key; + this.value = value; + } + } + + // Values in the drill-module.conf file for values that are customized + // in the defaults. + + public static final int DEFAULT_ZK_REFRESH = 500; // ms + public static final int DEFAULT_SERVER_RPC_THREADS = 10; + public static final int DEFAULT_SCAN_THREADS = 8; + public static final String OPTION_DEFAULTS_ROOT = "drill.exec.options."; + + protected ConfigBuilder configBuilder = new ConfigBuilder(); + protected List<RuntimeOption> sessionOptions; + protected List<RuntimeOption> systemOptions; + protected int bitCount = 1; + protected String bitNames[]; + protected int localZkCount; + protected ZookeeperHelper zkHelper; + protected boolean usingZk; + protected File tempDir; + protected boolean preserveLocalFiles; + protected Properties clientProps; + + /** + * The configuration builder which this fixture builder uses. + * @return the configuration builder for use in setting "advanced" + * configuration options. + */ + + public ConfigBuilder configBuilder() { return configBuilder; } + + /** + * Use the given configuration file, stored as a resource, to start the + * embedded Drillbit. Note that the resource file should have the two + * following settings to work as a test: + * <pre><code> + * drill.exec.sys.store.provider.local.write : false, + * drill.exec.http.enabled : false + * </code></pre> + * It may be more convenient to add your settings to the default + * config settings with {@link #configProperty(String, Object)}. + * @param configResource path to the file that contains the + * config file to be read + * @return this builder + * @see {@link #configProperty(String, Object)} + */ + + public ClusterFixtureBuilder configResource(String configResource) { + + // TypeSafe gets unhappy about a leading slash, but other functions + // require it. Silently discard the leading slash if given to + // preserve the test writer's sanity. + + configBuilder.resource(ClusterFixture.trimSlash(configResource)); + return this; + } + + /** + * + */ + public ClusterFixtureBuilder setOptionDefault(String key, Object value) { + String option_name = OPTION_DEFAULTS_ROOT + key; + configBuilder().put(option_name, value.toString()); + return this; + } + /** + * Add an additional boot-time property for the embedded Drillbit. + * @param key config property name + * @param value property value + * @return this builder + */ + + public ClusterFixtureBuilder configProperty(String key, Object value) { + configBuilder.put(key, value.toString()); + return this; + } + + public ClusterFixtureBuilder putDefinition(OptionDefinition definition) { + configBuilder.putDefinition(definition); + return this; + } + + /** + * Add an additional property for the client connection URL. Convert all the values into + * String type. + * @param key config property name + * @param value property value + * @return this builder + */ + public ClusterFixtureBuilder configClientProperty(String key, Object value) { + if (clientProps == null) { + clientProps = new Properties(); + } + clientProps.put(key, value.toString()); + return this; + } + + /** + * Provide a session option to be set once the Drillbit + * is started. + * + * @param key the name of the session option + * @param value the value of the session option + * @return this builder + * @see {@link ClusterFixture#alterSession(String, Object)} + */ + + public ClusterFixtureBuilder sessionOption(String key, Object value) { + if (sessionOptions == null) { + sessionOptions = new ArrayList<>(); + } + sessionOptions.add(new RuntimeOption(key, value)); + return this; + } + + /** + * Provide a system option to be set once the Drillbit + * is started. + * + * @param key the name of the system option + * @param value the value of the system option + * @return this builder + * @see {@link ClusterFixture#alterSystem(String, Object)} + */ + + public ClusterFixtureBuilder systemOption(String key, Object value) { + if (systemOptions == null) { + systemOptions = new ArrayList<>(); + } + systemOptions.add(new RuntimeOption(key, value)); + return this; + } + + /** + * Set the maximum parallelization (max width per node). Defaults + * to 2. + * + * @param n the "max width per node" parallelization option. + * @return this builder + */ + public ClusterFixtureBuilder maxParallelization(int n) { + return sessionOption(ExecConstants.MAX_WIDTH_PER_NODE_KEY, n); + } + + /** + * The number of Drillbits to start in the cluster. + * + * @param n the desired cluster size + * @return this builder + */ + public ClusterFixtureBuilder clusterSize(int n) { + bitCount = n; + bitNames = null; + return this; + } + + /** + * Define a cluster by providing names to the Drillbits. + * The cluster size is the same as the number of names provided. + * + * @param bitNames array of (unique) Drillbit names + * @return this builder + */ + public ClusterFixtureBuilder withBits(String bitNames[]) { + this.bitNames = bitNames; + bitCount = bitNames.length; + return this; + } + + /** + * By default the embedded Drillbits use an in-memory cluster coordinator. + * Use this option to start an in-memory ZK instance to coordinate the + * Drillbits. + * @return this builder + */ + public ClusterFixtureBuilder withLocalZk() { + return withLocalZk(1); + } + + public ClusterFixtureBuilder withLocalZk(int count) { + localZkCount = count; + usingZk = true; + + // Using ZK. Turn refresh wait back on. + + return configProperty(ExecConstants.ZK_REFRESH, DEFAULT_ZK_REFRESH); + } + + public ClusterFixtureBuilder withRemoteZk(String connStr) { + usingZk = true; + return configProperty(ExecConstants.ZK_CONNECTION, connStr); + } + + /** + * Run the cluster using a Zookeeper started externally. Use this if + * multiple tests start a cluster: allows ZK to be started once for + * the entire suite rather than once per test case. + * + * @param zk the global Zookeeper to use + * @return this builder + */ + public ClusterFixtureBuilder withZk(ZookeeperHelper zk) { + zkHelper = zk; + usingZk = true; + + // Using ZK. Turn refresh wait back on. + + configProperty(ExecConstants.ZK_REFRESH, DEFAULT_ZK_REFRESH); + return this; + } + + public ClusterFixtureBuilder tempDir(File path) { + this.tempDir = path; + return this; + } + + /** + * Starting with the addition of the CTTAS feature, a Drillbit will + * not restart unless we delete all local storage files before + * starting the Drillbit again. In particular, the stored copies + * of the storage plugin configs cause the temporary workspace + * check to fail. Normally the cluster fixture cleans up files + * both before starting and after shutting down the cluster. Set this + * option to preserve files after shutdown, perhaps to debug the + * contents. + * <p> + * This clean-up is needed only if we enable local storage writes + * (which we must do, unfortunately, to capture and analyze + * storage profiles.) + * + * @return this builder + */ + + public ClusterFixtureBuilder keepLocalFiles() { + preserveLocalFiles = true; + return this; + } + + /** + * Enable saving of query profiles. The only way to save them is + * to enable local store provider writes, which also saves the + * storage plugin configs. Doing so causes the CTTAS feature to + * fail on the next run, so the test fixture deletes all local + * files on start and close, unless + * {@link #keepLocalFiles()} is set. + * + * @return this builder + */ + + public ClusterFixtureBuilder saveProfiles() { + configProperty(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE, true); + systemOption(ExecConstants.ENABLE_QUERY_PROFILE_OPTION, true); + systemOption(ExecConstants.QUERY_PROFILE_DEBUG_OPTION, true); + return this; + } + + /** + * Create the embedded Drillbit and client, applying the options set + * in the builder. Best to use this in a try-with-resources block: + * <pre><code> + * FixtureBuilder builder = ClientFixture.newBuilder() + * .property(...) + * .sessionOption(...) + * ; + * try (ClusterFixture cluster = builder.build(); + * ClientFixture client = cluster.clientFixture()) { + * // Do the test + * } + * </code></pre> + * Note that you use a single cluster fixture to create any number of + * drillbits in your cluster. If you want multiple clients, create the + * first as above, the others (or even the first) using the + * {@link ClusterFixture#clientBuilder()}. Using the client builder + * also lets you set client-side options in the rare cases that you + * need them. + * + * @return + */ + + public ClusterFixture build() { + return new ClusterFixture(this); + } +} http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/test/ClusterTest.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/ClusterTest.java b/exec/java-exec/src/test/java/org/apache/drill/test/ClusterTest.java index e204fde..4a3823c 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/test/ClusterTest.java +++ b/exec/java-exec/src/test/java/org/apache/drill/test/ClusterTest.java @@ -77,7 +77,7 @@ public class ClusterTest extends DrillTest { protected static ClusterFixture cluster; protected static ClientFixture client; - protected static void startCluster(FixtureBuilder builder) throws Exception { + protected static void startCluster(ClusterFixtureBuilder builder) throws Exception { cluster = builder.build(); client = cluster.clientFixture(); } http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/test/ExampleTest.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/ExampleTest.java b/exec/java-exec/src/test/java/org/apache/drill/test/ExampleTest.java index a770d3e..67ae4a3 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/test/ExampleTest.java +++ b/exec/java-exec/src/test/java/org/apache/drill/test/ExampleTest.java @@ -88,7 +88,7 @@ public class ExampleTest { @Test public void secondTest() throws Exception { - FixtureBuilder builder = ClusterFixture.builder() + ClusterFixtureBuilder builder = ClusterFixture.builder() .configProperty(ExecConstants.SLICE_TARGET, 10) ; @@ -159,7 +159,7 @@ public class ExampleTest { // And trace messages for one class. .logger(ExternalSortBatch.class, Level.TRACE) ; - FixtureBuilder builder = ClusterFixture.builder() + ClusterFixtureBuilder builder = ClusterFixture.builder() // Easy way to run single threaded for easy debugging .maxParallelization(1) // Set some session options @@ -203,7 +203,7 @@ public class ExampleTest { @Test public void fifthTest() throws Exception { - FixtureBuilder builder = ClusterFixture.builder() + ClusterFixtureBuilder builder = ClusterFixture.builder() .maxParallelization(1) .configProperty(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE, true) ; http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/test/FixtureBuilder.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/FixtureBuilder.java b/exec/java-exec/src/test/java/org/apache/drill/test/FixtureBuilder.java deleted file mode 100644 index e73c2ba..0000000 --- a/exec/java-exec/src/test/java/org/apache/drill/test/FixtureBuilder.java +++ /dev/null @@ -1,326 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ -package org.apache.drill.test; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import org.apache.drill.exec.ExecConstants; -import org.apache.drill.exec.ZookeeperHelper; -import org.apache.drill.exec.server.options.OptionDefinition; - -/** - * Build a Drillbit and client with the options provided. The simplest - * builder starts an embedded Drillbit, with the "dfs_test" name space, - * a max width (parallelization) of 2. - */ - -public class FixtureBuilder { - - public static class RuntimeOption { - public String key; - public Object value; - - public RuntimeOption(String key, Object value) { - this.key = key; - this.value = value; - } - } - - // Values in the drill-module.conf file for values that are customized - // in the defaults. - - public static final int DEFAULT_ZK_REFRESH = 500; // ms - public static final int DEFAULT_SERVER_RPC_THREADS = 10; - public static final int DEFAULT_SCAN_THREADS = 8; - public static final String OPTION_DEFAULTS_ROOT = "drill.exec.options."; - - protected ConfigBuilder configBuilder = new ConfigBuilder(); - protected List<RuntimeOption> sessionOptions; - protected List<RuntimeOption> systemOptions; - protected int bitCount = 1; - protected String bitNames[]; - protected int localZkCount; - protected ZookeeperHelper zkHelper; - protected boolean usingZk; - protected File tempDir; - protected boolean preserveLocalFiles; - protected Properties clientProps; - - /** - * The configuration builder which this fixture builder uses. - * @return the configuration builder for use in setting "advanced" - * configuration options. - */ - - public ConfigBuilder configBuilder() { return configBuilder; } - - /** - * Use the given configuration file, stored as a resource, to start the - * embedded Drillbit. Note that the resource file should have the two - * following settings to work as a test: - * <pre><code> - * drill.exec.sys.store.provider.local.write : false, - * drill.exec.http.enabled : false - * </code></pre> - * It may be more convenient to add your settings to the default - * config settings with {@link #configProperty(String, Object)}. - * @param configResource path to the file that contains the - * config file to be read - * @return this builder - * @see {@link #configProperty(String, Object)} - */ - - public FixtureBuilder configResource(String configResource) { - - // TypeSafe gets unhappy about a leading slash, but other functions - // require it. Silently discard the leading slash if given to - // preserve the test writer's sanity. - - configBuilder.resource(ClusterFixture.trimSlash(configResource)); - return this; - } - - /** - * - */ - public FixtureBuilder setOptionDefault(String key, Object value) { - String option_name = OPTION_DEFAULTS_ROOT + key; - configBuilder().put(option_name, value.toString()); - return this; - } - /** - * Add an additional boot-time property for the embedded Drillbit. - * @param key config property name - * @param value property value - * @return this builder - */ - - public FixtureBuilder configProperty(String key, Object value) { - configBuilder.put(key, value.toString()); - return this; - } - - public FixtureBuilder putDefinition(OptionDefinition definition) { - configBuilder.putDefinition(definition); - return this; - } - - /** - * Add an additional property for the client connection URL. Convert all the values into - * String type. - * @param key config property name - * @param value property value - * @return this builder - */ - public FixtureBuilder configClientProperty(String key, Object value) { - if (clientProps == null) { - clientProps = new Properties(); - } - clientProps.put(key, value.toString()); - return this; - } - - /** - * Provide a session option to be set once the Drillbit - * is started. - * - * @param key the name of the session option - * @param value the value of the session option - * @return this builder - * @see {@link ClusterFixture#alterSession(String, Object)} - */ - - public FixtureBuilder sessionOption(String key, Object value) { - if (sessionOptions == null) { - sessionOptions = new ArrayList<>(); - } - sessionOptions.add(new RuntimeOption(key, value)); - return this; - } - - /** - * Provide a system option to be set once the Drillbit - * is started. - * - * @param key the name of the system option - * @param value the value of the system option - * @return this builder - * @see {@link ClusterFixture#alterSystem(String, Object)} - */ - - public FixtureBuilder systemOption(String key, Object value) { - if (systemOptions == null) { - systemOptions = new ArrayList<>(); - } - systemOptions.add(new RuntimeOption(key, value)); - return this; - } - - /** - * Set the maximum parallelization (max width per node). Defaults - * to 2. - * - * @param n the "max width per node" parallelization option. - * @return this builder - */ - public FixtureBuilder maxParallelization(int n) { - return sessionOption(ExecConstants.MAX_WIDTH_PER_NODE_KEY, n); - } - - /** - * The number of Drillbits to start in the cluster. - * - * @param n the desired cluster size - * @return this builder - */ - public FixtureBuilder clusterSize(int n) { - bitCount = n; - bitNames = null; - return this; - } - - /** - * Define a cluster by providing names to the Drillbits. - * The cluster size is the same as the number of names provided. - * - * @param bitNames array of (unique) Drillbit names - * @return this builder - */ - public FixtureBuilder withBits(String bitNames[]) { - this.bitNames = bitNames; - bitCount = bitNames.length; - return this; - } - - /** - * By default the embedded Drillbits use an in-memory cluster coordinator. - * Use this option to start an in-memory ZK instance to coordinate the - * Drillbits. - * @return this builder - */ - public FixtureBuilder withLocalZk() { - return withLocalZk(1); - } - - public FixtureBuilder withLocalZk(int count) { - localZkCount = count; - usingZk = true; - - // Using ZK. Turn refresh wait back on. - - return configProperty(ExecConstants.ZK_REFRESH, DEFAULT_ZK_REFRESH); - } - - public FixtureBuilder withRemoteZk(String connStr) { - usingZk = true; - return configProperty(ExecConstants.ZK_CONNECTION, connStr); - } - - /** - * Run the cluster using a Zookeeper started externally. Use this if - * multiple tests start a cluster: allows ZK to be started once for - * the entire suite rather than once per test case. - * - * @param zk the global Zookeeper to use - * @return this builder - */ - public FixtureBuilder withZk(ZookeeperHelper zk) { - zkHelper = zk; - usingZk = true; - - // Using ZK. Turn refresh wait back on. - - configProperty(ExecConstants.ZK_REFRESH, DEFAULT_ZK_REFRESH); - return this; - } - - public FixtureBuilder tempDir(File path) { - this.tempDir = path; - return this; - } - - /** - * Starting with the addition of the CTTAS feature, a Drillbit will - * not restart unless we delete all local storage files before - * starting the Drillbit again. In particular, the stored copies - * of the storage plugin configs cause the temporary workspace - * check to fail. Normally the cluster fixture cleans up files - * both before starting and after shutting down the cluster. Set this - * option to preserve files after shutdown, perhaps to debug the - * contents. - * <p> - * This clean-up is needed only if we enable local storage writes - * (which we must do, unfortunately, to capture and analyze - * storage profiles.) - * - * @return this builder - */ - - public FixtureBuilder keepLocalFiles() { - preserveLocalFiles = true; - return this; - } - - /** - * Enable saving of query profiles. The only way to save them is - * to enable local store provider writes, which also saves the - * storage plugin configs. Doing so causes the CTTAS feature to - * fail on the next run, so the test fixture deletes all local - * files on start and close, unless - * {@link #keepLocalFiles()} is set. - * - * @return this builder - */ - - public FixtureBuilder saveProfiles() { - configProperty(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE, true); - systemOption(ExecConstants.ENABLE_QUERY_PROFILE_OPTION, true); - systemOption(ExecConstants.QUERY_PROFILE_DEBUG_OPTION, true); - return this; - } - - /** - * Create the embedded Drillbit and client, applying the options set - * in the builder. Best to use this in a try-with-resources block: - * <pre><code> - * FixtureBuilder builder = ClientFixture.newBuilder() - * .property(...) - * .sessionOption(...) - * ; - * try (ClusterFixture cluster = builder.build(); - * ClientFixture client = cluster.clientFixture()) { - * // Do the test - * } - * </code></pre> - * Note that you use a single cluster fixture to create any number of - * drillbits in your cluster. If you want multiple clients, create the - * first as above, the others (or even the first) using the - * {@link ClusterFixture#clientBuilder()}. Using the client builder - * also lets you set client-side options in the rare cases that you - * need them. - * - * @return - */ - - public ClusterFixture build() { - return new ClusterFixture(this); - } -} http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/test/OperatorFixture.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/OperatorFixture.java b/exec/java-exec/src/test/java/org/apache/drill/test/OperatorFixture.java index 39b0dc7..09abf12 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/test/OperatorFixture.java +++ b/exec/java-exec/src/test/java/org/apache/drill/test/OperatorFixture.java @@ -18,12 +18,12 @@ package org.apache.drill.test; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.drill.common.config.DrillConfig; -import org.apache.drill.common.map.CaseInsensitiveMap; import org.apache.drill.common.scanner.ClassPathScanner; import org.apache.drill.common.scanner.persistence.ScanResult; import org.apache.drill.exec.ExecConstants; @@ -43,14 +43,10 @@ import org.apache.drill.exec.ops.OperatorStatReceiver; import org.apache.drill.exec.physical.base.PhysicalOperator; import org.apache.drill.exec.record.BatchSchema; import org.apache.drill.exec.record.VectorContainer; -import org.apache.drill.exec.server.options.BaseOptionSet; -import org.apache.drill.exec.server.options.OptionDefinition; import org.apache.drill.exec.server.options.OptionSet; -import org.apache.drill.exec.server.options.OptionValue; -import org.apache.drill.exec.server.options.OptionValue.AccessibleScopes; -import org.apache.drill.exec.server.options.OptionValue.OptionScope; import org.apache.drill.exec.server.options.SystemOptionManager; import org.apache.drill.exec.testing.ExecutionControls; +import org.apache.drill.test.ClusterFixtureBuilder.RuntimeOption; import org.apache.drill.test.rowSet.DirectRowSet; import org.apache.drill.test.rowSet.HyperRowSetImpl; import org.apache.drill.test.rowSet.IndirectRowSet; @@ -92,84 +88,29 @@ public class OperatorFixture extends BaseFixture implements AutoCloseable { public static class OperatorFixtureBuilder { - ConfigBuilder configBuilder = new ConfigBuilder(); - TestOptionSet options = new TestOptionSet(); + protected ConfigBuilder configBuilder = new ConfigBuilder(); + protected List<RuntimeOption> systemOptions; + protected ExecutionControls controls; public ConfigBuilder configBuilder() { return configBuilder; } - public TestOptionSet options() { - return options; - } - - public OperatorFixture build() { - return new OperatorFixture(this); - } - } - - /** - * Test-time implementation of the system and session options. Provides - * a simple storage and a simple set interface, then implements the standard - * system and session option read interface. - */ - - public static class TestOptionSet extends BaseOptionSet { - - private Map<String,OptionValue> values = CaseInsensitiveMap.newHashMap(); - private Map<String,OptionValue> defaults = CaseInsensitiveMap.newHashMap(); - - public TestOptionSet() { - DrillConfig defaultConfig = DrillConfig.create(); - Map<String, OptionDefinition> definitions = SystemOptionManager.createDefaultOptionDefinitions(); - CaseInsensitiveMap<OptionValue> defaultValues = SystemOptionManager.populateDefaultValues(definitions, defaultConfig); - - for (Map.Entry<String, OptionValue> entry: defaultValues.entrySet()) { - String optionName = entry.getKey(); - OptionValue optionValue = entry.getValue(); - defaults.put(optionName, optionValue); + public OperatorFixtureBuilder systemOption(String key, Object value) { + if (systemOptions == null) { + systemOptions = new ArrayList<>(); } - - // Crashes in FunctionImplementationRegistry if not set - set(ExecConstants.CAST_TO_NULLABLE_NUMERIC, false); - // Crashes in the Dynamic UDF code if not disabled - set(ExecConstants.USE_DYNAMIC_UDFS_KEY, false); - } - - public void set(String key, int value) { - set(key, (long) value); - } - - public void set(String key, long value) { - values.put(key, OptionValue.create(AccessibleScopes.SYSTEM, key, value, OptionScope.SYSTEM)); + systemOptions.add(new RuntimeOption(key, value)); + return this; } - public void set(String key, boolean value) { - values.put(key, OptionValue.create(AccessibleScopes.SYSTEM, key, value, OptionScope.SYSTEM)); - } - - public void set(String key, double value) { - values.put(key, OptionValue.create(AccessibleScopes.SYSTEM, key, value, OptionScope.SYSTEM)); - } - - public void set(String key, String value) { - values.put(key, OptionValue.create(AccessibleScopes.SYSTEM, key, value, OptionScope.SYSTEM)); - } - - @Override - public OptionValue getOption(String name) { - final OptionValue value = values.get(name); - - if (value != null) { - return value; - } - - return getDefault(name); + public OperatorFixtureBuilder setControls(ExecutionControls controls) { + this.controls = controls; + return this; } - @Override - public OptionValue getDefault(String optionName) { - return defaults.get(optionName); + public OperatorFixture build() { + return new OperatorFixture(this); } } @@ -255,7 +196,7 @@ public class OperatorFixture extends BaseFixture implements AutoCloseable { public static class MockStats implements OperatorStatReceiver { - public Map<Integer,Double> stats = new HashMap<>(); + public Map<Integer, Double> stats = new HashMap<>(); @Override public void addLongStat(MetricDef metric, long value) { @@ -295,26 +236,39 @@ public class OperatorFixture extends BaseFixture implements AutoCloseable { } } - private final TestOptionSet options; + private final SystemOptionManager options; private final TestCodeGenContext context; private final OperatorStatReceiver stats; protected OperatorFixture(OperatorFixtureBuilder builder) { config = builder.configBuilder().build(); allocator = RootAllocatorFactory.newRoot(config); - options = builder.options(); + options = new SystemOptionManager(config); + try { + options.init(); + } catch (Exception e) { + throw new IllegalStateException("Failed to initialize the system option manager", e); + } + if (builder.systemOptions != null) { + applySystemOptions(builder.systemOptions); + } context = new TestCodeGenContext(config, options); stats = new MockStats(); } - public TestOptionSet options() { return options; } - + private void applySystemOptions(List<RuntimeOption> systemOptions) { + for (RuntimeOption option : systemOptions) { + options.setLocalOption(option.key, option.value); + } + } - public FragmentExecContext codeGenContext() { return context; } + public SystemOptionManager options() { return options; } + public FragmentExecContext fragmentExecContext() { return context; } @Override public void close() throws Exception { allocator.close(); + options.close(); } public static OperatorFixtureBuilder builder() { http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/test/TestConfigLinkage.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/TestConfigLinkage.java b/exec/java-exec/src/test/java/org/apache/drill/test/TestConfigLinkage.java index 19b8ed5..83c60b3 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/test/TestConfigLinkage.java +++ b/exec/java-exec/src/test/java/org/apache/drill/test/TestConfigLinkage.java @@ -52,7 +52,7 @@ public class TestConfigLinkage { public void testDefaultInternalValue() throws Exception { OptionDefinition optionDefinition = createMockPropOptionDefinition(); - FixtureBuilder builder = ClusterFixture.builder(). + ClusterFixtureBuilder builder = ClusterFixture.builder(). configProperty(ExecConstants.bootDefaultFor(MOCK_PROPERTY), "a"). putDefinition(optionDefinition); @@ -72,7 +72,7 @@ public class TestConfigLinkage { public void testDefaultValidatorInternalValue() throws Exception { OptionDefinition optionDefinition = createMockPropOptionDefinition(); - FixtureBuilder builder = ClusterFixture.builder(). + ClusterFixtureBuilder builder = ClusterFixture.builder(). putDefinition(optionDefinition). configProperty(ExecConstants.bootDefaultFor(MOCK_PROPERTY), "a"); @@ -91,7 +91,7 @@ public class TestConfigLinkage { /* Test if session option takes precedence */ @Test public void testSessionOption() throws Exception { - FixtureBuilder builder = ClusterFixture.builder().sessionOption(ExecConstants.SLICE_TARGET, 10); + ClusterFixtureBuilder builder = ClusterFixture.builder().sessionOption(ExecConstants.SLICE_TARGET, 10); try (ClusterFixture cluster = builder.build(); ClientFixture client = cluster.clientFixture()) { String slice_target = client.queryBuilder().sql("SELECT val FROM sys.%s where name='planner.slice_target' and optionScope = 'SESSION'", SystemTable.OPTION_VAL @@ -104,7 +104,7 @@ public class TestConfigLinkage { /* Test if system option takes precedence over the boot option */ @Test public void testSystemOption() throws Exception { - FixtureBuilder builder = ClusterFixture.builder().systemOption(ExecConstants.SLICE_TARGET, 10000); + ClusterFixtureBuilder builder = ClusterFixture.builder().systemOption(ExecConstants.SLICE_TARGET, 10000); try (ClusterFixture cluster = builder.build(); ClientFixture client = cluster.clientFixture()) { String slice_target = client.queryBuilder().sql("SELECT val FROM sys.%s where name='planner.slice_target' and optionScope = 'SYSTEM'", SystemTable.OPTION_VAL.getTableName()) @@ -117,7 +117,7 @@ public class TestConfigLinkage { public void testInternalSystemOption() throws Exception { OptionDefinition optionDefinition = createMockPropOptionDefinition(); - FixtureBuilder builder = ClusterFixture.builder(). + ClusterFixtureBuilder builder = ClusterFixture.builder(). putDefinition(optionDefinition). configProperty(ExecConstants.bootDefaultFor(MOCK_PROPERTY), "a"). systemOption(MOCK_PROPERTY, "blah"); @@ -139,7 +139,7 @@ public class TestConfigLinkage { /* Test if config option takes precedence if config option is not set */ @Test public void testConfigOption() throws Exception { - FixtureBuilder builder = ClusterFixture.builder() + ClusterFixtureBuilder builder = ClusterFixture.builder() .setOptionDefault(ExecConstants.SLICE_TARGET, 1000); try (ClusterFixture cluster = builder.build(); ClientFixture client = cluster.clientFixture()) { @@ -164,7 +164,7 @@ public class TestConfigLinkage { /* Test if altering session option takes precedence over system option */ @Test public void testSessionPrecedence() throws Exception { - FixtureBuilder builder = ClusterFixture.builder().systemOption(ExecConstants.SLICE_TARGET, 100000); + ClusterFixtureBuilder builder = ClusterFixture.builder().systemOption(ExecConstants.SLICE_TARGET, 100000); try (ClusterFixture cluster = builder.build(); ClientFixture client = cluster.clientFixture()) { client.queryBuilder().sql("ALTER SESSION SET `planner.slice_target` = 10000").run(); @@ -177,7 +177,7 @@ public class TestConfigLinkage { /* Test if setting maxwidth option through config takes effect */ @Test public void testMaxWidthPerNodeConfig() throws Exception { - FixtureBuilder builder = ClusterFixture.bareBuilder().setOptionDefault(ExecConstants.MAX_WIDTH_PER_NODE_KEY, 2); + ClusterFixtureBuilder builder = ClusterFixture.bareBuilder().setOptionDefault(ExecConstants.MAX_WIDTH_PER_NODE_KEY, 2); try (ClusterFixture cluster = builder.build(); ClientFixture client = cluster.clientFixture()) { String maxWidth = client.queryBuilder().sql("SELECT val FROM sys.%s where name='planner.width.max_per_node' and optionScope = 'BOOT'", SystemTable.OPTION_VAL.getTableName()) @@ -189,7 +189,7 @@ public class TestConfigLinkage { /* Test if setting maxwidth at system level takes precedence */ @Test public void testMaxWidthPerNodeSystem() throws Exception { - FixtureBuilder builder = ClusterFixture.bareBuilder().systemOption(ExecConstants.MAX_WIDTH_PER_NODE_KEY, 3); + ClusterFixtureBuilder builder = ClusterFixture.bareBuilder().systemOption(ExecConstants.MAX_WIDTH_PER_NODE_KEY, 3); try (ClusterFixture cluster = builder.build(); ClientFixture client = cluster.clientFixture()) { String maxWidth = client.queryBuilder().sql("SELECT val FROM sys.%s where name='planner.width.max_per_node' and optionScope = 'SYSTEM'", SystemTable.OPTION_VAL.getTableName()) @@ -201,7 +201,7 @@ public class TestConfigLinkage { /* Test if setting maxwidth at session level takes precedence */ @Test public void testMaxWidthPerNodeSession() throws Exception { - FixtureBuilder builder = ClusterFixture.bareBuilder().sessionOption(ExecConstants.MAX_WIDTH_PER_NODE_KEY, 2); + ClusterFixtureBuilder builder = ClusterFixture.bareBuilder().sessionOption(ExecConstants.MAX_WIDTH_PER_NODE_KEY, 2); try (ClusterFixture cluster = builder.build(); ClientFixture client = cluster.clientFixture()) { String maxWidth = client.queryBuilder().sql("SELECT val FROM sys.%s where name='planner.width.max_per_node' and optionScope = 'SESSION'", SystemTable.OPTION_VAL.getTableName()) @@ -215,7 +215,7 @@ public class TestConfigLinkage { */ @Test public void testMaxWidthPerNodeDefault() throws Exception { - FixtureBuilder builder = ClusterFixture.bareBuilder().setOptionDefault(ExecConstants.CPU_LOAD_AVERAGE_KEY, 0.70); + ClusterFixtureBuilder builder = ClusterFixture.bareBuilder().setOptionDefault(ExecConstants.CPU_LOAD_AVERAGE_KEY, 0.70); try (ClusterFixture cluster = builder.build(); ClientFixture client = cluster.clientFixture()) { long maxWidth = ExecConstants.MAX_WIDTH_PER_NODE.computeMaxWidth(0.70, 0); @@ -228,7 +228,7 @@ public class TestConfigLinkage { /* Test if the scope is set during BOOT time and scope is actually BOOT */ @Test public void testScope() throws Exception { - FixtureBuilder builder = ClusterFixture.bareBuilder().setOptionDefault(ExecConstants.SLICE_TARGET, 100000); + ClusterFixtureBuilder builder = ClusterFixture.bareBuilder().setOptionDefault(ExecConstants.SLICE_TARGET, 100000); try (ClusterFixture cluster = builder.build(); ClientFixture client = cluster.clientFixture()) { String scope = client.queryBuilder() @@ -241,7 +241,7 @@ public class TestConfigLinkage { /* Test if the option is set at SYSTEM scope and the scope is actually SYSTEM */ @Test public void testScopeSystem() throws Exception { - FixtureBuilder builder = ClusterFixture.bareBuilder().systemOption(ExecConstants.SLICE_TARGET, 10000); + ClusterFixtureBuilder builder = ClusterFixture.bareBuilder().systemOption(ExecConstants.SLICE_TARGET, 10000); try (ClusterFixture cluster = builder.build(); ClientFixture client = cluster.clientFixture()) { String scope = client.queryBuilder() @@ -254,7 +254,7 @@ public class TestConfigLinkage { /* Test if the option is set at SESSION scope and the scope is actually SESSION */ @Test public void testScopeSession() throws Exception { - FixtureBuilder builder = ClusterFixture.bareBuilder().sessionOption(ExecConstants.SLICE_TARGET, 100000); + ClusterFixtureBuilder builder = ClusterFixture.bareBuilder().sessionOption(ExecConstants.SLICE_TARGET, 100000); try (ClusterFixture cluster = builder.build(); ClientFixture client = cluster.clientFixture()) { String scope = client.queryBuilder() @@ -267,7 +267,7 @@ public class TestConfigLinkage { /* Test if the option is altered at SYSTEM scope and the scope is actually SYSTEM */ @Test public void testScopeAlterSystem() throws Exception { - FixtureBuilder builder = ClusterFixture.bareBuilder(); + ClusterFixtureBuilder builder = ClusterFixture.bareBuilder(); try (ClusterFixture cluster = builder.build(); ClientFixture client = cluster.clientFixture()) { client.queryBuilder().sql("ALTER SYSTEM set `planner.slice_target`= 10000").run(); @@ -281,7 +281,7 @@ public class TestConfigLinkage { /* Test if the option is altered at SESSION scope and the scope is actually SESSION */ @Test public void testScopeAlterSession() throws Exception { - FixtureBuilder builder = ClusterFixture.bareBuilder(); + ClusterFixtureBuilder builder = ClusterFixture.bareBuilder(); try (ClusterFixture cluster = builder.build(); ClientFixture client = cluster.clientFixture()) { client.queryBuilder().sql("ALTER SESSION set `planner.slice_target`= 10000").run(); @@ -296,7 +296,7 @@ public class TestConfigLinkage { public void testAlterInternalSystemOption() throws Exception { OptionDefinition optionDefinition = createMockPropOptionDefinition(); - FixtureBuilder builder = ClusterFixture.builder(). + ClusterFixtureBuilder builder = ClusterFixture.builder(). configProperty(ExecConstants.bootDefaultFor(MOCK_PROPERTY), "a"). putDefinition(optionDefinition); http://git-wip-us.apache.org/repos/asf/drill/blob/42fc11e5/exec/java-exec/src/test/java/org/apache/drill/test/package-info.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/package-info.java b/exec/java-exec/src/test/java/org/apache/drill/test/package-info.java index 9f62478..dac71ec 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/test/package-info.java +++ b/exec/java-exec/src/test/java/org/apache/drill/test/package-info.java @@ -20,7 +20,7 @@ * tests and ad-hoc tests created while developing features. Key components * include: * <ul> - * <li>{@link FixtureBuilder}: Builder pattern to create an embedded Drillbit, + * <li>{@link ClusterFixtureBuilder}: Builder pattern to create an embedded Drillbit, * or cluster of Drillbits, using a specified set of configuration, session * and system options.</li> * <li>{@link ClusterFixture}: The cluster created by the builder.</li>
