nestene 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +15 -0
- data/.rspec +1 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/TODO.txt +7 -0
- data/api.rb +8 -0
- data/autons.rb +13 -0
- data/bin/nestene.rb +5 -0
- data/config.ru +21 -0
- data/features/api/api_create_auton.feature +6 -0
- data/features/api/api_credentials.feature +11 -0
- data/features/api/api_list_of_autons.feature +6 -0
- data/features/callback.feature +13 -0
- data/features/create_auton.feature +11 -0
- data/features/credentials.feature +7 -0
- data/features/execute_step.feature +59 -0
- data/features/restart.feature +7 -0
- data/features/schedule_steps.feature +7 -0
- data/features/step_definitions/api/api_create_auton_steps.rb +16 -0
- data/features/step_definitions/api/api_credentials_steps.rb +22 -0
- data/features/step_definitions/api/api_list_of_autons_steps.rb +8 -0
- data/features/step_definitions/callback_steps.rb +75 -0
- data/features/step_definitions/create_auton_steps.rb +32 -0
- data/features/step_definitions/credentials_steps.rb +24 -0
- data/features/step_definitions/execute_step_steps.rb +177 -0
- data/features/step_definitions/restart_steps.rb +5 -0
- data/features/step_definitions/schedule_steps_steps.rb +29 -0
- data/features/step_definitions/time_delayed_steps_steps.rb +103 -0
- data/features/step_definitions/ui/create_auton_steps.rb +21 -0
- data/features/step_definitions/ui/list_of_autons_steps.rb +18 -0
- data/features/step_definitions/ui/schedule_auton_step_steps.rb +64 -0
- data/features/step_definitions/ui/show_auton_steps.rb +49 -0
- data/features/support/env.rb +36 -0
- data/features/time_delayed_steps.feature +28 -0
- data/features/ui/create_auton.feature +7 -0
- data/features/ui/list_of_autons.feature +7 -0
- data/features/ui/schedule_auton_step.feature +12 -0
- data/features/ui/show_auton.feature +14 -0
- data/lib/nestene/actor/auton_queue.rb +87 -0
- data/lib/nestene/actor/auton_storage.rb +50 -0
- data/lib/nestene/actor/core.rb +150 -0
- data/lib/nestene/actor/delayed_scheduler.rb +76 -0
- data/lib/nestene/auton_context.rb +31 -0
- data/lib/nestene/auton_execution_queue.rb +43 -0
- data/lib/nestene/auton_state.rb +27 -0
- data/lib/nestene/callback.rb +7 -0
- data/lib/nestene/delayed_method.rb +17 -0
- data/lib/nestene/executed_method.rb +29 -0
- data/lib/nestene/executing_method.rb +23 -0
- data/lib/nestene/execution_error.rb +39 -0
- data/lib/nestene/scheduled_method.rb +21 -0
- data/lib/nestene/storage.rb +72 -0
- data/lib/nestene/ui/app.rb +103 -0
- data/lib/nestene/ui/public/app/application.js +75 -0
- data/lib/nestene/ui/public/vendor/angular-ui-sortable/sortable.min.js +1 -0
- data/lib/nestene/ui/public/vendor/angular.min.js +248 -0
- data/lib/nestene/ui/public/vendor/bootstrap/css/bootstrap-theme.css +347 -0
- data/lib/nestene/ui/public/vendor/bootstrap/css/bootstrap-theme.min.css +7 -0
- data/lib/nestene/ui/public/vendor/bootstrap/css/bootstrap.css +5785 -0
- data/lib/nestene/ui/public/vendor/bootstrap/css/bootstrap.min.css +7 -0
- data/lib/nestene/ui/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.eot +0 -0
- data/lib/nestene/ui/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.svg +229 -0
- data/lib/nestene/ui/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/lib/nestene/ui/public/vendor/bootstrap/fonts/glyphicons-halflings-regular.woff +0 -0
- data/lib/nestene/ui/public/vendor/bootstrap/js/bootstrap.js +1951 -0
- data/lib/nestene/ui/public/vendor/bootstrap/js/bootstrap.min.js +6 -0
- data/lib/nestene/ui/public/vendor/jquery-ui.min.js +13 -0
- data/lib/nestene/ui/public/vendor/jquery.bootstrap-growl.min.js +1 -0
- data/lib/nestene/ui/public/vendor/jquery.min.js +5 -0
- data/lib/nestene/ui/public/vendor/json-editor/directives.js +245 -0
- data/lib/nestene/ui/public/vendor/json-editor/styles.css +165 -0
- data/lib/nestene/ui/views/auton.haml +42 -0
- data/lib/nestene/ui/views/auton_form.haml +8 -0
- data/lib/nestene/ui/views/index.haml +35 -0
- data/lib/nestene/ui/views/layout.haml +40 -0
- data/lib/nestene/ui/views/schedule_step.haml +14 -0
- data/lib/nestene/version.rb +3 -0
- data/lib/nestene.rb +50 -0
- data/nestene.gemspec +39 -0
- data/spec/nestene/auton_execution_queue_spec.rb +78 -0
- data/spec/nestene/nestene_spec.rb +137 -0
- data/spec/nestene/storage_spec.rb +125 -0
- data/spec/spec_helper.rb +2 -0
- metadata +373 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OGZlMjkwODJhMGQ4MWE0ODkyYTgzNTU4NGQyOWM5M2Q0M2ZhMTg3Nw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NzhhN2NjOTM5MDM4MGZkMWZkMjU1ZGU5YTA5MDM1OTE2YzYxYTg1MQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NjhmY2Q4YWFhNmIxMTE4YWQwZDE3ZTc3NzNmMzVmNGYzODMxMDYwOTQzNjlj
|
10
|
+
NDBjMTFiNWUzYmY4Y2JjNGY0MTE3MzhiMmRmODIyZjA4ZTJkOGJhODhjYWVl
|
11
|
+
ZWNmMGZkZjFiYWY4MjA5ZGE3MWU4NGJlZjg5NGJlNzE1YWZlOGY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTRlZGIxYmIwMjY2MmExMGUwM2ViNDYwOWU5ZGRjMWExN2JkOGQyZDQ0Yzc2
|
14
|
+
NDk0MDc3MTc0MjY5ZjE1MWE4MTA3YzYyMWE3MDYwYjg5ODAxODFkMDA5ZmI0
|
15
|
+
YTEzZjRjYWJjMjg0YTczN2IzNjk2NzJjMzRhMjcwODcyZWE5ODM=
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Net Ice 9 Ltd
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Nestene
|
2
|
+
|
3
|
+
Execution framework for persistent Actors (Autons)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'nestene'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install nestene
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/nestene/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/TODO.txt
ADDED
data/api.rb
ADDED
data/autons.rb
ADDED
data/bin/nestene.rb
ADDED
data/config.ru
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$LOAD_PATH << '.'
|
2
|
+
$LOAD_PATH << 'lib'
|
3
|
+
|
4
|
+
require 'nestene'
|
5
|
+
|
6
|
+
Dir.mkdir('storage') unless File.exists?('storage')
|
7
|
+
|
8
|
+
Nestene::start_nestene(Nestene::DiskStorage.new('storage'))
|
9
|
+
|
10
|
+
to_check = Bundler.load.specs.map(&:full_gem_path)
|
11
|
+
to_check << '.'
|
12
|
+
|
13
|
+
to_check.each do |path|
|
14
|
+
file_name = "%s/autons.rb" % [path]
|
15
|
+
if File.exists?(file_name)
|
16
|
+
puts "loading %s" % file_name
|
17
|
+
load(file_name)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
run Nestene::Ui::App
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Feature: callback
|
2
|
+
|
3
|
+
Scenario: callback step execution
|
4
|
+
Given I have an Auton that holds counter state
|
5
|
+
And I have an Auton that schedules a callback step on the counter Auton
|
6
|
+
When I execute second Auton's schedule step
|
7
|
+
Then the callback step of the second Auton should be executed
|
8
|
+
|
9
|
+
Scenario: callback exception execution
|
10
|
+
Given I have an Auton that hold counter state and raises exception on execution
|
11
|
+
And I have an Auton that schedules a callback step on the counter Auton
|
12
|
+
When I execute second Auton's schedule step
|
13
|
+
Then the callback error step of the second Auton with the exception's message should be executed
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Feature: create auton
|
2
|
+
|
3
|
+
Scenario: create auton
|
4
|
+
Given an empty auton
|
5
|
+
When I create the auton
|
6
|
+
Then the Auton should be in the READY state
|
7
|
+
|
8
|
+
Scenario: attempt to create auton with a wrong class name
|
9
|
+
When I try to create an auton with a non-existing type
|
10
|
+
Then an exception should be raised
|
11
|
+
And the auton should not be created
|
@@ -0,0 +1,59 @@
|
|
1
|
+
Feature: execute step
|
2
|
+
|
3
|
+
Scenario: execute simple non-failing step with parameters
|
4
|
+
Given I have a running auton with one defined step with parameters
|
5
|
+
When I add the step with parameters to the execution queue
|
6
|
+
And I wait for the step to execute
|
7
|
+
Then the Auton should be in the READY state
|
8
|
+
And the execution result should be returned
|
9
|
+
|
10
|
+
Scenario: execute simple non-failing step with parameters
|
11
|
+
Given I have a running auton with one defined step with parameters
|
12
|
+
When I add the step with parameters to the execution queue
|
13
|
+
And I wait for the step to execute
|
14
|
+
Then the Auton should be in the READY state
|
15
|
+
And the execution result should be returned
|
16
|
+
|
17
|
+
Scenario: execute simple failing step
|
18
|
+
Given I have a running auton with one defined step that fails
|
19
|
+
When I add the step to the execution queue
|
20
|
+
And I wait for the step to execute
|
21
|
+
Then the auton should be in the FAILED state
|
22
|
+
And the execution result should be an exception
|
23
|
+
|
24
|
+
Scenario: stop execution when in FAILED state
|
25
|
+
Given I have a running auton with one defined step that fails and one that does not fail
|
26
|
+
When I add first the failing and then the not failing step to the execution queue
|
27
|
+
And I wait for the first step to execute
|
28
|
+
Then the auton should be in the FAILED state
|
29
|
+
And the execution result should be an exception
|
30
|
+
And the not failing step will not be executed
|
31
|
+
|
32
|
+
Scenario: repeating failed step
|
33
|
+
Given I have a running auton with one defined step that fails on the first invocation but succeeds on the second
|
34
|
+
When I add the step to the execution queue
|
35
|
+
And I wait for the step to execute
|
36
|
+
And I repeat the failed step
|
37
|
+
And I wait for the step to execute
|
38
|
+
Then the execution result should be returned
|
39
|
+
And the Auton should be in the READY state
|
40
|
+
|
41
|
+
Scenario: resuming after failure
|
42
|
+
Given I have a running auton with one defined step that fails and one that does not fail
|
43
|
+
When I add first the failing and then the not failing step to the execution queue
|
44
|
+
And I wait for the first step to execute
|
45
|
+
Then the auton should be in the FAILED state
|
46
|
+
When I resume the failed auton
|
47
|
+
And I wait for the second step to execute
|
48
|
+
Then the execution result should be returned
|
49
|
+
And the Auton should be in the READY state
|
50
|
+
|
51
|
+
Scenario: handling exception by Auton
|
52
|
+
Given I have a running auton with one defined step that fails and one that does not fail and an exception handling method for the whole Auton
|
53
|
+
When I add first the failing and then the not failing step to the execution queue
|
54
|
+
And I wait for the first step to execute
|
55
|
+
And I wait for the second step to execute
|
56
|
+
Then the execution result should be returned
|
57
|
+
And the Auton should be in the READY state
|
58
|
+
And the "handle_exception" method should have been executed
|
59
|
+
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Feature: schedule steps
|
2
|
+
|
3
|
+
Scenario: add step
|
4
|
+
Given I have an Auton that has two steps, first step scheduling the next step
|
5
|
+
When I schedule the first step that returns the uuid of the second scheduled step
|
6
|
+
And I wait for the second step to finish
|
7
|
+
Then the Auton should be in the READY state
|
@@ -0,0 +1,16 @@
|
|
1
|
+
When(/^request creation of an auton with an existing type$/) do
|
2
|
+
class EmptyAuton
|
3
|
+
include StructureMapper::Hash
|
4
|
+
|
5
|
+
attribute foo: String
|
6
|
+
end
|
7
|
+
@auton_type="EmptyAuton"
|
8
|
+
post '/autons', {auton_type: @auton_type}.to_json, 'Content-Type' => 'application/json'
|
9
|
+
end
|
10
|
+
|
11
|
+
Then(/^the API should respond with status code (\d+) and auton's ID$/) do |expected_status|
|
12
|
+
expect(last_response.status).to be(expected_status.to_i)
|
13
|
+
response = JSON.parse(last_response.body)
|
14
|
+
expect(response).not_to be_empty
|
15
|
+
expect(response).to have_key('auton_id')
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Given(/^there are credentials set$/) do
|
2
|
+
Celluloid::Actor[:nestene_core].set_credentials({'a' => 'b'})
|
3
|
+
end
|
4
|
+
|
5
|
+
When(/^I get credentials$/) do
|
6
|
+
get '/credentials'
|
7
|
+
end
|
8
|
+
|
9
|
+
Then(/^I should receive credentials$/) do
|
10
|
+
expect(last_response.status).to be(200)
|
11
|
+
response = JSON.parse(last_response.body)
|
12
|
+
expect(response).to eq({'a' => 'b'})
|
13
|
+
end
|
14
|
+
|
15
|
+
When(/^I set credentials$/) do
|
16
|
+
post '/credentials', {'a' => 'b'}.to_json, 'Content-Type' => 'application/json'
|
17
|
+
end
|
18
|
+
|
19
|
+
Then(/^the credentials should be set$/) do
|
20
|
+
expect(last_response.status).to be(200)
|
21
|
+
expect(Celluloid::Actor[:nestene_core].get_credentials).to eq({'a' => 'b'})
|
22
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
Given(/^I have an Auton that holds counter state$/) do
|
2
|
+
class CounterAuton
|
3
|
+
include StructureMapper::Hash
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.counter = 0
|
7
|
+
end
|
8
|
+
|
9
|
+
def next
|
10
|
+
self.counter += 1
|
11
|
+
end
|
12
|
+
|
13
|
+
attribute counter: Fixnum
|
14
|
+
end
|
15
|
+
@counter_auton_type="CounterAuton"
|
16
|
+
@counter_auton_id = Celluloid::Actor[:nestene_core].create_auton(@counter_auton_type, "counter")
|
17
|
+
end
|
18
|
+
|
19
|
+
Given(/^I have an Auton that schedules a callback step on the counter Auton$/) do
|
20
|
+
class CallbackAuton
|
21
|
+
include StructureMapper::Hash
|
22
|
+
|
23
|
+
def start
|
24
|
+
self.context.schedule_callback('counter', :next, [], :set_state)
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_state new_state
|
28
|
+
self.state = new_state
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_state_error error_type, message
|
32
|
+
self.error = message
|
33
|
+
end
|
34
|
+
|
35
|
+
attr_accessor :context
|
36
|
+
|
37
|
+
attribute state: Fixnum
|
38
|
+
attribute error: String
|
39
|
+
end
|
40
|
+
@callback_auton_type="CallbackAuton"
|
41
|
+
@callback_auton_id = Celluloid::Actor[:nestene_core].create_auton(@callback_auton_type, "callback")
|
42
|
+
end
|
43
|
+
|
44
|
+
When(/^I execute second Auton's schedule step$/) do
|
45
|
+
Celluloid::Actor[:nestene_core].schedule_step @callback_auton_id, :start
|
46
|
+
end
|
47
|
+
|
48
|
+
Then(/^the callback step of the second Auton should be executed$/) do
|
49
|
+
sleep 0.1
|
50
|
+
expect(Celluloid::Actor["storage:%s" % @callback_auton_id].get.serialized['state']).to eq(1)
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
Given(/^I have an Auton that hold counter state and raises exception on execution$/) do
|
55
|
+
class FailingCounterAuton
|
56
|
+
include StructureMapper::Hash
|
57
|
+
|
58
|
+
def initialize
|
59
|
+
self.counter = 0
|
60
|
+
end
|
61
|
+
|
62
|
+
def next
|
63
|
+
raise "some exception"
|
64
|
+
end
|
65
|
+
|
66
|
+
attribute counter: Fixnum
|
67
|
+
end
|
68
|
+
@counter_auton_type="FailingCounterAuton"
|
69
|
+
@counter_auton_id = Celluloid::Actor[:nestene_core].create_auton(@counter_auton_type, "counter")
|
70
|
+
end
|
71
|
+
|
72
|
+
Then(/^the callback error step of the second Auton with the exception's message should be executed$/) do
|
73
|
+
sleep 0.1
|
74
|
+
expect(Celluloid::Actor["storage:%s" % @callback_auton_id].get.serialized['error']).to eq('some exception')
|
75
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
Given(/^an empty auton$/) do
|
2
|
+
class EmptyAuton
|
3
|
+
include StructureMapper::Hash
|
4
|
+
|
5
|
+
attribute foo: String
|
6
|
+
end
|
7
|
+
@auton_type="EmptyAuton"
|
8
|
+
end
|
9
|
+
|
10
|
+
When(/^I create the auton$/) do
|
11
|
+
@auton_id = Celluloid::Actor[:nestene_core].create_auton @auton_type
|
12
|
+
end
|
13
|
+
|
14
|
+
Then(/^the Auton should be in the READY state$/) do
|
15
|
+
expect(Celluloid::Actor["storage:%s" % @auton_id].get.state).to eq(:ready)
|
16
|
+
end
|
17
|
+
|
18
|
+
When(/^I try to create an auton with a non\-existing type$/) do
|
19
|
+
begin
|
20
|
+
@auton_type = Celluloid::Actor[:nestene_core].create_auton "SomeNotExistingType"
|
21
|
+
rescue Exception => exception
|
22
|
+
@exception = exception
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Then(/^an exception should be raised$/) do
|
27
|
+
expect(@exception).not_to be_nil
|
28
|
+
end
|
29
|
+
|
30
|
+
Then(/^the auton should not be created$/) do
|
31
|
+
expect(@auton_type).to be_nil
|
32
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Given(/^I have an Auton that access credentials in the first step$/) do
|
2
|
+
class CredentialsAuton
|
3
|
+
include StructureMapper::Hash
|
4
|
+
|
5
|
+
attribute credentials: String
|
6
|
+
|
7
|
+
attr_accessor :context
|
8
|
+
|
9
|
+
def use_credentials
|
10
|
+
context.credentials['mail.google.com']
|
11
|
+
end
|
12
|
+
end
|
13
|
+
@auton_type="CredentialsAuton"
|
14
|
+
@auton_id = Celluloid::Actor[:nestene_core].create_auton @auton_type
|
15
|
+
end
|
16
|
+
|
17
|
+
Given(/^the credentials are set$/) do
|
18
|
+
Celluloid::Actor[:nestene_core].set_credentials({'mail.google.com' => 'creds'})
|
19
|
+
end
|
20
|
+
|
21
|
+
When(/^I execute the first step of the Auton$/) do
|
22
|
+
step_execution_id = Celluloid::Actor[:nestene_core].schedule_step @auton_id, :use_credentials
|
23
|
+
expect(Celluloid::Actor[:nestene_core].wait_for_execution_result(@auton_id, step_execution_id)).to eq('creds')
|
24
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
Given(/^I have a running auton with one defined step without any parameters$/) do
|
2
|
+
class SimpleAuton
|
3
|
+
include StructureMapper::Hash
|
4
|
+
|
5
|
+
def start
|
6
|
+
'ok'
|
7
|
+
end
|
8
|
+
|
9
|
+
attribute foo: String
|
10
|
+
end
|
11
|
+
@auton_type="SimpleAuton"
|
12
|
+
@auton_id = Celluloid::Actor[:nestene_core].create_auton @auton_type
|
13
|
+
@expected_result = "ok"
|
14
|
+
end
|
15
|
+
|
16
|
+
When(/^I add the step to the execution queue$/) do
|
17
|
+
@step_execution_id = Celluloid::Actor[:nestene_core].schedule_step @auton_id, :start
|
18
|
+
end
|
19
|
+
|
20
|
+
When(/^I wait for the step to execute$/) do
|
21
|
+
begin
|
22
|
+
@execution_result = Celluloid::Actor[:nestene_core].wait_for_execution_result(@auton_id, @step_execution_id)
|
23
|
+
rescue Exception => e
|
24
|
+
@execution_exception = e
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Then(/^the execution result should be returned$/) do
|
29
|
+
expect(@execution_result).to eq(@expected_result)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
Given(/^I have a running auton with one defined step with parameters$/) do
|
34
|
+
class SimpleParamsAuton
|
35
|
+
include StructureMapper::Hash
|
36
|
+
|
37
|
+
def start(p1)
|
38
|
+
'param: %s' % p1
|
39
|
+
end
|
40
|
+
|
41
|
+
attribute foo: String
|
42
|
+
end
|
43
|
+
@auton_type="SimpleParamsAuton"
|
44
|
+
@auton_id = Celluloid::Actor[:nestene_core].create_auton @auton_type
|
45
|
+
@expected_result = "param: p1"
|
46
|
+
end
|
47
|
+
|
48
|
+
When(/^I add the step with parameters to the execution queue$/) do
|
49
|
+
@step_execution_id = Celluloid::Actor[:nestene_core].schedule_step @auton_id, :start, "p1"
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
Given(/^I have a running auton with one defined step that fails$/) do
|
54
|
+
class SimpleFailingAuton
|
55
|
+
include StructureMapper::Hash
|
56
|
+
|
57
|
+
def start
|
58
|
+
raise "failed!"
|
59
|
+
end
|
60
|
+
|
61
|
+
attribute foo: String
|
62
|
+
end
|
63
|
+
@auton_type="SimpleFailingAuton"
|
64
|
+
@auton_id = Celluloid::Actor[:nestene_core].create_auton @auton_type
|
65
|
+
end
|
66
|
+
|
67
|
+
Then(/^the auton should be in the FAILED state$/) do
|
68
|
+
expect(Celluloid::Actor["storage:%s" % @auton_id].get.state).to eq(:failed)
|
69
|
+
end
|
70
|
+
|
71
|
+
Then(/^the execution result should be an exception$/) do
|
72
|
+
expect(@execution_exception).to be_a(Exception)
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
Given(/^I have a running auton with one defined step that fails and one that does not fail$/) do
|
77
|
+
class SimpleTwoStepsFirstFailingAuton
|
78
|
+
include StructureMapper::Hash
|
79
|
+
|
80
|
+
def start
|
81
|
+
raise "failed!"
|
82
|
+
end
|
83
|
+
|
84
|
+
def cont
|
85
|
+
end
|
86
|
+
|
87
|
+
attribute foo: String
|
88
|
+
end
|
89
|
+
@auton_type="SimpleTwoStepsFirstFailingAuton"
|
90
|
+
@auton_id = Celluloid::Actor[:nestene_core].create_auton @auton_type
|
91
|
+
end
|
92
|
+
|
93
|
+
When(/^I add first the failing and then the not failing step to the execution queue$/) do
|
94
|
+
@first_step_execution_id = Celluloid::Actor[:nestene_core].schedule_step @auton_id, :start
|
95
|
+
@second_step_execution_id = Celluloid::Actor[:nestene_core].schedule_step @auton_id, :cont
|
96
|
+
end
|
97
|
+
|
98
|
+
When(/^I wait for the first step to execute$/) do
|
99
|
+
begin
|
100
|
+
@execution_result = Celluloid::Actor[:nestene_core].wait_for_execution_result(@auton_id, @first_step_execution_id)
|
101
|
+
rescue Exception => e
|
102
|
+
@execution_exception = e
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
Then(/^the not failing step will not be executed$/) do
|
107
|
+
sleep 0.1
|
108
|
+
|
109
|
+
expect(Celluloid::Actor["storage:%s" % @auton_id].get.queue.to_execute.first.uuid).to eq(@second_step_execution_id)
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
Given(/^I have a running auton with one defined step that fails on the first invocation but succeeds on the second$/) do
|
114
|
+
class FirstExecutionFailingAuton
|
115
|
+
include StructureMapper::Hash
|
116
|
+
|
117
|
+
def initalize
|
118
|
+
self.first = true
|
119
|
+
end
|
120
|
+
|
121
|
+
def start
|
122
|
+
should_fail = self.first
|
123
|
+
self.first = false
|
124
|
+
raise "failed!" if should_fail
|
125
|
+
end
|
126
|
+
|
127
|
+
attribute first: Boolean
|
128
|
+
end
|
129
|
+
@auton_type="FirstExecutionFailingAuton"
|
130
|
+
@auton_id = Celluloid::Actor[:nestene_core].create_auton @auton_type
|
131
|
+
end
|
132
|
+
|
133
|
+
When(/^I repeat the failed step$/) do
|
134
|
+
|
135
|
+
@step_execution_id = Celluloid::Actor[:nestene_core].repeat_step @auton_id, @step_execution_id
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
When(/^I resume the failed auton$/) do
|
141
|
+
@step_execution_id = Celluloid::Actor[:nestene_core].resume @auton_id
|
142
|
+
end
|
143
|
+
|
144
|
+
When(/^I wait for the second step to execute$/) do
|
145
|
+
begin
|
146
|
+
@execution_result = Celluloid::Actor[:nestene_core].wait_for_execution_result(@auton_id, @second_step_execution_id)
|
147
|
+
rescue Exception => e
|
148
|
+
@execution_exception = e
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
Given(/^I have a running auton with one defined step that fails and one that does not fail and an exception handling method for the whole Auton$/) do
|
154
|
+
class TwoStepsFirstFailingWithExceptionHandlerAuton
|
155
|
+
include StructureMapper::Hash
|
156
|
+
|
157
|
+
def start
|
158
|
+
raise "failed!"
|
159
|
+
end
|
160
|
+
|
161
|
+
def cont
|
162
|
+
end
|
163
|
+
|
164
|
+
def handle_exception type, message, method_name, params
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
attribute foo: String
|
169
|
+
end
|
170
|
+
@auton_type="TwoStepsFirstFailingWithExceptionHandlerAuton"
|
171
|
+
@auton_id = Celluloid::Actor[:nestene_core].create_auton @auton_type
|
172
|
+
end
|
173
|
+
|
174
|
+
Then(/^the "(.*?)" method should have been executed$/) do |method_name|
|
175
|
+
expect(Celluloid::Actor["storage:%s" % @auton_id].get.queue.executed.map(&:name)).to include(method_name.to_sym)
|
176
|
+
end
|
177
|
+
|