zk-server 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -3
- data/lib/zk-server.rb +3 -2
- data/lib/zk-server/logging.rb +23 -0
- data/lib/zk-server/process.rb +19 -6
- data/lib/zk-server/version.rb +1 -1
- data/spec/spec_helper.rb +17 -0
- data/spec/zk-server/process_spec.rb +32 -0
- data/zk-server.gemspec +0 -1
- metadata +13 -25
data/Gemfile
CHANGED
data/lib/zk-server.rb
CHANGED
@@ -9,16 +9,16 @@ require 'socket'
|
|
9
9
|
|
10
10
|
Bundler.require
|
11
11
|
|
12
|
-
require 'zk'
|
12
|
+
# require 'zk'
|
13
13
|
|
14
14
|
#ZK.logger = Logger.new($stderr).tap { |l| l.level = Logger::DEBUG }
|
15
15
|
|
16
16
|
module ZK
|
17
17
|
module Server
|
18
|
+
|
18
19
|
ZK_JAR_GEM = 'slyphon-zookeeper_jar'
|
19
20
|
LOG4J_GEM = 'slyphon-log4j'
|
20
21
|
|
21
|
-
|
22
22
|
# Create a new {ZK::Server::Process} instance. if a block is given
|
23
23
|
# then yield the {Config} object to the block
|
24
24
|
#
|
@@ -91,6 +91,7 @@ module ZK
|
|
91
91
|
end
|
92
92
|
|
93
93
|
require 'zk-server/version'
|
94
|
+
require 'zk-server/logging'
|
94
95
|
require 'zk-server/config'
|
95
96
|
require 'zk-server/process'
|
96
97
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ZK
|
2
|
+
module Server
|
3
|
+
# default logger instance
|
4
|
+
@logger ||= Logger.new($stderr).tap { |l| l.level = Logger::FATAL }
|
5
|
+
|
6
|
+
class << self
|
7
|
+
attr_accessor :logger
|
8
|
+
end
|
9
|
+
|
10
|
+
# we might not have ZK::Logging, so we define our own
|
11
|
+
module Logging
|
12
|
+
def self.included(mod)
|
13
|
+
mod.extend(ZK::Server::Logging)
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def logger
|
18
|
+
ZK::Server.logger
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
data/lib/zk-server/process.rb
CHANGED
@@ -8,9 +8,9 @@ module ZK
|
|
8
8
|
# to store our data under (configurable).
|
9
9
|
#
|
10
10
|
class Process
|
11
|
-
include ZK::Logging
|
12
11
|
extend Forwardable
|
13
12
|
include FileUtils
|
13
|
+
include Logging
|
14
14
|
|
15
15
|
def_delegators :config,
|
16
16
|
:base_dir, :data_dir, :log4j_props_path, :log_dir, :command_args,
|
@@ -93,6 +93,7 @@ module ZK
|
|
93
93
|
rescue
|
94
94
|
false
|
95
95
|
end
|
96
|
+
alias pingable? ping?
|
96
97
|
|
97
98
|
# the pid of our child process
|
98
99
|
def pid
|
@@ -155,11 +156,23 @@ module ZK
|
|
155
156
|
end
|
156
157
|
|
157
158
|
def fork_and_exec!
|
158
|
-
@pid ||=
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
159
|
+
@pid ||=
|
160
|
+
fork do # gah, use fork because 1.8.7 sucks
|
161
|
+
3.upto(255) do |fd|
|
162
|
+
begin
|
163
|
+
if io = IO.new(fd)
|
164
|
+
io.close
|
165
|
+
end
|
166
|
+
rescue
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
$stderr.puts "stdio_redirect_path: #{stdio_redirect_path.inspect}"
|
171
|
+
$stdout.reopen($stderr)
|
172
|
+
$stderr.reopen(stdio_redirect_path, 'a')
|
173
|
+
|
174
|
+
exec(*command_args)
|
175
|
+
end
|
163
176
|
end
|
164
177
|
|
165
178
|
def create_files!
|
data/lib/zk-server/version.rb
CHANGED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
Bundler.require(:default, :development, :test)
|
5
|
+
|
6
|
+
require 'zk-server'
|
7
|
+
|
8
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
9
|
+
# in spec/support/ and its subdirectories.
|
10
|
+
Dir[File.expand_path("../{support,shared}/**/*.rb", __FILE__)].sort.each {|f| require f}
|
11
|
+
|
12
|
+
ZK::Server.logger = Logger.new($stderr).tap { |l| l.level = Logger::DEBUG }
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.mock_with :rspec
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
describe ZK::Server::Process do
|
5
|
+
let(:tmpdir) {
|
6
|
+
'/tmp/zookeeper'
|
7
|
+
}
|
8
|
+
|
9
|
+
subject do
|
10
|
+
ZK::Server::Process.new(:client_port => 21812, :base_dir => tmpdir)
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
subject.shutdown
|
15
|
+
subject.clobber!
|
16
|
+
FileUtils.rm_rf(tmpdir)
|
17
|
+
end
|
18
|
+
|
19
|
+
it %[should spawn a ZK server, ping, and then shutdown properly] do
|
20
|
+
subject.run
|
21
|
+
subject.should be_pingable
|
22
|
+
subject.should be_running
|
23
|
+
subject.should be_spawned
|
24
|
+
subject.pid.should_not be_nil
|
25
|
+
|
26
|
+
subject.shutdown
|
27
|
+
|
28
|
+
subject.should_not be_pingable
|
29
|
+
subject.should_not be_running
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
data/zk-server.gemspec
CHANGED
@@ -9,7 +9,6 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.homepage = "http://github.com/slyphon/zk-server"
|
10
10
|
|
11
11
|
s.add_runtime_dependency 'bundler', '~> 1.1.3'
|
12
|
-
s.add_runtime_dependency 'zk', '>= 1.0.0'
|
13
12
|
s.add_runtime_dependency 'slyphon-log4j', '= 1.2.15'
|
14
13
|
s.add_runtime_dependency 'slyphon-zookeeper_jar', '~> 3.3.5'
|
15
14
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zk-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 61
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 1
|
10
|
+
version: 0.8.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jonathan D. Simms
|
@@ -33,26 +33,10 @@ dependencies:
|
|
33
33
|
version: 1.1.3
|
34
34
|
type: :runtime
|
35
35
|
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: zk
|
38
|
-
prerelease: false
|
39
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
|
-
requirements:
|
42
|
-
- - ">="
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
hash: 23
|
45
|
-
segments:
|
46
|
-
- 1
|
47
|
-
- 0
|
48
|
-
- 0
|
49
|
-
version: 1.0.0
|
50
|
-
type: :runtime
|
51
|
-
version_requirements: *id002
|
52
36
|
- !ruby/object:Gem::Dependency
|
53
37
|
name: slyphon-log4j
|
54
38
|
prerelease: false
|
55
|
-
requirement: &
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
56
40
|
none: false
|
57
41
|
requirements:
|
58
42
|
- - "="
|
@@ -64,11 +48,11 @@ dependencies:
|
|
64
48
|
- 15
|
65
49
|
version: 1.2.15
|
66
50
|
type: :runtime
|
67
|
-
version_requirements: *
|
51
|
+
version_requirements: *id002
|
68
52
|
- !ruby/object:Gem::Dependency
|
69
53
|
name: slyphon-zookeeper_jar
|
70
54
|
prerelease: false
|
71
|
-
requirement: &
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
72
56
|
none: false
|
73
57
|
requirements:
|
74
58
|
- - ~>
|
@@ -80,7 +64,7 @@ dependencies:
|
|
80
64
|
- 5
|
81
65
|
version: 3.3.5
|
82
66
|
type: :runtime
|
83
|
-
version_requirements: *
|
67
|
+
version_requirements: *id003
|
84
68
|
description: runs a standalone zookeeper server
|
85
69
|
email:
|
86
70
|
- slyphon@gmail.com
|
@@ -102,8 +86,11 @@ files:
|
|
102
86
|
- lib/zk-server.rb
|
103
87
|
- lib/zk-server/config.rb
|
104
88
|
- lib/zk-server/log4j.properties
|
89
|
+
- lib/zk-server/logging.rb
|
105
90
|
- lib/zk-server/process.rb
|
106
91
|
- lib/zk-server/version.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
- spec/zk-server/process_spec.rb
|
107
94
|
- zk-server.gemspec
|
108
95
|
homepage: http://github.com/slyphon/zk-server
|
109
96
|
licenses: []
|
@@ -138,5 +125,6 @@ rubygems_version: 1.8.15
|
|
138
125
|
signing_key:
|
139
126
|
specification_version: 3
|
140
127
|
summary: runs a standalone zookeeper server
|
141
|
-
test_files:
|
142
|
-
|
128
|
+
test_files:
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
- spec/zk-server/process_spec.rb
|