Search in sources :

Example 1 with CleanupListener

use of com.thinkbiganalytics.nifi.core.api.cleanup.CleanupListener in project kylo by Teradata.

the class JmsCleanupEventConsumer method receiveEvent.

/**
 * Processes cleanup events.
 *
 * @param event the cleanup event
 */
@JmsListener(destination = MetadataQueues.CLEANUP_TRIGGER, containerFactory = JmsConstants.QUEUE_LISTENER_CONTAINER_FACTORY)
public void receiveEvent(@Nonnull final FeedCleanupTriggerEvent event) {
    LOG.debug("Received JMS message - topic: {}, message: {}, consumer {}", MetadataQueues.CLEANUP_TRIGGER, event, this);
    LOG.info("Received feed cleanup trigger event: {}", event);
    String key = generateKey(event.getCategoryName(), event.getFeedName());
    LOG.debug("Looking up listener for {}", key);
    CleanupListener listener = feedListeners.get(key);
    if (listener != null) {
        LOG.debug("Found listener for {}, triggering event {}", key, event);
        listener.triggered(event);
    } else {
        LOG.debug("Found no listener for {}", key);
    }
    this.anyFeedListeners.forEach(anyListener -> {
        LOG.debug("Triggering event {} for listener {}", event, anyListener);
        anyListener.triggered(event);
    });
}
Also used : CleanupListener(com.thinkbiganalytics.nifi.core.api.cleanup.CleanupListener) JmsListener(org.springframework.jms.annotation.JmsListener)

Example 2 with CleanupListener

use of com.thinkbiganalytics.nifi.core.api.cleanup.CleanupListener in project kylo by Teradata.

the class JmsCleanupEventServiceTest method test.

/**
 * Verify adding and removing cleanup event listeners.
 */
@Test
public void test() throws Exception {
    // Test adding listener
    final CleanupListener listener = Mockito.mock(CleanupListener.class);
    cleanupService.addListener("cat", "feed", listener);
    Mockito.verify(consumer).addListener("cat", "feed", listener);
    // Test removing listener
    cleanupService.removeListener(listener);
    Mockito.verify(consumer).removeListener(listener);
}
Also used : CleanupListener(com.thinkbiganalytics.nifi.core.api.cleanup.CleanupListener) Test(org.junit.Test)

Example 3 with CleanupListener

use of com.thinkbiganalytics.nifi.core.api.cleanup.CleanupListener in project kylo by Teradata.

the class JmsCleanupEventConsumerTest method test.

/**
 * Test consuming and dispatching a cleanup trigger event.
 */
@Test
public void test() {
    // Mock event and listener
    final FeedCleanupTriggerEvent event = new FeedCleanupTriggerEvent("FEEDID");
    event.setCategoryName("cat");
    event.setFeedName("feed");
    final CleanupListener listener = Mockito.mock(CleanupListener.class);
    // Test receiving and triggering event
    final JmsCleanupEventConsumer consumer = new JmsCleanupEventConsumer();
    consumer.addListener("cat", "feed", listener);
    consumer.receiveEvent(event);
    Mockito.verify(listener).triggered(event);
    // Test removing listener
    consumer.removeListener(listener);
    consumer.receiveEvent(event);
    Mockito.verifyNoMoreInteractions(listener);
}
Also used : FeedCleanupTriggerEvent(com.thinkbiganalytics.metadata.rest.model.event.FeedCleanupTriggerEvent) CleanupListener(com.thinkbiganalytics.nifi.core.api.cleanup.CleanupListener) Test(org.junit.Test)

Aggregations

CleanupListener (com.thinkbiganalytics.nifi.core.api.cleanup.CleanupListener)3 Test (org.junit.Test)2 FeedCleanupTriggerEvent (com.thinkbiganalytics.metadata.rest.model.event.FeedCleanupTriggerEvent)1 JmsListener (org.springframework.jms.annotation.JmsListener)1