mongo 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@ require './test/test_helper'
5
5
 
6
6
  # NOTE: This test expects a replica set of three nodes to be running
7
7
  # on the local host.
8
- class ReplicaPairQueryTest < Test::Unit::TestCase
8
+ class ReplicaSetQueryTest < Test::Unit::TestCase
9
9
  include Mongo
10
10
 
11
11
  def setup
@@ -0,0 +1,20 @@
1
+ require 'mongo'
2
+
3
+ START_PORT = 27017
4
+ N = 4
5
+
6
+ N.times do |n|
7
+ system("rm -rf /data/rs#{n}")
8
+ system("mkdir -p /data/rs#{n}")
9
+ system("mongod --replSet replica-set-foo --logpath '#{n}.log' --dbpath /data/rs#{n} --port #{START_PORT + n} --fork")
10
+ end
11
+
12
+ con =<<DOC
13
+ config = {_id: 'replica-set-foo',
14
+ members: [{_id: 0, host:'localhost:27017'},
15
+ {_id:1, host:'localhost:27018'},
16
+ {_id: 2, host: 'localhost:27019', arbiterOnly: true},
17
+ {_id: 3, host: 'localhost:27020'}]}"
18
+ DOC
19
+
20
+ puts con
@@ -2,7 +2,7 @@ require './test/test_helper'
2
2
  include Mongo
3
3
 
4
4
  class SafeTest < Test::Unit::TestCase
5
- context "Safe tests: " do
5
+ context "Safe mode propogation: " do
6
6
  setup do
7
7
  @con = standard_connection(:safe => {:w => 1})
8
8
  @db = @con[MONGO_TEST_DB]
@@ -39,4 +39,30 @@ class SafeTest < Test::Unit::TestCase
39
39
  @col.update({:a => 2}, {:a => 1}, :safe => false)
40
40
  end
41
41
  end
42
+
43
+ context "Safe error objects" do
44
+ setup do
45
+ @con = standard_connection
46
+ @db = @con[MONGO_TEST_DB]
47
+ @col = @db['test']
48
+ @col.remove
49
+ @col.insert({:a => 1})
50
+ @col.insert({:a => 1})
51
+ @col.insert({:a => 1})
52
+ end
53
+
54
+ should "return object on update" do
55
+ response = @col.update({:a => 1}, {"$set" => {:a => 2}},
56
+ :multi => true, :safe => true)
57
+
58
+ assert response['updatedExisting']
59
+ assert_equal 3, response['n']
60
+ end
61
+
62
+ should "return object on remove" do
63
+ response = @col.remove({}, :safe => true)
64
+ assert_equal 3, response['n']
65
+ end
66
+ end
67
+
42
68
  end
@@ -81,5 +81,54 @@ class CollectionTest < Test::Unit::TestCase
81
81
  @logger.stubs(:debug)
82
82
  @coll.update({}, {:title => 'Moby Dick'}, :safe => true)
83
83
  end
84
+
85
+ should "not call insert for each ensure_index call" do
86
+ @conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
87
+ @db = @conn['testing']
88
+ @coll = @db.collection('books')
89
+ @coll.expects(:generate_indexes).once
90
+
91
+ @coll.ensure_index [["x", Mongo::DESCENDING]]
92
+ @coll.ensure_index [["x", Mongo::DESCENDING]]
93
+
94
+ end
95
+ should "call generate_indexes for a new direction on the same field for ensure_index" do
96
+ @conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
97
+ @db = @conn['testing']
98
+ @coll = @db.collection('books')
99
+ @coll.expects(:generate_indexes).twice
100
+
101
+ @coll.ensure_index [["x", Mongo::DESCENDING]]
102
+ @coll.ensure_index [["x", Mongo::ASCENDING]]
103
+
104
+ end
105
+
106
+ should "call generate_indexes twice because the cache time is 0 seconds" do
107
+ @conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
108
+ @db = @conn['testing']
109
+ @db.cache_time = 0
110
+ @coll = @db.collection('books')
111
+ @coll.expects(:generate_indexes).twice
112
+
113
+
114
+ @coll.ensure_index [["x", Mongo::DESCENDING]]
115
+ @coll.ensure_index [["x", Mongo::DESCENDING]]
116
+
117
+ end
118
+
119
+ should "call generate_indexes for each key when calling ensure_indexes" do
120
+ @conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
121
+ @db = @conn['testing']
122
+ @db.cache_time = 300
123
+ @coll = @db.collection('books')
124
+ @coll.expects(:generate_indexes).once.with do |a, b, c|
125
+ a == {"x"=>-1, "y"=>-1}
126
+ end
127
+
128
+ @coll.ensure_index [["x", Mongo::DESCENDING], ["y", Mongo::DESCENDING]]
129
+ end
130
+
131
+
132
+
84
133
  end
