drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amansi...@apache.org
Subject [3/4] drill git commit: DRILL-5415: Improve Fixture Builder to configure client properties and keep collection type properties for server
Date Mon, 17 Apr 2017 05:24:08 GMT
DRILL-5415: Improve Fixture Builder to configure client properties and keep collection type
properties for server

Updated with review feedback

close apache/drill#807


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/3b71cbdb
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/3b71cbdb
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/3b71cbdb

Branch: refs/heads/master
Commit: 3b71cbdbe74f1c5462f488524427888ceadb3392
Parents: df81e56
Author: Sorabh Hamirwasia <shamirwasia@maprtech.com>
Authored: Wed Apr 5 11:04:58 2017 -0700
Committer: Aman Sinha <asinha@maprtech.com>
Committed: Sun Apr 16 22:20:31 2017 -0700

----------------------------------------------------------------------
 .../org/apache/drill/test/ClientFixture.java    |  1 +
 .../org/apache/drill/test/ClusterFixture.java   | 47 +++++++++++++++++---
 .../org/apache/drill/test/FixtureBuilder.java   | 19 +++++++-
 3 files changed, 60 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/3b71cbdb/exec/java-exec/src/test/java/org/apache/drill/test/ClientFixture.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/ClientFixture.java b/exec/java-exec/src/test/java/org/apache/drill/test/ClientFixture.java
index b83d5fc..25dab4f 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/test/ClientFixture.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/test/ClientFixture.java
@@ -43,6 +43,7 @@ public class ClientFixture implements AutoCloseable {
 
     protected ClientBuilder(ClusterFixture cluster) {
       this.cluster = cluster;
+      clientProps = cluster.getClientProps();
     }
     /**
      * Specify an optional client property.

http://git-wip-us.apache.org/repos/asf/drill/blob/3b71cbdb/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java b/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java
index b920edb..90ce206 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java
@@ -28,6 +28,8 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Properties;
 
+import com.typesafe.config.Config;
+import com.typesafe.config.ConfigValueFactory;
 import org.apache.commons.io.FileUtils;
 import org.apache.drill.BaseTestQuery;
 import org.apache.drill.DrillTestWrapper.TestServices;
@@ -133,6 +135,7 @@ public class ClusterFixture implements AutoCloseable {
   private boolean usesZk;
   private boolean preserveLocalFiles;
   private boolean isLocal;
+  private Properties clientProps;
 
   /**
    * Temporary directories created for this test cluster.
@@ -143,6 +146,7 @@ public class ClusterFixture implements AutoCloseable {
 
   ClusterFixture(FixtureBuilder builder) {
 
+    setClientProps(builder);
     configureZk(builder);
     try {
       createConfig(builder);
@@ -157,6 +161,18 @@ public class ClusterFixture implements AutoCloseable {
     }
   }
 
+  /**
+   * Set the client properties to be used by client fixture.
+   * @param builder {@link FixtureBuilder#clientProps}
+   */
+  private void setClientProps(FixtureBuilder builder) {
+      clientProps = builder.clientProps;
+  }
+
+  public Properties getClientProps() {
+    return clientProps;
+  }
+
   private void configureZk(FixtureBuilder builder) {
 
     // Start ZK if requested.
@@ -203,7 +219,7 @@ public class ClusterFixture implements AutoCloseable {
     if (builder.configResource != null) {
       config = DrillConfig.create(builder.configResource);
     } else if (builder.configProps != null) {
-      config = DrillConfig.create(configProperties(builder.configProps));
+      config = configProperties(builder.configProps);
     } else {
       throw new IllegalStateException("Configuration was not provided.");
     }
@@ -325,12 +341,31 @@ public class ClusterFixture implements AutoCloseable {
     }
   }
 
-  private Properties configProperties(Properties configProps) {
-    Properties effectiveProps = new Properties();
-    for (Entry<Object, Object> entry : configProps.entrySet()) {
-      effectiveProps.put(entry.getKey(), entry.getValue().toString());
+  private DrillConfig configProperties(Properties configProps) {
+    Properties stringProps = new Properties();
+    Properties collectionProps = new Properties();
+
+    // Filter out the collection type configs and other configs which can be converted to
string.
+    for(Entry<Object, Object> entry : configProps.entrySet()) {
+      if(entry.getValue() instanceof Collection<?>) {
+        collectionProps.put(entry.getKey(), entry.getValue());
+      } else {
+        stringProps.setProperty(entry.getKey().toString(), entry.getValue().toString());
+      }
+    }
+
+    // First create a DrillConfig based on string properties.
+    Config drillConfig = DrillConfig.create(stringProps);
+
+    // Then add the collection properties inside the DrillConfig. Below call to withValue
returns
+    // a new reference. Considering mostly properties will be of string type, doing this
+    // later will be less expensive as compared to doing it for all the properties.
+    for(Entry<Object, Object> entry : collectionProps.entrySet()) {
+      drillConfig = drillConfig.withValue(entry.getKey().toString(),
+        ConfigValueFactory.fromAnyRef(entry.getValue()));
     }
-    return effectiveProps;
+
+    return new DrillConfig(drillConfig, true);
   }
 
   public Drillbit drillbit() { return defaultDrillbit; }

http://git-wip-us.apache.org/repos/asf/drill/blob/3b71cbdb/exec/java-exec/src/test/java/org/apache/drill/test/FixtureBuilder.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/FixtureBuilder.java b/exec/java-exec/src/test/java/org/apache/drill/test/FixtureBuilder.java
index 461371a..f6106ff 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/test/FixtureBuilder.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/test/FixtureBuilder.java
@@ -19,6 +19,7 @@ package org.apache.drill.test;
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Properties;
 
@@ -67,6 +68,7 @@ public class FixtureBuilder {
   protected boolean usingZk;
   protected File tempDir;
   protected boolean preserveLocalFiles;
+  protected Properties clientProps;
 
   /**
    * Use the given configuration properties to start the embedded Drillbit.
@@ -117,7 +119,22 @@ public class FixtureBuilder {
     if (configProps == null) {
       configProps = defaultProps();
     }
-    configProps.put(key, value.toString());
+    configProps.put(key, value);
+    return this;
+  }
+
+  /**
+   * Add an additional property for the client connection URL. Convert all the values into
+   * String type.
+   * @param key config property name
+   * @param value property value
+   * @return this builder
+   */
+  public FixtureBuilder configClientProperty(String key, Object value) {
+    if(clientProps == null) {
+      clientProps = new Properties();
+    }
+    clientProps.put(key, value.toString());
     return this;
   }
 


Mime
View raw message