torquebox-core 2.3.2-java → 3.0.0.beta1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/torquebox/codecs/edn.rb +36 -0
- data/lib/torquebox/codecs/json.rb +61 -0
- data/lib/torquebox/codecs/marshal.rb +35 -0
- data/lib/torquebox/codecs/marshal_base64.rb +36 -0
- data/lib/torquebox/codecs/marshal_smart.rb +51 -0
- data/lib/torquebox/codecs.rb +65 -0
- data/lib/torquebox/injectors.rb +41 -10
- data/lib/torquebox/kernel.rb +1 -0
- data/lib/torquebox/logger.rb +13 -0
- data/lib/torquebox/msc.rb +60 -4
- data/lib/torquebox/registry.rb +9 -2
- data/lib/torquebox/scheduled_job.rb +174 -5
- data/lib/torquebox-core.jar +0 -0
- data/lib/torquebox-core.rb +2 -2
- data/licenses/cc0-1.0.txt +121 -0
- data/spec/codecs_spec.rb +87 -0
- data/spec/injectors_spec.rb +8 -13
- data/spec/scheduled_job_spec.rb +57 -0
- metadata +54 -12
- data/licenses/lgpl-2.1.txt +0 -502
@@ -20,6 +20,157 @@ module TorqueBox
|
|
20
20
|
class ScheduledJob
|
21
21
|
class << self
|
22
22
|
|
23
|
+
# Creates a new scheduled job.
|
24
|
+
#
|
25
|
+
# @note This is an asynchronous method.
|
26
|
+
# @param class_name The scheduled job implementation
|
27
|
+
# class name
|
28
|
+
# @param cron The cron expression defining when the job
|
29
|
+
# should run
|
30
|
+
# @param options Optional parameters (a Hash), including:
|
31
|
+
# @option options [String] :name The job name unique across the application, if not provided set to the class name
|
32
|
+
# @option options [String] :description Job description
|
33
|
+
# @option options [String] :timeout The time after the job execution should be interrupted. By default it'll never interrupt the job execution. Example: '2s', '1m'
|
34
|
+
# @option options [Hash] :config Data that should be injected to the job constructor
|
35
|
+
# @option options [Boolean] :stopped If the job should be stopped after installation (default: false)
|
36
|
+
# @option options [Boolean] :singleton Flag to determine if the job should be executed on every node (set to true, default) in the cluster or only on one node (set to false).
|
37
|
+
# @return [java.util.concurrent.CountDownLatch] The latch to wait for the task completion
|
38
|
+
# @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CountDownLatch.html
|
39
|
+
#
|
40
|
+
# @example A simple job
|
41
|
+
# TorqueBox::ScheduledJob.schedule('SimpleJob', "*/10 * * * * ?")
|
42
|
+
#
|
43
|
+
# @example A simple job with custom name
|
44
|
+
# TorqueBox::ScheduledJob.schedule('SimpleJob', "*/10 * * * * ?", :name => "simple.job")
|
45
|
+
#
|
46
|
+
# @example Schedule a job with data to be injected to the job constructor
|
47
|
+
# ScheduledJob.schedule('SimpleJob', "*/10 * * * * ?", :name => "simple.config.job", :config => {:text => "text", :hash => {:a => 2}})
|
48
|
+
#
|
49
|
+
# @example Schedule a job stopped after creation
|
50
|
+
# TorqueBox::ScheduledJob.schedule('SimpleJob', "*/10 * * * * ?", :stopped => true)
|
51
|
+
def schedule(class_name, cron, options = {})
|
52
|
+
raise "No job class name provided" if class_name.nil?
|
53
|
+
raise "No cron expression provided" if cron.nil?
|
54
|
+
|
55
|
+
options = {
|
56
|
+
:name => class_name.to_s,
|
57
|
+
:singleton => true,
|
58
|
+
:stopped => false,
|
59
|
+
:timeout => "0s"
|
60
|
+
}.merge(options)
|
61
|
+
|
62
|
+
with_schedulizer do |schedulizer|
|
63
|
+
schedulizer.create_job(class_name.to_s, cron, options[:timeout], options[:name], options[:description], options[:config], options[:singleton], options[:stopped])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Creates a new scheduled job.
|
68
|
+
#
|
69
|
+
# @note This is a synchronous method.
|
70
|
+
# @note This method accepts the same parameters as available in the schedule method.
|
71
|
+
# @return [Boolean] true if the job was successfully created, false otherwise
|
72
|
+
# @see TorqueBox::ScheduledJob.schedule
|
73
|
+
def schedule_sync(class_name, cron, options = {})
|
74
|
+
latch = schedule(class_name, cron, options)
|
75
|
+
wait_for_latch(latch)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Creates new 'at' job.
|
79
|
+
#
|
80
|
+
# @note This is an asynchronous method.
|
81
|
+
# @param class_name [String] The class name of the scheduled job to be executed
|
82
|
+
# @param options [Hash] A hash containing the at job options:
|
83
|
+
# @option options [Time] :at [Time] The start time of the job
|
84
|
+
# @option options [Fixnum] :in Specifies when the job execution should start, in ms
|
85
|
+
# @option options [Fixnum] :repeat Specifies the number of times to execute the job
|
86
|
+
# @option options [Fixnum] :every Specifies the delay (in ms) between job executions
|
87
|
+
# @option options [Time] :until The stop time of job execution
|
88
|
+
# @option options [String] :name The job name unique across the application, by default set to the job class name
|
89
|
+
# @option options [String] :description Job description
|
90
|
+
# @option options [String] :timeout The time after the job execution should be interrupted. By default it'll never interrupt the job execution. Example: '2s', '1m'
|
91
|
+
# @option options [Hash] :config Data that should be injected to the job constructor
|
92
|
+
# @option options [Boolean] :singleton Flag to determine if the job should be executed on every node (set to true) in the cluster or only on one node (set to false, default).
|
93
|
+
# @return [java.util.concurrent.CountDownLatch] The latch to wait for the task completion
|
94
|
+
# @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CountDownLatch.html
|
95
|
+
#
|
96
|
+
# @example Run a job every 200 ms for over 5 seconds, from now
|
97
|
+
# TorqueBox::ScheduledJob.at('SimpleJob', :every => 200, :until => Time.now + 5)
|
98
|
+
#
|
99
|
+
# @example Start in 1 second, then every 200 ms for over 4 seconds (5 seconds from now, but start is delayed):
|
100
|
+
# TorqueBox::ScheduledJob.at('SimpleJob', :at => Time.now + 1, :every => 200, :until => Time.now + 5)
|
101
|
+
#
|
102
|
+
# @example Start in 1 second, then every 200 ms for over 4 seconds (5 seconds from now, but start is delayed):
|
103
|
+
# TorqueBox::ScheduledJob.at('SimpleJob', :in => 1_000, :every => 200, :until => Time.now + 5)
|
104
|
+
#
|
105
|
+
# @example Start in 1 second, then repeat te job 10 times, every 200 ms
|
106
|
+
# TorqueBox::ScheduledJob.at('SimpleJob', :in => 1_000, :repeat => 10, :every => 200)
|
107
|
+
def at(class_name, options = {})
|
108
|
+
raise "No job class name provided" if class_name.nil?
|
109
|
+
raise "Invalid options for scheduling the job" if options.nil? or !options.is_a?(Hash)
|
110
|
+
raise "Invalid type for :in, should be a Fixnum" if !options[:in].nil? and !options[:in].is_a?(Fixnum)
|
111
|
+
raise "You can't specify both :at and :in" if options.has_key?(:at) and options.has_key?(:in)
|
112
|
+
raise "You can't specify :repeat without :every" if options.has_key?(:repeat) and !options.has_key?(:every)
|
113
|
+
raise "You can't specify :until without :every" if options.has_key?(:until) and !options.has_key?(:every)
|
114
|
+
|
115
|
+
options = {
|
116
|
+
:singleton => false,
|
117
|
+
:name => class_name,
|
118
|
+
:timeout => "0s",
|
119
|
+
:repeat => 0,
|
120
|
+
:every => 0,
|
121
|
+
:at => Time.now,
|
122
|
+
:async => true
|
123
|
+
}.merge(options)
|
124
|
+
|
125
|
+
if options.has_key?(:in)
|
126
|
+
start = Time.now + options[:in] / 1000.0
|
127
|
+
else
|
128
|
+
start = options[:at]
|
129
|
+
end
|
130
|
+
|
131
|
+
with_schedulizer do |schedulizer|
|
132
|
+
schedulizer.create_at_job(class_name.to_s, start, options[:until], options[:every], options[:repeat], options[:timeout], options[:name], options[:description], options[:config], options[:singleton])
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# Creates new 'at' job.
|
137
|
+
#
|
138
|
+
# @note This is a synchronous method.
|
139
|
+
# @note This method accepts the same parameters as available in the at method.
|
140
|
+
# @return [Boolean] true if the job was successfully created, false otherwise
|
141
|
+
# @see TorqueBox::ScheduledJob.at
|
142
|
+
def at_sync(class_name, options = {})
|
143
|
+
latch = at(class_name, options)
|
144
|
+
wait_for_latch(latch)
|
145
|
+
end
|
146
|
+
|
147
|
+
# Removes a scheduled job.
|
148
|
+
#
|
149
|
+
# This method removes the job asynchronously.
|
150
|
+
#
|
151
|
+
# @param name [String] The job name.
|
152
|
+
# @return [java.util.concurrent.CountDownLatch] The latch to wait for the task completion
|
153
|
+
# @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CountDownLatch.html
|
154
|
+
def remove(name)
|
155
|
+
raise "No job name provided" if name.nil?
|
156
|
+
raise "Couldn't find a job with name '#{name}''" if TorqueBox::ScheduledJob.lookup(name).nil?
|
157
|
+
|
158
|
+
with_schedulizer do |schedulizer|
|
159
|
+
schedulizer.remove_job(name)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
# Removes a scheduled job.
|
164
|
+
#
|
165
|
+
# @note This is a synchronous method.
|
166
|
+
# @note This method accepts the same parameters as available in the remove method.
|
167
|
+
# @return [Boolean] true if the job was successfully removed, false otherwise
|
168
|
+
# @see TorqueBox::ScheduledJob.remove
|
169
|
+
def remove_sync(name)
|
170
|
+
latch = remove(name)
|
171
|
+
wait_for_latch(latch)
|
172
|
+
end
|
173
|
+
|
23
174
|
# List all scheduled jobs of this application.
|
24
175
|
#
|
25
176
|
# @return [Array<org.torquebox.jobs.ScheduledJob>] the list of
|
@@ -27,14 +178,15 @@ module TorqueBox
|
|
27
178
|
# {TorqueBox::ScheduledJob.lookup} for more details on these
|
28
179
|
# instances
|
29
180
|
def list
|
30
|
-
prefix =
|
181
|
+
prefix = job_service_name.canonical_name
|
31
182
|
service_names = TorqueBox::MSC.service_names.select do |service_name|
|
32
183
|
name = service_name.canonical_name
|
33
184
|
name.start_with?(prefix) && !name.end_with?('mbean')
|
34
185
|
end
|
35
186
|
service_names.map do |service_name|
|
36
|
-
TorqueBox::MSC.get_service(service_name)
|
37
|
-
|
187
|
+
service = TorqueBox::MSC.get_service(service_name)
|
188
|
+
service.nil? ? nil : service.value
|
189
|
+
end.select { |v| !v.nil? }
|
38
190
|
end
|
39
191
|
|
40
192
|
# Lookup a scheduled job of this application by name.
|
@@ -60,17 +212,34 @@ module TorqueBox
|
|
60
212
|
# job.stop
|
61
213
|
# job.status => 'STOPPED'
|
62
214
|
def lookup(name)
|
63
|
-
service_name =
|
215
|
+
service_name = job_service_name.append(name)
|
64
216
|
service = TorqueBox::MSC.get_service(service_name)
|
65
217
|
service.nil? ? nil : service.value
|
66
218
|
end
|
67
219
|
|
68
220
|
private
|
69
221
|
|
70
|
-
|
222
|
+
# @api private
|
223
|
+
def job_service_name
|
71
224
|
TorqueBox::MSC.deployment_unit.service_name.append('scheduled_job')
|
72
225
|
end
|
73
226
|
|
227
|
+
# @api private
|
228
|
+
def with_schedulizer
|
229
|
+
yield TorqueBox::ServiceRegistry.lookup(TorqueBox::MSC.deployment_unit.service_name.append('job_schedulizer'))
|
230
|
+
end
|
231
|
+
|
232
|
+
# @api private
|
233
|
+
def wait_for_latch(latch)
|
234
|
+
begin
|
235
|
+
# Wait for the services to come up for up to 30 seconds
|
236
|
+
latch.await(30, java.util.concurrent.TimeUnit::SECONDS)
|
237
|
+
rescue
|
238
|
+
return false
|
239
|
+
end
|
240
|
+
|
241
|
+
true
|
242
|
+
end
|
74
243
|
end
|
75
244
|
end
|
76
245
|
end
|
data/lib/torquebox-core.jar
CHANGED
Binary file
|
data/lib/torquebox-core.rb
CHANGED
@@ -0,0 +1,121 @@
|
|
1
|
+
Creative Commons Legal Code
|
2
|
+
|
3
|
+
CC0 1.0 Universal
|
4
|
+
|
5
|
+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
6
|
+
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
7
|
+
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
8
|
+
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
9
|
+
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
10
|
+
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
11
|
+
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
12
|
+
HEREUNDER.
|
13
|
+
|
14
|
+
Statement of Purpose
|
15
|
+
|
16
|
+
The laws of most jurisdictions throughout the world automatically confer
|
17
|
+
exclusive Copyright and Related Rights (defined below) upon the creator
|
18
|
+
and subsequent owner(s) (each and all, an "owner") of an original work of
|
19
|
+
authorship and/or a database (each, a "Work").
|
20
|
+
|
21
|
+
Certain owners wish to permanently relinquish those rights to a Work for
|
22
|
+
the purpose of contributing to a commons of creative, cultural and
|
23
|
+
scientific works ("Commons") that the public can reliably and without fear
|
24
|
+
of later claims of infringement build upon, modify, incorporate in other
|
25
|
+
works, reuse and redistribute as freely as possible in any form whatsoever
|
26
|
+
and for any purposes, including without limitation commercial purposes.
|
27
|
+
These owners may contribute to the Commons to promote the ideal of a free
|
28
|
+
culture and the further production of creative, cultural and scientific
|
29
|
+
works, or to gain reputation or greater distribution for their Work in
|
30
|
+
part through the use and efforts of others.
|
31
|
+
|
32
|
+
For these and/or other purposes and motivations, and without any
|
33
|
+
expectation of additional consideration or compensation, the person
|
34
|
+
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
35
|
+
is an owner of Copyright and Related Rights in the Work, voluntarily
|
36
|
+
elects to apply CC0 to the Work and publicly distribute the Work under its
|
37
|
+
terms, with knowledge of his or her Copyright and Related Rights in the
|
38
|
+
Work and the meaning and intended legal effect of CC0 on those rights.
|
39
|
+
|
40
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
41
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
42
|
+
Related Rights"). Copyright and Related Rights include, but are not
|
43
|
+
limited to, the following:
|
44
|
+
|
45
|
+
i. the right to reproduce, adapt, distribute, perform, display,
|
46
|
+
communicate, and translate a Work;
|
47
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
48
|
+
iii. publicity and privacy rights pertaining to a person's image or
|
49
|
+
likeness depicted in a Work;
|
50
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
51
|
+
subject to the limitations in paragraph 4(a), below;
|
52
|
+
v. rights protecting the extraction, dissemination, use and reuse of data
|
53
|
+
in a Work;
|
54
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
55
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
56
|
+
protection of databases, and under any national implementation
|
57
|
+
thereof, including any amended or successor version of such
|
58
|
+
directive); and
|
59
|
+
vii. other similar, equivalent or corresponding rights throughout the
|
60
|
+
world based on applicable law or treaty, and any national
|
61
|
+
implementations thereof.
|
62
|
+
|
63
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention
|
64
|
+
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
65
|
+
irrevocably and unconditionally waives, abandons, and surrenders all of
|
66
|
+
Affirmer's Copyright and Related Rights and associated claims and causes
|
67
|
+
of action, whether now known or unknown (including existing as well as
|
68
|
+
future claims and causes of action), in the Work (i) in all territories
|
69
|
+
worldwide, (ii) for the maximum duration provided by applicable law or
|
70
|
+
treaty (including future time extensions), (iii) in any current or future
|
71
|
+
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
72
|
+
including without limitation commercial, advertising or promotional
|
73
|
+
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
74
|
+
member of the public at large and to the detriment of Affirmer's heirs and
|
75
|
+
successors, fully intending that such Waiver shall not be subject to
|
76
|
+
revocation, rescission, cancellation, termination, or any other legal or
|
77
|
+
equitable action to disrupt the quiet enjoyment of the Work by the public
|
78
|
+
as contemplated by Affirmer's express Statement of Purpose.
|
79
|
+
|
80
|
+
3. Public License Fallback. Should any part of the Waiver for any reason
|
81
|
+
be judged legally invalid or ineffective under applicable law, then the
|
82
|
+
Waiver shall be preserved to the maximum extent permitted taking into
|
83
|
+
account Affirmer's express Statement of Purpose. In addition, to the
|
84
|
+
extent the Waiver is so judged Affirmer hereby grants to each affected
|
85
|
+
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
86
|
+
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
87
|
+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
88
|
+
maximum duration provided by applicable law or treaty (including future
|
89
|
+
time extensions), (iii) in any current or future medium and for any number
|
90
|
+
of copies, and (iv) for any purpose whatsoever, including without
|
91
|
+
limitation commercial, advertising or promotional purposes (the
|
92
|
+
"License"). The License shall be deemed effective as of the date CC0 was
|
93
|
+
applied by Affirmer to the Work. Should any part of the License for any
|
94
|
+
reason be judged legally invalid or ineffective under applicable law, such
|
95
|
+
partial invalidity or ineffectiveness shall not invalidate the remainder
|
96
|
+
of the License, and in such case Affirmer hereby affirms that he or she
|
97
|
+
will not (i) exercise any of his or her remaining Copyright and Related
|
98
|
+
Rights in the Work or (ii) assert any associated claims and causes of
|
99
|
+
action with respect to the Work, in either case contrary to Affirmer's
|
100
|
+
express Statement of Purpose.
|
101
|
+
|
102
|
+
4. Limitations and Disclaimers.
|
103
|
+
|
104
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
105
|
+
surrendered, licensed or otherwise affected by this document.
|
106
|
+
b. Affirmer offers the Work as-is and makes no representations or
|
107
|
+
warranties of any kind concerning the Work, express, implied,
|
108
|
+
statutory or otherwise, including without limitation warranties of
|
109
|
+
title, merchantability, fitness for a particular purpose, non
|
110
|
+
infringement, or the absence of latent or other defects, accuracy, or
|
111
|
+
the present or absence of errors, whether or not discoverable, all to
|
112
|
+
the greatest extent permissible under applicable law.
|
113
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
114
|
+
that may apply to the Work or any use thereof, including without
|
115
|
+
limitation any person's Copyright and Related Rights in the Work.
|
116
|
+
Further, Affirmer disclaims responsibility for obtaining any necessary
|
117
|
+
consents, permissions or other rights required for any use of the
|
118
|
+
Work.
|
119
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
120
|
+
party to this document and has no duty or obligation with respect to
|
121
|
+
this CC0 or use of the Work.
|
data/spec/codecs_spec.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'torquebox/codecs'
|
2
|
+
require 'torquebox/codecs/json'
|
3
|
+
|
4
|
+
def define_JSON
|
5
|
+
klass = Class.new {
|
6
|
+
def self.fast_generate(_)
|
7
|
+
end
|
8
|
+
}
|
9
|
+
Object.const_set(:JSON, klass)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe TorqueBox::Codecs do
|
13
|
+
|
14
|
+
context "json" do
|
15
|
+
it "should decode an encoded array" do
|
16
|
+
TorqueBox::Codecs.decode(TorqueBox::Codecs.encode(['abc'], :json), :json).should eql(['abc'])
|
17
|
+
end
|
18
|
+
|
19
|
+
if RUBY_VERSION >= '1.9'
|
20
|
+
it "should decode an encoded string" do
|
21
|
+
TorqueBox::Codecs.decode(TorqueBox::Codecs.encode('abc', :json), :json).should eql('abc')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "requiring json" do
|
26
|
+
before(:each) do
|
27
|
+
Object.send(:remove_const, :JSON) if defined?(JSON)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should raise if json isn't available" do
|
31
|
+
TorqueBox::Codecs::JSON.should_receive(:require).with('json').and_raise(LoadError.new)
|
32
|
+
lambda { TorqueBox::Codecs.encode('abc', :json) }.should raise_error( RuntimeError )
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should not raise if json is available" do
|
36
|
+
TorqueBox::Codecs::JSON.should_receive(:require).with('json').and_return { define_JSON }
|
37
|
+
lambda { TorqueBox::Codecs.encode('abc', :json ) }.should_not raise_error
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should only require json once" do
|
41
|
+
TorqueBox::Codecs::JSON.should_receive(:require).once.with('json').and_return { define_JSON }
|
42
|
+
TorqueBox::Codecs.encode('abc', :json)
|
43
|
+
TorqueBox::Codecs.encode('abc', :json)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "edn" do
|
49
|
+
it "should decode what it encodes" do
|
50
|
+
TorqueBox::Codecs.decode(TorqueBox::Codecs.encode('abc', :edn), :edn).should eql('abc')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "marshal" do
|
55
|
+
it "should decode what it encodes" do
|
56
|
+
TorqueBox::Codecs.decode(TorqueBox::Codecs.encode('abc', :marshal), :marshal).should eql('abc')
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should decode and encode Time objects" do
|
60
|
+
now = Time.now
|
61
|
+
TorqueBox::Codecs.decode(TorqueBox::Codecs.encode(now, :marshal), :marshal).should eql(now)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "marshal base64" do
|
66
|
+
it "should decode what it encodes" do
|
67
|
+
TorqueBox::Codecs.decode(TorqueBox::Codecs.encode('abc', :marshal_base64), :marshal_base64).should eql('abc')
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should decode and encode Time objects" do
|
71
|
+
now = Time.now
|
72
|
+
TorqueBox::Codecs.decode(TorqueBox::Codecs.encode(now, :marshal_base64), :marshal_base64).should eql(now)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "marshal_smart" do
|
77
|
+
it "should decode what it encodes" do
|
78
|
+
TorqueBox::Codecs.decode(TorqueBox::Codecs.encode('abc', :marshal_smart), :marshal_smart).should eql('abc')
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should decode and encode Time objects" do
|
82
|
+
now = Time.now
|
83
|
+
TorqueBox::Codecs.decode(TorqueBox::Codecs.encode(now, :marshal_smart), :marshal_smart).should eql(now)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
data/spec/injectors_spec.rb
CHANGED
@@ -5,19 +5,7 @@ describe TorqueBox::Injectors do
|
|
5
5
|
|
6
6
|
include TorqueBox::Injectors
|
7
7
|
|
8
|
-
it
|
9
|
-
TorqueBox::Registry.merge!('this' => :that)
|
10
|
-
TorqueBox::Registry['this'].should == :that
|
11
|
-
inject('this').should == :that
|
12
|
-
inject_msc('this').should == :that
|
13
|
-
inject_service('this').should == :that
|
14
|
-
inject_cdi(:this).should == :that
|
15
|
-
inject_jndi('this').should == :that
|
16
|
-
inject_queue('this').should == :that
|
17
|
-
inject_topic('this').should == :that
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should return the same thing for all fetch types" do
|
8
|
+
it 'should return the same thing for all fetch types' do
|
21
9
|
TorqueBox::Registry.merge!('this' => :that)
|
22
10
|
TorqueBox::Registry['this'].should == :that
|
23
11
|
fetch('this').should == :that
|
@@ -31,3 +19,10 @@ describe TorqueBox::Injectors do
|
|
31
19
|
|
32
20
|
end
|
33
21
|
|
22
|
+
describe 'TorqueBox::Injectors without include' do
|
23
|
+
it 'should work' do
|
24
|
+
TorqueBox::Registry.merge!('this' => :that)
|
25
|
+
TorqueBox::Registry['this'].should == :that
|
26
|
+
TorqueBox.fetch('this').should == :that
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'torquebox/scheduled_job'
|
2
|
+
|
3
|
+
describe TorqueBox::ScheduledJob do
|
4
|
+
context "'at' jobs" do
|
5
|
+
it "should raise if no options are specified" do
|
6
|
+
lambda {
|
7
|
+
TorqueBox::ScheduledJob.at('Class', nil)
|
8
|
+
}.should raise_error("Invalid options for scheduling the job")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should raise if invalid options are specified" do
|
12
|
+
lambda {
|
13
|
+
TorqueBox::ScheduledJob.at('Class', "something")
|
14
|
+
}.should raise_error("Invalid options for scheduling the job")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should raise if :at and :in options are both specified" do
|
18
|
+
lambda {
|
19
|
+
TorqueBox::ScheduledJob.at('Class', :at => Time.now, :in => 2_000)
|
20
|
+
}.should raise_error("You can't specify both :at and :in")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should raise if :repeat is used without :every" do
|
24
|
+
lambda {
|
25
|
+
TorqueBox::ScheduledJob.at('Class', :at => Time.now, :repeat => 2_000)
|
26
|
+
}.should raise_error("You can't specify :repeat without :every")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should raise if :until is used without :every" do
|
30
|
+
lambda {
|
31
|
+
TorqueBox::ScheduledJob.at('Class', :at => Time.now, :until => Time.now + 2)
|
32
|
+
}.should raise_error("You can't specify :until without :every")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should raise if the :in parameter is not an Fixnum" do
|
36
|
+
lambda {
|
37
|
+
TorqueBox::ScheduledJob.at('Class', :in => Time.now)
|
38
|
+
}.should raise_error("Invalid type for :in, should be a Fixnum")
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "scheduled job" do
|
44
|
+
it "should raise if the job class is not provided" do
|
45
|
+
lambda {
|
46
|
+
TorqueBox::ScheduledJob.schedule(nil, '')
|
47
|
+
}.should raise_error("No job class name provided")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should raise if the cron expression is not provided" do
|
51
|
+
lambda {
|
52
|
+
TorqueBox::ScheduledJob.schedule('Class', nil)
|
53
|
+
}.should raise_error("No cron expression provided")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
metadata
CHANGED
@@ -1,16 +1,48 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: torquebox-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version:
|
4
|
+
prerelease: 6
|
5
|
+
version: 3.0.0.beta1
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- The TorqueBox Team
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: edn
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 1.0.0
|
21
|
+
none: false
|
22
|
+
requirement: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
27
|
+
none: false
|
28
|
+
prerelease: false
|
29
|
+
type: :runtime
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.4.6
|
37
|
+
none: false
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.4.6
|
43
|
+
none: false
|
44
|
+
prerelease: false
|
45
|
+
type: :development
|
14
46
|
- !ruby/object:Gem::Dependency
|
15
47
|
name: rspec
|
16
48
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -34,27 +66,35 @@ executables: []
|
|
34
66
|
extensions: []
|
35
67
|
extra_rdoc_files: []
|
36
68
|
files:
|
37
|
-
- licenses/
|
69
|
+
- licenses/cc0-1.0.txt
|
38
70
|
- lib/torquebox-core.jar
|
39
71
|
- lib/torquebox-core.rb
|
40
72
|
- lib/gem_hook.rb
|
41
|
-
- lib/torquebox/service.rb
|
42
|
-
- lib/torquebox/registry.rb
|
43
73
|
- lib/torquebox/component_manager.rb
|
44
74
|
- lib/torquebox/logger.rb
|
45
|
-
- lib/torquebox/core.rb
|
46
75
|
- lib/torquebox/msc.rb
|
47
|
-
- lib/torquebox/
|
48
|
-
- lib/torquebox/service_registry.rb
|
76
|
+
- lib/torquebox/registry.rb
|
49
77
|
- lib/torquebox/scheduled_job.rb
|
78
|
+
- lib/torquebox/kernel.rb
|
79
|
+
- lib/torquebox/service.rb
|
50
80
|
- lib/torquebox/injectors.rb
|
81
|
+
- lib/torquebox/service_registry.rb
|
82
|
+
- lib/torquebox/codecs.rb
|
83
|
+
- lib/torquebox/core.rb
|
84
|
+
- lib/torquebox/codecs/marshal_base64.rb
|
85
|
+
- lib/torquebox/codecs/marshal.rb
|
86
|
+
- lib/torquebox/codecs/json.rb
|
87
|
+
- lib/torquebox/codecs/marshal_smart.rb
|
88
|
+
- lib/torquebox/codecs/edn.rb
|
51
89
|
- spec/service_registry_spec.rb
|
52
90
|
- spec/logger_spec.rb
|
91
|
+
- spec/codecs_spec.rb
|
53
92
|
- spec/kernel_spec.rb
|
93
|
+
- spec/scheduled_job_spec.rb
|
54
94
|
- spec/injectors_spec.rb
|
55
95
|
homepage: http://torquebox.org/
|
56
96
|
licenses:
|
57
|
-
-
|
97
|
+
- Public Domain
|
58
98
|
post_install_message:
|
59
99
|
rdoc_options: []
|
60
100
|
require_paths:
|
@@ -67,9 +107,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
107
|
none: false
|
68
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
109
|
requirements:
|
70
|
-
- - '
|
110
|
+
- - '>'
|
71
111
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
112
|
+
version: 1.3.1
|
73
113
|
none: false
|
74
114
|
requirements: []
|
75
115
|
rubyforge_project:
|
@@ -80,5 +120,7 @@ summary: TorqueBox Core Gem
|
|
80
120
|
test_files:
|
81
121
|
- spec/service_registry_spec.rb
|
82
122
|
- spec/logger_spec.rb
|
123
|
+
- spec/codecs_spec.rb
|
83
124
|
- spec/kernel_spec.rb
|
125
|
+
- spec/scheduled_job_spec.rb
|
84
126
|
- spec/injectors_spec.rb
|