You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/10/13 00:51:01 UTC

[GitHub] [beam] robertwb commented on a change in pull request #15690: [BEAM-12769] Adds integration tests for Java Class Lookup based cross-language expansion

robertwb commented on a change in pull request #15690:
URL: https://github.com/apache/beam/pull/15690#discussion_r727614241



##########
File path: sdks/python/apache_beam/io/external/generate_sequence_test.py
##########
@@ -54,6 +57,44 @@ def test_generate_sequence(self):
       else:
         raise e
 
+  @unittest.skipUnless(
+      os.environ.get('EXPANSION_SERVICE_TYPE') != 'Python',
+      'Java Class Lookup based expansion is not supported by the Python '
+      'expansion service')
+  def test_generate_sequence_java_class_lookup_payload_builder(self):
+    port = os.environ.get('EXPANSION_PORT')
+    address = 'localhost:%s' % port
+
+    with TestPipeline() as p:
+      payload_builder = JavaClassLookupPayloadBuilder(
+          'org.apache.beam.sdk.io.GenerateSequence')
+      payload_builder.with_constructor_method('from', 1)
+      payload_builder.add_builder_method('to', 10)
+
+      res = (
+          p
+          | ExternalTransform(None, payload_builder, expansion_service=address))
+      assert_that(res, equal_to([i for i in range(1, 10)]))
+
+  @unittest.skipUnless(
+      os.environ.get('EXPANSION_SERVICE_TYPE') != 'Python',
+      'Java Class Lookup based expansion is not supported by the Python '
+      'expansion service')
+  def test_generate_sequence_java_external_transform(self):
+    port = os.environ.get('EXPANSION_PORT')
+    address = 'localhost:%s' % port
+
+    with TestPipeline() as p:
+      java_transform = JavaExternalTransform(
+          'org.apache.beam.sdk.io.GenerateSequence', expansion_service=address)
+      # We have to use 'getattr' below since 'from' is a reserved keyword for
+      # Python.
+      getattr(java_transform, 'from')(1)
+      java_transform.to(10)
+      res = (p | java_transform)
+
+      assert_that(res, equal_to([i for i in range(1, 10)]))

Review comment:
       list(range(1, 10))

##########
File path: sdks/java/testing/expansion-service/src/test/resources/test_expansion_service_allowlist.yaml
##########
@@ -0,0 +1,26 @@
+#
+# 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.
+#
+
+version: v1
+allowedClasses:

Review comment:
       The whole point of the expansion service is to reduce the number of hoops one needs to jump through to instantiate a Java transform, but having to create an allow list is extra boilerplate. Can we at least provide a * allow list, even if it's not the default? 

##########
File path: sdks/python/apache_beam/io/external/generate_sequence_test.py
##########
@@ -54,6 +57,44 @@ def test_generate_sequence(self):
       else:
         raise e
 
+  @unittest.skipUnless(
+      os.environ.get('EXPANSION_SERVICE_TYPE') != 'Python',
+      'Java Class Lookup based expansion is not supported by the Python '
+      'expansion service')
+  def test_generate_sequence_java_class_lookup_payload_builder(self):
+    port = os.environ.get('EXPANSION_PORT')
+    address = 'localhost:%s' % port
+
+    with TestPipeline() as p:
+      payload_builder = JavaClassLookupPayloadBuilder(
+          'org.apache.beam.sdk.io.GenerateSequence')
+      payload_builder.with_constructor_method('from', 1)
+      payload_builder.add_builder_method('to', 10)
+
+      res = (
+          p
+          | ExternalTransform(None, payload_builder, expansion_service=address))
+      assert_that(res, equal_to([i for i in range(1, 10)]))
+
+  @unittest.skipUnless(
+      os.environ.get('EXPANSION_SERVICE_TYPE') != 'Python',
+      'Java Class Lookup based expansion is not supported by the Python '
+      'expansion service')
+  def test_generate_sequence_java_external_transform(self):
+    port = os.environ.get('EXPANSION_PORT')
+    address = 'localhost:%s' % port
+
+    with TestPipeline() as p:
+      java_transform = JavaExternalTransform(
+          'org.apache.beam.sdk.io.GenerateSequence', expansion_service=address)
+      # We have to use 'getattr' below since 'from' is a reserved keyword for
+      # Python.
+      getattr(java_transform, 'from')(1)
+      java_transform.to(10)

Review comment:
       The intent is to use this like a builder pattern, not a sequence of side effects. The `from` field is really annoying, but we could at least write
   
   `java_transform = getattr(java_transform, 'from')(1).to(10)`
   
   or maybe we could support (still with a comment).
   
   `
   java_transform = JavaExternalTransform(
             'org.apache.beam.sdk.io.GenerateSequence', expansion_service=address)["from"](1).to(10)
   `
   

##########
File path: sdks/python/apache_beam/io/external/generate_sequence_test.py
##########
@@ -54,6 +57,44 @@ def test_generate_sequence(self):
       else:
         raise e
 
+  @unittest.skipUnless(
+      os.environ.get('EXPANSION_SERVICE_TYPE') != 'Python',

Review comment:
       `== 'Java'`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org