diff --git a/Gemfile.lock b/Gemfile.lock index 2ed920f..b2a9b11 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -77,7 +77,7 @@ GEM ostruct (0.6.0) rake (13.2.1) regexp_parser (2.9.2) - rsmp_schema (0.8.3) + rsmp_schema (0.8.4) json_schemer (~> 2.3.0) thor (~> 1.3.1) rspec (3.13.0) diff --git a/lib/rsmp/message.rb b/lib/rsmp/message.rb index 65d6c2c..21cc1ad 100644 --- a/lib/rsmp/message.rb +++ b/lib/rsmp/message.rb @@ -20,69 +20,69 @@ def self.parse_attributes json raise InvalidPacket, bin_to_chars(json) end - def self.build attributes, json + def self.build core_version, attributes, json validate_message_type attributes case attributes["type"] when "MessageAck" - message = MessageAck.new attributes + message = MessageAck.new core_version, attributes when "MessageNotAck" - message = MessageNotAck.new attributes + message = MessageNotAck.new core_version, attributes when "Version" - message = Version.new attributes + message = Version.new core_version, attributes when "AggregatedStatus" - message = AggregatedStatus.new attributes + message = AggregatedStatus.new core_version, attributes when "AggregatedStatusRequest" - message = AggregatedStatusRequest.new attributes + message = AggregatedStatusRequest.new core_version, attributes when "Watchdog" - message = Watchdog.new attributes + message = Watchdog.new core_version, attributes when "Alarm" - message = self.build_alarm attributes + message = self.build_alarm core_version, attributes when "CommandRequest" - message = CommandRequest.new attributes + message = CommandRequest.new core_version, attributes when "CommandResponse" - message = CommandResponse.new attributes + message = CommandResponse.new core_version, attributes when "StatusRequest" - message = StatusRequest.new attributes + message = StatusRequest.new core_version, attributes when "StatusResponse" - message = StatusResponse.new attributes + message = StatusResponse.new core_version, attributes when "StatusSubscribe" - message = StatusSubscribe.new attributes + message = StatusSubscribe.new core_version, attributes when "StatusUnsubscribe" - message = StatusUnsubscribe.new attributes + message = StatusUnsubscribe.new core_version, attributes when "StatusUpdate" - message = StatusUpdate.new attributes + message = StatusUpdate.new core_version, attributes else - message = Unknown.new attributes + message = Unknown.new core_version, attributes end message.json = json message.direction = :in message end - def self.build_alarm attributes + def self.build_alarm core_version, attributes case attributes["aSp"] when /^Issue$/i - AlarmIssue.new attributes + AlarmIssue.new core_version, attributes when /^Request$/i - AlarmRequest.new attributes + AlarmRequest.new core_version, attributes when /^Acknowledge$/i if attributes['ack'] =~ /^acknowledged$/i - AlarmAcknowledged.new attributes + AlarmAcknowledged.new core_version, attributes else - AlarmAcknowledge.new attributes + AlarmAcknowledge.new core_version, attributes end when /^Suspend$/i if attributes['sS'] =~ /^suspended$/i - AlarmSuspended.new attributes + AlarmSuspended.new core_version, attributes elsif attributes['sS'] =~ /^notSuspended$/i - AlarmResumed.new attributes + AlarmResumed.new core_version, attributes else - AlarmSuspend.new attributes + AlarmSuspend.new core_version, attributes end when /^Resume$/i - AlarmResume.new attributes + AlarmResume.new core_version, attributes else - Alarm.new attributes + Alarm.new core_version, attributes end end @@ -135,11 +135,10 @@ def self.validate_message_type attributes raise MalformedMessage.new("'type' must be a String, got #{attributes["type"].class}") unless attributes["type"].is_a? String end - def initialize attributes = {} + def initialize core_version, attributes = {} @timestamp = Time.now # this timestamp is for internal use, and does not use the clock # in the node, which can be set by an rsmp supervisor - - @attributes = { "mType"=> "rSMsg" }.merge attributes + @attributes = attributes.merge( "mType"=> "rSMsg" ) ensure_message_id end @@ -183,7 +182,7 @@ def generate_json end class Malformed < Message - def initialize attributes = {} + def initialize core_version, attributes = {} # don't call super, just copy (potentially invalid) attributes @attributes = {} @invalid_attributes = attributes @@ -191,10 +190,10 @@ def initialize attributes = {} end class Version < Message - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "type" => "Version", - }.merge attributes) + )) end def versions @@ -206,30 +205,30 @@ class Unknown < Message end class AggregatedStatus < Message - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "type" => "AggregatedStatus", - }.merge attributes) + )) end end class AggregatedStatusRequest < Message - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "type" => "AggregatedStatusRequest", - }.merge attributes) + )) end end class Alarm < Message - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "type" => "Alarm", "ntsOId" => '', "xNId" => '', "xACId" => '', "xNACId" => '' - }.merge attributes) + )) end def differ? from @@ -242,84 +241,85 @@ def differ? from end class AlarmIssue < Alarm - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "aSp" => "Issue" - }.merge attributes) + )) end end class AlarmRequest < Alarm - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "aSp" => "Request", - }.merge attributes) + )) end end class AlarmAcknowledge < Alarm - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "aSp" => "Acknowledge", - }.merge attributes) + )) end end class AlarmAcknowledged < Alarm - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "aSp" => "Acknowledge", - "ack" => "acknowledged" - }.merge attributes) + "ack" => "Acknowledged" + )) + p @attributes end end class AlarmSuspend < Alarm - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "aSp" => "Suspend", - }.merge attributes) + )) end end class AlarmSuspended < Alarm - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "aSp" => "Suspend", "sS" => "Suspended" - }.merge attributes) + )) end end class AlarmResume < Alarm - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "aSp" => "Resume", - }.merge attributes) + )) end end class AlarmResumed < Alarm - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "aSp" => "Suspend", "sS" => "notSuspended" - }.merge attributes) + )) end end class Watchdog < Message - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "type" => "Watchdog", - }.merge attributes) + )) end end class MessageAcking < Message attr_reader :original - def self.build_from message - return new({ + def self.build_from message, core_version + return new(core_version, { "oMId" => message.attributes["mId"] }) end @@ -332,83 +332,84 @@ def original= message def validate_id true end + + def ensure_message_id + # Ack and NotAck does not have a mId + end end class MessageAck < MessageAcking - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + p attributes + super(core_version, attributes.merge( "type" => "MessageAck", - }.merge attributes) - end - - def ensure_message_id - # Ack and NotAck does not have a mId + )) end end class MessageNotAck < MessageAcking - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "type" => "MessageNotAck", "rea" => "Unknown reason" - }.merge attributes) + )) @attributes.delete "mId" end end class CommandRequest < Message - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "type" => "CommandRequest", - }.merge attributes) + )) end end class CommandResponse < Message - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "type" => "CommandResponse", - }.merge attributes) + )) end end class StatusRequest < Message - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "type" => "StatusRequest", - }.merge attributes) + )) end end class StatusResponse < Message - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "type" => "StatusResponse", - }.merge attributes) + )) end end class StatusSubscribe < Message - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "type" => "StatusSubscribe", - }.merge attributes) + )) end end class StatusUnsubscribe < Message - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "type" => "StatusUnsubscribe", - }.merge attributes) + )) end end class StatusUpdate < Message - def initialize attributes = {} - super({ + def initialize core_version, attributes = {} + super(core_version, attributes.merge( "type" => "StatusUpdate", - }.merge attributes) + )) end end diff --git a/lib/rsmp/proxy.rb b/lib/rsmp/proxy.rb index c8daaab..fec7d6e 100644 --- a/lib/rsmp/proxy.rb +++ b/lib/rsmp/proxy.rb @@ -395,7 +395,7 @@ def verify_sequence message def process_packet json attributes = Message.parse_attributes json - message = Message.build attributes, json + message = Message.build core_version, attributes, json message.validate(get_schemas) if should_validate_ingoing_message?(message) verify_sequence message with_deferred_distribution do @@ -502,7 +502,7 @@ def process_version message def acknowledge original raise InvalidArgument unless original - ack = MessageAck.build_from(original) + ack = MessageAck.build_from(original, core_version) ack.original = original.clone send_message ack, "for #{ack.original.type} #{original.m_id_short}" check_ingoing_acknowledged original diff --git a/lib/rsmp/supervisor.rb b/lib/rsmp/supervisor.rb index 6446710..8b6a227 100644 --- a/lib/rsmp/supervisor.rb +++ b/lib/rsmp/supervisor.rb @@ -137,7 +137,7 @@ def check_max_sites def peek_version_message protocol json = protocol.peek_line attributes = Message.parse_attributes json - Message.build attributes, json + Message.build core_version, attributes, json end # accept an incoming connecting by creating and starting a proxy diff --git a/spec/ack_collector_spec.rb b/spec/ack_collector_spec.rb index d8d5dd4..b06951f 100644 --- a/spec/ack_collector_spec.rb +++ b/spec/ack_collector_spec.rb @@ -2,8 +2,8 @@ let(:timeout) { 0.01 } it 'gets a MessageAck from m_id' do - AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + AsyncRSpec.async do |task| + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) m_id = '397786b1-c8d0-4888-a557-241ad5772983' other_m_id = '297d122e-a2fb-4a22-a407-52b8c5133771' collect_task = task.async do @@ -16,8 +16,8 @@ expect(collector.messages.first).to be_an(RSMP::MessageAck) expect(collector.messages.first.attributes['oMId']).to eq(m_id) end - proxy.distribute RSMP::MessageAck.new "oMId" => other_m_id # should be ignored because oMId does not match - proxy.distribute RSMP::MessageAck.new "oMId" => m_id # should be collected, because oMID matches + proxy.distribute RSMP::MessageAck.new proxy.core_version, "oMId" => other_m_id # should be ignored because oMId does not match + proxy.distribute RSMP::MessageAck.new proxy.core_version, "oMId" => m_id # should be collected, because oMID matches collect_task.wait end end diff --git a/spec/alarm_collector_spec.rb b/spec/alarm_collector_spec.rb index 47cc4f7..65d57e8 100644 --- a/spec/alarm_collector_spec.rb +++ b/spec/alarm_collector_spec.rb @@ -40,7 +40,7 @@ describe '#collect' do it 'gets any alarm' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::AlarmCollector.new proxy, num: 2, timeout: timeout result = collector.collect @@ -59,7 +59,7 @@ it 'times out' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::AlarmCollector.new proxy, num: 1, timeout: timeout result = collector.collect @@ -72,7 +72,7 @@ it 'matches cId' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::AlarmCollector.new proxy, matcher: {'cId' => 'DL1'}, num: 1, timeout: timeout result = collector.collect @@ -90,7 +90,7 @@ it 'matches aCId' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::AlarmCollector.new proxy, matcher: {'aCId' => 'A0302'}, num: 1, timeout: timeout result = collector.collect @@ -108,7 +108,7 @@ it 'matches aSp' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::AlarmCollector.new proxy, matcher: {'aSp' => 'Issue'}, num: 1, timeout: timeout result = collector.collect @@ -126,7 +126,7 @@ it 'matches aSp with regex' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::AlarmCollector.new proxy, matcher: {'aSp' => /[Ii]ssue/}, num: 1, timeout: timeout result = collector.collect @@ -144,7 +144,7 @@ it 'matches ack' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::AlarmCollector.new proxy, matcher: {'ack' => 'Acknowledged'}, num: 1, timeout: timeout result = collector.collect @@ -162,7 +162,7 @@ it 'matches As' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::AlarmCollector.new proxy, matcher: {'aS' => 'Active'}, num: 1, timeout: timeout result = collector.collect @@ -180,7 +180,7 @@ it 'matches sS' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::AlarmCollector.new proxy, matcher: {'sS' => 'notSuspended'}, num: 1, timeout: timeout result = collector.collect @@ -198,7 +198,7 @@ it 'matches cat' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::AlarmCollector.new proxy, matcher: {'cat' => 'D'}, num: 1, timeout: timeout result = collector.collect @@ -216,7 +216,7 @@ it 'matches pri' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::AlarmCollector.new proxy, matcher: {'pri' => '1'}, num: 1, timeout: timeout result = collector.collect @@ -235,7 +235,7 @@ it 'matches rvs' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do rvs = [ {'n' => 'color', 'v' => 'green'} diff --git a/spec/collector_spec.rb b/spec/collector_spec.rb index fb817a1..5e37a69 100644 --- a/spec/collector_spec.rb +++ b/spec/collector_spec.rb @@ -4,7 +4,7 @@ describe '#collect' do it 'gets anything' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::Collector.new proxy, num: 1, timeout: timeout result = collector.collect @@ -21,7 +21,7 @@ it 'gets one Watchdog' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do filter = RSMP::Filter.new type: "Watchdog" collector = RSMP::Collector.new proxy, filter: filter, num: 1, timeout: timeout @@ -39,7 +39,7 @@ it 'gets two Watchdogs' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do filter = RSMP::Filter.new type: "Watchdog" collector = RSMP::Collector.new proxy, filter: filter, num: 2, timeout: timeout @@ -59,7 +59,7 @@ it 'gets a MessageAck' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do filter = RSMP::Filter.new type: "MessageAck" collector = RSMP::Collector.new proxy, filter: filter, num: 1, timeout: timeout @@ -70,14 +70,14 @@ expect(collector.messages.size).to eq(1) expect(collector.messages.first).to be_an(RSMP::MessageAck) end - proxy.distribute RSMP::MessageAck.new + proxy.distribute RSMP::MessageAck.new proxy.core_version collect_task.wait end end it 'gets a MessageNotAck' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do filter = RSMP::Filter.new type: "MessageNotAck" collector = RSMP::Collector.new proxy, filter: filter, num: 1, timeout: timeout @@ -95,7 +95,7 @@ it 'times out if nothing is received' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) filter = RSMP::Filter.new type: "Watchdog" collector = RSMP::Collector.new proxy, filter: filter, num: 1, timeout: timeout result = collector.collect @@ -108,7 +108,7 @@ it 'can be called with no timeout' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::Collector.new proxy, num: 1 result = collector.collect @@ -121,7 +121,7 @@ it 'can filter by component id' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do filter = RSMP::Filter.new component: 'good' collector = RSMP::Collector.new proxy, num: 1, timeout: 1, filter: filter @@ -140,7 +140,7 @@ it 'raises if required options are missing' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = RSMP::Collector.new proxy, task: task expect { collector.collect }.to raise_error(ArgumentError) end @@ -148,7 +148,7 @@ it 'can cancel on MessageNotAck' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) message = RSMP::StatusRequest.new collect_task = task.async do filter = RSMP::Filter.new type: "StatusUpdate" @@ -176,7 +176,7 @@ describe '#collect with block' do it 'can keep or skip messages' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::Collector.new proxy, num: 1, timeout: timeout messages = [] @@ -196,7 +196,7 @@ it 'can cancel collection' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::Collector.new proxy, num: 1, timeout: timeout result = collector.collect do |message| @@ -212,7 +212,7 @@ it 'can cancel on schema error' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::Collector.new proxy, num: 1, timeout: timeout result = collector.collect @@ -228,7 +228,7 @@ it 'can cancel if disconnect' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::Collector.new proxy, num: 1, timeout: timeout, cancel: {disconnect: true} result = collector.collect @@ -244,7 +244,7 @@ it 'can be used without num or timeout' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::Collector.new proxy, task: task messages = [] @@ -266,7 +266,7 @@ describe "#collect!" do it "raises exception if not successful" do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::Collector.new proxy, num: 1, timeout: timeout expect { collector.collect! }.to raise_error(RSMP::TimeoutError) @@ -277,7 +277,7 @@ it "returns messages if successful" do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collect_task = task.async do collector = RSMP::Collector.new proxy, num: 1, timeout: timeout messages = collector.collect! @@ -292,7 +292,7 @@ it 'raises on MessageNotAck' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) message = RSMP::StatusRequest.new collect_task = task.async do collector = RSMP::Collector.new( @@ -314,7 +314,7 @@ describe "#start" do it "sets status and returns immediately" do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = RSMP::Collector.new proxy, num: 1, timeout: timeout collector.start expect(collector.status).to eq(:collecting) @@ -325,7 +325,7 @@ describe "#wait" do it "returns :ok if already complete" do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = RSMP::Collector.new proxy, num: 1, timeout: timeout collector.start proxy.distribute RSMP::Watchdog.new @@ -337,7 +337,7 @@ it "returns :ok after completion" do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = RSMP::Collector.new proxy, num: 1, timeout: timeout collector.start collect_task = task.async do @@ -352,7 +352,7 @@ it "returns :timeout" do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = RSMP::Collector.new proxy, num: 1, timeout: timeout collector.start expect(collector.wait).to eq(:timeout) @@ -363,7 +363,7 @@ describe "#wait!" do it "returns messages if already complete" do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = RSMP::Collector.new proxy, num: 1, timeout: timeout collector.start proxy.distribute RSMP::Watchdog.new @@ -377,7 +377,7 @@ it "returns messages after completion" do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = RSMP::Collector.new proxy, num: 1, timeout: timeout collector.start collect_task = task.async do @@ -393,7 +393,7 @@ it "raises TimeoutError" do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = RSMP::Collector.new proxy, num: 1, timeout: timeout collector.start expect { collector.wait! }.to raise_error(RSMP::TimeoutError) diff --git a/spec/command_response_collector_spec.rb b/spec/command_response_collector_spec.rb index a70706e..66d13f8 100644 --- a/spec/command_response_collector_spec.rb +++ b/spec/command_response_collector_spec.rb @@ -37,7 +37,7 @@ def build_command_reponse command_list describe '#collect' do it 'completes with a single command response' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = RSMP::CommandResponseCollector.new(proxy, want.values, timeout: timeout) expect(collector.summary).to eq([false,false,false]) expect(collector.done?).to be(false) @@ -50,7 +50,7 @@ def build_command_reponse command_list it 'completes with sequential status updates' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = RSMP::CommandResponseCollector.new(proxy, want.values, timeout: timeout) expect(collector.summary).to eq([false,false,false]) expect(collector.done?).to be(false) @@ -72,7 +72,7 @@ def build_command_reponse command_list it 'cannot marks matchers as not done' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = RSMP::CommandResponseCollector.new(proxy, want.values, timeout: timeout) expect(collector.done?).to be(false) expect(collector.summary).to eq([false,false,false]) @@ -102,7 +102,7 @@ def build_command_reponse command_list it 'raises if notified after being complete' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = RSMP::CommandResponseCollector.new(proxy, want.values, timeout: timeout) collector.start collector.receive build_command_reponse(ok.values) @@ -113,7 +113,7 @@ def build_command_reponse command_list it 'extra status updates are ignored' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = RSMP::CommandResponseCollector.new(proxy, want.values, timeout: timeout) collector.use_task task # proxy should have no receivers initially @@ -145,7 +145,7 @@ def build_command_reponse command_list describe '#collect with block' do it 'gets message and each item' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = RSMP::CommandResponseCollector.new(proxy, want.values, task: task, timeout: timeout) collect_task = task.async do messages = [] @@ -170,7 +170,7 @@ def build_command_reponse command_list it 'can keep or reject items' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) want = {"sCI" => "S0001","n" => "status"} collector = RSMP::CommandResponseCollector.new(proxy, [want], task: task, timeout: timeout) collect_task = task.async do @@ -193,7 +193,7 @@ def build_command_reponse command_list it 'can cancel' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = RSMP::CommandResponseCollector.new(proxy, want.values, task: task) collect_task = task.async do result = collector.collect do |message, item| @@ -210,7 +210,7 @@ def build_command_reponse command_list it 'can cancel on MessageNotAck' do AsyncRSpec.async do |task| m_id = RSMP::Message.make_m_id - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = RSMP::CommandResponseCollector.new proxy, want.values, m_id: m_id, timeout: timeout collector.start expect(collector.status).to eq(:collecting) diff --git a/spec/message_spec.rb b/spec/message_spec.rb index 6accb71..9b2c7eb 100644 --- a/spec/message_spec.rb +++ b/spec/message_spec.rb @@ -2,9 +2,10 @@ def build json attributes = RSMP::Message.parse_attributes(json) - message = RSMP::Message.build(attributes,json) + core_version = RSMP::Schema.latest_core_version + message = RSMP::Message.build(core_version, attributes, json) message.validate({ - core: RSMP::Schema.latest_core_version, + core: core_version, tlc: RSMP::Schema.latest_version(:tlc) }) unless message.is_a? RSMP::Unknown message @@ -80,6 +81,10 @@ def sxl_version "type" => "Version", }} + it 'builds right type of objects when parsing JSON' do + expect(build(alarm_acknowledged)).to be_instance_of(RSMP::AlarmAcknowledged) + end + it 'builds right type of objects when parsing JSON' do expect(build(version_str)).to be_instance_of(RSMP::Version) expect(build(ack_str)).to be_instance_of(RSMP::MessageAck) @@ -132,23 +137,24 @@ def sxl_version end it 'builds specific message types' do - expect(RSMP::Version.new.type).to eq("Version") - expect(RSMP::MessageAck.new.type).to eq("MessageAck") - expect(RSMP::MessageNotAck.new.type).to eq("MessageNotAck") - expect(RSMP::AggregatedStatus.new.type).to eq("AggregatedStatus") - expect(RSMP::Watchdog.new.type).to eq("Watchdog") - expect(RSMP::Alarm.new.type).to eq("Alarm") - expect(RSMP::CommandRequest.new.type).to eq("CommandRequest") - expect(RSMP::CommandResponse.new.type).to eq("CommandResponse") - expect(RSMP::StatusRequest.new.type).to eq("StatusRequest") - expect(RSMP::StatusResponse.new.type).to eq("StatusResponse") - expect(RSMP::StatusSubscribe.new.type).to eq("StatusSubscribe") - expect(RSMP::StatusUnsubscribe.new.type).to eq("StatusUnsubscribe") - expect(RSMP::StatusUpdate.new.type).to eq("StatusUpdate") - expect(RSMP::Unknown.new.type).to be_nil - expect(RSMP::Malformed.new.type).to be_nil - expect(RSMP::Unknown.new.type).to be_nil - expect(RSMP::Message.new.type).to be_nil + core_version = RSMP::Schema.latest_core_version + expect(RSMP::Version.new(core_version).type).to eq("Version") + expect(RSMP::MessageAck.new(core_version).type).to eq("MessageAck") + expect(RSMP::MessageNotAck.new(core_version).type).to eq("MessageNotAck") + expect(RSMP::AggregatedStatus.new(core_version).type).to eq("AggregatedStatus") + expect(RSMP::Watchdog.new(core_version).type).to eq("Watchdog") + expect(RSMP::Alarm.new(core_version).type).to eq("Alarm") + expect(RSMP::CommandRequest.new(core_version).type).to eq("CommandRequest") + expect(RSMP::CommandResponse.new(core_version).type).to eq("CommandResponse") + expect(RSMP::StatusRequest.new(core_version).type).to eq("StatusRequest") + expect(RSMP::StatusResponse.new(core_version).type).to eq("StatusResponse") + expect(RSMP::StatusSubscribe.new(core_version).type).to eq("StatusSubscribe") + expect(RSMP::StatusUnsubscribe.new(core_version).type).to eq("StatusUnsubscribe") + expect(RSMP::StatusUpdate.new(core_version).type).to eq("StatusUpdate") + expect(RSMP::Unknown.new(core_version).type).to be_nil + expect(RSMP::Malformed.new(core_version).type).to be_nil + expect(RSMP::Unknown.new(core_version).type).to be_nil + expect(RSMP::Message.new(core_version).type).to be_nil end it 'generates json' do diff --git a/spec/status_collector_spec.rb b/spec/status_collector_spec.rb index b32bbce..434c6d9 100644 --- a/spec/status_collector_spec.rb +++ b/spec/status_collector_spec.rb @@ -39,7 +39,7 @@ def build_status_message status_list it 'completes with a single status update' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = StatusCollector.new(proxy, want.values, timeout: timeout) expect(collector.summary).to eq([false,false,false]) expect(collector.done?).to be(false) @@ -53,7 +53,7 @@ def build_status_message status_list it 'completes with sequential status updates' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = StatusCollector.new(proxy, want.values, timeout: timeout) expect(collector.summary).to eq([false,false,false]) expect(collector.done?).to be(false) @@ -75,7 +75,7 @@ def build_status_message status_list it 'marks matchers as not done' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = StatusCollector.new(proxy, want.values, timeout: timeout) expect(collector.done?).to be(false) expect(collector.summary).to eq([false,false,false]) @@ -105,7 +105,7 @@ def build_status_message status_list it 'raises if notified after being complete' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = StatusCollector.new(proxy, want.values, timeout: timeout) collector.start collector.receive build_status_message(ok.values) @@ -116,7 +116,7 @@ def build_status_message status_list it 'extra status updates are ignored' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = StatusCollector.new(proxy, want.values, timeout: timeout) collector.use_task task # proxy should have no receivers initially @@ -148,7 +148,7 @@ def build_status_message status_list describe '#collect with block' do it 'gets message and each item' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = StatusCollector.new(proxy, want.values, task: task, timeout: timeout) collect_task = task.async do messages = [] @@ -173,7 +173,7 @@ def build_status_message status_list it 'can keep or reject items' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) want = {"sCI" => "S0001","n" => "status"} collector = StatusCollector.new(proxy, [want], task: task, timeout: timeout) collect_task = task.async do @@ -196,7 +196,7 @@ def build_status_message status_list it 'can cancel' do AsyncRSpec.async do |task| - proxy = RSMP::SiteProxyStub.new task + proxy = RSMP::SiteProxyStub.new(RSMP::Schema.latest_core_version, task) collector = StatusCollector.new(proxy, want.values, task: task) collect_task = task.async do result = collector.collect do |message, item| diff --git a/spec/support/site_proxy_stub.rb b/spec/support/site_proxy_stub.rb index 6275259..ca81626 100644 --- a/spec/support/site_proxy_stub.rb +++ b/spec/support/site_proxy_stub.rb @@ -2,10 +2,11 @@ module RSMP class SiteProxyStub include RSMP::Distributor include RSMP::Logging - attr_reader :task + attr_reader :task, :core_version - def initialize task + def initialize core_version, task @task = task + @core_version = core_version initialize_distributor initialize_logging({log_settings:{'active'=>false}}) end