mirror of https://github.com/reiseburo/hermann
add reaping of java promises
This commit is contained in:
parent
2c1494a18e
commit
63c64f8ea3
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 } }
|
||||
|
|
Loading…
Reference in New Issue