moneta 1.4.1 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +425 -0
- data/CHANGES +17 -0
- data/CONTRIBUTORS +2 -0
- data/Gemfile +161 -60
- data/README.md +21 -17
- data/lib/moneta/adapter.rb +52 -0
- data/lib/moneta/adapters/activerecord.rb +77 -68
- data/lib/moneta/adapters/activesupportcache.rb +22 -31
- data/lib/moneta/adapters/cassandra.rb +114 -116
- data/lib/moneta/adapters/client.rb +17 -18
- data/lib/moneta/adapters/couch.rb +31 -26
- data/lib/moneta/adapters/datamapper.rb +9 -5
- data/lib/moneta/adapters/daybreak.rb +15 -21
- data/lib/moneta/adapters/dbm.rb +6 -12
- data/lib/moneta/adapters/file.rb +21 -13
- data/lib/moneta/adapters/fog.rb +5 -6
- data/lib/moneta/adapters/gdbm.rb +6 -12
- data/lib/moneta/adapters/hbase.rb +10 -12
- data/lib/moneta/adapters/kyotocabinet.rb +22 -27
- data/lib/moneta/adapters/leveldb.rb +14 -20
- data/lib/moneta/adapters/lmdb.rb +19 -22
- data/lib/moneta/adapters/localmemcache.rb +7 -13
- data/lib/moneta/adapters/lruhash.rb +20 -20
- data/lib/moneta/adapters/memcached/dalli.rb +25 -33
- data/lib/moneta/adapters/memcached/native.rb +14 -20
- data/lib/moneta/adapters/memory.rb +5 -7
- data/lib/moneta/adapters/mongo.rb +53 -52
- data/lib/moneta/adapters/pstore.rb +21 -27
- data/lib/moneta/adapters/redis.rb +42 -37
- data/lib/moneta/adapters/restclient.rb +17 -25
- data/lib/moneta/adapters/riak.rb +8 -9
- data/lib/moneta/adapters/sdbm.rb +6 -12
- data/lib/moneta/adapters/sequel/mysql.rb +8 -8
- data/lib/moneta/adapters/sequel/postgres.rb +17 -17
- data/lib/moneta/adapters/sequel/postgres_hstore.rb +47 -47
- data/lib/moneta/adapters/sequel/sqlite.rb +9 -9
- data/lib/moneta/adapters/sequel.rb +56 -65
- data/lib/moneta/adapters/sqlite.rb +37 -35
- data/lib/moneta/adapters/tdb.rb +8 -14
- data/lib/moneta/adapters/tokyocabinet.rb +19 -17
- data/lib/moneta/adapters/tokyotyrant.rb +29 -30
- data/lib/moneta/adapters/yaml.rb +1 -5
- data/lib/moneta/config.rb +101 -0
- data/lib/moneta/expires.rb +0 -1
- data/lib/moneta/expires_support.rb +3 -4
- data/lib/moneta/pool.rb +27 -7
- data/lib/moneta/proxy.rb +29 -0
- data/lib/moneta/server.rb +21 -14
- data/lib/moneta/version.rb +1 -1
- data/lib/moneta/wrapper.rb +5 -0
- data/lib/moneta.rb +2 -0
- data/moneta.gemspec +1 -0
- data/spec/active_support/cache_moneta_store_spec.rb +13 -13
- data/spec/features/null.rb +28 -28
- data/spec/features/persist.rb +3 -3
- data/spec/features/returndifferent.rb +4 -4
- data/spec/features/returnsame.rb +4 -4
- data/spec/features/store.rb +104 -104
- data/spec/helper.rb +15 -4
- data/spec/moneta/adapters/activerecord/adapter_activerecord_existing_connection_spec.rb +3 -1
- data/spec/moneta/adapters/activerecord/adapter_activerecord_spec.rb +15 -7
- data/spec/moneta/adapters/activerecord/standard_activerecord_spec.rb +5 -2
- data/spec/moneta/adapters/activerecord/standard_activerecord_with_expires_spec.rb +5 -2
- data/spec/moneta/adapters/activesupportcache/adapter_activesupportcache_spec.rb +3 -3
- data/spec/moneta/adapters/activesupportcache/adapter_activesupportcache_with_default_expires_spec.rb +2 -2
- data/spec/moneta/adapters/cassandra/adapter_cassandra_spec.rb +1 -1
- data/spec/moneta/adapters/cassandra/adapter_cassandra_with_default_expires_spec.rb +1 -1
- data/spec/moneta/adapters/cassandra/standard_cassandra_spec.rb +1 -1
- data/spec/moneta/adapters/client/client_helper.rb +4 -3
- data/spec/moneta/adapters/datamapper/adapter_datamapper_spec.rb +25 -8
- data/spec/moneta/adapters/datamapper/standard_datamapper_spec.rb +2 -2
- data/spec/moneta/adapters/datamapper/standard_datamapper_with_expires_spec.rb +2 -2
- data/spec/moneta/adapters/datamapper/standard_datamapper_with_repository_spec.rb +2 -2
- data/spec/moneta/adapters/faraday_helper.rb +3 -2
- data/spec/moneta/adapters/lruhash/adapter_lruhash_spec.rb +10 -6
- data/spec/moneta/adapters/memcached/dalli/adapter_memcached_dalli_spec.rb +13 -3
- data/spec/moneta/adapters/memcached/native/adapter_memcached_native_spec.rb +13 -3
- data/spec/moneta/adapters/mongo/adapter_mongo_spec.rb +2 -2
- data/spec/moneta/adapters/mongo/adapter_mongo_with_default_expires_spec.rb +1 -1
- data/spec/moneta/adapters/redis/adapter_redis_spec.rb +13 -3
- data/spec/moneta/adapters/redis/standard_redis_spec.rb +8 -1
- data/spec/moneta/adapters/sequel/adapter_sequel_spec.rb +4 -4
- data/spec/moneta/adapters/sequel/helper.rb +10 -5
- data/spec/moneta/adapters/sequel/standard_sequel_spec.rb +1 -1
- data/spec/moneta/adapters/sequel/standard_sequel_with_expires_spec.rb +1 -1
- data/spec/moneta/adapters/sqlite/adapter_sqlite_spec.rb +1 -1
- data/spec/moneta/adapters/sqlite/standard_sqlite_spec.rb +1 -1
- data/spec/moneta/adapters/sqlite/standard_sqlite_with_expires_spec.rb +1 -1
- data/spec/moneta/config_spec.rb +219 -0
- data/spec/moneta/proxies/enumerable/enumerable_spec.rb +2 -2
- data/spec/moneta/proxies/pool/pool_spec.rb +31 -3
- data/spec/moneta/proxies/transformer/transformer_bson_spec.rb +3 -1
- data/spec/moneta/proxies/transformer/transformer_marshal_escape_spec.rb +2 -0
- data/spec/rack/session_moneta_spec.rb +44 -25
- data/spec/restserver.rb +3 -14
- metadata +25 -15
- data/.travis.yml +0 -146
- data/spec/moneta/adapters/memcached/dalli/adapter_memcached_dalli_with_default_expires_spec.rb +0 -15
- data/spec/moneta/adapters/memcached/native/adapter_memcached_native_with_default_expires_spec.rb +0 -15
- data/spec/moneta/adapters/redis/adapter_redis_with_default_expires_spec.rb +0 -10
- data/spec/moneta/proxies/proxy/proxy_redis_spec.rb +0 -13
@@ -1,4 +1,4 @@
|
|
1
|
-
describe "standard_datamapper_with_expires",
|
1
|
+
describe "standard_datamapper_with_expires", unsupported: defined?(JRUBY_VERSION) || RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0'), adapter: :DataMapper, mysql: true do
|
2
2
|
let(:t_res) { 0.125 }
|
3
3
|
let(:min_ttl) { t_res }
|
4
4
|
use_timecop
|
@@ -12,7 +12,7 @@ describe "standard_datamapper_with_expires", broken: defined?(JRUBY_VERSION), ad
|
|
12
12
|
|
13
13
|
moneta_store :DataMapper do
|
14
14
|
{
|
15
|
-
setup: "mysql://#{mysql_username}:#{mysql_password}
|
15
|
+
setup: "mysql://#{mysql_username}:#{mysql_password}@#{mysql_host}:#{mysql_port}/#{mysql_database1}",
|
16
16
|
table: "simple_datamapper_with_expires",
|
17
17
|
expires: true
|
18
18
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe 'standard_datamapper_with_repository',
|
1
|
+
describe 'standard_datamapper_with_repository', unsupported: defined?(JRUBY_VERSION) || RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0'), adapter: :DataMapper, mysql: true do
|
2
2
|
before :all do
|
3
3
|
require 'dm-core'
|
4
4
|
|
@@ -9,7 +9,7 @@ describe 'standard_datamapper_with_repository', broken: defined?(JRUBY_VERSION),
|
|
9
9
|
moneta_store :DataMapper do
|
10
10
|
{
|
11
11
|
repository: :repo,
|
12
|
-
setup: "mysql://#{mysql_username}:#{mysql_password}
|
12
|
+
setup: "mysql://#{mysql_username}:#{mysql_password}@#{mysql_host}:#{mysql_port}/#{mysql_database1}",
|
13
13
|
table: "simple_datamapper_with_repository"
|
14
14
|
}
|
15
15
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
RSpec.shared_context :faraday_adapter do
|
2
2
|
before :context do
|
3
|
-
require 'faraday/adapter/manticore' if defined?(JRUBY_VERSION)
|
3
|
+
#require 'faraday/adapter/manticore' if defined?(JRUBY_VERSION)
|
4
4
|
end
|
5
5
|
|
6
6
|
let(:faraday_adapter) do
|
7
|
-
defined?(JRUBY_VERSION) ? :manticore : :net_http
|
7
|
+
#defined?(JRUBY_VERSION) ? :manticore : :net_http
|
8
|
+
:net_http
|
8
9
|
end
|
9
10
|
end
|
@@ -52,8 +52,10 @@ describe 'adapter_lruhash', adapter: :LRUHash do
|
|
52
52
|
|
53
53
|
it 'adds a value that is as large as the default max_size when max_size is missing' do
|
54
54
|
store = Moneta::Adapters::LRUHash.new
|
55
|
+
expect(store.config.max_size).to eq Moneta::Adapters::LRUHash.config_defaults[:max_size]
|
56
|
+
|
55
57
|
large_item = 'Really big'
|
56
|
-
allow(large_item).to receive(:bytesize).and_return(Moneta::Adapters::LRUHash
|
58
|
+
allow(large_item).to receive(:bytesize).and_return(Moneta::Adapters::LRUHash.config_defaults[:max_size])
|
57
59
|
store[:really_big] = large_item
|
58
60
|
store[:really_big].should eq(large_item)
|
59
61
|
end
|
@@ -61,7 +63,7 @@ describe 'adapter_lruhash', adapter: :LRUHash do
|
|
61
63
|
it 'does not add values that are larger than the default max_size when max_size is missing' do
|
62
64
|
store = Moneta::Adapters::LRUHash.new
|
63
65
|
large_item = 'Really big'
|
64
|
-
allow(large_item).to receive(:bytesize).and_return(Moneta::Adapters::LRUHash
|
66
|
+
allow(large_item).to receive(:bytesize).and_return(Moneta::Adapters::LRUHash.config_defaults[:max_size] + 1)
|
65
67
|
store[:really_big] = large_item
|
66
68
|
store[:really_big].should be_nil
|
67
69
|
end
|
@@ -69,7 +71,7 @@ describe 'adapter_lruhash', adapter: :LRUHash do
|
|
69
71
|
it 'adds values that are larger than the default max_size when max_size is nil' do
|
70
72
|
store = Moneta::Adapters::LRUHash.new(max_size: nil)
|
71
73
|
large_item = 'Really big'
|
72
|
-
allow(large_item).to receive(:bytesize).and_return(Moneta::Adapters::LRUHash
|
74
|
+
allow(large_item).to receive(:bytesize).and_return(Moneta::Adapters::LRUHash.config_defaults[:max_size] + 1)
|
73
75
|
store[:really_big] = large_item
|
74
76
|
store[:really_big].should eq(large_item)
|
75
77
|
end
|
@@ -94,7 +96,8 @@ describe 'adapter_lruhash', adapter: :LRUHash do
|
|
94
96
|
end
|
95
97
|
|
96
98
|
it 'only allows the default number of items when max_count is missing' do
|
97
|
-
|
99
|
+
defaults = Moneta::Adapters::LRUHash.config_defaults
|
100
|
+
allow(Moneta::Adapters::LRUHash).to receive(:config_defaults).and_return(defaults.merge(max_count: 5))
|
98
101
|
store = Moneta::Adapters::LRUHash.new(max_value: nil, max_size: nil)
|
99
102
|
(1..6).each { |n| store[n] = n }
|
100
103
|
store.key?(1).should be false
|
@@ -103,8 +106,9 @@ describe 'adapter_lruhash', adapter: :LRUHash do
|
|
103
106
|
store[6].should eq(6)
|
104
107
|
end
|
105
108
|
|
106
|
-
it 'adds more values than
|
107
|
-
|
109
|
+
it 'adds more values than the default max_count allows when max_count is nil' do
|
110
|
+
defaults = Moneta::Adapters::LRUHash.config_defaults
|
111
|
+
allow(Moneta::Adapters::LRUHash).to receive(:config_defaults).and_return(defaults.merge(max_count: 5))
|
108
112
|
store = Moneta::Adapters::LRUHash.new(max_count: nil, max_value: nil, max_size: nil)
|
109
113
|
(1..6).each { |n| store[n] = n }
|
110
114
|
store[1].should eq(1)
|
@@ -7,9 +7,19 @@ describe 'adapter_memcached_dalli', retry: 3, adapter: :Memcached do
|
|
7
7
|
|
8
8
|
include_context :start_memcached, 11212
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
describe 'without default expires' do
|
11
|
+
moneta_build do
|
12
|
+
Moneta::Adapters::MemcachedDalli.new(server: "127.0.0.1:11212")
|
13
|
+
end
|
14
|
+
|
15
|
+
moneta_specs ADAPTER_SPECS.with_native_expires
|
12
16
|
end
|
13
17
|
|
14
|
-
|
18
|
+
describe 'with default expires' do
|
19
|
+
moneta_build do
|
20
|
+
Moneta::Adapters::MemcachedDalli.new(server: '127.0.0.1:11212', expires: min_ttl)
|
21
|
+
end
|
22
|
+
|
23
|
+
moneta_specs NATIVE_EXPIRY_SPECS.with_default_expires
|
24
|
+
end
|
15
25
|
end
|
@@ -7,9 +7,19 @@ describe 'adapter_memcached_native', isolate: true, unstable: defined?(JRUBY_VER
|
|
7
7
|
|
8
8
|
include_context :start_memcached, 11214
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
describe 'without default expires' do
|
11
|
+
moneta_build do
|
12
|
+
Moneta::Adapters::MemcachedNative.new(server: "127.0.0.1:11214")
|
13
|
+
end
|
14
|
+
|
15
|
+
moneta_specs ADAPTER_SPECS.with_native_expires
|
12
16
|
end
|
13
17
|
|
14
|
-
|
18
|
+
describe 'with default expires' do
|
19
|
+
moneta_build do
|
20
|
+
Moneta::Adapters::MemcachedNative.new(server: '127.0.0.1:11214', expires: min_ttl)
|
21
|
+
end
|
22
|
+
|
23
|
+
moneta_specs NATIVE_EXPIRY_SPECS.with_default_expires
|
24
|
+
end
|
15
25
|
end
|
@@ -28,7 +28,7 @@ describe 'adapter_mongo', adapter: :Mongo do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'uses the database specified via the :database option' do
|
31
|
-
expect(store.
|
31
|
+
expect(store.config.database).to eq database
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'uses the database specified via the :db option' do
|
@@ -36,6 +36,6 @@ describe 'adapter_mongo', adapter: :Mongo do
|
|
36
36
|
db: database,
|
37
37
|
collection: 'adapter_mongo'
|
38
38
|
)
|
39
|
-
expect(store.
|
39
|
+
expect(store.config.database).to eq database
|
40
40
|
end
|
41
41
|
end
|
@@ -2,9 +2,19 @@ describe 'adapter_redis', adapter: :Redis do
|
|
2
2
|
let(:t_res) { 0.125 }
|
3
3
|
let(:min_ttl) { t_res }
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
describe 'without default expiry' do
|
6
|
+
moneta_build do
|
7
|
+
Moneta::Adapters::Redis.new(host: redis_host, port: redis_port, db: 6)
|
8
|
+
end
|
9
|
+
|
10
|
+
moneta_specs ADAPTER_SPECS.with_each_key.with_native_expires
|
7
11
|
end
|
8
12
|
|
9
|
-
|
13
|
+
describe 'with default expiry' do
|
14
|
+
moneta_build do
|
15
|
+
Moneta::Adapters::Redis.new(host: redis_host, port: redis_port, db: 6, expires: min_ttl)
|
16
|
+
end
|
17
|
+
|
18
|
+
moneta_specs NATIVE_EXPIRY_SPECS.with_default_expires
|
19
|
+
end
|
10
20
|
end
|
@@ -2,6 +2,13 @@ describe 'standard_redis', adapter: :Redis do
|
|
2
2
|
let(:t_res) { 0.125 }
|
3
3
|
let(:min_ttl) { t_res }
|
4
4
|
|
5
|
-
moneta_store :Redis
|
5
|
+
moneta_store :Redis do
|
6
|
+
{
|
7
|
+
db: 4,
|
8
|
+
host: redis_host,
|
9
|
+
port: redis_port
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
6
13
|
moneta_specs STANDARD_SPECS.with_native_expires.with_each_key
|
7
14
|
end
|
@@ -5,7 +5,7 @@ describe ':Sequel adapter', adapter: :Sequel do
|
|
5
5
|
|
6
6
|
specs = ADAPTER_SPECS.with_each_key.with_values(:nil)
|
7
7
|
|
8
|
-
context 'with MySQL backend' do
|
8
|
+
context 'with MySQL backend', mysql: true do
|
9
9
|
moneta_build do
|
10
10
|
Moneta::Adapters::Sequel.new(opts.merge(db: mysql_uri))
|
11
11
|
end
|
@@ -13,7 +13,7 @@ describe ':Sequel adapter', adapter: :Sequel do
|
|
13
13
|
include_examples :adapter_sequel, specs
|
14
14
|
end
|
15
15
|
|
16
|
-
context "with SQLite backend" do
|
16
|
+
context "with SQLite backend", sqlite: true do
|
17
17
|
moneta_build do
|
18
18
|
Moneta::Adapters::Sequel.new(opts.merge(db: sqlite_uri('adapter_sequel.db')))
|
19
19
|
end
|
@@ -21,7 +21,7 @@ describe ':Sequel adapter', adapter: :Sequel do
|
|
21
21
|
include_examples :adapter_sequel, specs.without_concurrent
|
22
22
|
end
|
23
23
|
|
24
|
-
context "with Postgres backend" do
|
24
|
+
context "with Postgres backend", postgres: true do
|
25
25
|
moneta_build do
|
26
26
|
Moneta::Adapters::Sequel.new(opts.merge(postgres_options))
|
27
27
|
end
|
@@ -37,7 +37,7 @@ describe ':Sequel adapter', adapter: :Sequel do
|
|
37
37
|
include_examples :adapter_sequel, specs, optimize: false
|
38
38
|
end
|
39
39
|
|
40
|
-
context "with Postgres HStore backend" do
|
40
|
+
context "with Postgres HStore backend", postgres: true do
|
41
41
|
moneta_build do
|
42
42
|
Moneta::Adapters::Sequel.new(postgres_hstore_options)
|
43
43
|
end
|
@@ -2,9 +2,11 @@ RSpec.shared_context :sequel do
|
|
2
2
|
def mysql_uri database=nil
|
3
3
|
database ||= mysql_database1
|
4
4
|
if defined?(JRUBY_VERSION)
|
5
|
-
"jdbc:mysql
|
5
|
+
uri = "jdbc:mysql://#{mysql_host}:#{mysql_port}/#{database}?user=#{mysql_username}&useSSL=false"
|
6
|
+
uri += "&password=#{mysql_password}" if mysql_password
|
7
|
+
uri
|
6
8
|
else
|
7
|
-
"mysql2://#{mysql_username}
|
9
|
+
"mysql2://#{mysql_username}:#{mysql_password}@#{mysql_host}:#{mysql_port}/#{database}"
|
8
10
|
end
|
9
11
|
end
|
10
12
|
|
@@ -15,11 +17,14 @@ RSpec.shared_context :sequel do
|
|
15
17
|
def postgres_options database=nil
|
16
18
|
database ||= postgres_database1
|
17
19
|
if defined?(JRUBY_VERSION)
|
18
|
-
|
20
|
+
uri = "jdbc:postgresql://localhost/#{database}?user=#{postgres_username}"
|
21
|
+
uri += "&password=#{postgres_password}" if postgres_password
|
22
|
+
{db: uri}
|
19
23
|
else
|
20
24
|
{
|
21
25
|
db: "postgres://localhost/#{database}",
|
22
|
-
user: postgres_username
|
26
|
+
user: postgres_username,
|
27
|
+
password: postgres_password
|
23
28
|
}
|
24
29
|
end
|
25
30
|
end
|
@@ -33,7 +38,7 @@ RSpec.shared_context :sequel do
|
|
33
38
|
def h2_uri
|
34
39
|
"jdbc:h2:" + tempdir
|
35
40
|
end
|
36
|
-
end
|
41
|
+
end
|
37
42
|
|
38
43
|
RSpec.shared_examples :adapter_sequel do |specs, optimize: true|
|
39
44
|
shared_examples :each_key_server do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe 'adapter_sqlite', unsupported: defined?(JRUBY_VERSION), adapter: :Sqlite do
|
1
|
+
describe 'adapter_sqlite', unsupported: defined?(JRUBY_VERSION), adapter: :Sqlite, sqlite: true do
|
2
2
|
moneta_build do
|
3
3
|
Moneta::Adapters::Sqlite.new(file: File.join(tempdir, "adapter_sqlite"))
|
4
4
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe 'standard_sqlite_with_expires', unsupported: defined?(JRUBY_VERSION), adapter: :Sqlite do
|
1
|
+
describe 'standard_sqlite_with_expires', unsupported: defined?(JRUBY_VERSION), adapter: :Sqlite, sqlite: true do
|
2
2
|
let(:t_res) { 0.125 }
|
3
3
|
let(:min_ttl) { 1 }
|
4
4
|
use_timecop
|
@@ -0,0 +1,219 @@
|
|
1
|
+
describe Moneta::Config do
|
2
|
+
describe 'without any configuration' do
|
3
|
+
it 'does not set the config attribute' do
|
4
|
+
klass = Class.new do
|
5
|
+
include ::Moneta::Config
|
6
|
+
|
7
|
+
def initialize(**options)
|
8
|
+
configure(**options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
instance = klass.new(k: 'v')
|
13
|
+
expect(instance.config).to be nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'basic functionality' do
|
18
|
+
subject :klass do
|
19
|
+
Class.new do
|
20
|
+
include ::Moneta::Config
|
21
|
+
|
22
|
+
config :a
|
23
|
+
config :b
|
24
|
+
|
25
|
+
def initialize(**options)
|
26
|
+
configure(**options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'sets all config values to nil by default' do
|
32
|
+
instance = klass.new
|
33
|
+
expect(instance.config.a).to eq nil
|
34
|
+
expect(instance.config.b).to be nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'sets config values with values provided to #configure' do
|
38
|
+
instance = klass.new(a: 1)
|
39
|
+
expect(instance.config.a).to eq 1
|
40
|
+
expect(instance.config.b).to be nil
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'freezes the config' do
|
44
|
+
instance = klass.new
|
45
|
+
expect(instance.config.frozen?).to be true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'with required arguments' do
|
50
|
+
subject :klass do
|
51
|
+
Class.new do
|
52
|
+
include ::Moneta::Config
|
53
|
+
|
54
|
+
config :a, required: true
|
55
|
+
config :b, default: 'x', required: true
|
56
|
+
|
57
|
+
def initialize(**options)
|
58
|
+
configure(**options)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'raises an ArgumentError if #configure is called without one of the required arguments' do
|
64
|
+
expect { klass.new(a: 1) }.to raise_error ArgumentError, 'b is required'
|
65
|
+
expect { klass.new(b: 1) }.to raise_error ArgumentError, 'a is required'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe 'with defaults' do
|
70
|
+
subject :klass do
|
71
|
+
Class.new do
|
72
|
+
include ::Moneta::Config
|
73
|
+
|
74
|
+
config :a, default: 't'
|
75
|
+
config :b, default: 's'
|
76
|
+
|
77
|
+
def initialize(**options)
|
78
|
+
configure(**options)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'uses the defaults if no argument is provided' do
|
84
|
+
instance = klass.new(a: 1)
|
85
|
+
|
86
|
+
expect(instance.config.a).to eq 1
|
87
|
+
expect(instance.config.b).to eq 's'
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'allows falsy values to override truthy defaults' do
|
91
|
+
instance = klass.new(a: nil, b: false)
|
92
|
+
|
93
|
+
expect(instance.config.a).to be nil
|
94
|
+
expect(instance.config.b).to be false
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'with coercion' do
|
99
|
+
describe 'using a symbol' do
|
100
|
+
subject :klass do
|
101
|
+
Class.new do
|
102
|
+
include ::Moneta::Config
|
103
|
+
|
104
|
+
config :a, coerce: :to_s
|
105
|
+
|
106
|
+
def initialize(**options)
|
107
|
+
configure(**options)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
it "uses the symbol's to_proc property" do
|
113
|
+
instance = klass.new(a: :x)
|
114
|
+
expect(instance.config.a).to eq 'x'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe 'using a lambda' do
|
119
|
+
subject :klass do
|
120
|
+
Class.new do
|
121
|
+
include ::Moneta::Config
|
122
|
+
|
123
|
+
config :a, coerce: lambda { |a| a.to_sym }
|
124
|
+
|
125
|
+
def initialize(**options)
|
126
|
+
configure(**options)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
it "calls the lambda" do
|
132
|
+
instance = klass.new(a: 'x')
|
133
|
+
expect(instance.config.a).to eq :x
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe 'with a block' do
|
139
|
+
subject :klass do
|
140
|
+
Class.new do
|
141
|
+
include ::Moneta::Config
|
142
|
+
|
143
|
+
config :a do |a:, b:|
|
144
|
+
{ a: a, b: b, test: @test }
|
145
|
+
end
|
146
|
+
|
147
|
+
config :b, default: 'b default'
|
148
|
+
|
149
|
+
def initialize(test: nil, **options)
|
150
|
+
@test = test
|
151
|
+
configure(**options)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'calls the block after all arguments and defaults have been processed' do
|
157
|
+
instance1 = klass.new(a: 'a value')
|
158
|
+
expect(instance1.config.a).to include(a: 'a value', b: 'b default')
|
159
|
+
|
160
|
+
instance2 = klass.new(b: 'b value')
|
161
|
+
expect(instance2.config.a).to include(a: nil, b: 'b value')
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'calls the block using instance_exec' do
|
165
|
+
instance = klass.new(test: 'test value')
|
166
|
+
expect(instance.config.a).to include(test: 'test value')
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe 'with inheritance' do
|
171
|
+
subject :klass do
|
172
|
+
Class.new do
|
173
|
+
include ::Moneta::Config
|
174
|
+
|
175
|
+
config :a
|
176
|
+
|
177
|
+
def initialize(**options)
|
178
|
+
configure(**options)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'does not allow subclasses to override superclass config' do
|
184
|
+
expect do
|
185
|
+
Class.new(klass) do
|
186
|
+
config :a
|
187
|
+
end
|
188
|
+
end.to raise_error ArgumentError, 'a is already a config option'
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'does not affect the superclass when additional config is added to the subclass' do
|
192
|
+
klass2 = Class.new(klass) do
|
193
|
+
config :b
|
194
|
+
end
|
195
|
+
|
196
|
+
instance1 = klass.new(a: 1, b: 2)
|
197
|
+
expect(instance1.config.to_h).to eq(a: 1)
|
198
|
+
|
199
|
+
instance2 = klass2.new(a: 1, b: 2)
|
200
|
+
expect(instance2.config.to_h).to eq(a: 1, b: 2)
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'is possible for two subclasses to have the same additional config' do
|
204
|
+
klass2 = Class.new(klass) do
|
205
|
+
config :b
|
206
|
+
end
|
207
|
+
|
208
|
+
klass3 = Class.new(klass) do
|
209
|
+
config :b
|
210
|
+
end
|
211
|
+
|
212
|
+
instance2 = klass2.new(a: 2, b: 1)
|
213
|
+
expect(instance2.config.to_h).to eq(a: 2, b: 1)
|
214
|
+
|
215
|
+
instance3 = klass3.new(a: 1, b: 2)
|
216
|
+
expect(instance3.config.to_h).to eq(a: 1, b: 2)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
@@ -14,8 +14,8 @@ describe 'enumerable', proxy: :Enumerable do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'allows enumeration over key-value pairs' do
|
17
|
-
moneta_property_of(keys: 100, values: 100) do |
|
18
|
-
pairs = keys.zip(values)
|
17
|
+
moneta_property_of(keys: 100, values: 100) do |m|
|
18
|
+
pairs = m.keys.zip(m.values)
|
19
19
|
store.merge!(pairs)
|
20
20
|
expect(store.to_a).to contain_exactly(*pairs)
|
21
21
|
expect(store.each.to_a).to contain_exactly(*pairs)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'timeout'
|
2
2
|
|
3
|
-
describe "pool", proxy: :Pool do
|
3
|
+
describe "pool", proxy: :Pool, broken: ::Gem::Version.new(RUBY_ENGINE_VERSION) < ::Gem::Version.new('2.4.0') do
|
4
4
|
describe "Moneta::Pool" do
|
5
5
|
# To test the pool, we create the store once and pass the same object around
|
6
6
|
# whenever a new store is requested.
|
@@ -153,7 +153,7 @@ describe "pool", proxy: :Pool do
|
|
153
153
|
describe "closing stores after TTL expiry" do
|
154
154
|
let(:num) { max || min + 10 }
|
155
155
|
|
156
|
-
it "closes
|
156
|
+
it "closes unneeded stores after ttl" do
|
157
157
|
stores.each do |store|
|
158
158
|
allow(store).to receive(:close)
|
159
159
|
end
|
@@ -169,6 +169,32 @@ describe "pool", proxy: :Pool do
|
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
172
|
+
shared_examples :ttl_with_nonzero_min do |ttl:, min:, max: nil|
|
173
|
+
describe "TTL check" do
|
174
|
+
let(:num) { max || min + 10 }
|
175
|
+
|
176
|
+
# This is testing that a very specific bug is fixed - see
|
177
|
+
# https://github.com/moneta-rb/moneta/issues/197. A better long-term
|
178
|
+
# solution would be to have more granular tests of the functions in the
|
179
|
+
# PoolManager
|
180
|
+
it "doesn't cause a busy-loop when there are available stores" do
|
181
|
+
# Check a store in and out - now the manager needs to decide whether to close
|
182
|
+
# stores after ttl seconds.
|
183
|
+
store = subject.check_out
|
184
|
+
subject.check_in(store)
|
185
|
+
sleep ttl
|
186
|
+
expect(subject.stats[:available]).to be > 0
|
187
|
+
|
188
|
+
# needs to be less than the TTL, but otherwise not important.
|
189
|
+
sleep_time = ttl / 2.0
|
190
|
+
sleep sleep_time
|
191
|
+
|
192
|
+
# during the sleep, the pool manager should have been idle.
|
193
|
+
expect(subject.stats[:idle_time]).to be >= sleep_time
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
172
198
|
shared_examples :timeout do |timeout, max:|
|
173
199
|
describe "raising an error after timeout" do
|
174
200
|
let(:num) { max }
|
@@ -233,6 +259,7 @@ describe "pool", proxy: :Pool do
|
|
233
259
|
include_examples :min, 10
|
234
260
|
include_examples :max, 20, timeout: 4
|
235
261
|
include_examples :ttl, 1, min: 10, max: 20
|
262
|
+
include_examples :ttl_with_nonzero_min, ttl: 1, min: 10, max: 20
|
236
263
|
include_examples :timeout, 4, max: 20
|
237
264
|
end
|
238
265
|
|
@@ -243,6 +270,7 @@ describe "pool", proxy: :Pool do
|
|
243
270
|
include_examples :min, 10
|
244
271
|
include_examples :max, 10, timeout: 4
|
245
272
|
include_examples :ttl, 2, min: 10, max: 10
|
273
|
+
include_examples :ttl_with_nonzero_min, ttl: 2, min: 10, max: 10
|
246
274
|
include_examples :timeout, 4, max: 10
|
247
275
|
end
|
248
276
|
|
@@ -292,7 +320,7 @@ describe "pool", proxy: :Pool do
|
|
292
320
|
end
|
293
321
|
|
294
322
|
it "raises a ShutdownError if the pool is stopped while waiting for a store" do
|
295
|
-
#
|
323
|
+
# Exhaust the pool
|
296
324
|
store = stores.first
|
297
325
|
allow(store).to receive(:close).once
|
298
326
|
expect(subject.check_out).to eq store
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# Currently broken in JRuby 9.3 - see https://github.com/jruby/jruby/issues/6941
|
2
|
+
|
3
|
+
describe 'transformer_bson', proxy: :Transformer, broken: defined?(JRUBY_VERSION) && ::Gem::Version.new(JRUBY_VERSION) >= ::Gem::Version.new('9.3.0.0') do
|
2
4
|
moneta_build do
|
3
5
|
Moneta.build do
|
4
6
|
use :Transformer, key: :bson, value: :bson
|