ernie 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ begin
12
12
  gem.files.include(["ext"])
13
13
  gem.extensions << 'ext/extconf.rb'
14
14
  gem.add_dependency('erlectricity', '>= 1.0.1')
15
- gem.add_dependency('bertrpc', '>= 0.2.0')
15
+ gem.add_dependency('bertrpc', '>= 0.3.4')
16
16
 
17
17
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
18
  end
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 4
2
+ :patch: 5
3
3
  :major: 0
4
4
  :minor: 3
@@ -71,9 +71,7 @@ handle_call(_Request, _From, State) ->
71
71
  handle_cast({process, Sock}, State) ->
72
72
  Request = #request{sock = Sock},
73
73
  State2 = receive_term(Request, State),
74
- Count = State2#state.count,
75
- State3 = State2#state{count = Count + 1},
76
- {noreply, State3};
74
+ {noreply, State2};
77
75
  handle_cast({asset_freed}, State) ->
78
76
  case queue:is_empty(State#state.pending) of
79
77
  false ->
@@ -187,15 +185,17 @@ process_request(Request, State) ->
187
185
  end.
188
186
 
189
187
  try_process_now(Request, State) ->
188
+ Count = State#state.count,
189
+ State2 = State#state{count = Count + 1},
190
190
  case asset_pool:lease() of
191
191
  {ok, Asset} ->
192
192
  % io:format("i", []),
193
193
  spawn(fun() -> process_now(Request, Asset) end),
194
- State;
194
+ State2;
195
195
  empty ->
196
196
  % io:format("q", []),
197
197
  Pending2 = queue:in(Request, State#state.pending),
198
- State#state{pending = Pending2}
198
+ State2#state{pending = Pending2}
199
199
  end.
200
200
 
201
201
  process_now(Request, Asset) ->
data/ernie.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ernie}
5
- s.version = "0.3.4"
5
+ s.version = "0.3.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Tom Preston-Werner"]
9
- s.date = %q{2009-09-06}
9
+ s.date = %q{2009-09-25}
10
10
  s.default_executable = %q{ernie}
11
11
  s.email = %q{tom@mojombo.com}
12
12
  s.executables = ["ernie"]
@@ -37,9 +37,11 @@ Gem::Specification.new do |s|
37
37
  "ext/Makefile",
38
38
  "ext/extconf.rb",
39
39
  "lib/ernie.rb",
40
+ "test/ernie_server_test.rb",
40
41
  "test/ernie_test.rb",
41
- "test/load.rb",
42
- "test/test_helper.rb"
42
+ "test/handler.rb",
43
+ "test/helper.rb",
44
+ "test/load.rb"
43
45
  ]
