mongo 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -154,6 +154,33 @@ class CursorTest < Test::Unit::TestCase
154
154
  assert_equal 5, results.length
155
155
  end
156
156
 
157
+ def test_timeout_options
158
+ cursor = Cursor.new(@@coll)
159
+ assert_equal true, cursor.timeout
160
+
161
+ cursor = @@coll.find
162
+ assert_equal true, cursor.timeout
163
+
164
+ cursor = @@coll.find({}, :timeout => nil)
165
+ assert_equal true, cursor.timeout
166
+
167
+ cursor = Cursor.new(@@coll, :timeout => false)
168
+ assert_equal false, cursor.timeout
169
+
170
+ @@coll.find({}, :timeout => false) do |cursor|
171
+ assert_equal false, cursor.timeout
172
+ end
173
+ end
174
+
175
+ def test_timeout
176
+ opts = Cursor.new(@@coll).query_opts
177
+ assert_equal 0, opts & Mongo::Constants::OP_QUERY_NO_CURSOR_TIMEOUT
178
+
179
+ opts = Cursor.new(@@coll, :timeout => false).query_opts
180
+ assert_equal Mongo::Constants::OP_QUERY_NO_CURSOR_TIMEOUT,
181
+ opts & Mongo::Constants::OP_QUERY_NO_CURSOR_TIMEOUT
182
+ end
183
+
157
184
  def test_limit_exceptions
158
185
  assert_raise ArgumentError do
159
186
  cursor = @@coll.find().limit('not-an-integer')
@@ -7,8 +7,16 @@ require './test/test_helper'
7
7
  class ConnectTest < Test::Unit::TestCase
8
8
  include Mongo
9
9
 
10
+ def test_connect_bad_name
11
+ assert_raise_error(ReplicaSetConnectionError, "expected 'wrong-repl-set-name'") do
12
+ Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]],
13
+ :name => "wrong-repl-set-name")
14
+ end
15
+ end
16
+
10
17
  def test_connect
11
- @conn = Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]])
18
+ @conn = Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]],
19
+ :name => "foo")
12
20
  assert @conn.connected?
13
21
  end
14
22
 
@@ -20,4 +28,19 @@ class ConnectTest < Test::Unit::TestCase
20
28
  assert @conn.connected?
21
29
  end
22
30
 
31
+ def test_connect_with_second_node_down
32
+ puts "Please kill the node at 27018."
33
+ gets
34
+
35
+ @conn = Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]])
36
+ assert @conn.connected?
37
+ end
38
+
39
+ def test_connect_with_third_node_down
40
+ puts "Please kill the node at 27019."
41
+ gets
42
+
43
+ @conn = Mongo::Connection.multi([['localhost', 27017], ['localhost', 27018], ['localhost', 27019]])
44
+ assert @conn.connected?
45
+ end
23
46
  end
@@ -0,0 +1,42 @@
1
+ require './test/test_helper'
2
+ include Mongo
3
+
4
+ class SafeTest < Test::Unit::TestCase
5
+ context "Safe tests: " do
6
+ setup do
7
+ @con = standard_connection(:safe => {:w => 1})
8
+ @db = @con[MONGO_TEST_DB]
9
+ @col = @db['test-safe']
10
+ @col.create_index([[:a, 1]], :unique => true)
11
+ @col.remove
12
+ end
13
+
14
+ should "propogate safe option on insert" do
15
+ @col.insert({:a => 1})
16
+
17
+ assert_raise_error(OperationFailure, "duplicate key") do
18
+ @col.insert({:a => 1})
19
+ end
20
+ end
21
+
22
+ should "allow safe override on insert" do
23
+ @col.insert({:a => 1})
24
+ @col.insert({:a => 1}, :safe => false)
25
+ end
26
+
27
+ should "propogate safe option on update" do
28
+ @col.insert({:a => 1})
29
+ @col.insert({:a => 2})
30
+
31
+ assert_raise_error(OperationFailure, "duplicate key") do
32
+ @col.update({:a => 2}, {:a => 1})
33
+ end
34
+ end
35
+
36
+ should "allow safe override on update" do
37
+ @col.insert({:a => 1})
38
+ @col.insert({:a => 2})
39
+ @col.update({:a => 2}, {:a => 1}, :safe => false)
40
+ end
41
+ end
42
+ end
@@ -16,7 +16,9 @@ class DBTest < Test::Unit::TestCase
16
16
  context "DB commands" do
