1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
# frozen_string_literal: true
require_relative '../helper'
require 'json'
class NoopCompressor
def self.compress(data)
data
end
def self.decompress(data)
data
end
end
describe 'Compressor' do
MemcachedManager.supported_protocols.each do |p|
describe "using the #{p} protocol" do
it 'default to Dalli::Compressor' do
memcached(p, 29_199) do |dc|
dc.set 1, 2
assert_equal Dalli::Compressor, dc.instance_variable_get(:@ring).servers.first.compressor
end
end
it 'support a custom compressor' do
memcached(p, 29_199) do |_dc|
memcache = Dalli::Client.new('127.0.0.1:29199', { compressor: NoopCompressor })
memcache.set 1, 2
begin
assert_equal NoopCompressor,
memcache.instance_variable_get(:@ring).servers.first.compressor
memcached(p, 19_127) do |newdc|
assert newdc.set('string-test', 'a test string')
assert_equal('a test string', newdc.get('string-test'))
end
end
end
end
describe 'GzipCompressor' do
it 'compress and uncompress data using Zlib::GzipWriter/Reader' do
memcached(p, 19_127) do |_dc|
memcache = Dalli::Client.new('127.0.0.1:19127', { compress: true, compressor: Dalli::GzipCompressor })
data = (0...1025).map { rand(65..90).chr }.join
assert memcache.set('test', data)
assert_equal(data, memcache.get('test'))
assert_equal Dalli::GzipCompressor, memcache.instance_variable_get(:@ring).servers.first.compressor
end
end
end
end
end
end
|