mirror of
https://github.com/apache/sqoop.git
synced 2025-05-02 00:22:17 +08:00
SQOOP-3347: Make verify() more generic in AvroTestUtils
(Boglarka Egyed via Szabolcs Vasas)
This commit is contained in:
parent
b3e941be05
commit
6c6963abe8
@ -204,6 +204,7 @@ public void testAvroImportWithDefaultPrecisionAndScale() throws IOException {
|
||||
}
|
||||
|
||||
private void verify() {
|
||||
AvroTestUtils.registerDecimalConversionUsageForVerification();
|
||||
AvroTestUtils.verify(configuration.getExpectedResults(), getConf(), getTablePath());
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user