You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by "Mike Fagan (JIRA)" <ji...@apache.org> on 2014/03/25 03:40:43 UTC

[jira] [Updated] (ACCUMULO-2544) Incorrect boundry matching for MockTableOperations.deleteRows

     [ https://issues.apache.org/jira/browse/ACCUMULO-2544?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mike Fagan updated ACCUMULO-2544:
---------------------------------

    Fix Version/s: 1.6.0
           Labels: mock newbie patch  (was: )
           Status: Patch Available  (was: Open)

>From d35862f4dae9da6746b6195da73e21a01d6b324a Mon Sep 17 00:00:00 2001
From: Michael Fagan <mf...@arcus-research.com>
Date: Mon, 24 Mar 2014 20:27:57 -0600
Subject: [PATCH] ACCUMULO-2544 - fix match boundaries for
 MockTableOperations.deleteRows to be consistent with actual accumulo instance

---
 .../org/apache/accumulo/core/client/mock/MockTableOperations.java | 8 +++++++-
 .../apache/accumulo/core/client/mock/MockTableOperationsTest.java | 2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)

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 cc6bce7..047dcc4 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
@@ -372,7 +372,13 @@ public class MockTableOperations extends TableOperationsHelper {
     if (!exists(tableName))
       throw new TableNotFoundException(tableName, tableName, "");
     MockTable t = acu.tables.get(tableName);
-    Set<Key> keep = new TreeSet<Key>(t.table.tailMap(new Key(start)).headMap(new Key(end)).keySet());
+    byte[] zero = { 0 };
+    Text startText = new Text(start);
+    Text endText = new Text(end);
+    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());
     t.table.keySet().removeAll(keep);
   }

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 216b3ba..42ae119 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
@@ -268,7 +268,7 @@ public class MockTableOperationsTest {
     to.deleteRows("test", new Text("1"), new Text("2"));
     Scanner s = connector.createScanner("test", Authorizations.EMPTY);
     for (Entry<Key,Value> entry : s) {
-      Assert.assertTrue(entry.getKey().getRow().toString().charAt(0) != '1');
+      Assert.assertTrue(entry.getKey().getRow().toString().charAt(0) != '2');
     }
   }

--
1.8.5.2 (Apple Git-48)



> Incorrect boundry matching for MockTableOperations.deleteRows
> -------------------------------------------------------------
>
>                 Key: ACCUMULO-2544
>                 URL: https://issues.apache.org/jira/browse/ACCUMULO-2544
>             Project: Accumulo
>          Issue Type: Bug
>          Components: test
>    Affects Versions: 1.6.1
>         Environment: Mac OS Mavericks; java 7
>            Reporter: Mike Fagan
>              Labels: patch, newbie, mock
>             Fix For: 1.6.0
>
>
> The api for deleteRows specifies: Delete rows between (start, end] but the current implementation for MockTableOperations.deleteRows is implemented as (start, end)
> Here is the failing test case
> public class TestDelete {
>   private static final String INSTANCE = "mock";
>   private static final String TABLE = "foo";
>   private static final String USER = "user";
>   private static final String PASS = "password";
>   private static final Authorizations AUTHS = new Authorizations();
>   @Test
>   public void testDelete() throws TableNotFoundException, AccumuloException,
>       AccumuloSecurityException, TableExistsException {
>     MockInstance mockAcc = new MockInstance(INSTANCE);
>     Connector conn = mockAcc.getConnector(USER, new PasswordToken(PASS));
>     conn.tableOperations().create(TABLE);
>     conn.securityOperations().grantTablePermission(USER, TABLE, TablePermission.READ);
>     conn.securityOperations().grantTablePermission(USER, TABLE, TablePermission.WRITE);
>     Mutation mut = new Mutation("2");
>     mut.put("colfam", "colqual", "value");
>     BatchWriter writer = conn.createBatchWriter(TABLE, new BatchWriterConfig());
>     writer.addMutation(mut);
>     Scanner scan = conn.createScanner(TABLE, AUTHS);
>     scan.setRange(new Range("2", "2"));
>     assertEquals(1, countRecords(scan));
>     
>     // this should delete (1,2] 
>     conn.tableOperations().deleteRows(TABLE, new Text("1"), new Text("2"));
>     scan = conn.createScanner(TABLE, AUTHS);
>     scan.setRange(new Range("2", "2"));
>     
>     // this will fail if row 2 exists
>     assertEquals(0, countRecords(scan));
>   }
>   private int countRecords(Scanner scan) {
>     int cnt = 0;
>     for (Entry<Key, Value> entry : scan) {
>       cnt++;
>     }
>     scan.close();
>     return cnt;
>   }
> }



--
This message was sent by Atlassian JIRA
(v6.2#6252)