Search in sources :

Example 6 with Shell

use of org.apache.accumulo.shell.Shell in project accumulo by apache.

the class ShellIT method setupShell.

@Before
public void setupShell() throws IOException {
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    output = new TestOutputStream();
    input = new StringInputStream();
    config = Files.createTempFile(null, null).toFile();
    terminal = new DumbTerminal(input, output);
    terminal.setSize(new Size(80, 24));
    reader = LineReaderBuilder.builder().terminal(terminal).build();
    shell = new Shell(reader);
    shell.setLogErrorsToConsole();
    shell.config("--config-file", config.toString(), "-u", "root", "-p", getRootPassword(), "-zi", getCluster().getInstanceName(), "-zh", getCluster().getZooKeepers());
}
Also used : Shell(org.apache.accumulo.shell.Shell) Size(org.jline.terminal.Size) DumbTerminal(org.jline.terminal.impl.DumbTerminal) Before(org.junit.Before)

Example 7 with Shell

use of org.apache.accumulo.shell.Shell in project accumulo by apache.

the class HistoryCommandTest method setUp.

@Before
public void setUp() throws Exception {
    command = new HistoryCommand();
    // Make sure everything is initialized
    command.getOptions();
    cl = createMock(CommandLine.class);
    expect(cl.hasOption("c")).andReturn(false);
    expect(cl.hasOption("np")).andReturn(true);
    replay(cl);
    History history = new DefaultHistory();
    history.add("foo");
    history.add("bar");
    baos = new ByteArrayOutputStream();
    // Construct a platform dependent new-line
    String input = String.format("!1%n");
    terminal = TerminalBuilder.builder().system(false).streams(new ByteArrayInputStream(input.getBytes()), baos).build();
    reader = LineReaderBuilder.builder().history(history).terminal(terminal).build();
    shell = new Shell(reader);
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) Shell(org.apache.accumulo.shell.Shell) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultHistory(org.jline.reader.impl.history.DefaultHistory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultHistory(org.jline.reader.impl.history.DefaultHistory) History(org.jline.reader.History) Before(org.junit.Before)

Example 8 with Shell

use of org.apache.accumulo.shell.Shell in project accumulo by apache.

the class SetIterCommandTest method addColumnAgeOffFilter.

@Test
public void addColumnAgeOffFilter() throws Exception {
    AccumuloClient client = EasyMock.createMock(AccumuloClient.class);
    CommandLine cli = EasyMock.createMock(CommandLine.class);
    Shell shellState = EasyMock.createMock(Shell.class);
    LineReader reader = EasyMock.createMock(LineReader.class);
    PrintWriter pw = EasyMock.createMock(PrintWriter.class);
    TableOperations tableOperations = EasyMock.createMock(TableOperations.class);
    // Command line parsing
    EasyMock.expect(cli.hasOption("all")).andReturn(true);
    EasyMock.expect(cli.hasOption("all")).andReturn(true);
    EasyMock.expect(cli.hasOption("all")).andReturn(true);
    EasyMock.expect(cli.hasOption("t")).andReturn(true);
    EasyMock.expect(cli.hasOption("t")).andReturn(true);
    EasyMock.expect(cli.getOptionValue("t")).andReturn("foo");
    EasyMock.expect(cli.hasOption("ns")).andReturn(false);
    EasyMock.expect(cli.getOptionValue("p")).andReturn("21");
    EasyMock.expect(cli.getOptionValue("class")).andReturn("org.apache.accumulo.core.iterators.user.ColumnAgeOffFilter");
    EasyMock.expect(cli.hasOption("ageoff")).andReturn(false);
    EasyMock.expect(cli.hasOption("regex")).andReturn(false);
    EasyMock.expect(cli.hasOption("reqvis")).andReturn(false);
    EasyMock.expect(cli.hasOption("vers")).andReturn(false);
    EasyMock.expect(cli.getOptionValue("n", null)).andReturn(null);
    // Loading the class
    EasyMock.expect(shellState.getClassLoader(cli, shellState)).andReturn(ClassLoaderUtil.getClassLoader(null));
    // Parsing iterator options
    pw.flush();
    EasyMock.expectLastCall().times(3);
    pw.println(EasyMock.anyObject(String.class));
    EasyMock.expectLastCall().times(2);
    EasyMock.expect(shellState.getReader()).andReturn(reader);
    EasyMock.expect(shellState.getWriter()).andReturn(pw);
    // Shell asking for negate option, we pass in an empty string to pickup the default value of
    // 'false'
    EasyMock.expect(reader.readLine(EasyMock.anyObject(String.class))).andReturn("");
    // Shell asking for the unnamed option for the column (a:a) and the TTL (1)
    EasyMock.expect(reader.readLine(EasyMock.anyObject(String.class))).andReturn("a:a 1");
    // Shell asking for another unnamed option; we pass in an empty string to signal that we are
    // done adding options
    EasyMock.expect(reader.readLine(EasyMock.anyObject(String.class))).andReturn("");
    EasyMock.expect(shellState.getAccumuloClient()).andReturn(client);
    // Table exists
    EasyMock.expect(client.tableOperations()).andReturn(tableOperations);
    EasyMock.expect(tableOperations.exists("foo")).andReturn(true);
    // Testing class load
    EasyMock.expect(shellState.getAccumuloClient()).andReturn(client);
    EasyMock.expect(client.tableOperations()).andReturn(tableOperations);
    EasyMock.expect(tableOperations.testClassLoad("foo", "org.apache.accumulo.core.iterators.user.ColumnAgeOffFilter", SortedKeyValueIterator.class.getName())).andReturn(true);
    // Attach iterator
    EasyMock.expect(shellState.getAccumuloClient()).andReturn(client);
    EasyMock.expect(client.tableOperations()).andReturn(tableOperations);
    tableOperations.attachIterator(EasyMock.eq("foo"), EasyMock.anyObject(IteratorSetting.class), EasyMock.eq(EnumSet.allOf(IteratorScope.class)));
    EasyMock.expectLastCall().once();
    EasyMock.expect(shellState.getTableName()).andReturn("foo").anyTimes();
    EasyMock.replay(client, cli, shellState, reader, tableOperations, pw);
    cmd.execute("setiter -all -p 21 -t foo" + " -class org.apache.accumulo.core.iterators.user.ColumnAgeOffFilter", cli, shellState);
    EasyMock.verify(client, cli, shellState, reader, tableOperations, pw);
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) CommandLine(org.apache.commons.cli.CommandLine) Shell(org.apache.accumulo.shell.Shell) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) LineReader(org.jline.reader.LineReader) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

Shell (org.apache.accumulo.shell.Shell)8 CommandLine (org.apache.commons.cli.CommandLine)7 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)6 Test (org.junit.Test)6 LineReader (org.jline.reader.LineReader)5 SecurityOperations (org.apache.accumulo.core.client.admin.SecurityOperations)4 Authorizations (org.apache.accumulo.core.security.Authorizations)3 PrintWriter (java.io.PrintWriter)2 TableOperations (org.apache.accumulo.core.client.admin.TableOperations)2 Before (org.junit.Before)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 TreeMap (java.util.TreeMap)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 InstanceOperations (org.apache.accumulo.core.client.admin.InstanceOperations)1 ClientContext (org.apache.accumulo.core.clientImpl.ClientContext)1 SortedKeyValueIterator (org.apache.accumulo.core.iterators.SortedKeyValueIterator)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 Options (org.apache.commons.cli.Options)1