jmongo 1.0.3 → 1.1.0
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.
- data/Gemfile +8 -0
 - data/Gemfile.lock +43 -0
 - data/Rakefile +72 -0
 - data/jmongo.gemspec +84 -6
 - data/lib/jmongo.rb +6 -14
 - data/lib/jmongo/collection.rb +196 -114
 - data/lib/jmongo/connection.rb +39 -13
 - data/lib/jmongo/cursor.rb +161 -63
 - data/lib/jmongo/db.rb +119 -30
 - data/lib/jmongo/exceptions.rb +39 -0
 - data/lib/jmongo/mongo-2.6.5.gb1.jar +0 -0
 - data/lib/jmongo/mongo/bson.rb +130 -0
 - data/lib/jmongo/mongo/collection.rb +185 -0
 - data/lib/jmongo/mongo/connection.rb +45 -0
 - data/lib/jmongo/mongo/db.rb +31 -0
 - data/lib/jmongo/mongo/jmongo.rb +44 -0
 - data/lib/jmongo/mongo/mongo.rb +98 -0
 - data/lib/jmongo/mongo/ruby_ext.rb +38 -0
 - data/lib/jmongo/mongo/utils.rb +136 -0
 - data/lib/jmongo/version.rb +1 -1
 - data/test-results.txt +98 -0
 - data/test/auxillary/1.4_features.rb +166 -0
 - data/test/auxillary/authentication_test.rb +68 -0
 - data/test/auxillary/autoreconnect_test.rb +41 -0
 - data/test/auxillary/fork_test.rb +30 -0
 - data/test/auxillary/repl_set_auth_test.rb +58 -0
 - data/test/auxillary/slave_connection_test.rb +36 -0
 - data/test/auxillary/threaded_authentication_test.rb +101 -0
 - data/test/bson/binary_test.rb +15 -0
 - data/test/bson/bson_test.rb +657 -0
 - data/test/bson/byte_buffer_test.rb +208 -0
 - data/test/bson/hash_with_indifferent_access_test.rb +38 -0
 - data/test/bson/json_test.rb +17 -0
 - data/test/bson/object_id_test.rb +138 -0
 - data/test/bson/ordered_hash_test.rb +245 -0
 - data/test/bson/test_helper.rb +46 -0
 - data/test/bson/timestamp_test.rb +46 -0
 - data/test/collection_test.rb +933 -0
 - data/test/connection_test.rb +325 -0
 - data/test/conversions_test.rb +121 -0
 - data/test/cursor_fail_test.rb +75 -0
 - data/test/cursor_message_test.rb +43 -0
 - data/test/cursor_test.rb +547 -0
 - data/test/data/empty_data +0 -0
 - data/test/data/sample_data +0 -0
 - data/test/data/sample_file.pdf +0 -0
 - data/test/data/small_data.txt +1 -0
 - data/test/db_api_test.rb +739 -0
 - data/test/db_connection_test.rb +15 -0
 - data/test/db_test.rb +325 -0
 - data/test/grid_file_system_test.rb +260 -0
 - data/test/grid_io_test.rb +210 -0
 - data/test/grid_test.rb +259 -0
 - data/test/load/thin/config.ru +6 -0
 - data/test/load/thin/config.yml.template +6 -0
 - data/test/load/thin/load.rb +24 -0
 - data/test/load/unicorn/config.ru +6 -0
 - data/test/load/unicorn/load.rb +23 -0
 - data/test/load/unicorn/unicorn.rb.template +29 -0
 - data/test/replica_sets/connect_test.rb +111 -0
 - data/test/replica_sets/connection_string_test.rb +29 -0
 - data/test/replica_sets/count_test.rb +36 -0
 - data/test/replica_sets/insert_test.rb +54 -0
 - data/test/replica_sets/pooled_insert_test.rb +58 -0
 - data/test/replica_sets/query_secondaries.rb +109 -0
 - data/test/replica_sets/query_test.rb +52 -0
 - data/test/replica_sets/read_preference_test.rb +43 -0
 - data/test/replica_sets/refresh_test.rb +123 -0
 - data/test/replica_sets/replication_ack_test.rb +71 -0
 - data/test/replica_sets/rs_test_helper.rb +27 -0
 - data/test/safe_test.rb +68 -0
 - data/test/support/hash_with_indifferent_access.rb +186 -0
 - data/test/support/keys.rb +45 -0
 - data/test/support_test.rb +19 -0
 - data/test/test_helper.rb +111 -0
 - data/test/threading/threading_with_large_pool_test.rb +90 -0
 - data/test/threading_test.rb +88 -0
 - data/test/tools/auth_repl_set_manager.rb +14 -0
 - data/test/tools/keyfile.txt +1 -0
 - data/test/tools/repl_set_manager.rb +377 -0
 - data/test/unit/collection_test.rb +128 -0
 - data/test/unit/connection_test.rb +85 -0
 - data/test/unit/cursor_test.rb +127 -0
 - data/test/unit/db_test.rb +96 -0
 - data/test/unit/grid_test.rb +51 -0
 - data/test/unit/node_test.rb +73 -0
 - data/test/unit/pool_manager_test.rb +47 -0
 - data/test/unit/pool_test.rb +9 -0
 - data/test/unit/read_test.rb +101 -0
 - data/test/unit/safe_test.rb +125 -0
 - data/test/uri_test.rb +92 -0
 - metadata +170 -99
 - data/lib/jmongo/ajrb.rb +0 -189
 - data/lib/jmongo/jmongo_jext.rb +0 -302
 - data/lib/jmongo/mongo-2.6.3.jar +0 -0
 - data/lib/jmongo/utils.rb +0 -61
 
