This repository was archived by the owner on Nov 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding specs to test fetching availabilities from event catcher
Components being tested are: * Persister and parser of targeted refresh. Collector is implicitly tested with parser. * New fuctions of event catcher's stream. Some existing test are slightly complemented. Some existing tests were adjusted due to small refactors for code reusability and avoid repeating stuff.
- Loading branch information
1 parent
24f7c82
commit 7e68ff0
Showing
11 changed files
with
582 additions
and
25 deletions.
There are no files selected for viewing
5 changes: 4 additions & 1 deletion
5
app/models/manageiq/providers/hawkular/inventory/availability_updates.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
RSpec.shared_context 'targeted_avail_updates' do | ||
let(:ems_hawkular) { FactoryGirl.create(:ems_hawkular) } | ||
let(:target) { ::ManageIQ::Providers::Hawkular::Inventory::AvailabilityUpdates.new([]) } | ||
let(:persister) { ::ManageIQ::Providers::Hawkular::Inventory::Persister::AvailabilityUpdates.new(ems_hawkular, target) } | ||
let(:collector) { ::ManageIQ::Providers::Hawkular::Inventory::Collector::AvailabilityUpdates.new(ems_hawkular, target) } | ||
let(:parser) do | ||
parser = described_class.new | ||
parser.collector = collector | ||
parser.persister = persister | ||
parser | ||
end | ||
end |
97 changes: 97 additions & 0 deletions
97
spec/models/manageiq/providers/hawkular/inventory/parser/availability_updates_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
describe ManageIQ::Providers::Hawkular::Inventory::Parser::AvailabilityUpdates do | ||
describe "#parse" do | ||
include_context 'targeted_avail_updates' | ||
|
||
it "must create an item in persister with new status data for each server reported by collector" do | ||
# Setup | ||
avail_data = { | ||
'Availability' => 'up', | ||
'Server State' => 'running', | ||
'Calculated Server State' => 'running' | ||
} | ||
|
||
target << ManagerRefresh::Target.new( | ||
:manager => ems_hawkular, | ||
:association => :middleware_servers, | ||
:manager_ref => { :ems_ref => 'abc' }, | ||
:options => avail_data | ||
) | ||
|
||
# Try | ||
parser.parse | ||
|
||
# Verify | ||
item = persister.middleware_servers.find('abc') | ||
expect(item).to be | ||
expect(item.manager_uuid).to eq('abc') | ||
expect(item.properties).to eq(avail_data) | ||
|
||
expect(persister.middleware_deployments.size).to be_zero | ||
end | ||
|
||
it "must create an item in persister with new status data for each deployment reported by collector" do | ||
# Setup | ||
target << ManagerRefresh::Target.new( | ||
:manager => ems_hawkular, | ||
:association => :middleware_deployments, | ||
:manager_ref => { :ems_ref => 'def' }, | ||
:options => { :status => 'ready' } | ||
) | ||
|
||
# Try | ||
parser.parse | ||
|
||
# Verify | ||
item = persister.middleware_deployments.find('def') | ||
expect(item).to be | ||
expect(item.manager_uuid).to eq('def') | ||
expect(item.status).to eq('ready') | ||
|
||
expect(persister.middleware_servers.size).to be_zero | ||
end | ||
|
||
it "must create one persister item if two servers in collector have same ems_ref" do | ||
# Setup | ||
target << ManagerRefresh::Target.new( | ||
:manager => ems_hawkular, | ||
:association => :middleware_servers, | ||
:manager_ref => { :ems_ref => 'abc' }, | ||
:options => { 'Server State' => 'ok' } | ||
) | ||
target << ManagerRefresh::Target.new( | ||
:manager => ems_hawkular, | ||
:association => :middleware_servers, | ||
:manager_ref => { :ems_ref => 'abc' }, | ||
:options => { 'Server State' => 'not ok' } | ||
) | ||
|
||
# Try | ||
parser.parse | ||
|
||
# Verify | ||
expect(persister.middleware_servers.size).to eq(1) | ||
end | ||
|
||
it "must create one persister item if two deployments in collector have same ems_ref" do | ||
# Setup | ||
target << ManagerRefresh::Target.new( | ||
:manager => ems_hawkular, | ||
:association => :middleware_deployments, | ||
:manager_ref => { :ems_ref => 'def' }, | ||
:options => { :status => 'ready' } | ||
) | ||
target << ManagerRefresh::Target.new( | ||
:manager => ems_hawkular, | ||
:association => :middleware_deployments, | ||
:manager_ref => { :ems_ref => 'def' }, | ||
:options => { :status => 'not ready' } | ||
) | ||
|
||
# Try | ||
parser.parse | ||
|
||
# Verify | ||
expect(persister.middleware_deployments.size).to eq(1) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
spec/models/manageiq/providers/hawkular/inventory/persister/availability_updates_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
describe ::ManageIQ::Providers::Hawkular::Inventory::Persister::AvailabilityUpdates do | ||
include_context 'targeted_avail_updates' | ||
|
||
describe '#save_servers' do | ||
let!(:db_server1) { ems_hawkular.middleware_servers.create(:ems_ref => 'server1', :feed => 'f1') } | ||
let!(:db_server2) { ems_hawkular.middleware_servers.create(:ems_ref => 'server2', :feed => 'f1', :properties => { 'Server State' => 'unknown' }) } | ||
|
||
it 'must update status of servers with no properties in database' do | ||
# Set-up | ||
updated_server = persister.middleware_servers.build(:ems_ref => 'server1', :properties => { 'Availability' => 'up' }) | ||
persister.middleware_servers << updated_server | ||
|
||
# Try | ||
described_class.save_servers(ems_hawkular, persister.middleware_servers) | ||
|
||
# Verify | ||
db_server1.reload | ||
db_server2.reload | ||
expect(db_server1.properties).to eq('Availability' => 'up') | ||
expect(db_server2.properties).to eq('Server State' => 'unknown') # Check the other one wasn't updated | ||
end | ||
|
||
it 'must update only status related fields' do | ||
# Set-up | ||
db_server1.properties = { 'Some other data' => 'value' } | ||
db_server1.save! | ||
|
||
updated_server = persister.middleware_servers.build( | ||
:ems_ref => 'server1', | ||
:properties => { | ||
'Availability' => 'up', | ||
'spurious field' => 'ok', | ||
'Server State' => 'running', | ||
'Calculated Server State' => 'down' | ||
} | ||
) | ||
persister.middleware_servers << updated_server | ||
|
||
# Try | ||
described_class.save_servers(ems_hawkular, persister.middleware_servers) | ||
|
||
# Verify | ||
db_server1.reload | ||
expect(db_server1.properties).to eq( | ||
'Availability' => 'up', | ||
'Server State' => 'running', | ||
'Calculated Server State' => 'down', | ||
'Some other data' => 'value' | ||
) | ||
end | ||
|
||
it 'must ignore servers not found in database' do | ||
# Set-up | ||
updated_server = persister.middleware_servers.build(:ems_ref => 'server7', :properties => { 'Server State' => 'new status' }) | ||
persister.middleware_servers << updated_server | ||
|
||
# Try | ||
described_class.save_servers(ems_hawkular, persister.middleware_servers) | ||
|
||
# Verify | ||
db_server1.reload | ||
db_server2.reload | ||
expect(db_server1.properties).to be_blank | ||
expect(db_server2.properties).to eq('Server State' => 'unknown') | ||
|
||
ems_hawkular.middleware_servers.reload | ||
expect(ems_hawkular.middleware_servers.count).to eq(2) | ||
end | ||
end | ||
|
||
describe '#save_deployments' do | ||
let!(:db_deployment1) { ems_hawkular.middleware_deployments.create(:ems_ref => 'deployment1', :status => 'old status') } | ||
let!(:db_deployment2) { ems_hawkular.middleware_deployments.create(:ems_ref => 'deployment2', :status => 'old status') } | ||
|
||
it 'must update status of specified deployments' do | ||
# Set-up | ||
updated_deployment = persister.middleware_deployments.build(:ems_ref => 'deployment1', :status => 'new status') | ||
persister.middleware_deployments << updated_deployment | ||
|
||
# Try | ||
described_class.save_deployments(ems_hawkular, persister.middleware_deployments) | ||
|
||
# Verify | ||
db_deployment1.reload | ||
db_deployment2.reload | ||
expect(db_deployment1.status).to eq('new status') | ||
expect(db_deployment2.status).to eq('old status') | ||
end | ||
|
||
it 'must ignore deployments not found in database' do | ||
# Set-up | ||
updated_deployment = persister.middleware_deployments.build(:ems_ref => 'deployment7', :status => 'new status') | ||
persister.middleware_deployments << updated_deployment | ||
|
||
# Try | ||
described_class.save_deployments(ems_hawkular, persister.middleware_deployments) | ||
|
||
# Verify | ||
db_deployment1.reload | ||
db_deployment2.reload | ||
expect(db_deployment1.status).to eq('old status') | ||
expect(db_deployment2.status).to eq('old status') | ||
|
||
ems_hawkular.middleware_deployments.reload | ||
expect(ems_hawkular.middleware_deployments.count).to eq(2) | ||
end | ||
end | ||
end |
Oops, something went wrong.