pahagon-mongo-abd 0.14.1
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.
- data/README.rdoc +353 -0
- data/Rakefile +62 -0
- data/bin/bson_benchmark.rb +59 -0
- data/bin/mongo_console +21 -0
- data/bin/run_test_script +19 -0
- data/bin/standard_benchmark +109 -0
- data/examples/admin.rb +41 -0
- data/examples/benchmarks.rb +42 -0
- data/examples/blog.rb +76 -0
- data/examples/capped.rb +23 -0
- data/examples/cursor.rb +47 -0
- data/examples/gridfs.rb +87 -0
- data/examples/index_test.rb +125 -0
- data/examples/info.rb +30 -0
- data/examples/queries.rb +69 -0
- data/examples/simple.rb +23 -0
- data/examples/strict.rb +34 -0
- data/examples/types.rb +35 -0
- data/lib/mongo.rb +19 -0
- data/lib/mongo/admin.rb +83 -0
- data/lib/mongo/collection.rb +415 -0
- data/lib/mongo/connection.rb +151 -0
- data/lib/mongo/cursor.rb +279 -0
- data/lib/mongo/db.rb +560 -0
- data/lib/mongo/errors.rb +26 -0
- data/lib/mongo/gridfs.rb +16 -0
- data/lib/mongo/gridfs/chunk.rb +92 -0
- data/lib/mongo/gridfs/grid_store.rb +464 -0
- data/lib/mongo/message.rb +20 -0
- data/lib/mongo/message/get_more_message.rb +32 -0
- data/lib/mongo/message/insert_message.rb +37 -0
- data/lib/mongo/message/kill_cursors_message.rb +31 -0
- data/lib/mongo/message/message.rb +80 -0
- data/lib/mongo/message/message_header.rb +45 -0
- data/lib/mongo/message/msg_message.rb +29 -0
- data/lib/mongo/message/opcodes.rb +27 -0
- data/lib/mongo/message/query_message.rb +78 -0
- data/lib/mongo/message/remove_message.rb +37 -0
- data/lib/mongo/message/update_message.rb +38 -0
- data/lib/mongo/query.rb +118 -0
- data/lib/mongo/types/binary.rb +38 -0
- data/lib/mongo/types/code.rb +30 -0
- data/lib/mongo/types/dbref.rb +33 -0
- data/lib/mongo/types/objectid.rb +143 -0
- data/lib/mongo/types/regexp_of_holding.rb +40 -0
- data/lib/mongo/util/bson.rb +546 -0
- data/lib/mongo/util/byte_buffer.rb +167 -0
- data/lib/mongo/util/ordered_hash.rb +113 -0
- data/lib/mongo/util/xml_to_ruby.rb +105 -0
- data/mongo-ruby-driver.gemspec +103 -0
- data/test/mongo-qa/_common.rb +8 -0
- data/test/mongo-qa/admin +26 -0
- data/test/mongo-qa/capped +22 -0
- data/test/mongo-qa/count1 +18 -0
- data/test/mongo-qa/dbs +22 -0
- data/test/mongo-qa/find +10 -0
- data/test/mongo-qa/find1 +15 -0
- data/test/mongo-qa/gridfs_in +16 -0
- data/test/mongo-qa/gridfs_out +17 -0
- data/test/mongo-qa/indices +49 -0
- data/test/mongo-qa/remove +25 -0
- data/test/mongo-qa/stress1 +35 -0
- data/test/mongo-qa/test1 +11 -0
- data/test/mongo-qa/update +18 -0
- data/test/test_admin.rb +69 -0
- data/test/test_bson.rb +268 -0
- data/test/test_byte_buffer.rb +69 -0
- data/test/test_chunk.rb +84 -0
- data/test/test_collection.rb +249 -0
- data/test/test_connection.rb +101 -0
- data/test/test_cursor.rb +331 -0
- data/test/test_db.rb +185 -0
- data/test/test_db_api.rb +798 -0
- data/test/test_db_connection.rb +18 -0
- data/test/test_grid_store.rb +284 -0
- data/test/test_message.rb +35 -0
- data/test/test_objectid.rb +105 -0
- data/test/test_ordered_hash.rb +138 -0
- data/test/test_round_trip.rb +120 -0
- data/test/test_threading.rb +37 -0
- metadata +135 -0
@@ -0,0 +1,120 @@
|
|
1
|
+
HERE = File.dirname(__FILE__)
|
2
|
+
$LOAD_PATH[0,0] = File.join(HERE, '..', 'lib')
|
3
|
+
require 'mongo'
|
4
|
+
require 'mongo/util/xml_to_ruby'
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
# For each xml/bson file in the data subdirectory, we turn the XML into an
|
8
|
+
# OrderedHash and then test both Ruby-to-BSON and BSON-to-Ruby translations.
|
9
|
+
#
|
10
|
+
# There is a whole other project that includes similar tests
|
11
|
+
# (http://github.com/mongodb/mongo-qa). If the directory ../../mongo-qa
|
12
|
+
# exists, (that is, the top-level dir of mongo-qa is next to the top-level dir
|
13
|
+
# of this project), then we find the BSON test files there and use those, too.
|
14
|
+
class RoundTripTest < Test::Unit::TestCase
|
15
|
+
|
16
|
+
include Mongo
|
17
|
+
|
18
|
+
@@ruby = nil
|
19
|
+
|
20
|
+
def setup
|
21
|
+
unless @@ruby
|
22
|
+
names = Dir[File.join(HERE, 'data', '*.xml')].collect {|f| File.basename(f).sub(/\.xml$/, '') }
|
23
|
+
@@ruby = {}
|
24
|
+
names.each { |name|
|
25
|
+
File.open(File.join(HERE, 'data', "#{name}.xml")) { |f|
|
26
|
+
@@ruby[name] = XMLToRuby.new.xml_to_ruby(f)
|
27
|
+
}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_dummy
|
33
|
+
assert true
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.create_test_for_round_trip_files_in_dir(dir)
|
37
|
+
names = Dir[File.join(dir, '*.xson')].collect {|f| File.basename(f).sub(/\.xson$/, '') }
|
38
|
+
names.each { |name|
|
39
|
+
eval <<EOS
|
40
|
+
def test_#{name}_#{dir.gsub(/[^a-zA-Z0-9_]/, '_')}
|
41
|
+
one_round_trip("#{dir}", "#{name}")
|
42
|
+
end
|
43
|
+
EOS
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
# Dynamically generate one test for each test file. This way, if one test
|
48
|
+
# fails the others will still run.
|
49
|
+
create_test_for_round_trip_files_in_dir(File.join(HERE, 'data'))
|
50
|
+
mongo_qa_dir = File.join(HERE, '../..', 'mongo-qa/modules/bson_tests/tests')
|
51
|
+
if File.exist?(mongo_qa_dir)
|
52
|
+
%w(basic_types complex single_types).each { |subdir_name|
|
53
|
+
create_test_for_round_trip_files_in_dir(File.join(mongo_qa_dir, subdir_name))
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
# Round-trip comparisons of Ruby-to-BSON and back.
|
58
|
+
# * Take the objects that were read from XML
|
59
|
+
# * Turn them into BSON bytes
|
60
|
+
# * Compare that with the BSON files we have
|
61
|
+
# * Turn those BSON bytes back in to Ruby objects
|
62
|
+
# * Turn them back into BSON bytes
|
63
|
+
# * Compare that with the BSON files we have (or the bytes that were already
|
64
|
+
# generated)
|
65
|
+
def one_round_trip(dir, name)
|
66
|
+
obj = File.open(File.join(dir, "#{name}.xson")) { |f|
|
67
|
+
begin
|
68
|
+
XMLToRuby.new.xml_to_ruby(f)
|
69
|
+
rescue => ex # unsupported type
|
70
|
+
return
|
71
|
+
end
|
72
|
+
}
|
73
|
+
|
74
|
+
File.open(File.join(dir, "#{name}.bson"), 'rb') { |f|
|
75
|
+
# Read the BSON from the file
|
76
|
+
bson = f.read
|
77
|
+
bson = if RUBY_VERSION >= '1.9'
|
78
|
+
bson.bytes.to_a
|
79
|
+
else
|
80
|
+
bson.split(//).collect { |c| c[0] }
|
81
|
+
end
|
82
|
+
|
83
|
+
# Turn the Ruby object into BSON bytes and compare with the BSON bytes
|
84
|
+
# from the file.
|
85
|
+
bson_from_ruby = BSON.new.serialize(obj).to_a
|
86
|
+
|
87
|
+
begin
|
88
|
+
assert_equal bson.length, bson_from_ruby.length
|
89
|
+
assert_equal bson, bson_from_ruby
|
90
|
+
rescue => ex
|
91
|
+
# File.open(File.join(dir, "#{name}_out_a.bson"), 'wb') { |f| # DEBUG
|
92
|
+
# bson_from_ruby.each { |b| f.putc(b) }
|
93
|
+
# }
|
94
|
+
raise ex
|
95
|
+
end
|
96
|
+
|
97
|
+
# Turn those BSON bytes back into a Ruby object.
|
98
|
+
#
|
99
|
+
# We're passing a nil db to the contructor here, but that's OK because
|
100
|
+
# the BSON DBRef bytes don't contain the db object in any case, and we
|
101
|
+
# don't care what the database is.
|
102
|
+
obj_from_bson = BSON.new.deserialize(ByteBuffer.new(bson_from_ruby))
|
103
|
+
assert_kind_of OrderedHash, obj_from_bson
|
104
|
+
|
105
|
+
# Turn that Ruby object into BSON and compare it to the original BSON
|
106
|
+
# bytes.
|
107
|
+
bson_from_ruby = BSON.new.serialize(obj_from_bson).to_a
|
108
|
+
begin
|
109
|
+
assert_equal bson.length, bson_from_ruby.length
|
110
|
+
assert_equal bson, bson_from_ruby
|
111
|
+
rescue => ex
|
112
|
+
# File.open(File.join(dir, "#{name}_out_b.bson"), 'wb') { |f| # DEBUG
|
113
|
+
# bson_from_ruby.each { |b| f.putc(b) }
|
114
|
+
# }
|
115
|
+
raise ex
|
116
|
+
end
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
require 'mongo'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TestThreading < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Mongo
|
8
|
+
|
9
|
+
@@host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
10
|
+
@@port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
11
|
+
@@db = Connection.new(@@host, @@port).db('ruby-mongo-test')
|
12
|
+
@@coll = @@db.collection('thread-test-collection')
|
13
|
+
|
14
|
+
def test_threading
|
15
|
+
@@coll.clear
|
16
|
+
|
17
|
+
1000.times do |i|
|
18
|
+
@@coll.insert("x" => i)
|
19
|
+
end
|
20
|
+
|
21
|
+
threads = []
|
22
|
+
|
23
|
+
10.times do |i|
|
24
|
+
threads[i] = Thread.new{
|
25
|
+
sum = 0
|
26
|
+
@@coll.find().each { |document|
|
27
|
+
sum += document["x"]
|
28
|
+
}
|
29
|
+
assert_equal 499500, sum
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
10.times do |i|
|
34
|
+
threads[i].join
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pahagon-mongo-abd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.14.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jim Menard
|
8
|
+
- Mike Dirolf
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-05-16 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: A Ruby driver for the 10gen Mongo DB. For more information about Mongo, see http://www.mongodb.org.
|
18
|
+
email: mongodb-dev@googlegroups.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- README.rdoc
|
27
|
+
- Rakefile
|
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
|
45
|
+
- lib/mongo/admin.rb
|
46
|
+
- lib/mongo/collection.rb
|
47
|
+
- lib/mongo/connection.rb
|
48
|
+
- lib/mongo/cursor.rb
|
49
|
+
- lib/mongo/db.rb
|
50
|
+
- lib/mongo/gridfs/chunk.rb
|
51
|
+
- lib/mongo/gridfs/grid_store.rb
|
52
|
+
- 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
|
+
- lib/mongo/types/binary.rb
|
67
|
+
- lib/mongo/types/code.rb
|
68
|
+
- lib/mongo/types/dbref.rb
|
69
|
+
- lib/mongo/types/objectid.rb
|
70
|
+
- lib/mongo/types/regexp_of_holding.rb
|
71
|
+
- lib/mongo/util/bson.rb
|
72
|
+
- lib/mongo/util/byte_buffer.rb
|
73
|
+
- lib/mongo/util/ordered_hash.rb
|
74
|
+
- lib/mongo/util/xml_to_ruby.rb
|
75
|
+
- lib/mongo.rb
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: http://www.mongodb.org
|
78
|
+
licenses:
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options:
|
81
|
+
- --main
|
82
|
+
- README.rdoc
|
83
|
+
- --inline-source
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0"
|
91
|
+
version:
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: "0"
|
97
|
+
version:
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.3.5
|
102
|
+
signing_key:
|
103
|
+
specification_version: 2
|
104
|
+
summary: Ruby driver for the 10gen Mongo DB
|
105
|
+
test_files:
|
106
|
+
- test/mongo-qa/_common.rb
|
107
|
+
- test/mongo-qa/admin
|
108
|
+
- test/mongo-qa/capped
|
109
|
+
- test/mongo-qa/count1
|
110
|
+
- test/mongo-qa/dbs
|
111
|
+
- test/mongo-qa/find
|
112
|
+
- test/mongo-qa/find1
|
113
|
+
- test/mongo-qa/gridfs_in
|
114
|
+
- test/mongo-qa/gridfs_out
|
115
|
+
- test/mongo-qa/indices
|
116
|
+
- test/mongo-qa/remove
|
117
|
+
- test/mongo-qa/stress1
|
118
|
+
- test/mongo-qa/test1
|
119
|
+
- test/mongo-qa/update
|
120
|
+
- test/test_admin.rb
|
121
|
+
- test/test_bson.rb
|
122
|
+
- test/test_byte_buffer.rb
|
123
|
+
- test/test_chunk.rb
|
124
|
+
- test/test_collection.rb
|
125
|
+
- test/test_connection.rb
|
126
|
+
- test/test_cursor.rb
|
127
|
+
- test/test_db.rb
|
128
|
+
- test/test_db_api.rb
|
129
|
+
- test/test_db_connection.rb
|
130
|
+
- test/test_grid_store.rb
|
131
|
+
- test/test_message.rb
|
132
|
+
- test/test_objectid.rb
|
133
|
+
- test/test_ordered_hash.rb
|
134
|
+
- test/test_threading.rb
|
135
|
+
- test/test_round_trip.rb
|