moneta 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +9 -4
  3. data/CHANGES +15 -0
  4. data/CONTRIBUTORS +6 -0
  5. data/Gemfile +21 -14
  6. data/README.md +2 -2
  7. data/lib/moneta/adapters/file.rb +2 -1
  8. data/lib/moneta/adapters/lruhash.rb +14 -11
  9. data/lib/moneta/adapters/memcached/dalli.rb +1 -1
  10. data/lib/moneta/adapters/memcached/native.rb +6 -0
  11. data/lib/moneta/adapters/mongo/base.rb +16 -1
  12. data/lib/moneta/adapters/mongo/moped.rb +2 -8
  13. data/lib/moneta/adapters/mongo/official.rb +31 -35
  14. data/lib/moneta/adapters/sequel.rb +1 -1
  15. data/lib/moneta/adapters/tokyotyrant.rb +13 -4
  16. data/lib/moneta/builder.rb +1 -1
  17. data/lib/moneta/transformer/config.rb +2 -2
  18. data/lib/moneta/transformer/helper.rb +16 -2
  19. data/lib/moneta/transformer/helper/bson.rb +25 -0
  20. data/lib/moneta/version.rb +1 -1
  21. data/lib/rack/cache/moneta.rb +2 -2
  22. data/script/generate-specs +216 -89
  23. data/script/start-services +6 -6
  24. data/spec/helper.rb +1 -1
  25. data/spec/moneta/adapter_datamapper_spec.rb +1 -1
  26. data/spec/moneta/adapter_lruhash_spec.rb +94 -1
  27. data/spec/moneta/adapter_mongo_moped_spec.rb +12 -4
  28. data/spec/moneta/adapter_mongo_moped_with_default_expires_spec.rb +3 -1
  29. data/spec/moneta/adapter_mongo_official_spec.rb +12 -4
  30. data/spec/moneta/adapter_mongo_official_with_default_expires_spec.rb +3 -1
  31. data/spec/moneta/adapter_mongo_spec.rb +2 -1
  32. data/spec/moneta/adapter_mongo_with_default_expires_spec.rb +3 -1
  33. data/spec/moneta/mutex_spec.rb +12 -12
  34. data/spec/moneta/optionmerger_spec.rb +1 -1
  35. data/spec/moneta/semaphore_spec.rb +15 -15
  36. data/spec/moneta/shared_tcp_spec.rb +1 -1
  37. data/spec/moneta/shared_unix_spec.rb +1 -1
  38. data/spec/moneta/standard_mongo_moped_spec.rb +1 -1
  39. data/spec/moneta/standard_mongo_official_spec.rb +1 -1
  40. data/spec/moneta/standard_mongo_spec.rb +1 -1
  41. data/spec/moneta/transformer_bson_spec.rb +6 -1
  42. data/spec/moneta/transformer_bzip2_spec.rb +1 -1
  43. data/spec/monetaspecs.rb +2434 -2434
  44. data/spec/rack/cache_moneta_spec.rb +2 -2
  45. data/spec/rack/moneta_store_spec.rb +1 -1
  46. metadata +196 -12
  47. data/script/install-bundle +0 -38
  48. data/script/upload-bundle +0 -2
  49. data/script/wait-services +0 -15
@@ -3,9 +3,9 @@
3
3
  echo 'Starting TokyoTyrant'
4
4
  /usr/sbin/ttserver -dmn -pid /tmp/ttserver.pid -log /tmp/ttserver.log -port 1978
5
5
 
6
- sudo service riak start &
7
- sudo service couchdb start &
8
- sudo service redis-server start &
9
- sudo service cassandra start &
10
- sudo service memcached start &
11
- sudo service mongodb start &
6
+ # Waiting for servers to start
7
+ sleep 3
8
+
9
+ echo 'TokyoTyrant status'
10
+ ps aux | grep ttserver
11
+ cat /tmp/ttserver.log
@@ -49,7 +49,7 @@ end
49
49
 
