-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
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 @@ | ||
Autotest.add_discovery { 'rspec2' } |
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 |
---|---|---|
@@ -1,3 +1,66 @@ | ||
module Zdevice | ||
# Your code goes here... | ||
require 'ffi-rzmq' | ||
|
||
module ZMQ | ||
module Device | ||
|
||
class Builder | ||
def initialize(conf = {}) | ||
@context = Context.new(conf.delete(:context)) | ||
@devices = {} | ||
|
||
conf.each do |name, c| | ||
p [name, c] | ||
@devices[name] = Device.new(name, c) | ||
end | ||
end | ||
|
||
def method_missing(method, *args, &blk) | ||
if d = @devices[method] | ||
return d | ||
end | ||
|
||
super | ||
end | ||
end | ||
|
||
class Context | ||
attr_reader :iothreads, :verbose | ||
def initialize(conf = {}) | ||
@iothreads = conf[:iothreads] || 1 | ||
@verbose = conf[:verbose] || false | ||
|
||
@ctx = ZMQ::Context.new(@iothreads) | ||
end | ||
end | ||
|
||
class Device | ||
attr_reader :name, :type | ||
def initialize(name, conf = {}) | ||
raise 'invalid name' if name == 'context' | ||
raise 'missing type' if !conf.key? :type | ||
|
||
@name = name | ||
@type = conf.delete(:type) | ||
# TODO: open sockets... | ||
end | ||
end | ||
|
||
class ZSocket | ||
attr_reader :name, :type | ||
def initialize(name, conf = {}) | ||
raise 'invalid name' if name == 'type' | ||
raise 'missing type' if !conf.key? :type | ||
|
||
# [:type, :bind, :connect, :option].each do |var| | ||
# raise "missing #{var}" if !conf.key? var | ||
# end | ||
|
||
@name = name | ||
@type = conf.delete(:type) | ||
|
||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
require 'lib/zdevice' | ||
|
||
include ZMQ::Device | ||
describe ZMQ::Device do | ||
|
||
context Builder do | ||
it "should assemble a ZMQ Device" do | ||
b = Builder.new( | ||
context: { iothreads: 5}, | ||
main: { | ||
type: :queue, | ||
frontend: { type: :SUB, option: { hwm: 1, swap: 25}, bind: "tcp://127.0.0.1:5555" }, | ||
backend: { bind: "tcp://eth0:5556" } | ||
} | ||
) | ||
|
||
b.main.class.should == Device | ||
b.main.type.should == :queue | ||
|
||
end | ||
end | ||
|
||
context Context do | ||
it "should accept optional iothread count" do | ||
c = Context.new(iothreads: 5) | ||
c.iothreads.should == 5 | ||
end | ||
|
||
it "should accept optional verbose flag" do | ||
c = Context.new(verbose: true) | ||
c.verbose.should be_true | ||
end | ||
end | ||
|
||
context Device do | ||
it "should validate type" do | ||
lambda { Device.new('context') }.should raise_error | ||
end | ||
|
||
it "should validate name" do | ||
lambda { Device.new('context', type: :a) }.should raise_error | ||
d = Device.new('valid', type: :a) | ||
d.name.should == 'valid' | ||
end | ||
end | ||
|
||
context ZSocket do | ||
it "should have any name except 'type'" do | ||
lambda { ZSocket.new('type') }.should raise_error('invalid name') | ||
|
||
s = ZSocket.new('valid', type: :queue) | ||
s.name.should == 'valid' | ||
end | ||
|
||
it "should have a type" do | ||
s = ZSocket.new('valid', type: :queue) | ||
s.type.should == :queue | ||
end | ||
|
||
# it "should have zero or more endpoints to bind the socket to" | ||
# it "should have zero or more endpoints to connect the socket to" | ||
# it "should have socket options" | ||
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