44
46
  s.homepage = %q{http://github.com/mojombo/ernie}
45
47
  s.rdoc_options = ["--charset=UTF-8"]
@@ -47,9 +49,11 @@ Gem::Specification.new do |s|
47
49
  s.rubygems_version = %q{1.3.5}
48
50
  s.summary = %q{Ernie is a BERT-RPC server implementation.}
49
51
  s.test_files = [
50
- "test/ernie_test.rb",
52
+ "test/ernie_server_test.rb",
53
+ "test/ernie_test.rb",
54
+ "test/handler.rb",
55
+ "test/helper.rb",
51
56
  "test/load.rb",
52
- "test/test_helper.rb",
53
57
  "examples/calc.rb"
54
58
  ]
55
59
 
@@ -59,13 +63,13 @@ Gem::Specification.new do |s|
59
63
 
60
64
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
61
65
  s.add_runtime_dependency(%q<erlectricity>, [">= 1.0.1"])
62
- s.add_runtime_dependency(%q<bertrpc>, [">= 0.2.0"])
66
+ s.add_runtime_dependency(%q<bertrpc>, [">= 0.3.4"])
63
67
  else
64
68
  s.add_dependency(%q<erlectricity>, [">= 1.0.1"])
65
- s.add_dependency(%q<bertrpc>, [">= 0.2.0"])
69
+ s.add_dependency(%q<bertrpc>, [">= 0.3.4"])
66
70
  end
67
71
  else
68
72
  s.add_dependency(%q<erlectricity>, [">= 1.0.1"])
69
- s.add_dependency(%q<bertrpc>, [">= 0.2.0"])
73
+ s.add_dependency(%q<bertrpc>, [">= 0.3.4"])
70
74
  end
71
75
  end
data/lib/ernie.rb CHANGED
@@ -59,7 +59,7 @@ class Ernie
59
59
  def self.dispatch(mod, fun, args)
60
60
  xargs = deconvert(args)
61
61
  self.log("-- " + [mod, fun, xargs].inspect)
62
- self.mods[mod] || raise(ServerError.new("No such module: '#{mod}'"))
62
+ self.mods[mod] || raise(ServerError.new("No such module '#{mod}'"))
63
63
  self.mods[mod].funs[fun] || raise(ServerError.new("No such function '#{mod}:#{fun}'"))
64
64
  res = self.mods[mod].funs[fun].call(*xargs)
65
65
  convert(res)
@@ -77,12 +77,12 @@ class Ernie
77
77
  self.log("<- " + xres.inspect)
78
78
  f.send!(xres)
79
79
  rescue ServerError => e
80
- xres = [:error, [:server, 0, e.message, e.backtrace]]
80
+ xres = [:error, [:server, 0, e.class.to_s, e.message, e.backtrace]]
81
81
  self.log("<- " + xres.inspect)
82
82
  self.log(e.backtrace.join("\n"))
83
83
  f.send!(xres)
84
84
  rescue Object => e
85
- xres = [:error, [:user, 0, e.message, e.backtrace]]
85
+ xres = [:error, [:user, 0, e.class.to_s, e.message, e.backtrace]]
86
86
  self.log("<- " + xres.inspect)
87
87
  self.log(e.backtrace.join("\n"))
88
88
  f.send!(xres)
@@ -0,0 +1,73 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ PORT = 27118
4
+
5
+ class ErnieServerTest < Test::Unit::TestCase
6
+ context "An Ernie Server" do
7
+ setup do
8
+ `#{ERNIE_ROOT}/bin/ernie -h #{ERNIE_ROOT}/test/handler.rb \
9
+ -P /tmp/ernie.pid \
10
+ -p #{PORT} \
11
+ -d`
12
+ @svc = BERTRPC::Service.new('localhost', PORT)
13
+ loop do
14
+ begin
15
+ @svc.call.test.zeronary
16
+ break
17
+ rescue Object => e
18
+ sleep 0.1
19
+ end
20
+ end
21
+ end
22
+
23
+ context "call" do
24
+ should "handle zeronary" do
25
+ assert_equal :foo, @svc.call.test.zeronary
26
+ end
27
+
28
+ should "handle unary" do
29
+ assert_equal 5, @svc.call.test.unary(5)
30
+ end
31
+
32
+ should "handle binary" do
33
+ assert_equal 7, @svc.call.test.binary(5, 2)
34
+ end
35
+
36
+ should "handle ternary" do
37
+ assert_equal 10, @svc.call.test.ternary(5, 2, 3)
38
+ end
39
+
40
+ should "get an error on missing module" do
41
+ begin
42
+ @svc.call.failboat.mcfail(:fail)
43
+ fail "Expected a BERTRPC::ServerError"
44
+ rescue BERTRPC::ServerError => e
45
+ assert_equal "No such module 'failboat'", e.message
46
+ end
47
+ end
48
+
49
+ should "get an error on missing function" do
50
+ begin
51
+ @svc.call.test.mcfail(:fail)
52
+ fail "Expected a BERTRPC::ServerError"
53
+ rescue BERTRPC::ServerError => e
54
+ assert_equal "No such function 'test:mcfail'", e.message
55
+ end
56
+ end
57
+ end
58
+
59
+ context "cast" do
60
+ should "be received and return immediately" do
61
+ t0 = Time.now
62
+ assert_equal nil, @svc.cast.test.set_state(7)
63
+ assert Time.now - t0 < 1
64
+ assert_equal 7, @svc.call.test.get_state
65
+ end
66
+ end
67
+
68
+ teardown do
69
+ pid = File.read('/tmp/ernie.pid')
70
+ `kill -9 #{pid}`
71
+ end
72
+ end
73
+ end
data/test/ernie_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require File.dirname(__FILE__) + '/helper'
2
2
 
3
3
  class ErnieTest < Test::Unit::TestCase
4
4
  context "mod" do
data/test/handler.rb ADDED
@@ -0,0 +1,37 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'ernie'
3
+
4
+ state = 0
5
+
6
+ # Just about the easiest example I could thing of.
7
+ mod(:test) do
8
+ fun(:zeronary) do
9
+ :foo
10
+ end
11
+
12
+ fun(:unary) do |a|
13
+ a
14
+ end
15
+
16
+ fun(:binary) do |a, b|
17
+ a + b
18
+ end
19
+
20
+ fun(:ternary) do |a, b, c|
21
+ a + b + c
22
+ end
23
+
24
+ fun(:set_state) do |x|
25
+ state = x
26
+ sleep 5
27
+ nil
28
+ end
29
+
30
+ fun(:get_state) do
31
+ state
32
+ end
33
+
34
+ fun(:cry) do
35
+ raise "abandon hope!"
36
+ end
37
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ ERNIE_ROOT = File.join(File.dirname(__FILE__), *%w[..])
6
+
7
+ $:.unshift(File.join(ERNIE_ROOT, 'lib'))
8
+
9
+ require 'ernie'
10
+ begin
11
+ require 'bertrpc'
12
+ rescue LoadError
13
+ puts "You need bertrpc gem installed to run tests."
14
+ exit!(1)
15
+ end
16
+
17
+ $test = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ernie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Preston-Werner
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-06 00:00:00 -07:00
12
+ date: 2009-09-25 00:00:00 -07:00
13
13
  default_executable: ernie
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.0
33
+ version: 0.3.4
34
34
  version:
35
35
  description:
36
36
  email: tom@mojombo.com
@@ -63,9 +63,11 @@ files:
63
63
  - ext/Makefile
64
64
  - ext/extconf.rb
65
65
  - lib/ernie.rb
66
+ - test/ernie_server_test.rb
66
67
  - test/ernie_test.rb
68
+ - test/handler.rb
69
+ - test/helper.rb
67
70
  - test/load.rb
68
- - test/test_helper.rb
69
71
  has_rdoc: true
70
72
  homepage: http://github.com/mojombo/ernie
71
73
  licenses: []
@@ -95,7 +97,9 @@ signing_key:
95
97
  specification_version: 3
96
98
  summary: Ernie is a BERT-RPC server implementation.
97
99
  test_files:
100
+ - test/ernie_server_test.rb
98
101
  - test/ernie_test.rb
102
+ - test/handler.rb
103
+ - test/helper.rb
99
104
  - test/load.rb
100
- - test/test_helper.rb
101
105
  - examples/calc.rb
data/test/test_helper.rb DELETED
@@ -1,12 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'ernie'
8
-
9
- class Test::Unit::TestCase
10
- end
11
-
12
- $test = true