juno 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. data/README.md +2 -277
  2. data/juno.gemspec +6 -5
  3. data/lib/juno.rb +3 -122
  4. metadata +23 -307
  5. data/.gitignore +0 -6
  6. data/.travis.yml +0 -30
  7. data/Gemfile +0 -56
  8. data/LICENSE +0 -20
  9. data/Rakefile +0 -33
  10. data/SPEC.md +0 -71
  11. data/benchmarks/run.rb +0 -180
  12. data/lib/juno/adapters/activerecord.rb +0 -74
  13. data/lib/juno/adapters/cassandra.rb +0 -89
  14. data/lib/juno/adapters/cookie.rb +0 -35
  15. data/lib/juno/adapters/couch.rb +0 -57
  16. data/lib/juno/adapters/datamapper.rb +0 -76
  17. data/lib/juno/adapters/dbm.rb +0 -25
  18. data/lib/juno/adapters/file.rb +0 -60
  19. data/lib/juno/adapters/fog.rb +0 -51
  20. data/lib/juno/adapters/gdbm.rb +0 -25
  21. data/lib/juno/adapters/hbase.rb +0 -64
  22. data/lib/juno/adapters/leveldb.rb +0 -35
  23. data/lib/juno/adapters/localmemcache.rb +0 -26
  24. data/lib/juno/adapters/lruhash.rb +0 -83
  25. data/lib/juno/adapters/memcached.rb +0 -11
  26. data/lib/juno/adapters/memcached_dalli.rb +0 -51
  27. data/lib/juno/adapters/memcached_native.rb +0 -52
  28. data/lib/juno/adapters/memory.rb +0 -32
  29. data/lib/juno/adapters/mongo.rb +0 -50
  30. data/lib/juno/adapters/null.rb +0 -30
  31. data/lib/juno/adapters/pstore.rb +0 -58
  32. data/lib/juno/adapters/redis.rb +0 -56
  33. data/lib/juno/adapters/riak.rb +0 -57
  34. data/lib/juno/adapters/sdbm.rb +0 -35
  35. data/lib/juno/adapters/sequel.rb +0 -67
  36. data/lib/juno/adapters/sqlite.rb +0 -61
  37. data/lib/juno/adapters/tokyocabinet.rb +0 -41
  38. data/lib/juno/adapters/yaml.rb +0 -15
  39. data/lib/juno/base.rb +0 -62
  40. data/lib/juno/builder.rb +0 -39
  41. data/lib/juno/cache.rb +0 -78
  42. data/lib/juno/expires.rb +0 -47
  43. data/lib/juno/lock.rb +0 -44
  44. data/lib/juno/logger.rb +0 -86
  45. data/lib/juno/proxy.rb +0 -72
  46. data/lib/juno/stack.rb +0 -72
  47. data/lib/juno/transformer.rb +0 -176
  48. data/lib/juno/version.rb +0 -5
  49. data/lib/rack/cache/juno.rb +0 -93
  50. data/lib/rack/juno_cookies.rb +0 -64
  51. data/lib/rack/session/juno.rb +0 -63
  52. data/spec/generate.rb +0 -1068
  53. data/spec/helper.rb +0 -78
  54. data/spec/juno/adapter_activerecord_spec.rb +0 -27
  55. data/spec/juno/adapter_cassandra_spec.rb +0 -13
  56. data/spec/juno/adapter_cookie_spec.rb +0 -13
  57. data/spec/juno/adapter_couch_spec.rb +0 -13
  58. data/spec/juno/adapter_datamapper_spec.rb +0 -44
  59. data/spec/juno/adapter_dbm_spec.rb +0 -13
  60. data/spec/juno/adapter_file_spec.rb +0 -13
  61. data/spec/juno/adapter_fog_spec.rb +0 -18
  62. data/spec/juno/adapter_gdbm_spec.rb +0 -13
  63. data/spec/juno/adapter_hbase_spec.rb +0 -13
  64. data/spec/juno/adapter_leveldb_spec.rb +0 -13
  65. data/spec/juno/adapter_localmemcache_spec.rb +0 -13
  66. data/spec/juno/adapter_lruhash_spec.rb +0 -26
  67. data/spec/juno/adapter_memcached_dalli_spec.rb +0 -14
  68. data/spec/juno/adapter_memcached_native_spec.rb +0 -14
  69. data/spec/juno/adapter_memcached_spec.rb +0 -14
  70. data/spec/juno/adapter_memory_spec.rb +0 -34
  71. data/spec/juno/adapter_mongo_spec.rb +0 -13
  72. data/spec/juno/adapter_pstore_spec.rb +0 -16
  73. data/spec/juno/adapter_redis_spec.rb +0 -14
  74. data/spec/juno/adapter_riak_spec.rb +0 -17
  75. data/spec/juno/adapter_sdbm_spec.rb +0 -13
  76. data/spec/juno/adapter_sequel_spec.rb +0 -13
  77. data/spec/juno/adapter_sqlite_spec.rb +0 -13
  78. data/spec/juno/adapter_tokyocabinet_bdb_spec.rb +0 -13
  79. data/spec/juno/adapter_tokyocabinet_hdb_spec.rb +0 -13
  80. data/spec/juno/adapter_yaml_spec.rb +0 -16
  81. data/spec/juno/cache_file_memory_spec.rb +0 -29
  82. data/spec/juno/cache_memory_null_spec.rb +0 -18
  83. data/spec/juno/expires_file_spec.rb +0 -71
  84. data/spec/juno/expires_memory_spec.rb +0 -49
  85. data/spec/juno/lock_spec.rb +0 -37
  86. data/spec/juno/null_adapter_spec.rb +0 -22
  87. data/spec/juno/proxy_expires_memory_spec.rb +0 -51
  88. data/spec/juno/proxy_redis_spec.rb +0 -18
  89. data/spec/juno/simple_activerecord_spec.rb +0 -45
  90. data/spec/juno/simple_activerecord_with_expires_spec.rb +0 -46
  91. data/spec/juno/simple_cassandra_spec.rb +0 -46
  92. data/spec/juno/simple_couch_spec.rb +0 -45
  93. data/spec/juno/simple_couch_with_expires_spec.rb +0 -46
  94. data/spec/juno/simple_datamapper_spec.rb +0 -47
  95. data/spec/juno/simple_datamapper_with_expires_spec.rb +0 -48
  96. data/spec/juno/simple_datamapper_with_repository_spec.rb +0 -47
  97. data/spec/juno/simple_dbm_spec.rb +0 -45
  98. data/spec/juno/simple_dbm_with_expires_spec.rb +0 -46
  99. data/spec/juno/simple_file_spec.rb +0 -45
  100. data/spec/juno/simple_file_with_expires_spec.rb +0 -46
  101. data/spec/juno/simple_fog_spec.rb +0 -50
  102. data/spec/juno/simple_fog_with_expires_spec.rb +0 -52
  103. data/spec/juno/simple_gdbm_spec.rb +0 -45
  104. data/spec/juno/simple_gdbm_with_expires_spec.rb +0 -46
  105. data/spec/juno/simple_hashfile_spec.rb +0 -45
  106. data/spec/juno/simple_hashfile_with_expires_spec.rb +0 -46
  107. data/spec/juno/simple_hbase_spec.rb +0 -45
  108. data/spec/juno/simple_hbase_with_expires_spec.rb +0 -46
  109. data/spec/juno/simple_leveldb_spec.rb +0 -45
  110. data/spec/juno/simple_leveldb_with_expires_spec.rb +0 -46
  111. data/spec/juno/simple_localmemcache_spec.rb +0 -45
  112. data/spec/juno/simple_localmemcache_with_expires_spec.rb +0 -46
  113. data/spec/juno/simple_lruhash_spec.rb +0 -45
  114. data/spec/juno/simple_lruhash_with_expires_spec.rb +0 -46
  115. data/spec/juno/simple_memcached_dalli_spec.rb +0 -46
  116. data/spec/juno/simple_memcached_native_spec.rb +0 -46
  117. data/spec/juno/simple_memcached_spec.rb +0 -46
  118. data/spec/juno/simple_memory_spec.rb +0 -45
  119. data/spec/juno/simple_memory_with_compress_spec.rb +0 -45
  120. data/spec/juno/simple_memory_with_expires_spec.rb +0 -46
  121. data/spec/juno/simple_memory_with_json_key_serializer_spec.rb +0 -32
  122. data/spec/juno/simple_memory_with_json_md5_key_serializer_spec.rb +0 -32
  123. data/spec/juno/simple_memory_with_json_serializer_spec.rb +0 -22
  124. data/spec/juno/simple_memory_with_json_value_serializer_spec.rb +0 -29
  125. data/spec/juno/simple_memory_with_prefix_spec.rb +0 -45
  126. data/spec/juno/simple_memory_with_quicklz_compress_spec.rb +0 -45
  127. data/spec/juno/simple_mongo_spec.rb +0 -45
  128. data/spec/juno/simple_mongo_with_expires_spec.rb +0 -46
  129. data/spec/juno/simple_null_spec.rb +0 -32
  130. data/spec/juno/simple_pstore_spec.rb +0 -45
  131. data/spec/juno/simple_pstore_with_expires_spec.rb +0 -46
  132. data/spec/juno/simple_redis_spec.rb +0 -46
  133. data/spec/juno/simple_riak_spec.rb +0 -49
  134. data/spec/juno/simple_riak_with_expires_spec.rb +0 -50
  135. data/spec/juno/simple_sdbm_spec.rb +0 -45
  136. data/spec/juno/simple_sdbm_with_expires_spec.rb +0 -46
  137. data/spec/juno/simple_sequel_spec.rb +0 -45
  138. data/spec/juno/simple_sequel_with_expires_spec.rb +0 -46
  139. data/spec/juno/simple_sqlite_spec.rb +0 -45
  140. data/spec/juno/simple_sqlite_with_expires_spec.rb +0 -46
  141. data/spec/juno/simple_tokyocabinet_spec.rb +0 -45
  142. data/spec/juno/simple_tokyocabinet_with_expires_spec.rb +0 -46
  143. data/spec/juno/simple_yaml_spec.rb +0 -44
  144. data/spec/juno/simple_yaml_with_expires_spec.rb +0 -45
  145. data/spec/juno/stack_file_memory_spec.rb +0 -20
  146. data/spec/juno/stack_memory_file_spec.rb +0 -19
  147. data/spec/juno/transformer_bencode_spec.rb +0 -25
  148. data/spec/juno/transformer_bert_spec.rb +0 -25
  149. data/spec/juno/transformer_bson_spec.rb +0 -25
  150. data/spec/juno/transformer_bzip2_spec.rb +0 -22
  151. data/spec/juno/transformer_json_spec.rb +0 -25
  152. data/spec/juno/transformer_lzma_spec.rb +0 -22
  153. data/spec/juno/transformer_lzo_spec.rb +0 -22
  154. data/spec/juno/transformer_marshal_base64_spec.rb +0 -48
  155. data/spec/juno/transformer_marshal_escape_spec.rb +0 -48
  156. data/spec/juno/transformer_marshal_hmac_spec.rb +0 -48
  157. data/spec/juno/transformer_marshal_md5_spec.rb +0 -48
  158. data/spec/juno/transformer_marshal_md5_spread_spec.rb +0 -48
  159. data/spec/juno/transformer_marshal_prefix_spec.rb +0 -48
  160. data/spec/juno/transformer_marshal_rmd160_spec.rb +0 -48
  161. data/spec/juno/transformer_marshal_sha1_spec.rb +0 -48
  162. data/spec/juno/transformer_marshal_sha256_spec.rb +0 -48
  163. data/spec/juno/transformer_marshal_sha384_spec.rb +0 -48
  164. data/spec/juno/transformer_marshal_sha512_spec.rb +0 -48
  165. data/spec/juno/transformer_marshal_uuencode_spec.rb +0 -48
  166. data/spec/juno/transformer_msgpack_spec.rb +0 -25
  167. data/spec/juno/transformer_ox_spec.rb +0 -46
  168. data/spec/juno/transformer_quicklz_spec.rb +0 -22
  169. data/spec/juno/transformer_snappy_spec.rb +0 -22
  170. data/spec/juno/transformer_tnet_spec.rb +0 -25
  171. data/spec/juno/transformer_yaml_spec.rb +0 -46
  172. data/spec/juno/transformer_zlib_spec.rb +0 -22
  173. data/spec/junospecs.rb +0 -2284
  174. data/spec/rack/cache_juno_spec.rb +0 -355
  175. data/spec/rack/juno_cookies_spec.rb +0 -81
  176. data/spec/rack/session_juno_spec.rb +0 -305
