Author: afuchs
Date: Wed Oct 10 14:27:11 2012
New Revision: 1396616

URL: http://svn.apache.org/viewvc?rev=1396616&view=rev
Log:
ACCUMULO-794 added unit test to detect condition

Added:
    
accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowIteratorTest.java
Modified:
    
accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/FirstEntryInRowIterator.java

Modified: 
accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/FirstEntryInRowIterator.java
URL: 
http://svn.apache.org/viewvc/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/FirstEntryInRowIterator.java?rev=1396616&r1=1396615&r2=1396616&view=diff
==============================================================================
--- 
accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/FirstEntryInRowIterator.java
 (original)
+++ 
accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/FirstEntryInRowIterator.java
 Wed Oct 10 14:27:11 2012
@@ -33,7 +33,7 @@ import org.apache.hadoop.io.Text;
 public class FirstEntryInRowIterator extends SkippingIterator implements 
OptionDescriber {
   
   // options
-  private static final String NUM_SCANS_STRING_NAME = "scansBeforeSeek";
+  static final String NUM_SCANS_STRING_NAME = "scansBeforeSeek";
   
   // iterator predecessor seek options to pass through
   private Range latestRange;

Added: 
accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowIteratorTest.java
URL: 
http://svn.apache.org/viewvc/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowIteratorTest.java?rev=1396616&view=auto
==============================================================================
--- 
accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowIteratorTest.java
 (added)
+++ 
accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowIteratorTest.java
 Wed Oct 10 14:27:11 2012
@@ -0,0 +1,94 @@
+package org.apache.accumulo.core.iterators;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.TreeMap;
+
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
+import org.apache.accumulo.core.data.Key;
+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.iterators.IteratorUtil.IteratorScope;
+import org.apache.accumulo.core.iterators.system.CountingIterator;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class FirstEntryInRowIteratorTest {
+
+  @SuppressWarnings("unchecked")
+    private static long process(TreeMap<Key,Value> sourceMap, 
TreeMap<Key,Value> resultMap, Range range, int numScans) throws IOException
+    {
+      org.apache.accumulo.core.iterators.SortedMapIterator source = new 
SortedMapIterator(sourceMap);
+      CountingIterator counter = new CountingIterator(source);
+      FirstEntryInRowIterator feiri = new FirstEntryInRowIterator();
+      IteratorEnvironment env = new IteratorEnvironment(){
+
+        public AccumuloConfiguration getConfig() {
+          return null;
+        }
+
+        public IteratorScope getIteratorScope() {
+          return null;
+        }
+
+        public boolean isFullMajorCompaction() {
+          return false;
+        }
+
+        public void registerSideChannel(SortedKeyValueIterator<Key, Value> 
arg0) {
+
+        }
+
+        public SortedKeyValueIterator<Key, Value> reserveMapFileReader(
+            String arg0) throws IOException {
+          return null;
+        }};
+
+        feiri.init(counter, 
Collections.singletonMap(FirstEntryInRowIterator.NUM_SCANS_STRING_NAME, 
Integer.toString(numScans)), env);
+
+        feiri.seek(range, Collections.EMPTY_SET, false);
+        while(feiri.hasTop())
+        {
+          resultMap.put(feiri.getTopKey(), feiri.getTopValue());
+          feiri.next();
+        }
+        return counter.getCount();
+    }
+
+  @Test
+    public void test() throws IOException {
+      TreeMap<Key,Value> sourceMap = new TreeMap<Key, Value>();
+      Value emptyValue = new Value("".getBytes());
+      sourceMap.put(new Key("r1","cf","cq"), emptyValue);
+      sourceMap.put(new Key("r2","cf","cq"), emptyValue);
+      sourceMap.put(new Key("r3","cf","cq"), emptyValue);
+      TreeMap<Key,Value> resultMap = new TreeMap<Key,Value>();
+      long numSourceEntries = sourceMap.size();
+      long numNexts = process(sourceMap,resultMap,new Range(),10);
+      assertEquals(numNexts, numSourceEntries);
+      assertEquals(sourceMap.size(),resultMap.size());
+
+      for(int i = 0; i < 20; i++)
+      {
+        sourceMap.put(new Key("r2","cf","cq"+i),emptyValue);
+      }
+      resultMap.clear();
+      numNexts = process(sourceMap,resultMap,new Range(new Key("r1"), (new 
Key("r2")).followingKey(PartialKey.ROW)),10);
+      assertEquals(numNexts,resultMap.size()+10);
+      assertEquals(resultMap.size(),2);
+
+      resultMap.clear();
+      numNexts = process(sourceMap,resultMap,new Range(new Key("r1"), new 
Key("r2","cf2")),10);
+      assertEquals(numNexts,resultMap.size()+10);
+      assertEquals(resultMap.size(),2);
+
+      resultMap.clear();
+      numNexts = process(sourceMap,resultMap,new Range(new Key("r1"), new 
Key("r4")),10);
+      assertEquals(numNexts,resultMap.size()+10);
+      assertEquals(resultMap.size(),3);
+    }
+
+}
+


Reply via email to