mongo 1.0 → 1.1.5

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 (95) hide show
  1. data/LICENSE.txt +1 -13
  2. data/{README.rdoc → README.md} +129 -149
  3. data/Rakefile +94 -58
  4. data/bin/mongo_console +21 -0
  5. data/docs/1.0_UPGRADE.md +21 -0
  6. data/docs/CREDITS.md +123 -0
  7. data/docs/FAQ.md +112 -0
  8. data/docs/GridFS.md +158 -0
  9. data/docs/HISTORY.md +185 -0
  10. data/docs/REPLICA_SETS.md +75 -0
  11. data/docs/TUTORIAL.md +247 -0
  12. data/docs/WRITE_CONCERN.md +28 -0
  13. data/lib/mongo/collection.rb +225 -105
  14. data/lib/mongo/connection.rb +374 -315
  15. data/lib/mongo/cursor.rb +122 -77
  16. data/lib/mongo/db.rb +109 -85
  17. data/lib/mongo/exceptions.rb +6 -0
  18. data/lib/mongo/gridfs/grid.rb +19 -11
  19. data/lib/mongo/gridfs/grid_ext.rb +36 -9
  20. data/lib/mongo/gridfs/grid_file_system.rb +15 -9
  21. data/lib/mongo/gridfs/grid_io.rb +49 -16
  22. data/lib/mongo/gridfs/grid_io_fix.rb +38 -0
  23. data/lib/mongo/repl_set_connection.rb +290 -0
  24. data/lib/mongo/util/conversions.rb +3 -1
  25. data/lib/mongo/util/core_ext.rb +17 -4
  26. data/lib/mongo/util/pool.rb +125 -0
  27. data/lib/mongo/util/server_version.rb +2 -0
  28. data/lib/mongo/util/support.rb +12 -0
  29. data/lib/mongo/util/uri_parser.rb +71 -0
  30. data/lib/mongo.rb +23 -7
  31. data/{mongo-ruby-driver.gemspec → mongo.gemspec} +9 -7
  32. data/test/auxillary/1.4_features.rb +2 -2
  33. data/test/auxillary/authentication_test.rb +1 -1
  34. data/test/auxillary/autoreconnect_test.rb +1 -1
  35. data/test/{slave_connection_test.rb → auxillary/slave_connection_test.rb} +6 -6
  36. data/test/bson/binary_test.rb +15 -0
  37. data/test/bson/bson_test.rb +537 -0
  38. data/test/bson/byte_buffer_test.rb +190 -0
  39. data/test/bson/hash_with_indifferent_access_test.rb +38 -0
  40. data/test/bson/json_test.rb +17 -0
  41. data/test/bson/object_id_test.rb +141 -0
  42. data/test/bson/ordered_hash_test.rb +197 -0
  43. data/test/collection_test.rb +195 -15
  44. data/test/connection_test.rb +93 -56
  45. data/test/conversions_test.rb +1 -1
  46. data/test/cursor_fail_test.rb +75 -0
  47. data/test/cursor_message_test.rb +43 -0
  48. data/test/cursor_test.rb +93 -32
  49. data/test/db_api_test.rb +28 -55
  50. data/test/db_connection_test.rb +2 -3
  51. data/test/db_test.rb +45 -40
  52. data/test/grid_file_system_test.rb +14 -6
  53. data/test/grid_io_test.rb +36 -7
  54. data/test/grid_test.rb +54 -10
  55. data/test/replica_sets/connect_test.rb +84 -0
  56. data/test/replica_sets/count_test.rb +35 -0
  57. data/test/{replica → replica_sets}/insert_test.rb +17 -14
  58. data/test/replica_sets/pooled_insert_test.rb +55 -0
  59. data/test/replica_sets/query_secondaries.rb +80 -0
  60. data/test/replica_sets/query_test.rb +41 -0
  61. data/test/replica_sets/replication_ack_test.rb +64 -0
  62. data/test/replica_sets/rs_test_helper.rb +29 -0
  63. data/test/safe_test.rb +68 -0
  64. data/test/support/hash_with_indifferent_access.rb +199 -0
  65. data/test/support/keys.rb +45 -0
  66. data/test/support_test.rb +19 -0
  67. data/test/test_helper.rb +53 -15
  68. data/test/threading/{test_threading_large_pool.rb → threading_with_large_pool_test.rb} +2 -2
  69. data/test/threading_test.rb +2 -2
  70. data/test/tools/repl_set_manager.rb +241 -0
  71. data/test/tools/test.rb +13 -0
  72. data/test/unit/collection_test.rb +70 -7
  73. data/test/unit/connection_test.rb +18 -39
  74. data/test/unit/cursor_test.rb +7 -8
  75. data/test/unit/db_test.rb +14 -17
  76. data/test/unit/grid_test.rb +49 -0
  77. data/test/unit/pool_test.rb +9 -0
  78. data/test/unit/repl_set_connection_test.rb +82 -0
  79. data/test/unit/safe_test.rb +125 -0
  80. metadata +132 -51
  81. data/bin/bson_benchmark.rb +0 -59
  82. data/bin/fail_if_no_c.rb +0 -11
  83. data/examples/admin.rb +0 -43
  84. data/examples/capped.rb +0 -22
  85. data/examples/cursor.rb +0 -48
  86. data/examples/gridfs.rb +0 -44
  87. data/examples/index_test.rb +0 -126
  88. data/examples/info.rb +0 -31
  89. data/examples/queries.rb +0 -70
  90. data/examples/simple.rb +0 -24
  91. data/examples/strict.rb +0 -35
  92. data/examples/types.rb +0 -36
  93. data/test/replica/count_test.rb +0 -34
  94. data/test/replica/pooled_insert_test.rb +0 -54
  95. data/test/replica/query_test.rb +0 -39
