Search in sources :

Example 6 with WorkUnitState

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

the class GobblinMCEPublisherTest method testPublishGMCEForORC.

@Test
public void testPublishGMCEForORC() throws IOException {
    GobblinMCEProducer producer = Mockito.mock(GobblinMCEProducer.class);
    Mockito.doCallRealMethod().when(producer).getGobblinMetadataChangeEvent(anyMap(), anyList(), anyList(), anyMap(), any(), any());
    Mockito.doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            GobblinMetadataChangeEvent gmce = producer.getGobblinMetadataChangeEvent((Map<Path, Metrics>) args[0], null, null, (Map<String, String>) args[1], OperationType.add_files, SchemaSource.SCHEMAREGISTRY);
            Assert.assertEquals(gmce.getNewFiles().size(), 1);
            FileSystem fs = FileSystem.get(new Configuration());
            Charset charset = Charset.forName("UTF-8");
            CharsetEncoder encoder = charset.newEncoder();
            Assert.assertEquals(gmce.getNewFiles().get(0).getFilePath(), orcFilePath.makeQualified(fs.getUri(), new Path("/")).toString());
            Assert.assertEquals(gmce.getNewFiles().get(0).getFileMetrics().getLowerBounds().get(1).getValue(), encoder.encode(CharBuffer.wrap("Alyssa")));
            Assert.assertEquals(gmce.getNewFiles().get(0).getFileMetrics().getUpperBounds().get(1).getValue(), encoder.encode(CharBuffer.wrap("Bob")));
            return null;
        }
    }).when(producer).sendGMCE(anyMap(), anyList(), anyList(), anyMap(), any(), any());
    WorkUnitState state = new WorkUnitState();
    setGMCEPublisherStateForOrcFile(state);
    Mockito.doCallRealMethod().when(producer).setState(state);
    producer.setState(state);
    GobblinMCEPublisher publisher = new GobblinMCEPublisher(state, producer);
    publisher.publishData(Arrays.asList(state));
}
Also used : Path(org.apache.hadoop.fs.Path) GobblinMetadataChangeEvent(org.apache.gobblin.metadata.GobblinMetadataChangeEvent) Configuration(org.apache.hadoop.conf.Configuration) WorkUnitState(gobblin.configuration.WorkUnitState) GobblinMCEProducer(org.apache.gobblin.iceberg.GobblinMCEProducer) Charset(java.nio.charset.Charset) CharsetEncoder(java.nio.charset.CharsetEncoder) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FileSystem(org.apache.hadoop.fs.FileSystem) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 7 with WorkUnitState

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

the class GrokToJsonConverterTest method convertOutputWithNonNullableFieldsShouldThrowDataConversionException.

@Test(expectedExceptions = DataConversionException.class)
public void convertOutputWithNonNullableFieldsShouldThrowDataConversionException() throws Exception {
    JsonParser parser = new JsonParser();
    String inputRecord = "10.121.123.104 - - [01/Nov/2012:21:01:17 +0100] \"GET /cpc/auth.do?loginsetup=true&targetPage=%2Fcpc%2F HTTP/1.1\" 302 466";
    JsonElement jsonElement = parser.parse(new InputStreamReader(getClass().getResourceAsStream("/converter/grok/schemaWithNonNullableFields.json")));
    JsonArray outputSchema = jsonElement.getAsJsonArray();
    GrokToJsonConverter grokToJsonConverter = new GrokToJsonConverter();
    WorkUnitState workUnitState = new WorkUnitState();
    workUnitState.setProp(GrokToJsonConverter.GROK_PATTERN, "^%{IPORHOST:clientip} (?:-|%{USER:ident}) (?:-|%{USER:auth}) \\[%{HTTPDATE:timestamp}\\] \\\"(?:%{WORD:verb} %{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|-)\\\" %{NUMBER:response} (?:-|%{NUMBER:bytes})");
    grokToJsonConverter.init(workUnitState);
    JsonObject actual = grokToJsonConverter.convertRecord(outputSchema, inputRecord, workUnitState).iterator().next();
    JsonObject expected = parser.parse(new InputStreamReader(getClass().getResourceAsStream("/converter/grok/convertedRecord.json"))).getAsJsonObject();
    grokToJsonConverter.close();
}
Also used : JsonArray(com.google.gson.JsonArray) InputStreamReader(java.io.InputStreamReader) JsonElement(com.google.gson.JsonElement) WorkUnitState(gobblin.configuration.WorkUnitState) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) Test(org.testng.annotations.Test)

Aggregations

WorkUnitState (gobblin.configuration.WorkUnitState)7 Test (org.testng.annotations.Test)6 JsonObject (com.google.gson.JsonObject)4 InputStreamReader (java.io.InputStreamReader)4 JsonArray (com.google.gson.JsonArray)3 JsonElement (com.google.gson.JsonElement)3 JsonParser (com.google.gson.JsonParser)3 Map (java.util.Map)3 GobblinMCEProducer (org.apache.gobblin.iceberg.GobblinMCEProducer)3 GobblinMetadataChangeEvent (org.apache.gobblin.metadata.GobblinMetadataChangeEvent)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Answer (org.mockito.stubbing.Answer)3 Configuration (org.apache.hadoop.conf.Configuration)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 Gson (com.google.gson.Gson)1 Type (java.lang.reflect.Type)1 Charset (java.nio.charset.Charset)1 CharsetEncoder (java.nio.charset.CharsetEncoder)1 BeforeClass (org.testng.annotations.BeforeClass)1