switchman 1.2.10 → 1.2.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/switchman/shard.rb +2 -2
- data/lib/switchman/active_record/connection_handler.rb +18 -9
- data/lib/switchman/active_record/connection_pool.rb +3 -0
- data/lib/switchman/active_record/query_cache.rb +6 -1
- data/lib/switchman/active_record/query_methods.rb +1 -1
- data/lib/switchman/connection_pool_proxy.rb +1 -1
- data/lib/switchman/r_spec_helper.rb +73 -61
- data/lib/switchman/test_helper.rb +8 -2
- data/lib/switchman/version.rb +1 -1
- data/lib/tasks/switchman.rake +5 -0
- data/spec/dummy/config/database.yml +2 -4
- data/spec/dummy/config/environments/development.rb +0 -4
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/db/schema.rb +12 -12
- data/spec/dummy/db/shard_120.sqlite3 +0 -0
- data/spec/dummy/db/shard_156.sqlite3 +0 -0
- data/spec/dummy/db/shard_193.sqlite3 +0 -0
- data/spec/dummy/db/shard_23.sqlite3 +0 -0
- data/spec/dummy/db/shard_234.sqlite3 +0 -0
- data/spec/dummy/db/shard_257.sqlite3 +0 -0
- data/spec/dummy/db/shard_277.sqlite3 +0 -0
- data/spec/dummy/db/shard_311.sqlite3 +0 -0
- data/spec/dummy/db/shard_324.sqlite3 +0 -0
- data/spec/dummy/db/shard_342.sqlite3 +0 -0
- data/spec/dummy/db/shard_375.sqlite3 +0 -0
- data/spec/dummy/db/shard_389.sqlite3 +0 -0
- data/spec/dummy/db/shard_428.sqlite3 +0 -0
- data/spec/dummy/db/shard_452.sqlite3 +0 -0
- data/spec/dummy/db/shard_462.sqlite3 +0 -0
- data/spec/dummy/db/shard_483.sqlite3 +0 -0
- data/spec/dummy/db/shard_508.sqlite3 +0 -0
- data/spec/dummy/db/shard_531.sqlite3 +0 -0
- data/spec/dummy/db/shard_554.sqlite3 +0 -0
- data/spec/dummy/db/shard_577.sqlite3 +0 -0
- data/spec/dummy/db/shard_58.sqlite3 +0 -0
- data/spec/dummy/db/shard_600.sqlite3 +0 -0
- data/spec/dummy/db/shard_623.sqlite3 +0 -0
- data/spec/dummy/db/shard_646.sqlite3 +0 -0
- data/spec/dummy/db/shard_668.sqlite3 +0 -0
- data/spec/dummy/db/shard_680.sqlite3 +0 -0
- data/spec/dummy/db/shard_708.sqlite3 +0 -0
- data/spec/dummy/db/shard_735.sqlite3 +0 -0
- data/spec/dummy/db/shard_753.sqlite3 +0 -0
- data/spec/dummy/db/shard_76.sqlite3 +0 -0
- data/spec/dummy/db/shard_802.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +7 -0
- data/spec/dummy/log/test.log +106293 -0
- data/spec/dummy/tmp/cache/313/970/shard%2F30 +1 -0
- data/spec/dummy/tmp/cache/316/980/shard%2F15 +1 -0
- data/spec/dummy/tmp/cache/317/9D0/shard%2F52 +1 -0
- data/spec/dummy/tmp/cache/31C/A40/shard%2F75 +1 -0
- data/spec/dummy/tmp/cache/345/E00/shard%2F500 +1 -0
- data/spec/dummy/tmp/cache/346/DF0/shard%2F321 +1 -0
- data/spec/dummy/tmp/cache/349/DE0/shard%2F126 +1 -0
- data/spec/dummy/tmp/cache/349/E10/shard%2F153 +0 -0
- data/spec/dummy/tmp/cache/349/E20/shard%2F243 +1 -0
- data/spec/dummy/tmp/cache/34A/E20/shard%2F154 +0 -0
- data/spec/dummy/tmp/cache/34A/E40/shard%2F172 +1 -0
- data/spec/dummy/tmp/cache/34A/E70/shard%2F523 +1 -0
- data/spec/dummy/tmp/cache/34A/EB0/shard%2F721 +1 -0
- data/spec/dummy/tmp/cache/34A/EC0/shard%2F730 +1 -0
- data/spec/dummy/tmp/cache/34B/E40/shard%2F245 +0 -0
- data/spec/dummy/tmp/cache/34B/E60/shard%2F425 +1 -0
- data/spec/dummy/tmp/cache/34B/EC0/shard%2F722 +1 -0
- data/spec/dummy/tmp/cache/34C/E50/shard%2F246 +0 -0
- data/spec/dummy/tmp/cache/34C/E80/shard%2F273 +1 -0
- data/spec/dummy/tmp/cache/34C/E90/shard%2F363 +0 -0
- data/spec/dummy/tmp/cache/34C/E90/shard%2F444 +1 -0
- data/spec/dummy/tmp/cache/34C/EA0/shard%2F615 +1 -0
- data/spec/dummy/tmp/cache/34C/F00/shard%2F750 +1 -0
- data/spec/dummy/tmp/cache/34D/E80/shard%2F265 +1 -0
- data/spec/dummy/tmp/cache/34D/ED0/shard%2F391 +1 -0
- data/spec/dummy/tmp/cache/34D/EE0/shard%2F724 +1 -0
- data/spec/dummy/tmp/cache/34E/ED0/shard%2F383 +1 -0
- data/spec/dummy/tmp/cache/34E/EF0/shard%2F725 +1 -0
- data/spec/dummy/tmp/cache/34E/F00/shard%2F653 +1 -0
- data/spec/dummy/tmp/cache/34F/EE0/shard%2F546 +1 -0
- data/spec/dummy/tmp/cache/34F/F00/shard%2F807 +1 -0
- data/spec/dummy/tmp/cache/34F/F30/shard%2F672 +1 -0
- data/spec/dummy/tmp/cache/350/EA0/shard%2F178 +1 -0
- data/spec/dummy/tmp/cache/350/EB0/shard%2F349 +1 -0
- data/spec/dummy/tmp/cache/350/F00/shard%2F718 +0 -0
- data/spec/dummy/tmp/cache/350/F40/shard%2F592 +1 -0
- data/spec/dummy/tmp/cache/351/F00/shard%2F386 +0 -0
- data/spec/dummy/tmp/cache/351/F10/shard%2F638 +1 -0
- data/spec/dummy/tmp/cache/351/F10/shard%2F719 +0 -0
- data/spec/dummy/tmp/cache/352/F10/shard%2F387 +0 -0
- data/spec/dummy/tmp/cache/352/F10/shard%2F468 +1 -0
- data/spec/dummy/tmp/cache/352/F30/shard%2F729 +1 -0
- data/spec/dummy/tmp/cache/353/F10/shard%2F298 +1 -0
- data/spec/dummy/tmp/cache/353/F50/shard%2F739 +1 -0
- data/spec/dummy/tmp/cache/354/F50/shard%2F569 +1 -0
- data/spec/dummy/tmp/cache/354/F80/shard%2F677 +1 -0
- data/spec/dummy/tmp/cache/354/F90/shard%2F767 +1 -0
- data/spec/dummy/tmp/cache/358/FE0/shard%2F699 +1 -0
- data/spec/dummy/tmp/cache/3A5/EA0/shard%2F10004 +1 -0
- data/spec/dummy/tmp/cache/3A6/F40/shard%2F10410 +1 -0
- data/spec/dummy/tmp/cache/3A7/F30/shard%2F10231 +1 -0
- data/spec/dummy/tmp/cache/3A8/F90/shard%2F10520 +1 -0
- data/spec/dummy/tmp/cache/3A9/F40/shard%2F10062 +1 -0
- data/spec/dummy/tmp/cache/3A9/F80/shard%2F10341 +1 -0
- data/spec/dummy/tmp/cache/3AA/F10/shard%2F10027 +1 -0
- data/spec/dummy/tmp/cache/3AA/F10/shard%2F10108 +1 -0
- data/spec/dummy/tmp/cache/3AA/FB0/shard%2F10441 +1 -0
- data/spec/dummy/tmp/cache/3AA/FC0/shard%2F10612 +1 -0
- data/spec/dummy/tmp/cache/3AB/010/shard%2F10730 +1 -0
- data/spec/dummy/tmp/cache/3AB/F70/shard%2F10154 +1 -0
- data/spec/dummy/tmp/cache/3AC/020/shard%2F10650 +1 -0
- data/spec/dummy/tmp/cache/3AC/FC0/shard%2F10272 +1 -0
- data/spec/dummy/tmp/cache/3AD/000/shard%2F10543 +1 -0
- data/spec/dummy/tmp/cache/3AD/F50/shard%2F10039 +1 -0
- data/spec/dummy/tmp/cache/3AD/F90/shard%2F10318 +1 -0
- data/spec/dummy/tmp/cache/3AD/FA0/shard%2F10246 +1 -0
- data/spec/dummy/tmp/cache/3AE/060/shard%2F10751 +1 -0
- data/spec/dummy/tmp/cache/3AE/FF0/shard%2F10364 +1 -0
- data/spec/dummy/tmp/cache/3AF/030/shard%2F10635 +1 -0
- data/spec/dummy/tmp/cache/3B0/FE0/shard%2F10177 +1 -0
- data/spec/dummy/tmp/cache/3B1/030/shard%2F10295 +1 -0
- data/spec/dummy/tmp/cache/3B1/040/shard%2F10466 +1 -0
- data/spec/dummy/tmp/cache/3B1/090/shard%2F10673 +1 -0
- data/spec/dummy/tmp/cache/3B2/070/shard%2F10566 +1 -0
- data/spec/dummy/tmp/cache/3B3/060/shard%2F10387 +1 -0
- data/spec/dummy/tmp/cache/3B5/0B0/shard%2F10497 +1 -0
- data/spec/dummy/tmp/cache/3B6/100/shard%2F10696 +1 -0
- data/spec/dummy/tmp/cache/3B7/0E0/shard%2F10589 +1 -0
- data/spec/dummy/tmp/cache/3BA/160/shard%2F10799 +1 -0
- data/spec/lib/action_controller/caching_spec.rb +4 -4
- data/spec/lib/active_record/abstract_adapter_spec.rb +1 -1
- data/spec/lib/active_record/association_spec.rb +83 -67
- data/spec/lib/active_record/attribute_methods_spec.rb +29 -29
- data/spec/lib/active_record/base_spec.rb +20 -20
- data/spec/lib/active_record/calculations_spec.rb +79 -59
- data/spec/lib/active_record/connection_handler_spec.rb +14 -14
- data/spec/lib/active_record/connection_pool_spec.rb +7 -7
- data/spec/lib/active_record/finder_methods_spec.rb +8 -8
- data/spec/lib/active_record/query_cache_spec.rb +38 -38
- data/spec/lib/active_record/query_methods_spec.rb +45 -45
- data/spec/lib/active_record/relation_spec.rb +8 -8
- data/spec/lib/active_record/spawn_methods_spec.rb +11 -11
- data/spec/lib/connection_pool_proxy_spec.rb +2 -2
- data/spec/lib/database_server_spec.rb +37 -37
- data/spec/lib/default_shard_spec.rb +3 -3
- data/spec/lib/r_spec_helper_spec.rb +33 -7
- data/spec/lib/rails_spec.rb +5 -5
- data/spec/lib/shackles_spec.rb +35 -35
- data/spec/models/shard_spec.rb +104 -104
- data/spec/spec_helper.rb +1 -1
- metadata +254 -29
@@ -8,14 +8,14 @@ module Switchman
|
|
8
8
|
describe "ids" do
|
9
9
|
it "should return id relative to the current shard" do
|
10
10
|
user = User.create!
|
11
|
-
user.id.
|
12
|
-
user.local_id.
|
13
|
-
user.global_id.
|
11
|
+
expect(user.id).to be < Shard::IDS_PER_SHARD
|
12
|
+
expect(user.local_id).to be < Shard::IDS_PER_SHARD
|
13
|
+
expect(user.global_id).to be > Shard::IDS_PER_SHARD
|
14
14
|
|
15
15
|
@shard1.activate do
|
16
|
-
user.id.
|
17
|
-
user.local_id.
|
18
|
-
user.global_id.
|
16
|
+
expect(user.id).to be > Shard::IDS_PER_SHARD
|
17
|
+
expect(user.local_id).to be < Shard::IDS_PER_SHARD
|
18
|
+
expect(user.global_id).to be > Shard::IDS_PER_SHARD
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -26,80 +26,80 @@ module Switchman
|
|
26
26
|
|
27
27
|
# local id, should stay local
|
28
28
|
appendage.original_user_id = 6
|
29
|
-
appendage.user_id.
|
29
|
+
expect(appendage.user_id).to eq 6
|
30
30
|
|
31
31
|
# (incorrect) self referencing global id; should come out as local
|
32
32
|
appendage.original_user_id = Shard.current.global_id_for(6)
|
33
|
-
appendage.user_id.
|
33
|
+
expect(appendage.user_id).to eq 6
|
34
34
|
|
35
35
|
# global id referencing another shard; should come out unscathed
|
36
36
|
appendage.original_user_id = @shard1.global_id_for(6)
|
37
|
-
appendage.user_id.
|
37
|
+
expect(appendage.user_id).to eq @shard1.global_id_for(6)
|
38
38
|
|
39
39
|
@shard1.activate do
|
40
40
|
# local id in another shard, should be global in this shard
|
41
41
|
appendage.original_user_id = 6
|
42
|
-
appendage.user_id.
|
42
|
+
expect(appendage.user_id).to eq Shard.default.global_id_for(6)
|
43
43
|
|
44
44
|
# (incorrect) self referencing global id; should come out as global in this shard
|
45
45
|
appendage.original_user_id = Shard.default.global_id_for(6)
|
46
|
-
appendage.user_id.
|
46
|
+
expect(appendage.user_id).to eq Shard.default.global_id_for(6)
|
47
47
|
|
48
48
|
# global id referencing this shard; should come out as a local id in this shard
|
49
49
|
appendage.original_user_id = @shard1.global_id_for(6)
|
50
|
-
appendage.user_id.
|
50
|
+
expect(appendage.user_id).to eq 6
|
51
51
|
|
52
52
|
# global id from an unrelated shard; should stay global
|
53
53
|
appendage.original_user_id = @shard2.global_id_for(6)
|
54
|
-
appendage.user_id.
|
54
|
+
expect(appendage.user_id).to eq @shard2.global_id_for(6)
|
55
55
|
end
|
56
56
|
|
57
57
|
# now that we trust the getters, try the setters
|
58
58
|
|
59
59
|
# local stays local
|
60
60
|
appendage.user_id = 6
|
61
|
-
appendage.original_user_id.
|
61
|
+
expect(appendage.original_user_id).to eq 6
|
62
62
|
appendage.user_id = '6'
|
63
|
-
appendage.original_user_id.
|
63
|
+
expect(appendage.original_user_id).to eq 6
|
64
64
|
|
65
65
|
# (incorrect) global id to this shard, should become local
|
66
66
|
appendage.user_id = Shard.current.global_id_for(6)
|
67
|
-
appendage.original_user_id.
|
67
|
+
expect(appendage.original_user_id).to eq 6
|
68
68
|
appendage.user_id = Shard.current.global_id_for(6).to_s
|
69
|
-
appendage.original_user_id.
|
69
|
+
expect(appendage.original_user_id).to eq 6
|
70
70
|
|
71
71
|
# global id from another shard, should stay global
|
72
72
|
appendage.user_id = @shard1.global_id_for(6)
|
73
|
-
appendage.original_user_id.
|
74
|
-
appendage.local_user_id.
|
73
|
+
expect(appendage.original_user_id).to eq @shard1.global_id_for(6)
|
74
|
+
expect(appendage.local_user_id).to eq 6
|
75
75
|
appendage.user_id = @shard1.global_id_for(6).to_s
|
76
|
-
appendage.original_user_id.
|
77
|
-
appendage.local_user_id.
|
76
|
+
expect(appendage.original_user_id).to eq @shard1.global_id_for(6)
|
77
|
+
expect(appendage.local_user_id).to eq 6
|
78
78
|
|
79
79
|
@shard1.activate do
|
80
80
|
# local to this shard becomes global
|
81
81
|
appendage.user_id = 6
|
82
|
-
appendage.original_user_id.
|
82
|
+
expect(appendage.original_user_id).to eq @shard1.global_id_for(6)
|
83
83
|
appendage.user_id = '6'
|
84
|
-
appendage.original_user_id.
|
84
|
+
expect(appendage.original_user_id).to eq @shard1.global_id_for(6)
|
85
85
|
|
86
86
|
# global id from original shard, should become local
|
87
87
|
appendage.user_id = Shard.default.global_id_for(6)
|
88
|
-
appendage.original_user_id.
|
88
|
+
expect(appendage.original_user_id).to eq 6
|
89
89
|
appendage.user_id = Shard.default.global_id_for(6).to_s
|
90
|
-
appendage.original_user_id.
|
90
|
+
expect(appendage.original_user_id).to eq 6
|
91
91
|
|
92
92
|
# global id from this shard, should stay global
|
93
93
|
appendage.user_id = Shard.current.global_id_for(6)
|
94
|
-
appendage.original_user_id.
|
94
|
+
expect(appendage.original_user_id).to eq @shard1.global_id_for(6)
|
95
95
|
appendage.user_id = Shard.current.global_id_for(6).to_s
|
96
|
-
appendage.original_user_id.
|
96
|
+
expect(appendage.original_user_id).to eq @shard1.global_id_for(6)
|
97
97
|
|
98
98
|
# global id from unrelated shard, should stay global
|
99
99
|
appendage.user_id = @shard2.global_id_for(6)
|
100
|
-
appendage.original_user_id.
|
100
|
+
expect(appendage.original_user_id).to eq @shard2.global_id_for(6)
|
101
101
|
appendage.user_id = @shard2.global_id_for(6).to_s
|
102
|
-
appendage.original_user_id.
|
102
|
+
expect(appendage.original_user_id).to eq @shard2.global_id_for(6)
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
@@ -8,21 +8,21 @@ module Switchman
|
|
8
8
|
describe "to_param" do
|
9
9
|
it "should return nil if no id" do
|
10
10
|
user = User.new
|
11
|
-
user.to_param.
|
11
|
+
expect(user.to_param).to be_nil
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should return the id even if not persisted" do
|
15
15
|
user = User.new
|
16
16
|
user.id = 1
|
17
|
-
user.to_param.
|
17
|
+
expect(user.to_param).to eq '1'
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should return local id if in the current shard" do
|
21
21
|
user = User.create!
|
22
|
-
user.to_param.
|
22
|
+
expect(user.to_param).to eq user.local_id.to_s
|
23
23
|
@shard1.activate do
|
24
24
|
user2 = User.create!
|
25
|
-
user2.to_param.
|
25
|
+
expect(user2.to_param).to eq user2.local_id.to_s
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -32,7 +32,7 @@ module Switchman
|
|
32
32
|
user = User.create!
|
33
33
|
end
|
34
34
|
@shard2.activate do
|
35
|
-
user.to_param.
|
35
|
+
expect(user.to_param).to eq "#{@shard1.id}~#{user.local_id}"
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -45,25 +45,25 @@ module Switchman
|
|
45
45
|
user = User.create!
|
46
46
|
appendage = Appendage.create!
|
47
47
|
|
48
|
-
helpers.user_path(user).
|
49
|
-
helpers.user_appendages_path(user).
|
50
|
-
helpers.user_appendage_path(user, appendage).
|
51
|
-
helpers.user_test1_path(user).
|
52
|
-
helpers.user_test2_path(user).
|
48
|
+
expect(helpers.user_path(user)).to eq "/users/#{user.local_id}"
|
49
|
+
expect(helpers.user_appendages_path(user)).to eq "/users/#{user.local_id}/appendages"
|
50
|
+
expect(helpers.user_appendage_path(user, appendage)).to eq "/users/#{user.local_id}/appendages/#{appendage.local_id}"
|
51
|
+
expect(helpers.user_test1_path(user)).to eq "/users/#{user.local_id}"
|
52
|
+
expect(helpers.user_test2_path(user)).to eq "/users/#{user.local_id}/test2"
|
53
53
|
end
|
54
54
|
|
55
55
|
@shard2.activate do
|
56
56
|
user_short_id = "#{@shard1.id}~#{user.local_id}"
|
57
57
|
appendage_short_id = "#{@shard1.id}~#{appendage.local_id}"
|
58
58
|
|
59
|
-
helpers.user_path(user).
|
60
|
-
helpers.user_appendages_path(user).
|
61
|
-
helpers.user_appendage_path(user, appendage).
|
62
|
-
helpers.user_test1_path(user).
|
63
|
-
helpers.user_test2_path(user).
|
59
|
+
expect(helpers.user_path(user)).to eq "/users/#{user_short_id}"
|
60
|
+
expect(helpers.user_appendages_path(user)).to eq "/users/#{user_short_id}/appendages"
|
61
|
+
expect(helpers.user_appendage_path(user, appendage)).to eq "/users/#{user_short_id}/appendages/#{appendage_short_id}"
|
62
|
+
expect(helpers.user_test1_path(user)).to eq "/users/#{user_short_id}"
|
63
|
+
expect(helpers.user_test2_path(user)).to eq "/users/#{user_short_id}/test2"
|
64
64
|
|
65
65
|
appendage2 = Appendage.create!
|
66
|
-
helpers.user_appendage_path(user, appendage2).
|
66
|
+
expect(helpers.user_appendage_path(user, appendage2)).to eq "/users/#{user_short_id}/appendages/#{appendage2.local_id}"
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
@@ -74,21 +74,21 @@ module Switchman
|
|
74
74
|
appendage = Appendage.new
|
75
75
|
appendage.user_id = user.id
|
76
76
|
appendage.shard = @shard1
|
77
|
-
appendage.attributes["user_id"].
|
77
|
+
expect(appendage.attributes["user_id"]).to eq user.global_id
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
describe ".shard_category=" do
|
82
82
|
it "should set up connection pools correctly for a model on a different db in the default shard" do
|
83
|
-
|
83
|
+
skip "remove_connection working properly"
|
84
84
|
::Rails.env.stubs(:test?).returns(false)
|
85
85
|
begin
|
86
86
|
config = { :adapter => 'sqlite3', :database => ':memory:', :something_unique_in_the_spec => true }
|
87
87
|
MirrorUser.establish_connection(config)
|
88
88
|
|
89
|
-
MirrorUser.connection.
|
89
|
+
expect(MirrorUser.connection).not_to eq ::ActiveRecord::Base.connection
|
90
90
|
::Shackles.activate(:slave) do
|
91
|
-
MirrorUser.connection.
|
91
|
+
expect(MirrorUser.connection).not_to eq ::ActiveRecord::Base.connection
|
92
92
|
end
|
93
93
|
ensure
|
94
94
|
MirrorUser.remove_connection
|
@@ -18,32 +18,32 @@ module Switchman
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should return non-id columns" do
|
21
|
-
User.where(:id => [@user1.id, @user2.id]).pluck(:name).sort.
|
21
|
+
expect(User.where(:id => [@user1.id, @user2.id]).pluck(:name).sort).to eq ["user1", "user2"]
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should return primary ids relative to current shard" do
|
25
|
-
Appendage.where(:id => @appendage1).pluck(:id).
|
26
|
-
Appendage.where(:id => @appendage2).pluck(:id).
|
25
|
+
expect(Appendage.where(:id => @appendage1).pluck(:id)).to eq [@appendage1.global_id]
|
26
|
+
expect(Appendage.where(:id => @appendage2).pluck(:id)).to eq [@appendage2.global_id]
|
27
27
|
@shard1.activate do
|
28
|
-
Appendage.where(:id => @appendage1).pluck(:id).
|
29
|
-
Appendage.where(:id => @appendage2).pluck(:id).
|
28
|
+
expect(Appendage.where(:id => @appendage1).pluck(:id)).to eq [@appendage1.local_id]
|
29
|
+
expect(Appendage.where(:id => @appendage2).pluck(:id)).to eq [@appendage2.global_id]
|
30
30
|
end
|
31
31
|
@shard2.activate do
|
32
|
-
Appendage.where(:id => @appendage1).pluck(:id).
|
33
|
-
Appendage.where(:id => @appendage2).pluck(:id).
|
32
|
+
expect(Appendage.where(:id => @appendage1).pluck(:id)).to eq [@appendage1.global_id]
|
33
|
+
expect(Appendage.where(:id => @appendage2).pluck(:id)).to eq [@appendage2.local_id]
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should return foreign ids relative to current shard" do
|
38
|
-
Appendage.where(:id => @appendage1).pluck(:user_id).
|
39
|
-
Appendage.where(:id => @appendage2).pluck(:user_id).
|
38
|
+
expect(Appendage.where(:id => @appendage1).pluck(:user_id)).to eq [@user1.global_id]
|
39
|
+
expect(Appendage.where(:id => @appendage2).pluck(:user_id)).to eq [@user2.global_id]
|
40
40
|
@shard1.activate do
|
41
|
-
Appendage.where(:id => @appendage1).pluck(:user_id).
|
42
|
-
Appendage.where(:id => @appendage2).pluck(:user_id).
|
41
|
+
expect(Appendage.where(:id => @appendage1).pluck(:user_id)).to eq [@user1.local_id]
|
42
|
+
expect(Appendage.where(:id => @appendage2).pluck(:user_id)).to eq [@user2.global_id]
|
43
43
|
end
|
44
44
|
@shard2.activate do
|
45
|
-
Appendage.where(:id => @appendage1).pluck(:user_id).
|
46
|
-
Appendage.where(:id => @appendage2).pluck(:user_id).
|
45
|
+
expect(Appendage.where(:id => @appendage1).pluck(:user_id)).to eq [@user1.global_id]
|
46
|
+
expect(Appendage.where(:id => @appendage2).pluck(:user_id)).to eq [@user2.local_id]
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -65,53 +65,53 @@ module Switchman
|
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should calculate average across shards" do
|
68
|
-
@user1.appendages.average(:value).
|
69
|
-
@shard1.activate {Appendage.average(:value)}.
|
68
|
+
expect(@user1.appendages.average(:value)).to eq 1.5
|
69
|
+
expect(@shard1.activate {Appendage.average(:value)}).to eq 1.5
|
70
70
|
|
71
|
-
@user2.appendages.average(:value).
|
72
|
-
@shard2.activate {Appendage.average(:value)}.
|
71
|
+
expect(@user2.appendages.average(:value)).to eq 4
|
72
|
+
expect(@shard2.activate {Appendage.average(:value)}).to eq 4
|
73
73
|
|
74
|
-
Appendage.where(:id => @appendages).average(:value).
|
74
|
+
expect(Appendage.where(:id => @appendages).average(:value)).to eq 3
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should count across shards" do
|
78
|
-
@user1.appendages.count.
|
79
|
-
@shard1.activate {Appendage.count}.
|
78
|
+
expect(@user1.appendages.count).to eq 2
|
79
|
+
expect(@shard1.activate {Appendage.count}).to eq 2
|
80
80
|
|
81
|
-
@user2.appendages.count.
|
82
|
-
@shard2.activate {Appendage.count}.
|
81
|
+
expect(@user2.appendages.count).to eq 3
|
82
|
+
expect(@shard2.activate {Appendage.count}).to eq 3
|
83
83
|
|
84
|
-
Appendage.where(:id => @appendages).count.
|
84
|
+
expect(Appendage.where(:id => @appendages).count).to eq 5
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should calculate minimum across shards" do
|
88
|
-
@user1.appendages.minimum(:value).
|
89
|
-
@shard1.activate {Appendage.minimum(:value)}.
|
88
|
+
expect(@user1.appendages.minimum(:value)).to eq 1
|
89
|
+
expect(@shard1.activate {Appendage.minimum(:value)}).to eq 1
|
90
90
|
|
91
|
-
@user2.appendages.minimum(:value).
|
92
|
-
@shard2.activate {Appendage.minimum(:value)}.
|
91
|
+
expect(@user2.appendages.minimum(:value)).to eq 3
|
92
|
+
expect(@shard2.activate {Appendage.minimum(:value)}).to eq 3
|
93
93
|
|
94
|
-
Appendage.where(:id => @appendages).minimum(:value).
|
94
|
+
expect(Appendage.where(:id => @appendages).minimum(:value)).to eq 1
|
95
95
|
end
|
96
96
|
|
97
97
|
it "should calculate maximum across shards" do
|
98
|
-
@user1.appendages.maximum(:value).
|
99
|
-
@shard1.activate {Appendage.maximum(:value)}.
|
98
|
+
expect(@user1.appendages.maximum(:value)).to eq 2
|
99
|
+
expect(@shard1.activate {Appendage.maximum(:value)}).to eq 2
|
100
100
|
|
101
|
-
@user2.appendages.maximum(:value).
|
102
|
-
@shard2.activate {Appendage.maximum(:value)}.
|
101
|
+
expect(@user2.appendages.maximum(:value)).to eq 5
|
102
|
+
expect(@shard2.activate {Appendage.maximum(:value)}).to eq 5
|
103
103
|
|
104
|
-
Appendage.where(:id => @appendages).maximum(:value).
|
104
|
+
expect(Appendage.where(:id => @appendages).maximum(:value)).to eq 5
|
105
105
|
end
|
106
106
|
|
107
107
|
it "should calculate sum across shards" do
|
108
|
-
@user1.appendages.sum(:value).
|
109
|
-
@shard1.activate {Appendage.sum(:value)}.
|
108
|
+
expect(@user1.appendages.sum(:value)).to eq 3
|
109
|
+
expect(@shard1.activate {Appendage.sum(:value)}).to eq 3
|
110
110
|
|
111
|
-
@user2.appendages.sum(:value).
|
112
|
-
@shard2.activate {Appendage.sum(:value)}.
|
111
|
+
expect(@user2.appendages.sum(:value)).to eq 12
|
112
|
+
expect(@shard2.activate {Appendage.sum(:value)}).to eq 12
|
113
113
|
|
114
|
-
Appendage.where(:id => @appendages).sum(:value).
|
114
|
+
expect(Appendage.where(:id => @appendages).sum(:value)).to eq 15
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
@@ -133,93 +133,113 @@ module Switchman
|
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should calculate average across shards" do
|
136
|
-
Appendage.shard([@shard1, @shard2]).group("appendages.user_id").average(:value).
|
136
|
+
expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").average(:value)).to eq(
|
137
137
|
{@user1.global_id => 1.5, @user2.global_id => 4}
|
138
|
+
)
|
138
139
|
|
139
140
|
@shard1.activate do
|
140
|
-
Appendage.shard([@shard1, @shard2]).group("appendages.user_id").average(:value).
|
141
|
+
expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").average(:value)).to eq(
|
141
142
|
{@user1.local_id => 1.5, @user2.global_id => 4}
|
143
|
+
)
|
142
144
|
end
|
143
145
|
|
144
146
|
@shard2.activate do
|
145
|
-
Appendage.shard([@shard1, @shard2]).group("appendages.user_id").average(:value).
|
147
|
+
expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").average(:value)).to eq(
|
146
148
|
{@user1.global_id => 1.5, @user2.local_id => 4}
|
149
|
+
)
|
147
150
|
end
|
148
151
|
|
149
|
-
Appendage.shard([@shard1, @shard2]).group(:user).average(:value).
|
152
|
+
expect(Appendage.shard([@shard1, @shard2]).group(:user).average(:value)).to eq(
|
150
153
|
{@user1 => 1.5, @user2 => 4}
|
154
|
+
)
|
151
155
|
end
|
152
156
|
|
153
157
|
it "should count across shards" do
|
154
|
-
Appendage.shard([@shard1, @shard2]).group("appendages.user_id").count.
|
158
|
+
expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").count).to eq(
|
155
159
|
{@user1.global_id => 2, @user2.global_id => 3}
|
160
|
+
)
|
156
161
|
|
157
162
|
@shard1.activate do
|
158
|
-
Appendage.shard([@shard1, @shard2]).group("appendages.user_id").count.
|
163
|
+
expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").count).to eq(
|
159
164
|
{@user1.local_id => 2, @user2.global_id => 3}
|
165
|
+
)
|
160
166
|
end
|
161
167
|
|
162
168
|
@shard2.activate do
|
163
|
-
Appendage.shard([@shard1, @shard2]).group("appendages.user_id").count.
|
169
|
+
expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").count).to eq(
|
164
170
|
{@user1.global_id => 2, @user2.local_id => 3}
|
171
|
+
)
|
165
172
|
end
|
166
173
|
|
167
|
-
Appendage.shard([@shard1, @shard2]).group(:user).count.
|
174
|
+
expect(Appendage.shard([@shard1, @shard2]).group(:user).count).to eq(
|
168
175
|
{@user1 => 2, @user2 => 3}
|
176
|
+
)
|
169
177
|
end
|
170
178
|
|
171
179
|
it "should calculate minimum across shards" do
|
172
|
-
Appendage.shard([@shard1, @shard2]).group("appendages.user_id").minimum(:value).
|
180
|
+
expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").minimum(:value)).to eq(
|
173
181
|
{@user1.global_id => 1, @user2.global_id => 3}
|
182
|
+
)
|
174
183
|
|
175
184
|
@shard1.activate do
|
176
|
-
Appendage.shard([@shard1, @shard2]).group("appendages.user_id").minimum(:value).
|
185
|
+
expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").minimum(:value)).to eq(
|
177
186
|
{@user1.local_id => 1, @user2.global_id => 3}
|
187
|
+
)
|
178
188
|
end
|
179
189
|
|
180
190
|
@shard2.activate do
|
181
|
-
Appendage.shard([@shard1, @shard2]).group("appendages.user_id").minimum(:value).
|
191
|
+
expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").minimum(:value)).to eq(
|
182
192
|
{@user1.global_id => 1, @user2.local_id => 3}
|
193
|
+
)
|
183
194
|
end
|
184
195
|
|
185
|
-
Appendage.shard([@shard1, @shard2]).group(:user).minimum(:value).
|
196
|
+
expect(Appendage.shard([@shard1, @shard2]).group(:user).minimum(:value)).to eq(
|
186
197
|
{@user1 => 1, @user2 => 3}
|
198
|
+
)
|
187
199
|
end
|
188
200
|
|
189
201
|
it "should calculate maximum across shards" do
|
190
|
-
Appendage.shard([@shard1, @shard2]).group("appendages.user_id").maximum(:value).
|
202
|
+
expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").maximum(:value)).to eq(
|
191
203
|
{@user1.global_id => 2, @user2.global_id => 5}
|
204
|
+
)
|
192
205
|
|
193
206
|
@shard1.activate do
|
194
|
-
Appendage.shard([@shard1, @shard2]).group("appendages.user_id").maximum(:value).
|
207
|
+
expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").maximum(:value)).to eq(
|
195
208
|
{@user1.local_id => 2, @user2.global_id => 5}
|
209
|
+
)
|
196
210
|
end
|
197
211
|
|
198
212
|
@shard2.activate do
|
199
|
-
Appendage.shard([@shard1, @shard2]).group("appendages.user_id").maximum(:value).
|
213
|
+
expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").maximum(:value)).to eq(
|
200
214
|
{@user1.global_id => 2, @user2.local_id => 5}
|
215
|
+
)
|
201
216
|
end
|
202
217
|
|
203
|
-
Appendage.shard([@shard1, @shard2]).group(:user).maximum(:value).
|
218
|
+
expect(Appendage.shard([@shard1, @shard2]).group(:user).maximum(:value)).to eq(
|
204
219
|
{@user1 => 2, @user2 => 5}
|
220
|
+
)
|
205
221
|
end
|
206
222
|
|
207
223
|
it "should calculate sum across shards" do
|
208
|
-
Appendage.shard([@shard1, @shard2]).group("appendages.user_id").sum(:value).
|
224
|
+
expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").sum(:value)).to eq(
|
209
225
|
{@user1.global_id => 3, @user2.global_id => 12}
|
226
|
+
)
|
210
227
|
|
211
228
|
@shard1.activate do
|
212
|
-
Appendage.shard([@shard1, @shard2]).group("appendages.user_id").sum(:value).
|
229
|
+
expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").sum(:value)).to eq(
|
213
230
|
{@user1.local_id => 3, @user2.global_id => 12}
|
231
|
+
)
|
214
232
|
end
|
215
233
|
|
216
234
|
@shard2.activate do
|
217
|
-
Appendage.shard([@shard1, @shard2]).group("appendages.user_id").sum(:value).
|
235
|
+
expect(Appendage.shard([@shard1, @shard2]).group("appendages.user_id").sum(:value)).to eq(
|
218
236
|
{@user1.global_id => 3, @user2.local_id => 12}
|
237
|
+
)
|
219
238
|
end
|
220
239
|
|
221
|
-
Appendage.shard([@shard1, @shard2]).group(:user).sum(:value).
|
240
|
+
expect(Appendage.shard([@shard1, @shard2]).group(:user).sum(:value)).to eq(
|
222
241
|
{@user1 => 3, @user2 => 12}
|
242
|
+
)
|
223
243
|
end
|
224
244
|
|
225
245
|
it "should respect order for a single shard" do
|
@@ -227,7 +247,7 @@ module Switchman
|
|
227
247
|
@user1.appendages.create!
|
228
248
|
user2 = User.create!
|
229
249
|
user2.appendages.create!
|
230
|
-
Appendage.group(:user_id).order("COUNT(*) DESC").limit(1).count.
|
250
|
+
expect(Appendage.group(:user_id).order("COUNT(*) DESC").limit(1).count).to eq({ @user1.id => 2 })
|
231
251
|
end
|
232
252
|
end
|
233
253
|
end
|