Search in sources :

Example 11 with CommandNotification

use of org.apache.rya.periodic.notification.notification.CommandNotification in project incubator-rya by apache.

the class PeriodicCommandNotificationConsumerIT method kafkaNotificationMillisProviderTest.

@Test
public void kafkaNotificationMillisProviderTest() throws InterruptedException {
    BasicConfigurator.configure();
    final BlockingQueue<TimestampedNotification> notifications = new LinkedBlockingQueue<>();
    final Properties props = createKafkaConfig();
    final KafkaProducer<String, CommandNotification> producer = new KafkaProducer<>(props);
    final String topic = rule.getKafkaTopicName();
    rule.createTopic(topic);
    registration = new KafkaNotificationRegistrationClient(topic, producer);
    coord = new PeriodicNotificationCoordinatorExecutor(1, notifications);
    provider = new KafkaNotificationProvider(topic, new StringDeserializer(), new CommandNotificationSerializer(), props, coord, 1);
    provider.start();
    registration.addNotification("1", 1000, 0, TimeUnit.MILLISECONDS);
    Thread.sleep(4000);
    // check that notifications are being added to the blocking queue
    Assert.assertEquals(true, notifications.size() > 0);
    registration.deleteNotification("1");
    Thread.sleep(2000);
    final int size = notifications.size();
    // sleep for 2 seconds to ensure no more messages being produced
    Thread.sleep(2000);
    Assert.assertEquals(size, notifications.size());
    tearDown();
}
Also used : KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) TimestampedNotification(org.apache.rya.periodic.notification.notification.TimestampedNotification) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Properties(java.util.Properties) CommandNotificationSerializer(org.apache.rya.periodic.notification.serialization.CommandNotificationSerializer) PeriodicNotificationCoordinatorExecutor(org.apache.rya.periodic.notification.coordinator.PeriodicNotificationCoordinatorExecutor) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) KafkaNotificationRegistrationClient(org.apache.rya.periodic.notification.registration.KafkaNotificationRegistrationClient) Test(org.junit.Test)

Example 12 with CommandNotification

use of org.apache.rya.periodic.notification.notification.CommandNotification in project incubator-rya by apache.

the class PeriodicCommandNotificationConsumerIT method kafkaNotificationProviderTest.

@Test
public void kafkaNotificationProviderTest() throws InterruptedException {
    BasicConfigurator.configure();
    final BlockingQueue<TimestampedNotification> notifications = new LinkedBlockingQueue<>();
    final Properties props = createKafkaConfig();
    final KafkaProducer<String, CommandNotification> producer = new KafkaProducer<>(props);
    final String topic = rule.getKafkaTopicName();
    rule.createTopic(topic);
    registration = new KafkaNotificationRegistrationClient(topic, producer);
    coord = new PeriodicNotificationCoordinatorExecutor(1, notifications);
    provider = new KafkaNotificationProvider(topic, new StringDeserializer(), new CommandNotificationSerializer(), props, coord, 1);
    provider.start();
    registration.addNotification("1", 1, 0, TimeUnit.SECONDS);
    Thread.sleep(4000);
    // check that notifications are being added to the blocking queue
    Assert.assertEquals(true, notifications.size() > 0);
    registration.deleteNotification("1");
    Thread.sleep(2000);
    final int size = notifications.size();
    // sleep for 2 seconds to ensure no more messages being produced
    Thread.sleep(2000);
    Assert.assertEquals(size, notifications.size());
    tearDown();
}
Also used : KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) TimestampedNotification(org.apache.rya.periodic.notification.notification.TimestampedNotification) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Properties(java.util.Properties) CommandNotificationSerializer(org.apache.rya.periodic.notification.serialization.CommandNotificationSerializer) PeriodicNotificationCoordinatorExecutor(org.apache.rya.periodic.notification.coordinator.PeriodicNotificationCoordinatorExecutor) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) KafkaNotificationRegistrationClient(org.apache.rya.periodic.notification.registration.KafkaNotificationRegistrationClient) Test(org.junit.Test)

Aggregations

CommandNotification (org.apache.rya.periodic.notification.notification.CommandNotification)12 PeriodicNotification (org.apache.rya.periodic.notification.notification.PeriodicNotification)6 Notification (org.apache.rya.periodic.notification.api.Notification)4 BasicNotification (org.apache.rya.periodic.notification.notification.BasicNotification)4 Properties (java.util.Properties)3 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)3 TimestampedNotification (org.apache.rya.periodic.notification.notification.TimestampedNotification)3 KafkaNotificationRegistrationClient (org.apache.rya.periodic.notification.registration.KafkaNotificationRegistrationClient)3 CommandNotificationSerializer (org.apache.rya.periodic.notification.serialization.CommandNotificationSerializer)3 Test (org.junit.Test)3 JsonObject (com.google.gson.JsonObject)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 KafkaProducer (org.apache.kafka.clients.producer.KafkaProducer)2 PeriodicNotificationCoordinatorExecutor (org.apache.rya.periodic.notification.coordinator.PeriodicNotificationCoordinatorExecutor)2 Command (org.apache.rya.periodic.notification.notification.CommandNotification.Command)2 JsonParseException (com.google.gson.JsonParseException)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 HashSet (java.util.HashSet)1 FluoClient (org.apache.fluo.api.client.FluoClient)1 Bytes (org.apache.fluo.api.data.Bytes)1