Author: ecn
Date: Wed Jan  9 16:31:52 2013
New Revision: 1430938

URL: http://svn.apache.org/viewvc?rev=1430938&view=rev
Log:
ACCUMULO-843 implement deleteRows in MockAccumulo, fake locality groups, ignore 
merge requests

Modified:
    
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java
    
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
    
accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java

Modified: 
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java
URL: 
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java?rev=1430938&r1=1430937&r2=1430938&view=diff
==============================================================================
--- 
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java
 (original)
+++ 
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockTable.java
 Wed Jan  9 16:31:52 2013
@@ -20,9 +20,11 @@ import java.util.Collection;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
 import java.util.Map.Entry;
 import java.util.SortedMap;
 import java.util.SortedSet;
+import java.util.TreeMap;
 import java.util.TreeSet;
 import java.util.concurrent.ConcurrentSkipListMap;
 
@@ -86,6 +88,7 @@ public class MockTable {
   Map<String,EnumSet<TablePermission>> userPermissions = new 
HashMap<String,EnumSet<TablePermission>>();
   private TimeType timeType;
   SortedSet<Text> splits = new TreeSet<Text>();
+  Map<String,Set<Text>> localityGroups = new TreeMap<String, Set<Text>>();
   
   MockTable(boolean limitVersion, TimeType timeType) {
     this.timeType = timeType;
@@ -122,4 +125,11 @@ public class MockTable {
   public Collection<Text> getSplits() {
     return splits;
   }
+  
+  public void setLocalityGroups(Map<String,Set<Text>> groups) {
+    localityGroups = groups;
+  }
+  public Map<String,Set<Text>> getLocalityGroups() {
+    return localityGroups;
+  }
 }

Modified: 
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
URL: 
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java?rev=1430938&r1=1430937&r2=1430938&view=diff
==============================================================================
--- 
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
 (original)
+++ 
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockTableOperations.java
 Wed Jan  9 16:31:52 2013
@@ -40,6 +40,7 @@ import org.apache.accumulo.core.client.a
 import org.apache.accumulo.core.conf.AccumuloConfiguration;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.PartialKey;
 import org.apache.accumulo.core.data.Range;
 import org.apache.accumulo.core.data.Value;
 import org.apache.accumulo.core.file.FileOperations;
@@ -155,17 +156,23 @@ public class MockTableOperations extends
   
   @Override
   public void setLocalityGroups(String tableName, Map<String,Set<Text>> 
groups) throws AccumuloException, AccumuloSecurityException, 
TableNotFoundException {
-    throw new NotImplementedException();
+    if (!exists(tableName))
+      throw new TableNotFoundException(tableName, tableName, "");
+    acu.tables.get(tableName).setLocalityGroups(groups);
   }
   
   @Override
   public Map<String,Set<Text>> getLocalityGroups(String tableName) throws 
AccumuloException, TableNotFoundException {
-    throw new NotImplementedException();
+    if (!exists(tableName))
+      throw new TableNotFoundException(tableName, tableName, "");
+    return acu.tables.get(tableName).getLocalityGroups();
   }
   
   @Override
   public Set<Range> splitRangeByTablets(String tableName, Range range, int 
maxSplits) throws AccumuloException, AccumuloSecurityException,
       TableNotFoundException {
+    if (!exists(tableName))
+      throw new TableNotFoundException(tableName, tableName, "");
     return Collections.singleton(range);
   }
   
@@ -262,15 +269,20 @@ public class MockTableOperations extends
   
   @Override
   public void offline(String tableName) throws AccumuloSecurityException, 
AccumuloException {
-    throw new NotImplementedException();
+    if (!exists(tableName))
+      throw new AccumuloException(tableName + " does not exists");
   }
   
   @Override
-  public void online(String tableName) throws AccumuloSecurityException, 
AccumuloException {}
+  public void online(String tableName) throws AccumuloSecurityException, 
AccumuloException {
+    if (!exists(tableName))
+      throw new AccumuloException(tableName + " does not exists");
+  }
   
   @Override
   public void clearLocatorCache(String tableName) throws 
TableNotFoundException {
-    throw new NotImplementedException();
+    if (!exists(tableName))
+      throw new TableNotFoundException(tableName, tableName, "");
   }
   
   @Override
@@ -284,24 +296,31 @@ public class MockTableOperations extends
   
   @Override
   public void merge(String tableName, Text start, Text end) throws 
AccumuloException, AccumuloSecurityException, TableNotFoundException {
-    throw new NotImplementedException();
-  }
+    if (!exists(tableName))
+      throw new TableNotFoundException(tableName, tableName, "");
+}
   
   @Override
   public void deleteRows(String tableName, Text start, Text end) throws 
AccumuloException, AccumuloSecurityException, TableNotFoundException {
-    throw new NotImplementedException();
+    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());
+    t.table.keySet().removeAll(keep);
   }
   
   @Override
   public void compact(String tableName, Text start, Text end, boolean flush, 
boolean wait) throws AccumuloSecurityException, TableNotFoundException,
       AccumuloException {
-    throw new NotImplementedException();
+    if (!exists(tableName))
+      throw new TableNotFoundException(tableName, tableName, "");
   }
   
   @Override
   public void compact(String tableName, Text start, Text end, 
List<IteratorSetting> iterators, boolean flush, boolean wait) throws 
AccumuloSecurityException,
       TableNotFoundException, AccumuloException {
-    throw new NotImplementedException();
+    if (!exists(tableName))
+      throw new TableNotFoundException(tableName, tableName, "");
   }
   
   @Override
