moneta 0.7.17 → 0.7.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +15 -9
  4. data/CHANGES +12 -1
  5. data/CONTRIBUTORS +2 -2
  6. data/Gemfile +3 -0
  7. data/README.md +30 -5
  8. data/Rakefile +1 -1
  9. data/lib/active_support/cache/moneta_store.rb +5 -2
  10. data/lib/moneta/adapters/couch.rb +63 -5
  11. data/lib/moneta/adapters/file.rb +29 -12
  12. data/lib/moneta/adapters/fog.rb +1 -0
  13. data/lib/moneta/adapters/mongo.rb +74 -22
  14. data/lib/moneta/adapters/sqlite.rb +6 -5
  15. data/lib/moneta/pool.rb +28 -5
  16. data/lib/moneta/transformer/config.rb +37 -34
  17. data/lib/moneta/version.rb +1 -1
  18. data/script/contributors +7 -0
  19. data/script/generate-specs +89 -30
  20. data/script/install-bundle +1 -1
  21. data/script/start-services +6 -12
  22. data/script/wait-services +15 -0
  23. data/spec/active_support/cache_moneta_store_spec.rb +3 -3
  24. data/spec/moneta/adapter_couch_spec.rb +14 -6
  25. data/spec/moneta/adapter_memory_spec.rb +29 -0
  26. data/spec/moneta/adapter_mongo_spec.rb +7 -0
  27. data/spec/moneta/adapter_mongo_with_default_expires_spec.rb +7 -0
  28. data/spec/moneta/adapter_pstore_spec.rb +42 -0
  29. data/spec/moneta/expires_file_spec.rb +4 -0
  30. data/spec/moneta/expires_memory_spec.rb +29 -0
  31. data/spec/moneta/expires_memory_with_default_expires_spec.rb +29 -0
  32. data/spec/moneta/lock_spec.rb +29 -0
  33. data/spec/moneta/null_adapter_spec.rb +13 -0
  34. data/spec/moneta/proxy_expires_memory_spec.rb +29 -0
  35. data/spec/moneta/simple_activerecord_spec.rb +42 -0
  36. data/spec/moneta/simple_activerecord_with_expires_spec.rb +42 -0
  37. data/spec/moneta/simple_cassandra_spec.rb +42 -0
  38. data/spec/moneta/simple_client_tcp_spec.rb +42 -0
  39. data/spec/moneta/simple_client_unix_spec.rb +42 -0
  40. data/spec/moneta/simple_couch_spec.rb +45 -2
  41. data/spec/moneta/simple_couch_with_expires_spec.rb +46 -2
  42. data/spec/moneta/simple_datamapper_spec.rb +42 -0
  43. data/spec/moneta/simple_datamapper_with_expires_spec.rb +42 -0
  44. data/spec/moneta/simple_datamapper_with_repository_spec.rb +42 -0
  45. data/spec/moneta/simple_daybreak_spec.rb +42 -0
  46. data/spec/moneta/simple_daybreak_with_expires_spec.rb +42 -0
  47. data/spec/moneta/simple_dbm_spec.rb +42 -0
  48. data/spec/moneta/simple_dbm_with_expires_spec.rb +42 -0
  49. data/spec/moneta/simple_file_spec.rb +42 -0
  50. data/spec/moneta/simple_file_with_expires_spec.rb +42 -0
  51. data/spec/moneta/simple_fog_spec.rb +42 -0
  52. data/spec/moneta/simple_fog_with_expires_spec.rb +42 -0
  53. data/spec/moneta/simple_gdbm_spec.rb +42 -0
  54. data/spec/moneta/simple_gdbm_with_expires_spec.rb +42 -0
  55. data/spec/moneta/simple_hashfile_spec.rb +42 -0
  56. data/spec/moneta/simple_hashfile_with_expires_spec.rb +42 -0
  57. data/spec/moneta/simple_hbase_spec.rb +42 -0
  58. data/spec/moneta/simple_hbase_with_expires_spec.rb +42 -0
  59. data/spec/moneta/simple_kyotocabinet_spec.rb +42 -0
  60. data/spec/moneta/simple_kyotocabinet_with_expires_spec.rb +42 -0
  61. data/spec/moneta/simple_leveldb_spec.rb +42 -0
  62. data/spec/moneta/simple_leveldb_with_expires_spec.rb +42 -0
  63. data/spec/moneta/simple_localmemcache_spec.rb +42 -0
  64. data/spec/moneta/simple_localmemcache_with_expires_spec.rb +42 -0
  65. data/spec/moneta/simple_lruhash_spec.rb +29 -0
  66. data/spec/moneta/simple_lruhash_with_expires_spec.rb +29 -0
  67. data/spec/moneta/simple_memcached_dalli_spec.rb +42 -0
  68. data/spec/moneta/simple_memcached_native_spec.rb +42 -0
  69. data/spec/moneta/simple_memcached_spec.rb +42 -0
  70. data/spec/moneta/simple_memory_spec.rb +29 -0
  71. data/spec/moneta/simple_memory_with_compress_spec.rb +29 -0
  72. data/spec/moneta/simple_memory_with_expires_spec.rb +29 -0
  73. data/spec/moneta/simple_memory_with_json_key_serializer_spec.rb +6 -0
  74. data/spec/moneta/simple_memory_with_json_value_serializer_spec.rb +8 -0
  75. data/spec/moneta/simple_memory_with_prefix_spec.rb +29 -0
  76. data/spec/moneta/simple_memory_with_snappy_compress_spec.rb +29 -0
  77. data/spec/moneta/simple_mongo_spec.rb +42 -0
  78. data/spec/moneta/simple_null_spec.rb +16 -0
  79. data/spec/moneta/simple_pstore_spec.rb +42 -0
  80. data/spec/moneta/simple_pstore_with_expires_spec.rb +42 -0
  81. data/spec/moneta/simple_redis_spec.rb +42 -0
  82. data/spec/moneta/simple_restclient_spec.rb +42 -0
  83. data/spec/moneta/simple_riak_spec.rb +42 -0
  84. data/spec/moneta/simple_riak_with_expires_spec.rb +42 -0
  85. data/spec/moneta/simple_sdbm_spec.rb +42 -0
  86. data/spec/moneta/simple_sdbm_with_expires_spec.rb +42 -0
  87. data/spec/moneta/simple_sequel_spec.rb +42 -0
  88. data/spec/moneta/simple_sequel_with_expires_spec.rb +42 -0
  89. data/spec/moneta/simple_sqlite_spec.rb +42 -0
  90. data/spec/moneta/simple_sqlite_with_expires_spec.rb +42 -0
  91. data/spec/moneta/simple_tdb_spec.rb +42 -0
  92. data/spec/moneta/simple_tdb_with_expires_spec.rb +42 -0
  93. data/spec/moneta/simple_tokyocabinet_spec.rb +42 -0
  94. data/spec/moneta/simple_tokyocabinet_with_expires_spec.rb +42 -0
  95. data/spec/moneta/simple_tokyotyrant_spec.rb +42 -0
  96. data/spec/moneta/simple_tokyotyrant_with_expires_spec.rb +42 -0
  97. data/spec/moneta/simple_yaml_spec.rb +42 -0
  98. data/spec/moneta/simple_yaml_with_expires_spec.rb +42 -0
  99. data/spec/moneta/transformer_bzip2_spec.rb +3 -0
  100. data/spec/moneta/transformer_key_inspect_spec.rb +6 -0
  101. data/spec/moneta/transformer_key_marshal_spec.rb +29 -0
  102. data/spec/moneta/transformer_key_to_s_spec.rb +6 -0
  103. data/spec/moneta/transformer_key_yaml_spec.rb +29 -0
  104. data/spec/moneta/transformer_lz4_spec.rb +3 -0
  105. data/spec/moneta/transformer_lzma_spec.rb +3 -0
  106. data/spec/moneta/transformer_lzo_spec.rb +3 -0
  107. data/spec/moneta/transformer_marshal_base64_spec.rb +29 -0
  108. data/spec/moneta/transformer_marshal_city128_spec.rb +152 -0
  109. data/spec/moneta/transformer_marshal_city32_spec.rb +152 -0
  110. data/spec/moneta/transformer_marshal_city64_spec.rb +152 -0
  111. data/spec/moneta/transformer_marshal_escape_spec.rb +29 -0
  112. data/spec/moneta/transformer_marshal_hmac_spec.rb +29 -0
  113. data/spec/moneta/transformer_marshal_md5_spec.rb +29 -0
  114. data/spec/moneta/transformer_marshal_md5_spread_spec.rb +29 -0
  115. data/spec/moneta/transformer_marshal_prefix_spec.rb +29 -0
  116. data/spec/moneta/transformer_marshal_qp_spec.rb +29 -0
  117. data/spec/moneta/transformer_marshal_rmd160_spec.rb +29 -0
  118. data/spec/moneta/transformer_marshal_sha1_spec.rb +29 -0
  119. data/spec/moneta/transformer_marshal_sha256_spec.rb +29 -0
  120. data/spec/moneta/transformer_marshal_sha384_spec.rb +29 -0
  121. data/spec/moneta/transformer_marshal_sha512_spec.rb +29 -0
  122. data/spec/moneta/transformer_marshal_spec.rb +29 -0
  123. data/spec/moneta/transformer_marshal_truncate_spec.rb +29 -0
  124. data/spec/moneta/transformer_marshal_uuencode_spec.rb +29 -0
  125. data/spec/moneta/transformer_ox_spec.rb +29 -0
  126. data/spec/moneta/transformer_quicklz_spec.rb +3 -0
  127. data/spec/moneta/transformer_snappy_spec.rb +3 -0
  128. data/spec/moneta/transformer_value_marshal_spec.rb +29 -0
  129. data/spec/moneta/transformer_value_yaml_spec.rb +29 -0
  130. data/spec/moneta/transformer_yaml_spec.rb +29 -0
  131. data/spec/moneta/transformer_zlib_spec.rb +3 -0
  132. data/spec/moneta/weak_create_spec.rb +2 -1
  133. data/spec/moneta/weak_increment_spec.rb +2 -1
  134. data/spec/monetaspecs.rb +29879 -6167
  135. metadata +10 -2
