[
https://issues.apache.org/jira/browse/BEAM-3912?focusedWorklogId=141148&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-141148
]
ASF GitHub Bot logged work on BEAM-3912:
----------------------------------------
Author: ASF GitHub Bot
Created on: 05/Sep/18 08:13
Start Date: 05/Sep/18 08:13
Worklog Time Spent: 10m
Work Description: echauchot commented on a change in pull request #6306:
[BEAM-3912] Add HadoopOutputFormatIO support
URL: https://github.com/apache/beam/pull/6306#discussion_r215173092
##########
File path:
sdks/java/io/hadoop-output-format/src/test/java/org/apache/beam/sdk/io/hadoop/outputformat/HadoopOutputFormatIOTest.java
##########
@@ -0,0 +1,202 @@
+/*
+ * 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.beam.sdk.io.hadoop.outputformat;
+
+import static
org.apache.beam.sdk.transforms.display.DisplayDataMatchers.hasDisplayItem;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.io.hadoop.SerializableConfiguration;
+import org.apache.beam.sdk.io.hadoop.inputformat.Employee;
+import org.apache.beam.sdk.io.hadoop.inputformat.TestEmployeeDataSet;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.transforms.Create;
+import org.apache.beam.sdk.transforms.display.DisplayData;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.mapreduce.OutputFormat;
+import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Unit tests for {@link HadoopOutputFormatIO}. */
+@RunWith(JUnit4.class)
+public class HadoopOutputFormatIOTest {
+ private static SerializableConfiguration serConf;
+
+ @Rule public final transient TestPipeline p = TestPipeline.create();
+ @Rule public ExpectedException thrown = ExpectedException.none();
+
+ @BeforeClass
+ public static void setUp() {
+ EmployeeOutputFormat.initWrittenOutput();
+ serConf = loadTestConfiguration(EmployeeOutputFormat.class, Text.class,
Employee.class);
+ }
+
+ private static SerializableConfiguration loadTestConfiguration(
+ Class<?> outputFormatClassName, Class<?> keyClass, Class<?> valueClass) {
+ Configuration conf = new Configuration();
+ conf.setClass("mapreduce.job.outputformat.class", outputFormatClassName,
OutputFormat.class);
+ conf.setClass("mapreduce.job.outputformat.key.class", keyClass,
Object.class);
+ conf.setClass("mapreduce.job.outputformat.value.class", valueClass,
Object.class);
+ return new SerializableConfiguration(conf);
+ }
+
+ @Test
+ public void testWriteBuildsCorrectly() {
+ HadoopOutputFormatIO.Write<Text, Employee> write =
+ HadoopOutputFormatIO.<Text,
Employee>write().withConfiguration(serConf.get());
+
+ assertEquals(serConf.get(), write.getConfiguration().get());
+ assertEquals(EmployeeOutputFormat.class,
write.getOutputFormatClass().getRawType());
+ assertEquals(Text.class, write.getOutputFormatKeyClass().getRawType());
+ assertEquals(Employee.class,
write.getOutputFormatValueClass().getRawType());
+ }
+
+ /**
+ * This test validates {@link HadoopOutputFormatIO.Write Write} transform
object creation fails
+ * with null configuration. {@link
HadoopOutputFormatIO.Write#withConfiguration(Configuration)
+ * withConfiguration(Configuration)} method checks configuration is null and
throws exception if
+ * it is null.
+ */
+ @Test
+ public void testWriteObjectCreationFailsIfConfigurationIsNull() {
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("Configuration can not be null");
+ HadoopOutputFormatIO.<Text, Employee>write().withConfiguration(null);
+ }
+
+ /**
+ * This test validates functionality of {@link
+ * HadoopOutputFormatIO.Write#withConfiguration(Configuration)
withConfiguration(Configuration)}
+ * function when Hadoop OutputFormat class is not provided by the user in
configuration.
+ */
+ @Test
+ public void testWriteValidationFailsMissingInputFormatInConf() {
+ Configuration configuration = new Configuration();
+ configuration.setClass(HadoopOutputFormatIO.OUTPUTFORMAT_KEY_CLASS,
Text.class, Object.class);
+ configuration.setClass(
+ HadoopOutputFormatIO.OUTPUTFORMAT_VALUE_CLASS, Employee.class,
Object.class);
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("Configuration must contain
\"mapreduce.job.outputformat.class\"");
+ HadoopOutputFormatIO.<Text,
Employee>write().withConfiguration(configuration);
+ }
+
+ /**
+ * This test validates functionality of {@link
+ * HadoopOutputFormatIO.Write#withConfiguration(Configuration)
withConfiguration(Configuration)}
+ * function when key class is not provided by the user in configuration.
+ */
+ @Test
+ public void testWriteValidationFailsMissingKeyClassInConf() {
Review comment:
Ditto: it is equivalent of testing that `checkArgument` used in validate
method works
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 141148)
Time Spent: 2h 20m (was: 2h 10m)
> Add support of HadoopOutputFormatIO
> -----------------------------------
>
> Key: BEAM-3912
> URL: https://issues.apache.org/jira/browse/BEAM-3912
> Project: Beam
> Issue Type: Improvement
> Components: io-java-hadoop
> Reporter: Alexey Romanenko
> Assignee: Alexey Romanenko
> Priority: Minor
> Time Spent: 2h 20m
> Remaining Estimate: 0h
>
> For the moment, there is only HadoopInputFormatIO in Beam. To provide a
> support of different writing IOs, that are not yet natively supported in Beam
> (for example, Apache Orc or HBase bulk load), it would make sense to add
> HadoopOutputFormatIO as well.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)