@Test public void addColumnAgeOffFilter() throws Exception { AccumuloClient client = EasyMock.createMock(AccumuloClient.class); CommandLine cli = EasyMock.createMock(CommandLine.class); Shell shellState = EasyMock.createMock(Shell.class); ConsoleReader reader = EasyMock.createMock(ConsoleReader.class); Writer out = EasyMock.createMock(PrintWriter.class); TableOperations tableOperations = EasyMock.createMock(TableOperations.class); 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); EasyMock.expect(shellState.getClassLoader(cli, shellState)) .andReturn(AccumuloVFSClassLoader.getClassLoader()); Field field = reader.getClass().getSuperclass().getDeclaredField("out"); field.setAccessible(true); field.set(reader, out); reader.flush(); EasyMock.expectLastCall().times(3); EasyMock.expect(shellState.getReader()).andReturn(reader); EasyMock.expect(reader.readLine(EasyMock.anyObject(String.class))).andReturn(""); EasyMock.expect(reader.readLine(EasyMock.anyObject(String.class))).andReturn("a:a 1"); EasyMock.expect(reader.readLine(EasyMock.anyObject(String.class))).andReturn(""); EasyMock.expect(shellState.getAccumuloClient()).andReturn(client); EasyMock.expect(client.tableOperations()).andReturn(tableOperations); EasyMock.expect(tableOperations.exists("foo")).andReturn(true); 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); 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); 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); }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException, ShellCommandException { boolean tables = cl.hasOption(OptUtil.tableOpt().getOpt()) || !shellState.getTableName().isEmpty(); boolean namespaces = cl.hasOption(OptUtil.namespaceOpt().getOpt()); final int priority = Integer.parseInt(cl.getOptionValue(priorityOpt.getOpt())); final Map<String,String> options = new HashMap<>(); String classname = cl.getOptionValue(classnameTypeOpt.getOpt()); if (cl.hasOption(regexTypeOpt.getOpt())) { classname = RegExFilter.class.getName(); } else if (cl.hasOption(ageoffTypeOpt.getOpt())) { classname = AgeOffFilter.class.getName(); } else if (cl.hasOption(versionTypeOpt.getOpt())) { classname = VersioningIterator.class.getName(); } else if (cl.hasOption(reqvisTypeOpt.getOpt())) { classname = ReqVisFilter.class.getName(); } String currentTableName = shellState.getTableName(); String tmpTable = null; String configuredName; try { if (profileOpt != null && (currentTableName == null || currentTableName.isBlank())) { tmpTable = "accumulo.metadata"; shellState.setTableName(tmpTable); tables = cl.hasOption(OptUtil.tableOpt().getOpt()) || !currentTableName.isEmpty(); } ClassLoader classloader = shellState.getClassLoader(cl, shellState); configuredName = setUpOptions(classloader, shellState.getReader(), classname, options); } finally { if (tmpTable != null) { shellState.setTableName(currentTableName); } } String name = cl.getOptionValue(nameOpt.getOpt(), null); if (name == null && configuredName == null) { throw new IllegalArgumentException("No provided or default name for iterator"); } else if (name == null) { name = configuredName; } if (namespaces) { try { setNamespaceProperties(cl, shellState, priority, options, classname, name); } catch (NamespaceNotFoundException e) { throw new IllegalArgumentException(e); } } else if (tables) { setTableProperties(cl, shellState, priority, options, classname, name); } else { throw new IllegalArgumentException("No table or namespace specified"); } return 0; }
SetIterCommand extends Command { @Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException, ShellCommandException { boolean tables = cl.hasOption(OptUtil.tableOpt().getOpt()) || !shellState.getTableName().isEmpty(); boolean namespaces = cl.hasOption(OptUtil.namespaceOpt().getOpt()); final int priority = Integer.parseInt(cl.getOptionValue(priorityOpt.getOpt())); final Map<String,String> options = new HashMap<>(); String classname = cl.getOptionValue(classnameTypeOpt.getOpt()); if (cl.hasOption(regexTypeOpt.getOpt())) { classname = RegExFilter.class.getName(); } else if (cl.hasOption(ageoffTypeOpt.getOpt())) { classname = AgeOffFilter.class.getName(); } else if (cl.hasOption(versionTypeOpt.getOpt())) { classname = VersioningIterator.class.getName(); } else if (cl.hasOption(reqvisTypeOpt.getOpt())) { classname = ReqVisFilter.class.getName(); } String currentTableName = shellState.getTableName(); String tmpTable = null; String configuredName; try { if (profileOpt != null && (currentTableName == null || currentTableName.isBlank())) { tmpTable = "accumulo.metadata"; shellState.setTableName(tmpTable); tables = cl.hasOption(OptUtil.tableOpt().getOpt()) || !currentTableName.isEmpty(); } ClassLoader classloader = shellState.getClassLoader(cl, shellState); configuredName = setUpOptions(classloader, shellState.getReader(), classname, options); } finally { if (tmpTable != null) { shellState.setTableName(currentTableName); } } String name = cl.getOptionValue(nameOpt.getOpt(), null); if (name == null && configuredName == null) { throw new IllegalArgumentException("No provided or default name for iterator"); } else if (name == null) { name = configuredName; } if (namespaces) { try { setNamespaceProperties(cl, shellState, priority, options, classname, name); } catch (NamespaceNotFoundException e) { throw new IllegalArgumentException(e); } } else if (tables) { setTableProperties(cl, shellState, priority, options, classname, name); } else { throw new IllegalArgumentException("No table or namespace specified"); } return 0; } }
SetIterCommand extends Command { @Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException, ShellCommandException { boolean tables = cl.hasOption(OptUtil.tableOpt().getOpt()) || !shellState.getTableName().isEmpty(); boolean namespaces = cl.hasOption(OptUtil.namespaceOpt().getOpt()); final int priority = Integer.parseInt(cl.getOptionValue(priorityOpt.getOpt())); final Map<String,String> options = new HashMap<>(); String classname = cl.getOptionValue(classnameTypeOpt.getOpt()); if (cl.hasOption(regexTypeOpt.getOpt())) { classname = RegExFilter.class.getName(); } else if (cl.hasOption(ageoffTypeOpt.getOpt())) { classname = AgeOffFilter.class.getName(); } else if (cl.hasOption(versionTypeOpt.getOpt())) { classname = VersioningIterator.class.getName(); } else if (cl.hasOption(reqvisTypeOpt.getOpt())) { classname = ReqVisFilter.class.getName(); } String currentTableName = shellState.getTableName(); String tmpTable = null; String configuredName; try { if (profileOpt != null && (currentTableName == null || currentTableName.isBlank())) { tmpTable = "accumulo.metadata"; shellState.setTableName(tmpTable); tables = cl.hasOption(OptUtil.tableOpt().getOpt()) || !currentTableName.isEmpty(); } ClassLoader classloader = shellState.getClassLoader(cl, shellState); configuredName = setUpOptions(classloader, shellState.getReader(), classname, options); } finally { if (tmpTable != null) { shellState.setTableName(currentTableName); } } String name = cl.getOptionValue(nameOpt.getOpt(), null); if (name == null && configuredName == null) { throw new IllegalArgumentException("No provided or default name for iterator"); } else if (name == null) { name = configuredName; } if (namespaces) { try { setNamespaceProperties(cl, shellState, priority, options, classname, name); } catch (NamespaceNotFoundException e) { throw new IllegalArgumentException(e); } } else if (tables) { setTableProperties(cl, shellState, priority, options, classname, name); } else { throw new IllegalArgumentException("No table or namespace specified"); } return 0; }  }
SetIterCommand extends Command { @Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException, ShellCommandException { boolean tables = cl.hasOption(OptUtil.tableOpt().getOpt()) || !shellState.getTableName().isEmpty(); boolean namespaces = cl.hasOption(OptUtil.namespaceOpt().getOpt()); final int priority = Integer.parseInt(cl.getOptionValue(priorityOpt.getOpt())); final Map<String,String> options = new HashMap<>(); String classname = cl.getOptionValue(classnameTypeOpt.getOpt()); if (cl.hasOption(regexTypeOpt.getOpt())) { classname = RegExFilter.class.getName(); } else if (cl.hasOption(ageoffTypeOpt.getOpt())) { classname = AgeOffFilter.class.getName(); } else if (cl.hasOption(versionTypeOpt.getOpt())) { classname = VersioningIterator.class.getName(); } else if (cl.hasOption(reqvisTypeOpt.getOpt())) { classname = ReqVisFilter.class.getName(); } String currentTableName = shellState.getTableName(); String tmpTable = null; String configuredName; try { if (profileOpt != null && (currentTableName == null || currentTableName.isBlank())) { tmpTable = "accumulo.metadata"; shellState.setTableName(tmpTable); tables = cl.hasOption(OptUtil.tableOpt().getOpt()) || !currentTableName.isEmpty(); } ClassLoader classloader = shellState.getClassLoader(cl, shellState); configuredName = setUpOptions(classloader, shellState.getReader(), classname, options); } finally { if (tmpTable != null) { shellState.setTableName(currentTableName); } } String name = cl.getOptionValue(nameOpt.getOpt(), null); if (name == null && configuredName == null) { throw new IllegalArgumentException("No provided or default name for iterator"); } else if (name == null) { name = configuredName; } if (namespaces) { try { setNamespaceProperties(cl, shellState, priority, options, classname, name); } catch (NamespaceNotFoundException e) { throw new IllegalArgumentException(e); } } else if (tables) { setTableProperties(cl, shellState, priority, options, classname, name); } else { throw new IllegalArgumentException("No table or namespace specified"); } return 0; }  @Override int execute(final String fullCommand, final CommandLine cl, final Shell shellState); @Override String description(); @Override Options getOptions(); @Override int numArgs(); }
SetIterCommand extends Command { @Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException, ShellCommandException { boolean tables = cl.hasOption(OptUtil.tableOpt().getOpt()) || !shellState.getTableName().isEmpty(); boolean namespaces = cl.hasOption(OptUtil.namespaceOpt().getOpt()); final int priority = Integer.parseInt(cl.getOptionValue(priorityOpt.getOpt())); final Map<String,String> options = new HashMap<>(); String classname = cl.getOptionValue(classnameTypeOpt.getOpt()); if (cl.hasOption(regexTypeOpt.getOpt())) { classname = RegExFilter.class.getName(); } else if (cl.hasOption(ageoffTypeOpt.getOpt())) { classname = AgeOffFilter.class.getName(); } else if (cl.hasOption(versionTypeOpt.getOpt())) { classname = VersioningIterator.class.getName(); } else if (cl.hasOption(reqvisTypeOpt.getOpt())) { classname = ReqVisFilter.class.getName(); } String currentTableName = shellState.getTableName(); String tmpTable = null; String configuredName; try { if (profileOpt != null && (currentTableName == null || currentTableName.isBlank())) { tmpTable = "accumulo.metadata"; shellState.setTableName(tmpTable); tables = cl.hasOption(OptUtil.tableOpt().getOpt()) || !currentTableName.isEmpty(); } ClassLoader classloader = shellState.getClassLoader(cl, shellState); configuredName = setUpOptions(classloader, shellState.getReader(), classname, options); } finally { if (tmpTable != null) { shellState.setTableName(currentTableName); } } String name = cl.getOptionValue(nameOpt.getOpt(), null); if (name == null && configuredName == null) { throw new IllegalArgumentException("No provided or default name for iterator"); } else if (name == null) { name = configuredName; } if (namespaces) { try { setNamespaceProperties(cl, shellState, priority, options, classname, name); } catch (NamespaceNotFoundException e) { throw new IllegalArgumentException(e); } } else if (tables) { setTableProperties(cl, shellState, priority, options, classname, name); } else { throw new IllegalArgumentException("No table or namespace specified"); } return 0; }  @Override int execute(final String fullCommand, final CommandLine cl, final Shell shellState); @Override String description(); @Override Options getOptions(); @Override int numArgs();  }