use of org.apache.rya.streams.querymanager.QueryManager.QueryEventWorker in project incubator-rya by apache.
the class QueryEventWorkerTest method shutdownSignalKillsThread.
@Test
public void shutdownSignalKillsThread() {
// The signal that will kill the working thread.
final AtomicBoolean shutdownSignal = new AtomicBoolean(false);
// The thread that will perform the QueryEventWorker task.
final Thread queryEventWorker = new Thread(new QueryEventWorker(new ArrayBlockingQueue<>(1), mock(QueryExecutor.class), 50, TimeUnit.MILLISECONDS, shutdownSignal));
queryEventWorker.start();
// Wait longer than the poll time to see if the thread died. Show that it is still running.
assertTrue(ThreadUtil.stillAlive(queryEventWorker, 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(queryEventWorker, 1000));
}
use of org.apache.rya.streams.querymanager.QueryManager.QueryEventWorker in project incubator-rya by apache.
the class QueryEventWorkerTest method stopAllWork.
@Test
public void stopAllWork() 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 all queries for a rya instance need to be stopped.
final String ryaInstance = "rya";
final QueryEvent stopAllEvent = QueryEvent.stopALL(ryaInstance);
// Release a latch if the stopQuery method on the queryExecutor is invoked with the correct values.
final CountDownLatch testMethodInvoked = new CountDownLatch(1);
final QueryExecutor queryExecutor = mock(QueryExecutor.class);
doAnswer(invocation -> {
testMethodInvoked.countDown();
return null;
}).when(queryExecutor).stopAll(ryaInstance);
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(stopAllEvent);
// Verify the Query Executor was told to stop all the queries.
assertTrue(testMethodInvoked.await(150, TimeUnit.MILLISECONDS));
} finally {
shutdownSignal.set(true);
queryEventWorker.join();
}
}
use of org.apache.rya.streams.querymanager.QueryManager.QueryEventWorker 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();
}
}
use of org.apache.rya.streams.querymanager.QueryManager.QueryEventWorker 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();
}
}
Aggregations