moneta 1.4.0 → 1.5.0
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 +415 -0
- data/CHANGES +18 -0
- data/CONTRIBUTORS +2 -0
- data/Gemfile +144 -56
- 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 +59 -50
- 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/helper.rb +14 -3
- 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/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 +17 -3
- data/spec/moneta/adapters/mongo/adapter_mongo_with_default_expires_spec.rb +4 -4
- data/spec/moneta/adapters/mongo/standard_mongo_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/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 -17
- 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
- data/spec/support/mongo_helper.rb +0 -12
data/lib/moneta/server.rb
CHANGED
@@ -4,14 +4,17 @@ module Moneta
|
|
4
4
|
# Moneta server to be used together with Moneta::Adapters::Client
|
5
5
|
# @api public
|
6
6
|
class Server
|
7
|
-
|
8
|
-
|
7
|
+
include Config
|
8
|
+
|
9
|
+
config :timeout, default: 1
|
10
|
+
config :max_size, default: 0x100000
|
9
11
|
|
10
12
|
# @api private
|
11
13
|
class Connection
|
12
|
-
def initialize(io, store)
|
14
|
+
def initialize(io, store, max_size)
|
13
15
|
@io = io
|
14
16
|
@store = store
|
17
|
+
@max_size = max_size
|
15
18
|
@fiber = Fiber.new { run }
|
16
19
|
end
|
17
20
|
|
@@ -58,7 +61,7 @@ module Moneta
|
|
58
61
|
|
59
62
|
def read_msg
|
60
63
|
size = read(4).unpack('N').first
|
61
|
-
throw :closed, 'Message too big' if size >
|
64
|
+
throw :closed, 'Message too big' if size > @max_size
|
62
65
|
Marshal.load(read(size))
|
63
66
|
end
|
64
67
|
|
@@ -155,9 +158,13 @@ module Moneta
|
|
155
158
|
# @param [Hash] options
|
156
159
|
# @option options [Integer] :port (9000) TCP port
|
157
160
|
# @option options [String] :socket Alternative Unix socket file name
|
161
|
+
# @option options [Integer] :timeout (1) Number of seconds to timeout on IO.select
|
162
|
+
# @option options [Integer] :max_size (0x100000) Maximum number of bytes
|
163
|
+
# allowed to be sent by clients in requests
|
158
164
|
def initialize(store, options = {})
|
165
|
+
options = configure(**options)
|
159
166
|
@store = store
|
160
|
-
@server = start(options)
|
167
|
+
@server = start(**options)
|
161
168
|
@ios = [@server]
|
162
169
|
@reads = @ios.dup
|
163
170
|
@writes = []
|
@@ -187,7 +194,7 @@ module Moneta
|
|
187
194
|
@ios
|
188
195
|
.reject { |io| io == @server }
|
189
196
|
.each { |io| close_connection(io) }
|
190
|
-
File.unlink(
|
197
|
+
File.unlink(config.socket) if config.socket rescue nil
|
191
198
|
end
|
192
199
|
end
|
193
200
|
|
@@ -202,7 +209,7 @@ module Moneta
|
|
202
209
|
private
|
203
210
|
|
204
211
|
def mainloop
|
205
|
-
if ready = IO.select(@reads, @writes, @ios,
|
212
|
+
if ready = IO.select(@reads, @writes, @ios, config.timeout)
|
206
213
|
reads, writes, errors = ready
|
207
214
|
errors.each { |io| close_connection(io) }
|
208
215
|
|
@@ -229,7 +236,7 @@ module Moneta
|
|
229
236
|
|
230
237
|
def accept_connection
|
231
238
|
io = @server.accept
|
232
|
-
@connections[io] = Connection.new(io, @store)
|
239
|
+
@connections[io] = Connection.new(io, @store, config.max_size)
|
233
240
|
@ios << io
|
234
241
|
resume(io)
|
235
242
|
ensure
|
@@ -261,21 +268,21 @@ module Moneta
|
|
261
268
|
end
|
262
269
|
end
|
263
270
|
|
264
|
-
def start(
|
265
|
-
if
|
271
|
+
def start(host: '127.0.0.1', port: 9000, socket: nil)
|
272
|
+
if socket
|
266
273
|
begin
|
267
|
-
UNIXServer.open(
|
274
|
+
UNIXServer.open(socket)
|
268
275
|
rescue Errno::EADDRINUSE
|
269
|
-
if client = (UNIXSocket.open(
|
276
|
+
if client = (UNIXSocket.open(socket) rescue nil)
|
270
277
|
client.close
|
271
278
|
raise
|
272
279
|
end
|
273
|
-
File.unlink(
|
280
|
+
File.unlink(socket)
|
274
281
|
tries ||= 0
|
275
282
|
(tries += 1) < 3 ? retry : raise
|
276
283
|
end
|
277
284
|
else
|
278
|
-
TCPServer.open(
|
285
|
+
TCPServer.open(host, port)
|
279
286
|
end
|
280
287
|
end
|
281
288
|
|
data/lib/moneta/version.rb
CHANGED
data/lib/moneta/wrapper.rb
CHANGED
data/lib/moneta.rb
CHANGED
@@ -3,9 +3,11 @@
|
|
3
3
|
# * {Moneta.new}
|
4
4
|
# * {Moneta.build}
|
5
5
|
module Moneta
|
6
|
+
autoload :Adapter, 'moneta/adapter'
|
6
7
|
autoload :Builder, 'moneta/builder'
|
7
8
|
autoload :Cache, 'moneta/cache'
|
8
9
|
autoload :CreateSupport, 'moneta/create_support'
|
10
|
+
autoload :Config, 'moneta/config'
|
9
11
|
autoload :DBMAdapter, 'moneta/dbm_adapter'
|
10
12
|
autoload :Defaults, 'moneta/defaults'
|
11
13
|
autoload :EachKeySupport, 'moneta/each_key_support'
|
data/moneta.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
|
27
27
|
s.required_ruby_version = '>= 2.3.0'
|
28
28
|
|
29
|
+
s.add_development_dependency 'multi_json', '~> 1.15.0'
|
29
30
|
s.add_development_dependency 'parallel_tests', '~> 2.29.2'
|
30
31
|
s.add_development_dependency 'rantly', '~> 1.2.0'
|
31
32
|
s.add_development_dependency 'rspec', '~> 3.0'
|
@@ -74,7 +74,7 @@ describe "cache_moneta_store" do
|
|
74
74
|
end
|
75
75
|
expect(result['rabbit']).to eq rabbit
|
76
76
|
expect(result['irish whisky']).to eq 'irish whisky was missing'
|
77
|
-
expect(store.fetch
|
77
|
+
expect(store.fetch('irish whisky')).to eq 'irish whisky was missing'
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -88,9 +88,9 @@ describe "cache_moneta_store" do
|
|
88
88
|
|
89
89
|
it 'writes multiple values with expiration time' do
|
90
90
|
store.write_multi({
|
91
|
-
|
92
|
-
|
93
|
-
|
91
|
+
'rabbit' => white_rabbit,
|
92
|
+
'irish whisky' => 'Jameson'
|
93
|
+
}, expires_in: 0.2.second)
|
94
94
|
|
95
95
|
expect(store.read_multi('rabbit', 'irish whisky')).to eq \
|
96
96
|
'rabbit' => white_rabbit,
|
@@ -234,23 +234,23 @@ describe "cache_moneta_store" do
|
|
234
234
|
end
|
235
235
|
|
236
236
|
context "with :Memory store" do
|
237
|
-
let(:store){ described_class.new(store: :Memory) }
|
237
|
+
let(:store) { described_class.new(store: :Memory) }
|
238
238
|
include_examples :moneta_store
|
239
239
|
end
|
240
240
|
|
241
241
|
context "with existing :Memory store" do
|
242
|
-
let(:store){ described_class.new(store: ::Moneta.new(:Memory)) }
|
242
|
+
let(:store) { described_class.new(store: ::Moneta.new(:Memory)) }
|
243
243
|
include_examples :moneta_store
|
244
244
|
end
|
245
245
|
|
246
|
-
context "with Redis store" do
|
247
|
-
let(:store) {described_class.new(store: :Redis) }
|
246
|
+
context "with Redis store", adapter: :Redis do
|
247
|
+
let(:store) { described_class.new(store: :Redis) }
|
248
248
|
include_examples :moneta_store
|
249
249
|
end
|
250
250
|
end
|
251
251
|
|
252
252
|
describe ActiveSupport::Cache::MemoryStore do
|
253
|
-
let(:store){ described_class.new }
|
253
|
+
let(:store) { described_class.new }
|
254
254
|
|
255
255
|
include_examples :basic_store
|
256
256
|
include_examples :expiry
|
@@ -258,8 +258,8 @@ describe "cache_moneta_store" do
|
|
258
258
|
include_examples :basic_instrumentation
|
259
259
|
end
|
260
260
|
|
261
|
-
describe ActiveSupport::Cache::MemCacheStore do
|
262
|
-
let(:store){ described_class.new('127.0.0.1:11213') }
|
261
|
+
describe ActiveSupport::Cache::MemCacheStore, memcached: true do
|
262
|
+
let(:store) { described_class.new('127.0.0.1:11213') }
|
263
263
|
|
264
264
|
include_context :start_memcached, 11213
|
265
265
|
|
@@ -270,8 +270,8 @@ describe "cache_moneta_store" do
|
|
270
270
|
include_examples :increment_decrement_instrumentation
|
271
271
|
end
|
272
272
|
|
273
|
-
describe ActiveSupport::Cache::RedisCacheStore do
|
274
|
-
let(:store){ described_class.new(url:
|
273
|
+
describe ActiveSupport::Cache::RedisCacheStore, redis: true do
|
274
|
+
let(:store) { described_class.new(url: "redis:///3") }
|
275
275
|
|
276
276
|
include_examples :basic_store
|
277
277
|
include_examples :expiry
|
data/spec/helper.rb
CHANGED
@@ -10,7 +10,6 @@ require 'rantly'
|
|
10
10
|
require 'rantly/rspec_extensions'
|
11
11
|
# rantly/shrinks
|
12
12
|
require 'timecop'
|
13
|
-
require_relative 'support/mongo_helper'
|
14
13
|
|
15
14
|
class MonetaParallelFormatter < RSpec::Core::Formatters::BaseTextFormatter
|
16
15
|
def start(*args)
|
@@ -214,11 +213,18 @@ ADAPTER_SPECS = MonetaSpecs.new(
|
|
214
213
|
:create, :features, :store_large, :not_each_key],
|
215
214
|
key: %w(string path),
|
216
215
|
value: %w(string path binary))
|
216
|
+
|
217
|
+
NATIVE_EXPIRY_SPECS = MonetaSpecs.new(
|
218
|
+
specs: [:create, :expires, :create_expires],
|
219
|
+
key: %w(string path),
|
220
|
+
value: %w(string path binary))
|
221
|
+
|
217
222
|
STANDARD_SPECS = MonetaSpecs.new(
|
218
223
|
specs: [:null, :store, :returndifferent,
|
219
224
|
:marshallable_key, :marshallable_value, :transform_value, :increment,
|
220
225
|
:concurrent_increment, :concurrent_create, :persist, :multiprocess, :create,
|
221
226
|
:features, :store_large, :not_each_key])
|
227
|
+
|
222
228
|
TRANSFORMER_SPECS = MonetaSpecs.new(
|
223
229
|
specs: [:null, :store, :returndifferent,
|
224
230
|
:transform_value, :increment, :create, :features, :store_large,
|
@@ -261,18 +267,24 @@ module MonetaHelpers
|
|
261
267
|
|
262
268
|
# Used by tests that rely on MySQL. These env vars can be used if you
|
263
269
|
# want to run the tests but don't want to grant root access to moneta
|
270
|
+
let(:mysql_host) { ENV['MYSQL_HOST'] || 'localhost' }
|
271
|
+
let(:mysql_port) { ENV['MYSQL_TCP_PORT'] || '3306' }
|
264
272
|
let(:mysql_username) { ENV['MONETA_MYSQL_USERNAME'] || 'root' }
|
265
273
|
let(:mysql_password) { ENV['MONETA_MYSQL_PASSWORD'] }
|
266
274
|
let(:mysql_database1) { ENV['MONETA_MYSQL_DATABASE1'] || 'moneta' }
|
267
275
|
let(:mysql_database2) { ENV['MONETA_MYSQL_DATABASE2'] || 'moneta2' }
|
268
276
|
|
269
|
-
let(:postgres_username) { ENV['
|
277
|
+
let(:postgres_username) { ENV['PGUSER'] || 'postgres' }
|
278
|
+
let(:postgres_password) { ENV['PGPASSWORD'] }
|
270
279
|
let(:postgres_database1) { ENV['MONETA_POSTGRES_DATABSASE1'] || 'moneta1' }
|
271
280
|
let(:postgres_database2) { ENV['MONETA_POSTGRES_DATABSASE1'] || 'moneta2' }
|
272
281
|
|
273
282
|
let(:couch_login) { ENV['COUCH_LOGIN'] || 'admin' }
|
274
283
|
let(:couch_password) { ENV['COUCH_PASSWORD'] || 'password' }
|
275
284
|
|
285
|
+
let(:redis_host) { ENV.fetch('REDIS_HOST', 'localhost') }
|
286
|
+
let(:redis_port) { ENV.fetch('REDIS_PORT', '6379') }
|
287
|
+
|
276
288
|
before do
|
277
289
|
store = new_store
|
278
290
|
store.clear
|
@@ -366,7 +378,6 @@ RSpec.configure do |config|
|
|
366
378
|
|
367
379
|
config.extend MonetaHelpers::ClassMethods
|
368
380
|
config.include MonetaHelpers::InstanceMethods
|
369
|
-
config.include MongoHelper, adapter: :Mongo
|
370
381
|
end
|
371
382
|
|
372
383
|
# FIXME: Get rid of this once raise_error expectations no longer generate
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe 'adapter_activerecord_existing_connection', adapter: :ActiveRecord do
|
1
|
+
describe 'adapter_activerecord_existing_connection', adapter: :ActiveRecord, mysql: true do
|
2
2
|
before :all do
|
3
3
|
require 'active_record'
|
4
4
|
end
|
@@ -8,6 +8,8 @@ describe 'adapter_activerecord_existing_connection', adapter: :ActiveRecord do
|
|
8
8
|
ActiveRecord::Base.configurations = {
|
9
9
|
default_env => {
|
10
10
|
'adapter' => (defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql2'),
|
11
|
+
'host' => mysql_host,
|
12
|
+
'port' => mysql_port,
|
11
13
|
'database' => mysql_database1,
|
12
14
|
'username' => mysql_username,
|
13
15
|
'password' => mysql_password
|
@@ -58,32 +58,39 @@ describe 'adapter_activerecord', adapter: :ActiveRecord do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
context "with MySQL" do
|
61
|
+
context "with MySQL", mysql: true do
|
62
62
|
let(:connection1) do
|
63
63
|
{
|
64
64
|
adapter: (defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql2'),
|
65
|
+
host: mysql_host,
|
66
|
+
port: mysql_port,
|
65
67
|
database: mysql_database1,
|
66
|
-
username: mysql_username
|
68
|
+
username: mysql_username,
|
69
|
+
password: mysql_password
|
67
70
|
}
|
68
71
|
end
|
69
72
|
|
70
73
|
let(:connection2) do
|
71
74
|
{
|
72
75
|
adapter: (defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql2'),
|
76
|
+
host: mysql_host,
|
77
|
+
port: mysql_port,
|
73
78
|
database: mysql_database2,
|
74
|
-
username: mysql_username
|
79
|
+
username: mysql_username,
|
80
|
+
password: mysql_password
|
75
81
|
}
|
76
82
|
end
|
77
83
|
|
78
84
|
include_examples :adapter_activerecord, activerecord_specs
|
79
85
|
end
|
80
86
|
|
81
|
-
context "with PostgreSQL" do
|
87
|
+
context "with PostgreSQL", postgres: true do
|
82
88
|
let(:connection1) do
|
83
89
|
{
|
84
90
|
adapter: (defined?(JRUBY_VERSION) ? 'jdbcpostgresql' : 'postgresql'),
|
85
91
|
database: postgres_database1,
|
86
|
-
username: postgres_username
|
92
|
+
username: postgres_username,
|
93
|
+
password: postgres_password
|
87
94
|
}
|
88
95
|
end
|
89
96
|
|
@@ -91,14 +98,15 @@ describe 'adapter_activerecord', adapter: :ActiveRecord do
|
|
91
98
|
{
|
92
99
|
adapter: (defined?(JRUBY_VERSION) ? 'jdbcpostgresql' : 'postgresql'),
|
93
100
|
database: postgres_database2,
|
94
|
-
username: postgres_username
|
101
|
+
username: postgres_username,
|
102
|
+
password: postgres_password
|
95
103
|
}
|
96
104
|
end
|
97
105
|
|
98
106
|
include_examples :adapter_activerecord, activerecord_specs
|
99
107
|
end
|
100
108
|
|
101
|
-
context "with SQLite" do
|
109
|
+
context "with SQLite", sqlite: true do
|
102
110
|
let(:connection1) do
|
103
111
|
{
|
104
112
|
adapter: (defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3'),
|
@@ -1,11 +1,14 @@
|
|
1
|
-
describe "standard_activerecord", adapter: :ActiveRecord do
|
1
|
+
describe "standard_activerecord", adapter: :ActiveRecord, mysql: true do
|
2
2
|
moneta_store :ActiveRecord do
|
3
3
|
{
|
4
4
|
table: 'standard_activerecord',
|
5
5
|
connection: {
|
6
6
|
adapter: (defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql2'),
|
7
|
+
host: mysql_host,
|
8
|
+
port: mysql_port,
|
7
9
|
database: mysql_database1,
|
8
|
-
username: mysql_username
|
10
|
+
username: mysql_username,
|
11
|
+
password: mysql_password
|
9
12
|
}
|
10
13
|
}
|
11
14
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe "standard_activerecord_with_expires", adapter: :ActiveRecord do
|
1
|
+
describe "standard_activerecord_with_expires", adapter: :ActiveRecord, mysql: true do
|
2
2
|
let(:t_res) { 0.125 }
|
3
3
|
let(:min_ttl) { t_res }
|
4
4
|
use_timecop
|
@@ -8,8 +8,11 @@ describe "standard_activerecord_with_expires", adapter: :ActiveRecord do
|
|
8
8
|
table: 'standard_activerecord_with_expires',
|
9
9
|
connection: {
|
10
10
|
adapter: (defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql2'),
|
11
|
+
host: mysql_host,
|
12
|
+
port: mysql_port,
|
11
13
|
database: mysql_database1,
|
12
|
-
username: mysql_username
|
14
|
+
username: mysql_username,
|
15
|
+
password: mysql_password
|
13
16
|
},
|
14
17
|
expires: true
|
15
18
|
}
|
@@ -23,7 +23,7 @@ describe 'adapter_activesupportcache', adapter: :ActiveSupportCache do
|
|
23
23
|
include_examples :adapter_activesupportcache
|
24
24
|
end
|
25
25
|
|
26
|
-
context 'using MemCacheStore' do
|
26
|
+
context 'using MemCacheStore', memcached: true do
|
27
27
|
let(:t_res) { 1 }
|
28
28
|
let(:min_ttl) { 2 }
|
29
29
|
use_timecop
|
@@ -34,12 +34,12 @@ describe 'adapter_activesupportcache', adapter: :ActiveSupportCache do
|
|
34
34
|
include_examples :adapter_activesupportcache
|
35
35
|
end
|
36
36
|
|
37
|
-
context 'using RedisCacheStore' do
|
37
|
+
context 'using RedisCacheStore', redis: true do
|
38
38
|
let(:t_res) { 1 }
|
39
39
|
let(:min_ttl) { t_res }
|
40
40
|
use_timecop
|
41
41
|
|
42
|
-
let(:backend) { ActiveSupport::Cache::RedisCacheStore.new(url:
|
42
|
+
let(:backend) { ActiveSupport::Cache::RedisCacheStore.new(url: "redis://#{redis_host}:#{redis_port}/1") }
|
43
43
|
include_examples :adapter_activesupportcache
|
44
44
|
end
|
45
45
|
|
data/spec/moneta/adapters/activesupportcache/adapter_activesupportcache_with_default_expires_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe 'adapter_activesupportcache_with_default_expires', adapter: :ActiveSupp
|
|
23
23
|
include_examples :adapter_activesupportcache_with_default_expires
|
24
24
|
end
|
25
25
|
|
26
|
-
context 'using MemCacheStore' do
|
26
|
+
context 'using MemCacheStore', memcached: true do
|
27
27
|
let(:t_res) { 1 }
|
28
28
|
let(:min_ttl) { 2 }
|
29
29
|
use_timecop
|
@@ -39,7 +39,7 @@ describe 'adapter_activesupportcache_with_default_expires', adapter: :ActiveSupp
|
|
39
39
|
let(:min_ttl) { t_res }
|
40
40
|
use_timecop
|
41
41
|
|
42
|
-
let(:backend) { ActiveSupport::Cache::RedisCacheStore.new(url:
|
42
|
+
let(:backend) { ActiveSupport::Cache::RedisCacheStore.new(url: "redis://#{redis_host}:#{redis_port}/2") }
|
43
43
|
include_examples :adapter_activesupportcache_with_default_expires
|
44
44
|
end
|
45
45
|
|
@@ -12,13 +12,14 @@ RSpec.shared_context :start_server do |**options|
|
|
12
12
|
puts "Failed to start server - #{ex.message}"
|
13
13
|
tries ||= 0
|
14
14
|
tries += 1
|
15
|
-
|
15
|
+
timeout = options[:timeout] || Moneta::Server.config_defaults[:timeout]
|
16
|
+
sleep 1
|
16
17
|
tries < 3 ? retry : raise
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
21
|
after :context do
|
21
|
-
@server
|
22
|
-
@thread
|
22
|
+
@server&.stop
|
23
|
+
@thread&.join
|
23
24
|
end
|
24
25
|
end
|
@@ -1,22 +1,32 @@
|
|
1
|
-
describe 'adapter_datamapper', broken: defined?(JRUBY_VERSION), adapter: :DataMapper do
|
1
|
+
describe 'adapter_datamapper', broken: defined?(JRUBY_VERSION), adapter: :DataMapper, mysql: true do
|
2
2
|
before :all do
|
3
3
|
require 'dm-core'
|
4
4
|
|
5
5
|
# DataMapper needs default repository to be setup
|
6
6
|
DataMapper.setup(:default, adapter: :in_memory)
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
moneta_build do
|
10
|
-
Moneta::Adapters::DataMapper.new(
|
10
|
+
Moneta::Adapters::DataMapper.new(
|
11
|
+
setup: "mysql://#{mysql_username}:#{mysql_password}@#{mysql_host}:#{mysql_port}/#{mysql_database1}",
|
12
|
+
table: "adapter_datamapper"
|
13
|
+
)
|
11
14
|
end
|
12
15
|
|
13
16
|
moneta_specs ADAPTER_SPECS.without_increment.with_values(:nil).without_values(:binary)
|
14
|
-
|
17
|
+
|
15
18
|
it 'does not cross contaminate when storing' do
|
16
|
-
first = Moneta::Adapters::DataMapper.new(
|
19
|
+
first = Moneta::Adapters::DataMapper.new(
|
20
|
+
setup: "mysql://#{mysql_username}:#{mysql_password}@#{mysql_host}:#{mysql_port}/#{mysql_database1}",
|
21
|
+
table: "datamapper_first"
|
22
|
+
)
|
17
23
|
first.clear
|
18
24
|
|
19
|
-
second = Moneta::Adapters::DataMapper.new(
|
25
|
+
second = Moneta::Adapters::DataMapper.new(
|
26
|
+
repository: :sample,
|
27
|
+
setup: "mysql://#{mysql_username}:#{mysql_password}@#{mysql_host}:#{mysql_port}/#{mysql_database1}",
|
28
|
+
table: "datamapper_second"
|
29
|
+
)
|
20
30
|
second.clear
|
21
31
|
|
22
32
|
first['key'] = 'value'
|
@@ -27,10 +37,17 @@ describe 'adapter_datamapper', broken: defined?(JRUBY_VERSION), adapter: :DataMa
|
|
27
37
|
end
|
28
38
|
|
29
39
|
it 'does not cross contaminate when deleting' do
|
30
|
-
first = Moneta::Adapters::DataMapper.new(
|
40
|
+
first = Moneta::Adapters::DataMapper.new(
|
41
|
+
setup: "mysql://#{mysql_username}:#{mysql_password}@#{mysql_host}:#{mysql_port}/#{mysql_database1}",
|
42
|
+
table: "datamapper_first"
|
43
|
+
)
|
31
44
|
first.clear
|
32
45
|
|
33
|
-
second = Moneta::Adapters::DataMapper.new(
|
46
|
+
second = Moneta::Adapters::DataMapper.new(
|
47
|
+
repository: :sample,
|
48
|
+
setup: "mysql://#{mysql_username}:#{mysql_password}@#{mysql_host}:#{mysql_port}/#{mysql_database1}",
|
49
|
+
table: "datamapper_second"
|
50
|
+
)
|
34
51
|
second.clear
|
35
52
|
|
36
53
|
first['key'] = 'value'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe "standard_datamapper", broken: defined?(JRUBY_VERSION), adapter: :DataMapper do
|
1
|
+
describe "standard_datamapper", broken: defined?(JRUBY_VERSION), adapter: :DataMapper, mysql: true do
|
2
2
|
before :all do
|
3
3
|
require 'dm-core'
|
4
4
|
|
@@ -8,7 +8,7 @@ describe "standard_datamapper", broken: defined?(JRUBY_VERSION), adapter: :DataM
|
|
8
8
|
|
9
9
|
moneta_store :DataMapper do
|
10
10
|
{
|
11
|
-
setup: "mysql://#{mysql_username}:#{mysql_password}
|
11
|
+
setup: "mysql://#{mysql_username}:#{mysql_password}@#{mysql_host}:#{mysql_port}/#{mysql_database1}",
|
12
12
|
table: "simple_datamapper"
|
13
13
|
}
|
14
14
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe "standard_datamapper_with_expires", broken: defined?(JRUBY_VERSION), adapter: :DataMapper do
|
1
|
+
describe "standard_datamapper_with_expires", broken: defined?(JRUBY_VERSION), 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', broken: defined?(JRUBY_VERSION), adapter: :DataMapper do
|
1
|
+
describe 'standard_datamapper_with_repository', broken: defined?(JRUBY_VERSION), 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
|