5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-02 04:41:03 +08:00

SQOOP-3347: Make verify() more generic in AvroTestUtils

(Boglarka Egyed via Szabolcs Vasas)
This commit is contained in:
Szabolcs Vasas 2018-07-20 16:56:47 +02:00
parent b3e941be05
commit 6c6963abe8
3 changed files with 16 additions and 2 deletions

View File

@ -204,6 +204,7 @@ public void testAvroImportWithDefaultPrecisionAndScale() throws IOException {
}
private void verify() {
AvroTestUtils.registerDecimalConversionUsageForVerification();
AvroTestUtils.verify(configuration.getExpectedResults(), getConf(), getTablePath());
}
}

View File

@ -76,6 +76,7 @@ public void testAvroImportWithPadding() throws IOException {
builder.withProperty("sqoop.avro.decimal_padding.enable", "true");
String[] args = builder.build();
runImport(args);
AvroTestUtils.registerDecimalConversionUsageForVerification();
AvroTestUtils.verify(AvroTestUtils.getExpectedResults(), getConf(), getTablePath());
}
}

View File

@ -25,6 +25,8 @@
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.io.DatumReader;
import org.apache.avro.mapred.FsInput;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
@ -37,6 +39,11 @@
public class AvroTestUtils {
private static final String OUTPUT_FILE_NAME = "part-m-00000.avro";
public static final Log LOG = LogFactory.getLog(
AvroTestUtils.class.getName());
public static List<String[]> getInputData() {
List<String[]> data = new ArrayList<>();
data.add(new String[]{"1", "'Aaron'", "1000000.05", "'engineering'"});
@ -63,9 +70,13 @@ public static ArgumentArrayBuilder getBuilderForAvroPaddingTest(BaseSqoopTestCas
.withOption("table", testCase.getTableName());
}
public static void verify(String[] expectedResults, Configuration conf, Path tablePath) {
Path outputFile = new Path(tablePath, "part-m-00000.avro");
public static void registerDecimalConversionUsageForVerification() {
GenericData.get().addLogicalTypeConversion(new Conversions.DecimalConversion());
}
public static void verify(String[] expectedResults, Configuration conf, Path tablePath) {
Path outputFile = new Path(tablePath, OUTPUT_FILE_NAME);
try (DataFileReader<GenericRecord> reader = read(outputFile, conf)) {
GenericRecord record;
if (!reader.hasNext() && expectedResults != null && expectedResults.length > 0) {
@ -78,6 +89,7 @@ record = reader.next();
}
}
catch (IOException ioe) {
LOG.error("Issue with verifying the output", ioe);
throw new RuntimeException(ioe);
}
}