pantheios-ruby 0.13.4 → 0.20.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # executes all other tests
4
+
5
+ this_dir = File.expand_path(File.dirname(__FILE__))
6
+
7
+ # all tc_*rb in current directory
8
+ Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
9
+
10
+ # all ts_*rb in immediate sub-directories
11
+ Dir[File.join(this_dir, '*', 'ts_*rb')].each { |file| require file }
12
+
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # test/unit/services/tc_multiplexing_log_service.rb
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '../../..', 'lib')
6
+
7
+ require 'pantheios/services/multiplexing_log_service'
8
+
9
+ require 'pantheios/api'
10
+ require 'pantheios/application_layer/stock_severity_levels'
11
+
12
+ require 'xqsr3/extensions/test/unit'
13
+
14
+ require 'test/unit'
15
+
16
+ require 'stringio'
17
+
18
+ class Test_MultiplexingLogservice < Test::Unit::TestCase
19
+
20
+ include ::Pantheios::API
21
+ include ::Pantheios::Services
22
+
23
+ class ProgrammableLogService
24
+
25
+ def initialize name, severities
26
+
27
+ @name = name
28
+ @severities = severities
29
+ @items = []
30
+ end
31
+
32
+ attr_reader :name
33
+ attr_reader :items
34
+
35
+ def severity_logged? severity
36
+
37
+ @severities.include? severity
38
+ end
39
+
40
+ def log sev, t, pref, msg
41
+
42
+ @items << [ sev, t, pref, msg ]
43
+ end
44
+ end
45
+
46
+ def log_multiple_statements svc
47
+
48
+ previous, _ = Pantheios::Core.set_service svc
49
+
50
+ begin
51
+
52
+ severities = Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVELS_PRIME
53
+
54
+ severities.each do |sev|
55
+
56
+ log sev, "a(n) #{sev} statement"
57
+ end
58
+ ensure
59
+
60
+ Pantheios::Core.set_service previous
61
+ end
62
+ end
63
+
64
+
65
+ def test_MultiplexingLogService_type_exists
66
+
67
+ assert defined? MultiplexingLogService
68
+ end
69
+
70
+ if defined?(MultiplexingLogService)
71
+
72
+ def test_MultiplexingLogService_type_is_a_class
73
+
74
+ assert_kind_of(::Class, MultiplexingLogService)
75
+ end
76
+
77
+ def test_MultiplexingLogService_type_has_expected_instance_methods
78
+
79
+ assert_type_has_instance_methods MultiplexingLogService, [ :severity_logged?, :log ]
80
+ end
81
+
82
+ def test_multiplex_1
83
+
84
+ svc_0 = ProgrammableLogService.new 'svc_0', Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVELS_PRIME - [ :informational, :notice, :trace ]
85
+ svc_1 = ProgrammableLogService.new 'svc_1', [ :informational, :notice, :warning, :failure ]
86
+ svc_2 = ProgrammableLogService.new 'svc_2', [ :informational, :debug0, :debug1, :debug2, :debug3, :debug4 ]
87
+
88
+ svc = MultiplexingLogService.new [ svc_0, svc_1, svc_2 ]
89
+
90
+ log_multiple_statements svc
91
+
92
+ assert_equal 11, svc_0.items.size
93
+ assert_equal 4, svc_1.items.size
94
+ assert_equal 6, svc_2.items.size
95
+ end
96
+
97
+ def test_multiplex_2
98
+
99
+ svc_0 = ProgrammableLogService.new 'svc_0', Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVELS_PRIME - [ :informational, :notice, :trace ]
100
+ svc_1 = ProgrammableLogService.new 'svc_1', [ :informational, :notice, :warning, :failure ]
101
+ svc_2 = ProgrammableLogService.new 'svc_2', [ :informational, :debug0, :debug1, :debug2, :debug3, :debug4 ]
102
+
103
+ svc = MultiplexingLogService.new [ svc_0, svc_1, svc_2 ], level_cache_mode: :none
104
+
105
+ log_multiple_statements svc
106
+
107
+ assert_equal 11, svc_0.items.size
108
+ assert_equal 4, svc_1.items.size
109
+ assert_equal 6, svc_2.items.size
110
+ end
111
+
112
+ def test_multiplex_3
113
+
114
+ svc_0 = ProgrammableLogService.new 'svc_0', Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVELS_PRIME - [ :informational, :notice, :trace ]
115
+ svc_1 = ProgrammableLogService.new 'svc_1', [ :informational, :notice, :warning, :failure ]
116
+ svc_2 = ProgrammableLogService.new 'svc_2', [ :informational, :debug0, :debug1, :debug2, :debug3, :debug4 ]
117
+
118
+ svc = MultiplexingLogService.new [ svc_0, svc_1, svc_2 ], level_cache_mode: :process_fixed
119
+
120
+ log_multiple_statements svc
121
+
122
+ assert_equal 11, svc_0.items.size
123
+ assert_equal 4, svc_1.items.size
124
+ assert_equal 6, svc_2.items.size
125
+ end
126
+
127
+ def test_multiplex_4
128
+
129
+ svc_0 = ProgrammableLogService.new 'svc_0', Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVELS_PRIME - [ :informational, :notice, :trace ]
130
+ svc_1 = ProgrammableLogService.new 'svc_1', [ :informational, :notice, :warning, :failure ]
131
+ svc_2 = ProgrammableLogService.new 'svc_2', [ :informational, :debug0, :debug1, :debug2, :debug3, :debug4 ]
132
+
133
+ svc = MultiplexingLogService.new [ svc_0, svc_1, svc_2 ], level_cache_mode: :thread_fixed
134
+
135
+ log_multiple_statements svc
136
+
137
+ assert_equal 11, svc_0.items.size
138
+ assert_equal 4, svc_1.items.size
139
+ assert_equal 6, svc_2.items.size
140
+ end
141
+ end
142
+ end
143
+
144
+
@@ -96,7 +96,7 @@ class Test_SimpleConsoleLogservice < Test::Unit::TestCase
96
96
  stdout_s = $stdout.string
