pantheios-ruby 0.18.1 → 0.21.0

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.
@@ -1,12 +1,12 @@
1
1
 
2
2
  # ######################################################################## #
3
- # File: lib/pantheios/services/simple_console_log_service.rb
3
+ # File: lib/pantheios/services/null_log_service.rb
4
4
  #
5
5
  # Purpose: Definition of the ::Pantheios::Services::NullLogService
6
6
  # class
7
7
  #
8
8
  # Created: 14th June 2015
9
- # Updated: 22nd January 2018
9
+ # Updated: 8th February 2018
10
10
  #
11
11
  # Home: http://github.com/synesissoftware/Pantheios-Ruby
12
12
  #
@@ -6,7 +6,7 @@
6
6
  # ::Pantheios::Services::SimpleConsoleLogService class
7
7
  #
8
8
  # Created: 14th June 2015
9
- # Updated: 6th January 2018
9
+ # Updated: 12th March 2018
10
10
  #
11
11
  # Home: http://github.com/synesissoftware/Pantheios-Ruby
12
12
  #
@@ -45,8 +45,6 @@
45
45
  # ######################################################################## #
46
46
 
47
47
 
48
- require 'pantheios/application_layer/stock_severity_levels'
49
-
50
48
  =begin
51
49
  =end
52
50
 
@@ -73,11 +71,14 @@ class SimpleConsoleLogService
73
71
  stm.puts "#{pref}#{msg}"
74
72
  end
75
73
 
74
+ # Overrideable method that determines which stream to write, based on a
75
+ # severity. This implementation always returns +$stderr+
76
+ #
77
+ # Overrides must return an object that supports the +puts(String)+
78
+ # method
76
79
  def infer_stream sev
77
80
 
78
- sev = ::Pantheios::ApplicationLayer::StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES[sev] if ::Symbol === sev
79
-
80
- (sev.to_i < 6) ? $stderr : $stdout
81
+ $stderr
81
82
  end
82
83
  end
83
84
 
@@ -9,6 +9,8 @@ module ReflectionUtil
9
9
  ROOT_CLASSES = [ ::Object, ::BasicObject ]
10
10
  end
11
11
 
12
+ # Obtains a list of all classes pertaining to +o+, excepting root
13
+ # objects (+::Object+ and +::BaseObject+).
12
14
  def self.non_root_classes o
13
15
 
14
16
  return [] if o.nil?
@@ -22,6 +22,7 @@ module ThreadUtil
22
22
  t.thread_name = name
23
23
  end
24
24
 
25
+ # Obtains the name of the calling thread
25
26
  def self.get_thread_name t
26
27
 
27
28
  t ||= Thread.current
@@ -5,13 +5,14 @@
5
5
  # Purpose: Version for Pantheios.Ruby library
6
6
  #
7
7
  # Created: 2nd April 2011
8
- # Updated: 5th February 2018
8
+ # Updated: 3rd June 2020
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/Pantheios-Ruby
11
11
  #
12
12
  # Author: Matthew Wilson
13
13
  #
14
- # Copyright (c) 2011-2018, Matthew Wilson and Synesis Software
14
+ # Copyright (c) 2019-2020, Matthew Wilson and Synesis Information Systems
15
+ # Copyright (c) 2011-2019, Matthew Wilson and Synesis Software
15
16
  # All rights reserved.
16
17
  #
17
18
  # Redistribution and use in source and binary forms, with or without
@@ -50,7 +51,7 @@
50
51
  module Pantheios
51
52
 
52
53
  # Current version of the Pantheios.Ruby library
53
- VERSION = '0.18.1'
54
+ VERSION = '0.21.0'
54
55
 
55
56
  private