85
134
  end
@@ -4,7 +4,7 @@ include Mongo
4
4
  class ConnectionTest < Test::Unit::TestCase
5
5
  context "Initialization: " do
6
6
  setup do
7
- def new_mock_socket
7
+ def new_mock_socket(host='localhost', port=27017)
8
8
  socket = Object.new
9
9
  socket.stubs(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
10
10
  socket.stubs(:close)
@@ -28,12 +28,12 @@ class ConnectionTest < Test::Unit::TestCase
28
28
  end
29
29
 
30
30
  should "set localhost and port to master" do
31
- assert_equal 'localhost', @conn.host
32
- assert_equal 27017, @conn.port
31
+ assert_equal 'localhost', @conn.primary_pool.host
32
+ assert_equal 27017, @conn.primary_pool.port
33
33
  end
34
34
 
35
35
  should "set connection pool to 1" do
36
- assert_equal 1, @conn.size
36
+ assert_equal 1, @conn.primary_pool.size
37
37
  end
38
38
 
39
39
  should "default slave_ok to false" do
@@ -43,22 +43,32 @@ class ConnectionTest < Test::Unit::TestCase
43
43
 
44
44
  context "connecting to a replica set" do
45
45
  setup do
46
- TCPSocket.stubs(:new).returns(new_mock_socket)
47
- @conn = Connection.new('localhost', 27017, :connect => false)
46
+ TCPSocket.stubs(:new).returns(new_mock_socket('localhost', 27017))
47
+ @conn = Connection.multi([['localhost', 27017]], :connect => false, :read_secondary => true)
48
48
 
49
49
  admin_db = new_mock_db
50
- @hosts = ['localhost:27018', 'localhost:27019']
51
- admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1, 'hosts' => @hosts})
52
- @conn.expects(:[]).with('admin').returns(admin_db)
50
+ @hosts = ['localhost:27018', 'localhost:27019', 'localhost:27020']
51
+
52
+ admin_db.stubs(:command).returns({'ok' => 1, 'ismaster' => 1, 'hosts' => @hosts}).
53
+ then.returns({'ok' => 1, 'ismaster' => 0, 'hosts' => @hosts, 'secondary' => 1}).
54
+ then.returns({'ok' => 1, 'ismaster' => 0, 'hosts' => @hosts, 'secondary' => 1}).
55
+ then.returns({'ok' => 1, 'ismaster' => 0, 'arbiterOnly' => 1})
56
+
57
+ @conn.stubs(:[]).with('admin').returns(admin_db)
53
58
  @conn.connect
54
59
  end
55
60
 
56
61
  should "store the hosts returned from the ismaster command" do
