Search in sources :

Example 1 with GetQuery

use of org.apache.rya.streams.api.interactor.GetQuery in project incubator-rya by apache.

the class RyaStreamsCommandsTest method startQuery_alreadyRunning.

@Test
public void startQuery_alreadyRunning() throws Exception {
    // Mock the object that performs the rya streams operation.
    final RyaStreamsClient mockClient = mock(RyaStreamsClient.class);
    final StartQuery startQuery = mock(StartQuery.class);
    when(mockClient.getStartQuery()).thenReturn(startQuery);
    final GetQuery getQuery = mock(GetQuery.class);
    when(mockClient.getGetQuery()).thenReturn(getQuery);
    // Mock a shell state and connect it to a Rya instance.
    final SharedShellState state = new SharedShellState();
    state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mock(RyaClient.class));
    state.connectedToInstance("unitTest");
    state.connectedToRyaStreams(mockClient);
    // Report the query as running.
    final UUID queryId = UUID.randomUUID();
    when(getQuery.getQuery(eq(queryId))).thenReturn(java.util.Optional.of(new StreamsQuery(queryId, "sparql", true, false)));
    // Execute the command.
    final RyaStreamsCommands commands = new RyaStreamsCommands(state, mock(SparqlPrompt.class), mock(ConsolePrinter.class));
    final String message = commands.startQuery(queryId.toString());
    // Verify the interactor was not invoked.
    verify(startQuery, never()).start(queryId);
    // Verify a message is printed to the user.
    final String expected = "That query is already running.";
    assertEquals(expected, message);
}
Also used : RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) ConsolePrinter(org.apache.rya.shell.util.ConsolePrinter) GetQuery(org.apache.rya.streams.api.interactor.GetQuery) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) RyaClient(org.apache.rya.api.client.RyaClient) UUID(java.util.UUID) StartQuery(org.apache.rya.streams.api.interactor.StartQuery) Test(org.junit.Test)

Example 2 with GetQuery

use of org.apache.rya.streams.api.interactor.GetQuery in project incubator-rya by apache.

the class RyaStreamsCommandsTest method stopQuery.

@Test
public void stopQuery() throws Exception {
    // Mock the object that performs the rya streams operation.
    final RyaStreamsClient mockClient = mock(RyaStreamsClient.class);
    final StopQuery stopQuery = mock(StopQuery.class);
    when(mockClient.getStopQuery()).thenReturn(stopQuery);
    final GetQuery getQuery = mock(GetQuery.class);
    when(mockClient.getGetQuery()).thenReturn(getQuery);
    // Mock a shell state and connect it to a Rya instance.
    final SharedShellState state = new SharedShellState();
    state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mock(RyaClient.class));
    state.connectedToInstance("unitTest");
    state.connectedToRyaStreams(mockClient);
    // Report the query as running.
    final UUID queryId = UUID.randomUUID();
    when(getQuery.getQuery(eq(queryId))).thenReturn(java.util.Optional.of(new StreamsQuery(queryId, "sparql", true, false)));
    // Execute the command.
    final RyaStreamsCommands commands = new RyaStreamsCommands(state, mock(SparqlPrompt.class), mock(ConsolePrinter.class));
    final String message = commands.stopQuery(queryId.toString());
    // Verify the interactor was invoked with the provided parameters.
    verify(stopQuery).stop(queryId);
    // Verify a message is printed to the user.
    final String expected = "The query will no longer be processed by the Rya Streams subsystem.";
    assertEquals(expected, message);
}
Also used : StopQuery(org.apache.rya.streams.api.interactor.StopQuery) RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) ConsolePrinter(org.apache.rya.shell.util.ConsolePrinter) GetQuery(org.apache.rya.streams.api.interactor.GetQuery) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) RyaClient(org.apache.rya.api.client.RyaClient) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with GetQuery

use of org.apache.rya.streams.api.interactor.GetQuery in project incubator-rya by apache.

the class RyaStreamsCommandsTest method startQuery.

@Test
public void startQuery() throws Exception {
    // Mock the object that performs the rya streams operation.
    final RyaStreamsClient mockClient = mock(RyaStreamsClient.class);
    final StartQuery startQuery = mock(StartQuery.class);
    when(mockClient.getStartQuery()).thenReturn(startQuery);
    final GetQuery getQuery = mock(GetQuery.class);
    when(mockClient.getGetQuery()).thenReturn(getQuery);
    // Mock a shell state and connect it to a Rya instance.
    final SharedShellState state = new SharedShellState();
    state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mock(RyaClient.class));
    state.connectedToInstance("unitTest");
    state.connectedToRyaStreams(mockClient);
    // Report the query as not running.
    final UUID queryId = UUID.randomUUID();
    when(getQuery.getQuery(eq(queryId))).thenReturn(java.util.Optional.of(new StreamsQuery(queryId, "sparql", false, false)));
    // Execute the command.
    final RyaStreamsCommands commands = new RyaStreamsCommands(state, mock(SparqlPrompt.class), mock(ConsolePrinter.class));
    final String message = commands.startQuery(queryId.toString());
    // Verify the interactor was invoked with the provided parameters.
    verify(startQuery).start(queryId);
    // Verify a message is printed to the user.
    final String expected = "The query will be processed by the Rya Streams subsystem.";
    assertEquals(expected, message);
}
Also used : RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) ConsolePrinter(org.apache.rya.shell.util.ConsolePrinter) GetQuery(org.apache.rya.streams.api.interactor.GetQuery) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) RyaClient(org.apache.rya.api.client.RyaClient) UUID(java.util.UUID) StartQuery(org.apache.rya.streams.api.interactor.StartQuery) Test(org.junit.Test)

