Repository: storm
Updated Branches:
  refs/heads/1.x-branch 58cbfe5e2 -> a8381dd65


STORM-2100 Fix Trident SQL join tests to not rely on ordering

* join doesn't guarantee preserving order (Trident and SQL itself)


Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/cf291150
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/cf291150
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/cf291150

Branch: refs/heads/1.x-branch
Commit: cf291150628c6193cb4af776064286ac59cd3031
Parents: 58cbfe5
Author: Jungtaek Lim <kabh...@gmail.com>
Authored: Mon Sep 19 22:24:26 2016 +0900
Committer: Satish Duggana <sdugg...@hortonworks.com>
Committed: Wed Sep 21 09:14:21 2016 +0530

----------------------------------------------------------------------
 external/sql/storm-sql-core/pom.xml             |  6 ++++
 .../backends/trident/TestPlanCompiler.java      | 37 +++++++++++---------
 2 files changed, 27 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/cf291150/external/sql/storm-sql-core/pom.xml
----------------------------------------------------------------------
diff --git a/external/sql/storm-sql-core/pom.xml 
b/external/sql/storm-sql-core/pom.xml
index 2e52be2..c4fd024 100644
--- a/external/sql/storm-sql-core/pom.xml
+++ b/external/sql/storm-sql-core/pom.xml
@@ -111,6 +111,12 @@
             <artifactId>mockito-all</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-collections4</artifactId>
+            <version>4.1</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     <build>
         <sourceDirectory>src/jvm</sourceDirectory>

http://git-wip-us.apache.org/repos/asf/storm/blob/cf291150/external/sql/storm-sql-core/src/test/org/apache/storm/sql/compiler/backends/trident/TestPlanCompiler.java
----------------------------------------------------------------------
diff --git 
a/external/sql/storm-sql-core/src/test/org/apache/storm/sql/compiler/backends/trident/TestPlanCompiler.java
 
b/external/sql/storm-sql-core/src/test/org/apache/storm/sql/compiler/backends/trident/TestPlanCompiler.java
index 0ad0a46..35d1364 100644
--- 
a/external/sql/storm-sql-core/src/test/org/apache/storm/sql/compiler/backends/trident/TestPlanCompiler.java
+++ 
b/external/sql/storm-sql-core/src/test/org/apache/storm/sql/compiler/backends/trident/TestPlanCompiler.java
@@ -19,34 +19,34 @@
  */
 package org.apache.storm.sql.compiler.backends.trident;
 
+import com.google.common.collect.Lists;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
+import org.apache.calcite.rel.type.RelDataTypeSystem;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.storm.Config;
 import org.apache.storm.ILocalCluster;
 import org.apache.storm.LocalCluster;
 import org.apache.storm.generated.StormTopology;
-import org.apache.storm.sql.runtime.AbstractValuesProcessor;
-import org.apache.storm.tuple.Fields;
-import org.apache.storm.tuple.Values;
-import org.apache.storm.utils.Utils;
-import org.apache.calcite.adapter.java.JavaTypeFactory;
-import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
-import org.apache.calcite.rel.type.RelDataTypeSystem;
 import org.apache.storm.sql.TestUtils;
 import 
org.apache.storm.sql.TestUtils.MockSqlTridentDataSource.CollectDataFunction;
 import org.apache.storm.sql.compiler.TestCompilerUtils;
 import org.apache.storm.sql.runtime.ISqlTridentDataSource;
 import org.apache.storm.sql.runtime.trident.AbstractTridentProcessor;
+import org.apache.storm.trident.TridentTopology;
+import org.apache.storm.tuple.Fields;
+import org.apache.storm.tuple.Values;
+import org.apache.storm.utils.Utils;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.apache.storm.trident.TridentTopology;
 
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.Callable;
 
-import static 
org.apache.storm.sql.TestUtils.MockSqlTridentDataSource.CollectDataFunction.*;
+import static 
org.apache.storm.sql.TestUtils.MockSqlTridentDataSource.CollectDataFunction.getCollectedValues;
 
 public class TestPlanCompiler {
   private final JavaTypeFactory typeFactory = new JavaTypeFactoryImpl(
@@ -122,7 +122,7 @@ public class TestPlanCompiler {
     proc.outputStream().each(f, new CollectDataFunction(), new 
Fields()).toStream();
     runTridentTopology(EXPECTED_VALUE_SIZE, proc, topo);
 
-    Assert.assertArrayEquals(new Values[] { new Values(1, 2L), new Values(0, 
2L)}, getCollectedValues().toArray());
+    assertListsAreEqualIgnoringOrder(Lists.newArrayList(new Values(1, 2L), new 
Values(0, 2L)), getCollectedValues());
   }
 
   @Test
@@ -140,7 +140,7 @@ public class TestPlanCompiler {
     proc.outputStream().each(f, new CollectDataFunction(), new 
Fields()).toStream();
     runTridentTopology(EXPECTED_VALUE_SIZE, proc, topo);
 
-    Assert.assertArrayEquals(new Values[] { new Values(2, null), new Values(3, 
null), new Values(4, null)}, getCollectedValues().toArray());
+    assertListsAreEqualIgnoringOrder(Lists.newArrayList(new Values(2, null), 
new Values(3, null), new Values(4, null)), getCollectedValues());
   }
 
   @Test
@@ -158,7 +158,7 @@ public class TestPlanCompiler {
     proc.outputStream().each(f, new CollectDataFunction(), new 
Fields()).toStream();
     runTridentTopology(EXPECTED_VALUE_SIZE, proc, topo);
 
-    Assert.assertArrayEquals(new Values[] { new Values(2, null), new Values(3, 
null), new Values(4, null)}, getCollectedValues().toArray());
+    assertListsAreEqualIgnoringOrder(Lists.newArrayList(new Values(2, null), 
new Values(3, null), new Values(4, null)), getCollectedValues());
   }
 
   @Test
@@ -176,9 +176,9 @@ public class TestPlanCompiler {
     proc.outputStream().each(f, new CollectDataFunction(), new 
Fields()).toStream();
     runTridentTopology(EXPECTED_VALUE_SIZE, proc, topo);
 
-    Assert.assertArrayEquals(new Values[] { new Values(null, "dept-2"), new 
Values(null, "dept-3"), new Values(null, "dept-4"),
-      new Values(10, null), new Values(11, null), new Values(12, null), new 
Values(13, null), new Values(14, null)},
-            getCollectedValues().toArray());
+    assertListsAreEqualIgnoringOrder(Lists.newArrayList(new Values(null, 
"dept-2"), new Values(null, "dept-3"), new Values(null, "dept-4"),
+            new Values(10, null), new Values(11, null), new Values(12, null), 
new Values(13, null), new Values(14, null)),
+            getCollectedValues());
   }
 
   @Test
@@ -274,4 +274,9 @@ public class TestPlanCompiler {
       Thread.sleep(100);
     }
   }
+
+  private void assertListsAreEqualIgnoringOrder(List<Values> expected, 
List<List<Object>> actual) {
+    Assert.assertTrue("Two lists are not same (even ignoring order)!\n"+ 
"Expected: " + expected + "\n" + "Actual: " + actual,
+            CollectionUtils.isEqualCollection(expected, actual));
+  }
 }
\ No newline at end of file

Reply via email to