57
- @hosts.each do |host|
58
- host, port = host.split(":")
59
- port = port.to_i
60
- assert @conn.nodes.include?([host, port]), "Connection doesn't include host #{host.inspect}."
61
- end
62
+ assert_equal 'localhost', @conn.primary_pool.host
63
+ assert_equal 27017, @conn.primary_pool.port
64
+
65
+ assert_equal 'localhost', @conn.secondary_pools[0].host
66
+ assert_equal 27018, @conn.secondary_pools[0].port
67
+
68
+ assert_equal 'localhost', @conn.secondary_pools[1].host
69
+ assert_equal 27019, @conn.secondary_pools[1].port
70
+
71
+ assert_equal 2, @conn.secondary_pools.length
62
72
  end
63
73
  end
64
74
 
@@ -75,13 +85,6 @@ class ConnectionTest < Test::Unit::TestCase
75
85
  end
76
86
 
77
87
  should "not store any hosts redundantly" do
78
- assert_equal 3, @conn.nodes.size
79
-
80
- @hosts.each do |host|
81
- host, port = host.split(":")
82
- port = port.to_i
83
- assert @conn.nodes.include?([host, port]), "Connection doesn't include host #{host.inspect}."
84
- end
85
88
  end
86
89
  end
87
90
 
@@ -0,0 +1,9 @@
1
+ require './test/test_helper'
2
+ include Mongo
3
+
4
+ class PoolTest < Test::Unit::TestCase
5
+ context "Initialization: " do
6
+ should "do" do
7
+ end
8
+ end
9
+ 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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 2
10
- version: 1.1.2
9
+ - 3
10
+ version: 1.1.3
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-11-04 00:00:00 -04:00
20
+ date: 2010-11-29 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -50,73 +50,80 @@ files:
50
50
  - mongo.gemspec
51
51
  - LICENSE.txt
52
52
  - lib/mongo.rb
53
- - lib/mongo/collection.rb
54
- - lib/mongo/connection.rb
55
53
  - lib/mongo/cursor.rb
56
- - lib/mongo/db.rb
54
+ - lib/mongo/collection.rb
57
55
  - lib/mongo/exceptions.rb
56
+ - lib/mongo/connection.rb
57
+ - lib/mongo/gridfs/grid_io.rb
58
+ - lib/mongo/gridfs/grid_file_system.rb
58
59
  - lib/mongo/gridfs/grid.rb
59
60
  - lib/mongo/gridfs/grid_ext.rb
60
- - lib/mongo/gridfs/grid_file_system.rb
61
- - lib/mongo/gridfs/grid_io.rb
62
61
  - lib/mongo/gridfs/grid_io_fix.rb
63
62
  - lib/mongo/util/conversions.rb
64
- - lib/mongo/util/core_ext.rb
63
+ - lib/mongo/util/support.rb
65
64
  - lib/mongo/util/pool.rb
65
+ - lib/mongo/util/core_ext.rb
66
66
  - lib/mongo/util/server_version.rb
67
- - lib/mongo/util/support.rb
68
- - docs/1.0_UPGRADE.md
69
- - docs/CREDITS.md
67
+ - lib/mongo/db.rb
70
68
  - docs/HISTORY.md
71
69
  - docs/TUTORIAL.md
70
+ - docs/CREDITS.md
71
+ - docs/FAQ.md
72
+ - docs/REPLICA_SETS.md
73
+ - docs/1.0_UPGRADE.md
74
+ - docs/GridFS.md
75
+ - docs/WRITE_CONCERN.md
72
76
  - bin/mongo_console
73
- - test/auxillary/1.4_features.rb
77
+ - test/grid_file_system_test.rb
78
+ - test/unit/db_test.rb
79
+ - test/unit/collection_test.rb
80
+ - test/unit/cursor_test.rb
81
+ - test/unit/grid_test.rb
82
+ - test/unit/connection_test.rb
83
+ - test/unit/pool_test.rb
84
+ - test/unit/safe_test.rb
85
+ - test/db_test.rb
86
+ - test/collection_test.rb
87
+ - test/rs.rb
88
+ - test/cursor_test.rb
89
+ - test/grid_test.rb
90
+ - test/db_api_test.rb
91
+ - test/auxillary/slave_connection_test.rb
74
92
  - test/auxillary/authentication_test.rb
