Search in sources :

Example 21 with Event

use of org.ff4j.audit.Event in project ff4j by ff4j.

the class EventWorkerTest method testErrorOnSubmitEventPublisher.

@Test
public void testErrorOnSubmitEventPublisher() {
    // Given
    EventRepository er = mock(EventRepository.class);
    Event evt = new Event(SOURCE_JAVA, TARGET_FEATURE, "F1", ACTION_CHECK_OFF);
    doThrow(new RuntimeException("Erreur")).when(er).saveEvent(evt);
    EventPublisher evtPublisher = new EventPublisher(er);
    evtPublisher.publish(evt);
    Assert.assertNotNull(evt);
}
Also used : EventPublisher(org.ff4j.audit.EventPublisher) Event(org.ff4j.audit.Event) InMemoryEventRepository(org.ff4j.audit.repository.InMemoryEventRepository) EventRepository(org.ff4j.audit.repository.EventRepository) Test(org.junit.Test)

Example 22 with Event

use of org.ff4j.audit.Event in project ff4j by ff4j.

the class EventWorkerTest method testEventWorkerCall.

@Test
public void testEventWorkerCall() throws Exception {
    // Given
    EventRepository er = mock(EventRepository.class);
    Event evt = new Event(SOURCE_JAVA, TARGET_FEATURE, "F1", ACTION_CHECK_OK);
    when(er.saveEvent(evt)).thenReturn(false);
    EventWorker ew = new EventWorker(evt, er);
    // When
    ew.call();
}
Also used : EventWorker(org.ff4j.audit.EventWorker) Event(org.ff4j.audit.Event) InMemoryEventRepository(org.ff4j.audit.repository.InMemoryEventRepository) EventRepository(org.ff4j.audit.repository.EventRepository) Test(org.junit.Test)

Example 23 with Event

use of org.ff4j.audit.Event in project ff4j by ff4j.

the class EventRepositoryRedis method getUsageCount.

private Map<String, MutableHitCount> getUsageCount(EventQueryDefinition query, Types type) {
    Map<String, MutableHitCount> hitCount = new HashMap<>();
    // Get events from Redis between the time range.
    Set<String> events = getEventsFromRedis(query);
    // Loop through create the buckets.
    for (String event : events) {
        Event eventObject = marshallEvent(event);
        String value = getValueFromAttribute(type, eventObject);
        MutableHitCount mutableHitCount = hitCount.get(value);
        if (mutableHitCount != null) {
            mutableHitCount.inc();
        } else {
            mutableHitCount = new MutableHitCount(1);
        }
        hitCount.put(value, mutableHitCount);
    }
    return hitCount;
}
Also used : HashMap(java.util.HashMap) Event(org.ff4j.audit.Event) MutableHitCount(org.ff4j.audit.MutableHitCount)

Example 24 with Event

use of org.ff4j.audit.Event in project ff4j by ff4j.

the class EventRepositoryTestSupport method testGetEventByUID.

/**
 * TDD.
 */
@Test
public void testGetEventByUID() throws InterruptedException {
    // Given
    String dummyId = "1234-5678-9012-3456";
    Event evt1 = new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OFF);
    evt1.setUuid(dummyId);
    // When
    repo.saveEvent(evt1);
    // Let the store to be updated
    Thread.sleep(100);
    // Then
    Event evt = repo.getEventByUUID(dummyId, System.currentTimeMillis());
    Assert.assertNotNull(evt);
}
Also used : Event(org.ff4j.audit.Event) Test(org.junit.Test)

Example 25 with Event

use of org.ff4j.audit.Event 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)

Aggregations

Event (org.ff4j.audit.Event)56 Test (org.junit.Test)32 EventQueryDefinition (org.ff4j.audit.EventQueryDefinition)22 MutableHitCount (org.ff4j.audit.MutableHitCount)15 EventSeries (org.ff4j.audit.EventSeries)8 TimeSeriesChart (org.ff4j.audit.chart.TimeSeriesChart)8 JestResult (io.searchbox.client.JestResult)6 HashMap (java.util.HashMap)5 EventRepository (org.ff4j.audit.repository.EventRepository)4 InMemoryEventRepository (org.ff4j.audit.repository.InMemoryEventRepository)4 Date (java.util.Date)2 TreeMap (java.util.TreeMap)2 EventPublisher (org.ff4j.audit.EventPublisher)2 EventWorker (org.ff4j.audit.EventWorker)2 BarChart (org.ff4j.audit.chart.BarChart)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 FF4j (org.ff4j.FF4j)1 Serie (org.ff4j.audit.chart.Serie)1 MongoEventMapper (org.ff4j.mongo.mapper.MongoEventMapper)1