add reaping of java promises

This commit is contained in:
jway 2014-10-15 11:09:16 -07:00
parent 2c1494a18e
commit 63c64f8ea3
4 changed files with 24 additions and 4 deletions

View File

@ -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,25 @@ describe Hermann::Producer do
end
end
end
context 'when reaping children' 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

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 } }