Search in sources :

Example 1 with KafkaStreamsFactory

use of org.apache.rya.streams.kafka.KafkaStreamsFactory in project incubator-rya by apache.

the class LocalQueryExecutorTest method stopAll.

@Test
public void stopAll() throws Exception {
    // Test values.
    final String ryaInstance1 = "rya1";
    final StreamsQuery query1 = new StreamsQuery(UUID.randomUUID(), "SELECT * WHERE { ?a ?b ?c. }", true, false);
    final String ryaInstance2 = "rya2";
    final StreamsQuery query2 = new StreamsQuery(UUID.randomUUID(), "SELECT * WHERE { ?a ?b ?c. }", true, false);
    // Mock the streams factory so that we can tell if the stop function is invoked by the executor.
    final KafkaStreamsFactory jobFactory = mock(KafkaStreamsFactory.class);
    final KafkaStreams queryJob1 = mock(KafkaStreams.class);
    when(jobFactory.make(eq(ryaInstance1), eq(query1))).thenReturn(queryJob1);
    final KafkaStreams queryJob2 = mock(KafkaStreams.class);
    when(jobFactory.make(eq(ryaInstance2), eq(query2))).thenReturn(queryJob2);
    // Start the executor that will be tested.
    final QueryExecutor executor = new LocalQueryExecutor(mock(CreateKafkaTopic.class), jobFactory);
    executor.startAndWait();
    try {
        // Tell the executor to start the queries.
        executor.startQuery(ryaInstance1, query1);
        executor.startQuery(ryaInstance2, query2);
        // Verify both are running.
        verify(queryJob1).start();
        verify(queryJob2).start();
        // Tell the executor to stop queries running under rya2.
        executor.stopAll(ryaInstance2);
        // Show the first query is still running, but the second isn't.
        verify(queryJob1, never()).close();
        verify(queryJob2).close();
    } finally {
        executor.stopAndWait();
    }
}
Also used : KafkaStreams(org.apache.kafka.streams.KafkaStreams) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) CreateKafkaTopic(org.apache.rya.streams.kafka.interactor.CreateKafkaTopic) QueryExecutor(org.apache.rya.streams.querymanager.QueryExecutor) KafkaStreamsFactory(org.apache.rya.streams.kafka.KafkaStreamsFactory) Test(org.junit.Test)

Example 2 with KafkaStreamsFactory

use of org.apache.rya.streams.kafka.KafkaStreamsFactory in project incubator-rya by apache.

the class LocalQueryExecutorTest method startQuery.

@Test
public void startQuery() throws Exception {
    // Test values.
    final String ryaInstance = "rya";
    final StreamsQuery query = new StreamsQuery(UUID.randomUUID(), "SELECT * WHERE { ?a ?b ?c. }", true, false);
    // Mock the streams factory so that we can tell if the start function is invoked by the executor.
    final KafkaStreamsFactory jobFactory = mock(KafkaStreamsFactory.class);
    final KafkaStreams queryJob = mock(KafkaStreams.class);
    when(jobFactory.make(eq(ryaInstance), eq(query))).thenReturn(queryJob);
    // Start the executor that will be tested.
    final QueryExecutor executor = new LocalQueryExecutor(mock(CreateKafkaTopic.class), jobFactory);
    executor.startAndWait();
    try {
        // Tell the executor to start the query.
        executor.startQuery(ryaInstance, query);
        // Show a job was started for that query's ID.
        verify(queryJob).start();
    } finally {
        executor.stopAndWait();
    }
}
Also used : KafkaStreams(org.apache.kafka.streams.KafkaStreams) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) CreateKafkaTopic(org.apache.rya.streams.kafka.interactor.CreateKafkaTopic) QueryExecutor(org.apache.rya.streams.querymanager.QueryExecutor) KafkaStreamsFactory(org.apache.rya.streams.kafka.KafkaStreamsFactory) Test(org.junit.Test)

Example 3 with KafkaStreamsFactory

use of org.apache.rya.streams.kafka.KafkaStreamsFactory in project incubator-rya by apache.