97
97
  stderr_s = $stderr.string
98
98
 
99
- assert_not_empty stdout_s, "SimpleConsoleLogService has not written to $stdout!"
99
+ assert_empty stdout_s, "SimpleConsoleLogService has written to $stdout!"
100
100
  assert_not_empty stderr_s, "SimpleConsoleLogService has not written to $stderr!"
101
101
  ensure
102
102
 
@@ -123,8 +123,8 @@ class Test_SimpleConsoleLogservice < Test::Unit::TestCase
123
123
 
124
124
  r = self.class.log_and_get_streams sev, 'msg'
125
125
 
126
- assert_not_empty r[0], "SimpleConsoleLogService failed to write to $stdout for severity #{sev}"
127
- assert_empty r[1], "SimpleConsoleLogService wrote unexpectedly to $stderr for severity #{sev}"
126
+ assert_empty r[0], "SimpleConsoleLogService wrote to $stdout for severity #{sev}"
127
+ assert_not_empty r[1], "SimpleConsoleLogService failed to write to $stderr for severity #{sev}"
128
128
  end
129
129
  end
130
130
  end
@@ -0,0 +1,252 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # test/unit/services/tc_simple_file_log_service.rb
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '../../..', 'lib')
6
+
7
+ require 'pantheios/services/simple_file_log_service'
8
+
9
+ require 'pantheios/application_layer/stock_severity_levels'
10
+
11
+ require 'xqsr3/extensions/test/unit'
12
+
13
+ require 'test/unit'
14
+
15
+ require 'stringio'
16
+ require 'tempfile'
17
+
18
+ class Test_SimpleFileLogservice < Test::Unit::TestCase
19
+
20
+ include ::Pantheios::Services
21
+
22
+ def test_SimpleFileLogService_type_exists
23
+
24
+ assert defined? SimpleFileLogService
25
+ end
26
+
27
+ if defined?(SimpleFileLogService)
28
+
29
+ def self.log_to_StringIO_and_get_output messages, def_sev, def_pref = nil, def_t = nil, **options
30
+
31
+ def_t ||= Time.now
32
+ def_pref ||= "[prog, thread, #{def_t}]: "
33
+
34
+ stream = StringIO.new
35
+
36
+ svc = SimpleFileLogService.new stream, **options
37
+
38
+ messages.each do |message|
39
+
40
+ ar = ::Array === message ? message : [ message ]
41
+
42
+ msg = ar[0]
43
+ sev = ar[1] || def_sev
44
+ pref = ar[2] || def_pref
45
+ t = ar[3] || def_t
46
+
47
+ svc.log sev, t, pref, msg
48
+ end
49
+
50
+ stream.string
51
+ end
52
+
53
+ def self.log_to_Tempfile_and_get_output messages, def_sev, def_pref = nil, def_t = nil, **options
54
+
55
+ def_t ||= Time.now
56
+ def_pref ||= "[prog, thread, #{def_t}]: "
57
+
58
+ tf = Tempfile.new 'Pantheios.Ruby.Tempfile'
59
+
60
+ begin
61
+
62
+ svc = SimpleFileLogService.new tf, **options
63
+
64
+ messages.each do |message|
65
+
66
+ ar = ::Array === message ? message : [ message ]
67
+
68
+ msg = ar[0]
69
+ sev = ar[1] || def_sev
70
+ pref = ar[2] || def_pref
71
+ t = ar[3] || def_t
72
+
73
+ svc.log sev, t, pref, msg
74
+ end
75
+
76
+ tf.rewind
77
+
78
+ return tf.read
79
+ ensure
80
+
81
+ tf.close
82
+ tf.unlink
83
+ end
84
+ end
85
+
86
+ def self.log_to_Tempfile_path_and_get_output messages, def_sev, def_pref = nil, def_t = nil, **options
87
+
88
+ def_t ||= Time.now
89
+ def_pref ||= "[prog, thread, #{def_t}]: "
90
+
91
+ tf = Tempfile.new 'Pantheios.Ruby.Tempfile'
92
+
93
+ begin
94
+
95
+ svc = SimpleFileLogService.new tf.path, **options
96
+
97
+ messages.each do |message|
98
+
99
+ ar = ::Array === message ? message : [ message ]
100
+
101
+ msg = ar[0]
102
+ sev = ar[1] || def_sev
103
+ pref = ar[2] || def_pref
104
+ t = ar[3] || def_t
105
+
106
+ svc.log sev, t, pref, msg
107
+ end
108
+
109
+ tf.rewind
110
+
111
+ return tf.read
112
+ ensure
113
+
114
+ tf.close
115
+ tf.unlink
116
+ end
117
+ end
118
+
119
+ def test_SimpleFileLogService_type_is_a_class
120
+
121
+ assert_kind_of(::Class, SimpleFileLogService)
122
+ end
123
+
124
+ def test_SimpleFileLogService_type_has_expected_instance_methods
125
+
126
+ assert_type_has_instance_methods SimpleFileLogService, [ :severity_logged?, :log ]
127
+ end
128
+
129
+ def test_ctor_failures_with_invalid_log_file_or_path
130
+
131
+ assert_raise_with_message(::ArgumentError, /log_file_or_path.*not.*nil/) { SimpleFileLogService.new nil }
132
+
133
+ assert_raise_with_message(::TypeError, [ /log_file_or_path.*must be/, /::File/, /::IO/, /::String/, /::StringIO/ ]) { SimpleFileLogService.new // }
134
+ end
135
+
136
+ def test_ctor_failures_with_invalid_options
137
+
138
+ assert_raise_with_message(::ArgumentError, /:roll_depth.*non.*negative.*integer/) { SimpleFileLogService.new '/dev/null', roll_depth: true }
139
+ assert_raise_with_message(::ArgumentError, /:roll_depth.*non.*negative.*integer/) { SimpleFileLogService.new '/dev/null', roll_depth: -1 }
140
+
141
+ assert_raise_with_message(::ArgumentError, /:roll_size.*non.*negative.*integer/) { SimpleFileLogService.new '/dev/null', roll_size: true }
142
+ assert_raise_with_message(::ArgumentError, /:roll_size.*non.*negative.*integer/) { SimpleFileLogService.new '/dev/null', roll_size: -1 }
143
+ end
144
+
145
+ def test_severity_logged_false_with_large_range_of_integers
146
+
147
+ output = StringIO.new
148
+
149
+ svc = SimpleFileLogService.new output
150
+
151
+ (-10000 .. 10000).each do |sev|
152
+
153
+ assert_true(svc.severity_logged?(sev), "severity '#{sev}' (#{sev.class}) was not logged")
154
+ end
155
+ end
156
+
157
+ def test_simple_logging_with_StringIO_1
158
+
159
+ message = 'msg'
160
+
161
+ output = self.class.log_to_StringIO_and_get_output [ message ], :notice, nil, nil
162
+
163
+ lines = output.split /\n/
164
+
165
+ assert_not_empty lines
166
+ assert_equal 1, lines.size
167
+ assert_match /msg$/, lines[0]
168
+ end
169
+
170
+ def test_simple_logging_with_StringIO_2
171
+
172
+ msgs = [
173
+
174
+ [ 'msg-1' ],
175
+ [ 'msg-2' ],
176
+ ]
177
+
178
+ output = self.class.log_to_StringIO_and_get_output msgs, :notice, nil, nil
179
+
180
+ lines = output.split /\n/
181
+
182
+ assert_not_empty lines
183
+ assert_equal 2, lines.size
184
+ assert_match /msg-1$/, lines[0]
185
+ assert_match /msg-2$/, lines[1]
186
+ end
187
+
188
+ def test_simple_logging_with_Tempfile_1
189
+
190
+ message = 'msg'
191
+
192
+ output = self.class.log_to_Tempfile_and_get_output [ message ], :notice, nil, nil
193
+
194
+ lines = output.split /\n/
195
+
196
+ assert_not_empty lines
197
+ assert_equal 1, lines.size
198
+ assert_match /msg$/, lines[0]
199
+ end
200
+
201
+ def test_simple_logging_with_Tempfile_2
202
+
203
+ msgs = [
204
+
205
+ [ 'msg-1' ],
206
+ [ 'msg-2' ],
207
+ ]
208
+
209
+ output = self.class.log_to_Tempfile_and_get_output msgs, :notice, nil, nil
210
+
211
+ lines = output.split /\n/
212
+
213
+ assert_not_empty lines
214
+ assert_equal 2, lines.size
215
+ assert_match /msg-1$/, lines[0]
216
+ assert_match /msg-2$/, lines[1]
217
+ end
218
+
219
+ def test_simple_logging_with_Tempfile_path_1
220
+
221
+ message = 'msg'
222
+
223
+ output = self.class.log_to_Tempfile_path_and_get_output [ message ], :notice, nil, nil
224
+
225
+ lines = output.split /\n/
226
+
227
+ assert_not_empty lines
228
+ assert_equal 1, lines.size
229
+ assert_match /msg$/, lines[0]
230
+ end
231
+
232
+ def test_simple_logging_with_Tempfile_path_2
233
+
234
+ msgs = [
235
+
236
+ [ 'msg-1' ],
237
+ [ 'msg-2' ],
238
+ ]
239
+
240
+ output = self.class.log_to_Tempfile_path_and_get_output msgs, :notice, nil, nil
241
+
242
+ lines = output.split /\n/
243
+
244
+ assert_not_empty lines
245
+ assert_equal 2, lines.size
246
+ assert_match /msg-1$/, lines[0]
247
+ assert_match /msg-2$/, lines[1]
248
+ end
249
+ end
250
+ end
251
+
252
+
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../..', 'lib')
4
+
5
+ require 'pantheios/util/process_util'
6
+
7
+ require 'xqsr3/extensions/test/unit'
8
+
9
+ require 'test/unit'
10
+
11
+ class Test_ProcessUtil_set_thread_name < Test::Unit::TestCase
12
+
13
+ PU = ::Pantheios::Util::ProcessUtil
14
+
15
+ def test_derive_process_name
16
+
17
+ assert_equal 'abc', PU.derive_process_name('abc')
18
+
19
+ assert_equal 'abc', PU.derive_process_name('abc.rb')
20
+
21
+ assert_equal 'abc', PU.derive_process_name('abc.rb')
22
+ end
23
+ end
24
+