| 
         @@ -0,0 +1,325 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require './test/test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'logger'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'stringio'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'thread'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            class TestConnection < 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.close
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              def test_connection_failure
         
     | 
| 
      
 20 
     | 
    
         
            +
                assert_raise Mongo::ConnectionFailure do
         
     | 
| 
      
 21 
     | 
    
         
            +
                  Mongo::Connection.new('localhost', 27347)
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              def test_connection_timeout
         
     | 
| 
      
 26 
     | 
    
         
            +
                passed = false
         
     | 
| 
      
 27 
     | 
    
         
            +
                begin
         
     | 
| 
      
 28 
     | 
    
         
            +
                  t0 = Time.now
         
     | 
| 
      
 29 
     | 
    
         
            +
                  Mongo::Connection.new('192.169.169.1', 27017, :connect_timeout => 3)
         
     | 
| 
      
 30 
     | 
    
         
            +
                rescue OperationTimeout
         
     | 
| 
      
 31 
     | 
    
         
            +
                  passed = true
         
     | 
| 
      
 32 
     | 
    
         
            +
                  t1 = Time.now
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                assert passed
         
     | 
| 
      
 36 
     | 
    
         
            +
                assert t1 - t0 < 4
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
              def test_host_port_accessors
         
     | 
| 
      
 41 
     | 
    
         
            +
                assert_equal @conn.host, TEST_HOST
         
     | 
| 
      
 42 
     | 
    
         
            +
                assert_equal @conn.port, TEST_PORT
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              def test_server_info
         
     | 
| 
      
 46 
     | 
    
         
            +
                server_info = @conn.server_info
         
     | 
| 
      
 47 
     | 
    
         
            +
                assert server_info.keys.include?("version")
         
     | 
| 
      
 48 
     | 
    
         
            +
                assert Mongo::Support.ok?(server_info)
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
              def test_ping
         
     | 
| 
      
 52 
     | 
    
         
            +
                ping = @conn.ping
         
     | 
| 
      
 53 
     | 
    
         
            +
                assert ping['ok']
         
     | 
| 
      
 54 
     | 
    
         
            +
              end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
              def test_connection_uri
         
     | 
| 
      
 57 
     | 
    
         
            +
                con = Connection.from_uri("mongodb://#{host_port}")
         
     | 
| 
      
 58 
     | 
    
         
            +
                assert_equal mongo_host, con.primary_pool.host
         
     | 
| 
      
 59 
     | 
    
         
            +
                assert_equal mongo_port, con.primary_pool.port
         
     | 
| 
      
 60 
     | 
    
         
            +
              end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
              def test_server_version
         
     | 
| 
      
 63 
     | 
    
         
            +
                assert_match(/\d\.\d+(\.\d+)?/, @conn.server_version.to_s)
         
     | 
| 
      
 64 
     | 
    
         
            +
              end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
              def test_invalid_database_names
         
     | 
| 
      
 67 
     | 
    
         
            +
                assert_raise TypeError do @conn.db(4) end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                assert_raise Mongo::InvalidNSName do @conn.db('') end
         
     | 
| 
      
 70 
     | 
    
         
            +
                assert_raise Mongo::InvalidNSName do @conn.db('te$t') end
         
     | 
| 
      
 71 
     | 
    
         
            +
                assert_raise Mongo::InvalidNSName do @conn.db('te.t') end
         
     | 
| 
      
 72 
     | 
    
         
            +
                assert_raise Mongo::InvalidNSName do @conn.db('te\\t') end
         
     | 
| 
      
 73 
     | 
    
         
            +
                assert_raise Mongo::InvalidNSName do @conn.db('te/t') end
         
     | 
| 
      
 74 
     | 
    
         
            +
                assert_raise Mongo::InvalidNSName do @conn.db('te st') end
         
     | 
| 
      
 75 
     | 
    
         
            +
              end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
              def test_options_passed_to_db
         
     | 
| 
      
 78 
     | 
    
         
            +
                @pk_mock = Object.new
         
     | 
| 
      
 79 
     | 
    
         
            +
                db = @conn.db('test', :pk => @pk_mock, :strict => true)
         
     | 
| 
      
 80 
     | 
    
         
            +
                assert_equal @pk_mock, db.pk_factory
         
     | 
| 
      
 81 
     | 
    
         
            +
                assert db.strict?
         
     | 
| 
      
 82 
     | 
    
         
            +
              end
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
              def test_database_info
         
     | 
| 
      
 85 
     | 
    
         
            +
                @conn.drop_database(MONGO_TEST_DB)
         
     | 
| 
      
 86 
     | 
    
         
            +
                @conn.db(MONGO_TEST_DB).collection('info-test').insert('a' => 1)
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                info = @conn.database_info
         
     | 
| 
      
 89 
     | 
    
         
            +
                assert_not_nil info
         
     | 
| 
      
 90 
     | 
    
         
            +
                assert_kind_of Hash, info
         
     | 
| 
      
 91 
     | 
    
         
            +
                assert_not_nil info[MONGO_TEST_DB]
         
     | 
| 
      
 92 
     | 
    
         
            +
                assert info[MONGO_TEST_DB] > 0
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
                @conn.drop_database(MONGO_TEST_DB)
         
     | 
| 
      
 95 
     | 
    
         
            +
              end
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
              def test_copy_database
         
     | 
