public void test() throws Exception {
Connector conn = new ZooKeeperInstance(accumulo.getInstanceName(), accumulo.getZooKeepers()).getConnector("root", "superSecret".getBytes());
conn.tableOperations().create("table1");
conn.securityOperations().createUser("user1", "pass1".getBytes(), new Authorizations("A", "B"));
conn.securityOperations().grantTablePermission("user1", "table1", TablePermission.WRITE);
conn.securityOperations().grantTablePermission("user1", "table1", TablePermission.READ);
IteratorSetting is = new IteratorSetting(10, SummingCombiner.class);
SummingCombiner.setEncodingType(is, LongCombiner.Type.STRING);
SummingCombiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("META", "COUNT")));
conn.tableOperations().attachIterator("table1", is);
Connector uconn = new ZooKeeperInstance(accumulo.getInstanceName(), accumulo.getZooKeepers()).getConnector("user1", "pass1".getBytes());
BatchWriter bw = uconn.createBatchWriter("table1", 10000, 1000000, 2);
UUID uuid = UUID.randomUUID();
Mutation m = new Mutation(uuid.toString());
m.put("META", "SIZE", new ColumnVisibility("A|B"), "8");
m.put("META", "CRC", new ColumnVisibility("A|B"), "456");
m.put("META", "COUNT", new ColumnVisibility("A|B"), "1");
m.put("DATA", "IMG", new ColumnVisibility("A&B"), "ABCDEFGH");
bw.addMutation(m);
bw.flush();
m = new Mutation(uuid.toString());
m.put("META", "COUNT", new ColumnVisibility("A|B"), "1");
m.put("META", "CRC", new ColumnVisibility("A|B"), "123");
bw.addMutation(m);
bw.close();
int count = 0;
Scanner scanner = uconn.createScanner("table1", new Authorizations("A"));
for (Entry<Key,Value> entry : scanner) {
if (entry.getKey().getColumnQualifierData().toString().equals("COUNT")) {
Assert.assertEquals("2", entry.getValue().toString());
} else if (entry.getKey().getColumnQualifierData().toString().equals("SIZE")) {
Assert.assertEquals("8", entry.getValue().toString());
} else if (entry.getKey().getColumnQualifierData().toString().equals("CRC")) {
Assert.assertEquals("123", entry.getValue().toString());
} else {
Assert.assertTrue(false);
}
count++;
}
Assert.assertEquals(3, count);
count = 0;
scanner = uconn.createScanner("table1", new Authorizations("A", "B"));
for (Entry<Key,Value> entry : scanner) {
if (entry.getKey().getColumnQualifierData().toString().equals("IMG")) {
Assert.assertEquals("ABCDEFGH", entry.getValue().toString());
}
count++;