pipeline_toolkit 1.2.7 → 1.2.8

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.
data/README.markdown CHANGED
@@ -96,13 +96,14 @@ Pipeline toolkit also includes pre-canned cucumber steps for you to test your ma
96
96
 
97
97
  Given I run this machine:
98
98
  When I input these messages:
99
+ When I input these messages with ack_ids:
99
100
  Then these messages are passed on:
100
101
  Then these messages are acknowledged:
101
102
 
102
103
  Given an amqp server running at "localhost" on port 1234
103
- Given amqp queue "test" is empty
104
- When I input these messages to exchange "test"
105
- Then these messages are on queue "test"
104
+ Given amqp queue "queue-name" is empty
105
+ When I input these messages to exchange "queue-name"
106
+ Then these messages are on queue "queue-name"
106
107
 
107
108
  The steps are defined in the following files, so have a look at them to get more details
108
109
 
@@ -17,6 +17,8 @@ Message Sink
17
17
  msg_sink
18
18
  EOL
19
19
 
20
+ opt :acknowledge, "If flag is set then messages are acknowledged", :type => :flag, :short => :a
21
+ opt :out, "If flag is set then messages are printed to stdout in plain-text", :type => :flag, :short => :o
20
22
  opt :env, "The environment to run (development, production)", :default => "development", :short => :e
21
23
  end
22
24
 
@@ -1,7 +1,7 @@
1
1
  require 'pipeline_toolkit/cucumber/amqp'
2
- require 'pipeline_toolkit/cucumber/in_out_process'
2
+ require 'pipeline_toolkit/cucumber/io_process'
3
+ require 'pipeline_toolkit/cucumber/pipeline_io'
3
4
  require 'pipeline_toolkit/cucumber/machine'
4
- require 'pipeline_toolkit/cucumber/msg_sub_process'
5
5
 
6
6
  require 'pipeline_toolkit/cucumber/machine_steps'
7
7
  require 'pipeline_toolkit/cucumber/amqp_steps'
@@ -5,7 +5,7 @@ module PipelineToolkit
5
5
 
6
6
  # Provides an interface for running and interacting with a stdin/stdout process which
7
7
  # talks messages.
8
- class InOutProcess
8
+ class IOProcess
9
9
 
10
10
  def run(command)
11
11
  @process = BackgroundProcess.run("ruby -rubygems bin/#{command}")
@@ -23,13 +23,13 @@ module PipelineToolkit
23
23
  @process.pid
24
24
  end
25
25
 
26
- def get_messages(number, timeout = 5)
27
- output_msgs = []
26
+ # Gets the raw output of the process
27
+ def get_output(number, timeout = 5)
28
+ lines = []
28
29
  get_lines(@process.stdout, number, timeout) do |line|
29
- msg = MessageCoder.decode(line)
30
- output_msgs << msg
30
+ lines << line
31
31
  end
32
- output_msgs
32
+ lines
33
33
  end
34
34
 
35
35
  private
@@ -5,29 +5,22 @@ module PipelineToolkit
5
5
  module Cucumber
6
6
 
7
7
  # Provides an interface for running and interacting with a pipeline_toolkit machine.
8
- class Machine < InOutProcess
8
+ class Machine < IOProcess
9
+ include PipelineIO
9
10
 
10
11
  attr_reader :use_acknowledgements
11
12
 
12
13
  def run(command, use_acknowledgements = true)
13
14
  super(command)
14
-
15
+
15
16
  @use_acknowledgements = use_acknowledgements
16
- setup_system
17
+ setup_system
17
18
  end
18
19
 
19
20
  def kill
20
21
  destroy_sys_pipe
21
22
  super
22
23
  end
23
-
24
- def input_messages(messages)
25
- messages.each do |message|
26
- store_acknowledgement(message) if use_acknowledgements
27
- @process.stdin.puts(MessageCoder.encode(message))
28
- @process.stdin.flush
29
- end
30
- end
31
24
 
32
25
  def get_acknowledged_messages(number, timeout = 5)
33
26
  output_msgs = []
@@ -50,6 +43,10 @@ module PipelineToolkit
50
43
  # send sys_message
51
44
  input_messages([message])
52
45
 
46
+ # first message should be system one
47
+ @sys_setup = get_messages(1).first
48
+ raise "Expecting first message to be system message, got instead: #{@sys_setup.inspect}" if @sys_setup[:msg_type] != "system"
49
+
53
50
  # get pipe_desc off sys_pipe
54
51
  get_lines(@sys_pipe, 1, 5)
55
52
  end
@@ -64,9 +61,9 @@ module PipelineToolkit
64
61
  @sys_pipe = File.new(name, "r+")
65
62
  end
66
63
 
67
- def store_acknowledgement(message)
64
+ def simulate_ack_id(message)
65
+ super(message)
68
66
  @messages_to_ack ||= {}
