rflow 1.0.1 → 1.1.0

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.
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  class RFlow
4
4
  describe ForwardToOutputPort do
5
5
  before(:each) do
6
- ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
6
+ ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
7
7
  Configuration.migrate_database
8
8
  end
9
9
 
@@ -12,18 +12,19 @@ class RFlow
12
12
  let(:generator) do
13
13
  RFlow::Components::GenerateIntegerSequence.new.tap do |c|
14
14
  c.configure!({})
15
- c.out.direct_connect ruby_proc_filter.filtered
16
15
  end
17
16
  end
18
17
 
19
- let(:ruby_proc_filter) do
18
+ let(:accept_evens) do
20
19
  RFlow::Components::RubyProcFilter.new.tap do |c|
21
20
  c.configure! 'filter_proc_string' => 'message % 2 == 0'
22
21
  end
23
22
  end
24
23
 
25
24
  it 'should place the messages on the output port, regardless of the filter' do
26
- ruby_proc_filter.filtered.collect_messages(nil, messages) do
25
+ generator.out.direct_connect accept_evens.filtered
26
+
27
+ accept_evens.filtered.collect_messages(nil, messages) do
27
28
  5.times { generator.generate }
28
29
  end
29
30
  expect(messages.map(&:data).map(&:data_object)).to eq([0, 1, 2, 3, 4])
@@ -17,16 +17,16 @@ class RFlow
17
17
 
18
18
  before(:each) { initialize_logger }
19
19
 
20
- it "should initialize correctly" do
20
+ it 'should initialize correctly' do
21
21
  expect(File.exist?(log_file_path)).to be true
22
22
 
23
- logger.error "TESTTESTTEST"
23
+ logger.error 'TESTTESTTEST'
24
24
  expect(File.read(log_file_path)).to match(/TESTTESTTEST/)
25
25
 
26
26
  logger.close
27
27
  end
28
28
 
29
- it "should reopen correctly" do
29
+ it 'should reopen correctly' do
30
30
  moved_path = log_file_path + '.old'
31
31
 
32
32
  expect(File.exist?(log_file_path)).to be true
@@ -36,13 +36,13 @@ class RFlow
36
36
 
37
37
  logger.reopen
38
38
 
39
- logger.error "TESTTESTTEST"
39
+ logger.error 'TESTTESTTEST'
40
40
  expect(File.read(log_file_path)).to match(/TESTTESTTEST/)
41
41
  expect(File.read(moved_path)).not_to match(/TESTTESTTEST/)
42
42
 
43
43
  logger.close
44
44
  end
45
45
 
46
- it "should toggle log level"
46
+ it 'should toggle log level'
47
47
  end
48
48
  end
@@ -7,11 +7,11 @@ class RFlow
7
7
  describe 'Raw Avro Schema' do
8
8
  let(:schema) { Configuration.available_data_types['RFlow::Message::Data::Raw']['avro'] }
9
9
 
10
- it "should load the schema" do
10
+ it 'should load the schema' do
11
11
  expect(schema).not_to be_nil
12
12
  end
13
13
 
14
- it "should encode and decode an object" do
14
+ it 'should encode and decode an object' do
15
15
  raw = {'raw' => Array.new(256) { rand(256) }.pack('c*')}
16
16
 
17
17
  expect { encode_avro(schema, raw) }.to_not raise_error
@@ -9,13 +9,13 @@ class RFlow
9
9
  let(:valid_schema) { '{"type": "string"}' }
10
10
  let(:serialized_string) { encode_avro(valid_schema, string) }
11
11
 
12
- context "if created without a schema" do
13
- it "should throw an exception" do
12
+ context 'if created without a schema' do
13
+ it 'should throw an exception' do
14
14
  expect { Data.new(nil) }.to raise_error(ArgumentError, /^Invalid schema/)
15
15
  end
16
16
  end
17
17
 
18
- context "if created with an invalid schema for the serialization" do
18
+ context 'if created with an invalid schema for the serialization' do
19
19
  ['avro', :avro].each do |it|
