use of org.ff4j.audit.Event in project ff4j by ff4j.
the class JdbcEventRepository method getFeatureUsageHistory.
/**
* {@inheritDoc}
*/
@Override
public TimeSeriesChart getFeatureUsageHistory(EventQueryDefinition query, TimeUnit units) {
// Create the interval depending on units
TimeSeriesChart tsc = new TimeSeriesChart(query.getFrom(), query.getTo(), units);
// Search All events
Iterator<Event> iterEvent = searchFeatureUsageEvents(query).iterator();
// Dispatch events into time slots
while (iterEvent.hasNext()) {
tsc.addEvent(iterEvent.next());
}
return tsc;
}
use of org.ff4j.audit.Event in project ff4j by ff4j.
the class JdbcEventMapper method mapEvent.
/**
* Unmarshall a resultset to Event.
*
* @param rs
* current line
* @return
* bean populated
* @throws SQLException
* cannot read SQL result
*/
public Event mapEvent(ResultSet rs) throws SQLException {
// Feature
Event evt = new Event();
evt.setUuid(rs.getString(COL_EVENT_UUID));
evt.setTimestamp(rs.getTimestamp(COL_EVENT_TIME).getTime());
evt.setType(rs.getString(COL_EVENT_TYPE));
evt.setName(rs.getString(COL_EVENT_NAME));
evt.setAction(rs.getString(COL_EVENT_ACTION));
evt.setHostName(rs.getString(COL_EVENT_HOSTNAME));
evt.setSource(rs.getString(COL_EVENT_SOURCE));
evt.setDuration(rs.getLong(COL_EVENT_DURATION));
evt.setUser(rs.getString(COL_EVENT_USER));
evt.setValue(rs.getString(COL_EVENT_VALUE));
evt.setCustomKeys(MappingUtil.toMap(rs.getString(COL_EVENT_KEYS)));
return evt;
}
use of org.ff4j.audit.Event in project ff4j by ff4j.
the class FF4jTest method monitoringAudit.
@Test
public void monitoringAudit() {
// Given
FF4j ff4j = new FF4j();
ff4j.setEventPublisher(new EventPublisher());
ff4j.setEventRepository(new InMemoryEventRepository());
ff4j.removeCurrentContext();
ff4j.getCurrentContext();
// When
ff4j.stop();
// When
ff4j.setEventPublisher(null);
ff4j.getEventPublisher();
ff4j.stop();
// When
Event evt = new Event("f1", EventConstants.TARGET_FEATURE, "f2", EventConstants.ACTION_CHECK_OK);
Assert.assertNotNull(evt.toJson());
Assert.assertNotNull(evt.toString());
// When
EventPublisher ep = new EventPublisher();
new EventPublisher(ep.getRepository(), null);
ep.setRepository(new InMemoryEventRepository());
// Then
Assert.assertNotNull(ep.getRepository());
}
use of org.ff4j.audit.Event in project ff4j by ff4j.
the class AbstractEventRepositoryTest method testSearchFeatureUsageEvents.
@Test
public void testSearchFeatureUsageEvents() 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());
EventSeries es = repo.searchFeatureUsageEvents(testQuery);
Assert.assertEquals(16, es.size());
// Then
}
use of org.ff4j.audit.Event 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());
}
Aggregations