You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2013/10/11 08:37:06 UTC
[1/4] ACCUMULO-1599 Move MiniAccumuloCluster output to target
directory
Updated Branches:
refs/heads/master 741daecfd -> aa7110234
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/GarbageCollectorIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/GarbageCollectorIT.java b/test/src/test/java/org/apache/accumulo/test/functional/GarbageCollectorIT.java
index 06c86e6..7b9282c 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/GarbageCollectorIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/GarbageCollectorIT.java
@@ -51,7 +51,7 @@ import org.apache.hadoop.io.Text;
import org.junit.Test;
public class GarbageCollectorIT extends ConfigurableMacIT {
-
+
@Override
public void configure(MiniAccumuloConfig cfg) {
Map<String,String> settings = new HashMap<String,String>();
@@ -61,7 +61,7 @@ public class GarbageCollectorIT extends ConfigurableMacIT {
settings.put(Property.TSERV_MAJC_DELAY.getKey(), "1");
cfg.setSiteConfig(settings);
}
-
+
@Test(timeout = 4 * 60 * 1000)
public void gcTest() throws Exception {
Connector c = getConnector();
@@ -88,7 +88,7 @@ public class GarbageCollectorIT extends ConfigurableMacIT {
assertTrue(after < before);
gc.destroy();
}
-
+
@Test(timeout = 4 * 60 * 1000)
public void gcLotsOfCandidatesIT() throws Exception {
log.info("Filling !METADATA table with bogus delete flags");
@@ -101,12 +101,12 @@ public class GarbageCollectorIT extends ConfigurableMacIT {
gc.destroy();
assertTrue(output.contains("delete candidates has exceeded"));
}
-
+
@Test(timeout = 4 * 60 * 1000)
public void dontGCRootLog() throws Exception {
// dirty !METADATA
Connector c = getConnector();
- String table = makeTableName();
+ String table = getTableNames(1)[0];
c.tableOperations().create(table);
// let gc run for a bit
Process gc = cluster.exec(SimpleGarbageCollector.class);
@@ -120,11 +120,12 @@ public class GarbageCollectorIT extends ConfigurableMacIT {
cluster.start();
// did it recover?
Scanner scanner = c.createScanner(MetadataTable.NAME, Authorizations.EMPTY);
- for (@SuppressWarnings("unused") Entry<Key,Value> unused : scanner) {
-
+ for (@SuppressWarnings("unused")
+ Entry<Key,Value> unused : scanner) {
+
}
}
-
+
private int countFiles() throws Exception {
FileSystem fs = FileSystem.get(CachedConfiguration.getInstance());
int result = 0;
@@ -135,11 +136,11 @@ public class GarbageCollectorIT extends ConfigurableMacIT {
}
return result;
}
-
+
public static void addEntries(Connector conn, BatchWriterOpts bwOpts) throws Exception {
conn.securityOperations().grantTablePermission(conn.whoami(), MetadataTable.NAME, TablePermission.WRITE);
BatchWriter bw = conn.createBatchWriter(MetadataTable.NAME, bwOpts.getBatchWriterConfig());
-
+
for (int i = 0; i < 100000; ++i) {
final Text emptyText = new Text("");
Text row = new Text(String.format("%s%s%020d%s", MetadataSchema.DeletesSection.getRowPrefix(), "/", i,
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/MapReduceIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/MapReduceIT.java b/test/src/test/java/org/apache/accumulo/test/functional/MapReduceIT.java
index 69825bc..9e42e55 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/MapReduceIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/MapReduceIT.java
@@ -34,15 +34,15 @@ import org.apache.hadoop.io.Text;
import org.codehaus.plexus.util.Base64;
import org.junit.Test;
-public class MapReduceIT extends SimpleMacIT {
-
+public class MapReduceIT extends ConfigurableMacIT {
+
static final String tablename = "mapredf";
static final String input_cf = "cf-HASHTYPE";
static final String input_cq = "cq-NOTHASHED";
static final String input_cfcq = input_cf + ":" + input_cq;
static final String output_cq = "cq-MD4BASE64";
- static final String output_cfcq = input_cf + ":" + output_cq;
-
+ static final String output_cfcq = input_cf + ":" + output_cq;
+
@Test(timeout = 60 * 1000)
public void test() throws Exception {
Connector c = getConnector();
@@ -54,16 +54,11 @@ public class MapReduceIT extends SimpleMacIT {
bw.addMutation(m);
}
bw.close();
-
- Process hash = exec(RowHash.class,
- "-i", c.getInstance().getInstanceName(),
- "-z", c.getInstance().getZooKeepers(),
- "-u", "root",
- "-p", ROOT_PASSWORD,
- "-t", tablename,
- "--column", input_cfcq);
+
+ Process hash = exec(RowHash.class, "-i", c.getInstance().getInstanceName(), "-z", c.getInstance().getZooKeepers(), "-u", "root", "-p", ROOT_PASSWORD, "-t",
+ tablename, "--column", input_cfcq);
assertEquals(0, hash.waitFor());
-
+
Scanner s = c.createScanner(tablename, Authorizations.EMPTY);
s.fetchColumn(new Text(input_cf), new Text(output_cq));
int i = 0;
@@ -73,8 +68,7 @@ public class MapReduceIT extends SimpleMacIT {
assertEquals(entry.getValue().toString(), new String(check));
i++;
}
-
+
}
-
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/MergeIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/MergeIT.java b/test/src/test/java/org/apache/accumulo/test/functional/MergeIT.java
index 2ae90ee..27b4f27 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/MergeIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/MergeIT.java
@@ -39,18 +39,18 @@ import org.apache.hadoop.io.Text;
import org.junit.Test;
public class MergeIT extends SimpleMacIT {
-
- SortedSet<Text> splits(String [] points) {
+
+ SortedSet<Text> splits(String[] points) {
SortedSet<Text> result = new TreeSet<Text>();
for (String point : points)
result.add(new Text(point));
return result;
}
-
+
@Test(timeout = 60 * 1000)
public void merge() throws Exception {
Connector c = getConnector();
- String tableName = makeTableName();
+ String tableName = getTableNames(1)[0];
c.tableOperations().create(tableName);
c.tableOperations().addSplits(tableName, splits("a b c d e f g h i j k".split(" ")));
BatchWriter bw = c.createBatchWriter(tableName, null);
@@ -64,11 +64,11 @@ public class MergeIT extends SimpleMacIT {
c.tableOperations().merge(tableName, new Text("c1"), new Text("f1"));
assertEquals(8, c.tableOperations().listSplits(tableName).size());
}
-
+
@Test(timeout = 60 * 1000)
public void mergeSize() throws Exception {
Connector c = getConnector();
- String tableName = makeTableName();
+ String tableName = getTableNames(1)[0];
c.tableOperations().create(tableName);
c.tableOperations().addSplits(tableName, splits("a b c d e f g h i j k l m n o p q r s t u v w x y z".split(" ")));
BatchWriter bw = c.createBatchWriter(tableName, null);
@@ -94,22 +94,22 @@ public class MergeIT extends SimpleMacIT {
}
return result;
}
-
+
private String[] ns(String... strings) {
return strings;
}
-
+
@Test(timeout = 4 * 60 * 1000)
public void mergeTest() throws Exception {
int tc = 0;
Connector c = getConnector();
- String tableName = makeTableName();
+ String tableName = getTableNames(1)[0];
runMergeTest(c, tableName + tc++, ns(), ns(), ns("l", "m", "n"), ns(null, "l"), ns(null, "n"));
-
+
runMergeTest(c, tableName + tc++, ns("m"), ns(), ns("l", "m", "n"), ns(null, "l"), ns(null, "n"));
runMergeTest(c, tableName + tc++, ns("m"), ns("m"), ns("l", "m", "n"), ns("m", "n"), ns(null, "z"));
runMergeTest(c, tableName + tc++, ns("m"), ns("m"), ns("l", "m", "n"), ns(null, "b"), ns("l", "m"));
-
+
runMergeTest(c, tableName + tc++, ns("b", "m", "r"), ns(), ns("a", "b", "c", "l", "m", "n", "q", "r", "s"), ns(null, "a"), ns(null, "s"));
runMergeTest(c, tableName + tc++, ns("b", "m", "r"), ns("m", "r"), ns("a", "b", "c", "l", "m", "n", "q", "r", "s"), ns(null, "a"), ns("c", "m"));
runMergeTest(c, tableName + tc++, ns("b", "m", "r"), ns("r"), ns("a", "b", "c", "l", "m", "n", "q", "r", "s"), ns(null, "a"), ns("n", "r"));
@@ -120,29 +120,31 @@ public class MergeIT extends SimpleMacIT {
runMergeTest(c, tableName + tc++, ns("b", "m", "r"), ns("b", "m", "r"), ns("a", "b", "c", "l", "m", "n", "q", "r", "s"), ns("r", "s"), ns(null, "z"));
runMergeTest(c, tableName + tc++, ns("b", "m", "r"), ns("b", "m", "r"), ns("a", "b", "c", "l", "m", "n", "q", "r", "s"), ns("b", "c"), ns("l", "m"));
runMergeTest(c, tableName + tc++, ns("b", "m", "r"), ns("b", "m", "r"), ns("a", "b", "c", "l", "m", "n", "q", "r", "s"), ns("m", "n"), ns("q", "r"));
-
+
}
-
- private void runMergeTest(Connector c, String table, String[] splits, String[] expectedSplits, String[] inserts, String[] start, String[] end) throws Exception {
+
+ private void runMergeTest(Connector c, String table, String[] splits, String[] expectedSplits, String[] inserts, String[] start, String[] end)
+ throws Exception {
int count = 0;
-
+
for (String s : start) {
for (String e : end) {
runMergeTest(c, table + "_" + count++, splits, expectedSplits, inserts, s, e);
}
}
}
-
- private void runMergeTest(Connector conn, String table, String[] splits, String[] expectedSplits, String[] inserts, String start, String end) throws Exception {
+
+ private void runMergeTest(Connector conn, String table, String[] splits, String[] expectedSplits, String[] inserts, String start, String end)
+ throws Exception {
System.out.println("Running merge test " + table + " " + Arrays.asList(splits) + " " + start + " " + end);
-
+
conn.tableOperations().create(table, true, TimeType.LOGICAL);
TreeSet<Text> splitSet = new TreeSet<Text>();
for (String split : splits) {
splitSet.add(new Text(split));
}
conn.tableOperations().addSplits(table, splitSet);
-
+
BatchWriter bw = conn.createBatchWriter(table, null);
HashSet<String> expected = new HashSet<String>();
for (String row : inserts) {
@@ -151,13 +153,13 @@ public class MergeIT extends SimpleMacIT {
bw.addMutation(m);
expected.add(row);
}
-
+
bw.close();
-
+
conn.tableOperations().merge(table, start == null ? null : new Text(start), end == null ? null : new Text(end));
-
+
Scanner scanner = conn.createScanner(table, Authorizations.EMPTY);
-
+
HashSet<String> observed = new HashSet<String>();
for (Entry<Key,Value> entry : scanner) {
String row = entry.getKey().getRowData().toString();
@@ -165,21 +167,21 @@ public class MergeIT extends SimpleMacIT {
throw new Exception("Saw data twice " + table + " " + row);
}
}
-
+
if (!observed.equals(expected)) {
throw new Exception("data inconsistency " + table + " " + observed + " != " + expected);
}
-
+
HashSet<Text> currentSplits = new HashSet<Text>(conn.tableOperations().listSplits(table));
HashSet<Text> ess = new HashSet<Text>();
for (String es : expectedSplits) {
ess.add(new Text(es));
}
-
+
if (!currentSplits.equals(ess)) {
throw new Exception("split inconsistency " + table + " " + currentSplits + " != " + ess);
}
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/MetadataIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/MetadataIT.java b/test/src/test/java/org/apache/accumulo/test/functional/MetadataIT.java
index aa5f8b0..92e0d44 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/MetadataIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/MetadataIT.java
@@ -67,7 +67,7 @@ public class MetadataIT extends SimpleMacIT {
@Test(timeout = 2 * 60 * 1000)
public void batchScanTest() throws Exception {
Connector c = getConnector();
- String tableName = makeTableName();
+ String tableName = getTableNames(1)[0];
c.tableOperations().create(tableName);
// batch scan regular metadata table
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/NativeMapIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/NativeMapIT.java b/test/src/test/java/org/apache/accumulo/test/functional/NativeMapIT.java
index b0b6344..32be35d 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/NativeMapIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/NativeMapIT.java
@@ -20,11 +20,11 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
-public class NativeMapIT extends SimpleMacIT {
-
+public class NativeMapIT extends ConfigurableMacIT {
+
@Test(timeout = 15 * 1000)
public void test() throws Exception {
assertEquals(0, exec(NativeMapTest.class).waitFor());
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/PermissionsIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/PermissionsIT.java b/test/src/test/java/org/apache/accumulo/test/functional/PermissionsIT.java
index 7c565f2..b8e1a4f 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/PermissionsIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/PermissionsIT.java
@@ -51,12 +51,11 @@ import org.junit.Test;
public class PermissionsIT extends SimpleMacIT {
static AtomicInteger userId = new AtomicInteger(0);
-
+
static String makeUserName() {
return "user_" + userId.getAndIncrement();
}
-
-
+
@Test(timeout = 60 * 1000)
public void systemPermissionsTest() throws Exception {
String testUser = makeUserName();
@@ -65,16 +64,16 @@ public class PermissionsIT extends SimpleMacIT {
// verify that the test is being run by root
Connector c = getConnector();
verifyHasOnlyTheseSystemPermissions(c, c.whoami(), SystemPermission.values());
-
+
// create the test user
c.securityOperations().createLocalUser(testUser, testPasswd);
Connector test_user_conn = c.getInstance().getConnector(testUser, testPasswd);
verifyHasNoSystemPermissions(c, testUser, SystemPermission.values());
-
+
// test each permission
for (SystemPermission perm : SystemPermission.values()) {
log.debug("Verifying the " + perm + " permission");
-
+
// verify GRANT can't be granted
if (perm.equals(SystemPermission.GRANT)) {
try {
@@ -85,17 +84,18 @@ public class PermissionsIT extends SimpleMacIT {
}
throw new IllegalStateException("Should NOT be able to grant GRANT");
}
-
+
// test permission before and after granting it
- testMissingSystemPermission(c, test_user_conn, perm);
+ String tableNamePrefix = getTableNames(1)[0];
+ testMissingSystemPermission(tableNamePrefix, c, test_user_conn, perm);
c.securityOperations().grantSystemPermission(testUser, perm);
verifyHasOnlyTheseSystemPermissions(c, testUser, perm);
- testGrantedSystemPermission(c, test_user_conn, perm);
+ testGrantedSystemPermission(tableNamePrefix, c, test_user_conn, perm);
c.securityOperations().revokeSystemPermission(testUser, perm);
verifyHasNoSystemPermissions(c, testUser, perm);
}
}
-
+
static Map<String,String> map(Iterable<Entry<String,String>> i) {
Map<String,String> result = new HashMap<String,String>();
for (Entry<String,String> e : i) {
@@ -103,16 +103,16 @@ public class PermissionsIT extends SimpleMacIT {
}
return result;
}
-
- private static void testMissingSystemPermission(Connector root_conn, Connector test_user_conn, SystemPermission perm) throws AccumuloException,
- TableExistsException, AccumuloSecurityException, TableNotFoundException {
+
+ private static void testMissingSystemPermission(String tableNamePrefix, Connector root_conn, Connector test_user_conn, SystemPermission perm)
+ throws AccumuloException, TableExistsException, AccumuloSecurityException, TableNotFoundException {
String tableName, user, password = "password";
log.debug("Confirming that the lack of the " + perm + " permission properly restricts the user");
-
+
// test permission prior to granting it
switch (perm) {
case CREATE_TABLE:
- tableName = makeTableName() + "__CREATE_TABLE_WITHOUT_PERM_TEST__";
+ tableName = tableNamePrefix + "__CREATE_TABLE_WITHOUT_PERM_TEST__";
try {
test_user_conn.tableOperations().create(tableName);
throw new IllegalStateException("Should NOT be able to create a table");
@@ -122,7 +122,7 @@ public class PermissionsIT extends SimpleMacIT {
}
break;
case DROP_TABLE:
- tableName = makeTableName() + "__DROP_TABLE_WITHOUT_PERM_TEST__";
+ tableName = tableNamePrefix + "__DROP_TABLE_WITHOUT_PERM_TEST__";
root_conn.tableOperations().create(tableName);
try {
test_user_conn.tableOperations().delete(tableName);
@@ -133,7 +133,7 @@ public class PermissionsIT extends SimpleMacIT {
}
break;
case ALTER_TABLE:
- tableName = makeTableName() + "__ALTER_TABLE_WITHOUT_PERM_TEST__";
+ tableName = tableNamePrefix + "__ALTER_TABLE_WITHOUT_PERM_TEST__";
root_conn.tableOperations().create(tableName);
try {
test_user_conn.tableOperations().setProperty(tableName, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%");
@@ -203,29 +203,29 @@ public class PermissionsIT extends SimpleMacIT {
throw new IllegalArgumentException("Unrecognized System Permission: " + perm);
}
}
-
- private static void testGrantedSystemPermission(Connector root_conn, Connector test_user_conn, SystemPermission perm) throws AccumuloException,
- AccumuloSecurityException, TableNotFoundException, TableExistsException {
+
+ private static void testGrantedSystemPermission(String tableNamePrefix, Connector root_conn, Connector test_user_conn, SystemPermission perm)
+ throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException {
String tableName, user, password = "password";
log.debug("Confirming that the presence of the " + perm + " permission properly permits the user");
-
+
// test permission after granting it
switch (perm) {
case CREATE_TABLE:
- tableName = makeTableName() + "__CREATE_TABLE_WITH_PERM_TEST__";
+ tableName = tableNamePrefix + "__CREATE_TABLE_WITH_PERM_TEST__";
test_user_conn.tableOperations().create(tableName);
if (!root_conn.tableOperations().list().contains(tableName))
throw new IllegalStateException("Should be able to create a table");
break;
case DROP_TABLE:
- tableName = makeTableName() + "__DROP_TABLE_WITH_PERM_TEST__";
+ tableName = tableNamePrefix + "__DROP_TABLE_WITH_PERM_TEST__";
root_conn.tableOperations().create(tableName);
test_user_conn.tableOperations().delete(tableName);
if (root_conn.tableOperations().list().contains(tableName))
throw new IllegalStateException("Should be able to delete a table");
break;
case ALTER_TABLE:
- tableName = makeTableName() + "__ALTER_TABLE_WITH_PERM_TEST__";
+ tableName = tableNamePrefix + "__ALTER_TABLE_WITH_PERM_TEST__";
String table2 = tableName + "2";
root_conn.tableOperations().create(tableName);
test_user_conn.tableOperations().setProperty(tableName, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%");
@@ -267,7 +267,7 @@ public class PermissionsIT extends SimpleMacIT {
throw new IllegalArgumentException("Unrecognized System Permission: " + perm);
}
}
-
+
private static void verifyHasOnlyTheseSystemPermissions(Connector root_conn, String user, SystemPermission... perms) throws AccumuloException,
AccumuloSecurityException {
List<SystemPermission> permList = Arrays.asList(perms);
@@ -283,15 +283,14 @@ public class PermissionsIT extends SimpleMacIT {
}
}
}
-
+
private static void verifyHasNoSystemPermissions(Connector root_conn, String user, SystemPermission... perms) throws AccumuloException,
AccumuloSecurityException {
for (SystemPermission p : perms)
if (root_conn.securityOperations().hasSystemPermission(user, p))
throw new IllegalStateException(user + " SHOULD NOT have system permission " + p);
}
-
-
+
@Test(timeout = 30 * 1000)
public void tablePermissionTest() throws Exception {
// create the test user
@@ -301,29 +300,29 @@ public class PermissionsIT extends SimpleMacIT {
Connector c = getConnector();
c.securityOperations().createLocalUser(testUser, testPasswd);
Connector test_user_conn = c.getInstance().getConnector(testUser, testPasswd);
-
+
// check for read-only access to metadata table
verifyHasOnlyTheseTablePermissions(c, c.whoami(), MetadataTable.NAME, TablePermission.READ, TablePermission.ALTER_TABLE);
verifyHasOnlyTheseTablePermissions(c, testUser, MetadataTable.NAME, TablePermission.READ);
- String tableName = makeTableName() + "__TABLE_PERMISSION_TEST__";
-
+ String tableName = getTableNames(1)[0] + "__TABLE_PERMISSION_TEST__";
+
// test each permission
for (TablePermission perm : TablePermission.values()) {
log.debug("Verifying the " + perm + " permission");
-
+
// test permission before and after granting it
createTestTable(c, testUser, tableName);
testMissingTablePermission(c, test_user_conn, perm, tableName);
c.securityOperations().grantTablePermission(testUser, tableName, perm);
verifyHasOnlyTheseTablePermissions(c, testUser, tableName, perm);
testGrantedTablePermission(c, test_user_conn, perm, tableName);
-
+
createTestTable(c, testUser, tableName);
c.securityOperations().revokeTablePermission(testUser, tableName, perm);
verifyHasNoTablePermissions(c, testUser, tableName, perm);
}
}
-
+
private void createTestTable(Connector c, String testUser, String tableName) throws Exception, MutationsRejectedException {
if (!c.tableOperations().exists(tableName)) {
// create the test table
@@ -334,20 +333,20 @@ public class PermissionsIT extends SimpleMacIT {
m.put(new Text("cf"), new Text("cq"), new Value("val".getBytes()));
writer.addMutation(m);
writer.close();
-
+
// verify proper permissions for creator and test user
verifyHasOnlyTheseTablePermissions(c, c.whoami(), tableName, TablePermission.values());
verifyHasNoTablePermissions(c, testUser, tableName, TablePermission.values());
-
+
}
}
-
+
private static void testMissingTablePermission(Connector root_conn, Connector test_user_conn, TablePermission perm, String tableName) throws Exception {
Scanner scanner;
BatchWriter writer;
Mutation m;
log.debug("Confirming that the lack of the " + perm + " permission properly restricts the user");
-
+
// test permission prior to granting it
switch (perm) {
case READ:
@@ -418,14 +417,14 @@ public class PermissionsIT extends SimpleMacIT {
throw new IllegalArgumentException("Unrecognized table Permission: " + perm);
}
}
-
- private static void testGrantedTablePermission(Connector root_conn, Connector test_user_conn, TablePermission perm, String tableName) throws AccumuloException,
- TableExistsException, AccumuloSecurityException, TableNotFoundException, MutationsRejectedException {
+
+ private static void testGrantedTablePermission(Connector root_conn, Connector test_user_conn, TablePermission perm, String tableName)
+ throws AccumuloException, TableExistsException, AccumuloSecurityException, TableNotFoundException, MutationsRejectedException {
Scanner scanner;
BatchWriter writer;
Mutation m;
log.debug("Confirming that the presence of the " + perm + " permission properly permits the user");
-
+
// test permission after granting it
switch (perm) {
case READ:
@@ -458,7 +457,7 @@ public class PermissionsIT extends SimpleMacIT {
throw new IllegalArgumentException("Unrecognized table Permission: " + perm);
}
}
-
+
private static void verifyHasOnlyTheseTablePermissions(Connector root_conn, String user, String table, TablePermission... perms) throws AccumuloException,
AccumuloSecurityException {
List<TablePermission> permList = Arrays.asList(perms);
@@ -474,7 +473,7 @@ public class PermissionsIT extends SimpleMacIT {
}
}
}
-
+
private static void verifyHasNoTablePermissions(Connector root_conn, String user, String table, TablePermission... perms) throws AccumuloException,
AccumuloSecurityException {
for (TablePermission p : perms)
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/RenameIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/RenameIT.java b/test/src/test/java/org/apache/accumulo/test/functional/RenameIT.java
index ff8d894..78b0537 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/RenameIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/RenameIT.java
@@ -24,11 +24,12 @@ import org.apache.accumulo.test.VerifyIngest;
import org.junit.Test;
public class RenameIT extends SimpleMacIT {
-
+
@Test(timeout = 2 * 60 * 1000)
public void renameTest() throws Exception {
- String name1 = makeTableName();
- String name2 = makeTableName();
+ String[] tableNames = getTableNames(2);
+ String name1 = tableNames[0];
+ String name2 = tableNames[1];
BatchWriterOpts bwOpts = new BatchWriterOpts();
ScannerOpts scanOpts = new ScannerOpts();
TestIngest.Opts opts = new TestIngest.Opts();
@@ -46,5 +47,5 @@ public class RenameIT extends SimpleMacIT {
vopts.tableName = name1;
VerifyIngest.verifyIngest(c, vopts, scanOpts);
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/ScanIteratorIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/ScanIteratorIT.java b/test/src/test/java/org/apache/accumulo/test/functional/ScanIteratorIT.java
index aa014c7..3264bd1 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/ScanIteratorIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/ScanIteratorIT.java
@@ -37,36 +37,36 @@ import org.apache.hadoop.io.Text;
import org.junit.Test;
public class ScanIteratorIT extends SimpleMacIT {
-
+
@Test(timeout = 30 * 1000)
public void run() throws Exception {
- String tableName = makeTableName();
+ String tableName = getTableNames(1)[0];
Connector c = getConnector();
c.tableOperations().create(tableName);
-
+
BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
-
+
for (int i = 0; i < 1000; i++) {
Mutation m = new Mutation(new Text(String.format("%06d", i)));
m.put(new Text("cf1"), new Text("cq1"), new Value(("" + (1000 - i)).getBytes()));
m.put(new Text("cf1"), new Text("cq2"), new Value(("" + (i - 1000)).getBytes()));
-
+
bw.addMutation(m);
}
-
+
bw.close();
-
+
Scanner scanner = c.createScanner(tableName, new Authorizations());
-
+
setupIter(scanner);
verify(scanner, 1, 999);
-
+
BatchScanner bscanner = c.createBatchScanner(tableName, new Authorizations(), 3);
bscanner.setRanges(Collections.singleton(new Range((Key) null, null)));
-
+
setupIter(bscanner);
verify(bscanner, 1, 999);
-
+
ArrayList<Range> ranges = new ArrayList<Range>();
ranges.add(new Range(new Text(String.format("%06d", 1))));
ranges.add(new Range(new Text(String.format("%06d", 6)), new Text(String.format("%06d", 16))));
@@ -75,52 +75,52 @@ public class ScanIteratorIT extends SimpleMacIT {
ranges.add(new Range(new Text(String.format("%06d", 56)), new Text(String.format("%06d", 61))));
ranges.add(new Range(new Text(String.format("%06d", 501)), new Text(String.format("%06d", 504))));
ranges.add(new Range(new Text(String.format("%06d", 998)), new Text(String.format("%06d", 1000))));
-
+
HashSet<Integer> got = new HashSet<Integer>();
HashSet<Integer> expected = new HashSet<Integer>();
for (int i : new int[] {1, 7, 9, 11, 13, 15, 23, 57, 59, 61, 501, 503, 999}) {
expected.add(i);
}
-
+
bscanner.setRanges(ranges);
-
+
for (Entry<Key,Value> entry : bscanner) {
got.add(Integer.parseInt(entry.getKey().getRow().toString()));
}
-
+
System.out.println("got : " + got);
-
+
if (!got.equals(expected)) {
throw new Exception(got + " != " + expected);
}
-
+
bscanner.close();
-
+
}
-
+
private void verify(Iterable<Entry<Key,Value>> scanner, int start, int finish) throws Exception {
-
+
int expected = start;
for (Entry<Key,Value> entry : scanner) {
if (Integer.parseInt(entry.getKey().getRow().toString()) != expected) {
throw new Exception("Saw unexpexted " + entry.getKey().getRow() + " " + expected);
}
-
+
if (entry.getKey().getColumnQualifier().toString().equals("cq2")) {
expected += 2;
}
}
-
+
if (expected != finish + 2) {
throw new Exception("Ended at " + expected + " not " + (finish + 2));
}
}
-
+
private void setupIter(ScannerBase scanner) throws Exception {
IteratorSetting dropMod = new IteratorSetting(50, "dropMod", "org.apache.accumulo.test.functional.DropModIter");
dropMod.addOption("mod", "2");
dropMod.addOption("drop", "0");
scanner.addScanIterator(dropMod);
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/ScanRangeIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/ScanRangeIT.java b/test/src/test/java/org/apache/accumulo/test/functional/ScanRangeIT.java
index 8a42740..e034740 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/ScanRangeIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/ScanRangeIT.java
@@ -32,95 +32,96 @@ import org.apache.hadoop.io.Text;
import org.junit.Test;
public class ScanRangeIT extends SimpleMacIT {
-
+
private static final int TS_LIMIT = 1;
private static final int CQ_LIMIT = 5;
private static final int CF_LIMIT = 5;
private static final int ROW_LIMIT = 100;
-
+
@Test(timeout = 2 * 60 * 1000)
public void run() throws Exception {
Connector c = getConnector();
- String table1 = makeTableName();
+ String[] tableNames = getTableNames(2);
+ String table1 = tableNames[0];
c.tableOperations().create(table1);
- String table2 = makeTableName();
+ String table2 = tableNames[1];
c.tableOperations().create(table2);
TreeSet<Text> splitRows = new TreeSet<Text>();
int splits = 3;
for (int i = (ROW_LIMIT / splits); i < ROW_LIMIT; i += (ROW_LIMIT / splits))
splitRows.add(createRow(i));
c.tableOperations().addSplits(table2, splitRows);
-
+
insertData(c, table1);
scanTable(c, table1);
-
+
insertData(c, table2);
scanTable(c, table2);
}
-
+
private void scanTable(Connector c, String table) throws Exception {
scanRange(c, table, new IntKey(0, 0, 0, 0), new IntKey(1, 0, 0, 0));
-
+
scanRange(c, table, new IntKey(0, 0, 0, 0), new IntKey(ROW_LIMIT - 1, CF_LIMIT - 1, CQ_LIMIT - 1, 0));
-
+
scanRange(c, table, null, null);
-
+
for (int i = 0; i < ROW_LIMIT; i += (ROW_LIMIT / 3)) {
for (int j = 0; j < CF_LIMIT; j += (CF_LIMIT / 2)) {
for (int k = 1; k < CQ_LIMIT; k += (CQ_LIMIT / 2)) {
scanRange(c, table, null, new IntKey(i, j, k, 0));
scanRange(c, table, new IntKey(0, 0, 0, 0), new IntKey(i, j, k, 0));
-
+
scanRange(c, table, new IntKey(i, j, k, 0), new IntKey(ROW_LIMIT - 1, CF_LIMIT - 1, CQ_LIMIT - 1, 0));
-
+
scanRange(c, table, new IntKey(i, j, k, 0), null);
-
+
}
}
}
-
+
for (int i = 0; i < ROW_LIMIT; i++) {
scanRange(c, table, new IntKey(i, 0, 0, 0), new IntKey(i, CF_LIMIT - 1, CQ_LIMIT - 1, 0));
-
+
if (i > 0 && i < ROW_LIMIT - 1) {
scanRange(c, table, new IntKey(i - 1, 0, 0, 0), new IntKey(i + 1, CF_LIMIT - 1, CQ_LIMIT - 1, 0));
}
}
-
+
}
-
+
private static class IntKey {
private int row;
private int cf;
private int cq;
private long ts;
-
+
IntKey(IntKey ik) {
this.row = ik.row;
this.cf = ik.cf;
this.cq = ik.cq;
this.ts = ik.ts;
}
-
+
IntKey(int row, int cf, int cq, long ts) {
this.row = row;
this.cf = cf;
this.cq = cq;
this.ts = ts;
}
-
+
Key createKey() {
Text trow = createRow(row);
Text tcf = createCF(cf);
Text tcq = createCQ(cq);
-
+
return new Key(trow, tcf, tcq, ts);
}
-
+
IntKey increment() {
-
+
IntKey ik = new IntKey(this);
-
+
ik.ts++;
if (ik.ts >= TS_LIMIT) {
ik.ts = 0;
@@ -134,91 +135,91 @@ public class ScanRangeIT extends SimpleMacIT {
}
}
}
-
+
return ik;
}
-
+
}
-
+
private void scanRange(Connector c, String table, IntKey ik1, IntKey ik2) throws Exception {
scanRange(c, table, ik1, false, ik2, false);
scanRange(c, table, ik1, false, ik2, true);
scanRange(c, table, ik1, true, ik2, false);
scanRange(c, table, ik1, true, ik2, true);
}
-
+
private void scanRange(Connector c, String table, IntKey ik1, boolean inclusive1, IntKey ik2, boolean inclusive2) throws Exception {
Scanner scanner = c.createScanner(table, Authorizations.EMPTY);
-
+
Key key1 = null;
Key key2 = null;
-
+
IntKey expectedIntKey;
IntKey expectedEndIntKey;
-
+
if (ik1 != null) {
key1 = ik1.createKey();
expectedIntKey = ik1;
-
+
if (!inclusive1) {
expectedIntKey = expectedIntKey.increment();
}
} else {
expectedIntKey = new IntKey(0, 0, 0, 0);
}
-
+
if (ik2 != null) {
key2 = ik2.createKey();
expectedEndIntKey = ik2;
-
+
if (inclusive2) {
expectedEndIntKey = expectedEndIntKey.increment();
}
} else {
expectedEndIntKey = new IntKey(ROW_LIMIT, 0, 0, 0);
}
-
+
Range range = new Range(key1, inclusive1, key2, inclusive2);
-
+
scanner.setRange(range);
-
+
for (Entry<Key,Value> entry : scanner) {
-
+
Key expectedKey = expectedIntKey.createKey();
if (!expectedKey.equals(entry.getKey())) {
throw new Exception(" " + expectedKey + " != " + entry.getKey());
}
-
+
expectedIntKey = expectedIntKey.increment();
}
-
+
if (!expectedIntKey.createKey().equals(expectedEndIntKey.createKey())) {
throw new Exception(" " + expectedIntKey.createKey() + " != " + expectedEndIntKey.createKey());
}
}
-
+
private static Text createCF(int cf) {
Text tcf = new Text(String.format("cf_%03d", cf));
return tcf;
}
-
+
private static Text createCQ(int cf) {
Text tcf = new Text(String.format("cq_%03d", cf));
return tcf;
}
-
+
private static Text createRow(int row) {
Text trow = new Text(String.format("r_%06d", row));
return trow;
}
-
+
private void insertData(Connector c, String table) throws Exception {
-
+
BatchWriter bw = c.createBatchWriter(table, new BatchWriterConfig());
-
+
for (int i = 0; i < ROW_LIMIT; i++) {
Mutation m = new Mutation(createRow(i));
-
+
for (int j = 0; j < CF_LIMIT; j++) {
for (int k = 0; k < CQ_LIMIT; k++) {
for (int t = 0; t < TS_LIMIT; t++) {
@@ -226,10 +227,10 @@ public class ScanRangeIT extends SimpleMacIT {
}
}
}
-
+
bw.addMutation(m);
}
-
+
bw.close();
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/ServerSideErrorIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/ServerSideErrorIT.java b/test/src/test/java/org/apache/accumulo/test/functional/ServerSideErrorIT.java
index a9fa847..cf7726e 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/ServerSideErrorIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/ServerSideErrorIT.java
@@ -37,28 +37,28 @@ import org.apache.hadoop.io.Text;
import org.junit.Test;
public class ServerSideErrorIT extends SimpleMacIT {
-
+
@Test(timeout = 2 * 60 * 1000)
public void run() throws Exception {
Connector c = getConnector();
- String tableName = makeTableName();
+ String tableName = getTableNames(1)[0];
c.tableOperations().create(tableName);
IteratorSetting is = new IteratorSetting(5, "Bad Aggregator", BadCombiner.class);
Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("acf")));
c.tableOperations().attachIterator(tableName, is);
-
+
BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
-
+
Mutation m = new Mutation(new Text("r1"));
m.put(new Text("acf"), new Text("foo"), new Value("1".getBytes()));
-
+
bw.addMutation(m);
-
+
bw.close();
-
+
// try to scan table
Scanner scanner = c.createScanner(tableName, Authorizations.EMPTY);
-
+
boolean caught = false;
try {
for (Entry<Key,Value> entry : scanner) {
@@ -67,14 +67,14 @@ public class ServerSideErrorIT extends SimpleMacIT {
} catch (Exception e) {
caught = true;
}
-
+
if (!caught)
throw new Exception("Scan did not fail");
-
+
// try to batch scan the table
BatchScanner bs = c.createBatchScanner(tableName, Authorizations.EMPTY, 2);
bs.setRanges(Collections.singleton(new Range()));
-
+
caught = false;
try {
for (Entry<Key,Value> entry : bs) {
@@ -85,27 +85,27 @@ public class ServerSideErrorIT extends SimpleMacIT {
} finally {
bs.close();
}
-
+
if (!caught)
throw new Exception("batch scan did not fail");
-
+
// remove the bad agg so accumulo can shutdown
TableOperations to = c.tableOperations();
for (Entry<String,String> e : to.getProperties(tableName)) {
to.removeProperty(tableName, e.getKey());
}
-
+
UtilWaitThread.sleep(500);
-
+
// should be able to scan now
scanner = c.createScanner(tableName, Authorizations.EMPTY);
for (Entry<Key,Value> entry : scanner) {
entry.getKey();
}
-
+
// set a non existant iterator, should cause scan to fail on server side
scanner.addScanIterator(new IteratorSetting(100, "bogus", "com.bogus.iterator"));
-
+
caught = false;
try {
for (Entry<Key,Value> entry : scanner) {
@@ -115,7 +115,7 @@ public class ServerSideErrorIT extends SimpleMacIT {
} catch (Exception e) {
caught = true;
}
-
+
if (!caught)
throw new Exception("Scan did not fail");
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/SimpleMacIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/SimpleMacIT.java b/test/src/test/java/org/apache/accumulo/test/functional/SimpleMacIT.java
index 4a37d82..9086f13 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/SimpleMacIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/SimpleMacIT.java
@@ -16,44 +16,61 @@
*/
package org.apache.accumulo.test.functional;
+import java.io.File;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
import org.apache.accumulo.minicluster.MiniAccumuloCluster;
import org.apache.accumulo.minicluster.MiniAccumuloConfig;
+import org.apache.accumulo.minicluster.MiniAccumuloInstance;
import org.apache.log4j.Logger;
-import org.junit.After;
-import org.junit.AfterClass;
import org.junit.BeforeClass;
-import org.junit.rules.TemporaryFolder;
public class SimpleMacIT extends AbstractMacIT {
public static final Logger log = Logger.getLogger(SimpleMacIT.class);
-
- static private TemporaryFolder folder = new TemporaryFolder();
- static private MiniAccumuloCluster cluster;
-
+
+ private static File folder;
+ private static MiniAccumuloCluster cluster = null;
+
@BeforeClass
- synchronized public static void setUp() throws Exception {
- if (cluster == null) {
- folder.create();
- MiniAccumuloConfig cfg = new MiniAccumuloConfig(folder.newFolder("mac"), ROOT_PASSWORD);
+ public static synchronized void setUp() throws Exception {
+ if (getInstanceOneConnector() == null && cluster == null) {
+ folder = createSharedTestDir(SimpleMacIT.class.getName());
+ MiniAccumuloConfig cfg = new MiniAccumuloConfig(folder, ROOT_PASSWORD);
cluster = new MiniAccumuloCluster(cfg);
cluster.start();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
- cleanUp(cluster, folder);
+ cleanUp(cluster);
}
});
}
}
-
+
+ @Override
+ public Connector getConnector() throws AccumuloException, AccumuloSecurityException {
+ Connector conn = getInstanceOneConnector();
+ return conn == null ? cluster.getConnector("root", ROOT_PASSWORD) : conn;
+ }
+
@Override
- public MiniAccumuloCluster getCluster() {
- return cluster;
+ public String rootPath() {
+ return (getInstanceOneConnector() == null ? cluster.getConfig().getDir() : getInstanceOnePath()).getAbsolutePath();
}
-
- @After
- public void cleanUp() throws Exception {}
-
- @AfterClass
- public static void tearDown() throws Exception {}
+
+ private static Connector getInstanceOneConnector() {
+ try {
+ return new MiniAccumuloInstance("instance1", getInstanceOnePath()).getConnector("root", new PasswordToken(ROOT_PASSWORD));
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ private static File getInstanceOnePath() {
+ return new File(System.getProperty("user.dir") + "/accumulo-maven-plugin/instance1");
+ }
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/SparseColumnFamilyIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/SparseColumnFamilyIT.java b/test/src/test/java/org/apache/accumulo/test/functional/SparseColumnFamilyIT.java
index c45a6a3..47db29a 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/SparseColumnFamilyIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/SparseColumnFamilyIT.java
@@ -35,45 +35,45 @@ import org.junit.Test;
* This test recreates issue ACCUMULO-516. Until that issue is fixed this test should time out.
*/
public class SparseColumnFamilyIT extends SimpleMacIT {
-
+
@Test(timeout = 60 * 1000)
public void sparceColumnFamily() throws Exception {
- String scftt = makeTableName();
+ String scftt = getTableNames(1)[0];
Connector c = getConnector();
c.tableOperations().create(scftt);
-
+
BatchWriter bw = c.createBatchWriter(scftt, new BatchWriterConfig());
-
+
// create file in the tablet that has mostly column family 0, with a few entries for column family 1
-
+
bw.addMutation(nm(0, 1, 0));
for (int i = 1; i < 99999; i++) {
bw.addMutation(nm(i * 2, 0, i));
}
bw.addMutation(nm(99999 * 2, 1, 99999));
bw.flush();
-
+
c.tableOperations().flush(scftt, null, null, true);
-
+
// create a file that has column family 1 and 0 interleaved
for (int i = 0; i < 100000; i++) {
bw.addMutation(nm(i * 2 + 1, i % 2 == 0 ? 0 : 1, i));
}
bw.close();
-
+
c.tableOperations().flush(scftt, null, null, true);
-
+
Scanner scanner = c.createScanner(scftt, Authorizations.EMPTY);
-
+
for (int i = 0; i < 200; i++) {
-
+
// every time we search for column family 1, it will scan the entire file
// that has mostly column family 0 until the bug is fixed
scanner.setRange(new Range(String.format("%06d", i), null));
scanner.clearColumns();
scanner.setBatchSize(3);
scanner.fetchColumnFamily(new Text(String.format("%03d", 1)));
-
+
Iterator<Entry<Key,Value>> iter = scanner.iterator();
if (iter.hasNext()) {
Entry<Key,Value> entry = iter.next();
@@ -83,7 +83,7 @@ public class SparseColumnFamilyIT extends SimpleMacIT {
}
}
}
-
+
/**
* @param i
* @param j
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/SplitRecoveryIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/SplitRecoveryIT.java b/test/src/test/java/org/apache/accumulo/test/functional/SplitRecoveryIT.java
index 69f2808..4d97886 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/SplitRecoveryIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/SplitRecoveryIT.java
@@ -20,11 +20,11 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
-public class SplitRecoveryIT extends SimpleMacIT {
-
+public class SplitRecoveryIT extends ConfigurableMacIT {
+
@Test(timeout = 10 * 1000)
public void test() throws Exception {
assertEquals(0, exec(SplitRecoveryTest.class).waitFor());
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/StartIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/StartIT.java b/test/src/test/java/org/apache/accumulo/test/functional/StartIT.java
index eeec941..8162f71 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/StartIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/StartIT.java
@@ -16,18 +16,19 @@
*/
package org.apache.accumulo.test.functional;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import org.apache.accumulo.start.TestMain;
import org.junit.Test;
-public class StartIT extends SimpleMacIT {
-
+public class StartIT extends ConfigurableMacIT {
+
@Test(timeout = 10 * 1000)
public void test() throws Exception {
assertTrue(exec(TestMain.class, "exception").waitFor() != 0);
assertEquals(0, exec(TestMain.class, "success").waitFor());
assertTrue(exec(TestMain.class).waitFor() != 0);
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/TableIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/TableIT.java b/test/src/test/java/org/apache/accumulo/test/functional/TableIT.java
index c3f8073..a9e78f8 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/TableIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/TableIT.java
@@ -43,12 +43,12 @@ import org.apache.hadoop.io.Text;
import org.junit.Test;
public class TableIT extends SimpleMacIT {
-
+
@Test(timeout = 2 * 60 * 1000)
public void test() throws Exception {
Connector c = getConnector();
TableOperations to = c.tableOperations();
- String tableName = makeTableName();
+ String tableName = getTableNames(1)[0];
to.create(tableName);
TestIngest.Opts opts = new TestIngest.Opts();
opts.tableName = tableName;
@@ -87,5 +87,5 @@ public class TableIT extends SimpleMacIT {
VerifyIngest.verifyIngest(c, vopts, new ScannerOpts());
to.delete(tableName);
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/TimeoutIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/TimeoutIT.java b/test/src/test/java/org/apache/accumulo/test/functional/TimeoutIT.java
index 4bae35c..505d69b 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/TimeoutIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/TimeoutIT.java
@@ -41,27 +41,27 @@ import org.junit.Test;
*
*/
public class TimeoutIT extends SimpleMacIT {
-
+
@Test(timeout = 60 * 1000)
public void run() throws Exception {
Connector conn = getConnector();
- testBatchWriterTimeout(conn);
- testBatchScannerTimeout(conn);
+ String[] tableNames = getTableNames(2);
+ testBatchWriterTimeout(conn, tableNames[0]);
+ testBatchScannerTimeout(conn, tableNames[1]);
}
-
- public void testBatchWriterTimeout(Connector conn) throws Exception {
- String tableName = makeTableName();
+
+ public void testBatchWriterTimeout(Connector conn, String tableName) throws Exception {
conn.tableOperations().create(tableName);
conn.tableOperations().addConstraint(tableName, SlowConstraint.class.getName());
-
+
// give constraint time to propagate through zookeeper
UtilWaitThread.sleep(1000);
-
+
BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig().setTimeout(3, TimeUnit.SECONDS));
-
+
Mutation mut = new Mutation("r1");
mut.put("cf1", "cq1", "v1");
-
+
bw.addMutation(mut);
try {
bw.close();
@@ -72,35 +72,34 @@ public class TimeoutIT extends SimpleMacIT {
throw mre;
}
}
-
- public void testBatchScannerTimeout(Connector conn) throws Exception {
- String tableName = makeTableName();
+
+ public void testBatchScannerTimeout(Connector conn, String tableName) throws Exception {
getConnector().tableOperations().create(tableName);
-
+
BatchWriter bw = getConnector().createBatchWriter(tableName, new BatchWriterConfig());
-
+
Mutation m = new Mutation("r1");
m.put("cf1", "cq1", "v1");
m.put("cf1", "cq2", "v2");
m.put("cf1", "cq3", "v3");
m.put("cf1", "cq4", "v4");
-
+
bw.addMutation(m);
bw.close();
-
+
BatchScanner bs = getConnector().createBatchScanner(tableName, Authorizations.EMPTY, 2);
bs.setRanges(Collections.singletonList(new Range()));
-
+
// should not timeout
for (Entry<Key,Value> entry : bs) {
entry.getKey();
}
-
+
bs.setTimeout(5, TimeUnit.SECONDS);
IteratorSetting iterSetting = new IteratorSetting(100, SlowIterator.class);
iterSetting.addOption("sleepTime", 2000 + "");
bs.addScanIterator(iterSetting);
-
+
try {
for (Entry<Key,Value> entry : bs) {
entry.getKey();
@@ -111,5 +110,5 @@ public class TimeoutIT extends SimpleMacIT {
}
bs.close();
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/VisibilityIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/VisibilityIT.java b/test/src/test/java/org/apache/accumulo/test/functional/VisibilityIT.java
index bde7883..3252dec 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/VisibilityIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/VisibilityIT.java
@@ -45,50 +45,51 @@ import org.apache.hadoop.io.Text;
import org.junit.Test;
public class VisibilityIT extends SimpleMacIT {
-
+
@Test(timeout = 2 * 60 * 1000)
public void run() throws Exception {
Connector c = getConnector();
- String table = makeTableName();
+ String[] tableNames = getTableNames(2);
+ String table = tableNames[0];
c.tableOperations().create(table);
- String table2 = makeTableName();
+ String table2 = tableNames[1];
c.tableOperations().create(table2);
c.tableOperations().setProperty(table2, Property.TABLE_DEFAULT_SCANTIME_VISIBILITY.getKey(), "DEFLABEL");
-
+
insertData(c, table);
queryData(c, table);
deleteData(c, table);
-
+
insertDefaultData(c, table2);
queryDefaultData(c, table2);
-
+
}
-
+
private static SortedSet<String> nss(String... labels) {
TreeSet<String> ts = new TreeSet<String>();
-
+
for (String s : labels) {
ts.add(s);
}
-
+
return ts;
}
-
+
private void mput(Mutation m, String cf, String cq, String cv, String val) {
ColumnVisibility le = new ColumnVisibility(cv.getBytes());
m.put(new Text(cf), new Text(cq), le, new Value(val.getBytes()));
}
-
+
private void mputDelete(Mutation m, String cf, String cq, String cv) {
ColumnVisibility le = new ColumnVisibility(cv.getBytes());
m.putDelete(new Text(cf), new Text(cq), le);
}
-
+
private void insertData(Connector c, String tableName) throws Exception {
-
+
BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
Mutation m1 = new Mutation(new Text("row1"));
-
+
mput(m1, "cf1", "cq1", "", "v1");
mput(m1, "cf1", "cq1", "A", "v2");
mput(m1, "cf1", "cq1", "B", "v3");
@@ -102,16 +103,16 @@ public class VisibilityIT extends SimpleMacIT {
mput(m1, "cf1", "cq1", "FOO", "v11");
mput(m1, "cf1", "cq1", "(A|B)&FOO&(L|M)", "v12");
mput(m1, "cf1", "cq1", "A&B&(L|M|FOO)", "v13");
-
+
bw.addMutation(m1);
bw.close();
}
-
+
private void deleteData(Connector c, String tableName) throws Exception {
-
+
BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
Mutation m1 = new Mutation(new Text("row1"));
-
+
mputDelete(m1, "cf1", "cq1", "");
mputDelete(m1, "cf1", "cq1", "A");
mputDelete(m1, "cf1", "cq1", "A&B");
@@ -120,12 +121,12 @@ public class VisibilityIT extends SimpleMacIT {
mputDelete(m1, "cf1", "cq1", "A&FOO&(L|M)");
mputDelete(m1, "cf1", "cq1", "(A|B)&FOO&(L|M)");
mputDelete(m1, "cf1", "cq1", "FOO&A"); // should not delete anything
-
+
bw.addMutation(m1);
bw.close();
-
+
Map<Set<String>,Set<String>> expected = new HashMap<Set<String>,Set<String>>();
-
+
expected.put(nss("A", "L"), nss("v5"));
expected.put(nss("A", "M"), nss("v5"));
expected.put(nss("B"), nss("v3"));
@@ -135,37 +136,37 @@ public class VisibilityIT extends SimpleMacIT {
expected.put(nss("A", "B", "FOO"), nss("v13"));
expected.put(nss("FOO"), nss("v11"));
expected.put(nss("A", "FOO"), nss("v9"));
-
+
queryData(c, tableName, nss("A", "B", "FOO", "L", "M", "Z"), nss("A", "B", "FOO", "L", "M", "Z"), expected);
}
-
+
private void insertDefaultData(Connector c, String tableName) throws Exception {
BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
Mutation m1 = new Mutation(new Text("row1"));
-
+
mput(m1, "cf1", "cq1", "BASE", "v1");
mput(m1, "cf1", "cq2", "DEFLABEL", "v2");
mput(m1, "cf1", "cq3", "", "v3");
-
+
bw.addMutation(m1);
bw.close();
}
-
+
private static void uniqueCombos(List<Set<String>> all, Set<String> prefix, Set<String> suffix) {
-
+
all.add(prefix);
-
+
TreeSet<String> ss = new TreeSet<String>(suffix);
-
+
for (String s : suffix) {
TreeSet<String> ps = new TreeSet<String>(prefix);
ps.add(s);
ss.remove(s);
-
+
uniqueCombos(all, ps, ss);
}
}
-
+
private void queryData(Connector c, String tableName) throws Exception {
Map<Set<String>,Set<String>> expected = new HashMap<Set<String>,Set<String>>();
expected.put(nss(), nss("v1"));
@@ -186,56 +187,56 @@ public class VisibilityIT extends SimpleMacIT {
expected.put(nss("A", "FOO", "M"), nss("v10", "v12"));
expected.put(nss("B", "FOO", "L"), nss("v12"));
expected.put(nss("B", "FOO", "M"), nss("v12"));
-
+
queryData(c, tableName, nss("A", "B", "FOO", "L", "M", "Z"), nss("A", "B", "FOO", "L", "M", "Z"), expected);
queryData(c, tableName, nss("A", "B", "FOO", "L", "M", "Z"), nss("A", "B", "L", "M", "Z"), expected);
queryData(c, tableName, nss("A", "B", "FOO", "L", "M", "Z"), nss("A", "Z"), expected);
queryData(c, tableName, nss("A", "B", "FOO", "L", "M", "Z"), nss("Z"), expected);
queryData(c, tableName, nss("A", "B", "FOO", "L", "M", "Z"), nss(), expected);
}
-
+
private void queryData(Connector c, String tableName, Set<String> allAuths, Set<String> userAuths, Map<Set<String>,Set<String>> expected) throws Exception {
-
+
c.securityOperations().changeUserAuthorizations("root", new Authorizations(nbas(userAuths)));
-
+
ArrayList<Set<String>> combos = new ArrayList<Set<String>>();
uniqueCombos(combos, nss(), allAuths);
-
+
for (Set<String> set1 : combos) {
Set<String> e = new TreeSet<String>();
for (Set<String> set2 : combos) {
-
+
set2 = new HashSet<String>(set2);
set2.retainAll(userAuths);
-
+
if (set1.containsAll(set2) && expected.containsKey(set2)) {
e.addAll(expected.get(set2));
}
}
-
+
set1.retainAll(userAuths);
verify(c, tableName, set1, e);
}
-
+
}
-
+
private void queryDefaultData(Connector c, String tableName) throws Exception {
Scanner scanner;
-
+
// should return no records
c.securityOperations().changeUserAuthorizations("root", new Authorizations("BASE", "DEFLABEL"));
scanner = getConnector().createScanner(tableName, new Authorizations());
verifyDefault(scanner, 0);
-
+
// should return one record
scanner = getConnector().createScanner(tableName, new Authorizations("BASE"));
verifyDefault(scanner, 1);
-
+
// should return all three records
scanner = getConnector().createScanner(tableName, new Authorizations("BASE", "DEFLABEL"));
verifyDefault(scanner, 3);
}
-
+
private void verifyDefault(Scanner scanner, int expectedCount) throws Exception {
for (@SuppressWarnings("unused")
Entry<Key,Value> entry : scanner)
@@ -243,17 +244,17 @@ public class VisibilityIT extends SimpleMacIT {
if (expectedCount != 0)
throw new Exception(" expected count !=0 " + expectedCount);
}
-
+
private void verify(Connector c, String tableName, Set<String> auths, Set<String> expectedValues) throws Exception {
ByteArraySet bas = nbas(auths);
-
+
try {
verify(c, tableName, bas, expectedValues.toArray(new String[0]));
} catch (Exception e) {
throw new Exception("Verification failed auths=" + auths + " exp=" + expectedValues, e);
}
}
-
+
private ByteArraySet nbas(Set<String> auths) {
ByteArraySet bas = new ByteArraySet();
for (String auth : auths) {
@@ -261,20 +262,20 @@ public class VisibilityIT extends SimpleMacIT {
}
return bas;
}
-
+
private void verify(Connector c, String tableName, ByteArraySet nss, String... expected) throws Exception {
Scanner scanner = c.createScanner(tableName, new Authorizations(nss));
verify(scanner.iterator(), expected);
-
+
BatchScanner bs = getConnector().createBatchScanner(tableName, new Authorizations(nss), 3);
bs.setRanges(Collections.singleton(new Range()));
verify(bs.iterator(), expected);
bs.close();
}
-
+
private void verify(Iterator<Entry<Key,Value>> iter, String... expected) throws Exception {
HashSet<String> valuesSeen = new HashSet<String>();
-
+
while (iter.hasNext()) {
Entry<Key,Value> entry = iter.next();
if (valuesSeen.contains(entry.getValue().toString())) {
@@ -282,13 +283,13 @@ public class VisibilityIT extends SimpleMacIT {
}
valuesSeen.add(entry.getValue().toString());
}
-
+
for (String ev : expected) {
if (!valuesSeen.remove(ev)) {
throw new Exception("Did not see expected value " + ev);
}
}
-
+
if (valuesSeen.size() != 0) {
throw new Exception("Saw more values than expected " + valuesSeen);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/WriteLotsIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/WriteLotsIT.java b/test/src/test/java/org/apache/accumulo/test/functional/WriteLotsIT.java
index f713474..7021395 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/WriteLotsIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/WriteLotsIT.java
@@ -28,17 +28,18 @@ import org.apache.accumulo.test.VerifyIngest;
import org.junit.Test;
public class WriteLotsIT extends SimpleMacIT {
-
+
@Test(timeout = 60 * 1000)
public void writeLots() throws Exception {
final Connector c = getConnector();
- final String tableName = makeTableName();
+ final String tableName = getTableNames(1)[0];
c.tableOperations().create(tableName);
final AtomicReference<Exception> ref = new AtomicReference<Exception>();
List<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < 10; i++) {
final int index = i;
Thread t = new Thread() {
+ @Override
public void run() {
try {
TestIngest.Opts opts = new TestIngest.Opts();
@@ -65,5 +66,5 @@ public class WriteLotsIT extends SimpleMacIT {
vopts.tableName = tableName;
VerifyIngest.verifyIngest(c, vopts, new ScannerOpts());
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/ZooCacheIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/ZooCacheIT.java b/test/src/test/java/org/apache/accumulo/test/functional/ZooCacheIT.java
index f4f4964..ba5f44b 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/ZooCacheIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/ZooCacheIT.java
@@ -16,7 +16,7 @@
*/
package org.apache.accumulo.test.functional;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.List;
@@ -24,19 +24,20 @@ import java.util.concurrent.atomic.AtomicReference;
import org.junit.Test;
-public class ZooCacheIT extends SimpleMacIT {
-
- @Test(timeout = 2 * 60 *1000)
+public class ZooCacheIT extends ConfigurableMacIT {
+
+ @Test(timeout = 2 * 60 * 1000)
public void test() throws Exception {
assertEquals(0, exec(CacheTestClean.class, "/zcTest-42", "/tmp/zcTest-42").waitFor());
final AtomicReference<Exception> ref = new AtomicReference<Exception>();
List<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < 3; i++) {
Thread reader = new Thread() {
+ @Override
public void run() {
try {
- CacheTestReader.main(new String[]{"/zcTest-42", "/tmp/zcTest-42", getConnector().getInstance().getZooKeepers()});
- } catch(Exception ex) {
+ CacheTestReader.main(new String[] {"/zcTest-42", "/tmp/zcTest-42", getConnector().getInstance().getZooKeepers()});
+ } catch (Exception ex) {
ref.set(ex);
}
}
@@ -44,12 +45,12 @@ public class ZooCacheIT extends SimpleMacIT {
reader.start();
threads.add(reader);
}
- assertEquals(0, exec(CacheTestWriter.class, "/zcTest-42", "/tmp/zcTest-42", "3","50").waitFor());
- for (Thread t: threads) {
+ assertEquals(0, exec(CacheTestWriter.class, "/zcTest-42", "/tmp/zcTest-42", "3", "50").waitFor());
+ for (Thread t : threads) {
t.join();
if (ref.get() != null)
throw ref.get();
}
}
-
+
}
[4/4] git commit: ACCUMULO-1599 Move MiniAccumuloCluster output to
target directory
Posted by ct...@apache.org.
ACCUMULO-1599 Move MiniAccumuloCluster output to target directory
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/aa711023
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/aa711023
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/aa711023
Branch: refs/heads/master
Commit: aa7110234e15a017bb1dbc99b4351f0bf06cc73b
Parents: 741daec
Author: Christopher Tubbs <ct...@apache.org>
Authored: Fri Oct 11 02:21:11 2013 -0400
Committer: Christopher Tubbs <ct...@apache.org>
Committed: Fri Oct 11 02:22:29 2013 -0400
----------------------------------------------------------------------
.../mapred/AccumuloFileOutputFormatTest.java | 83 ++-
.../core/client/mapred/TokenFileTest.java | 53 +-
.../mapreduce/AccumuloFileOutputFormatTest.java | 79 ++-
.../core/client/mapreduce/TokenFileTest.java | 51 +-
.../minicluster/MiniAccumuloCluster.java | 6 +-
.../minicluster/MiniAccumuloClusterGCTest.java | 17 +-
.../minicluster/MiniAccumuloClusterTest.java | 31 +-
.../minicluster/MiniAccumuloConfigTest.java | 7 +-
.../org/apache/accumulo/proxy/SimpleTest.java | 294 +++++----
.../tabletserver/log/MultiReaderTest.java | 29 +-
.../tabletserver/log/SortedLogRecoveryTest.java | 109 ++--
.../AccumuloReloadingVFSClassLoaderTest.java | 54 +-
.../vfs/AccumuloVFSClassLoaderTest.java | 15 +-
.../classloader/vfs/ContextManagerTest.java | 32 +-
test/pom.xml | 3 +-
.../accumulo/fate/zookeeper/ZooLockTest.java | 223 +++----
.../apache/accumulo/test/AuditMessageTest.java | 132 ++---
.../org/apache/accumulo/test/BatchWriterIT.java | 12 +-
.../accumulo/test/ConditionalWriterTest.java | 593 ++++++++++---------
.../org/apache/accumulo/test/DumpConfigIT.java | 28 +-
.../org/apache/accumulo/test/MetaSplitTest.java | 19 +-
.../org/apache/accumulo/test/ShellServerIT.java | 20 +-
.../apache/accumulo/test/TableOperationsIT.java | 51 +-
.../test/TestAccumuloSplitRecovery.java | 47 +-
.../org/apache/accumulo/test/VolumeTest.java | 17 +-
.../accumulo/test/functional/AbstractMacIT.java | 81 +--
.../accumulo/test/functional/AddSplitIT.java | 62 +-
.../test/functional/BadIteratorMincIT.java | 41 +-
.../test/functional/BatchScanSplitIT.java | 48 +-
.../test/functional/BatchWriterFlushIT.java | 82 +--
.../accumulo/test/functional/BinaryIT.java | 9 +-
.../accumulo/test/functional/BulkFileIT.java | 46 +-
.../apache/accumulo/test/functional/BulkIT.java | 10 +-
.../functional/BulkSplitOptimizationIT.java | 26 +-
.../accumulo/test/functional/ClassLoaderIT.java | 6 +-
.../accumulo/test/functional/CleanTmpIT.java | 2 +-
.../accumulo/test/functional/CloneTestIT.java | 92 +--
.../accumulo/test/functional/CombinerIT.java | 8 +-
.../accumulo/test/functional/CompactionIT.java | 22 +-
.../test/functional/ConfigurableMacIT.java | 53 +-
.../accumulo/test/functional/ConstraintIT.java | 136 ++---
.../test/functional/CreateAndUseIT.java | 51 +-
.../test/functional/CreateManyScannersIT.java | 6 +-
.../accumulo/test/functional/DeleteRowsIT.java | 12 +-
.../test/functional/DeleteRowsSplitIT.java | 32 +-
.../test/functional/FateStarvationIT.java | 20 +-
.../test/functional/GarbageCollectorIT.java | 21 +-
.../accumulo/test/functional/MapReduceIT.java | 24 +-
.../accumulo/test/functional/MergeIT.java | 56 +-
.../accumulo/test/functional/MetadataIT.java | 2 +-
.../accumulo/test/functional/NativeMapIT.java | 6 +-
.../accumulo/test/functional/PermissionsIT.java | 87 ++-
.../accumulo/test/functional/RenameIT.java | 9 +-
.../test/functional/ScanIteratorIT.java | 48 +-
.../accumulo/test/functional/ScanRangeIT.java | 99 ++--
.../test/functional/ServerSideErrorIT.java | 36 +-
.../accumulo/test/functional/SimpleMacIT.java | 59 +-
.../test/functional/SparseColumnFamilyIT.java | 26 +-
.../test/functional/SplitRecoveryIT.java | 6 +-
.../accumulo/test/functional/StartIT.java | 9 +-
.../accumulo/test/functional/TableIT.java | 6 +-
.../accumulo/test/functional/TimeoutIT.java | 41 +-
.../accumulo/test/functional/VisibilityIT.java | 109 ++--
.../accumulo/test/functional/WriteLotsIT.java | 7 +-
.../accumulo/test/functional/ZooCacheIT.java | 19 +-
65 files changed, 1809 insertions(+), 1711 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/core/src/test/java/org/apache/accumulo/core/client/mapred/AccumuloFileOutputFormatTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/mapred/AccumuloFileOutputFormatTest.java b/core/src/test/java/org/apache/accumulo/core/client/mapred/AccumuloFileOutputFormatTest.java
index b71ad07..565b618 100644
--- a/core/src/test/java/org/apache/accumulo/core/client/mapred/AccumuloFileOutputFormatTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/client/mapred/AccumuloFileOutputFormatTest.java
@@ -46,8 +46,8 @@ import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapred.lib.IdentityMapper;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
-import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -57,15 +57,15 @@ public class AccumuloFileOutputFormatTest {
private static final String BAD_TABLE = PREFIX + "_mapred_bad_table";
private static final String TEST_TABLE = PREFIX + "_mapred_test_table";
private static final String EMPTY_TABLE = PREFIX + "_mapred_empty_table";
-
- public static TemporaryFolder folder = new TemporaryFolder();
+
private static AssertionError e1 = null;
private static AssertionError e2 = null;
-
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+
@BeforeClass
public static void setup() throws Exception {
- folder.create();
-
MockInstance mockInstance = new MockInstance(INSTANCE_NAME);
Connector c = mockInstance.getConnector("root", new PasswordToken(""));
c.tableOperations().create(EMPTY_TABLE);
@@ -84,27 +84,22 @@ public class AccumuloFileOutputFormatTest {
bw.addMutation(m);
bw.close();
}
-
- @AfterClass
- public static void teardown() throws IOException {
- folder.delete();
- }
-
+
@Test
public void testEmptyWrite() throws Exception {
handleWriteTests(false);
}
-
+
@Test
public void testRealWrite() throws Exception {
handleWriteTests(true);
}
-
+
private static class MRTester extends Configured implements Tool {
private static class BadKeyMapper implements Mapper<Key,Value,Key,Value> {
-
+
int index = 0;
-
+
@Override
public void map(Key key, Value value, OutputCollector<Key,Value> output, Reporter reporter) throws IOException {
try {
@@ -120,10 +115,10 @@ public class AccumuloFileOutputFormatTest {
}
index++;
}
-
+
@Override
public void configure(JobConf job) {}
-
+
@Override
public void close() throws IOException {
try {
@@ -132,50 +127,50 @@ public class AccumuloFileOutputFormatTest {
e2 = e;
}
}
-
+
}
-
+
@Override
public int run(String[] args) throws Exception {
-
+
if (args.length != 4) {
throw new IllegalArgumentException("Usage : " + MRTester.class.getName() + " <user> <pass> <table> <outputfile>");
}
-
+
String user = args[0];
String pass = args[1];
String table = args[2];
-
+
JobConf job = new JobConf(getConf());
job.setJarByClass(this.getClass());
-
+
job.setInputFormat(AccumuloInputFormat.class);
-
+
AccumuloInputFormat.setConnectorInfo(job, user, new PasswordToken(pass));
AccumuloInputFormat.setInputTableName(job, table);
AccumuloInputFormat.setMockInstance(job, INSTANCE_NAME);
AccumuloFileOutputFormat.setOutputPath(job, new Path(args[3]));
-
+
job.setMapperClass(BAD_TABLE.equals(table) ? BadKeyMapper.class : IdentityMapper.class);
job.setMapOutputKeyClass(Key.class);
job.setMapOutputValueClass(Value.class);
job.setOutputFormat(AccumuloFileOutputFormat.class);
-
+
job.setNumReduceTasks(0);
-
+
return JobClient.runJob(job).isSuccessful() ? 0 : 1;
}
-
+
public static void main(String[] args) throws Exception {
assertEquals(0, ToolRunner.run(CachedConfiguration.getInstance(), new MRTester(), args));
}
}
-
+
public void handleWriteTests(boolean content) throws Exception {
- File f = folder.newFile();
+ File f = folder.newFile("handleWriteTests");
f.delete();
MRTester.main(new String[] {"root", "", content ? TEST_TABLE : EMPTY_TABLE, f.getAbsolutePath()});
-
+
assertTrue(f.exists());
File[] files = f.listFiles(new FileFilter() {
@Override
@@ -190,60 +185,60 @@ public class AccumuloFileOutputFormatTest {
assertEquals(0, files.length);
}
}
-
+
@Test
public void writeBadVisibility() throws Exception {
- File f = folder.newFile();
+ File f = folder.newFile("writeBadVisibility");
f.delete();
MRTester.main(new String[] {"root", "", BAD_TABLE, f.getAbsolutePath()});
assertNull(e1);
assertNull(e2);
}
-
+
@Test
public void validateConfiguration() throws IOException, InterruptedException {
-
+
int a = 7;
long b = 300l;
long c = 50l;
long d = 10l;
String e = "snappy";
-
+
JobConf job = new JobConf();
AccumuloFileOutputFormat.setReplication(job, a);
AccumuloFileOutputFormat.setFileBlockSize(job, b);
AccumuloFileOutputFormat.setDataBlockSize(job, c);
AccumuloFileOutputFormat.setIndexBlockSize(job, d);
AccumuloFileOutputFormat.setCompressionType(job, e);
-
+
AccumuloConfiguration acuconf = AccumuloFileOutputFormat.getAccumuloConfiguration(job);
-
+
assertEquals(7, acuconf.getCount(Property.TABLE_FILE_REPLICATION));
assertEquals(300l, acuconf.getMemoryInBytes(Property.TABLE_FILE_BLOCK_SIZE));
assertEquals(50l, acuconf.getMemoryInBytes(Property.TABLE_FILE_COMPRESSED_BLOCK_SIZE));
assertEquals(10l, acuconf.getMemoryInBytes(Property.TABLE_FILE_COMPRESSED_BLOCK_SIZE_INDEX));
assertEquals("snappy", acuconf.get(Property.TABLE_FILE_COMPRESSION_TYPE));
-
+
a = 17;
b = 1300l;
c = 150l;
d = 110l;
e = "lzo";
-
+
job = new JobConf();
AccumuloFileOutputFormat.setReplication(job, a);
AccumuloFileOutputFormat.setFileBlockSize(job, b);
AccumuloFileOutputFormat.setDataBlockSize(job, c);
AccumuloFileOutputFormat.setIndexBlockSize(job, d);
AccumuloFileOutputFormat.setCompressionType(job, e);
-
+
acuconf = AccumuloFileOutputFormat.getAccumuloConfiguration(job);
-
+
assertEquals(17, acuconf.getCount(Property.TABLE_FILE_REPLICATION));
assertEquals(1300l, acuconf.getMemoryInBytes(Property.TABLE_FILE_BLOCK_SIZE));
assertEquals(150l, acuconf.getMemoryInBytes(Property.TABLE_FILE_COMPRESSED_BLOCK_SIZE));
assertEquals(110l, acuconf.getMemoryInBytes(Property.TABLE_FILE_COMPRESSED_BLOCK_SIZE_INDEX));
assertEquals("lzo", acuconf.get(Property.TABLE_FILE_COMPRESSION_TYPE));
-
+
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/core/src/test/java/org/apache/accumulo/core/client/mapred/TokenFileTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/mapred/TokenFileTest.java b/core/src/test/java/org/apache/accumulo/core/client/mapred/TokenFileTest.java
index f1a95a1..0e1fe39 100644
--- a/core/src/test/java/org/apache/accumulo/core/client/mapred/TokenFileTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/client/mapred/TokenFileTest.java
@@ -39,6 +39,7 @@ import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.security.Authorizations;
import org.apache.accumulo.core.security.Credentials;
import org.apache.accumulo.core.util.CachedConfiguration;
+import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobClient;
@@ -48,7 +49,9 @@ import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
/**
*
@@ -59,13 +62,13 @@ public class TokenFileTest {
private static final String INSTANCE_NAME = PREFIX + "_mapred_instance";
private static final String TEST_TABLE_1 = PREFIX + "_mapred_table_1";
private static final String TEST_TABLE_2 = PREFIX + "_mapred_table_2";
-
+
private static class MRTokenFileTester extends Configured implements Tool {
private static class TestMapper implements Mapper<Key,Value,Text,Mutation> {
Key key = null;
int count = 0;
OutputCollector<Text,Mutation> finalOutput;
-
+
@Override
public void map(Key k, Value v, OutputCollector<Text,Mutation> output, Reporter reporter) throws IOException {
finalOutput = output;
@@ -80,62 +83,67 @@ public class TokenFileTest {
key = new Key(k);
count++;
}
-
+
@Override
public void configure(JobConf job) {}
-
+
@Override
public void close() throws IOException {
Mutation m = new Mutation("total");
m.put("", "", Integer.toString(count));
finalOutput.collect(new Text(), m);
}
-
+
}
-
+
@Override
public int run(String[] args) throws Exception {
-
+
if (args.length != 4) {
throw new IllegalArgumentException("Usage : " + MRTokenFileTester.class.getName() + " <user> <token file> <inputtable> <outputtable>");
}
-
+
String user = args[0];
String tokenFile = args[1];
String table1 = args[2];
String table2 = args[3];
-
+
JobConf job = new JobConf(getConf());
job.setJarByClass(this.getClass());
-
+
job.setInputFormat(AccumuloInputFormat.class);
-
+
AccumuloInputFormat.setConnectorInfo(job, user, tokenFile);
AccumuloInputFormat.setInputTableName(job, table1);
AccumuloInputFormat.setMockInstance(job, INSTANCE_NAME);
-
+
job.setMapperClass(TestMapper.class);
job.setMapOutputKeyClass(Key.class);
job.setMapOutputValueClass(Value.class);
job.setOutputFormat(AccumuloOutputFormat.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Mutation.class);
-
+
AccumuloOutputFormat.setConnectorInfo(job, user, tokenFile);
AccumuloOutputFormat.setCreateTables(job, false);
AccumuloOutputFormat.setDefaultTableName(job, table2);
AccumuloOutputFormat.setMockInstance(job, INSTANCE_NAME);
-
+
job.setNumReduceTasks(0);
-
+
return JobClient.runJob(job).isSuccessful() ? 0 : 1;
}
-
+
public static void main(String[] args) throws Exception {
- assertEquals(0, ToolRunner.run(CachedConfiguration.getInstance(), new MRTokenFileTester(), args));
+ Configuration conf = CachedConfiguration.getInstance();
+ conf.set("hadoop.tmp.dir", new File(args[1]).getParent());
+ assertEquals(0, ToolRunner.run(conf, new MRTokenFileTester(), args));
}
}
-
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+
@Test
public void testMR() throws Exception {
MockInstance mockInstance = new MockInstance(INSTANCE_NAME);
@@ -149,17 +157,16 @@ public class TokenFileTest {
bw.addMutation(m);
}
bw.close();
-
- String tokenFile = "root_test.pw";
- File tf = File.createTempFile(tokenFile, "");
+
+ File tf = folder.newFile("root_test.pw");
PrintStream out = new PrintStream(tf);
String outString = new Credentials("root", new PasswordToken("")).serialize();
out.println(outString);
out.close();
-
+
MRTokenFileTester.main(new String[] {"root", tf.getAbsolutePath(), TEST_TABLE_1, TEST_TABLE_2});
assertNull(e1);
-
+
Scanner scanner = c.createScanner(TEST_TABLE_2, new Authorizations());
Iterator<Entry<Key,Value>> iter = scanner.iterator();
assertTrue(iter.hasNext());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloFileOutputFormatTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloFileOutputFormatTest.java b/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloFileOutputFormatTest.java
index ae756a5..3746e5b 100644
--- a/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloFileOutputFormatTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloFileOutputFormatTest.java
@@ -41,8 +41,8 @@ import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
-import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -52,15 +52,15 @@ public class AccumuloFileOutputFormatTest {
private static final String BAD_TABLE = PREFIX + "_mapreduce_bad_table";
private static final String TEST_TABLE = PREFIX + "_mapreduce_test_table";
private static final String EMPTY_TABLE = PREFIX + "_mapreduce_empty_table";
-
- public static TemporaryFolder folder = new TemporaryFolder();
+
private static AssertionError e1 = null;
private static AssertionError e2 = null;
-
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+
@BeforeClass
public static void setup() throws Exception {
- folder.create();
-
MockInstance mockInstance = new MockInstance(INSTANCE_NAME);
Connector c = mockInstance.getConnector("root", new PasswordToken(""));
c.tableOperations().create(EMPTY_TABLE);
@@ -79,26 +79,21 @@ public class AccumuloFileOutputFormatTest {
bw.addMutation(m);
bw.close();
}
-
- @AfterClass
- public static void teardown() throws IOException {
- folder.delete();
- }
-
+
@Test
public void testEmptyWrite() throws Exception {
handleWriteTests(false);
}
-
+
@Test
public void testRealWrite() throws Exception {
handleWriteTests(true);
}
-
+
private static class MRTester extends Configured implements Tool {
private static class BadKeyMapper extends Mapper<Key,Value,Key,Value> {
int index = 0;
-
+
@Override
protected void map(Key key, Value value, Context context) throws IOException, InterruptedException {
try {
@@ -114,7 +109,7 @@ public class AccumuloFileOutputFormatTest {
}
index++;
}
-
+
@Override
protected void cleanup(Context context) throws IOException, InterruptedException {
try {
@@ -124,50 +119,50 @@ public class AccumuloFileOutputFormatTest {
}
}
}
-
+
@Override
public int run(String[] args) throws Exception {
-
+
if (args.length != 4) {
throw new IllegalArgumentException("Usage : " + MRTester.class.getName() + " <user> <pass> <table> <outputfile>");
}
-
+
String user = args[0];
String pass = args[1];
String table = args[2];
-
+
Job job = new Job(getConf(), this.getClass().getSimpleName() + "_" + System.currentTimeMillis());
job.setJarByClass(this.getClass());
-
+
job.setInputFormatClass(AccumuloInputFormat.class);
-
+
AccumuloInputFormat.setConnectorInfo(job, user, new PasswordToken(pass));
AccumuloInputFormat.setInputTableName(job, table);
AccumuloInputFormat.setMockInstance(job, INSTANCE_NAME);
AccumuloFileOutputFormat.setOutputPath(job, new Path(args[3]));
-
+
job.setMapperClass(BAD_TABLE.equals(table) ? BadKeyMapper.class : Mapper.class);
job.setMapOutputKeyClass(Key.class);
job.setMapOutputValueClass(Value.class);
job.setOutputFormatClass(AccumuloFileOutputFormat.class);
-
+
job.setNumReduceTasks(0);
-
+
job.waitForCompletion(true);
-
+
return job.isSuccessful() ? 0 : 1;
}
-
+
public static void main(String[] args) throws Exception {
assertEquals(0, ToolRunner.run(CachedConfiguration.getInstance(), new MRTester(), args));
}
}
-
+
public void handleWriteTests(boolean content) throws Exception {
- File f = folder.newFile();
+ File f = folder.newFile("handleWriteTests");
f.delete();
MRTester.main(new String[] {"root", "", content ? TEST_TABLE : EMPTY_TABLE, f.getAbsolutePath()});
-
+
assertTrue(f.exists());
File[] files = f.listFiles(new FileFilter() {
@Override
@@ -182,60 +177,60 @@ public class AccumuloFileOutputFormatTest {
assertEquals(0, files.length);
}
}
-
+
@Test
public void writeBadVisibility() throws Exception {
- File f = folder.newFile();
+ File f = folder.newFile("writeBadVisibility");
f.delete();
MRTester.main(new String[] {"root", "", BAD_TABLE, f.getAbsolutePath()});
assertNull(e1);
assertNull(e2);
}
-
+
@Test
public void validateConfiguration() throws IOException, InterruptedException {
-
+
int a = 7;
long b = 300l;
long c = 50l;
long d = 10l;
String e = "snappy";
-
+
Job job = new Job();
AccumuloFileOutputFormat.setReplication(job, a);
AccumuloFileOutputFormat.setFileBlockSize(job, b);
AccumuloFileOutputFormat.setDataBlockSize(job, c);
AccumuloFileOutputFormat.setIndexBlockSize(job, d);
AccumuloFileOutputFormat.setCompressionType(job, e);
-
+
AccumuloConfiguration acuconf = AccumuloFileOutputFormat.getAccumuloConfiguration(job);
-
+
assertEquals(7, acuconf.getCount(Property.TABLE_FILE_REPLICATION));
assertEquals(300l, acuconf.getMemoryInBytes(Property.TABLE_FILE_BLOCK_SIZE));
assertEquals(50l, acuconf.getMemoryInBytes(Property.TABLE_FILE_COMPRESSED_BLOCK_SIZE));
assertEquals(10l, acuconf.getMemoryInBytes(Property.TABLE_FILE_COMPRESSED_BLOCK_SIZE_INDEX));
assertEquals("snappy", acuconf.get(Property.TABLE_FILE_COMPRESSION_TYPE));
-
+
a = 17;
b = 1300l;
c = 150l;
d = 110l;
e = "lzo";
-
+
job = new Job();
AccumuloFileOutputFormat.setReplication(job, a);
AccumuloFileOutputFormat.setFileBlockSize(job, b);
AccumuloFileOutputFormat.setDataBlockSize(job, c);
AccumuloFileOutputFormat.setIndexBlockSize(job, d);
AccumuloFileOutputFormat.setCompressionType(job, e);
-
+
acuconf = AccumuloFileOutputFormat.getAccumuloConfiguration(job);
-
+
assertEquals(17, acuconf.getCount(Property.TABLE_FILE_REPLICATION));
assertEquals(1300l, acuconf.getMemoryInBytes(Property.TABLE_FILE_BLOCK_SIZE));
assertEquals(150l, acuconf.getMemoryInBytes(Property.TABLE_FILE_COMPRESSED_BLOCK_SIZE));
assertEquals(110l, acuconf.getMemoryInBytes(Property.TABLE_FILE_COMPRESSED_BLOCK_SIZE_INDEX));
assertEquals("lzo", acuconf.get(Property.TABLE_FILE_COMPRESSION_TYPE));
-
+
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/core/src/test/java/org/apache/accumulo/core/client/mapreduce/TokenFileTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/mapreduce/TokenFileTest.java b/core/src/test/java/org/apache/accumulo/core/client/mapreduce/TokenFileTest.java
index f0277fc..02c0604 100644
--- a/core/src/test/java/org/apache/accumulo/core/client/mapreduce/TokenFileTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/client/mapreduce/TokenFileTest.java
@@ -39,13 +39,16 @@ import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.security.Authorizations;
import org.apache.accumulo.core.security.Credentials;
import org.apache.accumulo.core.util.CachedConfiguration;
+import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
/**
*
@@ -56,12 +59,12 @@ public class TokenFileTest {
private static final String INSTANCE_NAME = PREFIX + "_mapreduce_instance";
private static final String TEST_TABLE_1 = PREFIX + "_mapreduce_table_1";
private static final String TEST_TABLE_2 = PREFIX + "_mapreduce_table_2";
-
+
private static class MRTokenFileTester extends Configured implements Tool {
private static class TestMapper extends Mapper<Key,Value,Text,Mutation> {
Key key = null;
int count = 0;
-
+
@Override
protected void map(Key k, Value v, Context context) throws IOException, InterruptedException {
try {
@@ -75,7 +78,7 @@ public class TokenFileTest {
key = new Key(k);
count++;
}
-
+
@Override
protected void cleanup(Context context) throws IOException, InterruptedException {
Mutation m = new Mutation("total");
@@ -83,52 +86,57 @@ public class TokenFileTest {
context.write(new Text(), m);
}
}
-
+
@Override
public int run(String[] args) throws Exception {
-
+
if (args.length != 4) {
throw new IllegalArgumentException("Usage : " + MRTokenFileTester.class.getName() + " <user> <token file> <inputtable> <outputtable>");
}
-
+
String user = args[0];
String tokenFile = args[1];
String table1 = args[2];
String table2 = args[3];
-
+
Job job = new Job(getConf(), this.getClass().getSimpleName() + "_" + System.currentTimeMillis());
job.setJarByClass(this.getClass());
-
+
job.setInputFormatClass(AccumuloInputFormat.class);
-
+
AccumuloInputFormat.setConnectorInfo(job, user, tokenFile);
AccumuloInputFormat.setInputTableName(job, table1);
AccumuloInputFormat.setMockInstance(job, INSTANCE_NAME);
-
+
job.setMapperClass(TestMapper.class);
job.setMapOutputKeyClass(Key.class);
job.setMapOutputValueClass(Value.class);
job.setOutputFormatClass(AccumuloOutputFormat.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Mutation.class);
-
+
AccumuloOutputFormat.setConnectorInfo(job, user, tokenFile);
AccumuloOutputFormat.setCreateTables(job, false);
AccumuloOutputFormat.setDefaultTableName(job, table2);
AccumuloOutputFormat.setMockInstance(job, INSTANCE_NAME);
-
+
job.setNumReduceTasks(0);
-
+
job.waitForCompletion(true);
-
+
return job.isSuccessful() ? 0 : 1;
}
-
+
public static void main(String[] args) throws Exception {
- assertEquals(0, ToolRunner.run(CachedConfiguration.getInstance(), new MRTokenFileTester(), args));
+ Configuration conf = CachedConfiguration.getInstance();
+ conf.set("hadoop.tmp.dir", new File(args[1]).getParent());
+ assertEquals(0, ToolRunner.run(conf, new MRTokenFileTester(), args));
}
}
-
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+
@Test
public void testMR() throws Exception {
MockInstance mockInstance = new MockInstance(INSTANCE_NAME);
@@ -142,17 +150,16 @@ public class TokenFileTest {
bw.addMutation(m);
}
bw.close();
-
- String tokenFile = "root_test.pw";
- File tf = File.createTempFile(tokenFile, "");
+
+ File tf = folder.newFile("root_test.pw");
PrintStream out = new PrintStream(tf);
String outString = new Credentials("root", new PasswordToken("")).serialize();
out.println(outString);
out.close();
-
+
MRTokenFileTester.main(new String[] {"root", tf.getAbsolutePath(), TEST_TABLE_1, TEST_TABLE_2});
assertNull(e1);
-
+
Scanner scanner = c.createScanner(TEST_TABLE_2, new Authorizations());
Iterator<Entry<Key,Value>> iter = scanner.iterator();
assertTrue(iter.hasNext());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
index d1ada62..165acad 100644
--- a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
+++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
@@ -330,7 +330,7 @@ public class MiniAccumuloCluster {
File siteFile = new File(config.getConfDir(), "accumulo-site.xml");
writeConfig(siteFile, config.getSiteConfig().entrySet());
-
+
FileWriter fileWriter = new FileWriter(siteFile);
fileWriter.append("<configuration>\n");
@@ -513,7 +513,7 @@ public class MiniAccumuloCluster {
if (proc.equals(gcProcess)) {
gcProcess.destroy();
gcProcess = null;
- found= true;
+ found = true;
}
break;
}
@@ -586,7 +586,7 @@ public class MiniAccumuloCluster {
Instance instance = new ZooKeeperInstance(this.getInstanceName(), this.getZooKeepers());
return instance.getConnector(user, new PasswordToken(passwd));
}
-
+
public FileSystem getFileSystem() {
try {
return FileSystem.get(new URI(dfsUri), new Configuration());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterGCTest.java
----------------------------------------------------------------------
diff --git a/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterGCTest.java b/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterGCTest.java
index f4a8ca9..1b2481b 100644
--- a/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterGCTest.java
+++ b/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterGCTest.java
@@ -38,7 +38,6 @@ import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
import com.google.common.collect.ImmutableMap;
@@ -47,17 +46,18 @@ import com.google.common.collect.ImmutableMap;
*/
public class MiniAccumuloClusterGCTest {
- private static TemporaryFolder tmpDir = new TemporaryFolder();
+ private static File testDir = new File(System.getProperty("user.dir") + "/target/" + MiniAccumuloClusterGCTest.class.getName());
private static MiniAccumuloConfig macConfig;
private static MiniAccumuloCluster accumulo;
private static final String passwd = "password";
@BeforeClass
public static void setupMiniCluster() throws Exception {
- tmpDir.create();
+ FileUtils.deleteQuietly(testDir);
+ testDir.mkdir();
Logger.getLogger("org.apache.zookeeper").setLevel(Level.ERROR);
- macConfig = new MiniAccumuloConfig(tmpDir.getRoot(), passwd);
+ macConfig = new MiniAccumuloConfig(testDir, passwd);
macConfig.setNumTservers(1);
// Turn on the garbage collector
@@ -74,14 +74,13 @@ public class MiniAccumuloClusterGCTest {
@AfterClass
public static void tearDownMiniCluster() throws Exception {
accumulo.stop();
- tmpDir.delete();
}
@Test(timeout = 20000)
public void testFilesAreGarbageCollected() throws Exception {
ZooKeeperInstance inst = new ZooKeeperInstance(accumulo.getInstanceName(), accumulo.getZooKeepers());
Connector c = inst.getConnector("root", new PasswordToken(passwd));
-
+
final String table = "foobar";
c.tableOperations().create(table);
@@ -108,7 +107,7 @@ public class MiniAccumuloClusterGCTest {
c.tableOperations().compact(table, null, null, flush, wait);
c.tableOperations().compact(MetadataTable.NAME, null, null, flush, wait);
- File accumuloDir = new File(tmpDir.getRoot().getAbsolutePath(), "accumulo");
+ File accumuloDir = new File(testDir, "accumulo");
File tables = new File(accumuloDir.getAbsolutePath(), "tables");
int fileCountAfterCompaction = FileUtils.listFiles(tables, new SuffixFileFilter(".rf"), TrueFileFilter.TRUE).size();
@@ -129,12 +128,12 @@ public class MiniAccumuloClusterGCTest {
@Test(timeout = 10000)
public void testAccurateProcessListReturned() throws Exception {
Map<ServerType,Collection<ProcessReference>> procs = accumulo.getProcesses();
-
+
for (ServerType t : new ServerType[] {ServerType.MASTER, ServerType.TABLET_SERVER, ServerType.ZOOKEEPER, ServerType.GARBAGE_COLLECTOR}) {
Assert.assertTrue(procs.containsKey(t));
Collection<ProcessReference> procRefs = procs.get(t);
Assert.assertTrue(1 <= procRefs.size());
-
+
for (ProcessReference procRef : procRefs) {
Assert.assertNotNull(procRef);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterTest.java
----------------------------------------------------------------------
diff --git a/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterTest.java b/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterTest.java
index 3e749ab..26a1546 100644
--- a/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterTest.java
+++ b/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloClusterTest.java
@@ -19,10 +19,10 @@ package org.apache.accumulo.minicluster;
import static org.junit.Assert.assertEquals;
import java.io.File;
-import java.util.Collections;
-import java.util.Map.Entry;
import java.util.Collection;
+import java.util.Collections;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
@@ -50,12 +50,13 @@ import org.apache.log4j.Logger;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
public class MiniAccumuloClusterTest {
- public static TemporaryFolder folder = new TemporaryFolder();
+ public static File testDir;
private static MiniAccumuloCluster accumulo;
@@ -63,8 +64,13 @@ public class MiniAccumuloClusterTest {
public static void setupMiniCluster() throws Exception {
Logger.getLogger("org.apache.zookeeper").setLevel(Level.ERROR);
- folder.create();
- MiniAccumuloConfig config = new MiniAccumuloConfig(folder.getRoot(), "superSecret").setJDWPEnabled(true);
+ File baseDir = new File(System.getProperty("user.dir") + "/target/mini-tests");
+ baseDir.mkdirs();
+ testDir = new File(baseDir, MiniAccumuloClusterTest.class.getName());
+ FileUtils.deleteQuietly(testDir);
+ testDir.mkdir();
+
+ MiniAccumuloConfig config = new MiniAccumuloConfig(testDir, "superSecret").setJDWPEnabled(true);
accumulo = new MiniAccumuloCluster(config);
accumulo.start();
}
@@ -150,6 +156,9 @@ public class MiniAccumuloClusterTest {
conn.tableOperations().delete("table1");
}
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+
@Test(timeout = 60000)
public void testPerTableClasspath() throws Exception {
@@ -158,9 +167,8 @@ public class MiniAccumuloClusterTest {
conn.tableOperations().create("table2");
- File jarFile = File.createTempFile("iterator", ".jar");
+ File jarFile = folder.newFile("iterator.jar");
FileUtils.copyURLToFile(this.getClass().getResource("/FooFilter.jar"), jarFile);
- jarFile.deleteOnExit();
conn.instanceOperations().setProperty(Property.VFS_CONTEXT_CLASSPATH_PROPERTY.getKey() + "cx1", jarFile.toURI().toString());
conn.tableOperations().setProperty("table2", Property.TABLE_CLASSPATH.getKey(), "cx1");
@@ -205,18 +213,18 @@ public class MiniAccumuloClusterTest {
Assert.assertTrue(debugPort.getSecond() > 0);
}
}
-
+
@Test(timeout = 10000)
public void testAccurateProcessListReturned() throws Exception {
Map<ServerType,Collection<ProcessReference>> procs = accumulo.getProcesses();
-
+
Assert.assertFalse(procs.containsKey(ServerType.GARBAGE_COLLECTOR));
-
+
for (ServerType t : new ServerType[] {ServerType.MASTER, ServerType.TABLET_SERVER, ServerType.ZOOKEEPER}) {
Assert.assertTrue(procs.containsKey(t));
Collection<ProcessReference> procRefs = procs.get(t);
Assert.assertTrue(1 <= procRefs.size());
-
+
for (ProcessReference procRef : procRefs) {
Assert.assertNotNull(procRef);
}
@@ -226,7 +234,6 @@ public class MiniAccumuloClusterTest {
@AfterClass
public static void tearDownMiniCluster() throws Exception {
accumulo.stop();
- folder.delete();
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloConfigTest.java
----------------------------------------------------------------------
diff --git a/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloConfigTest.java b/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloConfigTest.java
index 7094e21..8a764d2 100644
--- a/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloConfigTest.java
+++ b/minicluster/src/test/java/org/apache/accumulo/minicluster/MiniAccumuloConfigTest.java
@@ -19,6 +19,7 @@ package org.apache.accumulo.minicluster;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -31,7 +32,7 @@ import org.junit.rules.TemporaryFolder;
public class MiniAccumuloConfigTest {
- static TemporaryFolder tempFolder = new TemporaryFolder();
+ static TemporaryFolder tempFolder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
@BeforeClass
public static void setUp() throws IOException {
@@ -39,7 +40,7 @@ public class MiniAccumuloConfigTest {
}
@Test
- public void testZookeeperPort(){
+ public void testZookeeperPort() {
// set specific zookeeper port
MiniAccumuloConfig config = new MiniAccumuloConfig(tempFolder.getRoot(), "password").setZooKeeperPort(5000).initialize();
@@ -54,7 +55,7 @@ public class MiniAccumuloConfigTest {
public void testSiteConfig() {
// constructor site config overrides default props
- Map<String,String> siteConfig = new HashMap<String, String>();
+ Map<String,String> siteConfig = new HashMap<String,String>();
siteConfig.put(Property.INSTANCE_DFS_URI.getKey(), "hdfs://");
MiniAccumuloConfig config = new MiniAccumuloConfig(tempFolder.getRoot(), "password").setSiteConfig(siteConfig).initialize();
assertEquals("hdfs://", config.getSiteConfig().get(Property.INSTANCE_DFS_URI.getKey()));
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java
----------------------------------------------------------------------
diff --git a/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java b/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java
index c625ae3..242ef08 100644
--- a/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java
+++ b/proxy/src/test/java/org/apache/accumulo/proxy/SimpleTest.java
@@ -111,9 +111,9 @@ import org.junit.rules.TemporaryFolder;
* Call every method on the proxy and try to verify that it works.
*/
public class SimpleTest {
-
- public static TemporaryFolder folder = new TemporaryFolder();
-
+
+ public static TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+
private static MiniAccumuloCluster accumulo;
private static String secret = "superSecret";
private static Random random = new Random();
@@ -129,20 +129,21 @@ public class SimpleTest {
}
};
private static ByteBuffer creds = null;
-
+
private static Class<? extends TProtocolFactory> protocolClass;
-
+
static Class<? extends TProtocolFactory> getRandomProtocol() {
List<Class<? extends TProtocolFactory>> protocolFactories = new ArrayList<Class<? extends TProtocolFactory>>();
protocolFactories.add(org.apache.thrift.protocol.TJSONProtocol.Factory.class);
protocolFactories.add(org.apache.thrift.protocol.TBinaryProtocol.Factory.class);
protocolFactories.add(org.apache.thrift.protocol.TTupleProtocol.Factory.class);
protocolFactories.add(org.apache.thrift.protocol.TCompactProtocol.Factory.class);
-
+
return protocolFactories.get(random.nextInt(protocolFactories.size()));
}
-
+
private static final AtomicInteger tableCounter = new AtomicInteger(0);
+
private static String makeTableName() {
return "test" + tableCounter.getAndIncrement();
}
@@ -150,18 +151,17 @@ public class SimpleTest {
@BeforeClass
public static void setupMiniCluster() throws Exception {
folder.create();
- MiniAccumuloConfig config = new MiniAccumuloConfig (folder.getRoot(), secret)
- .setNumTservers (1);
+ MiniAccumuloConfig config = new MiniAccumuloConfig(folder.getRoot(), secret).setNumTservers(1);
accumulo = new MiniAccumuloCluster(config);
accumulo.start();
-
+
Properties props = new Properties();
props.put("instance", accumulo.getConfig().getInstanceName());
props.put("zookeepers", accumulo.getConfig().getZooKeepers());
props.put("tokenClass", PasswordToken.class.getName());
-
+
protocolClass = getRandomProtocol();
-
+
proxyPort = PortUtils.getRandomFreePort();
proxyServer = Proxy.createProxyServer(org.apache.accumulo.proxy.thrift.AccumuloProxy.class, org.apache.accumulo.proxy.ProxyServer.class, proxyPort,
protocolClass, props);
@@ -177,7 +177,7 @@ public class SimpleTest {
client = new TestProxyClient("localhost", proxyPort, protocolClass.newInstance()).proxy();
creds = client.login(principal, properties);
}
-
+
@Test(timeout = 10000)
public void security() throws Exception {
client.createLocalUser(creds, "user", s2bb(secret));
@@ -185,9 +185,9 @@ public class SimpleTest {
client.dropLocalUser(creds, "user");
final String table = makeTableName();
client.createTable(creds, table, false, TimeType.MILLIS);
-
+
final IteratorSetting setting = new IteratorSetting(100, "slow", SlowIterator.class.getName(), Collections.singletonMap("sleepTime", "200"));
-
+
try {
client.addConstraint(badLogin, table, NumericValueConstraint.class.getName());
fail("exception not thrown");
@@ -451,7 +451,7 @@ public class SimpleTest {
fail("exception not thrown");
} catch (AccumuloSecurityException ex) {}
}
-
+
@Test(timeout = 10000)
public void tableNotFound() throws Exception {
final String doesNotExist = "doesNotExists";
@@ -610,7 +610,7 @@ public class SimpleTest {
client.createConditionalWriter(creds, doesNotExist, new ConditionalWriterOptions());
} catch (TableNotFoundException ex) {}
}
-
+
@Test(timeout = 10000)
public void testExists() throws Exception {
client.createTable(creds, "ett1", false, TimeType.MILLIS);
@@ -628,27 +628,27 @@ public class SimpleTest {
fail("exception not thrown");
} catch (TableExistsException tee) {}
}
-
+
@Test(timeout = 10000)
public void testUnknownScanner() throws Exception {
final String TABLE_TEST = makeTableName();
-
+
client.createTable(creds, TABLE_TEST, true, TimeType.MILLIS);
-
+
String scanner = client.createScanner(creds, TABLE_TEST, null);
assertFalse(client.hasNext(scanner));
client.closeScanner(scanner);
-
+
try {
client.hasNext(scanner);
fail("exception not thrown");
} catch (UnknownScanner us) {}
-
+
try {
client.closeScanner(scanner);
fail("exception not thrown");
} catch (UnknownScanner us) {}
-
+
try {
client.nextEntry("99999999");
fail("exception not thrown");
@@ -666,22 +666,22 @@ public class SimpleTest {
fail("exception not thrown");
} catch (UnknownScanner us) {}
}
-
+
@Test(timeout = 10000)
public void testUnknownWriter() throws Exception {
final String TABLE_TEST = makeTableName();
-
+
client.createTable(creds, TABLE_TEST, true, TimeType.MILLIS);
-
+
String writer = client.createWriter(creds, TABLE_TEST, null);
client.update(writer, mutation("row0", "cf", "cq", "value"));
client.flush(writer);
client.update(writer, mutation("row2", "cf", "cq", "value2"));
client.closeWriter(writer);
-
+
// this is a oneway call, so it does not throw exceptions
client.update(writer, mutation("row2", "cf", "cq", "value2"));
-
+
try {
client.flush(writer);
fail("exception not thrown");
@@ -699,7 +699,7 @@ public class SimpleTest {
fail("exception not thrown");
} catch (UnknownWriter uw) {}
}
-
+
@Test(timeout = 10000)
public void testInstanceOperations() throws Exception {
int tservers = 0;
@@ -708,14 +708,14 @@ public class SimpleTest {
tservers++;
}
assertTrue(tservers > 0);
-
+
// get something we know is in the site config
Map<String,String> cfg = client.getSiteConfiguration(creds);
assertTrue(cfg.get("instance.dfs.dir").startsWith(folder.getRoot().toString()));
-
+
// set a property in zookeeper
client.setProperty(creds, "table.split.threshold", "500M");
-
+
// check that we can read it
for (int i = 0; i < 5; i++) {
cfg = client.getSystemConfiguration(creds);
@@ -724,7 +724,7 @@ public class SimpleTest {
UtilWaitThread.sleep(200);
}
assertEquals("500M", cfg.get("table.split.threshold"));
-
+
// unset the setting, check that it's not what it was
client.removeProperty(creds, "table.split.threshold");
for (int i = 0; i < 5; i++) {
@@ -734,11 +734,11 @@ public class SimpleTest {
UtilWaitThread.sleep(200);
}
assertNotEquals("500M", cfg.get("table.split.threshold"));
-
+
// try to load some classes via the proxy
assertTrue(client.testClassLoad(creds, DevNull.class.getName(), SortedKeyValueIterator.class.getName()));
assertFalse(client.testClassLoad(creds, "foo.bar", SortedKeyValueIterator.class.getName()));
-
+
// create a table that's very slow, so we can look for scans/compactions
client.createTable(creds, "slow", true, TimeType.MILLIS);
IteratorSetting setting = new IteratorSetting(100, "slow", SlowIterator.class.getName(), Collections.singletonMap("sleepTime", "200"));
@@ -747,7 +747,7 @@ public class SimpleTest {
client.updateAndFlush(creds, "slow", mutation("row2", "cf", "cq", "value"));
client.updateAndFlush(creds, "slow", mutation("row3", "cf", "cq", "value"));
client.updateAndFlush(creds, "slow", mutation("row4", "cf", "cq", "value"));
-
+
// scan
Thread t = new Thread() {
@Override
@@ -785,7 +785,7 @@ public class SimpleTest {
assertEquals(map.get("slow"), scan.getExtent().tableId);
assertTrue(scan.getExtent().endRow == null);
assertTrue(scan.getExtent().prevEndRow == null);
-
+
// start a compaction
t = new Thread() {
@Override
@@ -799,7 +799,7 @@ public class SimpleTest {
}
};
t.start();
-
+
// try to catch it in the act
List<ActiveCompaction> compactions = Collections.emptyList();
loop2: for (int i = 0; i < 100; i++) {
@@ -821,15 +821,15 @@ public class SimpleTest {
assertEquals("", c.localityGroup);
assertTrue(c.outputFile.contains("default_tablet"));
}
-
+
@Test
public void testSecurityOperations() throws Exception {
final String TABLE_TEST = makeTableName();
-
+
// check password
assertTrue(client.authenticateUser(creds, "root", s2pp(secret)));
assertFalse(client.authenticateUser(creds, "root", s2pp("")));
-
+
// create a user
client.createLocalUser(creds, "stooge", s2bb("password"));
// change auths
@@ -839,11 +839,11 @@ public class SimpleTest {
client.changeUserAuthorizations(creds, "stooge", auths);
List<ByteBuffer> update = client.getUserAuthorizations(creds, "stooge");
assertEquals(auths, new HashSet<ByteBuffer>(update));
-
+
// change password
client.changeLocalUserPassword(creds, "stooge", s2bb(""));
assertTrue(client.authenticateUser(creds, "stooge", s2pp("")));
-
+
// check permission failure
@SuppressWarnings("serial")
ByteBuffer stooge = client.login("stooge", new TreeMap<String,String>() {
@@ -851,7 +851,7 @@ public class SimpleTest {
put("password", "");
}
});
-
+
try {
client.createTable(stooge, "fail", true, TimeType.MILLIS);
fail("should not create the table");
@@ -864,7 +864,7 @@ public class SimpleTest {
assertTrue(client.hasSystemPermission(creds, "stooge", SystemPermission.CREATE_TABLE));
client.createTable(stooge, "success", true, TimeType.MILLIS);
client.listTables(creds).contains("succcess");
-
+
// revoke permissions
client.revokeSystemPermission(creds, "stooge", SystemPermission.CREATE_TABLE);
assertFalse(client.hasSystemPermission(creds, "stooge", SystemPermission.CREATE_TABLE));
@@ -897,27 +897,27 @@ public class SimpleTest {
client.nextK(scanner, 100);
fail("stooge should not read table test");
} catch (AccumuloSecurityException ex) {}
-
+
// delete user
client.dropLocalUser(creds, "stooge");
users = client.listLocalUsers(creds);
assertEquals(1, users.size());
-
+
}
-
+
@Test
public void testBatchWriter() throws Exception {
final String TABLE_TEST = makeTableName();
-
+
client.createTable(creds, TABLE_TEST, true, TimeType.MILLIS);
client.addConstraint(creds, TABLE_TEST, NumericValueConstraint.class.getName());
-
+
WriterOptions writerOptions = new WriterOptions();
writerOptions.setLatencyMs(10000);
writerOptions.setMaxMemory(2);
writerOptions.setThreads(1);
writerOptions.setTimeoutMs(100000);
-
+
String batchWriter = client.createWriter(creds, TABLE_TEST, writerOptions);
client.update(batchWriter, mutation("row1", "cf", "cq", "x"));
client.update(batchWriter, mutation("row1", "cf", "cq", "x"));
@@ -929,44 +929,44 @@ public class SimpleTest {
client.closeWriter(batchWriter);
fail("constraint did not fire");
} catch (MutationsRejectedException e) {}
-
+
client.removeConstraint(creds, TABLE_TEST, 2);
-
+
writerOptions = new WriterOptions();
writerOptions.setLatencyMs(10000);
writerOptions.setMaxMemory(3000);
writerOptions.setThreads(1);
writerOptions.setTimeoutMs(100000);
-
+
batchWriter = client.createWriter(creds, TABLE_TEST, writerOptions);
-
+
client.update(batchWriter, mutation("row1", "cf", "cq", "x"));
client.flush(batchWriter);
client.closeWriter(batchWriter);
-
+
String scanner = client.createScanner(creds, TABLE_TEST, null);
ScanResult more = client.nextK(scanner, 2);
assertEquals(1, more.getResults().size());
client.closeScanner(scanner);
-
+
client.deleteTable(creds, TABLE_TEST);
}
-
+
@Test
public void testTableOperations() throws Exception {
final String TABLE_TEST = makeTableName();
-
+
client.createTable(creds, TABLE_TEST, true, TimeType.MILLIS);
// constraints
client.addConstraint(creds, TABLE_TEST, NumericValueConstraint.class.getName());
- assertEquals (2, client.listConstraints (creds, TABLE_TEST).size ());
+ assertEquals(2, client.listConstraints(creds, TABLE_TEST).size());
client.updateAndFlush(creds, TABLE_TEST, mutation("row1", "cf", "cq", "123"));
-
+
try {
client.updateAndFlush(creds, TABLE_TEST, mutation("row1", "cf", "cq", "x"));
fail("constraint did not fire");
} catch (MutationsRejectedException ex) {}
-
+
client.removeConstraint(creds, TABLE_TEST, 2);
assertEquals(1, client.listConstraints(creds, TABLE_TEST).size());
client.updateAndFlush(creds, TABLE_TEST, mutation("row1", "cf", "cq", "x"));
@@ -1024,14 +1024,14 @@ public class SimpleTest {
client.closeScanner(scanner);
assertEquals(10, more.getResults().size());
client.deleteTable(creds, TABLE_TEST2);
-
+
// don't know how to test this, call it just for fun
client.clearLocatorCache(creds, TABLE_TEST);
-
+
// compact
client.compactTable(creds, TABLE_TEST, null, null, null, true, true);
assertEquals(1, countFiles(TABLE_TEST));
-
+
// get disk usage
client.cloneTable(creds, TABLE_TEST, TABLE_TEST2, true, null, null);
Set<String> tablesToScan = new HashSet<String>();
@@ -1051,7 +1051,7 @@ public class SimpleTest {
assertEquals(1, diskUsage.get(2).getTables().size());
client.deleteTable(creds, "foo");
client.deleteTable(creds, TABLE_TEST2);
-
+
// export/import
String dir = folder.getRoot() + "/test";
String destDir = folder.getRoot() + "/test_dest";
@@ -1074,7 +1074,7 @@ public class SimpleTest {
more = client.nextK(scanner, 100);
client.closeScanner(scanner);
assertEquals(10, more.results.size());
-
+
try {
// ACCUMULO-1558 a second import from the same dir should fail, the first import moved the files
client.importTable(creds, "testify2", destDir);
@@ -1125,19 +1125,19 @@ public class SimpleTest {
assertEquals(1, more.results.size());
ByteBuffer maxRow = client.getMaxRow(creds, "bar", null, null, false, null, false);
assertEquals(s2bb("a"), maxRow);
-
+
assertFalse(client.testTableClassLoad(creds, "bar", "abc123", SortedKeyValueIterator.class.getName()));
assertTrue(client.testTableClassLoad(creds, "bar", VersioningIterator.class.getName(), SortedKeyValueIterator.class.getName()));
}
-
+
private Condition newCondition(String cf, String cq) {
return new Condition(new Column(s2bb(cf), s2bb(cq), s2bb("")));
}
-
+
private Condition newCondition(String cf, String cq, String val) {
return newCondition(cf, cq).setValue(s2bb(val));
}
-
+
private Condition newCondition(String cf, String cq, long ts, String val) {
return newCondition(cf, cq).setValue(s2bb(val)).setTimestamp(ts);
}
@@ -1145,7 +1145,7 @@ public class SimpleTest {
private ColumnUpdate newColUpdate(String cf, String cq, String val) {
return new ColumnUpdate(s2bb(cf), s2bb(cq)).setValue(s2bb(val));
}
-
+
private ColumnUpdate newColUpdate(String cf, String cq, long ts, String val) {
return new ColumnUpdate(s2bb(cf), s2bb(cq)).setTimestamp(ts).setValue(s2bb(val));
}
@@ -1153,55 +1153,55 @@ public class SimpleTest {
private void assertScan(String[][] expected, String table) throws Exception {
String scid = client.createScanner(creds, table, new ScanOptions());
ScanResult keyValues = client.nextK(scid, expected.length + 1);
-
+
assertEquals(expected.length, keyValues.results.size());
assertFalse(keyValues.more);
-
+
for (int i = 0; i < keyValues.results.size(); i++) {
checkKey(expected[i][0], expected[i][1], expected[i][2], expected[i][3], keyValues.results.get(i));
}
-
+
client.closeScanner(scid);
}
@Test
public void testConditionalWriter() throws Exception {
final String TABLE_TEST = makeTableName();
-
+
client.createTable(creds, TABLE_TEST, true, TimeType.MILLIS);
-
+
client.addConstraint(creds, TABLE_TEST, NumericValueConstraint.class.getName());
String cwid = client.createConditionalWriter(creds, TABLE_TEST, new ConditionalWriterOptions());
-
+
Map<ByteBuffer,ConditionalUpdates> updates = new HashMap<ByteBuffer,ConditionalUpdates>();
-
+
updates.put(
s2bb("00345"),
new ConditionalUpdates(Arrays.asList(newCondition("meta", "seq")), Arrays.asList(newColUpdate("meta", "seq", 10, "1"),
newColUpdate("data", "img", "73435435"))));
-
+
Map<ByteBuffer,ConditionalStatus> results = client.updateRowsConditionally(cwid, updates);
-
+
assertEquals(1, results.size());
assertEquals(ConditionalStatus.ACCEPTED, results.get(s2bb("00345")));
-
+
assertScan(new String[][] { {"00345", "data", "img", "73435435"}, {"00345", "meta", "seq", "1"}}, TABLE_TEST);
-
+
// test not setting values on conditions
updates.clear();
-
+
updates.put(s2bb("00345"), new ConditionalUpdates(Arrays.asList(newCondition("meta", "seq")), Arrays.asList(newColUpdate("meta", "seq", "2"))));
updates.put(s2bb("00346"), new ConditionalUpdates(Arrays.asList(newCondition("meta", "seq")), Arrays.asList(newColUpdate("meta", "seq", "1"))));
-
+
results = client.updateRowsConditionally(cwid, updates);
-
+
assertEquals(2, results.size());
assertEquals(ConditionalStatus.REJECTED, results.get(s2bb("00345")));
assertEquals(ConditionalStatus.ACCEPTED, results.get(s2bb("00346")));
assertScan(new String[][] { {"00345", "data", "img", "73435435"}, {"00345", "meta", "seq", "1"}, {"00346", "meta", "seq", "1"}}, TABLE_TEST);
-
+
// test setting values on conditions
updates.clear();
@@ -1209,66 +1209,63 @@ public class SimpleTest {
s2bb("00345"),
new ConditionalUpdates(Arrays.asList(newCondition("meta", "seq", "1")), Arrays.asList(newColUpdate("meta", "seq", 20, "2"),
newColUpdate("data", "img", "567890"))));
-
+
updates.put(s2bb("00346"), new ConditionalUpdates(Arrays.asList(newCondition("meta", "seq", "2")), Arrays.asList(newColUpdate("meta", "seq", "3"))));
-
+
results = client.updateRowsConditionally(cwid, updates);
-
+
assertEquals(2, results.size());
assertEquals(ConditionalStatus.ACCEPTED, results.get(s2bb("00345")));
assertEquals(ConditionalStatus.REJECTED, results.get(s2bb("00346")));
-
- assertScan(new String[][] { {"00345", "data", "img", "567890"}, {"00345", "meta", "seq", "2"},
- {"00346", "meta", "seq", "1"}}, TABLE_TEST);
-
+
+ assertScan(new String[][] { {"00345", "data", "img", "567890"}, {"00345", "meta", "seq", "2"}, {"00346", "meta", "seq", "1"}}, TABLE_TEST);
+
// test setting timestamp on condition to a non-existant version
updates.clear();
-
+
updates.put(
s2bb("00345"),
new ConditionalUpdates(Arrays.asList(newCondition("meta", "seq", 10, "2")), Arrays.asList(newColUpdate("meta", "seq", 30, "3"),
newColUpdate("data", "img", "1234567890"))));
-
+
results = client.updateRowsConditionally(cwid, updates);
-
+
assertEquals(1, results.size());
assertEquals(ConditionalStatus.REJECTED, results.get(s2bb("00345")));
-
+
assertScan(new String[][] { {"00345", "data", "img", "567890"}, {"00345", "meta", "seq", "2"}, {"00346", "meta", "seq", "1"}}, TABLE_TEST);
-
// test setting timestamp to an existing version
-
+
updates.clear();
-
+
updates.put(
s2bb("00345"),
new ConditionalUpdates(Arrays.asList(newCondition("meta", "seq", 20, "2")), Arrays.asList(newColUpdate("meta", "seq", 30, "3"),
newColUpdate("data", "img", "1234567890"))));
-
-
+
results = client.updateRowsConditionally(cwid, updates);
-
+
assertEquals(1, results.size());
assertEquals(ConditionalStatus.ACCEPTED, results.get(s2bb("00345")));
-
+
assertScan(new String[][] { {"00345", "data", "img", "1234567890"}, {"00345", "meta", "seq", "3"}, {"00346", "meta", "seq", "1"}}, TABLE_TEST);
-
+
// run test w/ condition that has iterators
// following should fail w/o iterator
client.updateAndFlush(creds, TABLE_TEST, Collections.singletonMap(s2bb("00347"), Arrays.asList(newColUpdate("data", "count", "1"))));
client.updateAndFlush(creds, TABLE_TEST, Collections.singletonMap(s2bb("00347"), Arrays.asList(newColUpdate("data", "count", "1"))));
client.updateAndFlush(creds, TABLE_TEST, Collections.singletonMap(s2bb("00347"), Arrays.asList(newColUpdate("data", "count", "1"))));
-
+
updates.clear();
updates.put(s2bb("00347"),
new ConditionalUpdates(Arrays.asList(newCondition("data", "count", "3")), Arrays.asList(newColUpdate("data", "img", "1234567890"))));
-
+
results = client.updateRowsConditionally(cwid, updates);
-
+
assertEquals(1, results.size());
assertEquals(ConditionalStatus.REJECTED, results.get(s2bb("00347")));
-
+
assertScan(new String[][] { {"00345", "data", "img", "1234567890"}, {"00345", "meta", "seq", "3"}, {"00346", "meta", "seq", "1"},
{"00347", "data", "count", "1"}}, TABLE_TEST);
@@ -1279,10 +1276,10 @@ public class SimpleTest {
props.put("columns", "data:count");
IteratorSetting is = new IteratorSetting(1, "sumc", SummingCombiner.class.getName(), props);
iterCond.setIterators(Arrays.asList(is));
-
+
updates.clear();
updates.put(s2bb("00347"), new ConditionalUpdates(Arrays.asList(iterCond), Arrays.asList(newColUpdate("data", "img", "1234567890"))));
-
+
results = client.updateRowsConditionally(cwid, updates);
assertEquals(1, results.size());
@@ -1295,12 +1292,12 @@ public class SimpleTest {
updates.clear();
updates.put(s2bb("00347"),
new ConditionalUpdates(Arrays.asList(newCondition("data", "img", "1234567890")), Arrays.asList(newColUpdate("data", "count", "A"))));
-
+
results = client.updateRowsConditionally(cwid, updates);
-
+
assertEquals(1, results.size());
assertEquals(ConditionalStatus.VIOLATED, results.get(s2bb("00347")));
-
+
assertScan(new String[][] { {"00345", "data", "img", "1234567890"}, {"00345", "meta", "seq", "3"}, {"00346", "meta", "seq", "1"},
{"00347", "data", "count", "1"}, {"00347", "data", "img", "1234567890"}}, TABLE_TEST);
@@ -1311,56 +1308,56 @@ public class SimpleTest {
s2bb("00347"),
new ConditionalUpdates(Arrays.asList(newCondition("data", "img", "565"), newCondition("data", "count", "2")), Arrays.asList(
newColUpdate("data", "count", "3"), newColUpdate("data", "img", "0987654321"))));
-
+
results = client.updateRowsConditionally(cwid, updates);
-
+
assertEquals(1, results.size());
assertEquals(ConditionalStatus.REJECTED, results.get(s2bb("00347")));
-
+
assertScan(new String[][] { {"00345", "data", "img", "1234567890"}, {"00345", "meta", "seq", "3"}, {"00346", "meta", "seq", "1"},
{"00347", "data", "count", "1"}, {"00347", "data", "img", "1234567890"}}, TABLE_TEST);
-
+
// one condition should fail
updates.clear();
updates.put(
s2bb("00347"),
new ConditionalUpdates(Arrays.asList(newCondition("data", "img", "1234567890"), newCondition("data", "count", "2")), Arrays.asList(
newColUpdate("data", "count", "3"), newColUpdate("data", "img", "0987654321"))));
-
+
results = client.updateRowsConditionally(cwid, updates);
-
+
assertEquals(1, results.size());
assertEquals(ConditionalStatus.REJECTED, results.get(s2bb("00347")));
-
+
assertScan(new String[][] { {"00345", "data", "img", "1234567890"}, {"00345", "meta", "seq", "3"}, {"00346", "meta", "seq", "1"},
{"00347", "data", "count", "1"}, {"00347", "data", "img", "1234567890"}}, TABLE_TEST);
-
+
// one condition should fail
updates.clear();
updates.put(
s2bb("00347"),
new ConditionalUpdates(Arrays.asList(newCondition("data", "img", "565"), newCondition("data", "count", "1")), Arrays.asList(
newColUpdate("data", "count", "3"), newColUpdate("data", "img", "0987654321"))));
-
+
results = client.updateRowsConditionally(cwid, updates);
-
+
assertEquals(1, results.size());
assertEquals(ConditionalStatus.REJECTED, results.get(s2bb("00347")));
-
+
assertScan(new String[][] { {"00345", "data", "img", "1234567890"}, {"00345", "meta", "seq", "3"}, {"00346", "meta", "seq", "1"},
{"00347", "data", "count", "1"}, {"00347", "data", "img", "1234567890"}}, TABLE_TEST);
-
+
// both conditions should succeed
-
+
ConditionalStatus result = client.updateRowConditionally(
creds,
TABLE_TEST,
s2bb("00347"),
new ConditionalUpdates(Arrays.asList(newCondition("data", "img", "1234567890"), newCondition("data", "count", "1")), Arrays.asList(
newColUpdate("data", "count", "3"), newColUpdate("data", "img", "0987654321"))));
-
+
assertEquals(ConditionalStatus.ACCEPTED, result);
-
+
assertScan(new String[][] { {"00345", "data", "img", "1234567890"}, {"00345", "meta", "seq", "3"}, {"00346", "meta", "seq", "1"},
{"00347", "data", "count", "3"}, {"00347", "data", "img", "0987654321"}}, TABLE_TEST);
@@ -1375,43 +1372,44 @@ public class SimpleTest {
client.changeUserAuthorizations(creds, "cwuser", Collections.singleton(s2bb("A")));
client.grantTablePermission(creds, "cwuser", TABLE_TEST, TablePermission.WRITE);
client.grantTablePermission(creds, "cwuser", TABLE_TEST, TablePermission.READ);
-
+
ByteBuffer cwuCreds = client.login("cwuser", Collections.singletonMap("password", "bestpasswordever"));
-
+
cwid = client.createConditionalWriter(cwuCreds, TABLE_TEST, new ConditionalWriterOptions().setAuthorizations(Collections.singleton(s2bb("A"))));
-
+
updates.clear();
- updates.put(s2bb("00348"),
+ updates.put(
+ s2bb("00348"),
new ConditionalUpdates(Arrays.asList(new Condition(new Column(s2bb("data"), s2bb("c"), s2bb("A")))), Arrays.asList(newColUpdate("data", "seq", "1"),
newColUpdate("data", "c", "1").setColVisibility(s2bb("A")))));
updates.put(s2bb("00349"),
new ConditionalUpdates(Arrays.asList(new Condition(new Column(s2bb("data"), s2bb("c"), s2bb("B")))), Arrays.asList(newColUpdate("data", "seq", "1"))));
-
+
results = client.updateRowsConditionally(cwid, updates);
-
+
assertEquals(2, results.size());
assertEquals(ConditionalStatus.ACCEPTED, results.get(s2bb("00348")));
assertEquals(ConditionalStatus.INVISIBLE_VISIBILITY, results.get(s2bb("00349")));
-
+
assertScan(new String[][] { {"00345", "data", "img", "1234567890"}, {"00345", "meta", "seq", "3"}, {"00346", "meta", "seq", "1"},
{"00347", "data", "count", "3"}, {"00347", "data", "img", "0987654321"}, {"00348", "data", "seq", "1"}}, TABLE_TEST);
updates.clear();
-
+
updates.clear();
updates.put(
s2bb("00348"),
new ConditionalUpdates(Arrays.asList(new Condition(new Column(s2bb("data"), s2bb("c"), s2bb("A"))).setValue(s2bb("0"))), Arrays.asList(
newColUpdate("data", "seq", "2"), newColUpdate("data", "c", "2").setColVisibility(s2bb("A")))));
-
+
results = client.updateRowsConditionally(cwid, updates);
-
+
assertEquals(1, results.size());
assertEquals(ConditionalStatus.REJECTED, results.get(s2bb("00348")));
-
+
assertScan(new String[][] { {"00345", "data", "img", "1234567890"}, {"00345", "meta", "seq", "3"}, {"00346", "meta", "seq", "1"},
{"00347", "data", "count", "3"}, {"00347", "data", "img", "0987654321"}, {"00348", "data", "seq", "1"}}, TABLE_TEST);
-
+
updates.clear();
updates.put(
s2bb("00348"),
@@ -1419,10 +1417,10 @@ public class SimpleTest {
newColUpdate("data", "seq", "2"), newColUpdate("data", "c", "2").setColVisibility(s2bb("A")))));
results = client.updateRowsConditionally(cwid, updates);
-
+
assertEquals(1, results.size());
assertEquals(ConditionalStatus.ACCEPTED, results.get(s2bb("00348")));
-
+
assertScan(new String[][] { {"00345", "data", "img", "1234567890"}, {"00345", "meta", "seq", "3"}, {"00346", "meta", "seq", "1"},
{"00347", "data", "count", "3"}, {"00347", "data", "img", "0987654321"}, {"00348", "data", "seq", "2"}}, TABLE_TEST);
@@ -1466,23 +1464,23 @@ public class SimpleTest {
}
return result;
}
-
+
private Map<ByteBuffer,List<ColumnUpdate>> mutation(String row, String cf, String cq, String value) {
ColumnUpdate upd = new ColumnUpdate(s2bb(cf), s2bb(cq));
upd.setValue(value.getBytes());
return Collections.singletonMap(s2bb(row), Collections.singletonList(upd));
}
-
+
private ByteBuffer s2bb(String cf) {
return ByteBuffer.wrap(cf.getBytes());
}
-
+
private Map<String,String> s2pp(String cf) {
Map<String,String> toRet = new TreeMap<String,String>();
toRet.put("password", cf);
return toRet;
}
-
+
@AfterClass
public static void tearDownMiniCluster() throws Exception {
accumulo.stop();
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/server/src/test/java/org/apache/accumulo/server/tabletserver/log/MultiReaderTest.java
----------------------------------------------------------------------
diff --git a/server/src/test/java/org/apache/accumulo/server/tabletserver/log/MultiReaderTest.java b/server/src/test/java/org/apache/accumulo/server/tabletserver/log/MultiReaderTest.java
index c69baa4..d35ff35 100644
--- a/server/src/test/java/org/apache/accumulo/server/tabletserver/log/MultiReaderTest.java
+++ b/server/src/test/java/org/apache/accumulo/server/tabletserver/log/MultiReaderTest.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.io.File;
import java.io.IOException;
import org.apache.accumulo.server.fs.VolumeManager;
@@ -37,10 +38,10 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
public class MultiReaderTest {
-
+
VolumeManager fs;
- TemporaryFolder root = new TemporaryFolder();
-
+ TemporaryFolder root = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+
@Before
public void setUp() throws Exception {
// quiet log messages about compress.CodecPool
@@ -66,16 +67,16 @@ public class MultiReaderTest {
}
writer.close();
}
-
+
@After
public void tearDown() throws Exception {
root.create();
}
-
+
private void scan(MultiReader reader, int start) throws IOException {
IntWritable key = new IntWritable();
BytesWritable value = new BytesWritable();
-
+
for (int i = start + 1; i < 1000; i++) {
if (i == 10)
continue;
@@ -83,24 +84,24 @@ public class MultiReaderTest {
assertEquals(i, key.get());
}
}
-
+
private void scanOdd(MultiReader reader, int start) throws IOException {
IntWritable key = new IntWritable();
BytesWritable value = new BytesWritable();
-
+
for (int i = start + 2; i < 1000; i += 2) {
assertTrue(reader.next(key, value));
assertEquals(i, key.get());
}
}
-
+
@Test
public void testMultiReader() throws IOException {
Path manyMaps = new Path("file://" + root.getRoot().getAbsolutePath() + "/manyMaps");
MultiReader reader = new MultiReader(fs, manyMaps);
IntWritable key = new IntWritable();
BytesWritable value = new BytesWritable();
-
+
for (int i = 0; i < 1000; i++) {
if (i == 10)
continue;
@@ -109,7 +110,7 @@ public class MultiReaderTest {
}
assertEquals(value.compareTo(new BytesWritable("someValue".getBytes())), 0);
assertFalse(reader.next(key, value));
-
+
key.set(500);
assertTrue(reader.seek(key));
scan(reader, 500);
@@ -125,7 +126,7 @@ public class MultiReaderTest {
assertTrue(reader.next(key, value));
assertEquals(0, key.get());
reader.close();
-
+
fs.deleteRecursively(new Path(manyMaps, "even"));
reader = new MultiReader(fs, manyMaps);
key.set(501);
@@ -140,7 +141,7 @@ public class MultiReaderTest {
assertTrue(reader.next(key, value));
assertEquals(1, key.get());
reader.close();
-
+
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/server/src/test/java/org/apache/accumulo/server/tabletserver/log/SortedLogRecoveryTest.java
----------------------------------------------------------------------
diff --git a/server/src/test/java/org/apache/accumulo/server/tabletserver/log/SortedLogRecoveryTest.java b/server/src/test/java/org/apache/accumulo/server/tabletserver/log/SortedLogRecoveryTest.java
index dc15260..62c9f37 100644
--- a/server/src/test/java/org/apache/accumulo/server/tabletserver/log/SortedLogRecoveryTest.java
+++ b/server/src/test/java/org/apache/accumulo/server/tabletserver/log/SortedLogRecoveryTest.java
@@ -22,6 +22,7 @@ import static org.apache.accumulo.server.logger.LogEvents.DEFINE_TABLET;
import static org.apache.accumulo.server.logger.LogEvents.MUTATION;
import static org.apache.accumulo.server.logger.LogEvents.OPEN;
+import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -52,27 +53,27 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
public class SortedLogRecoveryTest {
-
+
static final KeyExtent extent = new KeyExtent(new Text("table"), null, null);
static final Text cf = new Text("cf");
static final Text cq = new Text("cq");
static final Value value = new Value("value".getBytes());
-
+
static class KeyValue implements Comparable<KeyValue> {
public final LogFileKey key;
public final LogFileValue value;
-
+
KeyValue() {
key = new LogFileKey();
value = new LogFileValue();
}
-
+
@Override
public int compareTo(KeyValue o) {
return key.compareTo(o.key);
}
}
-
+
private static KeyValue createKeyValue(LogEvents type, long seq, int tid, Object fileExtentMutation) {
KeyValue result = new KeyValue();
result.key.event = type;
@@ -94,27 +95,27 @@ public class SortedLogRecoveryTest {
result.value.mutations = Arrays.asList((Mutation) fileExtentMutation);
break;
case MANY_MUTATIONS:
- result.value.mutations = Arrays.asList((Mutation[])fileExtentMutation);
+ result.value.mutations = Arrays.asList((Mutation[]) fileExtentMutation);
}
return result;
}
-
+
private static class CaptureMutations implements MutationReceiver {
public ArrayList<Mutation> result = new ArrayList<Mutation>();
-
+
@Override
public void receive(Mutation m) {
// make a copy of Mutation:
result.add(m);
}
}
-
+
private static List<Mutation> recover(Map<String,KeyValue[]> logs, KeyExtent extent) throws IOException {
return recover(logs, new HashSet<String>(), extent);
}
-
+
private static List<Mutation> recover(Map<String,KeyValue[]> logs, Set<String> files, KeyExtent extent) throws IOException {
- TemporaryFolder root = new TemporaryFolder();
+ TemporaryFolder root = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
root.create();
final String workdir = "file://" + root.getRoot().getAbsolutePath() + "/workdir";
VolumeManager fs = VolumeManagerImpl.getLocal();
@@ -141,7 +142,7 @@ public class SortedLogRecoveryTest {
root.delete();
}
}
-
+
@Test
public void testCompactionCrossesLogs() throws IOException {
Mutation ignored = new ServerMutation(new Text("ignored"));
@@ -161,23 +162,23 @@ public class SortedLogRecoveryTest {
createKeyValue(MUTATION, 2, 3, ignored), createKeyValue(MUTATION, 3, 3, ignored), createKeyValue(MUTATION, 4, 3, ignored),};
KeyValue entries5[] = new KeyValue[] {createKeyValue(OPEN, 0, 4, "70"), createKeyValue(DEFINE_TABLET, 1, 4, extent),
createKeyValue(COMPACTION_START, 3, 4, "thisfile"), createKeyValue(MUTATION, 2, 4, ignored), createKeyValue(MUTATION, 6, 4, m2),};
-
+
Map<String,KeyValue[]> logs = new TreeMap<String,KeyValue[]>();
logs.put("entries", entries);
logs.put("entries2", entries2);
logs.put("entries3", entries3);
logs.put("entries4", entries4);
logs.put("entries5", entries5);
-
+
// Recover
List<Mutation> mutations = recover(logs, extent);
-
+
// Verify recovered data
Assert.assertEquals(2, mutations.size());
Assert.assertEquals(m, mutations.get(0));
Assert.assertEquals(m2, mutations.get(1));
}
-
+
@Test
public void testCompactionCrossesLogs5() throws IOException {
// Create a test log
@@ -215,7 +216,7 @@ public class SortedLogRecoveryTest {
Assert.assertEquals(m3, mutations.get(2));
Assert.assertEquals(m4, mutations.get(3));
}
-
+
@Test
public void testCompactionCrossesLogs6() throws IOException {
// Create a test log
@@ -235,20 +236,20 @@ public class SortedLogRecoveryTest {
createKeyValue(MUTATION, 3, 1, m),};
KeyValue entries2[] = new KeyValue[] {createKeyValue(OPEN, 0, 1, "2"), createKeyValue(DEFINE_TABLET, 1, 1, extent),
createKeyValue(COMPACTION_START, 2, 1, "somefile"), createKeyValue(COMPACTION_FINISH, 3, 1, "somefile"), createKeyValue(MUTATION, 3, 1, m2),};
-
+
Map<String,KeyValue[]> logs = new TreeMap<String,KeyValue[]>();
logs.put("entries", entries);
logs.put("entries2", entries2);
-
+
// Recover
List<Mutation> mutations = recover(logs, extent);
-
+
// Verify recovered data
Assert.assertEquals(2, mutations.size());
Assert.assertEquals(m, mutations.get(0));
Assert.assertEquals(m2, mutations.get(1));
}
-
+
@Test
public void testEmpty() throws IOException {
// Create a test log
@@ -259,9 +260,9 @@ public class SortedLogRecoveryTest {
List<Mutation> mutations = recover(logs, extent);
// Verify recovered data
Assert.assertEquals(0, mutations.size());
-
+
}
-
+
@Test
public void testMissingDefinition() {
// Create a test log
@@ -274,7 +275,7 @@ public class SortedLogRecoveryTest {
Assert.fail("tablet should not have been found");
} catch (Throwable t) {}
}
-
+
@Test
public void testSimple() throws IOException {
// Create a test log
@@ -289,7 +290,7 @@ public class SortedLogRecoveryTest {
Assert.assertEquals(1, mutations.size());
Assert.assertEquals(m, mutations.get(0));
}
-
+
@Test
public void testSkipSuccessfulCompaction() throws IOException {
// Create a test log
@@ -308,7 +309,7 @@ public class SortedLogRecoveryTest {
Assert.assertEquals(1, mutations.size());
Assert.assertEquals(m, mutations.get(0));
}
-
+
@Test
public void testSkipSuccessfulCompactionAcrossFiles() throws IOException {
// Create a test log
@@ -329,7 +330,7 @@ public class SortedLogRecoveryTest {
Assert.assertEquals(1, mutations.size());
Assert.assertEquals(m, mutations.get(0));
}
-
+
@Test
public void testGetMutationsAfterCompactionStart() throws IOException {
// Create a test log
@@ -353,7 +354,7 @@ public class SortedLogRecoveryTest {
Assert.assertEquals(m, mutations.get(0));
Assert.assertEquals(m2, mutations.get(1));
}
-
+
@Test
public void testDoubleFinish() throws IOException {
// Create a test log
@@ -375,7 +376,7 @@ public class SortedLogRecoveryTest {
Assert.assertEquals(m, mutations.get(0));
Assert.assertEquals(m2, mutations.get(1));
}
-
+
@Test
public void testCompactionCrossesLogs2() throws IOException {
// Create a test log
@@ -404,7 +405,7 @@ public class SortedLogRecoveryTest {
Assert.assertEquals(m2, mutations.get(1));
Assert.assertEquals(m3, mutations.get(2));
}
-
+
@Test
public void testBug1() throws IOException {
// this unit test reproduces a bug that occurred, nothing should recover
@@ -422,7 +423,7 @@ public class SortedLogRecoveryTest {
// Verify recovered data
Assert.assertEquals(0, mutations.size());
}
-
+
@Test
public void testBug2() throws IOException {
// Create a test log
@@ -449,7 +450,7 @@ public class SortedLogRecoveryTest {
Assert.assertEquals(m2, mutations.get(1));
Assert.assertEquals(m3, mutations.get(2));
}
-
+
@Test
public void testCompactionCrossesLogs4() throws IOException {
// Create a test log
@@ -487,9 +488,9 @@ public class SortedLogRecoveryTest {
logs.put("entries2", entries2);
logs.put("entries3", entries3);
// Recover
-
+
List<Mutation> mutations = recover(logs, extent);
-
+
// Verify recovered data
Assert.assertEquals(6, mutations.size());
Assert.assertEquals(m, mutations.get(0));
@@ -499,7 +500,7 @@ public class SortedLogRecoveryTest {
Assert.assertEquals(m5, mutations.get(4));
Assert.assertEquals(m6, mutations.get(5));
}
-
+
@Test
public void testLookingForBug3() throws IOException {
Mutation ignored = new ServerMutation(new Text("ignored"));
@@ -532,70 +533,70 @@ public class SortedLogRecoveryTest {
Assert.assertEquals(m4, mutations.get(3));
Assert.assertEquals(m5, mutations.get(4));
}
-
+
@Test
public void testMultipleTabletDefinition() throws Exception {
// test for a tablet defined multiple times in a log file
// there was a bug where the oldest tablet id was used instead
// of the newest
-
+
Mutation ignored = new ServerMutation(new Text("row1"));
ignored.put("foo", "bar", "v1");
Mutation m = new ServerMutation(new Text("row1"));
m.put("foo", "bar", "v1");
-
+
KeyValue entries[] = new KeyValue[] {createKeyValue(OPEN, 0, -1, "1"), createKeyValue(DEFINE_TABLET, 1, 1, extent),
createKeyValue(DEFINE_TABLET, 1, 2, extent), createKeyValue(MUTATION, 2, 2, ignored), createKeyValue(COMPACTION_START, 3, 2, "somefile"),
createKeyValue(MUTATION, 4, 2, m), createKeyValue(COMPACTION_FINISH, 6, 2, null),};
-
+
Arrays.sort(entries);
-
+
Map<String,KeyValue[]> logs = new TreeMap<String,KeyValue[]>();
logs.put("entries", entries);
-
+
List<Mutation> mutations = recover(logs, extent);
-
+
Assert.assertEquals(1, mutations.size());
Assert.assertEquals(m, mutations.get(0));
}
-
+
@Test
public void testNoFinish0() throws Exception {
// its possible that a minor compaction finishes successfully, but the process dies before writing the compaction event
-
+
Mutation ignored = new ServerMutation(new Text("row1"));
ignored.put("foo", "bar", "v1");
-
+
KeyValue entries[] = new KeyValue[] {createKeyValue(OPEN, 0, -1, "1"), createKeyValue(DEFINE_TABLET, 1, 2, extent),
createKeyValue(MUTATION, 2, 2, ignored), createKeyValue(COMPACTION_START, 3, 2, "/t/f1")};
-
+
Arrays.sort(entries);
Map<String,KeyValue[]> logs = new TreeMap<String,KeyValue[]>();
logs.put("entries", entries);
-
+
List<Mutation> mutations = recover(logs, Collections.singleton("/t/f1"), extent);
-
+
Assert.assertEquals(0, mutations.size());
}
-
+
@Test
public void testNoFinish1() throws Exception {
// its possible that a minor compaction finishes successfully, but the process dies before writing the compaction event
-
+
Mutation ignored = new ServerMutation(new Text("row1"));
ignored.put("foo", "bar", "v1");
Mutation m = new ServerMutation(new Text("row1"));
m.put("foo", "bar", "v2");
-
+
KeyValue entries[] = new KeyValue[] {createKeyValue(OPEN, 0, -1, "1"), createKeyValue(DEFINE_TABLET, 1, 2, extent),
createKeyValue(MUTATION, 2, 2, ignored), createKeyValue(COMPACTION_START, 3, 2, "/t/f1"), createKeyValue(MUTATION, 4, 2, m),};
-
+
Arrays.sort(entries);
Map<String,KeyValue[]> logs = new TreeMap<String,KeyValue[]>();
logs.put("entries", entries);
-
+
List<Mutation> mutations = recover(logs, Collections.singleton("/t/f1"), extent);
-
+
Assert.assertEquals(1, mutations.size());
Assert.assertEquals(m, mutations.get(0));
}
[3/4] ACCUMULO-1599 Move MiniAccumuloCluster output to target
directory
Posted by ct...@apache.org.
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloReloadingVFSClassLoaderTest.java
----------------------------------------------------------------------
diff --git a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloReloadingVFSClassLoaderTest.java b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloReloadingVFSClassLoaderTest.java
index 489dbb2..0a48a00 100644
--- a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloReloadingVFSClassLoaderTest.java
+++ b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloReloadingVFSClassLoaderTest.java
@@ -33,7 +33,7 @@ import org.junit.rules.TemporaryFolder;
public class AccumuloReloadingVFSClassLoaderTest {
- private TemporaryFolder folder1 = new TemporaryFolder();
+ private TemporaryFolder folder1 = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
private FileSystemManager vfs;
@Before
@@ -41,11 +41,11 @@ public class AccumuloReloadingVFSClassLoaderTest {
Logger.getRootLogger().setLevel(Level.ERROR);
vfs = ContextManagerTest.getVFS();
-
+
folder1.create();
FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"), folder1.newFile("HelloWorld.jar"));
}
-
+
FileObject[] createFileSystems(FileObject[] fos) throws FileSystemException {
FileObject[] rfos = new FileObject[fos.length];
for (int i = 0; i < fos.length; i++) {
@@ -54,7 +54,7 @@ public class AccumuloReloadingVFSClassLoaderTest {
else
rfos[i] = fos[i];
}
-
+
return rfos;
}
@@ -62,34 +62,34 @@ public class AccumuloReloadingVFSClassLoaderTest {
public void testConstructor() throws Exception {
FileObject testDir = vfs.resolveFile(folder1.getRoot().toURI().toString());
FileObject[] dirContents = testDir.getChildren();
-
+
AccumuloReloadingVFSClassLoader arvcl = new AccumuloReloadingVFSClassLoader(folder1.getRoot().toURI().toString(), vfs, new ReloadingClassLoader() {
@Override
public ClassLoader getClassLoader() {
return ClassLoader.getSystemClassLoader();
}
}, true);
-
+
VFSClassLoader cl = (VFSClassLoader) arvcl.getClassLoader();
-
+
FileObject[] files = cl.getFileObjects();
Assert.assertArrayEquals(createFileSystems(dirContents), files);
-
+
arvcl.close();
}
-
+
@Test
public void testReloading() throws Exception {
FileObject testDir = vfs.resolveFile(folder1.getRoot().toURI().toString());
FileObject[] dirContents = testDir.getChildren();
-
+
AccumuloReloadingVFSClassLoader arvcl = new AccumuloReloadingVFSClassLoader(folder1.getRoot().toURI().toString(), vfs, new ReloadingClassLoader() {
@Override
public ClassLoader getClassLoader() {
return ClassLoader.getSystemClassLoader();
}
}, 1000, true);
-
+
FileObject[] files = ((VFSClassLoader) arvcl.getClassLoader()).getFileObjects();
Assert.assertArrayEquals(createFileSystems(dirContents), files);
@@ -97,55 +97,54 @@ public class AccumuloReloadingVFSClassLoaderTest {
Object o1 = clazz1.newInstance();
Assert.assertEquals("Hello World!", o1.toString());
- //Check that the class is the same before the update
+ // Check that the class is the same before the update
Class<?> clazz1_5 = arvcl.getClassLoader().loadClass("test.HelloWorld");
Assert.assertEquals(clazz1, clazz1_5);
-
+
new File(folder1.getRoot(), "HelloWorld.jar").delete();
// Update the class
FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"), folder1.newFile("HelloWorld2.jar"));
- //Wait for the monitor to notice
+ // Wait for the monitor to notice
Thread.sleep(2000);
-
+
Class<?> clazz2 = arvcl.getClassLoader().loadClass("test.HelloWorld");
Object o2 = clazz2.newInstance();
Assert.assertEquals("Hello World!", o2.toString());
-
- //This is false because they are loaded by a different classloader
+
+ // This is false because they are loaded by a different classloader
Assert.assertFalse(clazz1.equals(clazz2));
Assert.assertFalse(o1.equals(o2));
-
+
arvcl.close();
}
-
@Test
public void testModifiedClass() throws Exception {
FileObject testDir = vfs.resolveFile(folder1.getRoot().toURI().toString());
FileObject[] dirContents = testDir.getChildren();
-
+
AccumuloReloadingVFSClassLoader arvcl = new AccumuloReloadingVFSClassLoader(folder1.getRoot().toURI().toString(), vfs, new ReloadingClassLoader() {
@Override
public ClassLoader getClassLoader() {
return ClassLoader.getSystemClassLoader();
}
}, 1000, true);
-
+
FileObject[] files = ((VFSClassLoader) arvcl.getClassLoader()).getFileObjects();
Assert.assertArrayEquals(createFileSystems(dirContents), files);
-
+
ClassLoader loader1 = arvcl.getClassLoader();
Class<?> clazz1 = loader1.loadClass("test.HelloWorld");
Object o1 = clazz1.newInstance();
Assert.assertEquals("Hello World!", o1.toString());
-
+
// Check that the class is the same before the update
Class<?> clazz1_5 = arvcl.getClassLoader().loadClass("test.HelloWorld");
Assert.assertEquals(clazz1, clazz1_5);
-
+
// java does aggressive caching of jar files. When using java code to read jar files that are created in the same second, it will only see the first jar
// file
Thread.sleep(1000);
@@ -154,19 +153,18 @@ public class AccumuloReloadingVFSClassLoaderTest {
// Update the class
FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld2.jar"), folder1.newFile("HelloWorld.jar"));
-
+
// Wait for the monitor to notice
Thread.sleep(2000);
-
Class<?> clazz2 = arvcl.getClassLoader().loadClass("test.HelloWorld");
Object o2 = clazz2.newInstance();
Assert.assertEquals("Hallo Welt", o2.toString());
-
+
// This is false because they are loaded by a different classloader
Assert.assertFalse(clazz1.equals(clazz2));
Assert.assertFalse(o1.equals(o2));
-
+
Class<?> clazz3 = loader1.loadClass("test.HelloWorld");
Object o3 = clazz3.newInstance();
Assert.assertEquals("Hello World!", o3.toString());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoaderTest.java
----------------------------------------------------------------------
diff --git a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoaderTest.java b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoaderTest.java
index 0d97f5e..e7c369e 100644
--- a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoaderTest.java
+++ b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoaderTest.java
@@ -42,14 +42,14 @@ import org.powermock.reflect.Whitebox;
@PowerMockIgnore({"org.apache.log4j.*", "org.apache.hadoop.log.metrics", "org.apache.commons.logging.*", "org.xml.*", "javax.xml.*", "org.w3c.dom.*",
"org.apache.hadoop.*"})
public class AccumuloVFSClassLoaderTest {
-
- private TemporaryFolder folder1 = new TemporaryFolder();
+
+ private TemporaryFolder folder1 = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
@Before
public void setup() throws IOException {
folder1.create();
}
-
+
@After
public void tearDown() {
folder1.delete();
@@ -84,19 +84,18 @@ public class AccumuloVFSClassLoaderTest {
Assert.assertTrue((acl instanceof VFSClassLoader));
Assert.assertTrue((acl.getParent() instanceof URLClassLoader));
}
-
+
/*
* Test with default context configured
*/
@Test
public void testDefaultContextConfigured() throws Exception {
-
Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);
-
+
// Copy jar file to TEST_DIR
FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"), folder1.newFile("HelloWorld.jar"));
-
+
File conf = folder1.newFile("accumulo-site.xml");
FileWriter out = new FileWriter(conf);
out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
@@ -126,5 +125,5 @@ public class AccumuloVFSClassLoaderTest {
Assert.assertEquals("Hello World!", o1.toString());
Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/start/src/test/java/org/apache/accumulo/start/classloader/vfs/ContextManagerTest.java
----------------------------------------------------------------------
diff --git a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/ContextManagerTest.java b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/ContextManagerTest.java
index d6d761b..6ed7906 100644
--- a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/ContextManagerTest.java
+++ b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/ContextManagerTest.java
@@ -34,13 +34,13 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
public class ContextManagerTest {
-
- private TemporaryFolder folder1 = new TemporaryFolder();
- private TemporaryFolder folder2 = new TemporaryFolder();
+
+ private TemporaryFolder folder1 = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+ private TemporaryFolder folder2 = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
private FileSystemManager vfs;
private URI uri1;
private URI uri2;
-
+
static FileSystemManager getVFS() {
try {
return AccumuloVFSClassLoader.generateVfs();
@@ -51,15 +51,15 @@ public class ContextManagerTest {
@Before
public void setup() throws Exception {
-
+
vfs = getVFS();
folder1.create();
folder2.create();
-
+
FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"), folder1.newFile("HelloWorld.jar"));
FileUtils.copyURLToFile(this.getClass().getResource("/HelloWorld.jar"), folder2.newFile("HelloWorld.jar"));
-
+
uri1 = new File(folder1.getRoot(), "HelloWorld.jar").toURI();
uri2 = folder2.getRoot().toURI();
@@ -73,13 +73,13 @@ public class ContextManagerTest {
else
rfos[i] = fos[i];
}
-
+
return rfos;
}
@Test
public void differentContexts() throws Exception {
-
+
ContextManager cm = new ContextManager(vfs, new ReloadingClassLoader() {
@Override
public ClassLoader getClassLoader() {
@@ -110,7 +110,7 @@ public class ContextManagerTest {
ClassLoader cl2 = cm.getClassLoader("CX2");
FileObject[] files2 = ((VFSClassLoader) cl2).getFileObjects();
Assert.assertArrayEquals(createFileSystems(dirContents2), files2);
-
+
Class<?> defaultContextClass = cl1.loadClass("test.HelloWorld");
Object o1 = defaultContextClass.newInstance();
Assert.assertEquals("Hello World!", o1.toString());
@@ -118,25 +118,25 @@ public class ContextManagerTest {
Class<?> myContextClass = cl2.loadClass("test.HelloWorld");
Object o2 = myContextClass.newInstance();
Assert.assertEquals("Hello World!", o2.toString());
-
+
Assert.assertFalse(defaultContextClass.equals(myContextClass));
cm.removeUnusedContexts(new HashSet<String>());
}
-
+
@Test
public void testPostDelegation() throws Exception {
final VFSClassLoader parent = new VFSClassLoader(new FileObject[] {vfs.resolveFile(uri1.toString())}, vfs);
-
+
Class<?> pclass = parent.loadClass("test.HelloWorld");
-
+
ContextManager cm = new ContextManager(vfs, new ReloadingClassLoader() {
@Override
public ClassLoader getClassLoader() {
return parent;
}
});
-
+
cm.setContextConfig(new ContextsConfig() {
@Override
public ContextConfig getContextConfig(String context) {
@@ -148,7 +148,7 @@ public class ContextManagerTest {
return null;
}
});
-
+
Assert.assertTrue(cm.getClassLoader("CX1").loadClass("test.HelloWorld") == pclass);
Assert.assertFalse(cm.getClassLoader("CX2").loadClass("test.HelloWorld") == pclass);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/pom.xml
----------------------------------------------------------------------
diff --git a/test/pom.xml b/test/pom.xml
index 8343bb2..e4d32e5 100644
--- a/test/pom.xml
+++ b/test/pom.xml
@@ -199,8 +199,7 @@
<argument>${project.build.directory}</argument>
<argument>${accumulo-it-mini-classpath}</argument>
<!-- InstanceName RootPassword, one pair per MiniAccumuloCluster -->
- <argument>testInstance1 rootPassword1</argument>
- <argument>testInstance2 rootPassword2</argument>
+ <argument>testInstance1 testRootPassword1</argument>
</arguments>
</configuration>
</execution>
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/fate/zookeeper/ZooLockTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/fate/zookeeper/ZooLockTest.java b/test/src/test/java/org/apache/accumulo/fate/zookeeper/ZooLockTest.java
index fb99f42..31d59e9 100644
--- a/test/src/test/java/org/apache/accumulo/fate/zookeeper/ZooLockTest.java
+++ b/test/src/test/java/org/apache/accumulo/fate/zookeeper/ZooLockTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.accumulo.fate.zookeeper;
+import java.io.File;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.List;
@@ -38,318 +39,318 @@ import org.junit.rules.TemporaryFolder;
*
*/
public class ZooLockTest {
-
- public static TemporaryFolder folder = new TemporaryFolder();
-
+
+ public static TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+
private static MiniAccumuloCluster accumulo;
-
+
static class TestALW implements AsyncLockWatcher {
-
+
LockLossReason reason = null;
boolean locked = false;
Exception exception = null;
int changes = 0;
-
+
@Override
public synchronized void lostLock(LockLossReason reason) {
this.reason = reason;
changes++;
this.notifyAll();
}
-
+
@Override
public synchronized void acquiredLock() {
this.locked = true;
changes++;
this.notifyAll();
}
-
+
@Override
public synchronized void failedToAcquireLock(Exception e) {
this.exception = e;
changes++;
this.notifyAll();
}
-
+
public synchronized void waitForChanges(int numExpected) throws InterruptedException {
while (changes < numExpected) {
this.wait();
}
}
-
+
@Override
public synchronized void unableToMonitorLockNode(Throwable e) {
changes++;
this.notifyAll();
}
}
-
+
@BeforeClass
public static void setupMiniCluster() throws Exception {
-
+
folder.create();
-
+
Logger.getLogger("org.apache.zookeeper").setLevel(Level.ERROR);
-
+
accumulo = new MiniAccumuloCluster(folder.getRoot(), "superSecret");
-
+
accumulo.start();
-
+
}
-
+
private static int pdCount = 0;
-
+
@Test(timeout = 10000)
public void testDeleteParent() throws Exception {
accumulo.getConfig().getZooKeepers();
-
+
String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
-
+
ZooLock zl = new ZooLock(accumulo.getConfig().getZooKeepers(), 30000, "digest", "secret".getBytes(), parent);
-
+
Assert.assertFalse(zl.isLocked());
-
+
ZooReaderWriter zk = ZooReaderWriter.getInstance(accumulo.getConfig().getZooKeepers(), 30000, "digest", "secret".getBytes());
-
+
// intentionally created parent after lock
zk.mkdirs(parent);
-
+
zk.delete(parent, -1);
-
+
zk.mkdirs(parent);
-
+
TestALW lw = new TestALW();
-
+
zl.lockAsync(lw, "test1".getBytes());
-
+
lw.waitForChanges(1);
-
+
Assert.assertTrue(lw.locked);
Assert.assertTrue(zl.isLocked());
Assert.assertNull(lw.exception);
Assert.assertNull(lw.reason);
-
+
zl.unlock();
}
-
+
@Test(timeout = 10000)
public void testNoParent() throws Exception {
accumulo.getConfig().getZooKeepers();
-
+
String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
-
+
ZooLock zl = new ZooLock(accumulo.getConfig().getZooKeepers(), 30000, "digest", "secret".getBytes(), parent);
-
+
Assert.assertFalse(zl.isLocked());
-
+
TestALW lw = new TestALW();
-
+
zl.lockAsync(lw, "test1".getBytes());
-
+
lw.waitForChanges(1);
-
+
Assert.assertFalse(lw.locked);
Assert.assertFalse(zl.isLocked());
Assert.assertNotNull(lw.exception);
Assert.assertNull(lw.reason);
}
-
+
@Test(timeout = 10000)
public void testDeleteLock() throws Exception {
accumulo.getConfig().getZooKeepers();
-
+
String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
-
+
ZooReaderWriter zk = ZooReaderWriter.getInstance(accumulo.getConfig().getZooKeepers(), 30000, "digest", "secret".getBytes());
zk.mkdirs(parent);
-
+
ZooLock zl = new ZooLock(accumulo.getConfig().getZooKeepers(), 30000, "digest", "secret".getBytes(), parent);
-
+
Assert.assertFalse(zl.isLocked());
-
+
TestALW lw = new TestALW();
-
+
zl.lockAsync(lw, "test1".getBytes());
-
+
lw.waitForChanges(1);
-
+
Assert.assertTrue(lw.locked);
Assert.assertTrue(zl.isLocked());
Assert.assertNull(lw.exception);
Assert.assertNull(lw.reason);
-
+
zk.delete(zl.getLockPath(), -1);
-
+
lw.waitForChanges(2);
-
+
Assert.assertEquals(LockLossReason.LOCK_DELETED, lw.reason);
Assert.assertNull(lw.exception);
-
+
}
-
+
@Test(timeout = 10000)
public void testDeleteWaiting() throws Exception {
accumulo.getConfig().getZooKeepers();
-
+
String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
-
+
ZooReaderWriter zk = ZooReaderWriter.getInstance(accumulo.getConfig().getZooKeepers(), 30000, "digest", "secret".getBytes());
zk.mkdirs(parent);
-
+
ZooLock zl = new ZooLock(accumulo.getConfig().getZooKeepers(), 30000, "digest", "secret".getBytes(), parent);
-
+
Assert.assertFalse(zl.isLocked());
-
+
TestALW lw = new TestALW();
-
+
zl.lockAsync(lw, "test1".getBytes());
-
+
lw.waitForChanges(1);
-
+
Assert.assertTrue(lw.locked);
Assert.assertTrue(zl.isLocked());
Assert.assertNull(lw.exception);
Assert.assertNull(lw.reason);
-
+
ZooLock zl2 = new ZooLock(accumulo.getConfig().getZooKeepers(), 30000, "digest", "secret".getBytes(), parent);
-
+
TestALW lw2 = new TestALW();
-
+
zl2.lockAsync(lw2, "test2".getBytes());
-
+
Assert.assertFalse(lw2.locked);
Assert.assertFalse(zl2.isLocked());
-
+
ZooLock zl3 = new ZooLock(accumulo.getConfig().getZooKeepers(), 30000, "digest", "secret".getBytes(), parent);
-
+
TestALW lw3 = new TestALW();
-
+
zl3.lockAsync(lw3, "test3".getBytes());
-
+
List<String> children = zk.getChildren(parent);
Collections.sort(children);
-
+
zk.delete(parent + "/" + children.get(1), -1);
-
+
lw2.waitForChanges(1);
-
+
Assert.assertFalse(lw2.locked);
Assert.assertNotNull(lw2.exception);
Assert.assertNull(lw2.reason);
-
+
zk.delete(parent + "/" + children.get(0), -1);
-
+
lw.waitForChanges(2);
-
+
Assert.assertEquals(LockLossReason.LOCK_DELETED, lw.reason);
Assert.assertNull(lw.exception);
-
+
lw3.waitForChanges(1);
-
+
Assert.assertTrue(lw3.locked);
Assert.assertTrue(zl3.isLocked());
Assert.assertNull(lw3.exception);
Assert.assertNull(lw3.reason);
-
+
zl3.unlock();
-
+
}
-
+
@Test(timeout = 10000)
public void testUnexpectedEvent() throws Exception {
accumulo.getConfig().getZooKeepers();
-
+
String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
-
+
ZooKeeper zk = new ZooKeeper(accumulo.getConfig().getZooKeepers(), 30000, null);
zk.addAuthInfo("digest", "secret".getBytes());
-
+
zk.create(parent, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-
+
ZooLock zl = new ZooLock(accumulo.getConfig().getZooKeepers(), 30000, "digest", "secret".getBytes(), parent);
-
+
Assert.assertFalse(zl.isLocked());
-
+
// would not expect data to be set on this node, but it should not cause problems.....
zk.setData(parent, "foo".getBytes(), -1);
-
+
TestALW lw = new TestALW();
-
+
zl.lockAsync(lw, "test1".getBytes());
-
+
lw.waitForChanges(1);
-
+
Assert.assertTrue(lw.locked);
Assert.assertTrue(zl.isLocked());
Assert.assertNull(lw.exception);
Assert.assertNull(lw.reason);
-
+
// would not expect data to be set on this node either
zk.setData(zl.getLockPath(), "bar".getBytes(), -1);
-
+
zk.delete(zl.getLockPath(), -1);
-
+
lw.waitForChanges(2);
-
+
Assert.assertEquals(LockLossReason.LOCK_DELETED, lw.reason);
Assert.assertNull(lw.exception);
-
+
}
-
+
@Test(timeout = 10000)
public void testTryLock() throws Exception {
String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
-
+
ZooLock zl = new ZooLock(accumulo.getConfig().getZooKeepers(), 1000, "digest", "secret".getBytes(), parent);
-
+
ZooKeeper zk = new ZooKeeper(accumulo.getConfig().getZooKeepers(), 1000, null);
zk.addAuthInfo("digest", "secret".getBytes());
-
+
for (int i = 0; i < 10; i++) {
zk.create(parent, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.delete(parent, -1);
}
-
+
zk.create(parent, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-
+
TestALW lw = new TestALW();
-
+
boolean ret = zl.tryLock(lw, "test1".getBytes());
-
+
Assert.assertTrue(ret);
-
+
// make sure still watching parent even though a lot of events occurred for the parent
synchronized (zl) {
Field field = zl.getClass().getDeclaredField("watchingParent");
field.setAccessible(true);
Assert.assertTrue((Boolean) field.get(zl));
}
-
+
zl.unlock();
}
-
+
@Test(timeout = 10000)
public void testChangeData() throws Exception {
String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
ZooKeeper zk = new ZooKeeper(accumulo.getZooKeepers(), 1000, null);
zk.addAuthInfo("digest", "secret".getBytes());
zk.create(parent, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-
+
ZooLock zl = new ZooLock(accumulo.getZooKeepers(), 1000, "digest", "secret".getBytes(), parent);
-
+
TestALW lw = new TestALW();
-
+
zl.lockAsync(lw, "test1".getBytes());
Assert.assertEquals("test1", new String(zk.getData(zl.getLockPath(), null, null)));
-
+
zl.replaceLockData("test2".getBytes());
Assert.assertEquals("test2", new String(zk.getData(zl.getLockPath(), null, null)));
}
-
+
@AfterClass
public static void tearDownMiniCluster() throws Exception {
accumulo.stop();
folder.delete();
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/AuditMessageTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/AuditMessageTest.java b/test/src/test/java/org/apache/accumulo/test/AuditMessageTest.java
index f4b601f..b9e72dc 100644
--- a/test/src/test/java/org/apache/accumulo/test/AuditMessageTest.java
+++ b/test/src/test/java/org/apache/accumulo/test/AuditMessageTest.java
@@ -65,7 +65,7 @@ import org.junit.rules.TemporaryFolder;
* so we have to find the logs and grep the bits we need out.
*/
public class AuditMessageTest {
-
+
private static MiniAccumuloCluster accumulo;
private static File logDir;
private static List<MiniAccumuloCluster.LogWriter> logWriters;
@@ -76,13 +76,13 @@ public class AuditMessageTest {
private static final String NEW_TEST_TABLE_NAME = "oranges";
private static final String THIRD_TEST_TABLE_NAME = "pears";
private static final Authorizations auths = new Authorizations("private", "public");
- private static TemporaryFolder folder = new TemporaryFolder();
-
+ private static TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+
// Must be static to survive Junit re-initialising the class every time.
private static String lastAuditTimestamp;
private Connector auditConnector;
private Connector conn;
-
+
private static ArrayList<String> findAuditMessage(ArrayList<String> input, String pattern) {
ArrayList<String> result = new ArrayList<String>();
for (String s : input) {
@@ -91,18 +91,18 @@ public class AuditMessageTest {
}
return result;
}
-
+
@BeforeClass
public static void setupMiniCluster() throws Exception {
folder.create();
Logger.getLogger("org.apache.zookeeper").setLevel(Level.ERROR);
-
+
accumulo = new MiniAccumuloCluster(folder.getRoot(), "superSecret");
accumulo.start();
logDir = accumulo.getConfig().getLogDir();
logWriters = accumulo.getLogWriters();
}
-
+
/**
* Returns a List of Audit messages that have been grep'd out of the MiniAccumuloCluster output.
*
@@ -111,14 +111,14 @@ public class AuditMessageTest {
* @return A List of the Audit messages, sorted (so in chronological order).
*/
private ArrayList<String> getAuditMessages(String stepName) throws IOException {
-
+
for (MiniAccumuloCluster.LogWriter lw : logWriters) {
lw.flush();
}
-
+
// Grab the audit messages
System.out.println("Start of captured audit messages for step " + stepName);
-
+
ArrayList<String> result = new ArrayList<String>();
for (File file : logDir.listFiles()) {
// We want to grab the files called .out
@@ -139,17 +139,17 @@ public class AuditMessageTest {
}
}
Collections.sort(result);
-
+
for (String s : result) {
System.out.println(s);
}
System.out.println("End of captured audit messages for step " + stepName);
if (result.size() > 0)
lastAuditTimestamp = (result.get(result.size() - 1)).substring(0, 23);
-
+
return result;
}
-
+
private void grantEverySystemPriv(Connector conn, String user) throws AccumuloSecurityException, AccumuloException {
SystemPermission[] arrayOfP = new SystemPermission[] {SystemPermission.SYSTEM, SystemPermission.ALTER_TABLE, SystemPermission.ALTER_USER,
SystemPermission.CREATE_TABLE, SystemPermission.CREATE_USER, SystemPermission.DROP_TABLE, SystemPermission.DROP_USER};
@@ -157,15 +157,15 @@ public class AuditMessageTest {
conn.securityOperations().grantSystemPermission(user, p);
}
}
-
+
@Before
public void setup() throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException {
conn = accumulo.getConnector("root", "superSecret");
-
+
// I don't want to recreate the instance for every test since it will take ages.
// If we run every test as non-root users, I can drop these users every test which should effectively
// reset the environment.
-
+
if (conn.securityOperations().listLocalUsers().contains(AUDIT_USER_1))
conn.securityOperations().dropLocalUser(AUDIT_USER_1);
if (conn.securityOperations().listLocalUsers().contains(AUDIT_USER_2))
@@ -176,21 +176,21 @@ public class AuditMessageTest {
conn.tableOperations().delete(NEW_TEST_TABLE_NAME);
if (conn.tableOperations().exists(OLD_TEST_TABLE_NAME))
conn.tableOperations().delete(OLD_TEST_TABLE_NAME);
-
+
// This will set the lastAuditTimestamp for the first test
getAuditMessages("setup");
-
+
}
-
+
@Test(timeout = 60 * 1000)
@SuppressWarnings("unchecked")
public void testTableOperationsAudits() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, IOException,
InterruptedException {
-
+
conn.securityOperations().createLocalUser(AUDIT_USER_1, new PasswordToken(PASSWORD));
conn.securityOperations().grantSystemPermission(AUDIT_USER_1, SystemPermission.SYSTEM);
conn.securityOperations().grantSystemPermission(AUDIT_USER_1, SystemPermission.CREATE_TABLE);
-
+
// Connect as Audit User and do a bunch of stuff.
// Testing activity begins here
auditConnector = accumulo.getConnector(AUDIT_USER_1, PASSWORD);
@@ -201,31 +201,31 @@ public class AuditMessageTest {
auditConnector.tableOperations().offline(NEW_TEST_TABLE_NAME);
auditConnector.tableOperations().delete(NEW_TEST_TABLE_NAME);
// Testing activity ends here
-
+
ArrayList<String> auditMessages = getAuditMessages("testTableOperationsAudits");
-
+
assertEquals(1, findAuditMessage(auditMessages, "action: createTable; targetTable: " + OLD_TEST_TABLE_NAME).size());
assertEquals(1, findAuditMessage(auditMessages, "action: renameTable; targetTable: " + OLD_TEST_TABLE_NAME).size());
assertEquals(1, findAuditMessage(auditMessages, "action: cloneTable; targetTable: " + NEW_TEST_TABLE_NAME).size());
assertEquals(1, findAuditMessage(auditMessages, "action: deleteTable; targetTable: " + OLD_TEST_TABLE_NAME).size());
assertEquals(1, findAuditMessage(auditMessages, "action: offlineTable; targetTable: " + NEW_TEST_TABLE_NAME).size());
assertEquals(1, findAuditMessage(auditMessages, "action: deleteTable; targetTable: " + NEW_TEST_TABLE_NAME).size());
-
+
}
-
+
@Test(timeout = 60 * 1000)
public void testUserOperationsAudits() throws AccumuloSecurityException, AccumuloException, TableExistsException, InterruptedException, IOException {
-
+
conn.securityOperations().createLocalUser(AUDIT_USER_1, new PasswordToken(PASSWORD));
conn.securityOperations().grantSystemPermission(AUDIT_USER_1, SystemPermission.SYSTEM);
conn.securityOperations().grantSystemPermission(AUDIT_USER_1, SystemPermission.CREATE_USER);
grantEverySystemPriv(conn, AUDIT_USER_1);
-
+
// Connect as Audit User and do a bunch of stuff.
// Start testing activities here
auditConnector = accumulo.getConnector(AUDIT_USER_1, PASSWORD);
auditConnector.securityOperations().createLocalUser(AUDIT_USER_2, new PasswordToken(PASSWORD));
-
+
// It seems only root can grant stuff.
conn.securityOperations().grantSystemPermission(AUDIT_USER_2, SystemPermission.ALTER_TABLE);
conn.securityOperations().revokeSystemPermission(AUDIT_USER_2, SystemPermission.ALTER_TABLE);
@@ -236,9 +236,9 @@ public class AuditMessageTest {
auditConnector.securityOperations().changeUserAuthorizations(AUDIT_USER_2, auths);
auditConnector.securityOperations().dropLocalUser(AUDIT_USER_2);
// Stop testing activities here
-
+
ArrayList<String> auditMessages = getAuditMessages("testUserOperationsAudits");
-
+
assertEquals(1, findAuditMessage(auditMessages, "action: createUser; targetUser: " + AUDIT_USER_2).size());
assertEquals(
1,
@@ -261,21 +261,21 @@ public class AuditMessageTest {
.size());
assertEquals(1, findAuditMessage(auditMessages, "action: dropUser; targetUser: " + AUDIT_USER_2).size());
}
-
+
@Test(timeout = 60 * 1000)
public void testImportExportOperationsAudits() throws AccumuloSecurityException, AccumuloException, TableExistsException, TableNotFoundException,
IOException, InterruptedException {
-
+
conn.securityOperations().createLocalUser(AUDIT_USER_1, new PasswordToken(PASSWORD));
conn.securityOperations().grantSystemPermission(AUDIT_USER_1, SystemPermission.SYSTEM);
conn.securityOperations().changeUserAuthorizations(AUDIT_USER_1, auths);
grantEverySystemPriv(conn, AUDIT_USER_1);
-
+
// Connect as Audit User and do a bunch of stuff.
// Start testing activities here
auditConnector = accumulo.getConnector(AUDIT_USER_1, PASSWORD);
auditConnector.tableOperations().create(OLD_TEST_TABLE_NAME);
-
+
// Insert some play data
BatchWriter bw = auditConnector.createBatchWriter(OLD_TEST_TABLE_NAME, new BatchWriterConfig());
Mutation m = new Mutation("myRow");
@@ -283,18 +283,18 @@ public class AuditMessageTest {
m.put("cf1", "cq2", "v3");
bw.addMutation(m);
bw.close();
-
+
// Prepare to export the table
File exportDir = new File(accumulo.getConfig().getDir().toString() + "/export");
-
+
auditConnector.tableOperations().offline(OLD_TEST_TABLE_NAME);
auditConnector.tableOperations().exportTable(OLD_TEST_TABLE_NAME, exportDir.toString());
-
+
// We've exported the table metadata to the MiniAccumuloCluster root dir. Grab the .rf file path to re-import it
File distCpTxt = new File(exportDir.toString() + "/distcp.txt");
File importFile = null;
LineIterator it = FileUtils.lineIterator(distCpTxt, Constants.UTF8.name());
-
+
// Just grab the first rf file, it will do for now.
String filePrefix = "file:";
try {
@@ -309,18 +309,18 @@ public class AuditMessageTest {
}
FileUtils.copyFileToDirectory(importFile, exportDir);
auditConnector.tableOperations().importTable(NEW_TEST_TABLE_NAME, exportDir.toString());
-
+
// Now do a Directory (bulk) import of the same data.
auditConnector.tableOperations().create(THIRD_TEST_TABLE_NAME);
File failDir = new File(exportDir + "/tmp");
failDir.mkdirs();
auditConnector.tableOperations().importDirectory(THIRD_TEST_TABLE_NAME, exportDir.toString(), failDir.toString(), false);
auditConnector.tableOperations().online(OLD_TEST_TABLE_NAME);
-
+
// Stop testing activities here
-
+
ArrayList<String> auditMessages = getAuditMessages("testImportExportOperationsAudits");
-
+
assertEquals(1, findAuditMessage(auditMessages, String.format(AuditedSecurityOperation.CAN_CREATE_TABLE_AUDIT_TEMPLATE, OLD_TEST_TABLE_NAME)).size());
assertEquals(1,
findAuditMessage(auditMessages, String.format(AuditedSecurityOperation.CAN_ONLINE_OFFLINE_TABLE_AUDIT_TEMPLATE, "offlineTable", OLD_TEST_TABLE_NAME))
@@ -339,23 +339,23 @@ public class AuditMessageTest {
assertEquals(1,
findAuditMessage(auditMessages, String.format(AuditedSecurityOperation.CAN_ONLINE_OFFLINE_TABLE_AUDIT_TEMPLATE, "onlineTable", OLD_TEST_TABLE_NAME))
.size());
-
+
}
-
+
@Test(timeout = 60 * 1000)
public void testDataOperationsAudits() throws AccumuloSecurityException, AccumuloException, TableExistsException, TableNotFoundException, IOException,
InterruptedException {
-
+
conn.securityOperations().createLocalUser(AUDIT_USER_1, new PasswordToken(PASSWORD));
conn.securityOperations().grantSystemPermission(AUDIT_USER_1, SystemPermission.SYSTEM);
conn.securityOperations().changeUserAuthorizations(AUDIT_USER_1, auths);
grantEverySystemPriv(conn, AUDIT_USER_1);
-
+
// Connect as Audit User and do a bunch of stuff.
// Start testing activities here
auditConnector = accumulo.getConnector(AUDIT_USER_1, PASSWORD);
auditConnector.tableOperations().create(OLD_TEST_TABLE_NAME);
-
+
// Insert some play data
BatchWriter bw = auditConnector.createBatchWriter(OLD_TEST_TABLE_NAME, new BatchWriterConfig());
Mutation m = new Mutation("myRow");
@@ -363,7 +363,7 @@ public class AuditMessageTest {
m.put("cf1", "cq2", "v3");
bw.addMutation(m);
bw.close();
-
+
// Start testing activities here
// A regular scan
Scanner scanner = auditConnector.createScanner(OLD_TEST_TABLE_NAME, auths);
@@ -371,43 +371,43 @@ public class AuditMessageTest {
System.out.println("Scanner row: " + entry.getKey() + " " + entry.getValue());
}
scanner.close();
-
+
// A batch scan
BatchScanner bs = auditConnector.createBatchScanner(OLD_TEST_TABLE_NAME, auths, 1);
bs.fetchColumn(new Text("cf1"), new Text("cq1"));
bs.setRanges(Arrays.asList(new Range("myRow", "myRow~")));
-
+
for (Map.Entry<Key,Value> entry : bs) {
System.out.println("BatchScanner row: " + entry.getKey() + " " + entry.getValue());
}
bs.close();
-
+
// Delete some data.
auditConnector.tableOperations().deleteRows(OLD_TEST_TABLE_NAME, new Text("myRow"), new Text("myRow~"));
-
+
// End of testing activities
-
+
ArrayList<String> auditMessages = getAuditMessages("testDataOperationsAudits");
assertTrue(1 <= findAuditMessage(auditMessages, "action: scan; targetTable: " + OLD_TEST_TABLE_NAME).size());
assertTrue(1 <= findAuditMessage(auditMessages, "action: scan; targetTable: " + OLD_TEST_TABLE_NAME).size());
assertEquals(1,
findAuditMessage(auditMessages, String.format(AuditedSecurityOperation.CAN_DELETE_RANGE_AUDIT_TEMPLATE, OLD_TEST_TABLE_NAME, "myRow", "myRow~")).size());
-
+
}
-
+
@Test(timeout = 60 * 1000)
public void testDeniedAudits() throws AccumuloSecurityException, AccumuloException, TableExistsException, TableNotFoundException, IOException,
InterruptedException {
-
+
// Create our user with no privs
conn.securityOperations().createLocalUser(AUDIT_USER_1, new PasswordToken(PASSWORD));
conn.tableOperations().create(OLD_TEST_TABLE_NAME);
auditConnector = accumulo.getConnector(AUDIT_USER_1, PASSWORD);
-
+
// Start testing activities
// We should get denied or / failed audit messages here.
// We don't want the thrown exceptions to stop our tests, and we are not testing that the Exceptions are thrown.
-
+
try {
auditConnector.tableOperations().create(NEW_TEST_TABLE_NAME);
} catch (AccumuloSecurityException ex) {}
@@ -431,10 +431,10 @@ public class AuditMessageTest {
try {
auditConnector.tableOperations().deleteRows(OLD_TEST_TABLE_NAME, new Text("myRow"), new Text("myRow~"));
} catch (AccumuloSecurityException ex) {}
-
+
// ... that will do for now.
// End of testing activities
-
+
ArrayList<String> auditMessages = getAuditMessages("testDeniedAudits");
assertEquals(1,
findAuditMessage(auditMessages, "operation: denied;.*" + String.format(AuditedSecurityOperation.CAN_CREATE_TABLE_AUDIT_TEMPLATE, NEW_TEST_TABLE_NAME))
@@ -461,11 +461,11 @@ public class AuditMessageTest {
findAuditMessage(auditMessages,
"operation: denied;.*" + String.format(AuditedSecurityOperation.CAN_DELETE_RANGE_AUDIT_TEMPLATE, OLD_TEST_TABLE_NAME, "myRow", "myRow~")).size());
}
-
+
@Test(timeout = 60 * 1000)
public void testFailedAudits() throws AccumuloSecurityException, AccumuloException, TableExistsException, TableNotFoundException, IOException,
InterruptedException {
-
+
// Start testing activities
// Test that we get a few "failed" audit messages come through when we tell it to do dumb stuff
// We don't want the thrown exceptions to stop our tests, and we are not testing that the Exceptions are thrown.
@@ -481,20 +481,20 @@ public class AuditMessageTest {
ArrayList<String> auditMessages = getAuditMessages("testFailedAudits");
// ... that will do for now.
// End of testing activities
-
+
assertEquals(1, findAuditMessage(auditMessages, String.format(AuditedSecurityOperation.DROP_USER_AUDIT_TEMPLATE, AUDIT_USER_2)).size());
assertEquals(
1,
findAuditMessage(auditMessages,
String.format(AuditedSecurityOperation.REVOKE_SYSTEM_PERMISSION_AUDIT_TEMPLATE, SystemPermission.ALTER_TABLE, AUDIT_USER_2)).size());
assertEquals(1, findAuditMessage(auditMessages, String.format(AuditedSecurityOperation.CREATE_USER_AUDIT_TEMPLATE, "root", "")).size());
-
+
}
-
+
@AfterClass
public static void tearDownMiniCluster() throws Exception {
accumulo.stop();
-
+
// Comment this out to have a look at the logs, they will be in /tmp/junit*
folder.delete();
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/BatchWriterIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/BatchWriterIT.java b/test/src/test/java/org/apache/accumulo/test/BatchWriterIT.java
index a126a9d..e467f36 100644
--- a/test/src/test/java/org/apache/accumulo/test/BatchWriterIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/BatchWriterIT.java
@@ -21,15 +21,15 @@ import org.apache.accumulo.core.client.BatchWriterConfig;
import org.apache.accumulo.core.client.Connector;
import org.apache.accumulo.core.data.Mutation;
import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.test.functional.ConfigurableMacIT;
+import org.apache.accumulo.test.functional.SimpleMacIT;
import org.junit.Test;
-public class BatchWriterIT extends ConfigurableMacIT {
-
- @Test(timeout=30*1000)
+public class BatchWriterIT extends SimpleMacIT {
+
+ @Test(timeout = 30 * 1000)
public void test() throws Exception {
// call the batchwriter with buffer of size zero
- String table = makeTableName();
+ String table = getTableNames(1)[0];
Connector c = getConnector();
c.tableOperations().create(table);
BatchWriterConfig config = new BatchWriterConfig();
@@ -41,4 +41,4 @@ public class BatchWriterIT extends ConfigurableMacIT {
writer.close();
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/ConditionalWriterTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/ConditionalWriterTest.java b/test/src/test/java/org/apache/accumulo/test/ConditionalWriterTest.java
index 70f115b..39e0481 100644
--- a/test/src/test/java/org/apache/accumulo/test/ConditionalWriterTest.java
+++ b/test/src/test/java/org/apache/accumulo/test/ConditionalWriterTest.java
@@ -17,6 +17,7 @@
package org.apache.accumulo.test;
+import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -84,11 +85,11 @@ import org.junit.rules.TemporaryFolder;
*
*/
public class ConditionalWriterTest {
-
+
private static String secret = "superSecret";
- public static TemporaryFolder folder = new TemporaryFolder();
+ public static TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
public static MiniAccumuloCluster cluster;
-
+
@BeforeClass
public static void setUpBeforeClass() throws Exception {
folder.create();
@@ -96,17 +97,17 @@ public class ConditionalWriterTest {
cluster = new MiniAccumuloCluster(cfg);
cluster.start();
}
-
+
@Test
public void testBasic() throws Exception {
-
+
ZooKeeperInstance zki = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
Connector conn = zki.getConnector("root", new PasswordToken(secret));
-
+
conn.tableOperations().create("foo");
-
+
ConditionalWriter cw = conn.createConditionalWriter("foo", new ConditionalWriterConfig());
-
+
// mutation conditional on column tx:seq not exiting
ConditionalMutation cm0 = new ConditionalMutation("99006", new Condition("tx", "seq"));
cm0.put("name", "last", "doe");
@@ -114,92 +115,92 @@ public class ConditionalWriterTest {
cm0.put("tx", "seq", "1");
Assert.assertEquals(Status.ACCEPTED, cw.write(cm0).getStatus());
Assert.assertEquals(Status.REJECTED, cw.write(cm0).getStatus());
-
+
// mutation conditional on column tx:seq being 1
ConditionalMutation cm1 = new ConditionalMutation("99006", new Condition("tx", "seq").setValue("1"));
cm1.put("name", "last", "Doe");
cm1.put("tx", "seq", "2");
Assert.assertEquals(Status.ACCEPTED, cw.write(cm1).getStatus());
-
+
// test condition where value differs
ConditionalMutation cm2 = new ConditionalMutation("99006", new Condition("tx", "seq").setValue("1"));
cm2.put("name", "last", "DOE");
cm2.put("tx", "seq", "2");
Assert.assertEquals(Status.REJECTED, cw.write(cm2).getStatus());
-
+
// test condition where column does not exists
ConditionalMutation cm3 = new ConditionalMutation("99006", new Condition("txtypo", "seq").setValue("1"));
cm3.put("name", "last", "deo");
cm3.put("tx", "seq", "2");
Assert.assertEquals(Status.REJECTED, cw.write(cm3).getStatus());
-
+
// test two conditions, where one should fail
ConditionalMutation cm4 = new ConditionalMutation("99006", new Condition("tx", "seq").setValue("2"), new Condition("name", "last").setValue("doe"));
cm4.put("name", "last", "deo");
cm4.put("tx", "seq", "3");
Assert.assertEquals(Status.REJECTED, cw.write(cm4).getStatus());
-
+
// test two conditions, where one should fail
ConditionalMutation cm5 = new ConditionalMutation("99006", new Condition("tx", "seq").setValue("1"), new Condition("name", "last").setValue("Doe"));
cm5.put("name", "last", "deo");
cm5.put("tx", "seq", "3");
Assert.assertEquals(Status.REJECTED, cw.write(cm5).getStatus());
-
+
// ensure rejected mutations did not write
Scanner scanner = conn.createScanner("foo", Authorizations.EMPTY);
scanner.fetchColumn(new Text("name"), new Text("last"));
scanner.setRange(new Range("99006"));
Assert.assertEquals("Doe", scanner.iterator().next().getValue().toString());
-
+
// test w/ two conditions that are met
ConditionalMutation cm6 = new ConditionalMutation("99006", new Condition("tx", "seq").setValue("2"), new Condition("name", "last").setValue("Doe"));
cm6.put("name", "last", "DOE");
cm6.put("tx", "seq", "3");
Assert.assertEquals(Status.ACCEPTED, cw.write(cm6).getStatus());
-
+
Assert.assertEquals("DOE", scanner.iterator().next().getValue().toString());
-
+
// test a conditional mutation that deletes
ConditionalMutation cm7 = new ConditionalMutation("99006", new Condition("tx", "seq").setValue("3"));
cm7.putDelete("name", "last");
cm7.putDelete("name", "first");
cm7.putDelete("tx", "seq");
Assert.assertEquals(Status.ACCEPTED, cw.write(cm7).getStatus());
-
+
Assert.assertFalse(scanner.iterator().hasNext());
-
+
// add the row back
Assert.assertEquals(Status.ACCEPTED, cw.write(cm0).getStatus());
Assert.assertEquals(Status.REJECTED, cw.write(cm0).getStatus());
-
+
Assert.assertEquals("doe", scanner.iterator().next().getValue().toString());
zki.close();
}
-
+
@Test
public void testFields() throws Exception {
String table = "foo2";
-
+
ZooKeeperInstance zki = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
Connector conn = zki.getConnector("root", new PasswordToken(secret));
-
+
conn.tableOperations().create(table);
-
+
Authorizations auths = new Authorizations("A", "B");
-
+
conn.securityOperations().changeUserAuthorizations("root", auths);
-
+
ConditionalWriter cw = conn.createConditionalWriter(table, new ConditionalWriterConfig().setAuthorizations(auths));
-
+
ColumnVisibility cva = new ColumnVisibility("A");
ColumnVisibility cvb = new ColumnVisibility("B");
-
+
ConditionalMutation cm0 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva));
cm0.put("name", "last", cva, "doe");
cm0.put("name", "first", cva, "john");
cm0.put("tx", "seq", cva, "1");
Assert.assertEquals(Status.ACCEPTED, cw.write(cm0).getStatus());
-
+
Scanner scanner = conn.createScanner(table, auths);
scanner.setRange(new Range("99006"));
// TODO verify all columns
@@ -207,325 +208,325 @@ public class ConditionalWriterTest {
Entry<Key,Value> entry = scanner.iterator().next();
Assert.assertEquals("1", entry.getValue().toString());
long ts = entry.getKey().getTimestamp();
-
+
// test wrong colf
ConditionalMutation cm1 = new ConditionalMutation("99006", new Condition("txA", "seq").setVisibility(cva).setValue("1"));
cm1.put("name", "last", cva, "Doe");
cm1.put("name", "first", cva, "John");
cm1.put("tx", "seq", cva, "2");
Assert.assertEquals(Status.REJECTED, cw.write(cm1).getStatus());
-
+
// test wrong colq
ConditionalMutation cm2 = new ConditionalMutation("99006", new Condition("tx", "seqA").setVisibility(cva).setValue("1"));
cm2.put("name", "last", cva, "Doe");
cm2.put("name", "first", cva, "John");
cm2.put("tx", "seq", cva, "2");
Assert.assertEquals(Status.REJECTED, cw.write(cm2).getStatus());
-
+
// test wrong colv
ConditionalMutation cm3 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvb).setValue("1"));
cm3.put("name", "last", cva, "Doe");
cm3.put("name", "first", cva, "John");
cm3.put("tx", "seq", cva, "2");
Assert.assertEquals(Status.REJECTED, cw.write(cm3).getStatus());
-
+
// test wrong timestamp
ConditionalMutation cm4 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva).setTimestamp(ts + 1).setValue("1"));
cm4.put("name", "last", cva, "Doe");
cm4.put("name", "first", cva, "John");
cm4.put("tx", "seq", cva, "2");
Assert.assertEquals(Status.REJECTED, cw.write(cm4).getStatus());
-
+
// test wrong timestamp
ConditionalMutation cm5 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva).setTimestamp(ts - 1).setValue("1"));
cm5.put("name", "last", cva, "Doe");
cm5.put("name", "first", cva, "John");
cm5.put("tx", "seq", cva, "2");
Assert.assertEquals(Status.REJECTED, cw.write(cm5).getStatus());
-
+
// ensure no updates were made
entry = scanner.iterator().next();
Assert.assertEquals("1", entry.getValue().toString());
-
+
// set all columns correctly
ConditionalMutation cm6 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva).setTimestamp(ts).setValue("1"));
cm6.put("name", "last", cva, "Doe");
cm6.put("name", "first", cva, "John");
cm6.put("tx", "seq", cva, "2");
Assert.assertEquals(Status.ACCEPTED, cw.write(cm6).getStatus());
-
+
entry = scanner.iterator().next();
Assert.assertEquals("2", entry.getValue().toString());
-
+
// TODO test each field w/ absence
zki.close();
-
+
}
-
+
@Test
public void testBadColVis() throws Exception {
// test when a user sets a col vis in a condition that can never be seen
String table = "foo3";
-
+
ZooKeeperInstance zki = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
Connector conn = zki.getConnector("root", new PasswordToken(secret));
-
+
conn.tableOperations().create(table);
-
+
Authorizations auths = new Authorizations("A", "B");
-
+
conn.securityOperations().changeUserAuthorizations("root", auths);
-
+
Authorizations filteredAuths = new Authorizations("A");
-
+
ConditionalWriter cw = conn.createConditionalWriter(table, new ConditionalWriterConfig().setAuthorizations(filteredAuths));
-
+
ColumnVisibility cva = new ColumnVisibility("A");
ColumnVisibility cvb = new ColumnVisibility("B");
ColumnVisibility cvc = new ColumnVisibility("C");
-
+
// User has authorization, but didn't include it in the writer
ConditionalMutation cm0 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvb));
cm0.put("name", "last", cva, "doe");
cm0.put("name", "first", cva, "john");
cm0.put("tx", "seq", cva, "1");
Assert.assertEquals(Status.INVISIBLE_VISIBILITY, cw.write(cm0).getStatus());
-
+
ConditionalMutation cm1 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvb).setValue("1"));
cm1.put("name", "last", cva, "doe");
cm1.put("name", "first", cva, "john");
cm1.put("tx", "seq", cva, "1");
Assert.assertEquals(Status.INVISIBLE_VISIBILITY, cw.write(cm1).getStatus());
-
+
// User does not have the authorization
ConditionalMutation cm2 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvc));
cm2.put("name", "last", cva, "doe");
cm2.put("name", "first", cva, "john");
cm2.put("tx", "seq", cva, "1");
Assert.assertEquals(Status.INVISIBLE_VISIBILITY, cw.write(cm2).getStatus());
-
+
ConditionalMutation cm3 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvc).setValue("1"));
cm3.put("name", "last", cva, "doe");
cm3.put("name", "first", cva, "john");
cm3.put("tx", "seq", cva, "1");
Assert.assertEquals(Status.INVISIBLE_VISIBILITY, cw.write(cm3).getStatus());
-
+
// if any visibility is bad, good visibilities don't override
ConditionalMutation cm4 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvb), new Condition("tx", "seq").setVisibility(cva));
-
+
cm4.put("name", "last", cva, "doe");
cm4.put("name", "first", cva, "john");
cm4.put("tx", "seq", cva, "1");
Assert.assertEquals(Status.INVISIBLE_VISIBILITY, cw.write(cm4).getStatus());
-
+
ConditionalMutation cm5 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvb).setValue("1"), new Condition("tx", "seq")
.setVisibility(cva).setValue("1"));
cm5.put("name", "last", cva, "doe");
cm5.put("name", "first", cva, "john");
cm5.put("tx", "seq", cva, "1");
Assert.assertEquals(Status.INVISIBLE_VISIBILITY, cw.write(cm5).getStatus());
-
+
ConditionalMutation cm6 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvb).setValue("1"),
new Condition("tx", "seq").setVisibility(cva));
cm6.put("name", "last", cva, "doe");
cm6.put("name", "first", cva, "john");
cm6.put("tx", "seq", cva, "1");
Assert.assertEquals(Status.INVISIBLE_VISIBILITY, cw.write(cm6).getStatus());
-
+
ConditionalMutation cm7 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvb), new Condition("tx", "seq").setVisibility(cva)
.setValue("1"));
cm7.put("name", "last", cva, "doe");
cm7.put("name", "first", cva, "john");
cm7.put("tx", "seq", cva, "1");
Assert.assertEquals(Status.INVISIBLE_VISIBILITY, cw.write(cm7).getStatus());
-
+
cw.close();
-
+
// test passing auths that exceed users configured auths
-
+
Authorizations exceedingAuths = new Authorizations("A", "B", "D");
ConditionalWriter cw2 = conn.createConditionalWriter(table, new ConditionalWriterConfig().setAuthorizations(exceedingAuths));
-
+
ConditionalMutation cm8 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvb), new Condition("tx", "seq").setVisibility(cva)
.setValue("1"));
cm8.put("name", "last", cva, "doe");
cm8.put("name", "first", cva, "john");
cm8.put("tx", "seq", cva, "1");
-
+
try {
cw2.write(cm8).getStatus();
Assert.fail();
} catch (AccumuloSecurityException ase) {}
-
+
cw2.close();
-
+
zki.close();
}
-
+
@Test
public void testConstraints() throws Exception {
// ensure constraint violations are properly reported
String table = "foo5";
-
+
ZooKeeperInstance zki = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
Connector conn = zki.getConnector("root", new PasswordToken(secret));
-
+
conn.tableOperations().create(table);
conn.tableOperations().addConstraint(table, AlphaNumKeyConstraint.class.getName());
conn.tableOperations().clone(table, table + "_clone", true, new HashMap<String,String>(), new HashSet<String>());
-
+
Scanner scanner = conn.createScanner(table + "_clone", new Authorizations());
-
+
ConditionalWriter cw = conn.createConditionalWriter(table + "_clone", new ConditionalWriterConfig());
-
+
ConditionalMutation cm0 = new ConditionalMutation("99006+", new Condition("tx", "seq"));
cm0.put("tx", "seq", "1");
-
+
Assert.assertEquals(Status.VIOLATED, cw.write(cm0).getStatus());
Assert.assertFalse(scanner.iterator().hasNext());
-
+
ConditionalMutation cm1 = new ConditionalMutation("99006", new Condition("tx", "seq"));
cm1.put("tx", "seq", "1");
-
+
Assert.assertEquals(Status.ACCEPTED, cw.write(cm1).getStatus());
Assert.assertTrue(scanner.iterator().hasNext());
-
+
cw.close();
zki.close();
-
+
}
-
+
@Test
public void testIterators() throws Exception {
String table = "foo4";
-
+
ZooKeeperInstance zki = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
Connector conn = zki.getConnector("root", new PasswordToken(secret));
-
+
conn.tableOperations().create(table, false);
-
+
BatchWriter bw = conn.createBatchWriter(table, new BatchWriterConfig());
-
+
Mutation m = new Mutation("ACCUMULO-1000");
m.put("count", "comments", "1");
bw.addMutation(m);
bw.addMutation(m);
bw.addMutation(m);
-
+
m = new Mutation("ACCUMULO-1001");
m.put("count2", "comments", "1");
bw.addMutation(m);
bw.addMutation(m);
-
+
m = new Mutation("ACCUMULO-1002");
m.put("count2", "comments", "1");
bw.addMutation(m);
bw.addMutation(m);
-
+
bw.close();
-
+
IteratorSetting iterConfig = new IteratorSetting(10, SummingCombiner.class);
SummingCombiner.setEncodingType(iterConfig, Type.STRING);
SummingCombiner.setColumns(iterConfig, Collections.singletonList(new IteratorSetting.Column("count")));
-
+
IteratorSetting iterConfig2 = new IteratorSetting(10, SummingCombiner.class);
SummingCombiner.setEncodingType(iterConfig2, Type.STRING);
SummingCombiner.setColumns(iterConfig2, Collections.singletonList(new IteratorSetting.Column("count2", "comments")));
-
+
IteratorSetting iterConfig3 = new IteratorSetting(5, VersioningIterator.class);
VersioningIterator.setMaxVersions(iterConfig3, 1);
-
+
Scanner scanner = conn.createScanner(table, new Authorizations());
scanner.addScanIterator(iterConfig);
scanner.setRange(new Range("ACCUMULO-1000"));
scanner.fetchColumn(new Text("count"), new Text("comments"));
-
+
Assert.assertEquals("3", scanner.iterator().next().getValue().toString());
-
+
ConditionalWriter cw = conn.createConditionalWriter(table, new ConditionalWriterConfig());
-
+
ConditionalMutation cm0 = new ConditionalMutation("ACCUMULO-1000", new Condition("count", "comments").setValue("3"));
cm0.put("count", "comments", "1");
Assert.assertEquals(Status.REJECTED, cw.write(cm0).getStatus());
Assert.assertEquals("3", scanner.iterator().next().getValue().toString());
-
+
ConditionalMutation cm1 = new ConditionalMutation("ACCUMULO-1000", new Condition("count", "comments").setIterators(iterConfig).setValue("3"));
cm1.put("count", "comments", "1");
Assert.assertEquals(Status.ACCEPTED, cw.write(cm1).getStatus());
Assert.assertEquals("4", scanner.iterator().next().getValue().toString());
-
+
ConditionalMutation cm2 = new ConditionalMutation("ACCUMULO-1000", new Condition("count", "comments").setValue("4"));
cm2.put("count", "comments", "1");
Assert.assertEquals(Status.REJECTED, cw.write(cm1).getStatus());
Assert.assertEquals("4", scanner.iterator().next().getValue().toString());
-
+
// run test with multiple iterators passed in same batch and condition with two iterators
-
+
ConditionalMutation cm3 = new ConditionalMutation("ACCUMULO-1000", new Condition("count", "comments").setIterators(iterConfig).setValue("4"));
cm3.put("count", "comments", "1");
-
+
ConditionalMutation cm4 = new ConditionalMutation("ACCUMULO-1001", new Condition("count2", "comments").setIterators(iterConfig2).setValue("2"));
cm4.put("count2", "comments", "1");
-
+
ConditionalMutation cm5 = new ConditionalMutation("ACCUMULO-1002", new Condition("count2", "comments").setIterators(iterConfig2, iterConfig3).setValue("2"));
cm5.put("count2", "comments", "1");
-
+
Iterator<Result> results = cw.write(Arrays.asList(cm3, cm4, cm5).iterator());
Map<String,Status> actual = new HashMap<String,Status>();
-
+
while (results.hasNext()) {
Result result = results.next();
String k = new String(result.getMutation().getRow());
Assert.assertFalse(actual.containsKey(k));
actual.put(k, result.getStatus());
}
-
+
Map<String,Status> expected = new HashMap<String,Status>();
expected.put("ACCUMULO-1000", Status.ACCEPTED);
expected.put("ACCUMULO-1001", Status.ACCEPTED);
expected.put("ACCUMULO-1002", Status.REJECTED);
-
+
Assert.assertEquals(expected, actual);
-
+
// TODO test w/ table that has iterators configured
-
+
cw.close();
zki.close();
}
-
+
@Test
public void testBatch() throws Exception {
String table = "foo6";
-
+
ZooKeeperInstance zki = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
Connector conn = zki.getConnector("root", new PasswordToken(secret));
-
+
conn.tableOperations().create(table);
-
+
conn.securityOperations().changeUserAuthorizations("root", new Authorizations("A", "B"));
-
+
ColumnVisibility cvab = new ColumnVisibility("A|B");
-
+
ArrayList<ConditionalMutation> mutations = new ArrayList<ConditionalMutation>();
-
+
ConditionalMutation cm0 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvab));
cm0.put("name", "last", cvab, "doe");
cm0.put("name", "first", cvab, "john");
cm0.put("tx", "seq", cvab, "1");
mutations.add(cm0);
-
+
ConditionalMutation cm1 = new ConditionalMutation("59056", new Condition("tx", "seq").setVisibility(cvab));
cm1.put("name", "last", cvab, "doe");
cm1.put("name", "first", cvab, "jane");
cm1.put("tx", "seq", cvab, "1");
mutations.add(cm1);
-
+
ConditionalMutation cm2 = new ConditionalMutation("19059", new Condition("tx", "seq").setVisibility(cvab));
cm2.put("name", "last", cvab, "doe");
cm2.put("name", "first", cvab, "jack");
cm2.put("tx", "seq", cvab, "1");
mutations.add(cm2);
-
+
ConditionalWriter cw = conn.createConditionalWriter(table, new ConditionalWriterConfig().setAuthorizations(new Authorizations("A")));
Iterator<Result> results = cw.write(mutations.iterator());
int count = 0;
@@ -534,39 +535,39 @@ public class ConditionalWriterTest {
Assert.assertEquals(Status.ACCEPTED, result.getStatus());
count++;
}
-
+
Assert.assertEquals(3, count);
-
+
Scanner scanner = conn.createScanner(table, new Authorizations("A"));
scanner.fetchColumn(new Text("tx"), new Text("seq"));
-
+
for (String row : new String[] {"99006", "59056", "19059"}) {
scanner.setRange(new Range(row));
Assert.assertEquals("1", scanner.iterator().next().getValue().toString());
}
-
+
TreeSet<Text> splits = new TreeSet<Text>();
splits.add(new Text("7"));
splits.add(new Text("3"));
conn.tableOperations().addSplits(table, splits);
-
+
mutations.clear();
-
+
ConditionalMutation cm3 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvab).setValue("1"));
cm3.put("name", "last", cvab, "Doe");
cm3.put("tx", "seq", cvab, "2");
mutations.add(cm3);
-
+
ConditionalMutation cm4 = new ConditionalMutation("59056", new Condition("tx", "seq").setVisibility(cvab));
cm4.put("name", "last", cvab, "Doe");
cm4.put("tx", "seq", cvab, "1");
mutations.add(cm4);
-
+
ConditionalMutation cm5 = new ConditionalMutation("19059", new Condition("tx", "seq").setVisibility(cvab).setValue("2"));
cm5.put("name", "last", cvab, "Doe");
cm5.put("tx", "seq", cvab, "3");
mutations.add(cm5);
-
+
results = cw.write(mutations.iterator());
int accepted = 0;
int rejected = 0;
@@ -580,119 +581,119 @@ public class ConditionalWriterTest {
rejected++;
}
}
-
+
Assert.assertEquals(1, accepted);
Assert.assertEquals(2, rejected);
-
+
for (String row : new String[] {"59056", "19059"}) {
scanner.setRange(new Range(row));
Assert.assertEquals("1", scanner.iterator().next().getValue().toString());
}
-
+
scanner.setRange(new Range("99006"));
Assert.assertEquals("2", scanner.iterator().next().getValue().toString());
-
+
scanner.clearColumns();
scanner.fetchColumn(new Text("name"), new Text("last"));
Assert.assertEquals("Doe", scanner.iterator().next().getValue().toString());
-
+
cw.close();
zki.close();
}
-
+
@Test
public void testBigBatch() throws Exception {
-
+
String table = "foo100";
-
+
ZooKeeperInstance zki = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
Connector conn = zki.getConnector("root", new PasswordToken(secret));
-
+
conn.tableOperations().create(table);
conn.tableOperations().addSplits(table, nss("2", "4", "6"));
-
+
UtilWaitThread.sleep(2000);
-
+
int num = 100;
-
+
ArrayList<byte[]> rows = new ArrayList<byte[]>(num);
ArrayList<ConditionalMutation> cml = new ArrayList<ConditionalMutation>(num);
-
+
Random r = new Random();
byte[] e = new byte[0];
-
+
for (int i = 0; i < num; i++) {
rows.add(FastFormat.toZeroPaddedString(Math.abs(r.nextLong()), 16, 16, e));
}
-
+
for (int i = 0; i < num; i++) {
ConditionalMutation cm = new ConditionalMutation(rows.get(i), new Condition("meta", "seq"));
-
+
cm.put("meta", "seq", "1");
cm.put("meta", "tx", UUID.randomUUID().toString());
-
+
cml.add(cm);
}
-
+
ConditionalWriter cw = conn.createConditionalWriter(table, new ConditionalWriterConfig());
-
+
Iterator<Result> results = cw.write(cml.iterator());
-
+
int count = 0;
-
+
// TODO check got each row back
while (results.hasNext()) {
Result result = results.next();
Assert.assertEquals(Status.ACCEPTED, result.getStatus());
count++;
}
-
+
Assert.assertEquals(num, count);
-
+
ArrayList<ConditionalMutation> cml2 = new ArrayList<ConditionalMutation>(num);
-
+
for (int i = 0; i < num; i++) {
ConditionalMutation cm = new ConditionalMutation(rows.get(i), new Condition("meta", "seq").setValue("1"));
-
+
cm.put("meta", "seq", "2");
cm.put("meta", "tx", UUID.randomUUID().toString());
-
+
cml2.add(cm);
}
-
+
count = 0;
-
+
results = cw.write(cml2.iterator());
-
+
while (results.hasNext()) {
Result result = results.next();
Assert.assertEquals(Status.ACCEPTED, result.getStatus());
count++;
}
-
+
Assert.assertEquals(num, count);
-
+
cw.close();
zki.close();
}
-
+
@Test
public void testBatchErrors() throws Exception {
-
+
String table = "foo7";
-
+
ZooKeeperInstance zki = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
Connector conn = zki.getConnector("root", new PasswordToken(secret));
-
+
conn.tableOperations().create(table);
conn.tableOperations().addConstraint(table, AlphaNumKeyConstraint.class.getName());
conn.tableOperations().clone(table, table + "_clone", true, new HashMap<String,String>(), new HashSet<String>());
-
+
conn.securityOperations().changeUserAuthorizations("root", new Authorizations("A", "B"));
-
+
ColumnVisibility cvaob = new ColumnVisibility("A|B");
ColumnVisibility cvaab = new ColumnVisibility("A&B");
-
+
switch ((new Random()).nextInt(3)) {
case 1:
conn.tableOperations().addSplits(table, nss("6"));
@@ -701,33 +702,33 @@ public class ConditionalWriterTest {
conn.tableOperations().addSplits(table, nss("2", "95"));
break;
}
-
+
ArrayList<ConditionalMutation> mutations = new ArrayList<ConditionalMutation>();
-
+
ConditionalMutation cm0 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvaob));
cm0.put("name+", "last", cvaob, "doe");
cm0.put("name", "first", cvaob, "john");
cm0.put("tx", "seq", cvaob, "1");
mutations.add(cm0);
-
+
ConditionalMutation cm1 = new ConditionalMutation("59056", new Condition("tx", "seq").setVisibility(cvaab));
cm1.put("name", "last", cvaab, "doe");
cm1.put("name", "first", cvaab, "jane");
cm1.put("tx", "seq", cvaab, "1");
mutations.add(cm1);
-
+
ConditionalMutation cm2 = new ConditionalMutation("19059", new Condition("tx", "seq").setVisibility(cvaob));
cm2.put("name", "last", cvaob, "doe");
cm2.put("name", "first", cvaob, "jack");
cm2.put("tx", "seq", cvaob, "1");
mutations.add(cm2);
-
+
ConditionalMutation cm3 = new ConditionalMutation("90909", new Condition("tx", "seq").setVisibility(cvaob).setValue("1"));
cm3.put("name", "last", cvaob, "doe");
cm3.put("name", "first", cvaob, "john");
cm3.put("tx", "seq", cvaob, "2");
mutations.add(cm3);
-
+
ConditionalWriter cw = conn.createConditionalWriter(table, new ConditionalWriterConfig().setAuthorizations(new Authorizations("A")));
Iterator<Result> results = cw.write(mutations.iterator());
HashSet<String> rows = new HashSet<String>();
@@ -745,57 +746,57 @@ public class ConditionalWriterTest {
}
rows.add(row);
}
-
+
Assert.assertEquals(4, rows.size());
-
+
Scanner scanner = conn.createScanner(table, new Authorizations("A"));
scanner.fetchColumn(new Text("tx"), new Text("seq"));
-
+
Iterator<Entry<Key,Value>> iter = scanner.iterator();
Assert.assertEquals("1", iter.next().getValue().toString());
Assert.assertFalse(iter.hasNext());
-
+
cw.close();
zki.close();
}
-
+
@Test
public void testSameRow() throws Exception {
// test multiple mutations for same row in same batch
-
+
String table = "foo8";
-
+
ZooKeeperInstance zki = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
Connector conn = zki.getConnector("root", new PasswordToken(secret));
-
+
conn.tableOperations().create(table);
-
+
ConditionalWriter cw = conn.createConditionalWriter(table, new ConditionalWriterConfig());
-
+
ConditionalMutation cm1 = new ConditionalMutation("r1", new Condition("tx", "seq"));
cm1.put("tx", "seq", "1");
cm1.put("data", "x", "a");
-
+
Assert.assertEquals(Status.ACCEPTED, cw.write(cm1).getStatus());
-
+
ConditionalMutation cm2 = new ConditionalMutation("r1", new Condition("tx", "seq").setValue("1"));
cm2.put("tx", "seq", "2");
cm2.put("data", "x", "b");
-
+
ConditionalMutation cm3 = new ConditionalMutation("r1", new Condition("tx", "seq").setValue("1"));
cm3.put("tx", "seq", "2");
cm3.put("data", "x", "c");
-
+
ConditionalMutation cm4 = new ConditionalMutation("r1", new Condition("tx", "seq").setValue("1"));
cm4.put("tx", "seq", "2");
cm4.put("data", "x", "d");
-
+
Iterator<Result> results = cw.write(Arrays.asList(cm2, cm3, cm4).iterator());
-
+
int accepted = 0;
int rejected = 0;
int total = 0;
-
+
while (results.hasNext()) {
Status status = results.next().getStatus();
if (status == Status.ACCEPTED)
@@ -804,32 +805,32 @@ public class ConditionalWriterTest {
rejected++;
total++;
}
-
+
Assert.assertEquals(1, accepted);
Assert.assertEquals(2, rejected);
Assert.assertEquals(3, total);
-
+
cw.close();
zki.close();
}
-
+
private static class Stats {
-
+
ByteSequence row = null;
int seq;
long sum;
int data[] = new int[10];
-
+
public Stats(Iterator<Entry<Key,Value>> iterator) {
while (iterator.hasNext()) {
Entry<Key,Value> entry = iterator.next();
-
+
if (row == null)
row = entry.getKey().getRowData();
-
+
String cf = entry.getKey().getColumnFamilyData().toString();
String cq = entry.getKey().getColumnQualifierData().toString();
-
+
if (cf.equals("data")) {
data[Integer.parseInt(cq)] = Integer.parseInt(entry.getValue().toString());
} else if (cf.equals("meta")) {
@@ -840,16 +841,16 @@ public class ConditionalWriterTest {
}
}
}
-
+
long sum2 = 0;
-
+
for (int datum : data) {
sum2 += datum;
}
-
+
Assert.assertEquals(sum2, sum);
}
-
+
public Stats(ByteSequence row) {
this.row = row;
for (int i = 0; i < data.length; i++) {
@@ -858,43 +859,43 @@ public class ConditionalWriterTest {
this.seq = -1;
this.sum = 0;
}
-
+
void set(int index, int value) {
sum -= data[index];
sum += value;
data[index] = value;
}
-
+
ConditionalMutation toMutation() {
Condition cond = new Condition("meta", "seq");
if (seq >= 0)
cond.setValue(seq + "");
-
+
ConditionalMutation cm = new ConditionalMutation(row, cond);
-
+
cm.put("meta", "seq", (seq + 1) + "");
cm.put("meta", "sum", (sum) + "");
-
+
for (int i = 0; i < data.length; i++) {
cm.put("data", i + "", data[i] + "");
}
-
+
return cm;
}
-
+
@Override
public String toString() {
return row + " " + seq + " " + sum;
}
}
-
+
private static class MutatorTask implements Runnable {
String table;
ArrayList<ByteSequence> rows;
ConditionalWriter cw;
Connector conn;
AtomicBoolean failed;
-
+
public MutatorTask(String table, Connector conn, ArrayList<ByteSequence> rows, ConditionalWriter cw, AtomicBoolean failed) {
this.table = table;
this.rows = rows;
@@ -902,64 +903,64 @@ public class ConditionalWriterTest {
this.cw = cw;
this.failed = failed;
}
-
+
@Override
public void run() {
try {
Random rand = new Random();
-
+
Scanner scanner = new IsolatedScanner(conn.createScanner(table, Authorizations.EMPTY));
-
+
for (int i = 0; i < 20; i++) {
int numRows = rand.nextInt(10) + 1;
-
+
ArrayList<ByteSequence> changes = new ArrayList<ByteSequence>(numRows);
ArrayList<ConditionalMutation> mutations = new ArrayList<ConditionalMutation>();
-
+
for (int j = 0; j < numRows; j++)
changes.add(rows.get(rand.nextInt(rows.size())));
-
+
for (ByteSequence row : changes) {
scanner.setRange(new Range(row.toString()));
Stats stats = new Stats(scanner.iterator());
stats.set(rand.nextInt(10), Math.abs(rand.nextInt()));
mutations.add(stats.toMutation());
}
-
+
ArrayList<ByteSequence> changed = new ArrayList<ByteSequence>(numRows);
Iterator<Result> results = cw.write(mutations.iterator());
while (results.hasNext()) {
Result result = results.next();
changed.add(new ArrayByteSequence(result.getMutation().getRow()));
}
-
+
Collections.sort(changes);
Collections.sort(changed);
-
+
Assert.assertEquals(changes, changed);
-
+
}
-
+
} catch (Exception e) {
e.printStackTrace();
failed.set(true);
}
}
}
-
+
@Test
public void testThreads() throws Exception {
// test multiple threads using a single conditional writer
-
+
String table = "foo9";
-
+
ZooKeeperInstance zki = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
Connector conn = zki.getConnector("root", new PasswordToken(secret));
-
+
conn.tableOperations().create(table);
-
+
Random rand = new Random();
-
+
switch (rand.nextInt(3)) {
case 1:
conn.tableOperations().addSplits(table, nss("4"));
@@ -968,20 +969,20 @@ public class ConditionalWriterTest {
conn.tableOperations().addSplits(table, nss("3", "5"));
break;
}
-
+
ConditionalWriter cw = conn.createConditionalWriter(table, new ConditionalWriterConfig());
-
+
ArrayList<ByteSequence> rows = new ArrayList<ByteSequence>();
-
+
for (int i = 0; i < 1000; i++) {
rows.add(new ArrayByteSequence(FastFormat.toZeroPaddedString(Math.abs(rand.nextLong()), 16, 16, new byte[0])));
}
-
+
ArrayList<ConditionalMutation> mutations = new ArrayList<ConditionalMutation>();
-
+
for (ByteSequence row : rows)
mutations.add(new Stats(row).toMutation());
-
+
ArrayList<ByteSequence> rows2 = new ArrayList<ByteSequence>();
Iterator<Result> results = cw.write(mutations.iterator());
while (results.hasNext()) {
@@ -989,126 +990,126 @@ public class ConditionalWriterTest {
Assert.assertEquals(Status.ACCEPTED, result.getStatus());
rows2.add(new ArrayByteSequence(result.getMutation().getRow()));
}
-
+
Collections.sort(rows);
Collections.sort(rows2);
-
+
Assert.assertEquals(rows, rows2);
-
+
AtomicBoolean failed = new AtomicBoolean(false);
-
+
ExecutorService tp = Executors.newFixedThreadPool(5);
for (int i = 0; i < 5; i++) {
tp.submit(new MutatorTask(table, conn, rows, cw, failed));
}
-
+
tp.shutdown();
-
+
while (!tp.isTerminated()) {
tp.awaitTermination(1, TimeUnit.MINUTES);
}
-
+
Assert.assertFalse(failed.get());
-
+
Scanner scanner = conn.createScanner(table, Authorizations.EMPTY);
-
+
RowIterator rowIter = new RowIterator(scanner);
-
+
while (rowIter.hasNext()) {
Iterator<Entry<Key,Value>> row = rowIter.next();
new Stats(row);
}
zki.close();
}
-
+
private SortedSet<Text> nss(String... splits) {
TreeSet<Text> ret = new TreeSet<Text>();
for (String split : splits)
ret.add(new Text(split));
-
+
return ret;
}
-
+
@Test
public void testSecurity() throws Exception {
// test against table user does not have read and/or write permissions for
-
+
ZooKeeperInstance zki = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
Connector conn = zki.getConnector("root", new PasswordToken(secret));
-
+
conn.securityOperations().createLocalUser("user1", new PasswordToken("u1p"));
-
+
conn.tableOperations().create("sect1");
conn.tableOperations().create("sect2");
conn.tableOperations().create("sect3");
-
+
conn.securityOperations().grantTablePermission("user1", "sect1", TablePermission.READ);
conn.securityOperations().grantTablePermission("user1", "sect2", TablePermission.WRITE);
conn.securityOperations().grantTablePermission("user1", "sect3", TablePermission.READ);
conn.securityOperations().grantTablePermission("user1", "sect3", TablePermission.WRITE);
-
+
Connector conn2 = zki.getConnector("user1", new PasswordToken("u1p"));
-
+
ConditionalMutation cm1 = new ConditionalMutation("r1", new Condition("tx", "seq"));
cm1.put("tx", "seq", "1");
cm1.put("data", "x", "a");
-
+
ConditionalWriter cw1 = conn2.createConditionalWriter("sect1", new ConditionalWriterConfig());
ConditionalWriter cw2 = conn2.createConditionalWriter("sect2", new ConditionalWriterConfig());
ConditionalWriter cw3 = conn2.createConditionalWriter("sect3", new ConditionalWriterConfig());
-
+
Assert.assertEquals(Status.ACCEPTED, cw3.write(cm1).getStatus());
-
+
try {
cw1.write(cm1).getStatus();
Assert.assertFalse(true);
} catch (AccumuloSecurityException ase) {
-
+
}
-
+
try {
cw2.write(cm1).getStatus();
Assert.assertFalse(true);
} catch (AccumuloSecurityException ase) {
-
+
}
zki.close();
-
+
}
-
+
@Test
public void testTimeout() throws Exception {
ZooKeeperInstance zki = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
Connector conn = zki.getConnector("root", new PasswordToken(secret));
-
+
String table = "fooT";
-
+
conn.tableOperations().create(table);
-
+
ConditionalWriter cw = conn.createConditionalWriter(table, new ConditionalWriterConfig().setTimeout(1, TimeUnit.SECONDS));
-
+
ConditionalMutation cm1 = new ConditionalMutation("r1", new Condition("tx", "seq"));
cm1.put("tx", "seq", "1");
cm1.put("data", "x", "a");
-
+
Assert.assertEquals(cw.write(cm1).getStatus(), Status.ACCEPTED);
-
+
IteratorSetting is = new IteratorSetting(5, SlowIterator.class);
SlowIterator.setSeekSleepTime(is, 1500);
-
+
ConditionalMutation cm2 = new ConditionalMutation("r1", new Condition("tx", "seq").setValue("1").setIterators(is));
cm2.put("tx", "seq", "2");
cm2.put("data", "x", "b");
-
+
Assert.assertEquals(cw.write(cm2).getStatus(), Status.UNKNOWN);
-
+
Scanner scanner = conn.createScanner(table, Authorizations.EMPTY);
-
+
for (Entry<Key,Value> entry : scanner) {
String cf = entry.getKey().getColumnFamilyData().toString();
String cq = entry.getKey().getColumnQualifierData().toString();
String val = entry.getValue().toString();
-
+
if (cf.equals("tx") && cq.equals("seq"))
Assert.assertEquals("1", val);
else if (cf.equals("data") && cq.equals("x"))
@@ -1116,42 +1117,42 @@ public class ConditionalWriterTest {
else
Assert.fail();
}
-
+
ConditionalMutation cm3 = new ConditionalMutation("r1", new Condition("tx", "seq").setValue("1"));
cm3.put("tx", "seq", "2");
cm3.put("data", "x", "b");
-
+
Assert.assertEquals(cw.write(cm3).getStatus(), Status.ACCEPTED);
-
+
cw.close();
zki.close();
}
-
+
@Test
public void testDeleteTable() throws Exception {
String table = "foo12";
-
+
ZooKeeperInstance zki = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
Connector conn = zki.getConnector("root", new PasswordToken(secret));
-
+
try {
conn.createConditionalWriter(table, new ConditionalWriterConfig());
Assert.assertFalse(true);
} catch (TableNotFoundException e) {}
-
+
conn.tableOperations().create(table);
-
+
ConditionalWriter cw = conn.createConditionalWriter(table, new ConditionalWriterConfig());
-
+
conn.tableOperations().delete(table);
-
+
ConditionalMutation cm1 = new ConditionalMutation("r1", new Condition("tx", "seq"));
cm1.put("tx", "seq", "1");
cm1.put("data", "x", "a");
-
+
Result result = cw.write(cm1);
-
+
try {
result.getStatus();
Assert.assertFalse(true);
@@ -1161,73 +1162,73 @@ public class ConditionalWriterTest {
zki.close();
}
-
+
@Test
public void testOffline() throws Exception {
String table = "foo11";
-
+
ZooKeeperInstance zki = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
Connector conn = zki.getConnector("root", new PasswordToken(secret));
-
+
conn.tableOperations().create(table);
-
+
ConditionalWriter cw = conn.createConditionalWriter(table, new ConditionalWriterConfig());
-
+
conn.tableOperations().offline(table, true);
-
+
ConditionalMutation cm1 = new ConditionalMutation("r1", new Condition("tx", "seq"));
cm1.put("tx", "seq", "1");
cm1.put("data", "x", "a");
-
+
Result result = cw.write(cm1);
-
+
try {
result.getStatus();
Assert.assertFalse(true);
} catch (AccumuloException ae) {
Assert.assertEquals(TableOfflineException.class, ae.getCause().getClass());
}
-
+
cw.close();
-
+
try {
conn.createConditionalWriter(table, new ConditionalWriterConfig());
Assert.assertFalse(true);
} catch (TableOfflineException e) {}
zki.close();
}
-
+
@Test
public void testError() throws Exception {
String table = "foo10";
-
+
ZooKeeperInstance zki = new ZooKeeperInstance(cluster.getInstanceName(), cluster.getZooKeepers());
Connector conn = zki.getConnector("root", new PasswordToken(secret));
-
+
conn.tableOperations().create(table);
-
+
ConditionalWriter cw = conn.createConditionalWriter(table, new ConditionalWriterConfig());
-
+
IteratorSetting iterSetting = new IteratorSetting(5, BadIterator.class);
-
+
ConditionalMutation cm1 = new ConditionalMutation("r1", new Condition("tx", "seq").setIterators(iterSetting));
cm1.put("tx", "seq", "1");
cm1.put("data", "x", "a");
-
+
Result result = cw.write(cm1);
-
+
try {
result.getStatus();
Assert.assertFalse(true);
} catch (AccumuloException ae) {
-
+
}
-
+
cw.close();
zki.close();
}
-
+
@AfterClass
public static void tearDownAfterClass() throws Exception {
cluster.stop();
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/DumpConfigIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/DumpConfigIT.java b/test/src/test/java/org/apache/accumulo/test/DumpConfigIT.java
index fe0a7ed..c653751 100644
--- a/test/src/test/java/org/apache/accumulo/test/DumpConfigIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/DumpConfigIT.java
@@ -16,37 +16,45 @@
*/
package org.apache.accumulo.test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileInputStream;
import java.util.Collections;
import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.metadata.MetadataTable;
import org.apache.accumulo.minicluster.MiniAccumuloConfig;
import org.apache.accumulo.server.util.Admin;
import org.apache.accumulo.test.functional.ConfigurableMacIT;
import org.apache.accumulo.test.functional.FunctionalTestUtils;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
public class DumpConfigIT extends ConfigurableMacIT {
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+
@Override
public void configure(MiniAccumuloConfig cfg) {
cfg.setSiteConfig(Collections.singletonMap(Property.TABLE_FILE_BLOCK_SIZE.getKey(), "1234567"));
}
-
- @Test(timeout=2 * 60 * 1000)
+
+ @Test(timeout = 2 * 60 * 1000)
public void test() throws Exception {
- File siteFile = new File("target/accumulo-site.xml.bak");
- siteFile.delete();
- assertEquals(0, exec(Admin.class, new String[]{"dumpConfig", "-a", "-d", "target"}).waitFor());
- assertTrue(siteFile.exists());
- String site = FunctionalTestUtils.readAll(new FileInputStream("target/accumulo-site.xml.bak"));
+ File siteFileBackup = new File(folder.getRoot(), "accumulo-site.xml.bak");
+ assertFalse(siteFileBackup.exists());
+ assertEquals(0, exec(Admin.class, new String[] {"dumpConfig", "-a", "-d", folder.getRoot().getPath()}).waitFor());
+ assertTrue(siteFileBackup.exists());
+ String site = FunctionalTestUtils.readAll(new FileInputStream(siteFileBackup));
assertTrue(site.contains(Property.TABLE_FILE_BLOCK_SIZE.getKey()));
assertTrue(site.contains("1234567"));
- String meta = FunctionalTestUtils.readAll(new FileInputStream("target/!METADATA.cfg"));
+ String meta = FunctionalTestUtils.readAll(new FileInputStream(new File(folder.getRoot(), MetadataTable.NAME + ".cfg")));
assertTrue(meta.contains(Property.TABLE_FILE_REPLICATION.getKey()));
}
-
+
}
[2/4] ACCUMULO-1599 Move MiniAccumuloCluster output to target
directory
Posted by ct...@apache.org.
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/MetaSplitTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/MetaSplitTest.java b/test/src/test/java/org/apache/accumulo/test/MetaSplitTest.java
index d3ebd0f..02b0e2f 100644
--- a/test/src/test/java/org/apache/accumulo/test/MetaSplitTest.java
+++ b/test/src/test/java/org/apache/accumulo/test/MetaSplitTest.java
@@ -18,6 +18,7 @@ package org.apache.accumulo.test;
import static org.junit.Assert.assertEquals;
+import java.io.File;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -35,11 +36,11 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
public class MetaSplitTest {
-
+
private static String secret = "superSecret";
- public static TemporaryFolder folder = new TemporaryFolder();
+ public static TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
public static MiniAccumuloCluster cluster;
-
+
@BeforeClass
public static void setUpBeforeClass() throws Exception {
folder.create();
@@ -47,13 +48,13 @@ public class MetaSplitTest {
cluster = new MiniAccumuloCluster(cfg);
cluster.start();
}
-
+
@AfterClass
public static void tearDownAfterClass() throws Exception {
cluster.stop();
folder.delete();
}
-
+
@Test(expected = AccumuloException.class)
public void testRootTableSplit() throws Exception {
Connector connector = cluster.getConnector("root", secret);
@@ -62,14 +63,14 @@ public class MetaSplitTest {
splits.add(new Text("5"));
opts.addSplits(RootTable.NAME, splits);
}
-
+
@Test
public void testRootTableMerge() throws Exception {
Connector connector = cluster.getConnector("root", secret);
TableOperations opts = connector.tableOperations();
opts.merge(RootTable.NAME, null, null);
}
-
+
private void addSplits(TableOperations opts, String... points) throws Exception {
SortedSet<Text> splits = new TreeSet<Text>();
for (String point : points) {
@@ -77,7 +78,7 @@ public class MetaSplitTest {
}
opts.addSplits(MetadataTable.NAME, splits);
}
-
+
@Test(timeout = 60000)
public void testMetadataTableSplit() throws Exception {
Connector connector = cluster.getConnector("root", secret);
@@ -98,5 +99,5 @@ public class MetaSplitTest {
opts.merge(MetadataTable.NAME, null, null);
assertEquals(0, opts.listSplits(MetadataTable.NAME).size());
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java b/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java
index 9694ce9..179bca7 100644
--- a/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java
@@ -49,6 +49,7 @@ import org.apache.accumulo.core.util.shell.Shell;
import org.apache.accumulo.minicluster.MiniAccumuloCluster;
import org.apache.accumulo.minicluster.MiniAccumuloConfig;
import org.apache.accumulo.server.trace.TraceServer;
+import org.apache.accumulo.test.functional.SimpleMacIT;
import org.apache.commons.io.FileUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
@@ -58,10 +59,11 @@ import org.apache.hadoop.tools.DistCp;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-public class ShellServerIT {
+public class ShellServerIT extends SimpleMacIT {
public static class TestOutputStream extends OutputStream {
StringBuilder sb = new StringBuilder();
@@ -98,7 +100,6 @@ public class ShellServerIT {
}
private static String secret = "superSecret";
- public static TemporaryFolder folder = new TemporaryFolder();
public static MiniAccumuloCluster cluster;
public static TestOutputStream output;
public static StringInputStream input;
@@ -759,15 +760,16 @@ public class ShellServerIT {
exec("deletetable -f t", true);
}
+ @Rule
+ public TemporaryFolder folder2 = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+
@Test(timeout = 30 * 1000)
public void testPertableClasspath() throws Exception {
- File fooFilterJar = File.createTempFile("FooFilter", ".jar");
+ File fooFilterJar = folder2.newFile("FooFilter.jar");
FileUtils.copyURLToFile(this.getClass().getResource("/FooFilter.jar"), fooFilterJar);
- fooFilterJar.deleteOnExit();
- File fooConstraintJar = File.createTempFile("FooConstraint", ".jar");
+ File fooConstraintJar = folder2.newFile("FooConstraint.jar");
FileUtils.copyURLToFile(this.getClass().getResource("/FooConstraint.jar"), fooConstraintJar);
- fooConstraintJar.deleteOnExit();
exec(
"config -s " + Property.VFS_CONTEXT_CLASSPATH_PROPERTY.getKey() + "cx1=" + fooFilterJar.toURI().toString() + "," + fooConstraintJar.toURI().toString(),
@@ -872,4 +874,10 @@ public class ShellServerIT {
return output.get().split("\n").length - 1;
}
+ public static TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target/"));
+
+ public MiniAccumuloCluster getCluster() {
+ return cluster;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/TableOperationsIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/TableOperationsIT.java b/test/src/test/java/org/apache/accumulo/test/TableOperationsIT.java
index 03b69b8..edc2987 100644
--- a/test/src/test/java/org/apache/accumulo/test/TableOperationsIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/TableOperationsIT.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
@@ -53,31 +54,31 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
public class TableOperationsIT {
-
- static TemporaryFolder tempFolder = new TemporaryFolder();
+
+ static TemporaryFolder tempFolder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
static final String ROOT = "root";
static final String ROOT_PASS = "password";
-
+
static MiniAccumuloCluster accumuloCluster;
-
+
static Connector connector;
static TabletClientService.Client client;
final AtomicInteger tableCounter = new AtomicInteger(0);
-
+
@BeforeClass
public static void startUp() throws IOException, AccumuloException, AccumuloSecurityException, TTransportException, InterruptedException {
tempFolder.create();
accumuloCluster = new MiniAccumuloCluster(tempFolder.getRoot(), ROOT_PASS);
-
+
accumuloCluster.start();
-
+
connector = accumuloCluster.getConnector(ROOT, ROOT_PASS);
}
-
+
String makeTableName() {
return "table" + tableCounter.getAndIncrement();
}
-
+
@Test(timeout = 30 * 1000)
public void getDiskUsageErrors() throws TableExistsException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TException {
String tableName = makeTableName();
@@ -86,33 +87,33 @@ public class TableOperationsIT {
assertEquals(1, diskUsage.size());
assertEquals(0, (long) diskUsage.get(0).getUsage());
assertEquals(tableName, diskUsage.get(0).getTables().iterator().next());
-
+
connector.securityOperations().revokeTablePermission(ROOT, tableName, TablePermission.READ);
try {
connector.tableOperations().getDiskUsage(Collections.singleton(tableName));
fail("Should throw securityexception");
} catch (AccumuloSecurityException e) {}
-
+
connector.tableOperations().delete(tableName);
try {
connector.tableOperations().getDiskUsage(Collections.singleton(tableName));
fail("Should throw tablenotfound");
} catch (TableNotFoundException e) {}
}
-
+
@Test(timeout = 30 * 1000)
public void getDiskUsage() throws TableExistsException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TException {
-
+
String tableName = makeTableName();
connector.tableOperations().create(tableName);
-
+
// verify 0 disk usage
List<DiskUsage> diskUsages = connector.tableOperations().getDiskUsage(Collections.singleton(tableName));
assertEquals(1, diskUsages.size());
assertEquals(1, diskUsages.get(0).getTables().size());
assertEquals(new Long(0), diskUsages.get(0).getUsage());
assertEquals(tableName, diskUsages.get(0).getTables().first());
-
+
// add some data
BatchWriter bw = connector.createBatchWriter(tableName, new BatchWriterConfig());
Mutation m = new Mutation("a");
@@ -120,19 +121,19 @@ public class TableOperationsIT {
bw.addMutation(m);
bw.flush();
bw.close();
-
+
connector.tableOperations().compact(tableName, new Text("A"), new Text("z"), true, true);
-
+
// verify we have usage
diskUsages = connector.tableOperations().getDiskUsage(Collections.singleton(tableName));
assertEquals(1, diskUsages.size());
assertEquals(1, diskUsages.get(0).getTables().size());
assertTrue(diskUsages.get(0).getUsage() > 0);
assertEquals(tableName, diskUsages.get(0).getTables().first());
-
+
// clone table
connector.tableOperations().clone(tableName, "table2", false, null, null);
-
+
// verify tables are exactly the same
Set<String> tables = new HashSet<String>();
tables.add(tableName);
@@ -141,10 +142,10 @@ public class TableOperationsIT {
assertEquals(1, diskUsages.size());
assertEquals(2, diskUsages.get(0).getTables().size());
assertTrue(diskUsages.get(0).getUsage() > 0);
-
+
connector.tableOperations().compact(tableName, new Text("A"), new Text("z"), true, true);
connector.tableOperations().compact("table2", new Text("A"), new Text("z"), true, true);
-
+
// verify tables have differences
diskUsages = connector.tableOperations().getDiskUsage(tables);
assertEquals(2, diskUsages.size());
@@ -152,10 +153,10 @@ public class TableOperationsIT {
assertEquals(1, diskUsages.get(1).getTables().size());
assertTrue(diskUsages.get(0).getUsage() > 0);
assertTrue(diskUsages.get(1).getUsage() > 0);
-
+
connector.tableOperations().delete(tableName);
}
-
+
@Test(timeout = 30 * 1000)
public void createTable() throws TableExistsException, AccumuloException, AccumuloSecurityException, TableNotFoundException {
String tableName = makeTableName();
@@ -165,7 +166,7 @@ public class TableOperationsIT {
assertEquals(DefaultKeySizeConstraint.class.getName(), props.get(Property.TABLE_CONSTRAINT_PREFIX.toString() + "1"));
connector.tableOperations().delete(tableName);
}
-
+
private Map<String,String> propsToMap(Iterable<Map.Entry<String,String>> props) {
Map<String,String> map = new HashMap<String,String>();
for (Map.Entry<String,String> prop : props) {
@@ -173,7 +174,7 @@ public class TableOperationsIT {
}
return map;
}
-
+
@AfterClass
public static void shutDown() throws IOException, InterruptedException {
accumuloCluster.stop();
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/TestAccumuloSplitRecovery.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/TestAccumuloSplitRecovery.java b/test/src/test/java/org/apache/accumulo/test/TestAccumuloSplitRecovery.java
index c481f91..a7a58ec 100644
--- a/test/src/test/java/org/apache/accumulo/test/TestAccumuloSplitRecovery.java
+++ b/test/src/test/java/org/apache/accumulo/test/TestAccumuloSplitRecovery.java
@@ -18,6 +18,7 @@ package org.apache.accumulo.test;
import static org.junit.Assert.assertEquals;
+import java.io.File;
import java.util.Map.Entry;
import org.apache.accumulo.core.client.BatchWriter;
@@ -44,31 +45,31 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
public class TestAccumuloSplitRecovery {
-
+
private static final String TABLE = "simple";
- public static TemporaryFolder folder = new TemporaryFolder();
+ public static TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
private MiniAccumuloCluster accumulo;
private String secret = "secret";
-
+
@Before
public void setUp() throws Exception {
folder.create();
accumulo = new MiniAccumuloCluster(folder.getRoot(), secret);
accumulo.start();
}
-
+
@After
public void tearDown() throws Exception {
accumulo.stop();
folder.delete();
}
-
+
private Mutation m(String row) {
Mutation result = new Mutation(row);
result.put("cf", "cq", new Value("value".getBytes()));
return result;
}
-
+
boolean isOffline(String tablename, Connector connector) throws TableNotFoundException {
String tableId = connector.tableOperations().tableIdMap().get(tablename);
Scanner scanner = connector.createScanner(MetadataTable.NAME, Authorizations.EMPTY);
@@ -80,12 +81,12 @@ public class TestAccumuloSplitRecovery {
}
return true;
}
-
+
@Test(timeout = 60000)
public void test() throws Exception {
-
+
for (int tn = 0; tn < 2; tn++) {
-
+
Connector connector = accumulo.getConnector("root", secret);
// create a table and put some data in it
connector.tableOperations().create(TABLE);
@@ -98,43 +99,43 @@ public class TestAccumuloSplitRecovery {
connector.tableOperations().offline(TABLE);
while (!isOffline(TABLE, connector))
UtilWaitThread.sleep(200);
-
+
// poke a partial split into the !METADATA table
connector.securityOperations().grantTablePermission("root", MetadataTable.NAME, TablePermission.WRITE);
String tableId = connector.tableOperations().tableIdMap().get(TABLE);
-
+
KeyExtent extent = new KeyExtent(new Text(tableId), null, new Text("b"));
Mutation m = extent.getPrevRowUpdateMutation();
-
+
TabletsSection.TabletColumnFamily.SPLIT_RATIO_COLUMN.put(m, new Value(Double.toString(0.5).getBytes()));
TabletsSection.TabletColumnFamily.OLD_PREV_ROW_COLUMN.put(m, KeyExtent.encodePrevEndRow(null));
bw = connector.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());
bw.addMutation(m);
-
+
if (tn == 1) {
-
+
bw.flush();
-
+
Scanner scanner = connector.createScanner(MetadataTable.NAME, Authorizations.EMPTY);
scanner.setRange(extent.toMetadataRange());
scanner.fetchColumnFamily(DataFileColumnFamily.NAME);
-
+
KeyExtent extent2 = new KeyExtent(new Text(tableId), new Text("b"), null);
m = extent2.getPrevRowUpdateMutation();
TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN.put(m, new Value("/t2".getBytes()));
TabletsSection.ServerColumnFamily.TIME_COLUMN.put(m, new Value("M0".getBytes()));
-
+
for (Entry<Key,Value> entry : scanner) {
m.put(DataFileColumnFamily.NAME, entry.getKey().getColumnQualifier(), entry.getValue());
}
-
+
bw.addMutation(m);
}
-
+
bw.close();
// bring the table online
connector.tableOperations().online(TABLE);
-
+
// verify the tablets went online
Scanner scanner = connector.createScanner(TABLE, Authorizations.EMPTY);
int i = 0;
@@ -144,10 +145,10 @@ public class TestAccumuloSplitRecovery {
i++;
}
assertEquals(3, i);
-
+
connector.tableOperations().delete(TABLE);
-
+
}
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/VolumeTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/VolumeTest.java b/test/src/test/java/org/apache/accumulo/test/VolumeTest.java
index 18b0c9a..8813c63 100644
--- a/test/src/test/java/org/apache/accumulo/test/VolumeTest.java
+++ b/test/src/test/java/org/apache/accumulo/test/VolumeTest.java
@@ -19,6 +19,7 @@ package org.apache.accumulo.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import java.io.File;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedSet;
@@ -45,15 +46,15 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
public class VolumeTest {
-
+
private static final Text EMPTY = new Text();
- private static final Value EMPTY_VALUE = new Value(new byte[]{});
+ private static final Value EMPTY_VALUE = new Value(new byte[] {});
private static String secret = "superSecret";
- public static TemporaryFolder folder = new TemporaryFolder();
+ public static TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
public static MiniAccumuloCluster cluster;
public static Path v1;
public static Path v2;
-
+
@BeforeClass
public static void setUpBeforeClass() throws Exception {
folder.create();
@@ -67,13 +68,13 @@ public class VolumeTest {
cluster = new MiniAccumuloCluster(cfg);
cluster.start();
}
-
+
@AfterClass
public static void tearDownAfterClass() throws Exception {
cluster.stop();
folder.delete();
}
-
+
@Test
public void test() throws Exception {
// create a table
@@ -108,11 +109,11 @@ public class VolumeTest {
int fileCount = 0;
for (Entry<Key,Value> entry : scanner) {
boolean inV1 = entry.getKey().getColumnQualifier().toString().contains(v1.toString());
- boolean inV2 = entry.getKey().getColumnQualifier().toString().contains(v2.toString());
+ boolean inV2 = entry.getKey().getColumnQualifier().toString().contains(v2.toString());
assertTrue(inV1 || inV2);
fileCount++;
}
assertEquals(4, fileCount);
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/AbstractMacIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/AbstractMacIT.java b/test/src/test/java/org/apache/accumulo/test/functional/AbstractMacIT.java
index f1a651d..d24b85b 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/AbstractMacIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/AbstractMacIT.java
@@ -16,62 +16,73 @@
*/
package org.apache.accumulo.test.functional;
-import java.io.IOException;
+import java.io.File;
+import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.accumulo.core.Constants;
import org.apache.accumulo.core.cli.BatchWriterOpts;
import org.apache.accumulo.core.cli.ScannerOpts;
import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.Connector;
-import org.apache.accumulo.core.client.Instance;
-import org.apache.accumulo.core.client.ZooKeeperInstance;
-import org.apache.accumulo.core.zookeeper.ZooUtil;
-import org.apache.accumulo.fate.zookeeper.ZooReader;
import org.apache.accumulo.minicluster.MiniAccumuloCluster;
+import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
-import org.apache.zookeeper.KeeperException;
-import org.junit.rules.TemporaryFolder;
+import org.junit.Rule;
+import org.junit.rules.TestName;
public abstract class AbstractMacIT {
public static final Logger log = Logger.getLogger(AbstractMacIT.class);
-
- public static final String ROOT_PASSWORD = "secret";
+
+ public static final String ROOT_PASSWORD = "testRootPassword1";
public static final ScannerOpts SOPTS = new ScannerOpts();
public static final BatchWriterOpts BWOPTS = new BatchWriterOpts();
-
- public abstract MiniAccumuloCluster getCluster();
-
- protected static void cleanUp(MiniAccumuloCluster cluster, TemporaryFolder folder) {
+
+ @Rule
+ public TestName testName = new TestName();
+
+ protected static void cleanUp(MiniAccumuloCluster cluster) {
if (cluster != null)
try {
cluster.stop();
} catch (Exception e) {}
- folder.delete();
}
-
+
static AtomicInteger tableCount = new AtomicInteger();
-
- static public String makeTableName() {
- return "table" + tableCount.getAndIncrement();
- }
-
- public Connector getConnector() throws AccumuloException, AccumuloSecurityException {
- return getCluster().getConnector("root", ROOT_PASSWORD);
- }
-
- public String getMonitor() throws KeeperException, InterruptedException {
- Instance instance = new ZooKeeperInstance(getCluster().getInstanceName(), getCluster().getZooKeepers());
- ZooReader zr = new ZooReader(getCluster().getZooKeepers(), 5000);
- return new String(zr.getData(ZooUtil.getRoot(instance) + Constants.ZMONITOR, null));
+
+ protected static File createSharedTestDir(String name) {
+ File baseDir = new File(System.getProperty("user.dir") + "/target/mini-tests");
+ baseDir.mkdirs();
+ if (name != null)
+ baseDir = new File(baseDir, name);
+ File testDir = new File(baseDir, System.currentTimeMillis() + "_" + new Random().nextInt(Short.MAX_VALUE));
+ FileUtils.deleteQuietly(testDir);
+ testDir.mkdir();
+ return testDir;
}
-
- public String rootPath() {
- return getCluster().getConfig().getDir().getAbsolutePath();
+
+ protected File createTestDir(String name) {
+ File baseDir = new File(System.getProperty("user.dir") + "/target/mini-tests");
+ baseDir.mkdirs();
+ if (name == null)
+ return baseDir;
+ File testDir = new File(baseDir, name);
+ FileUtils.deleteQuietly(testDir);
+ testDir.mkdir();
+ return testDir;
}
-
- public Process exec(Class<? extends Object> clazz, String... args) throws IOException {
- return getCluster().exec(clazz, args);
+
+ public String[] getTableNames(int num) {
+ if (num == 1)
+ return new String[] {testName.getMethodName()};
+ String[] names = new String[num];
+ for (int i = 0; i < num; i++)
+ names[i] = this.getClass().getSimpleName() + "_" + testName.getMethodName() + i;
+ return names;
}
+
+ public abstract Connector getConnector() throws AccumuloException, AccumuloSecurityException;
+
+ public abstract String rootPath();
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/AddSplitIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/AddSplitIT.java b/test/src/test/java/org/apache/accumulo/test/functional/AddSplitIT.java
index eba3081..e4760ba 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/AddSplitIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/AddSplitIT.java
@@ -37,98 +37,98 @@ import org.apache.hadoop.io.Text;
import org.junit.Test;
public class AddSplitIT extends SimpleMacIT {
-
+
@Test(timeout = 60 * 1000)
public void addSplitTest() throws Exception {
- String tableName = makeTableName();
+ String tableName = getTableNames(1)[0];
Connector c = getConnector();
c.tableOperations().create(tableName);
-
+
insertData(tableName, 1l);
-
+
TreeSet<Text> splits = new TreeSet<Text>();
splits.add(new Text(String.format("%09d", 333)));
splits.add(new Text(String.format("%09d", 666)));
-
+
c.tableOperations().addSplits(tableName, splits);
-
+
UtilWaitThread.sleep(100);
-
+
Collection<Text> actualSplits = c.tableOperations().listSplits(tableName);
-
+
if (!splits.equals(new TreeSet<Text>(actualSplits))) {
throw new Exception(splits + " != " + actualSplits);
}
-
+
verifyData(tableName, 1l);
insertData(tableName, 2l);
-
+
// did not clear splits on purpose, it should ignore existing split points
// and still create the three additional split points
-
+
splits.add(new Text(String.format("%09d", 200)));
splits.add(new Text(String.format("%09d", 500)));
splits.add(new Text(String.format("%09d", 800)));
-
+
c.tableOperations().addSplits(tableName, splits);
-
+
UtilWaitThread.sleep(100);
-
+
actualSplits = c.tableOperations().listSplits(tableName);
-
+
if (!splits.equals(new TreeSet<Text>(actualSplits))) {
throw new Exception(splits + " != " + actualSplits);
}
-
+
verifyData(tableName, 2l);
}
-
+
private void verifyData(String tableName, long ts) throws Exception {
Scanner scanner = getConnector().createScanner(tableName, Authorizations.EMPTY);
-
+
Iterator<Entry<Key,Value>> iter = scanner.iterator();
-
+
for (int i = 0; i < 10000; i++) {
if (!iter.hasNext()) {
throw new Exception("row " + i + " not found");
}
-
+
Entry<Key,Value> entry = iter.next();
-
+
String row = String.format("%09d", i);
-
+
if (!entry.getKey().getRow().equals(new Text(row))) {
throw new Exception("unexpected row " + entry.getKey() + " " + i);
}
-
+
if (entry.getKey().getTimestamp() != ts) {
throw new Exception("unexpected ts " + entry.getKey() + " " + ts);
}
-
+
if (Integer.parseInt(entry.getValue().toString()) != i) {
throw new Exception("unexpected value " + entry + " " + i);
}
}
-
+
if (iter.hasNext()) {
throw new Exception("found more than expected " + iter.next());
}
-
+
}
-
+
private void insertData(String tableName, long ts) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, MutationsRejectedException {
BatchWriter bw = getConnector().createBatchWriter(tableName, null);
-
+
for (int i = 0; i < 10000; i++) {
String row = String.format("%09d", i);
-
+
Mutation m = new Mutation(new Text(row));
m.put(new Text("cf1"), new Text("cq1"), ts, new Value(("" + i).getBytes()));
bw.addMutation(m);
}
-
+
bw.close();
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/BadIteratorMincIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/BadIteratorMincIT.java b/test/src/test/java/org/apache/accumulo/test/functional/BadIteratorMincIT.java
index 0d7e509..8de84f2 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/BadIteratorMincIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/BadIteratorMincIT.java
@@ -34,57 +34,57 @@ import org.apache.hadoop.io.Text;
import org.junit.Test;
public class BadIteratorMincIT extends SimpleMacIT {
-
+
@Test(timeout = 60 * 1000)
public void test() throws Exception {
Connector c = getConnector();
-
- String tableName = makeTableName();
+
+ String tableName = getTableNames(1)[0];
c.tableOperations().create(tableName);
IteratorSetting is = new IteratorSetting(30, BadIterator.class);
c.tableOperations().attachIterator(tableName, is, EnumSet.of(IteratorScope.minc));
BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
-
+
Mutation m = new Mutation(new Text("r1"));
m.put(new Text("acf"), new Text(tableName), new Value("1".getBytes()));
bw.addMutation(m);
bw.close();
-
+
c.tableOperations().flush(tableName, null, null, false);
UtilWaitThread.sleep(1000);
-
+
// minc should fail, so there should be no files
FunctionalTestUtils.checkRFiles(c, tableName, 1, 1, 0, 0);
-
+
// try to scan table
Scanner scanner = c.createScanner(tableName, Authorizations.EMPTY);
-
+
int count = 0;
for (@SuppressWarnings("unused")
Entry<Key,Value> entry : scanner) {
count++;
}
-
+
if (count != 1)
throw new Exception("Did not see expected # entries " + count);
-
+
// remove the bad iterator
c.tableOperations().removeIterator(tableName, BadIterator.class.getSimpleName(), EnumSet.of(IteratorScope.minc));
-
+
UtilWaitThread.sleep(5000);
-
+
// minc should complete
FunctionalTestUtils.checkRFiles(c, tableName, 1, 1, 1, 1);
-
+
count = 0;
for (@SuppressWarnings("unused")
Entry<Key,Value> entry : scanner) {
count++;
}
-
+
if (count != 1)
throw new Exception("Did not see expected # entries " + count);
-
+
// now try putting bad iterator back and deleting the table
c.tableOperations().attachIterator(tableName, is, EnumSet.of(IteratorScope.minc));
bw = c.createBatchWriter(tableName, new BatchWriterConfig());
@@ -92,20 +92,17 @@ public class BadIteratorMincIT extends SimpleMacIT {
m.put(new Text("acf"), new Text(tableName), new Value("1".getBytes()));
bw.addMutation(m);
bw.close();
-
+
// make sure property is given time to propagate
UtilWaitThread.sleep(500);
-
+
c.tableOperations().flush(tableName, null, null, false);
-
+
// make sure the flush has time to start
UtilWaitThread.sleep(1000);
-
+
// this should not hang
c.tableOperations().delete(tableName);
}
-
-
-
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/BatchScanSplitIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/BatchScanSplitIT.java b/test/src/test/java/org/apache/accumulo/test/functional/BatchScanSplitIT.java
index ba7f07c..0297ffc 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/BatchScanSplitIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/BatchScanSplitIT.java
@@ -39,42 +39,42 @@ import org.apache.hadoop.io.Text;
import org.junit.Test;
public class BatchScanSplitIT extends ConfigurableMacIT {
-
+
@Override
public void configure(MiniAccumuloConfig cfg) {
cfg.setSiteConfig(Collections.singletonMap(Property.TSERV_MAJC_DELAY.getKey(), "0"));
}
-
+
@Test(timeout = 2 * 60 * 1000)
public void test() throws Exception {
Connector c = getConnector();
- String tableName = makeTableName();
+ String tableName = getTableNames(1)[0];
c.tableOperations().create(tableName);
-
+
int numRows = 1 << 18;
-
+
BatchWriter bw = getConnector().createBatchWriter(tableName, new BatchWriterConfig());
-
+
for (int i = 0; i < numRows; i++) {
Mutation m = new Mutation(new Text(String.format("%09x", i)));
m.put(new Text("cf1"), new Text("cq1"), new Value(String.format("%016x", numRows - i).getBytes()));
bw.addMutation(m);
}
-
+
bw.close();
-
+
getConnector().tableOperations().flush(tableName, null, null, true);
-
+
getConnector().tableOperations().setProperty(tableName, Property.TABLE_SPLIT_THRESHOLD.getKey(), "4K");
-
+
Collection<Text> splits = getConnector().tableOperations().listSplits(tableName);
while (splits.size() < 2) {
UtilWaitThread.sleep(1);
splits = getConnector().tableOperations().listSplits(tableName);
}
-
+
System.out.println("splits : " + splits);
-
+
Random random = new Random(19011230);
HashMap<Text,Value> expected = new HashMap<Text,Value>();
ArrayList<Range> ranges = new ArrayList<Range>();
@@ -84,35 +84,35 @@ public class BatchScanSplitIT extends ConfigurableMacIT {
expected.put(row, new Value(String.format("%016x", numRows - r).getBytes()));
ranges.add(new Range(row));
}
-
+
// logger.setLevel(Level.TRACE);
-
+
HashMap<Text,Value> found = new HashMap<Text,Value>();
-
+
for (int i = 0; i < 20; i++) {
BatchScanner bs = getConnector().createBatchScanner(tableName, Authorizations.EMPTY, 4);
-
+
found.clear();
-
+
long t1 = System.currentTimeMillis();
-
+
bs.setRanges(ranges);
-
+
for (Entry<Key,Value> entry : bs) {
found.put(entry.getKey().getRow(), entry.getValue());
}
bs.close();
-
+
long t2 = System.currentTimeMillis();
-
+
log.info(String.format("rate : %06.2f%n", ranges.size() / ((t2 - t1) / 1000.0)));
-
+
if (!found.equals(expected))
throw new Exception("Found and expected differ " + found + " " + expected);
}
-
+
splits = getConnector().tableOperations().listSplits(tableName);
log.info("splits : " + splits);
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/BatchWriterFlushIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/BatchWriterFlushIT.java b/test/src/test/java/org/apache/accumulo/test/functional/BatchWriterFlushIT.java
index f313786..59fa753 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/BatchWriterFlushIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/BatchWriterFlushIT.java
@@ -39,114 +39,116 @@ import org.apache.hadoop.io.Text;
import org.junit.Test;
public class BatchWriterFlushIT extends SimpleMacIT {
-
+
private static final int NUM_TO_FLUSH = 100000;
-
+
@Test(timeout = 30 * 1000)
public void run() throws Exception {
Connector c = getConnector();
- String bwft = makeTableName();
+ String[] tableNames = getTableNames(2);
+ String bwft = tableNames[0];
c.tableOperations().create(bwft);
- String bwlt = makeTableName();
+ String bwlt = tableNames[1];
c.tableOperations().create(bwlt);
runFlushTest(bwft);
runLatencyTest(bwlt);
-
+
}
-
+
private void runLatencyTest(String tableName) throws Exception {
// should automatically flush after 2 seconds
BatchWriter bw = getConnector().createBatchWriter(tableName, new BatchWriterConfig().setMaxLatency(1000, TimeUnit.MILLISECONDS));
Scanner scanner = getConnector().createScanner(tableName, Authorizations.EMPTY);
-
+
Mutation m = new Mutation(new Text(String.format("r_%10d", 1)));
m.put(new Text("cf"), new Text("cq"), new Value(("" + 1).getBytes()));
bw.addMutation(m);
-
+
UtilWaitThread.sleep(500);
-
+
int count = 0;
for (@SuppressWarnings("unused")
Entry<Key,Value> entry : scanner) {
count++;
}
-
+
if (count != 0) {
throw new Exception("Flushed too soon");
}
-
+
UtilWaitThread.sleep(1500);
-
+
for (@SuppressWarnings("unused")
Entry<Key,Value> entry : scanner) {
count++;
}
-
+
if (count != 1) {
throw new Exception("Did not flush");
}
-
+
bw.close();
}
-
- private void runFlushTest(String tableName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, MutationsRejectedException, Exception {
+
+ private void runFlushTest(String tableName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, MutationsRejectedException,
+ Exception {
BatchWriter bw = getConnector().createBatchWriter(tableName, new BatchWriterConfig());
Scanner scanner = getConnector().createScanner(tableName, Authorizations.EMPTY);
Random r = new Random();
-
+
for (int i = 0; i < 4; i++) {
for (int j = 0; j < NUM_TO_FLUSH; j++) {
int row = i * NUM_TO_FLUSH + j;
-
+
Mutation m = new Mutation(new Text(String.format("r_%10d", row)));
m.put(new Text("cf"), new Text("cq"), new Value(("" + row).getBytes()));
bw.addMutation(m);
}
-
+
bw.flush();
-
+
// do a few random lookups into the data just flushed
-
+
for (int k = 0; k < 10; k++) {
int rowToLookup = r.nextInt(NUM_TO_FLUSH) + i * NUM_TO_FLUSH;
-
+
scanner.setRange(new Range(new Text(String.format("r_%10d", rowToLookup))));
-
+
Iterator<Entry<Key,Value>> iter = scanner.iterator();
-
+
if (!iter.hasNext())
throw new Exception(" row " + rowToLookup + " not found after flush");
-
+
Entry<Key,Value> entry = iter.next();
-
+
if (iter.hasNext())
throw new Exception("Scanner returned too much");
-
+
verifyEntry(rowToLookup, entry);
}
-
+
// scan all data just flushed
scanner.setRange(new Range(new Text(String.format("r_%10d", i * NUM_TO_FLUSH)), true, new Text(String.format("r_%10d", (i + 1) * NUM_TO_FLUSH)), false));
Iterator<Entry<Key,Value>> iter = scanner.iterator();
-
+
for (int j = 0; j < NUM_TO_FLUSH; j++) {
int row = i * NUM_TO_FLUSH + j;
-
+
if (!iter.hasNext())
throw new Exception("Scan stopped permaturely at " + row);
-
+
Entry<Key,Value> entry = iter.next();
-
+
verifyEntry(row, entry);
}
-
+
if (iter.hasNext())
throw new Exception("Scanner returned too much");
-
+
}
-
+
bw.close();
-
+
// test adding a mutation to a closed batch writer
boolean caught = false;
try {
@@ -154,20 +156,20 @@ public class BatchWriterFlushIT extends SimpleMacIT {
} catch (IllegalStateException ise) {
caught = true;
}
-
+
if (!caught) {
throw new Exception("Adding to closed batch writer did not fail");
}
}
-
+
private void verifyEntry(int row, Entry<Key,Value> entry) throws Exception {
if (!entry.getKey().getRow().toString().equals(String.format("r_%10d", row))) {
throw new Exception("Unexpected key returned, expected " + row + " got " + entry.getKey());
}
-
+
if (!entry.getValue().toString().equals("" + row)) {
throw new Exception("Unexpected value, expected " + row + " got " + entry.getValue());
}
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/BinaryIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/BinaryIT.java b/test/src/test/java/org/apache/accumulo/test/functional/BinaryIT.java
index 58ca57c..aad112e 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/BinaryIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/BinaryIT.java
@@ -27,14 +27,15 @@ import org.apache.hadoop.io.Text;
import org.junit.Test;
public class BinaryIT extends ConfigurableMacIT {
-
+
@Test(timeout = 60 * 1000)
public void test() throws Exception {
Connector c = getConnector();
c.tableOperations().create("bt");
runTest(c);
}
-
+
+ @Test(timeout = 60 * 1000)
public void testPreSplit() throws Exception {
Connector c = getConnector();
c.tableOperations().create("bt");
@@ -44,7 +45,7 @@ public class BinaryIT extends ConfigurableMacIT {
c.tableOperations().addSplits("bt", splits);
runTest(c);
}
-
+
public static void runTest(Connector c) throws Exception {
BatchWriterOpts bwOpts = new BatchWriterOpts();
ScannerOpts scanOpts = new ScannerOpts();
@@ -73,5 +74,5 @@ public class BinaryIT extends ConfigurableMacIT {
opts.mode = "verifyDeleted";
TestBinaryRows.runTest(c, opts, bwOpts, scanOpts);
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/BulkFileIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/BulkFileIT.java b/test/src/test/java/org/apache/accumulo/test/functional/BulkFileIT.java
index 6597c68..3a0eeda 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/BulkFileIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/BulkFileIT.java
@@ -40,11 +40,11 @@ import org.apache.hadoop.io.Text;
import org.junit.Test;
public class BulkFileIT extends SimpleMacIT {
-
+
@Test(timeout = 2 * 60 * 1000)
public void testBulkFile() throws Exception {
Connector c = getConnector();
- String tableName = makeTableName();
+ String tableName = getTableNames(1)[0];
c.tableOperations().create(tableName);
SortedSet<Text> splits = new TreeSet<Text>();
for (String split : "0333 0666 0999 1333 1666".split(" "))
@@ -53,62 +53,62 @@ public class BulkFileIT extends SimpleMacIT {
Configuration conf = new Configuration();
AccumuloConfiguration aconf = ServerConfiguration.getDefaultConfiguration();
FileSystem fs = TraceFileSystem.wrap(FileUtil.getFileSystem(conf, aconf));
-
- String dir = "/tmp/bulk_test_diff_files_89723987592";
-
+
+ String dir = rootPath() + "/bulk_test_diff_files_89723987592_" + getTableNames(1)[0];
+
fs.delete(new Path(dir), true);
-
+
FileSKVWriter writer1 = FileOperations.getInstance().openWriter(dir + "/f1." + RFile.EXTENSION, fs, conf, aconf);
writer1.startDefaultLocalityGroup();
writeData(writer1, 0, 333);
writer1.close();
-
+
FileSKVWriter writer2 = FileOperations.getInstance().openWriter(dir + "/f2." + RFile.EXTENSION, fs, conf, aconf);
writer2.startDefaultLocalityGroup();
writeData(writer2, 334, 999);
writer2.close();
-
+
FileSKVWriter writer3 = FileOperations.getInstance().openWriter(dir + "/f3." + RFile.EXTENSION, fs, conf, aconf);
writer3.startDefaultLocalityGroup();
writeData(writer3, 1000, 1999);
writer3.close();
-
- FunctionalTestUtils.bulkImport(c, fs, tableName, dir);
-
+
+ FunctionalTestUtils.bulkImport(c, fs, tableName, dir);
+
FunctionalTestUtils.checkRFiles(c, tableName, 6, 6, 1, 1);
-
+
verifyData(tableName, 0, 1999);
-
+
}
-
+
private void verifyData(String table, int s, int e) throws Exception {
Scanner scanner = getConnector().createScanner(table, Authorizations.EMPTY);
-
+
Iterator<Entry<Key,Value>> iter = scanner.iterator();
-
+
for (int i = s; i <= e; i++) {
if (!iter.hasNext())
throw new Exception("row " + i + " not found");
-
+
Entry<Key,Value> entry = iter.next();
-
+
String row = String.format("%04d", i);
-
+
if (!entry.getKey().getRow().equals(new Text(row)))
throw new Exception("unexpected row " + entry.getKey() + " " + i);
-
+
if (Integer.parseInt(entry.getValue().toString()) != i)
throw new Exception("unexpected value " + entry + " " + i);
}
-
+
if (iter.hasNext())
throw new Exception("found more than expected " + iter.next());
}
-
+
private void writeData(FileSKVWriter w, int s, int e) throws Exception {
for (int i = s; i <= e; i++) {
w.append(new Key(new Text(String.format("%04d", i))), new Value(("" + i).getBytes()));
}
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/BulkIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/BulkIT.java b/test/src/test/java/org/apache/accumulo/test/functional/BulkIT.java
index 607f2a5..2fb5827 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/BulkIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/BulkIT.java
@@ -26,20 +26,20 @@ import org.apache.hadoop.fs.Path;
import org.junit.Test;
public class BulkIT extends SimpleMacIT {
-
+
static final int N = 100000;
static final int COUNT = 5;
-
+
@Test(timeout = 4 * 60 * 1000)
public void test() throws Exception {
Connector c = getConnector();
- String tableName = makeTableName();
+ String tableName = getTableNames(1)[0];
c.tableOperations().create(tableName);
FileSystem fs = FileSystem.get(CachedConfiguration.getInstance());
String base = "target/accumulo-maven-plugin";
fs.delete(new Path(base + "/testrf"), true);
fs.mkdirs(new Path(base + "/testBulkFail"));
-
+
Opts opts = new Opts();
opts.timestamp = 1;
opts.random = 56;
@@ -70,5 +70,5 @@ public class BulkIT extends SimpleMacIT {
vopts.rows = 1;
VerifyIngest.verifyIngest(c, vopts, SOPTS);
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/BulkSplitOptimizationIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/BulkSplitOptimizationIT.java b/test/src/test/java/org/apache/accumulo/test/functional/BulkSplitOptimizationIT.java
index f836181..337d0f7 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/BulkSplitOptimizationIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/BulkSplitOptimizationIT.java
@@ -16,6 +16,7 @@
*/
package org.apache.accumulo.test.functional;
+import java.io.File;
import java.util.Collections;
import org.apache.accumulo.core.cli.ClientOpts.Password;
@@ -26,7 +27,9 @@ import org.apache.accumulo.core.util.UtilWaitThread;
import org.apache.accumulo.minicluster.MiniAccumuloConfig;
import org.apache.accumulo.test.VerifyIngest;
import org.apache.hadoop.fs.FileSystem;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
/**
* This test verifies that when a lot of files are bulk imported into a table with one tablet and then splits that not all map files go to the children tablets.
@@ -36,9 +39,12 @@ import org.junit.Test;
*/
public class BulkSplitOptimizationIT extends ConfigurableMacIT {
-
+
private static final String TABLE_NAME = "test_ingest";
-
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+
@Override
public void configure(MiniAccumuloConfig cfg) {
cfg.setSiteConfig(Collections.singletonMap(Property.TSERV_MAJC_DELAY.getKey(), "1s"));
@@ -54,23 +60,23 @@ public class BulkSplitOptimizationIT extends ConfigurableMacIT {
c.tableOperations().setProperty(TABLE_NAME, Property.TABLE_MAJC_RATIO.getKey(), "1000");
c.tableOperations().setProperty(TABLE_NAME, Property.TABLE_FILE_MAX.getKey(), "1000");
c.tableOperations().setProperty(TABLE_NAME, Property.TABLE_SPLIT_THRESHOLD.getKey(), "1G");
-
+
FileSystem fs = FileSystem.get(CachedConfiguration.getInstance());
- FunctionalTestUtils.createRFiles(c, fs, "tmp/testmf", ROWS, SPLITS, 8);
- FunctionalTestUtils.bulkImport(c, fs, TABLE_NAME, "tmp/testmf");
+ FunctionalTestUtils.createRFiles(c, fs, folder.getRoot() + "/testmf", ROWS, SPLITS, 8);
+ FunctionalTestUtils.bulkImport(c, fs, TABLE_NAME, folder.getRoot() + "/testmf");
FunctionalTestUtils.checkSplits(c, TABLE_NAME, 0, 0);
FunctionalTestUtils.checkRFiles(c, TABLE_NAME, 1, 1, 100, 100);
-
+
// initiate splits
getConnector().tableOperations().setProperty(TABLE_NAME, Property.TABLE_SPLIT_THRESHOLD.getKey(), "100K");
-
+
UtilWaitThread.sleep(2000);
-
+
// wait until over split threshold
while (getConnector().tableOperations().listSplits(TABLE_NAME).size() < 50) {
UtilWaitThread.sleep(500);
}
-
+
FunctionalTestUtils.checkSplits(c, TABLE_NAME, 50, 100);
VerifyIngest.Opts opts = new VerifyIngest.Opts();
opts.timestamp = 1;
@@ -81,7 +87,7 @@ public class BulkSplitOptimizationIT extends ConfigurableMacIT {
opts.cols = 1;
opts.password = new Password(ROOT_PASSWORD);
VerifyIngest.verifyIngest(c, opts, SOPTS);
-
+
// ensure each tablet does not have all map files
FunctionalTestUtils.checkRFiles(c, TABLE_NAME, 50, 100, 1, 4);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/ClassLoaderIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/ClassLoaderIT.java b/test/src/test/java/org/apache/accumulo/test/functional/ClassLoaderIT.java
index c85c78c..0834b89 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/ClassLoaderIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/ClassLoaderIT.java
@@ -43,7 +43,7 @@ import org.apache.hadoop.fs.Path;
import org.junit.Test;
public class ClassLoaderIT extends SimpleMacIT {
-
+
@Test(timeout = 2 * 60 * 1000)
public void test() throws Exception {
Connector c = getConnector();
@@ -56,7 +56,7 @@ public class ClassLoaderIT extends SimpleMacIT {
scanCheck(c, "Test");
FileSystem fs = FileSystem.get(CachedConfiguration.getInstance());
Path jarPath = new Path(rootPath() + "/lib/Test.jar");
- fs.copyFromLocalFile(new Path(System.getProperty("user.dir")+"/system/auto/TestCombinerX.jar"), jarPath);
+ fs.copyFromLocalFile(new Path(System.getProperty("user.dir") + "/system/auto/TestCombinerX.jar"), jarPath);
UtilWaitThread.sleep(1000);
IteratorSetting is = new IteratorSetting(10, "TestCombiner", "org.apache.accumulo.test.functional.TestCombiner");
Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf")));
@@ -64,7 +64,7 @@ public class ClassLoaderIT extends SimpleMacIT {
UtilWaitThread.sleep(5000);
scanCheck(c, "TestX");
fs.delete(jarPath, true);
- fs.copyFromLocalFile(new Path(System.getProperty("user.dir")+"/system/auto/TestCombinerY.jar"), jarPath);
+ fs.copyFromLocalFile(new Path(System.getProperty("user.dir") + "/system/auto/TestCombinerY.jar"), jarPath);
UtilWaitThread.sleep(5000);
scanCheck(c, "TestY");
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/CleanTmpIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/CleanTmpIT.java b/test/src/test/java/org/apache/accumulo/test/functional/CleanTmpIT.java
index 0216a7a..06ce6ee 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/CleanTmpIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/CleanTmpIT.java
@@ -53,7 +53,7 @@ public class CleanTmpIT extends ConfigurableMacIT {
public void test() throws Exception {
Connector c = getConnector();
// make a table
- String tableName = makeTableName();
+ String tableName = getTableNames(1)[0];
c.tableOperations().create(tableName);
// write to it
BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/CloneTestIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/CloneTestIT.java b/test/src/test/java/org/apache/accumulo/test/functional/CloneTestIT.java
index c238e96..f5c392f 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/CloneTestIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/CloneTestIT.java
@@ -50,143 +50,145 @@ import org.junit.Test;
*
*/
public class CloneTestIT extends SimpleMacIT {
-
+
@Test(timeout = 120 * 1000)
public void testProps() throws Exception {
- String table1 = makeTableName();
- String table2 = makeTableName();
-
+ String[] tableNames = getTableNames(2);
+ String table1 = tableNames[0];
+ String table2 = tableNames[1];
+
Connector c = getConnector();
-
+
c.tableOperations().create(table1);
-
+
c.tableOperations().setProperty(table1, Property.TABLE_FILE_COMPRESSED_BLOCK_SIZE.getKey(), "1M");
c.tableOperations().setProperty(table1, Property.TABLE_FILE_COMPRESSED_BLOCK_SIZE_INDEX.getKey(), "2M");
c.tableOperations().setProperty(table1, Property.TABLE_FILE_MAX.getKey(), "23");
-
+
BatchWriter bw = writeData(table1, c);
-
+
Map<String,String> props = new HashMap<String,String>();
props.put(Property.TABLE_FILE_COMPRESSED_BLOCK_SIZE.getKey(), "500K");
-
+
Set<String> exclude = new HashSet<String>();
exclude.add(Property.TABLE_FILE_MAX.getKey());
-
+
c.tableOperations().clone(table1, table2, true, props, exclude);
-
+
Mutation m3 = new Mutation("009");
m3.put("data", "x", "1");
m3.put("data", "y", "2");
bw.addMutation(m3);
bw.close();
-
+
checkData(table2, c);
-
+
HashMap<String,String> tableProps = new HashMap<String,String>();
for (Entry<String,String> prop : c.tableOperations().getProperties(table2)) {
tableProps.put(prop.getKey(), prop.getValue());
}
-
+
Assert.assertEquals("500K", tableProps.get(Property.TABLE_FILE_COMPRESSED_BLOCK_SIZE.getKey()));
Assert.assertEquals(Property.TABLE_FILE_MAX.getDefaultValue(), tableProps.get(Property.TABLE_FILE_MAX.getKey()));
Assert.assertEquals("2M", tableProps.get(Property.TABLE_FILE_COMPRESSED_BLOCK_SIZE_INDEX.getKey()));
-
+
c.tableOperations().delete(table1);
c.tableOperations().delete(table2);
-
+
}
-
+
private void checkData(String table2, Connector c) throws TableNotFoundException {
Scanner scanner = c.createScanner(table2, Authorizations.EMPTY);
-
+
HashMap<String,String> expected = new HashMap<String,String>();
expected.put("001:x", "9");
expected.put("001:y", "7");
expected.put("008:x", "3");
expected.put("008:y", "4");
-
+
HashMap<String,String> actual = new HashMap<String,String>();
-
+
for (Entry<Key,Value> entry : scanner)
actual.put(entry.getKey().getRowData().toString() + ":" + entry.getKey().getColumnQualifierData().toString(), entry.getValue().toString());
-
+
Assert.assertEquals(expected, actual);
}
-
+
private BatchWriter writeData(String table1, Connector c) throws TableNotFoundException, MutationsRejectedException {
BatchWriter bw = c.createBatchWriter(table1, new BatchWriterConfig());
-
+
Mutation m1 = new Mutation("001");
m1.put("data", "x", "9");
m1.put("data", "y", "7");
-
+
Mutation m2 = new Mutation("008");
m2.put("data", "x", "3");
m2.put("data", "y", "4");
-
+
bw.addMutation(m1);
bw.addMutation(m2);
-
+
bw.flush();
return bw;
}
-
+
@Test(timeout = 120 * 1000)
public void testDeleteClone() throws Exception {
- String table1 = makeTableName();
- String table2 = makeTableName();
- String table3 = makeTableName();
-
+ String[] tableNames = getTableNames(3);
+ String table1 = tableNames[0];
+ String table2 = tableNames[1];
+ String table3 = tableNames[2];
+
Connector c = getConnector();
// verify that deleting a new table removes the files
c.tableOperations().create(table3);
writeData(table3, c).close();
c.tableOperations().flush(table3, null, null, true);
- // check for files
+ // check for files
FileSystem fs = FileSystem.get(new Configuration());
String id = c.tableOperations().tableIdMap().get(table3);
FileStatus[] status = fs.listStatus(new Path(rootPath() + "/accumulo/tables/" + id));
assertTrue(status.length > 0);
- // verify disk usage
+ // verify disk usage
List<DiskUsage> diskUsage = c.tableOperations().getDiskUsage(Collections.singleton(table3));
assertEquals(1, diskUsage.size());
assertTrue(diskUsage.get(0).getUsage() > 100);
- // delete the table
+ // delete the table
c.tableOperations().delete(table3);
- // verify its gone from the file system
+ // verify its gone from the file system
status = fs.listStatus(new Path(rootPath() + "/accumulo/tables/" + id));
assertTrue(status == null || status.length == 0);
c.tableOperations().create(table1);
-
+
BatchWriter bw = writeData(table1, c);
Map<String,String> props = new HashMap<String,String>();
props.put(Property.TABLE_FILE_COMPRESSED_BLOCK_SIZE.getKey(), "500K");
-
+
Set<String> exclude = new HashSet<String>();
exclude.add(Property.TABLE_FILE_MAX.getKey());
-
+
c.tableOperations().clone(table1, table2, true, props, exclude);
-
+
Mutation m3 = new Mutation("009");
m3.put("data", "x", "1");
m3.put("data", "y", "2");
bw.addMutation(m3);
bw.close();
-
+
// delete source table, should not affect clone
c.tableOperations().delete(table1);
-
+
checkData(table2, c);
-
+
c.tableOperations().compact(table2, null, null, true, true);
-
+
checkData(table2, c);
-
+
c.tableOperations().delete(table2);
-
+
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/CombinerIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/CombinerIT.java b/test/src/test/java/org/apache/accumulo/test/functional/CombinerIT.java
index dc4368f..c3a7f38 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/CombinerIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/CombinerIT.java
@@ -38,7 +38,7 @@ import org.apache.accumulo.core.security.Authorizations;
import org.junit.Test;
public class CombinerIT extends SimpleMacIT {
-
+
private void checkSum(String tableName, Connector c) throws Exception {
Scanner s = c.createScanner(tableName, Authorizations.EMPTY);
Iterator<Entry<Key,Value>> i = s.iterator();
@@ -47,11 +47,11 @@ public class CombinerIT extends SimpleMacIT {
assertEquals("45", entry.getValue().toString());
assertFalse(i.hasNext());
}
-
+
@Test(timeout = 60 * 1000)
public void aggregationTest() throws Exception {
Connector c = getConnector();
- String tableName = makeTableName();
+ String tableName = getTableNames(1)[0];
c.tableOperations().create(tableName);
IteratorSetting setting = new IteratorSetting(10, SummingCombiner.class);
SummingCombiner.setEncodingType(setting, Type.STRING);
@@ -66,5 +66,5 @@ public class CombinerIT extends SimpleMacIT {
bw.close();
checkSum(tableName, c);
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/CompactionIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/CompactionIT.java b/test/src/test/java/org/apache/accumulo/test/functional/CompactionIT.java
index a49670e..cba24fd 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/CompactionIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/CompactionIT.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -41,10 +42,15 @@ import org.apache.accumulo.minicluster.MiniAccumuloConfig;
import org.apache.accumulo.server.util.Admin;
import org.apache.accumulo.test.VerifyIngest;
import org.apache.hadoop.fs.FileSystem;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
public class CompactionIT extends ConfigurableMacIT {
-
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+
@Override
public void configure(MiniAccumuloConfig cfg) {
Map<String,String> map = new HashMap<String,String>();
@@ -53,17 +59,17 @@ public class CompactionIT extends ConfigurableMacIT {
map.put(Property.TSERV_MAJC_MAXCONCURRENT.getKey(), "1");
cfg.setSiteConfig(map);
}
-
+
@Test(timeout = 4 * 60 * 1000)
public void test() throws Exception {
final Connector c = getConnector();
c.tableOperations().create("test_ingest");
c.tableOperations().setProperty("test_ingest", Property.TABLE_MAJC_RATIO.getKey(), "1.0");
FileSystem fs = FileSystem.get(CachedConfiguration.getInstance());
- FunctionalTestUtils.createRFiles(c, fs, "tmp/testrf", 500000, 59, 4);
- FunctionalTestUtils.bulkImport(c, fs, "test_ingest", "tmp/testrf");
+ FunctionalTestUtils.createRFiles(c, fs, folder.getRoot() + "/testrf", 500000, 59, 4);
+ FunctionalTestUtils.bulkImport(c, fs, "test_ingest", folder.getRoot() + "/testrf");
int beforeCount = countFiles(c);
-
+
final AtomicBoolean fail = new AtomicBoolean(false);
for (int count = 0; count < 5; count++) {
List<Thread> threads = new ArrayList<Thread>();
@@ -93,12 +99,12 @@ public class CompactionIT extends ConfigurableMacIT {
t.join();
assertFalse(fail.get());
}
-
+
int finalCount = countFiles(c);
assertTrue(finalCount < beforeCount);
assertEquals(0, cluster.exec(Admin.class, "stopAll").waitFor());
}
-
+
private int countFiles(Connector c) throws Exception {
Scanner s = c.createScanner(MetadataTable.NAME, Authorizations.EMPTY);
s.fetchColumnFamily(MetadataSchema.TabletsSection.TabletColumnFamily.NAME);
@@ -109,5 +115,5 @@ public class CompactionIT extends ConfigurableMacIT {
i++;
return i;
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableMacIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableMacIT.java b/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableMacIT.java
index c34fff5..597f385 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableMacIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/ConfigurableMacIT.java
@@ -16,40 +16,65 @@
*/
package org.apache.accumulo.test.functional;
+import java.io.IOException;
+
+import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.ZooKeeperInstance;
+import org.apache.accumulo.core.zookeeper.ZooUtil;
+import org.apache.accumulo.fate.zookeeper.ZooReader;
import org.apache.accumulo.minicluster.MiniAccumuloCluster;
import org.apache.accumulo.minicluster.MiniAccumuloConfig;
import org.apache.log4j.Logger;
+import org.apache.zookeeper.KeeperException;
import org.junit.After;
import org.junit.Before;
-import org.junit.rules.TemporaryFolder;
-import java.io.File;
public class ConfigurableMacIT extends AbstractMacIT {
public static final Logger log = Logger.getLogger(ConfigurableMacIT.class);
-
- public TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+
public MiniAccumuloCluster cluster;
-
+
+ public void configure(MiniAccumuloConfig cfg) {}
+
@Before
public void setUp() throws Exception {
- folder.create();
- MiniAccumuloConfig cfg = new MiniAccumuloConfig(folder.newFolder(this.getClass().getSimpleName()), ROOT_PASSWORD);
+ MiniAccumuloConfig cfg = new MiniAccumuloConfig(createTestDir(this.getClass().getName()), ROOT_PASSWORD);
configure(cfg);
cluster = new MiniAccumuloCluster(cfg);
cluster.start();
}
-
- public void configure(MiniAccumuloConfig cfg) {
- }
-
+
@After
public void tearDown() throws Exception {
- cleanUp(cluster, folder);
+ cleanUp(cluster);
}
- @Override
public MiniAccumuloCluster getCluster() {
return cluster;
}
-
+
+ @Override
+ public Connector getConnector() throws AccumuloException, AccumuloSecurityException {
+ return getCluster().getConnector("root", ROOT_PASSWORD);
+ }
+
+ public Process exec(Class<? extends Object> clazz, String... args) throws IOException {
+ return getCluster().exec(clazz, args);
+ }
+
+ @Override
+ public String rootPath() {
+ return getCluster().getConfig().getDir().getAbsolutePath();
+ }
+
+ public String getMonitor() throws KeeperException, InterruptedException {
+ Instance instance = new ZooKeeperInstance(getCluster().getInstanceName(), getCluster().getZooKeepers());
+ ZooReader zr = new ZooReader(getCluster().getZooKeepers(), 5000);
+ return new String(zr.getData(ZooUtil.getRoot(instance) + Constants.ZMONITOR, null));
+ }
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/ConstraintIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/ConstraintIT.java b/test/src/test/java/org/apache/accumulo/test/functional/ConstraintIT.java
index 56f0c22..1e824f8 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/ConstraintIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/ConstraintIT.java
@@ -40,132 +40,132 @@ import org.apache.hadoop.io.Text;
import org.junit.Test;
public class ConstraintIT extends SimpleMacIT {
-
+
@Test(timeout = 30 * 1000)
public void run() throws Exception {
- String[] tableNames = { makeTableName(), makeTableName(), makeTableName() };
+ String[] tableNames = getTableNames(3);
Connector c = getConnector();
for (String table : tableNames) {
c.tableOperations().create(table);
c.tableOperations().addConstraint(table, NumericValueConstraint.class.getName());
c.tableOperations().addConstraint(table, AlphaNumKeyConstraint.class.getName());
}
-
-// Logger logger = Logger.getLogger(Constants.CORE_PACKAGE_NAME);
- //logger.setLevel(Level.TRACE);
-
+
+ // Logger logger = Logger.getLogger(Constants.CORE_PACKAGE_NAME);
+ // logger.setLevel(Level.TRACE);
+
test1(tableNames[0]);
-
- //logger.setLevel(Level.TRACE);
-
+
+ // logger.setLevel(Level.TRACE);
+
test2(tableNames[1], false);
test2(tableNames[2], true);
}
-
+
private void test1(String tableName) throws Exception {
BatchWriter bw = getConnector().createBatchWriter(tableName, new BatchWriterConfig());
-
+
Mutation mut1 = new Mutation(new Text("r1"));
mut1.put(new Text("cf1"), new Text("cq1"), new Value("123".getBytes()));
-
+
bw.addMutation(mut1);
-
+
// should not throw any exceptions
bw.close();
-
+
bw = getConnector().createBatchWriter(tableName, new BatchWriterConfig());
-
+
// create a mutation with a non numeric value
Mutation mut2 = new Mutation(new Text("r1"));
mut2.put(new Text("cf1"), new Text("cq1"), new Value("123a".getBytes()));
-
+
bw.addMutation(mut2);
-
+
boolean sawMRE = false;
-
+
try {
bw.close();
// should not get here
throw new Exception("Test failed, constraint did not catch bad mutation");
} catch (MutationsRejectedException mre) {
sawMRE = true;
-
+
// verify constraint violation summary
List<ConstraintViolationSummary> cvsl = mre.getConstraintViolationSummaries();
-
+
if (cvsl.size() != 1) {
throw new Exception("Unexpected constraints");
}
-
+
for (ConstraintViolationSummary cvs : cvsl) {
if (!cvs.constrainClass.equals(NumericValueConstraint.class.getName())) {
throw new Exception("Unexpected constraint class " + cvs.constrainClass);
}
-
+
if (cvs.numberOfViolatingMutations != 1) {
throw new Exception("Unexpected # violating mutations " + cvs.numberOfViolatingMutations);
}
}
}
-
+
if (!sawMRE) {
throw new Exception("Did not see MutationsRejectedException");
}
-
+
// verify mutation did not go through
Scanner scanner = getConnector().createScanner(tableName, Authorizations.EMPTY);
scanner.setRange(new Range(new Text("r1")));
-
+
Iterator<Entry<Key,Value>> iter = scanner.iterator();
Entry<Key,Value> entry = iter.next();
-
+
if (!entry.getKey().getRow().equals(new Text("r1")) || !entry.getKey().getColumnFamily().equals(new Text("cf1"))
|| !entry.getKey().getColumnQualifier().equals(new Text("cq1")) || !entry.getValue().equals(new Value("123".getBytes()))) {
throw new Exception("Unexpected key or value " + entry.getKey() + " " + entry.getValue());
}
-
+
if (iter.hasNext()) {
entry = iter.next();
throw new Exception("Unexpected extra key or value " + entry.getKey() + " " + entry.getValue());
}
-
+
// remove the numeric value constraint
getConnector().tableOperations().removeConstraint(tableName, 2);
UtilWaitThread.sleep(1000);
-
+
// now should be able to add a non numeric value
bw = getConnector().createBatchWriter(tableName, new BatchWriterConfig());
bw.addMutation(mut2);
bw.close();
-
+
// verify mutation went through
iter = scanner.iterator();
entry = iter.next();
-
+
if (!entry.getKey().getRow().equals(new Text("r1")) || !entry.getKey().getColumnFamily().equals(new Text("cf1"))
|| !entry.getKey().getColumnQualifier().equals(new Text("cq1")) || !entry.getValue().equals(new Value("123a".getBytes()))) {
throw new Exception("Unexpected key or value " + entry.getKey() + " " + entry.getValue());
}
-
+
if (iter.hasNext()) {
entry = iter.next();
throw new Exception("Unexpected extra key or value " + entry.getKey() + " " + entry.getValue());
}
-
+
// add a constraint that references a non-existant class
getConnector().tableOperations().setProperty(tableName, Property.TABLE_CONSTRAINT_PREFIX + "1", "com.foobar.nonExistantClass");
UtilWaitThread.sleep(1000);
-
+
// add a mutation
bw = getConnector().createBatchWriter(tableName, new BatchWriterConfig());
-
+
Mutation mut3 = new Mutation(new Text("r1"));
mut3.put(new Text("cf1"), new Text("cq1"), new Value("foo".getBytes()));
-
+
bw.addMutation(mut3);
-
+
sawMRE = false;
-
+
try {
bw.close();
// should not get here
@@ -173,60 +173,60 @@ public class ConstraintIT extends SimpleMacIT {
} catch (MutationsRejectedException mre) {
sawMRE = true;
}
-
+
if (!sawMRE) {
throw new Exception("Did not see MutationsRejectedException");
}
-
+
// verify the mutation did not go through
iter = scanner.iterator();
entry = iter.next();
-
+
if (!entry.getKey().getRow().equals(new Text("r1")) || !entry.getKey().getColumnFamily().equals(new Text("cf1"))
|| !entry.getKey().getColumnQualifier().equals(new Text("cq1")) || !entry.getValue().equals(new Value("123a".getBytes()))) {
throw new Exception("Unexpected key or value " + entry.getKey() + " " + entry.getValue());
}
-
+
if (iter.hasNext()) {
entry = iter.next();
throw new Exception("Unexpected extra key or value " + entry.getKey() + " " + entry.getValue());
}
-
+
// remove the bad constraint
getConnector().tableOperations().removeConstraint(tableName, 1);
UtilWaitThread.sleep(1000);
-
+
// try the mutation again
bw = getConnector().createBatchWriter(tableName, new BatchWriterConfig());
bw.addMutation(mut3);
bw.close();
-
+
// verify it went through
iter = scanner.iterator();
entry = iter.next();
-
+
if (!entry.getKey().getRow().equals(new Text("r1")) || !entry.getKey().getColumnFamily().equals(new Text("cf1"))
|| !entry.getKey().getColumnQualifier().equals(new Text("cq1")) || !entry.getValue().equals(new Value("foo".getBytes()))) {
throw new Exception("Unexpected key or value " + entry.getKey() + " " + entry.getValue());
}
-
+
if (iter.hasNext()) {
entry = iter.next();
throw new Exception("Unexpected extra key or value " + entry.getKey() + " " + entry.getValue());
}
}
-
+
private Mutation newMut(String row, String cf, String cq, String val) {
Mutation mut1 = new Mutation(new Text(row));
mut1.put(new Text(cf), new Text(cq), new Value(val.getBytes()));
return mut1;
}
-
+
private void test2(String table, boolean doFlush) throws Exception {
// test sending multiple mutations with multiple constrain violations... all of the non violating mutations
// should go through
int numericErrors = 2;
-
+
BatchWriter bw = getConnector().createBatchWriter(table, new BatchWriterConfig());
bw.addMutation(newMut("r1", "cf1", "cq1", "123"));
bw.addMutation(newMut("r1", "cf1", "cq2", "I'm a bad value"));
@@ -248,64 +248,64 @@ public class ConstraintIT extends SimpleMacIT {
bw.addMutation(newMut("r1", "cf1", "cq3", "I'm a naughty value"));
bw.addMutation(newMut("@bad row@", "cf1", "cq2", "456"));
bw.addMutation(newMut("r1", "cf1", "cq4", "789"));
-
+
boolean sawMRE = false;
-
+
try {
bw.close();
// should not get here
throw new Exception("Test failed, constraint did not catch bad mutation");
} catch (MutationsRejectedException mre) {
System.out.println(mre);
-
+
sawMRE = true;
-
+
// verify constraint violation summary
List<ConstraintViolationSummary> cvsl = mre.getConstraintViolationSummaries();
-
+
if (cvsl.size() != 2) {
throw new Exception("Unexpected constraints");
}
-
+
HashMap<String,Integer> expected = new HashMap<String,Integer>();
-
+
expected.put("org.apache.accumulo.examples.simple.constraints.NumericValueConstraint", numericErrors);
expected.put("org.apache.accumulo.examples.simple.constraints.AlphaNumKeyConstraint", 1);
-
+
for (ConstraintViolationSummary cvs : cvsl) {
if (expected.get(cvs.constrainClass) != cvs.numberOfViolatingMutations) {
throw new Exception("Unexpected " + cvs.constrainClass + " " + cvs.numberOfViolatingMutations);
}
}
}
-
+
if (!sawMRE) {
throw new Exception("Did not see MutationsRejectedException");
}
-
+
Scanner scanner = getConnector().createScanner(table, Authorizations.EMPTY);
-
+
Iterator<Entry<Key,Value>> iter = scanner.iterator();
-
+
Entry<Key,Value> entry = iter.next();
-
+
if (!entry.getKey().getRow().equals(new Text("r1")) || !entry.getKey().getColumnFamily().equals(new Text("cf1"))
|| !entry.getKey().getColumnQualifier().equals(new Text("cq1")) || !entry.getValue().equals(new Value("123".getBytes()))) {
throw new Exception("Unexpected key or value " + entry.getKey() + " " + entry.getValue());
}
-
+
entry = iter.next();
-
+
if (!entry.getKey().getRow().equals(new Text("r1")) || !entry.getKey().getColumnFamily().equals(new Text("cf1"))
|| !entry.getKey().getColumnQualifier().equals(new Text("cq4")) || !entry.getValue().equals(new Value("789".getBytes()))) {
throw new Exception("Unexpected key or value " + entry.getKey() + " " + entry.getValue());
}
-
+
if (iter.hasNext()) {
entry = iter.next();
throw new Exception("Unexpected extra key or value " + entry.getKey() + " " + entry.getValue());
}
-
+
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/CreateAndUseIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/CreateAndUseIT.java b/test/src/test/java/org/apache/accumulo/test/functional/CreateAndUseIT.java
index ba17f88..68a6a2e 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/CreateAndUseIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/CreateAndUseIT.java
@@ -34,57 +34,58 @@ import org.apache.hadoop.io.Text;
import org.junit.Test;
public class CreateAndUseIT extends SimpleMacIT {
-
+
@Test(timeout = 2 * 60 * 1000)
public void run() throws Exception {
SortedSet<Text> splits = new TreeSet<Text>();
-
+
for (int i = 1; i < 256; i++) {
splits.add(new Text(String.format("%08x", i << 8)));
}
-
+
// TEST 1 create a table and immediately batch write to it
-
+
Text cf = new Text("cf1");
Text cq = new Text("cq1");
-
- String tableName = makeTableName();
+
+ String[] tableNames = getTableNames(3);
+ String tableName = tableNames[0];
getConnector().tableOperations().create(tableName);
getConnector().tableOperations().addSplits(tableName, splits);
BatchWriter bw = getConnector().createBatchWriter(tableName, new BatchWriterConfig());
-
+
for (int i = 1; i < 257; i++) {
Mutation m = new Mutation(new Text(String.format("%08x", (i << 8) - 16)));
m.put(cf, cq, new Value(("" + i).getBytes()));
-
+
bw.addMutation(m);
}
-
+
bw.close();
-
+
// verify data is there
Scanner scanner1 = getConnector().createScanner(tableName, Authorizations.EMPTY);
-
+
int ei = 1;
-
+
for (Entry<Key,Value> entry : scanner1) {
if (!entry.getKey().getRow().toString().equals(String.format("%08x", (ei << 8) - 16))) {
throw new Exception("Expected row " + String.format("%08x", (ei << 8) - 16) + " saw " + entry.getKey().getRow());
}
-
+
if (!entry.getValue().toString().equals("" + ei)) {
throw new Exception("Expected value " + ei + " saw " + entry.getValue());
}
-
+
ei++;
}
-
+
if (ei != 257) {
throw new Exception("Did not see expected number of rows, ei = " + ei);
}
-
+
// TEST 2 create a table and immediately scan it
- String table2 = makeTableName();
+ String table2 = tableNames[1];
getConnector().tableOperations().create(table2);
getConnector().tableOperations().addSplits(table2, splits);
Scanner scanner2 = getConnector().createScanner(table2, Authorizations.EMPTY);
@@ -93,19 +94,19 @@ public class CreateAndUseIT extends SimpleMacIT {
if (entry != null)
count++;
}
-
+
if (count != 0) {
throw new Exception("Did not see expected number of entries, count = " + count);
}
-
+
// TEST 3 create a table and immediately batch scan it
-
+
ArrayList<Range> ranges = new ArrayList<Range>();
for (int i = 1; i < 257; i++) {
ranges.add(new Range(new Text(String.format("%08x", (i << 8) - 16))));
}
- String table3 = makeTableName();
+ String table3 = tableNames[2];
getConnector().tableOperations().create(table3);
getConnector().tableOperations().addSplits(table3, splits);
BatchScanner bs = getConnector().createBatchScanner(table3, Authorizations.EMPTY, 3);
@@ -115,13 +116,13 @@ public class CreateAndUseIT extends SimpleMacIT {
if (entry != null)
count++;
}
-
+
if (count != 0) {
throw new Exception("Did not see expected number of entries, count = " + count);
}
-
+
bs.close();
-
+
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/CreateManyScannersIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/CreateManyScannersIT.java b/test/src/test/java/org/apache/accumulo/test/functional/CreateManyScannersIT.java
index 4549d55..0c51f2a 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/CreateManyScannersIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/CreateManyScannersIT.java
@@ -21,15 +21,15 @@ import org.apache.accumulo.core.security.Authorizations;
import org.junit.Test;
public class CreateManyScannersIT extends SimpleMacIT {
-
+
@Test(timeout = 60 * 1000)
public void run() throws Exception {
Connector c = getConnector();
- String tableName = makeTableName();
+ String tableName = getTableNames(1)[0];
c.tableOperations().create(tableName);
for (int i = 0; i < 100000; i++) {
c.createScanner(tableName, Authorizations.EMPTY);
}
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/DeleteRowsIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/DeleteRowsIT.java b/test/src/test/java/org/apache/accumulo/test/functional/DeleteRowsIT.java
index e6c0446..3ab2768 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/DeleteRowsIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/DeleteRowsIT.java
@@ -40,7 +40,7 @@ import org.junit.Test;
public class DeleteRowsIT extends SimpleMacIT {
private static final Logger log = Logger.getLogger(DeleteRowsIT.class);
-
+
private static final int ROWS_PER_TABLET = 10;
private static final String[] LETTERS = new String[] {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
"u", "v", "w", "x", "y", "z"};
@@ -56,13 +56,13 @@ public class DeleteRowsIT extends SimpleMacIT {
ROWS.add("A");
ROWS.add("{");
}
-
+
@Test(timeout = 10 * 60 * 1000)
public void test() throws Exception {
// Delete ranges of rows, and verify the tablets are removed.
int i = 0;
// Eliminate whole tablets
- String tableName = makeTableName();
+ String tableName = getTableNames(1)[0];
testSplit(tableName + i++, "f", "h", "abcdefijklmnopqrstuvwxyz", 260);
// Eliminate whole tablets, partial first tablet
testSplit(tableName + i++, "f1", "h", "abcdeff1ijklmnopqrstuvwxyz", 262);
@@ -89,7 +89,7 @@ public class DeleteRowsIT extends SimpleMacIT {
// Delete everything
testSplit(tableName + i++, null, null, "", 0);
}
-
+
private void testSplit(String table, String start, String end, String result, int entries) throws Exception {
// Put a bunch of rows on each tablet
Connector c = getConnector();
@@ -106,7 +106,7 @@ public class DeleteRowsIT extends SimpleMacIT {
bw.close();
// Split the table
c.tableOperations().addSplits(table, SPLITS);
-
+
Text startText = start == null ? null : new Text(start);
Text endText = end == null ? null : new Text(end);
c.tableOperations().deleteRows(table, startText, endText);
@@ -128,5 +128,5 @@ public class DeleteRowsIT extends SimpleMacIT {
log.info("Finished table " + table);
assertEquals(entries, count);
}
-
+
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/DeleteRowsSplitIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/DeleteRowsSplitIT.java b/test/src/test/java/org/apache/accumulo/test/functional/DeleteRowsSplitIT.java
index fae52d0..a08aa2c 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/DeleteRowsSplitIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/DeleteRowsSplitIT.java
@@ -39,9 +39,9 @@ import org.junit.Test;
// attempt to reproduce ACCUMULO-315
public class DeleteRowsSplitIT extends SimpleMacIT {
-
+
private static final Logger log = Logger.getLogger(DeleteRowsSplitIT.class);
-
+
private static final String LETTERS = "abcdefghijklmnopqrstuvwxyz";
static final SortedSet<Text> SPLITS = new TreeSet<Text>();
static final List<String> ROWS = new ArrayList<String>();
@@ -51,27 +51,27 @@ public class DeleteRowsSplitIT extends SimpleMacIT {
ROWS.add(new String(new byte[] {b}));
}
}
-
+
@Test(timeout = 4 * 60 * 1000)
public void run() throws Exception {
// Delete ranges of rows, and verify the are removed
// Do this while adding many splits
- final String tableName = makeTableName();
-
+ final String tableName = getTableNames(1)[0];
+
// Eliminate whole tablets
for (int test = 0; test < 10; test++) {
// create a table
log.info("Test " + test);
getConnector().tableOperations().create(tableName);
-
+
// put some data in it
fillTable(tableName);
-
+
// generate a random delete range
final Text start = new Text();
final Text end = new Text();
generateRandomRange(start, end);
-
+
// initiate the delete range
final boolean fail[] = {false};
Thread t = new Thread() {
@@ -90,28 +90,28 @@ public class DeleteRowsSplitIT extends SimpleMacIT {
}
};
t.start();
-
+
UtilWaitThread.sleep(test * 2);
-
+
getConnector().tableOperations().deleteRows(tableName, start, end);
-
+
t.join();
synchronized (fail) {
assertTrue(!fail[0]);
}
-
+
// scan the table
Scanner scanner = getConnector().createScanner(tableName, Authorizations.EMPTY);
for (Entry<Key,Value> entry : scanner) {
Text row = entry.getKey().getRow();
assertTrue(row.compareTo(start) <= 0 || row.compareTo(end) > 0);
}
-
+
// delete the table
getConnector().tableOperations().delete(tableName);
}
}
-
+
private void generateRandomRange(Text start, Text end) {
List<String> bunch = new ArrayList<String>(ROWS);
Collections.shuffle(bunch);
@@ -122,9 +122,9 @@ public class DeleteRowsSplitIT extends SimpleMacIT {
start.set(bunch.get(1));
end.set(bunch.get(0));
}
-
+
}
-
+
private void fillTable(String table) throws Exception {
BatchWriter bw = getConnector().createBatchWriter(table, new BatchWriterConfig());
for (String row : ROWS) {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/aa711023/test/src/test/java/org/apache/accumulo/test/functional/FateStarvationIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/FateStarvationIT.java b/test/src/test/java/org/apache/accumulo/test/functional/FateStarvationIT.java
index e58931d..cf16105 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/FateStarvationIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/FateStarvationIT.java
@@ -30,15 +30,15 @@ import org.junit.Test;
* See ACCUMULO-779
*/
public class FateStarvationIT extends SimpleMacIT {
-
+
@Test(timeout = 2 * 60 * 1000)
public void run() throws Exception {
- String tableName = makeTableName();
+ String tableName = getTableNames(1)[0];
Connector c = getConnector();
c.tableOperations().create(tableName);
-
+
c.tableOperations().addSplits(tableName, TestIngest.getSplitPoints(0, 100000, 50));
-
+
TestIngest.Opts opts = new TestIngest.Opts();
opts.random = 89;
opts.timestamp = 7;
@@ -47,20 +47,20 @@ public class FateStarvationIT extends SimpleMacIT {
opts.cols = 1;
opts.tableName = tableName;
TestIngest.ingest(c, opts, new BatchWriterOpts());
-
+
c.tableOperations().flush(tableName, null, null, true);
-
+
List<Text> splits = new ArrayList<Text>(TestIngest.getSplitPoints(0, 100000, 67));
Random rand = new Random();
-
+
for (int i = 0; i < 100; i++) {
int idx1 = rand.nextInt(splits.size() - 1);
int idx2 = rand.nextInt(splits.size() - (idx1 + 1)) + idx1 + 1;
-
+
c.tableOperations().compact(tableName, splits.get(idx1), splits.get(idx2), false, false);
}
-
+
c.tableOperations().offline(tableName);
}
-
+
}