@@ -26,16 +26,17 @@ module Moneta
26
26
  @backend.busy_timeout(options[:busy_timeout] || 1000)
27
27
  @backend.execute("create table if not exists #{table} (k blob not null primary key, v blob)")
28
28
  @stmts =
29
- [@select = @backend.prepare("select v from #{table} where k = ?"),
29
+ [@exists = @backend.prepare("select exists(select 1 from #{table} where k = ?)"),
30
+ @select = @backend.prepare("select v from #{table} where k = ?"),
30
31
  @replace = @backend.prepare("replace into #{table} values (?, ?)"),
31
- @delete = @backend.prepare("delete from #{table} where k = ?"),
32
- @clear = @backend.prepare("delete from #{table}"),
33
- @create = @backend.prepare("insert into #{table} values (?, ?)")]
32
+ @delete = @backend.prepare("delete from #{table} where k = ?"),
33
+ @clear = @backend.prepare("delete from #{table}"),
34
+ @create = @backend.prepare("insert into #{table} values (?, ?)")]
34
35
  end
35
36
 
36
37
  # (see Proxy#key?)
37
38
  def key?(key, options = {})
38
- !@select.execute!(key).empty?
39
+ @exists.execute!(key).first.first.to_i == 1
39
40
  end
40
41
 
