spec/integration/lhm_spec.rb in lhm-1.0.0.rc2 vs spec/integration/lhm_spec.rb in lhm-1.0.0.rc3
- old
+ new
@@ -1,87 +1,108 @@
-#
-# 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__)) + '/integration_helper'
require 'lhm'
describe Lhm do
include IntegrationHelper
- include Lhm
- before(:each) { connect! }
+ before(:each) { connect_master! }
describe "changes" do
before(:each) do
table_create(:users)
end
it "should add a column" do
- hadron_change_table("users") do |t|
+ Lhm.change_table(:users) do |t|
t.add_column(:logins, "INT(12) DEFAULT '0'")
end
- table_read("users").columns["logins"].must_equal({
- :type => "int(12)",
- :metadata => "DEFAULT '0'"
- })
+ slave do
+ table_read(:users).columns["logins"].must_equal({
+ :type => "int(12)",
+ :metadata => "DEFAULT '0'"
+ })
+ end
end
it "should copy all rows" do
23.times { |n| execute("insert into users set reference = '#{ n }'") }
- hadron_change_table("users") do |t|
+ Lhm.change_table(:users) do |t|
t.add_column(:logins, "INT(12) DEFAULT '0'")
end
- count_all("users").must_equal(23)
+ slave do
+ count_all(:users).must_equal(23)
+ end
end
it "should remove a column" do
- hadron_change_table("users") do |t|
+ Lhm.change_table(:users) do |t|
t.remove_column(:comment)
end
- table_read("users").columns["comment"].must_equal nil
+ slave do
+ table_read(:users).columns["comment"].must_equal nil
+ end
end
it "should add an index" do
- hadron_change_table("users") do |t|
+ Lhm.change_table(:users) do |t|
t.add_index([:comment, :created_at])
end
- key?(table_read("users"), ["comment", "created_at"]).must_equal(true)
+ slave do
+ key?(:users, [:comment, :created_at]).must_equal(true)
+ end
end
+ it "should add an index on a column with a reserved name" do
+ Lhm.change_table(:users) do |t|
+ t.add_index(:group)
+ end
+
+ slave do
+ key?(:users, :group).must_equal(true)
+ end
+ end
+
it "should add a unqiue index" do
- hadron_change_table("users") do |t|
+ Lhm.change_table(:users) do |t|
t.add_unique_index(:comment)
end
- key?(table_read(:users), :comment, :unique).must_equal(true)
+ slave do
+ key?(:users, :comment, :unique).must_equal(true)
+ end
end
it "should remove an index" do
- hadron_change_table("users") do |t|
+ Lhm.change_table(:users) do |t|
t.remove_index([:username, :created_at])
end
- key?(table_read("users"), ["username", "created_at"]).must_equal(false)
+ slave do
+ key?(:users, [:username, :created_at]).must_equal(false)
+ end
end
it "should apply a ddl statement" do
- hadron_change_table("users") do |t|
+ Lhm.change_table(:users) do |t|
t.ddl("alter table %s add column flag tinyint(1)" % t.name)
end
- table_read("users").columns["flag"].must_equal({
- :type => "tinyint(1)",
- :metadata => "DEFAULT NULL"
- })
+ slave do
+ table_read(:users).columns["flag"].must_equal({
+ :type => "tinyint(1)",
+ :metadata => "DEFAULT NULL"
+ })
+ end
end
describe "parallel" do
it "should perserve inserts during migration" do
50.times { |n| execute("insert into users set reference = '#{ n }'") }
@@ -91,36 +112,39 @@
execute("insert into users set reference = '#{ 100 + n }'")
sleep(0.17)
end
end
- hadron_change_table("users", :stride => 10, :throttle => 97) do |t|
+ Lhm.change_table(:users, :stride => 10, :throttle => 97) do |t|
t.add_column(:parallel, "INT(10) DEFAULT '0'")
end
insert.join
- count_all("users").must_equal(60)
+ slave do
+ count_all(:users).must_equal(60)
+ end
end
- end
- it "should perserve deletes during migration" do
- 50.times { |n| execute("insert into users set reference = '#{ n }'") }
+ it "should perserve deletes during migration" do
+ 50.times { |n| execute("insert into users set reference = '#{ n }'") }
- insert = Thread.new do
- 10.times do |n|
- execute("delete from users where id = '#{ n + 1 }'")
- sleep(0.17)
+ delete = Thread.new do
+ 10.times do |n|
+ execute("delete from users where id = '#{ n + 1 }'")
+ sleep(0.17)
+ end
end
- end
- hadron_change_table("users", :stride => 10, :throttle => 97) do |t|
- t.add_column(:parallel, "INT(10) DEFAULT '0'")
- end
+ Lhm.change_table(:users, :stride => 10, :throttle => 97) do |t|
+ t.add_column(:parallel, "INT(10) DEFAULT '0'")
+ end
- insert.join
+ delete.join
- count_all("users").must_equal(40)
+ slave do
+ count_all(:users).must_equal(40)
+ end
+ end
end
end
end
-