20
20
  it "should throw an exception for serialization type #{it.inspect}" do
21
21
  expect { Data.new(invalid_schema, it) }.to raise_error(ArgumentError, /^Invalid schema/)
@@ -23,14 +23,14 @@ class RFlow
23
23
  end
24
24
  end
25
25
 
26
- context "if created with a valid avro schema" do
26
+ context 'if created with a valid avro schema' do
27
27
  ['avro', :avro].each do |it|
28
28
  it "should instantiate correctly for serialization type #{it.inspect}" do
29
29
  expect { Data.new(valid_schema, it) }.to_not raise_error
30
30
  end
31
31
  end
32
32
 
33
- context "if created with a non-avro data serialization" do
33
+ context 'if created with a non-avro data serialization' do
34
34
  ['unknown', :unknown, 'xml', :xml].each do |it|
35
35
  it "should throw an exception for serialization type #{it.inspect}" do
36
36
  expect { Data.new(valid_schema, it) }.to raise_error(
@@ -39,15 +39,15 @@ class RFlow
39
39
  end
40
40
  end
41
41
 
42
- context "if created with an avro serialization" do
42
+ context 'if created with an avro serialization' do
43
43
  ['avro', :avro].each do |it|
44
44
  it "should instantiate correctly for serialization type #{it.inspect}" do
45
45
  expect { Data.new(valid_schema, it) }.to_not raise_error
46
46
  end
47
47
  end
48
48
 
49
- context "if created with a serialized data object" do
50
- it "should instantiate correctly" do
49
+ context 'if created with a serialized data object' do
50
+ it 'should instantiate correctly' do
51
51
  expect { Data.new(valid_schema, 'avro', serialized_string )}.to_not raise_error
52
52
  end
53
53
  end
@@ -4,70 +4,70 @@ require 'rflow/message'
4
4
 
5
5
  class RFlow
6
6
  describe Message do
7
- context "if created with an unknown data type" do
8
- it "should throw an exception" do
7
+ context 'if created with an unknown data type' do
8
+ it 'should throw an exception' do
9
9
  expect { Message.new('non_existent_data_type') }.to raise_error(
10
10
  ArgumentError, "Data type 'non_existent_data_type' with serialization_type 'avro' not found")
11
11
  end
12
12
  end
13
13
 
14
- context "if created with a known data type" do
14
+ context 'if created with a known data type' do
15
15
  before(:all) do
16
16
  @schema = '{"type": "string"}'
17
17
  Configuration.add_available_data_type(:string_type, 'avro', @schema)
18
18
  end
19
19
 
20
- it "should instantiate correctly" do
20
+ it 'should instantiate correctly' do
21
21
  expect { Message.new('string_type') }.to_not raise_error
22
22
  end
23
23
 
24
- context "if created with empty provenance" do
25
- context "if created with an unknown data serialization" do
24
+ context 'if created with empty provenance' do
25
+ context 'if created with an unknown data serialization' do
26
26
  ['unknown', :unknown].each do |it|
27
27
  it "should throw an exception for #{it.inspect}" do
28
- expect { Message.new('string_type', [], it) }.to raise_error(
28
+ expect { Message.new('string_type', [], {}, it) }.to raise_error(
29
29
  ArgumentError, "Data type 'string_type' with serialization_type 'unknown' not found")
30
30
  end
31
31
  end
32
32
  end
33
33
 
34
- context "if created with a known data serialization" do
34
+ context 'if created with a known data serialization' do
35
35
  ['avro', :avro].each do |it|
36
36
  it "should instantiate correctly for #{it.inspect}" do
37
- expect { Message.new('string_type', [], it) }.to_not raise_error
37
+ expect { Message.new('string_type', [], {}, it) }.to_not raise_error
38
38
  end
39
39
  end
40
40
 
41
- context "if created with a mismatched schema" do
41
+ context 'if created with a mismatched schema' do
42
42
  it
43
43
  end
44
- context "if created with a matched schema" do
44
+ context 'if created with a matched schema' do
45
45
  it
46
46
  end
47
47
 
48
- context "if created with a nil schema" do
49
- context "if created with a serialized data object" do
48
+ context 'if created with a nil schema' do
49
+ context 'if created with a serialized data object' do
50
50
  let(:serialized_string) { encode_avro(@schema, 'this is a string to be serialized') }
51
51
 
52
- it "should instantiate correctly" do
53
- expect { Message.new('string_type', [], 'avro', nil, serialized_string) }.to_not raise_error
52
+ it 'should instantiate correctly' do
53
+ expect { Message.new('string_type', [], {}, 'avro', nil, serialized_string) }.to_not raise_error
54
54
  end
55
55
  end
56
56
  end
57
57
  end
58
58
  end
59
59
 
60
- context "if created with invalid provenance" do
60
+ context 'if created with invalid provenance' do
61
61
  let(:invalid_processing_event_hash) { {'started_at' => 'bad time string'} }
62
62
  let(:invalid_provenance) { [invalid_processing_event_hash] }
63
63
 
64
- it "should throw an exception" do
64
+ it 'should throw an exception' do
65
65
  expect { Message.new('string_type', invalid_provenance) }.to raise_error(
66
66
  ArgumentError, 'invalid date: "bad time string"')
67
67
  end
68
68
  end
69
69
 
70
- context "if created with valid provenance" do
70
+ context 'if created with valid provenance' do
71
71
  let(:valid_xmlschema_time) { '2001-01-01T01:01:01.000001Z' }
72
72
  let(:valid_processing_event_hash) { {'component_instance_uuid' => 'uuid', 'started_at' => valid_xmlschema_time } }
73
73
  let(:valid_processing_event) { Message::ProcessingEvent.new('uuid', valid_xmlschema_time, valid_xmlschema_time, 'context') }
@@ -77,11 +77,11 @@ class RFlow
77
77
  valid_processing_event]
78
78
  end
79
79
 
80
- it "should instantiate correctly" do
80
+ it 'should instantiate correctly' do
81
81
  expect { Message.new('string_type', valid_provenance) }.to_not raise_error
82
82
  end
83
83
 
84
- it "should correctly set the provenance processing events" do
84
+ it 'should correctly set the provenance processing events' do
85
85
  Message.new('string_type', valid_provenance).provenance[1].tap do |p|
86
86
  expect(p.component_instance_uuid).to eq('uuid')
87
87
  expect(p.started_at).to eq(Time.xmlschema(valid_xmlschema_time))
@@ -90,16 +90,50 @@ class RFlow
90
90
  end
91
91
  end
92
92
 
93
- it "should to_hash its provenance correctly" do
93
+ it 'should to_hash its provenance correctly' do
94
94
  expect(Message.new('string_type', valid_provenance).provenance.map(&:to_hash)).to eq([
95
- {"component_instance_uuid" => "uuid", "started_at" => nil, "completed_at" => nil, "context" => nil},
96
- {"component_instance_uuid" => "uuid", "started_at" => valid_xmlschema_time, "completed_at" => nil, "context" => nil},
97
- {"component_instance_uuid" => "uuid", "started_at" => valid_xmlschema_time, "completed_at" => valid_xmlschema_time, "context" => "context"}])
95
+ {'component_instance_uuid' => 'uuid', 'started_at' => nil, 'completed_at' => nil, 'context' => nil},
96
+ {'component_instance_uuid' => 'uuid', 'started_at' => valid_xmlschema_time, 'completed_at' => nil, 'context' => nil},
97
+ {'component_instance_uuid' => 'uuid', 'started_at' => valid_xmlschema_time, 'completed_at' => valid_xmlschema_time, 'context' => 'context'}])
98
98
  end
