piotr-szuberski commented on a change in pull request #12297: URL: https://github.com/apache/beam/pull/12297#discussion_r468394074
########## File path: sdks/python/apache_beam/io/external/xlang_kinesisio_it_test.py ########## @@ -0,0 +1,304 @@ +# +# 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. +# + +""" +Integration test for Python cross-language pipelines for Java KinesisIO. + +If you want to run the tests on localstack then run it just with pipeline +options. + +To test it on a real AWS account you need to pass some additional params, e.g.: +python setup.py nosetests \ +--tests=apache_beam.io.external.xlang_kinesisio_it_test \ +--test-pipeline-options=" + --use_real_aws + --aws_kinesis_stream=<STREAM_NAME> + --aws_access_key=<AWS_ACCESS_KEY> + --aws_secret_key=<AWS_SECRET_KEY> + --aws_region=<AWS_REGION> + --runner=FlinkRunner" +""" + +# pytype: skip-file + +from __future__ import absolute_import + +import argparse +import logging +import time +import unittest +import uuid + +import apache_beam as beam +from apache_beam.io.kinesis import InitialPositionInStream +from apache_beam.io.kinesis import ReadDataFromKinesis +from apache_beam.io.kinesis import WriteToKinesis +from apache_beam.options.pipeline_options import PipelineOptions +from apache_beam.options.pipeline_options import StandardOptions +from apache_beam.testing.test_pipeline import TestPipeline +from apache_beam.testing.util import assert_that +from apache_beam.testing.util import equal_to + +# pylint: disable=wrong-import-order, wrong-import-position, ungrouped-imports +try: + import boto3 +except ImportError: + boto3 = None + +try: + from testcontainers.core.container import DockerContainer +except ImportError: + DockerContainer = None +# pylint: enable=wrong-import-order, wrong-import-position, ungrouped-imports + +LOCALSTACK_VERSION = '0.11.3' +NUM_RECORDS = 10 +NOW = time.time() +RECORD = b'record' + str(uuid.uuid4()).encode() + + +@unittest.skipIf(DockerContainer is None, 'testcontainers is not installed.') +@unittest.skipIf(boto3 is None, 'boto3 is not installed.') +@unittest.skipIf( + TestPipeline().get_pipeline_options().view_as(StandardOptions).runner is + None, + 'Do not run this test on precommit suites.', +) +class CrossLanguageKinesisIOTest(unittest.TestCase): + def test_kinesis_io(self): + self.run_kinesis_write() + # TODO: remove once BEAM-10664 is resolved + if not self.use_localstack: + self.run_kinesis_read_data() + + def run_kinesis_write(self): + with TestPipeline(options=PipelineOptions(self.pipeline_args)) as p: + p.not_use_test_runner_api = True + _ = ( + p + | 'Impulse' >> beam.Impulse() + | 'Generate' >> beam.FlatMap(lambda x: range(NUM_RECORDS)) # pylint: disable=range-builtin-not-iterating + | 'Map to bytes' >> + beam.Map(lambda x: RECORD + str(x).encode()).with_output_types(bytes) + | 'WriteToKinesis' >> WriteToKinesis( + stream_name=self.aws_kinesis_stream, + aws_access_key=self.aws_access_key, + aws_secret_key=self.aws_secret_key, + region=self.aws_region, + service_endpoint=self.aws_service_endpoint, + verify_certificate=(not self.use_localstack), + partition_key='1', + )) + + # TODO: Remove once BEAM-10664 is resolved + if self.use_localstack: + records = self.kinesis_helper.read_from_stream(self.aws_kinesis_stream) + self.assertEqual( + sorted(records), + sorted([RECORD + str(i).encode() for i in range(NUM_RECORDS)])) Review comment: I'll not write a separate read test for now because this can't be tested anyway and could be confusing later if there is some bug. I think that it'd be better to just leave test_kinesis_io_roundtrip and remove test_write once the problem is solved - it would reduce the amount of boto3 used in the test. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org