50
50
  RSpec.configure do |config|
51
51
  config.verbose_retry = true
52
- config.color_enabled = true
52
+ config.color = true
53
53
  config.tty = true
54
54
  config.formatter = ENV['PARALLEL_TESTS'] ? MonetaParallelFormatter : :progress
55
55
  end
@@ -57,7 +57,7 @@ describe_moneta "adapter_datamapper" do
57
57
  second['key'] = 'value2'
58
58
 
59
59
  first.delete('key').should == 'value'
60
- first.key?('key').should be_false
60
+ first.key?('key').should be false
61
61
  second['key'].should == 'value2'
62
62
  end
63
63
 
@@ -37,7 +37,100 @@ describe_moneta "adapter_lruhash" do
37
37
  (0...[9, i-1].min).each do |j|
38
38
  store.instance_variable_get(:@entry)[i-j].should_not be_nil
39
39
  end
40
- store.key?(i-9).should be_false if i > 9
40
+ store.key?(i-9).should be false if i > 9
41
41
  end
42
42
  end
43
+
44
+ it 'adds a value that is the same as max_size' do
45
+ store = Moneta::Adapters::LRUHash.new(max_size: 21)
46
+ store[:a_key] = 'This is 21 bytes long'
47
+ store[:a_key].should eq('This is 21 bytes long')
48
+ end
49
+
50
+ it 'does not add a value that is larger than max_size' do
51
+ store = Moneta::Adapters::LRUHash.new(max_size: 20)
52
+ store[:too_long] = 'This is 21 bytes long'
53
+ store[:too_long].should be_nil
54
+ end
55
+
56
+ it 'removes an existing key that is replaced by an item that is larger than max_size' do
57
+ store = Moneta::Adapters::LRUHash.new(max_size: 20)
58
+ store[:a_key] = 'This will fit'
59
+ store[:a_key] = 'This is 21 bytes long'
60
+ store[:a_key].should be_nil
61
+ end
62
+
63
+ it 'does not add a value that is larger than max_size, when max_value is explicitly missing' do
64
+ store = Moneta::Adapters::LRUHash.new(max_size: 20, max_value: nil)
65
+ store[:too_long] = 'This is 21 bytes long'
66
+ store[:too_long].should be_nil
67
+ end
68
+
69
+ it 'does not add a value that is larger than max_size, even if max_value is larger than max_size' do
70
+ store = Moneta::Adapters::LRUHash.new(max_size: 20, max_value: 25)
71
+ store[:too_long] = 'This is 21 bytes long'
72
+ store[:too_long].should be_nil
73
+ end
74
+
75
+ it 'adds a value that is as large as the default max_size when max_size is missing' do
76
+ store = Moneta::Adapters::LRUHash.new
77
+ large_item = 'Really big'
78
+ allow(large_item).to receive(:bytesize).and_return(Moneta::Adapters::LRUHash::DEFAULT_MAX_SIZE)
79
+ store[:really_big] = large_item
80
+ store[:really_big].should eq(large_item)
81
+ end
82
+
83
+ it 'does not add values that are larger than the default max_size when max_size is missing' do
84
+ store = Moneta::Adapters::LRUHash.new
85
+ large_item = 'Really big'
86
+ allow(large_item).to receive(:bytesize).and_return(Moneta::Adapters::LRUHash::DEFAULT_MAX_SIZE + 1)
87
+ store[:really_big] = large_item
88
+ store[:really_big].should be_nil
89
+ end
90
+
91
+ it 'adds values that are larger than the default max_size when max_size is nil' do
92
+ store = Moneta::Adapters::LRUHash.new(max_size: nil)
93
+ large_item = 'Really big'
94
+ allow(large_item).to receive(:bytesize).and_return(Moneta::Adapters::LRUHash::DEFAULT_MAX_SIZE + 1)
95
+ store[:really_big] = large_item
96
+ store[:really_big].should eq(large_item)
97
+ end
98
+
99
+ it 'adds an individual value that is equal to max_value' do
100
+ store = Moneta::Adapters::LRUHash.new(max_value: 13)
101
+ store[:a_key] = '13 bytes long'
102
+ store[:a_key].should eq('13 bytes long')
103
+ end
104
+
105
+ it 'does not add a value that is larger than max_value' do
106
+ store = Moneta::Adapters::LRUHash.new(max_value: 20)
107
+ store[:too_long] = 'This is 21 bytes long'
108
+ store[:too_long].should be_nil
109
+ end
110
+
111
+ it 'removes keys that are replaced by values larger than max_value' do
112
+ store = Moneta::Adapters::LRUHash.new(max_value: 20)
113
+ store[:too_long] = 'This will fit'
114
+ store[:too_long] = 'This is 21 bytes long'
115
+ store[:too_long].should be_nil
116
+ end
117
+
118
+ it 'only allows the default number of items when max_count is missing' do
119
+ stub_const('Moneta::Adapters::LRUHash::DEFAULT_MAX_COUNT', 5)
120
+ store = Moneta::Adapters::LRUHash.new(max_value: nil, max_size: nil)
121
+ (1..6).each { |n| store[n] = n }
122
+ store.key?(1).should be false
123
+ store[1].should be_nil
124
+ store[2].should eq(2)
125
+ store[6].should eq(6)
126
+ end
127
+
128
+ it 'adds more values than DEFAULT_MAX_COUNT allows when max_count is nil' do
129
+ stub_const('Moneta::Adapters::LRUHash::DEFAULT_MAX_COUNT', 5)
130
+ store = Moneta::Adapters::LRUHash.new(max_count: nil, max_value: nil, max_size: nil)
131
+ (1..6).each { |n| store[n] = n }
132
+ store[1].should eq(1)
133
+ store[2].should eq(2)
134
+ store[6].should eq(6)
135
+ end
43
136
  end
