Search in sources :

Example 1 with LogEventWorkGenerator

use of org.apache.rya.streams.querymanager.QueryManager.LogEventWorkGenerator in project incubator-rya by apache.

the class LogEventWorkGeneratorTest method shutdownSignalKillsThread.

@Test
public void shutdownSignalKillsThread() {
    // The signal that will kill the notifying thread.
    final AtomicBoolean shutdownSignal = new AtomicBoolean(false);
    // The queue generated work is offered to.
    final BlockingQueue<LogEvent> queue = new ArrayBlockingQueue<>(1);
    // The listener that will perform the LogEventWorkGenerator work.
    final LogEventWorkGenerator generator = new LogEventWorkGenerator(queue, 50, TimeUnit.MILLISECONDS, shutdownSignal);
    // A thread that will attempt to notify the generator with a created change log.
    final Thread notifyThread = new Thread(() -> {
        generator.notifyCreate("rya", mock(QueryChangeLog.class));
    });
    // Fill the queue so that nothing may be offered to it.
    queue.offer(LogEvent.delete("rya"));
    // Start the thread and show that it is still alive after the offer period.
    notifyThread.start();
    assertTrue(ThreadUtil.stillAlive(notifyThread, 200));
    // Set the shutdown signal to true and join the thread. If we were able to join, then it shut down.
    shutdownSignal.set(true);
    assertFalse(ThreadUtil.stillAlive(notifyThread, 1000));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) LogEventWorkGenerator(org.apache.rya.streams.querymanager.QueryManager.LogEventWorkGenerator) LogEvent(org.apache.rya.streams.querymanager.QueryManager.LogEvent) QueryChangeLog(org.apache.rya.streams.api.queries.QueryChangeLog) Test(org.junit.Test)

Example 2 with LogEventWorkGenerator

use of org.apache.rya.streams.querymanager.QueryManager.LogEventWorkGenerator in project incubator-rya by apache.

the class LogEventWorkGeneratorTest method notifyCreate.

@Test
public void notifyCreate() throws Exception {
    // The signal that will kill the notifying thread.
    final AtomicBoolean shutdownSignal = new AtomicBoolean(false);
    // The queue generated work is offered to.
    final BlockingQueue<LogEvent> queue = new ArrayBlockingQueue<>(1);
    // The listener that will perform the LogEventWorkGenerator work.
    final LogEventWorkGenerator generator = new LogEventWorkGenerator(queue, 50, TimeUnit.MILLISECONDS, shutdownSignal);
    // A thread that will attempt to notify the generator with a created change log.
    final CountDownLatch notified = new CountDownLatch(1);
    final Thread notifyThread = new Thread(() -> {
        generator.notifyCreate("rya", mock(QueryChangeLog.class));
        notified.countDown();
    });
    try {
        // Start the thread that performs the notification.
        notifyThread.start();
        // Wait for the thread to indicate it has notified and check the queue for the value.
        notified.await(200, TimeUnit.MILLISECONDS);
        final LogEvent event = queue.poll(200, TimeUnit.MILLISECONDS);
        assertEquals(LogEventType.CREATE, event.getEventType());
        assertEquals("rya", event.getRyaInstanceName());
    } finally {
        shutdownSignal.set(true);
        notifyThread.join();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) LogEventWorkGenerator(org.apache.rya.streams.querymanager.QueryManager.LogEventWorkGenerator) LogEvent(org.apache.rya.streams.querymanager.QueryManager.LogEvent) CountDownLatch(java.util.concurrent.CountDownLatch) QueryChangeLog(org.apache.rya.streams.api.queries.QueryChangeLog) Test(org.junit.Test)

Example 3 with LogEventWorkGenerator

use of org.apache.rya.streams.querymanager.QueryManager.LogEventWorkGenerator in project incubator-rya by apache.

the class LogEventWorkGeneratorTest method notifyDelete.

@Test
public void notifyDelete() throws Exception {
    // The signal that will kill the notifying thread.
    final AtomicBoolean shutdownSignal = new AtomicBoolean(false);
    // The queue generated work is offered to.
    final BlockingQueue<LogEvent> queue = new ArrayBlockingQueue<>(1);
    // The listener that will perform the LogEventWorkGenerator work.
    final LogEventWorkGenerator generator = new LogEventWorkGenerator(queue, 50, TimeUnit.MILLISECONDS, shutdownSignal);
    // A thread that will attempt to notify the generator with a deleted change log.
    final CountDownLatch notified = new CountDownLatch(1);
    final Thread notifyThread = new Thread(() -> {
        generator.notifyDelete("rya");
        notified.countDown();
    });
    try {
        // Start the thread that performs the notification.
        notifyThread.start();
        // Wait for the thread to indicate it has notified and check the queue for the value.
        notified.await(200, TimeUnit.MILLISECONDS);
        final LogEvent event = queue.poll(200, TimeUnit.MILLISECONDS);
        assertEquals(LogEventType.DELETE, event.getEventType());
        assertEquals("rya", event.getRyaInstanceName());
    } finally {
        shutdownSignal.set(true);
        notifyThread.join();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) LogEventWorkGenerator(org.apache.rya.streams.querymanager.QueryManager.LogEventWorkGenerator) LogEvent(org.apache.rya.streams.querymanager.QueryManager.LogEvent) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 LogEvent (org.apache.rya.streams.querymanager.QueryManager.LogEvent)3 LogEventWorkGenerator (org.apache.rya.streams.querymanager.QueryManager.LogEventWorkGenerator)3 Test (org.junit.Test)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 QueryChangeLog (org.apache.rya.streams.api.queries.QueryChangeLog)2