Search in sources :

Example 6 with LogEvent

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

the class LogEventWorkerTest method notify_logDeleted_exists.

@Test
public void notify_logDeleted_exists() throws Exception {
    // The signal that will kill the working thread.
    final AtomicBoolean shutdownSignal = new AtomicBoolean(false);
    // The queue used to feed work.
    final BlockingQueue<LogEvent> logEventQueue = new ArrayBlockingQueue<>(10);
    // The queue work is written to.
    final BlockingQueue<QueryEvent> queryEventQueue = new ArrayBlockingQueue<>(10);
    // The Query Change Log that will be watched.
    final QueryChangeLog changeLog = new InMemoryQueryChangeLog();
    // Start the worker that will be tested.
    final Thread logEventWorker = new Thread(new LogEventWorker(logEventQueue, queryEventQueue, 50, TimeUnit.MILLISECONDS, shutdownSignal));
    logEventWorker.start();
    try {
        // Write a unit of work that indicates a log was created.
        final LogEvent createLogEvent = LogEvent.create("rya", changeLog);
        logEventQueue.offer(createLogEvent);
        // Write a unit of work that indicates a log was deleted.
        logEventQueue.offer(LogEvent.delete("rya"));
        // Show that a single unit of work was created for deleting everything for "rya".
        assertEquals(QueryEvent.stopALL("rya"), queryEventQueue.poll(500, TimeUnit.MILLISECONDS));
        assertNull(queryEventQueue.poll(500, TimeUnit.MILLISECONDS));
    } finally {
        shutdownSignal.set(true);
        logEventWorker.join();
    }
}
Also used : InMemoryQueryChangeLog(org.apache.rya.streams.api.queries.InMemoryQueryChangeLog) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) LogEvent(org.apache.rya.streams.querymanager.QueryManager.LogEvent) QueryEvent(org.apache.rya.streams.querymanager.QueryManager.QueryEvent) InMemoryQueryChangeLog(org.apache.rya.streams.api.queries.InMemoryQueryChangeLog) QueryChangeLog(org.apache.rya.streams.api.queries.QueryChangeLog) LogEventWorker(org.apache.rya.streams.querymanager.QueryManager.LogEventWorker) Test(org.junit.Test)

Example 7 with LogEvent

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

the class LogEventWorkerTest method notify_logDeleted_doesNotExist.

@Test
public void notify_logDeleted_doesNotExist() throws Exception {
    // The signal that will kill the working thread.
    final AtomicBoolean shutdownSignal = new AtomicBoolean(false);
    // The queue used to feed work.
    final BlockingQueue<LogEvent> logEventQueue = new ArrayBlockingQueue<>(10);
    // The queue work is written to.
    final BlockingQueue<QueryEvent> queryEventQueue = new ArrayBlockingQueue<>(10);
    // Start the worker that will be tested.
    final Thread logEventWorker = new Thread(new LogEventWorker(logEventQueue, queryEventQueue, 50, TimeUnit.MILLISECONDS, shutdownSignal));
    logEventWorker.start();
    try {
        // Write a unit of work that indicates a log was deleted. Since it was never created,
        // this will not cause anything to be written to the QueryEvent queue.
        logEventQueue.offer(LogEvent.delete("rya"));
        // Show that a single unit of work was created for deleting everything for "rya".
        assertNull(queryEventQueue.poll(500, TimeUnit.MILLISECONDS));
    } finally {
        shutdownSignal.set(true);
        logEventWorker.join();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) LogEvent(org.apache.rya.streams.querymanager.QueryManager.LogEvent) QueryEvent(org.apache.rya.streams.querymanager.QueryManager.QueryEvent) LogEventWorker(org.apache.rya.streams.querymanager.QueryManager.LogEventWorker) Test(org.junit.Test)

Aggregations

ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 LogEvent (org.apache.rya.streams.querymanager.QueryManager.LogEvent)7 Test (org.junit.Test)7 QueryChangeLog (org.apache.rya.streams.api.queries.QueryChangeLog)5 LogEventWorker (org.apache.rya.streams.querymanager.QueryManager.LogEventWorker)4 QueryEvent (org.apache.rya.streams.querymanager.QueryManager.QueryEvent)4 InMemoryQueryChangeLog (org.apache.rya.streams.api.queries.InMemoryQueryChangeLog)3 LogEventWorkGenerator (org.apache.rya.streams.querymanager.QueryManager.LogEventWorkGenerator)3 HashSet (java.util.HashSet)2 UUID (java.util.UUID)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 StreamsQuery (org.apache.rya.streams.api.entity.StreamsQuery)2