redic-sentinels 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,110 @@
1
+ require_relative 'minitest_helper'
2
+
3
+ describe Redic::Sentinels do
4
+
5
+ VALID_HOSTS = [
6
+ 'localhost:26379',
7
+ 'localhost:26380',
8
+ 'localhost:26381'
9
+ ].shuffle
10
+
11
+ INVALID_HOSTS = [
12
+ 'localhost:26382',
13
+ 'localhost:26383'
14
+ ].shuffle
15
+
16
+ HOSTS = (VALID_HOSTS + INVALID_HOSTS).shuffle
17
+
18
+ MASTER_NAME = 'mymaster'
19
+
20
+ def disconnect(redis)
21
+ redis.client.configure "redis://#{INVALID_HOSTS.sample}"
22
+ end
23
+
24
+ after do
25
+ master = Redic.new 'redis://localhost:16379'
26
+ master.call! 'FLUSHDB'
27
+ end
28
+
29
+ describe 'Connection success' do
30
+
31
+ let(:redis) { Redic::Sentinels.new hosts: HOSTS, master_name: MASTER_NAME }
32
+
33
+ it 'call' do
34
+ redis.call('PING').must_equal 'PONG'
35
+ redis.call('INVALID_COMMAND').must_be_instance_of RuntimeError
36
+ end
37
+
38
+ it 'call!' do
39
+ redis.call!('PING').must_equal 'PONG'
40
+ proc { redis.call! 'INVALID_COMMAND' }.must_raise RuntimeError
41
+ end
42
+
43
+ it 'queue/commit' do
44
+ redis.queue('PING').must_equal [['PING']]
45
+ redis.queue('PING').must_equal [['PING'], ['PING']]
46
+ redis.commit.must_equal ['PONG', 'PONG']
47
+ end
48
+
49
+ it 'clear' do
50
+ redis.queue 'PING'
51
+ redis.client.buffer.must_equal [['PING']]
52
+
53
+ redis.clear
54
+ redis.client.buffer.must_be_empty
55
+ end
56
+
57
+ it 'get/set' do
58
+ redis.call!('GET', 'key1').must_be_nil
59
+ redis.call! 'SET', 'key1', 'value1'
60
+ redis.call!('GET', 'key1').must_equal 'value1'
61
+ end
62
+
63
+ it 'Retry on connection failures' do
64
+ redis.call('PING').must_equal 'PONG'
65
+
66
+ disconnect redis
67
+
68
+ redis.call('PING').must_equal 'PONG'
69
+ redis.queue('PING').must_equal [['PING']]
70
+
71
+ disconnect redis
72
+
73
+ redis.queue('PING').must_equal [['PING'], ['PING']]
74
+ redis.commit.must_equal ['PONG', 'PONG']
75
+ end
76
+
77
+ it 'Default DB' do
78
+ redis.client.url.must_equal 'redis://127.0.0.1:16379/0'
79
+ end
80
+
81
+ it 'Custom DB' do
82
+ redis = Redic::Sentinels.new hosts: HOSTS, master_name: MASTER_NAME, db: 7
83
+ redis.client.url.must_equal 'redis://127.0.0.1:16379/7'
84
+ end
85
+
86
+ it 'Auth' do
87
+ redis = Redic::Sentinels.new hosts: HOSTS, master_name: MASTER_NAME, password: 'pass'
88
+ redis.client.url.must_equal 'redis://:pass@127.0.0.1:16379/0'
89
+ end
90
+
91
+ end
92
+
93
+ describe 'Connection fail' do
94
+
95
+ it 'Invalid hosts' do
96
+ invalid_hosts = ['localhost:26382', 'localhost:26383']
97
+ proc { Redic::Sentinels.new hosts: invalid_hosts, master_name: MASTER_NAME }.must_raise Redic::Sentinels::UnreachableHosts
98
+ end
99
+
100
+ it 'Whithout hosts' do
101
+ proc { Redic::Sentinels.new hosts: [], master_name: MASTER_NAME }.must_raise Redic::Sentinels::UnreachableHosts
102
+ end
103
+
104
+ it 'Invalid master' do
105
+ proc { Redic::Sentinels.new hosts: VALID_HOSTS, master_name: 'invalid_master' }.must_raise Redic::Sentinels::UnknownMaster
106
+ end
107
+
108
+ end
109
+
110
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redic-sentinels
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel Naiman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redic
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-colorin
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-line
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.12'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.12'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.8'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry-nav
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.2'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.2'
139
+ description: Redic::Sentinels is a wrapper for the Redis client that fetches configuration
140
+ details from sentinels
141
+ email:
142
+ - gabynaiman@gmail.com
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".coveralls.yml"
148
+ - ".gitignore"
149
+ - ".ruby-gemset"
150
+ - ".ruby-version"
151
+ - ".travis.yml"
152
+ - Gemfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - config/redis-master.conf
157
+ - config/redis-sentinel-1.conf
158
+ - config/redis-sentinel-2.conf
159
+ - config/redis-sentinel-3.conf
160
+ - config/redis-slave.conf
161
+ - lib/redic-sentinels.rb
162
+ - lib/redic/sentinels.rb
163
+ - lib/redic/sentinels/version.rb
164
+ - redic-sentinels.gemspec
165
+ - spec/minitest_helper.rb
166
+ - spec/sentinels_spec.rb
167
+ homepage: https://github.com/gabynaiman/redic-sentinels
168
+ licenses:
169
+ - MIT
170
+ metadata: {}
171
+ post_install_message:
172
+ rdoc_options: []
173
+ require_paths:
174
+ - lib
175
+ required_ruby_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ required_rubygems_version: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ requirements: []
186
+ rubyforge_project:
187
+ rubygems_version: 2.5.1
188
+ signing_key:
189
+ specification_version: 4
190
+ summary: Redic::Sentinels is a wrapper for the Redis client that fetches configuration
191
+ details from sentinels
192
+ test_files:
193
+ - spec/minitest_helper.rb
194
+ - spec/sentinels_spec.rb