1
%%-----------------------------------------------------------------
5
%% Copyright Ericsson AB 2001-2011. All Rights Reserved.
7
%% The contents of this file are subject to the Erlang Public License,
8
%% Version 1.1, (the "License"); you may not use this file except in
9
%% compliance with the License. You should have received a copy of the
10
%% Erlang Public License along with this software. If not, it can be
11
%% retrieved online at http://www.erlang.org/.
13
%% Software distributed under the License is distributed on an "AS IS"
14
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
15
%% the License for the specific language governing rights and limitations
21
%%-----------------------------------------------------------------
23
-module(event_domain_SUITE).
25
-include_lib("test_server/include/test_server.hrl").
26
-include_lib("orber/include/corba.hrl").
27
-include_lib("cosNotification/include/CosNotifyChannelAdmin.hrl").
28
-include_lib("cosNotification/include/CosNotification.hrl").
30
-include_lib("cosEventDomain/include/CosEventDomainAdmin.hrl").
31
-include_lib("cosEventDomain/src/cosEventDomainApp.hrl").
33
%%-----------------------------------------------------------------
35
%%-----------------------------------------------------------------
37
-define(default_timeout, ?t:minutes(5)).
40
-define(match(ExpectedRes, Expr),
42
AcTuAlReS = (catch (Expr)),
45
io:format("------ CORRECT RESULT ------~n~p~n",
49
io:format("###### ERROR ERROR ######~n~p~n",
56
%%-----------------------------------------------------------------
58
%%-----------------------------------------------------------------
59
-export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2,
60
event_domain_api/1, event_domain_factory_api/1,
61
cases/0, init_per_suite/1, end_per_suite/1,
62
init_per_testcase/2, end_per_testcase/2, app_test/1]).
64
%%-----------------------------------------------------------------
66
%%-----------------------------------------------------------------
68
suite() -> [{ct_hooks,[ts_install_cth]}].
76
init_per_group(_GroupName, Config) ->
79
end_per_group(_GroupName, Config) ->
84
[event_domain_api, event_domain_factory_api, app_test].
86
%%-----------------------------------------------------------------
87
%% Init and cleanup functions.
88
%%-----------------------------------------------------------------
90
init_per_testcase(_Case, Config) ->
91
?line Dog=test_server:timetrap(?default_timeout),
92
[{watchdog, Dog}|Config].
95
end_per_testcase(_Case, Config) ->
96
Dog = ?config(watchdog, Config),
97
test_server:timetrap_cancel(Dog),
100
init_per_suite(Config) when is_list(Config) ->
101
mnesia:delete_schema([node()]),
102
mnesia:create_schema([node()]),
103
ok = corba:orb_init([{flags, 16#02},
104
{orber_debug_level, 10}]),
105
orber:install([node()]),
106
application:start(mnesia),
107
application:start(orber),
108
cosEventApp:install(),
110
cosNotificationApp:install(),
111
cosNotificationApp:start(),
112
cosEventDomainApp:install(),
113
cosEventDomainApp:start(),
116
end_per_suite(Config) when is_list(Config) ->
117
cosEventDomainApp:stop(),
118
cosEventDomainApp:uninstall(),
119
cosNotificationApp:stop(),
120
cosNotificationApp:uninstall(),
122
cosEventApp:uninstall(),
123
application:stop(orber),
124
application:stop(mnesia),
125
mnesia:delete_schema([node()]),
128
%%-----------------------------------------------------------------
130
%%-----------------------------------------------------------------
132
app_test(suite) -> [];
134
ok=test_server:app_test(cosEventDomain),
138
event_domain_api(doc) -> ["Testing the CosEventDomain Domain API", ""];
139
event_domain_api(suite) -> [];
140
event_domain_api(_Config) ->
142
%% We will setup a cluster looking like:
159
ChFac = ?match({_,key,_,_,_,_},
160
cosNotificationApp:start_global_factory([{pullInterval,1}])),
161
{Ch0,_} = ?match({{_,key,_,_,_,_}, _},
162
'CosNotifyChannelAdmin_EventChannelFactory':create_channel(ChFac, [], [])),
163
Fac = ?match({_,key,_,_,_,_},
164
cosEventDomainApp:start_factory()),
165
{ED, _} = ?match({{_,key,_,_,_,_}, _},
166
'CosEventDomainAdmin_EventDomainFactory':create_event_domain(Fac, [], [])),
167
ID0 = 'CosEventDomainAdmin_EventDomain':add_channel(ED, Ch0),
168
?match(Ch0, 'CosEventDomainAdmin_EventDomain':get_channel(ED, ID0)),
169
?match([0], 'CosEventDomainAdmin_EventDomain':get_all_channels(ED)),
170
?match({'EXCEPTION',{'CosNotifyChannelAdmin_ChannelNotFound',_}},
171
'CosEventDomainAdmin_EventDomain':get_channel(ED, 100)),
172
?match({'EXCEPTION',{'CosNotifyChannelAdmin_ChannelNotFound',_}},
173
'CosEventDomainAdmin_EventDomain':remove_channel(ED, 100)),
174
?match(ok, 'CosEventDomainAdmin_EventDomain':remove_channel(ED, 0)),
175
?match([], 'CosEventDomainAdmin_EventDomain':get_all_channels(ED)),
176
?match({'EXCEPTION',{'CosNotifyChannelAdmin_ChannelNotFound',_}},
177
'CosEventDomainAdmin_EventDomain':remove_channel(ED, 0)),
179
%% Create a new event channel.
180
{Ch1,_} = ?match({{_,key,_,_,_,_}, _},
181
'CosNotifyChannelAdmin_EventChannelFactory':create_channel(ChFac, [], [])),
182
{Ch2,_} = ?match({{_,key,_,_,_,_}, _},
183
'CosNotifyChannelAdmin_EventChannelFactory':create_channel(ChFac, [], [])),
184
{Ch3,_} = ?match({{_,key,_,_,_,_}, _},
185
'CosNotifyChannelAdmin_EventChannelFactory':create_channel(ChFac, [], [])),
186
{Ch4,_} = ?match({{_,key,_,_,_,_}, _},
187
'CosNotifyChannelAdmin_EventChannelFactory':create_channel(ChFac, [], [])),
188
{Ch5,_} = ?match({{_,key,_,_,_,_}, _},
189
'CosNotifyChannelAdmin_EventChannelFactory':create_channel(ChFac, [], [])),
190
{Ch6,_} = ?match({{_,key,_,_,_,_}, _},
191
'CosNotifyChannelAdmin_EventChannelFactory':create_channel(ChFac, [], [])),
192
{Ch7,_} = ?match({{_,key,_,_,_,_}, _},
193
'CosNotifyChannelAdmin_EventChannelFactory':create_channel(ChFac, [], [])),
194
{Ch8,_} = ?match({{_,key,_,_,_,_}, _},
195
'CosNotifyChannelAdmin_EventChannelFactory':create_channel(ChFac, [], [])),
196
{Ch9,_} = ?match({{_,key,_,_,_,_}, _},
197
'CosNotifyChannelAdmin_EventChannelFactory':create_channel(ChFac, [], [])),
199
ID1 = 'CosEventDomainAdmin_EventDomain':add_channel(ED, Ch1),
200
ID2 = 'CosEventDomainAdmin_EventDomain':add_channel(ED, Ch2),
201
ID3 = 'CosEventDomainAdmin_EventDomain':add_channel(ED, Ch3),
202
ID4 = 'CosEventDomainAdmin_EventDomain':add_channel(ED, Ch4),
203
ID5 = 'CosEventDomainAdmin_EventDomain':add_channel(ED, Ch5),
204
ID6 = 'CosEventDomainAdmin_EventDomain':add_channel(ED, Ch6),
205
ID7 = 'CosEventDomainAdmin_EventDomain':add_channel(ED, Ch7),
206
ID8 = 'CosEventDomainAdmin_EventDomain':add_channel(ED, Ch8),
207
ID9 = 'CosEventDomainAdmin_EventDomain':add_channel(ED, Ch9),
208
?match([_,_,_,_,_,_,_,_,_],
209
'CosEventDomainAdmin_EventDomain':get_all_channels(ED)),
211
?match([], 'CosEventDomainAdmin_EventDomain':get_all_connections(ED)),
212
C1 = #'CosEventDomainAdmin_Connection'{supplier_id=ID2,
214
ctype='STRUCTURED_EVENT',
215
notification_style='Pull'},
216
C2 = #'CosEventDomainAdmin_Connection'{supplier_id=ID4,
219
notification_style='Push'},
220
C3 = #'CosEventDomainAdmin_Connection'{supplier_id=ID1,
223
notification_style='Pull'},
224
C4 = #'CosEventDomainAdmin_Connection'{supplier_id=ID3,
226
ctype='STRUCTURED_EVENT',
227
notification_style='Push'},
228
C5 = #'CosEventDomainAdmin_Connection'{supplier_id=ID5,
231
notification_style='Pull'},
232
C6 = #'CosEventDomainAdmin_Connection'{supplier_id=ID9,
235
notification_style='Push'},
236
C7 = #'CosEventDomainAdmin_Connection'{supplier_id=ID4,
238
ctype='STRUCTURED_EVENT',
239
notification_style='Pull'},
240
C8 = #'CosEventDomainAdmin_Connection'{supplier_id=ID7,
243
notification_style='Push'},
244
C9 = #'CosEventDomainAdmin_Connection'{supplier_id=ID8,
247
notification_style='Pull'},
248
C10 = #'CosEventDomainAdmin_Connection'{supplier_id=ID5,
251
notification_style='Pull'},
252
C11 = #'CosEventDomainAdmin_Connection'{supplier_id=ID4,
255
notification_style='Pull'},
256
C12 = #'CosEventDomainAdmin_Connection'{supplier_id=ID8,
259
notification_style='Pull'},
261
CID1 = 'CosEventDomainAdmin_EventDomain':add_connection(ED, C1),
262
?match([CID1], 'CosEventDomainAdmin_EventDomain':get_all_connections(ED)),
263
_CID2 = 'CosEventDomainAdmin_EventDomain':add_connection(ED, C2),
265
'CosEventDomainAdmin_EventDomain':get_all_connections(ED)),
266
_CID3 = 'CosEventDomainAdmin_EventDomain':add_connection(ED, C3),
268
'CosEventDomainAdmin_EventDomain':get_all_connections(ED)),
269
_CID4 = 'CosEventDomainAdmin_EventDomain':add_connection(ED, C4),
271
'CosEventDomainAdmin_EventDomain':get_all_connections(ED)),
272
_CID5 = 'CosEventDomainAdmin_EventDomain':add_connection(ED, C5),
274
'CosEventDomainAdmin_EventDomain':get_all_connections(ED)),
275
_CID6 = 'CosEventDomainAdmin_EventDomain':add_connection(ED, C6),
276
?match([_,_,_,_,_,_],
277
'CosEventDomainAdmin_EventDomain':get_all_connections(ED)),
278
CID7 = 'CosEventDomainAdmin_EventDomain':add_connection(ED, C7),
279
?match([_,_,_,_,_,_,_],
280
'CosEventDomainAdmin_EventDomain':get_all_connections(ED)),
281
_CID8 = 'CosEventDomainAdmin_EventDomain':add_connection(ED, C8),
282
?match([_,_,_,_,_,_,_,_],
283
'CosEventDomainAdmin_EventDomain':get_all_connections(ED)),
285
?match({'EXCEPTION',{'CosEventDomainAdmin_AlreadyExists', _}},
286
'CosEventDomainAdmin_EventDomain':add_connection(ED, C8)),
287
%% No cycles should exist.
288
?match([], 'CosEventDomainAdmin_EventDomain':get_cycles(ED)),
290
?match([_, _], 'CosEventDomainAdmin_EventDomain':get_qos(ED)),
291
AllowCyclic = #'CosNotification_Property'{name=?CycleDetection,
292
value=any:create(orber_tc:short(),
294
?match({'EXCEPTION',{'CosNotification_UnsupportedQoS',_,_}},
295
'CosEventDomainAdmin_EventDomain':set_qos(ED, [AllowCyclic])),
296
ForbidCyclic = #'CosNotification_Property'{name=?CycleDetection,
297
value=any:create(orber_tc:short(),
299
%% The same as before; must work.
300
?match(ok, 'CosEventDomainAdmin_EventDomain':set_qos(ED, [ForbidCyclic])),
302
AllowDiamonds = #'CosNotification_Property'{name=?DiamondDetection,
303
value=any:create(orber_tc:short(),
304
?AuthorizeDiamonds)},
305
%% Since no diamonds allowed before this is always ok.
306
?match(ok, 'CosEventDomainAdmin_EventDomain':set_qos(ED, [AllowDiamonds])),
308
?match([_, _], 'CosEventDomainAdmin_EventDomain':get_qos(ED)),
310
ForbidDiamonds = #'CosNotification_Property'{name=?DiamondDetection,
311
value=any:create(orber_tc:short(),
313
%% No diamonds created before. Hence, will work.
314
?match(ok, 'CosEventDomainAdmin_EventDomain':set_qos(ED, [ForbidDiamonds])),
316
?match([_, _], 'CosEventDomainAdmin_EventDomain':get_qos(ED)),
318
?match({ok, [_]}, 'CosEventDomainAdmin_EventDomain':validate_qos(ED,
321
%% No diamonds exists, hence, this is ok.
322
?match({ok, [_]}, 'CosEventDomainAdmin_EventDomain':validate_qos(ED,
325
?match({'EXCEPTION',{'CosNotification_UnsupportedQoS',_,_}},
326
'CosEventDomainAdmin_EventDomain':validate_qos(ED, [ForbidDiamonds,
329
%% Since the ED is started is asyclic we may not succeed with this invokation.
330
?match({'EXCEPTION',{'CosEventDomainAdmin_CycleCreationForbidden',_,_}},
331
'CosEventDomainAdmin_EventDomain':add_connection(ED, C9)),
332
?match([], 'CosEventDomainAdmin_EventDomain':get_offer_channels(ED, ID2)),
334
?match([2], 'CosEventDomainAdmin_EventDomain':get_offer_channels(ED, ID4)),
335
?match([_,_,_], 'CosEventDomainAdmin_EventDomain':get_offer_channels(ED, ID8)),
336
?match({'EXCEPTION',{'CosNotifyChannelAdmin_ChannelNotFound',_}},
337
'CosEventDomainAdmin_EventDomain':get_offer_channels(ED, 100)),
338
?match([], 'CosEventDomainAdmin_EventDomain':get_subscription_channels(ED, ID8)),
340
'CosEventDomainAdmin_EventDomain':get_subscription_channels(ED, ID4)),
341
?match([_,_,_,_,_,_],
342
'CosEventDomainAdmin_EventDomain':get_subscription_channels(ED, ID2)),
343
?match({'EXCEPTION',{'CosNotifyChannelAdmin_ChannelNotFound',_}},
344
'CosEventDomainAdmin_EventDomain':get_subscription_channels(ED, 100)),
345
Nil = corba:create_nil_objref(),
347
P2=?match({_,key,_,_,_,_},
348
'CosEventDomainAdmin_EventDomain':connect_push_supplier_with_id(ED, Nil, ID2)),
349
P7=?match({_,key,_,_,_,_},
350
'CosEventDomainAdmin_EventDomain':connect_push_supplier_with_id(ED, Nil, ID7)),
351
P8=?match({_,key,_,_,_,_},
352
'CosEventDomainAdmin_EventDomain':connect_pull_consumer_with_id(ED, Nil, ID8)),
353
P6=?match({_,key,_,_,_,_},
354
'CosEventDomainAdmin_EventDomain':connect_pull_consumer_with_id(ED, Nil, ID6)),
355
E1 = #any{typecode=tk_long, value=1},
356
E2 = #any{typecode=tk_long, value=2},
358
?match(ok, 'CosNotifyChannelAdmin_ProxyPushConsumer':push(P2, E1)),
359
?match(E1, 'CosNotifyChannelAdmin_ProxyPullSupplier':pull(P8)),
360
?match(E1, 'CosNotifyChannelAdmin_ProxyPullSupplier':pull(P6)),
361
?match(ok, 'CosNotifyChannelAdmin_ProxyPushConsumer':push(P7, E2)),
362
?match(E2, 'CosNotifyChannelAdmin_ProxyPullSupplier':pull(P8)),
364
?match({_,false}, 'CosNotifyChannelAdmin_ProxyPullSupplier':try_pull(P6)),
366
?match(ok, 'CosEventDomainAdmin_EventDomain':remove_connection(ED, CID7)),
368
?match({'EXCEPTION',{'CosEventDomainAdmin_ConnectionNotFound',_}},
369
'CosEventDomainAdmin_EventDomain':remove_connection(ED, CID7)),
371
?match({'EXCEPTION',{'CosEventDomainAdmin_ConnectionNotFound',_}},
372
'CosEventDomainAdmin_EventDomain':remove_connection(ED, 100)),
374
?match([], 'CosEventDomainAdmin_EventDomain':get_offer_channels(ED, ID7)),
375
?match([2], 'CosEventDomainAdmin_EventDomain':get_offer_channels(ED, ID4)),
377
?match([8], 'CosEventDomainAdmin_EventDomain':get_subscription_channels(ED, ID7)),
378
?match([_,_,_], 'CosEventDomainAdmin_EventDomain':get_subscription_channels(ED, ID4)),
380
CID10 = ?match(8, 'CosEventDomainAdmin_EventDomain':add_connection(ED, C7)),
382
%% Now we'll check diamond management.
383
%% Currently it should not be possible to create a diamond (due to QoS-setting).
384
?match({'EXCEPTION',{'CosEventDomainAdmin_DiamondCreationForbidden',_,_}},
385
'CosEventDomainAdmin_EventDomain':add_connection(ED, C11)),
386
?match({'EXCEPTION',{'CosEventDomainAdmin_DiamondCreationForbidden',_,_}},
387
'CosEventDomainAdmin_EventDomain':add_connection(ED, C10)),
388
?match({'EXCEPTION',{'CosEventDomainAdmin_DiamondCreationForbidden',_,_}},
389
'CosEventDomainAdmin_EventDomain':add_connection(ED, C12)),
390
?match(ok, 'CosEventDomainAdmin_EventDomain':set_qos(ED, [AllowDiamonds])),
392
CID11 = ?match(9, 'CosEventDomainAdmin_EventDomain':add_connection(ED, C10)),
393
?match([_,_,_,_,_,_,_,_,_],
394
'CosEventDomainAdmin_EventDomain':get_all_connections(ED)),
395
?match([_], 'CosEventDomainAdmin_EventDomain':get_diamonds(ED)),
397
CID12 = ?match(10, 'CosEventDomainAdmin_EventDomain':add_connection(ED, C11)),
398
?match([_, _, _], 'CosEventDomainAdmin_EventDomain':get_diamonds(ED)),
400
CID13 = ?match(11, 'CosEventDomainAdmin_EventDomain':add_connection(ED, C12)),
402
?match([_, _, _], 'CosEventDomainAdmin_EventDomain':get_diamonds(ED)),
404
?match({'EXCEPTION',{'CosNotification_UnsupportedQoS',_,_}},
405
'CosEventDomainAdmin_EventDomain':set_qos(ED, [ForbidDiamonds])),
407
?match(ok, 'CosEventDomainAdmin_EventDomain':remove_connection(ED, CID10)),
408
?match(ok, 'CosEventDomainAdmin_EventDomain':remove_connection(ED, CID11)),
409
?match(ok, 'CosEventDomainAdmin_EventDomain':remove_connection(ED, CID12)),
410
?match(ok, 'CosEventDomainAdmin_EventDomain':remove_connection(ED, CID13)),
411
?match(ok, 'CosEventDomainAdmin_EventDomain':set_qos(ED, [ForbidDiamonds])),
412
?match([_, _], 'CosEventDomainAdmin_EventDomain':get_qos(ED)),
413
?match({'EXCEPTION',{'CosEventDomainAdmin_DiamondCreationForbidden',_,_}},
414
'CosEventDomainAdmin_EventDomain':add_connection(ED, C10)),
416
?match(ok, 'CosEventDomainAdmin_EventDomain':destroy(ED)),
420
event_domain_factory_api(doc) -> ["Testing the CosEventDomain Factory API", ""];
421
event_domain_factory_api(suite) -> [];
422
event_domain_factory_api(_Config) ->
424
Cyclic = #'CosNotification_Property'{name=?CycleDetection,
425
value=any:create(orber_tc:short(),
428
BadProp = #'CosNotification_Property'{name="Wrong",
429
value=any:create(orber_tc:short(),
432
BadQoSVal = #'CosNotification_Property'{name=?CycleDetection,
433
value=any:create(orber_tc:short(),
436
Fac = ?match({_,key,_,_,_,_},
437
cosEventDomainApp:start_factory()),
438
?match([], 'CosEventDomainAdmin_EventDomainFactory':get_all_domains(Fac)),
439
?match({'EXCEPTION',{'CosEventDomainAdmin_DomainNotFound',_}},
440
'CosEventDomainAdmin_EventDomainFactory':get_event_domain(Fac, 0)),
441
{ED,_} = 'CosEventDomainAdmin_EventDomainFactory':create_event_domain(Fac, [Cyclic], []),
442
?match([0], 'CosEventDomainAdmin_EventDomainFactory':get_all_domains(Fac)),
443
ED = 'CosEventDomainAdmin_EventDomainFactory':get_event_domain(Fac, 0),
444
?match({'EXCEPTION',{'CosEventDomainAdmin_DomainNotFound',_}},
445
'CosEventDomainAdmin_EventDomainFactory':get_event_domain(Fac, 1)),
448
?match([], 'CosEventDomainAdmin_EventDomainFactory':get_all_domains(Fac)),
449
?match({'EXCEPTION',{'CosEventDomainAdmin_DomainNotFound',_}},
450
'CosEventDomainAdmin_EventDomainFactory':get_event_domain(Fac, 0)),
451
{ED2,_} = ?match({{_,key,_,_,_,_}, _},
452
'CosEventDomainAdmin_EventDomainFactory':create_event_domain(Fac, [], [])),
453
?match([1], 'CosEventDomainAdmin_EventDomainFactory':get_all_domains(Fac)),
454
?match(ED2, 'CosEventDomainAdmin_EventDomainFactory':get_event_domain(Fac, 1)),
457
?match({'EXCEPTION', {'CosNotification_UnsupportedQoS',_,_}},
458
'CosEventDomainAdmin_EventDomainFactory':create_event_domain(Fac, [BadProp], [])),
459
?match({'EXCEPTION',{'CosNotification_UnsupportedAdmin',_,_}},
460
'CosEventDomainAdmin_EventDomainFactory':create_event_domain(Fac, [], [BadProp])),
461
?match({'EXCEPTION',{'CosNotification_UnsupportedQoS',_,_}},
462
'CosEventDomainAdmin_EventDomainFactory':create_event_domain(Fac, [BadQoSVal], [])),
463
?match({'EXCEPTION',{'CosNotification_UnsupportedAdmin',_,_}},
464
'CosEventDomainAdmin_EventDomainFactory':create_event_domain(Fac, [], [BadQoSVal])),