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);
}
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);
}
}
Aggregations