99
+
100
+ it "should not serialize data that doesn't match the schema" do
101
+ message = Message.new('string_type')
102
+ expect { message.to_avro }.to raise_error(::Avro::IO::AvroTypeError)
103
+ message.data.data_object = 'data'
104
+ expect { message.to_avro }.to_not raise_error
105
+ end
106
+ end
107
+
108
+ context 'if given properties' do
109
+ it 'should initialize and serialize with valid properties' do
110
+ properties = { 'boom' => 'boom', 'down' => 'town' }
111
+ message = Message.new('string_type', nil, properties)
112
+ expect(message.properties).to eq(properties)
113
+
114
+ message.data.data_object = 'data'
115
+
116
+ Message.from_avro(message.to_avro).tap do |processed|
117
+ expect(processed.properties).to eq(properties)
118
+ expect(processed.properties['boom']).to eq(message.properties['boom'])
119
+ end
120
+ end
121
+
122
+ it 'should stringify non-string properties' do
123
+ properties = { :boom => :town }
124
+ message = Message.new('string_type', nil, properties)
125
+
126
+ message.data.data_object = 'data'
127
+
128
+ Message.from_avro(message.to_avro).tap do |processed|
129
+ expect(processed.properties['boom']).to eq(message.properties[:boom].to_s)
130
+ end
131
+ end
132
+
99
133
  end