@@ -0,0 +1,71 @@
1
+ # encoding: UTF-8
2
+
3
+ # --
4
+ # Copyright (C) 2008-2010 10gen Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ # ++
18
+
19
+ module Mongo
20
+ module URIParser
21
+
22
+ DEFAULT_PORT = 27017
23
+ MONGODB_URI_MATCHER = /(([-_.\w\d]+):([-_\w\d]+)@)?([-.\w\d]+)(:([\w\d]+))?(\/([-\d\w]+))?/
24
+ MONGODB_URI_SPEC = "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database]"
25
+
26
+ extend self
27
+
28
+ # Parse a MongoDB URI. This method is used by Connection.from_uri.
29
+ # Returns an array of nodes and an array of db authorizations, if applicable.
30
+ #
31
+ # @private
32
+ def parse(string)
33
+ if string =~ /^mongodb:\/\//
34
+ string = string[10..-1]
35
+ else
36
+ raise MongoArgumentError, "MongoDB URI must match this spec: #{MONGODB_URI_SPEC}"
37
+ end
38
+
39
+ nodes = []
40
+ auths = []
41
+ specs = string.split(',')
42
+ specs.each do |spec|
43
+ matches = MONGODB_URI_MATCHER.match(spec)
44
+ if !matches
45
+ raise MongoArgumentError, "MongoDB URI must match this spec: #{MONGODB_URI_SPEC}"
46
+ end
47
+
48
+ uname = matches[2]
49
+ pwd = matches[3]
50
+ host = matches[4]
51
+ port = matches[6] || DEFAULT_PORT
52
+ if !(port.to_s =~ /^\d+$/)
53
+ raise MongoArgumentError, "Invalid port #{port}; port must be specified as digits."
54
+ end
55
+ port = port.to_i
56
+ db = matches[8]
57
+
58
+ if uname && pwd && db
59
+ auths << {'db_name' => db, 'username' => uname, 'password' => pwd}
60
+ elsif uname || pwd || db
61
+ raise MongoArgumentError, "MongoDB URI must include all three of username, password, " +
62
+ "and db if any one of these is specified."
63
+ end
64
+
65
+ nodes << [host, port]
66
+ end
67
+
68
+ [nodes, auths]
69
+ end
70
+ end
71
+ end
data/lib/mongo.rb CHANGED
@@ -1,7 +1,9 @@
1
+ # encoding: UTF-8
2
+
1
3
  $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
