Search in sources :

Example 1 with StandAloneProfiler

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());
}
Also used : StandAloneProfiler(org.apache.metron.profiler.StandAloneProfiler) Test(org.junit.Test)

Example 2 with StandAloneProfiler

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());
}
Also used : StandAloneProfiler(org.apache.metron.profiler.StandAloneProfiler) Test(org.junit.Test)

Example 3 with StandAloneProfiler

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());
}
Also used : StandAloneProfiler(org.apache.metron.profiler.StandAloneProfiler) Test(org.junit.Test)

Example 4 with StandAloneProfiler

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());
}
Also used : StandAloneProfiler(org.apache.metron.profiler.StandAloneProfiler) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) Test(org.junit.Test)

Example 5 with StandAloneProfiler

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"));
}
Also used : StandAloneProfiler(org.apache.metron.profiler.StandAloneProfiler) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

StandAloneProfiler (org.apache.metron.profiler.StandAloneProfiler)10 Test (org.junit.Test)10 JSONObject (org.json.simple.JSONObject)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DefaultStellarStatefulExecutor (org.apache.metron.stellar.common.DefaultStellarStatefulExecutor)1 StellarStatefulExecutor (org.apache.metron.stellar.common.StellarStatefulExecutor)1 SimpleFunctionResolver (org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver)1 JSONParser (org.json.simple.parser.JSONParser)1