[
https://issues.apache.org/jira/browse/BEAM-7586?focusedWorklogId=267230&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-267230
]
ASF GitHub Bot logged work on BEAM-7586:
----------------------------------------
Author: ASF GitHub Bot
Created on: 26/Jun/19 03:00
Start Date: 26/Jun/19 03:00
Worklog Time Spent: 10m
Work Description: chamikaramj commented on pull request #8895:
[BEAM-7586] Add Integration test for python mongodb io
URL: https://github.com/apache/beam/pull/8895#discussion_r297466816
##########
File path: sdks/python/apache_beam/io/mongodbio_pipeline.py
##########
@@ -0,0 +1,85 @@
+#
+# 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.
+#
+
+from __future__ import absolute_import
+
+import argparse
+import logging
+import time
+
+import apache_beam as beam
+from apache_beam.options.pipeline_options import PipelineOptions
+from apache_beam.testing.test_pipeline import TestPipeline
+from apache_beam.testing.util import assert_that
+from apache_beam.testing.util import equal_to
+
+
+def run(argv=None):
+ default_db = 'beam_mongodbio_it_db'
+ default_coll = 'integration_test_%d' % time.time()
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--mongo_uri',
+ default='mongodb://localhost:27017',
+ help='mongo uri string for connection')
+ parser.add_argument('--mongo_db',
+ default=default_db,
+ help='mongo uri string for connection')
+ parser.add_argument('--mongo_coll',
+ default=default_coll,
+ help='mongo uri string for connection')
+ parser.add_argument('--num_documents',
+ default=1000,
+ help='The expected number of documents to be generated '
+ 'for write or read',
+ type=int)
+ parser.add_argument('--batch_size',
+ default=100,
+ help=('batch size for writing to mongodb'))
+ known_args, pipeline_args = parser.parse_known_args(argv)
+
+ # Test Write to MongoDB
+ with TestPipeline(options=PipelineOptions(pipeline_args)) as p:
+ logging.info('Writing %d documents to mongodb' % known_args.num_documents)
+ docs = [{'test_document_n': x} for x in range(known_args.num_documents)]
+
+ start_time = time.time()
+ _ = p | 'Create documents' >> beam.Create(docs) \
+ | 'WriteToMongoDB' >> beam.io.WriteToMongoDB(known_args.mongo_uri,
+ known_args.mongo_db,
+ known_args.mongo_coll,
+ known_args.batch_size)
+ logging.info('Writing %d documents to mongodb finished in %.3f seconds' %
+ (known_args.num_documents, time.time() - start_time))
+
+ # Test Read from MongoDB
+ with TestPipeline(options=PipelineOptions(pipeline_args)) as p:
+ start_time = time.time()
+ logging.info('Reading from mongodb %s:%s' %
+ (known_args.mongo_db, known_args.mongo_coll))
+ r = p | 'ReadFromMongoDB' >> beam.io.ReadFromMongoDB(known_args.mongo_uri,
+ known_args.mongo_db,
+
known_args.mongo_coll)\
+ | 'Count' >> beam.combiners.Count.Globally()
Review comment:
Can we verify the contents of the documents instead of just the count ?
----------------------------------------------------------------
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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 267230)
> Add Integration Test for MongoDbIO in python sdk
> -------------------------------------------------
>
> Key: BEAM-7586
> URL: https://issues.apache.org/jira/browse/BEAM-7586
> Project: Beam
> Issue Type: Sub-task
> Components: sdk-py-core
> Reporter: Yichi Zhang
> Assignee: Yichi Zhang
> Priority: Major
> Time Spent: 1h 40m
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)