mongo 0.15.1 → 0.16

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 (63) hide show
  1. data/LICENSE.txt +202 -0
  2. data/README.rdoc +15 -2
  3. data/Rakefile +17 -3
  4. data/bin/autoreconnect.rb +26 -0
  5. data/bin/fail_if_no_c.rb +11 -0
  6. data/lib/mongo.rb +9 -2
  7. data/lib/mongo/admin.rb +1 -1
  8. data/lib/mongo/collection.rb +86 -25
  9. data/lib/mongo/connection.rb +11 -0
  10. data/lib/mongo/constants.rb +15 -0
  11. data/lib/mongo/cursor.rb +176 -36
  12. data/lib/mongo/db.rb +84 -97
  13. data/lib/mongo/errors.rb +7 -1
  14. data/lib/mongo/types/objectid.rb +5 -0
  15. data/lib/mongo/util/byte_buffer.rb +12 -0
  16. data/lib/mongo/util/server_version.rb +69 -0
  17. data/lib/mongo/{message.rb → util/support.rb} +7 -4
  18. data/mongo-ruby-driver.gemspec +9 -86
  19. data/test/test_admin.rb +2 -2
  20. data/test/test_bson.rb +14 -0
  21. data/test/test_byte_buffer.rb +14 -0
  22. data/test/test_chunk.rb +4 -4
  23. data/test/test_collection.rb +107 -17
  24. data/test/test_connection.rb +13 -4
  25. data/test/test_cursor.rb +17 -14
  26. data/test/test_db.rb +7 -7
  27. data/test/test_db_api.rb +31 -19
  28. data/test/test_db_connection.rb +1 -1
  29. data/test/test_grid_store.rb +8 -8
  30. data/test/test_helper.rb +25 -0
  31. data/test/test_objectid.rb +11 -1
  32. data/test/test_slave_connection.rb +37 -0
  33. data/test/test_threading.rb +1 -1
  34. data/test/unit/cursor_test.rb +122 -0
  35. metadata +26 -46
  36. data/bin/mongo_console +0 -21
  37. data/bin/run_test_script +0 -19
  38. data/bin/standard_benchmark +0 -109
  39. data/lib/mongo/message/get_more_message.rb +0 -32
  40. data/lib/mongo/message/insert_message.rb +0 -37
  41. data/lib/mongo/message/kill_cursors_message.rb +0 -31
  42. data/lib/mongo/message/message.rb +0 -80
  43. data/lib/mongo/message/message_header.rb +0 -45
  44. data/lib/mongo/message/msg_message.rb +0 -29
  45. data/lib/mongo/message/opcodes.rb +0 -27
  46. data/lib/mongo/message/query_message.rb +0 -69
  47. data/lib/mongo/message/remove_message.rb +0 -37
  48. data/lib/mongo/message/update_message.rb +0 -38
  49. data/lib/mongo/query.rb +0 -118
  50. data/test/mongo-qa/admin +0 -26
  51. data/test/mongo-qa/capped +0 -22
  52. data/test/mongo-qa/count1 +0 -18
  53. data/test/mongo-qa/dbs +0 -22
  54. data/test/mongo-qa/find +0 -10
  55. data/test/mongo-qa/find1 +0 -15
  56. data/test/mongo-qa/gridfs_in +0 -16
  57. data/test/mongo-qa/gridfs_out +0 -17
  58. data/test/mongo-qa/indices +0 -49
  59. data/test/mongo-qa/remove +0 -25
  60. data/test/mongo-qa/stress1 +0 -35
  61. data/test/mongo-qa/test1 +0 -11
  62. data/test/mongo-qa/update +0 -18
  63. data/test/test_message.rb +0 -35
@@ -12,7 +12,7 @@ class TestThreading < Test::Unit::TestCase
12
12
  @@coll = @@db.collection('thread-test-collection')
13
13
 
14
14
  def test_threading
15
- @@coll.clear
15
+ @@coll.remove
16
16
 
17
17
  1000.times do |i|
18
18
  @@coll.insert("x" => i)
