use of org.ff4j.audit.EventQueryDefinition in project ff4j by ff4j.
the class AbstractEventRepositoryTest method testFeatureUsageBarCharts.
@Test
public void testFeatureUsageBarCharts() throws InterruptedException {
long start = System.currentTimeMillis();
// Create Event
repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", EventConstants.ACTION_CREATE));
for (int i = 0; i < 8; i++) {
Thread.sleep(100);
repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OK));
repo.saveEvent(new Event(SOURCE_WEB, TARGET_FEATURE, "f2", ACTION_CHECK_OK));
}
// Assert bar chart (2 bars with 8 and 8)
EventQueryDefinition testQuery = new EventQueryDefinition(start - 10, System.currentTimeMillis() + 10);
BarChart bChart = repo.getFeatureUsageBarChart(testQuery);
Assert.assertEquals(2, bChart.getChartBars().size());
Assert.assertEquals(new Integer(8), bChart.getChartBars().get(0).getValue());
Assert.assertEquals(new Integer(8), bChart.getChartBars().get(1).getValue());
Assert.assertNotNull(bChart.getChartBars().get(0).getColor());
Assert.assertNotNull(bChart.getChartBars().get(1).getColor());
}
use of org.ff4j.audit.EventQueryDefinition in project ff4j by ff4j.
the class AbstractEventRepositoryTest method testSaveAuditTrail.
@Test
public void testSaveAuditTrail() throws InterruptedException {
long start = System.currentTimeMillis();
Event evt1 = new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", EventConstants.ACTION_CREATE);
Assert.assertTrue(repo.saveEvent(evt1));
Thread.sleep(200);
Assert.assertEquals(1, repo.getAuditTrail(new EventQueryDefinition(start - 10, System.currentTimeMillis())).size());
}
use of org.ff4j.audit.EventQueryDefinition in project ff4j by ff4j.
the class AbstractEventRepositoryTest method testGetFeatureUsageHistory.
@Test
public void testGetFeatureUsageHistory() throws InterruptedException {
long start = System.currentTimeMillis();
repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CREATE));
for (int i = 0; i < 8; i++) {
Thread.sleep(100);
repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OK));
repo.saveEvent(new Event(SOURCE_WEB, TARGET_FEATURE, "f2", ACTION_CHECK_OK));
}
Thread.sleep(100);
// Then
EventQueryDefinition testQuery = new EventQueryDefinition(start - 20, System.currentTimeMillis());
TimeSeriesChart tsc = repo.getFeatureUsageHistory(testQuery, TimeUnit.HOURS);
Assert.assertEquals(1, tsc.getTimeSlots().size());
}
use of org.ff4j.audit.EventQueryDefinition in project ff4j by ff4j.
the class AbstractEventRepositoryTest method testHostHitCount.
/**
* TDD.
*/
@Test
public void testHostHitCount() throws InterruptedException {
long start = System.currentTimeMillis();
// When
for (int i = 0; i < 8; i++) {
Thread.sleep(100);
repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OK));
}
Thread.sleep(200);
// Then
EventQueryDefinition testQuery = new EventQueryDefinition(start, System.currentTimeMillis());
Map<String, MutableHitCount> mapOfHit = repo.getHostHitCount(testQuery);
Assert.assertEquals(1, mapOfHit.size());
Assert.assertEquals(1, mapOfHit.values().size());
}
use of org.ff4j.audit.EventQueryDefinition in project ff4j by ff4j.
the class AuditBeanTest method testEventQueryDefinition.
@Test
public void testEventQueryDefinition() {
EventQueryDefinition eqd = new EventQueryDefinition();
eqd.setFrom(System.currentTimeMillis() - 100);
eqd.setTo(System.currentTimeMillis() + 100);
eqd.setHostFilters(Util.set("localhost"));
eqd.setSourceFilters(Util.set("JAVA_API"));
eqd.setActionFilters(Util.set(EventConstants.ACTION_CHECK_OK));
eqd.setNamesFilter(Util.set("F1"));
eqd.setFrom(new Long(eqd.getFrom()));
eqd.setTo(new Long(eqd.getTo()));
eqd.addFilterAction(EventConstants.ACTION_CLEAR);
eqd.addFilterHost("MC");
eqd.addFilterSource("WEB_CONSOLE");
eqd.addFilterName("f2");
Assert.assertTrue(eqd.getActionFilters().contains(EventConstants.ACTION_CHECK_OK));
Assert.assertFalse(eqd.matchAction(null));
Assert.assertTrue(eqd.matchAction(EventConstants.ACTION_CHECK_OK));
Assert.assertFalse(eqd.matchAction(EventConstants.ACTION_CHECK_OFF));
Assert.assertFalse(eqd.matchSource(null));
Assert.assertTrue(eqd.matchSource("JAVA_API"));
Assert.assertFalse(eqd.matchSource(EventConstants.ACTION_CHECK_OFF));
Assert.assertFalse(eqd.matchHost(null));
Assert.assertTrue(eqd.matchHost("localhost"));
Assert.assertFalse(eqd.matchHost(EventConstants.ACTION_CHECK_OFF));
Assert.assertFalse(eqd.matchName(null));
Assert.assertTrue(eqd.matchName("f2"));
Assert.assertFalse(eqd.matchName(EventConstants.ACTION_CHECK_OFF));
}
Aggregations