From 07c4923bf8b56e66eff409c2c7eff61c247716a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20L=C3=A9aut=C3=A9?= Date: Thu, 13 Nov 2014 19:15:39 -0800 Subject: [PATCH] add test for out of order merging --- .../client/CachingClusteredClientTest.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/server/src/test/java/io/druid/client/CachingClusteredClientTest.java b/server/src/test/java/io/druid/client/CachingClusteredClientTest.java index 17abc5c3214..57a0cf2ece3 100644 --- a/server/src/test/java/io/druid/client/CachingClusteredClientTest.java +++ b/server/src/test/java/io/druid/client/CachingClusteredClientTest.java @@ -35,6 +35,7 @@ import com.google.common.collect.Ordering; import com.google.common.hash.HashFunction; import com.google.common.hash.Hashing; import com.metamx.common.ISE; +import com.metamx.common.Pair; import com.metamx.common.guava.FunctionalIterable; import com.metamx.common.guava.MergeIterable; import com.metamx.common.guava.Sequence; @@ -598,6 +599,56 @@ public class CachingClusteredClientTest ); } + @Test + public void testOutOfOrderSequenceMerging() throws Exception + { + List>>> sequences = + Lists.newArrayList( + Pair.of( + // this could ne the result of a historical node returning the merged result of + // a) an empty result for segment 2011-01-02/2011-01-05 + // and b) result for a second partition for 2011-01-05/2011-01-10 + new Interval("2011-01-02/2011-01-10"), + Sequences.simple( + makeTopNResults( + new DateTime("2011-01-07"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, + new DateTime("2011-01-08"), "a", 50, 4988, "b", 50, 4987, "c", 50, 4986, + new DateTime("2011-01-09"), "a", 50, 4985, "b", 50, 4984, "c", 50, 4983 + ) + ) + ), + + Pair.of( + new Interval("2011-01-05/2011-01-10"), + Sequences.simple( + makeTopNResults( + new DateTime("2011-01-06T01"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, + new DateTime("2011-01-07T01"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, + new DateTime("2011-01-08T01"), "a", 50, 4988, "b", 50, 4987, "c", 50, 4986, + new DateTime("2011-01-09T01"), "a", 50, 4985, "b", 50, 4984, "c", 50, 4983 + ) + ) + ) + ); + + TestHelper.assertExpectedResults( + makeTopNResults( + new DateTime("2011-01-06T01"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, + new DateTime("2011-01-07"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, + new DateTime("2011-01-07T01"), "a", 50, 4991, "b", 50, 4990, "c", 50, 4989, + new DateTime("2011-01-08"), "a", 50, 4988, "b", 50, 4987, "c", 50, 4986, + new DateTime("2011-01-08T01"), "a", 50, 4988, "b", 50, 4987, "c", 50, 4986, + new DateTime("2011-01-09"), "a", 50, 4985, "b", 50, 4984, "c", 50, 4983, + new DateTime("2011-01-09T01"), "a", 50, 4985, "b", 50, 4984, "c", 50, 4983 + ), + client.mergeCachedAndUncachedSequences( + sequences, + new TopNQueryQueryToolChest(new TopNQueryConfig()) + ) + ); + } + + @Test @SuppressWarnings("unchecked") public void testTopNCachingEmptyResults() throws Exception