Merge pull request #55 from lookout/reap_java_children

add reaping of java promises
This commit is contained in:
R. Tyler Croy 2014-10-15 12:32:39 -07:00
commit 0a1d9efd61
4 changed files with 27 additions and 6 deletions

View File

@ -97,7 +97,7 @@ module Hermann
@children.each do |child|
# Skip over any children that should already be reaped for other
# reasons
next if child.reap?
next if child.completed?
# Propagate errors to the remaining children
child.internal_set_error(ex)
end
@ -112,7 +112,8 @@ module Hermann
def reap_children
# Filter all children who are no longer pending/fulfilled
total_children = @children.size
@children = @children.reject { |c| c.reap? }
@children = @children.reject { |c| c.completed? }
return (total_children - children.size)
end

View File

@ -23,7 +23,7 @@ module Hermann
end
# @return [Boolean] True if this child can be reaped
def reap?
def completed?
return true if rejected? || fulfilled?
return false
end

View File

@ -43,6 +43,26 @@ describe Hermann::Producer do
end
end
end
context 'when reaping children', :platform => :java do
subject { producer.push('f', :topic => passed_topic) }
context 'with reapable children' do
it 'should reap the children' do
promise = Concurrent::Promise.execute { 'f' }.wait(1)
producer.instance_variable_set(:@children, [promise])
expect{subject}.to change{producer.children.size}.by(0)
end
end
context 'with no reapable children' do
it 'should not reap the children' do
promise = Concurrent::Promise.new {'f'}
producer.instance_variable_set(:@children, [promise])
expect{subject}.to change{producer.children.size}.by(1)
end
end
end
end
describe '#create_result' do
@ -146,7 +166,7 @@ describe Hermann::Producer do
before :each do
3.times do
child = Hermann::Result.new(producer)
allow(child).to receive(:reap?) { reap }
allow(child).to receive(:completed?) { reap }
producer.children << child
end

View File

@ -25,8 +25,8 @@ describe Hermann::Result do
end
end
describe '#reap?' do
subject { result.reap? }
describe '#completed?' do
subject { result.completed? }
context 'if state == :pending' do
before(:each) { allow(result).to receive(:pending?) { true } }