mongo 1.9.2 → 1.10.0.rc0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/LICENSE +1 -1
  5. data/README.md +94 -334
  6. data/Rakefile +6 -4
  7. data/VERSION +1 -1
  8. data/bin/mongo_console +13 -6
  9. data/lib/mongo.rb +22 -27
  10. data/lib/mongo/bulk_write_collection_view.rb +352 -0
  11. data/lib/mongo/collection.rb +128 -188
  12. data/lib/mongo/collection_writer.rb +348 -0
  13. data/lib/mongo/connection.rb +19 -0
  14. data/lib/mongo/{util → connection}/node.rb +15 -1
  15. data/lib/mongo/{util → connection}/pool.rb +34 -19
  16. data/lib/mongo/{util → connection}/pool_manager.rb +8 -2
  17. data/lib/mongo/{util → connection}/sharding_pool_manager.rb +1 -1
  18. data/lib/mongo/connection/socket.rb +18 -0
  19. data/lib/mongo/{util → connection/socket}/socket_util.rb +5 -2
  20. data/lib/mongo/{util → connection/socket}/ssl_socket.rb +3 -4
  21. data/lib/mongo/{util → connection/socket}/tcp_socket.rb +25 -15
  22. data/lib/mongo/{util → connection/socket}/unix_socket.rb +6 -4
  23. data/lib/mongo/cursor.rb +113 -47
  24. data/lib/mongo/db.rb +203 -131
  25. data/lib/mongo/{exceptions.rb → exception.rb} +7 -1
  26. data/lib/mongo/functional.rb +19 -0
  27. data/lib/mongo/functional/authentication.rb +303 -0
  28. data/lib/mongo/{util → functional}/logging.rb +1 -1
  29. data/lib/mongo/{util → functional}/read_preference.rb +49 -1
  30. data/lib/mongo/{util → functional}/uri_parser.rb +81 -69
  31. data/lib/mongo/{util → functional}/write_concern.rb +2 -1
  32. data/{test/unit/pool_test.rb → lib/mongo/gridfs.rb} +5 -10
  33. data/lib/mongo/gridfs/grid.rb +1 -3
  34. data/lib/mongo/gridfs/grid_ext.rb +1 -1
  35. data/lib/mongo/gridfs/grid_file_system.rb +1 -1
  36. data/lib/mongo/gridfs/grid_io.rb +1 -1
  37. data/lib/mongo/legacy.rb +63 -8
  38. data/lib/mongo/mongo_client.rb +128 -154
  39. data/lib/mongo/mongo_replica_set_client.rb +17 -11
  40. data/lib/mongo/mongo_sharded_client.rb +2 -1
  41. data/lib/mongo/networking.rb +19 -10
  42. data/lib/mongo/utils.rb +19 -0
  43. data/lib/mongo/{util → utils}/conversions.rb +1 -1
  44. data/lib/mongo/{util → utils}/core_ext.rb +1 -1
  45. data/lib/mongo/{util → utils}/server_version.rb +1 -1
  46. data/lib/mongo/{util → utils}/support.rb +10 -57
  47. data/lib/mongo/{util → utils}/thread_local_variable_manager.rb +1 -1
  48. data/test/functional/authentication_test.rb +8 -21
  49. data/test/functional/bulk_write_collection_view_test.rb +782 -0
  50. data/test/functional/{connection_test.rb → client_test.rb} +153 -78
  51. data/test/functional/collection_test.rb +343 -97
  52. data/test/functional/collection_writer_test.rb +83 -0
  53. data/test/functional/conversions_test.rb +1 -3
  54. data/test/functional/cursor_fail_test.rb +3 -3
  55. data/test/functional/cursor_message_test.rb +3 -3
  56. data/test/functional/cursor_test.rb +38 -3
  57. data/test/functional/db_api_test.rb +5 -5
  58. data/test/functional/db_connection_test.rb +2 -2
  59. data/test/functional/db_test.rb +35 -11
  60. data/test/functional/grid_file_system_test.rb +2 -2
  61. data/test/functional/grid_io_test.rb +2 -2
  62. data/test/functional/grid_test.rb +2 -2
  63. data/test/functional/pool_test.rb +2 -3
  64. data/test/functional/safe_test.rb +5 -5
  65. data/test/functional/ssl_test.rb +22 -102
  66. data/test/functional/support_test.rb +1 -1
  67. data/test/functional/timeout_test.rb +6 -22
  68. data/test/functional/uri_test.rb +113 -12
  69. data/test/functional/write_concern_test.rb +6 -6
  70. data/test/helpers/general.rb +50 -0
  71. data/test/helpers/test_unit.rb +309 -0
  72. data/test/replica_set/authentication_test.rb +8 -23
  73. data/test/replica_set/basic_test.rb +41 -14
  74. data/test/replica_set/client_test.rb +179 -117
  75. data/test/replica_set/complex_connect_test.rb +6 -7
  76. data/test/replica_set/connection_test.rb +46 -38
  77. data/test/replica_set/count_test.rb +2 -2
  78. data/test/replica_set/cursor_test.rb +8 -8
  79. data/test/replica_set/insert_test.rb +64 -2
  80. data/test/replica_set/max_values_test.rb +59 -10
  81. data/test/replica_set/pinning_test.rb +2 -2
  82. data/test/replica_set/query_test.rb +2 -2
  83. data/test/replica_set/read_preference_test.rb +6 -6
  84. data/test/replica_set/refresh_test.rb +7 -7
  85. data/test/replica_set/replication_ack_test.rb +5 -5
  86. data/test/replica_set/ssl_test.rb +24 -106
  87. data/test/sharded_cluster/basic_test.rb +43 -15
  88. data/test/shared/authentication/basic_auth_shared.rb +215 -0
  89. data/test/shared/authentication/sasl_plain_shared.rb +96 -0
  90. data/test/shared/ssl_shared.rb +173 -0
  91. data/test/test_helper.rb +31 -199
  92. data/test/threading/basic_test.rb +29 -3
  93. data/test/tools/mongo_config.rb +45 -20
  94. data/test/tools/mongo_config_test.rb +1 -1
  95. data/test/unit/client_test.rb +136 -57
  96. data/test/unit/collection_test.rb +31 -55
  97. data/test/unit/connection_test.rb +135 -72
  98. data/test/unit/cursor_test.rb +2 -2
  99. data/test/unit/db_test.rb +19 -15
  100. data/test/unit/grid_test.rb +2 -2
  101. data/test/unit/mongo_sharded_client_test.rb +17 -15
  102. data/test/unit/node_test.rb +2 -2
  103. data/test/unit/pool_manager_test.rb +7 -5
  104. data/test/unit/read_pref_test.rb +82 -2
  105. data/test/unit/read_test.rb +14 -14
  106. data/test/unit/safe_test.rb +9 -9
  107. data/test/unit/sharding_pool_manager_test.rb +11 -5
  108. data/test/unit/write_concern_test.rb +9 -9
  109. metadata +71 -56
  110. metadata.gz.sig +0 -0
  111. data/test/functional/threading_test.rb +0 -109
  112. data/test/shared/authentication.rb +0 -121
  113. data/test/unit/util_test.rb +0 -69
