mongo 1.10.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/LICENSE +190 -0
  5. data/README.md +149 -0
  6. data/Rakefile +31 -0
  7. data/VERSION +1 -0
  8. data/bin/mongo_console +43 -0
  9. data/ext/jsasl/target/jsasl.jar +0 -0
  10. data/lib/mongo.rb +90 -0
  11. data/lib/mongo/bulk_write_collection_view.rb +380 -0
  12. data/lib/mongo/collection.rb +1164 -0
  13. data/lib/mongo/collection_writer.rb +364 -0
  14. data/lib/mongo/connection.rb +19 -0
  15. data/lib/mongo/connection/node.rb +239 -0
  16. data/lib/mongo/connection/pool.rb +347 -0
  17. data/lib/mongo/connection/pool_manager.rb +325 -0
  18. data/lib/mongo/connection/sharding_pool_manager.rb +67 -0
  19. data/lib/mongo/connection/socket.rb +18 -0
  20. data/lib/mongo/connection/socket/socket_util.rb +37 -0
  21. data/lib/mongo/connection/socket/ssl_socket.rb +95 -0
  22. data/lib/mongo/connection/socket/tcp_socket.rb +86 -0
  23. data/lib/mongo/connection/socket/unix_socket.rb +39 -0
  24. data/lib/mongo/cursor.rb +719 -0
  25. data/lib/mongo/db.rb +735 -0
  26. data/lib/mongo/exception.rb +88 -0
  27. data/lib/mongo/functional.rb +21 -0
  28. data/lib/mongo/functional/authentication.rb +318 -0
  29. data/lib/mongo/functional/logging.rb +85 -0
  30. data/lib/mongo/functional/read_preference.rb +174 -0
  31. data/lib/mongo/functional/sasl_java.rb +48 -0
  32. data/lib/mongo/functional/uri_parser.rb +374 -0
  33. data/lib/mongo/functional/write_concern.rb +66 -0
  34. data/lib/mongo/gridfs.rb +18 -0
  35. data/lib/mongo/gridfs/grid.rb +112 -0
  36. data/lib/mongo/gridfs/grid_ext.rb +53 -0
  37. data/lib/mongo/gridfs/grid_file_system.rb +163 -0
  38. data/lib/mongo/gridfs/grid_io.rb +484 -0
  39. data/lib/mongo/legacy.rb +140 -0
  40. data/lib/mongo/mongo_client.rb +702 -0
  41. data/lib/mongo/mongo_replica_set_client.rb +523 -0
  42. data/lib/mongo/mongo_sharded_client.rb +159 -0
  43. data/lib/mongo/networking.rb +370 -0
  44. data/lib/mongo/utils.rb +19 -0
  45. data/lib/mongo/utils/conversions.rb +110 -0
  46. data/lib/mongo/utils/core_ext.rb +70 -0
  47. data/lib/mongo/utils/server_version.rb +69 -0
  48. data/lib/mongo/utils/support.rb +80 -0
  49. data/lib/mongo/utils/thread_local_variable_manager.rb +25 -0
  50. data/mongo.gemspec +36 -0
  51. data/test/functional/authentication_test.rb +35 -0
  52. data/test/functional/bulk_api_stress_test.rb +133 -0
  53. data/test/functional/bulk_write_collection_view_test.rb +1129 -0
  54. data/test/functional/client_test.rb +565 -0
  55. data/test/functional/collection_test.rb +2073 -0
  56. data/test/functional/collection_writer_test.rb +83 -0
  57. data/test/functional/conversions_test.rb +163 -0
  58. data/test/functional/cursor_fail_test.rb +63 -0
  59. data/test/functional/cursor_message_test.rb +57 -0
  60. data/test/functional/cursor_test.rb +625 -0
  61. data/test/functional/db_api_test.rb +819 -0
  62. data/test/functional/db_connection_test.rb +27 -0
  63. data/test/functional/db_test.rb +344 -0
  64. data/test/functional/grid_file_system_test.rb +285 -0
  65. data/test/functional/grid_io_test.rb +252 -0
  66. data/test/functional/grid_test.rb +273 -0
  67. data/test/functional/pool_test.rb +62 -0
  68. data/test/functional/safe_test.rb +98 -0
  69. data/test/functional/ssl_test.rb +29 -0
  70. data/test/functional/support_test.rb +62 -0
  71. data/test/functional/timeout_test.rb +58 -0
  72. data/test/functional/uri_test.rb +330 -0
  73. data/test/functional/write_concern_test.rb +118 -0
  74. data/test/helpers/general.rb +50 -0
  75. data/test/helpers/test_unit.rb +317 -0
  76. data/test/replica_set/authentication_test.rb +35 -0
  77. data/test/replica_set/basic_test.rb +174 -0
  78. data/test/replica_set/client_test.rb +341 -0
  79. data/test/replica_set/complex_connect_test.rb +77 -0
  80. data/test/replica_set/connection_test.rb +138 -0
  81. data/test/replica_set/count_test.rb +64 -0
  82. data/test/replica_set/cursor_test.rb +212 -0
  83. data/test/replica_set/insert_test.rb +140 -0
  84. data/test/replica_set/max_values_test.rb +145 -0
  85. data/test/replica_set/pinning_test.rb +55 -0
  86. data/test/replica_set/query_test.rb +73 -0
  87. data/test/replica_set/read_preference_test.rb +214 -0
  88. data/test/replica_set/refresh_test.rb +175 -0
  89. data/test/replica_set/replication_ack_test.rb +94 -0
  90. data/test/replica_set/ssl_test.rb +32 -0
  91. data/test/sharded_cluster/basic_test.rb +197 -0
  92. data/test/shared/authentication/basic_auth_shared.rb +286 -0
  93. data/test/shared/authentication/bulk_api_auth_shared.rb +259 -0
  94. data/test/shared/authentication/gssapi_shared.rb +164 -0
  95. data/test/shared/authentication/sasl_plain_shared.rb +96 -0
  96. data/test/shared/ssl_shared.rb +235 -0
  97. data/test/test_helper.rb +56 -0
  98. data/test/threading/basic_test.rb +120 -0
  99. data/test/tools/mongo_config.rb +608 -0
  100. data/test/tools/mongo_config_test.rb +160 -0
  101. data/test/unit/client_test.rb +347 -0
  102. data/test/unit/collection_test.rb +166 -0
  103. data/test/unit/connection_test.rb +325 -0
  104. data/test/unit/cursor_test.rb +299 -0
  105. data/test/unit/db_test.rb +136 -0
  106. data/test/unit/grid_test.rb +76 -0
  107. data/test/unit/mongo_sharded_client_test.rb +48 -0
  108. data/test/unit/node_test.rb +93 -0
  109. data/test/unit/pool_manager_test.rb +142 -0
  110. data/test/unit/read_pref_test.rb +115 -0
  111. data/test/unit/read_test.rb +159 -0
  112. data/test/unit/safe_test.rb +158 -0
  113. data/test/unit/sharding_pool_manager_test.rb +84 -0
  114. data/test/unit/write_concern_test.rb +175 -0
  115. metadata +260 -0
  116. metadata.gz.sig +0 -0