| 
      
 98 
     | 
    
         
            +
                @conn.db('old').collection('copy-test').insert('a' => 1)
         
     | 
| 
      
 99 
     | 
    
         
            +
                @conn.copy_database('old', 'new', host_port)
         
     | 
| 
      
 100 
     | 
    
         
            +
                old_object = @conn.db('old').collection('copy-test').find.next_document
         
     | 
| 
      
 101 
     | 
    
         
            +
                new_object = @conn.db('new').collection('copy-test').find.next_document
         
     | 
| 
      
 102 
     | 
    
         
            +
                assert_equal old_object, new_object
         
     | 
| 
      
 103 
     | 
    
         
            +
                @conn.drop_database('old')
         
     | 
| 
      
 104 
     | 
    
         
            +
                @conn.drop_database('new')
         
     | 
| 
      
 105 
     | 
    
         
            +
              end
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
              def test_copy_database_with_auth
         
     | 
| 
      
 108 
     | 
    
         
            +
                @conn.db('old').collection('copy-test').insert('a' => 1)
         
     | 
| 
      
 109 
     | 
    
         
            +
                @conn.db('old').add_user('bob', 'secret')
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
                assert_raise Mongo::OperationFailure do
         
     | 
| 
      
 112 
     | 
    
         
            +
                  @conn.copy_database('old', 'new', host_port, 'bob', 'badpassword')
         
     | 
| 
      
 113 
     | 
    
         
            +
                end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
                result = @conn.copy_database('old', 'new', host_port, 'bob', 'secret')
         
     | 
| 
      
 116 
     | 
    
         
            +
                assert Mongo::Support.ok?(result)
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
                @conn.drop_database('old')
         
     | 
| 
      
 119 
     | 
    
         
            +
                @conn.drop_database('new')
         
     | 
| 
      
 120 
     | 
    
         
            +
              end
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
              def test_database_names
         
     | 
| 
      
 123 
     | 
    
         
            +
                @conn.drop_database(MONGO_TEST_DB)
         
     | 
| 
      
 124 
     | 
    
         
            +
                @conn.db(MONGO_TEST_DB).collection('info-test').insert('a' => 1)
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                names = @conn.database_names
         
     | 
| 
      
 127 
     | 
    
         
            +
                assert_not_nil names
         
     | 
| 
      
 128 
     | 
    
         
            +
                assert_kind_of Array, names
         
     | 
| 
      
 129 
     | 
    
         
            +
                assert names.length >= 1
         
     | 
| 
      
 130 
     | 
    
         
            +
                assert names.include?(MONGO_TEST_DB)
         
     | 
| 
      
 131 
     | 
    
         
            +
              end
         
     | 
| 
      
 132 
     | 
    
         
            +
             
     | 
| 
      
 133 
     | 
    
         
            +
              def test_logging
         
     | 
| 
      
 134 
     | 
    
         
            +
                output = StringIO.new
         
     | 
| 
      
 135 
     | 
    
         
            +
                logger = Logger.new(output)
         
     | 
| 
      
 136 
     | 
    
         
            +
                logger.level = Logger::DEBUG
         
     | 
| 
      
 137 
     | 
    
         
            +
                connection = standard_connection(:logger => logger).db(MONGO_TEST_DB)
         
     | 
| 
      
 138 
     | 
    
         
            +
                assert output.string.include?("admin['$cmd'].find")
         
     | 
| 
      
 139 
     | 
    
         
            +
              end
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
              def test_connection_logger
         
     | 
| 
      
 142 
     | 
    
         
            +
                output = StringIO.new
         
     | 
| 
      
 143 
     | 
    
         
            +
                logger = Logger.new(output)
         
     | 
| 
      
 144 
     | 
    
         
            +
                logger.level = Logger::DEBUG
         
     | 
| 
      
 145 
     | 
    
         
            +
                connection = standard_connection(:logger => logger)
         
     | 
| 
      
 146 
     | 
    
         
            +
                assert_equal logger, connection.logger
         
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
                connection.logger.debug 'testing'
         
     | 
| 
      
 149 
     | 
    
         
            +
                assert output.string.include?('testing')
         
     | 
| 
      
 150 
     | 
    
         
            +
              end
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
              def test_drop_database
         
     | 
| 
      
 153 
     | 
    
         
            +
                db = @conn.db('ruby-mongo-will-be-deleted')
         
     | 
| 
      
 154 
     | 
    
         
            +
                coll = db.collection('temp')
         
     | 
| 
      
 155 
     | 
    
         
            +
                coll.remove
         
     | 
| 
      
 156 
     | 
    
         
            +
                coll.insert(:name => 'temp')
         
     | 
| 
      
 157 
     | 
    
         
            +
                assert_equal 1, coll.count()
         
     | 
| 
      
 158 
     | 
    
         
            +
                assert @conn.database_names.include?('ruby-mongo-will-be-deleted')
         
     | 
| 
      
 159 
     | 
    
         
            +
             
     | 
| 
      
 160 
     | 
    
         
            +
                @conn.drop_database('ruby-mongo-will-be-deleted')
         
     | 
| 
      
 161 
     | 
    
         
            +
                assert !@conn.database_names.include?('ruby-mongo-will-be-deleted')
         
     | 
| 
      
 162 
     | 
    
         
            +
              end
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
      
 164 
     | 
    
         
            +
              def test_nodes
         
     | 
| 
      
 165 
     | 
    
         
            +
                conn = Connection.multi([['foo', 27017], ['bar', 27018]], :connect => false)
         
     | 
