You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@heron.apache.org by GitBox <gi...@apache.org> on 2018/11/08 22:52:40 UTC

[GitHub] nlu90 closed pull request #3105: Port Scala Streamlet integration tests to Java

nlu90 closed pull request #3105: Port Scala Streamlet integration tests to Java
URL: https://github.com/apache/incubator-heron/pull/3105
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/integration_test/src/java/org/apache/heron/integration_test/topology/streamlet_with_filter_and_transform/StreamletWithFilterAndTransform.java b/integration_test/src/java/org/apache/heron/integration_test/topology/streamlet_with_filter_and_transform/StreamletWithFilterAndTransform.java
new file mode 100644
index 0000000000..f1aeed391e
--- /dev/null
+++ b/integration_test/src/java/org/apache/heron/integration_test/topology/streamlet_with_filter_and_transform/StreamletWithFilterAndTransform.java
@@ -0,0 +1,84 @@
+/**
+ * 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.heron.integration_test.topology.streamlet_with_filter_and_transform;
+
+import java.net.MalformedURLException;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
+
+import org.apache.heron.api.Config;
+import org.apache.heron.integration_test.common.AbstractTestTopology;
+import org.apache.heron.integration_test.core.TestTopologyBuilder;
+import org.apache.heron.streamlet.Builder;
+import org.apache.heron.streamlet.Context;
+import org.apache.heron.streamlet.SerializableTransformer;
+import org.apache.heron.streamlet.impl.BuilderImpl;
+
+/**
+  * Streamlet Integration Test
+  */
+class StreamletWithFilterAndTransform extends AbstractTestTopology {
+
+  StreamletWithFilterAndTransform(String[] args) throws MalformedURLException {
+    super(args);
+  }
+
+  @Override
+  protected TestTopologyBuilder buildTopology(TestTopologyBuilder testTopologyBuilder) {
+    AtomicInteger atomicInteger = new AtomicInteger(0);
+
+    Builder streamletBuilder = Builder.newBuilder();
+    streamletBuilder
+      .newSource(() -> atomicInteger.getAndIncrement())
+      .setName("incremented-numbers")
+      .filter(i -> i <= 7)
+      .setName("numbers-lower-than-8")
+      .transform(new TextTransformer())
+      .setName("numbers-transformed-to-text");
+
+    BuilderImpl streamletBuilderImpl = (BuilderImpl) streamletBuilder;
+    TestTopologyBuilder topology =
+        (TestTopologyBuilder) streamletBuilderImpl.build(testTopologyBuilder);
+
+    return topology;
+  }
+
+  public static class TextTransformer implements SerializableTransformer<Integer, String> {
+    private String[] alphabet;
+
+    @Override
+    public void setup(Context context) {
+      alphabet = new String[] {"a", "b", "c", "d", "e", "f", "g", "h"};
+    }
+
+    @Override
+    public void transform(Integer i, Consumer<String> fun) {
+      fun.accept(String.format("%s-%d", alphabet[i].toUpperCase(), i));
+    }
+
+    @Override
+    public void cleanup() { }
+  }
+
+  public static void main(String[] args) throws Exception {
+    Config conf = new Config();
+    StreamletWithFilterAndTransform topology = new StreamletWithFilterAndTransform(args);
+    topology.submit(conf);
+  }
+}
diff --git a/integration_test/src/java/org/apache/heron/integration_test/topology/streamlet_with_filter_and_transform/StreamletWithFilterAndTransformResults.json b/integration_test/src/java/org/apache/heron/integration_test/topology/streamlet_with_filter_and_transform/StreamletWithFilterAndTransformResults.json
new file mode 100644
index 0000000000..dda72569e2
--- /dev/null
+++ b/integration_test/src/java/org/apache/heron/integration_test/topology/streamlet_with_filter_and_transform/StreamletWithFilterAndTransformResults.json
@@ -0,0 +1 @@
+["A-0", "B-1", "C-2", "D-3", "E-4", "F-5", "G-6", "H-7"]
\ No newline at end of file
diff --git a/integration_test/src/java/org/apache/heron/integration_test/topology/streamlet_with_map_and_flatmap_and_filter_and_clone/StreamletWithMapAndFlatMapAndFilterAndClone.java b/integration_test/src/java/org/apache/heron/integration_test/topology/streamlet_with_map_and_flatmap_and_filter_and_clone/StreamletWithMapAndFlatMapAndFilterAndClone.java
new file mode 100644
index 0000000000..19187967a4
--- /dev/null
+++ b/integration_test/src/java/org/apache/heron/integration_test/topology/streamlet_with_map_and_flatmap_and_filter_and_clone/StreamletWithMapAndFlatMapAndFilterAndClone.java
@@ -0,0 +1,81 @@
+/**
+ * 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.heron.integration_test.topology.streamlet_with_map_and_flatmap_and_filter_and_clone;
+
+import java.net.MalformedURLException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.heron.api.Config;
+import org.apache.heron.integration_test.common.AbstractTestTopology;
+import org.apache.heron.integration_test.core.TestTopologyBuilder;
+import org.apache.heron.streamlet.Builder;
+import org.apache.heron.streamlet.Streamlet;
+import org.apache.heron.streamlet.impl.BuilderImpl;
+
+class StreamletWithMapAndFlatMapAndFilterAndClone extends AbstractTestTopology {
+  private static final String MONTHS = "january - february - march - april - may - june"
+      + " - july - august - september - october - november - december";
+  private static final Set<String> SUMMER_MONTHS =
+      new HashSet<>(Arrays.asList("june", "july", "august"));
+  private static Set<String> incomingMonths = new HashSet<>();
+
+  StreamletWithMapAndFlatMapAndFilterAndClone(String[] args) throws MalformedURLException {
+    super(args);
+  }
+
+  @Override
+  protected TestTopologyBuilder buildTopology(TestTopologyBuilder testTopologyBuilder) {
+    Builder streamletBuilder = Builder.newBuilder();
+
+    Streamlet<String> streamlet = streamletBuilder
+        .newSource(() -> MONTHS)
+        .setName("months-text")
+        .flatMap((String m) -> Arrays.asList(m.split(" - ")))
+        .setName("months")
+        .filter((month) ->
+            SUMMER_MONTHS.contains(month.toLowerCase()) && incomingMonths.add(month.toLowerCase()))
+        .setName("summer-months")
+        .map((String word) -> word.substring(0, 3))
+        .setName("summer-months-with-short-name");
+
+    List<Streamlet<String>> clonedStreamlet = streamlet.clone(2);
+
+    //Returns Summer Months with year
+    clonedStreamlet.get(0).map((String month) -> month + "_2018");
+
+    //Returns Summer Months with Uppercase
+    clonedStreamlet.get(1).map((String month) -> month.toUpperCase());
+
+    BuilderImpl streamletBuilderImpl = (BuilderImpl) streamletBuilder;
+    TestTopologyBuilder topology =
+        (TestTopologyBuilder) streamletBuilderImpl.build(testTopologyBuilder);
+
+    return topology;
+  }
+
+  public static void main(String[] args) throws Exception {
+    Config conf = new Config();
+    StreamletWithMapAndFlatMapAndFilterAndClone topology =
+        new StreamletWithMapAndFlatMapAndFilterAndClone(args);
+    topology.submit(conf);
+  }
+}
diff --git a/integration_test/src/java/org/apache/heron/integration_test/topology/streamlet_with_map_and_flatmap_and_filter_and_clone/StreamletWithMapAndFlatMapAndFilterAndCloneResults.json b/integration_test/src/java/org/apache/heron/integration_test/topology/streamlet_with_map_and_flatmap_and_filter_and_clone/StreamletWithMapAndFlatMapAndFilterAndCloneResults.json
new file mode 100644
index 0000000000..6ececf2182
--- /dev/null
+++ b/integration_test/src/java/org/apache/heron/integration_test/topology/streamlet_with_map_and_flatmap_and_filter_and_clone/StreamletWithMapAndFlatMapAndFilterAndCloneResults.json
@@ -0,0 +1 @@
+["AUG", "JUL", "JUN", "aug_2018", "jul_2018", "jun_2018"]
\ No newline at end of file
diff --git a/integration_test/src/python/test_runner/main.py b/integration_test/src/python/test_runner/main.py
index 76cb281d71..161a759599 100644
--- a/integration_test/src/python/test_runner/main.py
+++ b/integration_test/src/python/test_runner/main.py
@@ -258,7 +258,7 @@ def submit_topology(heron_cli_path, cli_config_path, cluster, role,
   # Form the command to submit a topology.
   # Note the single quote around the arg for heron.package.core.uri.
   # This is needed to prevent shell expansion.
-  cmd = "%s submit --config-path=%s %s %s %s %s" %\
+  cmd = "%s submit --verbose --config-path=%s %s %s %s %s" %\
         (heron_cli_path, cli_config_path, cluster_token(cluster, role, env),
          jar_path, classpath, args)
 
diff --git a/integration_test/src/python/test_runner/resources/test.json b/integration_test/src/python/test_runner/resources/test.json
index 1174154645..762b2f6c16 100644
--- a/integration_test/src/python/test_runner/resources/test.json
+++ b/integration_test/src/python/test_runner/resources/test.json
@@ -128,6 +128,16 @@
       "topologyName" : "IntegrationTest_StatefulWindowingTest",
       "classPath"    : "windowing.stateful.StatefulWindowingTest",
       "expectedResultRelativePath" : "windowing/stateful/StatefulWindowingTestResults.json"
+    },
+    {
+      "topologyName": "IntegrationTest_StreamletWithFilterAndTransform",
+      "classPath": "streamlet_with_filter_and_transform.StreamletWithFilterAndTransform",
+      "expectedResultRelativePath": "streamlet_with_filter_and_transform/StreamletWithFilterAndTransformResults.json"
+    },
+    {
+      "topologyName": "IntegrationTest_StreamletWithMapAndFlatMapAndFilterAndClone",
+      "classPath": "streamlet_with_map_and_flatmap_and_filter_and_clone.StreamletWithMapAndFlatMapAndFilterAndClone",
+      "expectedResultRelativePath": "streamlet_with_map_and_flatmap_and_filter_and_clone/StreamletWithMapAndFlatMapAndFilterAndCloneResults.json"
     }
   ],
   "pythonTopologies": [
diff --git a/integration_test/src/scala/org/apache/heron/integration_test/topology/scala_streamlet_with_filter_and_transform/ScalaStreamletWithFilterAndTransform.scala b/integration_test/src/scala/org/apache/heron/integration_test/topology/scala_streamlet_with_filter_and_transform/ScalaStreamletWithFilterAndTransform.scala
index ac55f65331..3e73f2a8d4 100644
--- a/integration_test/src/scala/org/apache/heron/integration_test/topology/scala_streamlet_with_filter_and_transform/ScalaStreamletWithFilterAndTransform.scala
+++ b/integration_test/src/scala/org/apache/heron/integration_test/topology/scala_streamlet_with_filter_and_transform/ScalaStreamletWithFilterAndTransform.scala
@@ -57,7 +57,7 @@ class ScalaStreamletWithFilterAndTransform(args: Array[String])
       .newSource(() => atomicInteger.getAndIncrement())
       .setName("incremented-numbers")
       .filter((i: Int) => i <= 7)
-      .setName("positive-numbers-lower-than-8")
+      .setName("numbers-lower-than-8")
       .transform[String](new TextTransformer())
       .setName("numbers-transformed-to-text")
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services