Sha256: c0be4af7b60b7254175636e84eb9112a4843f77249fe82fde1414a065fe81293

Contents?: true

Size: 1.52 KB

Versions: 14

Compression:

Stored size: 1.52 KB

Contents

require File.join(File.dirname(__FILE__), %w[spec_helper])

describe ZK::MessageQueue do

  before(:each) do
    @zk = ZK.new("localhost:#{ZK_TEST_PORT}", :watcher => :default)
    @zk2 = ZK.new("localhost:#{ZK_TEST_PORT}", :watcher => :default)
    wait_until{ @zk.connected? && @zk2.connected? }
    @queue_name = "_specQueue"
    @consume_queue = @zk.queue(@queue_name)
    @publish_queue = @zk2.queue(@queue_name)
  end

  after(:each) do
    @consume_queue.destroy!
    @zk.close!
    @zk2.close!
    wait_until{ !@zk.connected? && !@zk2.connected? }
  end

  it "should be able to receive a published message" do
    message_received = false
    @consume_queue.subscribe do |title, data|
      data.should == 'mydata'
      message_received = true
    end
    @publish_queue.publish("mydata")
    wait_until {message_received }
    message_received.should be_true
  end

  it "should be able to receive a custom message title" do
    message_title = false
    @consume_queue.subscribe do |title, data|
      title.should == 'title'
      message_title = true
    end
    @publish_queue.publish("data", "title")
    wait_until { message_title }
    message_title.should be_true
  end

  it "should work even after processing a message from before" do
    @publish_queue.publish("data1", "title")
    message_times = 0
    @consume_queue.subscribe do |title, data|
      title.should == "title"
      message_times += 1
    end

    @publish_queue.publish("data2", "title")
    wait_until { message_times == 2 }
    message_times.should == 2
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
zk-0.9.1 spec/message_queue_spec.rb
zk-0.9.0 spec/message_queue_spec.rb
zk-0.8.9 spec/message_queue_spec.rb
zk-0.8.8 spec/message_queue_spec.rb
zk-0.8.7 spec/message_queue_spec.rb
zk-0.8.6 spec/message_queue_spec.rb
zk-0.8.5 spec/message_queue_spec.rb
zk-0.8.4 spec/message_queue_spec.rb
zk-0.8.3 spec/message_queue_spec.rb
zk-0.8.2 spec/message_queue_spec.rb
zk-0.8.1 spec/message_queue_spec.rb
zk-0.7.1 spec/message_queue_spec.rb
zk-0.6.5 spec/message_queue_spec.rb
zk-0.6.4 spec/message_queue_spec.rb