use of org.apache.rya.streams.querymanager.QueryManager.LogEvent in project incubator-rya by apache.
the class LogEventWorkerTest method nofity_logCreated_exists.
@Test
public void nofity_logCreated_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();
// Write a message that indicates a new query should be active.
final UUID firstQueryId = UUID.randomUUID();
changeLog.write(QueryChange.create(firstQueryId, "select * where { ?a ?b ?c . }", true, false));
// 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);
// Say the same log was created a second time.
logEventQueue.offer(createLogEvent);
// Show that only a single unit of work was added for the log. This indicates the
// second message was effectively skipped as it would have add its work added twice otherwise.
final Set<QueryEvent> expectedEvents = new HashSet<>();
expectedEvents.add(QueryEvent.executing("rya", new StreamsQuery(firstQueryId, "select * where { ?a ?b ?c . }", true, false)));
final Set<QueryEvent> queryEvents = new HashSet<>();
queryEvents.add(queryEventQueue.poll(500, TimeUnit.MILLISECONDS));
assertNull(queryEventQueue.poll(500, TimeUnit.MILLISECONDS));
assertEquals(expectedEvents, queryEvents);
} finally {
shutdownSignal.set(true);
logEventWorker.join();
}
}
use of org.apache.rya.streams.querymanager.QueryManager.LogEvent 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));
}
use of org.apache.rya.streams.querymanager.QueryManager.LogEvent 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();
}
}
use of org.apache.rya.streams.querymanager.QueryManager.LogEvent 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();
}
}
use of org.apache.rya.streams.querymanager.QueryManager.LogEvent in project incubator-rya by apache.
the class LogEventWorkerTest method nofity_logCreated_doesNotExist.
@Test
public void nofity_logCreated_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);
// The Query Change Log that will be watched.
final QueryChangeLog changeLog = new InMemoryQueryChangeLog();
// Write a message that indicates a new query should be active.
final UUID firstQueryId = UUID.randomUUID();
changeLog.write(QueryChange.create(firstQueryId, "select * where { ?a ?b ?c . }", true, false));
// Write a message that adds an active query, but then makes it inactive. Because both of these
// events are written to the log before the worker subscribes to the repository for updates, they
// must result in a single query stopped event.
final UUID secondQueryId = UUID.randomUUID();
changeLog.write(QueryChange.create(secondQueryId, "select * where { ?d ?e ?f . }", true, false));
changeLog.write(QueryChange.update(secondQueryId, false));
// 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);
// We must see the following Query Events added to the work queue.
// Query 1, executing.
// Query 2, stopped.
Set<QueryEvent> expectedEvents = new HashSet<>();
expectedEvents.add(QueryEvent.executing("rya", new StreamsQuery(firstQueryId, "select * where { ?a ?b ?c . }", true, false)));
expectedEvents.add(QueryEvent.stopped("rya", secondQueryId));
Set<QueryEvent> queryEvents = new HashSet<>();
queryEvents.add(queryEventQueue.poll(500, TimeUnit.MILLISECONDS));
queryEvents.add(queryEventQueue.poll(500, TimeUnit.MILLISECONDS));
assertEquals(expectedEvents, queryEvents);
// Write an event to the change log that stops the first query.
changeLog.write(QueryChange.update(firstQueryId, false));
// Show it was also reflected in the changes.
// Query 1, stopped.
expectedEvents = new HashSet<>();
expectedEvents.add(QueryEvent.stopped("rya", firstQueryId));
queryEvents = new HashSet<>();
queryEvents.add(queryEventQueue.poll(500, TimeUnit.MILLISECONDS));
assertEquals(expectedEvents, queryEvents);
} finally {
shutdownSignal.set(true);
logEventWorker.join();
}
}
Aggregations