use of org.apache.accumulo.core.client.BatchWriter in project accumulo by apache.
the class MockNamespacesTest method testNamespaceIterators.
/**
* This tests adding iterators to a namespace, listing them, and removing them
*/
@Test
public void testNamespaceIterators() throws Exception {
String namespace = "iterator";
String tableName = namespace + ".table";
String iter = "thing";
conn.namespaceOperations().create(namespace);
conn.tableOperations().create(tableName);
IteratorSetting setting = new IteratorSetting(250, iter, SimpleFilter.class.getName());
HashSet<IteratorScope> scope = new HashSet<>();
scope.add(IteratorScope.scan);
conn.namespaceOperations().attachIterator(namespace, setting, EnumSet.copyOf(scope));
BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
Mutation m = new Mutation("r");
m.put("a", "b", new Value("abcde".getBytes(UTF_8)));
bw.addMutation(m);
bw.flush();
Scanner s = conn.createScanner(tableName, Authorizations.EMPTY);
System.out.println(s.iterator().next());
// do scanners work correctly in mock?
// assertTrue(!s.iterator().hasNext());
assertTrue(conn.namespaceOperations().listIterators(namespace).containsKey(iter));
conn.namespaceOperations().removeIterator(namespace, iter, EnumSet.copyOf(scope));
}
use of org.apache.accumulo.core.client.BatchWriter in project accumulo by apache.
the class MockTableOperationsTest method testDeleteRows.
@Test
public void testDeleteRows() throws Exception {
TableOperations to = conn.tableOperations();
to.create("test");
BatchWriter bw = conn.createBatchWriter("test", new BatchWriterConfig());
for (int r = 0; r < 20; r++) {
Mutation m = new Mutation("" + r);
for (int c = 0; c < 5; c++) {
m.put(new Text("cf"), new Text("" + c), new Value(("" + c).getBytes()));
}
bw.addMutation(m);
}
bw.flush();
to.deleteRows("test", new Text("1"), new Text("2"));
Scanner s = conn.createScanner("test", Authorizations.EMPTY);
int oneCnt = 0;
for (Entry<Key, Value> entry : s) {
char rowStart = entry.getKey().getRow().toString().charAt(0);
Assert.assertTrue(rowStart != '2');
oneCnt += rowStart == '1' ? 1 : 0;
}
Assert.assertEquals(5, oneCnt);
}
use of org.apache.accumulo.core.client.BatchWriter in project accumulo by apache.
the class TestBatchScanner821 method test.
@Test
public void test() throws Exception {
MockInstance inst = new MockInstance();
Connector conn = inst.getConnector("root", new PasswordToken(""));
conn.tableOperations().create("test");
BatchWriter bw = conn.createBatchWriter("test", new BatchWriterConfig());
for (String row : "A,B,C,D".split(",")) {
Mutation m = new Mutation(row);
m.put("cf", "cq", "");
bw.addMutation(m);
}
bw.flush();
BatchScanner bs = conn.createBatchScanner("test", Authorizations.EMPTY, 1);
IteratorSetting cfg = new IteratorSetting(100, TransformIterator.class);
bs.addScanIterator(cfg);
bs.setRanges(Collections.singletonList(new Range("A", "Z")));
StringBuilder sb = new StringBuilder();
String comma = "";
for (Entry<Key, Value> entry : bs) {
sb.append(comma);
sb.append(entry.getKey().getRow());
comma = ",";
}
assertEquals("a,b,c,d", sb.toString());
}
use of org.apache.accumulo.core.client.BatchWriter in project accumulo by apache.
the class KerberosIT method testUserPrivilegesForTable.
@Test
public void testUserPrivilegesForTable() throws Exception {
String user1 = testName.getMethodName();
final File user1Keytab = new File(kdc.getKeytabDir(), user1 + ".keytab");
if (user1Keytab.exists() && !user1Keytab.delete()) {
log.warn("Unable to delete {}", user1Keytab);
}
// Create some new users -- cannot contain realm
kdc.createPrincipal(user1Keytab, user1);
final String qualifiedUser1 = kdc.qualifyUser(user1);
// Log in as user1
UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(qualifiedUser1, user1Keytab.getAbsolutePath());
log.info("Logged in as {}", user1);
ugi.doAs(new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
// Indirectly creates this user when we use it
Connector conn = mac.getConnector(qualifiedUser1, new KerberosToken());
log.info("Created connector as {}", qualifiedUser1);
// The new user should have no system permissions
for (SystemPermission perm : SystemPermission.values()) {
assertFalse(conn.securityOperations().hasSystemPermission(qualifiedUser1, perm));
}
return null;
}
});
final String table = testName.getMethodName() + "_user_table";
final String viz = "viz";
ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(rootUser.getPrincipal(), rootUser.getKeytab().getAbsolutePath());
ugi.doAs(new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
Connector conn = mac.getConnector(rootUser.getPrincipal(), new KerberosToken());
conn.tableOperations().create(table);
// Give our unprivileged user permission on the table we made for them
conn.securityOperations().grantTablePermission(qualifiedUser1, table, TablePermission.READ);
conn.securityOperations().grantTablePermission(qualifiedUser1, table, TablePermission.WRITE);
conn.securityOperations().grantTablePermission(qualifiedUser1, table, TablePermission.ALTER_TABLE);
conn.securityOperations().grantTablePermission(qualifiedUser1, table, TablePermission.DROP_TABLE);
conn.securityOperations().changeUserAuthorizations(qualifiedUser1, new Authorizations(viz));
return null;
}
});
// Switch back to the original user
ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(qualifiedUser1, user1Keytab.getAbsolutePath());
ugi.doAs(new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
Connector conn = mac.getConnector(qualifiedUser1, new KerberosToken());
// Make sure we can actually use the table we made
// Write data
final long ts = 1000l;
BatchWriter bw = conn.createBatchWriter(table, new BatchWriterConfig());
Mutation m = new Mutation("a");
m.put("b", "c", new ColumnVisibility(viz.getBytes()), ts, "d");
bw.addMutation(m);
bw.close();
// Compact
conn.tableOperations().compact(table, new CompactionConfig().setWait(true).setFlush(true));
// Alter
conn.tableOperations().setProperty(table, Property.TABLE_BLOOM_ENABLED.getKey(), "true");
// Read (and proper authorizations)
try (Scanner s = conn.createScanner(table, new Authorizations(viz))) {
Iterator<Entry<Key, Value>> iter = s.iterator();
assertTrue("No results from iterator", iter.hasNext());
Entry<Key, Value> entry = iter.next();
assertEquals(new Key("a", "b", "c", viz, ts), entry.getKey());
assertEquals(new Value("d".getBytes()), entry.getValue());
assertFalse("Had more results from iterator", iter.hasNext());
return null;
}
}
});
}
use of org.apache.accumulo.core.client.BatchWriter in project accumulo by apache.
the class KerberosIT method createTableWithDataAndCompact.
/**
* Creates a table, adds a record to it, and then compacts the table. A simple way to make sure that the system user exists (since the master does an RPC to
* the tserver which will create the system user if it doesn't already exist).
*/
private void createTableWithDataAndCompact(Connector conn) throws TableNotFoundException, AccumuloSecurityException, AccumuloException, TableExistsException {
final String table = testName.getMethodName() + "_table";
conn.tableOperations().create(table);
BatchWriter bw = conn.createBatchWriter(table, new BatchWriterConfig());
Mutation m = new Mutation("a");
m.put("b", "c", "d");
bw.addMutation(m);
bw.close();
conn.tableOperations().compact(table, new CompactionConfig().setFlush(true).setWait(true));
}
Aggregations