56
57
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #############################################################################
4
+ # File: test/scratch/multiplexing_log_service.rb
5
+ #
6
+ # Purpose: COMPLETE_ME
7
+ #
8
+ # Created: 7th February 2018
9
+ # Updated: 7th February 2018
10
+ #
11
+ # Author: Matthew Wilson
12
+ #
13
+ # Copyright: <<TBD>>
14
+ #
15
+ #############################################################################
16
+
17
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 2), 'lib')
18
+
19
+ require 'pantheios'
20
+ require 'pantheios/application_layer/stock_severity_levels'
21
+ require 'pantheios/services'
22
+
23
+ $num_BLS_sls = 0
24
+ $num_ELS_sls = 0
25
+
26
+ class BenchmarkLogService
27
+
28
+ def severity_logged? severity
29
+
30
+ $num_BLS_sls += 1
31
+
32
+ (0..100).each { |n| n ** n }
33
+
34
+ :benchmark == severity.to_s.to_sym
35
+ end
36
+
37
+ def log sev, t, pref, msg
38
+
39
+ puts "BENCHMARK: #{pref}#{msg}\n"
40
+ end
41
+ end
42
+
43
+ class EventLogService
44
+
45
+ def severity_logged? severity
46
+
47
+ $num_ELS_sls += 1
48
+
49
+ case severity.to_s.to_sym
50
+ when :notice, :warning, :failure, :critical, :alert, :violation
51
+
52
+ true
53
+ when :warn, :error, :emergency
54
+
55
+ true
56
+ else
57
+
58
+ false
59
+ end
60
+ end
61
+
62
+ def log sev, t, pref, msg
63
+
64
+ puts "EVENTLOG: #{pref}#{msg}\n"
65
+ end
66
+ end
67
+
68
+ scls = Pantheios::Services::SimpleConsoleLogService.new
69
+
70
+ def scls.severity_logged? severity; ![ :benchmark, :trace, :violation ].include? severity; end
71
+
72
+ services = [
73
+
74
+ BenchmarkLogService.new,
75
+ EventLogService.new,
76
+ scls,
77
+ ]
78
+
79
+ lcm = :none
80
+ #lcm = :thread_fixed
81
+ #lcm = :process_fixed
82
+ unsync = false
83
+ #unsync = true
84
+
85
+ Pantheios::Core.set_service Pantheios::Services::MultiplexingLogService.new(services, level_cache_mode: lcm, unsyc_process_lcm: unsync)
86
+
87
+ include Pantheios
88
+
89
+ t_b = Time.now
90
+
91
+ log :benchmark, 'statement at benchmark'
92
+ (0..100000).each { log :trace, 'statement at trace' }
93
+ log :debug4, 'statement at debug-4'
94
+ log :debug3, 'statement at debug-3'
95
+ log :debug2, 'statement at debug-2'
96
+ log :debug1, 'statement at debug-1'
97
+ log :debug0, 'statement at debug-0'
98
+ log :informational, 'statement at informational'
99
+ log :notice, 'statement at notice'
100
+ log :warning, 'statement at warning'
101
+ log :failure, 'statement at failure'
102
+ log :critical, 'statement at critical'
103
+ log :alert, 'statement at alert'
104
+ log :violation, 'statement at violation'
105
+
106
+ t_a = Time.now
107
+
108
+ $stderr.puts "mode= :#{lcm}; t=#{t_a - t_b}; #BLS=#{$num_BLS_sls}; #ELS=#{$num_ELS_sls}"
109
+
@@ -26,12 +26,15 @@ class Test_StockSeverityLevels < Test::Unit::TestCase
26
26
  debug2
27
27
  debug3
28
28
  debug4
29
+ debug5
29
30
  trace
31
+ benchmark
30
32
  }.map { |s| s.to_sym }
31
33
 
32
34
  EXPECTED_LEVELS = %w{
33
35
 
34
36
  emergency
37
+ fail
35
38
  info
36
39
  warn
37
40
  }.map { |s| s.to_sym } + EXPECTED_LEVELS_PRIME
@@ -51,6 +54,7 @@ class Test_StockSeverityLevels < Test::Unit::TestCase
51
54
  if defined? StockSeverityLevels
52
55
 
53
56
  assert StockSeverityLevels.const_defined?(:STOCK_SEVERITY_LEVELS)
57
+ assert StockSeverityLevels.const_defined?(:STOCK_SEVERITY_LEVELS_PRIME)
54
58
  assert StockSeverityLevels.const_defined?(:STOCK_SEVERITY_LEVEL_VALUES)
55
59
  assert StockSeverityLevels.const_defined?(:STOCK_SEVERITY_LEVEL_STRINGS)