data/lib/juno/version.rb DELETED
@@ -1,5 +0,0 @@
1
- module Juno
2
- # Juno version number
3
- # @api public
4
- VERSION = '0.3.1'
5
- end
@@ -1,93 +0,0 @@
1
- require 'juno'
2
- require 'rack/cache/key'
3
- require 'rack/cache/metastore'
4
- require 'rack/cache/entitystore'
5
-
6
- module Rack
7
- module Cache
8
- Juno = {}
9
-
10
- module JunoResolver
11
- include Rack::Utils
12
-
13
- def resolve(uri)
14
- cache = Rack::Cache::Juno[uri.to_s.sub(%r{^juno://}, '')] ||=
15
- begin
16
- options = parse_query(uri.query)
17
- options.keys.each do |key|
18
- options[key.to_sym] =
19
- case value = options.delete(key)
20
- when 'true'; true
21
- when 'false'; false
22
- else value
23
- end
24
- end
25
- ::Juno.new(uri.host.to_sym, options)
26
- end
27
- new(cache)
28
- end
29
- end
30
-
31
- class MetaStore
32
- class Juno < MetaStore
33
- extend JunoResolver
34
-
35
- def initialize(cache)
36
- @cache = cache
37
- end
38
-
39
- def read(key)
40
- @cache[key] || []
41
- end
42
-
43
- def write(key, entries)
44
- @cache[key] = entries
45
- end
46
-
47
- def purge(key)
48
- @cache.delete(key)
49
- nil
50
- end
51
- end
52
-
53
- JUNO = Juno
54
- end
55
-
56
- class EntityStore
57
- class Juno < EntityStore
58
- extend JunoResolver
59
-
60
- def initialize(cache)
61
- @cache = cache
62
- end
63
-
64
- def open(key)
65
- data = read(key)
66
- data && [data]
67
- end
68
-
69
- def exist?(key)
70
- @cache.key?(key)
71
- end
72
-
73
- def read(key)
74
- @cache[key]
75
- end
76
-
77
- def write(body, ttl = 0)
78
- buf = StringIO.new
79
- key, size = slurp(body) { |part| buf.write(part) }
80
- @cache.store(key, buf.string, ttl == 0 ? {} : {:expires => ttl})
81
- [key, size]
82
- end
83
-
84
- def purge(key)
85
- @cache.delete(key)
86
- nil
87
- end
88
- end
89
-
90
- JUNO = Juno
91
- end
92
- end
93
- end
@@ -1,64 +0,0 @@
1
- require 'juno'
2
- require 'rack/utils'
3
-
4
- module Rack
5
- # A Rack middleware that was made to reuse all juno transformers
6
- # on the cookie hash.
7
- #
8
- # @example config.ru
9
- # # Add Rack::JunoCookies somewhere in your rack stack
10
- # use Rack::JunoCookies
11
- #
12
- # run lambda { |env| [200, {}, []] }
13
- # # But this doesn't do much
14
- #
15
- # @example config.ru
16
- # # Give it some options
17
- # use Rack::JunoCookies, :domain => 'example.com', :path => '/path'
18
- #
19
- # @example config.ru
20
- # # Pass it a block like the one passed to Juno.build
21
- # use Rack::JunoCookies do
22
- # use :Transformer, :key => :prefix, :prefix => 'juno.'
23
- # adapter :Cookie
24
- # end
25
- #
26
- # run lambda do |env|
27
- # req = Rack::Request.new(env)
28
- # req.cookies #=> is now a Juno store!
29
- # env['rack.request.cookie_hash'] #=> is now a Juno store!
30
- # req.cookies['key'] #=> retrieves 'juno.key'
31
- # req.cookies['key'] = 'value' #=> sets 'juno.key'
32
- # req.cookies.delete('key') #=> removes 'juno.key'
33
- # [200, {}, []]
34
- # end
35
- #
36
- class JunoCookies
37
- def initialize(app, options = {}, &block)
38
- @app, @pool = app, []
39
- if block
40
- raise ArgumentError, 'Use either block or options' unless options.empty?
41
- @builder = Juno::Builder.new(&block)
42
- else
43
- @builder = Juno::Builder.new { adapter :Cookie, options }
44
- end
45
- end
46
-
47
- def call(env)
48
- stores = @pool.pop || @builder.build
49
- env['rack.request.cookie_hash'] = stores.last
50
- env['rack.request.cookie_string'] = env['HTTP_COOKIE']
51
- stores.first.reset(Rack::Utils.parse_query(env['HTTP_COOKIE']))
52
- status, headers, body = @app.call(env)
53
- stores.first.cookies.each do |key, cookie|
54
- if cookie == nil
55
- Rack::Utils.delete_cookie_header!(headers, key)
56
- else
57
- Rack::Utils.set_cookie_header!(headers, key, cookie)
58
- end
59
- end
60
- @pool << stores
61
- [status, headers, body]
62
- end
63
- end
64
- end
@@ -1,63 +0,0 @@
1
- require 'juno'
2
- require 'rack/session/abstract/id'
3
- require 'thread'
4
-
5
- module Rack
6
- module Session
7
- class Juno < Abstract::ID
8
- attr_reader :mutex, :pool
9
-
10
- def initialize(app, options = {}, &block)
11
- super
12
- if block
13
- raise ArgumentError, 'Use either block or option :store' if options[:store]
14
- @pool = ::Juno.build(&block)
15
- else
16
- raise ArgumentError, 'Option :store is required' unless @pool = options[:store]
17
- @pool = ::Juno.new(@pool, :expires => true) if Symbol === @pool
18
- end
19
- @mutex = Mutex.new
20
- end
21
-
22
- def generate_sid
23
- loop do
24
- sid = super
25
- break sid unless @pool.key?(sid)
26
- end
27
- end
28
-
29
- def get_session(env, sid)
30
- with_lock(env) do
31
- unless sid && session = @pool[sid]
32
- sid, session = generate_sid, {}
33
- @pool[sid] = session
34
- end
35
- [sid, session]
36
- end
37
- end
38
-
39
- def set_session(env, session_id, new_session, options)
40
- with_lock(env) do
41
- @pool.store(session_id, new_session,
42
- options[:expire_after] ? {:expires => options[:expire_after]} : {})
43
- session_id
44
- end
45
- end
46
-
47
- def destroy_session(env, session_id, options)
48
- with_lock(env) do
49
- @pool.delete(session_id)
50
- generate_sid unless options[:drop]
51
- end
52
- end
53
-
54
- def with_lock(env)
55
- @mutex.lock if env['rack.multithread']
56
- yield
57
- ensure
58
- @mutex.unlock if @mutex.locked?
59
- end
60
- end
61
- end
62
- end
63
-
data/spec/generate.rb DELETED
@@ -1,1068 +0,0 @@
1
- ADAPTER_SPECS = [:null_stringkey_stringvalue, :store_stringkey_stringvalue, :returndifferent_stringkey_stringvalue]
2
- SIMPLE_SPECS = [:null, :store, :returndifferent, :marshallable_key, :marshallable_value]
3
- EXPIRES_SPECS = SIMPLE_SPECS + [:expires_stringkey_stringvalue]
4
- header = "# Generated by #{__FILE__}\n"
5
-
6
- TESTS = {
7
- 'simple_memory' => {
8
- :store => :Memory
9
- },
10
- 'simple_memory_with_expires' => {
11
- :store => :Memory,
12
- :options => ':expires => true',
13
- :specs => EXPIRES_SPECS,
14
- },
15
- 'simple_memory_with_compress' => {
16
- :store => :Memory,
17
- :options => ':compress => true',
18
- },
19
- 'simple_memory_with_prefix' => {
20
- :store => :Memory,
21
- :options => ':prefix => "juno"',
22
- },
23
- 'simple_memory_with_json_serializer' => {
24
- :store => :Memory,
25
- :options => ':serializer => :json',
26
- :key => %w(Hash String),
27
- :value => %w(Hash String),
28
- :specs => [:null, :store, :returndifferent],
29
- },
30
- 'simple_memory_with_json_key_serializer' => {
31
- :store => :Memory,
32
- :options => ':key_serializer => :json',
33
- :key => %w(Hash String),
34
- :specs => [:null, :store, :returndifferent],
35
- },
36
- 'simple_memory_with_json_md5_key_serializer' => {
37
- :store => :Memory,
38
- :options => ':key_serializer => [:json, :md5]',
39
- :key => %w(Hash String),
40
- :specs => [:null, :store, :returndifferent],
41
- },
42
- 'simple_memory_with_json_value_serializer' => {
43
- :store => :Memory,
44
- :options => ':value_serializer => :json',
45
- :value => %w(Hash String),
46
- :specs => [:null, :store, :returndifferent, :marshallable_key],
47
- },
48
- 'simple_memory_with_quicklz_compress' => {
49
- :store => :Memory,
50
- :options => ':compress => :quicklz',
51
- },
52
- 'simple_lruhash' => {
53
- :store => :LRUHash,
54
- },
55
- 'simple_lruhash_with_expires' => {
56
- :store => :LRUHash,
57
- :options => ':expires => true',
58
- :specs => EXPIRES_SPECS,
59
- },
60
- 'simple_file' => {
61
- :store => :File,
62
- :options => ':dir => File.join(make_tempdir, "simple_file")'
63
- },
64
- 'simple_file_with_expires' => {
65
- :store => :File,
66
- :options => ':dir => File.join(make_tempdir, "simple_file_with_expires"), :expires => true',
67
- :specs => EXPIRES_SPECS
68
- },
69
- 'simple_hashfile' => {
70
- :store => :HashFile,
71
- :options => ':dir => File.join(make_tempdir, "simple_hashfile")'
72
- },
73
- 'simple_hashfile_with_expires' => {
74
- :store => :HashFile,
75
- :options => ':dir => File.join(make_tempdir, "simple_hashfile_with_expires"), :expires => true',
76
- :specs => EXPIRES_SPECS
77
- },
78
- 'simple_cassandra' => {
79
- :store => :Cassandra,
80
- :options => ':keyspace => "simple_cassandra"',
81
- :specs => EXPIRES_SPECS,
82
- },
83
- 'simple_hbase' => {
84
- :store => :HBase,
85
- :options => ':table => "simple_hbase"',
86
- },
87
- 'simple_hbase_with_expires' => {
88
- :store => :HBase,
89
- :options => ':table => "simple_hbase", :expires => true',
90
- :specs => EXPIRES_SPECS,
91
- },
92
- 'simple_dbm' => {
93
- :store => :DBM,
94
- :options => ':file => File.join(make_tempdir, "simple_dbm")'
95
- },
96
- 'simple_dbm_with_expires' => {
97
- :store => :DBM,
98
- :options => ':file => File.join(make_tempdir, "simple_dbm_with_expires"), :expires => true',
99
- :specs => EXPIRES_SPECS
100
- },
101
- 'simple_gdbm' => {
102
- :store => :GDBM,
103
- :options => ':file => File.join(make_tempdir, "simple_gdbm")'
104
- },
105
- 'simple_gdbm_with_expires' => {
106
- :store => :GDBM,
107
- :options => ':file => File.join(make_tempdir, "simple_gdbm_with_expires"), :expires => true',
108
- :specs => EXPIRES_SPECS
109
- },
110
- 'simple_sdbm' => {
111
- :store => :SDBM,
112
- :options => ':file => File.join(make_tempdir, "simple_sdbm")'
113
- },
114
- 'simple_sdbm_with_expires' => {
115
- :store => :SDBM,
116
- :options => ':file => File.join(make_tempdir, "simple_sdbm_with_expires"), :expires => true',
117
- :specs => EXPIRES_SPECS
118
- },
119
- 'simple_leveldb' => {
120
- :store => :LevelDB,
121
- :options => ':dir => File.join(make_tempdir, "simple_leveldb")'
122
- },
123
- 'simple_leveldb_with_expires' => {
124
- :store => :LevelDB,
125
- :options => ':dir => File.join(make_tempdir, "simple_leveldb_with_expires"), :expires => true',
126
- :specs => EXPIRES_SPECS
127
- },
128
- 'simple_pstore' => {
129
- :store => :PStore,
130
- :options => ':file => File.join(make_tempdir, "simple_pstore")'
131
- },
132
- 'simple_pstore_with_expires' => {
133
- :store => :PStore,
134
- :options => ':file => File.join(make_tempdir, "simple_pstore_with_expires"), :expires => true',
135
- :specs => EXPIRES_SPECS
136
- },
137
- 'simple_yaml' => {
138
- :store => :YAML,
139
- :options => ':file => File.join(make_tempdir, "simple_yaml")',
140
- :specs => [:null, :store, :returndifferent, :marshallable_key],
141
- },
142
- 'simple_yaml_with_expires' => {
143
- :store => :YAML,
144
- :options => ':file => File.join(make_tempdir, "simple_yaml_with_expires"), :expires => true',
145
- :specs => [:null, :store, :returndifferent, :marshallable_key, :expires_stringkey_stringvalue],
146
- },
147
- 'simple_localmemcache' => {
148
- :store => :LocalMemCache,
149
- :options => ':file => File.join(make_tempdir, "simple_localmemcache")'
150
- },
151
- 'simple_localmemcache_with_expires' => {
152
- :store => :LocalMemCache,
153
- :options => ':file => File.join(make_tempdir, "simple_localmemcache_with_expires"), :expires => true',
154
- :specs => EXPIRES_SPECS
155
- },
156
- 'simple_tokyocabinet' => {
157
- :store => :TokyoCabinet,
158
- :options => ':file => File.join(make_tempdir, "simple_tokyocabinet")'
159
- },
160
- 'simple_tokyocabinet_with_expires' => {
161
- :store => :TokyoCabinet,
162
- :options => ':file => File.join(make_tempdir, "simple_tokyocabinet_with_expires"), :expires => true',
163
- :specs => EXPIRES_SPECS
164
- },
165
- 'simple_sqlite' => {
166
- :store => :Sqlite,
167
- :options => ':file => File.join(make_tempdir, "simple_sqlite")'
168
- },
169
- 'simple_sqlite_with_expires' => {
170
- :store => :Sqlite,
171
- :options => ':file => File.join(make_tempdir, "simple_sqlite_with_expires"), :expires => true',
172
- :specs => EXPIRES_SPECS
173
- },
174
- 'simple_redis' => {
175
- :store => :Redis,
176
- :specs => EXPIRES_SPECS,
177
- },
178
- 'simple_memcached' => {
179
- :store => :Memcached,
180
- :specs => EXPIRES_SPECS,
181
- :options => ':namespace => "simple_memcached"'
182
- },
183
- 'simple_memcached_dalli' => {
184
- :store => :MemcachedDalli,
185
- :specs => EXPIRES_SPECS,
186
- :options => ':namespace => "simple_memcached_dalli"'
187
- },
188
- 'simple_memcached_native' => {
189
- :store => :MemcachedNative,
190
- :specs => EXPIRES_SPECS,
191
- :options => ':namespace => "simple_memcached_native"'
192
- },
193
- 'simple_riak' => {
194
- :store => :Riak,
195
- :options => ":bucket => 'simple_riak'",
196
- # We don't want Riak warnings in tests
197
- :preamble => "require 'riak'\n\nRiak.disable_list_keys_warnings = true\n\n"
198
- },
199
- 'simple_riak_with_expires' => {
200
- :store => :Riak,
201
- :options => ":bucket => 'simple_riak_with_expires', :expires => true",
202
- # We don't want Riak warnings in tests
203
- :preamble => "require 'riak'\n\nRiak.disable_list_keys_warnings = true\n\n",
204
- :specs => EXPIRES_SPECS
205
- },
206
- 'simple_couch' => {
207
- :store => :Couch,
208
- :options => ":db => 'simple_couch'"
209
- },
210
- 'simple_couch_with_expires' => {
211
- :store => :Couch,
212
- :options => ":db => 'simple_couch_with_expires', :expires => true",
213
- :specs => EXPIRES_SPECS
214
- },
215
- 'simple_mongo' => {
216
- :store => :Mongo,
217
- :options => ":db => 'simple_mongo'"
218
- },
219
- 'simple_mongo_with_expires' => {
220
- :store => :Mongo,
221
- :options => ":db => 'simple_mongo_with_expires', :expires => true",
222
- :specs => EXPIRES_SPECS
223
- },
224
- 'simple_null' => {
225
- :store => :Null,
226
- :specs => [:null, :marshallable_key, :returndifferent]
227
- },
228
- 'null_adapter' => {
229
- :build => 'Juno::Adapters::Null.new',
230
- :specs => :null
231
- },
232
- 'simple_sequel' => {
233
- :store => :Sequel,
234
- :options => ':db => (defined?(JRUBY_VERSION) ? "jdbc:sqlite:" : "sqlite:") + File.join(make_tempdir, "simple_sequel")'
235
- },
236
- 'simple_sequel_with_expires' => {
237
- :store => :Sequel,
238
- :options => ':db => (defined?(JRUBY_VERSION) ? "jdbc:sqlite:" : "sqlite:") + File.join(make_tempdir, "simple_sequel_with_expires"), :expires => true',
239
- :specs => EXPIRES_SPECS
240
- },
241
- 'simple_datamapper' => {
242
- :store => :DataMapper,
243
- :options => ':setup => "sqlite3://#{make_tempdir}/simple_datamapper"',
244
- # DataMapper needs default repository to be setup
245
- :preamble => "require 'dm-core'\nDataMapper.setup(:default, :adapter => :in_memory)\n"
246
- },
247
- 'simple_datamapper_with_expires' => {
248
- :store => :DataMapper,
249
- :options => ':setup => "sqlite3://#{make_tempdir}/simple_datamapper_with_expires", :expires => true',
250
- # DataMapper needs default repository to be setup
251
- :preamble => "require 'dm-core'\nDataMapper.setup(:default, :adapter => :in_memory)\n",
252
- :specs => EXPIRES_SPECS
253
- },
254
- 'simple_datamapper_with_repository' => {
255
- :store => :DataMapper,
256
- :options => ':repository => :repo, :setup => "sqlite3://#{make_tempdir}/simple_datamapper_with_repository"',
257
- # DataMapper needs default repository to be setup
258
- :preamble => "require 'dm-core'\nDataMapper.setup(:default, :adapter => :in_memory)\n"
259
- },
260
- 'simple_activerecord' => {
261
- :store => :ActiveRecord,
262
- :options => ":connection => { :adapter => (defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3'), :database => File.join(make_tempdir, 'simple_activerecord') }"
263
- },
264
- 'simple_activerecord_with_expires' => {
265
- :store => :ActiveRecord,
266
- :options => ":connection => { :adapter => (defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3'), :database => File.join(make_tempdir, 'simple_activerecord_with_expires') }, :expires => true",
267
- :specs => EXPIRES_SPECS
268
- },
269
- 'simple_fog' => {
270
- :store => :Fog,
271
- :options => ":aws_access_key_id => 'fake_access_key_id',
272
- :aws_secret_access_key => 'fake_secret_access_key',
273
- :provider => 'AWS',
274
- :dir => 'juno'",
275
- # Put Fog into testing mode
276
- :preamble => "require 'fog'\nFog.mock!\n"
277
- },
278
- 'simple_fog_with_expires' => {
279
- :store => :Fog,
280
- :options => ":aws_access_key_id => 'fake_access_key_id',
281
- :aws_secret_access_key => 'fake_secret_access_key',
282
- :provider => 'AWS',
283
- :dir => 'juno',
284
- :expires => true",
285
- # Put Fog into testing mode
286
- :preamble => "require 'fog'\nFog.mock!\n",
287
- :specs => EXPIRES_SPECS
288
- },
289
- 'expires_memory' => {
290
- :build => %{Juno.build do
291
- use :Expires
292
- adapter :Memory
293
- end},
294
- :specs => [:null, :store, :expires]
295
- },
296
- 'expires_file' => {
297
- :build => %{Juno.build do
298
- use :Expires
299
- use :Transformer, :key => [:marshal, :escape], :value => :marshal
300
- adapter :File, :dir => File.join(make_tempdir, "expires-file")
301
- end},
302
- :specs => [:null, :store, :expires, :returndifferent, :marshallable_key],
303
- :tests => %{
304
- it 'should delete expired value in underlying file storage' do
305
- store.store('foo', 'bar', :expires => 2)
306
- store['foo'].should == 'bar'
307
- sleep 1
308
- store['foo'].should == 'bar'
309
- sleep 2
310
- store['foo'].should == nil
311
- store.adapter['foo'].should == nil
312
- store.adapter.adapter['foo'].should == nil
313
- end
314
- }
315
- },
316
- 'proxy_redis' => {
317
- :build => %{Juno.build do
318
- use :Proxy
319
- use :Proxy
320
- adapter :Redis
321
- end},
322
- :specs => ADAPTER_SPECS + [:expires_stringkey_stringvalue]
323
- },
324
- 'proxy_expires_memory' => {
325
- :build => %{Juno.build do
326
- use :Proxy
327
- use :Expires
328
- use :Proxy
329
- adapter :Memory
330
- end},
331
- :specs => [:null, :store, :expires]
332
- },
333
- 'cache_file_memory' => {
334
- :build => %{Juno.build do
335
- use(:Cache) do
336
- backend { adapter :File, :dir => File.join(make_tempdir, "cache_file_memory") }
337
- cache { adapter :Memory }
338
- end
339
- end},
340
- :specs => ADAPTER_SPECS,
341
- :tests => %{
342
- it 'should store loaded values in cache' do
343
- store.backend['foo'] = 'bar'
344
- store.cache['foo'].should == nil
345
- store['foo'].should == 'bar'
346
- store.cache['foo'].should == 'bar'
347
- store.backend.delete('foo')
348
- store['foo'].should == 'bar'
349
- store.delete('foo')
350
- store['foo'].should == nil
351
- end
352
- }
353
- },
354
- 'cache_memory_null' => {
355
- :build => %{Juno.build do
356
- use(:Cache) do
357
- backend(Juno::Adapters::Memory.new)
358
- cache(Juno::Adapters::Null.new)
359
- end
360
- end},
361
- :specs => ADAPTER_SPECS
362
- },
363
- 'stack_file_memory' => {
364
- :build => %{Juno.build do
365
- use(:Stack) do
366
- add(Juno.new(:Null))
367
- add(Juno::Adapters::Null.new)
368
- add { adapter :File, :dir => File.join(make_tempdir, "stack-file1") }
369
- add { adapter :Memory }
370
- end
371
- end},
372
- :specs => ADAPTER_SPECS
373
- },
374
- 'stack_memory_file' => {
375
- :build => %{Juno.build do
376
- use(:Stack) do
377
- add(Juno.new(:Null))
378
- add(Juno::Adapters::Null.new)
379
- add { adapter :Memory }
380
- add { adapter :File, :dir => File.join(make_tempdir, "stack-file2") }
381
- end
382
- end},
383
- :specs => [:null_stringkey_stringvalue, :store_stringkey_stringvalue]
384
- },
385
- 'lock' => {
386
- :build => %{Juno.build do
387
- use :Lock
388
- adapter :Memory
389
- end},
390
- :specs => [:null, :store]
391
- },
392
- 'transformer_zlib' => {
393
- :build => %{Juno.build do
394
- use :Transformer, :value => :zlib
395
- adapter :Memory
396
- end},
397
- :value => %w(String),
398
- :specs => [:null, :store, :returndifferent]
399
- },
400
- 'transformer_bzip2' => {
401
- :build => %{Juno.build do
402
- use :Transformer, :value => :bzip2
403
- adapter :Memory
404
- end},
405
- :value => %w(String),
406
- :specs => [:null, :store, :returndifferent]
407
- },
408
- 'transformer_lzo' => {
409
- :build => %{Juno.build do
410
- use :Transformer, :value => :lzo
411
- adapter :Memory
412
- end},
413
- :value => %w(String),
414
- :specs => [:null, :store, :returndifferent]
415
- },
416
- 'transformer_lzma' => {
417
- :build => %{Juno.build do
418
- use :Transformer, :value => :lzma
419
- adapter :Memory
420
- end},
421
- :value => %w(String),
422
- :specs => [:null, :store, :returndifferent]
423
- },
424
- 'transformer_snappy' => {
425
- :build => %{Juno.build do
426
- use :Transformer, :value => :snappy
427
- adapter :Memory
428
- end},
429
- :value => %w(String),
430
- :specs => [:null, :store, :returndifferent]
431
- },
432
- 'transformer_quicklz' => {
433
- :build => %{Juno.build do
434
- use :Transformer, :value => :quicklz
435
- adapter :Memory
436
- end},
437
- :value => %w(String),
438
- :specs => [:null, :store, :returndifferent]
439
- },
440
- 'transformer_json' => {
441
- :build => %{Juno.build do
442
- use :Transformer, :key => :json, :value => :json
443
- adapter :Memory
444
- end},
445
- :key => %w(Hash String),
446
- :value => %w(Hash String),
447
- :specs => [:null, :store, :returndifferent]
448
- },
449
- 'transformer_bert' => {
450
- :build => %{Juno.build do
451
- use :Transformer, :key => :bert, :value => :bert
452
- adapter :Memory
453
- end},
454
- :key => %w(Hash String),
455
- :value => %w(Hash String),
456
- :specs => [:null, :store, :returndifferent]
457
- },
458
- 'transformer_bencode' => {
459
- :build => %{Juno.build do
460
- use :Transformer, :key => :bencode, :value => :bencode
461
- adapter :Memory
462
- end},
463
- :key => %w(Hash String),
464
- :value => %w(Hash String),
465
- :specs => [:null, :store, :returndifferent]
466
- },
467
- 'transformer_bson' => {
468
- :build => %{Juno.build do
469
- use :Transformer, :key => :bson, :value => :bson
470
- adapter :Memory
471
- end},
472
- :key => %w(Hash String),
473
- :value => %w(Hash String),
474
- :specs => [:null, :store, :returndifferent]
475
- },
476
- 'transformer_ox' => {
477
- :build => %{Juno.build do
478
- use :Transformer, :key => :ox, :value => :ox
479
- adapter :Memory
480
- end},
481
- :specs => [:null, :store, :returndifferent]
482
- },
483
- 'transformer_tnet' => {
484
- :build => %{Juno.build do
485
- use :Transformer, :key => :tnet, :value => :tnet
486
- adapter :Memory
487
- end},
488
- :key => %w(Hash String),
489
- :value => %w(Hash String),
490
- :specs => [:null, :store, :returndifferent]
491
- },
492
- 'transformer_msgpack' => {
493
- :build => %{Juno.build do
494
- use :Transformer, :key => :msgpack, :value => :msgpack
495
- adapter :Memory
496
- end},
497
- :key => %w(Hash String),
498
- :value => %w(Hash String),
499
- :specs => [:null, :store, :returndifferent]
500
- },
501
- 'transformer_yaml' => {
502
- :build => %{Juno.build do
503
- use :Transformer, :key => :yaml, :value => :yaml
504
- adapter :Memory
505
- end},
506
- :specs => [:null, :store, :returndifferent]
507
- },
508
- 'transformer_marshal_hmac' => {
509
- :build => %{Juno.build do
510
- use :Transformer, :key => :marshal, :value => [:marshal, :hmac], :secret => 'secret'
511
- adapter :Memory
512
- end},
513
- :specs => SIMPLE_SPECS
514
- },
515
- 'transformer_marshal_base64' => {
516
- :build => %{Juno.build do
517
- use :Transformer, :key => [:marshal, :base64], :value => [:marshal, :base64]
518
- adapter :Memory
519
- end},
520
- :specs => SIMPLE_SPECS
521
- },
522
- 'transformer_marshal_prefix' => {
523
- :build => %{Juno.build do
524
- use :Transformer, :key => [:marshal, :prefix], :value => :marshal, :prefix => 'juno'
525
- adapter :Memory
526
- end},
527
- :specs => SIMPLE_SPECS
528
- },
529
- 'transformer_marshal_uuencode' => {
530
- :build => %{Juno.build do
531
- use :Transformer, :key => [:marshal, :uuencode], :value => [:marshal, :uuencode]
532
- adapter :Memory
533
- end},
534
- :specs => SIMPLE_SPECS
535
- },
536
- 'transformer_marshal_escape' => {
537
- :build => %{Juno.build do
538
- use :Transformer, :key => [:marshal, :escape], :value => :marshal
539
- adapter :Memory
540
- end},
541
- :specs => SIMPLE_SPECS
542
- },
543
- 'transformer_marshal_md5' => {
544
- :build => %{Juno.build do
545
- use :Transformer, :key => [:marshal, :md5], :value => :marshal
546
- adapter :Memory
547
- end},
548
- :specs => SIMPLE_SPECS
549
- },
550
- 'transformer_marshal_sha1' => {
551
- :build => %{Juno.build do
552
- use :Transformer, :key => [:marshal, :sha1], :value => :marshal
553
- adapter :Memory
554
- end},
555
- :specs => SIMPLE_SPECS
556
- },
557
- 'transformer_marshal_sha256' => {
558
- :build => %{Juno.build do
559
- use :Transformer, :key => [:marshal, :sha256], :value => :marshal
560
- adapter :Memory
561
- end},
562
- :specs => SIMPLE_SPECS
563
- },
564
- 'transformer_marshal_sha384' => {
565
- :build => %{Juno.build do
566
- use :Transformer, :key => [:marshal, :sha384], :value => :marshal
567
- adapter :Memory
568
- end},
569
- :specs => SIMPLE_SPECS
570
- },
571
- 'transformer_marshal_sha512' => {
572
- :build => %{Juno.build do
573
- use :Transformer, :key => [:marshal, :sha512], :value => :marshal
574
- adapter :Memory
575
- end},
576
- :specs => SIMPLE_SPECS
577
- },
578
- 'transformer_marshal_rmd160' => {
579
- :build => %{Juno.build do
580
- use :Transformer, :key => [:marshal, :rmd160], :value => :marshal
581
- adapter :Memory
582
- end},
583
- :specs => SIMPLE_SPECS
584
- },
585
- 'transformer_marshal_md5_spread' => {
586
- :build => %{Juno.build do
587
- use :Transformer, :key => [:marshal, :md5, :spread], :value => :marshal
588
- adapter :Memory
589
- end},
590
- :specs => SIMPLE_SPECS
591
- },
592
- 'adapter_activerecord' => {
593
- :build => "Juno::Adapters::ActiveRecord.new(:connection => { :adapter => (defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3'), :database => File.join(make_tempdir, 'adapter_activerecord') })",
594
- :specs => ADAPTER_SPECS,
595
- :tests => %{
596
- it 'updates an existing key/value' do
597
- store['foo/bar'] = '1'
598
- store['foo/bar'] = '2'
599
- records = store.table.find :all, :conditions => { :k => 'foo/bar' }
600
- records.count.should == 1
601
- end
602
-
603
- it 'uses an existing connection' do
604
- ActiveRecord::Base.establish_connection :adapter => (defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3'), :database => File.join(make_tempdir, 'activerecord-existing')
605
-
606
- store = Juno::Adapters::ActiveRecord.new
607
- store.table.should be_table_exists
608
- end
609
- }
610
- },
611
- 'adapter_cassandra' => {
612
- :build => "Juno::Adapters::Cassandra.new(:keyspace => 'adapter_cassandra')",
613
- :specs => ADAPTER_SPECS
614
- },
615
- 'adapter_hbase' => {
616
- :build => "Juno::Adapters::HBase.new(:table => 'adapter_hbase')",
617
- :specs => ADAPTER_SPECS
618
- },
619
- 'adapter_cookie' => {
620
- :build => 'Juno::Adapters::Cookie.new',
621
- :specs => ADAPTER_SPECS
622
- },
623
- 'adapter_couch' => {
624
- :build => "Juno::Adapters::Couch.new(:db => 'adapter_couch')",
625
- :specs => ADAPTER_SPECS
626
- },
627
- 'adapter_datamapper' => {
628
- :build => 'Juno::Adapters::DataMapper.new(:setup => "sqlite3://#{make_tempdir}/adapter_datamapper")',
629
- # DataMapper needs default repository to be setup
630
- :preamble => "require 'dm-core'\nDataMapper.setup(:default, :adapter => :in_memory)\n",
631
- :specs => ADAPTER_SPECS,
632
- :tests => %q{
633
- it 'does not cross contaminate when storing' do
634
- first = Juno::Adapters::DataMapper.new(:setup => "sqlite3://#{make_tempdir}/datamapper-first")
635
- first.clear
636
-
637
- second = Juno::Adapters::DataMapper.new(:repository => :sample, :setup => "sqlite3://#{make_tempdir}/datamapper-second")
638
- second.clear
639
-
640
- first['key'] = 'value'
641
- second['key'] = 'value2'
642
-
643
- first['key'].should == 'value'
644
- second['key'].should == 'value2'
645
- end
646
-
647
- it 'does not cross contaminate when deleting' do
648
- first = Juno::Adapters::DataMapper.new(:setup => "sqlite3://#{make_tempdir}/datamapper-first")
649
- first.clear
650
-
651
- second = Juno::Adapters::DataMapper.new(:repository => :sample, :setup => "sqlite3://#{make_tempdir}/datamapper-second")
652
- second.clear
653
-
654
- first['key'] = 'value'
655
- second['key'] = 'value2'
656
-
657
- first.delete('key').should == 'value'
658
- first.key?('key').should == false
659
- second['key'].should == 'value2'
660
- end
661
- }
662
- },
663
- 'adapter_dbm' => {
664
- :build => 'Juno::Adapters::DBM.new(:file => File.join(make_tempdir, "adapter_dbm"))',
665
- :specs => ADAPTER_SPECS
666
- },
667
- 'adapter_file' => {
668
- :build => 'Juno::Adapters::File.new(:dir => File.join(make_tempdir, "adapter_file"))',
669
- :specs => ADAPTER_SPECS
670
- },
671
- 'adapter_fog' => {
672
- :build => "Juno::Adapters::Fog.new(:aws_access_key_id => 'fake_access_key_id',
673
- :aws_secret_access_key => 'fake_secret_access_key',
674
- :provider => 'AWS',
675
- :dir => 'juno')",
676
- # Put Fog into testing mode
677
- :preamble => "require 'fog'\nFog.mock!\n",
678
- :specs => ADAPTER_SPECS
679
- },
680
- 'adapter_gdbm' => {
681
- :build => 'Juno::Adapters::GDBM.new(:file => File.join(make_tempdir, "adapter_gdbm"))',
682
- :specs => ADAPTER_SPECS
683
- },
684
- 'adapter_localmemcache' => {
685
- :build => 'Juno::Adapters::LocalMemCache.new(:file => File.join(make_tempdir, "adapter_localmemcache"))',
686
- :specs => ADAPTER_SPECS
687
- },
688
- 'adapter_memcached_dalli' => {
689
- :build => 'Juno::Adapters::MemcachedDalli.new(:namespace => "adapter_memcached_dalli")',
690
- :specs => ADAPTER_SPECS + [:expires_stringkey_stringvalue]
691
- },
692
- 'adapter_memcached_native' => {
693
- :build => 'Juno::Adapters::MemcachedNative.new(:namespace => "adapter_memcached_native")',
694
- :specs => ADAPTER_SPECS + [:expires_stringkey_stringvalue]
695
- },
696
- 'adapter_memcached' => {
697
- :build => 'Juno::Adapters::Memcached.new(:namespace => "adapter_memcached")',
698
- :specs => ADAPTER_SPECS + [:expires_stringkey_stringvalue]
699
- },
700
- 'adapter_memory' => {
701
- :build => 'Juno::Adapters::Memory.new',
702
- :specs => [:null, :store]
703
- },
704
- 'adapter_lruhash' => {
705
- :build => 'Juno::Adapters::LRUHash.new',
706
- :specs => ADAPTER_SPECS,
707
- :tests => %{
708
- it 'should delete oldest' do
709
- store = Juno::Adapters::LRUHash.new(:max_size => 10)
710
- store[0] = 'y'
711
- (1..1000).each do |i|
712
- store[i] = 'x'
713
- store[0].should == 'y'
714
- store.instance_variable_get(:@entry).size.should == [10, i+1].min
715
- (0...[9, i-1].min).each do |j|
716
- store.instance_variable_get(:@entry)[i-j].should_not be_nil
717
- end
718
- store.key?(i-9).should be_false if i > 9
719
- end
720
- end}
721
- },
722
- 'adapter_mongo' => {
723
- :build => 'Juno::Adapters::Mongo.new(:db => "adapter_mongo")',
724
- :specs => ADAPTER_SPECS
725
- },
726
- 'adapter_pstore' => {
727
- :build => 'Juno::Adapters::PStore.new(:file => File.join(make_tempdir, "adapter_pstore"))',
728
- :specs => ADAPTER_SPECS + [:null_stringkey_objectvalue,
729
- :store_stringkey_objectvalue,
730
- :returndifferent_stringkey_objectvalue]
731
- },
732
- 'adapter_redis' => {
733
- :build => 'Juno::Adapters::Redis.new',
734
- :specs => ADAPTER_SPECS + [:expires_stringkey_stringvalue]
735
- },
736
- 'adapter_riak' => {
737
- :build => 'Juno::Adapters::Riak.new',
738
- :options => ":bucket => 'adapter_riak'",
739
- :specs => ADAPTER_SPECS,
740
- # We don't want Riak warnings in tests
741
- :preamble => "require 'riak'\n\nRiak.disable_list_keys_warnings = true\n\n"
742
- },
743
- 'adapter_sdbm' => {
744
- :build => 'Juno::Adapters::SDBM.new(:file => File.join(make_tempdir, "adapter_sdbm"))',
745
- :specs => ADAPTER_SPECS
746
- },
747
- 'adapter_leveldb' => {
748
- :build => 'Juno::Adapters::LevelDB.new(:dir => File.join(make_tempdir, "adapter_leveldb"))',
749
- :specs => ADAPTER_SPECS
750
- },
751
- 'adapter_sequel' => {
752
- :build => 'Juno::Adapters::Sequel.new(:db => (defined?(JRUBY_VERSION) ? "jdbc:sqlite:" : "sqlite:") + File.join(make_tempdir, "adapter_sequel"))',
753
- :specs => ADAPTER_SPECS
754
- },
755
- 'adapter_sqlite' => {
756
- :build => 'Juno::Adapters::Sqlite.new(:file => File.join(make_tempdir, "adapter_sqlite"))',
757
- :specs => ADAPTER_SPECS
758
- },
759
- 'adapter_tokyocabinet_bdb' => {
760
- :build => 'Juno::Adapters::TokyoCabinet.new(:file => File.join(make_tempdir, "adapter_tokyocabinet_bdb"), :type => :bdb)',
761
- :specs => ADAPTER_SPECS
762
- },
763
- 'adapter_tokyocabinet_hdb' => {
764
- :build => 'Juno::Adapters::TokyoCabinet.new(:file => File.join(make_tempdir, "adapter_tokyocabinet_hdb"), :type => :hdb)',
765
- :specs => ADAPTER_SPECS
766
- },
767
- 'adapter_yaml' => {
768
- :build => 'Juno::Adapters::YAML.new(:file => File.join(make_tempdir, "adapter_yaml"))',
769
- :specs => ADAPTER_SPECS + [:null_stringkey_objectvalue,
770
- :store_stringkey_objectvalue,
771
- :returndifferent_stringkey_objectvalue]
772
- },
773
- }
774
-
775
- SPECS = {}
776
-
777
- KEYS = {
778
- 'String' => ['strkey1', 'strkey2'].map(&:inspect),
779
- 'Object' => ['Value.new(:objkey1)', 'Value.new(:objkey2)'],
780
- 'Hash' => [{'hashkey1' => 'hashkey2'}, {'hashkey3' => 'hashkey4'}].map(&:inspect)
781
- }
782
-
783
- VALUES = {
784
- 'Boolean' => [true, false],
785
- 'String' => ['strval1', 'strval2'].map(&:inspect),
786
- 'Hash' => [{'hashval1' => ['array1', 1]}, {'hashval3' => ['array2', {'hashval4' => 42}]}].map(&:inspect),
787
- 'Object' => ['Value.new(:objval1)', 'Value.new(:objval2)'],
788
- }
789
-
790
- KEYS.each do |key_type, (key1,key2)|
791
- VALUES.each do |val_type, (val1,val2)|
792
-
793
- code = %{it "reads from keys that are #{key_type}s like a Hash" do
794
- store[#{key1}].should == nil
795
- store.load(#{key1}).should == nil
796
- end
797
-
798
- it "guarantees that the same #{val_type} value is returned when setting a #{key_type} key" do
799
- value = #{val1}
800
- (store[#{key1}] = value).should equal(value)
801
- end
802
-
803
- it "returns false from key? if a #{key_type} key is not available" do
804
- store.key?(#{key1}).should == false
805
- end
806
-
807
- it "returns nil from delete if an element for a #{key_type} key does not exist" do
808
- store.delete(#{key1}).should == nil
809
- end
810
-
811
- it "removes all #{key_type} keys from the store with clear" do
812
- store[#{key1}] = #{val1}
813
- store[#{key2}] = #{val2}
814
- store.clear.should equal(store)
815
- store.key?(#{key1}).should_not == true
816
- store.key?(#{key2}).should_not == true
817
- end
818
-
819
- it "fetches a #{key_type} key with a default value with fetch, if the key is not available" do
820
- store.fetch(#{key1}, #{val1}).should == #{val1}
821
- end
822
-
823
- it "fetches a #{key_type} key with a block with fetch, if the key is not available" do
824
- key = #{key1}
825
- value = #{val1}
826
- store.fetch(key) do |k|
827
- k.should equal(key)
828
- value
829
- end.should equal(value)
830
- end
831
-
832
- it 'should accept options' do
833
- store.key?(#{key1}, :option1 => 1).should == false
834
- store.load(#{key1}, :option2 => 2).should == nil
835
- store.fetch(#{key1}, 42, :option3 => 3).should == 42
836
- store.fetch(#{key1}, :option3 => 3) { 42 }.should == 42
837
- store.delete(#{key1}, :option4 => 4).should == nil
838
- store.clear(:option5 => 5).should equal(store)
839
- store.store(#{key1}, #{val1}, :option6 => 6).should == #{val1}
840
- end}
841
- SPECS["null_#{key_type.downcase}key_#{val_type.downcase}value"] = code
842
-
843
- code = %{it "writes #{val_type} values to keys that are #{key_type}s like a Hash" do
844
- store[#{key1}] = #{val1}
845
- store[#{key1}].should == #{val1}
846
- store.load(#{key1}).should == #{val1}
847
- end
848
-
849
- it "returns true from key? if a #{key_type} key is available" do
850
- store[#{key1}] = #{val1}
851
- store.key?(#{key1}).should == true
852
- store[#{key2}] = #{val2}
853
- store.key?(#{key2}).should == true
854
- end
855
-
856
- it "stores #{val_type} values with #{key_type} keys with #store" do
857
- value = #{val1}
858
- store.store(#{key1}, value).should equal(value)
859
- store[#{key1}].should == #{val1}
860
- store.load(#{key1}).should == #{val1}
861
- end
862
-
863
- it "removes and returns a #{val_type} element with a #{key_type} key from the backing store via delete if it exists" do
864
- store[#{key1}] = #{val1}
865
- store.delete(#{key1}).should == #{val1}
866
- store.key?(#{key1}).should == false
867
- end
868
-
869
- it "overwrites existing #{val_type} values with #{key_type}" do
870
- store[#{key1}] = #{val1}
871
- store[#{key1}].should == #{val1}
872
- store[#{key1}] = #{val2}
873
- store[#{key1}].should == #{val2}
874
- end
875
-
876
- it "does not run the block if the #{key_type} key is available" do
877
- store[#{key1}] = #{val1}
878
- unaltered = "unaltered"
879
- store.fetch(#{key1}) { unaltered = "altered" }
880
- unaltered.should == "unaltered"
881
- end
882
-
883
- it "fetches a #{key_type} key with a default value with fetch, if the key is available" do
884
- store[#{key1}] = #{val1}
885
- store.fetch(#{key1}, #{val2}).should == #{val1}
886
- end}
887
- SPECS["store_#{key_type.downcase}key_#{val_type.downcase}value"] = code
888
-
889
- code = %{it "guarantees that a different #{val_type} value is retrieved from the #{key_type} key" do
890
- value = #{val1}
891
- store[#{key1}] = #{val1}
892
- store[#{key1}].should_not be_equal(#{val1})
893
- end}
894
- if val_type != 'Boolean'
895
- SPECS["returndifferent_#{key_type.downcase}key_#{val_type.downcase}value"] = code
896
- end
897
-
898
- code = %{it 'should support expires on store and #[]' do
899
- store.store(#{key1}, #{val1}, :expires => 2)
900
- store[#{key1}].should == #{val1}
901
- sleep 1
902
- store[#{key1}].should == #{val1}
903
- sleep 2
904
- store[#{key1}].should == nil
905
- end
906
-
907
- it 'should support expires on store and load' do
908
- store.store(#{key1}, #{val1}, :expires => 2)
909
- store.load(#{key1}).should == #{val1}
910
- sleep 1
911
- store.load(#{key1}).should == #{val1}
912
- sleep 2
913
- store.load(#{key1}).should == nil
914
- end
915
-
916
- it 'should support expires on store and key?' do
917
- store.store(#{key1}, #{val1}, :expires => 2)
918
- store.key?(#{key1}).should == true
919
- sleep 1
920
- store.key?(#{key1}).should == true
921
- sleep 2
922
- store.key?(#{key1}).should == false
923
- end
924
-
925
- it 'should support updating the expiration time in load' do
926
- store.store(#{key2}, #{val2}, :expires => 2)
927
- store[#{key2}].should == #{val2}
928
- sleep 1
929
- store.load(#{key2}, :expires => 3).should == #{val2}
930
- store[#{key2}].should == #{val2}
931
- sleep 1
932
- store[#{key2}].should == #{val2}
933
- sleep 3
934
- store[#{key2}].should == nil
935
- end
936
-
937
- it 'should support updating the expiration time in key?' do
938
- store.store(#{key2}, #{val2}, :expires => 2)
939
- store[#{key2}].should == #{val2}
940
- sleep 1
941
- store.key?(#{key2}, :expires => 3).should be_true
942
- store[#{key2}].should == #{val2}
943
- sleep 1
944
- store[#{key2}].should == #{val2}
945
- sleep 3
946
- store[#{key2}].should == nil
947
- end
948
-
949
- it 'should support updating the expiration time in fetch' do
950
- store.store(#{key1}, #{val1}, :expires => 2)
951
- store[#{key1}].should == #{val1}
952
- sleep 1
953
- store.fetch(#{key1}, nil, :expires => 3).should == #{val1}
954
- store[#{key1}].should == #{val1}
955
- sleep 1
956
- store[#{key1}].should == #{val1}
957
- sleep 3
958
- store[#{key1}].should == nil
959
- end
960
-
961
- it 'should respect expires in delete' do
962
- store.store(#{key2}, #{val2}, :expires => 2)
963
- store[#{key2}].should == #{val2}
964
- sleep 1
965
- store[#{key2}].should == #{val2}
966
- sleep 2
967
- store.delete(#{key2}).should == nil
968
- end}
969
- SPECS["expires_#{key_type.downcase}key_#{val_type.downcase}value"] = code
970
-
971
- end
972
- end
973
-
974
- SPECS['marshallable_key'] = %{it 'refuses to #[] from keys that cannot be marshalled' do
975
- expect do
976
- store[Struct.new(:foo).new(:bar)]
977
- end.to raise_error(marshal_error)
978
- end
979
-
980
- it 'refuses to load from keys that cannot be marshalled' do
981
- expect do
982
- store.load(Struct.new(:foo).new(:bar))
983
- end.to raise_error(marshal_error)
984
- end
985
-
986
- it 'refuses to fetch from keys that cannot be marshalled' do
987
- expect do
988
- store.fetch(Struct.new(:foo).new(:bar), true)
989
- end.to raise_error(marshal_error)
990
- end
991
-
992
- it 'refuses to #[]= to keys that cannot be marshalled' do
993
- expect do
994
- store[Struct.new(:foo).new(:bar)] = 'value'
995
- end.to raise_error(marshal_error)
996
- end
997
-
998
- it 'refuses to store to keys that cannot be marshalled' do
999
- expect do
1000
- store.store Struct.new(:foo).new(:bar), 'value'
1001
- end.to raise_error(marshal_error)
1002
- end
1003
-
1004
- it 'refuses to check for key? if the key cannot be marshalled' do
1005
- expect do
1006
- store.key? Struct.new(:foo).new(:bar)
1007
- end.to raise_error(marshal_error)
1008
- end
1009
-
1010
- it 'refuses to delete a key if the key cannot be marshalled' do
1011
- expect do
1012
- store.delete Struct.new(:foo).new(:bar)
1013
- end.to raise_error(marshal_error)
1014
- end}
1015
-
1016
- SPECS['marshallable_value'] = %{it 'refuses to store values that cannot be marshalled' do
1017
- expect do
1018
- store.store 'key', Struct.new(:foo).new(:bar)
1019
- end.to raise_error(marshal_error)
1020
- end}
1021
-
1022
- specs_code = "#{header}\n"
1023
- SPECS.each do |key, code|
1024
- specs_code << "#################### #{key} ####################\n\n" <<
1025
- "shared_examples_for '#{key}' do\n " << code.gsub("\n", "\n ") << "\nend\n\n"
1026
- end
1027
- specs_code.gsub!(/\n +\n/, "\n\n")
1028
- File.open(File.join(File.dirname(__FILE__), 'junospecs.rb'), 'w') {|out| out << specs_code }
1029
-
1030
- TESTS.each do |name, options|
1031
- build = options.delete(:build)
1032
- store = options.delete(:store)
1033
- key = [options.delete(:key) || %w(Object String Hash)].flatten
1034
- value = [options.delete(:value) || %w(Object String Hash Boolean)].flatten
1035
-
1036
- specs = [options.delete(:specs) || SIMPLE_SPECS].flatten
1037
- specs_code = []
1038
- specs.each do |s|
1039
- specs_code << " it_should_behave_like '#{s}'" if SPECS[s.to_s]
1040
- key.each do |k|
1041
- value.each do |v|
1042
- x = "#{s}_#{k.downcase}key_#{v.downcase}value"
1043
- specs_code << " it_should_behave_like '#{x}'" if SPECS[x]
1044
- end
1045
- end
1046
- end
1047
-
1048
- preamble = options.delete(:preamble).to_s.gsub("\n", "\n ")
1049
- opts = options.delete(:options)
1050
- opts = ', ' << opts if opts
1051
-
1052
- build ||= "Juno.new(#{store.inspect}#{opts}, :logger => {:out => File.open(File.join(make_tempdir, '#{name}.log'), 'a')})"
1053
-
1054
- code = %{#{header}require 'helper'
1055
-
1056
- describe_juno #{name.inspect} do
1057
- #{preamble}def new_store
1058
- #{build.gsub("\n", "\n ")}
1059
- end
1060
-
1061
- include_context 'setup_store'
1062
- #{specs_code.join("\n")}#{options[:tests].to_s.gsub("\n", "\n ")}
1063
- end
1064
- }
1065
-
1066
- code.gsub!(/\n +\n/, "\n\n")
1067
- File.open(File.join(File.dirname(__FILE__), 'juno', "#{name}_spec.rb"), 'w') {|out| out << code }
1068
- end