moneta 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -4
- data/CHANGES +15 -0
- data/CONTRIBUTORS +6 -0
- data/Gemfile +21 -14
- data/README.md +2 -2
- data/lib/moneta/adapters/file.rb +2 -1
- data/lib/moneta/adapters/lruhash.rb +14 -11
- data/lib/moneta/adapters/memcached/dalli.rb +1 -1
- data/lib/moneta/adapters/memcached/native.rb +6 -0
- data/lib/moneta/adapters/mongo/base.rb +16 -1
- data/lib/moneta/adapters/mongo/moped.rb +2 -8
- data/lib/moneta/adapters/mongo/official.rb +31 -35
- data/lib/moneta/adapters/sequel.rb +1 -1
- data/lib/moneta/adapters/tokyotyrant.rb +13 -4
- data/lib/moneta/builder.rb +1 -1
- data/lib/moneta/transformer/config.rb +2 -2
- data/lib/moneta/transformer/helper.rb +16 -2
- data/lib/moneta/transformer/helper/bson.rb +25 -0
- data/lib/moneta/version.rb +1 -1
- data/lib/rack/cache/moneta.rb +2 -2
- data/script/generate-specs +216 -89
- data/script/start-services +6 -6
- data/spec/helper.rb +1 -1
- data/spec/moneta/adapter_datamapper_spec.rb +1 -1
- data/spec/moneta/adapter_lruhash_spec.rb +94 -1
- data/spec/moneta/adapter_mongo_moped_spec.rb +12 -4
- data/spec/moneta/adapter_mongo_moped_with_default_expires_spec.rb +3 -1
- data/spec/moneta/adapter_mongo_official_spec.rb +12 -4
- data/spec/moneta/adapter_mongo_official_with_default_expires_spec.rb +3 -1
- data/spec/moneta/adapter_mongo_spec.rb +2 -1
- data/spec/moneta/adapter_mongo_with_default_expires_spec.rb +3 -1
- data/spec/moneta/mutex_spec.rb +12 -12
- data/spec/moneta/optionmerger_spec.rb +1 -1
- data/spec/moneta/semaphore_spec.rb +15 -15
- data/spec/moneta/shared_tcp_spec.rb +1 -1
- data/spec/moneta/shared_unix_spec.rb +1 -1
- data/spec/moneta/standard_mongo_moped_spec.rb +1 -1
- data/spec/moneta/standard_mongo_official_spec.rb +1 -1
- data/spec/moneta/standard_mongo_spec.rb +1 -1
- data/spec/moneta/transformer_bson_spec.rb +6 -1
- data/spec/moneta/transformer_bzip2_spec.rb +1 -1
- data/spec/monetaspecs.rb +2434 -2434
- data/spec/rack/cache_moneta_spec.rb +2 -2
- data/spec/rack/moneta_store_spec.rb +1 -1
- metadata +196 -12
- data/script/install-bundle +0 -38
- data/script/upload-bundle +0 -2
- data/script/wait-services +0 -15
@@ -14,6 +14,9 @@ module Moneta
|
|
14
14
|
include Defaults
|
15
15
|
include HashAdapter
|
16
16
|
|
17
|
+
# error code: no record found
|
18
|
+
ENOREC = 7
|
19
|
+
|
17
20
|
supports :create, :increment
|
18
21
|
attr_reader :backend
|
19
22
|
|
@@ -29,7 +32,7 @@ module Moneta
|
|
29
32
|
elsif defined?(::TokyoTyrant::RDB)
|
30
33
|
# Use ruby client
|
31
34
|
@backend = ::TokyoTyrant::RDB.new
|
32
|
-
@backend.open(options[:host], options[:port]) or
|
35
|
+
@backend.open(options[:host], options[:port]) or error
|
33
36
|
else
|
34
37
|
# Use native client
|
35
38
|
@backend = ::TokyoTyrant::DB.new(options[:host], options[:port])
|
@@ -44,12 +47,14 @@ module Moneta
|
|
44
47
|
# (see Proxy#load)
|
45
48
|
def load(key, options = {})
|
46
49
|
value = @backend[key]
|
50
|
+
# raise if there is an error and the error is not "no record"
|
51
|
+
error if value.nil? && @backend.ecode != ENOREC
|
47
52
|
value && unpack(value)
|
48
53
|
end
|
49
54
|
|
50
55
|
# (see Proxy#store)
|
51
56
|
def store(key, value, options = {})
|
52
|
-
@backend
|
57
|
+
@backend.put(key, pack(value)) or error
|
53
58
|
value
|
54
59
|
end
|
55
60
|
|
@@ -57,14 +62,14 @@ module Moneta
|
|
57
62
|
def delete(key, options = {})
|
58
63
|
value = load(key, options)
|
59
64
|
if value
|
60
|
-
@backend.delete(key)
|
65
|
+
@backend.delete(key) or error
|
61
66
|
value
|
62
67
|
end
|
63
68
|
end
|
64
69
|
|
65
70
|
# (see Proxy#increment)
|
66
71
|
def increment(key, amount = 1, options = {})
|
67
|
-
@backend.addint(key, amount)
|
72
|
+
@backend.addint(key, amount) or error
|
68
73
|
end
|
69
74
|
|
70
75
|
# (see Proxy#create)
|
@@ -113,6 +118,10 @@ module Moneta
|
|
113
118
|
value
|
114
119
|
end
|
115
120
|
end
|
121
|
+
|
122
|
+
def error
|
123
|
+
raise "#{@backend.class.name} error: #{@backend.errmsg}"
|
124
|
+
end
|
116
125
|
end
|
117
126
|
end
|
118
127
|
end
|
data/lib/moneta/builder.rb
CHANGED
@@ -5,7 +5,7 @@ module Moneta
|
|
5
5
|
# Name: [ Type, Load, Dump, Library ],
|
6
6
|
bencode: [ :serialize, '::BEncode.load(%s)', '::BEncode.dump(%s)', 'bencode' ],
|
7
7
|
bert: [ :serialize, '::BERT.decode(%s)', '::BERT.encode(%s)', 'bert' ],
|
8
|
-
bson: [ :serialize,
|
8
|
+
bson: [ :serialize, 'Helper::BSON.load(%s)', 'Helper::BSON.dump(%s)', 'bson' ],
|
9
9
|
json: [ :serialize, '::MultiJson.load(%s)', '::MultiJson.dump(%s)', 'multi_json' ],
|
10
10
|
marshal: [ :serialize, '::Marshal.load(%s)', '::Marshal.dump(%s)' ],
|
11
11
|
msgpack: [ :serialize, '::MessagePack.unpack(%s)', '::MessagePack.pack(%s)', 'msgpack' ],
|
@@ -13,7 +13,7 @@ module Moneta
|
|
13
13
|
php: [ :serialize, '::PHP.unserialize(%s)', '::PHP.serialize(%s)', 'php_serialize' ],
|
14
14
|
tnet: [ :serialize, '::TNetstring.parse(%s).first', '::TNetstring.dump(%s)', 'tnetstring' ],
|
15
15
|
yaml: [ :serialize, '::YAML.load(%s)', '::YAML.dump(%s)', 'yaml' ],
|
16
|
-
bzip2: [ :compress, '
|
16
|
+
bzip2: [ :compress, 'Helper.bunzip2(%s)', 'Helper.bzip2(%s)', 'rbzip2' ],
|
17
17
|
lz4: [ :compress, '::LZ4.uncompress(%s)', '::LZ4.compress(%s)', 'lz4-ruby' ],
|
18
18
|
lzma: [ :compress, '::LZMA.decompress(%s)', '::LZMA.compress(%s)', 'lzma' ],
|
19
19
|
lzo: [ :compress, '::LZO.decompress(%s)', '::LZO.compress(%s)', 'lzoruby' ],
|
@@ -14,11 +14,11 @@ module Moneta
|
|
14
14
|
|
15
15
|
def hmacverify(value, secret)
|
16
16
|
hash, value = value[0..31], value[32..-1]
|
17
|
-
value if hash == OpenSSL::HMAC.digest(OpenSSL::Digest
|
17
|
+
value if hash == OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), secret, value)
|
18
18
|
end
|
19
19
|
|
20
20
|
def hmacsign(value, secret)
|
21
|
-
OpenSSL::HMAC.digest(OpenSSL::Digest
|
21
|
+
OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), secret, value) << value
|
22
22
|
end
|
23
23
|
|
24
24
|
def truncate(value, maxlen)
|
@@ -32,6 +32,20 @@ module Moneta
|
|
32
32
|
def spread(value)
|
33
33
|
::File.join(value[0..1], value[2..-1])
|
34
34
|
end
|
35
|
+
|
36
|
+
def bzip2(value)
|
37
|
+
io = ::StringIO.new
|
38
|
+
bz = ::RBzip2::Compressor.new(io)
|
39
|
+
bz.write(value)
|
40
|
+
bz.close
|
41
|
+
io.string
|
42
|
+
end
|
43
|
+
|
44
|
+
def bunzip2(value)
|
45
|
+
::RBzip2::Decompressor.new(::StringIO.new(value)).read
|
46
|
+
end
|
47
|
+
|
48
|
+
autoload :BSON, 'moneta/transformer/helper/bson'
|
35
49
|
end
|
36
50
|
end
|
37
51
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Moneta
|
2
|
+
class Transformer
|
3
|
+
module Helper::BSON
|
4
|
+
extend self
|
5
|
+
|
6
|
+
if ::BSON::VERSION >= '4.0.0'
|
7
|
+
def load value
|
8
|
+
::BSON::Document.from_bson(::BSON::ByteBuffer.new(value))['v']
|
9
|
+
end
|
10
|
+
|
11
|
+
def dump value
|
12
|
+
::BSON::Document['v'=>value].to_bson.to_s
|
13
|
+
end
|
14
|
+
else
|
15
|
+
def load value
|
16
|
+
::BSON::Document.from_bson(::StringIO.new(value))['v']
|
17
|
+
end
|
18
|
+
|
19
|
+
def dump value
|
20
|
+
::BSON::Document['v'=>value].to_bson
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/moneta/version.rb
CHANGED
data/lib/rack/cache/moneta.rb
CHANGED
data/script/generate-specs
CHANGED
@@ -425,17 +425,17 @@ end
|
|
425
425
|
},
|
426
426
|
'standard_mongo' => {
|
427
427
|
store: :Mongo,
|
428
|
-
options: "db: 'standard_mongo'",
|
428
|
+
options: "db: 'standard_mongo', collection: 'default'",
|
429
429
|
specs: STANDARD_SPECS.with_native_expires
|
430
430
|
},
|
431
431
|
'standard_mongo_moped' => {
|
432
432
|
store: :MongoMoped,
|
433
|
-
options: "db: '
|
433
|
+
options: "db: 'standard_mongo', collection: 'moped'",
|
434
434
|
specs: STANDARD_SPECS.with_native_expires
|
435
435
|
},
|
436
436
|
'standard_mongo_official' => {
|
437
437
|
store: :MongoOfficial,
|
438
|
-
options: "db: '
|
438
|
+
options: "db: 'standard_mongo', collection: 'official'",
|
439
439
|
specs: STANDARD_SPECS.with_native_expires
|
440
440
|
},
|
441
441
|
'standard_null' => {
|
@@ -633,7 +633,7 @@ end},
|
|
633
633
|
it 'shares values' do
|
634
634
|
store['shared_key'] = 'shared_value'
|
635
635
|
second = new_store
|
636
|
-
second.key?('shared_key').should
|
636
|
+
second.key?('shared_key').should be true
|
637
637
|
second['shared_key'].should == 'shared_value'
|
638
638
|
second.close
|
639
639
|
end
|
@@ -650,7 +650,7 @@ end},
|
|
650
650
|
it 'shares values' do
|
651
651
|
store['shared_key'] = 'shared_value'
|
652
652
|
second = new_store
|
653
|
-
second.key?('shared_key').should
|
653
|
+
second.key?('shared_key').should be true
|
654
654
|
second['shared_key'].should == 'shared_value'
|
655
655
|
second.close
|
656
656
|
end
|
@@ -710,7 +710,7 @@ end}
|
|
710
710
|
adapter :Memory
|
711
711
|
end},
|
712
712
|
specs: TRANSFORMER_SPECS.stringvalues_only,
|
713
|
-
load_value: '::
|
713
|
+
load_value: '::RBzip2::Decompressor.new(::StringIO.new(value)).read',
|
714
714
|
tests: %{
|
715
715
|
it 'compile transformer class' do
|
716
716
|
store.should_not be_nil
|
@@ -828,7 +828,12 @@ end}
|
|
828
828
|
adapter :Memory
|
829
829
|
end},
|
830
830
|
specs: TRANSFORMER_SPECS.simplekeys_only.simplevalues_only,
|
831
|
-
load_value:
|
831
|
+
load_value: %{
|
832
|
+
if ::BSON::VERSION >= '4.0.0'
|
833
|
+
::BSON::Document.from_bson(::BSON::ByteBuffer.new(value))['v']
|
834
|
+
else
|
835
|
+
::BSON::Document.from_bson(::StringIO.new(value))['v']
|
836
|
+
end},
|
832
837
|
tests: %{
|
833
838
|
it 'compile transformer class' do
|
834
839
|
store.should_not be_nil
|
@@ -1314,7 +1319,7 @@ it 'does not cross contaminate when deleting' do
|
|
1314
1319
|
second['key'] = 'value2'
|
1315
1320
|
|
1316
1321
|
first.delete('key').should == 'value'
|
1317
|
-
first.key?('key').should
|
1322
|
+
first.key?('key').should be false
|
1318
1323
|
second['key'].should == 'value2'
|
1319
1324
|
end
|
1320
1325
|
}
|
@@ -1395,46 +1400,168 @@ it 'deletes oldest' do
|
|
1395
1400
|
(0...[9, i-1].min).each do |j|
|
1396
1401
|
store.instance_variable_get(:@entry)[i-j].should_not be_nil
|
1397
1402
|
end
|
1398
|
-
store.key?(i-9).should
|
1403
|
+
store.key?(i-9).should be false if i > 9
|
1399
1404
|
end
|
1405
|
+
end
|
1406
|
+
|
1407
|
+
it 'adds a value that is the same as max_size' do
|
1408
|
+
store = Moneta::Adapters::LRUHash.new(max_size: 21)
|
1409
|
+
store[:a_key] = 'This is 21 bytes long'
|
1410
|
+
store[:a_key].should eq('This is 21 bytes long')
|
1411
|
+
end
|
1412
|
+
|
1413
|
+
it 'does not add a value that is larger than max_size' do
|
1414
|
+
store = Moneta::Adapters::LRUHash.new(max_size: 20)
|
1415
|
+
store[:too_long] = 'This is 21 bytes long'
|
1416
|
+
store[:too_long].should be_nil
|
1417
|
+
end
|
1418
|
+
|
1419
|
+
it 'removes an existing key that is replaced by an item that is larger than max_size' do
|
1420
|
+
store = Moneta::Adapters::LRUHash.new(max_size: 20)
|
1421
|
+
store[:a_key] = 'This will fit'
|
1422
|
+
store[:a_key] = 'This is 21 bytes long'
|
1423
|
+
store[:a_key].should be_nil
|
1424
|
+
end
|
1425
|
+
|
1426
|
+
it 'does not add a value that is larger than max_size, when max_value is explicitly missing' do
|
1427
|
+
store = Moneta::Adapters::LRUHash.new(max_size: 20, max_value: nil)
|
1428
|
+
store[:too_long] = 'This is 21 bytes long'
|
1429
|
+
store[:too_long].should be_nil
|
1430
|
+
end
|
1431
|
+
|
1432
|
+
it 'does not add a value that is larger than max_size, even if max_value is larger than max_size' do
|
1433
|
+
store = Moneta::Adapters::LRUHash.new(max_size: 20, max_value: 25)
|
1434
|
+
store[:too_long] = 'This is 21 bytes long'
|
1435
|
+
store[:too_long].should be_nil
|
1436
|
+
end
|
1437
|
+
|
1438
|
+
it 'adds a value that is as large as the default max_size when max_size is missing' do
|
1439
|
+
store = Moneta::Adapters::LRUHash.new
|
1440
|
+
large_item = 'Really big'
|
1441
|
+
allow(large_item).to receive(:bytesize).and_return(Moneta::Adapters::LRUHash::DEFAULT_MAX_SIZE)
|
1442
|
+
store[:really_big] = large_item
|
1443
|
+
store[:really_big].should eq(large_item)
|
1444
|
+
end
|
1445
|
+
|
1446
|
+
it 'does not add values that are larger than the default max_size when max_size is missing' do
|
1447
|
+
store = Moneta::Adapters::LRUHash.new
|
1448
|
+
large_item = 'Really big'
|
1449
|
+
allow(large_item).to receive(:bytesize).and_return(Moneta::Adapters::LRUHash::DEFAULT_MAX_SIZE + 1)
|
1450
|
+
store[:really_big] = large_item
|
1451
|
+
store[:really_big].should be_nil
|
1452
|
+
end
|
1453
|
+
|
1454
|
+
it 'adds values that are larger than the default max_size when max_size is nil' do
|
1455
|
+
store = Moneta::Adapters::LRUHash.new(max_size: nil)
|
1456
|
+
large_item = 'Really big'
|
1457
|
+
allow(large_item).to receive(:bytesize).and_return(Moneta::Adapters::LRUHash::DEFAULT_MAX_SIZE + 1)
|
1458
|
+
store[:really_big] = large_item
|
1459
|
+
store[:really_big].should eq(large_item)
|
1460
|
+
end
|
1461
|
+
|
1462
|
+
it 'adds an individual value that is equal to max_value' do
|
1463
|
+
store = Moneta::Adapters::LRUHash.new(max_value: 13)
|
1464
|
+
store[:a_key] = '13 bytes long'
|
1465
|
+
store[:a_key].should eq('13 bytes long')
|
1466
|
+
end
|
1467
|
+
|
1468
|
+
it 'does not add a value that is larger than max_value' do
|
1469
|
+
store = Moneta::Adapters::LRUHash.new(max_value: 20)
|
1470
|
+
store[:too_long] = 'This is 21 bytes long'
|
1471
|
+
store[:too_long].should be_nil
|
1472
|
+
end
|
1473
|
+
|
1474
|
+
it 'removes keys that are replaced by values larger than max_value' do
|
1475
|
+
store = Moneta::Adapters::LRUHash.new(max_value: 20)
|
1476
|
+
store[:too_long] = 'This will fit'
|
1477
|
+
store[:too_long] = 'This is 21 bytes long'
|
1478
|
+
store[:too_long].should be_nil
|
1479
|
+
end
|
1480
|
+
|
1481
|
+
it 'only allows the default number of items when max_count is missing' do
|
1482
|
+
stub_const('Moneta::Adapters::LRUHash::DEFAULT_MAX_COUNT', 5)
|
1483
|
+
store = Moneta::Adapters::LRUHash.new(max_value: nil, max_size: nil)
|
1484
|
+
(1..6).each { |n| store[n] = n }
|
1485
|
+
store.key?(1).should be false
|
1486
|
+
store[1].should be_nil
|
1487
|
+
store[2].should eq(2)
|
1488
|
+
store[6].should eq(6)
|
1489
|
+
end
|
1490
|
+
|
1491
|
+
it 'adds more values than DEFAULT_MAX_COUNT allows when max_count is nil' do
|
1492
|
+
stub_const('Moneta::Adapters::LRUHash::DEFAULT_MAX_COUNT', 5)
|
1493
|
+
store = Moneta::Adapters::LRUHash.new(max_count: nil, max_value: nil, max_size: nil)
|
1494
|
+
(1..6).each { |n| store[n] = n }
|
1495
|
+
store[1].should eq(1)
|
1496
|
+
store[2].should eq(2)
|
1497
|
+
store[6].should eq(6)
|
1400
1498
|
end}
|
1401
1499
|
},
|
1402
1500
|
'adapter_mongo' => {
|
1403
|
-
build:
|
1501
|
+
build: %{\
|
1502
|
+
Moneta::Adapters::Mongo.new(db: "adapter_mongo",
|
1503
|
+
collection: 'default')},
|
1404
1504
|
specs: ADAPTER_SPECS.with_native_expires.simplevalues_only
|
1405
1505
|
},
|
1406
1506
|
'adapter_mongo_with_default_expires' => {
|
1407
|
-
build: %{
|
1507
|
+
build: %{\
|
1508
|
+
Moneta::Adapters::Mongo.new(db: "adapter_mongo",
|
1509
|
+
collection: 'with_default_expires',
|
1510
|
+
expires: 1)},
|
1408
1511
|
specs: ADAPTER_SPECS.with_expires.with_default_expires.simplevalues_only
|
1409
1512
|
},
|
1410
1513
|
'adapter_mongo_moped' => {
|
1411
|
-
build:
|
1514
|
+
build: %{\
|
1515
|
+
Moneta::Adapters::MongoMoped.new(db: "adapter_mongo",
|
1516
|
+
collection: 'moped')},
|
1412
1517
|
specs: ADAPTER_SPECS.with_native_expires.simplevalues_only,
|
1413
1518
|
tests: %{
|
1414
1519
|
it 'automatically deletes expired document' do
|
1415
1520
|
store.store('key', 'val', expires: 5)
|
1416
|
-
|
1417
|
-
|
1418
|
-
store.instance_variable_get(:@collection).find(
|
1521
|
+
|
1522
|
+
i = 0
|
1523
|
+
query = store.instance_variable_get(:@collection).find(_id: ::BSON::Binary.new('key'))
|
1524
|
+
while i < 70 && query.first
|
1525
|
+
i += 1
|
1526
|
+
sleep 1 # Mongo needs up to 60 seconds
|
1527
|
+
end
|
1528
|
+
|
1529
|
+
i.should be > 0 # Indicates that it took at least one sleep to expire
|
1530
|
+
query.count.should == 0
|
1419
1531
|
end}
|
1420
1532
|
},
|
1421
1533
|
'adapter_mongo_moped_with_default_expires' => {
|
1422
|
-
build: %{
|
1534
|
+
build: %{\
|
1535
|
+
Moneta::Adapters::MongoMoped.new(db: "adapter_mongo",
|
1536
|
+
collection: 'moped_with_default_expires',
|
1537
|
+
expires: 1)},
|
1423
1538
|
specs: ADAPTER_SPECS.with_expires.with_default_expires.simplevalues_only
|
1424
1539
|
},
|
1425
1540
|
'adapter_mongo_official' => {
|
1426
|
-
build:
|
1541
|
+
build: %{\
|
1542
|
+
Moneta::Adapters::MongoOfficial.new(db: "adapter_mongo",
|
1543
|
+
collection: 'official')},
|
1427
1544
|
specs: ADAPTER_SPECS.with_native_expires.simplevalues_only,
|
1428
1545
|
tests: %{
|
1429
1546
|
it 'automatically deletes expired document' do
|
1430
1547
|
store.store('key', 'val', expires: 5)
|
1431
|
-
|
1432
|
-
|
1433
|
-
store.instance_variable_get(:@collection).
|
1548
|
+
|
1549
|
+
i = 0
|
1550
|
+
query = store.instance_variable_get(:@collection).find(_id: ::BSON::Binary.new('key'))
|
1551
|
+
while i < 70 && query.first
|
1552
|
+
i += 1
|
1553
|
+
sleep 1 # Mongo needs up to 60 seconds
|
1554
|
+
end
|
1555
|
+
|
1556
|
+
i.should be > 0 # Indicates that it took at least one sleep to expire
|
1557
|
+
query.count.should == 0
|
1434
1558
|
end}
|
1435
1559
|
},
|
1436
1560
|
'adapter_mongo_official_with_default_expires' => {
|
1437
|
-
build: %{
|
1561
|
+
build: %{\
|
1562
|
+
Moneta::Adapters::MongoOfficial.new(db: "adapter_mongo",
|
1563
|
+
collection: 'official_with_default_expires',
|
1564
|
+
expires: 1)},
|
1438
1565
|
specs: ADAPTER_SPECS.with_expires.with_default_expires.simplevalues_only
|
1439
1566
|
},
|
1440
1567
|
'adapter_pstore' => {
|
@@ -1506,8 +1633,8 @@ end}
|
|
1506
1633
|
tests: %{
|
1507
1634
|
it 'should have #lock' do
|
1508
1635
|
mutex = Moneta::Mutex.new(store, 'mutex')
|
1509
|
-
mutex.lock.should
|
1510
|
-
mutex.locked?.should
|
1636
|
+
mutex.lock.should be true
|
1637
|
+
mutex.locked?.should be true
|
1511
1638
|
expect do
|
1512
1639
|
mutex.lock
|
1513
1640
|
end.to raise_error(RuntimeError)
|
@@ -1515,13 +1642,13 @@ it 'should have #lock' do
|
|
1515
1642
|
mutex.try_lock
|
1516
1643
|
end.to raise_error(RuntimeError)
|
1517
1644
|
mutex.unlock.should be_nil
|
1518
|
-
mutex.locked?.should
|
1645
|
+
mutex.locked?.should be false
|
1519
1646
|
end
|
1520
1647
|
|
1521
1648
|
it 'should have #enter' do
|
1522
1649
|
mutex = Moneta::Mutex.new(store, 'mutex')
|
1523
|
-
mutex.enter.should
|
1524
|
-
mutex.locked?.should
|
1650
|
+
mutex.enter.should be true
|
1651
|
+
mutex.locked?.should be true
|
1525
1652
|
expect do
|
1526
1653
|
mutex.enter
|
1527
1654
|
end.to raise_error(RuntimeError)
|
@@ -1529,31 +1656,31 @@ it 'should have #enter' do
|
|
1529
1656
|
mutex.try_enter
|
1530
1657
|
end.to raise_error(RuntimeError)
|
1531
1658
|
mutex.leave.should be_nil
|
1532
|
-
mutex.locked?.should
|
1659
|
+
mutex.locked?.should be false
|
1533
1660
|
end
|
1534
1661
|
|
1535
1662
|
it 'should lock with #lock' do
|
1536
1663
|
a = Moneta::Mutex.new(store, 'mutex')
|
1537
1664
|
b = Moneta::Mutex.new(store, 'mutex')
|
1538
|
-
a.lock.should
|
1539
|
-
b.try_lock.should
|
1665
|
+
a.lock.should be true
|
1666
|
+
b.try_lock.should be false
|
1540
1667
|
a.unlock.should be_nil
|
1541
1668
|
end
|
1542
1669
|
|
1543
1670
|
it 'should have lock timeout' do
|
1544
1671
|
a = Moneta::Mutex.new(store, 'mutex')
|
1545
1672
|
b = Moneta::Mutex.new(store, 'mutex')
|
1546
|
-
a.lock.should
|
1547
|
-
b.lock(1).should
|
1673
|
+
a.lock.should be true
|
1674
|
+
b.lock(1).should be false
|
1548
1675
|
a.unlock.should be_nil
|
1549
1676
|
end
|
1550
1677
|
|
1551
1678
|
it 'should have #synchronize' do
|
1552
1679
|
mutex = Moneta::Mutex.new(store, 'mutex')
|
1553
1680
|
mutex.synchronize do
|
1554
|
-
mutex.locked?.should
|
1681
|
+
mutex.locked?.should be true
|
1555
1682
|
end
|
1556
|
-
mutex.locked?.should
|
1683
|
+
mutex.locked?.should be false
|
1557
1684
|
end
|
1558
1685
|
}
|
1559
1686
|
},
|
@@ -1563,8 +1690,8 @@ end
|
|
1563
1690
|
tests: %{
|
1564
1691
|
it 'should have #lock' do
|
1565
1692
|
mutex = Moneta::Semaphore.new(store, 'semaphore')
|
1566
|
-
mutex.lock.should
|
1567
|
-
mutex.locked?.should
|
1693
|
+
mutex.lock.should be true
|
1694
|
+
mutex.locked?.should be true
|
1568
1695
|
expect do
|
1569
1696
|
mutex.lock
|
1570
1697
|
end.to raise_error(RuntimeError)
|
@@ -1572,13 +1699,13 @@ it 'should have #lock' do
|
|
1572
1699
|
mutex.try_lock
|
1573
1700
|
end.to raise_error(RuntimeError)
|
1574
1701
|
mutex.unlock.should be_nil
|
1575
|
-
mutex.locked?.should
|
1702
|
+
mutex.locked?.should be false
|
1576
1703
|
end
|
1577
1704
|
|
1578
1705
|
it 'should have #enter' do
|
1579
1706
|
mutex = Moneta::Semaphore.new(store, 'semaphore')
|
1580
|
-
mutex.enter.should
|
1581
|
-
mutex.locked?.should
|
1707
|
+
mutex.enter.should be true
|
1708
|
+
mutex.locked?.should be true
|
1582
1709
|
expect do
|
1583
1710
|
mutex.enter
|
1584
1711
|
end.to raise_error(RuntimeError)
|
@@ -1586,22 +1713,22 @@ it 'should have #enter' do
|
|
1586
1713
|
mutex.try_enter
|
1587
1714
|
end.to raise_error(RuntimeError)
|
1588
1715
|
mutex.leave.should be_nil
|
1589
|
-
mutex.locked?.should
|
1716
|
+
mutex.locked?.should be false
|
1590
1717
|
end
|
1591
1718
|
|
1592
1719
|
it 'should lock with #lock' do
|
1593
1720
|
a = Moneta::Semaphore.new(store, 'semaphore')
|
1594
1721
|
b = Moneta::Semaphore.new(store, 'semaphore')
|
1595
|
-
a.lock.should
|
1596
|
-
b.try_lock.should
|
1722
|
+
a.lock.should be true
|
1723
|
+
b.try_lock.should be false
|
1597
1724
|
a.unlock.should be_nil
|
1598
1725
|
end
|
1599
1726
|
|
1600
1727
|
it 'should have lock timeout' do
|
1601
1728
|
a = Moneta::Semaphore.new(store, 'semaphore')
|
1602
1729
|
b = Moneta::Semaphore.new(store, 'semaphore')
|
1603
|
-
a.lock.should
|
1604
|
-
b.lock(1).should
|
1730
|
+
a.lock.should be true
|
1731
|
+
b.lock(1).should be false
|
1605
1732
|
a.unlock.should be_nil
|
1606
1733
|
end
|
1607
1734
|
|
@@ -1610,10 +1737,10 @@ it 'should count concurrent accesses' do
|
|
1610
1737
|
b = Moneta::Semaphore.new(store, 'semaphore', 2)
|
1611
1738
|
c = Moneta::Semaphore.new(store, 'semaphore', 2)
|
1612
1739
|
a.synchronize do
|
1613
|
-
a.locked?.should
|
1740
|
+
a.locked?.should be true
|
1614
1741
|
b.synchronize do
|
1615
|
-
b.locked?.should
|
1616
|
-
c.try_lock.should
|
1742
|
+
b.locked?.should be true
|
1743
|
+
c.try_lock.should be false
|
1617
1744
|
end
|
1618
1745
|
end
|
1619
1746
|
end
|
@@ -1621,9 +1748,9 @@ end
|
|
1621
1748
|
it 'should have #synchronize' do
|
1622
1749
|
semaphore = Moneta::Semaphore.new(store, 'semaphore')
|
1623
1750
|
semaphore.synchronize do
|
1624
|
-
semaphore.locked?.should
|
1751
|
+
semaphore.locked?.should be true
|
1625
1752
|
end
|
1626
|
-
semaphore.locked?.should
|
1753
|
+
semaphore.locked?.should be false
|
1627
1754
|
end
|
1628
1755
|
}
|
1629
1756
|
},
|
@@ -1719,7 +1846,7 @@ it 'supports adding proxis using #with' do
|
|
1719
1846
|
compressed_store['key'] = 'compressed value'
|
1720
1847
|
store['key'].should == 'uncompressed value'
|
1721
1848
|
compressed_store['key'].should == 'compressed value'
|
1722
|
-
store.key?('compressedkey').should
|
1849
|
+
store.key?('compressedkey').should be true
|
1723
1850
|
# Check if value is compressed
|
1724
1851
|
compressed_store['key'].should_not == store['compressedkey']
|
1725
1852
|
end}
|
@@ -1772,7 +1899,7 @@ it 'guarantees that the same value is returned when setting a key' do
|
|
1772
1899
|
end
|
1773
1900
|
|
1774
1901
|
it 'returns false from #key? if a key is not available' do
|
1775
|
-
store.key?(#{key1}).should
|
1902
|
+
store.key?(#{key1}).should be false
|
1776
1903
|
end
|
1777
1904
|
|
1778
1905
|
it 'returns nil from delete if a value for a key does not exist' do
|
@@ -1783,8 +1910,8 @@ it 'removes all keys from the store with clear' do
|
|
1783
1910
|
store[#{key1}] = #{val1}
|
1784
1911
|
store[#{key2}] = #{val2}
|
1785
1912
|
store.clear.should equal(store)
|
1786
|
-
store.key?(#{key1}).should
|
1787
|
-
store.key?(#{key2}).should
|
1913
|
+
store.key?(#{key1}).should be false
|
1914
|
+
store.key?(#{key2}).should be false
|
1788
1915
|
end
|
1789
1916
|
|
1790
1917
|
it 'fetches a key with a default value with fetch, if the key is not available' do
|
@@ -1803,7 +1930,7 @@ end
|
|
1803
1930
|
it 'accepts frozen options' do
|
1804
1931
|
options = {option1: 1, options2: 2}
|
1805
1932
|
options.freeze
|
1806
|
-
store.key?(#{key1}, options).should
|
1933
|
+
store.key?(#{key1}, options).should be false
|
1807
1934
|
store.load(#{key1}, options).should be_nil
|
1808
1935
|
store.fetch(#{key1}, 42, options).should == 42
|
1809
1936
|
store.fetch(#{key1}, options) { 42 }.should == 42
|
@@ -1821,7 +1948,7 @@ end
|
|
1821
1948
|
|
1822
1949
|
it 'returns true from #key? if a key is available' do
|
1823
1950
|
store[#{key1}] = #{val1}
|
1824
|
-
store.key?(#{key1}).should
|
1951
|
+
store.key?(#{key1}).should be true
|
1825
1952
|
end
|
1826
1953
|
|
1827
1954
|
it 'stores values with #store' do
|
@@ -1843,7 +1970,7 @@ end
|
|
1843
1970
|
it 'removes and returns a value from the backing store via delete if it exists' do
|
1844
1971
|
store[#{key1}] = #{val1}
|
1845
1972
|
store.delete(#{key1}).should == #{val1}
|
1846
|
-
store.key?(#{key1}).should
|
1973
|
+
store.key?(#{key1}).should be false
|
1847
1974
|
end
|
1848
1975
|
|
1849
1976
|
it 'overwrites existing values' do
|
@@ -1999,18 +2126,18 @@ end
|
|
1999
2126
|
|
2000
2127
|
it 'supports expires on store and #key?', retry: 3 do
|
2001
2128
|
store.store('key1', 'val1', expires: 3)
|
2002
|
-
store.key?('key1').should
|
2129
|
+
store.key?('key1').should be true
|
2003
2130
|
sleep 1
|
2004
|
-
store.key?('key1').should
|
2131
|
+
store.key?('key1').should be true
|
2005
2132
|
sleep 3
|
2006
|
-
store.key?('key1').should
|
2133
|
+
store.key?('key1').should be false
|
2007
2134
|
end
|
2008
2135
|
|
2009
2136
|
it 'supports strict expires on store and #key?' do
|
2010
2137
|
store.store('key1', 'val1', expires: 2)
|
2011
|
-
store.key?('key1').should
|
2138
|
+
store.key?('key1').should be true
|
2012
2139
|
sleep 3 # Sleep 3 seconds because after 2 seconds the value can still exist!
|
2013
|
-
store.key?('key1').should
|
2140
|
+
store.key?('key1').should be false
|
2014
2141
|
end
|
2015
2142
|
|
2016
2143
|
it 'supports updating the expiration time in load', retry: 3 do
|
@@ -2043,7 +2170,7 @@ it 'supports updating the expiration time in #key?', retry: 3 do
|
|
2043
2170
|
store.store('key2', 'val2', expires: 3)
|
2044
2171
|
store['key2'].should == 'val2'
|
2045
2172
|
sleep 1
|
2046
|
-
store.key?('key2', expires: 5).should
|
2173
|
+
store.key?('key2', expires: 5).should be true
|
2047
2174
|
store['key2'].should == 'val2'
|
2048
2175
|
sleep 3
|
2049
2176
|
store['key2'].should == 'val2'
|
@@ -2053,14 +2180,14 @@ end
|
|
2053
2180
|
|
2054
2181
|
it 'supports 0 as no-expires in #key?' do
|
2055
2182
|
store.store('key1', 'val1', expires: 2)
|
2056
|
-
store.key?('key1', expires: 0).should
|
2183
|
+
store.key?('key1', expires: 0).should be true
|
2057
2184
|
sleep 3
|
2058
2185
|
store['key1'].should == 'val1'
|
2059
2186
|
end
|
2060
2187
|
|
2061
2188
|
it 'supports false as no-expires in #key?' do
|
2062
2189
|
store.store('key1', 'val1', expires: 2)
|
2063
|
-
store.key?('key1', expires: false ).should
|
2190
|
+
store.key?('key1', expires: false ).should be true
|
2064
2191
|
sleep 3
|
2065
2192
|
store['key1'].should == 'val1'
|
2066
2193
|
end
|
@@ -2125,10 +2252,10 @@ end
|
|
2125
2252
|
|
2126
2253
|
it 'does not update the expiration time in #key? when not asked to do so', retry: 3 do
|
2127
2254
|
store.store('key1', 'val1', expires: 1)
|
2128
|
-
store.key?('key1').should
|
2129
|
-
store.key?('key1', expires: nil).should
|
2255
|
+
store.key?('key1').should be true
|
2256
|
+
store.key?('key1', expires: nil).should be true
|
2130
2257
|
sleep 2
|
2131
|
-
store.key?('key1').should
|
2258
|
+
store.key?('key1').should be false
|
2132
2259
|
end
|
2133
2260
|
|
2134
2261
|
it 'does not update the expiration time in fetch when not asked to do so', retry: 3 do
|
@@ -2149,11 +2276,11 @@ end}
|
|
2149
2276
|
|
2150
2277
|
SPECS['default_expires'] = %{it 'does set default expiration time' do
|
2151
2278
|
store['key1'] = 'val1'
|
2152
|
-
store.key?('key1').should
|
2279
|
+
store.key?('key1').should be true
|
2153
2280
|
store.fetch('key1').should == 'val1'
|
2154
2281
|
store.load('key1').should == 'val1'
|
2155
2282
|
sleep 2
|
2156
|
-
store.key?('key1').should
|
2283
|
+
store.key?('key1').should be false
|
2157
2284
|
store.fetch('key1').should be_nil
|
2158
2285
|
store.load('key1').should be_nil
|
2159
2286
|
end}
|
@@ -2222,27 +2349,27 @@ it 'have atomic create across multiple processes' do
|
|
2222
2349
|
end}
|
2223
2350
|
|
2224
2351
|
SPECS['increment'] = %{it 'initializes in #increment with 1' do
|
2225
|
-
store.key?('inckey').should
|
2352
|
+
store.key?('inckey').should be false
|
2226
2353
|
store.increment('inckey').should == 1
|
2227
|
-
store.key?('inckey').should
|
2354
|
+
store.key?('inckey').should be true
|
2228
2355
|
store.raw['inckey'].should == '1'
|
2229
2356
|
store.raw.load('inckey').should == '1'
|
2230
2357
|
store.load('inckey', raw: true).should == '1'
|
2231
2358
|
|
2232
2359
|
store.delete('inckey', raw: true).should == '1'
|
2233
|
-
store.key?('inckey').should
|
2360
|
+
store.key?('inckey').should be false
|
2234
2361
|
end
|
2235
2362
|
|
2236
2363
|
it 'initializes in #increment with higher value' do
|
2237
2364
|
store.increment('inckey', 42).should == 42
|
2238
|
-
store.key?('inckey').should
|
2365
|
+
store.key?('inckey').should be true
|
2239
2366
|
store.raw['inckey'].should == '42'
|
2240
2367
|
store.delete('inckey', raw: true).should == '42'
|
2241
2368
|
end
|
2242
2369
|
|
2243
2370
|
it 'initializes in #increment with 0' do
|
2244
2371
|
store.increment('inckey', 0).should == 0
|
2245
|
-
store.key?('inckey').should
|
2372
|
+
store.key?('inckey').should be true
|
2246
2373
|
store.raw['inckey'].should == '0'
|
2247
2374
|
store.delete('inckey', raw: true).should == '0'
|
2248
2375
|
end
|
@@ -2310,36 +2437,36 @@ it 'supports Semaphore' do
|
|
2310
2437
|
b = Moneta::Semaphore.new(store, 'semaphore', 2)
|
2311
2438
|
c = Moneta::Semaphore.new(store, 'semaphore', 2)
|
2312
2439
|
a.synchronize do
|
2313
|
-
a.locked?.should
|
2440
|
+
a.locked?.should be true
|
2314
2441
|
b.synchronize do
|
2315
|
-
b.locked?.should
|
2316
|
-
c.try_lock.should
|
2442
|
+
b.locked?.should be true
|
2443
|
+
c.try_lock.should be false
|
2317
2444
|
end
|
2318
2445
|
end
|
2319
2446
|
end
|
2320
2447
|
}
|
2321
2448
|
|
2322
2449
|
SPECS['create'] = %{it 'creates the given key' do
|
2323
|
-
store.create('key','value').should
|
2450
|
+
store.create('key','value').should be true
|
2324
2451
|
store['key'].should == 'value'
|
2325
2452
|
end
|
2326
2453
|
|
2327
2454
|
it 'creates raw value with the given key' do
|
2328
|
-
store.raw.create('key','value').should
|
2455
|
+
store.raw.create('key','value').should be true
|
2329
2456
|
store.raw['key'].should == 'value'
|
2330
2457
|
end
|
2331
2458
|
|
2332
2459
|
it 'does not create a key if it exists' do
|
2333
2460
|
store['key'] = 'value'
|
2334
|
-
store.create('key','another value').should
|
2461
|
+
store.create('key','another value').should be false
|
2335
2462
|
store['key'].should == 'value'
|
2336
2463
|
end
|
2337
2464
|
|
2338
2465
|
it 'supports Mutex' do
|
2339
2466
|
a = Moneta::Mutex.new(store, 'mutex')
|
2340
2467
|
b = Moneta::Mutex.new(store, 'mutex')
|
2341
|
-
a.lock.should
|
2342
|
-
b.try_lock.should
|
2468
|
+
a.lock.should be true
|
2469
|
+
b.try_lock.should be false
|
2343
2470
|
a.unlock.should be_nil
|
2344
2471
|
end
|
2345
2472
|
}
|
@@ -2351,19 +2478,19 @@ SPECS['not_create'] = %{it 'does not support #create' do
|
|
2351
2478
|
end}
|
2352
2479
|
|
2353
2480
|
SPECS['create_expires'] = %{it 'creates the given key and expires it' do
|
2354
|
-
store.create('key','value', expires: 1).should
|
2481
|
+
store.create('key','value', expires: 1).should be true
|
2355
2482
|
store['key'].should == 'value'
|
2356
2483
|
sleep 2
|
2357
|
-
store.key?('key').should
|
2484
|
+
store.key?('key').should be false
|
2358
2485
|
end
|
2359
2486
|
|
2360
2487
|
it 'does not change expires if the key exists' do
|
2361
2488
|
store.store('key', 'value', expires: false).should == 'value'
|
2362
|
-
store.create('key','another value', expires: 1).should
|
2489
|
+
store.create('key','another value', expires: 1).should be false
|
2363
2490
|
store['key'].should == 'value'
|
2364
2491
|
sleep 2
|
2365
2492
|
store['key'].should == 'value'
|
2366
|
-
store.key?('key').should
|
2493
|
+
store.key?('key').should be true
|
2367
2494
|
end}
|
2368
2495
|
|
2369
2496
|
SPECS['marshallable_key'] = %{it 'refuses to #[] from keys that cannot be marshalled' do
|
@@ -2465,7 +2592,7 @@ SPECS['transform_value_expires'] = %{it 'allows to bypass transformer with :raw
|
|
2465
2592
|
store['key'] = nil
|
2466
2593
|
load_value(store.load('key', raw: true)).should == [nil]
|
2467
2594
|
store['key'] = false
|
2468
|
-
load_value(store.load('key', raw: true)).should
|
2595
|
+
load_value(store.load('key', raw: true)).should be false
|
2469
2596
|
|
2470
2597
|
store.store('key', 'value', expires: 10)
|
2471
2598
|
load_value(store.load('key', raw: true)).first.should == 'value'
|
@@ -2502,14 +2629,14 @@ SPECS['features'] = %{it 'should report correct features' do
|
|
2502
2629
|
end
|
2503
2630
|
|
2504
2631
|
it 'should have frozen features' do
|
2505
|
-
store.features.frozen?.should
|
2632
|
+
store.features.frozen?.should be true
|
2506
2633
|
end
|
2507
2634
|
|
2508
2635
|
it 'should have #supports?' do
|
2509
2636
|
features.each do |f|
|
2510
|
-
store.supports?(f).should
|
2637
|
+
store.supports?(f).should be true
|
2511
2638
|
end
|
2512
|
-
store.supports?(:unknown).should
|
2639
|
+
store.supports?(:unknown).should be false
|
2513
2640
|
end}
|
2514
2641
|
|
2515
2642
|
specs_code = "#{header}\n"
|