Search in sources :

Example 1 with ChangeLogEntry

use of org.apache.rya.streams.api.queries.ChangeLogEntry in project incubator-rya by apache.

the class QueryEventWorkGeneratorTest method notifyUpdate_isActive.

@Test
public void notifyUpdate_isActive() 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<QueryEvent> queue = new ArrayBlockingQueue<>(1);
    // The listener that will perform the QueryEventWorkGenerator work.
    final CountDownLatch latch = new CountDownLatch(1);
    latch.countDown();
    final QueryEventWorkGenerator generator = new QueryEventWorkGenerator("rya", latch, queue, 50, TimeUnit.MILLISECONDS, shutdownSignal);
    // A thread that will attempt to notify the generator with an update query change.
    final UUID queryId = UUID.randomUUID();
    final StreamsQuery query = new StreamsQuery(queryId, "query", true, false);
    final Thread notifyThread = new Thread(() -> {
        final QueryChange change = QueryChange.update(queryId, true);
        final ChangeLogEntry<QueryChange> entry = new ChangeLogEntry<>(0, change);
        generator.notify(entry, Optional.of(query));
    });
    // Start the thread.
    notifyThread.start();
    try {
        // Show work was added to the queue and the notifying thread died.
        final QueryEvent event = queue.poll(500, TimeUnit.MILLISECONDS);
        final QueryEvent expected = QueryEvent.executing("rya", new StreamsQuery(queryId, query.getSparql(), query.isActive(), query.isInsert()));
        assertEquals(expected, event);
    } finally {
        shutdownSignal.set(true);
        notifyThread.join();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) QueryEventWorkGenerator(org.apache.rya.streams.querymanager.QueryManager.QueryEventWorkGenerator) QueryChange(org.apache.rya.streams.api.queries.QueryChange) ChangeLogEntry(org.apache.rya.streams.api.queries.ChangeLogEntry) QueryEvent(org.apache.rya.streams.querymanager.QueryManager.QueryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with ChangeLogEntry

use of org.apache.rya.streams.api.queries.ChangeLogEntry in project incubator-rya by apache.

the class QueryEventWorkGeneratorTest 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<QueryEvent> queue = new ArrayBlockingQueue<>(1);
    // The listener that will perform the QueryEventWorkGenerator work.
    final CountDownLatch latch = new CountDownLatch(1);
    latch.countDown();
    final QueryEventWorkGenerator generator = new QueryEventWorkGenerator("rya", latch, queue, 50, TimeUnit.MILLISECONDS, shutdownSignal);
    // A thread that will attempt to notify the generator with a deleted query.
    final UUID queryId = UUID.randomUUID();
    final Thread notifyThread = new Thread(() -> {
        final QueryChange change = QueryChange.delete(queryId);
        final ChangeLogEntry<QueryChange> entry = new ChangeLogEntry<>(0, change);
        generator.notify(entry, Optional.empty());
    });
    // Start the thread.
    notifyThread.start();
    try {
        // Show work was added to the queue and the notifying thread died.
        final QueryEvent event = queue.poll(500, TimeUnit.MILLISECONDS);
        final QueryEvent expected = QueryEvent.stopped("rya", queryId);
        assertEquals(expected, event);
    } finally {
        shutdownSignal.set(true);
        notifyThread.join();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) QueryEventWorkGenerator(org.apache.rya.streams.querymanager.QueryManager.QueryEventWorkGenerator) QueryChange(org.apache.rya.streams.api.queries.QueryChange) ChangeLogEntry(org.apache.rya.streams.api.queries.ChangeLogEntry) QueryEvent(org.apache.rya.streams.querymanager.QueryManager.QueryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with ChangeLogEntry

use of org.apache.rya.streams.api.queries.ChangeLogEntry in project incubator-rya by apache.

the class KafkaQueryChangeLogIT method readFromPosition_positionStartsBegining.

@Test
public void readFromPosition_positionStartsBegining() throws Exception {
    final List<QueryChange> expected = write10ChangesToChangeLog().subList(5, 10);
    // set the position to some non-0 position
    final TopicPartition partition = new TopicPartition(topic, 0);
    consumer.assign(Lists.newArrayList(partition));
    consumer.seekToBeginning(Lists.newArrayList(partition));
    final CloseableIteration<ChangeLogEntry<QueryChange>, QueryChangeLogException> iter = changeLog.readFromPosition(5L);
    final List<QueryChange> actual = new ArrayList<>();
    while (iter.hasNext()) {
        final ChangeLogEntry<QueryChange> entry = iter.next();
        actual.add(entry.getEntry());
    }
    assertEquals(expected, actual);
}
Also used : QueryChangeLogException(org.apache.rya.streams.api.queries.QueryChangeLog.QueryChangeLogException) TopicPartition(org.apache.kafka.common.TopicPartition) ArrayList(java.util.ArrayList) QueryChange(org.apache.rya.streams.api.queries.QueryChange) ChangeLogEntry(org.apache.rya.streams.api.queries.ChangeLogEntry) Test(org.junit.Test)

Example 4 with ChangeLogEntry

use of org.apache.rya.streams.api.queries.ChangeLogEntry in project incubator-rya by apache.

the class KafkaQueryChangeLogIT method readFromPosition_positionStartsNotBegining.

@Test
public void readFromPosition_positionStartsNotBegining() throws Exception {
    final List<QueryChange> expected = write10ChangesToChangeLog().subList(5, 10);
    // set the position to some non-0 position
    final TopicPartition partition = new TopicPartition(topic, 0);
    consumer.assign(Lists.newArrayList(partition));
    consumer.seekToEnd(Lists.newArrayList(partition));
    final CloseableIteration<ChangeLogEntry<QueryChange>, QueryChangeLogException> iter = changeLog.readFromPosition(5L);
    final List<QueryChange> actual = new ArrayList<>();
    while (iter.hasNext()) {
        final ChangeLogEntry<QueryChange> entry = iter.next();
        actual.add(entry.getEntry());
    }
    assertEquals(expected, actual);
}
Also used : QueryChangeLogException(org.apache.rya.streams.api.queries.QueryChangeLog.QueryChangeLogException) TopicPartition(org.apache.kafka.common.TopicPartition) ArrayList(java.util.ArrayList) QueryChange(org.apache.rya.streams.api.queries.QueryChange) ChangeLogEntry(org.apache.rya.streams.api.queries.ChangeLogEntry) Test(org.junit.Test)

Example 5 with ChangeLogEntry

use of org.apache.rya.streams.api.queries.ChangeLogEntry in project incubator-rya by apache.

the class KafkaQueryChangeLogIT method readFromBegining_positionStartsNotBegining.

@Test
public void readFromBegining_positionStartsNotBegining() throws Exception {
    final List<QueryChange> expected = write10ChangesToChangeLog();
    // set the position to some non-0 position
    final TopicPartition partition = new TopicPartition(topic, 0);
    consumer.assign(Lists.newArrayList(partition));
    consumer.seek(partition, 5L);
    final CloseableIteration<ChangeLogEntry<QueryChange>, QueryChangeLogException> iter = changeLog.readFromStart();
    final List<QueryChange> actual = new ArrayList<>();
    while (iter.hasNext()) {
        final ChangeLogEntry<QueryChange> entry = iter.next();
        actual.add(entry.getEntry());
    }
    assertEquals(expected, actual);
}
Also used : QueryChangeLogException(org.apache.rya.streams.api.queries.QueryChangeLog.QueryChangeLogException) TopicPartition(org.apache.kafka.common.TopicPartition) ArrayList(java.util.ArrayList) QueryChange(org.apache.rya.streams.api.queries.QueryChange) ChangeLogEntry(org.apache.rya.streams.api.queries.ChangeLogEntry) Test(org.junit.Test)

Aggregations

ChangeLogEntry (org.apache.rya.streams.api.queries.ChangeLogEntry)9 Test (org.junit.Test)9 QueryChange (org.apache.rya.streams.api.queries.QueryChange)8 UUID (java.util.UUID)5 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 QueryEvent (org.apache.rya.streams.querymanager.QueryManager.QueryEvent)5 QueryEventWorkGenerator (org.apache.rya.streams.querymanager.QueryManager.QueryEventWorkGenerator)5 TopicPartition (org.apache.kafka.common.TopicPartition)4 StreamsQuery (org.apache.rya.streams.api.entity.StreamsQuery)4 QueryChangeLogException (org.apache.rya.streams.api.queries.QueryChangeLog.QueryChangeLogException)4 ArrayList (java.util.ArrayList)3