17
17
  setup do
18
18
  @conn = stub()
19
+ @conn.stubs(:safe)
19
20
  @db = DB.new("testing", @conn)
21
+ @db.stubs(:safe)
20
22
  @collection = mock()
21
23
  @db.stubs(:system_command_collection).returns(@collection)
22
24
  end
@@ -0,0 +1,49 @@
1
+ require './test/test_helper'
2
+
3
+ class GridTest < Test::Unit::TestCase
4
+
5
+ context "GridFS: " do
6
+ setup do
7
+ @conn = stub()
8
+ @conn.stubs(:safe)
9
+ @db = DB.new("testing", @conn)
10
+ @files = mock()
11
+ @chunks = mock()
12
+
13
+ @db.expects(:[]).with('fs.files').returns(@files)
14
+ @db.expects(:[]).with('fs.chunks').returns(@chunks)
15
+ @db.stubs(:safe)
16
+ end
17
+
18
+ context "Grid classe with standard connections" do
19
+ setup do
20
+ @conn.expects(:slave_ok?).returns(false)
21
+ end
22
+
23
+ should "create indexes for Grid" do
24
+ @chunks.expects(:create_index)
25
+ Grid.new(@db)
26
+ end
27
+
28
+ should "create indexes for GridFileSystem" do
29
+ @files.expects(:create_index)
30
+ @chunks.expects(:create_index)
31
+ GridFileSystem.new(@db)
32
+ end
33
+ end
34
+
35
+ context "Grid classes with slave connection" do
36
+ setup do
37
+ @conn.expects(:slave_ok?).returns(true)
38
+ end
39
+
40
+ should "not create indexes for Grid" do
41
+ Grid.new(@db)
42
+ end
43
+
44
+ should "not create indexes for GridFileSystem" do
45
+ GridFileSystem.new(@db)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,125 @@
1
+ require File.expand_path('./test/test_helper.rb')
2
+
3
+ class SafeTest < Test::Unit::TestCase
4
+
5
+ context "Safe mode on connection: " do
6
+ setup do
7
+ @safe_value = {:w => 7}
8
+ @con = Mongo::Connection.new('localhost', 27017, :safe => @safe_value, :connect => false)
9
+ end
10
+
11
+ should "propogate to DB" do
12
+ db = @con['foo']
13
+ assert_equal @safe_value, db.safe
14
+
15
+
16
+ db = @con.db('foo')
17
+ assert_equal @safe_value, db.safe
18
+
19
+ db = DB.new('foo', @con)
20
+ assert_equal @safe_value, db.safe
21
+ end
22
+
23
+ should "allow db override" do
24
+ db = DB.new('foo', @con, :safe => false)
25
+ assert_equal false, db.safe
26
+
27
+ db = @con.db('foo', :safe => false)
28
+ assert_equal false, db.safe
29
+ end
30
+
31
+ context "on DB: " do
32
+ setup do
33
+ @db = @con['foo']
34
+ end
35
+
36
+ should "propogate to collection" do
37
+ col = @db.collection('bar')
38
+ assert_equal @safe_value, col.safe
39
+
40
+ col = @db['bar']
41
+ assert_equal @safe_value, col.safe
42
+
43
+ col = Collection.new(@db, 'bar')
44
+ assert_equal @safe_value, col.safe
45
+ end
46
+
47
+ should "allow override on collection" do
48
+ col = @db.collection('bar', :safe => false)
49
+ assert_equal false, col.safe
50
+
51
+ col = Collection.new(@db, 'bar', :safe => false)
52
+ assert_equal false, col.safe
53
+ end
54
+ end
55
+
56
+ context "on operations supporting safe mode" do
57
+ setup do
58
+ @col = @con['foo']['bar']
59
+ end
60
+
61
+ should "use default value on insert" do
62
+ @con.expects(:send_message_with_safe_check).with do |op, msg, log, n, safe|
63
+ safe == @safe_value
64
+ end
65
+
66
+ @col.insert({:a => 1})
67
+ end
68
+
69
+ should "allow override alternate value on insert" do
70
+ @con.expects(:send_message_with_safe_check).with do |op, msg, log, n, safe|
71
+ safe == {:w => 100}
72
+ end
73
+
74
+ @col.insert({:a => 1}, :safe => {:w => 100})
75
+ end
76
+
77
+ should "allow override to disable on insert" do
78
+ @con.expects(:send_message)
79
+ @col.insert({:a => 1}, :safe => false)
80
+ end
81
+
82
+ should "use default value on update" do
83
+ @con.expects(:send_message_with_safe_check).with do |op, msg, log, n, safe|
84
+ safe == @safe_value
85
+ end
86
+
87
+ @col.update({:a => 1}, {:a => 2})
88
+ end
89
+
90
+ should "allow override alternate value on update" do
91
+ @con.expects(:send_message_with_safe_check).with do |op, msg, log, n, safe|
92
+ safe == {:w => 100}
93
+ end
94
+
95
+ @col.update({:a => 1}, {:a => 2}, :safe => {:w => 100})
96
+ end
97
+
98
+ should "allow override to disable on update" do
99
+ @con.expects(:send_message)
100
+ @col.update({:a => 1}, {:a => 2}, :safe => false)
101
+ end
102
+
103
+ should "use default value on remove" do
104
+ @con.expects(:send_message_with_safe_check).with do |op, msg, log, n, safe|
105
+ safe == @safe_value
106
+ end
107
+
108
+ @col.remove
109
+ end
110
+
111
+ should "allow override alternate value on remove" do
112
+ @con.expects(:send_message_with_safe_check).with do |op, msg, log, n, safe|
113
+ safe == {:w => 100}
114
+ end
115
+
116
+ @col.remove({}, :safe => {:w => 100})
117
+ end
118
+
119
+ should "allow override to disable on remove" do
120
+ @con.expects(:send_message)
121
+ @col.remove({}, :safe => false)
122
+ end
123
+ end
124
+ end
125
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 1
10
- version: 1.1.1
9
+ - 2
10
+ version: 1.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jim Menard
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-10-14 00:00:00 -04:00
20
+ date: 2010-11-04 00:00:00 -04:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -43,10 +43,9 @@ executables:
43
43
  extensions: []
