Search in sources :

Example 6 with StandAloneProfiler

use of org.apache.metron.profiler.StandAloneProfiler in project metron by apache.

the class ProfilerFunctionsTest method testProfilerApplyWithMultipleMessagesInJSONString.

@Test
public void testProfilerApplyWithMultipleMessagesInJSONString() {
    // 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", messages);
    StandAloneProfiler result = run("PROFILER_APPLY(messages, profiler)", StandAloneProfiler.class);
    // validate
    assertSame(profiler, result);
    assertEquals(1, profiler.getProfileCount());
    assertEquals(3, profiler.getMessageCount());
    assertEquals(3, profiler.getRouteCount());
}
Also used : StandAloneProfiler(org.apache.metron.profiler.StandAloneProfiler) Test(org.junit.Test)

Example 7 with StandAloneProfiler

use of org.apache.metron.profiler.StandAloneProfiler in project metron by apache.

the class ProfilerFunctionsTest method testProfilerInitWithProfiles.

@Test
public void testProfilerInitWithProfiles() {
    state.put("config", helloWorldProfilerDef);
    StandAloneProfiler profiler = run("PROFILER_INIT(config)", StandAloneProfiler.class);
    assertNotNull(profiler);
    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 8 with StandAloneProfiler

use of org.apache.metron.profiler.StandAloneProfiler in project metron by apache.

the class ProfilerFunctionsTest method testProfilerInitWithNoGlobalConfig.

@Test
public void testProfilerInitWithNoGlobalConfig() {
    state.put("config", helloWorldProfilerDef);
    String expression = "PROFILER_INIT(config)";
    // use an executor with no GLOBAL_CONFIG defined in the context
    StellarStatefulExecutor executor = new DefaultStellarStatefulExecutor(new SimpleFunctionResolver().withClass(ProfilerFunctions.ProfilerInit.class).withClass(ProfilerFunctions.ProfilerApply.class).withClass(ProfilerFunctions.ProfilerFlush.class), Context.EMPTY_CONTEXT());
    StandAloneProfiler profiler = executor.execute(expression, state, StandAloneProfiler.class);
    assertNotNull(profiler);
    assertEquals(1, profiler.getProfileCount());
    assertEquals(0, profiler.getMessageCount());
    assertEquals(0, profiler.getRouteCount());
}
Also used : StandAloneProfiler(org.apache.metron.profiler.StandAloneProfiler) StellarStatefulExecutor(org.apache.metron.stellar.common.StellarStatefulExecutor) DefaultStellarStatefulExecutor(org.apache.metron.stellar.common.DefaultStellarStatefulExecutor) DefaultStellarStatefulExecutor(org.apache.metron.stellar.common.DefaultStellarStatefulExecutor) SimpleFunctionResolver(org.apache.metron.stellar.dsl.functions.resolver.SimpleFunctionResolver) Test(org.junit.Test)

Example 9 with StandAloneProfiler

use of org.apache.metron.profiler.StandAloneProfiler in project metron by apache.

the class ProfilerFunctionsTest method testProfilerApplyWithListOfMessages.

@Test
public void testProfilerApplyWithListOfMessages() {
    // 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("msg", message);
    StandAloneProfiler result = run("PROFILER_APPLY([msg, msg, msg], profiler)", StandAloneProfiler.class);
    // validate
    assertSame(profiler, result);
    assertEquals(1, profiler.getProfileCount());
    assertEquals(3, profiler.getMessageCount());
    assertEquals(3, profiler.getRouteCount());
}
Also used : StandAloneProfiler(org.apache.metron.profiler.StandAloneProfiler) Test(org.junit.Test)

Example 10 with StandAloneProfiler

use of org.apache.metron.profiler.StandAloneProfiler in project metron by apache.

the class ProfilerFunctionsTest method testProfilerApplyWithNullMessage.

@Test(expected = IllegalArgumentException.class)
public void testProfilerApplyWithNullMessage() {
    // initialize the profiler
    state.put("config", helloWorldProfilerDef);
    StandAloneProfiler profiler = run("PROFILER_INIT(config)", StandAloneProfiler.class);
    state.put("profiler", profiler);
    // there is no 'messages' variable - should throw exception
    run("PROFILER_APPLY(messages, profiler)", StandAloneProfiler.class);
}
Also used : StandAloneProfiler(org.apache.metron.profiler.StandAloneProfiler) 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