mongo 1.12.5 → 2.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CONTRIBUTING.md +64 -0
- data/LICENSE +1 -1
- data/README.md +23 -125
- data/Rakefile +26 -21
- data/bin/mongo_console +6 -38
- data/lib/mongo.rb +23 -82
- data/lib/mongo/address.rb +111 -0
- data/lib/mongo/address/ipv4.rb +85 -0
- data/lib/mongo/address/ipv6.rb +85 -0
- data/lib/mongo/address/unix.rb +76 -0
- data/lib/mongo/auth.rb +108 -0
- data/lib/mongo/auth/cr.rb +44 -0
- data/lib/mongo/auth/cr/conversation.rb +119 -0
- data/lib/mongo/auth/executable.rb +52 -0
- data/lib/mongo/auth/ldap.rb +48 -0
- data/lib/mongo/auth/ldap/conversation.rb +92 -0
- data/lib/mongo/auth/roles.rb +104 -0
- data/lib/mongo/auth/scram.rb +53 -0
- data/lib/mongo/auth/scram/conversation.rb +450 -0
- data/lib/mongo/auth/user.rb +159 -0
- data/lib/mongo/auth/user/view.rb +102 -0
- data/lib/mongo/auth/x509.rb +48 -0
- data/lib/mongo/auth/x509/conversation.rb +92 -0
- data/lib/mongo/{gridfs.rb → bulk.rb} +2 -5
- data/lib/mongo/bulk/bulk_write.rb +307 -0
- data/lib/mongo/client.rb +233 -0
- data/lib/mongo/cluster.rb +203 -0
- data/lib/mongo/cluster/topology.rb +60 -0
- data/lib/mongo/cluster/topology/replica_set.rb +160 -0
- data/lib/mongo/cluster/topology/sharded.rb +132 -0
- data/lib/mongo/cluster/topology/standalone.rb +132 -0
- data/lib/mongo/cluster/topology/unknown.rb +155 -0
- data/lib/mongo/collection.rb +130 -1101
- data/lib/mongo/collection/view.rb +169 -0
- data/lib/mongo/collection/view/aggregation.rb +108 -0
- data/lib/mongo/collection/view/explainable.rb +49 -0
- data/lib/mongo/collection/view/immutable.rb +43 -0
- data/lib/mongo/collection/view/iterable.rb +48 -0
- data/lib/mongo/collection/view/map_reduce.rb +191 -0
- data/lib/mongo/collection/view/readable.rb +363 -0
- data/lib/mongo/collection/view/writable.rb +169 -0
- data/lib/mongo/cursor.rb +79 -680
- data/lib/mongo/database.rb +224 -0
- data/lib/mongo/database/view.rb +101 -0
- data/lib/mongo/error.rb +81 -0
- data/lib/mongo/error/bulk_write_failure.rb +41 -0
- data/lib/mongo/{utils/thread_local_variable_manager.rb → error/empty_batch.rb} +22 -8
- data/{test/functional/db_connection_test.rb → lib/mongo/error/invalid_bulk_operation.rb} +19 -8
- data/lib/mongo/error/invalid_collection_name.rb +39 -0
- data/lib/mongo/error/invalid_database_name.rb +39 -0
- data/{test/replica_set/ssl_test.rb → lib/mongo/error/invalid_document.rb} +21 -14
- data/lib/mongo/error/invalid_file.rb +38 -0
- data/lib/mongo/error/invalid_nonce.rb +46 -0
- data/lib/mongo/error/invalid_replacement_document.rb +39 -0
- data/lib/mongo/error/invalid_signature.rb +47 -0
- data/{test/functional/ssl_test.rb → lib/mongo/error/invalid_update_document.rb} +22 -12
- data/lib/mongo/error/max_bson_size.rb +40 -0
- data/lib/mongo/error/max_message_size.rb +42 -0
- data/lib/mongo/{utils.rb → error/need_primary_server.rb} +10 -6
- data/lib/mongo/{connection.rb → error/operation_failure.rb} +10 -6
- data/lib/mongo/error/parser.rb +77 -0
- data/lib/mongo/{connection/socket.rb → error/socket_error.rb} +10 -5
- data/lib/mongo/error/socket_timeout_error.rb +23 -0
- data/lib/mongo/error/unsupported_features.rb +43 -0
- data/lib/mongo/event.rb +40 -0
- data/lib/mongo/event/listeners.rb +63 -0
- data/lib/mongo/event/primary_elected.rb +53 -0
- data/lib/mongo/event/publisher.rb +42 -0
- data/lib/mongo/event/server_added.rb +53 -0
- data/lib/mongo/event/server_removed.rb +53 -0
- data/lib/mongo/event/subscriber.rb +41 -0
- data/lib/mongo/grid.rb +16 -0
- data/lib/mongo/grid/file.rb +94 -0
- data/lib/mongo/grid/file/chunk.rb +184 -0
- data/lib/mongo/grid/file/metadata.rb +223 -0
- data/lib/mongo/grid/fs.rb +149 -0
- data/lib/mongo/index.rb +64 -0
- data/lib/mongo/index/view.rb +205 -0
- data/lib/mongo/loggable.rb +126 -0
- data/lib/mongo/logger.rb +132 -0
- data/lib/mongo/operation.rb +26 -0
- data/lib/mongo/operation/aggregate.rb +100 -0
- data/lib/mongo/operation/aggregate/result.rb +84 -0
- data/lib/mongo/operation/batchable.rb +103 -0
- data/lib/mongo/operation/bulk_delete/result.rb +197 -0
- data/lib/mongo/operation/bulk_insert/result.rb +195 -0
- data/lib/mongo/operation/bulk_update/result.rb +295 -0
- data/lib/mongo/operation/command.rb +62 -0
- data/lib/mongo/operation/executable.rb +105 -0
- data/lib/mongo/operation/kill_cursors.rb +39 -0
- data/lib/mongo/operation/limited.rb +37 -0
- data/lib/mongo/operation/list_collections/result.rb +116 -0
- data/lib/mongo/operation/list_indexes/result.rb +118 -0
- data/lib/mongo/operation/map_reduce.rb +96 -0
- data/lib/mongo/operation/map_reduce/result.rb +122 -0
- data/lib/mongo/{functional.rb → operation/read.rb} +7 -7
- data/lib/mongo/operation/read/collections_info.rb +67 -0
- data/lib/mongo/operation/read/get_more.rb +71 -0
- data/lib/mongo/operation/read/indexes.rb +68 -0
- data/lib/mongo/operation/read/list_collections.rb +75 -0
- data/lib/mongo/operation/read/list_indexes.rb +77 -0
- data/lib/mongo/operation/read/query.rb +71 -0
- data/lib/mongo/operation/read_preferrable.rb +34 -0
- data/lib/mongo/operation/result.rb +259 -0
- data/lib/mongo/operation/specifiable.rb +380 -0
- data/lib/mongo/operation/write.rb +25 -0
- data/lib/mongo/operation/write/bulk_delete.rb +158 -0
- data/lib/mongo/operation/write/bulk_insert.rb +160 -0
- data/lib/mongo/operation/write/bulk_update.rb +167 -0
- data/lib/mongo/{connection/socket/socket_util.rb → operation/write/command.rb} +9 -24
- data/lib/mongo/operation/write/command/create_user.rb +43 -0
- data/lib/mongo/operation/write/command/delete.rb +56 -0
- data/lib/mongo/operation/write/command/drop_index.rb +51 -0
- data/lib/mongo/operation/write/command/ensure_index.rb +55 -0
- data/lib/mongo/operation/write/command/insert.rb +55 -0
- data/lib/mongo/operation/write/command/remove_user.rb +42 -0
- data/lib/mongo/operation/write/command/update.rb +60 -0
- data/lib/mongo/operation/write/command/writable.rb +61 -0
- data/lib/mongo/operation/write/create_index.rb +84 -0
- data/lib/mongo/operation/write/create_user.rb +75 -0
- data/lib/mongo/operation/write/delete.rb +91 -0
- data/lib/mongo/operation/write/drop_index.rb +62 -0
- data/lib/mongo/operation/write/insert.rb +88 -0
- data/lib/mongo/operation/write/remove_user.rb +70 -0
- data/lib/mongo/operation/write/update.rb +98 -0
- data/lib/mongo/protocol.rb +15 -0
- data/lib/mongo/protocol/bit_vector.rb +61 -0
- data/lib/mongo/protocol/delete.rb +94 -0
- data/lib/mongo/protocol/get_more.rb +99 -0
- data/lib/mongo/protocol/insert.rb +99 -0
- data/lib/mongo/protocol/kill_cursors.rb +74 -0
- data/lib/mongo/protocol/message.rb +252 -0
- data/lib/mongo/protocol/query.rb +147 -0
- data/lib/mongo/protocol/reply.rb +72 -0
- data/lib/mongo/protocol/serializers.rb +180 -0
- data/lib/mongo/protocol/update.rb +111 -0
- data/lib/mongo/server.rb +163 -0
- data/lib/mongo/server/connectable.rb +99 -0
- data/lib/mongo/server/connection.rb +133 -0
- data/lib/mongo/server/connection_pool.rb +141 -0
- data/lib/mongo/server/connection_pool/queue.rb +182 -0
- data/lib/mongo/server/context.rb +66 -0
- data/lib/mongo/server/description.rb +450 -0
- data/lib/mongo/server/description/features.rb +85 -0
- data/lib/mongo/server/description/inspector.rb +79 -0
- data/lib/mongo/server/description/inspector/primary_elected.rb +58 -0
- data/lib/mongo/server/description/inspector/server_added.rb +59 -0
- data/lib/mongo/server/description/inspector/server_removed.rb +59 -0
- data/lib/mongo/server/monitor.rb +160 -0
- data/lib/mongo/server/monitor/connection.rb +88 -0
- data/lib/mongo/server_selector.rb +81 -0
- data/lib/mongo/server_selector/nearest.rb +94 -0
- data/lib/mongo/server_selector/primary.rb +88 -0
- data/lib/mongo/server_selector/primary_preferred.rb +94 -0
- data/lib/mongo/server_selector/secondary.rb +91 -0
- data/lib/mongo/server_selector/secondary_preferred.rb +96 -0
- data/lib/mongo/server_selector/selectable.rb +209 -0
- data/lib/mongo/socket.rb +179 -0
- data/lib/mongo/socket/ssl.rb +108 -0
- data/lib/mongo/socket/tcp.rb +69 -0
- data/lib/mongo/socket/unix.rb +66 -0
- data/lib/mongo/uri.rb +504 -0
- data/lib/mongo/version.rb +21 -0
- data/lib/mongo/write_concern.rb +99 -0
- data/lib/mongo/write_concern/acknowledged.rb +38 -0
- data/lib/mongo/write_concern/normalizable.rb +73 -0
- data/lib/mongo/write_concern/unacknowledged.rb +43 -0
- data/mongo.gemspec +17 -14
- data/spec/mongo/address/ipv4_spec.rb +74 -0
- data/spec/mongo/address/ipv6_spec.rb +74 -0
- data/spec/mongo/address/unix_spec.rb +30 -0
- data/spec/mongo/address_spec.rb +206 -0
- data/spec/mongo/auth/cr_spec.rb +59 -0
- data/spec/mongo/auth/ldap_spec.rb +40 -0
- data/spec/mongo/auth/scram/conversation_spec.rb +197 -0
- data/spec/mongo/auth/scram_spec.rb +55 -0
- data/spec/mongo/auth/user/view_spec.rb +76 -0
- data/spec/mongo/auth/user_spec.rb +190 -0
- data/spec/mongo/auth/x509_spec.rb +40 -0
- data/spec/mongo/auth_spec.rb +65 -0
- data/spec/mongo/bulk/bulk_write_spec.rb +175 -0
- data/spec/mongo/client_spec.rb +564 -0
- data/spec/mongo/cluster/topology/replica_set_spec.rb +101 -0
- data/spec/mongo/cluster/topology/sharded_spec.rb +74 -0
- data/spec/mongo/cluster/topology/standalone_spec.rb +79 -0
- data/spec/mongo/cluster/topology_spec.rb +65 -0
- data/spec/mongo/cluster_spec.rb +129 -0
- data/spec/mongo/collection/view/aggregation_spec.rb +135 -0
- data/spec/mongo/collection/view/explainable_spec.rb +32 -0
- data/spec/mongo/collection/view/map_reduce_spec.rb +242 -0
- data/spec/mongo/collection/view/readable_spec.rb +603 -0
- data/spec/mongo/collection/view/writable_spec.rb +504 -0
- data/spec/mongo/collection/view_spec.rb +521 -0
- data/spec/mongo/collection_spec.rb +362 -0
- data/spec/mongo/cursor_spec.rb +295 -0
- data/spec/mongo/database_spec.rb +306 -0
- data/spec/mongo/error/parser_spec.rb +119 -0
- data/spec/mongo/event/publisher_spec.rb +50 -0
- data/spec/mongo/event/subscriber_spec.rb +34 -0
- data/spec/mongo/grid/file/chunk_spec.rb +226 -0
- data/spec/mongo/grid/file/metadata_spec.rb +69 -0
- data/spec/mongo/grid/file_spec.rb +138 -0
- data/spec/mongo/grid/fs_spec.rb +129 -0
- data/spec/mongo/index/view_spec.rb +226 -0
- data/spec/mongo/loggable_spec.rb +62 -0
- data/spec/mongo/logger_spec.rb +97 -0
- data/spec/mongo/operation/aggregate/result_spec.rb +80 -0
- data/spec/mongo/operation/aggregate_spec.rb +135 -0
- data/spec/mongo/operation/command_spec.rb +106 -0
- data/spec/mongo/operation/kill_cursors_spec.rb +66 -0
- data/spec/mongo/operation/limited_spec.rb +50 -0
- data/spec/mongo/operation/map_reduce_spec.rb +143 -0
- data/spec/mongo/operation/read/collections_info_spec.rb +40 -0
- data/spec/mongo/operation/read/get_more_spec.rb +81 -0
- data/spec/mongo/operation/read/indexes_spec.rb +31 -0
- data/spec/mongo/operation/read/query_spec.rb +84 -0
- data/spec/mongo/operation/result_spec.rb +275 -0
- data/spec/mongo/operation/specifiable_spec.rb +53 -0
- data/spec/mongo/operation/write/bulk_delete_spec.rb +473 -0
- data/spec/mongo/operation/write/bulk_insert_spec.rb +466 -0
- data/spec/mongo/operation/write/bulk_update_spec.rb +524 -0
- data/spec/mongo/operation/write/command/delete_spec.rb +116 -0
- data/spec/mongo/operation/write/command/insert_spec.rb +117 -0
- data/spec/mongo/operation/write/command/update_spec.rb +123 -0
- data/spec/mongo/operation/write/create_user_spec.rb +44 -0
- data/spec/mongo/operation/write/delete_spec.rb +178 -0
- data/spec/mongo/operation/write/drop_index_spec.rb +51 -0
- data/spec/mongo/operation/write/ensure_index_spec.rb +81 -0
- data/spec/mongo/operation/write/insert_spec.rb +231 -0
- data/spec/mongo/operation/write/remove_user_spec.rb +46 -0
- data/spec/mongo/operation/write/response_spec.rb +85 -0
- data/spec/mongo/operation/write/update_spec.rb +177 -0
- data/spec/mongo/protocol/delete_spec.rb +167 -0
- data/spec/mongo/protocol/get_more_spec.rb +146 -0
- data/spec/mongo/protocol/insert_spec.rb +161 -0
- data/spec/mongo/protocol/kill_cursors_spec.rb +101 -0
- data/spec/mongo/protocol/query_spec.rb +285 -0
- data/spec/mongo/protocol/reply_spec.rb +157 -0
- data/spec/mongo/protocol/update_spec.rb +186 -0
- data/spec/mongo/server/connection_pool/queue_spec.rb +170 -0
- data/spec/mongo/server/connection_pool_spec.rb +120 -0
- data/spec/mongo/server/connection_spec.rb +289 -0
- data/spec/mongo/server/description/features_spec.rb +138 -0
- data/spec/mongo/server/description/inspector/primary_elected_spec.rb +94 -0
- data/spec/mongo/server/description/inspector/server_added_spec.rb +92 -0
- data/spec/mongo/server/description/inspector/server_removed_spec.rb +95 -0
- data/spec/mongo/server/description_spec.rb +510 -0
- data/spec/mongo/server/monitor_spec.rb +130 -0
- data/spec/mongo/server_discovery_and_monitoring_spec.rb +103 -0
- data/spec/mongo/server_selection_rtt_spec.rb +104 -0
- data/spec/mongo/server_selection_spec.rb +89 -0
- data/spec/mongo/server_selector/nearest_spec.rb +250 -0
- data/spec/mongo/server_selector/primary_preferred_spec.rb +290 -0
- data/spec/mongo/server_selector/primary_spec.rb +114 -0
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +252 -0
- data/spec/mongo/server_selector/secondary_spec.rb +196 -0
- data/spec/mongo/server_selector_spec.rb +101 -0
- data/spec/mongo/server_spec.rb +131 -0
- data/spec/mongo/uri_spec.rb +517 -0
- data/spec/mongo/write_concern/acknowledged_spec.rb +44 -0
- data/spec/mongo/write_concern/unacknowledged_spec.rb +15 -0
- data/spec/mongo_orchestration_spec.rb +70 -0
- data/spec/spec_helper.rb +148 -0
- data/spec/support/authorization.rb +245 -0
- data/spec/support/helpers.rb +140 -0
- data/spec/support/matchers.rb +37 -0
- data/spec/support/mongo_orchestration.rb +61 -0
- data/spec/support/mongo_orchestration/requestable.rb +109 -0
- data/spec/support/mongo_orchestration/standalone.rb +57 -0
- data/spec/support/sdam/rs/discover_arbiters.yml +41 -0
- data/spec/support/sdam/rs/discover_passives.yml +41 -0
- data/spec/support/sdam/rs/discover_primary.yml +40 -0
- data/spec/support/sdam/rs/discover_secondary.yml +41 -0
- data/spec/support/sdam/rs/discovery.yml +195 -0
- data/spec/support/sdam/rs/ghost_discovered.yml +39 -0
- data/spec/support/sdam/rs/hosts_differ_from_seeds.yml +34 -0
- data/spec/support/sdam/rs/member_reconfig.yml +68 -0
- data/spec/support/sdam/rs/member_standalone.yml +60 -0
- data/spec/support/sdam/rs/new_primary.yml +74 -0
- data/spec/support/sdam/rs/new_primary_wrong_set_name.yml +71 -0
- data/spec/support/sdam/rs/non_rs_member.yml +31 -0
- data/spec/support/sdam/rs/normalize_case.yml +49 -0
- data/spec/support/sdam/rs/primary_becomes_standalone.yml +52 -0
- data/spec/support/sdam/rs/primary_changes_set_name.yml +57 -0
- data/spec/support/sdam/rs/primary_disconnect.yml +56 -0
- data/spec/support/sdam/rs/primary_wrong_set_name.yml +27 -0
- data/spec/support/sdam/rs/response_from_removed.yml +63 -0
- data/spec/support/sdam/rs/rsother_discovered.yml +41 -0
- data/spec/support/sdam/rs/sec_not_auth.yml +49 -0
- data/spec/support/sdam/rs/secondary_wrong_set_name.yml +28 -0
- data/spec/support/sdam/rs/secondary_wrong_set_name_with_primary.yml +69 -0
- data/spec/support/sdam/rs/unexpected_mongos.yml +26 -0
- data/spec/support/sdam/rs/wrong_set_name.yml +35 -0
- data/spec/support/sdam/sharded/multiple_mongoses.yml +46 -0
- data/spec/support/sdam/sharded/non_mongos_removed.yml +41 -0
- data/spec/support/sdam/sharded/normalize_uri_case.yml +32 -0
- data/spec/support/sdam/single/direct_connection_external_ip.yml +34 -0
- data/spec/support/sdam/single/direct_connection_mongos.yml +33 -0
- data/spec/support/sdam/single/direct_connection_rsarbiter.yml +35 -0
- data/spec/support/sdam/single/direct_connection_rsprimary.yml +34 -0
- data/spec/support/sdam/single/direct_connection_rssecondary.yml +35 -0
- data/spec/support/sdam/single/direct_connection_slave.yml +32 -0
- data/spec/support/sdam/single/direct_connection_standalone.yml +32 -0
- data/spec/support/sdam/single/not_ok_response.yml +39 -0
- data/spec/support/sdam/single/standalone_removed.yml +32 -0
- data/spec/support/sdam/single/unavailable_seed.yml +28 -0
- data/spec/support/server_discovery_and_monitoring.rb +167 -0
- data/spec/support/server_selection.rb +140 -0
- data/spec/support/server_selection/rtt/first_value.yml +4 -0
- data/spec/support/server_selection/rtt/first_value_zero.yml +4 -0
- data/spec/support/server_selection/rtt/value_test_1.yml +4 -0
- data/spec/support/server_selection/rtt/value_test_2.yml +4 -0
- data/spec/support/server_selection/rtt/value_test_3.yml +4 -0
- data/spec/support/server_selection/rtt/value_test_4.yml +4 -0
- data/spec/support/server_selection/rtt/value_test_5.yml +4 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest.yml +32 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_non_matching.yml +27 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Primary.yml +23 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred.yml +32 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/PrimaryPreferred_non_matching.yml +27 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary.yml +32 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred.yml +32 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/SecondaryPreferred_non_matching.yml +27 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_non_matching.yml +27 -0
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest.yml +41 -0
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_non_matching.yml +34 -0
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Primary.yml +33 -0
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred.yml +39 -0
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/PrimaryPreferred_non_matching.yml +36 -0
- data/spec/support/server_selection/selection/Sharded/read/SecondaryPreferred.yml +32 -0
- data/spec/support/server_selection/selection/Single/read/SecondaryPreferred.yml +23 -0
- data/spec/support/server_selection/selection/Unknown/read/SecondaryPreferred.yml +13 -0
- data/spec/support/server_selection_rtt.rb +41 -0
- data/spec/support/shared/bulk_write.rb +498 -0
- data/spec/support/shared/cursor.rb +38 -0
- data/spec/support/shared/operation.rb +77 -0
- data/spec/support/shared/protocol.rb +31 -0
- data/spec/support/shared/server_selector.rb +111 -0
- data/spec/support/shared/socket.rb +82 -0
- data/spec/support/travis.rb +14 -0
- metadata +523 -189
- metadata.gz.sig +0 -0
- data/VERSION +0 -1
- data/lib/mongo/bulk_write_collection_view.rb +0 -387
- data/lib/mongo/collection_writer.rb +0 -364
- data/lib/mongo/connection/node.rb +0 -249
- data/lib/mongo/connection/pool.rb +0 -340
- data/lib/mongo/connection/pool_manager.rb +0 -320
- data/lib/mongo/connection/sharding_pool_manager.rb +0 -67
- data/lib/mongo/connection/socket/ssl_socket.rb +0 -95
- data/lib/mongo/connection/socket/tcp_socket.rb +0 -87
- data/lib/mongo/connection/socket/unix_socket.rb +0 -39
- data/lib/mongo/db.rb +0 -808
- data/lib/mongo/exception.rb +0 -145
- data/lib/mongo/functional/authentication.rb +0 -455
- data/lib/mongo/functional/logging.rb +0 -85
- data/lib/mongo/functional/read_preference.rb +0 -183
- data/lib/mongo/functional/scram.rb +0 -556
- data/lib/mongo/functional/uri_parser.rb +0 -409
- data/lib/mongo/functional/write_concern.rb +0 -66
- data/lib/mongo/gridfs/grid.rb +0 -112
- data/lib/mongo/gridfs/grid_ext.rb +0 -53
- data/lib/mongo/gridfs/grid_file_system.rb +0 -163
- data/lib/mongo/gridfs/grid_io.rb +0 -484
- data/lib/mongo/legacy.rb +0 -140
- data/lib/mongo/mongo_client.rb +0 -697
- data/lib/mongo/mongo_replica_set_client.rb +0 -535
- data/lib/mongo/mongo_sharded_client.rb +0 -159
- data/lib/mongo/networking.rb +0 -372
- data/lib/mongo/utils/conversions.rb +0 -110
- data/lib/mongo/utils/core_ext.rb +0 -70
- data/lib/mongo/utils/server_version.rb +0 -69
- data/lib/mongo/utils/support.rb +0 -80
- data/test/functional/authentication_test.rb +0 -39
- data/test/functional/bulk_api_stress_test.rb +0 -133
- data/test/functional/bulk_write_collection_view_test.rb +0 -1198
- data/test/functional/client_test.rb +0 -627
- data/test/functional/collection_test.rb +0 -2175
- data/test/functional/collection_writer_test.rb +0 -83
- data/test/functional/conversions_test.rb +0 -163
- data/test/functional/cursor_fail_test.rb +0 -57
- data/test/functional/cursor_message_test.rb +0 -56
- data/test/functional/cursor_test.rb +0 -683
- data/test/functional/db_api_test.rb +0 -835
- data/test/functional/db_test.rb +0 -348
- data/test/functional/grid_file_system_test.rb +0 -285
- data/test/functional/grid_io_test.rb +0 -252
- data/test/functional/grid_test.rb +0 -273
- data/test/functional/pool_test.rb +0 -136
- data/test/functional/safe_test.rb +0 -98
- data/test/functional/support_test.rb +0 -62
- data/test/functional/timeout_test.rb +0 -60
- data/test/functional/uri_test.rb +0 -446
- data/test/functional/write_concern_test.rb +0 -118
- data/test/helpers/general.rb +0 -50
- data/test/helpers/test_unit.rb +0 -476
- data/test/replica_set/authentication_test.rb +0 -37
- data/test/replica_set/basic_test.rb +0 -189
- data/test/replica_set/client_test.rb +0 -393
- data/test/replica_set/connection_test.rb +0 -138
- data/test/replica_set/count_test.rb +0 -66
- data/test/replica_set/cursor_test.rb +0 -220
- data/test/replica_set/insert_test.rb +0 -157
- data/test/replica_set/max_values_test.rb +0 -151
- data/test/replica_set/pinning_test.rb +0 -105
- data/test/replica_set/query_test.rb +0 -73
- data/test/replica_set/read_preference_test.rb +0 -219
- data/test/replica_set/refresh_test.rb +0 -211
- data/test/replica_set/replication_ack_test.rb +0 -95
- data/test/sharded_cluster/basic_test.rb +0 -203
- data/test/shared/authentication/basic_auth_shared.rb +0 -260
- data/test/shared/authentication/bulk_api_auth_shared.rb +0 -249
- data/test/shared/authentication/gssapi_shared.rb +0 -176
- data/test/shared/authentication/sasl_plain_shared.rb +0 -96
- data/test/shared/authentication/scram_shared.rb +0 -92
- data/test/shared/ssl_shared.rb +0 -235
- data/test/test_helper.rb +0 -61
- data/test/threading/basic_test.rb +0 -120
- data/test/tools/mongo_config.rb +0 -708
- data/test/tools/mongo_config_test.rb +0 -160
- data/test/unit/client_test.rb +0 -381
- data/test/unit/collection_test.rb +0 -166
- data/test/unit/connection_test.rb +0 -335
- data/test/unit/cursor_test.rb +0 -307
- data/test/unit/db_test.rb +0 -136
- data/test/unit/grid_test.rb +0 -76
- data/test/unit/mongo_sharded_client_test.rb +0 -48
- data/test/unit/node_test.rb +0 -93
- data/test/unit/pool_manager_test.rb +0 -111
- data/test/unit/read_pref_test.rb +0 -406
- data/test/unit/read_test.rb +0 -159
- data/test/unit/safe_test.rb +0 -158
- data/test/unit/sharding_pool_manager_test.rb +0 -84
- data/test/unit/write_concern_test.rb +0 -175
data/test/functional/db_test.rb
DELETED
@@ -1,348 +0,0 @@
|
|
1
|
-
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
require 'test_helper'
|
16
|
-
require 'digest/md5'
|
17
|
-
require 'stringio'
|
18
|
-
require 'logger'
|
19
|
-
|
20
|
-
class TestPKFactory
|
21
|
-
def create_pk(row)
|
22
|
-
row['_id'] ||= BSON::ObjectId.new
|
23
|
-
row
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class DBTest < Test::Unit::TestCase
|
28
|
-
|
29
|
-
include Mongo
|
30
|
-
|
31
|
-
def setup
|
32
|
-
@client = standard_connection
|
33
|
-
@db = @client.db(TEST_DB)
|
34
|
-
@version = @client.server_version
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_close
|
38
|
-
@client.close
|
39
|
-
assert !@client.connected?
|
40
|
-
begin
|
41
|
-
@db.collection('test').insert('a' => 1)
|
42
|
-
fail "expected 'NilClass' exception"
|
43
|
-
rescue => ex
|
44
|
-
assert_match(/NilClass/, ex.to_s)
|
45
|
-
ensure
|
46
|
-
@db = standard_connection.db(TEST_DB)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_create_collection
|
51
|
-
col = @db.create_collection('foo')
|
52
|
-
assert_equal @db['foo'].name, col.name
|
53
|
-
|
54
|
-
col = @db.create_collection(:foo)
|
55
|
-
assert_equal @db['foo'].name, col.name
|
56
|
-
|
57
|
-
@db.drop_collection('foo')
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_get_and_drop_collection
|
61
|
-
db = @client.db(TEST_DB, :strict => true)
|
62
|
-
db.create_collection('foo')
|
63
|
-
assert db.collection('foo')
|
64
|
-
assert db.drop_collection('foo')
|
65
|
-
|
66
|
-
db.create_collection(:foo)
|
67
|
-
assert db.collection(:foo)
|
68
|
-
# Use a string because of SERVER-16260
|
69
|
-
assert db.drop_collection('foo')
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_logger
|
73
|
-
output = StringIO.new
|
74
|
-
logger = Logger.new(output)
|
75
|
-
logger.level = Logger::DEBUG
|
76
|
-
conn = standard_connection(:logger => logger)
|
77
|
-
assert_equal logger, conn.logger
|
78
|
-
|
79
|
-
conn.logger.debug 'testing'
|
80
|
-
assert output.string.include?('testing')
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_full_coll_name
|
84
|
-
coll = @db.collection('test')
|
85
|
-
assert_equal "#{TEST_DB}.test", @db.full_collection_name(coll.name)
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_collection_names
|
89
|
-
@db.collection("test").insert("foo" => 5)
|
90
|
-
@db.collection("test.mike").insert("bar" => 0)
|
91
|
-
|
92
|
-
colls = @db.collection_names()
|
93
|
-
assert colls.include?("test")
|
94
|
-
assert colls.include?("test.mike")
|
95
|
-
colls.each { |name|
|
96
|
-
assert !name.include?("$")
|
97
|
-
}
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_collections
|
101
|
-
@db.collection("test.durran").insert("foo" => 5)
|
102
|
-
@db.collection("test.les").insert("bar" => 0)
|
103
|
-
|
104
|
-
colls = @db.collections()
|
105
|
-
assert_not_nil colls.select { |coll| coll.name == "test.durran" }
|
106
|
-
assert_not_nil colls.select { |coll| coll.name == "test.les" }
|
107
|
-
assert_equal [], colls.select { |coll| coll.name == "does_not_exist" }
|
108
|
-
|
109
|
-
assert_kind_of Collection, colls[0]
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_pk_factory
|
113
|
-
db = standard_connection.db(TEST_DB, :pk => TestPKFactory.new)
|
114
|
-
coll = db.collection('test')
|
115
|
-
coll.remove
|
116
|
-
|
117
|
-
insert_id = coll.insert('name' => 'Fred', 'age' => 42)
|
118
|
-
# new id gets added to returned object
|
119
|
-
row = coll.find_one({'name' => 'Fred'})
|
120
|
-
oid = row['_id']
|
121
|
-
assert_not_nil oid
|
122
|
-
assert_equal insert_id, oid
|
123
|
-
|
124
|
-
oid = BSON::ObjectId.new
|
125
|
-
data = {'_id' => oid, 'name' => 'Barney', 'age' => 41}
|
126
|
-
coll.insert(data)
|
127
|
-
row = coll.find_one({'name' => data['name']})
|
128
|
-
db_oid = row['_id']
|
129
|
-
assert_equal oid, db_oid
|
130
|
-
assert_equal data, row
|
131
|
-
|
132
|
-
coll.remove
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_pk_factory_reset
|
136
|
-
conn = standard_connection
|
137
|
-
db = conn.db(TEST_DB)
|
138
|
-
db.pk_factory = Object.new # first time
|
139
|
-
begin
|
140
|
-
db.pk_factory = Object.new
|
141
|
-
fail "error: expected exception"
|
142
|
-
rescue => ex
|
143
|
-
assert_match(/Cannot change/, ex.to_s)
|
144
|
-
ensure
|
145
|
-
conn.close
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_command
|
150
|
-
assert_raise OperationFailure do
|
151
|
-
@db.command({:non_command => 1}, :check_response => true)
|
152
|
-
end
|
153
|
-
|
154
|
-
result = @db.command({:non_command => 1}, :check_response => false)
|
155
|
-
assert !Mongo::Support.ok?(result)
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_error
|
159
|
-
@db.reset_error_history
|
160
|
-
assert_nil @db.get_last_error['err']
|
161
|
-
assert !@db.error?
|
162
|
-
assert_nil @db.previous_error
|
163
|
-
|
164
|
-
@db.command({:forceerror => 1}, :check_response => false)
|
165
|
-
assert @db.error?
|
166
|
-
assert_not_nil @db.get_last_error['err']
|
167
|
-
assert_not_nil @db.previous_error
|
168
|
-
|
169
|
-
@db.command({:forceerror => 1}, :check_response => false)
|
170
|
-
assert @db.error?
|
171
|
-
assert @db.get_last_error['err']
|
172
|
-
prev_error = @db.previous_error
|
173
|
-
assert_equal 1, prev_error['nPrev']
|
174
|
-
assert_equal prev_error["err"], @db.get_last_error['err']
|
175
|
-
|
176
|
-
@db.collection('test').find_one
|
177
|
-
assert_nil @db.get_last_error['err']
|
178
|
-
assert !@db.error?
|
179
|
-
assert @db.previous_error
|
180
|
-
assert_equal 2, @db.previous_error['nPrev']
|
181
|
-
|
182
|
-
@db.reset_error_history
|
183
|
-
assert_nil @db.get_last_error['err']
|
184
|
-
assert !@db.error?
|
185
|
-
assert_nil @db.previous_error
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_check_command_response
|
189
|
-
if @version >= "2.1.0"
|
190
|
-
command = {:create => "$$$$"}
|
191
|
-
expected_codes = [10356, 2]
|
192
|
-
expected_msg = "invalid"
|
193
|
-
raised = false
|
194
|
-
begin
|
195
|
-
@db.command(command)
|
196
|
-
rescue => ex
|
197
|
-
raised = true
|
198
|
-
assert ex.message.include?(expected_msg) ||
|
199
|
-
(ex.result.has_key?("assertion") &&
|
200
|
-
ex.result["assertion"].include?(expected_msg)),
|
201
|
-
"error message does not contain '#{expected_msg}'"
|
202
|
-
assert expected_codes.include?(ex.error_code)
|
203
|
-
assert expected_codes.include?(ex.result['code'])
|
204
|
-
ensure
|
205
|
-
assert raised, "No assertion raised!"
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
def test_arbitrary_command_opts
|
211
|
-
with_forced_timeout(@client) do
|
212
|
-
assert_raise ExecutionTimeout do
|
213
|
-
cmd = OrderedHash.new
|
214
|
-
cmd[:ping] = 1
|
215
|
-
cmd[:maxTimeMS] = 100
|
216
|
-
@db.command(cmd)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
def test_command_with_bson
|
222
|
-
normal_response = @db.command({:buildInfo => 1})
|
223
|
-
bson = BSON::BSON_CODER.serialize({:buildInfo => 1}, false, false)
|
224
|
-
bson_response = @db.command({:bson => bson})
|
225
|
-
assert_equal normal_response, bson_response
|
226
|
-
end
|
227
|
-
|
228
|
-
def test_last_status
|
229
|
-
@db['test'].remove
|
230
|
-
@db['test'].save("i" => 1)
|
231
|
-
|
232
|
-
@db['test'].update({"i" => 1}, {"$set" => {"i" => 2}})
|
233
|
-
assert @db.get_last_error()["updatedExisting"]
|
234
|
-
|
235
|
-
@db['test'].update({"i" => 1}, {"$set" => {"i" => 500}})
|
236
|
-
assert !@db.get_last_error()["updatedExisting"]
|
237
|
-
end
|
238
|
-
|
239
|
-
def test_text_port_number_raises_no_errors
|
240
|
-
client = standard_connection
|
241
|
-
db = client[TEST_DB]
|
242
|
-
db.collection('users').remove
|
243
|
-
end
|
244
|
-
|
245
|
-
def test_stored_function_management
|
246
|
-
grant_admin_user_eval_role(@client)
|
247
|
-
@db.add_stored_function("sum", "function (x, y) { return x + y; }")
|
248
|
-
assert_equal @db.eval("return sum(2,3);"), 5
|
249
|
-
assert @db.remove_stored_function("sum")
|
250
|
-
assert_raise OperationFailure do
|
251
|
-
@db.eval("return sum(2,3);")
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
def test_eval
|
256
|
-
grant_admin_user_eval_role(@client)
|
257
|
-
@db.eval("db.system.save({_id:'hello', value: function() { print('hello'); } })")
|
258
|
-
assert_equal 'hello', @db['system'].find_one['_id']
|
259
|
-
end
|
260
|
-
|
261
|
-
def test_eval_nook
|
262
|
-
grant_admin_user_eval_role(@client)
|
263
|
-
function = "db.system.save({_id:'hello', value: function(string) { print(string); } })"
|
264
|
-
@db.expects(:command).with do |selector, opts|
|
265
|
-
selector[:nolock] == true
|
266
|
-
end.returns({ 'ok' => 1, 'retval' => 1 })
|
267
|
-
@db.eval(function, 'hello', :nolock => true)
|
268
|
-
end
|
269
|
-
|
270
|
-
def test_default_admin_roles
|
271
|
-
return unless @version >= '2.5.3'
|
272
|
-
# admin user
|
273
|
-
@db.stubs(:command).returns({}, true)
|
274
|
-
@db.expects(:command).with do |command, cmd_opts|
|
275
|
-
command[:createUser] == TEST_USER
|
276
|
-
cmd_opts[:roles] == ['root'] if cmd_opts
|
277
|
-
end
|
278
|
-
|
279
|
-
silently { @db.add_user(TEST_USER, TEST_USER_PWD) }
|
280
|
-
|
281
|
-
@db.stubs(:command).returns({}, true)
|
282
|
-
@db.expects(:command).with do |command, cmd_opts|
|
283
|
-
command[:createUser] == TEST_USER
|
284
|
-
cmd_opts[:roles] == ['readAnyDatabase'] if cmd_opts
|
285
|
-
end
|
286
|
-
|
287
|
-
silently { @db.add_user(TEST_USER, TEST_USER_PWD, true) }
|
288
|
-
end
|
289
|
-
|
290
|
-
def test_db_stats
|
291
|
-
return unless @version >= "1.3.5"
|
292
|
-
stats = @db.stats
|
293
|
-
assert stats.has_key?('collections')
|
294
|
-
assert stats.has_key?('dataSize')
|
295
|
-
end
|
296
|
-
|
297
|
-
context "database profiling" do
|
298
|
-
setup do
|
299
|
-
@db = @client[TEST_DB]
|
300
|
-
@coll = @db['test']
|
301
|
-
@coll.remove
|
302
|
-
@r1 = @coll.insert('a' => 1) # collection not created until it's used
|
303
|
-
end
|
304
|
-
|
305
|
-
should "set default profiling level" do
|
306
|
-
assert_equal :off, @db.profiling_level
|
307
|
-
end
|
308
|
-
|
309
|
-
should "change profiling level" do
|
310
|
-
@db.profiling_level = :slow_only
|
311
|
-
assert_equal :slow_only, @db.profiling_level
|
312
|
-
@db.profiling_level = :off
|
313
|
-
assert_equal :off, @db.profiling_level
|
314
|
-
@db.profiling_level = :all
|
315
|
-
assert_equal :all, @db.profiling_level
|
316
|
-
begin
|
317
|
-
@db.profiling_level = :medium
|
318
|
-
fail "shouldn't be able to do this"
|
319
|
-
rescue
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
should "return profiling info" do
|
324
|
-
if @version >= "2.2" && @version < "3.0"
|
325
|
-
@db.profiling_level = :all
|
326
|
-
@coll.find()
|
327
|
-
@db.profiling_level = :off
|
328
|
-
|
329
|
-
info = @db.profiling_info
|
330
|
-
assert_kind_of Array, info
|
331
|
-
assert info.length >= 1
|
332
|
-
first = info.first
|
333
|
-
assert_kind_of Time, first['ts']
|
334
|
-
assert_kind_of Numeric, first['millis']
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
should "validate collection" do
|
339
|
-
doc = @db.validate_collection(@coll.name)
|
340
|
-
if @version >= "1.9.1"
|
341
|
-
assert doc['valid']
|
342
|
-
else
|
343
|
-
assert doc['result']
|
344
|
-
end
|
345
|
-
end
|
346
|
-
|
347
|
-
end
|
348
|
-
end
|
@@ -1,285 +0,0 @@
|
|
1
|
-
# Copyright (C) 2009-2013 MongoDB, Inc.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
require 'test_helper'
|
16
|
-
|
17
|
-
class GridFileSystemTest < Test::Unit::TestCase
|
18
|
-
context "GridFileSystem:" do
|
19
|
-
setup do
|
20
|
-
@con = standard_connection
|
21
|
-
@db = @con.db(TEST_DB)
|
22
|
-
end
|
23
|
-
|
24
|
-
teardown do
|
25
|
-
@db.drop_collection('fs.files')
|
26
|
-
@db.drop_collection('fs.chunks')
|
27
|
-
end
|
28
|
-
|
29
|
-
context "Initialization" do
|
30
|
-
setup do
|
31
|
-
@chunks_data = "CHUNKS" * 50000
|
32
|
-
@grid = GridFileSystem.new(@db)
|
33
|
-
@opts = {:w => 1}
|
34
|
-
@original_opts = @opts.dup
|
35
|
-
@grid.open('sample.file', 'w', @opts) do |f|
|
36
|
-
f.write @chunks_data
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
should "not modify original opts" do
|
41
|
-
assert_equal @original_opts, @opts
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "When reading:" do
|
46
|
-
setup do
|
47
|
-
@chunks_data = "CHUNKS" * 50000
|
48
|
-
@grid = GridFileSystem.new(@db)
|
49
|
-
@grid.open('sample.file', 'w') do |f|
|
50
|
-
f.write @chunks_data
|
51
|
-
end
|
52
|
-
|
53
|
-
@grid = GridFileSystem.new(@db)
|
54
|
-
end
|
55
|
-
|
56
|
-
should "return existence of the file" do
|
57
|
-
file = @grid.exist?(:filename => 'sample.file')
|
58
|
-
assert_equal 'sample.file', file['filename']
|
59
|
-
end
|
60
|
-
|
61
|
-
should "return nil if the file doesn't exist" do
|
62
|
-
assert_nil @grid.exist?(:filename => 'foo.file')
|
63
|
-
end
|
64
|
-
|
65
|
-
should "read sample data" do
|
66
|
-
data = @grid.open('sample.file', 'r') { |f| f.read }
|
67
|
-
assert_equal data.length, @chunks_data.length
|
68
|
-
end
|
69
|
-
|
70
|
-
should "have a unique index on chunks" do
|
71
|
-
assert @db['fs.chunks'].index_information['files_id_1_n_1']['unique']
|
72
|
-
end
|
73
|
-
|
74
|
-
should "have an index on filename" do
|
75
|
-
assert @db['fs.files'].index_information['filename_1_uploadDate_-1']
|
76
|
-
end
|
77
|
-
|
78
|
-
should "return an empty string if length is zero" do
|
79
|
-
data = @grid.open('sample.file', 'r') { |f| f.read(0) }
|
80
|
-
assert_equal '', data
|
81
|
-
end
|
82
|
-
|
83
|
-
should "return the first n bytes" do
|
84
|
-
data = @grid.open('sample.file', 'r') {|f| f.read(288888) }
|
85
|
-
assert_equal 288888, data.length
|
86
|
-
assert_equal @chunks_data[0...288888], data
|
87
|
-
end
|
88
|
-
|
89
|
-
should "return the first n bytes even with an offset" do
|
90
|
-
data = @grid.open('sample.file', 'r') do |f|
|
91
|
-
f.seek(1000)
|
92
|
-
f.read(288888)
|
93
|
-
end
|
94
|
-
assert_equal 288888, data.length
|
95
|
-
assert_equal @chunks_data[1000...289888], data
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context "When writing:" do
|
100
|
-
setup do
|
101
|
-
@data = "BYTES" * 50
|
102
|
-
@grid = GridFileSystem.new(@db)
|
103
|
-
@grid.open('sample', 'w') do |f|
|
104
|
-
f.write @data
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
should "read sample data" do
|
109
|
-
data = @grid.open('sample', 'r') { |f| f.read }
|
110
|
-
assert_equal data.length, @data.length
|
111
|
-
end
|
112
|
-
|
113
|
-
should "return the total number of bytes written" do
|
114
|
-
data = 'a' * 300000
|
115
|
-
assert_equal 300000, @grid.open('sample', 'w') {|f| f.write(data) }
|
116
|
-
end
|
117
|
-
|
118
|
-
should "more read sample data" do
|
119
|
-
data = @grid.open('sample', 'r') { |f| f.read }
|
120
|
-
assert_equal data.length, @data.length
|
121
|
-
end
|
122
|
-
|
123
|
-
should "raise exception if file not found" do
|
124
|
-
assert_raise GridFileNotFound do
|
125
|
-
@grid.open('io', 'r') { |f| f.write('hello') }
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
should "raise exception if not opened for write" do
|
130
|
-
assert_raise GridError do
|
131
|
-
@grid.open('sample', 'r') { |f| f.write('hello') }
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
context "and when overwriting the file" do
|
136
|
-
setup do
|
137
|
-
@old = @grid.open('sample', 'r')
|
138
|
-
|
139
|
-
@new_data = "DATA" * 10
|
140
|
-
@grid.open('sample', 'w') do |f|
|
141
|
-
f.write @new_data
|
142
|
-
end
|
143
|
-
|
144
|
-
@new = @grid.open('sample', 'r')
|
145
|
-
end
|
146
|
-
|
147
|
-
should "have a newer upload date" do
|
148
|
-
assert @new.upload_date > @old.upload_date, "New data is not greater than old date."
|
149
|
-
end
|
150
|
-
|
151
|
-
should "have a different files_id" do
|
152
|
-
assert_not_equal @new.files_id, @old.files_id
|
153
|
-
end
|
154
|
-
|
155
|
-
should "contain the new data" do
|
156
|
-
assert_equal @new_data, @new.read, "Expected DATA"
|
157
|
-
end
|
158
|
-
|
159
|
-
context "and on a second overwrite" do
|
160
|
-
setup do
|
161
|
-
@new_data = "NEW" * 1000
|
162
|
-
@grid.open('sample', 'w') do |f|
|
163
|
-
f.write @new_data
|
164
|
-
end
|
165
|
-
|
166
|
-
@ids = @db['fs.files'].find({'filename' => 'sample'}).map {|file| file['_id']}
|
167
|
-
end
|
168
|
-
|
169
|
-
should "write a third version of the file" do
|
170
|
-
assert_equal 3, @db['fs.files'].find({'filename' => 'sample'}).count
|
171
|
-
assert_equal 3, @db['fs.chunks'].find({'files_id' => {'$in' => @ids}}).count
|
172
|
-
end
|
173
|
-
|
174
|
-
should "remove all versions and their data on delete" do
|
175
|
-
@grid.delete('sample')
|
176
|
-
assert_equal 0, @db['fs.files'].find({'filename' => 'sample'}).count
|
177
|
-
assert_equal 0, @db['fs.chunks'].find({'files_id' => {'$in' => @ids}}).count
|
178
|
-
end
|
179
|
-
|
180
|
-
should "delete all versions which exceed the number of versions to keep specified by the option :versions" do
|
181
|
-
@versions = 1 + rand(4-1)
|
182
|
-
@grid.open('sample', 'w', :versions => @versions) do |f|
|
183
|
-
f.write @new_data
|
184
|
-
end
|
185
|
-
@new_ids = @db['fs.files'].find({'filename' => 'sample'}).map {|file| file['_id']}
|
186
|
-
assert_equal @versions, @new_ids.length
|
187
|
-
id = @new_ids.first
|
188
|
-
assert !@ids.include?(id)
|
189
|
-
assert_equal @versions, @db['fs.files'].find({'filename' => 'sample'}).count
|
190
|
-
end
|
191
|
-
|
192
|
-
should "delete old versions on write with :delete_old is passed in" do
|
193
|
-
@grid.open('sample', 'w', :delete_old => true) do |f|
|
194
|
-
f.write @new_data
|
195
|
-
end
|
196
|
-
@new_ids = @db['fs.files'].find({'filename' => 'sample'}).map {|file| file['_id']}
|
197
|
-
assert_equal 1, @new_ids.length
|
198
|
-
id = @new_ids.first
|
199
|
-
assert !@ids.include?(id)
|
200
|
-
assert_equal 1, @db['fs.files'].find({'filename' => 'sample'}).count
|
201
|
-
assert_equal 1, @db['fs.chunks'].find({'files_id' => id}).count
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
context "When writing chunks:" do
|
208
|
-
setup do
|
209
|
-
data = "B" * 50000
|
210
|
-
@grid = GridFileSystem.new(@db)
|
211
|
-
@grid.open('sample', 'w', :chunk_size => 1000) do |f|
|
212
|
-
f.write data
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
should "write the correct number of chunks" do
|
217
|
-
file = @db['fs.files'].find_one({:filename => 'sample'})
|
218
|
-
chunks = @db['fs.chunks'].find({'files_id' => file['_id']}).to_a
|
219
|
-
assert_equal 50, chunks.length
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
context "Positioning:" do
|
224
|
-
setup do
|
225
|
-
data = 'hello, world' + '1' * 5000 + 'goodbye!' + '2' * 1000 + '!'
|
226
|
-
@grid = GridFileSystem.new(@db)
|
227
|
-
@grid.open('hello', 'w', :chunk_size => 1000) do |f|
|
228
|
-
f.write data
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
should "seek within chunks" do
|
233
|
-
@grid.open('hello', 'r') do |f|
|
234
|
-
f.seek(0)
|
235
|
-
assert_equal 'h', f.read(1)
|
236
|
-
f.seek(7)
|
237
|
-
assert_equal 'w', f.read(1)
|
238
|
-
f.seek(4)
|
239
|
-
assert_equal 'o', f.read(1)
|
240
|
-
f.seek(0)
|
241
|
-
f.seek(7, IO::SEEK_CUR)
|
242
|
-
assert_equal 'w', f.read(1)
|
243
|
-
f.seek(-2, IO::SEEK_CUR)
|
244
|
-
assert_equal ' ', f.read(1)
|
245
|
-
f.seek(-4, IO::SEEK_CUR)
|
246
|
-
assert_equal 'l', f.read(1)
|
247
|
-
f.seek(3, IO::SEEK_CUR)
|
248
|
-
assert_equal 'w', f.read(1)
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
should "seek between chunks" do
|
253
|
-
@grid.open('hello', 'r') do |f|
|
254
|
-
f.seek(1000)
|
255
|
-
assert_equal '11111', f.read(5)
|
256
|
-
|
257
|
-
f.seek(5009)
|
258
|
-
assert_equal '111goodbye!222', f.read(14)
|
259
|
-
|
260
|
-
f.seek(-1, IO::SEEK_END)
|
261
|
-
assert_equal '!', f.read(1)
|
262
|
-
f.seek(-6, IO::SEEK_END)
|
263
|
-
assert_equal '2', f.read(1)
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
should "tell the current position" do
|
268
|
-
@grid.open('hello', 'r') do |f|
|
269
|
-
assert_equal 0, f.tell
|
270
|
-
|
271
|
-
f.seek(999)
|
272
|
-
assert_equal 999, f.tell
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
should "seek only in read mode" do
|
277
|
-
assert_raise GridError do
|
278
|
-
silently do
|
279
|
-
@grid.open('hello', 'w') { |f| f.seek(0) }
|
280
|
-
end
|
281
|
-
end
|
282
|
-
end
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|