switchman 1.4.2 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/models/switchman/shard.rb +3 -3
- data/lib/switchman/active_record/connection_handler.rb +2 -2
- data/lib/switchman/database_server.rb +11 -7
- data/lib/switchman/default_shard.rb +1 -1
- data/lib/switchman/engine.rb +0 -7
- data/lib/switchman/r_spec_helper.rb +1 -1
- data/lib/switchman/test_helper.rb +2 -2
- data/lib/switchman/version.rb +1 -1
- data/lib/tasks/switchman.rake +12 -6
- data/spec/dummy/config/environments/production.rb +1 -1
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/db/shard_2203.sqlite3 +0 -0
- data/spec/dummy/db/shard_2256.sqlite3 +0 -0
- data/spec/dummy/db/shard_2301.sqlite3 +0 -0
- data/spec/dummy/db/shard_2336.sqlite3 +0 -0
- data/spec/dummy/db/shard_2360.sqlite3 +0 -0
- data/spec/dummy/db/shard_2385.sqlite3 +0 -0
- data/spec/dummy/db/shard_2406.sqlite3 +0 -0
- data/spec/dummy/db/shard_2452.sqlite3 +0 -0
- data/spec/dummy/db/shard_2465.sqlite3 +0 -0
- data/spec/dummy/db/shard_2507.sqlite3 +0 -0
- data/spec/dummy/db/shard_2515.sqlite3 +0 -0
- data/spec/dummy/db/shard_2557.sqlite3 +0 -0
- data/spec/dummy/db/shard_2580.sqlite3 +0 -0
- data/spec/dummy/db/shard_2598.sqlite3 +0 -0
- data/spec/dummy/db/shard_2626.sqlite3 +0 -0
- data/spec/dummy/db/shard_2672.sqlite3 +0 -0
- data/spec/dummy/db/shard_2681.sqlite3 +0 -0
- data/spec/dummy/db/shard_2754.sqlite3 +0 -0
- data/spec/dummy/db/shard_2790.sqlite3 +0 -0
- data/spec/dummy/db/shard_2803.sqlite3 +0 -0
- data/spec/dummy/db/shard_2834.sqlite3 +0 -0
- data/spec/dummy/db/shard_2862.sqlite3 +0 -0
- data/spec/dummy/db/shard_2897.sqlite3 +0 -0
- data/spec/dummy/db/shard_2928.sqlite3 +0 -0
- data/spec/dummy/db/shard_2951.sqlite3 +0 -0
- data/spec/dummy/db/shard_2970.sqlite3 +0 -0
- data/spec/dummy/db/shard_3009.sqlite3 +0 -0
- data/spec/dummy/log/test.log +114198 -0
- data/spec/dummy/tmp/cache/377/540/shard%2F2221 +1 -0
- data/spec/dummy/tmp/cache/379/540/shard%2F3015 +1 -0
- data/spec/dummy/tmp/cache/379/580/shard%2F2403 +1 -0
- data/spec/dummy/tmp/cache/37A/5E0/shard%2F2611 +1 -0
- data/spec/dummy/tmp/cache/37B/5A0/shard%2F2324 +1 -0
- data/spec/dummy/tmp/cache/37C/5D0/shard%2F2343 +1 -0
- data/spec/dummy/tmp/cache/37C/5E0/shard%2F2352 +1 -0
- data/spec/dummy/tmp/cache/37D/5E0/shard%2F2344 +1 -0
- data/spec/dummy/tmp/cache/37D/650/shard%2F2812 +1 -0
- data/spec/dummy/tmp/cache/37D/660/shard%2F2740 +2 -0
- data/spec/dummy/tmp/cache/37E/640/shard%2F2390 +1 -0
- data/spec/dummy/tmp/cache/37F/660/shard%2F2562 +1 -0
- data/spec/dummy/tmp/cache/37F/680/shard%2F2823 +1 -0
- data/spec/dummy/tmp/cache/37F/6B0/shard%2F2931 +1 -0
- data/spec/dummy/tmp/cache/380/630/shard%2F2527 +1 -0
- data/spec/dummy/tmp/cache/380/670/shard%2F2644 +1 -0
- data/spec/dummy/tmp/cache/380/690/shard%2F2824 +1 -0
- data/spec/dummy/tmp/cache/380/6E0/shard%2F2950 +1 -0
- data/spec/dummy/tmp/cache/382/640/shard%2F2277 +1 -0
- data/spec/dummy/tmp/cache/382/650/shard%2F2448 +1 -0
- data/spec/dummy/tmp/cache/382/660/shard%2F2295 +1 -0
- data/spec/dummy/tmp/cache/382/6F0/shard%2F2781 +1 -0
- data/spec/dummy/tmp/cache/382/700/shard%2F2871 +1 -0
- data/spec/dummy/tmp/cache/383/6B0/shard%2F2494 +1 -0
- data/spec/dummy/tmp/cache/383/6B0/shard%2F2575 +2 -0
- data/spec/dummy/tmp/cache/383/6F0/shard%2F2935 +1 -0
- data/spec/dummy/tmp/cache/384/700/shard%2F2693 +1 -0
- data/spec/dummy/tmp/cache/384/700/shard%2F2936 +1 -0
- data/spec/dummy/tmp/cache/385/6D0/shard%2F2739 +2 -0
- data/spec/dummy/tmp/cache/385/6E0/shard%2F2586 +1 -0
- data/spec/dummy/tmp/cache/385/760/shard%2F2982 +1 -0
- data/spec/dummy/tmp/cache/386/6C0/shard%2F2479 +1 -0
- data/spec/dummy/tmp/cache/386/710/shard%2F2767 +2 -0
- data/spec/dummy/tmp/cache/386/710/shard%2F2848 +1 -0
- data/spec/dummy/tmp/cache/387/700/shard%2F2669 +1 -0
- data/spec/dummy/tmp/cache/387/710/shard%2F2759 +1 -0
- data/spec/dummy/tmp/cache/388/770/shard%2F2886 +1 -0
- data/spec/dummy/tmp/cache/3A4/F20/shard%2F13000 +1 -0
- data/spec/dummy/tmp/cache/3A6/F50/shard%2F12201 +1 -0
- data/spec/dummy/tmp/cache/3A7/FA0/shard%2F12400 +1 -0
- data/spec/dummy/tmp/cache/3AA/FC0/shard%2F12313 +1 -0
- data/spec/dummy/tmp/cache/3AB/010/shard%2F12512 +1 -0
- data/spec/dummy/tmp/cache/3AD/010/shard%2F12253 +1 -0
- data/spec/dummy/tmp/cache/3AE/030/shard%2F12344 +1 -0
- data/spec/dummy/tmp/cache/3AE/0B0/shard%2F12740 +1 -0
- data/spec/dummy/tmp/cache/3AF/070/shard%2F12372 +1 -0
- data/spec/dummy/tmp/cache/3AF/080/shard%2F12624 +1 -0
- data/spec/dummy/tmp/cache/3B0/060/shard%2F12436 +1 -0
- data/spec/dummy/tmp/cache/3B0/0C0/shard%2F12652 +1 -0
- data/spec/dummy/tmp/cache/3B1/090/shard%2F12293 +1 -0
- data/spec/dummy/tmp/cache/3B1/0E0/shard%2F12824 +1 -0
- data/spec/dummy/tmp/cache/3B1/100/shard%2F12680 +1 -0
- data/spec/dummy/tmp/cache/3B2/0A0/shard%2F12456 +1 -0
- data/spec/dummy/tmp/cache/3B2/120/shard%2F12852 +1 -0
- data/spec/dummy/tmp/cache/3B3/0E0/shard%2F12484 +1 -0
- data/spec/dummy/tmp/cache/3B3/160/shard%2F12880 +1 -0
- data/spec/dummy/tmp/cache/3B4/0D0/shard%2F12548 +1 -0
- data/spec/dummy/tmp/cache/3B4/110/shard%2F12908 +1 -0
- data/spec/dummy/tmp/cache/3B5/110/shard%2F12576 +1 -0
- data/spec/dummy/tmp/cache/3B5/150/shard%2F12936 +1 -0
- data/spec/dummy/tmp/cache/3B6/190/shard%2F12964 +1 -0
- data/spec/dummy/tmp/cache/3B7/150/shard%2F12596 +1 -0
- data/spec/dummy/tmp/cache/3B8/170/shard%2F12768 +1 -0
- data/spec/dummy/tmp/cache/3B9/1B0/shard%2F12796 +1 -0
- data/spec/lib/active_record/connection_pool_spec.rb +5 -5
- data/spec/lib/active_record/postgresql_adapter_spec.rb +1 -0
- data/spec/lib/connection_pool_proxy_spec.rb +1 -1
- data/spec/lib/database_server_spec.rb +14 -14
- data/spec/lib/rails_spec.rb +1 -1
- data/spec/lib/rake_spec.rb +9 -1
- data/spec/lib/shackles_spec.rb +2 -2
- data/spec/models/shard_spec.rb +10 -10
- data/spec/spec_helper.rb +1 -1
- metadata +184 -2
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454952281.847283:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954252.107578:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953751.124701:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953911.634756:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953567.7266428:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value{ I"id:ETi' I" name;TI"switchman_test_shard_2343;TI"database_server_id;TI" test;TI"default;TF:@created_atf1454953700.1946151:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953697.943316:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value{ I"id:ETi( I" name;TI"switchman_test_shard_2344;TI"database_server_id;TI"1;TI"default;TF:@created_atf1454953700.1967208:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954185.702271:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953718.354923:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953894.35137:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value{ I"id:ETiI" name;TI"switchman_test_shard_2823;TI"database_server_id;TI" test;TI"default;TF:@created_atf1454954195.612056:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954223.821203:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953883.913304:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953923.02127:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value{ I"id:ETiI" name;TI"switchman_test_shard_2824;TI"database_server_id;TI"1;TI"default;TF:@created_atf1454954195.6708689:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954231.403268:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953221.727403:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953852.345695:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953421.8768268:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954174.635145:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954203.967125:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953875.538141:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value{ I"id:ETiwI" name;TI"switchman_test_shard_2935;TI"database_server_id;TI" test;TI"default;TF:@created_atf1454954233.520403:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953942.2424982:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value{ I"id:ETixI" name;TI"switchman_test_shard_2936;TI"database_server_id;TI"1;TI"default;TF:@created_atf1454954233.5221171:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953902.985973:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954241.1974971:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953865.986658:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954194.7953842:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953931.866626:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954138.313615:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954212.902188:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954252.136723:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454952281.399483:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953750.627025:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953567.388341:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953883.9622452:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953221.654282:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953697.991678:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954138.386438:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953718.218687:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953923.291151:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953852.630045:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953931.9088142:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953421.781354:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954194.927814:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953942.115639:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953865.844864:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954203.671841:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953875.5033212:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954212.824377:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953894.449315:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954223.9249978:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953902.886399:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954230.9272928:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954240.867776:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454953911.156364:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954174.670942:@expires_in0
|
@@ -0,0 +1 @@
|
|
1
|
+
o: ActiveSupport::Cache::Entry:@value:nil:@created_atf1454954185.3990772:@expires_in0
|
@@ -6,23 +6,23 @@ module Switchman
|
|
6
6
|
it "should be able to access another shard on a db server after the 'primary' shard is gone" do
|
7
7
|
skip 'A "real" database"' unless Shard.default.database_server.shareable?
|
8
8
|
# separate connections
|
9
|
-
server = DatabaseServer.create(
|
9
|
+
server = DatabaseServer.create(Shard.default.database_server.config)
|
10
10
|
s1 = server.shards.create!(:name => 'non_existent_shard') # don't actually create any schema
|
11
11
|
s2 = server.shards.create! # inherit's the default shard's config, which is functional
|
12
12
|
s1.activate do
|
13
|
-
expect { User.count }.to
|
13
|
+
expect { User.count }.to raise_error(::ActiveRecord::StatementInvalid)
|
14
14
|
end
|
15
15
|
# the config for s1 should not be the permanent default for all new
|
16
16
|
# connections now
|
17
17
|
s2.activate do
|
18
|
-
expect { User.count }.not_to
|
18
|
+
expect { User.count }.not_to raise_error
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
describe "clear_idle_connections!" do
|
23
23
|
before do
|
24
24
|
skip 'A "real" database"' unless Shard.default.database_server.shareable?
|
25
|
-
@server = DatabaseServer.create(
|
25
|
+
@server = DatabaseServer.create(Shard.default.database_server.config)
|
26
26
|
@shard = @server.shards.create!
|
27
27
|
@conn, @pool = @shard.activate{ [User.connection, User.connection_pool.current_pool] }
|
28
28
|
end
|
@@ -56,7 +56,7 @@ module Switchman
|
|
56
56
|
describe "release_connection" do
|
57
57
|
before do
|
58
58
|
skip 'A "real" database"' unless Shard.default.database_server.shareable?
|
59
|
-
@server = DatabaseServer.create(
|
59
|
+
@server = DatabaseServer.create(Shard.default.database_server.config)
|
60
60
|
@shard = @server.shards.create!
|
61
61
|
@pool = @shard.activate{ User.connection_pool.current_pool }
|
62
62
|
@timeout_was = @pool.spec.config[:idle_timeout]
|
@@ -30,6 +30,7 @@ module Switchman
|
|
30
30
|
shard.stubs(:name).returns('bob')
|
31
31
|
::ActiveRecord::Base.connection.stubs(:use_qualified_names?).returns(true)
|
32
32
|
::ActiveRecord::Base.connection.stubs(:shard).returns(shard)
|
33
|
+
::ActiveRecord::Base.connection.stubs(:columns).returns([])
|
33
34
|
|
34
35
|
expect(User.joins(:parent).where(id: 1).to_sql).to be_include %{* FROM "bob"."users" INNER JOIN "bob"."users" "parents_users" ON "parents_users"."id" = "users"."parent_id" WHERE "users"."id" = 1}
|
35
36
|
end
|
@@ -5,7 +5,7 @@ module Switchman
|
|
5
5
|
include RSpecHelper
|
6
6
|
|
7
7
|
it "should not share connections for sqlite shards on the same db" do
|
8
|
-
@db = DatabaseServer.create(:
|
8
|
+
@db = DatabaseServer.create(adapter: 'sqlite3', database: ':memory:')
|
9
9
|
@sqlite_shard1 = @db.shards.create!
|
10
10
|
@sqlite_shard2 = @db.shards.create!
|
11
11
|
expect(::ActiveRecord::Base.connection).not_to eq @sqlite_shard2.activate { ::ActiveRecord::Base.connection }
|
@@ -4,36 +4,36 @@ module Switchman
|
|
4
4
|
describe DatabaseServer do
|
5
5
|
describe "shareable?" do
|
6
6
|
it "should be false for sqlite" do
|
7
|
-
db = DatabaseServer.new(
|
7
|
+
db = DatabaseServer.new(nil, adapter: 'sqlite3', database: '%{shard_name}')
|
8
8
|
expect(db.shareable?).to eq false
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should be true for mysql" do
|
12
|
-
db = DatabaseServer.new(
|
12
|
+
db = DatabaseServer.new(nil, adapter: 'mysql')
|
13
13
|
expect(db.shareable?).to eq true
|
14
14
|
|
15
|
-
db = DatabaseServer.new(
|
15
|
+
db = DatabaseServer.new(nil, adapter: 'mysql2')
|
16
16
|
expect(db.shareable?).to eq true
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should be true for postgres with a non-variable username" do
|
20
|
-
db = DatabaseServer.new(
|
20
|
+
db = DatabaseServer.new(nil, adapter: 'postgresql')
|
21
21
|
expect(db.shareable?).to eq true
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should be false for postgres with variable username" do
|
25
|
-
db = DatabaseServer.new(
|
25
|
+
db = DatabaseServer.new(nil, adapter: 'postgresql', username: '%{schema_search_path}')
|
26
26
|
expect(db.shareable?).to eq false
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should depend on the database environment" do
|
30
|
-
db = DatabaseServer.new(
|
30
|
+
db = DatabaseServer.new(nil, adapter: 'postgresql', username: '%{schema_search_path}', deploy: { username: 'deploy' })
|
31
31
|
expect(db.shareable?).to eq false
|
32
32
|
expect(::Shackles.activate(:deploy) { db.shareable? }).to eq true
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should handle string keys" do
|
36
|
-
db = DatabaseServer.new(
|
36
|
+
db = DatabaseServer.new(nil, adapter: 'postgresql', username: '%{schema_search_path}', deploy: { 'username' => 'deploy' })
|
37
37
|
expect(db.shareable?).to eq false
|
38
38
|
expect(::Shackles.activate(:deploy) { db.shareable? }).to eq true
|
39
39
|
end
|
@@ -72,7 +72,7 @@ module Switchman
|
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should be able to create a new sqlite shard from a given server" do
|
75
|
-
db = DatabaseServer.create(:
|
75
|
+
db = DatabaseServer.create(adapter: 'sqlite3', database: '%{shard_name}', shard_name: ':memory:')
|
76
76
|
begin
|
77
77
|
create_shard(db)
|
78
78
|
ensure
|
@@ -93,7 +93,7 @@ module Switchman
|
|
93
93
|
skip 'A "real" database"' unless %w{MySQL Mysql2 PostgreSQL}.include?(adapter)
|
94
94
|
|
95
95
|
# So, it's really the same server, but we want separate connections
|
96
|
-
db = DatabaseServer.create(
|
96
|
+
db = DatabaseServer.create(Shard.default.database_server.config)
|
97
97
|
begin
|
98
98
|
create_shard(db)
|
99
99
|
ensure
|
@@ -103,7 +103,7 @@ module Switchman
|
|
103
103
|
|
104
104
|
class MyException < Exception; end
|
105
105
|
it "should use the connection's db name as temp db name" do
|
106
|
-
db = DatabaseServer.new(
|
106
|
+
db = DatabaseServer.new(nil, adapter: 'postgresql')
|
107
107
|
Shard.expects(:create!).with(:name => Shard.default.name, :database_server => db).raises(MyException.new)
|
108
108
|
expect { db.create_new_shard }.to raise_error(MyException)
|
109
109
|
end
|
@@ -114,7 +114,7 @@ module Switchman
|
|
114
114
|
base_config = { database: 'db',
|
115
115
|
slave: [nil, { database: 'slave' }],
|
116
116
|
deploy: { username: 'deploy' }}
|
117
|
-
ds = DatabaseServer.new(
|
117
|
+
ds = DatabaseServer.new(nil, base_config)
|
118
118
|
expect(ds.config).to eq base_config
|
119
119
|
expect(ds.config(:slave)).to eq [{ database: 'db', deploy: base_config[:deploy] },
|
120
120
|
{ database: 'slave', deploy: base_config[:deploy] }]
|
@@ -195,7 +195,7 @@ module Switchman
|
|
195
195
|
after(:all) do
|
196
196
|
@db1.config[:open] = @old_open
|
197
197
|
@old_servers.each do |db|
|
198
|
-
DatabaseServer.create(
|
198
|
+
DatabaseServer.create(db.config.merge(id: db.id))
|
199
199
|
end
|
200
200
|
end
|
201
201
|
|
@@ -209,7 +209,7 @@ module Switchman
|
|
209
209
|
end
|
210
210
|
|
211
211
|
it "should return another server if it's the only one open" do
|
212
|
-
@db2 = DatabaseServer.create(:
|
212
|
+
@db2 = DatabaseServer.create(open: true)
|
213
213
|
4.times { expect(DatabaseServer.server_for_new_shard).to eq @db2 }
|
214
214
|
@db2.config.delete(:open)
|
215
215
|
@db1.config[:open] = true
|
@@ -217,7 +217,7 @@ module Switchman
|
|
217
217
|
end
|
218
218
|
|
219
219
|
it "should return multiple open servers" do
|
220
|
-
@db2 = DatabaseServer.create(:
|
220
|
+
@db2 = DatabaseServer.create(open: true)
|
221
221
|
@db1.config[:open] = true
|
222
222
|
dbs = []
|
223
223
|
20.times do
|
data/spec/lib/rails_spec.rb
CHANGED
@@ -5,7 +5,7 @@ module Switchman
|
|
5
5
|
it "should automatically isolate cache keys from different shards" do
|
6
6
|
cache = ::ActiveSupport::Cache.lookup_store(:memory_store)
|
7
7
|
::Rails.stubs(:cache).returns(cache)
|
8
|
-
db = DatabaseServer.create(:
|
8
|
+
db = DatabaseServer.create(adapter: 'sqlite3')
|
9
9
|
s1 = db.shards.create!
|
10
10
|
s2 = db.shards.create!
|
11
11
|
|
data/spec/lib/rake_spec.rb
CHANGED
@@ -13,7 +13,7 @@ module Switchman
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def shard_scope(shard_ids)
|
16
|
-
Rake.send(:shard_scope, Shard.all, shard_ids)
|
16
|
+
Rake.send(:shard_scope, Shard.all, shard_ids).order(:id)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should work for default shard" do
|
@@ -88,5 +88,13 @@ module Switchman
|
|
88
88
|
expect(shard_scope("7/7").to_a).to eq []
|
89
89
|
end
|
90
90
|
end
|
91
|
+
|
92
|
+
describe '.scope' do
|
93
|
+
it "supports selecting open servers" do
|
94
|
+
db = DatabaseServer.create(open: true)
|
95
|
+
shard = db.shards.create!
|
96
|
+
expect(Rake.scope(database_server: 'open').to_a).to eq([shard])
|
97
|
+
end
|
98
|
+
end
|
91
99
|
end
|
92
100
|
end
|
data/spec/lib/shackles_spec.rb
CHANGED
@@ -40,7 +40,7 @@ module Switchman
|
|
40
40
|
it "should connect to the first working slave" do
|
41
41
|
# have to unstub long enough to create this
|
42
42
|
::Rails.env.unstub(:test?)
|
43
|
-
ds = DatabaseServer.create(
|
43
|
+
ds = DatabaseServer.create(Shard.default.database_server.config.merge(
|
44
44
|
:slave => [{ host: 'some.postgres.server' }, nil]))
|
45
45
|
::Rails.env.stubs(:test?).returns(false)
|
46
46
|
ds.shackle!
|
@@ -86,7 +86,7 @@ module Switchman
|
|
86
86
|
Shard.default.database_server.shackle!
|
87
87
|
# have to unstub long enough to create this
|
88
88
|
::Rails.env.unstub(:test?)
|
89
|
-
ds = DatabaseServer.create(
|
89
|
+
ds = DatabaseServer.create(adapter: 'postgresql', host: 'notshackled', slave: { host: 'shackled' })
|
90
90
|
::Rails.env.stubs(:test?).returns(false)
|
91
91
|
s = ds.shards.create!
|
92
92
|
s.activate do
|
data/spec/models/shard_spec.rb
CHANGED
@@ -27,7 +27,7 @@ module Switchman
|
|
27
27
|
|
28
28
|
describe ".destroy" do
|
29
29
|
it "works on created shards" do
|
30
|
-
server = DatabaseServer.create(
|
30
|
+
server = DatabaseServer.create(Shard.default.database_server.config)
|
31
31
|
shard = server.create_new_shard
|
32
32
|
expect{ shard.destroy }.to_not raise_error
|
33
33
|
expect(Shard.where(id: shard.id)).to be_empty
|
@@ -35,7 +35,7 @@ module Switchman
|
|
35
35
|
|
36
36
|
it "fails on the default shard" do
|
37
37
|
shard = Shard.default
|
38
|
-
expect{ shard.destroy }.to raise_error
|
38
|
+
expect{ shard.destroy }.to raise_error("Cannot destroy the default shard")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -83,7 +83,7 @@ module Switchman
|
|
83
83
|
describe "#drop_database" do
|
84
84
|
it "should work" do
|
85
85
|
# use a separate connection so we don't commit the transaction
|
86
|
-
server = DatabaseServer.create(
|
86
|
+
server = DatabaseServer.create(Shard.default.database_server.config)
|
87
87
|
shard = server.create_new_shard
|
88
88
|
shard.activate do
|
89
89
|
User.create!
|
@@ -91,12 +91,12 @@ module Switchman
|
|
91
91
|
end
|
92
92
|
shard.drop_database
|
93
93
|
shard.activate do
|
94
|
-
expect { User.count }.to raise_error
|
94
|
+
expect { User.count }.to raise_error(::ActiveRecord::StatementInvalid)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
98
|
it "raises an exception if the shard is the default shard" do
|
99
|
-
expect{ Shard.default.drop_database }.to raise_error
|
99
|
+
expect{ Shard.default.drop_database }.to raise_error("Cannot drop the database of the default shard")
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
@@ -123,7 +123,7 @@ module Switchman
|
|
123
123
|
describe ".with_each_shard" do
|
124
124
|
describe ":exception" do
|
125
125
|
it "should default to :raise" do
|
126
|
-
expect { Shard.with_each_shard { raise "error" } }.to raise_error
|
126
|
+
expect { Shard.with_each_shard { raise "error" } }.to raise_error("error")
|
127
127
|
end
|
128
128
|
|
129
129
|
it "should :ignore" do
|
@@ -132,7 +132,7 @@ module Switchman
|
|
132
132
|
|
133
133
|
it "should :defer" do
|
134
134
|
counter = 0
|
135
|
-
expect { Shard.with_each_shard(exception: :defer) { counter += 1; raise "error" } }.to raise_error
|
135
|
+
expect { Shard.with_each_shard(exception: :defer) { counter += 1; raise "error" } }.to raise_error("error")
|
136
136
|
# called more than once
|
137
137
|
expect(counter).to be > 1
|
138
138
|
end
|
@@ -279,19 +279,19 @@ module Switchman
|
|
279
279
|
end
|
280
280
|
|
281
281
|
it "should fall back to shard_name in the config if nil" do
|
282
|
-
db = DatabaseServer.new(
|
282
|
+
db = DatabaseServer.new(nil, adapter: 'mysql', database: 'canvas', shard_name: 'yoyoyo')
|
283
283
|
shard = Shard.new(database_server: db)
|
284
284
|
expect(shard.name).to eq 'yoyoyo'
|
285
285
|
end
|
286
286
|
|
287
287
|
it "should fall back to the database_server if nil" do
|
288
|
-
db = DatabaseServer.new(
|
288
|
+
db = DatabaseServer.new(nil, adapter: 'mysql', database: 'canvas')
|
289
289
|
shard = Shard.new(database_server: db)
|
290
290
|
expect(shard.name).to eq 'canvas'
|
291
291
|
end
|
292
292
|
|
293
293
|
it "should get it from the postgres connection if not otherwise specified" do
|
294
|
-
db = DatabaseServer.create(
|
294
|
+
db = DatabaseServer.create(adapter: 'postgresql', database: 'notme')
|
295
295
|
shard = Shard.new(database_server: db)
|
296
296
|
shard.database_server = db
|
297
297
|
connection = mock()
|