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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
%{
**********************************************************************
Copyright (c) 2003-2017 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.
**********************************************************************
%}
classdef AllTests
methods(Static)
function r = connect(prx)
nRetry = 10;
while nRetry > 0
nRetry = nRetry - 1;
try
prx.ice_getConnection();
break;
catch ex
if isa(ex, 'Ice.ConnectTimeoutException')
% Can sporadically occur with slow machines
else
rethrow(ex);
end
end
end
r = prx.ice_getConnection(); % Establish connection
end
function r = allTests(app)
import test.Ice.timeout.Test.*;
communicator = app.communicator();
sref = ['timeout:', app.getTestEndpoint(0, '')];
obj = communicator.stringToProxy(sref);
assert(~isempty(obj));
mult = 1;
if ~strcmp(communicator.getProperties().getPropertyWithDefault('Ice.Default.Protocol', 'tcp'), 'tcp')
mult = 4;
end
timeout = TimeoutPrx.checkedCast(obj);
assert(~isempty(timeout));
fprintf('testing connect timeout... ');
%
% Expect ConnectTimeoutException.
%
to = timeout.ice_timeout(100 * mult);
timeout.holdAdapter(500 * mult);
try
to.op();
assert(false);
catch ex
% Expected.
assert(isa(ex, 'Ice.ConnectTimeoutException'));
end
%
% Expect success.
%
timeout.op(); % Ensure adapter is active.
to = timeout.ice_timeout(1000 * mult);
timeout.holdAdapter(500 * mult);
try
to.op();
catch ex
if isa(ex, 'Ice.ConnectTimeoutException')
assert(false);
else
rethrow(ex);
end
end
fprintf('ok\n');
% The sequence needs to be large enough to fill the write/recv buffers
bufSize = 2000000;
seq = zeros(1, bufSize, 'uint8');
fprintf('testing connection timeout... ');
%
% Expect TimeoutException.
%
to = timeout.ice_timeout(250);
AllTests.connect(to);
timeout.holdAdapter(750 * mult);
try
to.sendData(seq);
assert(false);
catch ex
% Expected.
assert(isa(ex, 'Ice.TimeoutException'));
end
%
% Expect success.
%
timeout.op(); % Ensure adapter is active.
to = timeout.ice_timeout(1000 * mult);
timeout.holdAdapter(500 * mult);
try
to.sendData(zeros(1, 1000000, 'uint8'));
catch ex
if isa(ex, 'Ice.TimeoutException')
assert(false);
else
rethrow(ex);
end
end
fprintf('ok\n');
fprintf('testing invocation timeout... ');
connection = obj.ice_getConnection();
to = timeout.ice_invocationTimeout(100);
assert(connection == to.ice_getConnection());
try
to.sleep(750 * mult);
assert(false);
catch ex
assert(isa(ex, 'Ice.InvocationTimeoutException'));
end
obj.ice_ping();
to = TimeoutPrx.checkedCast(obj.ice_invocationTimeout(500 * mult));
assert(connection == to.ice_getConnection());
try
to.sleep(100 * mult);
catch ex
if isa(ex, 'Ice.InvocationTimeoutException')
assert(false);
else
rethrow(ex);
end
end
assert(connection == to.ice_getConnection());
%
% Expect InvocationTimeoutException.
%
to = timeout.ice_invocationTimeout(100);
f = to.sleepAsync(750 * mult);
try
f.fetchOutputs();
catch ex
assert(isa(ex, 'Ice.TimeoutException'));
end
obj.ice_ping();
%
% Expect success.
%
to = timeout.ice_invocationTimeout(500 * mult);
f = to.sleepAsync(100 * mult);
f.fetchOutputs();
%
% Backward compatible connection timeouts
%
to = timeout.ice_invocationTimeout(-2).ice_timeout(250);
con = AllTests.connect(to);
try
to.sleep(750);
assert(false);
catch ex
if isa(ex, 'Ice.TimeoutException')
assert(~isempty(con));
try
con.getInfo();
assert(false);
catch ex
if isa(ex, 'Ice.TimeoutException')
% Connection got closed as well.
else
rethrow(ex);
end
end
end
end
obj.ice_ping();
try
con = AllTests.connect(to);
to.sleepAsync(750).fetchOutputs();
assert(false);
catch ex
assert(isa(ex, 'Ice.TimeoutException'));
assert(~isempty(con));
try
con.getInfo();
assert(false);
catch ex
if isa(ex, 'Ice.TimeoutException')
% Connection got closed as well.
else
rethrow(ex);
end
end
end
obj.ice_ping();
fprintf('ok\n');
fprintf('testing close timeout... ');
to = TimeoutPrx.uncheckedCast(obj.ice_timeout(250 * mult));
connection = AllTests.connect(to);
timeout.holdAdapter(600);
connection.close(Ice.ConnectionClose.GracefullyWithWait);
try
connection.getInfo(); % getInfo() doesn't throw in the closing state.
catch ex
assert(false);
end
pause(.650 * mult);
try
connection.getInfo();
assert(false);
catch ex
% Expected.
assert(isa(ex, 'Ice.ConnectionManuallyClosedException'));
assert(ex.graceful);
end
timeout.op(); % Ensure adapter is active.
fprintf('ok\n');
fprintf('testing timeout overrides... ');
%
% Test Ice.Override.Timeout. This property overrides all
% endpoint timeouts.
%
initData = app.createInitializationData();
initData.properties_ = communicator.getProperties().clone();
initData.properties_.setProperty('Ice.Override.ConnectTimeout', '250');
initData.properties_.setProperty('Ice.Override.Timeout', '100');
comm = app.initialize(initData);
to = TimeoutPrx.uncheckedCast(comm.stringToProxy(sref));
AllTests.connect(to);
timeout.holdAdapter(500 * mult);
try
to.sendData(seq);
assert(false);
catch ex
% Expected.
assert(isa(ex, 'Ice.TimeoutException'));
end
%
% Calling ice_timeout() should have no effect.
%
timeout.op(); % Ensure adapter is active.
to = TimeoutPrx.uncheckedCast(to.ice_timeout(1000 * mult));
AllTests.connect(to);
timeout.holdAdapter(500 * mult);
try
to.sendData(seq);
assert(false);
catch ex
% Expected.
assert(isa(ex, 'Ice.TimeoutException'));
end
comm.destroy();
%
% Test Ice.Override.ConnectTimeout.
%
initData = app.createInitializationData();
initData.properties_ = communicator.getProperties().clone();
if mult == 1
initData.properties_.setProperty('Ice.Override.ConnectTimeout', '250');
else
initData.properties_.setProperty('Ice.Override.ConnectTimeout', '2500');
end
comm = app.initialize(initData);
to = TimeoutPrx.uncheckedCast(comm.stringToProxy(sref));
timeout.holdAdapter(750 * mult);
try
to.op();
assert(false);
catch ex
% Expected.
assert(isa(ex, 'Ice.ConnectTimeoutException'));
end
%
% Calling ice_timeout() should have no effect on the connect timeout.
%
timeout.op(); % Ensure adapter is active.
timeout.holdAdapter(750 * mult);
to = to.ice_timeout(1000 * mult);
try
to.op();
assert(false);
catch ex
% Expected.
assert(isa(ex, 'Ice.ConnectTimeoutException'));
end
%
% Verify that timeout set via ice_timeout() is still used for requests.
%
timeout.op(); % Ensure adapter is active.
to = to.ice_timeout(250);
AllTests.connect(to);
timeout.holdAdapter(750 * mult);
try
to.sendData(seq);
assert(false);
catch ex
% Expected.
assert(isa(ex, 'Ice.TimeoutException'));
end
comm.destroy();
%
% Test Ice.Override.CloseTimeout.
%
initData = app.createInitializationData();
initData.properties_ = communicator.getProperties().clone();
initData.properties_.setProperty('Ice.Override.CloseTimeout', '100');
comm = app.initialize(initData);
comm.stringToProxy(sref).ice_getConnection();
timeout.holdAdapter(800);
tic();
comm.destroy();
assert(toc() < .7);
fprintf('ok\n');
r = timeout;
end
end
end
|