DISPATCH-731: add functional tests

Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/2c80f108
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/2c80f108
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/2c80f108

Branch: refs/heads/master
Commit: 2c80f10877c2837af48244ff0315a12f7042eda3
Parents: f6dab30
Author: Kenneth Giusti <kgiu...@apache.org>
Authored: Wed Aug 2 12:21:33 2017 -0400
Committer: Kenneth Giusti <kgiu...@apache.org>
Committed: Thu Aug 3 10:06:04 2017 -0400

----------------------------------------------------------------------
 tests/system_tests_qdmanage.py    | 54 +++++++++++++++++++++++-
 tests/system_tests_two_routers.py | 77 ++++++++++++++++++++++++++++++++++
 2 files changed, 130 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/2c80f108/tests/system_tests_qdmanage.py
----------------------------------------------------------------------
diff --git a/tests/system_tests_qdmanage.py b/tests/system_tests_qdmanage.py
index 91b38c0..9b92dbc 100644
--- a/tests/system_tests_qdmanage.py
+++ b/tests/system_tests_qdmanage.py
@@ -351,7 +351,59 @@ class QdmanageTest(TestCase):
                          ' name=' + ssl_profile_name + ' certDb=' + 
self.ssl_file('ca-certificate.pem')
         output = json.loads(self.run_qdmanage(ssl_create_command))
         self.assertEqual(output['name'], ssl_profile_name)
-        self.run_qdmanage('DELETE --type=sslProfile --name=' + 
ssl_profile_name)
+        self.run_qdmanage('DELETE --type=sslProfile --name=' +
+        ssl_profile_name)
+
+    def test_create_delete_address_pattern(self):
+        config = [('mercury.*.earth.#', 'closest'),
+                  ('*/mars/*/#', 'multicast'),
+                  ('*.mercury', 'closest'),
+                  ('*/#/pluto', 'multicast')]
+        long_type = 'org.apache.qpid.dispatch.router.config.address'
+
+        # add patterns:
+        pcount = 0
+        for p in config:
+            query_command = 'CREATE --type=' + long_type + \
+                                             ' pattern=' + p[0] + \
+                                             ' distribution=' + p[1] + \
+                                             ' name=Pattern' + str(pcount)
+            self.run_qdmanage(query_command)
+            pcount += 1
+
+        # verify correctly added:
+        query_command = 'QUERY --type=' + long_type
+        output = json.loads(self.run_qdmanage(query_command))
+        total = len(output)
+
+        pcount = 0
+        for o in output:
+            pattern = o.get('pattern')
+            if pattern is not None:
+                for p in config:
+                    if p[0] == pattern:
+                        pcount += 1
+                        self.assertEqual(p[1], o.get('distribution'))
+        self.assertEqual(pcount, len(config))
+
+        # delete
+        pcount = 0
+        for p in config:
+            query_command = 'DELETE --type=' + long_type + \
+                                             ' --name=Pattern' + str(pcount)
+            self.run_qdmanage(query_command)
+            pcount += 1
+
+        # verify deleted:
+        query_command = 'QUERY --type=' + long_type
+        output = json.loads(self.run_qdmanage(query_command))
+        self.assertEqual(len(output), total - len(config))
+        for o in output:
+            pattern = o.get('pattern')
+            if pattern is not None:
+                for p in config:
+                    self.assertNotEqual(p[0], pattern)
+
 
 if __name__ == '__main__':
     unittest.main(main_module())

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/2c80f108/tests/system_tests_two_routers.py
----------------------------------------------------------------------
diff --git a/tests/system_tests_two_routers.py 
b/tests/system_tests_two_routers.py
index db2b20b..cebc74a 100644
--- a/tests/system_tests_two_routers.py
+++ b/tests/system_tests_two_routers.py
@@ -57,6 +57,20 @@ class RouterTest(TestCase):
                 ('address', {'prefix': 'closest', 'distribution': 'closest'}),
                 ('address', {'prefix': 'spread', 'distribution': 'balanced'}),
                 ('address', {'prefix': 'multicast', 'distribution': 
'multicast'}),
+
+                # for testing pattern matching
+                ('address', {'pattern': 'a.b.c.d',
+                             'distribution': 'closest'}),
+                ('address', {'pattern': '#.b.c.d',
+                             'distribution': 'multicast'}),
+                ('address', {'pattern': 'a/*/#/d',
+                             'distribution': 'closest'}),
+                ('address', {'pattern': '*/b/c/d',
+                             'distribution': 'multicast'}),
+                ('address', {'pattern': 'a.x.d',
+                             'distribution': 'closest'}),
+                ('address', {'pattern': 'a.*.d',
+                             'distribution': 'multicast'}),
                 connection
             ]
 
@@ -1090,6 +1104,69 @@ class RouterTest(TestCase):
         M1.stop()
         M2.stop()
 
+    def test_17_address_wildcard(self):
+        # verify proper distribution is selected by wildcard
+        addresses = [
+            # (address, count of messages expected to be received)
+            ('a.b.c.d',   1), # closest 'a.b.c.d'
+            ('b.c.d',     2), # multi   '#.b.c.d'
+            ('f.a.b.c.d', 2), # multi   '#.b.c.d
+            ('a.c.d',     2), # multi   'a.*.d'
+            ('a/c/c/d',   1), # closest 'a/*/#.d
+            ('a/x/z/z/d', 1), # closest 'a/*/#.d
+            ('a/x/d',     1), # closest 'a.x.d'
+            ('a.x.e',     1), # balanced  ----
+            ('m.b.c.d',   2)  # multi   '*/b/c/d'
+        ]
+
+        # two receivers per address - one for each router
+        receivers = []
+        for a in addresses:
+            for x in range(2):
+                M = self.messenger(timeout=0.1)
+                M.route("amqp:/*", self.routers[x].addresses[0]+"/$1")
+                M.start()
+                M.subscribe('amqp:/' + a[0])
+                receivers.append(M)
+            self.routers[0].wait_address(a[0], 1, 1)
+            self.routers[1].wait_address(a[0], 1, 1)
+
+        # single sender sends one message to each address
+        M1 = self.messenger()
+        M1.route("amqp:/*", self.routers[0].addresses[0]+"/$1")
+        M1.start()
+        for a in addresses:
+            tm = Message()
+            tm.address = 'amqp:/' + a[0]
+            tm.body = {'address': a[0]}
+            M1.put(tm)
+            M1.send()
+
+        # gather all received messages
+        msgs_recvd = {}
+        rm = Message()
+        for M in receivers:
+            try:
+                while True:
+                    M.recv(1)
+                    M.get(rm)
+                    index = rm.body.get('address', "ERROR")
+                    if index not in msgs_recvd:
+                        msgs_recvd[index] = 0
+                    msgs_recvd[index] += 1
+            except Exception as exc:
+                self.assertTrue("None" in str(exc))
+
+        # verify expected count == actual count
+        self.assertTrue("ERROR" not in msgs_recvd)
+        for a in addresses:
+            self.assertTrue(a[0] in msgs_recvd)
+            self.assertEqual(a[1], msgs_recvd[a[0]])
+
+        M1.stop()
+        for M in receivers:
+            M.stop()
+
 
 class Timeout(object):
     def __init__(self, parent):


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to