Search in sources :

Example 1 with TestConverter

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);
    }
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) Schema(org.apache.avro.Schema) JsonObject(com.google.gson.JsonObject) TestConverter(org.apache.gobblin.test.TestConverter) Test(org.testng.annotations.Test)

Example 2 with TestConverter

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());
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) Schema(org.apache.avro.Schema) TestConverter(org.apache.gobblin.test.TestConverter) Test(org.testng.annotations.Test)

Example 3 with TestConverter

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);
    }
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) Schema(org.apache.avro.Schema) JsonObject(com.google.gson.JsonObject) TestConverter(org.apache.gobblin.test.TestConverter) Test(org.testng.annotations.Test)

Example 4 with TestConverter

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());
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) Schema(org.apache.avro.Schema) JsonObject(com.google.gson.JsonObject) TestConverter(org.apache.gobblin.test.TestConverter) Test(org.testng.annotations.Test)

Example 5 with TestConverter

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);
    }
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) Schema(org.apache.avro.Schema) JsonObject(com.google.gson.JsonObject) TestConverter(org.apache.gobblin.test.TestConverter) Test(org.testng.annotations.Test)

Aggregations

Schema (org.apache.avro.Schema)5 WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)5 TestConverter (org.apache.gobblin.test.TestConverter)5 Test (org.testng.annotations.Test)5 JsonObject (com.google.gson.JsonObject)4