@@ -8,7 +8,8 @@ describe_moneta "adapter_mongo_moped" do
8
8
  end
9
9
 
10
10
  def new_store
11
- Moneta::Adapters::MongoMoped.new(db: "adapter_mongo")
11
+ Moneta::Adapters::MongoMoped.new(db: "adapter_mongo",
12
+ collection: 'moped')
12
13
  end
13
14
 
14
15
  def load_value(value)
@@ -49,8 +50,15 @@ describe_moneta "adapter_mongo_moped" do
49
50
  it_should_behave_like 'store_large'
50
51
  it 'automatically deletes expired document' do
51
52
  store.store('key', 'val', expires: 5)
52
- store.instance_variable_get(:@collection).find('_id' => ::Moped::BSON::Binary.new(:generic, 'key')).one.should_not be_nil
53
- sleep 70 # Mongo needs up to 60 seconds
54
- store.instance_variable_get(:@collection).find('_id' => ::Moped::BSON::Binary.new(:generic, 'key')).one.should be_nil
53
+
54
+ i = 0
55
+ query = store.instance_variable_get(:@collection).find(_id: ::BSON::Binary.new('key'))
56
+ while i < 70 && query.first
57
+ i += 1
58
+ sleep 1 # Mongo needs up to 60 seconds
59
+ end
60
+
61
+ i.should be > 0 # Indicates that it took at least one sleep to expire
62
+ query.count.should == 0
55
63
  end
56
64
  end
@@ -8,7 +8,9 @@ describe_moneta "adapter_mongo_moped_with_default_expires" do
8
8
  end
9
9
 
10
10
  def new_store
11
- Moneta::Adapters::MongoMoped.new(expires: 1)
11
+ Moneta::Adapters::MongoMoped.new(db: "adapter_mongo",
12
+ collection: 'moped_with_default_expires',
13
+ expires: 1)
12
14
  end
13
15
 
