accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [accumulo] branch 2.0 updated: Fix #811 Unit test InputFormatBuilder.java (#1150)
Date Thu, 20 Jun 2019 20:53:34 GMT
This is an automated email from the ASF dual-hosted git repository.

ctubbsii pushed a commit to branch 2.0
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/2.0 by this push:
     new 6e5d6ae  Fix #811 Unit test InputFormatBuilder.java (#1150)
6e5d6ae is described below

commit 6e5d6ae9faf2424f724780c4aae591b84365a524
Author: elinaawise <47641800+elinaawise@users.noreply.github.com>
AuthorDate: Thu Jun 20 16:53:30 2019 -0400

    Fix #811 Unit test InputFormatBuilder.java (#1150)
    
    Unit test InputFormatBuilder.java classLoaderContext() and executionHints() functions
---
 .../mapreduce/InputFormatBuilderTest.java          | 120 +++++++++++++++++++++
 1 file changed, 120 insertions(+)

diff --git a/hadoop-mapreduce/src/test/java/org/apache/accumulo/hadoopImpl/mapreduce/InputFormatBuilderTest.java
b/hadoop-mapreduce/src/test/java/org/apache/accumulo/hadoopImpl/mapreduce/InputFormatBuilderTest.java
new file mode 100644
index 0000000..3f5341e
--- /dev/null
+++ b/hadoop-mapreduce/src/test/java/org/apache/accumulo/hadoopImpl/mapreduce/InputFormatBuilderTest.java
@@ -0,0 +1,120 @@
+/*
+ * 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.accumulo.hadoopImpl.mapreduce;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.accumulo.hadoop.mapreduce.InputFormatBuilder;
+import org.apache.hadoop.mapred.JobConf;
+import org.junit.Before;
+import org.junit.Test;
+
+/*
+ This unit tests ClassLoaderContext and ExecuteHints functionality
+ */
+public class InputFormatBuilderTest {
+
+  private class InputFormatBuilderImplTest<T> extends InputFormatBuilderImpl<T>
{
+    private String currentTable;
+    private SortedMap<String,InputTableConfig> tableConfigMap = new TreeMap<>();
+    private SortedMap<String,String> newHints = new TreeMap<>();
+
+    private InputFormatBuilderImplTest(Class<T> callingClass) {
+      super(callingClass);
+    }
+
+    @Override
+    public InputFormatBuilder.InputFormatOptions<T> table(String tableName) {
+      this.currentTable = tableName;
+      tableConfigMap.put(currentTable, new InputTableConfig());
+      return this;
+    }
+
+    @Override
+    public InputFormatBuilder.InputFormatOptions<T> classLoaderContext(String context)
{
+      tableConfigMap.get(currentTable).setContext(context);
+      return this;
+    }
+
+    private Optional<String> getClassLoaderContext() {
+      return tableConfigMap.get(currentTable).getContext();
+    }
+
+    @Override
+    public InputFormatBuilder.InputFormatOptions<T> executionHints(Map<String,String>
hints) {
+      this.newHints.putAll(hints);
+      tableConfigMap.get(currentTable).setExecutionHints(hints);
+      return this;
+    }
+
+    private SortedMap<String,String> getExecutionHints() {
+      return newHints;
+    }
+  }
+
+  private InputTableConfig tableQueryConfig;
+  private InputFormatBuilderImplTest<InputFormatBuilderTest> formatBuilderTest;
+
+  @Before
+  public void setUp() {
+    tableQueryConfig = new InputTableConfig();
+    formatBuilderTest = new InputFormatBuilderImplTest<>(InputFormatBuilderTest.class);
+    formatBuilderTest.table("test");
+  }
+
+  @Test
+  public void testInputFormatBuilder_ClassLoaderContext() {
+    String context = "classLoaderContext";
+
+    InputFormatBuilderImpl<JobConf> formatBuilder =
+        new InputFormatBuilderImpl<>(InputFormatBuilderTest.class);
+    formatBuilder.table("test");
+    formatBuilder.classLoaderContext(context);
+
+    Optional<String> classLoaderContextStr = tableQueryConfig.getContext();
+    assertTrue(classLoaderContextStr.toString().contains("empty")); // returns Optional.empty
+  }
+
+  @Test
+  public void testInputFormatBuilderImplTest_ClassLoaderContext() {
+    String context = "classLoaderContext";
+
+    formatBuilderTest.classLoaderContext(context);
+
+    Optional<String> classLoaderContextStr = formatBuilderTest.getClassLoaderContext();
+    assertEquals(context, classLoaderContextStr.get());
+  }
+
+  @Test
+  public void testInputFormatBuilderImplTest_ExecuteHints() {
+    SortedMap<String,String> hints = new TreeMap<>();
+    hints.put("key1", "value1");
+    hints.put("key2", "value2");
+    hints.put("key3", "value3");
+
+    formatBuilderTest.executionHints(hints);
+
+    SortedMap<String,String> executionHints = formatBuilderTest.getExecutionHints();
+    assertEquals(hints.toString(), executionHints.toString());
+  }
+}


Mime
View raw message