Search in sources :

Example 6 with TimeSeriesChart

use of org.ff4j.audit.chart.TimeSeriesChart 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());
}
Also used : TimeSeriesChart(org.ff4j.audit.chart.TimeSeriesChart) EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Example 7 with TimeSeriesChart

use of org.ff4j.audit.chart.TimeSeriesChart in project ff4j by ff4j.

the class AuditBeanTest method testTimeSerieChart.

@Test
public void testTimeSerieChart() {
    long top = System.currentTimeMillis();
    TimeSeriesChart t1 = new TimeSeriesChart(top - 100000, top + 100000, TimeUnit.MINUTES);
    new TimeSeriesChart(top - 100000, top + 100000, TimeUnit.HOURS);
    new TimeSeriesChart(top - 100000, top + 100000, TimeUnit.DAYS);
    new TimeSeriesChart(top - 100000, top + 100000, TimeUnit.SECONDS);
    t1.addEvent(new EventBuilder().name("f1").build());
    t1.addEvent(new EventBuilder().name("f2").build());
    Assert.assertNotNull(t1.getSdf());
    Assert.assertNotNull(t1.toString());
    TimeSeriesChart tsc1 = new TimeSeriesChart();
    tsc1.setSdf(new SimpleDateFormat("yyyy"));
    tsc1.setTimeSlots(new ArrayList<String>());
    tsc1.setSeries(new HashMap<String, Serie<Map<String, MutableHitCount>>>());
    Assert.assertNotNull(tsc1);
}
Also used : EventBuilder(org.ff4j.audit.EventBuilder) TimeSeriesChart(org.ff4j.audit.chart.TimeSeriesChart) SimpleDateFormat(java.text.SimpleDateFormat) Serie(org.ff4j.audit.chart.Serie) MutableHitCount(org.ff4j.audit.MutableHitCount) Test(org.junit.Test)

Example 8 with TimeSeriesChart

use of org.ff4j.audit.chart.TimeSeriesChart in project ff4j by ff4j.

the class EventRepositoryRedis method getFeatureUsageHistory.

/**
 * {@inheritDoc}
 */
@Override
public TimeSeriesChart getFeatureUsageHistory(EventQueryDefinition query, TimeUnit tu) {
    TimeSeriesChart tsc = new TimeSeriesChart(query.getFrom(), query.getTo(), tu);
    Set<String> events = getEventsFromRedis(query);
    for (String event : events) {
        tsc.addEvent(marshallEvent(event));
    }
    return tsc;
}
Also used : TimeSeriesChart(org.ff4j.audit.chart.TimeSeriesChart)

Example 9 with TimeSeriesChart

use of org.ff4j.audit.chart.TimeSeriesChart in project ff4j by ff4j.

the class EventRepositoryTestSupport 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());
}
Also used : TimeSeriesChart(org.ff4j.audit.chart.TimeSeriesChart) EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Example 10 with TimeSeriesChart

use of org.ff4j.audit.chart.TimeSeriesChart in project ff4j by ff4j.

the class EventRepositoryHBase 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;
}
Also used : TimeSeriesChart(org.ff4j.audit.chart.TimeSeriesChart) Event(org.ff4j.audit.Event)

Aggregations

TimeSeriesChart (org.ff4j.audit.chart.TimeSeriesChart)11 Event (org.ff4j.audit.Event)8 EventQueryDefinition (org.ff4j.audit.EventQueryDefinition)3 Test (org.junit.Test)3 MutableHitCount (org.ff4j.audit.MutableHitCount)2 Serie (org.ff4j.audit.chart.Serie)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 EventBuilder (org.ff4j.audit.EventBuilder)1 EventSeries (org.ff4j.audit.EventSeries)1