use of org.apache.metron.parsers.BasicParser in project metron by apache.
the class ParserBoltTest method testFieldTransformationPriorToValidation.
@Test
public void testFieldTransformationPriorToValidation() {
String sensorType = "dummy";
RecordingWriter recordingWriter = new RecordingWriter();
// create a parser which acts like a basic parser but returns no timestamp field.
BasicParser dummyParser = new BasicParser() {
@Override
public void init() {
}
@Override
public List<JSONObject> parse(byte[] rawMessage) {
return ImmutableList.of(new JSONObject() {
{
put("data", "foo");
put("timestampstr", "2016-01-05 17:02:30");
put("original_string", "blah");
}
});
}
@Override
public void configure(Map<String, Object> config) {
}
};
ParserBolt parserBolt = new ParserBolt("zookeeperUrl", sensorType, dummyParser, new WriterHandler(recordingWriter)) {
@Override
protected SensorParserConfig getSensorParserConfig() {
try {
return SensorParserConfig.fromBytes(Bytes.toBytes(csvWithFieldTransformations));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
protected ConfigurationsUpdater<ParserConfigurations> createUpdater() {
return ParserBoltTest.createUpdater();
}
};
parserBolt.setCuratorFramework(client);
parserBolt.setZKCache(cache);
parserBolt.prepare(new HashMap(), topologyContext, outputCollector);
when(t1.getBinary(0)).thenReturn(new byte[] {});
parserBolt.execute(t1);
Assert.assertEquals(1, recordingWriter.getRecords().size());
long expected = 1452013350000L;
Assert.assertEquals(expected, recordingWriter.getRecords().get(0).get("timestamp"));
}
Aggregations