Search in sources :

Example 6 with QueryChange

use of org.apache.rya.streams.api.queries.QueryChange 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 7 with QueryChange

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

the class KafkaQueryChangeLogIT method testWrite.

@Test
public void testWrite() throws Exception {
    final String sparql = "SOME QUERY HERE";
    final UUID uuid = UUID.randomUUID();
    final QueryChange newChange = QueryChange.create(uuid, sparql, true, false);
    changeLog.write(newChange);
    consumer.subscribe(Lists.newArrayList(topic));
    final ConsumerRecords<?, QueryChange> records = consumer.poll(2000);
    assertEquals(1, records.count());
    final QueryChange record = records.iterator().next().value();
    assertEquals(newChange, record);
}
Also used : QueryChange(org.apache.rya.streams.api.queries.QueryChange) UUID(java.util.UUID) Test(org.junit.Test)

Example 8 with QueryChange

use of org.apache.rya.streams.api.queries.QueryChange 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)

Example 9 with QueryChange

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

the class AddQueryCommandIT method setup.

@Before
public void setup() {
    // Make sure the topic that the change log uses exists.
    final String changeLogTopic = KafkaTopics.queryChangeLogTopic("" + ryaInstance);
    kafka.createTopic(changeLogTopic);
    // Setup the QueryRepository used by the test.
    final Producer<?, QueryChange> queryProducer = KafkaTestUtil.makeProducer(kafka, StringSerializer.class, QueryChangeSerializer.class);
    final Consumer<?, QueryChange> queryConsumer = KafkaTestUtil.fromStartConsumer(kafka, StringDeserializer.class, QueryChangeDeserializer.class);
    final QueryChangeLog changeLog = new KafkaQueryChangeLog(queryProducer, queryConsumer, changeLogTopic);
    queryRepo = new InMemoryQueryRepository(changeLog, Scheduler.newFixedRateSchedule(0L, 5, TimeUnit.SECONDS));
}
Also used : QueryChange(org.apache.rya.streams.api.queries.QueryChange) InMemoryQueryRepository(org.apache.rya.streams.api.queries.InMemoryQueryRepository) QueryChangeLog(org.apache.rya.streams.api.queries.QueryChangeLog) KafkaQueryChangeLog(org.apache.rya.streams.kafka.queries.KafkaQueryChangeLog) KafkaQueryChangeLog(org.apache.rya.streams.kafka.queries.KafkaQueryChangeLog) Before(org.junit.Before)

Example 10 with QueryChange

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

the class ListQueryCommandIT method setup.

@Before
public void setup() {
    // Make sure the topic that the change log uses exists.
    final String changeLogTopic = KafkaTopics.queryChangeLogTopic("" + ryaInstance);
    kafka.createTopic(changeLogTopic);
    // Setup the QueryRepository used by the test.
    final Producer<?, QueryChange> queryProducer = KafkaTestUtil.makeProducer(kafka, StringSerializer.class, QueryChangeSerializer.class);
    final Consumer<?, QueryChange> queryConsumer = KafkaTestUtil.fromStartConsumer(kafka, StringDeserializer.class, QueryChangeDeserializer.class);
    final QueryChangeLog changeLog = new KafkaQueryChangeLog(queryProducer, queryConsumer, changeLogTopic);
    queryRepo = new InMemoryQueryRepository(changeLog, Scheduler.newFixedRateSchedule(0L, 5, TimeUnit.SECONDS));
}
Also used : QueryChange(org.apache.rya.streams.api.queries.QueryChange) InMemoryQueryRepository(org.apache.rya.streams.api.queries.InMemoryQueryRepository) QueryChangeLog(org.apache.rya.streams.api.queries.QueryChangeLog) KafkaQueryChangeLog(org.apache.rya.streams.kafka.queries.KafkaQueryChangeLog) KafkaQueryChangeLog(org.apache.rya.streams.kafka.queries.KafkaQueryChangeLog) Before(org.junit.Before)

Aggregations

QueryChange (org.apache.rya.streams.api.queries.QueryChange)18 Test (org.junit.Test)11 ChangeLogEntry (org.apache.rya.streams.api.queries.ChangeLogEntry)8 UUID (java.util.UUID)7 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 InMemoryQueryRepository (org.apache.rya.streams.api.queries.InMemoryQueryRepository)5 QueryChangeLog (org.apache.rya.streams.api.queries.QueryChangeLog)5 KafkaQueryChangeLog (org.apache.rya.streams.kafka.queries.KafkaQueryChangeLog)5 QueryEvent (org.apache.rya.streams.querymanager.QueryManager.QueryEvent)5 QueryEventWorkGenerator (org.apache.rya.streams.querymanager.QueryManager.QueryEventWorkGenerator)5 ArrayList (java.util.ArrayList)4 StreamsQuery (org.apache.rya.streams.api.entity.StreamsQuery)4 Before (org.junit.Before)4 TopicPartition (org.apache.kafka.common.TopicPartition)3 QueryChangeLogException (org.apache.rya.streams.api.queries.QueryChangeLog.QueryChangeLogException)3 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)2 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)2 VisibilityBindingSetDeserializer (org.apache.rya.streams.kafka.serialization.VisibilityBindingSetDeserializer)2