41
42
  # (see Proxy#load)
@@ -1,3 +1,5 @@
1
+ require 'thread'
2
+
1
3
  module Moneta
2
4
  # Creates a pool of stores.
3
5
  # Each thread gets its own store.
@@ -14,24 +16,45 @@ module Moneta
14
16
  class Pool < Wrapper
15
17
  # @param [Moneta store] adapter The underlying store
16
18
  # @param [Hash] options
19
+ # @option options [String] :mutex (::Mutex.new) Mutex object
17
20
  def initialize(options = {}, &block)
18
21
  super(nil)
22
+ @mutex = options[:mutex] || ::Mutex.new
23
+ @id = "Moneta::Pool(#{object_id})"
19
24
  @builder = Builder.new(&block)
20
- @pool, @active = [], {}
25
+ @pool, @all = [], []
26
+ end
27
+
28
+ def close
29
+ @mutex.synchronize do
30
+ raise '#close can only when no thread is using the pool' if @all.size != @pool.size
31
+ @all.each(&:close)
32
+ @all = @pool = nil
33
+ end
21
34
  end
22
35
 
23
36
  protected
24
37
 
25
38
  def adapter
26
- @active[Thread.current]
39
+ Thread.current[@id]
27
40
  end
28
41
 
29
42
  def wrap(*args)
30
- @pool << @builder.build.last if @pool.empty?
31
- @active[Thread.current] = @pool.pop
43
+ store = Thread.current[@id] = pop
32
44
  yield
33
45
  ensure
34
- @pool << @active.delete(Thread.current)
46
+ Thread.current[@id] = nil
47
+ @mutex.synchronize { @pool << store }
48
+ end
49
+
50
+ def pop
51
+ if @mutex.synchronize { @pool.empty? }
52
+ store = @builder.build.last
53
+ @mutex.synchronize { @all << store }
54
+ store
55
+ else
56
+ @mutex.synchronize { @pool.pop }
57
+ end
35
58
  end
36
59
  end
37
60
  end
@@ -2,42 +2,45 @@ module Moneta
2
2
  class Transformer
3
3
  # Available key/value transformers
