mongo 1.8.6 → 1.9.0

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.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +13 -1
  5. data/VERSION +1 -1
  6. data/bin/mongo_console +15 -0
  7. data/lib/mongo.rb +14 -0
  8. data/lib/mongo/collection.rb +80 -42
  9. data/lib/mongo/cursor.rb +15 -1
  10. data/lib/mongo/db.rb +56 -19
  11. data/lib/mongo/exceptions.rb +14 -0
  12. data/lib/mongo/gridfs/grid.rb +16 -3
  13. data/lib/mongo/gridfs/grid_ext.rb +14 -0
  14. data/lib/mongo/gridfs/grid_file_system.rb +16 -3
  15. data/lib/mongo/gridfs/grid_io.rb +17 -3
  16. data/lib/mongo/legacy.rb +14 -0
  17. data/lib/mongo/mongo_client.rb +93 -40
  18. data/lib/mongo/mongo_replica_set_client.rb +21 -0
  19. data/lib/mongo/mongo_sharded_client.rb +15 -1
  20. data/lib/mongo/networking.rb +14 -0
  21. data/lib/mongo/util/conversions.rb +16 -2
  22. data/lib/mongo/util/core_ext.rb +14 -31
  23. data/lib/mongo/util/logging.rb +23 -7
  24. data/lib/mongo/util/node.rb +17 -2
  25. data/lib/mongo/util/pool.rb +17 -1
  26. data/lib/mongo/util/pool_manager.rb +15 -2
  27. data/lib/mongo/util/read_preference.rb +14 -0
  28. data/lib/mongo/util/server_version.rb +15 -0
  29. data/lib/mongo/util/sharding_pool_manager.rb +13 -0
  30. data/lib/mongo/util/socket_util.rb +14 -0
  31. data/lib/mongo/util/ssl_socket.rb +48 -7
  32. data/lib/mongo/util/support.rb +14 -0
  33. data/lib/mongo/util/tcp_socket.rb +18 -4
  34. data/lib/mongo/util/thread_local_variable_manager.rb +14 -0
  35. data/lib/mongo/util/unix_socket.rb +20 -6
  36. data/lib/mongo/util/uri_parser.rb +16 -8
  37. data/lib/mongo/util/write_concern.rb +16 -2
  38. data/test/functional/authentication_test.rb +26 -1
  39. data/test/functional/collection_test.rb +140 -41
  40. data/test/functional/connection_test.rb +19 -6
  41. data/test/functional/conversions_test.rb +14 -0
  42. data/test/functional/cursor_fail_test.rb +14 -0
  43. data/test/functional/cursor_message_test.rb +14 -0
  44. data/test/functional/cursor_test.rb +15 -1
  45. data/test/functional/db_api_test.rb +15 -1
  46. data/test/functional/db_connection_test.rb +14 -0
  47. data/test/functional/db_test.rb +14 -0
  48. data/test/functional/grid_file_system_test.rb +16 -4
  49. data/test/functional/grid_io_test.rb +14 -0
  50. data/test/functional/grid_test.rb +14 -0
  51. data/test/functional/pool_test.rb +22 -6
  52. data/test/functional/safe_test.rb +14 -0
  53. data/test/functional/ssl_test.rb +109 -0
  54. data/test/functional/support_test.rb +14 -0
  55. data/test/functional/threading_test.rb +22 -8
  56. data/test/functional/timeout_test.rb +20 -6
  57. data/test/functional/uri_test.rb +14 -14
  58. data/test/functional/write_concern_test.rb +14 -0
  59. data/test/replica_set/authentication_test.rb +28 -2
  60. data/test/replica_set/basic_test.rb +14 -0
  61. data/test/replica_set/client_test.rb +14 -0
  62. data/test/replica_set/complex_connect_test.rb +14 -0
  63. data/test/replica_set/connection_test.rb +14 -0
  64. data/test/replica_set/count_test.rb +14 -0
  65. data/test/replica_set/cursor_test.rb +14 -0
  66. data/test/replica_set/insert_test.rb +14 -0
  67. data/test/replica_set/max_values_test.rb +14 -0
  68. data/test/replica_set/pinning_test.rb +14 -0
  69. data/test/replica_set/query_test.rb +14 -0
  70. data/test/replica_set/read_preference_test.rb +14 -0
  71. data/test/replica_set/refresh_test.rb +14 -0
  72. data/test/replica_set/replication_ack_test.rb +14 -0
  73. data/test/replica_set/ssl_test.rb +114 -0
  74. data/test/sharded_cluster/basic_test.rb +14 -0
  75. data/test/shared/authentication.rb +55 -0
  76. data/test/test_helper.rb +15 -1
  77. data/test/threading/basic_test.rb +14 -0
  78. data/test/tools/mongo_config.rb +16 -1
  79. data/test/tools/mongo_config_test.rb +15 -1
  80. data/test/unit/client_test.rb +14 -0
  81. data/test/unit/collection_test.rb +14 -0
  82. data/test/unit/connection_test.rb +14 -0
  83. data/test/unit/cursor_test.rb +14 -0
  84. data/test/unit/db_test.rb +15 -1
  85. data/test/unit/grid_test.rb +14 -0
  86. data/test/unit/mongo_sharded_client_test.rb +14 -0
  87. data/test/unit/node_test.rb +15 -0
  88. data/test/unit/pool_manager_test.rb +15 -0
  89. data/test/unit/pool_test.rb +14 -0
  90. data/test/unit/read_pref_test.rb +14 -0
  91. data/test/unit/read_test.rb +14 -0
  92. data/test/unit/safe_test.rb +14 -0
  93. data/test/unit/sharding_pool_manager_test.rb +15 -0
  94. data/test/unit/util_test.rb +14 -0
  95. data/test/unit/write_concern_test.rb +15 -1
  96. metadata +8 -4
  97. metadata.gz.sig +0 -0
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen 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
+
1
15
  require 'test_helper'
