mongo 1.5.1 → 1.5.2

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.
@@ -1,42 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- # --
4
- # Copyright (C) 2008-2011 10gen Inc.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- # ++
18
- module Mongo #:nodoc:
19
- module TimeoutWrapper
20
- extend self
21
-
22
- def timeout_lib=(lib)
23
- @@timeout_lib = lib
24
- end
25
-
26
- def timeout_lib
27
- @@timeout_lib
28
- end
29
-
30
- def timeout(delay, &block)
31
- if timeout_lib
32
- begin
33
- timeout_lib.timeout(delay, &block)
34
- rescue ::Timeout::Error
35
- raise Mongo::OperationTimeout
36
- end
37
- else
38
- yield
39
- end
40
- end
41
- end
42
- end
@@ -1,30 +0,0 @@
1
- # encoding:utf-8
2
- require './test/bson/test_helper'
3
- require 'complex'
4
- require 'bigdecimal'
5
- require 'rational'
6
-
7
- class BSONTest < Test::Unit::TestCase
8
-
9
- include BSON
10
-
11
- def setup
12
- @encoder = BSON::BSON_CODER
13
- end
14
-
15
- def assert_doc_pass(doc, options={})
16
- bson = @encoder.serialize(doc)
17
- if options[:debug]
18
- puts "DEBUGGING DOC:"
19
- p bson.to_a
20
- puts "DESERIALIZES TO:"
21
- end
22
- assert_equal @encoder.serialize(doc).to_a, bson.to_a
23
- assert_equal doc, @encoder.deserialize(bson)
24
- end
25
-
26
- def test_string
27
- assert_doc_pass({:a => "hello"})
28
- end
29
-
30
- end
@@ -1,21 +0,0 @@
1
- require './test/test_helper'
2
- require 'logger'
3
- require 'stringio'
4
- require 'thread'
5
-
6
- class TestPool < Test::Unit::TestCase
7
-
8
- include Mongo
9
- include BSON
10
-
11
- def setup
12
- @conn = standard_connection
13
- end
14
-
15
- def teardown
16
- @conn[MONGO_TEST_DB].get_last_error
17
- end
18
-
19
- def test_foo
20
- end
21
- end
@@ -1,111 +0,0 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- require './test/replica_sets/rs_test_helper'
3
-
4
- class ReplicaSetThreadingTest < Test::Unit::TestCase
5
- include ReplicaSetTest
6
-
7
- def setup_safe_data
8
- @conn = ReplSetConnection.new([self.rs.host, self.rs.ports[0]],
9
- :pool_size => 100)
10
- @db = @conn[MONGO_TEST_DB]
11
- @coll = @db.collection('thread-test-collection')
12
- @db.drop_collection('duplicate')
13
- @db.drop_collection('unique')
14
- @duplicate = @db.collection('duplicate')
15
- @unique = @db.collection('unique')
16
-
17
- @duplicate.insert("test" => "insert")
18
- @duplicate.insert("test" => "update")
19
- @unique.insert("test" => "insert")
20
- @unique.insert("test" => "update")
21
- @unique.create_index("test", :unique => true)
22
- end
23
-
24
- def test_safe_update
25
- setup_safe_data
26
- times = []
27
- threads = []
28
- 100.times do |i|
29
- threads[i] = Thread.new do
30
- 10.times do
31
- if i % 2 == 0
32
- assert_raise Mongo::OperationFailure do
33
- t1 = Time.now
34
- @unique.update({"test" => "insert"},
35
- {"$set" => {"test" => "update"}}, :safe => true)
36
- times << Time.now - t1
37
- end
38
- else
39
- t1 = Time.now
40
- @duplicate.update({"test" => "insert"},
41
- {"$set" => {"test" => "update"}}, :safe => true)
42
- times << Time.now - t1
43
- end
44
- end
45
- end
46
- end
47
-
48
- 100.times do |i|
49
- threads[i].join
50
- end
51
- @conn.close
52
- end
53
-
54
- def test_safe_insert
55
- setup_safe_data
56
- threads = []
57
- 100.times do |i|
58
- threads[i] = Thread.new do
59
- if i % 2 == 0
60
- assert_raise Mongo::OperationFailure do
61
- @unique.insert({"test" => "insert"}, :safe => true)
62
- end
63
- else
64
- @duplicate.insert({"test" => "insert"}, :safe => true)
65
- end
66
- end
67
- end
68
-
69
- 100.times do |i|
70
- threads[i].join
71
- end
72
- @conn.close
73
- end
74
-
75
- def setup_replica_set_connection
76
- @conn = ReplSetConnection.new([self.rs.host, self.rs.ports[0]],
77
- :pool_size => 100, :auto_refresh => :sync,
78
- :refresh_interval => 2)
79
- @db = @conn[MONGO_TEST_DB]
80
- @coll = @db.collection('thread-test-collection')
81
- end
82
-
83
- def test_threading_with_queries
84
- setup_replica_set_connection
85
- @coll.drop
86
- @coll = @db.collection('thread-test-collection')
87
-
88
- 1000.times do |i|
89
- @coll.insert("x" => i)
90
- end
91
-
92
- threads = []
93
-
94
- 10.times do |i|
95
- threads[i] = Thread.new do
96
- 100.times do
97
- sum = 0
98
- @coll.find().each do |document|
99
- sum += document["x"]
100
- end
101
- assert_equal 499500, sum
102
- end
103
- end
104
- end
105
-
106
- 10.times do |i|
107
- threads[i].join
108
- end
109
- @conn.close
110
- end
111
- end
@@ -1,14 +0,0 @@
1
- require './test/test_helper'
2
-
3
- class TestTimeout < Test::Unit::TestCase
4
-
5
- def test_timeout
6
- @conn = standard_connection(:op_timeout => 2)
7
- assert @conn[MONGO_TEST_DB]['test'].save({:a => 1})
8
- assert @conn[MONGO_TEST_DB]['test'].find.next
9
- assert_raise OperationTimeout do
10
- @conn[MONGO_TEST_DB]['test'].find({'$where' => 'function() { while(true) { this.a == 1 } }'}).next
11
- end
12
- end
13
-
14
- end