56
60
  end
@@ -58,18 +62,36 @@ class Test_StockSeverityLevels < Test::Unit::TestCase
58
62
 
59
63
  def test_StockSeverityLevels_expected_levels
60
64
 
65
+ # all the ones that we expect exist
66
+
61
67
  EXPECTED_LEVELS.each do |sev|
62
68
 
63
69
  assert(StockSeverityLevels::STOCK_SEVERITY_LEVELS.include?(sev), "did not find level #{::Symbol === sev ? ':' : ''}#{sev} in #{StockSeverityLevels}::STOCK_SEVERITY_LEVELS")
64
70
  end
71
+
72
+ # we expect all the ones that exist
73
+
74
+ StockSeverityLevels::STOCK_SEVERITY_LEVELS.each do |sev|
75
+
76
+ assert(EXPECTED_LEVELS.include?(sev), "found unexpected level #{::Symbol === sev ? ':' : ''}#{sev} in #{StockSeverityLevels}::STOCK_SEVERITY_LEVELS")
77
+ end
65
78
  end
66
79
 
67
80
  def test_StockSeverityLevels_expected_prime_levels
68
81
 
82
+ # all the ones that we expect exist
83
+
69
84
  EXPECTED_LEVELS_PRIME.each do |sev|
70
85
 
71
86
  assert(StockSeverityLevels::STOCK_SEVERITY_LEVELS_PRIME.include?(sev), "did not find level #{::Symbol === sev ? ':' : ''}#{sev} in #{StockSeverityLevels}::STOCK_SEVERITY_LEVELS")
72
87
  end
88
+
89
+ # we expect all the ones that exist
90
+
91
+ StockSeverityLevels::STOCK_SEVERITY_LEVELS_PRIME.each do |sev|
92
+
93
+ assert(EXPECTED_LEVELS_PRIME.include?(sev), "found unexpected level #{::Symbol === sev ? ':' : ''}#{sev} in #{StockSeverityLevels}::STOCK_SEVERITY_LEVELS")
94
+ end
73
95
  end
74
96
 
75
97
  def test_StockSeverityLevels_expected_prime_levels_have_distinct_values
@@ -99,5 +121,50 @@ class Test_StockSeverityLevels < Test::Unit::TestCase
99
121
  strings[string] = string
100
122
  end
101
123
  end
124
+
125
+ def test_StockSeverityLevels_aliases
126
+
127
+ aliases = StockSeverityLevels::STOCK_SEVERITY_LEVEL_ALIASES
128
+
129
+ assert_equal :violation, aliases[:violation]
130
+ assert_equal :violation, aliases[:emergency]
131
+
132
+ assert_equal :alert, aliases[:alert]
133
+
134
+ assert_equal :critical, aliases[:critical]
135
+
136
+ assert_equal :failure, aliases[:failure]
137
+ assert_equal :failure, aliases[:fail]
138
+ #assert_equal :failure, aliases[:error]
139
+
140
+ assert_equal :warning, aliases[:warning]
141
+ assert_equal :warning, aliases[:warn]
142
+
143
+ assert_equal :notice, aliases[:notice]
144
+
145
+ assert_equal :informational, aliases[:informational]
146
+ assert_equal :informational, aliases[:info]
147
+
148
+ %i{ debug0 debug1 debug2 debug3 debug4 debug5 }.each do |sev|
149
+
150
+ assert_equal sev, aliases[sev]
151
+ end
152
+
153
+ assert_equal :trace, aliases[:trace]
154
+
155
+ assert_equal :benchmark, aliases[:benchmark]
156
+ end
157
+
158
+ def test_StockSeverityLevels_recognised_values_are_nil
159
+
160
+ EXPECTED_LEVELS.each do |sev|
161
+
162
+ assert_not_nil StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES[sev]
163
+ assert_nil StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES[sev.to_s]
164
+ end
165
+
166
+ assert_nil StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES[nil]
167
+ assert_nil StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES['failure']
168
+ end
102
169
  end
