incubator-accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bil...@apache.org
Subject svn commit: r1207638 - in /incubator/accumulo/branches/1.4/src/core/src: main/java/org/apache/accumulo/core/iterators/user/SummingArrayCombiner.java test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java
Date Mon, 28 Nov 2011 21:47:27 GMT
Author: billie
Date: Mon Nov 28 21:47:26 2011
New Revision: 1207638

URL: http://svn.apache.org/viewvc?rev=1207638&view=rev
Log:
ACCUMULO-167 expanded test for SummingArrayCombiner, fixed bug in its initialization

Modified:
    incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/SummingArrayCombiner.java
    incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java

Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/SummingArrayCombiner.java
URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/SummingArrayCombiner.java?rev=1207638&r1=1207637&r2=1207638&view=diff
==============================================================================
--- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/SummingArrayCombiner.java
(original)
+++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/SummingArrayCombiner.java
Mon Nov 28 21:47:26 2011
@@ -43,11 +43,11 @@ import org.apache.hadoop.io.WritableUtil
 public class SummingArrayCombiner extends TypedValueCombiner<List<Long>> {
   private static final String TYPE = "type";
   private static final String CLASS_PREFIX = "class:";
-
+  
   public static enum Type {
     VARNUM, LONG, STRING
   }
-
+  
   @Override
   public List<Long> typedReduce(Key key, Iterator<List<Long>> iter) {
     List<Long> sum = new ArrayList<Long>();
@@ -88,7 +88,7 @@ public class SummingArrayCombiner extend
             type.substring(CLASS_PREFIX.length()), Encoder.class);
         encoder = clazz.newInstance();
         List<Long> testList = encoder.decode(encoder.encode(Arrays.asList(0l, 1l)));
-        if (testList.size() != 3 || testList.get(0) != 0l || testList.get(1) != 1l) {
+        if (testList.size() != 2 || testList.get(0) != 0l || testList.get(1) != 1l) {
           throw new IllegalArgumentException("something wrong with " + type + " -- doesn't
encode and decode a List<Long> properly");
         }
       } catch (ClassNotFoundException e) {
@@ -236,7 +236,7 @@ public class SummingArrayCombiner extend
    * @param is
    *          IteratorSetting object to configure.
    * @param encoderClass
-   *          Class<? extends Encoder<Long>> specifying the encoding type.
+   *          Class<? extends Encoder<List<Long>>> specifying the encoding
type.
    */
   public static void setEncodingType(IteratorSetting is, Class<? extends Encoder<List<Long>>>
encoderClass) {
     is.addOption(TYPE, CLASS_PREFIX + encoderClass.getName());

Modified: incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java
URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java?rev=1207638&r1=1207637&r2=1207638&view=diff
==============================================================================
--- incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java
(original)
+++ incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java
Mon Nov 28 21:47:26 2011
@@ -370,7 +370,7 @@ public class CombinerTest {
     IteratorSetting is = new IteratorSetting(1, SummingCombiner.class);
     LongCombiner.setEncodingType(is, StringEncoder.class);
     Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
-
+    
     List<SortedKeyValueIterator<Key,Value>> sources = new ArrayList<SortedKeyValueIterator<Key,Value>>(3);
     sources.add(new SortedMapIterator(tm1));
     sources.add(new SortedMapIterator(tm2));
@@ -529,7 +529,10 @@ public class CombinerTest {
       assertEquals(a[i], b[i]);
   }
   
-  public static void sumArray(Encoder<List<Long>> encoder, String type) throws
IOException {
+  public static void sumArray(Class<? extends Encoder<List<Long>>> encoderClass,
String type) throws IOException, InstantiationException,
+      IllegalAccessException {
+    Encoder<List<Long>> encoder = encoderClass.newInstance();
+    
     TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>();
     
     // keys that aggregate
@@ -539,8 +542,38 @@ public class CombinerTest {
     
     Combiner ai = new SummingArrayCombiner();
     
-    IteratorSetting is = new IteratorSetting(1, SummingCombiner.class);
-    LongCombiner.setEncodingType(is, SummingCombiner.Type.valueOf(type));
+    IteratorSetting is = new IteratorSetting(1, SummingArrayCombiner.class);
+    SummingArrayCombiner.setEncodingType(is, SummingArrayCombiner.Type.valueOf(type));
+    Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
+    
+    ai.init(new SortedMapIterator(tm1), is.getProperties(), null);
+    ai.seek(new Range(), EMPTY_COL_FAMS, false);
+    
+    assertTrue(ai.hasTop());
+    assertEquals(nk(1, 1, 1, 3), ai.getTopKey());
+    assertBytesEqual(encoder.encode(nal(4l, 6l, 5l)), ai.getTopValue().get());
+    
+    ai.next();
+    
+    assertFalse(ai.hasTop());
+    
+    is.clearOptions();
+    SummingArrayCombiner.setEncodingType(is, encoderClass);
+    Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
+    
+    ai.init(new SortedMapIterator(tm1), is.getProperties(), null);
+    ai.seek(new Range(), EMPTY_COL_FAMS, false);
+    
+    assertTrue(ai.hasTop());
+    assertEquals(nk(1, 1, 1, 3), ai.getTopKey());
+    assertBytesEqual(encoder.encode(nal(4l, 6l, 5l)), ai.getTopValue().get());
+    
+    ai.next();
+    
+    assertFalse(ai.hasTop());
+    
+    is.clearOptions();
+    SummingArrayCombiner.setEncodingType(is, encoderClass.getName());
     Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
     
     ai.init(new SortedMapIterator(tm1), is.getProperties(), null);
@@ -556,12 +589,9 @@ public class CombinerTest {
   }
   
   @Test
-  public void sumArrayTest() throws IOException {
-    Encoder<List<Long>> encoder = new SummingArrayCombiner.VarNumArrayEncoder();
-    sumArray(encoder, "VARNUM");
-    encoder = new SummingArrayCombiner.LongArrayEncoder();
-    sumArray(encoder, "LONG");
-    encoder = new SummingArrayCombiner.StringArrayEncoder();
-    sumArray(encoder, "STRING");
+  public void sumArrayTest() throws IOException, InstantiationException, IllegalAccessException
{
+    sumArray(SummingArrayCombiner.VarNumArrayEncoder.class, "VARNUM");
+    sumArray(SummingArrayCombiner.LongArrayEncoder.class, "LONG");
+    sumArray(SummingArrayCombiner.StringArrayEncoder.class, "STRING");
   }
 }



Mime
View raw message