44
44
 
45
45
  extra_rdoc_files:
46
- - README.rdoc
46
+ - README.md
47
47
  files:
48
- - README.rdoc
49
- - HISTORY
48
+ - README.md
50
49
  - Rakefile
51
50
  - mongo.gemspec
52
51
  - LICENSE.txt
@@ -63,22 +62,13 @@ files:
63
62
  - lib/mongo/gridfs/grid_io_fix.rb
64
63
  - lib/mongo/util/conversions.rb
65
64
  - lib/mongo/util/core_ext.rb
65
+ - lib/mongo/util/pool.rb
66
66
  - lib/mongo/util/server_version.rb
67
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
68
+ - docs/1.0_UPGRADE.md
69
+ - docs/CREDITS.md
70
+ - docs/HISTORY.md
71
+ - docs/TUTORIAL.md
82
72
  - bin/mongo_console
83
73
  - test/auxillary/1.4_features.rb
84
74
  - test/auxillary/authentication_test.rb
@@ -114,6 +104,7 @@ files:
114
104
  - test/replica_sets/pooled_insert_test.rb
115
105
  - test/replica_sets/query_test.rb
116
106
  - test/replica_sets/replication_ack_test.rb
107
+ - test/safe_test.rb
117
108
  - test/support/hash_with_indifferent_access.rb
