From d19b895fb96889a95ecc43430929352e2c292191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20L=C3=A9aut=C3=A9?= Date: Thu, 13 Nov 2014 14:49:13 -0800 Subject: [PATCH] add tests for empty sequences --- .../collections/OrderedMergeSequenceTest.java | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/common/src/test/java/io/druid/collections/OrderedMergeSequenceTest.java b/common/src/test/java/io/druid/collections/OrderedMergeSequenceTest.java index 7d7f80e2bfe..3931196b17e 100644 --- a/common/src/test/java/io/druid/collections/OrderedMergeSequenceTest.java +++ b/common/src/test/java/io/druid/collections/OrderedMergeSequenceTest.java @@ -20,6 +20,7 @@ package io.druid.collections; import com.google.common.base.Function; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.collect.Ordering; import com.metamx.common.guava.BaseSequence; @@ -28,7 +29,7 @@ import com.metamx.common.guava.Sequence; import com.metamx.common.guava.SequenceTestHelper; import com.metamx.common.guava.Sequences; import com.metamx.common.guava.TestSequence; -import junit.framework.Assert; +import org.junit.Assert; import org.junit.Test; import javax.annotation.Nullable; @@ -59,6 +60,61 @@ public class OrderedMergeSequenceTest } } + @Test + public void testMergeEmptySequence() throws Exception + { + final ArrayList> testSequences = Lists.newArrayList( + TestSequence.create(ImmutableList.of()), + TestSequence.create(2, 8), + TestSequence.create(4, 6, 8) + ); + + OrderedMergeSequence seq = makeMergedSequence(Ordering.natural(), testSequences); + + SequenceTestHelper.testAll(seq, Arrays.asList(2, 4, 6, 8, 8)); + + for (TestSequence sequence : testSequences) { + Assert.assertTrue(sequence.isClosed()); + } + } + + @Test + public void testMergeEmptySequenceAtEnd() throws Exception + { + final ArrayList> testSequences = Lists.newArrayList( + TestSequence.create(2, 8), + TestSequence.create(4, 6, 8), + TestSequence.create(ImmutableList.of()) + ); + + OrderedMergeSequence seq = makeMergedSequence(Ordering.natural(), testSequences); + + SequenceTestHelper.testAll(seq, Arrays.asList(2, 4, 6, 8, 8)); + + for (TestSequence sequence : testSequences) { + Assert.assertTrue(sequence.isClosed()); + } + } + + + @Test + public void testMergeEmptySequenceMiddle() throws Exception + { + final ArrayList> testSequences = Lists.newArrayList( + TestSequence.create(2, 8), + TestSequence.create(ImmutableList.of()), + TestSequence.create(4, 6, 8) + ); + + OrderedMergeSequence seq = makeMergedSequence(Ordering.natural(), testSequences); + + SequenceTestHelper.testAll(seq, Arrays.asList(2, 4, 6, 8, 8)); + + for (TestSequence sequence : testSequences) { + Assert.assertTrue(sequence.isClosed()); + } + } + @Test public void testScrewsUpOnOutOfOrderBeginningOfList() throws Exception {