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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003-2006 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, threading
Ice.loadSlice('Test.ice')
import Test
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(5.0)
if self._called:
self._called = False
return True;
else:
return False
finally:
self._cond.release()
def called(self):
self._cond.acquire()
self._called = True
self._cond.notify()
self._cond.release()
class AMI_Test_pidI(CallbackBase):
def ice_response(self, pid):
self._pid = pid
self.called()
def ice_exception(self, ex):
test(False)
def pid(self):
return self._pid
class AMI_Test_shutdownI(CallbackBase):
def ice_response(self):
self.called()
def ice_exception(self, ex):
test(False)
class AMI_Test_abortI(CallbackBase):
def ice_response(self):
test(False)
def ice_exception(self, ex):
try:
raise ex
except Ice.ConnectionLostException:
pass
except Ice.ConnectFailedException:
pass
except Ice.Exception, ex:
print ex
test(False)
self.called()
class AMI_Test_idempotentAbortI(AMI_Test_abortI):
def ice_response(self):
test(False)
def ice_exception(self, ex):
AMI_Test_abortI.ice_exception(self, ex)
class AMI_Test_nonmutatingAbortI(AMI_Test_abortI):
def ice_response(self):
test(False)
def ice_exception(self, ex):
AMI_Test_abortI.ice_exception(self, ex)
def allTests(communicator, ports):
print "testing stringToProxy... ",
ref = "test"
for p in ports:
ref = ref + ":default -t 60000 -p " + str(p)
base = communicator.stringToProxy(ref)
test(base)
print "ok"
print "testing checked cast... ",
obj = Test.TestIntfPrx.checkedCast(base)
test(obj)
test(obj == base)
print "ok"
oldPid = 0
ami = False
i = 1
j = 0
while i <= len(ports):
if j > 3:
j = 0
ami = not ami
if not ami:
print "testing server #%d... " % i,
pid = obj.pid()
test(pid != oldPid)
print "ok"
oldPid = pid
else:
print "testing server #%d with AMI... " % i,
cb = AMI_Test_pidI()
obj.pid_async(cb)
test(cb.check())
pid = cb.pid()
test(pid != oldPid)
print "ok"
oldPid = pid
if j == 0:
if not ami:
print "shutting down server #%d... " % i,
obj.shutdown()
print "ok"
else:
print "shutting down server #%d with AMI... " % i,
cb = AMI_Test_shutdownI()
obj.shutdown_async(cb)
test(cb.check())
print "ok"
elif j == 1 or i + 1 > len(ports):
if not ami:
print "aborting server #%d... " % i,
try:
obj.abort()
test(False)
except Ice.ConnectionLostException:
print "ok"
except Ice.ConnectFailedException:
print "ok"
else:
print "aborting server #%d with AMI... " % i,
cb = AMI_Test_abortI()
obj.abort_async(cb)
test(cb.check())
print "ok"
elif j == 2:
if not ami:
print "aborting server #%d and #%d with idempotent call... " % (i, i + 1),
try:
obj.idempotentAbort()
test(False)
except Ice.ConnectionLostException:
print "ok"
except Ice.ConnectFailedException:
print "ok"
else:
print "aborting server #%d and #%d with idempotent AMI call... " % (i, i + 1),
cb = AMI_Test_idempotentAbortI()
obj.idempotentAbort_async(cb)
test(cb.check())
print "ok"
i = i + 1
elif j == 3:
if not ami:
print "aborting server #%d and #%d with nonmutating call... " % (i, i + 1),
try:
obj.nonmutatingAbort()
test(False)
except Ice.ConnectionLostException:
print "ok"
except Ice.ConnectFailedException:
print "ok"
else:
print "aborting server #%d and #%d with nonmutating AMI call... " % (i, i + 1),
cb = AMI_Test_nonmutatingAbortI()
obj.nonmutatingAbort_async(cb)
test(cb.check())
print "ok"
i = i + 1
else:
assert(False)
i = i + 1
j = j + 1
print "testing whether all servers are gone... ",
try:
obj.ice_ping()
test(False)
except Ice.LocalException:
print "ok"
|