[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-03-28 Thread Kunal Khatua (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15946102#comment-15946102
 ] 

Kunal Khatua commented on DRILL-5126:
-

Closing as no QA verification is required

> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>  Labels: ready-to-commit
> Fix For: 1.10.0
>
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different config, so they immediately tear down the 
> default cluster and create a new one.
> This ticket proposes a new test framework, available for new tests, that 
> combines the best of the existing test frameworks into a single, easy-to-use 
> package.
> * Builder for the cluster
> * Accept config-time options
> * Accept run-time session and system options
> * Specify number of Drillbits
> * Simplified API for the most common options
> * AutoCloseable for use in try-with-resources statements
> * Integration with existing test builder classes
> And so on.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-03-28 Thread Paul Rogers (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15945834#comment-15945834
 ] 

Paul Rogers commented on DRILL-5126:


Development-only issue, no QA verification needed.

> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>  Labels: ready-to-commit
> Fix For: 1.10.0
>
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different config, so they immediately tear down the 
> default cluster and create a new one.
> This ticket proposes a new test framework, available for new tests, that 
> combines the best of the existing test frameworks into a single, easy-to-use 
> package.
> * Builder for the cluster
> * Accept config-time options
> * Accept run-time session and system options
> * Specify number of Drillbits
> * Simplified API for the most common options
> * AutoCloseable for use in try-with-resources statements
> * Integration with existing test builder classes
> And so on.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-26 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15840180#comment-15840180
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user paul-rogers commented on the issue:

https://github.com/apache/drill/pull/710
  
Rebased on master, resolved conflict and squashed commits.


> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>  Labels: ready-to-commit
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different config, so they immediately tear down the 
> default cluster and create a new one.
> This ticket proposes a new test framework, available for new tests, that 
> combines the best of the existing test frameworks into a single, easy-to-use 
> package.
> * Builder for the cluster
> * Accept config-time options
> * Accept run-time session and system options
> * Specify number of Drillbits
> * Simplified API for the most common options
> * AutoCloseable for use in try-with-resources statements
> * Integration with existing test builder classes
> And so on.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-24 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15836916#comment-15836916
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sudheeshkatkam commented on the issue:

https://github.com/apache/drill/pull/710
  
+1, thanks!


> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>  Labels: ready-to-commit
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different config, so they immediately tear down the 
> default cluster and create a new one.
> This ticket proposes a new test framework, available for new tests, that 
> combines the best of the existing test frameworks into a single, easy-to-use 
> package.
> * Builder for the cluster
> * Accept config-time options
> * Accept run-time session and system options
> * Specify number of Drillbits
> * Simplified API for the most common options
> * AutoCloseable for use in try-with-resources statements
> * Integration with existing test builder classes
> And so on.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-19 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15830947#comment-15830947
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sohami commented on the issue:

https://github.com/apache/drill/pull/710
  
+1 LGTM


> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different config, so they immediately tear down the 
> default cluster and create a new one.
> This ticket proposes a new test framework, available for new tests, that 
> combines the best of the existing test frameworks into a single, easy-to-use 
> package.
> * Builder for the cluster
> * Accept config-time options
> * Accept run-time session and system options
> * Specify number of Drillbits
> * Simplified API for the most common options
> * AutoCloseable for use in try-with-resources statements
> * Integration with existing test builder classes
> And so on.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-19 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15830397#comment-15830397
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user paul-rogers commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r96927306
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/QueryBuilder.java ---
@@ -49,6 +57,107 @@
 public class QueryBuilder {
 
   /**
+   * Listener used to retrieve the query summary (only) asynchronously
+   * using a {@link QuerySummaryFuture}.
+   */
+
+  public class SummaryOnlyQueryEventListener implements 
UserResultsListener {
+
+private final QuerySummaryFuture future;
+private QueryId queryId;
+private int recordCount;
+private int batchCount;
+private long startTime;
+
+public SummaryOnlyQueryEventListener(QuerySummaryFuture future) {
+  this.future = future;
+  startTime = System.currentTimeMillis();
+}
+
+@Override
+public void queryIdArrived(QueryId queryId) {
+  this.queryId = queryId;
+}
+
+@Override
+public void submissionFailed(UserException ex) {
+  future.completed(new QuerySummary(queryId, recordCount, batchCount,
+  System.currentTimeMillis() - startTime, ex));
--- End diff --

Fixed.


> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different config, so they immediately tear down the 
> default cluster and create a new one.
> This ticket proposes a new test framework, available for new tests, that 
> combines the best of the existing test frameworks into a single, easy-to-use 
> package.
> * Builder for the cluster
> * Accept config-time options
> * Accept run-time session and system options
> * Specify number of Drillbits
> * Simplified API for the most common options
> * AutoCloseable for use in try-with-resources statements
> * Integration with existing test builder classes
> And so on.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-19 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15830398#comment-15830398
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user paul-rogers commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r96928159
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/QueryBuilder.java ---
@@ -49,6 +57,107 @@
 public class QueryBuilder {
 
   /**
+   * Listener used to retrieve the query summary (only) asynchronously
+   * using a {@link QuerySummaryFuture}.
+   */
+
+  public class SummaryOnlyQueryEventListener implements 
UserResultsListener {
+
+private final QuerySummaryFuture future;
+private QueryId queryId;
+private int recordCount;
+private int batchCount;
+private long startTime;
+
+public SummaryOnlyQueryEventListener(QuerySummaryFuture future) {
+  this.future = future;
+  startTime = System.currentTimeMillis();
+}
+
+@Override
+public void queryIdArrived(QueryId queryId) {
+  this.queryId = queryId;
+}
+
+@Override
+public void submissionFailed(UserException ex) {
+  future.completed(new QuerySummary(queryId, recordCount, batchCount,
+  System.currentTimeMillis() - startTime, ex));
+}
+
+@Override
+public void dataArrived(QueryDataBatch result, ConnectionThrottle 
throttle) {
+  batchCount++;
+  recordCount += result.getHeader().getRowCount();
+  result.release();
+}
+
+@Override
+public void queryCompleted(QueryState state) {
+  future.completed(new QuerySummary(queryId, recordCount, batchCount,
+   System.currentTimeMillis() - startTime, state));
+}
+  }
+
+  /**
+   * The future used to wait for the completion of an async query. Returns
+   * just the summary of the query.
+   */
+
+  public class QuerySummaryFuture implements Future {
+
+/**
+ * Synchronizes the listener thread and the test thread that
+ * launched the query.
+ */
+
--- End diff --

Fixed the other way: consistent white space before & after Javadoc comments.


> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different config, so they immediately tear down the 
> default cluster and create a new one.
> This ticket proposes a new test framework, available for new tests, that 
> combines the best of the existing test frameworks into a single, easy-to-use 
> package.
> * Builder for the cluster
> * Accept config-time options
> * Accept run-time session and system options
> * Specify number of Drillbits
> * Simplified API for the most common options
> * AutoCloseable for use in try-with-resources statements
> * Integration with existing test builder classes
> And so on.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-19 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15830399#comment-15830399
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user paul-rogers commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r96924435
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/LogFixture.java ---
@@ -0,0 +1,255 @@
+/*
+ * 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.util.ArrayList;
+import java.util.List;
+
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.ConsoleAppender;
+
+/**
+ * Establishes test-specific logging without having to alter the global
+ * logback-test.xml file. Allows directing output to the console
+ * (if not already configured) and setting the log level on specific 
loggers
+ * of interest in the test. The fixture automatically restores the original
+ * log configuration on exit.
+ * 
+ * Typical usage: 
+ * {@literal @}Test
+ * public void myTest() {
+ *   LogFixtureBuilder logBuilder = LogFixture.builder()
+ *  .toConsole()
+ *  .disable() // Silence all other loggers
+ *  .logger(ExternalSortBatch.class, Level.DEBUG);
+ *   try (LogFixture logs = logBuilder.build()) {
+ * // Test code here
+ *   }
+ * }
+ *  
+ * You can – and should – combine the log fixtue with the
+ * cluster and client fixtures to have complete control over your test-time
+ * Drill environment.
+ */
+
+public class LogFixture implements AutoCloseable {
+
+  // Elapsed time in ms, log level, thread, logger, message.
+
+  public static final String DEFAULT_CONSOLE_FORMAT = "%r %level [%thread] 
[%logger] - %msg%n";
+  private static final String DRILL_PACKAGE_NAME = "org.apache.drill";
+
+  /**
+   * Memento for a logger name and level.
+   */
+  public static class LogSpec {
+String loggerName;
+Level logLevel;
+
+public LogSpec(String loggerName, Level level) {
+  this.loggerName = loggerName;
+  this.logLevel = level;
+}
+  }
+
+  /**
+   * Builds the log settings to be used for a test. The log settings here
+   * add to those specified in a logback.xml or
+   * logback-test.xml file on your class path. In particular, if
+   * the logging configuration already redirects the Drill logger to the
+   * console, setting console logging here does nothing.
+   */
+
+  public static class LogFixtureBuilder {
+
+private String consoleFormat = DEFAULT_CONSOLE_FORMAT;
+private boolean logToConsole;
+private List loggers = new ArrayList<>();
+
+/**
+ * Send all enabled logging to the console (if not already 
configured.) Some
+ * Drill log configuration files send the root to the console (or 
file), but
+ * the Drill loggers to Lilith. In that case, Lilith "hides" the 
console
+ * logger. Using this call adds a console logger to the Drill logger 
so that
+ * output does, in fact, go to the console regardless of the 
configuration
+ * in the Logback configuration file.
+ *
+ * @return this builder
+ */
+public LogFixtureBuilder toConsole() {
+  logToConsole = true;
+  return this;
+}
+
+/**
+ * Send logging to the console using the defined format.
+ *
+ * @param format valid Logback log format
+ * @return this builder
+ */
+
+public LogFixtureBuilder toConsole(String format) {
+  consoleFormat = format;
+

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-18 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15829237#comment-15829237
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sohami commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r96785539
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/QueryBuilder.java ---
@@ -57,20 +166,36 @@
 private final int records;
 private final int batches;
 private final long ms;
+private final QueryState finalState;
+private final Exception error;
 
-public QuerySummary(QueryId queryId, int recordCount, int batchCount, 
long elapsed) {
+public QuerySummary(QueryId queryId, int recordCount, int batchCount, 
long elapsed, QueryState state) {
   this.queryId = queryId;
   records = recordCount;
   batches = batchCount;
   ms = elapsed;
+  finalState = state;
+  error = null;
 }
 
-public long recordCount( ) { return records; }
-public int batchCount( ) { return batches; }
-public long runTimeMs( ) { return ms; }
-public QueryId queryId( ) { return queryId; }
-public String queryIdString( ) { return 
QueryIdHelper.getQueryId(queryId); }
+public QuerySummary(QueryId queryId, int recordCount, int batchCount, 
long elapsed, Exception ex) {
+  this.queryId = queryId;
+  records = recordCount;
+  batches = batchCount;
+  ms = elapsed;
+  finalState = null;
+  error = ex;
+}
 
+public boolean failed() { return error != null; }
+public boolean succeeded() { return error == null; }
--- End diff --

formatting here ?


> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different config, so they immediately tear down the 
> default cluster and create a new one.
> This ticket proposes a new test framework, available for new tests, that 
> combines the best of the existing test frameworks into a single, easy-to-use 
> package.
> * Builder for the cluster
> * Accept config-time options
> * Accept run-time session and system options
> * Specify number of Drillbits
> * Simplified API for the most common options
> * AutoCloseable for use in try-with-resources statements
> * Integration with existing test builder classes
> And so on.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-18 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15829239#comment-15829239
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sohami commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r96785470
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/QueryBuilder.java ---
@@ -49,6 +57,107 @@
 public class QueryBuilder {
 
   /**
+   * Listener used to retrieve the query summary (only) asynchronously
+   * using a {@link QuerySummaryFuture}.
+   */
+
+  public class SummaryOnlyQueryEventListener implements 
UserResultsListener {
+
+private final QuerySummaryFuture future;
+private QueryId queryId;
+private int recordCount;
+private int batchCount;
+private long startTime;
+
+public SummaryOnlyQueryEventListener(QuerySummaryFuture future) {
+  this.future = future;
+  startTime = System.currentTimeMillis();
+}
+
+@Override
+public void queryIdArrived(QueryId queryId) {
+  this.queryId = queryId;
+}
+
+@Override
+public void submissionFailed(UserException ex) {
+  future.completed(new QuerySummary(queryId, recordCount, batchCount,
+  System.currentTimeMillis() - startTime, ex));
+}
+
+@Override
+public void dataArrived(QueryDataBatch result, ConnectionThrottle 
throttle) {
+  batchCount++;
+  recordCount += result.getHeader().getRowCount();
+  result.release();
+}
+
+@Override
+public void queryCompleted(QueryState state) {
+  future.completed(new QuerySummary(queryId, recordCount, batchCount,
+   System.currentTimeMillis() - startTime, state));
+}
+  }
+
+  /**
+   * The future used to wait for the completion of an async query. Returns
+   * just the summary of the query.
+   */
+
+  public class QuerySummaryFuture implements Future {
+
+/**
+ * Synchronizes the listener thread and the test thread that
+ * launched the query.
+ */
+
--- End diff --

please remove extra space here and other places too. Like line 120


> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different config, so they immediately tear down the 
> default cluster and create a new one.
> This ticket proposes a new test framework, available for new tests, that 
> combines the best of the existing test frameworks into a single, easy-to-use 
> package.
> * Builder for the cluster
> * Accept config-time options
> * Accept run-time session and system options
> * Specify number of Drillbits
> * Simplified API for the most common options
> * AutoCloseable for use in try-with-resources statements
> * Integration with existing test builder classes
> And so on.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-18 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15829238#comment-15829238
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sohami commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r96785327
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/LogFixture.java ---
@@ -0,0 +1,255 @@
+/*
+ * 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.util.ArrayList;
+import java.util.List;
+
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.ConsoleAppender;
+
+/**
+ * Establishes test-specific logging without having to alter the global
+ * logback-test.xml file. Allows directing output to the console
+ * (if not already configured) and setting the log level on specific 
loggers
+ * of interest in the test. The fixture automatically restores the original
+ * log configuration on exit.
+ * 
+ * Typical usage: 
+ * {@literal @}Test
+ * public void myTest() {
+ *   LogFixtureBuilder logBuilder = LogFixture.builder()
+ *  .toConsole()
+ *  .disable() // Silence all other loggers
+ *  .logger(ExternalSortBatch.class, Level.DEBUG);
+ *   try (LogFixture logs = logBuilder.build()) {
+ * // Test code here
+ *   }
+ * }
+ *  
+ * You can – and should – combine the log fixtue with the
+ * cluster and client fixtures to have complete control over your test-time
+ * Drill environment.
+ */
+
+public class LogFixture implements AutoCloseable {
+
+  // Elapsed time in ms, log level, thread, logger, message.
+
+  public static final String DEFAULT_CONSOLE_FORMAT = "%r %level [%thread] 
[%logger] - %msg%n";
+  private static final String DRILL_PACKAGE_NAME = "org.apache.drill";
+
+  /**
+   * Memento for a logger name and level.
+   */
+  public static class LogSpec {
+String loggerName;
+Level logLevel;
+
+public LogSpec(String loggerName, Level level) {
+  this.loggerName = loggerName;
+  this.logLevel = level;
+}
+  }
+
+  /**
+   * Builds the log settings to be used for a test. The log settings here
+   * add to those specified in a logback.xml or
+   * logback-test.xml file on your class path. In particular, if
+   * the logging configuration already redirects the Drill logger to the
+   * console, setting console logging here does nothing.
+   */
+
+  public static class LogFixtureBuilder {
+
+private String consoleFormat = DEFAULT_CONSOLE_FORMAT;
+private boolean logToConsole;
+private List loggers = new ArrayList<>();
+
+/**
+ * Send all enabled logging to the console (if not already 
configured.) Some
+ * Drill log configuration files send the root to the console (or 
file), but
+ * the Drill loggers to Lilith. In that case, Lilith "hides" the 
console
+ * logger. Using this call adds a console logger to the Drill logger 
so that
+ * output does, in fact, go to the console regardless of the 
configuration
+ * in the Logback configuration file.
+ *
+ * @return this builder
+ */
+public LogFixtureBuilder toConsole() {
+  logToConsole = true;
+  return this;
+}
+
+/**
+ * Send logging to the console using the defined format.
+ *
+ * @param format valid Logback log format
+ * @return this builder
+ */
+
+public LogFixtureBuilder toConsole(String format) {
+  consoleFormat = format;
+  ret

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-18 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15829236#comment-15829236
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sohami commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r96785415
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/QueryBuilder.java ---
@@ -49,6 +57,107 @@
 public class QueryBuilder {
 
   /**
+   * Listener used to retrieve the query summary (only) asynchronously
+   * using a {@link QuerySummaryFuture}.
+   */
+
+  public class SummaryOnlyQueryEventListener implements 
UserResultsListener {
+
+private final QuerySummaryFuture future;
+private QueryId queryId;
+private int recordCount;
+private int batchCount;
+private long startTime;
+
+public SummaryOnlyQueryEventListener(QuerySummaryFuture future) {
+  this.future = future;
+  startTime = System.currentTimeMillis();
+}
+
+@Override
+public void queryIdArrived(QueryId queryId) {
+  this.queryId = queryId;
+}
+
+@Override
+public void submissionFailed(UserException ex) {
+  future.completed(new QuerySummary(queryId, recordCount, batchCount,
+  System.currentTimeMillis() - startTime, ex));
--- End diff --

formatting


> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different config, so they immediately tear down the 
> default cluster and create a new one.
> This ticket proposes a new test framework, available for new tests, that 
> combines the best of the existing test frameworks into a single, easy-to-use 
> package.
> * Builder for the cluster
> * Accept config-time options
> * Accept run-time session and system options
> * Specify number of Drillbits
> * Simplified API for the most common options
> * AutoCloseable for use in try-with-resources statements
> * Integration with existing test builder classes
> And so on.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-18 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15828880#comment-15828880
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user paul-rogers commented on the issue:

https://github.com/apache/drill/pull/710
  
Rebased onto master. Pulled in additional changes from development branch 
that have accumulated in the three weeks that this PR has worked its way though 
the process. See the description in the third commit for details.


> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different config, so they immediately tear down the 
> default cluster and create a new one.
> This ticket proposes a new test framework, available for new tests, that 
> combines the best of the existing test frameworks into a single, easy-to-use 
> package.
> * Builder for the cluster
> * Accept config-time options
> * Accept run-time session and system options
> * Specify number of Drillbits
> * Simplified API for the most common options
> * AutoCloseable for use in try-with-resources statements
> * Integration with existing test builder classes
> And so on.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-18 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15828858#comment-15828858
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user paul-rogers commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r96739079
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/QueryBuilder.java ---
@@ -0,0 +1,314 @@
+/*
+ * 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.util.List;
+
+import org.apache.drill.PlanTestBase;
+import org.apache.drill.QueryTestUtil;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.expression.SchemaPath;
+import org.apache.drill.exec.client.PrintingResultsListener;
+import org.apache.drill.exec.client.QuerySubmitter.Format;
+import org.apache.drill.exec.proto.UserBitShared.QueryId;
+import org.apache.drill.exec.proto.UserBitShared.QueryType;
+import org.apache.drill.exec.proto.helper.QueryIdHelper;
+import org.apache.drill.exec.record.RecordBatchLoader;
+import org.apache.drill.exec.record.VectorWrapper;
+import org.apache.drill.exec.rpc.RpcException;
+import org.apache.drill.exec.rpc.user.AwaitableUserResultsListener;
+import org.apache.drill.exec.rpc.user.QueryDataBatch;
+import org.apache.drill.exec.rpc.user.UserResultsListener;
+import org.apache.drill.exec.util.VectorUtil;
+import org.apache.drill.exec.vector.NullableVarCharVector;
+import org.apache.drill.exec.vector.ValueVector;
+import org.apache.drill.test.BufferingQueryEventListener.QueryEvent;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Builder for a Drill query. Provides all types of query formats,
+ * and a variety of ways to run the query.
+ */
+
+public class QueryBuilder {
+
+  /**
+   * Summary results of a query: records, batches, run time.
+   */
+
+  public static class QuerySummary {
+private final QueryId queryId;
+private final int records;
+private final int batches;
+private final long ms;
+
+public QuerySummary(QueryId queryId, int recordCount, int batchCount, 
long elapsed) {
+  this.queryId = queryId;
+  records = recordCount;
+  batches = batchCount;
+  ms = elapsed;
+}
+
+public long recordCount( ) { return records; }
+public int batchCount( ) { return batches; }
+public long runTimeMs( ) { return ms; }
+public QueryId queryId( ) { return queryId; }
+public String queryIdString( ) { return 
QueryIdHelper.getQueryId(queryId); }
+
+  }
+
+  private final ClientFixture client;
+  private QueryType queryType;
+  private String queryText;
+
+  QueryBuilder(ClientFixture client) {
+this.client = client;
+  }
+
+  public QueryBuilder query(QueryType type, String text) {
+queryType = type;
+queryText = text;
+return this;
+  }
+
+  public QueryBuilder sql(String sql) {
+return query( QueryType.SQL, sql );
+  }
+
+  public QueryBuilder sql(String query, Object... args) {
+return sql(String.format(query, args));
+  }
+
+  public QueryBuilder physical(String plan) {
+return query( QueryType.PHYSICAL, plan);
+  }
+
+  public QueryBuilder sqlResource(String resource) {
+sql(ClusterFixture.loadResource(resource));
+return this;
+  }
+
+  public QueryBuilder sqlResource(String resource, Object... args) {
+sql(ClusterFixture.loadResource(resource), args);
+return this;
+  }
+
+  public QueryBuilder physicalResource(String resource) {
+physical(ClusterFixture.loadResource(resource));
+return this;
+  }
+
+  /**
+   * Run the query returning jus

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806921#comment-15806921
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user paul-rogers commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95053180
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/FixtureBuilder.java ---
@@ -0,0 +1,251 @@
+/*
+ * 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.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.ZookeeperHelper;
+
+/**
+ * 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 Properties defaultProps() {
+Properties props = new Properties();
+props.putAll(ClusterFixture.TEST_CONFIGURATIONS);
+return props;
+  }
+
+  String configResource;
+  Properties configProps;
+  boolean enableFullCache;
+  List sessionOptions;
+  List systemOptions;
+  int bitCount = 1;
+  String bitNames[];
+  int zkCount;
+  ZookeeperHelper zkHelper;
+
+  /**
+   * Use the given configuration properties to start the embedded Drillbit.
+   * @param configProps a collection of config properties
+   * @return this builder
+   * @see {@link #configProperty(String, Object)}
+   */
+
+  public FixtureBuilder configProps(Properties configProps) {
+this.configProps = configProps;
+return this;
+  }
+
+  /**
+   * 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:
+   * 
+   * drill.exec.sys.store.provider.local.write : false,
+   * drill.exec.http.enabled : false
+   * 
+   * 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.
+
+this.configResource = ClusterFixture.trimSlash(configResource);
+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) {
+if (configProps == null) {
+  configProps = defaultProps();
+}
+configProps.put(key, value.toString());
+return this;
+  }
+
+   /**
+   * Provide a session option to be set once the Drillbit
+   * 

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806923#comment-15806923
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user paul-rogers commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95053415
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/QueryBuilder.java ---
@@ -0,0 +1,314 @@
+/*
+ * 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.util.List;
+
+import org.apache.drill.PlanTestBase;
+import org.apache.drill.QueryTestUtil;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.expression.SchemaPath;
+import org.apache.drill.exec.client.PrintingResultsListener;
+import org.apache.drill.exec.client.QuerySubmitter.Format;
+import org.apache.drill.exec.proto.UserBitShared.QueryId;
+import org.apache.drill.exec.proto.UserBitShared.QueryType;
+import org.apache.drill.exec.proto.helper.QueryIdHelper;
+import org.apache.drill.exec.record.RecordBatchLoader;
+import org.apache.drill.exec.record.VectorWrapper;
+import org.apache.drill.exec.rpc.RpcException;
+import org.apache.drill.exec.rpc.user.AwaitableUserResultsListener;
+import org.apache.drill.exec.rpc.user.QueryDataBatch;
+import org.apache.drill.exec.rpc.user.UserResultsListener;
+import org.apache.drill.exec.util.VectorUtil;
+import org.apache.drill.exec.vector.NullableVarCharVector;
+import org.apache.drill.exec.vector.ValueVector;
+import org.apache.drill.test.BufferingQueryEventListener.QueryEvent;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Builder for a Drill query. Provides all types of query formats,
+ * and a variety of ways to run the query.
+ */
+
+public class QueryBuilder {
+
+  /**
+   * Summary results of a query: records, batches, run time.
+   */
+
+  public static class QuerySummary {
+private final QueryId queryId;
+private final int records;
+private final int batches;
+private final long ms;
+
+public QuerySummary(QueryId queryId, int recordCount, int batchCount, 
long elapsed) {
+  this.queryId = queryId;
+  records = recordCount;
+  batches = batchCount;
+  ms = elapsed;
+}
+
+public long recordCount( ) { return records; }
+public int batchCount( ) { return batches; }
+public long runTimeMs( ) { return ms; }
+public QueryId queryId( ) { return queryId; }
+public String queryIdString( ) { return 
QueryIdHelper.getQueryId(queryId); }
+
+  }
+
+  private final ClientFixture client;
+  private QueryType queryType;
+  private String queryText;
+
+  QueryBuilder(ClientFixture client) {
+this.client = client;
+  }
+
+  public QueryBuilder query(QueryType type, String text) {
+queryType = type;
+queryText = text;
+return this;
+  }
+
+  public QueryBuilder sql(String sql) {
+return query( QueryType.SQL, sql );
+  }
+
+  public QueryBuilder sql(String query, Object... args) {
+return sql(String.format(query, args));
+  }
+
+  public QueryBuilder physical(String plan) {
+return query( QueryType.PHYSICAL, plan);
+  }
+
+  public QueryBuilder sqlResource(String resource) {
+sql(ClusterFixture.loadResource(resource));
+return this;
+  }
+
+  public QueryBuilder sqlResource(String resource, Object... args) {
+sql(ClusterFixture.loadResource(resource), args);
+return this;
+  }
+
+  public QueryBuilder physicalResource(String resource) {
+physical(ClusterFixture.loadResource(resource));
+return this;
+  }
+
+  /**
+   * Run the query returning jus

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806924#comment-15806924
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user paul-rogers commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95053052
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java ---
@@ -0,0 +1,405 @@
+/*
+ * 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.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.drill.DrillTestWrapper.TestServices;
+import org.apache.drill.QueryTestUtil;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.exceptions.ExecutionSetupException;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.ZookeeperHelper;
+import org.apache.drill.exec.client.DrillClient;
+import org.apache.drill.exec.memory.BufferAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
+import org.apache.drill.exec.proto.UserBitShared.QueryType;
+import org.apache.drill.exec.rpc.user.QueryDataBatch;
+import org.apache.drill.exec.server.Drillbit;
+import org.apache.drill.exec.server.RemoteServiceSet;
+import org.apache.drill.exec.store.StoragePluginRegistry;
+import org.apache.drill.exec.store.StoragePluginRegistryImpl;
+import org.apache.drill.exec.store.dfs.FileSystemConfig;
+import org.apache.drill.exec.store.dfs.FileSystemPlugin;
+import org.apache.drill.exec.store.dfs.WorkspaceConfig;
+import org.apache.drill.exec.store.mock.MockStorageEngine;
+import org.apache.drill.exec.store.mock.MockStorageEngineConfig;
+import org.apache.drill.exec.util.TestUtilities;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Preconditions;
+import com.google.common.io.Files;
+import com.google.common.io.Resources;
+
+/**
+ * Test fixture to start a Drillbit with provide options, create a client,
+ * and execute queries. Can be used in JUnit tests, or in ad-hoc programs.
+ * Provides a builder to set the necessary embedded Drillbit and client
+ * options, then creates the requested Drillbit and client.
+ */
+
+public class ClusterFixture implements AutoCloseable {
+//  private static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(ClientFixture.class);
+  public static final String ENABLE_FULL_CACHE = 
"drill.exec.test.use-full-cache";
+  public static final int MAX_WIDTH_PER_NODE = 2;
+
+  @SuppressWarnings("serial")
+  public static final Properties TEST_CONFIGURATIONS = new Properties() {
+{
+  // Properties here mimic those in drill-root/pom.xml, Surefire plugin
+  // configuration. They allow tests to run successfully in Eclipse.
+
+  put(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE, false);
+  put(ExecConstants.HTTP_ENABLE, false);
+  put(Drillbit.SYSTEM_OPTIONS_NAME, 
"org.apache.drill.exec.compile.ClassTransformer.scalar_replacement=on");
+  put(QueryTestUtil.TEST_QUERY_PRINTING_SILENT, true);
+  put("drill.catastrophic_to_standard_out", true);
+
+  // See Drillbit.close. The Drillbit normally waits a specified amount
+  // of time for ZK registration to drop. But, embedded Drillbits 
normally
+  // don't use ZK, so no need to wait.
+
+  put(ExecConstants.ZK_REFRESH, 0);
+
+  // This is just a test, no need to be heavy-duty on threads.
+  // This is the number of serve

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806920#comment-15806920
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user paul-rogers commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95053287
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/ProfileParser.java ---
@@ -0,0 +1,217 @@
+/*
+ * 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.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonNumber;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+import javax.json.JsonValue;
+
+/**
+ * Parses a query profile and provides access to various bits of the 
profile
+ * for diagnostic purposes during tests.
+ */
+
+public class ProfileParser {
+
+  JsonObject profile;
+  List plans;
+
+  public ProfileParser( File file ) throws IOException {
+try (FileReader fileReader = new FileReader(file);
+ JsonReader reader = Json.createReader(fileReader)) {
+  profile = (JsonObject) reader.read();
+}
+  }
+
+  public String getQuery( ) {
+return profile.get("query").toString();
+  }
+
+  public String getPlan() {
+return profile.get("plan").toString();
+  }
+
+  public List getPlans() {
+if ( plans != null ) {
+  return plans; }
+String plan = getPlan( );
+Pattern p = Pattern.compile( "(\\d\\d-\\d+[^]*)n", 
Pattern.MULTILINE );
+Matcher m = p.matcher(plan);
+plans = new ArrayList<>( );
+while ( m.find() ) {
+  plans.add(m.group(1));
+}
+return plans;
+  }
+
+  public String getScan( ) {
+int n = getPlans( ).size();
+Pattern p = Pattern.compile( "\\d+-\\d+\\s+(\\w+)\\(" );
--- End diff --

Yes. What we *should* do is provide the JSON version of the query profile 
in the UI so that customers/users can send us that form instead of the text 
form. With the JSON form, parsing is much simpler.

Yes, this can be simplified. Originally grabbed the other information such 
as the numbers, but not now. Also, was being paranoid incase the word "Scan" 
showed up as a table or field name, but "Scan(" is probably safe.

And, yes, in the general case there are multiple scans. Changed that also.


> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different config, so they immediately tear down the 
> default cluster and create a new one.
> This ticket proposes a new test framework, available for new tests

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806919#comment-15806919
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user paul-rogers commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95052905
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java ---
@@ -0,0 +1,405 @@
+/*
+ * 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.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.drill.DrillTestWrapper.TestServices;
+import org.apache.drill.QueryTestUtil;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.exceptions.ExecutionSetupException;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.ZookeeperHelper;
+import org.apache.drill.exec.client.DrillClient;
+import org.apache.drill.exec.memory.BufferAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
+import org.apache.drill.exec.proto.UserBitShared.QueryType;
+import org.apache.drill.exec.rpc.user.QueryDataBatch;
+import org.apache.drill.exec.server.Drillbit;
+import org.apache.drill.exec.server.RemoteServiceSet;
+import org.apache.drill.exec.store.StoragePluginRegistry;
+import org.apache.drill.exec.store.StoragePluginRegistryImpl;
+import org.apache.drill.exec.store.dfs.FileSystemConfig;
+import org.apache.drill.exec.store.dfs.FileSystemPlugin;
+import org.apache.drill.exec.store.dfs.WorkspaceConfig;
+import org.apache.drill.exec.store.mock.MockStorageEngine;
+import org.apache.drill.exec.store.mock.MockStorageEngineConfig;
+import org.apache.drill.exec.util.TestUtilities;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Preconditions;
+import com.google.common.io.Files;
+import com.google.common.io.Resources;
+
+/**
+ * Test fixture to start a Drillbit with provide options, create a client,
+ * and execute queries. Can be used in JUnit tests, or in ad-hoc programs.
+ * Provides a builder to set the necessary embedded Drillbit and client
+ * options, then creates the requested Drillbit and client.
+ */
+
+public class ClusterFixture implements AutoCloseable {
+//  private static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(ClientFixture.class);
+  public static final String ENABLE_FULL_CACHE = 
"drill.exec.test.use-full-cache";
+  public static final int MAX_WIDTH_PER_NODE = 2;
+
+  @SuppressWarnings("serial")
+  public static final Properties TEST_CONFIGURATIONS = new Properties() {
+{
+  // Properties here mimic those in drill-root/pom.xml, Surefire plugin
+  // configuration. They allow tests to run successfully in Eclipse.
+
+  put(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE, false);
+  put(ExecConstants.HTTP_ENABLE, false);
+  put(Drillbit.SYSTEM_OPTIONS_NAME, 
"org.apache.drill.exec.compile.ClassTransformer.scalar_replacement=on");
+  put(QueryTestUtil.TEST_QUERY_PRINTING_SILENT, true);
+  put("drill.catastrophic_to_standard_out", true);
+
+  // See Drillbit.close. The Drillbit normally waits a specified amount
+  // of time for ZK registration to drop. But, embedded Drillbits 
normally
+  // don't use ZK, so no need to wait.
+
+  put(ExecConstants.ZK_REFRESH, 0);
+
+  // This is just a test, no need to be heavy-duty on threads.
+  // This is the number of serve

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806928#comment-15806928
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user paul-rogers commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95052969
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java ---
@@ -0,0 +1,405 @@
+/*
+ * 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.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.drill.DrillTestWrapper.TestServices;
+import org.apache.drill.QueryTestUtil;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.exceptions.ExecutionSetupException;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.ZookeeperHelper;
+import org.apache.drill.exec.client.DrillClient;
+import org.apache.drill.exec.memory.BufferAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
+import org.apache.drill.exec.proto.UserBitShared.QueryType;
+import org.apache.drill.exec.rpc.user.QueryDataBatch;
+import org.apache.drill.exec.server.Drillbit;
+import org.apache.drill.exec.server.RemoteServiceSet;
+import org.apache.drill.exec.store.StoragePluginRegistry;
+import org.apache.drill.exec.store.StoragePluginRegistryImpl;
+import org.apache.drill.exec.store.dfs.FileSystemConfig;
+import org.apache.drill.exec.store.dfs.FileSystemPlugin;
+import org.apache.drill.exec.store.dfs.WorkspaceConfig;
+import org.apache.drill.exec.store.mock.MockStorageEngine;
+import org.apache.drill.exec.store.mock.MockStorageEngineConfig;
+import org.apache.drill.exec.util.TestUtilities;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Preconditions;
+import com.google.common.io.Files;
+import com.google.common.io.Resources;
+
+/**
+ * Test fixture to start a Drillbit with provide options, create a client,
+ * and execute queries. Can be used in JUnit tests, or in ad-hoc programs.
+ * Provides a builder to set the necessary embedded Drillbit and client
+ * options, then creates the requested Drillbit and client.
+ */
+
+public class ClusterFixture implements AutoCloseable {
+//  private static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(ClientFixture.class);
+  public static final String ENABLE_FULL_CACHE = 
"drill.exec.test.use-full-cache";
+  public static final int MAX_WIDTH_PER_NODE = 2;
+
+  @SuppressWarnings("serial")
+  public static final Properties TEST_CONFIGURATIONS = new Properties() {
+{
+  // Properties here mimic those in drill-root/pom.xml, Surefire plugin
+  // configuration. They allow tests to run successfully in Eclipse.
+
+  put(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE, false);
+  put(ExecConstants.HTTP_ENABLE, false);
+  put(Drillbit.SYSTEM_OPTIONS_NAME, 
"org.apache.drill.exec.compile.ClassTransformer.scalar_replacement=on");
+  put(QueryTestUtil.TEST_QUERY_PRINTING_SILENT, true);
+  put("drill.catastrophic_to_standard_out", true);
+
+  // See Drillbit.close. The Drillbit normally waits a specified amount
+  // of time for ZK registration to drop. But, embedded Drillbits 
normally
+  // don't use ZK, so no need to wait.
+
+  put(ExecConstants.ZK_REFRESH, 0);
+
+  // This is just a test, no need to be heavy-duty on threads.
+  // This is the number of serve

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806922#comment-15806922
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user paul-rogers commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95052737
  
--- Diff: exec/java-exec/pom.xml ---
@@ -458,6 +458,12 @@
   httpdlog-parser
   2.4
 
+   
--- End diff --

Fixed.


> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different config, so they immediately tear down the 
> default cluster and create a new one.
> This ticket proposes a new test framework, available for new tests, that 
> combines the best of the existing test frameworks into a single, easy-to-use 
> package.
> * Builder for the cluster
> * Accept config-time options
> * Accept run-time session and system options
> * Specify number of Drillbits
> * Simplified API for the most common options
> * AutoCloseable for use in try-with-resources statements
> * Integration with existing test builder classes
> And so on.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806925#comment-15806925
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user paul-rogers commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95052810
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java ---
@@ -0,0 +1,405 @@
+/*
+ * 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.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.drill.DrillTestWrapper.TestServices;
+import org.apache.drill.QueryTestUtil;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.exceptions.ExecutionSetupException;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.ZookeeperHelper;
+import org.apache.drill.exec.client.DrillClient;
+import org.apache.drill.exec.memory.BufferAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
+import org.apache.drill.exec.proto.UserBitShared.QueryType;
+import org.apache.drill.exec.rpc.user.QueryDataBatch;
+import org.apache.drill.exec.server.Drillbit;
+import org.apache.drill.exec.server.RemoteServiceSet;
+import org.apache.drill.exec.store.StoragePluginRegistry;
+import org.apache.drill.exec.store.StoragePluginRegistryImpl;
+import org.apache.drill.exec.store.dfs.FileSystemConfig;
+import org.apache.drill.exec.store.dfs.FileSystemPlugin;
+import org.apache.drill.exec.store.dfs.WorkspaceConfig;
+import org.apache.drill.exec.store.mock.MockStorageEngine;
+import org.apache.drill.exec.store.mock.MockStorageEngineConfig;
+import org.apache.drill.exec.util.TestUtilities;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Preconditions;
+import com.google.common.io.Files;
+import com.google.common.io.Resources;
+
+/**
+ * Test fixture to start a Drillbit with provide options, create a client,
+ * and execute queries. Can be used in JUnit tests, or in ad-hoc programs.
+ * Provides a builder to set the necessary embedded Drillbit and client
+ * options, then creates the requested Drillbit and client.
+ */
+
+public class ClusterFixture implements AutoCloseable {
+//  private static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(ClientFixture.class);
+  public static final String ENABLE_FULL_CACHE = 
"drill.exec.test.use-full-cache";
+  public static final int MAX_WIDTH_PER_NODE = 2;
+
+  @SuppressWarnings("serial")
+  public static final Properties TEST_CONFIGURATIONS = new Properties() {
+{
+  // Properties here mimic those in drill-root/pom.xml, Surefire plugin
+  // configuration. They allow tests to run successfully in Eclipse.
+
+  put(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE, false);
+  put(ExecConstants.HTTP_ENABLE, false);
+  put(Drillbit.SYSTEM_OPTIONS_NAME, 
"org.apache.drill.exec.compile.ClassTransformer.scalar_replacement=on");
+  put(QueryTestUtil.TEST_QUERY_PRINTING_SILENT, true);
+  put("drill.catastrophic_to_standard_out", true);
+
+  // See Drillbit.close. The Drillbit normally waits a specified amount
+  // of time for ZK registration to drop. But, embedded Drillbits 
normally
+  // don't use ZK, so no need to wait.
+
+  put(ExecConstants.ZK_REFRESH, 0);
+
+  // This is just a test, no need to be heavy-duty on threads.
+  // This is the number of serve

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806927#comment-15806927
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user paul-rogers commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95052757
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/TestSimpleExternalSort.java
 ---
@@ -22,220 +22,167 @@
 
 import java.util.List;
 
-import org.apache.drill.BaseTestQuery;
-import org.apache.drill.common.config.DrillConfig;
 import org.apache.drill.common.expression.ExpressionPosition;
 import org.apache.drill.common.expression.SchemaPath;
-import org.apache.drill.common.util.FileUtils;
 import org.apache.drill.common.util.TestTools;
-import org.apache.drill.exec.client.DrillClient;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.exception.SchemaChangeException;
+import org.apache.drill.exec.memory.BufferAllocator;
 import org.apache.drill.exec.record.RecordBatchLoader;
 import org.apache.drill.exec.rpc.user.QueryDataBatch;
-import org.apache.drill.exec.server.Drillbit;
-import org.apache.drill.exec.server.RemoteServiceSet;
 import org.apache.drill.exec.vector.BigIntVector;
+import org.apache.drill.test.ClientFixture;
+import org.apache.drill.test.ClusterFixture;
+import org.apache.drill.test.ClusterTest;
+import org.apache.drill.test.DrillTest;
+import org.apache.drill.test.FixtureBuilder;
 import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TestRule;
 
-import com.google.common.base.Charsets;
-import com.google.common.io.Files;
-
-@Ignore
-public class TestSimpleExternalSort extends BaseTestQuery {
+public class TestSimpleExternalSort extends DrillTest {
   static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(TestSimpleExternalSort.class);
-  DrillConfig c = DrillConfig.create();
-
 
   @Rule public final TestRule TIMEOUT = TestTools.getTimeoutRule(8);
 
   @Test
-  public void mergeSortWithSv2() throws Exception {
-List results = 
testPhysicalFromFileWithResults("xsort/one_key_sort_descending_sv2.json");
-int count = 0;
-for(QueryDataBatch b : results) {
-  if (b.getHeader().getRowCount() != 0) {
-count += b.getHeader().getRowCount();
-  }
-}
-assertEquals(50, count);
-
-long previousBigInt = Long.MAX_VALUE;
-
-int recordCount = 0;
-int batchCount = 0;
-
-for (QueryDataBatch b : results) {
-  if (b.getHeader().getRowCount() == 0) {
-break;
-  }
-  batchCount++;
-  RecordBatchLoader loader = new RecordBatchLoader(allocator);
-  loader.load(b.getHeader().getDef(),b.getData());
-  BigIntVector c1 = (BigIntVector) 
loader.getValueAccessorById(BigIntVector.class,
-  loader.getValueVectorId(new SchemaPath("blue", 
ExpressionPosition.UNKNOWN)).getFieldIds()).getValueVector();
-
-
-  BigIntVector.Accessor a1 = c1.getAccessor();
+  public void mergeSortWithSv2Legacy() throws Exception {
+mergeSortWithSv2(true);
+  }
 
-  for (int i =0; i < c1.getAccessor().getValueCount(); i++) {
-recordCount++;
-assertTrue(String.format("%d > %d", previousBigInt, a1.get(i)), 
previousBigInt >= a1.get(i));
-previousBigInt = a1.get(i);
-  }
-  loader.clear();
-  b.release();
+  /**
+   * Tests the external sort using an in-memory sort. Relies on default 
memory
+   * settings to be large enough to do the in-memory sort (there is,
+   * unfortunately, no way to double-check that no spilling was done.)
+   * This must be checked manually by setting a breakpoint in the in-memory
+   * sort routine.
+   *
+   * @param testLegacy
+   * @throws Exception
+   */
+
+  private void mergeSortWithSv2(boolean testLegacy) throws Exception {
+try (ClusterFixture cluster = ClusterFixture.standardCluster( );
+ ClientFixture client = cluster.clientFixture()) {
+  chooseImpl(client, testLegacy);
+  List results = 
client.queryBuilder().physicalResource("xsort/one_key_sort_descending_sv2.json").results();
+  assertEquals(50, client.countResults( results ));
+  validateResults(client.allocator(), results);
 }
+  }
 
-System.out.println(String.format("Sorted %,d records in %d batches.", 
recordCount, batchCount));
+  private void chooseImpl(ClientFixture client, boolean testLegacy) throws 
Exception {
--- End diff --

Yes. This is a pl

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806926#comment-15806926
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user paul-rogers commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95053137
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/FixtureBuilder.java ---
@@ -0,0 +1,251 @@
+/*
+ * 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.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.ZookeeperHelper;
+
+/**
+ * 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 Properties defaultProps() {
+Properties props = new Properties();
+props.putAll(ClusterFixture.TEST_CONFIGURATIONS);
+return props;
+  }
+
+  String configResource;
+  Properties configProps;
+  boolean enableFullCache;
+  List sessionOptions;
+  List systemOptions;
+  int bitCount = 1;
+  String bitNames[];
+  int zkCount;
+  ZookeeperHelper zkHelper;
+
+  /**
+   * Use the given configuration properties to start the embedded Drillbit.
+   * @param configProps a collection of config properties
+   * @return this builder
+   * @see {@link #configProperty(String, Object)}
+   */
+
+  public FixtureBuilder configProps(Properties configProps) {
+this.configProps = configProps;
+return this;
+  }
+
+  /**
+   * 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:
+   * 
+   * drill.exec.sys.store.provider.local.write : false,
+   * drill.exec.http.enabled : false
+   * 
+   * 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.
+
+this.configResource = ClusterFixture.trimSlash(configResource);
+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) {
+if (configProps == null) {
+  configProps = defaultProps();
+}
+configProps.put(key, value.toString());
+return this;
+  }
+
+   /**
+   * Provide a session option to be set once the Drillbit
+   * 

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806918#comment-15806918
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user paul-rogers commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95053125
  
--- Diff: exec/java-exec/src/test/java/org/apache/drill/test/FieldDef.java 
---
@@ -0,0 +1,74 @@
+/*
+ * 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.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Basic representation of a column parsed from a query profile.
+ * Idea is to use this to generate mock data that represents a
+ * query obtained from a user. This is a work in progress.
+ */
+
+public class FieldDef {
+  public enum Type { VARCHAR, DOUBLE };
+  public enum TypeHint { DATE, TIME };
+
+  public final String name;
+  public final String typeStr;
+  public final Type type;
+  public int length;
+  public TypeHint hint;
+
+  public FieldDef( String name, String typeStr ) {
+this.name = name;
+this.typeStr = typeStr;
+Pattern p = Pattern.compile( "(\\w+)(?:\\((\\d+)\\))?" );
+Matcher m = p.matcher(typeStr);
+if ( ! m.matches() ) { throw new IllegalStateException( ); }
+if ( m.group(2) == null ) {
+  length = 0;
+} else {
+  length = Integer.parseInt( m.group(2) );
--- End diff --

Done. There is much to do still here. This is a work in progress that needs 
expansion as we use it for more test cases.


> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different config, so they immediately tear down the 
> default cluster and create a new one.
> This ticket proposes a new test framework, available for new tests, that 
> combines the best of the existing test frameworks into a single, easy-to-use 
> package.
> * Builder for the cluster
> * Accept config-time options
> * Accept run-time session and system options
> * Specify number of Drillbits
> * Simplified API for the most common options
> * AutoCloseable for use in try-with-resources statements
> * Integration with existing test builder classes
> And so on.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806396#comment-15806396
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sohami commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95047142
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/ProfileParser.java ---
@@ -0,0 +1,217 @@
+/*
+ * 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.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonNumber;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+import javax.json.JsonValue;
+
+/**
+ * Parses a query profile and provides access to various bits of the 
profile
+ * for diagnostic purposes during tests.
+ */
+
+public class ProfileParser {
+
+  JsonObject profile;
+  List plans;
+
+  public ProfileParser( File file ) throws IOException {
+try (FileReader fileReader = new FileReader(file);
+ JsonReader reader = Json.createReader(fileReader)) {
+  profile = (JsonObject) reader.read();
+}
+  }
+
+  public String getQuery( ) {
+return profile.get("query").toString();
+  }
+
+  public String getPlan() {
+return profile.get("plan").toString();
+  }
+
+  public List getPlans() {
+if ( plans != null ) {
+  return plans; }
+String plan = getPlan( );
+Pattern p = Pattern.compile( "(\\d\\d-\\d+[^]*)n", 
Pattern.MULTILINE );
+Matcher m = p.matcher(plan);
+plans = new ArrayList<>( );
+while ( m.find() ) {
+  plans.add(m.group(1));
+}
+return plans;
+  }
+
+  public String getScan( ) {
+int n = getPlans( ).size();
+Pattern p = Pattern.compile( "\\d+-\\d+\\s+(\\w+)\\(" );
+for ( int i = n-1; i >= 0;  i-- ) {
+  String plan = plans.get( i );
+  Matcher m = p.matcher( plan );
+  if ( ! m.find() ) { continue; }
+  if ( m.group(1).equals( "Scan" ) ) {
+return plan; }
+}
+return null;
+  }
+
+  public List getColumns( String plan ) {
+Pattern p = Pattern.compile( "RecordType\\((.*)\\):" );
+Matcher m = p.matcher(plan);
+if ( ! m.find() ) { return null; }
+String frag = m.group(1);
+String parts[] = frag.split( ", " );
+List fields = new ArrayList<>( );
+for ( String part : parts ) {
+  String halves[] = part.split( " " );
+  fields.add( new FieldDef( halves[1], halves[0] ) );
+}
+return fields;
+  }
+
+  public Map getOperators( ) {
+Map ops = new HashMap<>();
+int n = getPlans( ).size();
+Pattern p = Pattern.compile( "\\d+-(\\d+)\\s+(\\w+)" );
--- End diff --

Verified all the regex with a sample plan from a query profile. Looks good!


> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of way

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806386#comment-15806386
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sohami commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95019120
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/FixtureBuilder.java ---
@@ -0,0 +1,251 @@
+/*
+ * 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.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.ZookeeperHelper;
+
+/**
+ * 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 Properties defaultProps() {
+Properties props = new Properties();
+props.putAll(ClusterFixture.TEST_CONFIGURATIONS);
+return props;
+  }
+
+  String configResource;
+  Properties configProps;
+  boolean enableFullCache;
+  List sessionOptions;
+  List systemOptions;
+  int bitCount = 1;
+  String bitNames[];
+  int zkCount;
+  ZookeeperHelper zkHelper;
+
+  /**
+   * Use the given configuration properties to start the embedded Drillbit.
+   * @param configProps a collection of config properties
+   * @return this builder
+   * @see {@link #configProperty(String, Object)}
+   */
+
+  public FixtureBuilder configProps(Properties configProps) {
+this.configProps = configProps;
+return this;
+  }
+
+  /**
+   * 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:
+   * 
+   * drill.exec.sys.store.provider.local.write : false,
+   * drill.exec.http.enabled : false
+   * 
+   * 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.
+
+this.configResource = ClusterFixture.trimSlash(configResource);
+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) {
+if (configProps == null) {
+  configProps = defaultProps();
+}
+configProps.put(key, value.toString());
+return this;
+  }
+
+   /**
+   * Provide a session option to be set once the Drillbit
+   * is st

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806388#comment-15806388
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sohami commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r94505587
  
--- Diff: exec/java-exec/pom.xml ---
@@ -458,6 +458,12 @@
   httpdlog-parser
   2.4
 
+   
--- End diff --

Please fix the indentation


> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different config, so they immediately tear down the 
> default cluster and create a new one.
> This ticket proposes a new test framework, available for new tests, that 
> combines the best of the existing test frameworks into a single, easy-to-use 
> package.
> * Builder for the cluster
> * Accept config-time options
> * Accept run-time session and system options
> * Specify number of Drillbits
> * Simplified API for the most common options
> * AutoCloseable for use in try-with-resources statements
> * Integration with existing test builder classes
> And so on.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806397#comment-15806397
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sohami commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95046976
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/xsort/TestSimpleExternalSort.java
 ---
@@ -22,220 +22,167 @@
 
 import java.util.List;
 
-import org.apache.drill.BaseTestQuery;
-import org.apache.drill.common.config.DrillConfig;
 import org.apache.drill.common.expression.ExpressionPosition;
 import org.apache.drill.common.expression.SchemaPath;
-import org.apache.drill.common.util.FileUtils;
 import org.apache.drill.common.util.TestTools;
-import org.apache.drill.exec.client.DrillClient;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.exception.SchemaChangeException;
+import org.apache.drill.exec.memory.BufferAllocator;
 import org.apache.drill.exec.record.RecordBatchLoader;
 import org.apache.drill.exec.rpc.user.QueryDataBatch;
-import org.apache.drill.exec.server.Drillbit;
-import org.apache.drill.exec.server.RemoteServiceSet;
 import org.apache.drill.exec.vector.BigIntVector;
+import org.apache.drill.test.ClientFixture;
+import org.apache.drill.test.ClusterFixture;
+import org.apache.drill.test.ClusterTest;
+import org.apache.drill.test.DrillTest;
+import org.apache.drill.test.FixtureBuilder;
 import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TestRule;
 
-import com.google.common.base.Charsets;
-import com.google.common.io.Files;
-
-@Ignore
-public class TestSimpleExternalSort extends BaseTestQuery {
+public class TestSimpleExternalSort extends DrillTest {
   static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(TestSimpleExternalSort.class);
-  DrillConfig c = DrillConfig.create();
-
 
   @Rule public final TestRule TIMEOUT = TestTools.getTimeoutRule(8);
 
   @Test
-  public void mergeSortWithSv2() throws Exception {
-List results = 
testPhysicalFromFileWithResults("xsort/one_key_sort_descending_sv2.json");
-int count = 0;
-for(QueryDataBatch b : results) {
-  if (b.getHeader().getRowCount() != 0) {
-count += b.getHeader().getRowCount();
-  }
-}
-assertEquals(50, count);
-
-long previousBigInt = Long.MAX_VALUE;
-
-int recordCount = 0;
-int batchCount = 0;
-
-for (QueryDataBatch b : results) {
-  if (b.getHeader().getRowCount() == 0) {
-break;
-  }
-  batchCount++;
-  RecordBatchLoader loader = new RecordBatchLoader(allocator);
-  loader.load(b.getHeader().getDef(),b.getData());
-  BigIntVector c1 = (BigIntVector) 
loader.getValueAccessorById(BigIntVector.class,
-  loader.getValueVectorId(new SchemaPath("blue", 
ExpressionPosition.UNKNOWN)).getFieldIds()).getValueVector();
-
-
-  BigIntVector.Accessor a1 = c1.getAccessor();
+  public void mergeSortWithSv2Legacy() throws Exception {
+mergeSortWithSv2(true);
+  }
 
-  for (int i =0; i < c1.getAccessor().getValueCount(); i++) {
-recordCount++;
-assertTrue(String.format("%d > %d", previousBigInt, a1.get(i)), 
previousBigInt >= a1.get(i));
-previousBigInt = a1.get(i);
-  }
-  loader.clear();
-  b.release();
+  /**
+   * Tests the external sort using an in-memory sort. Relies on default 
memory
+   * settings to be large enough to do the in-memory sort (there is,
+   * unfortunately, no way to double-check that no spilling was done.)
+   * This must be checked manually by setting a breakpoint in the in-memory
+   * sort routine.
+   *
+   * @param testLegacy
+   * @throws Exception
+   */
+
+  private void mergeSortWithSv2(boolean testLegacy) throws Exception {
+try (ClusterFixture cluster = ClusterFixture.standardCluster( );
+ ClientFixture client = cluster.clientFixture()) {
+  chooseImpl(client, testLegacy);
+  List results = 
client.queryBuilder().physicalResource("xsort/one_key_sort_descending_sv2.json").results();
+  assertEquals(50, client.countResults( results ));
+  validateResults(client.allocator(), results);
 }
+  }
 
-System.out.println(String.format("Sorted %,d records in %d batches.", 
recordCount, batchCount));
+  private void chooseImpl(ClientFixture client, boolean testLegacy) throws 
Exception {
--- End diff --

Will the implementatio

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806394#comment-15806394
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sohami commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95044899
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/ProfileParser.java ---
@@ -0,0 +1,217 @@
+/*
+ * 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.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonNumber;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+import javax.json.JsonValue;
+
+/**
+ * Parses a query profile and provides access to various bits of the 
profile
+ * for diagnostic purposes during tests.
+ */
+
+public class ProfileParser {
+
+  JsonObject profile;
+  List plans;
+
+  public ProfileParser( File file ) throws IOException {
+try (FileReader fileReader = new FileReader(file);
+ JsonReader reader = Json.createReader(fileReader)) {
+  profile = (JsonObject) reader.read();
+}
+  }
+
+  public String getQuery( ) {
+return profile.get("query").toString();
+  }
+
+  public String getPlan() {
+return profile.get("plan").toString();
+  }
+
+  public List getPlans() {
+if ( plans != null ) {
+  return plans; }
+String plan = getPlan( );
+Pattern p = Pattern.compile( "(\\d\\d-\\d+[^]*)n", 
Pattern.MULTILINE );
+Matcher m = p.matcher(plan);
+plans = new ArrayList<>( );
+while ( m.find() ) {
+  plans.add(m.group(1));
+}
+return plans;
+  }
+
+  public String getScan( ) {
+int n = getPlans( ).size();
+Pattern p = Pattern.compile( "\\d+-\\d+\\s+(\\w+)\\(" );
--- End diff --

So we are just trying to find if this plan has Scan keyword after fragment 
number. Can't we simply use plan.contains("Scan") ? I guess the scan keyword 
will only be in plans which are actually Scan's.?

Also there can be multiple Scans in the plan right ? In which case we 
should return list of plans here.


> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different config, so they immediately tear down the 
> default cluster and create a new one.
> This ticket proposes a new test framework, available for new tests, that 
> combines the best of the existing test frameworks into a single, easy-to-use 
> package.
> * Builder for the cluster
> * Accept config-time options
> * Accept run-time session and system option

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806387#comment-15806387
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sohami commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95038015
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java ---
@@ -0,0 +1,405 @@
+/*
+ * 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.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.drill.DrillTestWrapper.TestServices;
+import org.apache.drill.QueryTestUtil;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.exceptions.ExecutionSetupException;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.ZookeeperHelper;
+import org.apache.drill.exec.client.DrillClient;
+import org.apache.drill.exec.memory.BufferAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
+import org.apache.drill.exec.proto.UserBitShared.QueryType;
+import org.apache.drill.exec.rpc.user.QueryDataBatch;
+import org.apache.drill.exec.server.Drillbit;
+import org.apache.drill.exec.server.RemoteServiceSet;
+import org.apache.drill.exec.store.StoragePluginRegistry;
+import org.apache.drill.exec.store.StoragePluginRegistryImpl;
+import org.apache.drill.exec.store.dfs.FileSystemConfig;
+import org.apache.drill.exec.store.dfs.FileSystemPlugin;
+import org.apache.drill.exec.store.dfs.WorkspaceConfig;
+import org.apache.drill.exec.store.mock.MockStorageEngine;
+import org.apache.drill.exec.store.mock.MockStorageEngineConfig;
+import org.apache.drill.exec.util.TestUtilities;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Preconditions;
+import com.google.common.io.Files;
+import com.google.common.io.Resources;
+
+/**
+ * Test fixture to start a Drillbit with provide options, create a client,
+ * and execute queries. Can be used in JUnit tests, or in ad-hoc programs.
+ * Provides a builder to set the necessary embedded Drillbit and client
+ * options, then creates the requested Drillbit and client.
+ */
+
+public class ClusterFixture implements AutoCloseable {
+//  private static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(ClientFixture.class);
+  public static final String ENABLE_FULL_CACHE = 
"drill.exec.test.use-full-cache";
+  public static final int MAX_WIDTH_PER_NODE = 2;
+
+  @SuppressWarnings("serial")
+  public static final Properties TEST_CONFIGURATIONS = new Properties() {
+{
+  // Properties here mimic those in drill-root/pom.xml, Surefire plugin
+  // configuration. They allow tests to run successfully in Eclipse.
+
+  put(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE, false);
+  put(ExecConstants.HTTP_ENABLE, false);
+  put(Drillbit.SYSTEM_OPTIONS_NAME, 
"org.apache.drill.exec.compile.ClassTransformer.scalar_replacement=on");
+  put(QueryTestUtil.TEST_QUERY_PRINTING_SILENT, true);
+  put("drill.catastrophic_to_standard_out", true);
+
+  // See Drillbit.close. The Drillbit normally waits a specified amount
+  // of time for ZK registration to drop. But, embedded Drillbits 
normally
+  // don't use ZK, so no need to wait.
+
+  put(ExecConstants.ZK_REFRESH, 0);
+
+  // This is just a test, no need to be heavy-duty on threads.
+  // This is the number of server and

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806391#comment-15806391
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sohami commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95026609
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/FixtureBuilder.java ---
@@ -0,0 +1,251 @@
+/*
+ * 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.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.ZookeeperHelper;
+
+/**
+ * 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 Properties defaultProps() {
+Properties props = new Properties();
+props.putAll(ClusterFixture.TEST_CONFIGURATIONS);
+return props;
+  }
+
+  String configResource;
+  Properties configProps;
+  boolean enableFullCache;
+  List sessionOptions;
+  List systemOptions;
+  int bitCount = 1;
+  String bitNames[];
+  int zkCount;
+  ZookeeperHelper zkHelper;
+
+  /**
+   * Use the given configuration properties to start the embedded Drillbit.
+   * @param configProps a collection of config properties
+   * @return this builder
+   * @see {@link #configProperty(String, Object)}
+   */
+
+  public FixtureBuilder configProps(Properties configProps) {
+this.configProps = configProps;
+return this;
+  }
+
+  /**
+   * 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:
+   * 
+   * drill.exec.sys.store.provider.local.write : false,
+   * drill.exec.http.enabled : false
+   * 
+   * 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.
+
+this.configResource = ClusterFixture.trimSlash(configResource);
+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) {
+if (configProps == null) {
+  configProps = defaultProps();
+}
+configProps.put(key, value.toString());
+return this;
+  }
+
+   /**
+   * Provide a session option to be set once the Drillbit
+   * is st

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806389#comment-15806389
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sohami commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95036224
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java ---
@@ -0,0 +1,405 @@
+/*
+ * 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.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.drill.DrillTestWrapper.TestServices;
+import org.apache.drill.QueryTestUtil;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.exceptions.ExecutionSetupException;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.ZookeeperHelper;
+import org.apache.drill.exec.client.DrillClient;
+import org.apache.drill.exec.memory.BufferAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
+import org.apache.drill.exec.proto.UserBitShared.QueryType;
+import org.apache.drill.exec.rpc.user.QueryDataBatch;
+import org.apache.drill.exec.server.Drillbit;
+import org.apache.drill.exec.server.RemoteServiceSet;
+import org.apache.drill.exec.store.StoragePluginRegistry;
+import org.apache.drill.exec.store.StoragePluginRegistryImpl;
+import org.apache.drill.exec.store.dfs.FileSystemConfig;
+import org.apache.drill.exec.store.dfs.FileSystemPlugin;
+import org.apache.drill.exec.store.dfs.WorkspaceConfig;
+import org.apache.drill.exec.store.mock.MockStorageEngine;
+import org.apache.drill.exec.store.mock.MockStorageEngineConfig;
+import org.apache.drill.exec.util.TestUtilities;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Preconditions;
+import com.google.common.io.Files;
+import com.google.common.io.Resources;
+
+/**
+ * Test fixture to start a Drillbit with provide options, create a client,
+ * and execute queries. Can be used in JUnit tests, or in ad-hoc programs.
+ * Provides a builder to set the necessary embedded Drillbit and client
+ * options, then creates the requested Drillbit and client.
+ */
+
+public class ClusterFixture implements AutoCloseable {
+//  private static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(ClientFixture.class);
+  public static final String ENABLE_FULL_CACHE = 
"drill.exec.test.use-full-cache";
+  public static final int MAX_WIDTH_PER_NODE = 2;
+
+  @SuppressWarnings("serial")
+  public static final Properties TEST_CONFIGURATIONS = new Properties() {
+{
+  // Properties here mimic those in drill-root/pom.xml, Surefire plugin
+  // configuration. They allow tests to run successfully in Eclipse.
+
+  put(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE, false);
+  put(ExecConstants.HTTP_ENABLE, false);
+  put(Drillbit.SYSTEM_OPTIONS_NAME, 
"org.apache.drill.exec.compile.ClassTransformer.scalar_replacement=on");
+  put(QueryTestUtil.TEST_QUERY_PRINTING_SILENT, true);
+  put("drill.catastrophic_to_standard_out", true);
+
+  // See Drillbit.close. The Drillbit normally waits a specified amount
+  // of time for ZK registration to drop. But, embedded Drillbits 
normally
+  // don't use ZK, so no need to wait.
+
+  put(ExecConstants.ZK_REFRESH, 0);
+
+  // This is just a test, no need to be heavy-duty on threads.
+  // This is the number of server and

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806393#comment-15806393
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sohami commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95041561
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/QueryBuilder.java ---
@@ -0,0 +1,314 @@
+/*
+ * 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.util.List;
+
+import org.apache.drill.PlanTestBase;
+import org.apache.drill.QueryTestUtil;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.expression.SchemaPath;
+import org.apache.drill.exec.client.PrintingResultsListener;
+import org.apache.drill.exec.client.QuerySubmitter.Format;
+import org.apache.drill.exec.proto.UserBitShared.QueryId;
+import org.apache.drill.exec.proto.UserBitShared.QueryType;
+import org.apache.drill.exec.proto.helper.QueryIdHelper;
+import org.apache.drill.exec.record.RecordBatchLoader;
+import org.apache.drill.exec.record.VectorWrapper;
+import org.apache.drill.exec.rpc.RpcException;
+import org.apache.drill.exec.rpc.user.AwaitableUserResultsListener;
+import org.apache.drill.exec.rpc.user.QueryDataBatch;
+import org.apache.drill.exec.rpc.user.UserResultsListener;
+import org.apache.drill.exec.util.VectorUtil;
+import org.apache.drill.exec.vector.NullableVarCharVector;
+import org.apache.drill.exec.vector.ValueVector;
+import org.apache.drill.test.BufferingQueryEventListener.QueryEvent;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Builder for a Drill query. Provides all types of query formats,
+ * and a variety of ways to run the query.
+ */
+
+public class QueryBuilder {
+
+  /**
+   * Summary results of a query: records, batches, run time.
+   */
+
+  public static class QuerySummary {
+private final QueryId queryId;
+private final int records;
+private final int batches;
+private final long ms;
+
+public QuerySummary(QueryId queryId, int recordCount, int batchCount, 
long elapsed) {
+  this.queryId = queryId;
+  records = recordCount;
+  batches = batchCount;
+  ms = elapsed;
+}
+
+public long recordCount( ) { return records; }
+public int batchCount( ) { return batches; }
+public long runTimeMs( ) { return ms; }
+public QueryId queryId( ) { return queryId; }
+public String queryIdString( ) { return 
QueryIdHelper.getQueryId(queryId); }
+
+  }
+
+  private final ClientFixture client;
+  private QueryType queryType;
+  private String queryText;
+
+  QueryBuilder(ClientFixture client) {
+this.client = client;
+  }
+
+  public QueryBuilder query(QueryType type, String text) {
+queryType = type;
+queryText = text;
+return this;
+  }
+
+  public QueryBuilder sql(String sql) {
+return query( QueryType.SQL, sql );
+  }
+
+  public QueryBuilder sql(String query, Object... args) {
+return sql(String.format(query, args));
+  }
+
+  public QueryBuilder physical(String plan) {
+return query( QueryType.PHYSICAL, plan);
+  }
+
+  public QueryBuilder sqlResource(String resource) {
+sql(ClusterFixture.loadResource(resource));
+return this;
+  }
+
+  public QueryBuilder sqlResource(String resource, Object... args) {
+sql(ClusterFixture.loadResource(resource), args);
+return this;
+  }
+
+  public QueryBuilder physicalResource(String resource) {
+physical(ClusterFixture.loadResource(resource));
+return this;
+  }
+
+  /**
+   * Run the query returning just a s

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806392#comment-15806392
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sohami commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95032760
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java ---
@@ -0,0 +1,405 @@
+/*
+ * 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.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.drill.DrillTestWrapper.TestServices;
+import org.apache.drill.QueryTestUtil;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.exceptions.ExecutionSetupException;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.ZookeeperHelper;
+import org.apache.drill.exec.client.DrillClient;
+import org.apache.drill.exec.memory.BufferAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
+import org.apache.drill.exec.proto.UserBitShared.QueryType;
+import org.apache.drill.exec.rpc.user.QueryDataBatch;
+import org.apache.drill.exec.server.Drillbit;
+import org.apache.drill.exec.server.RemoteServiceSet;
+import org.apache.drill.exec.store.StoragePluginRegistry;
+import org.apache.drill.exec.store.StoragePluginRegistryImpl;
+import org.apache.drill.exec.store.dfs.FileSystemConfig;
+import org.apache.drill.exec.store.dfs.FileSystemPlugin;
+import org.apache.drill.exec.store.dfs.WorkspaceConfig;
+import org.apache.drill.exec.store.mock.MockStorageEngine;
+import org.apache.drill.exec.store.mock.MockStorageEngineConfig;
+import org.apache.drill.exec.util.TestUtilities;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Preconditions;
+import com.google.common.io.Files;
+import com.google.common.io.Resources;
+
+/**
+ * Test fixture to start a Drillbit with provide options, create a client,
+ * and execute queries. Can be used in JUnit tests, or in ad-hoc programs.
+ * Provides a builder to set the necessary embedded Drillbit and client
+ * options, then creates the requested Drillbit and client.
+ */
+
+public class ClusterFixture implements AutoCloseable {
+//  private static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(ClientFixture.class);
+  public static final String ENABLE_FULL_CACHE = 
"drill.exec.test.use-full-cache";
+  public static final int MAX_WIDTH_PER_NODE = 2;
+
+  @SuppressWarnings("serial")
+  public static final Properties TEST_CONFIGURATIONS = new Properties() {
+{
+  // Properties here mimic those in drill-root/pom.xml, Surefire plugin
+  // configuration. They allow tests to run successfully in Eclipse.
+
+  put(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE, false);
+  put(ExecConstants.HTTP_ENABLE, false);
+  put(Drillbit.SYSTEM_OPTIONS_NAME, 
"org.apache.drill.exec.compile.ClassTransformer.scalar_replacement=on");
+  put(QueryTestUtil.TEST_QUERY_PRINTING_SILENT, true);
+  put("drill.catastrophic_to_standard_out", true);
+
+  // See Drillbit.close. The Drillbit normally waits a specified amount
+  // of time for ZK registration to drop. But, embedded Drillbits 
normally
+  // don't use ZK, so no need to wait.
+
+  put(ExecConstants.ZK_REFRESH, 0);
+
+  // This is just a test, no need to be heavy-duty on threads.
+  // This is the number of server and

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806395#comment-15806395
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sohami commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95045450
  
--- Diff: exec/java-exec/src/test/java/org/apache/drill/test/FieldDef.java 
---
@@ -0,0 +1,74 @@
+/*
+ * 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.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Basic representation of a column parsed from a query profile.
+ * Idea is to use this to generate mock data that represents a
+ * query obtained from a user. This is a work in progress.
+ */
+
+public class FieldDef {
+  public enum Type { VARCHAR, DOUBLE };
+  public enum TypeHint { DATE, TIME };
+
+  public final String name;
+  public final String typeStr;
+  public final Type type;
+  public int length;
+  public TypeHint hint;
+
+  public FieldDef( String name, String typeStr ) {
+this.name = name;
+this.typeStr = typeStr;
+Pattern p = Pattern.compile( "(\\w+)(?:\\((\\d+)\\))?" );
+Matcher m = p.matcher(typeStr);
+if ( ! m.matches() ) { throw new IllegalStateException( ); }
+if ( m.group(2) == null ) {
+  length = 0;
+} else {
+  length = Integer.parseInt( m.group(2) );
--- End diff --

It would be great to add a comment that group(2) is for VARCHAR types which 
has field length. e.g.: VARCHAR(2147483647)


> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different config, so they immediately tear down the 
> default cluster and create a new one.
> This ticket proposes a new test framework, available for new tests, that 
> combines the best of the existing test frameworks into a single, easy-to-use 
> package.
> * Builder for the cluster
> * Accept config-time options
> * Accept run-time session and system options
> * Specify number of Drillbits
> * Simplified API for the most common options
> * AutoCloseable for use in try-with-resources statements
> * Integration with existing test builder classes
> And so on.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15806390#comment-15806390
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

Github user sohami commented on a diff in the pull request:

https://github.com/apache/drill/pull/710#discussion_r95035750
  
--- Diff: 
exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java ---
@@ -0,0 +1,405 @@
+/*
+ * 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.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.drill.DrillTestWrapper.TestServices;
+import org.apache.drill.QueryTestUtil;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.exceptions.ExecutionSetupException;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.ZookeeperHelper;
+import org.apache.drill.exec.client.DrillClient;
+import org.apache.drill.exec.memory.BufferAllocator;
+import org.apache.drill.exec.memory.RootAllocatorFactory;
+import org.apache.drill.exec.proto.UserBitShared.QueryType;
+import org.apache.drill.exec.rpc.user.QueryDataBatch;
+import org.apache.drill.exec.server.Drillbit;
+import org.apache.drill.exec.server.RemoteServiceSet;
+import org.apache.drill.exec.store.StoragePluginRegistry;
+import org.apache.drill.exec.store.StoragePluginRegistryImpl;
+import org.apache.drill.exec.store.dfs.FileSystemConfig;
+import org.apache.drill.exec.store.dfs.FileSystemPlugin;
+import org.apache.drill.exec.store.dfs.WorkspaceConfig;
+import org.apache.drill.exec.store.mock.MockStorageEngine;
+import org.apache.drill.exec.store.mock.MockStorageEngineConfig;
+import org.apache.drill.exec.util.TestUtilities;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Preconditions;
+import com.google.common.io.Files;
+import com.google.common.io.Resources;
+
+/**
+ * Test fixture to start a Drillbit with provide options, create a client,
+ * and execute queries. Can be used in JUnit tests, or in ad-hoc programs.
+ * Provides a builder to set the necessary embedded Drillbit and client
+ * options, then creates the requested Drillbit and client.
+ */
+
+public class ClusterFixture implements AutoCloseable {
+//  private static final org.slf4j.Logger logger = 
org.slf4j.LoggerFactory.getLogger(ClientFixture.class);
+  public static final String ENABLE_FULL_CACHE = 
"drill.exec.test.use-full-cache";
+  public static final int MAX_WIDTH_PER_NODE = 2;
+
+  @SuppressWarnings("serial")
+  public static final Properties TEST_CONFIGURATIONS = new Properties() {
+{
+  // Properties here mimic those in drill-root/pom.xml, Surefire plugin
+  // configuration. They allow tests to run successfully in Eclipse.
+
+  put(ExecConstants.SYS_STORE_PROVIDER_LOCAL_ENABLE_WRITE, false);
+  put(ExecConstants.HTTP_ENABLE, false);
+  put(Drillbit.SYSTEM_OPTIONS_NAME, 
"org.apache.drill.exec.compile.ClassTransformer.scalar_replacement=on");
+  put(QueryTestUtil.TEST_QUERY_PRINTING_SILENT, true);
+  put("drill.catastrophic_to_standard_out", true);
+
+  // See Drillbit.close. The Drillbit normally waits a specified amount
+  // of time for ZK registration to drop. But, embedded Drillbits 
normally
+  // don't use ZK, so no need to wait.
+
+  put(ExecConstants.ZK_REFRESH, 0);
+
+  // This is just a test, no need to be heavy-duty on threads.
+  // This is the number of server and

[jira] [Commented] (DRILL-5126) Provide simplified, unified "cluster fixture" for tests

2016-12-27 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/DRILL-5126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15782260#comment-15782260
 ] 

ASF GitHub Bot commented on DRILL-5126:
---

GitHub user paul-rogers opened a pull request:

https://github.com/apache/drill/pull/710

DRILL-5126: Provide simplified, unified "cluster fixture" for test

Drill provides a robust selection of test frameworks that have evolved to 
satisfy the needs of a variety of test cases. However, some do some of what a 
given test needs, while others to other parts. Also, the various frameworks 
make assumptions (in the form of boot-time configuration) that differs from 
what some test may need, forcing the test to start, then stop, then restart a 
Drillbit - an expensive operation.

Also, many ways exist to run queries, but they all do part of the job. 
Several ways exist to change runtime options.

This checkin shamelessly grabs the best parts from existing frameworks, 
adds a fluent builder facade and provides a complete, versitie test framework 
for new tests. Old tests are unaffected by this new code.

An adjustment was made to allow use of the existing TestBuilder mechanism. 
TestBuilder used to depend on static members of BaseTestQuery. A "shim" allows 
the same code to work in the old way for old tests, but with the new 
ClusterFixture for new tests.

Details are in the org.apache.drill.test.package-info.java file.

This commit modifies a single test case, TestSimpleExternalSort, to use the 
new framework. More cases will follow once this framework itself is committed.

Also, the framework will eventually allow use of the extended mock data 
source from SQL. However, that change must await checkin of the mock data 
source changes.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/paul-rogers/drill DRILL-5126

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/drill/pull/710.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #710


commit 1df75e40535209c74f4e8dd807ced560bbea2e50
Author: Paul Rogers 
Date:   2016-12-13T21:41:23Z

DRILL-5126: Provide simplified, unified "cluster fixture" for test

Drill provides a robust selection of test frameworks that have evolved to 
satisfy the needs of a variety of test cases.
However, some do some of what a given test needs, while others to other 
parts. Also, the various frameworks make
assumptions (in the form of boot-time configuration) that differs from what 
some test may need, forcing the test
to start, then stop, then restart a Drillbit - an expensive operation.

Also, many ways exist to run queries, but they all do part of the job. 
Several ways exist to channge
runtime options.

This checkin shamelessly grabs the best parts from existing frameworks, 
adds a fluent builder facade
and provides a complete, versitie test framework for new tests. Old tests 
are unaffected by this
new code.

An adjustment was made to allow use of the existing TestBuilder mechanism. 
TestBuilder used to
depend on static members of BaseTestQuery. A "shim" allows the same code to 
work in the old
way for old tests, but with the new ClusterFixture for new tests.

Details are in the org.apache.drill.test.package-info.java file.

This commit modifies a single test case, TestSimpleExternalSort, to use the 
new framework.
More cases will follow once this framework itself is committed.

Also, the framework will eventually allow use of the extended mock data 
source
from SQL. However, that change must await checkin of the mock data source 
changes.




> Provide simplified, unified "cluster fixture" for tests
> ---
>
> Key: DRILL-5126
> URL: https://issues.apache.org/jira/browse/DRILL-5126
> Project: Apache Drill
>  Issue Type: Improvement
>  Components: Tools, Build & Test
>Affects Versions: 1.9.0
>Reporter: Paul Rogers
>Assignee: Paul Rogers
>Priority: Minor
>
> Drill provides a robust selection of test frameworks that have evolved to 
> satisfy the needs of a variety of test cases. For newbies, however, the 
> result is a bewildering array of ways to do basically the same thing: set up 
> an embedded Drill cluster, run queries and check results.
> Further, some key test settings are distributed: some are in the pom.xml 
> file, some in config files stored as resources, some in hard-coded settings 
> in base test classes.
> Also, some test base classes helpfully set up a test cluster, but then 
> individual tests need a different