[DRE-commits] [ruby-moneta] 05/09: New upstream version 1.0.0

Daisuke Higuchi dai at moszumanska.debian.org
Fri Jul 28 13:50:29 UTC 2017


This is an automated email from the git hooks/post-receive script.

dai pushed a commit to branch exp/debian
in repository ruby-moneta.

commit 205b014c12c5fafe90c48829b1d9f3c4fe777c4b
Author: HIGUCHI Daisuke (VDR dai) <dai at debian.org>
Date:   Fri Jul 28 20:38:30 2017 +0900

    New upstream version 1.0.0
---
 CHANGES                                        |   6 +
 CONTRIBUTORS                                   |   2 +
 Gemfile                                        |   1 +
 LICENSE                                        |   2 +-
 lib/active_support/cache/moneta_store.rb       |   9 +-
 lib/moneta/adapters/sequel.rb                  |   9 +
 lib/moneta/version.rb                          |   2 +-
 moneta.gemspec                                 |   4 +-
 script/parallel-tests                          |  12 ++
 spec/active_support/cache_moneta_store_spec.rb | 248 +++++++++++++++----------
 10 files changed, 194 insertions(+), 101 deletions(-)

diff --git a/CHANGES b/CHANGES
index fafefaf..6460416 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,9 @@
+1.0.0
+
+* Adapters::Sequel - allow usage of Sequel extensions and connection validation
+* ActiveSupport::Cache::MonetaStore - dup options before mutating them
+* ActiveSupport::Cache::MonetaStore - allow writing raw values
+
 0.8.1
 
 * Adapters::TokyoTyrant - more consistent error handling
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 7ea4d3f..b98f0df 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -26,6 +26,8 @@ Potapov Sergey <blake131313 at gmail.com>
 Quin Hoxie <quin at aboutus.org>
 Ryan T. Hosford <tad.hosford at gmail.com>
 Scott Wadden <scott.wadden at gmail.com>
+Timo Goebel <timo.goebel at dm.de>
 Tom Meier <ozmeier at yahoo.co.uk>
+Tony Han <h.bing612 at gmail.com>
 Xavier Shay <xavier at rhnh.net>
 Yehuda Katz <wycats at gmail.com>
diff --git a/Gemfile b/Gemfile
index 8796183..50b7423 100644
--- a/Gemfile
+++ b/Gemfile
@@ -16,6 +16,7 @@ gem 'msgpack', platforms: :ruby
 gem 'msgpack-jruby', platforms: :jruby
 gem 'bert', platforms: :ruby
 gem 'php_serialize'
+gem 'nokogiri', '~> 1.6.0'
 
 # Compressors used by Transformer
 gem 'rbzip2'
