mongo 1.7.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/{LICENSE.txt → LICENSE} +0 -0
  2. data/README.md +124 -111
  3. data/Rakefile +9 -325
  4. data/VERSION +1 -0
  5. data/bin/mongo_console +4 -4
  6. data/examples/admin.rb +43 -0
  7. data/examples/capped.rb +22 -0
  8. data/examples/cursor.rb +48 -0
  9. data/examples/gridfs.rb +44 -0
  10. data/examples/index_test.rb +126 -0
  11. data/examples/info.rb +31 -0
  12. data/examples/queries.rb +74 -0
  13. data/examples/replica_set.rb +26 -0
  14. data/examples/simple.rb +25 -0
  15. data/examples/strict.rb +35 -0
  16. data/examples/types.rb +36 -0
  17. data/{test/load → examples/web}/thin/load.rb +3 -1
  18. data/{test/load → examples/web}/unicorn/load.rb +5 -3
  19. data/lib/mongo.rb +8 -10
  20. data/lib/mongo/collection.rb +134 -114
  21. data/lib/mongo/cursor.rb +21 -14
  22. data/lib/mongo/db.rb +30 -28
  23. data/lib/mongo/exceptions.rb +1 -1
  24. data/lib/mongo/gridfs/grid.rb +8 -7
  25. data/lib/mongo/gridfs/grid_ext.rb +1 -1
  26. data/lib/mongo/gridfs/grid_file_system.rb +6 -5
  27. data/lib/mongo/gridfs/grid_io.rb +22 -19
  28. data/lib/mongo/legacy.rb +82 -0
  29. data/lib/mongo/{connection.rb → mongo_client.rb} +82 -61
  30. data/lib/mongo/{repl_set_connection.rb → mongo_replica_set_client.rb} +54 -39
  31. data/lib/mongo/{sharded_connection.rb → mongo_sharded_client.rb} +9 -9
  32. data/lib/mongo/networking.rb +25 -20
  33. data/lib/mongo/util/conversions.rb +1 -1
  34. data/lib/mongo/util/core_ext.rb +1 -1
  35. data/lib/mongo/util/logging.rb +20 -4
  36. data/lib/mongo/util/node.rb +16 -16
  37. data/lib/mongo/util/pool.rb +56 -27
  38. data/lib/mongo/util/pool_manager.rb +28 -27
  39. data/lib/mongo/util/server_version.rb +1 -1
  40. data/lib/mongo/util/sharding_pool_manager.rb +8 -8
  41. data/lib/mongo/util/ssl_socket.rb +1 -5
  42. data/lib/mongo/util/support.rb +24 -8
  43. data/lib/mongo/util/tcp_socket.rb +0 -4
  44. data/lib/mongo/util/uri_parser.rb +54 -38
  45. data/lib/mongo/util/write_concern.rb +67 -0
  46. data/mongo.gemspec +21 -32
  47. data/test/auxillary/{1.4_features.rb → 1.4_feature_test.rb} +4 -5
  48. data/test/auxillary/authentication_test.rb +18 -20
  49. data/test/auxillary/autoreconnect_test.rb +3 -5
  50. data/test/auxillary/fork_test.rb +5 -7
  51. data/test/auxillary/repl_set_auth_test.rb +13 -15
  52. data/test/auxillary/slave_connection_test.rb +8 -7
  53. data/test/auxillary/threaded_authentication_test.rb +15 -17
  54. data/test/bson/binary_test.rb +1 -1
  55. data/test/bson/bson_test.rb +60 -36
  56. data/test/bson/byte_buffer_test.rb +1 -1
  57. data/test/bson/hash_with_indifferent_access_test.rb +2 -2
  58. data/test/bson/json_test.rb +1 -2
  59. data/test/bson/object_id_test.rb +1 -2
  60. data/test/bson/ordered_hash_test.rb +1 -1
  61. data/test/bson/timestamp_test.rb +1 -1
  62. data/test/{collection_test.rb → functional/collection_test.rb} +57 -57
  63. data/test/{connection_test.rb → functional/connection_test.rb} +75 -89
  64. data/test/{conversions_test.rb → functional/conversions_test.rb} +1 -1
  65. data/test/{cursor_fail_test.rb → functional/cursor_fail_test.rb} +3 -29
  66. data/test/{cursor_message_test.rb → functional/cursor_message_test.rb} +1 -1
  67. data/test/{cursor_test.rb → functional/cursor_test.rb} +5 -1
  68. data/test/{db_api_test.rb → functional/db_api_test.rb} +8 -9
  69. data/test/{db_connection_test.rb → functional/db_connection_test.rb} +3 -5
  70. data/test/{db_test.rb → functional/db_test.rb} +13 -13
  71. data/test/{grid_file_system_test.rb → functional/grid_file_system_test.rb} +2 -2
  72. data/test/{grid_io_test.rb → functional/grid_io_test.rb} +6 -6
  73. data/test/{grid_test.rb → functional/grid_test.rb} +4 -10
  74. data/test/{pool_test.rb → functional/pool_test.rb} +1 -1
  75. data/test/functional/safe_test.rb +84 -0
  76. data/test/{support_test.rb → functional/support_test.rb} +1 -1
  77. data/test/{threading_test.rb → functional/threading_test.rb} +9 -9
  78. data/test/{timeout_test.rb → functional/timeout_test.rb} +1 -1
  79. data/test/{uri_test.rb → functional/uri_test.rb} +1 -1
  80. data/test/functional/write_concern_test.rb +104 -0
  81. data/test/replica_set/basic_test.rb +139 -0
  82. data/test/replica_set/client_test.rb +255 -0
  83. data/test/replica_set/complex_connect_test.rb +62 -0
  84. data/test/replica_set/connection_test.rb +255 -0
  85. data/test/{replica_sets → replica_set}/count_test.rb +17 -14
  86. data/test/replica_set/cursor_test.rb +75 -0
  87. data/test/{replica_sets → replica_set}/insert_test.rb +19 -16
  88. data/test/replica_set/query_test.rb +64 -0
  89. data/test/replica_set/refresh_test.rb +153 -0
  90. data/test/{replica_sets → replica_set}/replication_ack_test.rb +21 -17
  91. data/test/sharded_cluster/basic_test.rb +31 -50
  92. data/test/support/hash_with_indifferent_access.rb +1 -1
  93. data/test/test_helper.rb +56 -9
  94. data/test/threading/threading_with_large_pool_test.rb +8 -8
  95. data/test/tools/mongo_config.rb +270 -58
  96. data/test/tools/mongo_config_test.rb +146 -0
  97. data/test/unit/client_test.rb +230 -0
  98. data/test/unit/collection_test.rb +45 -32
  99. data/test/unit/connection_test.rb +82 -74
  100. data/test/unit/cursor_test.rb +14 -6
  101. data/test/unit/db_test.rb +8 -8
  102. data/test/unit/grid_test.rb +11 -11
  103. data/test/unit/node_test.rb +24 -24
  104. data/test/unit/pool_manager_test.rb +13 -13
  105. data/test/unit/pool_test.rb +1 -1
  106. data/test/unit/read_test.rb +21 -26
  107. data/test/unit/safe_test.rb +52 -33
  108. data/test/unit/util_test.rb +55 -0
  109. data/test/unit/write_concern_test.rb +161 -0
  110. metadata +158 -171
  111. data/docs/CREDITS.md +0 -123
  112. data/docs/FAQ.md +0 -116
  113. data/docs/GRID_FS.md +0 -158
  114. data/docs/HISTORY.md +0 -392
  115. data/docs/READ_PREFERENCE.md +0 -99
  116. data/docs/RELEASES.md +0 -54
  117. data/docs/REPLICA_SETS.md +0 -113
  118. data/docs/TAILABLE_CURSORS.md +0 -51
  119. data/docs/TUTORIAL.md +0 -356
  120. data/docs/WRITE_CONCERN.md +0 -31
  121. data/lib/mongo/gridfs/grid_io_fix.rb +0 -38
  122. data/lib/mongo/version.rb +0 -3
  123. data/test/bson/test_helper.rb +0 -30
  124. data/test/replica_sets/basic_test.rb +0 -119
  125. data/test/replica_sets/complex_connect_test.rb +0 -57
  126. data/test/replica_sets/complex_read_preference_test.rb +0 -237
  127. data/test/replica_sets/connect_test.rb +0 -156
  128. data/test/replica_sets/cursor_test.rb +0 -70
  129. data/test/replica_sets/pooled_insert_test.rb +0 -57
  130. data/test/replica_sets/query_test.rb +0 -50
  131. data/test/replica_sets/read_preference_test.rb +0 -234
  132. data/test/replica_sets/refresh_test.rb +0 -156
  133. data/test/replica_sets/refresh_with_threads_test.rb +0 -60
  134. data/test/replica_sets/rs_test_helper.rb +0 -39
  135. data/test/safe_test.rb +0 -68
  136. data/test/sharded_cluster/mongo_config_test.rb +0 -126
  137. data/test/sharded_cluster/sc_test_helper.rb +0 -39
  138. data/test/tools/repl_set_manager.rb +0 -418