69
- message[:ack_id] = "#{Time.now.to_i}_#{rand(9999)}"
70
67
  @messages_to_ack[message[:ack_id]] = message
71
68
  end
72
69
 
@@ -9,8 +9,8 @@ After do
9
9
  @process.kill unless @process.nil?
10
10
  end
11
11
 
12
- When /^I input these messages:$/ do |messages|
13
- @process.input_messages(messages.hashes)
12
+ When /^I input these messages with(out)? ack_ids?:$/ do |without_acks_ids, messages|
13
+ @process.input_messages(messages.hashes, !without_acks_ids)
14
14
  end
15
15
 
16
16
  Then /^these messages are passed on:$/ do |expected_msgs|
@@ -0,0 +1,37 @@
1
+ require 'pipeline_toolkit'
2
+ require 'background_process'
3
+
4
+ module PipelineToolkit
5
+ module Cucumber
6
+
7
+ # Provides IO methods for reading and writting pipeline messages to an IOProcess. NB: It is assumed that the module
8
+ # is being included in a IOProcess or subclass of.
9
+ module PipelineIO
10
+
11
+ # Gets output from process, and decodes it into a pipeline message
12
+ def get_messages(number, timeout = 5)
13
+ output_msgs = []
14
+ get_lines(@process.stdout, number, timeout) do |line|
15
+ msg = MessageCoder.decode(line)
16
+ output_msgs << msg
17
+ end
18
+ output_msgs
19
+ end
20
+
21
+ def input_messages(messages, simulate_acks = false)
22
+ messages.each do |message|
23
+ simulate_ack_id(message) if simulate_acks
24
+ @process.stdin.puts(MessageCoder.encode(message))
25
+ @process.stdin.flush
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def simulate_ack_id(message)
32
+ message[:ack_id] = "#{Time.now.to_i}_#{rand(9999)}"
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -49,7 +49,7 @@ module PipelineToolkit
49
49
  def process_standard(message)
50
50
  DefaultLogger.debug("MessagePusher#process_standard(message)") if options[:env] == "development"
51
51
  publish(message)
52
- acknowledge(message) if options[:ack]
52
+ acknowledge(message) if options[:ack] && message[:ack_id]
53
53
  end
54
54
 
55
55
  end
@@ -2,9 +2,13 @@ module PipelineToolkit
2
2
 
3
3
  class MessageSink
4
4
  include MessageCommand
5
-
5
+
6
6
  def process_standard(message)
7
- acknowledge(message)
7
+ if @options[:out]
8
+ $stdout.puts(message.inspect)
9
+ $stdout.flush
10
+ end
11
+ acknowledge(message) if @options[:acknowledge]
8
12
  end
9
13
 
10
14
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 2
8
- - 7
9
- version: 1.2.7
8
+ - 8
9
+ version: 1.2.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Aisha Fenton
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-27 00:00:00 +12:00
18
+ date: 2010-08-29 00:00:00 +12:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -169,10 +169,10 @@ files:
169
169
  - lib/pipeline_toolkit/cucumber.rb
170
170
  - lib/pipeline_toolkit/cucumber/amqp.rb
171
171
  - lib/pipeline_toolkit/cucumber/amqp_steps.rb
172
- - lib/pipeline_toolkit/cucumber/in_out_process.rb
172
+ - lib/pipeline_toolkit/cucumber/io_process.rb
173
173
  - lib/pipeline_toolkit/cucumber/machine.rb
174
174
  - lib/pipeline_toolkit/cucumber/machine_steps.rb
175
- - lib/pipeline_toolkit/cucumber/msg_sub_process.rb
175
+ - lib/pipeline_toolkit/cucumber/pipeline_io.rb
176
176
  - lib/pipeline_toolkit/default_logger.rb
177
177
  - lib/pipeline_toolkit/handlers/message_handler.rb
178
178
  - lib/pipeline_toolkit/message_coder.rb
@@ -1,34 +0,0 @@
1
-
2
- module PipelineToolkit
3
- module Cucumber
4
-
5
- # Provides an interface for running and interacting with a msg_subscribe process.
6
- class MsgSubProcess < InOutProcess
7
-
8
- def run(command)
9
- super(command)
10
- self.setup_pipe
11
- end
12
-
13
- def setup_pipe
14
- # first message should be system one
15
- msg = get_messages(1).first
16
- raise "Expecting first message to be system message, got instead: #{msg.inspect}" if msg[:msg_type] != "system"
17
- @system_setup = msg
18
- @ack_pipe = File.open(msg[:sys_pipe], "w")
19
- end
20
-
21
- def acknowledge_message(message)
22
- ack_message = {:msg_type => "ack", :ack_id => message[:ack_id]}
23
- @ack_pipe.syswrite(MessageCoder.encode(ack_message) << "\n")
24
- end
25
-
26
- def kill
27
- @ack_pipe.close
28
- super
29
- end
30
-
31
- end
32
-
33
- end
34
- end