use of org.apache.gobblin.test.TestConverter in project incubator-gobblin by apache.
the class MultiConverterTest method testConversionWithMultiplicityAndOneOrEmpty.
/**
* Combines {@link MultiIdentityConverter()} with {@link OneOrEmptyConverter()}
* @throws Exception
*/
@Test
public void testConversionWithMultiplicityAndOneOrEmpty() throws Exception {
MultiConverter multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new MultiIdentityConverter(20), new OneOrEmptyConverter(1), new TestConverter()));
WorkUnitState workUnitState = new WorkUnitState();
Schema schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
Iterable<Object> convertedRecordIterable = multiConverter.convertRecord(schema, TEST_RECORD, workUnitState);
Assert.assertEquals(Iterables.size(convertedRecordIterable), 20);
for (Object record : convertedRecordIterable) {
checkConvertedAvroData(schema, (GenericRecord) record);
}
multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new MultiIdentityConverter(20), new OneOrEmptyConverter(10), new TestConverter()));
workUnitState = new WorkUnitState();
schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
convertedRecordIterable = multiConverter.convertRecord(schema, TEST_RECORD, workUnitState);
Assert.assertEquals(Iterables.size(convertedRecordIterable), 2);
for (Object record : convertedRecordIterable) {
checkConvertedAvroData(schema, (GenericRecord) record);
}
multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new MultiIdentityConverter(20), new OneOrEmptyConverter(10), new MultiIdentityConverter(10), new TestConverter()));
workUnitState = new WorkUnitState();
schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
convertedRecordIterable = multiConverter.convertRecord(schema, TEST_RECORD, workUnitState);
Assert.assertEquals(Iterables.size(convertedRecordIterable), 20);
for (Object record : convertedRecordIterable) {
checkConvertedAvroData(schema, (GenericRecord) record);
}
}
use of org.apache.gobblin.test.TestConverter in project incubator-gobblin by apache.
the class MultiConverterTest method testConversionWithEmptyConverter.
@Test
public void testConversionWithEmptyConverter() throws Exception {
WorkUnitState workUnitState = new WorkUnitState();
MultiConverter multiConverter = new MultiConverter(Lists.newArrayList(new EmptyConverter(), new SchemaSimplificationConverter(), new TestConverter()));
Schema schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
Assert.assertFalse(multiConverter.convertRecord(schema, TEST_RECORD, workUnitState).iterator().hasNext());
multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new EmptyConverter(), new TestConverter()));
schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
Assert.assertFalse(multiConverter.convertRecord(schema, TEST_RECORD, workUnitState).iterator().hasNext());
multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new TestConverter(), new EmptyConverter()));
schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
Assert.assertFalse(multiConverter.convertRecord(schema, TEST_RECORD, workUnitState).iterator().hasNext());
multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new MultiIdentityConverter(5), new TestConverter(), new EmptyConverter()));
schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
Assert.assertFalse(multiConverter.convertRecord(schema, TEST_RECORD, workUnitState).iterator().hasNext());
multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new EmptyConverter(), new MultiIdentityConverter(5), new TestConverter()));
schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
Assert.assertFalse(multiConverter.convertRecord(schema, TEST_RECORD, workUnitState).iterator().hasNext());
}
use of org.apache.gobblin.test.TestConverter in project incubator-gobblin by apache.
the class MultiConverterTest method testConversionWithMultiplicity.
@Test
public void testConversionWithMultiplicity() throws Exception {
MultiConverter multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new MultiIdentityConverter(2), new MultiIdentityConverter(2), new TestConverter()));
WorkUnitState workUnitState = new WorkUnitState();
Schema schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
Iterable<Object> convertedRecordIterable = multiConverter.convertRecord(schema, TEST_RECORD, workUnitState);
Assert.assertEquals(Iterables.size(convertedRecordIterable), 4);
for (Object record : convertedRecordIterable) {
checkConvertedAvroData(schema, (GenericRecord) record);
}
}
use of org.apache.gobblin.test.TestConverter in project incubator-gobblin by apache.
the class MultiConverterTest method testConversion.
@Test
public void testConversion() throws Exception {
MultiConverter multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new IdentityConverter(), new TestConverter()));
WorkUnitState workUnitState = new WorkUnitState();
Schema schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
Iterable<Object> convertedRecordIterable = multiConverter.convertRecord(schema, TEST_RECORD, workUnitState);
Assert.assertEquals(Iterables.size(convertedRecordIterable), 1);
checkConvertedAvroData(schema, (GenericRecord) convertedRecordIterable.iterator().next());
}
use of org.apache.gobblin.test.TestConverter in project incubator-gobblin by apache.
the class MultiConverterTest method testConversionWithMultiplicityAndAlternating.
/**
* Combines {@link MultiIdentityConverter()} with {@link AlternatingConverter()}
* @throws Exception
*/
@Test
public void testConversionWithMultiplicityAndAlternating() throws Exception {
MultiConverter multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new MultiIdentityConverter(6), new AlternatingConverter(4), new TestConverter()));
WorkUnitState workUnitState = new WorkUnitState();
Schema schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
Iterable<Object> convertedRecordIterable = multiConverter.convertRecord(schema, TEST_RECORD, workUnitState);
Assert.assertEquals(Iterables.size(convertedRecordIterable), 10);
for (Object record : convertedRecordIterable) {
checkConvertedAvroData(schema, (GenericRecord) record);
}
multiConverter = new MultiConverter(Lists.newArrayList(new SchemaSimplificationConverter(), new MultiIdentityConverter(6), new AlternatingConverter(4), new MultiIdentityConverter(4), new TestConverter()));
workUnitState = new WorkUnitState();
schema = (Schema) multiConverter.convertSchema(TEST_SCHEMA, workUnitState);
convertedRecordIterable = multiConverter.convertRecord(schema, TEST_RECORD, workUnitState);
Assert.assertEquals(Iterables.size(convertedRecordIterable), 40);
for (Object record : convertedRecordIterable) {
checkConvertedAvroData(schema, (GenericRecord) record);
}
}
Aggregations