103
170
 
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../..', 'lib')
4
+
5
+ require 'pantheios/front_ends/threshold_front_end'
6
+
7
+ require 'test/unit'
8
+
9
+ class Test_FrontEnds_ThresholdFrontEnd < Test::Unit::TestCase
10
+
11
+ include ::Pantheios::FrontEnds
12
+
13
+ def test_SimpleConsoleLogService_type_exists
14
+
15
+ assert defined? ThresholdFrontEnd
16
+ end
17
+
18
+ def test_construct_with_invalid_parameters
19
+
20
+ assert_raise(::TypeError) { ThresholdFrontEnd.new('notice') }
21
+
22
+ assert_raise_with_message(::ArgumentError, /unknown threshold severity level.*something_else.*Symbol/) { ThresholdFrontEnd.new(:something_else) }
23
+
24
+ ThresholdFrontEnd.new(:notice)
25
+ ThresholdFrontEnd.new(:notice, value_lookup_map: Hash.new)
26
+ assert_raise_with_message(::TypeError, /:value_lookup_map must be.*Hash/) { ThresholdFrontEnd.new(:notice, value_lookup_map: Array.new) }
27
+ end
28
+
29
+ def test_default_construct
30
+
31
+ fe = ThresholdFrontEnd.new(:notice)
32
+
33
+ assert_equal :notice, fe.threshold
34
+
35
+ assert_true fe.severity_logged?(:violation)
36
+ assert_true fe.severity_logged?(:alert)
37
+ assert_true fe.severity_logged?(:critical)
38
+ assert_true fe.severity_logged?(:failure)
39
+ assert_true fe.severity_logged?(:warning)
40
+ assert_true fe.severity_logged?(:notice)
41
+ assert_false fe.severity_logged?(:informational)
42
+ assert_false fe.severity_logged?(:debug0)
43
+ assert_false fe.severity_logged?(:debug1)
44
+ assert_false fe.severity_logged?(:debug2)
45
+ assert_false fe.severity_logged?(:debug3)
46
+ assert_false fe.severity_logged?(:debug4)
47
+ assert_false fe.severity_logged?(:debug5)
48
+ assert_false fe.severity_logged?(:trace)
49
+ end
50
+
51
+ def test_default_construct_and_change_threshold
52
+
53
+ fe = ThresholdFrontEnd.new(:notice)
54
+
55
+ assert_equal :notice, fe.threshold
56
+
57
+ fe.threshold = :failure
58
+
59
+ assert_equal :failure, fe.threshold
60
+
61
+ assert_true fe.severity_logged?(:violation)
62
+ assert_true fe.severity_logged?(:alert)
63
+ assert_true fe.severity_logged?(:critical)
64
+ assert_true fe.severity_logged?(:failure)
65
+ assert_false fe.severity_logged?(:warning)
66
+ assert_false fe.severity_logged?(:notice)
67
+ assert_false fe.severity_logged?(:informational)
68
+ assert_false fe.severity_logged?(:debug0)
69
+ assert_false fe.severity_logged?(:debug1)
70
+ assert_false fe.severity_logged?(:debug2)
71
+ assert_false fe.severity_logged?(:debug3)
72
+ assert_false fe.severity_logged?(:debug4)
73
+ assert_false fe.severity_logged?(:debug5)
74
+ assert_false fe.severity_logged?(:trace)
75
+ end
76
+
77
+ def test_use_custom_thresholds
78
+
79
+ value_lookup_map = {
80
+
81
+ FATAL: 1,
82
+ ERROR: 2,
83
+ WARN: 3,
84
+ INFO: 4,
85
+ DEBUG: 5,
86
+ }
87
+
88
+ fe = ThresholdFrontEnd.new(:INFO, value_lookup_map: value_lookup_map)
89
+
90
+ assert_equal :INFO, fe.threshold
91
+
92
+ assert_true fe.severity_logged?(:FATAL)
93
+ assert_true fe.severity_logged?(:ERROR)
94
+ assert_true fe.severity_logged?(:WARN)
95
+ assert_true fe.severity_logged?(:INFO)
96
+ assert_false fe.severity_logged?(:DEBUG)
97
+ end
98
+ end
99
+
100
+ # ############################## end of file ############################# #
101
+
102
+
@@ -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 12, 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 12, 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 12, 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 12, 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
+