@@ -1,121 +0,0 @@
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
-
15
- module AuthenticationTests
16
-
17
- def init_auth
18
- # enable authentication by creating and logging in as admin user
19
- @admin = @client['admin']
20
- @admin.add_user('admin', 'password')
21
- @admin.authenticate('admin', 'password')
22
- end
23
-
24
- def teardown
25
- @admin.logout
26
- @admin.authenticate('admin','password')
27
- @admin['system.users'].remove
28
- @db['system.users'].remove
29
- @db['test'].remove
30
- @admin.logout
31
- end
32
-
33
- def test_add_user
34
- @db.add_user('bob','user')
35
- assert @db['system.users'].find_one({:user => 'bob'})
36
- end
37
-
38
- def test_remove_user
39
- @db.remove_user('bob')
40
- assert_nil @db['system.users'].find_one({:user => 'bob'})
41
- end
42
-
43
- def test_remove_non_existent_user
44
- assert_equal @db.remove_user('joe'), false
45
- end
46
-
47
- def test_authenticate
48
- @db.add_user('peggy', 'user')
49
- assert @db.authenticate('peggy', 'user')
50
- @db.remove_user('peggy')
51
- @db.logout
52
- end
53
-
54
- def test_authenticate_non_existent_user
55
- assert_raise Mongo::AuthenticationError do
56
- @db.authenticate('frank', 'thetank')
57
- end
58
- end
59
-
60
- def test_delegated_authentication
61
- return if @client.server_version < '2.4'
62
-
63
- # TODO: remove this line when slaves have this code:
64
- # https://github.com/travis-ci/travis-cookbooks/pull/180
65
- return if ENV['TRAVIS']
66
-
67
- doc = {'_id' => 'test'}
68
- # create accounts database to hold user credentials
69
- accounts = @client['accounts']
70
- accounts['system.users'].remove
71
- accounts.add_user('tyler', 'brock', nil, :roles => [])
72
-
73
- # insert test data and give user permissions on test db
74
- @db['test'].remove
75
- @db['test'].insert(doc)
76
- @db.add_user('tyler', nil, nil, :roles => ['read'], :userSource => 'accounts')
77
- @admin.logout
78
-
79
- # auth must occur on the db where the user is defined
80
- assert_raise Mongo::AuthenticationError do
81
- @db.authenticate('tyler', 'brock')
82
- end
83
-
84
- # auth directly
85
- assert accounts.authenticate('tyler', 'brock')
86
- assert_equal doc, @db['test'].find_one
87
- accounts.logout
88
- assert_raise Mongo::OperationFailure do
89
- @db['test'].find_one
90
- end
91
-
92
- # auth using source
93
- @db.authenticate('tyler', 'brock', true, 'accounts')
94
- assert_equal doc, @db['test'].find_one
95
- @db.logout
96
- assert_raise Mongo::OperationFailure do
97
- @db['test'].find_one
98
- end
99
- end
100
-
101
- def test_logout
102
- @db.add_user('peggy', 'user')
103
- assert @db.authenticate('peggy', 'user')
104
- assert @db.logout
105
- @db.remove_user('peggy')
106
- end
107
-
108
- def test_authenticate_with_special_characters
109
- assert @db.add_user('foo:bar','@foo')
110
- assert @db.authenticate('foo:bar','@foo')
111
- @db.remove_user('foo:bar')
112
- @db.logout
113
- end
114
-
115
- def test_authenticate_read_only
116
- @db.add_user('randy', 'readonly', true)
117
- assert @db.authenticate('randy', 'readonly')
118
- @db.remove_user('randy')
119
- @db.logout
120
- end
121
- end
@@ -1,69 +0,0 @@
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
-
15
- require File.expand_path("../../test_helper", __FILE__)
16
-
17
- class UtilTest < Test::Unit::TestCase
18
- context "Support" do
19
- context ".secondary_ok?" do
20
- should "return false for mapreduces with a string for out" do
21
- assert_equal false, Mongo::Support.secondary_ok?(BSON::OrderedHash[
22
- 'mapreduce', 'test-collection',
23
- 'out', 'new-test-collection'
24
- ])
25
- end
26
-
27
- should "return false for mapreduces replacing a collection" do
28
- assert_equal false, Mongo::Support.secondary_ok?(BSON::OrderedHash[
29
- 'mapreduce', 'test-collection',
30
- 'out', BSON::OrderedHash['replace', 'new-test-collection']
31
- ])
32
- end
33
-
34
- should "return false for mapreduces replacing the inline collection" do
35
- assert_equal false, Mongo::Support.secondary_ok?(BSON::OrderedHash[
36
- 'mapreduce', 'test-collection',
37
- 'out', 'inline'
38
- ])
39
- end
40
-
41
- should "return true for inline output mapreduces when inline is a symbol" do
42
- assert_equal true, Mongo::Support.secondary_ok?(BSON::OrderedHash[
43
- 'mapreduce', 'test-collection',
44
- 'out', BSON::OrderedHash[:inline, 'true']
45
- ])
46
- end
47
-
48
- should "return true for inline output mapreduces when inline is a string" do
49
- assert_equal true, Mongo::Support.secondary_ok?(BSON::OrderedHash[
50
- 'mapreduce', 'test-collection',
51
- 'out', BSON::OrderedHash['inline', 'true']
52
- ])
53
- end
54
-
55
- should 'return true for count' do
56
- assert_equal true, Mongo::Support.secondary_ok?(BSON::OrderedHash[
57
- 'count', 'test-collection',
58
- 'query', BSON::OrderedHash['a', 'b']
59
- ])
60
- end
61
-
62
- should 'return false for serverStatus' do
63
- assert_equal false, Mongo::Support.secondary_ok?(BSON::OrderedHash[
64
- 'serverStatus', 1
65
- ])
66
- end
67
- end
68
- end
69
- end