use of org.apache.rya.streams.querymanager.QueryExecutor 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();
}
}
use of org.apache.rya.streams.querymanager.QueryExecutor in project incubator-rya by apache.
the class LocalQueryExecutorTest method getRunningQueryIds_noneStarted.
@Test
public void getRunningQueryIds_noneStarted() throws Exception {
// Start an executor.
final QueryExecutor executor = new LocalQueryExecutor(mock(CreateKafkaTopic.class), mock(KafkaStreamsFactory.class));
executor.startAndWait();
try {
// Get the list of running queries.
final Set<UUID> runningQueries = executor.getRunningQueryIds();
// Show no queries are reported as running.
assertTrue(runningQueries.isEmpty());
} finally {
executor.stopAndWait();
}
}
use of org.apache.rya.streams.querymanager.QueryExecutor 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();
}
}
use of org.apache.rya.streams.querymanager.QueryExecutor in project incubator-rya by apache.
the class LocalQueryExecutorTest method stopAll_serviceNotStarted.
@Test(expected = IllegalStateException.class)
public void stopAll_serviceNotStarted() throws Exception {
final QueryExecutor executor = new LocalQueryExecutor(mock(CreateKafkaTopic.class), mock(KafkaStreamsFactory.class));
executor.stopAll("rya");
}
use of org.apache.rya.streams.querymanager.QueryExecutor 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();
}
}
Aggregations