Sha256: ea8350ef8e0d60b513991462f660fb10c43138c1367f5e96613ee00b0fe16a10

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

require 'spec_helper'

describe FluQ::Buffer::File do

  let(:event) { FluQ::Event.new("some.tag", 1313131313, {}) }

  it           { should be_a(FluQ::Buffer::Base) }
  its(:config) { should == {max_size: 268435456, path: "tmp/buffers"} }
  its(:file)   { should be_instance_of(File) }
  its(:size)   { should == 0 }

  it "should return a name" do
    Time.stub(now: Time.at(1313131313.45678))
    subject.name.should == "file-fb-1313131313457.1"
  end

  it "should generate unique paths" do
    Time.stub(now: Time.at(1313131313.45678))
    subject.file.path.should == FluQ.root.join("tmp/buffers/fb-1313131313457.1").to_s
    described_class.new.file.path.should == FluQ.root.join("tmp/buffers/fb-1313131313457.2").to_s
  end

  it "should write data" do
    data = event.to_msgpack
    100.times { subject.write(data) }
    subject.size.should == 1900
  end

  it "should drain contents" do
    4.times { subject.write(event.to_msgpack) }
    subject.drain do |io|
      io.read.should == ([event.to_msgpack] * 4).join
    end
  end

  it "should prevent writes once buffer is 'drained'" do
    subject.write(event.to_msgpack)
    subject.drain {|*| }
    lambda { subject.write(event.to_msgpack) }.should raise_error(IOError, /closed/)
  end

  it "should close and unlink files" do
    subject.write(event.to_msgpack)
    lambda { subject.close }.should change { File.exists?(subject.file.path) }.to(false)
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fluq-0.7.5 spec/fluq/buffer/file_spec.rb
fluq-0.7.3 spec/fluq/buffer/file_spec.rb
fluq-0.7.1 spec/fluq/buffer/file_spec.rb
fluq-0.7.0 spec/fluq/buffer/file_spec.rb