Search in sources :

Example 11 with QueryEvent

use of org.apache.rya.streams.querymanager.QueryManager.QueryEvent 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)

Example 12 with QueryEvent

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

the class QueryEventWorkerTest method executingWork.

@Test
public void executingWork() throws Exception {
    // The signal that will kill the working thread.
    final AtomicBoolean shutdownSignal = new AtomicBoolean(false);
    // The queue used to send the execute work to the thread.
    final BlockingQueue<QueryEvent> queue = new ArrayBlockingQueue<>(1);
    // The message that indicates a query needs to be executed.
    final String ryaInstance = "rya";
    final StreamsQuery query = new StreamsQuery(UUID.randomUUID(), "sparql", true, false);
    final QueryEvent executingEvent = QueryEvent.executing(ryaInstance, query);
    // Release a latch if the startQuery method on the queryExecutor is invoked with the correct values.
    final CountDownLatch startQueryInvoked = new CountDownLatch(1);
    final QueryExecutor queryExecutor = mock(QueryExecutor.class);
    doAnswer(invocation -> {
        startQueryInvoked.countDown();
        return null;
    }).when(queryExecutor).startQuery(ryaInstance, query);
    // The thread that will perform the QueryEventWorker task.
    final Thread queryEventWorker = new Thread(new QueryEventWorker(queue, queryExecutor, 50, TimeUnit.MILLISECONDS, shutdownSignal));
    try {
        queryEventWorker.start();
        // Provide a message indicating a query needs to be executing.
        queue.put(executingEvent);
        // Verify the Query Executor was told to start the query.
        assertTrue(startQueryInvoked.await(150, TimeUnit.MILLISECONDS));
    } finally {
        shutdownSignal.set(true);
        queryEventWorker.join();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) QueryEventWorker(org.apache.rya.streams.querymanager.QueryManager.QueryEventWorker) QueryEvent(org.apache.rya.streams.querymanager.QueryManager.QueryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 13 with QueryEvent

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

the class QueryEventWorkerTest method stoppedWork.

@Test
public void stoppedWork() throws Exception {
    // The signal that will kill the working thread.
    final AtomicBoolean shutdownSignal = new AtomicBoolean(false);
    // The queue used to send the execute work to the thread.
    final BlockingQueue<QueryEvent> queue = new ArrayBlockingQueue<>(1);
    // The message that indicates a query needs to be stopped.
    final UUID queryId = UUID.randomUUID();
    final QueryEvent stoppedEvent = QueryEvent.stopped("rya", queryId);
    // Release a latch if the stopQuery method on the queryExecutor is invoked with the correct values.
    final CountDownLatch stopQueryInvoked = new CountDownLatch(1);
    final QueryExecutor queryExecutor = mock(QueryExecutor.class);
    doAnswer(invocation -> {
        stopQueryInvoked.countDown();
        return null;
    }).when(queryExecutor).stopQuery(queryId);
    final Thread queryEventWorker = new Thread(new QueryEventWorker(queue, queryExecutor, 50, TimeUnit.MILLISECONDS, shutdownSignal));
    try {
        // The thread that will perform the QueryEventWorker task.
        queryEventWorker.start();
        // Provide a message indicating a query needs to be executing.
        queue.put(stoppedEvent);
        // Verify the Query Executor was told to stop the query.
        assertTrue(stopQueryInvoked.await(150, TimeUnit.MILLISECONDS));
    } finally {
        shutdownSignal.set(true);
        queryEventWorker.join();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) QueryEventWorker(org.apache.rya.streams.querymanager.QueryManager.QueryEventWorker) QueryEvent(org.apache.rya.streams.querymanager.QueryManager.QueryEvent) UUID(java.util.UUID) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 QueryEvent (org.apache.rya.streams.querymanager.QueryManager.QueryEvent)13 Test (org.junit.Test)13 CountDownLatch (java.util.concurrent.CountDownLatch)9 UUID (java.util.UUID)8 StreamsQuery (org.apache.rya.streams.api.entity.StreamsQuery)7 ChangeLogEntry (org.apache.rya.streams.api.queries.ChangeLogEntry)6 QueryEventWorkGenerator (org.apache.rya.streams.querymanager.QueryManager.QueryEventWorkGenerator)6 QueryChange (org.apache.rya.streams.api.queries.QueryChange)5 LogEvent (org.apache.rya.streams.querymanager.QueryManager.LogEvent)4 LogEventWorker (org.apache.rya.streams.querymanager.QueryManager.LogEventWorker)4 InMemoryQueryChangeLog (org.apache.rya.streams.api.queries.InMemoryQueryChangeLog)3 QueryChangeLog (org.apache.rya.streams.api.queries.QueryChangeLog)3 QueryEventWorker (org.apache.rya.streams.querymanager.QueryManager.QueryEventWorker)3 HashSet (java.util.HashSet)2