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
1 parent
03c14f0
commit 6794b34
Showing
3 changed files
with
120 additions
and
120 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 |
---|---|---|
@@ -1,91 +1,91 @@ | ||
require File.expand_path('../../spec_helper', __FILE__) | ||
|
||
describe Cloudist::Message do | ||
before(:each) do | ||
stub_amqp! | ||
@queue = Cloudist::Queue.new("test.queue") | ||
@queue.stubs(:publish) | ||
@headers = {} | ||
end | ||
it "should have a unique id when new" do | ||
msg = Cloudist::Message.new({:hello => "world"}, @headers) | ||
msg.id.size.should == "57b474f0-496c-012e-6f57-34159e11a916".size | ||
end | ||
it "should not update id when existing message" do | ||
msg = Cloudist::Message.new({:hello => "world"}, {:id => "not-an-id"}) | ||
msg.update_headers | ||
msg.id.should == "not-an-id" | ||
end | ||
it "should remove id from headers and update with message_id" do | ||
msg = Cloudist::Message.new({:hello => "world"}, {:id => "not-an-id"}) | ||
msg.update_headers | ||
msg.id.should == "not-an-id" | ||
msg.headers.id.should == nil | ||
msg = Cloudist::Message.new({:hello => "world"}, {:message_id => "not-an-id"}) | ||
msg.update_headers | ||
msg.id.should == "not-an-id" | ||
msg.headers.id.should == nil | ||
end | ||
it "should update headers" do | ||
msg = Cloudist::Message.new({:hello => "world"}, {:id => "not-an-id"}) | ||
msg.update_headers | ||
msg.headers.keys.should include *["ttl", "timestamp", "message_id"] | ||
end | ||
it "should allow custom header when updating" do | ||
msg = Cloudist::Message.new({:hello => "world"}, {:id => "not-an-id"}) | ||
msg.update_headers(:message_type => "reply") | ||
msg.headers.keys.should include *["ttl", "timestamp", "message_id", "message_type"] | ||
end | ||
it "should not be published if timestamp is not in headers" do | ||
msg = Cloudist::Message.new({:hello => "world"}, {:id => "not-an-id"}) | ||
msg.published?.should be_false | ||
end | ||
it "should be published if timestamp is in headers" do | ||
msg = Cloudist::Message.new({:hello => "world"}, {:id => "not-an-id"}) | ||
msg.publish(@queue) | ||
msg.published?.should be_true | ||
end | ||
it "should include ttl in headers" do | ||
msg = Cloudist::Message.new({:hello => "world"}) | ||
# msg.publish(@queue) | ||
msg.headers[:ttl].should == "300" | ||
end | ||
it "should get created_at date from header" do | ||
time = Time.now.to_f | ||
msg = Cloudist::Message.new({:hello => "world"}, {:timestamp => time}) | ||
msg.created_at.to_f.should == time | ||
end | ||
it "should set published_at when publishing" do | ||
time = Time.now.to_f | ||
msg = Cloudist::Message.new({:hello => "world"}, {:timestamp => time}) | ||
msg.publish(@queue) | ||
msg.published_at.to_f.should > time | ||
end | ||
it "should have latency" do | ||
time = (Time.now).to_f | ||
msg = Cloudist::Message.new({:hello => "world"}, {:timestamp => time}) | ||
sleep(0.1) | ||
msg.publish(@queue) | ||
msg.latency.should be_within(0.001).of(0.1) | ||
end | ||
it "should reply to sender" do | ||
msg = Cloudist::Message.new({:hello => "world"}, {:id => "not-an-id"}) | ||
msg.reply(:success => true) | ||
end | ||
end | ||
# describe Cloudist::Message do | ||
# before(:each) do | ||
# stub_amqp! | ||
# @queue = Cloudist::Queue.new("test.queue") | ||
# @queue.stubs(:publish) | ||
# @headers = {} | ||
# end | ||
# | ||
# it "should have a unique id when new" do | ||
# msg = Cloudist::Message.new({:hello => "world"}, @headers) | ||
# msg.id.size.should == "57b474f0-496c-012e-6f57-34159e11a916".size | ||
# end | ||
# | ||
# it "should not update id when existing message" do | ||
# msg = Cloudist::Message.new({:hello => "world"}, {:id => "not-an-id"}) | ||
# msg.update_headers | ||
# msg.id.should == "not-an-id" | ||
# end | ||
# | ||
# it "should remove id from headers and update with message_id" do | ||
# msg = Cloudist::Message.new({:hello => "world"}, {:id => "not-an-id"}) | ||
# msg.update_headers | ||
# msg.id.should == "not-an-id" | ||
# msg.headers.id.should == nil | ||
# | ||
# msg = Cloudist::Message.new({:hello => "world"}, {:message_id => "not-an-id"}) | ||
# msg.update_headers | ||
# msg.id.should == "not-an-id" | ||
# msg.headers.id.should == nil | ||
# end | ||
# | ||
# it "should update headers" do | ||
# msg = Cloudist::Message.new({:hello => "world"}, {:id => "not-an-id"}) | ||
# msg.update_headers | ||
# | ||
# msg.headers.keys.should include *["ttl", "timestamp", "message_id"] | ||
# end | ||
# | ||
# it "should allow custom header when updating" do | ||
# msg = Cloudist::Message.new({:hello => "world"}, {:id => "not-an-id"}) | ||
# msg.update_headers(:message_type => "reply") | ||
# | ||
# msg.headers.keys.should include *["ttl", "timestamp", "message_id", "message_type"] | ||
# end | ||
# | ||
# it "should not be published if timestamp is not in headers" do | ||
# msg = Cloudist::Message.new({:hello => "world"}, {:id => "not-an-id"}) | ||
# msg.published?.should be_false | ||
# end | ||
# | ||
# it "should be published if timestamp is in headers" do | ||
# msg = Cloudist::Message.new({:hello => "world"}, {:id => "not-an-id"}) | ||
# msg.publish(@queue) | ||
# msg.published?.should be_true | ||
# end | ||
# | ||
# it "should include ttl in headers" do | ||
# msg = Cloudist::Message.new({:hello => "world"}) | ||
# # msg.publish(@queue) | ||
# msg.headers[:ttl].should == "300" | ||
# end | ||
# | ||
# it "should get created_at date from header" do | ||
# time = Time.now.to_f | ||
# msg = Cloudist::Message.new({:hello => "world"}, {:timestamp => time}) | ||
# msg.created_at.to_f.should == time | ||
# end | ||
# | ||
# it "should set published_at when publishing" do | ||
# time = Time.now.to_f | ||
# msg = Cloudist::Message.new({:hello => "world"}, {:timestamp => time}) | ||
# msg.publish(@queue) | ||
# msg.published_at.to_f.should > time | ||
# end | ||
# | ||
# it "should have latency" do | ||
# time = (Time.now).to_f | ||
# msg = Cloudist::Message.new({:hello => "world"}, {:timestamp => time}) | ||
# sleep(0.1) | ||
# msg.publish(@queue) | ||
# msg.latency.should be_within(0.001).of(0.1) | ||
# end | ||
# | ||
# it "should reply to sender" do | ||
# msg = Cloudist::Message.new({:hello => "world"}, {:id => "not-an-id"}) | ||
# msg.reply(:success => true) | ||
# 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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
require File.expand_path('../../spec_helper', __FILE__) | ||
|
||
describe Cloudist::Messaging do | ||
it "should add queue to queues list" do | ||
queue = mock("Cloudist::Queue") | ||
queue.stubs(:name).returns("test.queue") | ||
Cloudist::Messaging.add_queue(queue) | ||
Cloudist::Messaging.active_queues.keys.should include('test.queue') | ||
end | ||
it "should be able to remove queues from list" do | ||
queue = mock("Cloudist::Queue") | ||
queue.stubs(:name).returns("test.queue") | ||
Cloudist::Messaging.add_queue(queue).keys.should == ['test.queue'] | ||
Cloudist::Messaging.remove_queue('test.queue').keys.should == [] | ||
end | ||
end | ||
# describe Cloudist::Messaging do | ||
# | ||
# it "should add queue to queues list" do | ||
# queue = mock("Cloudist::Queue") | ||
# queue.stubs(:name).returns("test.queue") | ||
# Cloudist::Messaging.add_queue(queue) | ||
# Cloudist::Messaging.active_queues.keys.should include('test.queue') | ||
# end | ||
# | ||
# it "should be able to remove queues from list" do | ||
# queue = mock("Cloudist::Queue") | ||
# queue.stubs(:name).returns("test.queue") | ||
# Cloudist::Messaging.add_queue(queue).keys.should == ['test.queue'] | ||
# Cloudist::Messaging.remove_queue('test.queue').keys.should == [] | ||
# 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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
require File.expand_path('../../spec_helper', __FILE__) | ||
|
||
describe Cloudist::Queue do | ||
before(:each) do | ||
stub_amqp! | ||
end | ||
it "should cache new queues" do | ||
q1 = Cloudist::Queue.new("test.queue") | ||
q2 = Cloudist::Queue.new("test.queue") | ||
# q1.cached_queues.should == {} | ||
q1.q.should == q2.q | ||
Cloudist::Queue.cached_queues.should == {} | ||
end | ||
end | ||
# describe Cloudist::Queue do | ||
# before(:each) do | ||
# stub_amqp! | ||
# end | ||
# | ||
# it "should cache new queues" do | ||
# q1 = Cloudist::Queue.new("test.queue") | ||
# q2 = Cloudist::Queue.new("test.queue") | ||
# | ||
# # q1.cached_queues.should == {} | ||
# q1.q.should == q2.q | ||
# Cloudist::Queue.cached_queues.should == {} | ||
# end | ||
# end |