mongo 1.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +5 -0
- data/README.rdoc +8 -3
- data/Rakefile +4 -10
- data/lib/mongo.rb +6 -1
- data/lib/mongo/connection.rb +1 -2
- data/lib/mongo/gridfs/grid_io_fix.rb +38 -0
- data/mongo.gemspec +1 -1
- data/test/bson/bson_test.rb +65 -58
- data/test/bson/byte_buffer_test.rb +1 -1
- data/test/bson/hash_with_indifferent_access_test.rb +38 -0
- data/test/bson/json_test.rb +7 -6
- data/test/bson/object_id_test.rb +1 -3
- data/test/collection_test.rb +3 -3
- data/test/connection_test.rb +12 -18
- data/test/cursor_fail_test.rb +1 -2
- data/test/cursor_message_test.rb +1 -2
- data/test/cursor_test.rb +1 -2
- data/test/db_api_test.rb +7 -5
- data/test/db_test.rb +8 -10
- data/test/grid_file_system_test.rb +2 -3
- data/test/grid_io_test.rb +1 -2
- data/test/grid_test.rb +1 -2
- data/test/replica_sets/connect_test.rb +23 -0
- data/test/support/hash_with_indifferent_access.rb +199 -0
- data/test/support/keys.rb +45 -0
- data/test/test_helper.rb +37 -2
- data/test/threading/test_threading_large_pool.rb +1 -1
- data/test/threading_test.rb +1 -1
- metadata +169 -118
- data/test/bson/basic_test.rb +0 -99
- data/test/bson/bench_test.rb +0 -172
- data/test/bson/c_encode_test.rb +0 -51
- data/test/bson/java_bson_test.rb +0 -146
- data/test/bson/jruby_bson_test.rb +0 -24
- data/test/bson/jruby_encode_test.rb +0 -438
@@ -0,0 +1,45 @@
|
|
1
|
+
class Hash
|
2
|
+
# Return a new hash with all keys converted to strings.
|
3
|
+
def stringify_keys
|
4
|
+
dup.stringify_keys!
|
5
|
+
end
|
6
|
+
|
7
|
+
# Destructively convert all keys to strings.
|
8
|
+
def stringify_keys!
|
9
|
+
keys.each do |key|
|
10
|
+
self[key.to_s] = delete(key)
|
11
|
+
end
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
# Return a new hash with all keys converted to symbols, as long as
|
16
|
+
# they respond to +to_sym+.
|
17
|
+
def symbolize_keys
|
18
|
+
dup.symbolize_keys!
|
19
|
+
end
|
20
|
+
|
21
|
+
# Destructively convert all keys to symbols, as long as they respond
|
22
|
+
# to +to_sym+.
|
23
|
+
def symbolize_keys!
|
24
|
+
keys.each do |key|
|
25
|
+
self[(key.to_sym rescue key) || key] = delete(key)
|
26
|
+
end
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
alias_method :to_options, :symbolize_keys
|
31
|
+
#alias_method :to_options!, :symbolize_keys!
|
32
|
+
|
33
|
+
# Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch.
|
34
|
+
# Note that keys are NOT treated indifferently, meaning if you use strings for keys but assert symbols
|
35
|
+
# as keys, this will fail.
|
36
|
+
#
|
37
|
+
# ==== Examples
|
38
|
+
# { :name => "Rob", :years => "28" }.assert_valid_keys(:name, :age) # => raises "ArgumentError: Unknown key(s): years"
|
39
|
+
# { :name => "Rob", :age => "28" }.assert_valid_keys("name", "age") # => raises "ArgumentError: Unknown key(s): name, age"
|
40
|
+
# { :name => "Rob", :age => "28" }.assert_valid_keys(:name, :age) # => passes, raises nothing
|
41
|
+
def assert_valid_keys(*valid_keys)
|
42
|
+
unknown_keys = keys - [valid_keys].flatten
|
43
|
+
raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty?
|
44
|
+
end
|
45
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -19,14 +19,49 @@ MSG
|
|
19
19
|
exit
|
20
20
|
end
|
21
21
|
|
22
|
-
require 'bson_ext/cbson' if ENV['C_EXT']
|
22
|
+
require 'bson_ext/cbson' if !(RUBY_PLATFORM =~ /java/) && ENV['C_EXT']
|
23
23
|
|
24
|
-
|
24
|
+
unless defined? MONGO_TEST_DB
|
25
|
+
MONGO_TEST_DB = 'mongo-ruby-test'
|
26
|
+
end
|
25
27
|
|
26
28
|
class Test::Unit::TestCase
|
27
29
|
include Mongo
|
28
30
|
include BSON
|
29
31
|
|
32
|
+
def self.standard_connection(options={})
|
33
|
+
Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
34
|
+
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def standard_connection(options={})
|
38
|
+
self.class.standard_connection(options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.host_port
|
42
|
+
"#{mongo_host}:#{mongo_port}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.mongo_host
|
46
|
+
ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.mongo_port
|
50
|
+
ENV['MONGO_RUBY_DRIVER_PORT'] ? ENV['MONGO_RUBY_DRIVER_PORT'].to_i : 27017
|
51
|
+
end
|
52
|
+
|
53
|
+
def host_port
|
54
|
+
self.class.host_port
|
55
|
+
end
|
56
|
+
|
57
|
+
def mongo_host
|
58
|
+
self.class.mongo_host
|
59
|
+
end
|
60
|
+
|
61
|
+
def mongo_port
|
62
|
+
self.class.mongo_port
|
63
|
+
end
|
64
|
+
|
30
65
|
# Generic code for rescuing connection failures and retrying operations.
|
31
66
|
# This could be combined with some timeout functionality.
|
32
67
|
def rescue_connection_failure
|
@@ -6,7 +6,7 @@ class TestThreadingLargePool < Test::Unit::TestCase
|
|
6
6
|
|
7
7
|
include Mongo
|
8
8
|
|
9
|
-
@@db =
|
9
|
+
@@db = standard_connection(:pool_size => 50, :timeout => 60).db(MONGO_TEST_DB)
|
10
10
|
@@coll = @@db.collection('thread-test-collection')
|
11
11
|
|
12
12
|
def set_up_safe_data
|
data/test/threading_test.rb
CHANGED
@@ -4,7 +4,7 @@ class TestThreading < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
include Mongo
|
6
6
|
|
7
|
-
@@db =
|
7
|
+
@@db = standard_connection(:pool_size => 1, :timeout => 30).db(MONGO_TEST_DB)
|
8
8
|
@@coll = @@db.collection('thread-test-collection')
|
9
9
|
|
10
10
|
def set_up_safe_data
|
metadata
CHANGED
@@ -1,156 +1,207 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 1.1.1
|
9
11
|
platform: ruby
|
10
12
|
authors:
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
- Jim Menard
|
14
|
+
- Mike Dirolf
|
15
|
+
- Kyle Banker
|
14
16
|
autorequire:
|
15
17
|
bindir: bin
|
16
18
|
cert_chain: []
|
17
19
|
|
18
|
-
date: 2010-10-
|
20
|
+
date: 2010-10-14 00:00:00 -04:00
|
19
21
|
default_executable:
|
20
22
|
dependencies:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
name: bson
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 17
|
32
|
+
segments:
|
33
|
+
- 1
|
34
|
+
- 1
|
35
|
+
- 1
|
36
|
+
version: 1.1.1
|
37
|
+
type: :runtime
|
38
|
+
version_requirements: *id001
|
35
39
|
description: A Ruby driver for MongoDB. For more information about Mongo, see http://www.mongodb.org.
|
36
40
|
email: mongodb-dev@googlegroups.com
|
37
41
|
executables:
|
38
|
-
|
42
|
+
- mongo_console
|
39
43
|
extensions: []
|
40
44
|
|
41
45
|
extra_rdoc_files:
|
42
|
-
|
46
|
+
- README.rdoc
|
43
47
|
files:
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
48
|
+
- README.rdoc
|
49
|
+
- HISTORY
|
50
|
+
- Rakefile
|
51
|
+
- mongo.gemspec
|
52
|
+
- LICENSE.txt
|
53
|
+
- lib/mongo.rb
|
54
|
+
- lib/mongo/collection.rb
|
55
|
+
- lib/mongo/connection.rb
|
56
|
+
- lib/mongo/cursor.rb
|
57
|
+
- lib/mongo/db.rb
|
58
|
+
- lib/mongo/exceptions.rb
|
59
|
+
- lib/mongo/gridfs/grid.rb
|
60
|
+
- lib/mongo/gridfs/grid_ext.rb
|
61
|
+
- lib/mongo/gridfs/grid_file_system.rb
|
62
|
+
- lib/mongo/gridfs/grid_io.rb
|
63
|
+
- lib/mongo/gridfs/grid_io_fix.rb
|
64
|
+
- lib/mongo/util/conversions.rb
|
65
|
+
- lib/mongo/util/core_ext.rb
|
66
|
+
- lib/mongo/util/server_version.rb
|
67
|
+
- lib/mongo/util/support.rb
|
68
|
+
- examples/admin.rb
|
69
|
+
- examples/capped.rb
|
70
|
+
- examples/cursor.rb
|
71
|
+
- examples/gridfs.rb
|
72
|
+
- examples/index_test.rb
|
73
|
+
- examples/info.rb
|
74
|
+
- examples/queries.rb
|
75
|
+
- examples/simple.rb
|
76
|
+
- examples/strict.rb
|
77
|
+
- examples/types.rb
|
78
|
+
- bin/bson_benchmark.rb
|
79
|
+
- bin/fail_if_no_c.rb
|
80
|
+
- bin/insert.rb
|
81
|
+
- bin/oid.rb
|
82
|
+
- bin/mongo_console
|
83
|
+
- test/auxillary/1.4_features.rb
|
84
|
+
- test/auxillary/authentication_test.rb
|
85
|
+
- test/auxillary/autoreconnect_test.rb
|
86
|
+
- test/auxillary/slave_connection_test.rb
|
87
|
+
- test/bson/binary_test.rb
|
88
|
+
- test/bson/bson_test.rb
|
89
|
+
- test/bson/byte_buffer_test.rb
|
90
|
+
- test/bson/hash_with_indifferent_access_test.rb
|
91
|
+
- test/bson/json_test.rb
|
92
|
+
- test/bson/object_id_test.rb
|
93
|
+
- test/bson/ordered_hash_test.rb
|
94
|
+
- test/collection_test.rb
|
95
|
+
- test/connection_test.rb
|
96
|
+
- test/conversions_test.rb
|
97
|
+
- test/cursor_fail_test.rb
|
98
|
+
- test/cursor_message_test.rb
|
99
|
+
- test/cursor_test.rb
|
100
|
+
- test/db_api_test.rb
|
101
|
+
- test/db_connection_test.rb
|
102
|
+
- test/db_test.rb
|
103
|
+
- test/grid_file_system_test.rb
|
104
|
+
- test/grid_io_test.rb
|
105
|
+
- test/grid_test.rb
|
106
|
+
- test/replica_pairs/count_test.rb
|
107
|
+
- test/replica_pairs/insert_test.rb
|
108
|
+
- test/replica_pairs/pooled_insert_test.rb
|
109
|
+
- test/replica_pairs/query_test.rb
|
110
|
+
- test/replica_sets/connect_test.rb
|
111
|
+
- test/replica_sets/count_test.rb
|
112
|
+
- test/replica_sets/insert_test.rb
|
113
|
+
- test/replica_sets/node_type_test.rb
|
114
|
+
- test/replica_sets/pooled_insert_test.rb
|
115
|
+
- test/replica_sets/query_test.rb
|
116
|
+
- test/replica_sets/replication_ack_test.rb
|
117
|
+
- test/support/hash_with_indifferent_access.rb
|
118
|
+
- test/support/keys.rb
|
119
|
+
- test/support_test.rb
|
120
|
+
- test/test_helper.rb
|
121
|
+
- test/threading/test_threading_large_pool.rb
|
122
|
+
- test/threading_test.rb
|
123
|
+
- test/unit/collection_test.rb
|
124
|
+
- test/unit/connection_test.rb
|
125
|
+
- test/unit/cursor_test.rb
|
126
|
+
- test/unit/db_test.rb
|
78
127
|
has_rdoc: true
|
79
128
|
homepage: http://www.mongodb.org
|
80
129
|
licenses: []
|
81
130
|
|
82
131
|
post_install_message:
|
83
132
|
rdoc_options:
|
84
|
-
|
85
|
-
|
86
|
-
|
133
|
+
- --main
|
134
|
+
- README.rdoc
|
135
|
+
- --inline-source
|
87
136
|
require_paths:
|
88
|
-
|
137
|
+
- lib
|
89
138
|
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
90
140
|
requirements:
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
hash: 3
|
144
|
+
segments:
|
145
|
+
- 0
|
146
|
+
version: "0"
|
96
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
none: false
|
97
149
|
requirements:
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
hash: 3
|
153
|
+
segments:
|
154
|
+
- 0
|
155
|
+
version: "0"
|
103
156
|
requirements: []
|
104
157
|
|
105
158
|
rubyforge_project:
|
106
|
-
rubygems_version: 1.3.
|
159
|
+
rubygems_version: 1.3.7
|
107
160
|
signing_key:
|
108
161
|
specification_version: 3
|
109
162
|
summary: Ruby driver for the MongoDB
|
110
163
|
test_files:
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
- test/unit/cursor_test.rb
|
156
|
-
- test/unit/db_test.rb
|
164
|
+
- test/auxillary/1.4_features.rb
|
165
|
+
- test/auxillary/authentication_test.rb
|
166
|
+
- test/auxillary/autoreconnect_test.rb
|
167
|
+
- test/auxillary/slave_connection_test.rb
|
168
|
+
- test/bson/binary_test.rb
|
169
|
+
- test/bson/bson_test.rb
|
170
|
+
- test/bson/byte_buffer_test.rb
|
171
|
+
- test/bson/hash_with_indifferent_access_test.rb
|
172
|
+
- test/bson/json_test.rb
|
173
|
+
- test/bson/object_id_test.rb
|
174
|
+
- test/bson/ordered_hash_test.rb
|
175
|
+
- test/collection_test.rb
|
176
|
+
- test/connection_test.rb
|
177
|
+
- test/conversions_test.rb
|
178
|
+
- test/cursor_fail_test.rb
|
179
|
+
- test/cursor_message_test.rb
|
180
|
+
- test/cursor_test.rb
|
181
|
+
- test/db_api_test.rb
|
182
|
+
- test/db_connection_test.rb
|
183
|
+
- test/db_test.rb
|
184
|
+
- test/grid_file_system_test.rb
|
185
|
+
- test/grid_io_test.rb
|
186
|
+
- test/grid_test.rb
|
187
|
+
- test/replica_pairs/count_test.rb
|
188
|
+
- test/replica_pairs/insert_test.rb
|
189
|
+
- test/replica_pairs/pooled_insert_test.rb
|
190
|
+
- test/replica_pairs/query_test.rb
|
191
|
+
- test/replica_sets/connect_test.rb
|
192
|
+
- test/replica_sets/count_test.rb
|
193
|
+
- test/replica_sets/insert_test.rb
|
194
|
+
- test/replica_sets/node_type_test.rb
|
195
|
+
- test/replica_sets/pooled_insert_test.rb
|
196
|
+
- test/replica_sets/query_test.rb
|
197
|
+
- test/replica_sets/replication_ack_test.rb
|
198
|
+
- test/support/hash_with_indifferent_access.rb
|
199
|
+
- test/support/keys.rb
|
200
|
+
- test/support_test.rb
|
201
|
+
- test/test_helper.rb
|
202
|
+
- test/threading/test_threading_large_pool.rb
|
203
|
+
- test/threading_test.rb
|
204
|
+
- test/unit/collection_test.rb
|
205
|
+
- test/unit/connection_test.rb
|
206
|
+
- test/unit/cursor_test.rb
|
207
|
+
- test/unit/db_test.rb
|
data/test/bson/basic_test.rb
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
# encoding:utf-8
|
2
|
-
require './test/test_helper'
|
3
|
-
require 'complex'
|
4
|
-
require 'bigdecimal'
|
5
|
-
require 'rational'
|
6
|
-
require 'benchmark'
|
7
|
-
|
8
|
-
MEDIUM = {
|
9
|
-
'integer' => 5,
|
10
|
-
'number' => 5.05,
|
11
|
-
'boolean' => false,
|
12
|
-
'array' => ['test', 'benchmark']
|
13
|
-
}
|
14
|
-
|
15
|
-
|
16
|
-
LARGE = {
|
17
|
-
'base_url' => 'http://www.example.com/test-me',
|
18
|
-
'total_word_count' => 6743,
|
19
|
-
'access_time' => Time.now,
|
20
|
-
'meta_tags' => {
|
21
|
-
'description' => 'i am a long description string',
|
22
|
-
'author' => 'Holly Man',
|
23
|
-
'dynamically_created_meta_tag' => 'who know\n what'
|
24
|
-
},
|
25
|
-
'page_structure' => {
|
26
|
-
'counted_tags' => 3450,
|
27
|
-
'no_of_js_attached' => 10,
|
28
|
-
'no_of_images' => 6
|
29
|
-
},
|
30
|
-
'harvested_words' => ['10gen','web','open','source','application','paas',
|
31
|
-
'platform-as-a-service','technology','helps',
|
32
|
-
'developers','focus','building','mongodb','mongo'] * 20
|
33
|
-
}
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
begin
|
38
|
-
require 'active_support/core_ext'
|
39
|
-
require 'active_support/hash_with_indifferent_access'
|
40
|
-
Time.zone = "Pacific Time (US & Canada)"
|
41
|
-
Zone = Time.zone.now
|
42
|
-
rescue LoadError
|
43
|
-
warn 'Could not test BSON with HashWithIndifferentAccess.'
|
44
|
-
module ActiveSupport
|
45
|
-
class TimeWithZone
|
46
|
-
end
|
47
|
-
end
|
48
|
-
Zone = ActiveSupport::TimeWithZone.new
|
49
|
-
end
|
50
|
-
|
51
|
-
class BSONTest < Test::Unit::TestCase
|
52
|
-
include BSON
|
53
|
-
|
54
|
-
def test_string
|
55
|
-
doc = {'doc' => 'hello, world'}
|
56
|
-
bson = bson = BSON::BSON_CODER.serialize(doc)
|
57
|
-
assert_equal doc, BSON::BSON_CODER.deserialize(bson)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_object
|
61
|
-
doc = {'doc' => {'age' => 42, 'name' => 'Spongebob', 'shoe_size' => 9.5}}
|
62
|
-
bson = BSON::BSON_CODER.serialize(doc)
|
63
|
-
assert_equal doc, BSON::BSON_CODER.deserialize(bson)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_oid
|
67
|
-
doc = {'doc' => ObjectID.new}
|
68
|
-
bson = BSON::BSON_CODER.serialize(doc)
|
69
|
-
assert_equal doc, BSON::BSON_CODER.deserialize(bson)
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_array
|
73
|
-
doc = {'doc' => [1, 2, "a", "b"]}
|
74
|
-
bson = BSON::BSON_CODER.serialize(doc)
|
75
|
-
assert_equal doc, BSON::BSON_CODER.deserialize(bson)
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_speed
|
79
|
-
|
80
|
-
Benchmark.bm do |x|
|
81
|
-
x.report('serialize obj') do
|
82
|
-
1000.times do
|
83
|
-
BSON::BSON_CODER.serialize(LARGE)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
Benchmark.bm do |x|
|
91
|
-
b = BSON::BSON_CODER.serialize(LARGE)
|
92
|
-
x.report('deserialize obj') do
|
93
|
-
1000.times do
|
94
|
-
BSON::BSON_CODER.deserialize(b)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|