mongo 1.3.0.rc0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -5,10 +5,6 @@ require 'fileutils'
5
5
  require 'rake'
6
6
  require 'rake/testtask'
7
7
  require 'rake/gempackagetask'
8
- begin
9
- require 'rake/contrib/rubyforgepublisher'
10
- rescue LoadError
11
- end
12
8
  require 'rbconfig'
13
9
  include Config
14
10
  ENV['TEST_MODE'] = 'TRUE'
@@ -146,16 +142,24 @@ task :ydoc do
146
142
  require File.join(File.dirname(__FILE__), 'lib', 'mongo')
147
143
  out = File.join('ydoc', Mongo::VERSION)
148
144
  FileUtils.rm_rf('ydoc')
149
- system "yardoc lib/**/*.rb lib/mongo/**/*.rb lib/bson/**/*.rb -e yard/yard_ext.rb -p yard/templates -o #{out} --title MongoRuby-#{Mongo::VERSION} --files docs/TUTORIAL.md,docs/GridFS.md,docs/FAQ.md,docs/REPLICA_SETS.md,docs/WRITE_CONCERN.md,docs/HISTORY.md,docs/CREDITS.md,docs/1.0_UPGRADE.md,docs/RELEASES.md"
145
+ system "yardoc lib/**/*.rb lib/mongo/**/*.rb lib/bson/**/*.rb -e yard/yard_ext.rb -p yard/templates -o #{out} --title MongoRuby-#{Mongo::VERSION} --files docs/TUTORIAL.md,docs/GridFS.md,docs/FAQ.md,docs/REPLICA_SETS.md,docs/WRITE_CONCERN.md,docs/HISTORY.md,docs/CREDITS.md,docs/RELEASES.md"
150
146
  end
151
147
 
152
148
  namespace :bamboo do
149
+ task :ci_reporter do
150
+ begin
151
+ require 'ci/reporter/rake/test_unit'
152
+ rescue LoadError
153
+ warn "Warning: Unable to load ci_reporter gem."
154
+ end
155
+ end
156
+
153
157
  namespace :test do
154
- task :ruby do
158
+ task :ruby => [:ci_reporter, "ci:setup:testunit"] do
155
159
  Rake::Task['test:ruby'].invoke
156
160
  end
157
161
 
158
- task :c do
162
+ task :c => [:ci_reporter, "ci:setup:testunit"] do
159
163
  Rake::Task['gem:install_extensions'].invoke
160
164
  Rake::Task['test:c'].invoke
161
165
  end
@@ -166,29 +170,30 @@ namespace :gem do
166
170
 
167
171
  desc "Install the gem locally"
168
172
  task :install do
169
- sh "gem build bson.gemspec"
170
- sh "gem install --no-rdoc --no-ri bson-*.gem"
173
+ `gem build bson.gemspec`
174
+ `gem install --no-rdoc --no-ri bson-*.gem`
171
175
 
172
- sh "gem build mongo.gemspec"
173
- sh "gem install --no-rdoc --no-ri mongo-*.gem"
176
+ `gem build mongo.gemspec`
177
+ `gem install --no-rdoc --no-ri mongo-*.gem`
174
178
 
175
- sh "rm mongo-*.gem"
176
- sh "rm bson-*.gem"
179
+ `rm mongo-*.gem`
180
+ `rm bson-*.gem`
177
181
  end
178
182
 
179
183
  desc "Install the optional c extensions"
180
184
  task :install_extensions do
181
- sh "gem build bson_ext.gemspec"
182
- sh "gem install --no-rdoc --no-ri bson_ext-*.gem"
183
- sh "rm bson_ext-*.gem"
185
+ `gem uninstall bson_ext`
186
+ `gem build bson_ext.gemspec`
187
+ `gem install --no-rdoc --no-ri bson_ext-*.gem`
188
+ `rm bson_ext-*.gem`
184
189
  end
185
190
 
186
191
  desc "Build all gems"
187
192
  task :build_all do
