You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@heron.apache.org by nl...@apache.org on 2018/11/08 22:52:43 UTC
[incubator-heron] branch master updated: Port Scala Streamlet
integration tests to Java (#3105)
This is an automated email from the ASF dual-hosted git repository.
nlu90 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-heron.git
The following commit(s) were added to refs/heads/master by this push:
new ff53016 Port Scala Streamlet integration tests to Java (#3105)
ff53016 is described below
commit ff53016235d6bc2b23d29ba3b816cadd65f54532
Author: Ning Wang <nw...@twitter.com>
AuthorDate: Thu Nov 8 14:52:39 2018 -0800
Port Scala Streamlet integration tests to Java (#3105)
---
.../StreamletWithFilterAndTransform.java | 84 ++++++++++++++++++++++
.../StreamletWithFilterAndTransformResults.json | 1 +
...treamletWithMapAndFlatMapAndFilterAndClone.java | 81 +++++++++++++++++++++
...tWithMapAndFlatMapAndFilterAndCloneResults.json | 1 +
integration_test/src/python/test_runner/main.py | 2 +-
.../src/python/test_runner/resources/test.json | 10 +++
.../ScalaStreamletWithFilterAndTransform.scala | 2 +-
7 files changed, 179 insertions(+), 2 deletions(-)
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 0000000..f1aeed3
--- /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 0000000..dda7256
--- /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 0000000..1918796
--- /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 0000000..6ececf2
--- /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 76cb281..161a759 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 1174154..762b2f6 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 ac55f65..3e73f2a 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")