dalli 2.7.4 → 2.7.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of dalli might be problematic. Click here for more details.

@@ -1,85 +0,0 @@
1
- require 'helper'
2
-
3
- describe 'Ring' do
4
-
5
- describe 'a ring of servers' do
6
-
7
- it "have the continuum sorted by value" do
8
- servers = [stub(:name => "localhost:11211", :weight => 1),
9
- stub(:name => "localhost:9500", :weight => 1)]
10
- ring = Dalli::Ring.new(servers, {})
11
- previous_value = 0
12
- ring.continuum.each do |entry|
13
- assert entry.value > previous_value
14
- previous_value = entry.value
15
- end
16
- end
17
-
18
- it 'raise when no servers are available/defined' do
19
- ring = Dalli::Ring.new([], {})
20
- assert_raises Dalli::RingError, :message => "No server available" do
21
- ring.server_for_key('test')
22
- end
23
- end
24
-
25
- describe 'containing only a single server' do
26
- it "raise correctly when it's not alive" do
27
- servers = [
28
- Dalli::Server.new("localhost:12345"),
29
- ]
30
- ring = Dalli::Ring.new(servers, {})
31
- assert_raises Dalli::RingError, :message => "No server available" do
32
- ring.server_for_key('test')
33
- end
34
- end
35
-
36
- it "return the server when it's alive" do
37
- servers = [
38
- Dalli::Server.new("localhost:19191"),
39
- ]
40
- ring = Dalli::Ring.new(servers, {})
41
- memcached(19191) do |mc|
42
- ring = mc.send(:ring)
43
- assert_equal ring.servers.first.port, ring.server_for_key('test').port
44
- end
45
- end
46
- end
47
-
48
- describe 'containing multiple servers' do
49
- it "raise correctly when no server is alive" do
50
- servers = [
51
- Dalli::Server.new("localhost:12345"),
52
- Dalli::Server.new("localhost:12346"),
53
- ]
54
- ring = Dalli::Ring.new(servers, {})
55
- assert_raises Dalli::RingError, :message => "No server available" do
56
- ring.server_for_key('test')
57
- end
58
- end
59
-
60
- it "return an alive server when at least one is alive" do
61
- servers = [
62
- Dalli::Server.new("localhost:12346"),
63
- Dalli::Server.new("localhost:19191"),
64
- ]
65
- ring = Dalli::Ring.new(servers, {})
66
- memcached(19191) do |mc|
67
- ring = mc.send(:ring)
68
- assert_equal ring.servers.first.port, ring.server_for_key('test').port
69
- end
70
- end
71
- end
72
-
73
- it 'detect when a dead server is up again' do
74
- memcached(19997) do
75
- down_retry_delay = 0.5
76
- dc = Dalli::Client.new(['localhost:19997', 'localhost:19998'], :down_retry_delay => down_retry_delay)
77
- assert_equal 1, dc.stats.values.compact.count
78
-
79
- memcached(19998) do
80
- assert_equal 2, dc.stats.values.compact.count
81
- end
82
- end
83
- end
84
- end
85
- end
@@ -1,105 +0,0 @@
1
- require 'helper'
2
-
3
- describe 'Sasl' do
4
-
5
- # https://github.com/seattlerb/minitest/issues/298
6
- def self.xit(msg, &block)
7
- end
8
-
9
- describe 'a server requiring authentication' do
10
- before do
11
- @server = mock()
12
- @server.stubs(:request).returns(true)
13
- @server.stubs(:weight).returns(1)
14
- @server.stubs(:name).returns("localhost:19124")
15
- end
16
-
17
- describe 'without authentication credentials' do
18
- before do
19
- ENV['MEMCACHE_USERNAME'] = 'foo'
20
- ENV['MEMCACHE_PASSWORD'] = 'wrongpwd'
21
- end
22
-
23
- after do
24
- ENV['MEMCACHE_USERNAME'] = nil
25
- ENV['MEMCACHE_PASSWORD'] = nil
26
- end
27
-
28
- xit 'gracefully handle authentication failures' do
29
- memcached_sasl_persistent do |dc|
30
- assert_error Dalli::DalliError, /32/ do
31
- dc.set('abc', 123)
32
- end
33
- end
34
- end
35
- end
36
-
37
- xit 'fail SASL authentication with wrong options' do
38
- memcached_sasl_persistent do |dc, port|
39
- dc = Dalli::Client.new("localhost:#{port}", :username => 'testuser', :password => 'testtest')
40
- assert_error Dalli::DalliError, /32/ do
41
- dc.set('abc', 123)
42
- end
43
- end
44
- end
45
-
46
- # OSX: Create a SASL user for the memcached application like so:
47
- #
48
- # saslpasswd2 -a memcached -c testuser
49
- #
50
- # with password 'testtest'
51
- describe 'in an authenticated environment' do
52
- before do
53
- ENV['MEMCACHE_USERNAME'] = 'testuser'
54
- ENV['MEMCACHE_PASSWORD'] = 'testtest'
55
- end
56
-
57
- after do
58
- ENV['MEMCACHE_USERNAME'] = nil
59
- ENV['MEMCACHE_PASSWORD'] = nil
60
- end
61
-
62
- xit 'pass SASL authentication' do
63
- memcached_sasl_persistent do |dc|
64
- # I get "Dalli::DalliError: Error authenticating: 32" in OSX
65
- # but SASL works on Heroku servers. YMMV.
66
- assert_equal true, dc.set('abc', 123)
67
- assert_equal 123, dc.get('abc')
68
- results = dc.stats
69
- assert_equal 1, results.size
70
- assert_equal 38, results.values.first.size
71
- end
72
- end
73
- end
74
-
75
- xit 'pass SASL authentication with options' do
76
- memcached_sasl_persistent do |dc, port|
77
- dc = Dalli::Client.new("localhost:#{port}", sasl_credentials)
78
- # I get "Dalli::DalliError: Error authenticating: 32" in OSX
79
- # but SASL works on Heroku servers. YMMV.
80
- assert_equal true, dc.set('abc', 123)
81
- assert_equal 123, dc.get('abc')
82
- results = dc.stats
83
- assert_equal 1, results.size
84
- assert_equal 38, results.values.first.size
85
- end
86
- end
87
-
88
- it 'pass SASL as URI' do
89
- Dalli::Server.expects(:new).with("localhost:19124",
90
- :username => "testuser", :password => "testtest").returns(@server)
91
- dc = Dalli::Client.new('memcached://testuser:testtest@localhost:19124')
92
- dc.flush_all
93
- end
94
-
95
- it 'pass SASL as ring of URIs' do
96
- Dalli::Server.expects(:new).with("localhost:19124",
97
- :username => "testuser", :password => "testtest").returns(@server)
98
- Dalli::Server.expects(:new).with("otherhost:19125",
99
- :username => "testuser2", :password => "testtest2").returns(@server)
100
- dc = Dalli::Client.new(['memcached://testuser:testtest@localhost:19124',
101
- 'memcached://testuser2:testtest2@otherhost:19125'])
102
- dc.flush_all
103
- end
104
- end
105
- end
@@ -1,29 +0,0 @@
1
- # encoding: utf-8
2
- require 'helper'
3
- require 'json'
4
- require 'memcached_mock'
5
-
6
- describe 'Serializer' do
7
-
8
- it 'default to Marshal' do
9
- memcached(29198) do |dc|
10
- dc.set 1,2
11
- assert_equal Marshal, dc.instance_variable_get('@ring').servers.first.serializer
12
- end
13
- end
14
-
15
- it 'support a custom serializer' do
16
- memcached(29198) do |dc, port|
17
- memcache = Dalli::Client.new("127.0.0.1:#{port}", :serializer => JSON)
18
- memcache.set 1,2
19
- begin
20
- assert_equal JSON, memcache.instance_variable_get('@ring').servers.first.serializer
21
-
22
- memcached(21956) do |newdc|
23
- assert newdc.set("json_test", {"foo" => "bar"})
24
- assert_equal({"foo" => "bar"}, newdc.get("json_test"))
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,110 +0,0 @@
1
- require 'helper'
2
-
3
- describe Dalli::Server do
4
- describe 'hostname parsing' do
5
- it 'handles unix socket with no weight' do
6
- s = Dalli::Server.new('/var/run/memcached/sock')
7
- assert_equal '/var/run/memcached/sock', s.hostname
8
- assert_equal 1, s.weight
9
- assert_equal :unix, s.socket_type
10
- end
11
-
12
- it 'handles unix socket with a weight' do
13
- s = Dalli::Server.new('/var/run/memcached/sock:2')
14
- assert_equal '/var/run/memcached/sock', s.hostname
15
- assert_equal 2, s.weight
16
- assert_equal :unix, s.socket_type
17
- end
18
-
19
- it 'handles no port or weight' do
20
- s = Dalli::Server.new('localhost')
21
- assert_equal 'localhost', s.hostname
22
- assert_equal 11211, s.port
23
- assert_equal 1, s.weight
24
- assert_equal :tcp, s.socket_type
25
- end
26
-
27
- it 'handles a port, but no weight' do
28
- s = Dalli::Server.new('localhost:11212')
29
- assert_equal 'localhost', s.hostname
30
- assert_equal 11212, s.port
31
- assert_equal 1, s.weight
32
- assert_equal :tcp, s.socket_type
33
- end
34
-
35
- it 'handles a port and a weight' do
36
- s = Dalli::Server.new('localhost:11212:2')
37
- assert_equal 'localhost', s.hostname
38
- assert_equal 11212, s.port
39
- assert_equal 2, s.weight
40
- assert_equal :tcp, s.socket_type
41
- end
42
-
43
- it 'handles ipv4 addresses' do
44
- s = Dalli::Server.new('127.0.0.1')
45
- assert_equal '127.0.0.1', s.hostname
46
- assert_equal 11211, s.port
47
- assert_equal 1, s.weight
48
- assert_equal :tcp, s.socket_type
49
- end
50
-
51
- it 'handles ipv6 addresses' do
52
- s = Dalli::Server.new('[::1]')
53
- assert_equal '::1', s.hostname
54
- assert_equal 11211, s.port
55
- assert_equal 1, s.weight
56
- assert_equal :tcp, s.socket_type
57
- end
58
-
59
- it 'handles ipv6 addresses with port' do
60
- s = Dalli::Server.new('[::1]:11212')
61
- assert_equal '::1', s.hostname
62
- assert_equal 11212, s.port
63
- assert_equal 1, s.weight
64
- assert_equal :tcp, s.socket_type
65
- end
66
-
67
- it 'handles ipv6 addresses with port and weight' do
68
- s = Dalli::Server.new('[::1]:11212:2')
69
- assert_equal '::1', s.hostname
70
- assert_equal 11212, s.port
71
- assert_equal 2, s.weight
72
- assert_equal :tcp, s.socket_type
73
- end
74
-
75
- it 'handles a FQDN' do
76
- s = Dalli::Server.new('my.fqdn.com')
77
- assert_equal 'my.fqdn.com', s.hostname
78
- assert_equal 11211, s.port
79
- assert_equal 1, s.weight
80
- assert_equal :tcp, s.socket_type
81
- end
82
-
83
- it 'handles a FQDN with port and weight' do
84
- s = Dalli::Server.new('my.fqdn.com:11212:2')
85
- assert_equal 'my.fqdn.com', s.hostname
86
- assert_equal 11212, s.port
87
- assert_equal 2, s.weight
88
- assert_equal :tcp, s.socket_type
89
- end
90
-
91
- it 'throws an exception if the hostname cannot be parsed' do
92
- lambda { Dalli::Server.new('[]') }.must_raise Dalli::DalliError
93
- lambda { Dalli::Server.new('my.fqdn.com:') }.must_raise Dalli::DalliError
94
- lambda { Dalli::Server.new('my.fqdn.com:11212,:2') }.must_raise Dalli::DalliError
95
- lambda { Dalli::Server.new('my.fqdn.com:11212:abc') }.must_raise Dalli::DalliError
96
- end
97
- end
98
-
99
- describe 'ttl translation' do
100
- it 'does not translate ttls under 30 days' do
101
- s = Dalli::Server.new('localhost')
102
- assert_equal s.send(:sanitize_ttl, 30*24*60*60), 30*24*60*60
103
- end
104
-
105
- it 'translates ttls over 30 days into timestamps' do
106
- s = Dalli::Server.new('localhost')
107
- assert_equal s.send(:sanitize_ttl, 30*24*60*60 + 1), Time.now.to_i + 30*24*60*60+1
108
- end
109
- end
110
- end