Skip to content

Commit 6af11e0

Browse files
author
ahanusa
committed
add threading test
1 parent d2e1b1e commit 6af11e0

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

entity_base.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class EntityBase
2+
def id=(value)
3+
raise "id must be implemented"
4+
end
5+
end

threading_test.rb

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
require_relative "command_base"
2+
require_relative "execution_result"
3+
require_relative "service_base"
4+
require_relative "DataProxies/DatabaseProxies/customer_database_proxy"
5+
require_relative "DataProxies/RestfulServiceProxies/customer_restful_proxy"
6+
require_relative "Rules/field_length_rule"
7+
require_relative "Rules/field_required_rule"
8+
9+
class CustomerService < ServiceBase
10+
def initialize(data_proxy)
11+
super(data_proxy)
12+
end
13+
def rules_for_insert(entity)
14+
rules = []
15+
rules << FieldRequiredRule.new(entity, :name)
16+
.if_valid_then_execute(lambda { |rule| puts "WOOT!" })
17+
.if_valid_then_validate(FieldLengthRule.new(entity, :name, 10)
18+
.if_invalid_then_execute(lambda { |rule| puts "ARGH!!" }))
19+
rules
20+
end
21+
end
22+
23+
#customer_data_proxy = CustomerRestfulProxy.new
24+
customer_data_proxy = CustomerDatabaseProxy.new
25+
26+
service = CustomerService.new(customer_data_proxy)
27+
28+
commands = []
29+
commands << service.insert_command({:id => 1, :name => ""})
30+
commands << service.insert_command({:id => 2, :name => "Foo Bar"})
31+
commands << service.insert_command({:id => 3, :name => ""})
32+
commands << service.insert_command({:id => 4, :name => "Mikasaessucasa"})
33+
commands << service.insert_command({:id => 5, :name => "John"})
34+
commands << service.insert_command({:id => 6, :name => ""})
35+
commands << service.insert_command({:id => 7, :name => ""})
36+
commands << service.insert_command({:id => 8, :name => "meh"})
37+
commands << service.insert_command({:id => 9, :name => ""})
38+
commands << service.insert_command({:id => 10, :name => "Aargssssssssss"})
39+
commands << service.insert_command({:id => 11, :name => ""})
40+
41+
results = []
42+
threads = commands.map { |command| Thread.new(command) { |command| results << command.execute } }
43+
threads.each { |t| t.join }
44+
45+
results.each { |result| puts result.inspect }

validation_result.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
class ValidationResult
2-
attr_accessor :member, :error_messages
2+
attr_accessor :entity, :error_messages
33

4-
def initialize
5-
@error_messages = []
4+
def initialize(entity, error_messages = [])
5+
@entity = entity
6+
@error_messages = error_messages
67
end
78
end

0 commit comments

Comments
 (0)