Search in sources :

Example 41 with Event

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

the class EventRepositoryTestSupport method testSaveCheckOff.

/**
 * TDD.
 */
@Test
public void testSaveCheckOff() throws InterruptedException {
    long start = System.currentTimeMillis();
    // Given
    Event evt1 = new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OFF);
    // When
    Assert.assertTrue(repo.saveEvent(evt1));
    Thread.sleep(100);
    // Then
    Assert.assertEquals(0, repo.getFeatureUsageTotalHitCount(new EventQueryDefinition(start, System.currentTimeMillis())));
    Assert.assertEquals(0, repo.getAuditTrail(new EventQueryDefinition(start, System.currentTimeMillis())).size());
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Example 42 with Event

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

the class EventRepositoryTestSupport method testSourceHitCount.

/**
 * TDD.
 */
@Test
public void testSourceHitCount() 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));
        repo.saveEvent(new Event(SOURCE_WEB, TARGET_FEATURE, "f2", ACTION_CHECK_OK));
    }
    Thread.sleep(200);
    repo.saveEvent(new Event(SOURCE_WEBAPI, TARGET_FEATURE, "f1", ACTION_CHECK_OK));
    Thread.sleep(200);
    // Then
    EventQueryDefinition testQuery = new EventQueryDefinition(start - 20, System.currentTimeMillis());
    Map<String, MutableHitCount> mapOfHit = repo.getSourceHitCount(testQuery);
    Assert.assertEquals(3, mapOfHit.size());
    Assert.assertTrue(mapOfHit.containsKey(SOURCE_JAVA));
    Assert.assertTrue(mapOfHit.containsKey(SOURCE_WEB));
    Assert.assertEquals(1, mapOfHit.get(SOURCE_WEBAPI).get());
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) MutableHitCount(org.ff4j.audit.MutableHitCount) Test(org.junit.Test)

Example 43 with Event

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

the class EventRepositoryTestSupport method testPurgeEvents.

/**
 * TDD.
 */
@Test
public void testPurgeEvents() throws InterruptedException {
    // Given, 2 events in the repo
    long topStart = System.currentTimeMillis();
    Event evtAudit = new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CREATE);
    evtAudit.setUuid("1234-5678-9012-3456");
    Event evtFeatureUsage = new Event(SOURCE_JAVA, TARGET_FEATURE, "f2", ACTION_CHECK_OK);
    evtFeatureUsage.setUuid("1234-5678-9012-3457");
    repo.saveEvent(evtAudit);
    repo.saveEvent(evtFeatureUsage);
    Thread.sleep(100);
    Assert.assertNotNull(repo.getEventByUUID(evtAudit.getUuid(), System.currentTimeMillis()));
    Assert.assertNotNull(repo.getEventByUUID(evtFeatureUsage.getUuid(), System.currentTimeMillis()));
    // When
    EventQueryDefinition testQuery = new EventQueryDefinition(topStart - 100, System.currentTimeMillis());
    repo.purgeAuditTrail(testQuery);
    // Then
    Assert.assertNull(repo.getEventByUUID(evtAudit.getUuid(), System.currentTimeMillis()));
    repo.purgeFeatureUsage(testQuery);
    Thread.sleep(100);
    Assert.assertNull(repo.getEventByUUID(evtFeatureUsage.getUuid(), System.currentTimeMillis()));
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Example 44 with Event

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

the class EventRepositoryTestSupport method testUserHitCount.

/**
 * TDD.
 */
@Test
public void testUserHitCount() throws InterruptedException {
    long start = System.currentTimeMillis();
    // When
    for (int i = 0; i < 8; i++) {
        Event e1 = new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OK);
        e1.setUser("JOHN");
        repo.saveEvent(e1);
        Thread.sleep(100);
        Event e2 = new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OK);
        e2.setUser("BOB");
        repo.saveEvent(e2);
        Thread.sleep(100);
    }
    Thread.sleep(200);
    // Then
    EventQueryDefinition testQuery = new EventQueryDefinition(start - 20, System.currentTimeMillis());
    Map<String, MutableHitCount> mapOfHit = repo.getUserHitCount(testQuery);
    Assert.assertEquals(2, mapOfHit.size());
    Assert.assertTrue(mapOfHit.containsKey("JOHN"));
    Assert.assertTrue(mapOfHit.containsKey("BOB"));
    Assert.assertEquals(8, mapOfHit.get("BOB").get());
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) MutableHitCount(org.ff4j.audit.MutableHitCount) Test(org.junit.Test)

Example 45 with Event

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

the class AbstractEventRepositoryTest method testSaveCheckOff.

/**
 * TDD.
 */
@Test
public void testSaveCheckOff() throws InterruptedException {
    long start = System.currentTimeMillis();
    // Given
    Event evt1 = new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OFF);
    // When
    Assert.assertTrue(repo.saveEvent(evt1));
    Thread.sleep(100);
    // Then
    Assert.assertEquals(0, repo.getFeatureUsageTotalHitCount(new EventQueryDefinition(start, System.currentTimeMillis())));
    Assert.assertEquals(0, repo.getAuditTrail(new EventQueryDefinition(start, System.currentTimeMillis())).size());
}
Also used : 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