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());
}
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());
}
Aggregations