1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
#
# 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 . import common
import gc
import pyngus
class APITest(common.Test):
def test_create_destroy(self):
gc.enable()
gc.collect()
assert not gc.garbage, "Object leak: %s" % str(gc.garbage)
container = pyngus.Container("My-Container")
assert container.name == "My-Container"
container.destroy()
def test_create_connection(self):
gc.enable()
gc.collect()
assert not gc.garbage, "Object leak: %s" % str(gc.garbage)
container = pyngus.Container("A123")
container.create_connection("c1")
container.create_connection("c2")
c1 = container.get_connection("c1")
assert c1 and c1.name == "c1", "Connection not found!"
c3 = container.get_connection("c3")
assert not c3, "Bad connection returned!"
container.destroy()
del c1
def test_cleanup(self):
gc.enable()
gc.collect()
assert not gc.garbage, "Object leak: %s" % str(gc.garbage)
container = pyngus.Container("abc")
c1 = container.create_connection("c1")
c2 = container.create_connection("c2")
assert c2
del c2
gc.collect()
c2 = container.get_connection("c2")
assert c2
c1 = container.get_connection("c1")
assert c1
c1.create_receiver("r1")
c1.create_sender("s1")
del c1
del c2
container.destroy()
del container
gc.collect()
assert not gc.garbage, "Object leak: %s" % str(gc.garbage)
def test_need_processing(self):
gc.enable()
gc.collect()
assert not gc.garbage, "Object leak: %s" % str(gc.garbage)
container = pyngus.Container("abc")
c1 = container.create_connection("c1")
c2 = container.create_connection("c2")
props = {"idle-time-out": 10}
c3 = container.create_connection("c3", properties=props)
c4 = container.create_connection("c4")
c1.open()
c2.open()
c3.open()
c4.open()
# every connection should need both input and output,
# but no timers yet (connection's not up)
r, w, t = container.need_processing()
assert c1 in r and c1 in w
assert c2 in r and c2 in w
assert c3 in r and c3 in w
assert c4 in r and c4 in w
assert not t
common.process_connections(c1, c2)
common.process_connections(c3, c4)
# After connections come up, no connection should need to do I/O, and
# only c4 and c4 should be in the timer list:
r, w, t = container.need_processing()
assert c1 in r
assert c2 in r
assert c3 in r
assert c4 in r
assert not w
assert len(t) == 2 and c3 in t and c4 in t
container.destroy()
|