14
16
  def load_value(value)
@@ -8,7 +8,8 @@ describe_moneta "adapter_mongo_official" do
8
8
  end
9
9
 
10
10
  def new_store
11
- Moneta::Adapters::MongoOfficial.new(db: "adapter_mongo")
11
+ Moneta::Adapters::MongoOfficial.new(db: "adapter_mongo",
12
+ collection: 'official')
12
13
  end
13
14
 
14
15
  def load_value(value)
@@ -49,8 +50,15 @@ describe_moneta "adapter_mongo_official" do
49
50
  it_should_behave_like 'store_large'
50
51
  it 'automatically deletes expired document' do
51
52
  store.store('key', 'val', expires: 5)
52
- store.instance_variable_get(:@collection).find_one('_id' => ::BSON::Binary.new('key')).should_not be_nil
53
- sleep 70 # Mongo needs up to 60 seconds
54
- store.instance_variable_get(:@collection).find_one('_id' => ::BSON::Binary.new('key')).should be_nil
53
+
54
+ i = 0
55
+ query = store.instance_variable_get(:@collection).find(_id: ::BSON::Binary.new('key'))
56
+ while i < 70 && query.first
57
+ i += 1
58
+ sleep 1 # Mongo needs up to 60 seconds
59
+ end
60
+
61
+ i.should be > 0 # Indicates that it took at least one sleep to expire
62
+ query.count.should == 0
55
63
  end
56
64
  end
@@ -8,7 +8,9 @@ describe_moneta "adapter_mongo_official_with_default_expires" do
8
8
  end
9
9
 
10
10
  def new_store
11
- Moneta::Adapters::MongoOfficial.new(expires: 1)
11
+ Moneta::Adapters::MongoOfficial.new(db: "adapter_mongo",
12
+ collection: 'official_with_default_expires',
13
+ expires: 1)
12
14
  end
13
15
 
14
16
  def load_value(value)
@@ -8,7 +8,8 @@ describe_moneta "adapter_mongo" do
8
8
  end
9
9
 
10
10
  def new_store
11
- Moneta::Adapters::Mongo.new(db: "adapter_mongo")
11
+ Moneta::Adapters::Mongo.new(db: "adapter_mongo",
12
+ collection: 'default')
12
13
  end
13
14
 
14
15
  def load_value(value)
@@ -8,7 +8,9 @@ describe_moneta "adapter_mongo_with_default_expires" do
8
8
  end
9
9
 
10
10
  def new_store
11
- Moneta::Adapters::Mongo.new(expires: 1)
11
+ Moneta::Adapters::Mongo.new(db: "adapter_mongo",
12
+ collection: 'with_default_expires',
13
+ expires: 1)
12
14
  end
13
15
 
14
16
  def load_value(value)
@@ -19,8 +19,8 @@ describe_moneta "mutex" do
19
19
 
20
20
  it 'should have #lock' do
21
21
  mutex = Moneta::Mutex.new(store, 'mutex')
22
- mutex.lock.should be_true
23
- mutex.locked?.should be_true
22
+ mutex.lock.should be true
23
+ mutex.locked?.should be true
24
24
  expect do
25
25
  mutex.lock
26
26
  end.to raise_error(RuntimeError)
@@ -28,13 +28,13 @@ describe_moneta "mutex" do
28
28
  mutex.try_lock
29
29
  end.to raise_error(RuntimeError)
30
30
  mutex.unlock.should be_nil
31
- mutex.locked?.should be_false
31
+ mutex.locked?.should be false
32
32
  end
33
33
 
34
34
  it 'should have #enter' do
35
35
  mutex = Moneta::Mutex.new(store, 'mutex')
36
- mutex.enter.should be_true
37
- mutex.locked?.should be_true
36
+ mutex.enter.should be true
37
+ mutex.locked?.should be true
38
38
  expect do
39
39
  mutex.enter