100
134
 
101
- context "if correctly created" do
102
- it "should serialize and deserialize correctly to/from avro" do
135
+ context 'if correctly created' do
136
+ it 'should serialize and deserialize correctly to/from avro' do
103
137
  message = Message.new('string_type').tap do |m|
104
138
  m.provenance << Message::ProcessingEvent.new('UUID')
105
139
  m.data.data_object = 'teh awesome'
@@ -112,8 +146,8 @@ class RFlow
112
146
  end
113
147
  end
114
148
 
115
- context "if data extensions exist" do
116
- it "should extend the data element with the extension" do
149
+ context 'if data extensions exist' do
150
+ it 'should extend the data element with the extension' do
117
151
  module ExtensionModule; def ext_method; end; end
118
152
 
119
153
  message = Message.new('string_type')
@@ -126,7 +160,7 @@ class RFlow
126
160
  end
127
161
  end
128
162
 
129
- it "should correctly handle large raw types" do
163
+ it 'should correctly handle large raw types' do
130
164
  message = Message.new('RFlow::Message::Data::Raw').tap do |m|
131
165
  m.data.raw = Array.new(101) { rand(256) }.pack('c*')
132
166
  end
data/spec/rflow_spec.rb CHANGED
@@ -37,7 +37,7 @@ describe RFlow do
37
37
 
38
38
  # Grab all the pids from the log, which seems to be the only
39
39
  # reliable way to get them
40
- log_lines.map {|line| /\((\d+)\)/.match(line)[1].to_i }.uniq
40
+ log_lines.map {|line| /\(\s*(\d+)\s*\)/.match(line)[1].to_i }.uniq
41
41
  end
42
42
 
43
43
  def run_and_shutdown(app_name, expected_worker_count)
@@ -64,7 +64,7 @@ describe RFlow do
64
64
  yield # verify output
65
65
 
66
66
  # Terminate the master
67
- expect(Process.kill("TERM", master_pid)).to eq(1)
67
+ expect(Process.kill('TERM', master_pid)).to eq(1)
68
68
 
69
69
  # Make sure everything is dead after a second
70
70
  sleep 2
@@ -72,7 +72,7 @@ describe RFlow do
72
72
  expect { Process.kill(0, pid) }.to raise_error(Errno::ESRCH)
73
73
  end
74
74
  rescue Exception => e
75
- Process.kill("TERM", master_pid) if master_pid
75
+ Process.kill('TERM', master_pid) if master_pid
76
76
  raise
77
77
  end
78
78
 
@@ -94,13 +94,13 @@ describe RFlow do
94
94
 
95
95
  after(:each) { Dir.chdir @original_directory_path }
96
96
 
97
- context "when executing from the test script" do
97
+ context 'when executing from the test script' do
98
98
  before(:all) { load @extensions_file_name }
99
99
 
100
100
  describe '.run!' do
101
101
  def run_rflow_with_dsl(&block)
102
102
  rflow_thread = Thread.new do
103
- ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
103
+ ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
104
104
  RFlow::Configuration.migrate_database