4
4
  TRANSFORMER = {
5
- # Name => [ Type, Load, Dump, Library ],
6
- :bencode => [ :serialize, '::BEncode.load(%s)', '::BEncode.dump(%s)', 'bencode' ],
7
- :bert => [ :serialize, '::BERT.decode(%s)', '::BERT.encode(%s)', 'bert' ],
8
- :bson => [ :serialize, "::BSON.deserialize(%s)['v']", "::BSON.serialize('v'=>%s).to_s", 'bson' ],
9
- :json => [ :serialize, '::MultiJson.load(%s).first', '::MultiJson.dump([%s])', 'multi_json' ],
10
- :marshal => [ :serialize, '::Marshal.load(%s)', '::Marshal.dump(%s)' ],
11
- :msgpack => [ :serialize, '::MessagePack.unpack(%s)', '::MessagePack.pack(%s)', 'msgpack' ],
12
- :ox => [ :serialize, '::Ox.parse_obj(%s)', '::Ox.dump(%s)', 'ox' ],
13
- :tnet => [ :serialize, '::TNetstring.parse(%s).first', '::TNetstring.dump(%s)', 'tnetstring' ],
14
- :yaml => [ :serialize, '::YAML.load(%s)', '::YAML.dump(%s)', 'yaml' ],
15
- :bzip2 => [ :compress, '::Bzip2.uncompress(%s)', '::Bzip2.compress(%s)', 'bzip2' ],
16
- :lz4 => [ :compress, '::LZ4.uncompress(%s)', '::LZ4.compress(%s)', 'lz4-ruby' ],
17
- :lzma => [ :compress, '::LZMA.decompress(%s)', '::LZMA.compress(%s)', 'lzma' ],
18
- :lzo => [ :compress, '::LZO.decompress(%s)', '::LZO.compress(%s)', 'lzoruby' ],
19
- :snappy => [ :compress, '::Snappy.inflate(%s)', '::Snappy.deflate(%s)', 'snappy' ],
20
- :quicklz => [ :compress, '::QuickLZ.decompress(%s)', '::QuickLZ.compress(%s)', 'qlzruby' ],
21
- :zlib => [ :compress, '::Zlib::Inflate.inflate(%s)', '::Zlib::Deflate.deflate(%s)', 'zlib' ],
22
- :qp => [ :encode, "%s.unpack('M').first", "[%s].pack('M')" ],
23
- :uuencode => [ :encode, "%s.unpack('u').first", "[%s].pack('u')" ],
5
+ # Name => [ Type, Load, Dump, Library ],
6
+ :bencode => [ :serialize, '::BEncode.load(%s)', '::BEncode.dump(%s)', 'bencode' ],
7
+ :bert => [ :serialize, '::BERT.decode(%s)', '::BERT.encode(%s)', 'bert' ],
8
+ :bson => [ :serialize, "::BSON.deserialize(%s)['v']", "::BSON.serialize('v'=>%s).to_s", 'bson' ],
9
+ :json => [ :serialize, '::MultiJson.load(%s).first', '::MultiJson.dump([%s])', 'multi_json' ],
10
+ :marshal => [ :serialize, '::Marshal.load(%s)', '::Marshal.dump(%s)' ],
11
+ :msgpack => [ :serialize, '::MessagePack.unpack(%s)', '::MessagePack.pack(%s)', 'msgpack' ],
12
+ :ox => [ :serialize, '::Ox.parse_obj(%s)', '::Ox.dump(%s)', 'ox' ],
13
+ :tnet => [ :serialize, '::TNetstring.parse(%s).first', '::TNetstring.dump(%s)', 'tnetstring' ],
14
+ :yaml => [ :serialize, '::YAML.load(%s)', '::YAML.dump(%s)', 'yaml' ],
15
+ :bzip2 => [ :compress, '::Bzip2.uncompress(%s)', '::Bzip2.compress(%s)', 'bzip2' ],
16
+ :lz4 => [ :compress, '::LZ4.uncompress(%s)', '::LZ4.compress(%s)', 'lz4-ruby' ],
17
+ :lzma => [ :compress, '::LZMA.decompress(%s)', '::LZMA.compress(%s)', 'lzma' ],
18
+ :lzo => [ :compress, '::LZO.decompress(%s)', '::LZO.compress(%s)', 'lzoruby' ],
19
+ :snappy => [ :compress, '::Snappy.inflate(%s)', '::Snappy.deflate(%s)', 'snappy' ],
20
+ :quicklz => [ :compress, '::QuickLZ.decompress(%s)', '::QuickLZ.compress(%s)', 'qlzruby' ],
21
+ :zlib => [ :compress, '::Zlib::Inflate.inflate(%s)', '::Zlib::Deflate.deflate(%s)', 'zlib' ],
22
+ :qp => [ :encode, "%s.unpack('M').first", "[%s].pack('M')" ],
23
+ :uuencode => [ :encode, "%s.unpack('u').first", "[%s].pack('u')" ],
24
24
  :base64 => RUBY_VERSION > '1.9' ?
25
- [ :encode, "%s.unpack('m0').first", "[%s].pack('m0')" ] :
26
- [ :encode, "%s.unpack('m').first", "[%s].pack('m').gsub(\"\n\", '')" ],
27
- :escape => [ :encode, 'Helper.unescape(%s)', 'Helper.escape(%s)' ],
25
+ [ :encode, "%s.unpack('m0').first", "[%s].pack('m0')" ] :
26
+ [ :encode, "%s.unpack('m').first", "[%s].pack('m').gsub(\"\n\", '')" ],
27
+ :escape => [ :encode, 'Helper.unescape(%s)', 'Helper.escape(%s)' ],
28
28
  :hmac => [ :hmac, 'Helper.hmacverify(%s, options[:secret] || @secret)',
29
- 'Helper.hmacsign(%s, options[:secret] || @secret)', 'openssl' ],
30
- :truncate => [ :truncate, nil, 'Helper.truncate(%s, @maxlen)', 'digest/md5' ],
31
- :md5 => [ :digest, nil, '::Digest::MD5.hexdigest(%s)', 'digest/md5' ],
32
- :rmd160 => [ :digest, nil, '::Digest::RMD160.hexdigest(%s)', 'digest/rmd160' ],
33
- :sha1 => [ :digest, nil, '::Digest::SHA1.hexdigest(%s)', 'digest/sha1' ],
34
- :sha256 => [ :digest, nil, '::Digest::SHA256.hexdigest(%s)', 'digest/sha2' ],
35
- :sha384 => [ :digest, nil, '::Digest::SHA384.hexdigest(%s)', 'digest/sha2' ],
36
- :sha512 => [ :digest, nil, '::Digest::SHA512.hexdigest(%s)', 'digest/sha2' ],
37
- :prefix => [ :prefix, nil, '(options[:prefix] || @prefix)+%s' ],
38
- :spread => [ :spread, nil, 'Helper.spread(%s)' ],
39
- :to_s => [ :string, nil, '%s.to_s' ],
40
- :inspect => [ :string, nil, '%s.inspect' ],
29
+ 'Helper.hmacsign(%s, options[:secret] || @secret)', 'openssl' ],
30
+ :truncate => [ :truncate, nil, 'Helper.truncate(%s, @maxlen)', 'digest/md5' ],
31
+ :md5 => [ :digest, nil, '::Digest::MD5.hexdigest(%s)', 'digest/md5' ],
32
+ :rmd160 => [ :digest, nil, '::Digest::RMD160.hexdigest(%s)', 'digest/rmd160' ],
33
+ :sha1 => [ :digest, nil, '::Digest::SHA1.hexdigest(%s)', 'digest/sha1' ],
34
+ :sha256 => [ :digest, nil, '::Digest::SHA256.hexdigest(%s)', 'digest/sha2' ],
35
+ :sha384 => [ :digest, nil, '::Digest::SHA384.hexdigest(%s)', 'digest/sha2' ],
36
+ :sha512 => [ :digest, nil, '::Digest::SHA512.hexdigest(%s)', 'digest/sha2' ],
37
+ :city32 => [ :digest, nil, '::CityHash.hash32(%s).to_s(16)', 'cityhash' ],
38
+ :city64 => [ :digest, nil, '::CityHash.hash64(%s).to_s(16)', 'cityhash' ],
39
+ :city128 => [ :digest, nil, '::CityHash.hash128(%s).to_s(16)', 'cityhash' ],
40
+ :prefix => [ :prefix, nil, '(options[:prefix] || @prefix)+%s' ],
41
+ :spread => [ :spread, nil, 'Helper.spread(%s)' ],
42
+ :to_s => [ :string, nil, '%s.to_s' ],
43
+ :inspect => [ :string, nil, '%s.inspect' ],
41
44
  }
