use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.
the class KafkaEmitterTest method testStringIsValidType.
/**
* 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 testStringIsValidType() throws Exception {
ProfileMeasurement measurement = new ProfileMeasurement().withProfileName("profile").withEntity("entity").withPeriod(20000, 15, TimeUnit.MINUTES).withTriageValues(Collections.singletonMap("triage-key", "value")).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);
JSONObject actual = (JSONObject) values.get(0);
// the triage expression is valid
assertEquals(measurement.getTriageValues().get("triage-key"), actual.get("triage-key"));
}
use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.
the class KafkaEmitterTest method testSerialization.
/**
* The handler must serialize the ProfileMeasurement into a JSONObject.
*/
@Test
public void testSerialization() throws Exception {
ProfileMeasurement measurement = new ProfileMeasurement().withProfileName("profile").withEntity("entity").withPeriod(20000, 15, TimeUnit.MINUTES).withTriageValues(Collections.singletonMap("triage-key", "triage-value")).withDefinition(profile);
handler.emit(measurement, collector);
ArgumentCaptor<Values> arg = ArgumentCaptor.forClass(Values.class);
verify(collector, times(1)).emit(eq(handler.getStreamId()), arg.capture());
// expect a JSONObject
Values values = arg.getValue();
assertTrue(values.get(0) instanceof JSONObject);
// validate the json
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"));
assertEquals(measurement.getTriageValues().get("triage-key"), actual.get("triage-key"));
assertNotNull(actual.get("timestamp"));
assertEquals("profiler", actual.get("source.type"));
}
use of org.apache.metron.profiler.ProfileMeasurement 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"));
}
use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.
the class KafkaEmitterTest method testIntegerIsValidType.
/**
* 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 testIntegerIsValidType() throws Exception {
ProfileMeasurement measurement = new ProfileMeasurement().withProfileName("profile").withEntity("entity").withPeriod(20000, 15, TimeUnit.MINUTES).withTriageValues(Collections.singletonMap("triage-key", 123)).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);
JSONObject actual = (JSONObject) values.get(0);
// the triage expression is valid
assertEquals(measurement.getTriageValues().get("triage-key"), actual.get("triage-key"));
}
use of org.apache.metron.profiler.ProfileMeasurement in project metron by apache.
the class ProfileBuilderBoltTest method testDoNotEmitWhenNoFlush.
/**
* If the {@code FlushSignal} tells the bolt NOT to flush, nothing should be emitted.
*/
@Test
public void testDoNotEmitWhenNoFlush() throws Exception {
ProfileBuilderBolt bolt = createBolt();
// create a profile measurement
ProfileMeasurement m = new ProfileMeasurement().withEntity("entity1").withProfileName("profile1").withPeriod(1000, 500, TimeUnit.MILLISECONDS).withProfileValue(22);
// create a mock that returns the profile measurement above
MessageDistributor distributor = mock(MessageDistributor.class);
when(distributor.flush()).thenReturn(Collections.singletonList(m));
bolt.withMessageDistributor(distributor);
// no flush signal
flushSignal.setFlushNow(false);
// execute the bolt
Tuple tuple1 = createTuple("entity1", message1, profile1, 1000L);
TupleWindow tupleWindow = createWindow(tuple1);
bolt.execute(tupleWindow);
// nothing should have been emitted
getProfileMeasurements(outputCollector, 0);
}
Aggregations