@@ -312,8 +331,9 @@ public class MockTableOperations extends
   
   @Override
   public void flush(String tableName, Text start, Text end, boolean wait) 
throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
-    throw new NotImplementedException();
-  }
+    if (!exists(tableName))
+      throw new TableNotFoundException(tableName, tableName, "");
+ }
   
   @Override
   public Text getMaxRow(String tableName, Authorizations auths, Text startRow, 
boolean startInclusive, Text endRow, boolean endInclusive)

Modified: 
accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java
URL: 
http://svn.apache.org/viewvc/accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java?rev=1430938&r1=1430937&r2=1430938&view=diff
==============================================================================
--- 
accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java
 (original)
+++ 
accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mock/MockTableOperationsTest.java
 Wed Jan  9 16:31:52 2013
@@ -58,6 +58,7 @@ import org.apache.accumulo.core.util.Pai
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.io.Text;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -249,7 +250,7 @@ public class MockTableOperationsTest {
         testFiles.importPath.toString(), testFiles.failurePath.toString(),
         false);
   }
-
+  
   @Test(expected = IOException.class)
   public void testFailsWithNonEmptyFailureDirectory() throws Throwable {
     Instance instance = new MockInstance("foo");
@@ -264,4 +265,26 @@ public class MockTableOperationsTest {
         false);
   }
   
+  @Test
+  public void testDeleteRows() throws Exception {
+    Instance instance = new MockInstance("rows");
+    Connector connector = instance.getConnector("user", "foo");
+    TableOperations to = connector.tableOperations();
+    to.create("test");
+    BatchWriter bw = connector.createBatchWriter("test", new 
BatchWriterConfig());
+    for (int r = 0; r < 20; r++) {
+      Mutation m = new Mutation("" + r);
+      for (int c = 0; c < 5; c++) {
+        m.put(new Text("cf"), new Text("" + c), new Value(("" + 
c).getBytes()));
+      }
+      bw.addMutation(m);
+    }
+    bw.flush();
+    to.deleteRows("test", new Text("1"), new Text("2"));
+    Scanner s = connector.createScanner("test", Constants.NO_AUTHS);
+    for (Entry<Key, Value> entry : s) {
+      Assert.assertTrue(entry.getKey().getRow().toString().charAt(0) != '1');
+    }
+  }
+  
 }


Reply via email to