42
45
 
43
46
  # Allowed value transformers (Read it like a regular expression!)
@@ -1,5 +1,5 @@
1
1
  module Moneta
2
2
  # Moneta version number
3
3
  # @api public
4
- VERSION = '0.7.17'
4
+ VERSION = '0.7.18'
5
5
  end
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+ git log --format='%aN <%aE>' |\
3
+ sed -e 's/hiddenbek/Scott Wadden/g' |\
4
+ sed -e 's/Asmod4n/Hendrik Beskow/' |\
5
+ grep -v 'hannes.georg@xing.com\|spotapov\|yehuda-katzs-mac\|wycats ' |\
6
+ sort -u | sort > CONTRIBUTORS
7
+
@@ -7,8 +7,8 @@ class Specs
7
7
 
8
8
  def initialize(options = {})
9
9
  @specs = options.delete(:specs).to_a
10
- @key = options.delete(:key) || %w(object string hash boolean nil integer)
11
- @value = options.delete(:value) || %w(object string hash boolean nil integer)
10
+ @key = options.delete(:key) || %w(object string hash boolean nil integer number)
11
+ @value = options.delete(:value) || %w(object string hash boolean nil integer number)
12
12
  @features = []
13
13
  [:expires, :expires_native, :increment, :create].each do |feature|