@@ -0,0 +1,175 @@
1
+ # Copyright (C) 2009-2013 MongoDB, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'test_helper'
16
+
17
+ class ReplicaSetRefreshTest < Test::Unit::TestCase
18
+
19
+ def setup
20
+ ensure_cluster(:rs)
21
+ end
22
+
23
+ def test_connect_and_manual_refresh_with_secondary_down
24
+ num_secondaries = @rs.secondaries.size
25
+ client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :refresh_mode => false)
26
+
27
+ assert_equal num_secondaries, client.secondaries.size
28
+ assert client.connected?
29
+ assert_equal client.read_pool, client.primary_pool
30
+ old_refresh_version = client.refresh_version
31
+
32
+ @rs.stop_secondary
33
+
34
+ client.refresh
35
+ assert_equal num_secondaries - 1, client.secondaries.size
36
+ assert client.connected?
37
+ assert_equal client.read_pool, client.primary_pool
38
+ assert client.refresh_version > old_refresh_version
39
+ old_refresh_version = client.refresh_version
40
+
41
+ # Test no changes after restart until manual refresh
42
+ @rs.restart
43
+ assert_equal num_secondaries - 1, client.secondaries.size
44
+ assert client.connected?
45
+ assert_equal client.read_pool, client.primary_pool
46
+ assert_equal client.refresh_version, old_refresh_version
47
+
48
+ # Refresh and ensure state
49
+ client.refresh
50
+ assert_equal num_secondaries, client.secondaries.size
51
+ assert client.connected?
52
+ assert_equal client.read_pool, client.primary_pool
53
+ assert client.refresh_version > old_refresh_version
54
+ end
55
+
56
+ def test_automated_refresh_with_secondary_down
57
+ num_secondaries = @rs.secondaries.size
58
+ client = MongoReplicaSetClient.new(@rs.repl_set_seeds,
59
+ :refresh_interval => 1, :refresh_mode => :sync, :read => :secondary_preferred)
60
+
61
+ # Ensure secondaries are all recognized by client and client is connected
62
+ assert_equal num_secondaries, client.secondaries.size
63
+ assert client.connected?
64
+ assert client.secondary_pools.include?(client.read_pool)
65
+ pool = client.read_pool
66
+
67
+ @rs.member_by_name(pool.host_string).stop
68
+ sleep(2)
69
+
70
+ old_refresh_version = client.refresh_version
71
+ # Trigger synchronous refresh
72
+ client[TEST_DB]['rs-refresh-test'].find_one
73
+
74
+ assert client.connected?
75
+ assert client.refresh_version > old_refresh_version
76
+ assert_equal num_secondaries - 1, client.secondaries.size
77
+ assert client.secondary_pools.include?(client.read_pool)
78
+ assert_not_equal pool, client.read_pool
79
+
80
+ # Restart nodes and ensure refresh interval has passed
81
+ @rs.restart
82
+ sleep(2)
83
+
84
+ old_refresh_version = client.refresh_version
85
+ # Trigger synchronous refresh
86
+ client[TEST_DB]['rs-refresh-test'].find_one
87
+
88
+ assert client.connected?
89
+ assert client.refresh_version > old_refresh_version,
90
+ "Refresh version hasn't changed."
91
+ assert_equal num_secondaries, client.secondaries.size
92
+ "No secondaries have been added."
93
+ assert_equal num_secondaries, client.secondary_pools.size
94
+ end
95
+
96
+ def test_concurrent_refreshes
97
+ factor = 5
98
+ nthreads = factor * 10
99
+ threads = []
100
+ client = MongoReplicaSetClient.new(@rs.repl_set_seeds, :refresh_mode => :sync, :refresh_interval => 1)
101
+
102
+ nthreads.times do |i|
103
+ threads << Thread.new do
104
+ # force a connection failure every couple of threads that causes a refresh
105
+ if i % factor == 0
106
+ cursor = client[TEST_DB]['rs-refresh-test'].find
107
+ cursor.stubs(:checkout_socket_from_connection).raises(ConnectionFailure)
108
+ begin
109
+ cursor.next
110
+ rescue => ex
111
+ raise ex unless ex.class == ConnectionFailure
112
+ next
113
+ end
114
+ else
115
+ # synchronous refreshes will happen every couple of find_ones
116
+ cursor = client[TEST_DB]['rs-refresh-test'].find_one
117
+ end
118
+ end
119
+ end
120
+
121
+ threads.each do |t|
122
+ t.join
123
+ end
124
+ end
125
+
126
+ =begin
127
+ def test_automated_refresh_with_removed_node
128
+ client = MongoReplicaSetClient.new(@rs.repl_set_seeds,
129
+ :refresh_interval => 1, :refresh_mode => :sync)
130
+
131
+ num_secondaries = client.secondary_pools.length
132
+ old_refresh_version = client.refresh_version
133
+
134
+ n = @rs.repl_set_remove_node(2)
135
+ sleep(2)
136
+
137
+ rescue_connection_failure do
138
+ client[TEST_DB]['rs-refresh-test'].find_one
139
+ end
140
+
141
+ assert client.refresh_version > old_refresh_version,
142
+ "Refresh version hasn't changed."
143
+ assert_equal num_secondaries - 1, client.secondaries.length
144
+ assert_equal num_secondaries - 1, client.secondary_pools.length
145
+
146
+ #@rs.add_node(n)
147
+ end
148
+
149
+ def test_adding_and_removing_nodes
150
+ client = MongoReplicaSetClient.new(build_seeds(3),
151
+ :refresh_interval => 2, :refresh_mode => :sync)
152
+
153
+ @rs.add_node
154
+ sleep(4)
155
+ client[TEST_DB]['rs-refresh-test'].find_one
156
+
157
+ @conn2 = MongoReplicaSetClient.new(build_seeds(3),
158
+ :refresh_interval => 2, :refresh_mode => :sync)
159
+
160
+ assert @conn2.secondaries.sort == client.secondaries.sort,
161
+ "Second connection secondaries not equal to first."
162
+ assert_equal 3, client.secondary_pools.length
163
+ assert_equal 3, client.secondaries.length
164
+
165
+ config = client['admin'].command({:ismaster => 1})
166
+
167
+ @rs.remove_secondary_node
168
+ sleep(4)
169
+ config = client['admin'].command({:ismaster => 1})
170
+
171
+ assert_equal 2, client.secondary_pools.length
172
+ assert_equal 2, client.secondaries.length
173
+ end
174
+ =end
175
+ end
@@ -0,0 +1,94 @@
1
+ # Copyright (C) 2009-2013 MongoDB, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'test_helper'
16
+
17
+ class ReplicaSetAckTest < Test::Unit::TestCase
18
+
19
+ def setup
20
+ ensure_cluster(:rs)
21
+ @client = MongoReplicaSetClient.new(@rs.repl_set_seeds)
22
+
23
+ @slave1 = MongoClient.new(
24
+ @client.secondary_pools.first.host,
25
+ @client.secondary_pools.first.port, :slave_ok => true)
26
+
27
+ assert !@slave1.read_primary?
28
+
29
+ @db = @client.db(TEST_DB)
30
+ @db.drop_collection("test-sets")
31
+ @col = @db.collection("test-sets")
32
+ end
33
+
34
+ def teardown
35
+ @client.close if @conn
36
+ end
37
+
38
+ def test_safe_mode_with_w_failure
39
+ assert_raise_error WriteConcernError, "time" do
40
+ @col.insert({:foo => 1}, :w => 4, :wtimeout => 1, :fsync => true)
41
+ end
42
+ assert_raise_error WriteConcernError, "time" do
43
+ @col.update({:foo => 1}, {:foo => 2}, :w => 4, :wtimeout => 1, :fsync => true)
44
+ end
45
+ assert_raise_error WriteConcernError, "time" do
46
+ @col.remove({:foo => 2}, :w => 4, :wtimeout => 1, :fsync => true)
47
+ end
48
+ if @client.server_version >= '2.5.4'
49
+ assert_raise_error WriteConcernError do
50
+ @col.insert({:foo => 3}, :w => "test-tag")
51
+ end
52
+ else # indistinguishable "errmsg"=>"exception: unrecognized getLastError mode: test-tag"
53
+ assert_raise_error OperationFailure do
54
+ @col.insert({:foo => 3}, :w => "test-tag")
55
+ end
56
+ end
57
+ end
58
+
59
+ def test_safe_mode_replication_ack
60
+ @col.insert({:baz => "bar"}, :w => 3, :wtimeout => 5000)
61
+
62
+ assert @col.insert({:foo => "0" * 5000}, :w => 3, :wtimeout => 5000)
63
+ assert_equal 2, @slave1[TEST_DB]["test-sets"].count
64
+
65
+ assert @col.update({:baz => "bar"}, {:baz => "foo"}, :w => 3, :wtimeout => 5000)
66
+ assert @slave1[TEST_DB]["test-sets"].find_one({:baz => "foo"})
67
+
68
+ assert @col.insert({:foo => "bar"}, :w => "majority")
69
+
70
+ assert @col.insert({:bar => "baz"}, :w => :majority)
71
+
72
+ assert @col.remove({}, :w => 3, :wtimeout => 5000)
73
+ assert_equal 0, @slave1[TEST_DB]["test-sets"].count
74
+ end
75
+
76
+ def test_last_error_responses
77
+ 20.times { @col.insert({:baz => "bar"}) }
78
+ response = @db.get_last_error(:w => 3, :wtimeout => 5000)
79
+ assert response['ok'] == 1
80
+ assert response['lastOp']
81
+
82
+ @col.update({}, {:baz => "foo"})
83
+ response = @db.get_last_error(:w => 3, :wtimeout => 5000)
84
+ assert response['ok'] == 1
85
+ assert response['lastOp']
86
+
87
+ @col.remove({})
88
+ response = @db.get_last_error(:w => 3, :wtimeout => 5000)
89
+ assert response['ok'] == 1
90
+ assert response['n'] == 20
91
+ assert response['lastOp']
92
+ end
93
+
94
+ end
@@ -0,0 +1,32 @@
1
+ # Copyright (C) 2009-2013 MongoDB, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'test_helper'
16
+ require 'shared/ssl_shared'
17
+
18
+ class ReplicaSetSSLTest < Test::Unit::TestCase
19
+ include Mongo
20
+ include SSLTests
21
+
22
+ SEEDS = ['server:3000','server:3001','server:3002']
23
+ BAD_SEEDS = ['localhost:3000','localhost:3001','localhost:3002']
24
+
25
+ def setup
26
+ @client_class = MongoReplicaSetClient
27
+ @uri_info = SEEDS.join(',')
28
+ @connect_info = SEEDS
29
+ @bad_connect_info = BAD_SEEDS
30
+ end
31
+
32
+ end
@@ -0,0 +1,197 @@
1
+ # Copyright (C) 2009-2013 MongoDB, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'test_helper'
16
+ include Mongo
17
+
18
+ class Cursor
19
+ public :construct_query_spec
20
+ end
21
+
22
+ class ShardedClusterBasicTest < Test::Unit::TestCase
23
+
24
+ def setup
25
+ ensure_cluster(:sc)
26
+ @document = { "name" => "test_user" }
27
+ @seeds = @sc.mongos_seeds
28
+ end
29
+
30
+ # TODO member.primary? ==> true
31
+ def test_connect
32
+ @client = MongoShardedClient.new(@seeds)
33
+ assert @client.connected?
34
+ assert_equal(@seeds.size, @client.seeds.size)
35
+ probe(@seeds.size)
36
+ @client.close
37
+ end
38
+
39
+ def test_connect_from_standard_client
40
+ mongos = @seeds.first
41
+ @client = MongoClient.new(*mongos.split(':'))
42
+ assert @client.connected?
43
+ assert @client.mongos?
44
+ @client.close
45
+ end
46
+
47
+ def test_read_from_client
48
+ host, port = @seeds.first.split(':')
49
+ tags = [{:dc => "mongolia"}]
50
+ @client = MongoClient.new(host, port, {:read => :secondary, :tag_sets => tags})
51
+ assert @client.connected?
52
+ cursor = Cursor.new(@client[TEST_DB]['whatever'], {})
53
+ assert_equal cursor.construct_query_spec['$readPreference'], {:mode => 'secondary', :tags => tags}
54
+ end
55
+
56
+ def test_find_one_with_read_secondary
57
+ @client = MongoShardedClient.new(@seeds, { :read => :secondary })
58
+ @client[TEST_DB]["users"].insert([ @document ])
59
+ assert_equal @client[TEST_DB]['users'].find_one["name"], "test_user"
60
+ end
61
+
62
+ def test_find_one_with_read_secondary_preferred
63
+ @client = MongoShardedClient.new(@seeds, { :read => :secondary_preferred })
64
+ @client[TEST_DB]["users"].insert([ @document ])
65
+ assert_equal @client[TEST_DB]['users'].find_one["name"], "test_user"
66
+ end
67
+
68
+ def test_find_one_with_read_primary
69
+ @client = MongoShardedClient.new(@seeds, { :read => :primary })
70
+ @client[TEST_DB]["users"].insert([ @document ])
71
+ assert_equal @client[TEST_DB]['users'].find_one["name"], "test_user"
72
+ end
73
+
74
+ def test_find_one_with_read_primary_preferred
75
+ @client = MongoShardedClient.new(@seeds, { :read => :primary_preferred })
76
+ @client[TEST_DB]["users"].insert([ @document ])
77
+ assert_equal @client[TEST_DB]['users'].find_one["name"], "test_user"
78
+ end
79
+
80
+ def test_read_from_sharded_client
81
+ tags = [{:dc => "mongolia"}]
82
+ @client = MongoShardedClient.new(@seeds, {:read => :secondary, :tag_sets => tags})
83
+ assert @client.connected?
84
+ cursor = Cursor.new(@client[TEST_DB]['whatever'], {})
85
+ assert_equal cursor.construct_query_spec['$readPreference'], {:mode => 'secondary', :tags => tags}
86
+ end
87
+
88
+ def test_hard_refresh
89
+ @client = MongoShardedClient.new(@seeds)
90
+ assert @client.connected?
91
+ @client.hard_refresh!
92
+ assert @client.connected?
93
+ @client.close
94
+ end
95
+
96
+ def test_reconnect
97
+ @client = MongoShardedClient.new(@seeds)
98
+ assert @client.connected?
99
+ router = @sc.servers(:routers).first
100
+ router.stop
101
+ probe(@seeds.size)
102
+ assert @client.connected?
103
+ @client.close
104
+ end
105
+
106
+ def test_mongos_failover
107
+ @client = MongoShardedClient.new(@seeds, :refresh_interval => 5, :refresh_mode => :sync)
108
+ assert @client.connected?
109
+ # do a find to pin a pool
110
+ @client[TEST_DB]['test'].find_one
111
+ original_primary = @client.manager.primary
112
+ # stop the pinned member
113
+ @sc.member_by_name("#{original_primary[0]}:#{original_primary[1]}").stop
114
+ # assert that the client fails over to the next available mongos
115
+ assert_nothing_raised do
116
+ @client[TEST_DB]['test'].find_one
117
+ end
118
+
119
+ assert_not_equal original_primary, @client.manager.primary
120
+ assert @client.connected?
121
+ @client.close
122
+ end
123
+
124
+ def test_all_down
125
+ @client = MongoShardedClient.new(@seeds)
126
+ assert @client.connected?
127
+ @sc.servers(:routers).each{|router| router.stop}
128
+ assert_raises Mongo::ConnectionFailure do
129
+ probe(@seeds.size)
130
+ end
131
+ assert_false @client.connected?
132
+ @client.close
133
+ end
134
+
135
+ def test_cycle
136
+ @client = MongoShardedClient.new(@seeds)
137
+ assert @client.connected?
138
+ routers = @sc.servers(:routers)
139
+ while routers.size > 0 do
140
+ rescue_connection_failure do
141
+ probe(@seeds.size)
142
+ end
143
+ probe(@seeds.size)
144
+ router = routers.detect{|r| r.port == @client.manager.primary.last}
145
+ routers.delete(router)
146
+ router.stop
147
+ end
148
+ assert_raises Mongo::ConnectionFailure do
149
+ probe(@seeds.size)
150
+ end
151
+ assert_false @client.connected?
152
+ routers = @sc.servers(:routers).reverse
153
+ routers.each do |r|
154
+ r.start
155
+ @client.hard_refresh!
156
+ rescue_connection_failure do
157
+ probe(@seeds.size)
158
+ end
159
+ probe(@seeds.size)
160
+ end
161
+ @client.close
162
+ end
163
+
164
+ def test_wire_version_not_in_range
165
+ [
166
+ [Mongo::MongoClient::MAX_WIRE_VERSION+1, Mongo::MongoClient::MAX_WIRE_VERSION+1],
167
+ [Mongo::MongoClient::MIN_WIRE_VERSION-1, Mongo::MongoClient::MIN_WIRE_VERSION-1]
168
+ ].each do |min_wire_version_value, max_wire_version_value|
169
+ Mongo.module_eval <<-EVAL
170
+ class ShardingPoolManager
171
+ def max_wire_version
172
+ return #{max_wire_version_value}
173
+ end
174
+ def min_wire_version
175
+ return #{min_wire_version_value}
176
+ end
177
+ end
178
+ EVAL
179
+ @client = MongoShardedClient.new(@seeds, :connect => false)
180
+ assert !@client.connected?
181
+ assert_raises Mongo::ConnectionFailure do
182
+ @client.connect
183
+ end
184
+ end
185
+ Mongo.module_eval <<-EVAL
186
+ class ShardingPoolManager
187
+ attr_reader :max_wire_version, :min_wire_version
188
+ end
189
+ EVAL
190
+ end
191
+
192
+ private
193
+
194
+ def probe(size)
195
+ assert_equal(size, @client['config']['mongos'].find.to_a.size)
196
+ end
197
+ end