| 
      
 166 
     | 
    
         
            +
                nodes = conn.nodes
         
     | 
| 
      
 167 
     | 
    
         
            +
                assert_equal 2, nodes.length
         
     | 
| 
      
 168 
     | 
    
         
            +
                assert_equal ['foo', 27017], nodes[0]
         
     | 
| 
      
 169 
     | 
    
         
            +
                assert_equal ['bar', 27018], nodes[1]
         
     | 
| 
      
 170 
     | 
    
         
            +
              end
         
     | 
| 
      
 171 
     | 
    
         
            +
             
     | 
| 
      
 172 
     | 
    
         
            +
              def test_fsync_lock
         
     | 
| 
      
 173 
     | 
    
         
            +
                assert !@conn.locked?
         
     | 
| 
      
 174 
     | 
    
         
            +
                @conn.lock!
         
     | 
| 
      
 175 
     | 
    
         
            +
                assert @conn.locked?
         
     | 
| 
      
 176 
     | 
    
         
            +
                assert_equal 1, @conn['admin']['$cmd.sys.inprog'].find_one['fsyncLock'], "Not fsync-locked"
         
     | 
| 
      
 177 
     | 
    
         
            +
                assert_match(/unlock/, @conn.unlock!['info'])
         
     | 
| 
      
 178 
     | 
    
         
            +
                unlocked = false
         
     | 
| 
      
 179 
     | 
    
         
            +
                counter  = 0
         
     | 
| 
      
 180 
     | 
    
         
            +
                while counter < 5
         
     | 
| 
      
 181 
     | 
    
         
            +
                  if @conn['admin']['$cmd.sys.inprog'].find_one['fsyncLock'].nil?
         
     | 
| 
      
 182 
     | 
    
         
            +
                    unlocked = true
         
     | 
| 
      
 183 
     | 
    
         
            +
                    break
         
     | 
| 
      
 184 
     | 
    
         
            +
                  else
         
     | 
| 
      
 185 
     | 
    
         
            +
                    sleep(1)
         
     | 
| 
      
 186 
     | 
    
         
            +
                    counter += 1
         
     | 
| 
      
 187 
     | 
    
         
            +
                  end
         
     | 
| 
      
 188 
     | 
    
         
            +
                end
         
     | 
| 
      
 189 
     | 
    
         
            +
                assert !@conn.locked?
         
     | 
| 
      
 190 
     | 
    
         
            +
                assert unlocked, "mongod failed to unlock"
         
     | 
| 
      
 191 
     | 
    
         
            +
              end
         
     | 
| 
      
 192 
     | 
    
         
            +
             
     | 
| 
      
 193 
     | 
    
         
            +
              def test_max_bson_size_value
         
     | 
| 
      
 194 
     | 
    
         
            +
                conn = standard_connection(:connect => false)
         
     | 
| 
      
 195 
     | 
    
         
            +
             
     | 
| 
      
 196 
     | 
    
         
            +
                admin_db = Object.new
         
     | 
| 
      
 197 
     | 
    
         
            +
                admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1, 'maxBsonObjectSize' => 15_000_000})
         
     | 
| 
      
 198 
     | 
    
         
            +
                conn.expects(:[]).with('admin').returns(admin_db)
         
     | 
| 
      
 199 
     | 
    
         
            +
                conn.connect
         
     | 
| 
      
 200 
     | 
    
         
            +
                assert_equal 15_000_000, conn.max_bson_size
         
     | 
| 
      
 201 
     | 
    
         
            +
             
     | 
| 
      
 202 
     | 
    
         
            +
                conn = standard_connection
         
     | 
| 
      
 203 
     | 
    
         
            +
                if conn.server_version > "1.7.2"
         
     | 
| 
      
 204 
     | 
    
         
            +
                  assert_equal conn['admin'].command({:ismaster => 1})['maxBsonObjectSize'], conn.max_bson_size
         
     | 
| 
      
 205 
     | 
    
         
            +
                end
         
     | 
| 
      
 206 
     | 
    
         
            +
             
     | 
| 
      
 207 
     | 
    
         
            +
                conn.connect
         
     | 
| 
      
 208 
     | 
    
         
            +
                doc = {'n' => 'a' * (conn.max_bson_size)}
         
     | 
| 
      
 209 
     | 
    
         
            +
                assert_raise InvalidDocument do
         
     | 
| 
      
 210 
     | 
    
         
            +
                  assert BSON::BSON_CODER.serialize(doc, false, true, @conn.max_bson_size)
         
     | 
| 
      
 211 
     | 
    
         
            +
                end
         
     | 
| 
      
 212 
     | 
    
         
            +
              end
         
     | 
| 
      
 213 
     | 
    
         
            +
             
     | 
| 
      
 214 
     | 
    
         
            +
              def test_max_bson_size_with_no_reported_max_size
         
     | 
| 
      
 215 
     | 
    
         
            +
                conn = standard_connection(:connect => false)
         
     | 
| 
      
 216 
     | 
    
         
            +
             
     | 
| 
      
 217 
     | 
    
         
            +
                admin_db = Object.new
         
     | 
| 
      
 218 
     | 
    
         
            +
                admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1})
         
     | 
| 
      
 219 
     | 
    
         
            +
                conn.expects(:[]).with('admin').returns(admin_db)
         
     | 
| 
      
 220 
     | 
    
         
            +
             
     | 
| 
      
 221 
     | 
    
         
            +
                conn.connect
         
     | 
