Sha256: c8bc1ae6fe6a6df22b6b4284fb807a679c085e62c8edd4193192de7079a6c896

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

require 'helper'

describe Agent::Transport::Queue do
  include Agent::Transport

  it "should support synchronous, unbuffered communication" do
    lambda { Queue.new("spec") }.should_not raise_error

    q = Queue.new("spec")
    q.max.should == 1
    q.async?.should be_false

    lambda { q.send("hello") }.should_not raise_error
    lambda { q.send("hello", true) }.should raise_error(ThreadError, "buffer full")

    q.receive.should == "hello"
    lambda { q.receive(true) }.should raise_error(ThreadError, "buffer empty")
  end

  it "should support asynchronous, buffered communication" do
    lambda { Queue.new("spec", 2) }.should_not raise_error

    q = Queue.new("spec", 2)
    q.max.should == 2
    q.async?.should be_true

    lambda { q.send("hello 1") }.should_not raise_error
    lambda { q.send("hello 2", true) }.should_not raise_error(ThreadError, "buffer full")
    lambda { q.send("hello 3", true) }.should raise_error(ThreadError, "buffer full")

    q.receive.should == "hello 1"
    q.receive.should == "hello 2"
    lambda { q.receive(true) }.should raise_error(ThreadError, "buffer empty")
  end

  it "should persist data between queue objects" do
    q = Queue.new("spec")
    q.send "hello"

    q = Queue.new("spec")
    q.receive.should == "hello"
  end

   it "should clear registry on close" do
     q = Queue.new("spec")
     q.send "hello"
     q.close

     q = Queue.new("spec")
     lambda { q.receive(true) }.should raise_error(ThreadError, "buffer empty")
   end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
agent-0.1.0 spec/queue_spec.rb