File without changes
data/README.md CHANGED
@@ -1,3 +1,13 @@
1
+ [![Build Status][travis-img]][travis-url] [![Jenkins Status][jenkins-img]][jenkins-url] [![Code Climate][codeclimate-img]][codeclimate-url]
2
+
3
+ [travis-img]: https://secure.travis-ci.org/mongodb/mongo-ruby-driver.png
4
+ [travis-url]: http://travis-ci.org/mongodb/mongo-ruby-driver
5
+ [codeclimate-img]: https://codeclimate.com/badge.png
6
+ [codeclimate-url]: https://codeclimate.com/github/mongodb/mongo-ruby-driver
7
+ [jenkins-img]: https://jenkins.10gen.com/job/mongo-ruby-driver/badge/icon
8
+ [jenkins-url]: https://jenkins.10gen.com/job/mongo-ruby-driver/
9
+ [api-url]: http://api.mongodb.org/ruby/current
10
+
1
11
  # Documentation
2
12
 
3
13
  This API documentation is available online at [http://api.mongodb.org/ruby](http://api.mongodb.org/ruby)
@@ -8,103 +18,84 @@ has a link to API Documentation for the current release.
8
18
 
9
19
  If you have the source, you can generate the matching documentation by typing
10
20
 
11
- $ rake ydoc
21
+ $ rake docs
12
22
 
13
- Then open the file ydoc/index.html in your browser.
23
+ Once generated, the API documentation can be found in the docs/ folder.
14
24
 
15
25
  # Introduction
16
26
 
17
27
  This is the 10gen-supported Ruby driver for [MongoDB](http://www.mongodb.org).
18
28
 
19
- For the reference manual, use the links in the upper-left and upper-right corners for quick navigation to the following.
29
+ For the api reference please see the [API][api-url]
20
30
 
21
- * [Alphabetic Index](_index.html)
22
- * [Class List](class_list.html)
23
- * [Method List](method_list.html)
24
- * [File List](file_list.html)
31
+ The [wiki](https://github.com/mongodb/mongo-ruby-driver/wiki) has other articles of interest, including:
25
32
 
26
- This documentation has other articles of interest, including:
33
+ 1. [A tutorial](https://github.com/mongodb/mongo-ruby-driver/wiki/Tutorial).
34
+ 2. [Replica Sets in Ruby](https://github.com/mongodb/mongo-ruby-driver/wiki/Replica-Sets).
35
+ 3. [Write Concern in Ruby](https://github.com/mongodb/mongo-ruby-driver/wiki/Write-Concern).
36
+ 4. [Tailable Cursors in Ruby](https://github.com/mongodb/mongo-ruby-driver/wiki/Tailable-Cursors).
37
+ 5. [Read Preference in Ruby](https://github.com/mongodb/mongo-ruby-driver/wiki/Read-Preference).
38
+ 6. [GridFS in Ruby](https://github.com/mongodb/mongo-ruby-driver/wiki/GridFS).
39
+ 7. [Frequently Asked Questions](https://github.com/mongodb/mongo-ruby-driver/wiki/FAQ).
40
+ 8. [History](https://github.com/mongodb/mongo-ruby-driver/wiki/History).
41
+ 9. [Release plan](https://github.com/mongodb/mongo-ruby-driver/wiki/Releases).
42
+ 10. [Credits](https://github.com/mongodb/mongo-ruby-driver/wiki/Credits).
27
43
 
28
- 1. [A tutorial](file.TUTORIAL.html).
29
- 2. [Replica Sets in Ruby](file.REPLICA_SETS.html).
30
- 3. [Write Concern in Ruby](file.WRITE_CONCERN.html).
31
- 4. [Tailable Cursors in Ruby](file.TAILABLE_CURSORS.html).
32
- 5. [Read Preference in Ruby](file.READ_PREFERENCE.html).
33
- 6. [GridFS in Ruby](file.GRID_FS.html).
34
- 7. [Frequently Asked Questions](file.FAQ.html).
35
- 8. [History](file.HISTORY.html).
36
- 9. [Release plan](file.RELEASES.html).
37
- 10. [Credits](file.CREDITS.html).
44
+ Here's a quick code sample. Again, see the [MongoDB Ruby Tutorial](https://github.com/mongodb/mongo-ruby-driver/wiki/Tutorial) for much more:
38
45
 
39
- Here's a quick code sample. Again, see the [MongoDB Ruby Tutorial](file.TUTORIAL.html)
40
- for much more:
46
+ ```ruby
47
+ require 'rubygems'
48
+ require 'mongo'
41
49
 
42
- require 'rubygems'
43
- require 'mongo'
50
+ include Mongo
44
51
 
45
- @conn = Mongo::Connection.new
46
- @db = @conn['sample-db']
47
- @coll = @db['test']
52
+ @client = MongoClient.new('localhost', 27017)
53
+ @db = @client['sample-db']
54
+ @coll = @db['test']
48
55
 
49
- @coll.remove
50
- 3.times do |i|
51
- @coll.insert({'a' => i+1})
52
- end
56
+ @coll.remove
53
57
 
54
- puts "There are #{@coll.count} records. Here they are:"
55
- @coll.find.each { |doc| puts doc.inspect }
58
+ 3.times do |i|
59
+ @coll.insert({'a' => i+1})
60
+ end
61
+
62
+ puts "There are #{@coll.count} records. Here they are:"
63
+ @coll.find.each { |doc| puts doc.inspect }
64
+ ```
56
65
 
57
66
  # Installation
58
67
 
59
68
  ### Ruby Versions
60
69
 
61
- The driver works and is consistently tested on Ruby 1.8.7 and 1.9.3 as well as JRuby 1.6.6.
70
+ The driver works and is consistently tested on Ruby 1.8.7 and 1.9.3 as well as JRuby 1.6.x and 1.7.x.
62
71
 
63
- Note that if you're on 1.8.7, be sure that you're using a patchlevel >= 249. There
64
- are some IO bugs in earlier versions.
72
+ Note that if you're on 1.8.7, be sure that you're using a patchlevel >= 249. There are some IO bugs in earlier versions.
65
73
 
66
74
  ### Gems
67
75
 
68
- The driver's gems are hosted at [Rubygems.org](http://rubygems.org). Make sure you're
69
- using the latest version of rubygems:
70
-
71
76
  $ gem update --system
72
-
73
- Then you can install the mongo gem as follows:
74
-
75
77
  $ gem install mongo
76
78
 
77
- The driver also requires the bson gem:
78
-
79
- $ gem install bson
80
-
81
- And for a significant performance boost, you'll want to install the C extensions:
79
+ For a significant performance boost, you'll want to install the C extension:
82
80
 
83
81
  $ gem install bson_ext
84
82
 
85
- Note that bson_ext isn't used with JRuby. Instead, some native Java extensions are bundled with the bson gem.
86
- If you ever need to modify these extensions, you can recompile with the following rake task:
83
+ Note that bson_ext isn't used with JRuby. Instead, we use some native Java extensions are bundled with the bson gem. If you ever need to modify these extensions, you can recompile with the following rake task:
87
84
 
88
- $ rake build:java
85
+ $ rake compile:jbson
89
86
 
90
87
  ### From the GitHub source
91
88
 
92
89
  The source code is available at http://github.com/mongodb/mongo-ruby-driver.
93
90
  You can either clone the git repository or download a tarball or zip file.
94
91
  Once you have the source, you can use it from wherever you downloaded it or
95
- you can install it as a gem from the source by typing
96
-
97
- $ rake gem:install
98
-
99
- To install the C extensions from source, type this instead:
92
+ you can install it as a gem from the source by typing:
100
93
 
101
- $ rake gem:install_extensions
102
-
103
- That's all there is to it!
94
+ $ rake install
104
95
 
105
96
  # Examples
106
97
 
107
- For extensive examples, see the [MongoDB Ruby Tutorial](file.TUTORIAL.html).
98
+ For extensive examples, see the [MongoDB Ruby Tutorial](https://github.com/mongodb/mongo-ruby-driver/wiki/Tutorial).
108
99
 
109
100
  Bundled with the driver are many examples, located in the "docs/examples" subdirectory. Samples include using
110
101
  the driver and using the GridFS class GridStore. MongoDB must be running for
@@ -133,19 +124,21 @@ features (metadata, content type, seek, tell, etc).
133
124
 
134
125
  Examples:
135
126
 
136
- # Write a file on disk to the Grid
137
- file = File.open('image.jpg')
138
- grid = Mongo::Grid.new(db)
139
- id = grid.put(file)
127
+ ```ruby
128
+ # Write a file on disk to the Grid
129
+ file = File.open('image.jpg')
130
+ grid = Mongo::Grid.new(db)
131
+ id = grid.put(file)
140
132
 
141
- # Retrieve the file
142
- file = grid.get(id)
143
- file.read
133
+ # Retrieve the file
134
+ file = grid.get(id)
135
+ file.read
144
136
 
145
- # Get all the file's metata
146
- file.filename
147
- file.content_type
148
- file.metadata
137
+ # Get all the file's metata
138
+ file.filename
139
+ file.content_type
140
+ file.metadata
141
+ ```
149
142
 
150
143
  # Notes
151
144
 
@@ -162,7 +155,9 @@ timeout for waiting for old connections to be released to the pool.
162
155
 
163
156
  To set up a pooled connection to a single MongoDB instance:
164
157
 
165
- @conn = Connection.new("localhost", 27017, :pool_size => 5, :timeout => 5)
158
+ ```ruby
159
+ @client = MongoClient.new("localhost", 27017, :pool_size => 5, :timeout => 5)
160
+ ```
166
161
 
167
162
  Though the pooling architecture will undoubtedly evolve, it currently owes much credit
168
163
  to the connection pooling implementations in ActiveRecord and PyMongo.
@@ -175,13 +170,13 @@ of v1.3.0, the Ruby driver detects forking and reconnects automatically.
175
170
 
176
171
  ## Environment variable `MONGODB_URI`
177
172
 
178
- `Mongo::Connection.from_uri`, `Mongo::Connection.new` and `Mongo::ReplSetConnection.new` will use <code>ENV["MONGODB_URI"]</code> if no other args are provided.
173
+ `Mongo::MongoClient.from_uri`, `Mongo::MongoClient.new` and `Mongo::MongoReplicaSetClient.new` will use <code>ENV["MONGODB_URI"]</code> if no other args are provided.
179
174
 
180
175
  The URI must fit this specification:
181
176
 
182
177
  mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
183
178
 
184
- If the type of connection (direct or replica set) should be determined entirely from <code>ENV["MONGODB_URI"]</code>, you may want to use `Mongo::Connection.from_uri` because it will return either `Mongo::Connection` or a `Mongo::ReplSetConnection` depending on how many hosts are specified. Trying to use `Mongo::Connection.new` with multiple hosts in <code>ENV["MONGODB_URI"]</code> will raise an exception.
179
+ If the type of connection (direct or replica set) should be determined entirely from <code>ENV["MONGODB_URI"]</code>, you may want to use `Mongo::MongoClient.from_uri` because it will return either `Mongo::MongoClient` or a `Mongo::MongoReplicaSetClient` depending on how many hosts are specified. Trying to use `Mongo::MongoClient.new` with multiple hosts in <code>ENV["MONGODB_URI"]</code> will raise an exception.
185
180
 
186
181
  ## String Encoding
187
182
 
@@ -211,9 +206,12 @@ generate _id values. If you want to control _id values or even their types,
211
206
  using a PK factory lets you do so.
212
207
 
213
208
  You can tell the Ruby Mongo driver how to create primary keys by passing in
214
- the :pk option to the Connection#db method.
209
+ the :pk option to the MongoClient#db method.
215
210
 
216
- db = Mongo::Connection.new.db('dbname', :pk => MyPKFactory.new)
211
+ ```ruby
212
+ include Mongo
213
+ db = MongoClient.new('localhost', 27017).db('dbname', :pk => MyPKFactory.new)
214
+ ```
217
215
 
218
216
  A primary key factory object must respond to :create_pk, which should
219
217
  take a hash and return a hash which merges the original hash with any
@@ -226,27 +224,28 @@ database. The idea here is that whenever a record is inserted, the
226
224
  returned will be inserted.
227
225
 
228
226
  Here is a sample primary key factory, taken from the tests:
229
-
230
- class TestPKFactory
231
- def create_pk(row)
232
- row['_id'] ||= BSON::ObjectId.new
233
- row
234
- end
235
- end
236
-
227
+ ```ruby
228
+ class TestPKFactory
229
+ def create_pk(doc)
230
+ doc['_id'] ||= BSON::ObjectId.new
231
+ doc
232
+ end
233
+ end
234
+ ```
237
235
  Here's a slightly more sophisticated one that handles both symbol and string
238
236
  keys. This is the PKFactory that comes with the MongoRecord code (an
239
237
  ActiveRecord-like framework for non-Rails apps) and the AR Mongo adapter code
240
238
  (for Rails):
241
-
242
- class PKFactory
243
- def create_pk(row)
244
- return row if row[:_id]
245
- row.delete(:_id) # in case it exists but the value is nil
246
- row['_id'] ||= BSON::ObjectId.new
247
- row
248
- end
249
- end
239
+ ```ruby
240
+ class PKFactory
241
+ def create_pk(doc)
242
+ return doc if doc[:_id]
243
+ doc.delete(:_id) # in case it exists but the value is nil
244
+ doc['_id'] ||= BSON::ObjectId.new
245
+ doc
246
+ end
247
+ end
248
+ ```
250
249
 
251
250
  A database's PK factory object may be set either when a DB object is created
252
251
  or immediately after you obtain it, but only once. The only reason it is
@@ -266,11 +265,13 @@ completely harmless; strict mode is a programmer convenience only.
266
265
  To turn on strict mode, either pass in :strict => true when obtaining a DB
267
266
  object or call the `:strict=` method:
268
267
 
269
- db = Connection.new.db('dbname', :strict => true)
270
- # I'm feeling lax
271
- db.strict = false
272
- # No, I'm not!
273
- db.strict = true
268
+ ```ruby
269
+ db = MongoClient.new('localhost', 27017).db('dbname', :strict => true)
270
+ # I'm feeling lax
271
+ db.strict = false
272
+ # No, I'm not!
273
+ db.strict = true
274
+ ```
274
275
 
275
276
  The method DB#strict? returns the current value of that flag.
276
277
 
@@ -289,26 +290,21 @@ Notes:
289
290
  ## Socket timeouts
290
291
 
291
292
  The Ruby driver support timeouts on socket read operations. To enable them, set the
292
- `:op_timeout` option when you create a `Mongo::Connection` object.
293
+ `:op_timeout` option when you create a `Mongo::MongoClient` object.
293
294
 
294
295
  If implementing higher-level timeouts, using tools like `Rack::Timeout`, it's very important
295
- to call `Mongo::Connection#close` to prevent the subsequent operation from receiving the previous
296
+ to call `Mongo::MongoClient#close` to prevent the subsequent operation from receiving the previous
296
297
  request.
297
298
 
298
- ### Test-Unit, Shoulda, and Mocha
299
+ # Testing
299
300
 
300
- Running the test suite requires test-unit, shoulda, and mocha. You can install them as follows:
301
+ Before running the tests, make sure you install all test dependencies by running:
301
302
 
302
- $ gem install test-unit
303
- $ gem install shoulda
304
- $ gem install mocha
303
+ $ gem install bundler; bundle install
305
304
 
306
- The tests assume that the Mongo database is running on the default port. You
307
- can override the default host (localhost) and port (Connection::DEFAULT_PORT) by
308
- using the environment variables MONGO_RUBY_DRIVER_HOST and
309
- MONGO_RUBY_DRIVER_PORT.
305
+ To run all default test suites, just type:
310
306
 
311
- # Testing
307
+ $ rake test
312
308
 
313
309
  If you have the source code, you can run the tests. Skip this test with the C extension if you're running JRuby.
314
310
 
@@ -329,15 +325,32 @@ To run any individual rake tasks with the C extension enabled, just pass C_EXT=t
329
325
 
330
326
  If you want to test replica set, you can run the following task:
331
327
 
332
- $ rake test:rs
328
+ $ rake test:replica_set
329
+
330
+ To run a single test at the top level, add -Itest since we no longer modify LOAD_PATH:
331
+
332
+ $ ruby -Itest -Ilib test/bson/bson_test.rb
333
+
334
+ To run a single test from the test directory, add -I. since we no longer modify LOAD_PATH:
335
+
336
+ $ ruby -I. -I../lib bson/bson_test.rb
337
+
338
+ To run a single test from its subdirectory, add -I.. since we no longer modify LOAD_PATH:
339
+
340
+ $ ruby -I.. -I../../lib bson_test.rb
341
+
342
+ To fix the following error on Mac OS X - "/.../lib/bson_ext/cbson.bundle: [BUG] Segmentation fault":
343
+
344
+ $ rake compile
333
345
 
334
346
  # Release Notes
335
347
 
336
- See HISTORY.
348
+ See [history](https://github.com/mongodb/mongo-ruby-driver/wiki/History).
349
+
337
350
 
338
351
  # Credits
339
352
 
340
- See CREDITS.
353
+ See [credits](https://github.com/mongodb/mongo-ruby-driver/wiki/Credits).
341
354
 
342
355
  # License
343
356
 
@@ -347,7 +360,7 @@ See CREDITS.
347
360
  you may not use this file except in compliance with the License.
348
361
  You may obtain a copy of the License at
349
362
 
350
- http://www.apache.org/licenses/LICENSE-2.0
363
+ http://www.apache.org/licenses/LICENSE-2.0
351
364
 
352
365
  Unless required by applicable law or agreed to in writing, software
353
366
  distributed under the License is distributed on an "AS IS" BASIS,
data/Rakefile CHANGED
@@ -1,333 +1,17 @@
1
1
  # -*- mode: ruby; -*-
2
- if RUBY_VERSION < '1.9.0'
3
- require 'rubygems'
4
- require 'rubygems/specification'
5
- end
6
2
 
7
- require 'fileutils'
8
- require 'rake/testtask'
9
- require 'rake'
10
- require 'rake/extensiontask'
11
- require 'rake/javaextensiontask'
3
+ require 'rubygems'
12
4
 
13
5
  begin
14
- require 'git'
15
- require 'devkit'
16
- require 'ci/reporter/rake/test_unit'
17
- rescue LoadError
18
- end
19
-
20
- ENV['TEST_MODE'] = 'TRUE'
21
-
22
- Rake::ExtensionTask.new('cbson') do |ext|
23
- ext.lib_dir = "lib/bson_ext"
24
- end
25
-
26
- #Rake::JavaExtensionTask.new('jbson') do |ext| # not yet functional
27
- # ext.ext_dir = 'ext/src/org/jbson'
28
- #end
29
-
30
- desc "Compiles and tests MongoDB Ruby driver w/ C extensions."
31
- task :c do
32
- Rake::Task['compile:cbson'].invoke
33
- Rake::Task['test:c'].invoke
34
- end
35
-
36
- task :java do
37
- Rake::Task['build:java'].invoke
38
- Rake::Task['test:ruby'].invoke
39
- end
40
-
41
- namespace :build do
42
- desc "Build the java extensions."
43
- task :java do
44
- puts "Building Java extensions..."
45
- java_dir = File.join(File.dirname(__FILE__), 'ext', 'java')
46
- jar_dir = File.join(java_dir, 'jar')
47
-
48
- jruby_jar = File.join(jar_dir, 'jruby.jar')
49
- mongo_jar = File.join(jar_dir, 'mongo-2.6.5.jar')
50
-
51
- src_base = File.join(java_dir, 'src')
52
-
53
- system("javac -Xlint:deprecation -Xlint:unchecked -classpath #{jruby_jar}:#{mongo_jar} #{File.join(src_base, 'org', 'jbson', '*.java')}")
54
- system("cd #{src_base} && jar cf #{File.join(jar_dir, 'jbson.jar')} #{File.join('.', 'org', 'jbson', '*.class')}")
55
- end
56
- end
57
-
58
- desc "Test the MongoDB Ruby driver."
59
- task :test do
60
- puts "\nTo test the driver with the C-extensions:\nrake test:c\n\n"
61
- puts "To test the pure ruby driver: \nrake test:ruby\n\n"
62
- end
63
-
64
- task :path do
65
- $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
66
- end
67
-
68
- namespace :test do
69
-
70
- desc "Test the driver with the C extension enabled."
71
- task :c => :path do
72
- ENV['C_EXT'] = 'TRUE'
73
- if ENV['TEST']
74
- Rake::Task['test:functional'].invoke
75
- else
76
- Rake::Task['test:unit'].invoke
77
- Rake::Task['test:functional'].invoke
78
- Rake::Task['test:bson'].invoke
79
- Rake::Task['test:pooled_threading'].invoke
80
- Rake::Task['test:drop_databases'].invoke
81
- end
82
- ENV['C_EXT'] = nil
83
- end
84
-
85
- desc "Test the driver using pure ruby (no C extension)"
86
- task :ruby => :path do
87
- ENV['C_EXT'] = nil
88
- if ENV['TEST']
89
- Rake::Task['test:functional'].invoke
90
- else
91
- Rake::Task['test:unit'].invoke
92
- Rake::Task['test:functional'].invoke
93
- Rake::Task['test:bson'].invoke
94
- Rake::Task['test:pooled_threading'].invoke
95
- Rake::Task['test:drop_databases'].invoke
96
- end
97
- end
98
-
99
- desc "Run the replica set test suite"
100
- Rake::TestTask.new(:rs) do |t|
101
- t.test_files = FileList['test/replica_sets/*_test.rb']
102
- t.ruby_opts << '-w'
103
- end
104
-
105
- desc "Run the replica set test suite"
106
- Rake::TestTask.new(:rs_no_threads) do |t|
107
- t.test_files = FileList['test/replica_sets/*_test.rb'] - ["test/replica_sets/refresh_with_threads_test.rb"]
108
- t.ruby_opts << '-w'
109
- end
110
-
111
- desc "Run the sharded cluster test suite"
112
- Rake::TestTask.new(:sc) do |t|
113
- t.test_files = FileList['test/sharded_cluster/*_test.rb']
114
- t.ruby_opts << '-w'
115
- end
116
-
117
- Rake::TestTask.new(:unit) do |t|
118
- t.test_files = FileList['test/unit/*_test.rb']
119
- t.ruby_opts << '-w'
120
- end
121
-
122
- Rake::TestTask.new(:functional) do |t|
123
- t.test_files = FileList['test/*_test.rb']
124
- t.ruby_opts << '-w'
125
- end
126
-
127
- Rake::TestTask.new(:pooled_threading) do |t|
128
- t.test_files = FileList['test/threading/*_test.rb']
129
- t.ruby_opts << '-w'
130
- end
131
-
132
- Rake::TestTask.new(:auto_reconnect) do |t|
133
- t.test_files = FileList['test/auxillary/autoreconnect_test.rb']
134
- t.ruby_opts << '-w'
135
- end
136
-
137
- Rake::TestTask.new(:authentication) do |t|
138
- t.test_files = FileList['test/auxillary/authentication_test.rb']
139
- t.ruby_opts << '-w'
140
- end
141
-
142
- Rake::TestTask.new(:new_features) do |t|
143
- t.test_files = FileList['test/auxillary/1.4_features.rb']
144
- t.ruby_opts << '-w'
145
- end
146
-
147
- Rake::TestTask.new(:bson) do |t|
148
- t.test_files = FileList['test/bson/*_test.rb']
149
- t.ruby_opts << '-w'
150
- end
151
-
152
- task :drop_databases => :path do |t|
153
- puts "Dropping test databases..."
154
- require 'mongo'
155
- con = Mongo::Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
156
- ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Connection::DEFAULT_PORT)
157
- con.database_names.each do |name|
158
- con.drop_database(name) if name =~ /^ruby-test/
159
- end
160
- end
6
+ require 'bundler'
7
+ rescue LoadError
8
+ raise '[FAIL] Bundler not found! Install it with `gem install bundler; bundle install`.'
161
9
  end
162
10
 
163
- desc "Generate RDOC documentation"
164
- task :rdoc do
165
- version = eval(File.read("mongo.gemspec")).version
166
- out = File.join('html', version.to_s)
167
- FileUtils.rm_rf('html')
168
- system "rdoc --main README.md --op #{out} --inline-source --quiet README.md `find lib -name '*.rb'`"
11
+ if ENV['TEST']
12
+ Bundler.require(:default, :testing)
13
+ else
14
+ Bundler.require(:default, :deploy, :testing)
169
15
  end
170
16
 
171
- desc "Generate YARD documentation"
172
- task :ydoc do
173
- require './lib/mongo/version.rb'
174
- out = File.join('ydoc', Mongo::VERSION)
175
- FileUtils.rm_rf('ydoc')
176
- system "yardoc -o #{out} --title MongoRuby-#{Mongo::VERSION}"
177
- end
178
-
179
- namespace :jenkins do
180
- task :ci_reporter do
181
- begin
182
- require 'ci/reporter/rake/test_unit'
183
- rescue LoadError
184
- warn "Warning: Unable to load ci_reporter gem."
185
- end
186
- end
187
-
188
- namespace :test do
189
- task :ruby do
190
- Rake::Task['test:ruby'].invoke
191
- end
192
-
193
- task :c do
194
- Rake::Task['gem:install_extensions'].invoke
195
- Rake::Task['test:c'].invoke
196
- end
197
- end
198
- end
199
-
200
- namespace :gem do
201
- desc "Install the gem locally"
202
- task :install do
203
- `gem build bson.gemspec`
204
- `gem install --no-rdoc --no-ri bson-*.gem`
205
-
206
- `gem build mongo.gemspec`
207
- `gem install --no-rdoc --no-ri mongo-*.gem`
208
-
209
- `rm mongo-*.gem`
210
- `rm bson-*.gem`
211
- end
212
-
213
- desc "Uninstall the optional c extensions"
214
- task :uninstall_extensions do
215
- `gem uninstall bson_ext`
216
- end
217
-
218
- desc "Install the optional c extensions"
219
- task :install_extensions do
220
- `gem build bson_ext.gemspec`
221
- `gem install --no-rdoc --no-ri bson_ext-*.gem`
222
- `rm bson_ext-*.gem`
223
- end
224
- end
225
-
226
- namespace :ci do
227
- namespace :test do
228
- task :c => :path do
229
- Rake::Task['gem:install'].invoke
230
- Rake::Task['gem:install_extensions'].invoke
231
- Rake::Task['test:c'].invoke
232
- end
233
- end
234
- end
235
-
236
- # Deployment
237
- VERSION_FILES = %w(lib/bson/version.rb lib/mongo/version.rb ext/cbson/version.h)
238
- GEMSPECS = %w(bson.gemspec bson.java.gemspec bson_ext.gemspec mongo.gemspec)
239
-
240
- def gem_list(version)
241
- files = []
242
- files << "bson-#{version}.gem"
243
- files << "bson-#{version}-java.gem"
244
- files << "bson_ext-#{version}.gem"
245
- files << "mongo-#{version}.gem"
246
- return files
247
- end
248
-
249
- def check_gem_list_existence(version)
250
- gem_list(version).each do |filename|
251
- if !File.exists?(filename)
252
- raise "#{filename} does not exist!"
253
- end
254
- end
255
- end
256
-
257
- def check_version(version)
258
- if !(version =~ /(\d).(\d).(\d)(.rc(\d))?/)
259
- raise "Must specify a valid version (e.g., x.y.z)"
260
- end
261
- end
262
-
263
- def current_version
264
- f = File.open("lib/mongo/version.rb")
265
- str = f.read
266
- str =~ /VERSION\s+=\s+([.\drc"]+)$/
267
- return $1
268
- end
269
-
270
- def change_version(new_version)
271
- version = current_version
272
- puts "Changing version from #{version} to #{new_version}"
273
- VERSION_FILES.each do |filename|
274
- f = File.open(filename)
275
- str = f.read
276
- f.close
277
- str.gsub!(version, "\"#{new_version}\"")
278
- File.open(filename, 'w') do |f|
279
- f.write(str)
280
- end
281
- end
282
- end
283
-
284
- namespace :deploy do
285
- desc "Change version to new release"
286
- task :change_version, [:version] do |t, args|
287
- check_version(args[:version])
288
- change_version(args[:version])
289
- end
290
-
291
- desc "Add version files, commit, tag release"
292
- task :git_prepare do |t, args|
293
- g = Git.open(Dir.getwd())
294
- version = current_version
295
- to_commit = VERSION_FILES << 'docs/HISTORY.md'
296
- g.add(to_commit)
297
- g.commit "RELEASE #{version}"
298
- g.add_tag("#{version}")
299
- end
300
-
301
- desc "Push release to github"
302
- task :git_push do
303
- g = Git.open(Dir.getwd())
304
- g.push
305
- end
306
-
307
- desc "Build all gems"
308
- task :gem_build do
309
- `rm *.gem`
310
- `gem build mongo.gemspec`
311
- `gem build bson.gemspec`
312
- `gem build bson.java.gemspec`
313
- `gem build bson_ext.gemspec`
314
- puts `ls *.gem`
315
- end
316
-
317
- desc "Push all gems to RubyGems"
318
- task :gem_push do |t, args|
319
- check_gem_list_existence(current_version)
320
- gem_list.each do |gem|
321
- puts "Push #{gem} to RubyGems? (y/N)"
322
- if gets.chomp! == 'y'
323
- system "gem push #{gem}"
324
- end
325
- end
326
- end
327
- end
328
-
329
- task :default => :list
330
-
331
- task :list do
332
- system 'rake -T'
333
- end
17
+ Dir.glob(File.join('tasks', '**', '*.rake')).sort.each { |rake| load File.expand_path(rake) }