| 
      
 222 
     | 
    
         
            +
                assert_equal Mongo::DEFAULT_MAX_BSON_SIZE, BSON::BSON_CODER.max_bson_size
         
     | 
| 
      
 223 
     | 
    
         
            +
              end
         
     | 
| 
      
 224 
     | 
    
         
            +
             
     | 
| 
      
 225 
     | 
    
         
            +
              def test_connection_activity
         
     | 
| 
      
 226 
     | 
    
         
            +
                conn = standard_connection
         
     | 
| 
      
 227 
     | 
    
         
            +
                assert conn.active?
         
     | 
| 
      
 228 
     | 
    
         
            +
             
     | 
| 
      
 229 
     | 
    
         
            +
                conn.primary_pool.close
         
     | 
| 
      
 230 
     | 
    
         
            +
                assert !conn.active?
         
     | 
| 
      
 231 
     | 
    
         
            +
             
     | 
| 
      
 232 
     | 
    
         
            +
                # Simulate a dropped connection.
         
     | 
| 
      
 233 
     | 
    
         
            +
                dropped_socket = Mocha::Mock.new
         
     | 
| 
      
 234 
     | 
    
         
            +
                dropped_socket.stubs(:read).raises(Errno::ECONNRESET)
         
     | 
| 
      
 235 
     | 
    
         
            +
                dropped_socket.stubs(:send).raises(Errno::ECONNRESET)
         
     | 
| 
      
 236 
     | 
    
         
            +
                dropped_socket.stub_everything
         
     | 
| 
      
 237 
     | 
    
         
            +
             
     | 
| 
      
 238 
     | 
    
         
            +
                conn.primary_pool.host = 'localhost'
         
     | 
| 
      
 239 
     | 
    
         
            +
                conn.primary_pool.port = Mongo::Connection::DEFAULT_PORT
         
     | 
| 
      
 240 
     | 
    
         
            +
                conn.primary_pool.instance_variable_set("@pids", {dropped_socket => Process.pid})
         
     | 
| 
      
 241 
     | 
    
         
            +
                conn.primary_pool.instance_variable_set("@sockets", [dropped_socket])
         
     | 
| 
      
 242 
     | 
    
         
            +
             
     | 
| 
      
 243 
     | 
    
         
            +
                assert !conn.active?
         
     | 
| 
      
 244 
     | 
    
         
            +
              end
         
     | 
| 
      
 245 
     | 
    
         
            +
             
     | 
| 
      
 246 
     | 
    
         
            +
              context "Saved authentications" do
         
     | 
| 
      
 247 
     | 
    
         
            +
                setup do
         
     | 
| 
      
 248 
     | 
    
         
            +
                  @conn = standard_connection
         
     | 
| 
      
 249 
     | 
    
         
            +
                  @auth = {'db_name' => 'test', 'username' => 'bob', 'password' => 'secret'}
         
     | 
| 
      
 250 
     | 
    
         
            +
                  @conn.add_auth(@auth['db_name'], @auth['username'], @auth['password'])
         
     | 
| 
      
 251 
     | 
    
         
            +
                end
         
     | 
| 
      
 252 
     | 
    
         
            +
             
     | 
| 
      
 253 
     | 
    
         
            +
                teardown do
         
     | 
| 
      
 254 
     | 
    
         
            +
                  @conn.clear_auths
         
     | 
| 
      
 255 
     | 
    
         
            +
                end
         
     | 
| 
      
 256 
     | 
    
         
            +
             
     | 
| 
      
 257 
     | 
    
         
            +
                should "save the authentication" do
         
     | 
| 
      
 258 
     | 
    
         
            +
                  assert_equal @auth, @conn.auths[0]
         
     | 
| 
      
 259 
     | 
    
         
            +
                end
         
     | 
| 
      
 260 
     | 
    
         
            +
             
     | 
| 
      
 261 
     | 
    
         
            +
                should "replace the auth if given a new auth for the same db" do
         
     | 
| 
      
 262 
     | 
    
         
            +
                  auth = {'db_name' => 'test', 'username' => 'mickey', 'password' => 'm0u53'}
         
     | 
| 
      
 263 
     | 
    
         
            +
                  @conn.add_auth(auth['db_name'], auth['username'], auth['password'])
         
     | 
| 
      
 264 
     | 
    
         
            +
                  assert_equal 1, @conn.auths.length
         
     | 
| 
      
 265 
     | 
    
         
            +
                  assert_equal auth, @conn.auths[0]
         
     | 
| 
      
 266 
     | 
    
         
            +
                end
         
     | 
| 
      
 267 
     | 
    
         
            +
             
     | 
| 
      
 268 
     | 
    
         
            +
                should "remove auths by database" do
         
     | 
| 
      
 269 
     | 
    
         
            +
                  @conn.remove_auth('non-existent database')
         
     | 
| 
      
 270 
     | 
    
         
            +
                  assert_equal 1, @conn.auths.length
         
     | 
| 
      
 271 
     | 
    
         
            +
             
     | 
| 
      
 272 
     | 
    
         
            +
                  @conn.remove_auth('test')
         
     | 
| 
      
 273 
     | 
    
         
            +
                  assert_equal 0, @conn.auths.length
         
     | 
| 
      
 274 
     | 
    
         
            +
                end
         
     | 
| 
      
 275 
     | 
    
         
            +
             
     | 
| 
      
 276 
     | 
    
         
            +
                should "remove all auths" do
         
     | 
