You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2019/02/02 03:07:02 UTC

[pulsar] branch master updated: Re-enable running Python tests in CI PR validation (#3424)

This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 2b03106  Re-enable running Python tests in CI PR validation (#3424)
2b03106 is described below

commit 2b03106b3085178e4593b919bc91163108c33a2b
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Fri Feb 1 19:06:56 2019 -0800

    Re-enable running Python tests in CI PR validation (#3424)
    
    * Re-enable running Python tests in CI PR validation
    
    * Fixed python test topic name
    
    * Copy both test scripts into /tmp
    
    * Fixed tests with schema changes
    
    * Use isinstance for py2 compat
    
    * Clear multi-topics consumer queue to avoid thread deadlock
    
    * Ensure fields list is sorted by name
---
 pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc     |  1 +
 pulsar-client-cpp/python/pulsar/__init__.py          | 14 +++++++++++---
 pulsar-client-cpp/python/pulsar/schema/definition.py |  4 ++--
 pulsar-client-cpp/python/pulsar_test.py              | 12 ++++++++++--
 pulsar-client-cpp/run-unit-tests.sh                  |  3 +--
 5 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc b/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc
index 98385d5..963c20f 100644
--- a/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc
+++ b/pulsar-client-cpp/lib/MultiTopicsConsumerImpl.cc
@@ -414,6 +414,7 @@ void MultiTopicsConsumerImpl::handleSingleConsumerClose(Result result, std::stri
 
     // closed all consumers
     if (numberTopicPartitions_->load() == 0) {
+        messages_.clear();
         consumers_.clear();
         topicsPartitions_.clear();
         unAckedMessageTrackerPtr_->clear();
diff --git a/pulsar-client-cpp/python/pulsar/__init__.py b/pulsar-client-cpp/python/pulsar/__init__.py
index 427bd7b..8118b4e 100644
--- a/pulsar-client-cpp/python/pulsar/__init__.py
+++ b/pulsar-client-cpp/python/pulsar/__init__.py
@@ -909,7 +909,10 @@ class Consumer:
         * `message`:
           The received message or message id.
         """
-        self._consumer.acknowledge(message)
+        if isinstance(message, Message):
+            self._consumer.acknowledge(message._message)
+        else:
+            self._consumer.acknowledge(message)
 
     def acknowledge_cumulative(self, message):
         """
@@ -924,7 +927,10 @@ class Consumer:
         * `message`:
           The received message or message id.
         """
-        self._consumer.acknowledge_cumulative(message)
+        if isinstance(message, Message):
+            self._consumer.acknowledge_cumulative(message._message)
+        else:
+            self._consumer.acknowledge_cumulative(message)
 
     def pause_message_listener(self):
         """
@@ -1036,7 +1042,9 @@ def _check_type_or_none(var_type, var, name):
 
 
 def _listener_wrapper(listener, schema):
-    def wrapper(c, msg):
+    def wrapper(consumer, msg):
+        c = Consumer()
+        c._consumer = consumer
         m = Message()
         m._message = msg
         m._schema = schema
diff --git a/pulsar-client-cpp/python/pulsar/schema/definition.py b/pulsar-client-cpp/python/pulsar/schema/definition.py
index 4658c03..1c3e025 100644
--- a/pulsar-client-cpp/python/pulsar/schema/definition.py
+++ b/pulsar-client-cpp/python/pulsar/schema/definition.py
@@ -76,10 +76,10 @@ class Record(with_metaclass(RecordMeta, object)):
             'fields': []
         }
 
-        for name, value in cls._fields.items():
+        for name in sorted(cls._fields.keys()):
             schema['fields'].append({
                 'name': name,
-                'type': value.schema()
+                'type': cls._fields[name].schema()
             })
         return schema
 
diff --git a/pulsar-client-cpp/python/pulsar_test.py b/pulsar-client-cpp/python/pulsar_test.py
index 9f2aa89..8710350 100755
--- a/pulsar-client-cpp/python/pulsar_test.py
+++ b/pulsar-client-cpp/python/pulsar_test.py
@@ -474,7 +474,7 @@ class PulsarTest(TestCase):
 
         content = 'test'.encode('utf-8')
 
-        self._check_value_error(lambda: producer.send(5))
+        self._check_type_error(lambda: producer.send(5))
         self._check_value_error(lambda: producer.send(content, properties='test'))
         self._check_value_error(lambda: producer.send(content, partition_key=5))
         self._check_value_error(lambda: producer.send(content, sequence_id='test'))
@@ -839,7 +839,7 @@ class PulsarTest(TestCase):
         consumer = client.subscribe('my-python-topic-producer-consumer-zstd',
                                     'my-sub',
                                     consumer_type=ConsumerType.Shared)
-        producer = client.create_producer('my-python-topic-producer-consumer',
+        producer = client.create_producer('my-python-topic-producer-consumer-zstd',
                                           compression_type=CompressionType.ZSTD)
         producer.send(b'hello')
 
@@ -899,6 +899,14 @@ class PulsarTest(TestCase):
         except ValueError:
             pass  # Expected
 
+    def _check_type_error(self, fun):
+        try:
+            fun()
+            # Should throw exception
+            self.assertTrue(False)
+        except TypeError:
+            pass  # Expected
+
 
 if __name__ == '__main__':
     main()
diff --git a/pulsar-client-cpp/run-unit-tests.sh b/pulsar-client-cpp/run-unit-tests.sh
index 9dd1c95..f709c83 100755
--- a/pulsar-client-cpp/run-unit-tests.sh
+++ b/pulsar-client-cpp/run-unit-tests.sh
@@ -34,7 +34,6 @@ if [ -f /gtest-parallel/gtest-parallel ]; then
         echo "Running tests: $1"
     fi
     /gtest-parallel/gtest-parallel ./main $tests --workers=10
-    exit 0
     RES=$?
 else
     ./main
@@ -55,7 +54,7 @@ if [ $RES -eq 0 ]; then
 
     # Running tests from a different directory to avoid importing directly
     # from the current dir, but rather using the installed wheel file
-    cp pulsar_test.py /tmp
+    cp *_test.py /tmp
     pushd /tmp
 
     python pulsar_test.py