188
- sh "gem build mongo.gemspec"
189
- sh "gem build bson.gemspec"
190
- sh "gem build bson.java.gemspec"
191
- sh "gem build bson_ext.gemspec"
193
+ `gem build mongo.gemspec`
194
+ `gem build bson.gemspec`
195
+ `gem build bson.java.gemspec`
196
+ `gem build bson_ext.gemspec`
192
197
  end
193
198
 
194
199
  end
@@ -1,28 +1,28 @@
1
1
  # MongoDB Ruby Driver History
2
2
 
3
- ### 1.3.0.rc0
4
- 2011-3-29
3
+ ### 1.3.0
4
+ 2011-4-04
5
5
 
6
- * Add option to set timeouts on socket read calls. Use
7
- the :op_timeout option when creating a new connection.
6
+ * Add option to set timeouts on socket read calls using the
7
+ Mongo::Connection :op_timeout option.
8
8
  * Add StringIO methods to GridIO objects
9
9
  * Support for BSON timestamp type with BSON::Timestamp
10
10
  * Change the BSON binary subtype from 2 to 0
11
11
  * Remove private method Connection#reset_conection
12
12
  and deprecate public method ReplSetConnection#reset_connection
13
- * ByteBuffer#== and OrderedHash#dup (FooBarWidget)
13
+ * ByteBuffer#== and OrderedHash#dup (Hongli Lai)
14
14
  * Better check for UTF8 validity in Ruby 1.9
15
15
  * Added previously removed Connection#host and Connection#port
16
- * Added transformers to allow Mongo::Cursor to allow instantiated objects (jnunemaker)
16
+ * Added transformers to allow Mongo::Cursor to allow instantiated objects (John Nunemaker)
17
17
  * Automated reconnection on fork
18
18
  * Added Cursor#next alias for Cursor#next_document
19
- * Audit tests after enabling warnings (wpiekutowski)
20
- * Various bug fixes thanks to FooBarWidget, Datanoise, Malitogeek
19
+ * Audit tests after enabling warnings (Wojciech Piekutowski)
20
+ * Various bug fixes thanks to Datanoise, Hongli Lai, and Mauro Pompilio
21
21
 
22
22
  ### 1.2.4
23
23
  2011-2-23
24
24
 
25
- * Fix the exception message shown when there's an IOError (malditogeek)
25
+ * Fix the exception message shown when there's an IOError (Mauro Pompilio)
26
26
  * Another update to map-reduce docs for v1.8. Note that if you use the new
27
27
  output option {:out => {:inline => true}}, then you must also specify
28
28
  :raw => true.
@@ -19,7 +19,7 @@
19
19
  $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
20
20
 
21
21
  module Mongo
22
- VERSION = "1.3.0.rc0"
22
+ VERSION = "1.3.0"
23
23
  end
24
24
 
25
25
  module Mongo