the class LocalQueryExecutorTest method getRunningQueryIds_noneStopped.

@Test
public void getRunningQueryIds_noneStopped() throws Exception {
    // Test values.
    final String ryaInstance = "rya";
    final StreamsQuery query1 = new StreamsQuery(UUID.randomUUID(), "SELECT * WHERE { ?a ?b ?c. }", true, false);
    final StreamsQuery query2 = new StreamsQuery(UUID.randomUUID(), "SELECT * WHERE { ?a ?b ?c. }", true, false);
    final StreamsQuery query3 = new StreamsQuery(UUID.randomUUID(), "SELECT * WHERE { ?a ?b ?c. }", true, false);
    // Mock the streams factory so that we can figure out what is started.
    final KafkaStreamsFactory jobFactory = mock(KafkaStreamsFactory.class);
    when(jobFactory.make(eq(ryaInstance), eq(query1))).thenReturn(mock(KafkaStreams.class));
    when(jobFactory.make(eq(ryaInstance), eq(query2))).thenReturn(mock(KafkaStreams.class));
    when(jobFactory.make(eq(ryaInstance), eq(query3))).thenReturn(mock(KafkaStreams.class));
    // Start the executor that will be tested.
    final QueryExecutor executor = new LocalQueryExecutor(mock(CreateKafkaTopic.class), jobFactory);
    executor.startAndWait();
    try {
        // Start the queries.
        executor.startQuery(ryaInstance, query1);
        executor.startQuery(ryaInstance, query2);
        executor.startQuery(ryaInstance, query3);
        // All of those query IDs should be reported as running.
        final Set<UUID> expected = Sets.newHashSet(query1.getQueryId(), query2.getQueryId(), query3.getQueryId());
        assertEquals(expected, executor.getRunningQueryIds());
    } finally {
        executor.stopAndWait();
    }
}
Also used : KafkaStreams(org.apache.kafka.streams.KafkaStreams) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) CreateKafkaTopic(org.apache.rya.streams.kafka.interactor.CreateKafkaTopic) QueryExecutor(org.apache.rya.streams.querymanager.QueryExecutor) KafkaStreamsFactory(org.apache.rya.streams.kafka.KafkaStreamsFactory) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with KafkaStreamsFactory

use of org.apache.rya.streams.kafka.KafkaStreamsFactory in project incubator-rya by apache.

the class LocalQueryExecutorTest method getRunningQueryIds_stoppedNoLongerListed.

@Test
public void getRunningQueryIds_stoppedNoLongerListed() throws Exception {
    // Test values.
    final String ryaInstance = "rya";
    final StreamsQuery query1 = new StreamsQuery(UUID.randomUUID(), "SELECT * WHERE { ?a ?b ?c. }", true, false);
    final StreamsQuery query2 = new StreamsQuery(UUID.randomUUID(), "SELECT * WHERE { ?a ?b ?c. }", true, false);
    final StreamsQuery query3 = new StreamsQuery(UUID.randomUUID(), "SELECT * WHERE { ?a ?b ?c. }", true, false);
    // Mock the streams factory so that we can figure out what is started.
    final KafkaStreamsFactory jobFactory = mock(KafkaStreamsFactory.class);
    when(jobFactory.make(eq(ryaInstance), eq(query1))).thenReturn(mock(KafkaStreams.class));
    when(jobFactory.make(eq(ryaInstance), eq(query2))).thenReturn(mock(KafkaStreams.class));
    when(jobFactory.make(eq(ryaInstance), eq(query3))).thenReturn(mock(KafkaStreams.class));
    // Start the executor that will be tested.
    final QueryExecutor executor = new LocalQueryExecutor(mock(CreateKafkaTopic.class), jobFactory);
    executor.startAndWait();
    try {
        // Start the queries.
        executor.startQuery(ryaInstance, query1);
        executor.startQuery(ryaInstance, query2);
        executor.startQuery(ryaInstance, query3);
        // Stop the second query.
        executor.stopQuery(query2.getQueryId());
        // Only the first and third queries are running.
        final Set<UUID> expected = Sets.newHashSet(query1.getQueryId(), query3.getQueryId());
        assertEquals(expected, executor.getRunningQueryIds());
    } finally {
        executor.stopAndWait();
    }
}
Also used : KafkaStreams(org.apache.kafka.streams.KafkaStreams) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) CreateKafkaTopic(org.apache.rya.streams.kafka.interactor.CreateKafkaTopic) QueryExecutor(org.apache.rya.streams.querymanager.QueryExecutor) KafkaStreamsFactory(org.apache.rya.streams.kafka.KafkaStreamsFactory) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with KafkaStreamsFactory

