Search in sources :

Example 1 with DeleteQuery

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

the class RyaStreamsCommandsTest method deleteQuery.

@Test
public void deleteQuery() throws Exception {
    // Mock the object that performs the rya streams operation.
    final RyaStreamsClient mockClient = mock(RyaStreamsClient.class);
    final DeleteQuery deleteQuery = mock(DeleteQuery.class);
    when(mockClient.getDeleteQuery()).thenReturn(deleteQuery);
    // 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 UUID queryId = UUID.randomUUID();
    final String message = commands.deleteQuery(queryId.toString());
    // Verify the interactor was invoked with the provided parameters.
    verify(deleteQuery).delete(eq(queryId));
    // Verify a message is printed to the user.
    final String expected = "The query has been deleted.";
    assertEquals(expected, message);
}
Also used : RyaStreamsClient(org.apache.rya.streams.api.RyaStreamsClient) ConsolePrinter(org.apache.rya.shell.util.ConsolePrinter) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) DeleteQuery(org.apache.rya.streams.api.interactor.DeleteQuery) RyaClient(org.apache.rya.api.client.RyaClient) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with DeleteQuery

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

the class DeleteQueryCommand method execute.

@Override
public void execute(final String[] args) throws ArgumentsException, ExecutionException {
    requireNonNull(args);
    // Parse the command line arguments.
    final RemoveParameters params = new RemoveParameters();
    try {
        new JCommander(params, args);
    } catch (final ParameterException e) {
        throw new ArgumentsException("Could not add a new query because of invalid command line parameters.", e);
    }
    // Create the Kafka backed QueryChangeLog.
    final String bootstrapServers = params.kafkaIP + ":" + params.kafkaPort;
    final String topic = KafkaTopics.queryChangeLogTopic(params.ryaInstance);
    final QueryChangeLog queryChangeLog = KafkaQueryChangeLogFactory.make(bootstrapServers, topic);
    // The DeleteQuery command doesn't use the scheduled service feature.
    final Scheduler scheduler = Scheduler.newFixedRateSchedule(0L, 5, TimeUnit.SECONDS);
    final QueryRepository queryRepo = new InMemoryQueryRepository(queryChangeLog, scheduler);
    // Execute the delete query command.
    try {
        final DeleteQuery deleteQuery = new DefaultDeleteQuery(queryRepo);
        try {
            deleteQuery.delete(UUID.fromString(params.queryId));
            System.out.println("Deleted query: " + params.queryId);
        } catch (final RyaStreamsException e) {
            System.err.println("Unable to delete query with ID: " + params.queryId);
            e.printStackTrace();
            System.exit(1);
        }
    } catch (final Exception e) {
        System.err.println("Problem encountered while closing the QueryRepository.");
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : Scheduler(com.google.common.util.concurrent.AbstractScheduledService.Scheduler) DefaultDeleteQuery(org.apache.rya.streams.api.interactor.defaults.DefaultDeleteQuery) InMemoryQueryRepository(org.apache.rya.streams.api.queries.InMemoryQueryRepository) QueryChangeLog(org.apache.rya.streams.api.queries.QueryChangeLog) RyaStreamsException(org.apache.rya.streams.api.exception.RyaStreamsException) ParameterException(com.beust.jcommander.ParameterException) JCommander(com.beust.jcommander.JCommander) RyaStreamsException(org.apache.rya.streams.api.exception.RyaStreamsException) ParameterException(com.beust.jcommander.ParameterException) InMemoryQueryRepository(org.apache.rya.streams.api.queries.InMemoryQueryRepository) QueryRepository(org.apache.rya.streams.api.queries.QueryRepository) DeleteQuery(org.apache.rya.streams.api.interactor.DeleteQuery) DefaultDeleteQuery(org.apache.rya.streams.api.interactor.defaults.DefaultDeleteQuery)

Aggregations

DeleteQuery (org.apache.rya.streams.api.interactor.DeleteQuery)2 JCommander (com.beust.jcommander.JCommander)1 ParameterException (com.beust.jcommander.ParameterException)1 Scheduler (com.google.common.util.concurrent.AbstractScheduledService.Scheduler)1 UUID (java.util.UUID)1 RyaClient (org.apache.rya.api.client.RyaClient)1 AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)1 ConsolePrinter (org.apache.rya.shell.util.ConsolePrinter)1 SparqlPrompt (org.apache.rya.shell.util.SparqlPrompt)1 RyaStreamsClient (org.apache.rya.streams.api.RyaStreamsClient)1 RyaStreamsException (org.apache.rya.streams.api.exception.RyaStreamsException)1 DefaultDeleteQuery (org.apache.rya.streams.api.interactor.defaults.DefaultDeleteQuery)1 InMemoryQueryRepository (org.apache.rya.streams.api.queries.InMemoryQueryRepository)1 QueryChangeLog (org.apache.rya.streams.api.queries.QueryChangeLog)1 QueryRepository (org.apache.rya.streams.api.queries.QueryRepository)1 Test (org.junit.Test)1