| 
      
 277 
     | 
    
         
            +
                  @conn.clear_auths
         
     | 
| 
      
 278 
     | 
    
         
            +
                  assert_equal 0, @conn.auths.length
         
     | 
| 
      
 279 
     | 
    
         
            +
                end
         
     | 
| 
      
 280 
     | 
    
         
            +
              end
         
     | 
| 
      
 281 
     | 
    
         
            +
             
     | 
| 
      
 282 
     | 
    
         
            +
              context "Connection exceptions" do
         
     | 
| 
      
 283 
     | 
    
         
            +
                setup do
         
     | 
| 
      
 284 
     | 
    
         
            +
                  @con = standard_connection(:pool_size => 10, :timeout => 10)
         
     | 
| 
      
 285 
     | 
    
         
            +
                  @coll = @con[MONGO_TEST_DB]['test-connection-exceptions']
         
     | 
| 
      
 286 
     | 
    
         
            +
                end
         
     | 
| 
      
 287 
     | 
    
         
            +
             
     | 
| 
      
 288 
     | 
    
         
            +
                should "release connection if an exception is raised on send_message" do
         
     | 
| 
      
 289 
     | 
    
         
            +
                  @con.stubs(:send_message_on_socket).raises(ConnectionFailure)
         
     | 
| 
      
 290 
     | 
    
         
            +
                  assert_equal 0, @con.primary_pool.checked_out.size
         
     | 
| 
      
 291 
     | 
    
         
            +
                  assert_raise ConnectionFailure do
         
     | 
| 
      
 292 
     | 
    
         
            +
                    @coll.insert({:test => "insert"})
         
     | 
| 
      
 293 
     | 
    
         
            +
                  end
         
     | 
| 
      
 294 
     | 
    
         
            +
                  assert_equal 0, @con.primary_pool.checked_out.size
         
     | 
| 
      
 295 
     | 
    
         
            +
                end
         
     | 
| 
      
 296 
     | 
    
         
            +
             
     | 
| 
      
 297 
     | 
    
         
            +
                should "release connection if an exception is raised on send_with_safe_check" do
         
     | 
| 
      
 298 
     | 
    
         
            +
                  @con.stubs(:receive).raises(ConnectionFailure)
         
     | 
| 
      
 299 
     | 
    
         
            +
                  assert_equal 0, @con.primary_pool.checked_out.size
         
     | 
| 
      
 300 
     | 
    
         
            +
                  assert_raise ConnectionFailure do
         
     | 
| 
      
 301 
     | 
    
         
            +
                    @coll.insert({:test => "insert"}, :safe => true)
         
     | 
| 
      
 302 
     | 
    
         
            +
                  end
         
     | 
| 
      
 303 
     | 
    
         
            +
                  assert_equal 0, @con.primary_pool.checked_out.size
         
     | 
| 
      
 304 
     | 
    
         
            +
                end
         
     | 
| 
      
 305 
     | 
    
         
            +
             
     | 
| 
      
 306 
     | 
    
         
            +
                should "release connection if an exception is raised on receive_message" do
         
     | 
| 
      
 307 
     | 
    
         
            +
                  @con.stubs(:receive).raises(ConnectionFailure)
         
     | 
| 
      
 308 
     | 
    
         
            +
                  assert_equal 0, @con.primary_pool.checked_out.size
         
     | 
| 
      
 309 
     | 
    
         
            +
                  assert_raise ConnectionFailure do
         
     | 
| 
      
 310 
     | 
    
         
            +
                    @coll.find.to_a
         
     | 
| 
      
 311 
     | 
    
         
            +
                  end
         
     | 
| 
      
 312 
     | 
    
         
            +
                  assert_equal 0, @con.primary_pool.checked_out.size
         
     | 
| 
      
 313 
     | 
    
         
            +
                end
         
     | 
| 
      
 314 
     | 
    
         
            +
             
     | 
| 
      
 315 
     | 
    
         
            +
                should "show a proper exception message if an IOError is raised while closing a socket" do
         
     | 
| 
      
 316 
     | 
    
         
            +
                  fake_socket = Mocha::Mock.new
         
     | 
| 
      
 317 
     | 
    
         
            +
                  fake_socket.stubs(:close).raises(IOError.new)
         
     | 
| 
      
 318 
     | 
    
         
            +
                  fake_socket.stub_everything
         
     | 
| 
      
 319 
     | 
    
         
            +
                  TCPSocket.stubs(:new).returns(fake_socket)
         
     | 
| 
      
 320 
     | 
    
         
            +
             
     | 
| 
      
 321 
     | 
    
         
            +
                  @con.primary_pool.checkout_new_socket
         
     | 
| 
      
 322 
     | 
    
         
            +
                  assert_equal [], @con.primary_pool.close
         
     | 
| 
      
 323 
     | 
    
         
            +
                end
         
     | 
| 
      
 324 
     | 
    
         
            +
              end
         
     | 
| 
      
 325 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,121 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            __END__
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require './test/test_helper'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'mongo/exceptions'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'mongo/util/conversions'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            class ConversionsTest < Test::Unit::TestCase
         
     | 
| 
      
 8 
     | 
    
         
            +
              include Mongo::Conversions
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              def test_array_as_sort_parameters_with_array_of_key_and_value
         
     | 
| 
      
 11 
     | 
    
         
            +
                params = array_as_sort_parameters(["field1", "asc"])
         
     | 
| 
      
 12 
     | 
    
         
            +
                assert_equal({"field1" => 1}, params)
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              def test_array_as_sort_parameters_with_array_of_string_and_values
         
     | 
