@Test
public void testAttachIterator() throws Exception {
Tester t = new Tester();
Map<String,String> empty = Collections.emptyMap();
t.attachIterator("table", new IteratorSetting(10, "someName", "foo.bar", empty), EnumSet.of(IteratorScope.scan));
t.check("table", new String[] {"table.iterator.scan.someName=10,foo.bar",});
t.removeIterator("table", "someName", EnumSet.of(IteratorScope.scan));
t.check("table", new String[] {});
IteratorSetting setting = new IteratorSetting(10, "someName", "foo.bar");
setting.addOptions(Collections.singletonMap("key", "value"));
t.attachIterator("table", setting, EnumSet.of(IteratorScope.majc));
setting = new IteratorSetting(10, "someName", "foo.bar");
t.attachIterator("table", setting, EnumSet.of(IteratorScope.scan));
t.check("table", new String[] {"table.iterator.majc.someName=10,foo.bar", "table.iterator.majc.someName.opt.key=value",
"table.iterator.scan.someName=10,foo.bar",});
t.removeIterator("table", "someName", EnumSet.of(IteratorScope.scan));
setting = new IteratorSetting(20, "otherName", "some.classname");
setting.addOptions(Collections.singletonMap("key", "value"));
t.attachIterator("table", setting, EnumSet.of(IteratorScope.majc));
setting = new IteratorSetting(20, "otherName", "some.classname");
t.attachIterator("table", setting, EnumSet.of(IteratorScope.scan));
Map<String,EnumSet<IteratorScope>> two = t.listIterators("table");
Assert.assertEquals(2, two.size());
Assert.assertTrue(two.containsKey("otherName"));
Assert.assertTrue(two.get("otherName").size() == 2);
Assert.assertTrue(two.get("otherName").contains(IteratorScope.majc));
Assert.assertTrue(two.get("otherName").contains(IteratorScope.scan));
Assert.assertTrue(two.containsKey("someName"));
Assert.assertTrue(two.get("someName").size() == 1);
Assert.assertTrue(two.get("someName").contains(IteratorScope.majc));
t.removeIterator("table", "someName", EnumSet.allOf(IteratorScope.class));
t.check("table", new String[] {"table.iterator.majc.otherName=20,some.classname", "table.iterator.majc.otherName.opt.key=value",
"table.iterator.scan.otherName=20,some.classname",});
setting = t.getIteratorSetting("table", "otherName", IteratorScope.scan);
Assert.assertEquals(20, setting.getPriority());
Assert.assertEquals("some.classname", setting.getIteratorClass());
Assert.assertTrue(setting.getOptions().isEmpty());
setting = t.getIteratorSetting("table", "otherName", IteratorScope.majc);
Assert.assertEquals(20, setting.getPriority());
Assert.assertEquals("some.classname", setting.getIteratorClass());
Assert.assertFalse(setting.getOptions().isEmpty());
Assert.assertEquals(Collections.singletonMap("key", "value"), setting.getOptions());
t.attachIterator("table", setting, EnumSet.of(IteratorScope.minc));
t.check("table", new String[] {"table.iterator.majc.otherName=20,some.classname", "table.iterator.majc.otherName.opt.key=value",
"table.iterator.minc.otherName=20,some.classname", "table.iterator.minc.otherName.opt.key=value", "table.iterator.scan.otherName=20,some.classname",});
try {
t.attachIterator("table", setting);
Assert.fail();
} catch (AccumuloException e) {}
setting.setName("thirdName");
try {
t.attachIterator("table", setting);
Assert.fail();
} catch (AccumuloException e) {}
setting.setPriority(10);
t.setProperty("table", "table.iterator.minc.thirdName.opt.key", "value");
try {
t.attachIterator("table", setting);
Assert.fail();
} catch (AccumuloException e) {}