Permalink
Browse files

a Publisher can publish

  • Loading branch information...
1 parent 57e9da8 commit 72f71e0d5bd735538dfe5c08d8629bef1ba68f29 @gorsuch gorsuch committed Aug 28, 2012
Showing with 15 additions and 1 deletion.
  1. +4 −0 lib/backstop/publisher.rb
  2. +11 −1 spec/backstop/publisher_spec.rb
View
4 lib/backstop/publisher.rb
@@ -6,5 +6,9 @@ def initialize(urls)
@connections = []
@connections = urls.map { |u| URI.parse(u) }.map { |u| TCPSocket.new(u.host, u.port) }
end
+
+ def publish(name, value, time)
+ connections.sample.puts("#{name} #{value} #{time}")
+ end
end
end
View
12 spec/backstop/publisher_spec.rb
@@ -1,11 +1,21 @@
require 'spec_helper'
describe Backstop::Publisher do
- it "should initialize with an array of urls" do
+ it 'should initialize with an array of urls' do
urls = ['tcp://10.0.0.1:5000', 'tcp://10.0.0.1:5001']
TCPSocket.should_receive(:new).with('10.0.0.1', 5000)
TCPSocket.should_receive(:new).with('10.0.0.1', 5001)
b = Backstop::Publisher.new(urls)
b.connections.count.should eq 2
end
+
+ it 'should publish data' do
+ urls = ['tcp://10.0.0.1:5000']
+ socket_double = double('TCPSocket')
+ TCPSocket.should_receive(:new).with('10.0.0.1', 5000) { socket_double }
+ b = Backstop::Publisher.new(urls)
+
+ socket_double.should_receive(:puts).with("foo 1 1")
+ b.publish('foo', 1, 1)
+ end
end

0 comments on commit 72f71e0

Please sign in to comment.