| 
      
 16 
     | 
    
         
            +
                params = array_as_sort_parameters([["field1", :asc], ["field2", :desc]])
         
     | 
| 
      
 17 
     | 
    
         
            +
                assert_equal({ "field1" => 1, "field2" => -1 }, params)
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
              def test_string_as_sort_parameters_with_string
         
     | 
| 
      
 21 
     | 
    
         
            +
                params = string_as_sort_parameters("field")
         
     | 
| 
      
 22 
     | 
    
         
            +
                assert_equal({ "field" => 1 }, params)
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              def test_string_as_sort_parameters_with_empty_string
         
     | 
| 
      
 26 
     | 
    
         
            +
                params = string_as_sort_parameters("")
         
     | 
| 
      
 27 
     | 
    
         
            +
                assert_equal({}, params)
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
              def test_symbol_as_sort_parameters
         
     | 
| 
      
 31 
     | 
    
         
            +
                params = string_as_sort_parameters(:field)
         
     | 
| 
      
 32 
     | 
    
         
            +
                assert_equal({ "field" => 1 }, params)
         
     | 
| 
      
 33 
     | 
    
         
            +
              end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
              def test_sort_value_when_value_is_one
         
     | 
| 
      
 36 
     | 
    
         
            +
                assert_equal 1, sort_value(1)
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
              def test_sort_value_when_value_is_one_as_a_string
         
     | 
| 
      
 40 
     | 
    
         
            +
                assert_equal 1, sort_value("1")
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
              def test_sort_value_when_value_is_negative_one
         
     | 
| 
      
 44 
     | 
    
         
            +
                assert_equal(-1, sort_value(-1))
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
              def test_sort_value_when_value_is_negative_one_as_a_string
         
     | 
| 
      
 48 
     | 
    
         
            +
                assert_equal(-1, sort_value("-1"))
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
              def test_sort_value_when_value_is_ascending
         
     | 
| 
      
 52 
     | 
    
         
            +
                assert_equal 1, sort_value("ascending")
         
     | 
| 
      
 53 
     | 
    
         
            +
              end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
              def test_sort_value_when_value_is_asc
         
     | 
| 
      
 56 
     | 
    
         
            +
                assert_equal 1, sort_value("asc")
         
     | 
| 
      
 57 
     | 
    
         
            +
              end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
              def test_sort_value_when_value_is_uppercase_ascending
         
     | 
| 
      
 60 
     | 
    
         
            +
                assert_equal 1, sort_value("ASCENDING")
         
     | 
| 
      
 61 
     | 
    
         
            +
              end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
              def test_sort_value_when_value_is_uppercase_asc
         
     | 
| 
      
 64 
     | 
    
         
            +
                assert_equal 1, sort_value("ASC")
         
     | 
| 
      
 65 
     | 
    
         
            +
              end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
              def test_sort_value_when_value_is_symbol_ascending
         
     | 
| 
      
 68 
     | 
    
         
            +
                assert_equal 1, sort_value(:ascending)
         
     | 
| 
      
 69 
     | 
    
         
            +
              end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
              def test_sort_value_when_value_is_symbol_asc
         
     | 
| 
      
 72 
     | 
    
         
            +
                assert_equal 1, sort_value(:asc)
         
     | 
| 
      
 73 
     | 
    
         
            +
              end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
              def test_sort_value_when_value_is_symbol_uppercase_ascending
         
     | 
| 
      
 76 
     | 
    
         
            +
                assert_equal 1, sort_value(:ASCENDING)
         
     | 
| 
      
 77 
     | 
    
         
            +
              end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
              def test_sort_value_when_value_is_symbol_uppercase_asc
         
     | 
| 
      
 80 
     | 
    
         
            +
                assert_equal 1, sort_value(:ASC)
         
     | 
| 
      
 81 
     | 
    
         
            +
              end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
              def test_sort_value_when_value_is_descending
         
     | 
| 
      
 84 
     | 
    
         
            +
                assert_equal(-1, sort_value("descending"))
         
     | 
| 
      
 85 
     | 
    
         
            +
              end
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
              def test_sort_value_when_value_is_desc
         
     | 
| 
      
 88 
     | 
    
         
            +
                assert_equal(-1, sort_value("desc"))
         
     | 
| 
      
 89 
     | 
    
         
            +
              end
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
              def test_sort_value_when_value_is_uppercase_descending
         
     | 
| 
      
 92 
     | 
    
         
            +
                assert_equal(-1, sort_value("DESCENDING"))
         
     | 
| 
      
 93 
     | 
    
         
            +
              end
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
              def test_sort_value_when_value_is_uppercase_desc
         
     | 
| 
      
 96 
     | 
    
         
            +
                assert_equal(-1, sort_value("DESC"))
         
     | 
| 
      
 97 
     | 
    
         
            +
              end
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
              def test_sort_value_when_value_is_symbol_descending
         
     | 
| 
      
 100 
     | 
    
         
            +
                assert_equal(-1, sort_value(:descending))
         
     | 
| 
      
 101 
     | 
    
         
            +
              end
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
              def test_sort_value_when_value_is_symbol_desc
         
     | 
| 
      
 104 
     | 
    
         
            +
                assert_equal(-1, sort_value(:desc))
         
     | 
| 
      
 105 
     | 
    
         
            +
              end
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
              def test_sort_value_when_value_is_uppercase_symbol_descending
         
     | 
