Search in sources :

Example 1 with EventPublisher

use of org.ff4j.audit.EventPublisher 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());
}
Also used : EventPublisher(org.ff4j.audit.EventPublisher) FF4j(org.ff4j.FF4j) InMemoryEventRepository(org.ff4j.audit.repository.InMemoryEventRepository) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Example 2 with EventPublisher

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

the class AbstractEventRepositoryTest method setUp.

/**
 * {@inheritDoc}
 */
@Before
public void setUp() throws Exception {
    repo = initRepository();
    publisher = new EventPublisher(repo);
    features = new ArrayList<Feature>(new InMemoryFeatureStore("ff4j.xml").readAll().values());
}
Also used : EventPublisher(org.ff4j.audit.EventPublisher) InMemoryFeatureStore(org.ff4j.store.InMemoryFeatureStore) Feature(org.ff4j.core.Feature) Before(org.junit.Before)

Example 3 with EventPublisher

use of org.ff4j.audit.EventPublisher 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 4 with EventPublisher

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

the class FF4j method init.

/**
 * Initialization of background components.
 */
private synchronized void init() {
    // Execution Context
    FlippingExecutionContext context = new FlippingExecutionContext();
    this.currentExecutionContext.set(context);
    // Event Publisher
    if (eventPublisher == null) {
        eventPublisher = new EventPublisher(eventRepository);
        this.shutdownEventPublisher = true;
    }
    // Audit is enabled, proxified stores for auditing
    if (isEnableAudit()) {
        if (fstore != null && !(fstore instanceof FeatureStoreAuditProxy)) {
            this.fstore = new FeatureStoreAuditProxy(this, fstore);
        }
        if (pStore != null && !(pStore instanceof PropertyStoreAuditProxy)) {
            this.pStore = new PropertyStoreAuditProxy(this, pStore);
        }
    } else {
        // Audit is disabled but could have been enabled before... removing PROXY if relevant
        if (fstore != null && fstore instanceof FeatureStoreAuditProxy) {
            this.fstore = ((FeatureStoreAuditProxy) fstore).getTarget();
        }
        if (pStore != null && pStore instanceof PropertyStoreAuditProxy) {
            this.pStore = ((PropertyStoreAuditProxy) pStore).getTarget();
        }
    }
    // Flag as OK
    this.initialized = true;
}
Also used : PropertyStoreAuditProxy(org.ff4j.audit.proxy.PropertyStoreAuditProxy) EventPublisher(org.ff4j.audit.EventPublisher) FeatureStoreAuditProxy(org.ff4j.audit.proxy.FeatureStoreAuditProxy) FlippingExecutionContext(org.ff4j.core.FlippingExecutionContext)

Aggregations

EventPublisher (org.ff4j.audit.EventPublisher)4 Event (org.ff4j.audit.Event)2 InMemoryEventRepository (org.ff4j.audit.repository.InMemoryEventRepository)2 Test (org.junit.Test)2 FF4j (org.ff4j.FF4j)1 FeatureStoreAuditProxy (org.ff4j.audit.proxy.FeatureStoreAuditProxy)1 PropertyStoreAuditProxy (org.ff4j.audit.proxy.PropertyStoreAuditProxy)1 EventRepository (org.ff4j.audit.repository.EventRepository)1 Feature (org.ff4j.core.Feature)1 FlippingExecutionContext (org.ff4j.core.FlippingExecutionContext)1 InMemoryFeatureStore (org.ff4j.store.InMemoryFeatureStore)1 Before (org.junit.Before)1