Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify default behavior of dummy server error, etc #75

Merged
merged 1 commit into from
Jun 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions test/dummy_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ def create_error_page

class DummyServer
class << self
def start(seed = 0, seed_500 = 0)
@server ||= DummyServer.new(seed, seed_500).start
def start(seed = 0)
@server ||= DummyServer.new(seed).start
end
end

def initialize(seed = 0, seed_500 = 0)
def initialize(seed = 0)
@random = Random.new(seed)
@random_500 = Random.new(seed_500)
@random_500 = Random.new(seed)
@random_error = false
@requests = []
@accepted_records = []
@failed_count = 0
Expand All @@ -52,6 +53,7 @@ def start
end

def clear
@random_error = false
@requests = []
@accepted_records = []
@failed_count = 0
Expand All @@ -72,11 +74,11 @@ def requests
end

def records
flatten_records(@accepted_records, false)
flatten_records(@accepted_records)
end

def detailed_records
flatten_records(@accepted_records, true)
flatten_records(@accepted_records, detailed: true)
end

def failed_count
Expand All @@ -87,6 +89,25 @@ def error_count
@error_count
end

def aggregated_count
aggregated_count = 0
@accepted_records.flat_map do |record|
data = Base64.decode64(record[:record]['Data'])
if data[0,4] == ['F3899AC2'].pack('H*')
aggregated_count += 1
end
end
aggregated_count
end

def enable_random_error
@random_error = true
end

def disable_random_error
@random_error = false
end

private

def init_server
Expand Down Expand Up @@ -131,11 +152,13 @@ def init_server
end

def random_fail
return false unless @random_error
return true if failed_count == 0
@random.rand >= 0.9
end

def random_error_500
return false unless @random_error
return true if error_count == 0
@random_500.rand >= 0.9
end
Expand Down Expand Up @@ -214,7 +237,7 @@ def put_record_batch_boby(req)
}
end

def flatten_records(records, detailed)
def flatten_records(records, detailed: false)
records.flat_map do |record|
data = Base64.decode64(record[:record]['Data'])
partition_key = record[:record]['PartitionKey']
Expand Down
1 change: 1 addition & 0 deletions test/plugin/test_out_kinesis_firehose.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def test_max_record_size_without_append_new_line
end

def test_record_count
@server.enable_random_error
d = create_driver
count = 10
count.times do
Expand Down
2 changes: 2 additions & 0 deletions test/plugin/test_out_kinesis_producer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def test_max_record_size
end

def test_record_count
@server.enable_random_error
d = create_driver
count = 200
count.times do
Expand All @@ -158,5 +159,6 @@ def test_record_count
assert_equal count, @server.records.size
assert @server.failed_count > 0
assert @server.error_count > 0
assert @server.aggregated_count > 0
end
end
1 change: 1 addition & 0 deletions test/plugin/test_out_kinesis_streams.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def test_max_record_size
end

def test_record_count
@server.enable_random_error
d = create_driver
count = 10
count.times do
Expand Down