4
 
3
5
  module Mongo
4
- VERSION = "1.0"
6
+ VERSION = "1.1.5"
5
7
  end
6
8
 
7
9
  module Mongo
@@ -19,13 +21,18 @@ module Mongo
19
21
  OP_DELETE = 2006
20
22
  OP_KILL_CURSORS = 2007
21
23
 
22
- OP_QUERY_TAILABLE = 2
23
- OP_QUERY_SLAVE_OK = 4
24
- OP_QUERY_NO_CURSOR_TIMEOUT = 16
25
-
26
- DEFAULT_BATCH_SIZE = 100
24
+ OP_QUERY_TAILABLE = 2 ** 1
25
+ OP_QUERY_SLAVE_OK = 2 ** 2
26
+ OP_QUERY_OPLOG_REPLAY = 2 ** 3
27
+ OP_QUERY_NO_CURSOR_TIMEOUT = 2 ** 4
28
+ OP_QUERY_AWAIT_DATA = 2 ** 5
29
+ OP_QUERY_EXHAUST = 2 ** 6
30
+
31
+ REPLY_CURSOR_NOT_FOUND = 2 ** 0
32
+ REPLY_QUERY_FAILURE = 2 ** 1
33
+ REPLY_SHARD_CONFIG_STALE = 2 ** 2
34
+ REPLY_AWAIT_CAPABLE = 2 ** 3
27
35
  end
28
-
29
36
  end
30
37
 
31
38
  require 'bson'
@@ -33,13 +40,22 @@ require 'bson'
33
40
  require 'mongo/util/conversions'
34
41
  require 'mongo/util/support'
35
42
  require 'mongo/util/core_ext'
43
+ require 'mongo/util/pool'
36
44
  require 'mongo/util/server_version'
45
+ require 'mongo/util/uri_parser'
37
46
 
38
47
  require 'mongo/collection'
39
48
  require 'mongo/connection'
49
+ require 'mongo/repl_set_connection'
40
50
  require 'mongo/cursor'
41
51
  require 'mongo/db'
42
52
  require 'mongo/exceptions'
53
+ require 'mongo/gridfs/grid_ext'
43
54
  require 'mongo/gridfs/grid'
44
55
  require 'mongo/gridfs/grid_io'
56
+ if RUBY_PLATFORM =~ /java/
57
+ require 'mongo/gridfs/grid_io_fix'
58
+ end
45
59
  require 'mongo/gridfs/grid_file_system'
60
+
61
+
@@ -1,4 +1,4 @@
1
- require "lib/mongo"
1
+ require "./lib/mongo"
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'mongo'
@@ -11,22 +11,24 @@ Gem::Specification.new do |s|
11
11
 
12
12
  s.require_paths = ['lib']
13
13
 
14
- s.files = ['README.rdoc', 'Rakefile', 'mongo-ruby-driver.gemspec', 'LICENSE.txt']
14
+ s.files = ['README.md', 'Rakefile', 'mongo.gemspec', 'LICENSE.txt']
15
15
  s.files += ['lib/mongo.rb'] + Dir['lib/mongo/**/*.rb']
16
- s.files += Dir['examples/**/*.rb'] + Dir['bin/**/*.rb']
16
+ s.files += Dir['docs/**/*.md'] + Dir['examples/**/*.rb'] + Dir['bin/**/*.rb']
17
+ s.files += Dir['bin/mongo_console']
17
18
  s.test_files = Dir['test/**/*.rb']
18
19
 
20
+ s.executables = ['mongo_console']
21
+
19
22
  s.has_rdoc = true
20
23
  s.test_files = Dir['test/**/*.rb']
21
- s.test_files -= Dir['test/mongo_bson/*.rb'] # remove these files from the manifest
22
24
 
23
25
  s.has_rdoc = true
24
- s.rdoc_options = ['--main', 'README.rdoc', '--inline-source']
25
- s.extra_rdoc_files = ['README.rdoc']
26
+ s.rdoc_options = ['--main', 'README.md', '--inline-source']
27
+ s.extra_rdoc_files = ['README.md']
26
28
 