| 
      
 108 
     | 
    
         
            +
                assert_equal(-1, sort_value(:DESCENDING))
         
     | 
| 
      
 109 
     | 
    
         
            +
              end
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
              def test_sort_value_when_value_is_uppercase_symbol_desc
         
     | 
| 
      
 112 
     | 
    
         
            +
                assert_equal(-1, sort_value(:DESC))
         
     | 
| 
      
 113 
     | 
    
         
            +
              end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
              def test_sort_value_when_value_is_invalid
         
     | 
| 
      
 116 
     | 
    
         
            +
                assert_raise Mongo::InvalidSortValueError do
         
     | 
| 
      
 117 
     | 
    
         
            +
                  sort_value(2)
         
     | 
| 
      
 118 
     | 
    
         
            +
                end
         
     | 
| 
      
 119 
     | 
    
         
            +
              end
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,75 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require './test/test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'logger'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            class CursorFailTest < Test::Unit::TestCase
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              include Mongo
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              @@connection = standard_connection
         
     | 
| 
      
 9 
     | 
    
         
            +
              @@db   = @@connection.db(MONGO_TEST_DB)
         
     | 
| 
      
 10 
     | 
    
         
            +
              @@coll = @@db.collection('test')
         
     | 
| 
      
 11 
     | 
    
         
            +
              @@version = @@connection.server_version
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 14 
     | 
    
         
            +
                @@coll.remove
         
     | 
| 
      
 15 
     | 
    
         
            +
                @@coll.insert('a' => 1)     # collection not created until it's used
         
     | 
| 
      
 16 
     | 
    
         
            +
                @@coll_full_name = "#{MONGO_TEST_DB}.test"
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              def test_refill_via_get_more
         
     | 
| 
      
 20 
     | 
    
         
            +
                assert_equal 1, @@coll.count
         
     | 
| 
      
 21 
     | 
    
         
            +
                1000.times { |i|
         
     | 
| 
      
 22 
     | 
    
         
            +
                  assert_equal 1 + i, @@coll.count
         
     | 
| 
      
 23 
     | 
    
         
            +
                  @@coll.insert('a' => i)
         
     | 
| 
      
 24 
     | 
    
         
            +
                }
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                assert_equal 1001, @@coll.count
         
     | 
| 
      
 27 
     | 
    
         
            +
                count = 0
         
     | 
| 
      
 28 
     | 
    
         
            +
                @@coll.find.each { |obj|
         
     | 
| 
      
 29 
     | 
    
         
            +
                  count += obj['a']
         
     | 
| 
      
 30 
     | 
    
         
            +
                }
         
     | 
| 
      
 31 
     | 
    
         
            +
                assert_equal 1001, @@coll.count
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                # do the same thing again for debugging
         
     | 
| 
      
 34 
     | 
    
         
            +
                assert_equal 1001, @@coll.count
         
     | 
| 
      
 35 
     | 
    
         
            +
                count2 = 0
         
     | 
| 
      
 36 
     | 
    
         
            +
                @@coll.find.each { |obj|
         
     | 
| 
      
 37 
     | 
    
         
            +
                  count2 += obj['a']
         
     | 
| 
      
 38 
     | 
    
         
            +
                }
         
     | 
| 
      
 39 
     | 
    
         
            +
                assert_equal 1001, @@coll.count
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                assert_equal count, count2
         
     | 
| 
      
 42 
     | 
    
         
            +
                assert_equal 499501, count
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              def test_refill_via_get_more_alt_coll
         
     | 
| 
      
 46 
     | 
    
         
            +
                coll = @@db.collection('test-alt-coll')
         
     | 
| 
      
 47 
     | 
    
         
            +
                coll.remove
         
     | 
| 
      
 48 
     | 
    
         
            +
                coll.insert('a' => 1)     # collection not created until it's used
         
     | 
| 
      
 49 
     | 
    
         
            +
                assert_equal 1, coll.count
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                1000.times { |i|
         
     | 
| 
      
 52 
     | 
    
         
            +
                  assert_equal 1 + i, coll.count
         
     | 
| 
      
 53 
     | 
    
         
            +
                  coll.insert('a' => i)
         
     | 
| 
      
 54 
     | 
    
         
            +
                }
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                assert_equal 1001, coll.count
         
     | 
| 
      
 57 
     | 
    
         
            +
                count = 0
         
     | 
| 
      
 58 
     | 
    
         
            +
                coll.find.each { |obj|
         
     | 
| 
      
 59 
     | 
    
         
            +
                  count += obj['a']
         
     | 
| 
      
 60 
     | 
    
         
            +
                }
         
     | 
| 
      
 61 
     | 
    
         
            +
                assert_equal 1001, coll.count
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                # do the same thing again for debugging
         
     | 
| 
      
 64 
     | 
    
         
            +
                assert_equal 1001, coll.count
         
     | 
| 
      
 65 
     | 
    
         
            +
                count2 = 0
         
     | 
| 
      
 66 
     | 
    
         
            +
                coll.find.each { |obj|
         
     | 
| 
      
 67 
     | 
    
         
            +
                  count2 += obj['a']
         
     | 
| 
      
 68 
     | 
    
         
            +
                }
         
     | 
| 
      
 69 
     | 
    
         
            +
                assert_equal 1001, coll.count
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                assert_equal count, count2
         
     | 
| 
      
 72 
     | 
    
         
            +
                assert_equal 499501, count
         
     | 
| 
      
 73 
     | 
    
         
            +
              end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
            end
         
     |