Permalink
Browse files

fix testing to work with new alerts model

  • Loading branch information...
1 parent 907ecd7 commit 5df91e2df1ba4da8a07e657b899fac7a0f810eb2 @fetep committed May 28, 2012
Showing with 36 additions and 67 deletions.
  1. +13 −28 lib/cepmon/test.rb
  2. +12 −0 test.cfg
  3. +11 −0 test.data
  4. +0 −39 testdata.txt
View
@@ -7,7 +7,7 @@ class Test
def initialize(config)
@config = config
@engine = CEPMon::Engine.new
- @event_listener = CEPMon::EventListener.new(@engine)
+ @event_listener = CEPMon::EventListener.new(@engine, @config)
@engine.add_statements(@config, @event_listener)
end
@@ -23,36 +23,21 @@ def run(args)
when "clear"
@engine.admin.destroyAllStatements()
@engine.add_statements(@config, @event_listener)
- @event_listener.clear_history
- when /^assert (!)?([^ ]+)( .*)?/
- negate, statement, variables = $1, $2, $3
-
- if negate
- # make sure the statement hasn't fired
- hist = @event_listener.history.select { |h| h[0] == statement }
- if hist.length > 0
- raise "#{file}:#{linenum}: assert !#{statement} failed, rule fired: #{hist.inspect}"
+ @event_listener.clear
+ when /^(assert_active|assert_inactive) (.+)/
+ assert_type, statement = $1, $2
+ match = false
+ @event_listener.alerts.each do |a|
+ if a.data[:statement] == statement
+ match = true
+ break
end
-
- next
end
- # make sure the statement fired
- hist = @event_listener.alerts.select { |key, alert| alert.statement == statement }
- if hist.length == 0
- raise "#{file}:#{linenum}: assert #{statement} failed, did not fire"
- end
-
- # check variables
- variables ||= ""
- variables.strip.split(/ +/).each do |eq|
- var, value = eq.split("=", 2)
- # use the first event that fired
- event_vars = hist.first[1]
- #puts "checking #{var} == #{value.inspect}: #{event_vars[var].inspect}"
- if value != event_vars[var].to_s
- raise "#{file}:#{linenum}: assert #{statement} #{var}==#{value} failed, actual value is #{event_vars[var]}"
- end
+ if assert_type == "assert_active" and match == false
+ raise "#{file}:#{linenum}: assert_active #{statement} failed"
+ elsif assert_type == "assert_inactive" and match == true
+ raise "#{file}:#{linenum}: assert_inactive #{statement} failed"
end
else
CEPMon::Metric.new(line).send(@engine)
View
@@ -0,0 +1,12 @@
+# vim:syntax=ruby
+# "metric" events have attributes: name, host, cluster, value
+
+listen "127.0.0.1", 8989
+
+threshold('test_host_gt', 'test.foo',
+ :operator => '>',
+ :threshold => 1.0,
+ :units => 'foo/s',
+ :average_over => '1 min',
+ :level => :host
+ )
View
@@ -0,0 +1,11 @@
+clear
+
+test.foo.colo1.host1 0 20
+test.foo.colo1.host1 0 40
+test.foo.colo1.host1 0 60
+test.foo.colo1.host1 0.4 80
+test.foo.colo1.host1 0.9 100
+test.foo.colo1.host1 1.2 120
+assert_inactive test_host_gt
+test.foo.colo1.host1 1.0 140
+assert_active test_host_gt
View
@@ -1,39 +0,0 @@
-clear
-
-browserid.stats.verifier.verify_time.mean.stage.web1_idweb 11.34 10
-browserid.stats.verifier.verify_time.mean.stage.web2_idweb 10.97 10
-
-browserid.stats.verifier.verify_time.mean.stage.web1_idweb 8.80 55
-browserid.stats.verifier.verify_time.mean.stage.web2_idweb 9.45 55
-
-browserid.stats.verifier.verify_time.mean.stage.web1_idweb 12.41 100
-browserid.stats.verifier.verify_time.mean.stage.web2_idweb 10.43 100
-
-browserid.stats.verifier.verify_time.mean.stage.web1_idweb 9.89 145
-browserid.stats.verifier.verify_time.mean.stage.web2_idweb 7.74 145
-
-browserid.stats.verifier.verify_time.mean.stage.web1_idweb 11.89 190
-browserid.stats.verifier.verify_time.mean.stage.web2_idweb 12.32 190
-
-browserid.stats.verifier.verify_time.mean.stage.web1_idweb 13.83 235
-browserid.stats.verifier.verify_time.mean.stage.web2_idweb 10.44 235
-
-browserid.stats.verifier.verify_time.mean.stage.web1_idweb 15.88 280
-browserid.stats.verifier.verify_time.mean.stage.web2_idweb 8.39 280
-
-browserid.stats.verifier.verify_time.mean.stage.web1_idweb 19.32 325
-browserid.stats.verifier.verify_time.mean.stage.web2_idweb 10.11 325
-
-browserid.stats.verifier.verify_time.mean.stage.web1_idweb 22.00 370
-browserid.stats.verifier.verify_time.mean.stage.web2_idweb 9.44 370
-
-browserid.stats.verifier.verify_time.mean.stage.web1_idweb 25.43 415
-browserid.stats.verifier.verify_time.mean.stage.web2_idweb 9.19 415
-
-browserid.stats.verifier.verify_time.mean.stage.web1_idweb 25.01 450
-browserid.stats.verifier.verify_time.mean.stage.web2_idweb 9.23 450
-
-browserid.stats.verifier.verify_time.mean.stage.web1_idweb 22.88 495
-browserid.stats.verifier.verify_time.mean.stage.web2_idweb 10.33 495
-
-assert 10_alerts_cluster_sla_gt_browserid_stats_verifier_verify_time_mean

0 comments on commit 5df91e2

Please sign in to comment.