dynport_tools 0.2.17 → 0.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/dynport_tools.gemspec +1 -1
- data/lib/dynport_tools/embedded_redis.rb +22 -12
- data/spec/dynport_tools/embedded_redis_spec.rb +59 -4
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.18
|
data/dynport_tools.gemspec
CHANGED
@@ -6,20 +6,28 @@ require "fileutils"
|
|
6
6
|
class DynportTools::EmbeddedRedis
|
7
7
|
include Singleton
|
8
8
|
|
9
|
-
attr_accessor :started, :base_path, :killed
|
9
|
+
attr_accessor :started, :base_path, :killed, :custom_config
|
10
10
|
attr_writer :logger
|
11
11
|
|
12
12
|
def initialize(options = {})
|
13
|
-
self.base_path = options[:base_path] || "/tmp"
|
13
|
+
self.base_path = options[:base_path] || "/tmp/embedded_redis"
|
14
14
|
self.logger = options[:logger] || Logger.new($stderr)
|
15
15
|
end
|
16
16
|
|
17
17
|
def pid_path
|
18
|
-
"#{base_path}/
|
18
|
+
"#{base_path}/redis.#{Process.pid}.pid"
|
19
19
|
end
|
20
20
|
|
21
21
|
def socket_path
|
22
|
-
"#{base_path}/
|
22
|
+
"#{base_path}/redis.#{Process.pid}.socket"
|
23
|
+
end
|
24
|
+
|
25
|
+
def dbfilename
|
26
|
+
"redis.#{Process.pid}.rdb"
|
27
|
+
end
|
28
|
+
|
29
|
+
def dbfile_path
|
30
|
+
"#{base_path}/#{dbfilename}"
|
23
31
|
end
|
24
32
|
|
25
33
|
def pid
|
@@ -43,7 +51,7 @@ class DynportTools::EmbeddedRedis
|
|
43
51
|
end
|
44
52
|
|
45
53
|
def do_start!
|
46
|
-
|
54
|
+
FileUtils.mkdir_p(base_path)
|
47
55
|
system(%(echo "#{config}" | redis-server -))
|
48
56
|
sleep 0.1
|
49
57
|
self.started = true
|
@@ -82,17 +90,19 @@ class DynportTools::EmbeddedRedis
|
|
82
90
|
log "killing #{pid}"
|
83
91
|
system(%(kill #{pid}))
|
84
92
|
FileUtils.rm_f(socket_path)
|
93
|
+
FileUtils.rm_f(dbfile_path)
|
85
94
|
self.killed = true
|
86
95
|
end
|
87
96
|
end
|
88
97
|
|
98
|
+
def default_config
|
99
|
+
{
|
100
|
+
:daemonize => "yes", :pidfile => pid_path, :port => 0, :unixsocket => socket_path, :dir => base_path,
|
101
|
+
:dbfilename => dbfilename
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
89
105
|
def config
|
90
|
-
[
|
91
|
-
"daemonize yes",
|
92
|
-
"pidfile #{pid_path}",
|
93
|
-
"port 0",
|
94
|
-
"unixsocket #{socket_path}"
|
95
|
-
|
96
|
-
].join("\n")
|
106
|
+
default_config.merge(custom_config || {}).map { |key, value| ["#{key} #{value}"] }.join("\n")
|
97
107
|
end
|
98
108
|
end
|
@@ -13,6 +13,49 @@ describe DynportTools::EmbeddedRedis do
|
|
13
13
|
|
14
14
|
after(:each) do
|
15
15
|
DynportTools::EmbeddedRedis.instance.instance_variable_set("@connection", nil)
|
16
|
+
DynportTools::EmbeddedRedis.instance.custom_config = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#kill" do
|
20
|
+
before(:each) do
|
21
|
+
er.unstub(:kill)
|
22
|
+
er.stub!(:killed?).and_return false
|
23
|
+
er.stub!(:pid).and_return "123"
|
24
|
+
FileUtils.stub!(:rm_f)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "kills the proces" do
|
28
|
+
er.should_receive(:system).with("kill 123")
|
29
|
+
er.kill
|
30
|
+
end
|
31
|
+
|
32
|
+
it "removes the socket file" do
|
33
|
+
er.should_receive(:socket_path).and_return("/path/to/socket.tst")
|
34
|
+
FileUtils.should_receive(:rm_f).with("/path/to/socket.tst")
|
35
|
+
er.kill
|
36
|
+
end
|
37
|
+
|
38
|
+
it "removes the file path" do
|
39
|
+
er.stub!(:base_path).and_return("/base/path")
|
40
|
+
er.stub!(:dbfilename).and_return("some_name")
|
41
|
+
FileUtils.should_receive(:rm_f).with("/base/path/some_name")
|
42
|
+
er.kill
|
43
|
+
end
|
44
|
+
|
45
|
+
it "sets killed to true" do
|
46
|
+
er.kill
|
47
|
+
er.killed.should == true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "does not call system when killed" do
|
51
|
+
er.stub(:killed?).and_return true
|
52
|
+
er.should_not_receive(:system)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "does not call system when pid is nil" do
|
56
|
+
er.stub(:pid?).and_return nil
|
57
|
+
er.should_not_receive(:system)
|
58
|
+
end
|
16
59
|
end
|
17
60
|
|
18
61
|
describe "#pid" do
|
@@ -75,16 +118,28 @@ describe DynportTools::EmbeddedRedis do
|
|
75
118
|
end
|
76
119
|
end
|
77
120
|
|
78
|
-
describe "
|
121
|
+
describe "#config" do
|
122
|
+
it "returns the default config" do
|
123
|
+
er.stub!(:default_config).and_return(:a => 1, :b => 2)
|
124
|
+
er.config.should == "a 1\nb 2"
|
125
|
+
end
|
126
|
+
|
127
|
+
it "merges the custom_config when defined" do
|
128
|
+
er.stub!(:default_config).and_return(:a => 1, :b => 2)
|
129
|
+
er.custom_config = { :a => 3 }
|
130
|
+
er.config.should == "a 3\nb 2"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "#do_start" do
|
79
135
|
it "sets started to true" do
|
80
136
|
er.do_start!
|
81
137
|
er.started.should be_true
|
82
138
|
end
|
83
139
|
|
84
140
|
it "creates dir of pid and socket paths" do
|
85
|
-
er.stub(:base_path).and_return "/custom_base"
|
86
|
-
FileUtils.should_receive(:mkdir_p).with("/custom_base/
|
87
|
-
FileUtils.should_receive(:mkdir_p).with("/custom_base/sockets")
|
141
|
+
er.stub(:base_path).and_return "/custom_base/test"
|
142
|
+
FileUtils.should_receive(:mkdir_p).with("/custom_base/test")
|
88
143
|
er.do_start!
|
89
144
|
end
|
90
145
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynport_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 51
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 18
|
10
|
+
version: 0.2.18
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tobias Schwab
|