14
14
  @features << feature if @specs.include?(feature)
@@ -21,8 +21,8 @@ class Specs
21
21
  Specs.new({:specs => specs, :key => key, :value => value}.merge(options))
22
22
  end
23
23
 
24
- def stringkeys_only
25
- new(:key => %w(string))
24
+ def simplestringkeys_only
25
+ new(:key => %w(simplestring))
26
26
  end
27
27
 
28
28
  def stringvalues_only
@@ -404,12 +404,12 @@ end
404
404
  :store => :Couch,
405
405
  :options => ":db => 'simple_couch'",
406
406
  :load_value => '::Marshal.load(value.unpack(\'m\').first)',
407
- :specs => STANDARD_SPECS.without_increment.without_create
407
+ :specs => STANDARD_SPECS.without_increment
408
408
  },
409
409
  'simple_couch_with_expires' => {
410
410
  :store => :Couch,
411
411
  :options => ":db => 'simple_couch_with_expires', :expires => true",
412
- :specs => STANDARD_SPECS.without_increment.without_create.with_expires,
412
+ :specs => STANDARD_SPECS.without_increment.with_expires,
413
413
  :load_value => '::Marshal.load(value.unpack(\'m\').first)'
414
414
  },
415
415
  'simple_mongo' => {
@@ -495,16 +495,18 @@ end
495
495
  :specs => STANDARD_SPECS.without_increment.without_create.with_expires
496
496
  },
497
497
  'weak_create' => {
498
+ :preamble => "start_restserver\n",
498
499
  :build => %{Moneta.build do
499
500
  use :WeakCreate
500
- adapter :Couch, :db => 'weak_create'
501
+ adapter :RestClient, :url => 'http://localhost:8808/moneta/'
501
502
  end},
502
503
  :specs => ADAPTER_SPECS.without_increment.without_concurrent
503
504
  },
504
505
  'weak_increment' => {
506
+ :preamble => "start_restserver\n",
505
507
  :build => %{Moneta.build do
506
508
  use :WeakIncrement
507
- adapter :Couch, :db => 'weak_increment'
509
+ adapter :RestClient, :url => 'http://localhost:8808/moneta/'
508
510
  end},
509
511
  :specs => ADAPTER_SPECS.without_create.without_concurrent
510
512
  },
@@ -1103,6 +1105,42 @@ end},
1103
1105
  it 'compile transformer class' do
1104
1106
  store.should_not be_nil
1105
1107
  Moneta::Transformer::MarshalMd5SpreadKeyMarshalValue.should_not be_nil
1108
+ end}
1109
+ },
1110
+ 'transformer_marshal_city32' => {
1111
+ :build => %{Moneta.build do
1112
+ use :Transformer, :key => [:marshal, :city32], :value => :marshal
1113
+ adapter :Memory
1114
+ end},
1115
+ :specs => STANDARD_SPECS.without_persist,
1116
+ :tests => %{
1117
+ it 'compile transformer class' do
1118
+ store.should_not be_nil
1119
+ Moneta::Transformer::MarshalCity32KeyMarshalValue.should_not be_nil
1120
+ end}
1121
+ },
1122
+ 'transformer_marshal_city64' => {
1123
+ :build => %{Moneta.build do
1124
+ use :Transformer, :key => [:marshal, :city64], :value => :marshal
1125
+ adapter :Memory
1126
+ end},
1127
+ :specs => STANDARD_SPECS.without_persist,
1128
+ :tests => %{
1129
+ it 'compile transformer class' do
1130
+ store.should_not be_nil
1131
+ Moneta::Transformer::MarshalCity64KeyMarshalValue.should_not be_nil
1132
+ end}
1133
+ },
1134
+ 'transformer_marshal_city128' => {
1135
+ :build => %{Moneta.build do
1136
+ use :Transformer, :key => [:marshal, :city128], :value => :marshal
1137
+ adapter :Memory
1138
+ end},
1139
+ :specs => STANDARD_SPECS.without_persist,
1140
+ :tests => %{
1141
+ it 'compile transformer class' do
1142
+ store.should_not be_nil
1143
+ Moneta::Transformer::MarshalCity128KeyMarshalValue.should_not be_nil
1106
1144
  end}
1107
1145
  },
1108
1146
  'transformer_marshal_truncate' => {
@@ -1187,7 +1225,7 @@ end}
1187
1225
  },
