Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactor set_expected_state to use hash. Enforce completeness of the

expected state through explicit checking.

Change-Id: I270fda3e42e0731709710feff5c92bcd1de7b386
  • Loading branch information...
commit 6395e85e8eeb7d007bf70aec7c032d8817e0e397 1 parent b50c800
@bnugmanov bnugmanov authored
View
1  .gitignore
@@ -13,3 +13,4 @@ ci-working-dir
*.swp
.rvmrc
*.pid
+/vendor
View
21 lib/health_manager/app_state.rb
@@ -58,13 +58,20 @@ def initialize(id)
reset_missing_indices
end
- def set_expected_state(num_instances, state, live_version, framework, runtime, last_updated)
- @num_instances = num_instances
- @state = state
- @live_version = live_version
- @framework = framework
- @runtime = runtime
- @last_updated = last_updated
+ def set_expected_state(values)
+ values = values.dup #preserve the original
+ [:state,
+ :num_instances,
+ :live_version,
+ :framework,
+ :runtime,
+ :last_updated].each do |k|
+
+ v = values.delete(k)
+ raise ArgumentError.new("Value #{k} is required") unless v
+ self.instance_variable_set("@#{k.to_s}",v)
+ end
+ raise ArgumentError.new("unsupported keys: #{values.keys}") unless values.empty?
end
def notify(event_type, *args)
View
12 lib/health_manager/bulk_based_expected_state_provider.rb
@@ -14,12 +14,12 @@ def set_expected_state(known, expected)
logger.debug { "bulk: #set_expected_state: known: #{known.inspect} expected: #{expected.inspect}" }
known.set_expected_state(
- expected['instances'],
- expected['state'],
- "#{expected['staged_package_hash']}-#{expected['run_count']}",
- expected['framework'],
- expected['runtime'],
- parse_utc(expected['updated_at']))
+ :num_instances => expected['instances'],
+ :state => expected['state'],
+ :live_version => "#{expected['staged_package_hash']}-#{expected['run_count']}",
+ :framework => expected['framework'],
+ :runtime => expected['runtime'],
+ :last_updated => parse_utc(expected['updated_at']))
end
private
View
2  lib/health_manager/harmonizer.rb
@@ -171,7 +171,7 @@ def analyze_all_apps
varz.update_realtime_stats_for_droplet(known_droplet)
true
else
- # TODO: remove
+ # TODO: remove once ready for production
varz.set(:droplets, known_state_provider.droplets)
varz.publish_realtime_stats
View
4 spec/unit/app_state_spec.rb
@@ -19,7 +19,7 @@
it 'should invoke missing_instances event handler' do
future_answer = [1, 3]
event_handler_invoked = false
- app, expected = make_app
+ app, _ = make_app
#no heartbeats arrived yet, so all instances are assumed missing
app.missing_indices.should == [0, 1, 2, 3]
@@ -55,7 +55,7 @@
it 'should invoke extra_instances event handler' do
app, expected = make_app
- extra_instance_id = expected[2]+"-0"
+ extra_instance_id = expected[:live_version]+"-0"
future_answer = [[extra_instance_id, "Extra instance"]]
event_handler_invoked = false
View
10 spec/unit/nats_based_known_state_provider_spec.rb
@@ -27,16 +27,8 @@
it 'should forward heartbeats' do
app, expected = make_app
-
app1 = @nb.get_droplet(app.id)
-
- app1.set_expected_state(
- app.num_instances,
- app.state,
- app.live_version,
- app.framework,
- app.runtime,
- app.last_updated)
+ app1.set_expected_state(expected)
instance = app1.get_instance(app.live_version, 0)
instance['state'].should == 'DOWN'
View
18 spec/unit/spec_helper.rb
@@ -15,16 +15,16 @@ def in_em(timeout = 2)
def make_app(id=1)
app = AppState.new(id)
- expected = [
- 4,
- 'STARTED',
- '12345abcded',
- 'sinatra',
- 'ruby19',
- Time.now.to_i - 60*60*24
- ]
+ expected = {
+ :num_instances => 4,
+ :state => 'STARTED',
+ :live_version => '12345abcded',
+ :framework => 'sinatra',
+ :runtime => 'ruby19',
+ :last_updated => Time.now.to_i - 60*60*24
+ }
- app.set_expected_state(*expected)
+ app.set_expected_state(expected)
return app, expected
end
Please sign in to comment.
Something went wrong with that request. Please try again.