Updated Branches: refs/heads/master cf388fe8b -> 3d01b9aa8
CRUNCH-322: Use InMemoryEmitter instead of StoreLastEmitter in unit tests. Project: http://git-wip-us.apache.org/repos/asf/crunch/repo Commit: http://git-wip-us.apache.org/repos/asf/crunch/commit/3d01b9aa Tree: http://git-wip-us.apache.org/repos/asf/crunch/tree/3d01b9aa Diff: http://git-wip-us.apache.org/repos/asf/crunch/diff/3d01b9aa Branch: refs/heads/master Commit: 3d01b9aa823b2fb5085a1404be06c0d47b8de942 Parents: cf388fe Author: Josh Wills <[email protected]> Authored: Thu Jan 16 00:32:54 2014 -0800 Committer: Josh Wills <[email protected]> Committed: Thu Jan 16 12:14:28 2014 -0800 ---------------------------------------------------------------------- .../crunch/impl/mem/emit/InMemoryEmitter.java | 5 +++ .../org/apache/crunch/fn/ExtractKeyFnTest.java | 6 ++- .../java/org/apache/crunch/fn/PairMapTest.java | 6 ++- .../org/apache/crunch/fn/StoreLastEmitter.java | 41 -------------------- 4 files changed, 13 insertions(+), 45 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/crunch/blob/3d01b9aa/crunch-core/src/main/java/org/apache/crunch/impl/mem/emit/InMemoryEmitter.java ---------------------------------------------------------------------- diff --git a/crunch-core/src/main/java/org/apache/crunch/impl/mem/emit/InMemoryEmitter.java b/crunch-core/src/main/java/org/apache/crunch/impl/mem/emit/InMemoryEmitter.java index 93988e6..23c7a32 100644 --- a/crunch-core/src/main/java/org/apache/crunch/impl/mem/emit/InMemoryEmitter.java +++ b/crunch-core/src/main/java/org/apache/crunch/impl/mem/emit/InMemoryEmitter.java @@ -22,6 +22,7 @@ import java.util.List; import org.apache.crunch.Emitter; import com.google.common.collect.Lists; +import org.apache.crunch.Pair; /** * An {@code Emitter} instance that writes emitted records to a backing @@ -33,6 +34,10 @@ public class InMemoryEmitter<T> implements Emitter<T> { private final List<T> output; + public static <T> InMemoryEmitter<T> create() { + return new InMemoryEmitter<T>(); + } + public InMemoryEmitter() { this(Lists.<T> newArrayList()); } http://git-wip-us.apache.org/repos/asf/crunch/blob/3d01b9aa/crunch-core/src/test/java/org/apache/crunch/fn/ExtractKeyFnTest.java ---------------------------------------------------------------------- diff --git a/crunch-core/src/test/java/org/apache/crunch/fn/ExtractKeyFnTest.java b/crunch-core/src/test/java/org/apache/crunch/fn/ExtractKeyFnTest.java index b5b2a1b..1854f27 100644 --- a/crunch-core/src/test/java/org/apache/crunch/fn/ExtractKeyFnTest.java +++ b/crunch-core/src/test/java/org/apache/crunch/fn/ExtractKeyFnTest.java @@ -19,8 +19,10 @@ package org.apache.crunch.fn; import static org.junit.Assert.assertEquals; +import com.google.common.collect.Iterables; import org.apache.crunch.MapFn; import org.apache.crunch.Pair; +import org.apache.crunch.impl.mem.emit.InMemoryEmitter; import org.junit.Test; @SuppressWarnings("serial") @@ -37,8 +39,8 @@ public class ExtractKeyFnTest { @Test public void test() { - StoreLastEmitter<Pair<Integer, String>> emitter = StoreLastEmitter.create(); + InMemoryEmitter<Pair<Integer, String>> emitter = InMemoryEmitter.create(); one.process("boza", emitter); - assertEquals(Pair.of("boza".hashCode(), "boza"), emitter.getLast()); + assertEquals(Pair.of("boza".hashCode(), "boza"), Iterables.getOnlyElement(emitter.getOutput())); } } http://git-wip-us.apache.org/repos/asf/crunch/blob/3d01b9aa/crunch-core/src/test/java/org/apache/crunch/fn/PairMapTest.java ---------------------------------------------------------------------- diff --git a/crunch-core/src/test/java/org/apache/crunch/fn/PairMapTest.java b/crunch-core/src/test/java/org/apache/crunch/fn/PairMapTest.java index bef6c85..83fa9fb 100644 --- a/crunch-core/src/test/java/org/apache/crunch/fn/PairMapTest.java +++ b/crunch-core/src/test/java/org/apache/crunch/fn/PairMapTest.java @@ -19,8 +19,10 @@ package org.apache.crunch.fn; import static org.junit.Assert.assertTrue; +import com.google.common.collect.Iterables; import org.apache.crunch.MapFn; import org.apache.crunch.Pair; +import org.apache.crunch.impl.mem.emit.InMemoryEmitter; import org.junit.Test; @SuppressWarnings("serial") @@ -42,10 +44,10 @@ public class PairMapTest { @Test public void testPairMap() { - StoreLastEmitter<Pair<Integer, Integer>> emitter = StoreLastEmitter.create(); + InMemoryEmitter<Pair<Integer, Integer>> emitter = InMemoryEmitter.create(); PairMapFn<String, String, Integer, Integer> fn = new PairMapFn<String, String, Integer, Integer>(one, two); fn.process(Pair.of("a", "b"), emitter); - Pair<Integer, Integer> pair = emitter.getLast(); + Pair<Integer, Integer> pair = Iterables.getOnlyElement(emitter.getOutput()); assertTrue(pair.first() == 1); assertTrue(pair.second() == 2); } http://git-wip-us.apache.org/repos/asf/crunch/blob/3d01b9aa/crunch-core/src/test/java/org/apache/crunch/fn/StoreLastEmitter.java ---------------------------------------------------------------------- diff --git a/crunch-core/src/test/java/org/apache/crunch/fn/StoreLastEmitter.java b/crunch-core/src/test/java/org/apache/crunch/fn/StoreLastEmitter.java deleted file mode 100644 index cdd8754..0000000 --- a/crunch-core/src/test/java/org/apache/crunch/fn/StoreLastEmitter.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.crunch.fn; - -import org.apache.crunch.Emitter; - -class StoreLastEmitter<T> implements Emitter<T> { - private T last; - - @Override - public void emit(T emitted) { - last = emitted; - } - - public T getLast() { - return last; - } - - @Override - public void flush() { - } - - public static <T> StoreLastEmitter<T> create() { - return new StoreLastEmitter<T>(); - } -} \ No newline at end of file
