Search in sources :

Example 46 with WorkUnitState

use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.

the class BytesToJsonConverterTest method testConverter.

@Test
public void testConverter() throws DataConversionException, IOException {
    BytesToJsonConverter converter = new BytesToJsonConverter();
    WorkUnitState state = new WorkUnitState();
    JsonObject record = converter.convertRecord("dummySchema", IOUtils.toByteArray(this.getClass().getResourceAsStream("/converter/jsonToAvroRecord.json")), state).iterator().next();
    Assert.assertEquals(record.get("longField").getAsLong(), 1234L);
    Assert.assertEquals(record.get("nestedRecords").getAsJsonObject().get("nestedField2").getAsString(), "test2");
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 47 with WorkUnitState

use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.

the class ObjectStoreDeleteConverterTest method convertStringObjId.

@Test
public void convertStringObjId() throws Exception {
    WorkUnitState wu = new WorkUnitState();
    wu.setProp(ObjectStoreDeleteConverter.OBJECT_ID_FIELD, "objectId");
    ObjectStoreDeleteConverter converter = new ObjectStoreDeleteConverter();
    converter.init(wu);
    Schema schema = new Schema.Parser().parse("{ \"type\" : \"record\", \"name\" : \"test_schema\", \"namespace\" : \"com.gobblin.test\", " + "\"fields\" : [ { \"name\" : \"objectId\", \"type\" : \"string\"} ], \"doc:\" : \"\" }");
    GenericRecord datum = new GenericData.Record(schema);
    String objId = "abcd";
    datum.put("objectId", objId);
    Assert.assertEquals(Iterables.getFirst(converter.convertRecord(converter.convertSchema(schema, wu), datum, wu), null).getObjectId(), objId.getBytes());
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) Schema(org.apache.avro.Schema) GenericRecord(org.apache.avro.generic.GenericRecord) GenericRecord(org.apache.avro.generic.GenericRecord) Test(org.testng.annotations.Test)

Example 48 with WorkUnitState

use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.

the class ObjectStoreDeleteConverterTest method convertLongObjId.

@Test
public void convertLongObjId() throws Exception {
    WorkUnitState wu = new WorkUnitState();
    wu.setProp(ObjectStoreDeleteConverter.OBJECT_ID_FIELD, "objectId");
    ObjectStoreDeleteConverter converter = new ObjectStoreDeleteConverter();
    converter.init(wu);
    Schema schema = new Schema.Parser().parse("{ \"type\" : \"record\", \"name\" : \"test_schema\", \"namespace\" : \"com.gobblin.test\", " + "\"fields\" : [ { \"name\" : \"objectId\", \"type\" : \"long\"} ], \"doc:\" : \"\" }");
    GenericRecord datum = new GenericData.Record(schema);
    long objId = 1234l;
    datum.put("objectId", objId);
    Assert.assertEquals(Iterables.getFirst(converter.convertRecord(converter.convertSchema(schema, wu), datum, wu), null).getObjectId(), Longs.toByteArray(objId));
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) Schema(org.apache.avro.Schema) GenericRecord(org.apache.avro.generic.GenericRecord) GenericRecord(org.apache.avro.generic.GenericRecord) Test(org.testng.annotations.Test)

Example 49 with WorkUnitState

use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.

the class ObjectToStringConverterTest method testConvertRecord.

/**
 * Test for {@link ObjectToStringConverter#convertRecord(Class, Object, WorkUnitState)}. Checks that the convertRecord
 * method properly converts an {@link Object} to its String equivalent.
 */
@Test
public void testConvertRecord() throws DataConversionException {
    WorkUnitState workUnitState = new WorkUnitState();
    ObjectToStringConverter converter = new ObjectToStringConverter();
    converter.init(workUnitState);
    // Test that an Integer can properly be converted to a String
    Integer integerValue = new Integer(1);
    Iterator<String> itr = converter.convertRecord(String.class, integerValue, workUnitState).iterator();
    Assert.assertTrue(itr.hasNext());
    Assert.assertEquals(itr.next(), "1");
    Assert.assertTrue(!itr.hasNext());
    // Test that a Long can properly be converted to a String
    Long longValue = new Long(2);
    itr = converter.convertRecord(String.class, longValue, workUnitState).iterator();
    Assert.assertTrue(itr.hasNext());
    Assert.assertEquals(itr.next(), "2");
    Assert.assertTrue(!itr.hasNext());
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) Test(org.testng.annotations.Test)

Example 50 with WorkUnitState

use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.

the class StringFilterConverterTest method testConvertRecordWithNoRegex.

/**
 * Test for {@link StringFilterConverter#convertRecord(Class, String, WorkUnitState)} with a blank regex.
 */
@Test
public void testConvertRecordWithNoRegex() throws DataConversionException {
    WorkUnitState workUnitState = new WorkUnitState();
    StringFilterConverter converter = new StringFilterConverter();
    converter.init(workUnitState);
    String test = "HelloWorld";
    Iterator<String> itr = converter.convertRecord(String.class, test, workUnitState).iterator();
    Assert.assertTrue(!itr.hasNext());
}
Also used : WorkUnitState(org.apache.gobblin.configuration.WorkUnitState) Test(org.testng.annotations.Test)

Aggregations

WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)222 Test (org.testng.annotations.Test)143 State (org.apache.gobblin.configuration.State)48 SourceState (org.apache.gobblin.configuration.SourceState)39 WorkUnit (org.apache.gobblin.source.workunit.WorkUnit)39 Schema (org.apache.avro.Schema)29 Path (org.apache.hadoop.fs.Path)26 GenericRecord (org.apache.avro.generic.GenericRecord)19 JsonObject (com.google.gson.JsonObject)17 ArrayList (java.util.ArrayList)16 File (java.io.File)14 TaskState (org.apache.hadoop.mapreduce.v2.api.records.TaskState)12 List (java.util.List)11 Configuration (org.apache.hadoop.conf.Configuration)11 IOException (java.io.IOException)10 LongWatermark (org.apache.gobblin.source.extractor.extract.LongWatermark)10 Extract (org.apache.gobblin.source.workunit.Extract)10 FileSystem (org.apache.hadoop.fs.FileSystem)10 Closer (com.google.common.io.Closer)8 JsonParser (com.google.gson.JsonParser)8