Skip to content

Commit

Permalink
Merge pull request soundcloud#11 from Shopify/test_for_detroying_sing…
Browse files Browse the repository at this point in the history
…le_row_when_the_id_is_not_1_sc_master

Test for detroying single row when the id is not 1 sc master
  • Loading branch information
Camilo Lopez committed Nov 3, 2015
2 parents 13b0414 + 7f721c0 commit 7d30899
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Lhm.change_table :users, throttler: [:time_throttler, {stride: x}] do
end
```
* #118 - Truncate long trigger names. (@sj26)
* #114 - Update chunker requirements (@bjk-soundcloud)
* #98 - Add slave lag throttler. (@camilo, @jasonhl)
* #92 - Fix check for table requirement before starting a lhm.(@hannestyden)
Expand Down
3 changes: 2 additions & 1 deletion lib/lhm/chunker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def initialize(migration, connection = nil, options = {})
def execute
return unless @start && @limit
@next_to_insert = @start
while @next_to_insert < @limit || (@next_to_insert == 1 && @start == 1)
while @next_to_insert < @limit || (@start == @limit)
stride = @throttler.stride
affected_rows = @connection.update(copy(bottom, top(stride)))

Expand All @@ -37,6 +37,7 @@ def execute

@printer.notify(bottom, @limit)
@next_to_insert = top(stride) + 1
break if @start == @limit
end
@printer.end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/lhm/entangler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def create_delete_trigger
end

def trigger(type)
"lhmt_#{ type }_#{ @origin.name }"
"lhmt_#{ type }_#{ @origin.name }"[0...64]
end

def validate
Expand Down
17 changes: 16 additions & 1 deletion spec/integration/chunker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,22 @@
@migration = Lhm::Migration.new(@origin, @destination)
end

it 'should copy 23 rows from origin to destination with time based throttler' do
it 'should copy 1 rows from origin to destination even if the id of the single row does not start at 1' do
execute("insert into origin set id = 1001 ")
printer = Lhm::Printer::Base.new

def printer.notify(*) ;end
def printer.end(*) [] ;end

Lhm::Chunker.new(@migration, connection, {:throttler => Lhm::Throttler::Time.new(:stride => 100), :printer => printer} ).run

slave do
count_all(@destination.name).must_equal(1)
end

end

it 'should copy 23 rows from origin to destination' do
23.times { |n| execute("insert into origin set id = '#{ n * n + 23 }'") }

printer = MiniTest::Mock.new
Expand Down
15 changes: 15 additions & 0 deletions spec/unit/entangler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@

@entangler.entangle.must_include strip(ddl)
end

describe 'super long table names' do
before(:each) do
@origin = Lhm::Table.new('a' * 64)
@destination = Lhm::Table.new('b' * 64)
@migration = Lhm::Migration.new(@origin, @destination)
@entangler = Lhm::Entangler.new(@migration)
end

it 'should use truncated names' do
@entangler.trigger(:ins).length.must_be :<=, 64
@entangler.trigger(:upd).length.must_be :<=, 64
@entangler.trigger(:del).length.must_be :<=, 64
end
end
end

describe 'removal' do
Expand Down

0 comments on commit 7d30899

Please sign in to comment.