@@ -0,0 +1,122 @@
1
+ require 'test/test_helper'
2
+
3
+ class TestCursor < Test::Unit::TestCase
4
+
5
+ context "Cursor options" do
6
+ setup do
7
+ @db = stub(:name => "testing", :slave_ok? => false)
8
+ @collection = stub(:db => @db, :name => "items")
9
+ @cursor = Cursor.new(@collection)
10
+ end
11
+
12
+ should "set admin to false" do
13
+ assert_equal false, @cursor.admin
14
+
15
+ @cursor = Cursor.new(@collection, :admin => true)
16
+ assert_equal true, @cursor.admin
17
+ end
18
+
19
+ should "set selector" do
20
+ assert @cursor.selector == {}
21
+
22
+ @cursor = Cursor.new(@collection, :selector => {:name => "Jones"})
23
+ assert @cursor.selector == {:name => "Jones"}
24
+ end
25
+
26
+ should "set fields" do
27
+ assert_nil @cursor.fields
28
+
29
+ @cursor = Cursor.new(@collection, :fields => [:name, :date])
30
+ assert @cursor.fields == {:name => 1, :date => 1}
31
+ end
32
+
33
+ should "set limit" do
34
+ assert_equal 0, @cursor.limit
35
+
36
+ @cursor = Cursor.new(@collection, :limit => 10)
37
+ assert_equal 10, @cursor.limit
38
+ end
39
+
40
+
41
+ should "set skip" do
42
+ assert_equal 0, @cursor.skip
43
+
44
+ @cursor = Cursor.new(@collection, :skip => 5)
45
+ assert_equal 5, @cursor.skip
46
+ end
47
+
48
+ should "set sort order" do
49
+ assert_nil @cursor.order
50
+
51
+ @cursor = Cursor.new(@collection, :order => "last_name")
52
+ assert_equal "last_name", @cursor.order
53
+ end
54
+
55
+ should "set hint" do
56
+ assert_nil @cursor.hint
57
+
58
+ @cursor = Cursor.new(@collection, :hint => "name")
59
+ assert_equal "name", @cursor.hint
60
+ end
61
+
62
+ should "cache full collection name" do
63
+ assert_equal "testing.items", @cursor.full_collection_name
64
+ end
65
+ end
66
+
67
+ context "Query options" do
68
+ should "test timeout true and slave_ok false" do
69
+ @db = stub(:slave_ok? => false, :name => "testing")
70
+ @collection = stub(:db => @db, :name => "items")
71
+ @cursor = Cursor.new(@collection, :timeout => true)
72
+ assert_equal 0, @cursor.query_opts
73
+ end
74
+
75
+ should "test timeout false and slave_ok false" do
76
+ @db = stub(:slave_ok? => false, :name => "testing")
77
+ @collection = stub(:db => @db, :name => "items")
78
+ @cursor = Cursor.new(@collection, :timeout => false)
79
+ assert_equal 16, @cursor.query_opts
80
+ end
81
+
82
+ should "set timeout true and slave_ok true" do
83
+ @db = stub(:slave_ok? => true, :name => "testing")
84
+ @collection = stub(:db => @db, :name => "items")
85
+ @cursor = Cursor.new(@collection, :timeout => true)
86
+ assert_equal 4, @cursor.query_opts
87
+ end
88
+
89
+ should "set timeout false and slave_ok true" do
90
+ @db = stub(:slave_ok? => true, :name => "testing")
91
+ @collection = stub(:db => @db, :name => "items")
92
+ @cursor = Cursor.new(@collection, :timeout => false)
93
+ assert_equal 20, @cursor.query_opts
94
+ end
95
+ end
96
+
97
+ context "Query fields" do
98
+ setup do
99
+ @db = stub(:slave_ok? => true, :name => "testing")
100
+ @collection = stub(:db => @db, :name => "items")
101
+ end
102
+
103
+ should "when an array should return a hash with each key" do
104
+ @cursor = Cursor.new(@collection, :fields => [:name, :age])
105
+ result = @cursor.fields
106
+ assert_equal result.keys.sort{|a,b| a.to_s <=> b.to_s}, [:age, :name].sort{|a,b| a.to_s <=> b.to_s}
107
+ assert result.values.all? {|v| v == 1}
108
+ end
109
+
110
+ should "when a string, return a hash with just the key" do
111
+ @cursor = Cursor.new(@collection, :fields => "name")
112
+ result = @cursor.fields
113
+ assert_equal result.keys.sort, ["name"]
114
+ assert result.values.all? {|v| v == 1}
115
+ end
116
+
117
+ should "return nil when neither hash nor string nor symbol" do
118
+ @cursor = Cursor.new(@collection, :fields => 1234567)
119
+ assert_nil @cursor.fields
120
+ end
121
+ end
122
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: "0.16"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Menard
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-10-08 00:00:00 -04:00
13
+ date: 2009-10-26 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -26,43 +26,17 @@ files:
26
26
  - README.rdoc
27
27
  - Rakefile
