moneta 1.0.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +425 -0
- data/.gitignore +3 -0
- data/.rspec +4 -0
- data/.rubocop.yml +194 -0
- data/.yardopts +6 -1
- data/CHANGES +88 -0
- data/CONTRIBUTORS +10 -2
- data/Gemfile +198 -76
- data/LICENSE +1 -1
- data/README.md +181 -83
- data/SPEC.md +70 -0
- data/feature_matrix.yaml +227 -0
- data/lib/action_dispatch/middleware/session/moneta_store.rb +1 -0
- data/lib/active_support/cache/moneta_store.rb +102 -6
- data/lib/moneta/adapter.rb +52 -0
- data/lib/moneta/adapters/activerecord.rb +284 -99
- data/lib/moneta/adapters/activesupportcache.rb +120 -0
- data/lib/moneta/adapters/cassandra.rb +303 -51
- data/lib/moneta/adapters/client.rb +72 -23
- data/lib/moneta/adapters/couch.rb +353 -49
- data/lib/moneta/adapters/datamapper.rb +11 -5
- data/lib/moneta/adapters/daybreak.rb +31 -20
- data/lib/moneta/adapters/dbm.rb +10 -16
- data/lib/moneta/adapters/file.rb +34 -13
- data/lib/moneta/adapters/fog.rb +5 -6
- data/lib/moneta/adapters/gdbm.rb +10 -16
- data/lib/moneta/adapters/hbase.rb +11 -13
- data/lib/moneta/adapters/kyotocabinet.rb +78 -17
- data/lib/moneta/adapters/leveldb.rb +35 -15
- data/lib/moneta/adapters/lmdb.rb +47 -23
- data/lib/moneta/adapters/localmemcache.rb +7 -13
- data/lib/moneta/adapters/lruhash.rb +45 -48
- data/lib/moneta/adapters/memcached/dalli.rb +67 -30
- data/lib/moneta/adapters/memcached/native.rb +33 -30
- data/lib/moneta/adapters/memcached.rb +1 -0
- data/lib/moneta/adapters/memory.rb +7 -7
- data/lib/moneta/adapters/mongo.rb +265 -6
- data/lib/moneta/adapters/null.rb +1 -2
- data/lib/moneta/adapters/pstore.rb +68 -25
- data/lib/moneta/adapters/redis.rb +101 -32
- data/lib/moneta/adapters/restclient.rb +17 -16
- data/lib/moneta/adapters/riak.rb +10 -11
- data/lib/moneta/adapters/sdbm.rb +10 -16
- data/lib/moneta/adapters/sequel/mysql.rb +66 -0
- data/lib/moneta/adapters/sequel/postgres.rb +80 -0
- data/lib/moneta/adapters/sequel/postgres_hstore.rb +240 -0
- data/lib/moneta/adapters/sequel/sqlite.rb +57 -0
- data/lib/moneta/adapters/sequel.rb +253 -52
- data/lib/moneta/adapters/sqlite.rb +103 -23
- data/lib/moneta/adapters/tdb.rb +21 -12
- data/lib/moneta/adapters/tokyocabinet.rb +24 -16
- data/lib/moneta/adapters/tokyotyrant.rb +49 -28
- data/lib/moneta/adapters/yaml.rb +1 -5
- data/lib/moneta/builder.rb +2 -3
- data/lib/moneta/cache.rb +11 -1
- data/lib/moneta/config.rb +101 -0
- data/lib/moneta/create_support.rb +21 -0
- data/lib/moneta/dbm_adapter.rb +31 -0
- data/lib/moneta/defaults.rb +320 -0
- data/lib/moneta/each_key_support.rb +27 -0
- data/lib/moneta/enumerable.rb +38 -0
- data/lib/moneta/expires.rb +112 -11
- data/lib/moneta/expires_support.rb +59 -0
- data/lib/moneta/fallback.rb +84 -0
- data/lib/moneta/hash_adapter.rb +68 -0
- data/lib/moneta/increment_support.rb +16 -0
- data/lib/moneta/lock.rb +26 -2
- data/lib/moneta/logger.rb +2 -2
- data/lib/moneta/nil_values.rb +35 -0
- data/lib/moneta/option_support.rb +51 -0
- data/lib/moneta/optionmerger.rb +0 -1
- data/lib/moneta/pool.rb +339 -28
- data/lib/moneta/proxy.rb +75 -2
- data/lib/moneta/server.rb +230 -68
- data/lib/moneta/shared.rb +36 -14
- data/lib/moneta/stack.rb +7 -7
- data/lib/moneta/synchronize.rb +5 -11
- data/lib/moneta/transformer/config.rb +64 -42
- data/lib/moneta/transformer/helper/bson.rb +7 -14
- data/lib/moneta/transformer/helper.rb +5 -5
- data/lib/moneta/transformer.rb +217 -23
- data/lib/moneta/utils.rb +3 -9
- data/lib/moneta/version.rb +1 -1
- data/lib/moneta/weak_each_key.rb +72 -0
- data/lib/moneta/wrapper.rb +30 -0
- data/lib/moneta.rb +29 -10
- data/lib/rack/cache/moneta.rb +13 -11
- data/lib/rack/moneta_rest.rb +2 -2
- data/lib/rack/session/moneta.rb +3 -4
- data/moneta.gemspec +19 -4
- data/script/benchmarks +311 -100
- data/script/contributors +11 -6
- data/script/parallel-tests +58 -83
- data/script/start-couchdb +27 -0
- data/script/start-hbase +47 -0
- data/script/start-services +5 -6
- data/script/update-feature-matrix +148 -0
- data/spec/active_support/cache_moneta_store_spec.rb +129 -106
- data/spec/features/concurrent_create.rb +42 -0
- data/spec/features/concurrent_increment.rb +39 -0
- data/spec/features/create.rb +25 -0
- data/spec/features/create_expires.rb +19 -0
- data/spec/features/default_expires.rb +14 -0
- data/spec/features/each_key.rb +119 -0
- data/spec/features/expires.rb +296 -0
- data/spec/features/features.rb +16 -0
- data/spec/features/increment.rb +98 -0
- data/spec/features/marshallable_key.rb +43 -0
- data/spec/features/marshallable_value.rb +7 -0
- data/spec/features/multiprocess.rb +8 -0
- data/spec/features/not_create.rb +7 -0
- data/spec/features/not_each_key.rb +7 -0
- data/spec/features/not_increment.rb +13 -0
- data/spec/features/not_persist.rb +9 -0
- data/spec/features/null.rb +66 -0
- data/spec/features/persist.rb +14 -0
- data/spec/features/returndifferent.rb +9 -0
- data/spec/features/returnsame.rb +9 -0
- data/spec/features/store.rb +261 -0
- data/spec/features/store_large.rb +13 -0
- data/spec/features/transform_value.rb +44 -0
- data/spec/features/transform_value_expires.rb +41 -0
- data/spec/helper.rb +345 -78
- data/spec/moneta/adapters/activerecord/adapter_activerecord_existing_connection_spec.rb +61 -0
- data/spec/moneta/adapters/activerecord/adapter_activerecord_spec.rb +126 -0
- data/spec/moneta/adapters/activerecord/standard_activerecord_spec.rb +21 -0
- data/spec/moneta/adapters/activerecord/standard_activerecord_with_expires_spec.rb +27 -0
- data/spec/moneta/adapters/activesupportcache/adapter_activesupportcache_spec.rb +54 -0
- data/spec/moneta/adapters/activesupportcache/adapter_activesupportcache_with_default_expires_spec.rb +54 -0
- data/spec/moneta/adapters/activesupportcache/standard_activesupportcache_spec.rb +14 -0
- data/spec/moneta/adapters/cassandra/adapter_cassandra_spec.rb +17 -0
- data/spec/moneta/adapters/cassandra/adapter_cassandra_with_default_expires_spec.rb +18 -0
- data/spec/moneta/adapters/cassandra/helper.rb +18 -0
- data/spec/moneta/adapters/cassandra/standard_cassandra_spec.rb +18 -0
- data/spec/moneta/adapters/client/adapter_client_spec.rb +11 -0
- data/spec/moneta/adapters/client/client_helper.rb +25 -0
- data/spec/moneta/adapters/client/standard_client_tcp_spec.rb +23 -0
- data/spec/moneta/adapters/client/standard_client_unix_spec.rb +28 -0
- data/spec/moneta/adapters/cookie/adapter_cookie_spec.rb +7 -0
- data/spec/moneta/adapters/couch/adapter_couch_spec.rb +204 -0
- data/spec/moneta/adapters/couch/standard_couch_spec.rb +15 -0
- data/spec/moneta/adapters/couch/standard_couch_with_expires_spec.rb +19 -0
- data/spec/moneta/adapters/datamapper/adapter_datamapper_spec.rb +60 -0
- data/spec/moneta/adapters/datamapper/standard_datamapper_spec.rb +21 -0
- data/spec/moneta/adapters/datamapper/standard_datamapper_with_expires_spec.rb +26 -0
- data/spec/moneta/adapters/datamapper/standard_datamapper_with_repository_spec.rb +22 -0
- data/spec/moneta/adapters/daybreak/adapter_daybreak_spec.rb +7 -0
- data/spec/moneta/adapters/daybreak/standard_daybreak_spec.rb +7 -0
- data/spec/moneta/adapters/daybreak/standard_daybreak_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/dbm/adapter_dbm_spec.rb +7 -0
- data/spec/moneta/adapters/dbm/standard_dbm_spec.rb +7 -0
- data/spec/moneta/adapters/dbm/standard_dbm_with_expires_spec.rb +12 -0
- data/spec/moneta/adapters/faraday_helper.rb +10 -0
- data/spec/moneta/adapters/file/adapter_file_spec.rb +7 -0
- data/spec/moneta/adapters/file/standard_file_spec.rb +7 -0
- data/spec/moneta/adapters/file/standard_file_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/fog/adapter_fog_spec.rb +16 -0
- data/spec/moneta/adapters/fog/standard_fog_spec.rb +15 -0
- data/spec/moneta/adapters/fog/standard_fog_with_expires_spec.rb +20 -0
- data/spec/moneta/adapters/gdbm/adapter_gdbm_spec.rb +7 -0
- data/spec/moneta/adapters/gdbm/standard_gdbm_spec.rb +7 -0
- data/spec/moneta/adapters/gdbm/standard_gdbm_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/hashfile/standard_hashfile_spec.rb +7 -0
- data/spec/moneta/adapters/hashfile/standard_hashfile_with_expires_spec.rb +12 -0
- data/spec/moneta/adapters/hbase/adapter_hbase_spec.rb +7 -0
- data/spec/moneta/adapters/hbase/standard_hbase_spec.rb +4 -0
- data/spec/moneta/adapters/hbase/standard_hbase_with_expires_spec.rb +8 -0
- data/spec/moneta/adapters/kyotocabinet/adapter_kyotocabinet_spec.rb +7 -0
- data/spec/moneta/adapters/kyotocabinet/standard_kyotocabinet_spec.rb +7 -0
- data/spec/moneta/adapters/kyotocabinet/standard_kyotocabinet_with_expires_spec.rb +14 -0
- data/spec/moneta/adapters/leveldb/adapter_leveldb_spec.rb +7 -0
- data/spec/moneta/adapters/leveldb/standard_leveldb_spec.rb +7 -0
- data/spec/moneta/adapters/leveldb/standard_leveldb_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/lmdb/adapter_lmdb_spec.rb +7 -0
- data/spec/moneta/adapters/lmdb/adapter_lmdb_with_db_spec.rb +7 -0
- data/spec/moneta/adapters/lmdb/standard_lmdb_spec.rb +7 -0
- data/spec/moneta/adapters/lmdb/standard_lmdb_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/localmemcache/adapter_localmemcache_spec.rb +7 -0
- data/spec/moneta/adapters/localmemcache/standard_localmemcache_spec.rb +7 -0
- data/spec/moneta/adapters/localmemcache/standard_localmemcache_with_expires_spec.rb +11 -0
- data/spec/moneta/{adapter_lruhash_spec.rb → adapters/lruhash/adapter_lruhash_spec.rb} +15 -33
- data/spec/moneta/adapters/lruhash/standard_lruhash_spec.rb +4 -0
- data/spec/moneta/adapters/lruhash/standard_lruhash_with_expires_spec.rb +8 -0
- data/spec/moneta/adapters/memcached/adapter_memcached_spec.rb +13 -0
- data/spec/moneta/adapters/memcached/dalli/adapter_memcached_dalli_spec.rb +25 -0
- data/spec/moneta/adapters/memcached/dalli/standard_memcached_dalli_spec.rb +11 -0
- data/spec/moneta/adapters/memcached/native/adapter_memcached_native_spec.rb +25 -0
- data/spec/moneta/adapters/memcached/native/standard_memcached_native_spec.rb +11 -0
- data/spec/moneta/adapters/memcached/standard_memcached_spec.rb +17 -0
- data/spec/moneta/adapters/memcached_helper.rb +20 -0
- data/spec/moneta/adapters/memory/adapter_memory_spec.rb +7 -0
- data/spec/moneta/adapters/memory/standard_memory_spec.rb +4 -0
- data/spec/moneta/adapters/memory/standard_memory_with_compress_spec.rb +9 -0
- data/spec/moneta/adapters/memory/standard_memory_with_expires_spec.rb +8 -0
- data/spec/moneta/adapters/memory/standard_memory_with_json_key_serializer_spec.rb +4 -0
- data/spec/moneta/adapters/memory/standard_memory_with_json_serializer_spec.rb +9 -0
- data/spec/moneta/adapters/memory/standard_memory_with_json_value_serializer_spec.rb +9 -0
- data/spec/moneta/adapters/memory/standard_memory_with_prefix_spec.rb +41 -0
- data/spec/moneta/adapters/memory/standard_memory_with_snappy_compress_spec.rb +9 -0
- data/spec/moneta/adapters/mongo/adapter_mongo_spec.rb +41 -0
- data/spec/moneta/adapters/mongo/adapter_mongo_with_default_expires_spec.rb +14 -0
- data/spec/moneta/adapters/mongo/standard_mongo_spec.rb +7 -0
- data/spec/moneta/adapters/null/null_adapter_spec.rb +7 -0
- data/spec/moneta/adapters/null/standard_null_spec.rb +4 -0
- data/spec/moneta/adapters/pstore/adapter_pstore_spec.rb +7 -0
- data/spec/moneta/adapters/pstore/standard_pstore_spec.rb +9 -0
- data/spec/moneta/adapters/pstore/standard_pstore_with_expires_spec.rb +13 -0
- data/spec/moneta/adapters/redis/adapter_redis_spec.rb +20 -0
- data/spec/moneta/adapters/redis/standard_redis_spec.rb +14 -0
- data/spec/moneta/adapters/restclient/adapter_restclient_spec.rb +13 -0
- data/spec/moneta/adapters/restclient/helper.rb +12 -0
- data/spec/moneta/adapters/restclient/standard_restclient_spec.rb +13 -0
- data/spec/moneta/adapters/riak/adapter_riak_spec.rb +14 -0
- data/spec/moneta/adapters/riak/standard_riak_spec.rb +10 -0
- data/spec/moneta/adapters/riak/standard_riak_with_expires_spec.rb +14 -0
- data/spec/moneta/adapters/sdbm/adapter_sdbm_spec.rb +7 -0
- data/spec/moneta/adapters/sdbm/standard_sdbm_spec.rb +7 -0
- data/spec/moneta/adapters/sdbm/standard_sdbm_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/sequel/adapter_sequel_spec.rb +133 -0
- data/spec/moneta/adapters/sequel/helper.rb +80 -0
- data/spec/moneta/adapters/sequel/standard_sequel_spec.rb +8 -0
- data/spec/moneta/adapters/sequel/standard_sequel_with_expires_spec.rb +18 -0
- data/spec/moneta/adapters/sqlite/adapter_sqlite_spec.rb +7 -0
- data/spec/moneta/adapters/sqlite/standard_sqlite_spec.rb +7 -0
- data/spec/moneta/adapters/sqlite/standard_sqlite_with_expires_spec.rb +15 -0
- data/spec/moneta/adapters/tdb/adapter_tdb_spec.rb +7 -0
- data/spec/moneta/adapters/tdb/standard_tdb_spec.rb +7 -0
- data/spec/moneta/adapters/tdb/standard_tdb_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/tokyocabinet/adapter_tokyocabinet_bdb_spec.rb +7 -0
- data/spec/moneta/adapters/tokyocabinet/adapter_tokyocabinet_hdb_spec.rb +7 -0
- data/spec/moneta/adapters/tokyocabinet/standard_tokyocabinet_spec.rb +7 -0
- data/spec/moneta/adapters/tokyocabinet/standard_tokyocabinet_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/tokyotyrant/adapter_tokyotyrant_spec.rb +11 -0
- data/spec/moneta/adapters/tokyotyrant/helper.rb +12 -0
- data/spec/moneta/adapters/tokyotyrant/standard_tokyotyrant_spec.rb +7 -0
- data/spec/moneta/adapters/tokyotyrant/standard_tokyotyrant_with_expires_spec.rb +12 -0
- data/spec/moneta/adapters/yaml/adapter_yaml_spec.rb +7 -0
- data/spec/moneta/adapters/yaml/standard_yaml_spec.rb +9 -0
- data/spec/moneta/adapters/yaml/standard_yaml_with_expires_spec.rb +13 -0
- data/spec/moneta/builder_spec.rb +22 -1
- data/spec/moneta/config_spec.rb +219 -0
- data/spec/moneta/mutex_spec.rb +6 -23
- data/spec/moneta/proxies/cache/cache_file_memory_spec.rb +24 -0
- data/spec/moneta/proxies/cache/cache_memory_null_spec.rb +12 -0
- data/spec/moneta/proxies/enumerable/enumerable_spec.rb +26 -0
- data/spec/moneta/proxies/expires/expires_file_spec.rb +28 -0
- data/spec/moneta/proxies/expires/expires_memory_spec.rb +15 -0
- data/spec/moneta/proxies/expires/expires_memory_with_default_expires_spec.rb +16 -0
- data/spec/moneta/proxies/fallback/fallback_spec.rb +42 -0
- data/spec/moneta/proxies/lock/lock_spec.rb +10 -0
- data/spec/moneta/{optionmerger_spec.rb → proxies/optionmerger/optionmerger_spec.rb} +2 -18
- data/spec/moneta/proxies/pool/pool_spec.rb +353 -0
- data/spec/moneta/proxies/proxy/proxy_expires_memory_spec.rb +16 -0
- data/spec/moneta/proxies/shared/shared_tcp_spec.rb +59 -0
- data/spec/moneta/proxies/shared/shared_unix_spec.rb +58 -0
- data/spec/moneta/proxies/transformer/transformer_bencode_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_bert_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_bson_spec.rb +25 -0
- data/spec/moneta/proxies/transformer/transformer_bzip2_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_json_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_key_inspect_spec.rb +17 -0
- data/spec/moneta/proxies/transformer/transformer_key_marshal_spec.rb +17 -0
- data/spec/moneta/proxies/transformer/transformer_key_to_s_spec.rb +17 -0
- data/spec/moneta/proxies/transformer/transformer_key_yaml_spec.rb +17 -0
- data/spec/moneta/proxies/transformer/transformer_lz4_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_lzma_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_lzo_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_base64_spec.rb +20 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_city128_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_city32_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_city64_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_escape_spec.rb +21 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_hex_spec.rb +20 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_hmac_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_md5_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_md5_spread_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_prefix_base64_spec.rb +33 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_prefix_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_qp_spec.rb +20 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_rmd160_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_sha1_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_sha256_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_sha384_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_sha512_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_truncate_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_urlsafe_base64_spec.rb +20 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_uuencode_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_msgpack_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_ox_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_php_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_quicklz_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_snappy_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_tnet_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_value_marshal_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_value_yaml_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_yaml_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_zlib_spec.rb +19 -0
- data/spec/moneta/proxies/weak_create/weak_create_spec.rb +21 -0
- data/spec/moneta/proxies/weak_each_key/weak_each_key_spec.rb +22 -0
- data/spec/moneta/proxies/weak_increment/weak_increment_spec.rb +21 -0
- data/spec/moneta/semaphore_spec.rb +6 -23
- data/spec/moneta/stack_file_memory_spec.rb +5 -29
- data/spec/moneta/stack_memory_file_spec.rb +5 -31
- data/spec/rack/session_moneta_spec.rb +44 -25
- data/spec/restserver.rb +44 -0
- data/{spec → test}/action_dispatch/fixtures/session_autoload_test/foo.rb +0 -0
- data/{spec/action_dispatch/session_moneta_store_spec.rb → test/action_dispatch/session_moneta_store_test.rb} +13 -5
- metadata +545 -369
- data/.travis.yml +0 -55
- data/lib/moneta/adapters/mongo/base.rb +0 -78
- data/lib/moneta/adapters/mongo/moped.rb +0 -107
- data/lib/moneta/adapters/mongo/official.rb +0 -117
- data/lib/moneta/mixins.rb +0 -343
- data/script/generate-specs +0 -2696
- data/script/install-kyotocabinet +0 -17
- data/spec/moneta/adapter_activerecord_exisiting_connection_spec.rb +0 -36
- data/spec/moneta/adapter_activerecord_spec.rb +0 -65
- data/spec/moneta/adapter_cassandra_spec.rb +0 -33
- data/spec/moneta/adapter_cassandra_with_default_expires_spec.rb +0 -34
- data/spec/moneta/adapter_client_spec.rb +0 -35
- data/spec/moneta/adapter_cookie_spec.rb +0 -30
- data/spec/moneta/adapter_couch_spec.rb +0 -36
- data/spec/moneta/adapter_datamapper_spec.rb +0 -64
- data/spec/moneta/adapter_daybreak_spec.rb +0 -31
- data/spec/moneta/adapter_dbm_spec.rb +0 -31
- data/spec/moneta/adapter_file_spec.rb +0 -34
- data/spec/moneta/adapter_fog_spec.rb +0 -37
- data/spec/moneta/adapter_gdbm_spec.rb +0 -31
- data/spec/moneta/adapter_hbase_spec.rb +0 -33
- data/spec/moneta/adapter_kyotocabinet_spec.rb +0 -31
- data/spec/moneta/adapter_leveldb_spec.rb +0 -31
- data/spec/moneta/adapter_lmdb_spec.rb +0 -32
- data/spec/moneta/adapter_lmdb_with_db_spec.rb +0 -32
- data/spec/moneta/adapter_localmemcache_spec.rb +0 -32
- data/spec/moneta/adapter_memcached_dalli_spec.rb +0 -36
- data/spec/moneta/adapter_memcached_dalli_with_default_expires_spec.rb +0 -37
- data/spec/moneta/adapter_memcached_native_spec.rb +0 -36
- data/spec/moneta/adapter_memcached_native_with_default_expires_spec.rb +0 -37
- data/spec/moneta/adapter_memcached_spec.rb +0 -36
- data/spec/moneta/adapter_memcached_with_default_expires_spec.rb +0 -37
- data/spec/moneta/adapter_memory_spec.rb +0 -184
- data/spec/moneta/adapter_mongo_moped_spec.rb +0 -64
- data/spec/moneta/adapter_mongo_moped_with_default_expires_spec.rb +0 -53
- data/spec/moneta/adapter_mongo_official_spec.rb +0 -64
- data/spec/moneta/adapter_mongo_official_with_default_expires_spec.rb +0 -53
- data/spec/moneta/adapter_mongo_spec.rb +0 -51
- data/spec/moneta/adapter_mongo_with_default_expires_spec.rb +0 -53
- data/spec/moneta/adapter_pstore_spec.rb +0 -250
- data/spec/moneta/adapter_redis_spec.rb +0 -36
- data/spec/moneta/adapter_redis_with_default_expires_spec.rb +0 -37
- data/spec/moneta/adapter_restclient_spec.rb +0 -33
- data/spec/moneta/adapter_riak_spec.rb +0 -36
- data/spec/moneta/adapter_sdbm_spec.rb +0 -30
- data/spec/moneta/adapter_sequel_spec.rb +0 -34
- data/spec/moneta/adapter_sqlite_spec.rb +0 -32
- data/spec/moneta/adapter_tdb_spec.rb +0 -31
- data/spec/moneta/adapter_tokyocabinet_bdb_spec.rb +0 -31
- data/spec/moneta/adapter_tokyocabinet_hdb_spec.rb +0 -31
- data/spec/moneta/adapter_tokyotyrant_spec.rb +0 -34
- data/spec/moneta/adapter_yaml_spec.rb +0 -57
- data/spec/moneta/cache_file_memory_spec.rb +0 -50
- data/spec/moneta/cache_memory_null_spec.rb +0 -35
- data/spec/moneta/expires_file_spec.rb +0 -78
- data/spec/moneta/expires_memory_spec.rb +0 -189
- data/spec/moneta/expires_memory_with_default_expires_spec.rb +0 -190
- data/spec/moneta/lock_spec.rb +0 -187
- data/spec/moneta/null_adapter_spec.rb +0 -86
- data/spec/moneta/pool_spec.rb +0 -38
- data/spec/moneta/proxy_expires_memory_spec.rb +0 -191
- data/spec/moneta/proxy_redis_spec.rb +0 -40
- data/spec/moneta/shared_tcp_spec.rb +0 -46
- data/spec/moneta/shared_unix_spec.rb +0 -46
- data/spec/moneta/standard_activerecord_spec.rb +0 -253
- data/spec/moneta/standard_activerecord_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_cassandra_spec.rb +0 -252
- data/spec/moneta/standard_client_tcp_spec.rb +0 -269
- data/spec/moneta/standard_client_unix_spec.rb +0 -254
- data/spec/moneta/standard_couch_spec.rb +0 -252
- data/spec/moneta/standard_couch_with_expires_spec.rb +0 -254
- data/spec/moneta/standard_datamapper_spec.rb +0 -254
- data/spec/moneta/standard_datamapper_with_expires_spec.rb +0 -256
- data/spec/moneta/standard_datamapper_with_repository_spec.rb +0 -254
- data/spec/moneta/standard_daybreak_spec.rb +0 -250
- data/spec/moneta/standard_daybreak_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_dbm_spec.rb +0 -250
- data/spec/moneta/standard_dbm_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_file_spec.rb +0 -253
- data/spec/moneta/standard_file_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_fog_spec.rb +0 -256
- data/spec/moneta/standard_fog_with_expires_spec.rb +0 -258
- data/spec/moneta/standard_gdbm_spec.rb +0 -250
- data/spec/moneta/standard_gdbm_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_hashfile_spec.rb +0 -253
- data/spec/moneta/standard_hashfile_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_hbase_spec.rb +0 -252
- data/spec/moneta/standard_hbase_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_kyotocabinet_spec.rb +0 -250
- data/spec/moneta/standard_kyotocabinet_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_leveldb_spec.rb +0 -250
- data/spec/moneta/standard_leveldb_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_lmdb_spec.rb +0 -251
- data/spec/moneta/standard_lmdb_with_expires_spec.rb +0 -253
- data/spec/moneta/standard_localmemcache_spec.rb +0 -251
- data/spec/moneta/standard_localmemcache_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_lruhash_spec.rb +0 -187
- data/spec/moneta/standard_lruhash_with_expires_spec.rb +0 -189
- data/spec/moneta/standard_memcached_dalli_spec.rb +0 -255
- data/spec/moneta/standard_memcached_native_spec.rb +0 -255
- data/spec/moneta/standard_memcached_spec.rb +0 -255
- data/spec/moneta/standard_memory_spec.rb +0 -187
- data/spec/moneta/standard_memory_with_compress_spec.rb +0 -187
- data/spec/moneta/standard_memory_with_expires_spec.rb +0 -189
- data/spec/moneta/standard_memory_with_json_key_serializer_spec.rb +0 -86
- data/spec/moneta/standard_memory_with_json_serializer_spec.rb +0 -49
- data/spec/moneta/standard_memory_with_json_value_serializer_spec.rb +0 -90
- data/spec/moneta/standard_memory_with_prefix_spec.rb +0 -187
- data/spec/moneta/standard_memory_with_snappy_compress_spec.rb +0 -187
- data/spec/moneta/standard_mongo_moped_spec.rb +0 -255
- data/spec/moneta/standard_mongo_official_spec.rb +0 -255
- data/spec/moneta/standard_mongo_spec.rb +0 -255
- data/spec/moneta/standard_null_spec.rb +0 -120
- data/spec/moneta/standard_pstore_spec.rb +0 -253
- data/spec/moneta/standard_pstore_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_redis_spec.rb +0 -255
- data/spec/moneta/standard_restclient_spec.rb +0 -252
- data/spec/moneta/standard_riak_spec.rb +0 -255
- data/spec/moneta/standard_riak_with_expires_spec.rb +0 -256
- data/spec/moneta/standard_sdbm_spec.rb +0 -249
- data/spec/moneta/standard_sdbm_with_expires_spec.rb +0 -251
- data/spec/moneta/standard_sequel_spec.rb +0 -253
- data/spec/moneta/standard_sequel_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_sqlite_spec.rb +0 -251
- data/spec/moneta/standard_sqlite_with_expires_spec.rb +0 -253
- data/spec/moneta/standard_tdb_spec.rb +0 -250
- data/spec/moneta/standard_tdb_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_tokyocabinet_spec.rb +0 -250
- data/spec/moneta/standard_tokyocabinet_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_tokyotyrant_spec.rb +0 -253
- data/spec/moneta/standard_tokyotyrant_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_yaml_spec.rb +0 -250
- data/spec/moneta/standard_yaml_with_expires_spec.rb +0 -252
- data/spec/moneta/transformer_bencode_spec.rb +0 -55
- data/spec/moneta/transformer_bert_spec.rb +0 -55
- data/spec/moneta/transformer_bson_spec.rb +0 -60
- data/spec/moneta/transformer_bzip2_spec.rb +0 -55
- data/spec/moneta/transformer_json_spec.rb +0 -55
- data/spec/moneta/transformer_key_inspect_spec.rb +0 -91
- data/spec/moneta/transformer_key_marshal_spec.rb +0 -191
- data/spec/moneta/transformer_key_to_s_spec.rb +0 -91
- data/spec/moneta/transformer_key_yaml_spec.rb +0 -191
- data/spec/moneta/transformer_lz4_spec.rb +0 -55
- data/spec/moneta/transformer_lzma_spec.rb +0 -55
- data/spec/moneta/transformer_lzo_spec.rb +0 -55
- data/spec/moneta/transformer_marshal_base64_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_city128_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_city32_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_city64_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_escape_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_hex_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_hmac_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_md5_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_md5_spread_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_prefix_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_qp_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_rmd160_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_sha1_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_sha256_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_sha384_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_sha512_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_spec.rb +0 -191
- data/spec/moneta/transformer_marshal_truncate_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_uuencode_spec.rb +0 -194
- data/spec/moneta/transformer_msgpack_spec.rb +0 -55
- data/spec/moneta/transformer_ox_spec.rb +0 -191
- data/spec/moneta/transformer_php_spec.rb +0 -55
- data/spec/moneta/transformer_quicklz_spec.rb +0 -55
- data/spec/moneta/transformer_snappy_spec.rb +0 -55
- data/spec/moneta/transformer_tnet_spec.rb +0 -55
- data/spec/moneta/transformer_value_marshal_spec.rb +0 -191
- data/spec/moneta/transformer_value_yaml_spec.rb +0 -191
- data/spec/moneta/transformer_yaml_spec.rb +0 -191
- data/spec/moneta/transformer_zlib_spec.rb +0 -55
- data/spec/moneta/weak_create_spec.rb +0 -41
- data/spec/moneta/weak_increment_spec.rb +0 -41
- data/spec/monetaspecs.rb +0 -51267
- data/spec/quality_spec.rb +0 -51
@@ -2,19 +2,7 @@ require 'moneta'
|
|
2
2
|
require 'active_support'
|
3
3
|
require 'active_support/cache/moneta_store'
|
4
4
|
require 'ostruct'
|
5
|
-
|
6
|
-
module MonetaStoreHelpers
|
7
|
-
def with_notifications
|
8
|
-
described_class.instrument = true
|
9
|
-
yield
|
10
|
-
ensure
|
11
|
-
described_class.instrument = false
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
RSpec.configure do |config|
|
16
|
-
config.include(MonetaStoreHelpers)
|
17
|
-
end
|
5
|
+
require_relative '../moneta/adapters/memcached_helper.rb'
|
18
6
|
|
19
7
|
describe "cache_moneta_store" do
|
20
8
|
before(:all) do
|
@@ -30,75 +18,99 @@ describe "cache_moneta_store" do
|
|
30
18
|
|
31
19
|
# All stores should implement this basic behavior.
|
32
20
|
shared_examples :basic_store do
|
33
|
-
|
34
|
-
|
35
|
-
@white_rabbit = OpenStruct.new color: 'white'
|
21
|
+
let(:rabbit) { OpenStruct.new name: 'bunny' }
|
22
|
+
let(:white_rabbit) { OpenStruct.new color: 'white' }
|
36
23
|
|
24
|
+
before(:each) do
|
37
25
|
store.clear
|
38
|
-
store.write 'rabbit',
|
26
|
+
store.write 'rabbit', rabbit
|
27
|
+
@events.clear
|
39
28
|
end
|
40
29
|
|
41
30
|
it 'reads the data' do
|
42
|
-
store.read('rabbit').
|
31
|
+
expect(store.read('rabbit')).to eq rabbit
|
43
32
|
end
|
44
33
|
|
45
34
|
it 'writes the data' do
|
46
|
-
store.write 'rabbit',
|
47
|
-
store.read('rabbit').
|
35
|
+
store.write 'rabbit', white_rabbit
|
36
|
+
expect(store.read('rabbit')).to eq white_rabbit
|
48
37
|
end
|
49
38
|
|
50
39
|
it 'deletes data' do
|
51
40
|
store.delete 'rabbit'
|
52
|
-
store.read('rabbit').
|
41
|
+
expect(store.read('rabbit')).to be_nil
|
53
42
|
end
|
54
43
|
|
55
44
|
it 'verifies existence of an object in the store' do
|
56
|
-
store.exist?('rabbit').
|
57
|
-
(!!store.exist?('rab-a-dub')).
|
45
|
+
expect(store.exist?('rabbit')).to be true
|
46
|
+
expect(!!store.exist?('rab-a-dub')).to be false
|
58
47
|
end
|
59
48
|
|
60
49
|
it 'fetches data' do
|
61
|
-
store.fetch('rabbit').
|
62
|
-
store.fetch('rub-a-dub').
|
50
|
+
expect(store.fetch('rabbit')).to eq rabbit
|
51
|
+
expect(store.fetch('rub-a-dub')).to be_nil
|
63
52
|
store.fetch('rub-a-dub') { 'Flora de Cana' }
|
64
|
-
store.fetch('rub-a-dub').
|
53
|
+
expect(store.fetch('rub-a-dub')).to eq 'Flora de Cana'
|
65
54
|
end
|
66
55
|
|
67
56
|
it 'reads multiple keys' do
|
68
57
|
store.write 'irish whisky', 'Jameson'
|
69
58
|
result = store.read_multi 'rabbit', 'irish whisky'
|
70
|
-
result['rabbit'].
|
71
|
-
result['irish whisky'].
|
59
|
+
expect(result['rabbit']).to eq rabbit
|
60
|
+
expect(result['irish whisky']).to eq 'Jameson'
|
72
61
|
end
|
73
62
|
|
74
63
|
it 'reads multiple keys and returns only the matched ones' do
|
75
64
|
store.delete 'irish whisky'
|
76
65
|
result = store.read_multi 'rabbit', 'irish whisky'
|
77
|
-
result.
|
78
|
-
result.
|
66
|
+
expect(result).not_to include('irish whisky')
|
67
|
+
expect(result).to include('rabbit')
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'fetches multiple keys and fills in the missing ones' do
|
71
|
+
store.delete 'irish whisky'
|
72
|
+
result = store.fetch_multi('rabbit', 'irish whisky') do |k|
|
73
|
+
k + ' was missing'
|
74
|
+
end
|
75
|
+
expect(result['rabbit']).to eq rabbit
|
76
|
+
expect(result['irish whisky']).to eq 'irish whisky was missing'
|
77
|
+
expect(store.fetch('irish whisky')).to eq 'irish whisky was missing'
|
79
78
|
end
|
80
79
|
end
|
81
80
|
|
82
81
|
shared_examples :expiry do
|
83
82
|
it 'writes the data with expiration time' do
|
84
|
-
store.write 'rabbit',
|
85
|
-
store.read('rabbit').
|
86
|
-
sleep
|
87
|
-
store.read('rabbit').
|
83
|
+
store.write 'rabbit', white_rabbit, expires_in: 0.2.second
|
84
|
+
expect(store.read('rabbit')).to eq white_rabbit
|
85
|
+
sleep 0.3
|
86
|
+
expect(store.read('rabbit')).to be_nil
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'writes multiple values with expiration time' do
|
90
|
+
store.write_multi({
|
91
|
+
'rabbit' => white_rabbit,
|
92
|
+
'irish whisky' => 'Jameson'
|
93
|
+
}, expires_in: 0.2.second)
|
94
|
+
|
95
|
+
expect(store.read_multi('rabbit', 'irish whisky')).to eq \
|
96
|
+
'rabbit' => white_rabbit,
|
97
|
+
'irish whisky' => 'Jameson'
|
98
|
+
|
99
|
+
sleep 0.3
|
100
|
+
expect(store.read_multi('rabbit', 'irish whisky')).to be_empty
|
88
101
|
end
|
89
102
|
|
90
103
|
it "sets expiry on cache miss" do
|
91
|
-
store.fetch('rabbit', force: true)
|
92
|
-
store.fetch('rabbit'
|
93
|
-
|
94
|
-
|
95
|
-
store.fetch('rabbit').should be_nil
|
104
|
+
store.fetch('rabbit', force: true, expires_in: 0.2.second) { white_rabbit }
|
105
|
+
expect(store.fetch('rabbit')).to eq white_rabbit
|
106
|
+
sleep 0.3
|
107
|
+
expect(store.fetch('rabbit')).to be_nil
|
96
108
|
end
|
97
109
|
|
98
110
|
it 'does not set expiry on cache hit' do
|
99
|
-
store.fetch('rabbit', expires_in:
|
100
|
-
sleep
|
101
|
-
store.fetch('rabbit').
|
111
|
+
expect(store.fetch('rabbit', expires_in: 0.2.second) { white_rabbit }).to eq rabbit
|
112
|
+
sleep 0.3
|
113
|
+
expect(store.fetch('rabbit')).to eq rabbit
|
102
114
|
end
|
103
115
|
end
|
104
116
|
|
@@ -106,149 +118,160 @@ describe "cache_moneta_store" do
|
|
106
118
|
shared_examples :increment_decrement do
|
107
119
|
it 'increments a key' do
|
108
120
|
store.write 'counter', 0, raw: true
|
109
|
-
3.
|
110
|
-
|
121
|
+
(1..3).each do |i|
|
122
|
+
expect(store.increment('counter')).to eq i
|
123
|
+
end
|
124
|
+
expect(store.read('counter', raw: true).to_i).to eq 3
|
111
125
|
end
|
112
126
|
|
113
127
|
it 'decrements a key' do
|
114
128
|
store.write 'counter', 0, raw: true
|
115
129
|
3.times { store.increment 'counter' }
|
116
130
|
2.times { store.decrement 'counter' }
|
117
|
-
store.read('counter', raw: true).to_i.
|
131
|
+
expect(store.read('counter', raw: true).to_i).to eq 1
|
118
132
|
end
|
119
133
|
|
120
134
|
it 'increments a key by given value' do
|
121
135
|
store.write 'counter', 0, raw: true
|
122
136
|
store.increment 'counter', 3
|
123
|
-
store.read('counter', raw: true).to_i.
|
137
|
+
expect(store.read('counter', raw: true).to_i).to eq 3
|
124
138
|
end
|
125
139
|
|
126
140
|
it 'decrements a key by given value' do
|
127
141
|
store.write 'counter', 0, raw: true
|
128
142
|
3.times { store.increment 'counter' }
|
129
143
|
store.decrement 'counter', 2
|
130
|
-
store.read('counter', raw: true).to_i.
|
144
|
+
expect(store.read('counter', raw: true).to_i).to eq 1
|
131
145
|
end
|
132
146
|
end
|
133
147
|
|
134
148
|
shared_examples :basic_instrumentation do
|
135
149
|
it 'notifies on #fetch' do
|
136
|
-
|
137
|
-
store.fetch('radiohead') { 'House Of Cards' }
|
138
|
-
end
|
150
|
+
store.fetch('radiohead') { 'House Of Cards' }
|
139
151
|
|
140
152
|
read = @events.shift
|
141
|
-
read.name.
|
142
|
-
read.payload.
|
153
|
+
expect(read.name).to eq 'cache_read.active_support'
|
154
|
+
expect(read.payload).to include(key: 'radiohead', super_operation: :fetch, hit: false)
|
143
155
|
|
144
156
|
generate = @events.shift
|
145
|
-
generate.name.
|
146
|
-
generate.payload.
|
157
|
+
expect(generate.name).to eq 'cache_generate.active_support'
|
158
|
+
expect(generate.payload).to include(key: 'radiohead')
|
147
159
|
|
148
160
|
write = @events.shift
|
149
|
-
write.name.
|
150
|
-
write.payload.
|
161
|
+
expect(write.name).to eq 'cache_write.active_support'
|
162
|
+
expect(write.payload).to include(key: 'radiohead')
|
151
163
|
end
|
152
164
|
|
153
165
|
it 'notifies on #read' do
|
154
|
-
|
155
|
-
store.read 'metallica'
|
156
|
-
end
|
166
|
+
store.read 'metallica'
|
157
167
|
|
158
168
|
read = @events.shift
|
159
|
-
read.name.
|
160
|
-
read.payload.
|
169
|
+
expect(read.name).to eq 'cache_read.active_support'
|
170
|
+
expect(read.payload).to include(key: 'metallica', hit: false)
|
161
171
|
end
|
162
172
|
|
163
173
|
it 'notifies on #write' do
|
164
|
-
|
165
|
-
store.write 'depeche mode', 'Enjoy The Silence'
|
166
|
-
end
|
174
|
+
store.write 'depeche mode', 'Enjoy The Silence'
|
167
175
|
|
168
176
|
write = @events.shift
|
169
|
-
write.name.
|
170
|
-
write.payload.
|
177
|
+
expect(write.name).to eq 'cache_write.active_support'
|
178
|
+
expect(write.payload).to include(key: 'depeche mode')
|
171
179
|
end
|
172
180
|
|
173
181
|
it 'notifies on #delete' do
|
174
|
-
|
175
|
-
store.delete 'the new cardigans'
|
176
|
-
end
|
182
|
+
store.delete 'the new cardigans'
|
177
183
|
|
178
184
|
delete = @events.shift
|
179
|
-
delete.name.
|
180
|
-
delete.payload.
|
185
|
+
expect(delete.name).to eq 'cache_delete.active_support'
|
186
|
+
expect(delete.payload).to include(key: 'the new cardigans')
|
181
187
|
end
|
182
188
|
|
183
189
|
it 'notifies on #exist?' do
|
184
|
-
|
185
|
-
store.exist? 'the smiths'
|
186
|
-
end
|
190
|
+
store.exist? 'the smiths'
|
187
191
|
|
188
192
|
exist = @events.shift
|
189
|
-
exist.name.
|
190
|
-
exist.payload.
|
193
|
+
expect(exist.name).to eq 'cache_exist?.active_support'
|
194
|
+
expect(exist.payload).to include(key: 'the smiths')
|
191
195
|
end
|
192
|
-
|
193
196
|
end
|
194
197
|
|
195
198
|
# This doesn't seem to be documented at all, so we follow the
|
196
199
|
# behavior of MemCacheStore.
|
197
200
|
shared_examples :increment_decrement_instrumentation do
|
198
201
|
it 'notifies on #increment' do
|
199
|
-
|
200
|
-
store.increment 'pearl jam'
|
201
|
-
end
|
202
|
+
store.increment 'pearl jam'
|
202
203
|
|
203
204
|
increment = @events.shift
|
204
|
-
increment.name.
|
205
|
-
increment.payload.
|
205
|
+
expect(increment.name).to eq 'cache_increment.active_support'
|
206
|
+
expect(increment.payload).to eq(key: 'pearl jam', amount: 1)
|
206
207
|
end
|
207
208
|
|
208
209
|
it 'notifies on #decrement' do
|
209
|
-
|
210
|
-
store.decrement 'placebo'
|
211
|
-
end
|
212
|
-
|
210
|
+
store.decrement 'placebo'
|
213
211
|
decrement = @events.shift
|
214
|
-
decrement.name.
|
215
|
-
decrement.payload.
|
212
|
+
expect(decrement.name).to eq 'cache_decrement.active_support'
|
213
|
+
expect(decrement.payload).to eq(key: 'placebo', amount: 1)
|
216
214
|
end
|
217
215
|
end
|
218
216
|
|
219
217
|
describe ActiveSupport::Cache::MonetaStore do
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
it 'notifies on #clear' do
|
231
|
-
with_notifications do
|
218
|
+
shared_examples :moneta_store do
|
219
|
+
include_examples :basic_store
|
220
|
+
include_examples :expiry
|
221
|
+
include_examples :increment_decrement
|
222
|
+
include_examples :basic_instrumentation
|
223
|
+
include_examples :increment_decrement_instrumentation
|
224
|
+
|
225
|
+
# FIXME: no other store does this -- perhaps this should be
|
226
|
+
# removed.
|
227
|
+
it 'notifies on #clear' do
|
232
228
|
store.clear
|
229
|
+
|
230
|
+
clear = @events.shift
|
231
|
+
expect(clear.name).to eq 'cache_clear.active_support'
|
232
|
+
expect(clear.payload).to eq(key: nil)
|
233
233
|
end
|
234
|
+
end
|
235
|
+
|
236
|
+
context "with :Memory store" do
|
237
|
+
let(:store) { described_class.new(store: :Memory) }
|
238
|
+
include_examples :moneta_store
|
239
|
+
end
|
240
|
+
|
241
|
+
context "with existing :Memory store" do
|
242
|
+
let(:store) { described_class.new(store: ::Moneta.new(:Memory)) }
|
243
|
+
include_examples :moneta_store
|
244
|
+
end
|
234
245
|
|
235
|
-
|
236
|
-
|
237
|
-
|
246
|
+
context "with Redis store", adapter: :Redis do
|
247
|
+
let(:store) { described_class.new(store: :Redis) }
|
248
|
+
include_examples :moneta_store
|
238
249
|
end
|
239
250
|
end
|
240
251
|
|
241
252
|
describe ActiveSupport::Cache::MemoryStore do
|
242
|
-
let(:store){ described_class.new }
|
253
|
+
let(:store) { described_class.new }
|
254
|
+
|
255
|
+
include_examples :basic_store
|
256
|
+
include_examples :expiry
|
257
|
+
include_examples :increment_decrement
|
258
|
+
include_examples :basic_instrumentation
|
259
|
+
end
|
260
|
+
|
261
|
+
describe ActiveSupport::Cache::MemCacheStore, memcached: true do
|
262
|
+
let(:store) { described_class.new('127.0.0.1:11213') }
|
263
|
+
|
264
|
+
include_context :start_memcached, 11213
|
243
265
|
|
244
266
|
include_examples :basic_store
|
245
267
|
include_examples :expiry
|
246
268
|
include_examples :increment_decrement
|
247
269
|
include_examples :basic_instrumentation
|
270
|
+
include_examples :increment_decrement_instrumentation
|
248
271
|
end
|
249
272
|
|
250
|
-
describe ActiveSupport::Cache::
|
251
|
-
let(:store){ described_class.new }
|
273
|
+
describe ActiveSupport::Cache::RedisCacheStore, redis: true do
|
274
|
+
let(:store) { described_class.new(url: "redis:///3") }
|
252
275
|
|
253
276
|
include_examples :basic_store
|
254
277
|
include_examples :expiry
|
@@ -0,0 +1,42 @@
|
|
1
|
+
shared_examples :concurrent_create do
|
2
|
+
# Each thread attempts to create
|
3
|
+
def create_thread(name)
|
4
|
+
Thread.new do
|
5
|
+
s = new_store
|
6
|
+
begin
|
7
|
+
(0...1000).map do |i|
|
8
|
+
s.create(i.to_s, name, expires: false).tap do
|
9
|
+
Thread.pass if rand(100) >= 99
|
10
|
+
end
|
11
|
+
end
|
12
|
+
ensure
|
13
|
+
s.close
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'have atomic create across multiple threads', isolate: true do
|
19
|
+
names = %w{a b c}
|
20
|
+
|
21
|
+
# Spawn threads and then group results (lists of true/false values) by
|
22
|
+
# store index (0...1000)
|
23
|
+
results = names
|
24
|
+
.map { |name| create_thread(name) }
|
25
|
+
.map(&:value)
|
26
|
+
.transpose.each_with_index
|
27
|
+
.map { |created_values, i| [i.to_s, created_values] }
|
28
|
+
.to_h
|
29
|
+
|
30
|
+
# Just a quick sanity check
|
31
|
+
expect(results.length).to eq 1000
|
32
|
+
|
33
|
+
# Ensure that for each index, one and only one created value is true
|
34
|
+
expect(results.map { |_, created_values| created_values.inject(:^) }).to all(be true)
|
35
|
+
|
36
|
+
# Check that the when a call to create returned true, that the store
|
37
|
+
# contains the correct value as a result
|
38
|
+
expect(store.slice(*results.keys).to_h).to eq(results.map do |i, values|
|
39
|
+
[i, names[values.index(true)]]
|
40
|
+
end.to_h)
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
shared_examples :concurrent_increment do
|
2
|
+
def increment_thread(name)
|
3
|
+
Thread.new do
|
4
|
+
s = new_store
|
5
|
+
begin
|
6
|
+
# Create an array where each entry is a list of all the return values
|
7
|
+
# from calling increment for a particular key.
|
8
|
+
increments = (0...100).map { [] }
|
9
|
+
100.times do
|
10
|
+
100.times do |j|
|
11
|
+
increments[j] << s.increment(j.to_s, 1, expires: false)
|
12
|
+
Thread.pass if rand(1000) >= 995
|
13
|
+
end
|
14
|
+
end
|
15
|
+
increments
|
16
|
+
ensure
|
17
|
+
s.close
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'have atomic increment across multiple threads', isolate: true do
|
23
|
+
results = %w{a b c}
|
24
|
+
.map { |name| increment_thread(name) }
|
25
|
+
.map(&:value)
|
26
|
+
.transpose # Now the array is indexed by store key instead of thread
|
27
|
+
|
28
|
+
# Sanity check
|
29
|
+
expect(results.length).to eq 100
|
30
|
+
|
31
|
+
results.each do |ith_values|
|
32
|
+
# ensure that for each pair in the triple there are no overlapping values
|
33
|
+
expect(ith_values.combination(2).map { |a, b| a & b }).to all be_empty
|
34
|
+
|
35
|
+
# ensure that when joined together they cover the full 1..300 range
|
36
|
+
expect(ith_values.inject(:+)).to contain_exactly(*1..300)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
shared_examples :create do
|
2
|
+
it 'creates the given key' do
|
3
|
+
store.create('key','value').should be true
|
4
|
+
store['key'].should == 'value'
|
5
|
+
end
|
6
|
+
|
7
|
+
it 'creates raw value with the given key' do
|
8
|
+
store.raw.create('key','value').should be true
|
9
|
+
store.raw['key'].should == 'value'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'does not create a key if it exists' do
|
13
|
+
store['key'] = 'value'
|
14
|
+
store.create('key','another value').should be false
|
15
|
+
store['key'].should == 'value'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'supports Mutex' do
|
19
|
+
a = Moneta::Mutex.new(store, 'mutex')
|
20
|
+
b = Moneta::Mutex.new(store, 'mutex')
|
21
|
+
a.lock.should be true
|
22
|
+
b.try_lock.should be false
|
23
|
+
a.unlock.should be_nil
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
shared_examples :create_expires do
|
2
|
+
it 'creates the given key and expires it' do
|
3
|
+
store.create('key','value', expires: min_ttl).should be true
|
4
|
+
store['key'].should == 'value'
|
5
|
+
advance min_ttl
|
6
|
+
2.times { advance_next_tick }
|
7
|
+
store.key?('key').should be false
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'does not change expires if the key exists' do
|
11
|
+
store.store('key', 'value', expires: false).should == 'value'
|
12
|
+
store.create('key','another value', expires: min_ttl).should be false
|
13
|
+
store['key'].should == 'value'
|
14
|
+
advance min_ttl
|
15
|
+
2.times { advance_next_tick }
|
16
|
+
store['key'].should == 'value'
|
17
|
+
store.key?('key').should be true
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
shared_examples :default_expires do
|
2
|
+
it 'sets the default expiration time', default_expires: true do
|
3
|
+
store['key1'] = 'val1'
|
4
|
+
advance(t_res / 4.0) # sleep less than a single time-space
|
5
|
+
store.key?('key1').should be true
|
6
|
+
store.fetch('key1').should == 'val1'
|
7
|
+
store.load('key1').should == 'val1'
|
8
|
+
advance min_ttl
|
9
|
+
2.times { advance_next_tick }
|
10
|
+
store.key?('key1').should be false
|
11
|
+
store.fetch('key1').should be_nil
|
12
|
+
store.load('key1').should be_nil
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
shared_examples :each_key do
|
2
|
+
shared_examples "enumerable" do
|
3
|
+
it 'returns an empty enum when there are no keys' do
|
4
|
+
expect(each_key.call.count).to eq(0)
|
5
|
+
end
|
6
|
+
|
7
|
+
it 'returns collection with the stored key/s' do
|
8
|
+
expect { store.store('1st_key', 'value') }
|
9
|
+
.to change { each_key.call.to_a }
|
10
|
+
.from([])
|
11
|
+
.to(['1st_key'])
|
12
|
+
|
13
|
+
expect { store.store('2nd_key', 'value') }
|
14
|
+
.to change { each_key.call.to_a.sort }
|
15
|
+
.from(['1st_key'])
|
16
|
+
.to(['1st_key', '2nd_key'].sort)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'when a lazy size implementation exist it returns the size of the collection or nil' do
|
20
|
+
expect(store.each_key.size).to eq(nil) | eq(0)
|
21
|
+
|
22
|
+
if !store.each_key.size.nil? && store.each_key.size.zero?
|
23
|
+
expect { store.store('1st_key', 'value') }
|
24
|
+
.to change { store.each_key.size }
|
25
|
+
.from(0)
|
26
|
+
.to(1)
|
27
|
+
|
28
|
+
expect { store.store('2nd_key', 'value') }
|
29
|
+
.to change { store.each_key.size }
|
30
|
+
.from(1)
|
31
|
+
.to(2)
|
32
|
+
|
33
|
+
expect { store.delete('1st_key') }
|
34
|
+
.to change { store.each_key.size }
|
35
|
+
.from(2)
|
36
|
+
.to(1)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'doesn\'t duplicate keys' do
|
41
|
+
expect { 2.times { |i| store.store('a_key', "#{i}_val") } }
|
42
|
+
.to change { each_key.call.to_a }
|
43
|
+
.from([])
|
44
|
+
.to(['a_key'])
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'doesn\'t return deleted keys' do
|
48
|
+
store.store('a_key', "a_val")
|
49
|
+
store.store('b_key', "b_val")
|
50
|
+
expect { store.delete('a_key') }
|
51
|
+
.to change { each_key.call.to_a.sort }
|
52
|
+
.from(['a_key', 'b_key'].sort)
|
53
|
+
.to(['b_key'])
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'allows checking and retrieving entries while enumerating' do
|
57
|
+
store['a'] = 'b'
|
58
|
+
store['c'] = 'd'
|
59
|
+
each_key.call do |k|
|
60
|
+
val = if k == 'a' then 'b' else 'd' end
|
61
|
+
expect(store.key?(k)).to be true
|
62
|
+
expect(store[k]).to eq val
|
63
|
+
expect(store.fetch(k)).to eq val
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when a block is not given" do
|
69
|
+
let(:each_key) do
|
70
|
+
store.method(:each_key)
|
71
|
+
end
|
72
|
+
|
73
|
+
include_examples 'enumerable'
|
74
|
+
|
75
|
+
it "returns the store if a block is given to #each" do
|
76
|
+
expect(store.each_key.each.each.each{}).to eq store
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when a block is given" do
|
81
|
+
let :each_key do
|
82
|
+
proc do |&block|
|
83
|
+
if block
|
84
|
+
store.each_key(&block)
|
85
|
+
else
|
86
|
+
Enumerator.new do |y|
|
87
|
+
store.each_key(&y.method(:<<))
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
include_examples 'enumerable'
|
94
|
+
|
95
|
+
it 'yields the keys to the block' do
|
96
|
+
# Make a list of keys that we expect to find in the store
|
97
|
+
keys = []
|
98
|
+
|
99
|
+
2.times do |i|
|
100
|
+
key = "key_#{i}"
|
101
|
+
keys << key
|
102
|
+
store.store(key, "#{i}_val")
|
103
|
+
end
|
104
|
+
|
105
|
+
# Enumerate the store, making store that at each iteration we find one of
|
106
|
+
# the keys we are looking for
|
107
|
+
expect(store.each_key do |k|
|
108
|
+
expect(keys.delete(k)).not_to be_nil
|
109
|
+
end).to eq(store)
|
110
|
+
|
111
|
+
# To assert that all keys were seen by the block
|
112
|
+
expect(keys).to be_empty
|
113
|
+
end
|
114
|
+
|
115
|
+
it "returns the store" do
|
116
|
+
expect(store.each_key{}).to eq store
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|