118
109
  - test/support/keys.rb
119
110
  - test/support_test.rb
@@ -124,6 +115,8 @@ files:
124
115
  - test/unit/connection_test.rb
125
116
  - test/unit/cursor_test.rb
126
117
  - test/unit/db_test.rb
118
+ - test/unit/grid_test.rb
119
+ - test/unit/safe_test.rb
127
120
  has_rdoc: true
128
121
  homepage: http://www.mongodb.org
129
122
  licenses: []
@@ -131,7 +124,7 @@ licenses: []
131
124
  post_install_message:
132
125
  rdoc_options:
133
126
  - --main
134
- - README.rdoc
127
+ - README.md
135
128
  - --inline-source
136
129
  require_paths:
137
130
  - lib
@@ -195,6 +188,7 @@ test_files:
195
188
  - test/replica_sets/pooled_insert_test.rb
196
189
  - test/replica_sets/query_test.rb
197
190
  - test/replica_sets/replication_ack_test.rb
191
+ - test/safe_test.rb
198
192
  - test/support/hash_with_indifferent_access.rb
199
193
  - test/support/keys.rb
200
194
  - test/support_test.rb
@@ -205,3 +199,5 @@ test_files:
205
199
  - test/unit/connection_test.rb
206
200
  - test/unit/cursor_test.rb
207
201
  - test/unit/db_test.rb