40
40
  end.to raise_error(RuntimeError)
@@ -42,31 +42,31 @@ describe_moneta "mutex" do
42
42
  mutex.try_enter
43
43
  end.to raise_error(RuntimeError)
44
44
  mutex.leave.should be_nil
45
- mutex.locked?.should be_false
45
+ mutex.locked?.should be false
46
46
  end
47
47
 
48
48
  it 'should lock with #lock' do
49
49
  a = Moneta::Mutex.new(store, 'mutex')
50
50
  b = Moneta::Mutex.new(store, 'mutex')
51
- a.lock.should be_true
52
- b.try_lock.should be_false
51
+ a.lock.should be true
52
+ b.try_lock.should be false
53
53
  a.unlock.should be_nil
54
54
  end
55
55
 
56
56
  it 'should have lock timeout' do
57
57
  a = Moneta::Mutex.new(store, 'mutex')
58
58
  b = Moneta::Mutex.new(store, 'mutex')
59
- a.lock.should be_true
60
- b.lock(1).should be_false
59
+ a.lock.should be true
60
+ b.lock(1).should be false
61
61
  a.unlock.should be_nil
62
62
  end
63
63
 
64
64
  it 'should have #synchronize' do
65
65
  mutex = Moneta::Mutex.new(store, 'mutex')
66
66
  mutex.synchronize do
67
- mutex.locked?.should be_true
67
+ mutex.locked?.should be true
68
68
  end
69
- mutex.locked?.should be_false
69
+ mutex.locked?.should be false
70
70
  end
71
71
 
72
72
  end
@@ -105,7 +105,7 @@ describe_moneta "optionmerger" do
105
105
  compressed_store['key'] = 'compressed value'
106
106
  store['key'].should == 'uncompressed value'
107
107
  compressed_store['key'].should == 'compressed value'
108
- store.key?('compressedkey').should be_true
108
+ store.key?('compressedkey').should be true
109
109
  # Check if value is compressed
110
110
  compressed_store['key'].should_not == store['compressedkey']
111
111
  end
@@ -19,8 +19,8 @@ describe_moneta "semaphore" do
19
19
 
20
20
  it 'should have #lock' do
21
21
  mutex = Moneta::Semaphore.new(store, 'semaphore')
22
- mutex.lock.should be_true
23
- mutex.locked?.should be_true
22
+ mutex.lock.should be true
23
+ mutex.locked?.should be true
24
24
  expect do
25
25
  mutex.lock
26
26
  end.to raise_error(RuntimeError)
@@ -28,13 +28,13 @@ describe_moneta "semaphore" do
28
28
  mutex.try_lock
29
29
  end.to raise_error(RuntimeError)
30
30
  mutex.unlock.should be_nil
31
- mutex.locked?.should be_false
31
+ mutex.locked?.should be false
32
32
  end
33
33
 
34
34
  it 'should have #enter' do
35
35
  mutex = Moneta::Semaphore.new(store, 'semaphore')
36
- mutex.enter.should be_true
37
- mutex.locked?.should be_true
36
+ mutex.enter.should be true
37
+ mutex.locked?.should be true
38
38
  expect do
39
39
  mutex.enter
40
40
  end.to raise_error(RuntimeError)
@@ -42,22 +42,22 @@ describe_moneta "semaphore" do
42
42
  mutex.try_enter
43
43
  end.to raise_error(RuntimeError)
44
44
  mutex.leave.should be_nil
45
- mutex.locked?.should be_false
45
+ mutex.locked?.should be false
46
46
  end
47
47
 
48
48
  it 'should lock with #lock' do
49
49
  a = Moneta::Semaphore.new(store, 'semaphore')
50
50
  b = Moneta::Semaphore.new(store, 'semaphore')
51
- a.lock.should be_true
52
- b.try_lock.should be_false
51
+ a.lock.should be true
52
+ b.try_lock.should be false
53
53
  a.unlock.should be_nil
