Search in sources :

Example 21 with MutableHitCount

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

the class EventRepositoryTestSupport method testFeatureUsageHitCount.

/**
 * TDD.
 */
@Test
public void testFeatureUsageHitCount() throws InterruptedException {
    long start = System.currentTimeMillis();
    // Given empty event repository
    // When
    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, System.currentTimeMillis());
    // Assert Pie Chart (2 sectors with 8 and 8)
    Map<String, MutableHitCount> mapOfHit = repo.getFeatureUsageHitCount(testQuery);
    Assert.assertEquals(2, mapOfHit.size());
    Assert.assertTrue(mapOfHit.containsKey("f1"));
    Assert.assertTrue(mapOfHit.containsKey("f2"));
    Assert.assertEquals(8, mapOfHit.get("f1").get());
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) MutableHitCount(org.ff4j.audit.MutableHitCount) Test(org.junit.Test)

Example 22 with MutableHitCount

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

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

Example 23 with MutableHitCount

use of org.ff4j.audit.MutableHitCount 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 24 with MutableHitCount

use of org.ff4j.audit.MutableHitCount 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 25 with MutableHitCount

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

the class AbstractEventRepositoryTest 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)

Aggregations

MutableHitCount (org.ff4j.audit.MutableHitCount)27 Event (org.ff4j.audit.Event)15 HashMap (java.util.HashMap)14 Test (org.junit.Test)10 EventQueryDefinition (org.ff4j.audit.EventQueryDefinition)8 ResultSet (com.datastax.driver.core.ResultSet)4 Row (com.datastax.driver.core.Row)4 JestResult (io.searchbox.client.JestResult)4 Map (java.util.Map)3 Timestamp (java.sql.Timestamp)2 Date (java.util.Date)2 TreeMap (java.util.TreeMap)2 Serie (org.ff4j.audit.chart.Serie)2 TimeSeriesChart (org.ff4j.audit.chart.TimeSeriesChart)2 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 SimpleDateFormat (java.text.SimpleDateFormat)1