[ 
https://issues.apache.org/jira/browse/BEAM-5301?focusedWorklogId=142263&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-142263
 ]

ASF GitHub Bot logged work on BEAM-5301:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 07/Sep/18 18:12
            Start Date: 07/Sep/18 18:12
    Worklog Time Spent: 10m 
      Work Description: pabloem closed pull request #6333: [BEAM-5301] migrate 
datastore_worcount python integration test to Beam
URL: https://github.com/apache/beam/pull/6333
 
 
   

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/sdks/python/apache_beam/examples/cookbook/datastore_wordcount.py 
b/sdks/python/apache_beam/examples/cookbook/datastore_wordcount.py
index b8c4213643e..2e5dab8a160 100644
--- a/sdks/python/apache_beam/examples/cookbook/datastore_wordcount.py
+++ b/sdks/python/apache_beam/examples/cookbook/datastore_wordcount.py
@@ -69,12 +69,6 @@
 import uuid
 from builtins import object
 
-from google.cloud.proto.datastore.v1 import entity_pb2
-from google.cloud.proto.datastore.v1 import query_pb2
-from googledatastore import helper as datastore_helper
-from googledatastore import PropertyFilter
-from past.builtins import unicode
-
 import apache_beam as beam
 from apache_beam.io import ReadFromText
 from apache_beam.io.gcp.datastore.v1.datastoreio import ReadFromDatastore
@@ -84,6 +78,18 @@
 from apache_beam.options.pipeline_options import PipelineOptions
 from apache_beam.options.pipeline_options import SetupOptions
 
+# Protect against environments where datastore library is not available.
+# pylint: disable=wrong-import-order, wrong-import-position
+try:
+  from google.cloud.proto.datastore.v1 import entity_pb2
+  from google.cloud.proto.datastore.v1 import query_pb2
+  from googledatastore import helper as datastore_helper
+  from googledatastore import PropertyFilter
+  from past.builtins import unicode
+except ImportError:
+  pass
+# pylint: enable=wrong-import-order, wrong-import-position
+
 
 class WordExtractingDoFn(beam.DoFn):
   """Parse each line of input text into words."""
diff --git 
a/sdks/python/apache_beam/examples/cookbook/datastore_wordcount_it_test.py 
b/sdks/python/apache_beam/examples/cookbook/datastore_wordcount_it_test.py
new file mode 100644
index 00000000000..5005a6081e5
--- /dev/null
+++ b/sdks/python/apache_beam/examples/cookbook/datastore_wordcount_it_test.py
@@ -0,0 +1,67 @@
+#
+# 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.
+#
+
+"""End-to-end test for Datastore Wordcount example."""
+
+from __future__ import absolute_import
+
+import logging
+import time
+import unittest
+
+from hamcrest.core.core.allof import all_of
+from nose.plugins.attrib import attr
+
+from apache_beam.examples.cookbook import datastore_wordcount
+from apache_beam.testing.pipeline_verifiers import FileChecksumMatcher
+from apache_beam.testing.pipeline_verifiers import PipelineStateMatcher
+from apache_beam.testing.test_pipeline import TestPipeline
+
+
+class DatastoreWordCountIT(unittest.TestCase):
+
+  DATASTORE_WORDCOUNT_KIND = "DatastoreWordCount"
+  EXPECTED_CHECKSUM = '826f69ed0275858c2e098f1e8407d4e3ba5a4b3f'
+
+  @attr('IT')
+  def test_datastore_wordcount_it(self):
+    test_pipeline = TestPipeline(is_integration_test=True)
+    dataset = test_pipeline.get_option("project")
+    kind = self.DATASTORE_WORDCOUNT_KIND
+    output = '/'.join([test_pipeline.get_option('output'),
+                       str(int(time.time())),
+                       'datastore_wordcount_results'])
+
+    arg_sleep_secs = test_pipeline.get_option('sleep_secs')
+    sleep_secs = int(arg_sleep_secs) if arg_sleep_secs is not None else None
+    pipeline_verifiers = [PipelineStateMatcher(),
+                          FileChecksumMatcher(output + '*-of-*',
+                                              self.EXPECTED_CHECKSUM,
+                                              sleep_secs)]
+    extra_opts = {'dataset': dataset,
+                  'kind': kind,
+                  'output': output,
+                  'read_only': True,
+                  'on_success_matcher': all_of(*pipeline_verifiers)}
+
+    datastore_wordcount.run(test_pipeline.get_full_options_as_args(
+        **extra_opts))
+
+
+if __name__ == '__main__':
+  logging.getLogger().setLevel(logging.DEBUG)
+  unittest.main()


 

----------------------------------------------------------------
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:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 142263)
    Time Spent: 2h  (was: 1h 50m)

> Migrate integration tests for datastore_wordcount
> -------------------------------------------------
>
>                 Key: BEAM-5301
>                 URL: https://issues.apache.org/jira/browse/BEAM-5301
>             Project: Beam
>          Issue Type: Bug
>          Components: testing
>            Reporter: yifan zou
>            Assignee: yifan zou
>            Priority: Major
>          Time Spent: 2h
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to