@@ -0,0 +1,20 @@
1
+
2
+ class Foo
3
+
4
+ def zed
5
+ puts "Foo"
6
+ end
7
+
8
+ end
9
+
10
+ class Bar < Foo
11
+
12
+ def zed(n=nil)
13
+ if n.nil?
14
+ puts "Bar"
15
+ else
16
+ super()
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,224 @@
1
+ require 'test/test_helper'
2
+
3
+ class TestCollection < Test::Unit::TestCase
4
+ @@connection ||= Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT)
5
+ @@db = @@connection.db(MONGO_TEST_DB)
6
+ @@test = @@db.collection("test")
7
+ @@version = @@connection.server_version
8
+
9
+ def setup
10
+ @@test.remove
11
+ end
12
+
13
+ def wait_for_async
14
+ sleep 0.2
15
+ end
16
+
17
+ def test_async_update
18
+ id1 = @@test.save("x" => 5)
19
+ failsafe = mock('failsafe will get called in block', :call => true)
20
+
21
+ @@test.update({}, {"$inc" => {"x" => 1}}, :async => true) do |error, result|
22
+ assert_nil error
23
+ assert result
24
+ failsafe.call
25
+ end
26
+ wait_for_async
27
+
28
+ assert_equal 1, @@test.count()
29
+ assert_equal 6, @@test.find_one(:_id => id1)["x"]
30
+ end
31
+
32
+ if @@version >= "1.1.3"
33
+ def test_async_multi_update
34
+ failsafe = mock('failsafe will get called in block', :call => true)
35
+
36
+ @@test.save("num" => 10)
37
+ @@test.save("num" => 10)
38
+ @@test.save("num" => 10)
39
+ assert_equal 3, @@test.count
40
+
41
+ @@test.update({"num" => 10}, {"$set" => {"num" => 100}}, :multi => true, :async => true) do |error, result|
42
+ assert_nil error
43
+ assert result
44
+ failsafe.call
45
+ end
46
+ wait_for_async
47
+ end
48
+ end
49
+
50
+ def test_async_upsert
51
+ failsafe = mock('failsafe will get called in block')
52
+ failsafe.expects(:call).times(2)
53
+
54
+ @@test.update({"page" => "/"}, {"$inc" => {"count" => 1}}, :upsert => true, :async => true) do |error, result|
55
+ assert_nil error
56
+ assert result
57
+ failsafe.call
58
+ end
59
+
60
+ @@test.update({"page" => "/"}, {"$inc" => {"count" => 1}}, :upsert => true, :async => true) do |error, result|
61
+ assert_nil error
62
+ assert result
63
+ failsafe.call
64
+ end
65
+ wait_for_async
66
+
67
+ assert_equal 1, @@test.count()
68
+ assert_equal 2, @@test.find_one()["count"]
69
+ end
70
+
71
+ def test_async_save
72
+ failsafe = mock('failsafe will get called in block', :call => true)
73
+
74
+ # note that the first parameter has explicit curly brackets around
75
+ # the hash; without those brackets as a delimiter, the :async key is
76
+ # viewed as part of the required +document+ parameter
77
+ @@test.save({"hello" => "world"}, :async => true) do |error, result|
78
+ assert_nil error
79
+ assert result
80
+ failsafe.call
81
+ end
82
+ wait_for_async
83
+
84
+ assert_equal "world", @@test.find_one()["hello"]
85
+ end
86
+
87
+ def test_async_save_with_exception
88
+ failsafe = mock('failsafe will get called in block', :call => true)
89
+
90
+ @@test.create_index("hello", :unique => true)
91
+ @@test.save("hello" => "world")
92
+
93
+ # all async calls on collections occur in :safe mode
94
+ @@test.save({"hello" => "world"}, :async => true) do |error, result|
95
+ assert error
96
+ assert error.instance_of?(OperationFailure)
97
+ assert_nil result
98
+ failsafe.call
99
+ end
100
+ wait_for_async
101
+
102
+ assert_equal 1, @@test.count()
103
+ @@test.drop
104
+ end
105
+
106
+ def test_async_remove
107
+ failsafe = mock('failsafe will get called in block', :call => true)
108
+
109
+ @conn = Connection.new
110
+ @db = @conn[MONGO_TEST_DB]
111
+ @test = @db['test-async-remove']
112
+ @test.save({:a => 50})
113
+ @test.remove({}, :async => true) do |error, result|
114
+ assert_nil error
115
+ assert result
116
+ failsafe.call
117
+ end
118
+ wait_for_async
119
+
120
+ @test.drop
121
+ end
122
+
123
+ def test_async_count
124
+ failsafe = mock('failsafe will get called in block', :call => true)
125
+
126
+ @@test.drop
127
+
128
+ @@test.save("x" => 1)
129
+ @@test.save("x" => 2)
130
+
131
+ @@test.count(:async => true) do |error, result|
132
+ assert_nil error
133
+ assert_equal 2, result
134
+ failsafe.call
135
+ end
136
+ wait_for_async
137
+ end
138
+
139
+ # Note: #size is just an alias for #count.
140
+ def test_async_size
141
+ failsafe = mock('failsafe will get called in block', :call => true)
142
+
143
+ @@test.drop
144
+
145
+ @@test.save("x" => 1)
146
+ @@test.save("x" => 2)
147
+
148
+ @@test.size(:async => true) do |error, result|
149
+ assert_nil error
150
+ assert_equal 2, result
151
+ failsafe.call
152
+ end
153
+ wait_for_async
154
+ end
155
+
156
+ def test_async_find_one
157
+ failsafe = mock('failsafe will get called in block', :call => true)
158
+
159
+ id = @@test.save("hello" => "world", "foo" => "bar")
160
+
161
+ @@test.find_one({}, :async => true) do |error, result|
162
+ assert_nil error
163
+ assert_equal @@test.find_one(id), result
164
+ failsafe.call
165
+ end
166
+ wait_for_async
167
+ end
168
+
169
+ def test_async_insert
170
+ failsafe = mock('failsafe will get called in block', :call => true)
171
+
172
+ doc = {"hello" => "world"}
173
+ @@test.insert(doc, :async => true) do |error, result|
174
+ assert_nil error
175
+ assert result
176
+ failsafe.call
177
+ end
178
+ wait_for_async
179
+
180
+ assert_equal 1, @@test.count
181
+ end
182
+
183
+ def test_async_find
184
+ assert_raise RuntimeError do
185
+ @@test.find({}, :async => true)
186
+ end
187
+ end
188
+
189
+ if @@version > "1.3.0"
190
+ def test_async_find_and_modify
191
+ failsafe = mock('failsafe will get called in block', :call => true)
192
+
193
+ @@test << { :a => 1, :processed => false }
194
+ @@test << { :a => 2, :processed => false }
195
+ @@test << { :a => 3, :processed => false }
196
+
197
+ @@test.find_and_modify(:query => {}, :sort => [['a', -1]], :update => {"$set" => {:processed => true}}, :async => true) do |error, result|
198
+ assert_nil error
199
+ assert result
200
+ failsafe.call
201
+ end
202
+ wait_for_async
203
+
204
+ assert @@test.find_one({:a => 3})['processed']
205
+ end
206
+
207
+ def test_async_find_and_modify_with_invalid_options
208
+ failsafe = mock('failsafe will get called in block', :call => true)
209
+
210
+ @@test << { :a => 1, :processed => false }
211
+ @@test << { :a => 2, :processed => false }
212
+ @@test << { :a => 3, :processed => false }
213
+
214
+ @@test.find_and_modify(:blimey => {}, :async => true) do |error, result|
215
+ assert error
216
+ assert error.instance_of?(OperationFailure)
217
+ assert_nil result
218
+ failsafe.call
219
+ end
220
+ wait_for_async
221
+ end
222
+ end
223
+
224
+ end
@@ -0,0 +1,24 @@
1
+ require 'test/test_helper'
2
+ include Mongo
3
+
4
+ class ConnectionTest < Test::Unit::TestCase
5
+ context "Initialization: " do
6
+
7
+ context "given async connection options" do
8
+
9
+ should "default the workers pool to 1" do
10
+ Async::WorkerPool.expects(:new).with(1)
11
+
12
+ Connection.new('localhost', 27017)
13
+ end
14
+
15
+ should "override the workers pool size with the :worker_pool_size key" do
16
+ size = 6
17
+ Async::WorkerPool.expects(:new).with(size)
18
+
19
+ Connection.new('localhost', 27017, :worker_pool_size => size)
20
+ end
21
+ end # context 'given async connection options'
22
+
23
+ end # context 'Initialization'
24
+ end
@@ -0,0 +1,162 @@
1
+ require 'test/test_helper'
2
+ require 'logger'
3
+
4
+ class CursorTest < Test::Unit::TestCase
5
+
6
+ include Mongo
7
+
8
+ @@connection = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
9
+ ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT)
10
+ @@db = @@connection.db(MONGO_TEST_DB)
11
+ @@coll = @@db.collection('test')
12
+ @@version = @@connection.server_version
13
+
14
+ def wait_for_async
15
+ sleep 0.2
16
+ end
17
+
18
+ def setup
19
+ @@coll.remove
20
+ @@coll.insert('a' => 1) # collection not created until it's used
21
+ @@coll_full_name = "#{MONGO_TEST_DB}.test"
22
+ end
23
+
24
+ def test_async_explain
25
+ failsafe = mock('failsafe will get called in block', :call => true)
26
+
27
+ cursor = @@coll.find('a' => 1)
28
+
29
+ cursor.explain(:async => true) do |error, result|
30
+ assert_not_nil result['cursor']
31
+ assert_kind_of Numeric, result['n']
32
+ assert_kind_of Numeric, result['millis']
33
+ assert_kind_of Numeric, result['nscanned']
34
+ failsafe.call
35
+ end
36
+ wait_for_async
37
+ end
38
+
39
+ def test_async_count
40
+ failsafe = mock('failsafe will get called in block')
41
+ failsafe.expects(:call).times(3)
42
+
43
+ @@coll.remove
44
+
45
+ @@coll.find.count(:async => true) do |error, count|
46
+ assert_equal 0, count
47
+ failsafe.call
48
+ end
49
+ wait_for_async
50
+
51
+ 10.times do |i|
52
+ @@coll.save("x" => i)
53
+ end
54
+
55
+ @@coll.find.count(:async => true) do |error, count|
56
+ assert_equal 10, count
57
+ failsafe.call
58
+ end
59
+ wait_for_async
60
+
61
+ @@coll.find({"x" => 1}).count(:async => true) do |error, count|
62
+ assert_equal 1, count
63
+ failsafe.call
64
+ end
65
+ wait_for_async
66
+ end
67
+
68
+ def test_async_close
69
+ failsafe = mock('failsafe will get called in block', :call => true)
70
+
71
+ @@coll.remove
72
+ cursor = @@coll.find
73
+
74
+ cursor.close(:async => true) do |error, result|
75
+ assert_nil error
76
+ assert result
77
+ assert cursor.closed?
78
+ failsafe.call
79
+ end
80
+ wait_for_async
81
+ end
82
+
83
+ def test_async_has_next
84
+ failsafe = mock('failsafe will get called in block', :call => true)
85
+
86
+ @@coll.remove
87
+ 200.times do |n|
88
+ @@coll.save("x" => n)
89
+ end
90
+
91
+ cursor = @@coll.find
92
+ cursor.has_next?(:async => true) do |error, result|
93
+ assert_nil error
94
+ assert result
95
+ failsafe.call
96
+ end
97
+ wait_for_async
98
+ end
99
+
100
+ def test_async_next_document
101
+ failsafe = mock('failsafe will get called in block')
102
+ failsafe.expects(:call).times(2)
103
+
104
+ @@coll.remove
105
+ 200.times do |n|
106
+ @@coll.save("x" => n)
107
+ end
108
+
109
+ cursor = @@coll.find
110
+ cursor.next_document(:async => true) do |error, result|
111
+ assert_nil error
112
+ assert result
113
+ failsafe.call
114
+ end
115
+ wait_for_async
116
+
117
+ callback = Proc.new do |error, result|
118
+ assert_nil error
119
+ assert result
120
+ failsafe.call
121
+ end
122
+
123
+ cursor.next_document(:async => true, :callback => callback)
124
+ wait_for_async
125
+ end
126
+
127
+ def test_async_to_a
128
+ failsafe = mock('failsafe will get called in block')
129
+ failsafe.expects(:call)
130
+
131
+ @@coll.remove
132
+ total = 200
133
+ total.times do |n|
134
+ @@coll.save("x" => n)
135
+ end
136
+
137
+ cursor = @@coll.find
138
+ cursor.to_a(:async => true) do |error, result|
139
+ assert_nil error
140
+ assert_equal total, result.size
141
+ failsafe.call
142
+ end
143
+ wait_for_async
144
+ end
145
+
146
+ def test_async_each
147
+ @@coll.remove
148
+ total = 200
149
+ total.times do |n|
150
+ @@coll.save("x" => n)
151
+ end
152
+
153
+ cursor = @@coll.find
154
+ count = 0
155
+ cursor.each(:async => true) do |error, result|
156
+ count += 1
157
+ end
158
+ wait_for_async
159
+
160
+ assert_equal total, count
161
+ end
162
+ end