Example 4 with GetQuery

use of org.apache.rya.streams.api.interactor.GetQuery in project incubator-rya by apache.

the class RyaStreamsCommandsTest method stopQuery_alreadyStopped.

@Test
public void stopQuery_alreadyStopped() throws Exception {
    // Mock the object that performs the rya streams operation.
    final RyaStreamsClient mockClient = mock(RyaStreamsClient.class);
    final StopQuery stopQuery = mock(StopQuery.class);
    when(mockClient.getStopQuery()).thenReturn(stopQuery);
    final GetQuery getQuery = mock(GetQuery.class);
    when(mockClient.getGetQuery()).thenReturn(getQuery);
    // Mock a shell state and connect it to a Rya instance.
    final SharedShellState state = new SharedShellState();
    state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mock(RyaClient.class));
    state.connectedToInstance("unitTest");
    state.connectedToRyaStreams(mockClient);
    // Report the query as not running.
    final UUID queryId = UUID.randomUUID();
    when(getQuery.getQuery(eq(queryId))).thenReturn(java.util.Optional.of(new StreamsQuery(queryId, "sparql", false, false)));
    // Execute the command.
    final RyaStreamsCommands commands = new RyaStreamsCommands(state, mock(SparqlPrompt.class), mock(ConsolePrinter.class));
    final String message = commands.stopQuery(queryId.toString());
    // Verify the interactor was not invoked with the provided parameters.
    verify(stopQuery, never()).stop(queryId);
    // Verify a message is printed to the user.
    final String expected = "That query is already stopped.";
    assertEquals(expected, message);
}
Also used : StopQuery(org.apache.rya.streams.api.interactor.StopQuery) RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) ConsolePrinter(org.apache.rya.shell.util.ConsolePrinter) GetQuery(org.apache.rya.streams.api.interactor.GetQuery) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) RyaClient(org.apache.rya.api.client.RyaClient) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with GetQuery

use of org.apache.rya.streams.api.interactor.GetQuery in project incubator-rya by apache.

the class RyaStreamsCommandsTest method printQueryDetails.

@Test
public void printQueryDetails() throws Exception {
    // Mock the object that performs the rya streams operation.
    final RyaStreamsClient mockClient = mock(RyaStreamsClient.class);
    final GetQuery getQuery = mock(GetQuery.class);
    when(mockClient.getGetQuery()).thenReturn(getQuery);
    final UUID queryId = UUID.fromString("da55cea5-c21c-46a5-ab79-5433eef4efaa");
    final StreamsQuery query = new StreamsQuery(queryId, "SELECT * WHERE { ?a ?b ?c . }", true, false);
    when(getQuery.getQuery(queryId)).thenReturn(java.util.Optional.of(query));
    // Mock a shell state and connect it to a Rya instance.
    final SharedShellState state = new SharedShellState();
    state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mock(RyaClient.class));
    state.connectedToInstance("unitTest");
    state.connectedToRyaStreams(mockClient);
    // Execute the command.
    final RyaStreamsCommands commands = new RyaStreamsCommands(state, mock(SparqlPrompt.class), mock(ConsolePrinter.class));
    final String message = commands.printQueryDetails(queryId.toString());
    // Verify the correct report is returned.
    final String expected = " Query ID: da55cea5-c21c-46a5-ab79-5433eef4efaa\n" + "Is Active: true\n" + "Is Insert: false\n" + "   SPARQL: select ?a ?b ?c\n" + "           where {\n" + "             ?a ?b ?c.\n" + "           }\n";
    assertEquals(expected, message);
}
Also used : RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) ConsolePrinter(org.apache.rya.shell.util.ConsolePrinter) GetQuery(org.apache.rya.streams.api.interactor.GetQuery) StreamsQuery(org.apache.rya.streams.api.entity.StreamsQuery) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) RyaClient(org.apache.rya.api.client.RyaClient) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

UUID (java.util.UUID)5 RyaClient (org.apache.rya.api.client.RyaClient)5 AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)5 ConsolePrinter (org.apache.rya.shell.util.ConsolePrinter)5 SparqlPrompt (org.apache.rya.shell.util.SparqlPrompt)5 RyaStreamsClient (org.apache.rya.streams.api.RyaStreamsClient)5 StreamsQuery (org.apache.rya.streams.api.entity.StreamsQuery)5 GetQuery (org.apache.rya.streams.api.interactor.GetQuery)5 Test (org.junit.Test)5 StartQuery (org.apache.rya.streams.api.interactor.StartQuery)2 StopQuery (org.apache.rya.streams.api.interactor.StopQuery)2