summaryrefslogtreecommitdiff
path: root/python/tests
diff options
context:
space:
mode:
Diffstat (limited to 'python/tests')
-rw-r--r--python/tests/__init__.py5
-rw-r--r--python/tests/assembler.py77
-rw-r--r--python/tests/connection010.py137
-rw-r--r--python/tests/datatypes.py91
-rw-r--r--python/tests/framer.py92
-rw-r--r--python/tests/spec010.py60
6 files changed, 462 insertions, 0 deletions
diff --git a/python/tests/__init__.py b/python/tests/__init__.py
index 41dcc705e6..8e9eeb44d6 100644
--- a/python/tests/__init__.py
+++ b/python/tests/__init__.py
@@ -22,3 +22,8 @@
from codec import *
from queue import *
from spec import *
+from framer import *
+from assembler import *
+from datatypes import *
+from connection010 import *
+from spec010 import *
diff --git a/python/tests/assembler.py b/python/tests/assembler.py
new file mode 100644
index 0000000000..b76924e59d
--- /dev/null
+++ b/python/tests/assembler.py
@@ -0,0 +1,77 @@
+#
+# 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 threading import *
+from unittest import TestCase
+from qpid.util import connect, listen
+from qpid.assembler import *
+
+PORT = 1234
+
+class AssemblerTest(TestCase):
+
+ def setUp(self):
+ started = Event()
+ self.running = True
+
+ def run():
+ running = True
+ for s in listen("0.0.0.0", PORT, lambda: self.running, lambda: started.set()):
+ asm = Assembler(s)
+ try:
+ asm.write_header(*asm.read_header()[-2:])
+ while True:
+ seg = asm.read_segment()
+ asm.write_segment(seg)
+ except Closed:
+ pass
+
+ self.server = Thread(target=run)
+ self.server.setDaemon(True)
+ self.server.start()
+
+ started.wait(3)
+
+ def tearDown(self):
+ self.running = False
+ self.server.join()
+
+ def test(self):
+ asm = Assembler(connect("0.0.0.0", PORT), max_payload = 1)
+ asm.write_header(0, 10)
+ asm.write_segment(Segment(True, False, 1, 2, 3, "TEST"))
+ asm.write_segment(Segment(False, True, 1, 2, 3, "ING"))
+
+ assert asm.read_header() == ("AMQP", 1, 1, 0, 10)
+
+ seg = asm.read_segment()
+ assert seg.first == True
+ assert seg.last == False
+ assert seg.type == 1
+ assert seg.track == 2
+ assert seg.channel == 3
+ assert seg.payload == "TEST"
+
+ seg = asm.read_segment()
+ assert seg.first == False
+ assert seg.last == True
+ assert seg.type == 1
+ assert seg.track == 2
+ assert seg.channel == 3
+ assert seg.payload == "ING"
diff --git a/python/tests/connection010.py b/python/tests/connection010.py
new file mode 100644
index 0000000000..5e4bf983da
--- /dev/null
+++ b/python/tests/connection010.py
@@ -0,0 +1,137 @@
+#
+# 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 threading import *
+from unittest import TestCase
+from qpid.util import connect, listen
+from qpid.connection010 import *
+from qpid.datatypes import Message
+from qpid.testlib import testrunner
+from qpid.delegates import Server
+from qpid.queue import Queue
+from qpid.spec010 import load
+from qpid.session import Delegate
+
+PORT = 1234
+
+class TestServer:
+
+ def __init__(self, queue):
+ self.queue = queue
+
+ def connection(self, connection):
+ return Server(connection, delegate=self.session)
+
+ def session(self, session):
+ return TestSession(session, self.queue)
+
+class TestSession(Delegate):
+
+ def __init__(self, session, queue):
+ self.session = session
+ self.queue = queue
+
+ def queue_query(self, qq):
+ return qq.type.result.type.new((qq.queue,), {})
+
+ def message_transfer(self, cmd):
+ self.queue.put(cmd)
+
+ def body(self, body):
+ self.queue.put(body)
+
+class ConnectionTest(TestCase):
+
+ def setUp(self):
+ self.spec = load(testrunner.get_spec_file("amqp.0-10.xml"))
+ self.queue = Queue()
+ self.running = True
+ started = Event()
+
+ def run():
+ ts = TestServer(self.queue)
+ for s in listen("0.0.0.0", PORT, lambda: self.running, lambda: started.set()):
+ conn = Connection(s, self.spec, ts.connection)
+ try:
+ conn.start(5)
+ except Closed:
+ pass
+
+ self.server = Thread(target=run)
+ self.server.setDaemon(True)
+ self.server.start()
+
+ started.wait(3)
+
+ def tearDown(self):
+ self.running = False
+ connect("0.0.0.0", PORT).close()
+ self.server.join(3)
+
+ def test(self):
+ c = Connection(connect("0.0.0.0", PORT), self.spec)
+ c.start(10)
+
+ ssn1 = c.session("test1")
+ ssn2 = c.session("test2")
+
+ assert ssn1 == c.sessions["test1"]
+ assert ssn2 == c.sessions["test2"]
+ assert ssn1.channel != None
+ assert ssn2.channel != None
+ assert ssn1 in c.attached.values()
+ assert ssn2 in c.attached.values()
+
+ ssn1.close(5)
+
+ assert ssn1.channel == None
+ assert ssn1 not in c.attached.values()
+ assert ssn2 in c.sessions.values()
+
+ ssn2.close(5)
+
+ assert ssn2.channel == None
+ assert ssn2 not in c.attached.values()
+ assert ssn2 not in c.sessions.values()
+
+ ssn = c.session("session")
+
+ assert ssn.channel != None
+ assert ssn in c.sessions.values()
+
+ destinations = ("one", "two", "three")
+
+ for d in destinations:
+ ssn.message_transfer(d)
+
+ for d in destinations:
+ cmd = self.queue.get(10)
+ assert cmd.destination == d
+
+ msg = Message("this is a test")
+ ssn.message_transfer("four", message=msg)
+ cmd = self.queue.get(10)
+ assert cmd.destination == "four"
+ body = self.queue.get(10)
+ assert body.payload == msg.body
+ assert body.last
+
+ qq = ssn.queue_query("asdf")
+ assert qq.queue == "asdf"
+ c.close(5)
diff --git a/python/tests/datatypes.py b/python/tests/datatypes.py
new file mode 100644
index 0000000000..cafd53c89f
--- /dev/null
+++ b/python/tests/datatypes.py
@@ -0,0 +1,91 @@
+#
+# 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 unittest import TestCase
+from qpid.datatypes import *
+
+class RangeSetTest(TestCase):
+
+ def check(self, ranges):
+ posts = []
+ for range in ranges:
+ posts.append(range.lower)
+ posts.append(range.upper)
+
+ sorted = posts[:]
+ sorted.sort()
+
+ assert posts == sorted
+
+ idx = 1
+ while idx + 1 < len(posts):
+ assert posts[idx] + 1 != posts[idx+1]
+ idx += 2
+
+ def test(self):
+ rs = RangeSet()
+
+ self.check(rs.ranges)
+
+ rs.add(1)
+
+ assert 1 in rs
+ assert 2 not in rs
+ assert 0 not in rs
+ self.check(rs.ranges)
+
+ rs.add(2)
+
+ assert 0 not in rs
+ assert 1 in rs
+ assert 2 in rs
+ assert 3 not in rs
+ self.check(rs.ranges)
+
+ rs.add(0)
+
+ assert -1 not in rs
+ assert 0 in rs
+ assert 1 in rs
+ assert 2 in rs
+ assert 3 not in rs
+ self.check(rs.ranges)
+
+ rs.add(37)
+
+ assert -1 not in rs
+ assert 0 in rs
+ assert 1 in rs
+ assert 2 in rs
+ assert 3 not in rs
+ assert 36 not in rs
+ assert 37 in rs
+ assert 38 not in rs
+ self.check(rs.ranges)
+
+ rs.add(-1)
+ self.check(rs.ranges)
+
+ rs.add(-3)
+ self.check(rs.ranges)
+
+ rs.add_range(Range(1, 20))
+ assert 21 not in rs
+ assert 20 in rs
+ self.check(rs.ranges)
diff --git a/python/tests/framer.py b/python/tests/framer.py
new file mode 100644
index 0000000000..ea2e04e954
--- /dev/null
+++ b/python/tests/framer.py
@@ -0,0 +1,92 @@
+#
+# 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 threading import *
+from unittest import TestCase
+from qpid.util import connect, listen
+from qpid.framer import *
+
+PORT = 1234
+
+class FramerTest(TestCase):
+
+ def setUp(self):
+ self.running = True
+ started = Event()
+ def run():
+ for s in listen("0.0.0.0", PORT, lambda: self.running, lambda: started.set()):
+ conn = Framer(s)
+ try:
+ conn.write_header(*conn.read_header()[-2:])
+ while True:
+ frame = conn.read_frame()
+ conn.write_frame(frame)
+ except Closed:
+ pass
+
+ self.server = Thread(target=run)
+ self.server.setDaemon(True)
+ self.server.start()
+
+ started.wait(3)
+
+ def tearDown(self):
+ self.running = False
+ self.server.join(3)
+
+ def test(self):
+ c = Framer(connect("0.0.0.0", PORT))
+
+ c.write_header(0, 10)
+ assert c.read_header() == ("AMQP", 1, 1, 0, 10)
+
+ c.write_frame(Frame(FIRST_FRM, 1, 2, 3, "THIS"))
+ c.write_frame(Frame(0, 1, 2, 3, "IS"))
+ c.write_frame(Frame(0, 1, 2, 3, "A"))
+ c.write_frame(Frame(LAST_FRM, 1, 2, 3, "TEST"))
+
+ f = c.read_frame()
+ assert f.flags & FIRST_FRM
+ assert not (f.flags & LAST_FRM)
+ assert f.type == 1
+ assert f.track == 2
+ assert f.channel == 3
+ assert f.payload == "THIS"
+
+ f = c.read_frame()
+ assert f.flags == 0
+ assert f.type == 1
+ assert f.track == 2
+ assert f.channel == 3
+ assert f.payload == "IS"
+
+ f = c.read_frame()
+ assert f.flags == 0
+ assert f.type == 1
+ assert f.track == 2
+ assert f.channel == 3
+ assert f.payload == "A"
+
+ f = c.read_frame()
+ assert f.flags & LAST_FRM
+ assert not (f.flags & FIRST_FRM)
+ assert f.type == 1
+ assert f.track == 2
+ assert f.channel == 3
+ assert f.payload == "TEST"
diff --git a/python/tests/spec010.py b/python/tests/spec010.py
new file mode 100644
index 0000000000..1c520ee323
--- /dev/null
+++ b/python/tests/spec010.py
@@ -0,0 +1,60 @@
+#
+# 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 unittest import TestCase
+from qpid.spec010 import load
+from qpid.codec010 import Codec, StringCodec
+from qpid.testlib import testrunner
+from qpid.datatypes import Struct
+
+class SpecTest(TestCase):
+
+ def setUp(self):
+ self.spec = load(testrunner.get_spec_file("amqp.0-10.xml"))
+
+ def testSessionHeader(self):
+ hdr = self.spec["session.header"]
+ sc = StringCodec(self.spec)
+ hdr.encode(sc, Struct({"sync": True}))
+ assert sc.encoded == "\x01\x01"
+
+ sc = StringCodec(self.spec)
+ hdr.encode(sc, Struct({"sync": False}))
+ assert sc.encoded == "\x01\x00"
+
+ def encdec(self, type, value):
+ sc = StringCodec(self.spec)
+ type.encode(sc, value)
+ decoded = type.decode(sc)
+ return decoded
+
+ def testMessageProperties(self):
+ props = Struct({"content_length": 0xDEADBEEF,
+ "reply_to":
+ Struct({"exchange": "the exchange name", "routing_key": "the routing key"})})
+ dec = self.encdec(self.spec["message.message_properties"], props)
+ assert props.content_length == dec.content_length
+ assert props.reply_to.exchange == dec.reply_to.exchange
+ assert props.reply_to.routing_key == dec.reply_to.routing_key
+
+ def testMessageSubscribe(self):
+ cmd = Struct({"exclusive": True, "destination": "this is a test"})
+ dec = self.encdec(self.spec["message.subscribe"], cmd)
+ assert cmd.exclusive == dec.exclusive
+ assert cmd.destination == dec.destination