1188
1226
  'adapter_couch' => {
1189
1227
  :build => "Moneta::Adapters::Couch.new(:db => 'adapter_couch')",
1190
- :specs => ADAPTER_SPECS.without_increment.without_create
1228
+ :specs => ADAPTER_SPECS.without_increment.simplevalues_only.simplestringkeys_only
1191
1229
  },
1192
1230
  'adapter_datamapper' => {
1193
1231
  :build => 'Moneta::Adapters::DataMapper.new(:setup => "mysql://root:@localhost/moneta", :table => "adapter_datamapper")',
@@ -1307,7 +1345,7 @@ end}
1307
1345
  },
1308
1346
  'adapter_mongo' => {
1309
1347
  :build => 'Moneta::Adapters::Mongo.new(:db => "adapter_mongo")',
1310
- :specs => ADAPTER_SPECS.with_native_expires,
1348
+ :specs => ADAPTER_SPECS.with_native_expires.simplevalues_only,
1311
1349
  :tests => %{
1312
1350
  it 'automatically deletes expired document' do
1313
1351
  store.store('key', 'val', :expires => 5)
@@ -1318,7 +1356,7 @@ end}
1318
1356
  },
1319
1357
  'adapter_mongo_with_default_expires' => {
1320
1358
  :build => %{Moneta::Adapters::Mongo.new(:expires => 1)},
1321
- :specs => ADAPTER_SPECS.with_expires.with_default_expires
1359
+ :specs => ADAPTER_SPECS.with_expires.with_default_expires.simplevalues_only
1322
1360
  },
