-
Notifications
You must be signed in to change notification settings - Fork 0
/
class_TestTraceEmitter.erl
433 lines (293 loc) · 14.3 KB
/
class_TestTraceEmitter.erl
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
% Copyright (C) 2007-2024 Olivier Boudeville
%
% This file is part of the Ceylan-Traces library.
%
% This library is free software: you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License or
% the GNU General Public License, as they are published by the Free Software
% Foundation, either version 3 of these Licenses, or (at your option)
% any later version.
% You can also redistribute it and/or modify it under the terms of the
% Mozilla Public License, version 1.1 or later.
%
% This library is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Lesser General Public License and the GNU General Public License
% for more details.
%
% You should have received a copy of the GNU Lesser General Public
% License, of the GNU General Public License and of the Mozilla Public License
% along with this library.
% If not, see <http://www.gnu.org/licenses/> and
% <http://www.mozilla.org/MPL/>.
%
% Author: Olivier Boudeville [olivier (dot) boudeville (at) esperide (dot) com]
% Creation date: July 1, 2007.
-module(class_TestTraceEmitter).
-moduledoc """
A trace emitter introduced **for testing**.
""".
-define( class_description,
"Trace emitter child class introduced for testing."
"See class_TraceEmitter.hrl and class_TraceEmitter.erl." ).
% Determines what are the direct mother classes of this class (if any):
-define( superclasses, [ class_TraceEmitter ] ).
-define( class_attributes, [] ).
% Used by the trace_categorize/1 macro to use the right emitter:
-define( trace_emitter_categorization, "TraceEmitter.Test" ).
% Exported helpers:
-export([ send_traces/1, send_emergency_trace/1, send_debug_trace/1 ]).
% Allows to define WOOPER base variables and methods for that class:
-include_lib("wooper/include/wooper.hrl").
% Only to test the trace system:
-define( log_prefix, "[Test TraceEmitter]" ).
% Allows to use macros for trace sending:
-include("class_TraceEmitter.hrl").
% The sendings whose severity is error-like have been commented out, as we do
% not want measures to be biased beyond repair by the large cost of console
% printouts.
-doc "Constructs a test trace emitter.".
-spec construct( wooper:state(), class_TraceEmitter:emitter_init() ) ->
wooper:state().
construct( State, TraceEmitterName ) ->
%trace_utils:notice_fmt( "~ts Creating a test trace emitter, whose name "
% "is ~p, whose PID is ~w.", [ ?log_prefix, TraceEmitterName, self() ] ),
% First the direct mother classes, then this class-specific actions:
TraceState = class_TraceEmitter:construct( State,
?trace_categorize(TraceEmitterName) ),
% From now on, traces can be sent (but, from the constructor, send_* traces
% only should be sent, to be able to refer to a trace-enabled state):
%?send_emergency( TraceState, "Hello emergency world!" ),
%?send_alert( TraceState, "Hello alert world!" ),
%?send_critical( TraceState, "Hello critical world!" ),
%?send_error( TraceState, "Hello error world!" ),
%?send_warning( TraceState, "Hello warning world!" ),
%?send_notice( TraceState, "Hello notice world!" ),
?send_info( TraceState, "Hello trace world!" ),
?send_debug( TraceState, "Hello debug world!" ),
?send_void( TraceState, "Hello void world!" ),
TraceState.
-doc "Overridden destructor.".
-spec destruct( wooper:state() ) -> wooper:state().
destruct( State ) ->
% Class-specific actions:
%trace_utils:notice_fmt( "~ts Deleting test trace emitter ~ts.",
% [ ?log_prefix, ?getAttr(name) ] ),
% Last moment to send traces:
%?emergency( "Goodbye emergency world!" ),
%?alert( "Goodbye alert world!" ),
%?critical( "Goodbye critical world!" ),
%?error( "Goodbye error world!" ),
%?warning( "Goodbye warning world!" ),
%?notice( "Goodbye notice world!" ),
?info( "Goodbye info world!" ),
?debug( "Goodbye debug world!" ),
?void( "Goodbye void world!" ),
%trace_utils:notice_fmt( "~ts Test trace emitter ~ts deleted.",
% [ ?log_prefix, ?getAttr(name) ] ),
% Allows chaining:
State.
% Methods section.
-spec sendTraces( wooper:state() ) -> const_request_return( 'ok' ).
sendTraces( State ) ->
%trace_utils:notice_fmt( "~ts Sending some traces.", [ ?log_prefix ] ),
%send_traces( State ),
send_traces_benchmark( State ),
wooper:const_return_result( ok ).
-spec sendAsyncTraces( wooper:state() ) -> const_oneway_return().
sendAsyncTraces( State ) ->
%trace_utils:notice_fmt( "~ts Sending some asynchronous traces.",
% [ ?log_prefix ] ),
%send_traces( State ),
[ send_traces_benchmark( State ) || _ <- lists:seq( 1, 5 ) ],
wooper:const_return().
% Helper functions.
-doc "We should be testing all forms of traces here.".
-spec send_traces( wooper:state() ) -> void().
send_traces( State ) ->
%trace_utils:notice_fmt( "~ts Sending some traces.", [ ?log_prefix ] ),
% We used to replace emergency, alert, critical and error traces by warning
% ones, as the former ones induced fixed waitings (i.e. timer:sleep/1
% calls), yet now failure-oriented traces (warning, error, critical, alert
% and emergency) rely on an explicit synchronisation with the trace
% aggregator.
% With no formatting:
?emergency( "Still livin' in an emergency world! (plain)" ),
?alert( "Still livin' in an alert world! (plain)" ),
?critical( "Still livin' in a critical world! (plain)" ),
?error( "Still livin' in an error world! (plain)" ),
?warning( "Still livin' in a warning world! (plain)" ),
?notice( "Still livin' in a notice world! (plain)" ),
?info( "Still livin' in an info world! (plain)" ),
?debug( "Still livin' in a debug world! (plain)" ),
?void( "Still livin' in a void world! (plain)" ),
?emergency_cat( "Still livin' in an emergency world! (cat)",
?application_start ),
?alert_cat( "Still livin' in an alert world! (cat)",
?application_start ),
?critical_cat( "Still livin' in a critical world! (cat)",
?application_start ),
?error_cat( "Still livin' in an error world! (cat)",
?application_save ),
?warning_cat( "Still livin' in a warning world! (cat)", ?time ),
?notice_cat( "Still livin' in a notice world! (cat)", ?execution ),
?info_cat( "Still livin' in an info world! (cat)",
?application_start ),
?debug_cat( "Still livin' in a debug world! (cat)",
?application_start ),
?void_cat( "Still livin' in a void world! (cat)",
?application_start ),
?emergency_full( "Still livin' in an emergency world! (full)",
?application_start, 5 ),
?alert_full( "Still livin' in an alert world! (full)",
?application_start, 5 ),
?critical_full( "Still livin' in a critical world! (full)",
?application_start, 5 ),
?error_full( "Still livin' in an error world! (full)",
?application_save, 6 ),
?warning_full( "Still livin' in a warning world! (full)",
?time, 7 ),
?notice_full( "Still livin' in a notice world! (full)",
?execution, 8 ),
?info_full( "Still livin' in an info world! (full)",
?application_start, 10 ),
?debug_full( "Still livin' in a debug world! (full)",
?application_start, 10 ),
?void_full( "Still livin' in a void world! (full)",
?application_start, 11 ),
% With formatting:
?emergency_fmt( "Yes, still livin' in a ~w world! (plain)", [emergency] ),
?alert_fmt( "Yes, still livin' in a ~w world! (plain)", [alert] ),
?critical_fmt( "Yes, still livin' in a ~w world! (plain)", [critical] ),
?error_fmt( "Yes, still livin' in a ~w world! (plain)", [error] ),
?warning_fmt( "Yes, still livin' in a ~w world! (plain)", [warning] ),
?notice_fmt( "Yes, still livin' in a ~w world! (plain)", [notice] ),
?info_fmt( "Yes, still livin' in a ~w world! (plain)", [info] ),
?debug_fmt( "Yes, still livin' in a ~w world! (plain)", [debug] ),
?void_fmt( "Yes, still livin' in a ~w world! (plain)", [void] ),
?emergency_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [emergency], ?application_start ),
?alert_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [alert], ?application_start ),
?critical_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [critical], ?application_start ),
?error_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [error], ?application_save ),
?warning_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [warning], ?time ),
?notice_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [notice], ?execution ),
?info_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [info], ?application_start ),
?debug_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [debug], ?application_start ),
?void_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [void], ?application_start ),
?emergency_fmt_full( "Oh yeah ~w", [emergency], ?application_start, 5 ),
?alert_fmt_full( "Oh yeah ~w", [alert], ?application_start, 5 ),
?critical_fmt_full( "Oh yeah ~w", [critical], ?application_start, 5 ),
?error_fmt_full( "Oh yeah ~w", [error], ?application_save, 6 ),
?warning_fmt_full( "Oh yeah ~w", [warning], ?time, 7 ),
?notice_fmt_full( "Oh yeah ~w", [notice], ?execution, 8 ),
?info_fmt_full( "Oh yeah ~w", [info], ?application_start, 9 ),
?debug_fmt_full( "Oh yeah ~w", [debug], ?application_start, 10 ),
?void_fmt_full( "Oh yeah ~w", [void], ?application_start, 11 ).
-doc """
To test compilation problems when only one non-maskable trace is used
(e.g. variable unused, or term constructed whereas not used either).
""".
-spec send_emergency_trace( wooper:state() ) -> void().
send_emergency_trace( State ) ->
Message = "Unique ~w trace!",
Format = [ emergency ],
Categ = ?application_start,
?emergency_fmt_cat( Message, Format, Categ ).
-doc """
To test compilation problems when only one maskable trace is used (e.g.
variable unused, or term constructed whereas not used either).
""".
-spec send_debug_trace( wooper:state() ) -> void().
send_debug_trace( State ) ->
Message = "Unique ~w trace!",
Format = [ debug ],
MsgCateg = ?application_start,
?debug_fmt_cat( Message, Format, MsgCateg ).
-spec send_traces_benchmark( wooper:state() ) -> void().
send_traces_benchmark( State ) ->
%trace_utils:notice_fmt( "~ts Sending some traces.", [ ?log_prefix ] ),
% We used to replace emergency, alert, critical and error traces by warning
% ones, as the former ones induced fixed waitings (i.e. timer:sleep/1
% calls), yet now failure-oriented traces (warning, error, critical, alert
% and emergency) rely on an explicit synchronisation with the trace
% aggregator.
% With no formatting:
%?warning( "Still livin' in an emergency world! (plain)" ),
%?warning( "Still livin' in an alert world! (plain)" ),
%?warning( "Still livin' in a critical world! (plain)" ),
%?warning( "Still livin' in an error world! (plain)" ),
%?warning( "Still livin' in a warning world! (plain)" ),
%?notice( "Still livin' in a notice world! (plain)" ),
?info( "Still livin' in a info world! (plain)" ),
?debug( "Still livin' in a debug world! (plain)" ),
?void( "Still livin' in a void world! (plain)" ),
% Not replaced:
%?emergency_cat( "Still livin' in an emergency world! (cat)",
% ?application_start ),
%?alert_cat( "Still livin' in an alert world! (cat)",
% ?application_start ),
%?critical_cat( "Still livin' in a critical world! (cat)",
% ?application_start ),
%?error_cat( "Still livin' in an error world! (cat)",
% ?application_save ),
%?warning_cat( "Still livin' in a warning world! (cat)",
% ?time ),
%?notice_cat( "Still livin' in a notice world! (cat)",
% ?execution ),
?info_cat( "Still livin' in an info world! (cat)",
?application_start ),
?debug_cat( "Still livin' in a debug world! (cat)",
?application_start ),
?void_cat( "Still livin' in a void world! (cat)",
?application_start ),
%?emergency_full( "Still livin' in an emergency world! (full)",
% ?application_start, 5 ),
%?alert_full( "Still livin' in an alert world! (full)",
% ?application_start, 5 ),
%?critical_full( "Still livin' in a critical world! (full)",
% ?application_start, 5 ),
%?error_full( "Still livin' in an error world! (full)",
% ?application_save, 6 ),
%?warning_full( "Still livin' in a warning world! (full)",
% ?time, 7 ),
% Useful also to test non-integer timestamps (works correctly with the trace
% supervisors as they are):
%
%?notice_full( "Still livin' in a notice world! (full)",
% ?execution, {8,2} ),
?info_full( "Still livin' in an info world! (full)",
?application_start, 9 ),
?debug_full( "Still livin' in a debug world! (full)",
?application_start, 10 ),
?void_full( "Still livin' in a void world! (full)",
?application_start, 11 ),
% With formatting:
%?emergency_fmt( "Yes, still livin' in a ~w world! (plain)", [emergency] ),
%?alert_fmt( "Yes, still livin' in a ~w world! (plain)", [alert] ),
%?critical_fmt( "Yes, still livin' in a ~w world! (plain)", [critical] ),
%?error_fmt( "Yes, still livin' in a ~w world! (plain)", [error] ),
%?warning_fmt( "Yes, still livin' in a ~w world! (plain)", [warning] ),
%?notice_fmt( "Yes, still livin' in a ~w world! (plain)", [notice] ),
?info_fmt( "Yes, still livin' in a ~w world! (plain)", [info] ),
?debug_fmt( "Yes, still livin' in a ~w world! (plain)", [debug] ),
?void_fmt( "Yes, still livin' in a ~w world! (plain)", [void] ),
%?emergency_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [emergency],
% ?application_start ),
%?alert_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [alert], ?application_start ),
%?critical_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [critical], ?application_start ),
%?error_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [error], ?application_save ),
%?warning_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [warning], ?time ),
%?notice_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [notice], ?execution ),
?info_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [info], ?application_start ),
?debug_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [debug], ?application_start ),
?void_fmt_cat( "Ouh-ouh-ouuuuuh ~w", [void], ?application_start ),
%?emergency_fmt_full( "Oh yeah ~w", [emergency], ?application_start, 5 ),
%?alert_fmt_full( "Oh yeah ~w", [alert], ?application_start, 5 ),
%?critical_fmt_full( "Oh yeah ~w", [critical], ?application_start, 5 ),
%?error_fmt_full( "Oh yeah ~w", [error], ?application_save, 6 ),
%?warning_fmt_full( "Oh yeah ~w", [warning], ?time, 7 ),
%?notice_fmt_full( "Oh yeah ~w", [notice], ?execution, 8 ),
?info_fmt_full( "Oh yeah ~w", [info], ?application_start, 9 ),
?debug_fmt_full( "Oh yeah ~w", [debug], ?application_start, 10 ),
?void_fmt_full( "Oh yeah ~w", [void], ?application_start, 11 ).