27
29
  s.authors = ['Jim Menard', 'Mike Dirolf', 'Kyle Banker']
28
30
  s.email = 'mongodb-dev@googlegroups.com'
29
31
  s.homepage = 'http://www.mongodb.org'
30
32
 
31
- s.add_dependency(%q<bson>, ["= #{Mongo::VERSION}"])
33
+ s.add_dependency(%q<bson>, [">= #{Mongo::VERSION}"])
32
34
  end
@@ -1,7 +1,7 @@
1
1
  $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  require 'mongo'
3
3
  require 'test/unit'
4
- require 'test/test_helper'
4
+ require './test/test_helper'
5
5
 
6
6
  # Demonstrate features in MongoDB 1.4
7
7
  class Features14Test < Test::Unit::TestCase
@@ -150,7 +150,7 @@ class Features14Test < Test::Unit::TestCase
150
150
  end
151
151
 
152
152
  should "use geoNear command to return distances from a point" do
153
- cmd = OrderedHash.new
153
+ cmd = BSON::OrderedHash.new
154
154
  cmd['geoNear'] = 'places'
155
155
  cmd['near'] = @empire_state
156
156
  cmd['num'] = 6
@@ -1,7 +1,7 @@
1
1
  $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  require 'mongo'
3
3
  require 'test/unit'
4
- require 'test/test_helper'
4
+ require './test/test_helper'
5
5
 
6
6
  # NOTE: This test requires bouncing the server.
7
7
  # It also requires that a user exists on the admin database.
@@ -1,7 +1,7 @@
1
1
  $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  require 'mongo'
3
3
  require 'test/unit'
4
- require 'test/test_helper'
4
+ require './test/test_helper'
5
5
 
6
6
  # NOTE: This test requires bouncing the server
7
7
  class AutoreconnectTest < Test::Unit::TestCase
@@ -1,4 +1,4 @@
1
- require 'test/test_helper'
1
+ require './test/test_helper'
2
2
 
3
3
  # NOTE: these tests are run only if we can connect to a single MongoDB in slave mode.
4
4
  class SlaveConnectionTest < Test::Unit::TestCase
@@ -8,22 +8,22 @@ class SlaveConnectionTest < Test::Unit::TestCase
8
8
  @@host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
9
9
  @@port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
10
10
  conn = Connection.new(@@host, @@port, :slave_ok => true)
11
- cmd = conn['admin'].command(:ismaster => 1)
12
- cmd['ok'] == 1 && cmd['ismaster'] != 1
11
+ response = conn['admin'].command(:ismaster => 1)
12
+ Mongo::Support.ok?(response) && response['ismaster'] != 1
13
13
  end
14
14
 
15
15
  if self.connect_to_slave
16
16
  puts "Connected to slave; running slave tests."
17
17
 
18
18
  def test_connect_to_slave
19
- assert_raise Mongo::ConfigurationError do
19
+ assert_raise Mongo::ConnectionFailure do
20
20
  @db = Connection.new(@@host, @@port, :slave_ok => false).db('ruby-mongo-demo')
21
21
  end
22
22
  end
23
23
 
24
24
  def test_slave_ok_sent_to_queries
25
- @db = Connection.new(@@host, @@port, :slave_ok => true).db('ruby-mongo-demo')
26
- assert_equal true, @db.slave_ok?
25
+ @con = Connection.new(@@host, @@port, :slave_ok => true)
26
+ assert_equal true, @con.slave_ok?
27
27
  end
28
28
  else
29
29
  puts "Not connected to slave; skipping slave connection tests."
@@ -0,0 +1,15 @@
1
+ # encoding:utf-8
2
+ require './test/test_helper'
3
+
4
+ class BinaryTest < Test::Unit::TestCase
5
+ context "Inspecting" do
6
+ setup do
7
+ @data = ("THIS IS BINARY " * 50).unpack("c*")
8
+ end
9
+
10
+ should "not display actual data" do
11
+ binary = BSON::Binary.new(@data)
12
+ assert_equal "<BSON::Binary:#{binary.object_id}>", binary.inspect
13
+ end
14
+ end
15
+ end