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
|
# **********************************************************************
#
# Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
#
# This copy of Ice is licensed to you under the terms described in the
# ICE_LICENSE file included in this distribution.
#
# **********************************************************************
import Ice, Test, threading
def test(b):
if not b:
raise RuntimeError('test assertion failed')
class CallbackBase:
def __init__(self):
self._called = False
self._cond = threading.Condition()
def check(self):
self._cond.acquire()
try:
while not self._called:
self._cond.wait()
self._called = False
finally:
self._cond.release()
def called(self):
self._cond.acquire()
self._called = True
self._cond.notify()
self._cond.release()
class CallbackSuccess(CallbackBase):
def response(self):
self.called()
def exception(self, ex):
test(False)
class CallbackFail(CallbackBase):
def response(self):
test(False)
def exception(self, ex):
test(isinstance(ex, Ice.ConnectionLostException))
self.called()
def allTests(communicator):
print "testing stringToProxy...",
ref = "retry:default -p 12010"
base1 = communicator.stringToProxy(ref)
test(base1)
base2 = communicator.stringToProxy(ref)
test(base2)
print "ok"
print "testing checked cast...",
retry1 = Test.RetryPrx.checkedCast(base1)
test(retry1)
test(retry1 == base1)
retry2 = Test.RetryPrx.checkedCast(base2)
test(retry2)
test(retry2 == base2)
print "ok"
print "calling regular operation with first proxy...",
retry1.op(False)
print "ok"
print "calling operation to kill connection with second proxy...",
try:
retry2.op(True)
test(False)
except Ice.ConnectionLostException:
print "ok"
print "calling regular operation with first proxy again...",
retry1.op(False)
print "ok"
cb1 = CallbackSuccess()
cb2 = CallbackFail()
print "calling regular AMI operation with first proxy...",
retry1.begin_op(False, cb1.response, cb1.exception)
cb1.check()
print "ok"
print "calling AMI operation to kill connection with second proxy...",
retry2.begin_op(True, cb2.response, cb2.exception)
cb2.check()
print "ok"
print "calling regular AMI operation with first proxy again...",
retry1.begin_op(False, cb1.response, cb1.exception)
cb1.check()
print "ok"
return retry1
|