pipeline_toolkit 1.2.9 → 1.2.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +12 -5
- data/lib/pipeline_toolkit/cucumber/amqp_steps.rb +1 -1
- data/lib/pipeline_toolkit/cucumber/io_process.rb +2 -2
- data/lib/pipeline_toolkit/cucumber/machine.rb +2 -2
- data/lib/pipeline_toolkit/cucumber/machine_steps.rb +23 -1
- data/lib/pipeline_toolkit/cucumber/pipeline_io.rb +6 -0
- data/lib/pipeline_toolkit/message_coder.rb +10 -3
- metadata +2 -2
data/README.markdown
CHANGED
@@ -96,12 +96,19 @@ Pipeline toolkit also includes pre-canned cucumber steps for you to test your ma
|
|
96
96
|
|
97
97
|
Given I run this machine with acknowledgements:
|
98
98
|
Given I run this machine without acknowledgements:
|
99
|
-
|
100
|
-
When I input these messages
|
101
|
-
|
102
|
-
|
99
|
+
|
100
|
+
When I input these messages: (table)
|
101
|
+
When I input these messages with ack_ids: (table)
|
102
|
+
When I input these messages without ack_ids: (table)
|
103
|
+
|
104
|
+
When I input this messages: (json string)
|
105
|
+
When I input these messages with ack_ids: (json string)
|
106
|
+
When I input these messages without ack_ids: (json string)
|
107
|
+
|
108
|
+
Then these messages are passed on: (table)
|
109
|
+
Then these messages are acknowledged: (table)
|
103
110
|
|
104
|
-
Given an amqp server running
|
111
|
+
Given an amqp server running on "localhost" at port 1234
|
105
112
|
Given amqp queue "queue-name" is empty
|
106
113
|
When I input these messages to exchange "queue-name"
|
107
114
|
Then these messages are on queue "queue-name"
|
@@ -7,8 +7,8 @@ module PipelineToolkit
|
|
7
7
|
# talks messages.
|
8
8
|
class IOProcess
|
9
9
|
|
10
|
-
def run(command)
|
11
|
-
@process = BackgroundProcess.run("ruby -rubygems
|
10
|
+
def run(command, path = "bin")
|
11
|
+
@process = BackgroundProcess.run("ruby -rubygems #{path}/#{command}")
|
12
12
|
# wait for process to start
|
13
13
|
sleep(0.5)
|
14
14
|
raise @process.stderr.gets unless @process.running?
|
@@ -10,8 +10,8 @@ module PipelineToolkit
|
|
10
10
|
|
11
11
|
attr_reader :use_acknowledgements
|
12
12
|
|
13
|
-
def run(command, use_acknowledgements = true)
|
14
|
-
super(command)
|
13
|
+
def run(command, use_acknowledgements = true, path = "bin")
|
14
|
+
super(command, path)
|
15
15
|
|
16
16
|
@use_acknowledgements = use_acknowledgements
|
17
17
|
setup_system
|
@@ -9,10 +9,23 @@ After do
|
|
9
9
|
@process.kill unless @process.nil?
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
# Lets you use JSON to express a complex message
|
13
|
+
When /^I input this message$/ do |json_str|
|
14
|
+
@process.input_messages([JSON.parse(json_str)], false)
|
15
|
+
end
|
16
|
+
|
17
|
+
When /^I input this message with(out)? ack_ids$/ do |without_acks_ids, json_str|
|
18
|
+
@process.input_messages([JSON.parse(json_str)], !without_acks_ids)
|
19
|
+
end
|
20
|
+
|
21
|
+
When /^I input these messages with(out)? ack_ids:$/ do |without_acks_ids, messages|
|
13
22
|
@process.input_messages(messages.hashes, !without_acks_ids)
|
14
23
|
end
|
15
24
|
|
25
|
+
When /^I input these messages:$/ do |messages|
|
26
|
+
@process.input_messages(messages.hashes, false)
|
27
|
+
end
|
28
|
+
|
16
29
|
Then /^these messages are passed on:$/ do |expected_msgs|
|
17
30
|
received_messages = @process.get_messages(expected_msgs.rows.size)
|
18
31
|
# turn everything into str
|
@@ -20,6 +33,14 @@ Then /^these messages are passed on:$/ do |expected_msgs|
|
|
20
33
|
expected_msgs.diff!(received_messages)
|
21
34
|
end
|
22
35
|
|
36
|
+
# Lets you use JSON to express a complex message
|
37
|
+
Then /^this message is passed on$/ do |expected_msg|
|
38
|
+
received_message = @process.get_messages(1).first
|
39
|
+
# turn everything into str
|
40
|
+
received_message.each { |k,v| received_message[k] = v.to_s }
|
41
|
+
received_message.should == JSON.parse(expected_msg)
|
42
|
+
end
|
43
|
+
|
23
44
|
Then /^these messages are acknowledged:$/ do |expected_msgs|
|
24
45
|
received_messages = @process.get_acknowledged_messages(expected_msgs.rows.size)
|
25
46
|
# turn everything into str
|
@@ -27,3 +48,4 @@ Then /^these messages are acknowledged:$/ do |expected_msgs|
|
|
27
48
|
expected_msgs.diff!(received_messages)
|
28
49
|
end
|
29
50
|
|
51
|
+
|
@@ -8,6 +8,8 @@ module PipelineToolkit
|
|
8
8
|
# is being included in a IOProcess or subclass of.
|
9
9
|
module PipelineIO
|
10
10
|
|
11
|
+
attr_reader :all_messages
|
12
|
+
|
11
13
|
# Gets output from process, and decodes it into a pipeline message
|
12
14
|
def get_messages(number, timeout = 5)
|
13
15
|
output_msgs = []
|
@@ -15,6 +17,10 @@ module PipelineToolkit
|
|
15
17
|
msg = MessageCoder.decode(line)
|
16
18
|
output_msgs << msg
|
17
19
|
end
|
20
|
+
|
21
|
+
@all_messages ||= []
|
22
|
+
@all_messages << output_msgs
|
23
|
+
|
18
24
|
output_msgs
|
19
25
|
end
|
20
26
|
|
@@ -6,6 +6,12 @@ module PipelineToolkit
|
|
6
6
|
#
|
7
7
|
class MessageCoder
|
8
8
|
|
9
|
+
# Replace illegal chars (because we're using a line orientated procotol)
|
10
|
+
TRANSLATION = {
|
11
|
+
"\r" => "@@r",
|
12
|
+
"\n" => "@@n",
|
13
|
+
}
|
14
|
+
|
9
15
|
##
|
10
16
|
# Encode the hash message
|
11
17
|
#
|
@@ -14,9 +20,9 @@ module PipelineToolkit
|
|
14
20
|
def self.encode(message)
|
15
21
|
# NB: Using Msgpack because it's 9-10x faster than altnatives
|
16
22
|
# See http://gist.github.com/190849
|
17
|
-
MessagePack.pack(message)
|
18
|
-
|
19
|
-
|
23
|
+
str = MessagePack.pack(message)
|
24
|
+
str.gsub!(/[#{TRANSLATION.keys.join}]/) { |c| TRANSLATION[c] }
|
25
|
+
str
|
20
26
|
end
|
21
27
|
|
22
28
|
##
|
@@ -26,6 +32,7 @@ module PipelineToolkit
|
|
26
32
|
#
|
27
33
|
def self.decode(str)
|
28
34
|
str.chomp!
|
35
|
+
str.gsub!(/#{TRANSLATION.values.join("|")}/) { |s| TRANSLATION.invert[s] }
|
29
36
|
obj = MessagePack.unpack(str)
|
30
37
|
|
31
38
|
obj = case obj
|