use of org.apache.metron.profiler.StandAloneProfiler in project metron by apache.
the class ProfilerFunctionsTest method testProfilerInitNoProfiles.
@Test
public void testProfilerInitNoProfiles() {
state.put("config", "{ \"profiles\" : [] }");
StandAloneProfiler profiler = run("PROFILER_INIT(config)", StandAloneProfiler.class);
assertNotNull(profiler);
assertEquals(0, profiler.getProfileCount());
assertEquals(0, profiler.getMessageCount());
assertEquals(0, profiler.getRouteCount());
}
use of org.apache.metron.profiler.StandAloneProfiler in project metron by apache.
the class ProfilerFunctionsTest method testProfilerApplyWithString.
@Test
public void testProfilerApplyWithString() {
// initialize the profiler
state.put("config", helloWorldProfilerDef);
StandAloneProfiler profiler = run("PROFILER_INIT(config)", StandAloneProfiler.class);
state.put("profiler", profiler);
// apply a message to the profiler
state.put("message", message);
StandAloneProfiler result = run("PROFILER_APPLY(message, profiler)", StandAloneProfiler.class);
// validate
assertSame(profiler, result);
assertEquals(1, profiler.getProfileCount());
assertEquals(1, profiler.getMessageCount());
assertEquals(1, profiler.getRouteCount());
}
use of org.apache.metron.profiler.StandAloneProfiler in project metron by apache.
the class ProfilerFunctionsTest method testProfilerApplyWithEmptyList.
@Test
public void testProfilerApplyWithEmptyList() {
// initialize the profiler
state.put("config", helloWorldProfilerDef);
StandAloneProfiler profiler = run("PROFILER_INIT(config)", StandAloneProfiler.class);
state.put("profiler", profiler);
// apply a message to the profiler
state.put("messages", "[ ]");
StandAloneProfiler result = run("PROFILER_APPLY(messages, profiler)", StandAloneProfiler.class);
// validate
assertSame(profiler, result);
assertEquals(1, profiler.getProfileCount());
assertEquals(0, profiler.getMessageCount());
assertEquals(0, profiler.getRouteCount());
}
use of org.apache.metron.profiler.StandAloneProfiler in project metron by apache.
the class ProfilerFunctionsTest method testProfilerApplyWithJSONObject.
@Test
public void testProfilerApplyWithJSONObject() throws Exception {
// initialize the profiler
state.put("config", helloWorldProfilerDef);
StandAloneProfiler profiler = run("PROFILER_INIT(config)", StandAloneProfiler.class);
state.put("profiler", profiler);
// apply a message to the profiler
JSONParser parser = new JSONParser();
JSONObject jsonObject = (JSONObject) parser.parse(message);
state.put("jsonObj", jsonObject);
StandAloneProfiler result = run("PROFILER_APPLY(jsonObj, profiler)", StandAloneProfiler.class);
// validate
assertSame(profiler, result);
assertEquals(1, profiler.getProfileCount());
assertEquals(1, profiler.getMessageCount());
assertEquals(1, profiler.getRouteCount());
}
use of org.apache.metron.profiler.StandAloneProfiler in project metron by apache.
the class ProfilerFunctionsTest method testProfilerFlush.
@Test
public void testProfilerFlush() {
// initialize the profiler
state.put("config", helloWorldProfilerDef);
StandAloneProfiler profiler = run("PROFILER_INIT(config)", StandAloneProfiler.class);
state.put("profiler", profiler);
// apply a message to the profiler
state.put("message", message);
run("PROFILER_APPLY(message, profiler)", StandAloneProfiler.class);
// flush the profiles
List<Map<String, Object>> measurements = run("PROFILER_FLUSH(profiler)", List.class);
// validate
assertNotNull(measurements);
assertEquals(1, measurements.size());
Map<String, Object> measurement = measurements.get(0);
assertEquals("hello-world", measurement.get("profile"));
assertEquals("10.0.0.1", measurement.get("entity"));
assertEquals(1, measurement.get("value"));
assertEquals(Collections.emptyList(), measurement.get("groups"));
}
Aggregations