You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by md...@apache.org on 2014/03/13 21:17:49 UTC
[2/3] git commit: ACCUMULO-2465 Unit tests for BigDecimalCombiner
ACCUMULO-2465 Unit tests for BigDecimalCombiner
Add tests for min and max. Refactor setup into @Before method.
Add keys that won't combine to make sure all values are still correct.
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/b66ee24c
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/b66ee24c
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/b66ee24c
Branch: refs/heads/master
Commit: b66ee24cd101aeb1c49b5e6840bfa0e61cc60071
Parents: 58ec7b1
Author: Mike Drob <md...@cloudera.com>
Authored: Tue Mar 11 12:21:14 2014 -0400
Committer: Mike Drob <md...@cloudera.com>
Committed: Thu Mar 13 16:10:00 2014 -0400
----------------------------------------------------------------------
.../iterators/user/BigDecimalCombinerTest.java | 91 ++++++++++++++++----
.../core/iterators/user/CombinerTest.java | 2 +-
2 files changed, 76 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/b66ee24c/core/src/test/java/org/apache/accumulo/core/iterators/user/BigDecimalCombinerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/user/BigDecimalCombinerTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/user/BigDecimalCombinerTest.java
index 4cf4d5d..9e3d975 100644
--- a/core/src/test/java/org/apache/accumulo/core/iterators/user/BigDecimalCombinerTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/iterators/user/BigDecimalCombinerTest.java
@@ -25,9 +25,11 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.List;
import java.util.TreeMap;
import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.IteratorSetting.Column;
import org.apache.accumulo.core.data.ByteSequence;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Range;
@@ -35,39 +37,96 @@ import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.iterators.Combiner;
import org.apache.accumulo.core.iterators.SortedMapIterator;
import org.apache.accumulo.core.iterators.TypedValueCombiner.Encoder;
+import org.junit.Before;
import org.junit.Test;
public class BigDecimalCombinerTest {
private static final Collection<ByteSequence> EMPTY_COL_FAMS = new ArrayList<ByteSequence>();
private static double delta = 0.00001;
-
- @Test
- public void testSums() throws IOException {
- Encoder<BigDecimal> encoder = new BigDecimalCombiner.BigDecimalEncoder();
-
- TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>();
-
- // keys that do not aggregate
+ Encoder<BigDecimal> encoder;
+ TreeMap<Key,Value> tm1;
+ List<Column> columns;
+ Combiner ai;
+
+
+ @Before
+ public void setup() {
+ encoder = new BigDecimalCombiner.BigDecimalEncoder();
+ tm1 = new TreeMap<Key,Value>();
+ columns = Collections.singletonList(new IteratorSetting.Column("cf001"));
+
+ // keys that will aggregate
CombinerTest.nkv(tm1, 1, 1, 1, 1, false, BigDecimal.valueOf(2), encoder);
CombinerTest.nkv(tm1, 1, 1, 1, 2, false, BigDecimal.valueOf(2.3), encoder);
CombinerTest.nkv(tm1, 1, 1, 1, 3, false, BigDecimal.valueOf(-1.4E1), encoder);
-
- Combiner ai = new BigDecimalCombiner.BigDecimalSummingCombiner();
+
+ // and keys that will not aggregate
+ CombinerTest.nkv(tm1, 1, 2, 1, 1, false, BigDecimal.valueOf(99), encoder);
+ CombinerTest.nkv(tm1, 1, 3, 1, 1, false, BigDecimal.valueOf(-88), encoder);
+ }
+
+ @Test
+ public void testSums() throws IOException {
+ ai = new BigDecimalCombiner.BigDecimalSummingCombiner();
IteratorSetting is = new IteratorSetting(1, BigDecimalCombiner.BigDecimalSummingCombiner.class);
- Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001")));
+ Combiner.setColumns(is, columns);
+
+ ai.init(new SortedMapIterator(tm1), is.getOptions(), null);
+ ai.seek(new Range(), EMPTY_COL_FAMS, false);
+
+ assertTrue(ai.hasTop());
+ assertEquals(CombinerTest.nk(1, 1, 1, 3), ai.getTopKey());
+ assertEquals(-9.7, encoder.decode(ai.getTopValue().get()).doubleValue(), delta);
+
+ verify();
+ }
+
+ @Test
+ public void testMin() throws IOException {
+ ai = new BigDecimalCombiner.BigDecimalMinCombiner();
+ IteratorSetting is = new IteratorSetting(1, BigDecimalCombiner.BigDecimalMinCombiner.class);
+ Combiner.setColumns(is, columns);
ai.init(new SortedMapIterator(tm1), is.getOptions(), null);
ai.seek(new Range(), EMPTY_COL_FAMS, false);
-
+
assertTrue(ai.hasTop());
assertEquals(CombinerTest.nk(1, 1, 1, 3), ai.getTopKey());
- assertEquals(-9.7, encoder.decode(ai.getTopValue().get()).doubleValue(),delta);
-
+ assertEquals(-14.0, encoder.decode(ai.getTopValue().get()).doubleValue(), delta);
+
+ verify();
+ }
+
+ @Test
+ public void testMax() throws IOException {
+ ai = new BigDecimalCombiner.BigDecimalMaxCombiner();
+ IteratorSetting is = new IteratorSetting(1, BigDecimalCombiner.BigDecimalMaxCombiner.class);
+ Combiner.setColumns(is, columns);
+
+ ai.init(new SortedMapIterator(tm1), is.getOptions(), null);
+ ai.seek(new Range(), EMPTY_COL_FAMS, false);
+
+ assertTrue(ai.hasTop());
+ assertEquals(CombinerTest.nk(1, 1, 1, 3), ai.getTopKey());
+ assertEquals(2.3, encoder.decode(ai.getTopValue().get()).doubleValue(), delta);
+
+ verify();
+ }
+
+ private void verify() throws IOException {
+ ai.next(); // Skip the combined key, since we've already looked at it by now
+
+ // Should have exactly two more keys left over
+ assertEquals(CombinerTest.nk(1, 2, 1, 1), ai.getTopKey());
+ assertEquals(99.0, encoder.decode(ai.getTopValue().get()).doubleValue(), delta);
+ ai.next();
+
+ assertEquals(CombinerTest.nk(1, 3, 1, 1), ai.getTopKey());
+ assertEquals(-88.0, encoder.decode(ai.getTopValue().get()).doubleValue(), delta);
ai.next();
-
+
assertFalse(ai.hasTop());
}
-
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/b66ee24c/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java
index 0c91ef7..41d6425 100644
--- a/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java
@@ -55,7 +55,7 @@ public class CombinerTest {
static Key nk(int row, int colf, int colq, long ts, boolean deleted) {
Key k = nk(row, colf, colq, ts);
- k.setDeleted(true);
+ k.setDeleted(deleted);
return k;
}