mailbox 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/mailbox.rb +12 -2
- data/mailbox.gemspec +2 -2
- data/test/mailbox_test.rb +50 -0
- metadata +3 -3
data/VERSION.yml
CHANGED
data/lib/mailbox.rb
CHANGED
@@ -33,7 +33,17 @@ module Mailbox
|
|
33
33
|
# methods should be run on the calling thread.
|
34
34
|
#
|
35
35
|
# <b>*** Intended for synchronous unit testing of concurrent apps***</b>
|
36
|
-
|
36
|
+
attr_reader :synchronous, :raise_exceptions_immediately
|
37
|
+
|
38
|
+
def synchronous= value
|
39
|
+
@synchronous = value
|
40
|
+
@raise_exceptions_immediately = false if value == false
|
41
|
+
end
|
42
|
+
|
43
|
+
def raise_exceptions_immediately= value
|
44
|
+
raise Exception.new('cannot set raise_exceptions_immediately when not in synchronous mode!') if value && !Mailbox.synchronous
|
45
|
+
@raise_exceptions_immediately = value
|
46
|
+
end
|
37
47
|
|
38
48
|
end
|
39
49
|
|
@@ -140,7 +150,7 @@ module Mailbox
|
|
140
150
|
self.send(@__verbose_target__, "dequeued #{method_name}") if defined? @__verbose_target__
|
141
151
|
result = self.send(:"__#{method_name}__", *args )
|
142
152
|
rescue Exception => ex
|
143
|
-
raise if exception_method.nil?
|
153
|
+
raise if exception_method.nil? || Mailbox.raise_exceptions_immediately
|
144
154
|
self.send(:"#{exception_method}", ex)
|
145
155
|
ensure
|
146
156
|
latch.count_down if replyable
|
data/mailbox.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mailbox}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Joel Friedman", "Patrick Farley"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-05-18}
|
13
13
|
s.description = %q{Mailbox is a JRuby module that simplifies concurrency and is backed by JVM threads.}
|
14
14
|
s.email = %q{asher.friedman@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/mailbox_test.rb
CHANGED
@@ -75,6 +75,56 @@ class MailboxTest < Test::Unit::TestCase
|
|
75
75
|
assert Mailbox.synchronous == false, "Mailbox is defaulting to synchronous execution"
|
76
76
|
end
|
77
77
|
|
78
|
+
def test_default_is_run_with_exception_callbacks
|
79
|
+
assert !Mailbox.raise_exceptions_immediately, "Mailbox is defaulting to raising exceptions immediately"
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_cannot_set_raise_exceptions_immediately_unless_in_synchronous_mode
|
83
|
+
begin
|
84
|
+
assert !Mailbox.synchronous
|
85
|
+
assert_raises(Exception) { Mailbox.raise_exceptions_immediately = true }
|
86
|
+
ensure
|
87
|
+
Mailbox.raise_exceptions_immediately = false
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_raise_exceptions_immediately_is_turned_off_when_setting_synchronous_to_false
|
92
|
+
begin
|
93
|
+
Mailbox.synchronous = true
|
94
|
+
Mailbox.raise_exceptions_immediately = true
|
95
|
+
Mailbox.synchronous = false
|
96
|
+
assert !Mailbox.raise_exceptions_immediately
|
97
|
+
ensure
|
98
|
+
Mailbox.synchronous = false
|
99
|
+
Mailbox.raise_exceptions_immediately = false
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_can_set_mailbox_to_ignore_exception_callback_and_raise_exceptions_for_tests
|
104
|
+
begin
|
105
|
+
Mailbox.synchronous = true
|
106
|
+
Mailbox.raise_exceptions_immediately = true
|
107
|
+
klass = Class.new do
|
108
|
+
include Mailbox
|
109
|
+
mailslot :exception => :should_not_run
|
110
|
+
def test_method
|
111
|
+
raise Exception.new('test exception')
|
112
|
+
end
|
113
|
+
|
114
|
+
def should_not_run exception
|
115
|
+
raise Exception.new('exception handled')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
obj = klass.new
|
120
|
+
raised = assert_raises(Exception) { obj.test_method }
|
121
|
+
assert_equal 'test exception', raised.message
|
122
|
+
ensure
|
123
|
+
Mailbox.raise_exceptions_immediately = false
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
78
128
|
def test_can_set_mailslot_to_run_synchronously
|
79
129
|
begin
|
80
130
|
Mailbox.synchronous = true
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 3
|
9
|
+
version: 0.2.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joel Friedman
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-05-18 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|