105
105
  RFlow::Configuration::RubyDSL.configure {|c| block.call(c) }
106
106
  RFlow::Configuration.merge_defaults!
@@ -117,7 +117,7 @@ describe RFlow do
117
117
  rflow_thread.join
118
118
  end
119
119
 
120
- it "should run a non-sharded workflow" do
120
+ it 'should run a non-sharded workflow' do
121
121
  run_rflow_with_dsl do |c|
122
122
  c.setting 'rflow.log_level', 'ERROR'
123
123
  c.setting 'rflow.application_directory_path', @temp_directory_path
@@ -158,7 +158,7 @@ describe RFlow do
158
158
  end
159
159
  end
160
160
 
161
- it "should run a sharded workflow" do
161
+ it 'should run a sharded workflow' do
162
162
  run_rflow_with_dsl do |c|
163
163
  c.setting 'rflow.log_level', 'ERROR'
164
164
  c.setting 'rflow.application_directory_path', @temp_directory_path
@@ -207,7 +207,7 @@ describe RFlow do
207
207
  end
208
208
  end
209
209
 
210
- it "should deliver broadcast messages to every copy of a shard" do
210
+ it 'should deliver broadcast messages to every copy of a shard' do
211
211
  run_rflow_with_dsl do |c|
212
212
  c.setting 'rflow.log_level', 'FATAL'
213
213
  c.setting 'rflow.application_directory_path', @temp_directory_path
@@ -249,8 +249,8 @@ describe RFlow do
249
249
  end
250
250
  end
251
251
 
252
- context "when executing via the rflow binary" do
253
- context "with a simple ruby DSL config file" do
252
+ context 'when executing via the rflow binary' do
253
+ context 'with a simple ruby DSL config file' do
254
254
  before(:each) do
255
255
  write_config_file <<-EOF
256
256
  RFlow::Configuration::RubyDSL.configure do |c|
@@ -259,14 +259,14 @@ describe RFlow do
259
259
  EOF
260
260
  end
261
261
 
262
- it "should load a ruby dsl file into a sqlite DB" do
262
+ it 'should load a ruby dsl file into a sqlite DB' do
263
263
  load_database
264
264
 
265
- ActiveRecord::Base.establish_connection adapter: "sqlite3", database: db_file_name
265
+ ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: db_file_name
266
266
  expect(RFlow::Configuration::Setting.where(:name => 'mysetting').first.value).to eq('myvalue')
267
267
  end
268
268
 
269
- it "should not load a database if the database file already exists" do
269
+ it 'should not load a database if the database file already exists' do
270
270
  File.open(db_file_name, 'w') {|file| file.write 'boom' }
271
271
 
272
272
  r = execute_rflow("load -d #{db_file_name} -c #{config_file_name}")
@@ -278,7 +278,7 @@ describe RFlow do
278
278
  end
279
279
  end
280
280
 
281
- context "with a component that runs subshells" do
281
+ context 'with a component that runs subshells' do
282
282
  let(:app_name) { 'sharded_subshell_test' }
283
283
 
284
284
  before(:each) do
@@ -300,15 +300,15 @@ describe RFlow do
300
300
  load_database
301
301
  end
302
302
 
303
- it "should run successfully daemonize and run in the background" do
303
+ it 'should run successfully daemonize and run in the background' do
304
304
  run_and_shutdown app_name, 1 do # 1 default worker
305
305
  expect(File.exist?(File.join(@temp_directory_path, 'out1'))).to be true
306
- File.readlines('out1').each {|line| expect(line).to match /\w+ \w+ \d+ \d+:\d+:\d+ \w+ \d+/ }
306
+ File.readlines('out1').each {|line| expect(line).to match /\w+ \w+\s+\d+ \d+:\d+:\d+ \w+ \d+/ }
307
307
  end
308
308
  end
309
309
  end
310
310
 
311
- context "with a complex, sharded ruby DSL config file" do
311
+ context 'with a complex, sharded ruby DSL config file' do
312
312
  let(:app_name) { 'sharded_bin_test' }
313
313
 
314
314
  before(:each) do
