sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject sqoop git commit: SQOOP-2480: Sqoop2: Provide ability to add entire Map instance to our MutableMapContext
Date Thu, 20 Aug 2015 18:57:51 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 b62c3dec8 -> daaa75762


SQOOP-2480: Sqoop2: Provide ability to add entire Map instance to our MutableMapContext

(Jarek Jarcec Cecho via Abraham Elmahrek)


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

Branch: refs/heads/sqoop2
Commit: daaa7576249003e3c959d083d9e194ffa9217767
Parents: b62c3de
Author: Abraham Elmahrek <abe@apache.org>
Authored: Thu Aug 20 11:57:03 2015 -0700
Committer: Abraham Elmahrek <abe@apache.org>
Committed: Thu Aug 20 11:57:22 2015 -0700

----------------------------------------------------------------------
 .../org/apache/sqoop/common/MutableContext.java |   7 ++
 .../apache/sqoop/common/MutableMapContext.java  |   5 +
 .../sqoop/common/TestMutableMapContext.java     | 100 +++++++++++++++++++
 3 files changed, 112 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/daaa7576/common/src/main/java/org/apache/sqoop/common/MutableContext.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/common/MutableContext.java b/common/src/main/java/org/apache/sqoop/common/MutableContext.java
index 272343f..548d91d 100644
--- a/common/src/main/java/org/apache/sqoop/common/MutableContext.java
+++ b/common/src/main/java/org/apache/sqoop/common/MutableContext.java
@@ -20,6 +20,8 @@ package org.apache.sqoop.common;
 import org.apache.sqoop.classification.InterfaceAudience;
 import org.apache.sqoop.classification.InterfaceStability;
 
+import java.util.Map;
+
 /**
  * Mutable addition to immutable context.
  */
@@ -58,4 +60,9 @@ public interface MutableContext extends ImmutableContext {
    * @param value New value
    */
   public void setBoolean(String key, boolean value);
+
+  /**
+   * Add all properties from given map to this context instance.
+   */
+  public void setAll(Map<String, String> map);
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/daaa7576/common/src/main/java/org/apache/sqoop/common/MutableMapContext.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/common/MutableMapContext.java b/common/src/main/java/org/apache/sqoop/common/MutableMapContext.java
index 59c520c..06ea7a9 100644
--- a/common/src/main/java/org/apache/sqoop/common/MutableMapContext.java
+++ b/common/src/main/java/org/apache/sqoop/common/MutableMapContext.java
@@ -63,6 +63,11 @@ public class MutableMapContext extends MapContext implements MutableContext
{
   }
 
   @Override
+  public void setAll(Map<String, String> map) {
+    getOptions().putAll(map);
+  }
+
+  @Override
   public Iterator<Map.Entry<String, String>> iterator() {
     return getOptions().entrySet().iterator();
   }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/daaa7576/common/src/test/java/org/apache/sqoop/common/TestMutableMapContext.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/common/TestMutableMapContext.java b/common/src/test/java/org/apache/sqoop/common/TestMutableMapContext.java
new file mode 100644
index 0000000..9aab7f8
--- /dev/null
+++ b/common/src/test/java/org/apache/sqoop/common/TestMutableMapContext.java
@@ -0,0 +1,100 @@
+/**
+ * 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.sqoop.common;
+
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+public class TestMutableMapContext {
+
+  MutableMapContext context;
+
+  @BeforeTest
+  public void setUpContext() {
+    context = new MutableMapContext();
+  }
+
+  @Test
+  public void testConstructors() {
+    assertNull(context.getString("random.key"));
+
+    Map<String, String> map = new HashMap<>();
+    map.put("string", "A");
+    map.put("long", "1");
+    map.put("integer", "13");
+    map.put("boolean", "true");
+
+    context = new MutableMapContext(map);
+    assertEquals(context.getString("string"), "A");
+    assertEquals(context.getLong("long", -1), 1L);
+    assertEquals(context.getInt("integer", -1), 13);
+    assertEquals(context.getBoolean("boolean", false), true);
+  }
+
+  @Test
+  public void testSetString() {
+    context.setString("a", "b");
+    assertEquals(context.getString("a"), "b");
+  }
+
+  @Test
+  public void testSetLong() {
+    context.setLong("a", 1L);
+    assertEquals(context.getLong("a", -1L), 1L);
+  }
+
+  @Test
+  public void testSetInteger() {
+    context.setInteger("a", 1);
+    assertEquals(context.getInt("a", -1), 1);
+  }
+
+  @Test
+  public void testSetBoolean() {
+    context.setBoolean("a", true);
+    assertEquals(context.getBoolean("a", false), true);
+  }
+
+  @Test
+  public void testSetAll() {
+    // Pre-setting few properties
+    context.setString("string", "original_value");
+    context.setLong("long", 55L);
+
+    // Generate map that contains few properties that are already in the context and some
new properties
+    Map<String, String> map = new HashMap<>();
+    map.put("string", "A");
+    map.put("long", "1");
+    map.put("integer", "13");
+    map.put("boolean", "true");
+
+    // Calling setAll should set all new properties and override the existing ones
+    context.setAll(map);
+    assertEquals(context.getString("string"), "A");
+    assertEquals(context.getLong("long", -1), 1L);
+    assertEquals(context.getInt("integer", -1), 13);
+    assertEquals(context.getBoolean("boolean", false), true);
+  }
+
+}


Mime
View raw message