28
28
  - mongo-ruby-driver.gemspec
29
- - bin/bson_benchmark.rb
30
- - bin/mongo_console
31
- - bin/run_test_script
32
- - bin/standard_benchmark
33
- - examples/admin.rb
34
- - examples/benchmarks.rb
35
- - examples/blog.rb
36
- - examples/capped.rb
37
- - examples/cursor.rb
38
- - examples/gridfs.rb
39
- - examples/index_test.rb
40
- - examples/info.rb
41
- - examples/queries.rb
42
- - examples/simple.rb
43
- - examples/strict.rb
44
- - examples/types.rb
29
+ - LICENSE.txt
45
30
  - lib/mongo/admin.rb
46
31
  - lib/mongo/collection.rb
47
32
  - lib/mongo/connection.rb
33
+ - lib/mongo/constants.rb
48
34
  - lib/mongo/cursor.rb
49
35
  - lib/mongo/db.rb
36
+ - lib/mongo/errors.rb
50
37
  - lib/mongo/gridfs/chunk.rb
51
38
  - lib/mongo/gridfs/grid_store.rb
52
39
  - lib/mongo/gridfs.rb
53
- - lib/mongo/errors.rb
54
- - lib/mongo/message/get_more_message.rb
55
- - lib/mongo/message/insert_message.rb
56
- - lib/mongo/message/kill_cursors_message.rb
57
- - lib/mongo/message/message.rb
58
- - lib/mongo/message/message_header.rb
59
- - lib/mongo/message/msg_message.rb
60
- - lib/mongo/message/opcodes.rb
61
- - lib/mongo/message/query_message.rb
62
- - lib/mongo/message/remove_message.rb
63
- - lib/mongo/message/update_message.rb
64
- - lib/mongo/message.rb
65
- - lib/mongo/query.rb
66
40
  - lib/mongo/types/binary.rb
67
41
  - lib/mongo/types/code.rb
68
42
  - lib/mongo/types/dbref.rb
@@ -72,8 +46,25 @@ files:
72
46
  - lib/mongo/util/byte_buffer.rb
73
47
  - lib/mongo/util/conversions.rb
74
48
  - lib/mongo/util/ordered_hash.rb
49
+ - lib/mongo/util/server_version.rb
50
+ - lib/mongo/util/support.rb
75
51
  - lib/mongo/util/xml_to_ruby.rb
76
52
  - lib/mongo.rb
53
+ - examples/admin.rb
54
+ - examples/benchmarks.rb
55
+ - examples/blog.rb
56
+ - examples/capped.rb
57
+ - examples/cursor.rb
58
+ - examples/gridfs.rb
59
+ - examples/index_test.rb
60
+ - examples/info.rb
61
+ - examples/queries.rb
62
+ - examples/simple.rb
63
+ - examples/strict.rb
64
+ - examples/types.rb
65
+ - bin/autoreconnect.rb
66
+ - bin/bson_benchmark.rb
67
+ - bin/fail_if_no_c.rb
77
68
  has_rdoc: true
78
69
  homepage: http://www.mongodb.org
79
70
  licenses: []
@@ -106,19 +97,6 @@ specification_version: 3
106
97
  summary: Ruby driver for the MongoDB
107
98
  test_files:
108
99
  - test/mongo-qa/_common.rb
109
- - test/mongo-qa/admin
110
- - test/mongo-qa/capped
111
- - test/mongo-qa/count1
112
- - test/mongo-qa/dbs
113
- - test/mongo-qa/find
114
- - test/mongo-qa/find1
115
- - test/mongo-qa/gridfs_in
116
- - test/mongo-qa/gridfs_out
117
- - test/mongo-qa/indices
118
- - test/mongo-qa/remove
119
- - test/mongo-qa/stress1
120
- - test/mongo-qa/test1
121
- - test/mongo-qa/update
122
100
  - test/test_admin.rb
123
101
  - test/test_bson.rb
124
102
  - test/test_byte_buffer.rb
@@ -131,8 +109,10 @@ test_files:
131
109
  - test/test_db_api.rb
132
110
  - test/test_db_connection.rb
133
111
  - test/test_grid_store.rb
134
- - test/test_message.rb
112
+ - test/test_helper.rb
135
113
  - test/test_objectid.rb
136
114
  - test/test_ordered_hash.rb
137
- - test/test_threading.rb
138
115
  - test/test_round_trip.rb
