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.
Files changed (81) hide show
  1. data/README.rdoc +353 -0
  2. data/Rakefile +62 -0
  3. data/bin/bson_benchmark.rb +59 -0
  4. data/bin/mongo_console +21 -0
  5. data/bin/run_test_script +19 -0
  6. data/bin/standard_benchmark +109 -0
  7. data/examples/admin.rb +41 -0
  8. data/examples/benchmarks.rb +42 -0
  9. data/examples/blog.rb +76 -0
  10. data/examples/capped.rb +23 -0
  11. data/examples/cursor.rb +47 -0
  12. data/examples/gridfs.rb +87 -0
  13. data/examples/index_test.rb +125 -0
  14. data/examples/info.rb +30 -0
  15. data/examples/queries.rb +69 -0
  16. data/examples/simple.rb +23 -0
  17. data/examples/strict.rb +34 -0
  18. data/examples/types.rb +35 -0
  19. data/lib/mongo.rb +19 -0
  20. data/lib/mongo/admin.rb +83 -0
  21. data/lib/mongo/collection.rb +415 -0
  22. data/lib/mongo/connection.rb +151 -0
  23. data/lib/mongo/cursor.rb +279 -0
  24. data/lib/mongo/db.rb +560 -0
  25. data/lib/mongo/errors.rb +26 -0
  26. data/lib/mongo/gridfs.rb +16 -0
  27. data/lib/mongo/gridfs/chunk.rb +92 -0
  28. data/lib/mongo/gridfs/grid_store.rb +464 -0
  29. data/lib/mongo/message.rb +20 -0
  30. data/lib/mongo/message/get_more_message.rb +32 -0
  31. data/lib/mongo/message/insert_message.rb +37 -0
  32. data/lib/mongo/message/kill_cursors_message.rb +31 -0
  33. data/lib/mongo/message/message.rb +80 -0
  34. data/lib/mongo/message/message_header.rb +45 -0
  35. data/lib/mongo/message/msg_message.rb +29 -0
  36. data/lib/mongo/message/opcodes.rb +27 -0
  37. data/lib/mongo/message/query_message.rb +78 -0
  38. data/lib/mongo/message/remove_message.rb +37 -0
  39. data/lib/mongo/message/update_message.rb +38 -0
  40. data/lib/mongo/query.rb +118 -0
  41. data/lib/mongo/types/binary.rb +38 -0
  42. data/lib/mongo/types/code.rb +30 -0
  43. data/lib/mongo/types/dbref.rb +33 -0
  44. data/lib/mongo/types/objectid.rb +143 -0
  45. data/lib/mongo/types/regexp_of_holding.rb +40 -0
  46. data/lib/mongo/util/bson.rb +546 -0
  47. data/lib/mongo/util/byte_buffer.rb +167 -0
  48. data/lib/mongo/util/ordered_hash.rb +113 -0
  49. data/lib/mongo/util/xml_to_ruby.rb +105 -0
  50. data/mongo-ruby-driver.gemspec +103 -0
  51. data/test/mongo-qa/_common.rb +8 -0
  52. data/test/mongo-qa/admin +26 -0
  53. data/test/mongo-qa/capped +22 -0
  54. data/test/mongo-qa/count1 +18 -0
  55. data/test/mongo-qa/dbs +22 -0
  56. data/test/mongo-qa/find +10 -0
  57. data/test/mongo-qa/find1 +15 -0
  58. data/test/mongo-qa/gridfs_in +16 -0
  59. data/test/mongo-qa/gridfs_out +17 -0
  60. data/test/mongo-qa/indices +49 -0
  61. data/test/mongo-qa/remove +25 -0
  62. data/test/mongo-qa/stress1 +35 -0
  63. data/test/mongo-qa/test1 +11 -0
  64. data/test/mongo-qa/update +18 -0
  65. data/test/test_admin.rb +69 -0
  66. data/test/test_bson.rb +268 -0
  67. data/test/test_byte_buffer.rb +69 -0
  68. data/test/test_chunk.rb +84 -0
  69. data/test/test_collection.rb +249 -0
  70. data/test/test_connection.rb +101 -0
  71. data/test/test_cursor.rb +331 -0
  72. data/test/test_db.rb +185 -0
  73. data/test/test_db_api.rb +798 -0
  74. data/test/test_db_connection.rb +18 -0
  75. data/test/test_grid_store.rb +284 -0
  76. data/test/test_message.rb +35 -0
  77. data/test/test_objectid.rb +105 -0
  78. data/test/test_ordered_hash.rb +138 -0
  79. data/test/test_round_trip.rb +120 -0
  80. data/test/test_threading.rb +37 -0
  81. 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