54
54
  end
55
55
 
56
56
  it 'should have lock timeout' do
57
57
  a = Moneta::Semaphore.new(store, 'semaphore')
58
58
  b = Moneta::Semaphore.new(store, 'semaphore')
59
- a.lock.should be_true
60
- b.lock(1).should be_false
59
+ a.lock.should be true
60
+ b.lock(1).should be false
61
61
  a.unlock.should be_nil
62
62
  end
63
63
 
@@ -66,10 +66,10 @@ describe_moneta "semaphore" do
66
66
  b = Moneta::Semaphore.new(store, 'semaphore', 2)
67
67
  c = Moneta::Semaphore.new(store, 'semaphore', 2)
68
68
  a.synchronize do
69
- a.locked?.should be_true
69
+ a.locked?.should be true
70
70
  b.synchronize do
71
- b.locked?.should be_true
72
- c.try_lock.should be_false
71
+ b.locked?.should be true
72
+ c.try_lock.should be false
73
73
  end
74
74
  end
75
75
  end
@@ -77,9 +77,9 @@ describe_moneta "semaphore" do
77
77
  it 'should have #synchronize' do
78
78
  semaphore = Moneta::Semaphore.new(store, 'semaphore')
79
79
  semaphore.synchronize do
80
- semaphore.locked?.should be_true
80
+ semaphore.locked?.should be true
81
81
  end
82
- semaphore.locked?.should be_false
82
+ semaphore.locked?.should be false
83
83
  end
84
84
 
85
85
  end
@@ -38,7 +38,7 @@ describe_moneta "shared_tcp" do
38
38
  it 'shares values' do
39
39
  store['shared_key'] = 'shared_value'
40
40
  second = new_store
41
- second.key?('shared_key').should be_true
41
+ second.key?('shared_key').should be true
42
42
  second['shared_key'].should == 'shared_value'
43
43
  second.close
44
44
  end
@@ -38,7 +38,7 @@ describe_moneta "shared_unix" do
38
38
  it 'shares values' do
39
39
  store['shared_key'] = 'shared_value'
40
40
  second = new_store
41
- second.key?('shared_key').should be_true
41
+ second.key?('shared_key').should be true
42
42
  second['shared_key'].should == 'shared_value'
43
43
  second.close
44
44
  end
@@ -8,7 +8,7 @@ describe_moneta "standard_mongo_moped" do
8
8
  end
9
9
 
10
10
  def new_store
11
- Moneta.new(:MongoMoped, db: 'standard_mongo_moped', logger: {file: File.join(make_tempdir, 'standard_mongo_moped.log')})
11
+ Moneta.new(:MongoMoped, db: 'standard_mongo', collection: 'moped', logger: {file: File.join(make_tempdir, 'standard_mongo_moped.log')})
12
12
  end
13
13
 
14
14
  def load_value(value)
@@ -8,7 +8,7 @@ describe_moneta "standard_mongo_official" do
8
8
  end
9
9
 
10
10
  def new_store
11
- Moneta.new(:MongoOfficial, db: 'standard_mongo_official', logger: {file: File.join(make_tempdir, 'standard_mongo_official.log')})
11
+ Moneta.new(:MongoOfficial, db: 'standard_mongo', collection: 'official', logger: {file: File.join(make_tempdir, 'standard_mongo_official.log')})
12
12
  end
13
13
 
14
14
  def load_value(value)
@@ -8,7 +8,7 @@ describe_moneta "standard_mongo" do
8
8
  end
9
9
 
10
10
  def new_store
11
- Moneta.new(:Mongo, db: 'standard_mongo', logger: {file: File.join(make_tempdir, 'standard_mongo.log')})
11
+ Moneta.new(:Mongo, db: 'standard_mongo', collection: 'default', logger: {file: File.join(make_tempdir, 'standard_mongo.log')})
12
12
  end
13
13
 
14
14
  def load_value(value)