spec/unit/chunker_spec.rb in lhm-1.0.0.rc2 vs spec/unit/chunker_spec.rb in lhm-1.0.0.rc3
- old
+ new
@@ -1,9 +1,7 @@
-#
-# Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
-# Schmidt
-#
+# Copyright (c) 2011, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
+# Schmidt
require File.expand_path(File.dirname(__FILE__)) + '/unit_helper'
require 'lhm/table'
require 'lhm/migration'
@@ -14,11 +12,11 @@
before(:each) do
@origin = Lhm::Table.new("origin")
@destination = Lhm::Table.new("destination")
@migration = Lhm::Migration.new(@origin, @destination)
- @chunker = Lhm::Chunker.new(@migration, 1, nil, { :stride => 100_000 })
+ @chunker = Lhm::Chunker.new(@migration, nil, { :start => 1, :limit => 10 })
end
describe "copy into" do
before(:each) do
@origin.columns["secret"] = { :metadata => "VARCHAR(255)"}
@@ -32,48 +30,82 @@
"where `id` between 1 and 100"
)
end
end
+ describe "invalid" do
+ before do
+ @chunker = Lhm::Chunker.new(@migration, nil, { :start => 0, :limit => -1 })
+ end
+
+ it "should have zero chunks" do
+ @chunker.traversable_chunks_size.must_equal 0
+ end
+
+ it "should not iterate" do
+ @chunker.up_to do |bottom, top|
+ raise "should not iterate"
+ end
+ end
+ end
+
describe "one" do
+ before do
+ @chunker = Lhm::Chunker.new(@migration, nil, {
+ :stride => 100_000, :start => 1, :limit => 300_000
+ })
+ end
+
it "should have one chunk" do
- @chunker.traversable_chunks_up_to(100).must_equal 1
+ @chunker.traversable_chunks_size.must_equal 3
end
it "should lower bound chunk on 1" do
@chunker.bottom(chunk = 1).must_equal 1
end
it "should upper bound chunk on 100" do
- @chunker.top(chunk = 1, limit = 100).must_equal 100
+ @chunker.top(chunk = 1).must_equal 100_000
end
end
describe "two" do
+ before do
+ @chunker = Lhm::Chunker.new(@migration, nil, {
+ :stride => 100_000, :start => 2, :limit => 150_000
+ })
+ end
+
it "should have two chunks" do
- @chunker.traversable_chunks_up_to(150_000).must_equal 2
+ @chunker.traversable_chunks_size.must_equal 2
end
it "should lower bound second chunk on 100_000" do
- @chunker.bottom(chunk = 2).must_equal 100_001
+ @chunker.bottom(chunk = 2).must_equal 100_002
end
it "should upper bound second chunk on 150_000" do
- @chunker.top(chunk = 2, limit = 150_000).must_equal 150_000
+ @chunker.top(chunk = 2).must_equal 150_000
end
end
describe "iterating" do
- it "should iterate" do
- @chunker = Lhm::Chunker.new(@migration, nil, nil, {
- :stride => 150,
- :throttle => 0
+ before do
+ @chunker = Lhm::Chunker.new(@migration, nil, {
+ :stride => 100, :start => 53, :limit => 121
})
+ end
- @chunker.up_to(limit = 100) do |bottom, top|
- bottom.must_equal 1
- top.must_equal 100
+ it "should iterate" do
+ @chunker.up_to do |bottom, top|
+ bottom.must_equal 53
+ top.must_equal 121
end
end
end
-end
+ describe "throttling" do
+ it "should default to 100 milliseconds" do
+ @chunker.throttle_seconds.must_equal 0.1
+ end
+ end
+end