@@ -352,7 +352,7 @@ describe RFlow do
352
352
  expect(r[:stdout]).to match /error/i
353
353
  end
354
354
 
355
- it "should daemonize and run in the background" do
355
+ it 'should daemonize and run in the background' do
356
356
  output_files = {
357
357
  'out1' => [0, 3, 6, 9] * 3,
358
358
  'out2' => (20..30).to_a * 2,
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
+ - John Stoneham
7
8
  - Michael L. Artz
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-07-17 00:00:00.000000000 Z
12
+ date: 2016-06-14 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: uuidtools
@@ -44,14 +45,14 @@ dependencies:
44
45
  requirements:
45
46
  - - "~>"
46
47
  - !ruby/object:Gem::Version
47
- version: 1.1.2
48
+ version: '1.1'
48
49
  type: :runtime
49
50
  prerelease: false
50
51
  version_requirements: !ruby/object:Gem::Requirement
51
52
  requirements:
52
53
  - - "~>"
53
54
  - !ruby/object:Gem::Version
54
- version: 1.1.2
55
+ version: '1.1'
55
56
  - !ruby/object:Gem::Dependency
56
57
  name: sqlite3
57
58
  requirement: !ruby/object:Gem::Requirement
@@ -86,26 +87,26 @@ dependencies:
86
87
  requirements:
87
88
  - - "~>"
88
89
  - !ruby/object:Gem::Version
89
- version: 1.7.5
90
+ version: '1.7'
90
91
  type: :runtime
91
92
  prerelease: false
92
93
  version_requirements: !ruby/object:Gem::Requirement
93
94
  requirements:
94
95
  - - "~>"
95
96
  - !ruby/object:Gem::Version
96
- version: 1.7.5
97
+ version: '1.7'
97
98
  - !ruby/object:Gem::Dependency
98
99
  name: em-zeromq
99
100
  requirement: !ruby/object:Gem::Requirement
100
101
  requirements:
101
- - - '='
102
+ - - "~>"
102
103
  - !ruby/object:Gem::Version
103
104
  version: 0.5.0
104
105
  type: :runtime
105
106
  prerelease: false
106
107
  version_requirements: !ruby/object:Gem::Requirement
107
108
  requirements:
108
- - - '='
109
+ - - "~>"
109
110
  - !ruby/object:Gem::Version
110
111
  version: 0.5.0
111
112
  - !ruby/object:Gem::Dependency
@@ -114,14 +115,14 @@ dependencies:
114
115
  requirements:
115
116
  - - "~>"
116
117
  - !ruby/object:Gem::Version
117
- version: '1.6'
118
+ version: '1'
118
119
  type: :development
119
120
  prerelease: false
120
121
  version_requirements: !ruby/object:Gem::Requirement
121
122
  requirements:
122
123
  - - "~>"
123
124
  - !ruby/object:Gem::Version
124
- version: '1.6'
125
+ version: '1'
125
126
  - !ruby/object:Gem::Dependency
126
127
  name: rspec
127
128
  requirement: !ruby/object:Gem::Requirement
@@ -181,7 +182,8 @@ dependencies:
181
182
  description: A Ruby flow-based programming framework that utilizes ZeroMQ for component
182
183
  connections and Avro for serialization
183
184
  email:
184
- - michael.artz@redjack.com
185
+ - john.stoneham@redjack.com
186
+ - mlartz@gmail.com
185
187
  executables:
186
188
  - rflow
187
189
  extensions: []
@@ -196,7 +198,6 @@ files:
196
198
  - Gemfile
197
199
  - Guardfile
198
200
  - LICENSE
199
- - NOTES
200
201
  - README.VAGRANT
201
202
  - README.md
202
203
  - Rakefile
@@ -277,7 +278,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
277
278
  version: '0'
278
279
  requirements: []
279
280
  rubyforge_project:
280
- rubygems_version: 2.3.0
281
+ rubygems_version: 2.5.1
281
282
  signing_key:
282
283
  specification_version: 4
283
284
  summary: A Ruby flow-based programming framework