use of org.apache.rya.streams.kafka.KafkaStreamsFactory in project incubator-rya by apache.

the class LocalQueryExecutorTest method stopAll_noneForThatRyaInstance.

@Test
public void stopAll_noneForThatRyaInstance() throws Exception {
    // Test values.
    final String ryaInstance = "rya";
    final StreamsQuery query1 = new StreamsQuery(UUID.randomUUID(), "SELECT * WHERE { ?a ?b ?c. }", true, false);
    final StreamsQuery query2 = new StreamsQuery(UUID.randomUUID(), "SELECT * WHERE { ?a ?b ?c. }", true, false);
    // Mock the streams factory so that we can tell if the stop function is invoked by the executor.
    final KafkaStreamsFactory jobFactory = mock(KafkaStreamsFactory.class);
    final KafkaStreams queryJob1 = mock(KafkaStreams.class);
    final KafkaStreams queryJob2 = mock(KafkaStreams.class);
    when(jobFactory.make(eq(ryaInstance), eq(query1))).thenReturn(queryJob1);
    when(jobFactory.make(eq(ryaInstance), eq(query2))).thenReturn(queryJob2);
    // Start the executor that will be tested.
    final QueryExecutor executor = new LocalQueryExecutor(mock(CreateKafkaTopic.class), jobFactory);
    executor.startAndWait();
    try {
        // Tell the executor to start the queries.
        executor.startQuery(ryaInstance, query1);
        executor.startQuery(ryaInstance, query2);
        // Verify both are running.
        verify(queryJob1).start();
        verify(queryJob2).start();
        // Tell the executor to stop queries running under rya2.
        executor.stopAll("someOtherRyaInstance");
        // Show none of the queries were stopped.
        verify(queryJob1, never()).close();
        verify(queryJob2, never()).close();
    } finally {
        executor.stopAndWait();
    }
}
Also used : KafkaStreams(org.apache.kafka.streams.KafkaStreams) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) CreateKafkaTopic(org.apache.rya.streams.kafka.interactor.CreateKafkaTopic) QueryExecutor(org.apache.rya.streams.querymanager.QueryExecutor) KafkaStreamsFactory(org.apache.rya.streams.kafka.KafkaStreamsFactory) Test(org.junit.Test)

Aggregations

KafkaStreamsFactory (org.apache.rya.streams.kafka.KafkaStreamsFactory)8 CreateKafkaTopic (org.apache.rya.streams.kafka.interactor.CreateKafkaTopic)8 StreamsQuery (org.apache.rya.streams.api.entity.StreamsQuery)7 QueryExecutor (org.apache.rya.streams.querymanager.QueryExecutor)7 Test (org.junit.Test)7 KafkaStreams (org.apache.kafka.streams.KafkaStreams)6 UUID (java.util.UUID)2 SingleThreadKafkaStreamsFactory (org.apache.rya.streams.kafka.SingleThreadKafkaStreamsFactory)2 JCommander (com.beust.jcommander.JCommander)1 ParameterException (com.beust.jcommander.ParameterException)1 Scheduler (com.google.common.util.concurrent.AbstractScheduledService.Scheduler)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 TimeUnit (java.util.concurrent.TimeUnit)1 JAXBException (javax.xml.bind.JAXBException)1 DaemonInitException (org.apache.commons.daemon.DaemonInitException)1 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)1 VisibilityStatement (org.apache.rya.api.model.VisibilityStatement)1 LoadStatements (org.apache.rya.streams.api.interactor.LoadStatements)1