Agent framework designed for testing ZeroMQ Applications
The agent types correspond to underlying ZMQ Socket type under test
Inside of your project, declare your agents inside of config/zmq_agents.rb
like this:
require 'agent_zmq'
AgentZMQ.define_ZMQ_SUB :my_sub_agent do |a|
a.socket_opts << {ZMQ::SUBSCRIBE=>'com.connamara.BODPosition'}
a.end_point_type=:bind
a.end_point='tcp://*:5556'
end
AgentZMQ.define_ZMQ_PUB :my_pub_agent do |a|
a.end_point_type=:connect
a.end_points=['tcp://127.0.0.1:5558', 'tcp://127.0.0.1:5559']
end
AgentZMQ.define_ZMQ_REQ :my_req_agent do |a|
a.end_point_type=:connect
a.end_point='tcp://127.0.0.1:5552'
end
AgentZMQ.define_ZMQ_REP :my_rep_agent do |a|
a.reply = Proc.new {|msg| "ok"}
a.end_point_type=:bind
a.end_point='tcp://*:5552'
end
require 'agent_zmq'
AgentZMQ.start
at_exit { AgentZMQ.stop }
You may want to reset the agent states between tests without stopping and starting. This may be done with AgentZMQ.reset
Grab the agent by the name given in the config file
my_agent = AgentZMQ.agents_hash[:my_sub_agent]
This agent provides a message cache
all_messages_received = my_sub_agent.messages_received
# returns and removes the last message received from the cache
last_message_received = my_sub_agent.pop
On reset
, the sub agent cache is cleared
The publish
method takes a single message of one or more parts
my_pub_agent.publish "single part message"
my_pub_agent.publish ["part 1", "part 2"]
The publish
method takes a single message of one or more parts. The agent blocks until a response is received and returned as an array of message parts
response = my_req_agent.publish "single part message"
response = my_pub_agent.publish ["part 1", "part 2"]
Like the ZMQ_SUB agent, ZMQ_REP provides a message cache
all_messages_received = my_rep_agent.messages_received
# returns and removes the last message received from the cache
last_message_received = my_rep_agent.pop
When receiving requests, the agent will reply with the output of the reply
Proc. The return value of this proc may be in the form of a multi-part message.
There is some support for cucumber. See features for example usage.
Once a message is captured, you may want to parse and inspect it some way. The message serialization technique is specific to the system being tested. Some common serialization methods include JSON and Protocol Buffers. json_spec and protobuf_spec are two examples of testing libraries that can be easily paired with agent_zmq for complete testing.
Check out specs and features to see all the ways you can use agent_zmq.
gem install agent_zmq
or add the following to Gemfile:
gem 'agent_zmq'
and run bundle install
from your shell.
Please see the contribution guidelines.
Contributers:
agent_zmq is maintained and funded by Connamara Systems, llc.
The names and logos for Connamara Systems are trademarks of Connamara Systems, llc.
agent_zmq is Copyright © 2016 Connamara Systems, llc.
This software is available under the GPL and a commercial license. Please see the LICENSE file for the terms specified by the GPL license. The commercial license offers more flexible licensing terms compared to the GPL, and includes support services. Contact us for more information on the Connamara commercial license, what it enables, and how you can start developing with it.