202
+ - test/unit/grid_test.rb
203
+ - test/unit/safe_test.rb
data/HISTORY DELETED
@@ -1,215 +0,0 @@
1
- 1.1.1 2010-10-14
2
- * Several critical JRuby bug fixes
3
- * Fixes for JRuby in 1.9 mode
4
- * Check keys and move id only when necessary for JRuby encoder
5
-
6
- 1.1 2010-10-4
7
- * Official JRuby support via Java extensons for BSON (beta)
8
- * Connection#lock! and Connection#unlock! for easy fsync lock
9
- * Note: BSON::Code is no longer a subclass of String.
10
-
11
- 1.0.9 2010-9-20
12
- * Significant performance improvements
13
-
14
- 1.0.8 2010-8-27
15
-
16
- * Cursor#rewind! and more consistent Cursor Enumberable behavior
17
- * Deprecated ObjectID for ObjectId
18
- * Numerous minor bug fixes.
19
-
20
- 1.0.7 2010-8-4
21
-
22
- * A few minor test/doc fixes.
23
- * Better tests for replica sets and replication acknowledgment.
24
- * Deprecated DB#error and DB#last_status
25
-
26
- 1.0.6 2010-7-26
27
-
28
- * Replica set support.
29
- * Collection#map_reduce bug fix.
30
-
31
- 1.0.5 2010-7-13
32
-
33
- * Fix for bug introduced in 1.0.4.
34
-
35
- 1.0.4 2010-7-13
36
-
37
- * Removed deprecated
38
- - Cursor admin option
39
- - DB#query
40
- - DB#create_index (use Collection#create_index)
41
- - DB#command only takes hash options now
42
- * j2bson executable (neomantra)
43
- * Fixed bson_ext compilation on Solaris (slyphon)
44
- * System JS helpers (neovintage)
45
- * Use one mutex per thread on pooled connections (cremes)
46
- * Check for CursorNotFound response flag
47
- * MapReduce can return raw command output using :raw
48
- * BSON::OrderedHash equality with other Ruby hashes (Ryan Angilly)
49
- * Fix for broken Socket.send with large payloads (Frédéric De Jaeger)
50
- * Lots of minor improvements. See commmits.
51
-
52
- 1.0.3 2010-6-15
53
-
54
- * Optimiztion for BSON::OrderedHash
55
- * Some important fixes.
56
-
57
- 1.0.2 2010-6-5
58
- This is a minor release for fixing an incompatibility with MongoDB v1.5.2
59
-
60
- * Fix for boolean response on commands for core server v1.5.2
61
- * BSON.read_bson_document and b2json executable (neomantra)
62
- * BSON::ObjectID() shortcut for BSON::ObjectID.from_string (tmm1)
63
- * Various bug fixes.
64
-
65
- 1.0.1 2010-5-7
66
-
67
- * set Encoding.default_internal
68
- * DEPRECATE JavaScript string on Collection#find. You now must specify $where explicitly.
69
- * Added Grid#exist? and GridFileSystem#exist?
70
- * Support for replication acknowledgment
71
- * Support for $slice
72
- * Namespaced OrderedHash under BSON (sleverbor)
73
-
74
- 1.0 2010-4-29
75
- Note: if upgrading from versions prior to 0.20, be sure to upgrade
76
- to 0.20 before upgrading to 1.0.
77
-
78
- * Inspected ObjectID is represented in MongoDB extended json format.
79
- * Support for tailable cursors.
80
- * Configurable query response batch size (thx. to Aman Gupta)
81
-
82
- * bson_ext installs on early release of Ruby 1.8.5 (dfitzgibbon)
83
- * Deprecated DB#create_index. Use Collection#create_index index.
84
- * Removed deprecated Grid#put syntax; no longer requires a filename.
85
-
86
- 0.20.1 2010-4-7
87
- * Added bson gem dependency.
88
-
89
- 0.20 2010-4-7
90
- If upgrading from a previous version of the Ruby driver, please read these notes carefully,
91
- along with the 0.20_UPGRADE doc.
92
-
93
- * Support for new commands:
94
- * Collection#find_and_modify
95
- * Collection#stats
96
- * DB#stats
97
- * Query :fields options allows for values of 0 to exclude fields (houdini, railsjedi).
98
- * GridFS
99
- * Option to delete old versions of GridFileSystem entries.
100
- * Filename is now optional for Grid#put.
101
- * Option to write arbitrary attributes to a file: @grid.put(@data, :favorite_phrase => "blimey!")
102
- * Indexes created on the chunks collection are now unique. If you have an existing chunks collection,
103
- you may want to remove
104
- * Removed the following deprecated items:
105
- * GridStore class
106
- * RegexpOfHolding class
107
- * Paired connections must now be initialized with Connection.paired
108
-
109
- * BSON-related code extracted into two separate gems: bson and bson_ext (thx to Chuck Remes).
110
- * mongo_ext no longer exists.
111
- * BSON::Binary constructor can now take a string, which will be packed into an array.
112
- * Exception class adjustments:
113
- * Mongo::InvalidObjectID moved to BSON::InvalidObjectID
114
- * Mongo::InvalidDocument moved to BSON::InvalidDocument
115
- * Mongo::InvalidStringEncoding moved to BSON::InvalidStringEncoding
116
- * Mongo::InvalidName replaced by Mongo::InvalidNSName and BSON::InvalidKeyName
117
- * BSON types are now namespaced under the BSON module. These types include:
118
- * Binary
119
- * ObjectID
120
- * Code
121
- * DBRef
122
- * MinKey and MaxKey
123
- * Extensions compile on Rubinius (Chuck Remes).
124
-
125
- 0.19.3 2010-4-5
126
- * Minor fix for assert_valid_keys.
127
-
128
- 0.19.2 2010-4-5
129
- This release fixes a major bug and is the final release
130
- in the 0.19 series. The next release, 0.20.0, will introduce
131
- separate gems for bson and bson_ext and may require small
132
- changes to existing code bases. Expect that release in the next
133
- few days.
134
- * Fix for Grid#delete bug.
135
- * Log messages read like valid ruby driver code.
136
- * Cursor#has_next.
137
- * Tests for MongoDB 1.4 features.
138
- * Flexible index creation method with Mongo::GEO2D constant.
139
-
140
- 0.19.1 2010-3-2
141
- * Fix for HashWithIndifferentAccess in ActiveSupport-3.0
142
-
143
- 0.19 2010-3-1
144
- * Deprecated GridFS::GridStore. Grid and GridFileSystem classes replace
145
- the GridFS implementation with a simpler API and vastly-improved performance.
146
- See http://www.mongodb.org/display/DOCS/GridFS+in+Ruby for more details.
147
- * Safe mode for Grid and GridFileSystem.
148
- * Grid and GridFileSystem use Mime/Types to detect content type (if available)
149
- * Connection API simplified. Use Connection.paired for pairs and Connection.from_uri to
150
- use MongoDB's connection URI specification.
151
- * Authentication can be saved so that reauthentication happens automatically
152
- on reconnect.
153
- * Raise exception if authentication fails.
154
- * Raise exception if index creation fails.
155
- * Removed a number of deprecated methods and classes.
156
- * Several bug fixes.
157
- * Nearing 1.0!
158
-
159
- 0.18.3 2010-1-25
160
- * Convert docs to YARD
161
- * Support MongoDB extended JSON on ObjectID#to_json
162
- * ObjectID#from_time for performing date range queries on _id (thx., Sunny Hirai)
163
- * GridStore#mv for renaming files (Matt Powell)
164
- * Safe mode for Collection#remove (Patrick Collison)
165
- * Support BSON types MinKey and MaxKey
166
- * DEPRECATED Admin, XMLToRuby, and RegexpOfHolding classes.
167
- * Handle unsupported Numeric types gracefully (Complex, Rational, BigDecimal)
168
- * Handle unsupported Time types gracefully (Date, DateTime, ActiveSupport::TimeWithZone)
169
- * Numerous small bug fixes
170
- * Minor performance improvements
171
-
172
- 0.18.2 2009-12-29
173
- * Significant GridStore performance improvement (thx., Sunny Hirai)
174
- * Enabled support for keyf on group
175
- * Support :query option for Collection#distinct
176
- * Support :finalize option for Collection#group
177
- * (0.18.1) ObjectID#generation_time returns a created_at timestamp.
178
- * Deprecated Command#group running as a JS eval; should now be run as a command.
179
- * Deprecated Cursor#next_object for Cursor#next_document
180
- * Character encoding fixes for C extension
181
- * Enforce 4MB limit on document creation
182
- * Simplified connection pooling code
183
- * Fixes for connection pooling on Ruby 1.8.6/Windows.
184
-
185
- 0.18.1 2009-12-05
186
- * Fixed issue with negative dates in Ruby 1.9
187
- * Minor refactorings for C extension and BSON classes
188
- * Ensure UTF-8 in Ruby 1.8
189
- * Fix for connections on non-default port (Delano Mandelbaum)
190
- * More explicit test suite tasks for running with/without C extension.
191
-
192
- 0.18 2009-11-25
193
- * Connections now support connection pooling. See http://api.mongodb.org/ruby/0.18/classes/Mongo/Connection.html#M000158
194
- * Deprecated :auto_reconnect option on connection; if the driver fails to
195
- connect, it will automatically try to reconnect on the subsequent operation.
196
- See http://www.mongodb.org/display/DOCS/Replica+Pairs+in+Ruby
197
- * Added Collection#map_reduce helper (Christos Trochalakis)
198
- * Deprecated DB#db_command in favor of DB#command.
199
- * Removed deprecated old sort options, :offset, and Connection#clear.
200
- * Lots of internal code restructuring for better maintainability.
201
-
202
- 0.17.1 2009-11-17
203
- * Index ordering fix
204
- * Notice to install mongo_ext
205
-
206
- 0.17 2009-11-16
207
- * Performance improvements
208
- * large document inserts twice as fast as 0.16
209
- * queries 18% faster than 0.16 on average
210
- * see benchmark comparison: http://gist.github.com/236062
211
- * Support for multi-update for Mongo >= 1.1.3 (See Collection#update)
212
- * Collection#distinct
213
- * Connection#copy_database (voodootikigod)
214
- * C optimizations for ByteBuffer#to_s and ObjectID#generate (seancribbs)
215
- * Continue code restructuring for performance and simplicity.