aws-swf 0.1.2

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.
@@ -0,0 +1,47 @@
1
+ require './lib/swf/runner'
2
+
3
+ describe SWF::Runner do
4
+ before do
5
+ SWF.stub(:domain_name) { 'phony_domain' }
6
+ SWF.stub(:domain) { double(:domain, name: SWF.domain_name ) }
7
+ end
8
+
9
+ subject { SWF::Runner.new('phony_domain', 'phony_task_list') }
10
+
11
+ it "has a handle on the domain" do
12
+ subject.domain.name.should == 'phony_domain'
13
+ end
14
+
15
+ describe "#be_decider" do
16
+ it "polls for decision tasks" do
17
+ subject.stub(:domain) { double(:domain,
18
+ decision_tasks: double(:decision_tasks).tap {|o|
19
+ o.should_receive(:poll).with('phony_task_list') {|&blk|
20
+ task = :placeholder_decision_task
21
+ SWF::DecisionTaskHandler.should_receive(:handle).with(subject, task)
22
+ blk.call task
23
+ }
24
+ }
25
+ ) }
26
+
27
+ subject.be_decider
28
+ end
29
+ end
30
+
31
+ describe "#be_worker" do
32
+ it "polls for activity tasks" do
33
+ subject.stub(:domain) { double(:domain,
34
+ activity_tasks: double(:activity_tasks).tap {|o|
35
+ o.should_receive(:poll).with('phony_task_list') {|&blk|
36
+ task = :placeholder_activity_task
37
+ SWF::ActivityTaskHandler.should_receive(:handle).with(subject, task)
38
+ blk.call task
39
+ }
40
+ }
41
+ ) }
42
+
43
+ subject.be_worker
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,65 @@
1
+ require './lib/swf/activity_task_handler.rb'
2
+
3
+ describe SWF::TaskHandler do
4
+ before { $stdout.stub :write }
5
+
6
+ subject { Class.new(Object) { extend SWF::TaskHandler } }
7
+
8
+ describe '.get_handler_class_or_fail' do
9
+ context "(when nothing registered) " do
10
+ it "fails the activity task" do
11
+ subject.should_receive(:find_handler_class).with(:task_placeholder)
12
+ subject.should_receive(:configuration_help_message) { :configuration_help_message_placeholder }
13
+ subject.should_receive(:fail!) {|task, args|
14
+ task.should == :task_placeholder
15
+ args[:reason].should == "unknown type"
16
+ args[:details].should include 'configuration_help_message_placeholder'
17
+ }
18
+
19
+ subject.send :get_handler_class_or_fail, :task_placeholder
20
+ end
21
+ end
22
+
23
+ context "(when handler (subclass) is registered with a handle_* method matching activity type's name) " do
24
+ it "returns the handler (subclass)" do
25
+ subject.should_not_receive(:fail!)
26
+ subject.should_receive(:find_handler_class).with(:task_placeholder) { :subclass_placeholder }
27
+
28
+ subject.send(:get_handler_class_or_fail, :task_placeholder).should == :subclass_placeholder
29
+ end
30
+ end
31
+ end
32
+
33
+ describe '.handle' do
34
+ before {
35
+ subject.should_receive(:find_handler_class).with(:task_placeholder) {
36
+ double(:handler_class, name: 'handler_class_name').tap{|hc|
37
+ hc.should_receive(:new).with(:runner_placeholder, :task_placeholder).and_return(handler)
38
+ }
39
+ }
40
+ }
41
+
42
+ let(:handler) { double(:handler).tap {|o|
43
+ @call_handle_receiver = o.should_receive(:call_handle)
44
+ } }
45
+
46
+ context "(if subclass#call_handle raises)" do
47
+ it "fails the activity" do
48
+ handler
49
+ @call_handle_receiver.and_raise("fail")
50
+ subject.should_receive(:fail!)
51
+
52
+ subject.handle :runner_placeholder, :task_placeholder
53
+ end
54
+ end
55
+
56
+ context "(if subclass#call_handle succeeds)" do
57
+ it "all works fine (no activity fail)" do
58
+ subject.should_not_receive(:fail!)
59
+
60
+ subject.handle :runner_placeholder, :task_placeholder
61
+ end
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,81 @@
1
+ require './lib/swf'
2
+
3
+ describe SWF do
4
+
5
+ describe '.swf' do
6
+ before do
7
+ SWF.instance_variable_set(:@swf, nil)
8
+ end
9
+ it 'creates a new AWS::SimpleWorkflow object if @swf is not defined' do
10
+ AWS::SimpleWorkflow.should_receive(:new)
11
+ SWF.swf
12
+ end
13
+ end
14
+
15
+ context "domain" do
16
+ after(:each) do
17
+ SWF.instance_variable_set(:@domain_name, nil)
18
+ end
19
+
20
+ describe '.domain_name' do
21
+ it "returns @domain_name if set" do
22
+ SWF.instance_variable_set(:@domain_name, 'domain')
23
+ SWF.domain_name.should == 'domain'
24
+ end
25
+
26
+ it "throws UndefinedDomainName if @domain_name is not set" do
27
+ ->{ SWF.domain_name }.should raise_exception(SWF::UndefinedDomainName)
28
+ end
29
+ end
30
+
31
+ describe '.domain_name=' do
32
+ it "sets @domain_name" do
33
+ SWF.domain_name = 'domain'
34
+ SWF.instance_variable_get(:@domain_name).should == 'domain'
35
+ end
36
+ end
37
+
38
+ describe '.domain' do
39
+ let(:domain_object) { double(:domain, exists?: true) }
40
+ before do
41
+
42
+ domains = { 'domain' => domain_object }
43
+ SWF.stub(:swf) {
44
+ double(:swf,
45
+ domains: double(:domains).tap{|d| d.stub(:[]) {|arg| domains[arg] || double(:domain, exists?: false) } }
46
+ )
47
+ }
48
+ end
49
+
50
+ it 'returns the SWF domain object if domain_name exists as a SWF domain' do
51
+ SWF.stub(:domain_name) { 'domain' }
52
+ SWF.domain.should == domain_object
53
+ end
54
+ it 'throws UnknownSWFDomain if domain_name exists as a SWF domain' do
55
+ SWF.stub(:domain_name) { 'foobar' }
56
+ ->{ SWF.domain }.should raise_exception(SWF::UnknownSWFDomain)
57
+ end
58
+ end
59
+
60
+ describe '.task_list' do
61
+ after(:each) do
62
+ SWF.instance_variable_set(:@task_list, nil)
63
+ end
64
+ it "returns @task_list if set" do
65
+ SWF.instance_variable_set(:@task_list, 'task_list')
66
+ SWF.task_list.should == 'task_list'
67
+ end
68
+ it "throws UndefinedTaskList if @task_list not set" do
69
+ ->{ SWF.task_list }.should raise_exception(SWF::UndefinedTaskList)
70
+ end
71
+ end
72
+
73
+ describe '.task_list=' do
74
+ it "sets @task_list" do
75
+ SWF.task_list = 'task_list'
76
+ SWF.instance_variable_get(:@task_list).should == 'task_list'
77
+ end
78
+ end
79
+ end
80
+
81
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws-swf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Vijay Krishna Ramesh
9
+ - Tim James
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-07-19 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ description:
32
+ email:
33
+ - vijay@change.org
34
+ executables:
35
+ - swf_run
36
+ extensions: []
37
+ extra_rdoc_files:
38
+ - README.md
39
+ files:
40
+ - Gemfile
41
+ - Gemfile.lock
42
+ - LICENSE
43
+ - README.md
44
+ - bin/swf_run
45
+ - spec/swf/activity_task_handler_spec.rb
46
+ - spec/swf/boot_spec.rb
47
+ - spec/swf/decision_task_handler_spec.rb
48
+ - spec/swf/runner_spec.rb
49
+ - spec/swf/task_handler_spec.rb
50
+ - spec/swf_spec.rb
51
+ - lib/aws-swf.rb
52
+ - lib/swf/activity_task_handler.rb
53
+ - lib/swf/boot.rb
54
+ - lib/swf/decision_task_handler.rb
55
+ - lib/swf/runner.rb
56
+ - lib/swf/task_handler.rb
57
+ - lib/swf.rb
58
+ - lib/workflows.rb
59
+ homepage: https://github.com/change/aws-swf
60
+ licenses: []
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --main
64
+ - README.md
65
+ require_paths:
66
+ - lib
67
+ - lib/swf
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.23
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: light framework for creating AWS Simple Workflow applications in Ruby.
86
+ test_files: []