Search in sources :

Example 11 with ProfileConfig

use of org.apache.metron.common.configuration.profiler.ProfileConfig in project metron by apache.

the class DefaultMessageDistributorTest method testDistribute.

/**
 * Tests that one message can be distributed to one profile.
 */
@Test
public void testDistribute() throws Exception {
    // setup
    long timestamp = 100;
    ProfileConfig definition = createDefinition(profileOne);
    String entity = (String) messageOne.get("ip_src_addr");
    MessageRoute route = new MessageRoute(definition, entity);
    // distribute one message and flush
    distributor.distribute(messageOne, timestamp, route, context);
    List<ProfileMeasurement> measurements = distributor.flush();
    // expect one measurement coming from one profile
    assertEquals(1, measurements.size());
    ProfileMeasurement m = measurements.get(0);
    assertEquals(definition.getProfile(), m.getProfileName());
    assertEquals(entity, m.getEntity());
}
Also used : ProfileConfig(org.apache.metron.common.configuration.profiler.ProfileConfig) Test(org.junit.Test)

Example 12 with ProfileConfig

use of org.apache.metron.common.configuration.profiler.ProfileConfig in project metron by apache.

the class DefaultMessageDistributorTest method testProfilesShouldExpire.

/**
 * A profile should expire after a fixed period of time.
 */
@Test
public void testProfilesShouldExpire() throws Exception {
    // the ticker drives time to allow us to test cache expiration
    FixedTicker ticker = new FixedTicker();
    // setup
    ProfileConfig definition = createDefinition(profileOne);
    String entity = (String) messageOne.get("ip_src_addr");
    MessageRoute route = new MessageRoute(definition, entity);
    distributor = new DefaultMessageDistributor(periodDurationMillis, profileTimeToLiveMillis, maxNumberOfRoutes, ticker);
    // distribute one message
    distributor.distribute(messageOne, 100000, route, context);
    // advance time to just beyond the period duration
    ticker.advanceTime(profileTimeToLiveMillis + 1000, MILLISECONDS);
    // the profile should have expired by now
    assertEquals(1, distributor.flushExpired().size());
    assertEquals(0, distributor.flush().size());
}
Also used : ProfileConfig(org.apache.metron.common.configuration.profiler.ProfileConfig) Test(org.junit.Test)

Aggregations

ProfileConfig (org.apache.metron.common.configuration.profiler.ProfileConfig)12 Test (org.junit.Test)7 ProfilerConfig (org.apache.metron.common.configuration.profiler.ProfilerConfig)3 BaseBoltTest (org.apache.metron.test.bolt.BaseBoltTest)3 Values (org.apache.storm.tuple.Values)3 ProfileMeasurement (org.apache.metron.profiler.ProfileMeasurement)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 ArrayList (java.util.ArrayList)1 ProfileResult (org.apache.metron.common.configuration.profiler.ProfileResult)1 MessageRoute (org.apache.metron.profiler.MessageRoute)1 RowKeyBuilder (org.apache.metron.profiler.hbase.RowKeyBuilder)1 Tuple (org.apache.storm.tuple.Tuple)1 JSONObject (org.json.simple.JSONObject)1 Before (org.junit.Before)1