75
93
  - test/auxillary/autoreconnect_test.rb
76
- - test/auxillary/slave_connection_test.rb
77
- - test/bson/binary_test.rb
78
- - test/bson/bson_test.rb
94
+ - test/auxillary/1.4_features.rb
95
+ - test/conversions_test.rb
96
+ - test/connection_test.rb
97
+ - test/cursor_message_test.rb
98
+ - test/cursor_fail_test.rb
99
+ - test/threading/test_threading_large_pool.rb
100
+ - test/test_helper.rb
101
+ - test/grid_io_test.rb
79
102
  - test/bson/byte_buffer_test.rb
80
- - test/bson/hash_with_indifferent_access_test.rb
81
- - test/bson/json_test.rb
103
+ - test/bson/binary_test.rb
82
104
  - test/bson/object_id_test.rb
105
+ - test/bson/json_test.rb
106
+ - test/bson/bson_test.rb
83
107
  - test/bson/ordered_hash_test.rb
84
- - test/collection_test.rb
85
- - test/connection_test.rb
86
- - test/conversions_test.rb
87
- - test/cursor_fail_test.rb
88
- - test/cursor_message_test.rb
89
- - test/cursor_test.rb
90
- - test/db_api_test.rb
108
+ - test/bson/hash_with_indifferent_access_test.rb
109
+ - test/support/keys.rb
110
+ - test/support/hash_with_indifferent_access.rb
91
111
  - test/db_connection_test.rb
92
- - test/db_test.rb
93
- - test/grid_file_system_test.rb
94
- - test/grid_io_test.rb
95
- - test/grid_test.rb
96
- - test/replica_pairs/count_test.rb
97
- - test/replica_pairs/insert_test.rb
98
- - test/replica_pairs/pooled_insert_test.rb
99
- - test/replica_pairs/query_test.rb
100
- - test/replica_sets/connect_test.rb
101
- - test/replica_sets/count_test.rb
102
- - test/replica_sets/insert_test.rb
103
- - test/replica_sets/node_type_test.rb
104
112
  - test/replica_sets/pooled_insert_test.rb
105
- - test/replica_sets/query_test.rb
113
+ - test/replica_sets/count_test.rb
106
114
  - test/replica_sets/replication_ack_test.rb
115
+ - test/replica_sets/query_secondaries.rb
116
+ - test/replica_sets/query_test.rb
117
+ - test/replica_sets/node_type_test.rb
118
+ - test/replica_sets/insert_test.rb
119
+ - test/replica_sets/connect_test.rb
107
120
  - test/safe_test.rb
108
- - test/support/hash_with_indifferent_access.rb
109
- - test/support/keys.rb
110
121
  - test/support_test.rb
111
- - test/test_helper.rb
112
- - test/threading/test_threading_large_pool.rb
122
+ - test/replica_pairs/pooled_insert_test.rb
123
+ - test/replica_pairs/count_test.rb
124
+ - test/replica_pairs/query_test.rb
125
+ - test/replica_pairs/insert_test.rb
113
126
  - test/threading_test.rb
114
- - test/unit/collection_test.rb
115
- - test/unit/connection_test.rb
116
- - test/unit/cursor_test.rb
117
- - test/unit/db_test.rb
118
- - test/unit/grid_test.rb
119
- - test/unit/safe_test.rb
120
127
  has_rdoc: true
121
128
  homepage: http://www.mongodb.org
122
129
  licenses: []
@@ -154,50 +161,53 @@ signing_key:
154
161
  specification_version: 3
155
162
  summary: Ruby driver for the MongoDB
156
163
  test_files:
157
- - test/auxillary/1.4_features.rb
164
+ - test/grid_file_system_test.rb
165
+ - test/unit/db_test.rb
166
+ - test/unit/collection_test.rb
167
+ - test/unit/cursor_test.rb
168
+ - test/unit/grid_test.rb
169
+ - test/unit/connection_test.rb
170
+ - test/unit/pool_test.rb
171
+ - test/unit/safe_test.rb
172
+ - test/db_test.rb
173
+ - test/collection_test.rb
174
+ - test/rs.rb
175
+ - test/cursor_test.rb
176
+ - test/grid_test.rb
177
+ - test/db_api_test.rb
178
+ - test/auxillary/slave_connection_test.rb
158
179
  - test/auxillary/authentication_test.rb
159
180
  - test/auxillary/autoreconnect_test.rb
160
- - test/auxillary/slave_connection_test.rb
161
- - test/bson/binary_test.rb
162
- - test/bson/bson_test.rb
181
+ - test/auxillary/1.4_features.rb
182
+ - test/conversions_test.rb
183
+ - test/connection_test.rb
184
+ - test/cursor_message_test.rb
185
+ - test/cursor_fail_test.rb
186
+ - test/threading/test_threading_large_pool.rb
187
+ - test/test_helper.rb
188
+ - test/grid_io_test.rb
163
189
  - test/bson/byte_buffer_test.rb
164
- - test/bson/hash_with_indifferent_access_test.rb
165
- - test/bson/json_test.rb
190
+ - test/bson/binary_test.rb
166
191
  - test/bson/object_id_test.rb
192
+ - test/bson/json_test.rb
193
+ - test/bson/bson_test.rb
167
194
  - test/bson/ordered_hash_test.rb
168
- - test/collection_test.rb
169
- - test/connection_test.rb
170
- - test/conversions_test.rb
171
- - test/cursor_fail_test.rb
172
- - test/cursor_message_test.rb
173
- - test/cursor_test.rb
174
- - test/db_api_test.rb
195
+ - test/bson/hash_with_indifferent_access_test.rb
196
+ - test/support/keys.rb
197
+ - test/support/hash_with_indifferent_access.rb
175
198
  - test/db_connection_test.rb
176
- - test/db_test.rb
177
- - test/grid_file_system_test.rb
178
- - test/grid_io_test.rb
179
- - test/grid_test.rb
180
- - test/replica_pairs/count_test.rb
181
- - test/replica_pairs/insert_test.rb
182
- - test/replica_pairs/pooled_insert_test.rb
183
- - test/replica_pairs/query_test.rb
184
- - test/replica_sets/connect_test.rb
185
- - test/replica_sets/count_test.rb
186
- - test/replica_sets/insert_test.rb
187
- - test/replica_sets/node_type_test.rb
188
199
  - test/replica_sets/pooled_insert_test.rb
189
- - test/replica_sets/query_test.rb
200
+ - test/replica_sets/count_test.rb
190
201
  - test/replica_sets/replication_ack_test.rb
202
+ - test/replica_sets/query_secondaries.rb
203
+ - test/replica_sets/query_test.rb
204
+ - test/replica_sets/node_type_test.rb
205
+ - test/replica_sets/insert_test.rb
206
+ - test/replica_sets/connect_test.rb
191
207
  - test/safe_test.rb
192
- - test/support/hash_with_indifferent_access.rb
193
- - test/support/keys.rb
194
208
  - test/support_test.rb
195
- - test/test_helper.rb
196
- - test/threading/test_threading_large_pool.rb
209
+ - test/replica_pairs/pooled_insert_test.rb
210
+ - test/replica_pairs/count_test.rb
211
+ - test/replica_pairs/query_test.rb
212
+ - test/replica_pairs/insert_test.rb
197
213
  - test/threading_test.rb
198
- - test/unit/collection_test.rb
199
- - test/unit/connection_test.rb
200
- - test/unit/cursor_test.rb
201
- - test/unit/db_test.rb
202
- - test/unit/grid_test.rb
203
- - test/unit/safe_test.rb