2
16
  require 'mongo/exceptions'
3
17
  require 'mongo/util/conversions'
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen 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
+
1
15
  require 'test_helper'
2
16
  require 'logger'
3
17
 
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen 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
+
1
15
  require 'test_helper'
2
16
  require 'logger'
3
17
 
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen 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
+
1
15
  require 'test_helper'
2
16
  require 'logger'
3
17
 
@@ -198,7 +212,7 @@ class CursorTest < Test::Unit::TestCase
198
212
  @@coll.save({:t => 't1'})
199
213
  @@coll.save({:t => 't1'})
200
214
  @@coll.save({:t => 't1'})
201
- sleep(2)
215
+ sleep(1)
202
216
  t2 = Time.now
203
217
  t2_id = ObjectId.from_time(t2)
204
218
  @@coll.save({:t => 't2'})
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen 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
+
1
15
  require 'test_helper'
2
16
 
3
17
  class DBAPITest < Test::Unit::TestCase
@@ -614,7 +628,7 @@ HERE
614
628
  :initial => {"count" => 0}, :reduce => "function (obj, prev) { prev.count++; }")[0]["count"]
615
629
 
616
630
  finalize = "function (obj) { obj.f = obj.count - 1; }"
617
- assert_equal 2, test.group(:initial => {"count" => 0},
631
+ assert_equal 2, test.group(:initial => {"count" => 0},
618
632
  :reduce => "function (obj, prev) { prev.count++; }", :finalize => finalize)[0]["f"]
619
633
 
620
634
  test.insert("a" => 2, "b" => 3)
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen 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
+
1
15
  require 'test_helper'
2
16
 
3
17
  class DBConnectionTest < Test::Unit::TestCase
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen 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
+
1
15
  require 'test_helper'
2
16
  require 'digest/md5'
3
17
  require 'stringio'
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen 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
+
1
15
  require 'test_helper'
2
16
 
3
17
  class GridFileSystemTest < Test::Unit::TestCase
@@ -73,7 +87,7 @@ class GridFileSystemTest < Test::Unit::TestCase
73
87
  end
74
88
 
75
89
  should "return the first n bytes even with an offset" do
76
- data = @grid.open('sample.file', 'r') do |f|
90
+ data = @grid.open('sample.file', 'r') do |f|
77
91
  f.seek(1000)
78
92
  f.read(288888)
79
93
  end
@@ -123,7 +137,6 @@ class GridFileSystemTest < Test::Unit::TestCase
123
137
  @old = @grid.open('sample', 'r')
124
138
 
125
139
  @new_data = "DATA" * 10
126
- sleep(2)
127
140
  @grid.open('sample', 'w') do |f|
128
141
  f.write @new_data
129
142
  end
@@ -145,7 +158,6 @@ class GridFileSystemTest < Test::Unit::TestCase
145
158
 
146
159
  context "and on a second overwrite" do
147
160
  setup do
148
- sleep(2)
149
161
  @new_data = "NEW" * 1000
150
162
  @grid.open('sample', 'w') do |f|
151
163
  f.write @new_data
@@ -176,7 +188,7 @@ class GridFileSystemTest < Test::Unit::TestCase
176
188
  assert !@ids.include?(id)
177
189
  assert_equal @versions, @db['fs.files'].find({'filename' => 'sample'}).count
178
190
  end
179
-
191
+
180
192
  should "delete old versions on write with :delete_old is passed in" do
181
193
  @grid.open('sample', 'w', :delete_old => true) do |f|
182
194
  f.write @new_data
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen 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
+
1
15
  require 'test_helper'
2
16
 
3
17
  class GridIOTest < Test::Unit::TestCase
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen 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
+
1
15
  require 'test_helper'
2
16
  include Mongo
3
17
 
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen 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
+
1
15
  require 'test_helper'
2
16
  require 'thread'
3
17
 
@@ -5,7 +19,7 @@ class PoolTest < Test::Unit::TestCase
5
19
  include Mongo
6
20
 
7
21
  def setup
8
- @client ||= standard_connection({:pool_size => 500, :pool_timeout => 5})
22
+ @client ||= standard_connection({:pool_size => 15, :pool_timeout => 5})
9
23
  @db = @client.db(MONGO_TEST_DB)
10
24
  @collection = @db.collection("pool_test")
11
25
  end
@@ -18,7 +32,7 @@ class PoolTest < Test::Unit::TestCase
18
32
  threads << Thread.new do
19
33
  original_socket = pool.checkout
20
34
  pool.checkin(original_socket)
21
- 5000.times do
35
+ 500.times do
22
36
  socket = pool.checkout
23
37
  assert_equal original_socket, socket
24
38
  pool.checkin(socket)
@@ -30,17 +44,19 @@ class PoolTest < Test::Unit::TestCase
30
44
  end
31
45
 
32
46
  def test_pool_affinity_max_size
33
- 8000.times {|x| @collection.insert({:value => x})}
47
+ docs = []
48
+ 8000.times {|x| docs << {:value => x}}
49
+ @collection.insert(docs)
50
+
34
51
  threads = []
35
52
  threads << Thread.new do
36
53
  @collection.find({"value" => {"$lt" => 100}}).each {|e| e}
37
54
  Thread.pass
38
- sleep(5)
55
+ sleep(0.125)
39
56
  @collection.find({"value" => {"$gt" => 100}}).each {|e| e}
40
57
  end
41
- sleep(1)
42
58
  threads << Thread.new do
43
- @collection.find({'$where' => "function() {for(i=0;i<8000;i++) {this.value};}"}).each {|e| e}
59
+ @collection.find({'$where' => "function() {for(i=0;i<1000;i++) {this.value};}"}).each {|e| e}
44
60
  end
45
61
  threads.each(&:join)
46
62
  end
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen 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
+
1
15
  require 'test_helper'
2
16
  include Mongo
3
17
 
@@ -0,0 +1,109 @@
1
+ require 'test_helper'
2
+
3
+ class SSLCertValidationTest < Test::Unit::TestCase
4
+ include Mongo
5
+
6
+ CERT_PATH = "#{Dir.pwd}/test/fixtures/certificates/"
7
+ CLIENT_CERT = "#{CERT_PATH}client.pem"
8
+ CA_CERT = "#{CERT_PATH}ca.pem"
9
+
10
+ # This test doesn't connect, no server config required
11
+ def test_ssl_configuration
12
+ # raises when ssl=false and ssl opts specified
13
+ assert_raise MongoArgumentError do
14
+ MongoClient.new('server', 27017, :connect => false,
15
+ :ssl => false,
16
+ :ssl_cert => CLIENT_CERT)
17
+ end
18
+
19
+ # raises when ssl=nil and ssl opts specified
20
+ assert_raise MongoArgumentError do
21
+ MongoClient.new('server', 27017, :connect => false,
22
+ :ssl_key => CLIENT_CERT)
23
+ end
24
+
25
+ # raises when verify=true and no ca_cert
26
+ assert_raise MongoArgumentError do
27
+ MongoClient.new('server', 27017, :connect => false,
28
+ :ssl => true,
29
+ :ssl_key => CLIENT_CERT,
30
+ :ssl_cert => CLIENT_CERT,
31
+ :ssl_verify => true)
32
+ end
33
+ end
34
+
35
+ # Requires MongoDB built with SSL and the follow options:
36
+ #
37
+ # mongod --dbpath /path/to/data/directory --sslOnNormalPorts \
38
+ # --sslPEMKeyFile /path/to/server.pem \
39
+ # --sslCAFile /path/to/ca.pem \
40
+ # --sslCRLFile /path/to/crl.pem \
41
+ # --sslWeakCertificateValidation
42
+ #
43
+ # Make sure you have 'server' as an alias for localhost in /etc/hosts
44
+ #
45
+ def test_ssl_basic
46
+ client = MongoClient.new('server', 27017, :connect => false,
47
+ :ssl => true)
48
+ assert client.connect
49
+ end
50
+
51
+ # Requires MongoDB built with SSL and the follow options:
52
+ #
53
+ # mongod --dbpath /path/to/data/directory --sslOnNormalPorts \
54
+ # --sslPEMKeyFile /path/to/server.pem \
55
+ # --sslCAFile /path/to/ca.pem \
56
+ # --sslCRLFile /path/to/crl.pem
57
+ #
58
+ # Make sure you have 'server' as an alias for localhost in /etc/hosts
59
+ #
60
+ def test_ssl_with_cert
61
+ client = MongoClient.new('server', 27017, :connect => false,
62
+ :ssl => true,
63
+ :ssl_cert => CLIENT_CERT,
64
+ :ssl_key => CLIENT_CERT)
65
+ assert client.connect
66
+ end
67
+
68
+ def test_ssl_with_peer_cert_validation
69
+ client = MongoClient.new('server', 27017, :connect => false,
70
+ :ssl => true,
71
+ :ssl_key => CLIENT_CERT,
72
+ :ssl_cert => CLIENT_CERT,
73
+ :ssl_verify => true,
74
+ :ssl_ca_cert => CA_CERT)
75
+ assert client.connect
76
+ end
77
+
78
+ def test_ssl_peer_cert_validation_hostname_fail
79
+ client = MongoClient.new('localhost', 27017, :connect => false,
80
+ :ssl => true,
81
+ :ssl_key => CLIENT_CERT,
82
+ :ssl_cert => CLIENT_CERT,
83
+ :ssl_verify => true,
84
+ :ssl_ca_cert => CA_CERT)
85
+ assert_raise ConnectionFailure do
86
+ client.connect
87
+ end
88
+ end
89
+
90
+ # Requires mongod built with SSL and the follow options:
91
+ #
92
+ # mongod --dbpath /path/to/data/directory --sslOnNormalPorts \
93
+ # --sslPEMKeyFile /path/to/server.pem \
94
+ # --sslCAFile /path/to/ca.pem \
95
+ # --sslCRLFile /path/to/crl_client_revoked.pem
96
+ #
97
+ # Make sure you have 'server' as an alias for localhost in /etc/hosts
98
+ #
99
+ def test_ssl_with_invalid_cert
100
+ assert_raise ConnectionFailure do
101
+ MongoClient.new('server', 27017, :ssl => true,
102
+ :ssl_key => CLIENT_CERT,
103
+ :ssl_cert => CLIENT_CERT,
104
+ :ssl_verify => true,
105
+ :ssl_ca_cert => CA_CERT)
106
+ end
107
+ end
108
+
109
+ end
@@ -1,3 +1,17 @@
1
+ # Copyright (C) 2013 10gen 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
+
1
15
  require 'test_helper'
2
16
 
3
17
  class SupportTest < Test::Unit::TestCase
@@ -1,10 +1,24 @@
1
+ # Copyright (C) 2013 10gen 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
+
1
15
  require 'test_helper'
2
16
 
3
17
  class TestThreading < Test::Unit::TestCase
4
18
 
5
19
  include Mongo
6
20
 
7
- @@client = standard_connection(:pool_size => 10, :pool_timeout => 30)
21
+ @@client = standard_connection(:pool_size => 2, :pool_timeout => 30)
8
22
  @@db = @@client[MONGO_TEST_DB]
9
23
  @@coll = @@db.collection('thread-test-collection')
10
24
 
@@ -25,7 +39,7 @@ class TestThreading < Test::Unit::TestCase
25
39
  times = []
26
40
  set_up_safe_data
27
41
  threads = []
28
- 100.times do |i|
42
+ 25.times do |i|
29
43
  threads[i] = Thread.new do
30
44
  100.times do
31
45
  if i % 2 == 0
@@ -43,7 +57,7 @@ class TestThreading < Test::Unit::TestCase
43
57
  end
44
58
  end
45
59
 
46
- 100.times do |i|
60
+ 25.times do |i|
47
61
  threads[i].join
48
62
  end
49
63
  end
@@ -51,7 +65,7 @@ class TestThreading < Test::Unit::TestCase
51
65
  def test_safe_insert
52
66
  set_up_safe_data
53
67
  threads = []
54
- 100.times do |i|
68
+ 25.times do |i|
55
69
  threads[i] = Thread.new do
56
70
  if i % 2 == 0
57
71
  assert_raise Mongo::OperationFailure do
@@ -63,7 +77,7 @@ class TestThreading < Test::Unit::TestCase
63
77
  end
64
78
  end
65
79
 
66
- 100.times do |i|
80
+ 25.times do |i|
67
81
  threads[i].join
68
82
  end
69
83
  end
@@ -72,9 +86,9 @@ class TestThreading < Test::Unit::TestCase
72
86
  @@coll.drop
73
87
  @@coll = @@db.collection('thread-test-collection')
74
88
 
75
- 1000.times do |i|
76
- @@coll.insert({"x" => i})
77
- end
89
+ docs = []
90
+ 1000.times {|i| docs << {:x => i}}
91
+ @@coll.insert(docs)
78
92
 
79
93
  threads = []
80
94