# # testing the sqs with yaml messages # require 'test/unit' require 'yaml' require 'base64' require 'openwfe/def' require 'openwfe/util/sqs' require 'openwfe/engine/engine' require 'openwfe/listeners/sqslisteners' require 'openwfe/participants/sqsparticipants' class SqsTest < Test::Unit::TestCase #def setup #end #def teardown #end #def xxxx_0 def test_0 hash = { :red => :color, :count => "twelve", "fish" => "sakana", :llen => 4, :list => [ 0, 1, 2, 3, 4, :fizz ] } qs = SQS::QueueService.new qs.create_queue(:yamltest) puts "created queue 'yamltest'" msg = YAML.dump(hash) msg = Base64.encode64(msg) puts "message size is #{msg.size.to_f / 1024.0} K" msg_id = qs.put_message(:yamltest, msg) puts "sent hash as message, msg_id is #{msg_id}" sleep(1) msg = qs.get_message(:yamltest, msg_id) puts "got message back" msg = Base64.decode64(msg.message_body) msg = YAML.load(msg) pp msg assert msg == hash count = qs.flush_queue(:yamltest) puts "flushed #{count} messages from queue 'yamltest'" qs.delete_queue(:yamltest) end class SqsDefinition0 < OpenWFE::ProcessDefinition def make participant :sqs end end #def xxxx_participant_0 def test_participant_0 engine = OpenWFE::Engine.new sqsp = SqsParticipant.new("wiqueue") #class << sqsp # def encode_workitem (wi) # "hello from #{@queue.name} #{wi.fei.workflow_instance_id}" # end #end engine.register_participant(:sqs, sqsp) engine.add_workitem_listener( OpenWFE::SqsListener.new(:wiqueue, engine.application_context), "2s") engine.launch(SqsDefinition0) sleep(5) qs = sqsp.queue_service qs.delete_queue("wiqueue") end end