116
+ - test/test_slave_connection.rb
117
+ - test/test_threading.rb
118
+ - test/unit/cursor_test.rb
@@ -1,21 +0,0 @@
1
- #!/usr/bin/env ruby
2
- org_argv = ARGV.dup
3
- ARGV.clear
4
-
5
- require 'irb'
6
-
7
- $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
8
- require 'mongo'
9
-
10
- include Mongo
11
-
12
- host = org_argv[0] || ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
13
- port = org_argv[1] || ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
14
- dbnm = org_argv[2] || ENV['MONGO_RUBY_DRIVER_DB'] || 'ruby-mongo-console'
15
-
16
- puts "Connecting to #{host}:#{port} (CONN) on with database #{dbnm} (DB)"
17
- CONN = Connection.new(host, port)
18
- DB = CONN.db(dbnm)
19
-
20
- puts "Starting IRB session..."
21
- IRB.start(__FILE__)
@@ -1,19 +0,0 @@
1
- #!/bin/bash
2
- # usage: run_test_script test_name output_file
3
- #
4
- # See http://mongodb.onconfluence.com/display/DOCS/Using+the+Framework+(for+Driver+Developers)
5
-
6
- HERE=`dirname $0`
7
-
8
- if [ ! -f $HERE/../test/mongo-qa/$1 ] ; then
9
- exit 0
10
- fi
11
-
12
- begintime=`date`
13
- ruby $HERE/../test/mongo-qa/$1 $3 $4 >> $2
14
- exitval=$?
15
- endtime=`date`
16
-
17
- echo "begintime:$begintime" >> $2
18
- echo "endtime:$endtime" >> $2
19
- echo "exit_code:$exitval" >> $2
@@ -1,109 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Note: Ruby 1.9 is faster than 1.8, as expected.
4
-
5
- $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
6
- require 'mongo'
7
-
8
- include Mongo
9
-
10
- TRIALS = 2
11
- PER_TRIAL = 5000
12
- BATCH_SIZE = 100
13
-
14
- SMALL = {}
15
- MEDIUM = {
16
- 'integer' => 5,
17
- 'number' => 5.05,
18
- 'boolean' => false,
19
- 'array' => ['test', 'benchmark']
20
- }
21
- LARGE = {
22
- 'base_url' => 'http://www.example.com/test-me',
23
- 'total_word_count' => 6743,
24
- 'access_time' => Time.now,
25
- 'meta_tags' => {
26
- 'description' => 'i am a long description string',
27
- 'author' => 'Holly Man',
28
- 'dynamically_created_meta_tag' => 'who know\n what'
29
- },
30
- 'page_structure' => {
31
- 'counted_tags' => 3450,
32
- 'no_of_js_attached' => 10,
33
- 'no_of_images' => 6
34
- },
35
- 'harvested_words' => ['10gen','web','open','source','application','paas',
36
- 'platform-as-a-service','technology','helps',
37
- 'developers','focus','building','mongodb','mongo'] * 20
38
- }
39
-
40
- def report(str, t)
41
- printf("%s%d\n", str.ljust(60, '.'), PER_TRIAL / t)
42
- end
43
-
44
- def benchmark(str, proc, n, db, coll_name, object, setup=nil)
45
- coll = db.collection(coll_name)
46
- setup.call(coll, object) if setup
47
- t0 = Time.new
48
- n.times { |i| proc.call(coll, object, i) }
49
- report(str, Time.new.to_f - t0.to_f)
50
- end
51
-
52
- host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
53
- port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
54
-
55
- connection = Connection.new(host, port)
56
- connection.drop_database("benchmark")
57
- db = connection.db('benchmark')
58
-
59
- insert = Proc.new { |coll, object, i|
60
- object['x'] = i
61
- coll.insert(object)
62
- }
63
- benchmark('insert (small, no index)', insert, PER_TRIAL, db, 'small_none', SMALL)
64
- benchmark('insert (medium, no index)', insert, PER_TRIAL, db, 'medium_none', MEDIUM)
65
- benchmark('insert (large, no index)', insert, PER_TRIAL, db, 'large_none', LARGE)
66
-
67
- index_on_x = Proc.new { |coll, object|
68
- coll.create_index('x')
69
- }
70
- benchmark('insert (small, indexed)', insert, PER_TRIAL, db, 'small_index', SMALL, index_on_x)
71
- benchmark('insert (medium, indexed)', insert, PER_TRIAL, db, 'medium_index', MEDIUM, index_on_x)
72
- benchmark('insert (large, indexed)', insert, PER_TRIAL, db, 'large_index', LARGE, index_on_x)
73
-
74
- insert_batch = Proc.new { |coll, object, i|
75
- object['x'] = i
76
- coll.insert([object] * BATCH_SIZE)
77
- }
78
- benchmark('batch insert (small, no index)', insert_batch, PER_TRIAL/BATCH_SIZE, db, 'small_bulk', SMALL)
79
- benchmark('batch insert (medium, no index)', insert_batch, PER_TRIAL/BATCH_SIZE, db, 'medium_bulk', MEDIUM)
80
- benchmark('batch insert (large, no index)', insert_batch, PER_TRIAL/BATCH_SIZE, db, 'large_bulk', LARGE)
81
-
82
- find_one = Proc.new { |coll, x, i|
83
- coll.find_one('x' => x)
84
- }
85
- benchmark('find_one (small, no index)', find_one, PER_TRIAL, db, 'small_none', PER_TRIAL / 2)
86
- benchmark('find_one (medium, no index)', find_one, PER_TRIAL, db, 'medium_none', PER_TRIAL / 2)
87
- benchmark('find_one (large, no index)', find_one, PER_TRIAL, db, 'large_none', PER_TRIAL / 2)
88
-
89
- benchmark('find_one (small, indexed)', find_one, PER_TRIAL, db, 'small_index', PER_TRIAL / 2)
90
- benchmark('find_one (medium, indexed)', find_one, PER_TRIAL, db, 'medium_index', PER_TRIAL / 2)
91
- benchmark('find_one (large, indexed)', find_one, PER_TRIAL, db, 'large_index', PER_TRIAL / 2)
92
-
93
- find = Proc.new { |coll, x, i|
94
- coll.find('x' => x).each {}
95
- }
96
- benchmark('find (small, no index)', find, PER_TRIAL, db, 'small_none', PER_TRIAL / 2)
97
- benchmark('find (medium, no index)', find, PER_TRIAL, db, 'medium_none', PER_TRIAL / 2)
98
- benchmark('find (large, no index)', find, PER_TRIAL, db, 'large_none', PER_TRIAL / 2)
99
-
100
- benchmark('find (small, indexed)', find, PER_TRIAL, db, 'small_index', PER_TRIAL / 2)
101
- benchmark('find (medium, indexed)', find, PER_TRIAL, db, 'medium_index', PER_TRIAL / 2)
102
- benchmark('find (large, indexed)', find, PER_TRIAL, db, 'large_index', PER_TRIAL / 2)
103
-
104
- benchmark('find range (small, indexed)', find, PER_TRIAL, db, 'small_index',
105
- {"$gt" => PER_TRIAL / 2, "$lt" => PER_TRIAL / 2 + BATCH_SIZE})
106
- benchmark('find range (medium, indexed)', find, PER_TRIAL, db, 'medium_index',
107
- {"$gt" => PER_TRIAL / 2, "$lt" => PER_TRIAL / 2 + BATCH_SIZE})
108
- benchmark('find range (large, indexed)', find, PER_TRIAL, db, 'large_index',
109
- {"$gt" => PER_TRIAL / 2, "$lt" => PER_TRIAL / 2 + BATCH_SIZE})
@@ -1,32 +0,0 @@
1
- # --
2
- # Copyright (C) 2008-2009 10gen Inc.
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
- # ++
16
-
17
- require 'mongo/message/message'
18
- require 'mongo/message/opcodes'
19
-
20
- module Mongo
21
-
22
- class GetMoreMessage < Message
23
-
24
- def initialize(db_name, collection_name, cursor)
25
- super(OP_GET_MORE)
26
- write_int(0)
27
- write_string("#{db_name}.#{collection_name}")
28
- write_int(0) # num to return; leave it up to the db for now
29
- write_long(cursor)
30
- end
31
- end
32
- end
@@ -1,37 +0,0 @@
1
- # --
2
- # Copyright (C) 2008-2009 10gen Inc.
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
- # ++
16
-
17
- require 'mongo/message/message'
18
- require 'mongo/message/opcodes'
19
-
20
- module Mongo
21
-
22
- class InsertMessage < Message
23
-
24
- def initialize(db_name, collection_name, check_keys=true, *objs)
25
- @collection_name = collection_name
26
- @objs = objs
27
- super(OP_INSERT)
28
- write_int(0)
29
- write_string("#{db_name}.#{collection_name}")
30
- objs.each { |o| write_doc(o, check_keys) }
31
- end
32
-
33
- def to_s
34
- "db.#{@collection_name}.insert(#{@objs.inspect})"
35
- end
36
- end
37
- end