Sha256: 0f90e11ea2427f43081d9e85d17116fd8c34b618a3b7e9c6d13c3566791040df

Contents?: true

Size: 1.14 KB

Versions: 18

Compression:

Stored size: 1.14 KB

Contents

require 'spec_helper'

describe Chicago::ETL::Counter do
  it "returns the next available key" do
    key = described_class.new(3)
    key.next.should == 4
    key.next.should == 5
  end

  it "can have the initial key set via a block" do
    counter = described_class.new { 1 + 1 }
    counter.next.should == 3
  end

  it "defaults the counter to 0 if the block returns nil" do
    counter = described_class.new { nil }
    counter.next.should == 1
  end

  it "prefers the block to the argument for setting initial state" do
    counter = described_class.new(5) { 2 }
    counter.next.should == 3
  end

  it "can be constructed with no argument, implying 0" do
    described_class.new.next.should == 1
  end

  it "updates keys in a thread-safe fashion" do
    key = described_class.new

    # These seem to need to be a fairly large number of times to see
    # errors
    [Thread.new { 100_000.times {|i| key.next } },
     Thread.new { 100_000.times {|i| key.next } },
     Thread.new { 100_000.times {|i| key.next } }].each(&:join)

    key.next.should == 300_001
  end

  it "has a current value" do
    described_class.new.current.should == 0
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
chicago-etl-0.3.0 spec/etl/counter_spec.rb
chicago-etl-0.2.7 spec/etl/counter_spec.rb
chicago-etl-0.2.5 spec/etl/counter_spec.rb
chicago-etl-0.2.4 spec/etl/counter_spec.rb
chicago-etl-0.2.3 spec/etl/counter_spec.rb
chicago-etl-0.2.2 spec/etl/counter_spec.rb
chicago-etl-0.2.1 spec/etl/counter_spec.rb
chicago-etl-0.2.0 spec/etl/counter_spec.rb
chicago-etl-0.1.4 spec/etl/counter_spec.rb
chicago-etl-0.1.3 spec/etl/counter_spec.rb
chicago-etl-0.1.2 spec/etl/counter_spec.rb
chicago-etl-0.1.1 spec/etl/counter_spec.rb
chicago-etl-0.1.0 spec/etl/counter_spec.rb
chicago-etl-0.0.13 spec/etl/counter_spec.rb
chicago-etl-0.0.12 spec/etl/counter_spec.rb
chicago-etl-0.0.11 spec/etl/counter_spec.rb
chicago-etl-0.0.10 spec/etl/counter_spec.rb
chicago-etl-0.0.9 spec/etl/counter_spec.rb