1323
1361
  'adapter_pstore' => {
1324
1362
  :build => 'Moneta::Adapters::PStore.new(:file => File.join(make_tempdir, "adapter_pstore"))',
@@ -1606,8 +1644,10 @@ SPECS = {}
1606
1644
  KEYS = {
1607
1645
  'nil' => [0, 'nil'],
1608
1646
  'integer' => [-10, 42],
1647
+ 'number' => [0.5, -0.3, 1<<127, 99],
1609
1648
  'boolean' => [true, false],
1610
- 'string' => ['strkey1', 'strkey2'].map(&:inspect),
1649
+ 'string' => %w(strkey1 strkey2 foo/bar bar/foo/baz).map(&:inspect),
1650
+ 'simplestring' => %w(strkey1 strkey2).map(&:inspect),
1611
1651
  'object' => ['Value.new(:objkey1)', 'Value.new(:objkey2)'],
1612
1652
  'hash' => [{'hashkey1' => 'hashkey2'}, {'hashkey3' => 'hashkey4'}].map(&:inspect)
1613
1653
  }
@@ -1615,19 +1655,24 @@ KEYS = {
1615
1655
  VALUES = {
1616
1656
  'nil' => [0, 'nil'],
1617
1657
  'integer' => [41, -12],
1658
+ 'number' => [123.456, -98.7, 1<<128, 33],
1618
1659
  'boolean' => [true, false],
1619
- 'string' => ['strval1', 'strval2'].map(&:inspect),
1660
+ 'string' => %w(strval1 strval2).map(&:inspect),
1620
1661
  'hash' => [{'hashval1' => ['array1', 1]}, {'hashval3' => ['array2', {'hashval4' => 42}]}].map(&:inspect),
1621
1662
  'object' => ['Value.new(:objval1)', 'Value.new(:objval2)'],
1622
1663
  }
1623
1664
 
1624
- KEYS.each do |key_type, keypair|
1625
- VALUES.each do |val_type, valpair|
1626
- 4.times do |i|
1627
- key1, key2 = i % 2 == 0 ? keypair : keypair.reverse
1628
- val1, val2 = i < 2 ? valpair : valpair.reverse
1629
-
1630
- code = %{it 'reads from keys like a Hash' do
1665
+ KEYS.each do |key_type, keys|
1666
+ VALUES.each do |val_type, vals|
1667
+ (keys.size/2).times do |k|
1668
+ keypair = keys[2*k,2]
1669
+ (vals.size/2).times do |v|
1670
+ valpair = vals[2*v,2]
1671
+ 4.times do |i|
1672
+ key1, key2 = i % 2 == 0 ? keypair : keypair.reverse
1673
+ val1, val2 = i < 2 ? valpair : valpair.reverse
1674
+
1675
+ code = %{it 'reads from keys like a Hash' do
1631
1676
  store[#{key1}].should be_nil
1632
1677
  store.load(#{key1}).should be_nil
1633
1678
  end
@@ -1677,9 +1722,9 @@ it 'accepts frozen options' do
1677
1722
  store.clear(options).should equal(store)
1678
1723
  store.store(#{key1}, #{val1}, options).should == #{val1}
1679
1724
  end}
1680
- (SPECS["null_#{key_type}key_#{val_type}value"] ||= []) << code
1725
+ (SPECS["null_#{key_type}key_#{val_type}value"] ||= []) << code
1681
1726
 
1682
- code = %{it 'writes values to keys that like a Hash' do
1727
+ code = %{it 'writes values to keys that like a Hash' do
1683
1728
  store[#{key1}] = #{val1}
1684
1729
  store[#{key1}].should == #{val1}
1685
1730
  store.load(#{key1}).should == #{val1}
@@ -1717,10 +1762,22 @@ it 'overwrites existing values' do
1717
1762
  store[#{key1}].should == #{val1}
1718
1763
  store[#{key1}] = #{val2}
1719
1764
  store[#{key1}].should == #{val2}
1765
+ end
1766
+
1767
+ it 'stores frozen values' do
1768
+ value = #{val1}.freeze
1769
+ (store[#{key1}] = value).should equal(value)
1770
+ store[#{key1}].should == #{val1}
1771
+ end
1772
+
1773
+ it 'stores frozen keys' do
1774
+ key = #{key1}.freeze
1775
+ store[key] = #{val1}
1776
+ store[#{key1}].should == #{val1}
1720
1777
  end}
1721
1778
 
1722
- if val_type != 'nil'
1723
- code << %{
1779
+ if val_type != 'nil'
1780
+ code << %{
1724
1781
  it 'fetches a key with a default value with fetch, if the key is available' do
1725
1782
  store[#{key1}] = #{val1}
1726
1783
  store.fetch(#{key1}, #{val2}).should == #{val1}
@@ -1732,11 +1789,11 @@ it 'does not run the block in fetch if the key is available' do
1732
1789
  store.fetch(#{key1}) { unaltered = 'altered' }
1733
1790
  unaltered.should == 'unaltered'
1734
1791
  end}
1735
- end
1792
+ end
1736
1793
 
1737
- (SPECS["store_#{key_type}key_#{val_type}value"] ||= []) << code
1794
+ (SPECS["store_#{key_type}key_#{val_type}value"] ||= []) << code
1738
1795
 
1739
- if val_type != 'boolean' && val_type != 'nil' && val_type != 'integer'
1796
+ if val_type != 'boolean' && val_type != 'nil' && val_type != 'integer' && val_type != 'number'
1740
1797
  (SPECS["returndifferent_#{key_type}key_#{val_type}value"] ||= []) << %{it 'guarantees that a different value is retrieved' do
1741
1798
  value = #{val1}
1742
1799
  store[#{key1}] = value
@@ -1747,15 +1804,17 @@ end}
1747
1804
  store[#{key1}] = value
1748
1805
  store[#{key1}].should be_equal(value)
1749
1806
  end}
1750
- end
1807
+ end
1751
1808
 
1752
- code = %{it 'persists values' do
1809
+ code = %{it 'persists values' do
1753
1810
  store[#{key1}] = #{val1}
1754
1811
  store.close
1755
1812
  @store = nil
1756
1813
  store[#{key1}].should == #{val1}
1757
1814
  end}
1758
- (SPECS["persist_#{key_type}key_#{val_type}value"] ||= []) << code
1815
+ (SPECS["persist_#{key_type}key_#{val_type}value"] ||= []) << code
1816
+ end
1817
+ end
1759
1818
  end
1760
1819
  end
1761
1820
  end
@@ -16,7 +16,7 @@ end
16
16
 
17
17
  BUNDLE_FILE = "moneta-bundle-#{RUBY_VERSION}-#{ruby}.tar.gz"
18
18
 
19
- if system("wget --no-check-certificate --quiet -O #{BUNDLE_FILE} https://moneta:#{ENV['DAV_PW']}@mendler.net/dav/#{BUNDLE_FILE}")
19
+ if system("curl -u moneta:#{ENV['DAV_PW']} -k -o #{BUNDLE_FILE} https://mendler.net/dav/#{BUNDLE_FILE}")
20
20
  cmd 'rm -rf .bundle'
21
21
  cmd "tar -xpf #{BUNDLE_FILE}"
22
22
  cmd "rm -f #{BUNDLE_FILE}"
@@ -1,17 +1,11 @@
1
1
  #!/bin/bash
2
- sudo service riak start
3
- sudo service couchdb start
4
- sudo service redis-server start
5
- sudo service cassandra start
6
- sudo service memcached start
7
- sudo service mongodb start
8
2
 
9
3
  echo 'Starting TokyoTyrant'
10
4
  /usr/sbin/ttserver -dmn -pid /tmp/ttserver.pid -log /tmp/ttserver.log -port 1978
11
5
 
12
- # Waiting for servers to start
13
- sleep 3
14
-
15
- #echo 'TokyoTyrant status'
16
- #ps aux | grep ttserver
17
- #cat /tmp/ttserver.log
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 &