use of org.apache.metron.statistics.OnlineStatisticsProvider in project metron by apache.
the class KafkaEmitterTest method testInvalidType.
/**
* Values destined for Kafka can only be serialized into text, which limits the types of values
* that can result from a triage expression. Only primitive types and Strings are allowed.
*/
@Test
public void testInvalidType() throws Exception {
// create one invalid expression and one valid expression
Map<String, Object> triageValues = ImmutableMap.of("invalid", new OnlineStatisticsProvider(), "valid", 4);
ProfileMeasurement measurement = new ProfileMeasurement().withProfileName("profile").withEntity("entity").withPeriod(20000, 15, TimeUnit.MINUTES).withTriageValues(triageValues).withDefinition(profile);
handler.emit(measurement, collector);
ArgumentCaptor<Values> arg = ArgumentCaptor.forClass(Values.class);
verify(collector, times(1)).emit(eq(handler.getStreamId()), arg.capture());
Values values = arg.getValue();
assertTrue(values.get(0) instanceof JSONObject);
// only the triage expression value itself should have been skipped, all others should be there
JSONObject actual = (JSONObject) values.get(0);
assertEquals(measurement.getDefinition().getProfile(), actual.get("profile"));
assertEquals(measurement.getEntity(), actual.get("entity"));
assertEquals(measurement.getPeriod().getPeriod(), actual.get("period"));
assertEquals(measurement.getPeriod().getStartTimeMillis(), actual.get("period.start"));
assertEquals(measurement.getPeriod().getEndTimeMillis(), actual.get("period.end"));
assertNotNull(actual.get("timestamp"));
assertEquals("profiler", actual.get("source.type"));
// the invalid expression should be skipped due to invalid type
assertFalse(actual.containsKey("invalid"));
// but the valid expression should still be there
assertEquals(triageValues.get("valid"), actual.get("valid"));
}
Aggregations