diff --git a/LICENSE b/LICENSE
index 50c86c2..8eaa077 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2009 - 2014 Daniel Mendler, Yehuda Katz
+Copyright (c) 2009 - 2017 Daniel Mendler, Yehuda Katz, Alastair Pharo
 
 Permission is hereby granted, free of charge, to any person obtaining
 a copy of this software and associated documentation files (the
diff --git a/lib/active_support/cache/moneta_store.rb b/lib/active_support/cache/moneta_store.rb
index fc089dc..baef6d2 100644
--- a/lib/active_support/cache/moneta_store.rb
+++ b/lib/active_support/cache/moneta_store.rb
@@ -38,7 +38,8 @@ module ActiveSupport
       end
 
       def write_entry(key, entry, options)
-        @store.store(key, entry, moneta_options(options))
+        value = options[:raw] ? entry.value.to_s : entry
+        @store.store(key, value, moneta_options(options))
         true
       end
 
@@ -50,9 +51,9 @@ module ActiveSupport
       private
 
       def moneta_options(options)
-        options ||= {}
-        options[:expires] = options.delete(:expires_in).to_i if options.include?(:expires_in)
-        options
+        new_options = options ? options.dup : {}
+        new_options[:expires] = new_options.delete(:expires_in).to_i if new_options.include?(:expires_in)
+        new_options
       end
     end
   end
diff --git a/lib/moneta/adapters/sequel.rb b/lib/moneta/adapters/sequel.rb
index f47b1cc..d2a9e24 100644
--- a/lib/moneta/adapters/sequel.rb
+++ b/lib/moneta/adapters/sequel.rb
@@ -17,15 +17,24 @@ module Moneta
       # @param [Hash] options
       # @option options [String] :db Sequel database
       # @option options [String/Symbol] :table (:moneta) Table name
+      # @option options [Array] :extensions ([]) List of Sequel extensions
+      # @option options [Integer] :connection_validation_timeout (nil) Sequel connection_validation_timeout
       # @option options All other options passed to `Sequel#connect`
       # @option options [Sequel connection] :backend Use existing backend instance
       def initialize(options = {})
         table = (options.delete(:table) || :moneta).to_sym
+        extensions = options.delete(:extensions) || []
+        raise ArgumentError, 'Option :extensions must be an Array' unless extensions.is_a?(Array)
+        connection_validation_timeout = options.delete(:connection_validation_timeout)
         @backend = options[:backend] ||
           begin
             raise ArgumentError, 'Option :db is required' unless db = options.delete(:db)
             ::Sequel.connect(db, options)
           end
+        extensions.each do |extension|
+          @backend.extension(extension.to_sym)
+        end
+        @backend.pool.connection_validation_timeout = connection_validation_timeout if connection_validation_timeout
         @backend.create_table?(table) do
           String :k, null: false, primary_key: true
           File :v
diff --git a/lib/moneta/version.rb b/lib/moneta/version.rb
index 2edb4f4..4862923 100644
--- a/lib/moneta/version.rb
+++ b/lib/moneta/version.rb
@@ -1,5 +1,5 @@
 module Moneta
   # Moneta version number
   # @api public
-  VERSION = '0.8.1'
+  VERSION = '1.0.0'
 end
diff --git a/moneta.gemspec b/moneta.gemspec
index f413b4c..e2ab14c 100644
--- a/moneta.gemspec
+++ b/moneta.gemspec
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
   s.name             = 'moneta'
   s.version          = Moneta::VERSION
   s.date             = Date.today.to_s
-  s.authors          = ['Daniel Mendler', 'Yehuda Katz', 'Hannes Georg']
-  s.email            = %w{mail at daniel-mendler.de wycats at gmail.com hannes.georg at googlemail.com}
+  s.authors          = ['Daniel Mendler', 'Yehuda Katz', 'Hannes Georg', 'Alastair Pharo']
+  s.email            = %w{mail at daniel-mendler.de wycats at gmail.com hannes.georg at googlemail.com asppsa at gmail.com}
   s.description      = 'A unified interface to key/value stores'
   s.extra_rdoc_files = %w{README.md SPEC.md LICENSE}
   s.files            = `git ls-files`.split("\n")
diff --git a/script/parallel-tests b/script/parallel-tests
index 70b9e2e..30e14fb 100755
--- a/script/parallel-tests
+++ b/script/parallel-tests
@@ -68,6 +68,18 @@ parallel = []
     parallel << serial
   end
 end
+
+# The activesupport cache specs also use memcached
+activesupport_cache_specs = specs.grep(/active_support.+cache/)
+specs -= activesupport_cache_specs
+
+if memcache_specs = parallel.find{ |serial| serial.all?{ |s| s.match /memcached/ } }
+  activesupport_cache_specs.each(&memcache_specs.method(:push))
+else
+  parallel += activesupport_cache_specs
+end
+
+# All the left-overs
 parallel += specs.map {|s| [s] }
 
 threads = []
diff --git a/spec/active_support/cache_moneta_store_spec.rb b/spec/active_support/cache_moneta_store_spec.rb
index b80505d..b8e8085 100644
--- a/spec/active_support/cache_moneta_store_spec.rb
+++ b/spec/active_support/cache_moneta_store_spec.rb
@@ -3,7 +3,20 @@ require 'active_support'
 require 'active_support/cache/moneta_store'
 require 'ostruct'
 
-describe ActiveSupport::Cache::MonetaStore do
+module MonetaStoreHelpers
+  def with_notifications
+    described_class.instrument = true
+    yield
+  ensure
+    described_class.instrument = false
+  end
+end
+
+RSpec.configure do |config|
+  config.include(MonetaStoreHelpers)
+end
+
+describe "cache_moneta_store" do
   before(:all) do
     @events = []
     ActiveSupport::Notifications.subscribe(/^cache_(.*)\.active_support$/) do |*args|
@@ -13,185 +26,234 @@ describe ActiveSupport::Cache::MonetaStore do
 
   before(:each) do
     @events.clear
-    @store  = ActiveSupport::Cache::MonetaStore.new(store: Moneta.new(:Memory))
-    @rabbit = OpenStruct.new name: 'bunny'
-    @white_rabbit = OpenStruct.new color: 'white'
-
-    @store.write 'rabbit', @rabbit
-    @store.delete 'counter'
-    @store.delete 'rub-a-dub'
   end
 
-  it 'reads the data' do
-    @store.read('rabbit').should == @rabbit
-  end
+  # All stores should implement this basic behavior.
+  shared_examples :basic_store do
+    before(:each) do
+      @rabbit = OpenStruct.new name: 'bunny'
+      @white_rabbit = OpenStruct.new color: 'white'
 
-  it 'writes the data' do
-    @store.write 'rabbit', @white_rabbit
-    @store.read('rabbit').should == @white_rabbit
-  end
+      store.clear
+      store.write 'rabbit', @rabbit
+    end
 
-  it 'writes the data with expiration time' do
-    @store.write 'rabbit', @white_rabbit, expires_in: 1.second
-    @store.read('rabbit').should == @white_rabbit
-    sleep 2
-    @store.read('rabbit').should be_nil
-  end
+    it 'reads the data' do
+      store.read('rabbit').should == @rabbit
+    end
 
-  it 'deletes data' do
-    @store.delete 'rabbit'
-    @store.read('rabbit').should be_nil
-  end
+    it 'writes the data' do
+      store.write 'rabbit', @white_rabbit
+      store.read('rabbit').should == @white_rabbit
+    end
 
-  it 'verifies existence of an object in the store' do
-    @store.exist?('rabbit').should == true
-    (!!@store.exist?('rab-a-dub')).should == false
-  end
+    it 'deletes data' do
+      store.delete 'rabbit'
+      store.read('rabbit').should be_nil
+    end
 
-  it 'fetches data' do
-    @store.fetch('rabbit').should == @rabbit
-    @store.fetch('rub-a-dub').should be_nil
-    @store.fetch('rub-a-dub') { 'Flora de Cana' }
-    @store.fetch('rub-a-dub').should == 'Flora de Cana'
-    @store.fetch('rabbit', force: true) # force cache miss
-    @store.fetch('rabbit', force: true, expires_in: 1.second) { @white_rabbit }
-    @store.fetch('rabbit').should == @white_rabbit
-    sleep 2
-    @store.fetch('rabbit').should be_nil
-  end
+    it 'verifies existence of an object in the store' do
+      store.exist?('rabbit').should be true
+      (!!store.exist?('rab-a-dub')).should be false
+    end
 
-  it 'reads multiple keys' do
-    @store.write 'irish whisky', 'Jameson'
-    result = @store.read_multi 'rabbit', 'irish whisky'
-    result['rabbit'].should == @rabbit
-    result['irish whisky'].should == 'Jameson'
-  end
+    it 'fetches data' do
+      store.fetch('rabbit').should == @rabbit
+      store.fetch('rub-a-dub').should be_nil
+      store.fetch('rub-a-dub') { 'Flora de Cana' }
+      store.fetch('rub-a-dub').should == 'Flora de Cana'
+    end
 
-  it 'reads multiple keys and returns only the matched ones' do
-    @store.delete 'irish whisky'
-    result = @store.read_multi 'rabbit', 'irish whisky'
-    result.should_not include('irish whisky')
-    result.should include('rabbit')
-  end
+    it 'reads multiple keys' do
+      store.write 'irish whisky', 'Jameson'
+      result = store.read_multi 'rabbit', 'irish whisky'
+      result['rabbit'].should == @rabbit
+      result['irish whisky'].should == 'Jameson'
+    end
 
-  it 'increments a key' do
-    3.times { @store.increment 'counter' }
-    @store.read('counter', raw: true).should == '3'
+    it 'reads multiple keys and returns only the matched ones' do
+      store.delete 'irish whisky'
+      result = store.read_multi 'rabbit', 'irish whisky'
+      result.should_not include('irish whisky')
+      result.should include('rabbit')
+    end
   end
 
-  it 'decrements a key' do
-    3.times { @store.increment 'counter' }
-    2.times { @store.decrement 'counter' }
-    @store.read('counter', raw: true).should == '1'
-  end
+  shared_examples :expiry do
+    it 'writes the data with expiration time' do
+      store.write 'rabbit', @white_rabbit, expires_in: 1.second
+      store.read('rabbit').should == @white_rabbit
+      sleep 2
+      store.read('rabbit').should be_nil
+    end
+
+    it "sets expiry on cache miss" do
+      store.fetch('rabbit', force: true) # force cache miss
+      store.fetch('rabbit', force: true, expires_in: 1.second) { @white_rabbit }
+      store.fetch('rabbit').should == @white_rabbit
+      sleep 2
+      store.fetch('rabbit').should be_nil
+    end
 
-  it 'increments a key by given value' do
-    @store.increment 'counter', 3
-    @store.read('counter', raw: true).should == '3'
+    it 'does not set expiry on cache hit' do
+      store.fetch('rabbit', expires_in: 1.second) { @white_rabbit }.should == @rabbit
+      sleep 2
+      store.fetch('rabbit').should == @rabbit
+    end
   end
 
-  it 'decrements a key by given value' do
-    3.times { @store.increment 'counter' }
-    @store.decrement 'counter', 2
-    @store.read('counter', raw: true).should == '1'
+  # A store *may* implement this
+  shared_examples :increment_decrement do
+    it 'increments a key' do
+      store.write 'counter', 0, raw: true
+      3.times { store.increment 'counter' }
+      store.read('counter', raw: true).to_i.should == 3
+    end
+
+    it 'decrements a key' do
+      store.write 'counter', 0, raw: true
+      3.times { store.increment 'counter' }
+      2.times { store.decrement 'counter' }
+      store.read('counter', raw: true).to_i.should == 1
+    end
+
+    it 'increments a key by given value' do
+      store.write 'counter', 0, raw: true
+      store.increment 'counter', 3
+      store.read('counter', raw: true).to_i.should == 3
+    end
+
+    it 'decrements a key by given value' do
+      store.write 'counter', 0, raw: true
+      3.times { store.increment 'counter' }
+      store.decrement 'counter', 2
+      store.read('counter', raw: true).to_i.should == 1
+    end
   end
 
-  describe 'notifications' do
+  shared_examples :basic_instrumentation do
     it 'notifies on #fetch' do
       with_notifications do
-        @store.fetch('radiohead') { 'House Of Cards' }
+        store.fetch('radiohead') { 'House Of Cards' }
       end
 
-      read, generate, write = @events
-
+      read = @events.shift
       read.name.should == 'cache_read.active_support'
       read.payload.should == { key: 'radiohead', super_operation: :fetch }
 
+      generate = @events.shift
       generate.name.should == 'cache_generate.active_support'
       generate.payload.should == { key: 'radiohead' }
 
+      write = @events.shift
       write.name.should == 'cache_write.active_support'
       write.payload.should == { key: 'radiohead' }
     end
 
     it 'notifies on #read' do
       with_notifications do
-        @store.read 'metallica'
+        store.read 'metallica'
       end
 
-      read = @events.first
+      read = @events.shift
       read.name.should == 'cache_read.active_support'
       read.payload.should == { key: 'metallica', hit: false }
     end
 
     it 'notifies on #write' do
       with_notifications do
-        @store.write 'depeche mode', 'Enjoy The Silence'
+        store.write 'depeche mode', 'Enjoy The Silence'
       end
 
-      write = @events.first
+      write = @events.shift
       write.name.should == 'cache_write.active_support'
       write.payload.should == { key: 'depeche mode' }
     end
 
     it 'notifies on #delete' do
       with_notifications do
-        @store.delete 'the new cardigans'
+        store.delete 'the new cardigans'
       end
 
-      delete = @events.first
+      delete = @events.shift
       delete.name.should == 'cache_delete.active_support'
       delete.payload.should == { key: 'the new cardigans' }
     end
 
     it 'notifies on #exist?' do
       with_notifications do
-        @store.exist? 'the smiths'
+        store.exist? 'the smiths'
       end
 
-      exist = @events.first
+      exist = @events.shift
       exist.name.should == 'cache_exist?.active_support'
       exist.payload.should == { key: 'the smiths' }
     end
 
+  end
+
+  # This doesn't seem to be documented at all, so we follow the
+  # behavior of MemCacheStore.
+  shared_examples :increment_decrement_instrumentation do
     it 'notifies on #increment' do
       with_notifications do
-        @store.increment 'pearl jam'
+        store.increment 'pearl jam'
       end
 
-      increment = @events.first
+      increment = @events.shift
       increment.name.should == 'cache_increment.active_support'
       increment.payload.should == { key: 'pearl jam', amount: 1 }
     end
 
     it 'notifies on #decrement' do
       with_notifications do
-        @store.decrement 'placebo'
+        store.decrement 'placebo'
       end
 
-      decrement = @events.first
+      decrement = @events.shift
       decrement.name.should == 'cache_decrement.active_support'
       decrement.payload.should == { key: 'placebo', amount: 1 }
     end
+  end
 
-    it 'should notify on clear' do
+  describe ActiveSupport::Cache::MonetaStore do
+    let(:store){ described_class.new(store: Moneta.new(:Memory)) }
+
+    include_examples :basic_store
+    include_examples :expiry
+    include_examples :increment_decrement
+    include_examples :basic_instrumentation
+    include_examples :increment_decrement_instrumentation
+
+    # FIXME: no other store does this -- perhaps this should be
+    # removed.
+    it 'notifies on #clear' do
       with_notifications do
-        @store.clear
+        store.clear
       end
 
-      clear = @events.first
+      clear = @events.shift
       clear.name.should == 'cache_clear.active_support'
       clear.payload.should == { key: nil }
     end
   end
 
-  private
+  describe ActiveSupport::Cache::MemoryStore do
+    let(:store){ described_class.new }
 
-  def with_notifications
-    ActiveSupport::Cache::MonetaStore.instrument = true
-    yield
-  ensure
-    ActiveSupport::Cache::MonetaStore.instrument = false
+    include_examples :basic_store
+    include_examples :expiry
+    include_examples :increment_decrement
+    include_examples :basic_instrumentation
   end
-end
 
+  describe ActiveSupport::Cache::MemCacheStore do
+    let(:store){ described_class.new }
+
+    include_examples :basic_store
+    include_examples :expiry
+    include_examples :increment_decrement
+    include_examples :basic_instrumentation
+    include_examples :increment_decrement_instrumentation
+  end
+end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-moneta.git



More information about the Pkg-ruby-extras-commits mailing list