You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by el...@apache.org on 2014/04/29 18:25:09 UTC

[3/9] git commit: ACCUMULO-2748 added logic to handle null keys for MockTableOperations.deleteRow

ACCUMULO-2748 added logic to handle null keys for MockTableOperations.deleteRow

Signed-off-by: Josh Elser <el...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/ff8c2383
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/ff8c2383
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/ff8c2383

Branch: refs/heads/master
Commit: ff8c2383bbd394dadffa669518da53e37d0122e5
Parents: 708ad54
Author: Michael Fagan <mf...@eitccorp.com>
Authored: Mon Apr 28 21:42:15 2014 -0600
Committer: Josh Elser <el...@apache.org>
Committed: Tue Apr 29 11:41:07 2014 -0400

----------------------------------------------------------------------
 .../core/client/mock/MockTableOperations.java   |  4 +-
 .../client/mock/MockTableOperationsTest.java    | 59 +++++++++++++++++++-
 2 files changed, 60 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/ff8c2383/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
index dc4a619..64f8225 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
@@ -314,8 +314,8 @@ public class MockTableOperations extends TableOperationsHelper {
     if (!exists(tableName))
       throw new TableNotFoundException(tableName, tableName, "");
     MockTable t = acu.tables.get(tableName);
-    Text startText = new Text(start);
-    Text endText = new Text(end);
+    Text startText = start != null ? new Text(start) : new Text();
+    Text endText = end != null ? new Text(end) : new Text(t.table.lastKey().getRow().getBytes());
     startText.append(ZERO, 0, 1);
     endText.append(ZERO, 0, 1);
     Set<Key> keep = new TreeSet<Key>(t.table.subMap(new Key(startText), new Key(endText)).keySet());

http://git-wip-us.apache.org/repos/asf/accumulo/blob/ff8c2383/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java b/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java
index e377884..ea916e7 100644
--- a/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java
@@ -275,5 +275,62 @@ public class MockTableOperationsTest {
     }
     Assert.assertEquals(5, oneCnt);
   }
-  
+
+  @Test
+  public void testDeleteRowsWithNullKeys() throws Exception {
+    Instance instance = new MockInstance("rows");
+    Connector connector = instance.getConnector("user", new PasswordToken("foo"));
+    TableOperations to = connector.tableOperations();
+    to.create("test2");
+    BatchWriter bw = connector.createBatchWriter("test2", new BatchWriterConfig());
+    for (int r = 0; r < 30; r++) {
+      Mutation m = new Mutation(Integer.toString(r));
+      for (int c = 0; c < 5; c++) {
+        m.put(new Text("cf"), new Text(Integer.toString(c)), new Value(Integer.toString(c).getBytes()));
+      }
+      bw.addMutation(m);
+    }
+    bw.flush();
+
+    // test null end
+    // will remove rows 4 through 9 (6 * 5 = 30 entries)
+    to.deleteRows("test2", new Text("30"), null);
+    Scanner s = connector.createScanner("test2", Constants.NO_AUTHS);
+    int rowCnt = 0;
+    for (Entry<Key,Value> entry : s) {
+      String rowId = entry.getKey().getRow().toString();
+      Assert.assertFalse(rowId.startsWith("30"));
+      rowCnt++;
+    }
+    s.close();
+    Assert.assertEquals(120, rowCnt);
+
+    // test null start
+    // will remove 0-1, 10-19, 2
+    to.deleteRows("test2", null, new Text("2"));
+    s = connector.createScanner("test2", Constants.NO_AUTHS);
+    rowCnt = 0;
+    for (Entry<Key,Value> entry : s) {
+      char rowStart = entry.getKey().getRow().toString().charAt(0);
+      Assert.assertTrue(rowStart >= '2');
+      rowCnt++;
+    }
+    s.close();
+    Assert.assertEquals(55, rowCnt);
+
+    // test null start and end
+    // deletes everything still left
+    to.deleteRows("test2", null, null);
+    s = connector.createScanner("test2", Constants.NO_AUTHS);
+    rowCnt = 0;
+    for (@SuppressWarnings("unused")
+    Entry<Key,Value> entry : s) {
+      rowCnt++;
+    }
+    s.close();
+    to.delete("test2");
+    Assert.assertEquals(0, rowCnt);
+
+  }
+
 }