-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix for SimplePool.setPoolSize() #3143 #3144
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,18 +16,18 @@ | |
|
||
package org.springframework.integration.util; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.fail; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.Semaphore; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import org.junit.Test; | ||
|
||
import org.springframework.integration.test.util.TestUtils; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.fail; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, do not rearrange imports order. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, I tried to keep imports untouched. I will revert this |
||
|
||
/** | ||
* @author Gary Russell | ||
* @since 2.2 | ||
|
@@ -146,7 +146,27 @@ public void testDoubleReturn() { | |
pool.releaseItem(s1); | ||
assertThat(permits.availablePermits()).isEqualTo(2); | ||
} | ||
|
||
@Test | ||
public void testSizeUpdateIfNotAllocated() { | ||
SimplePool<String> pool = stringPool(10, new HashSet<>(), new AtomicBoolean()); | ||
pool.setPoolSize(5); | ||
assertThat(pool.getPoolSize()).isEqualTo(5); | ||
} | ||
|
||
@Test | ||
public void testSizeUpdateIfAllocated() { | ||
SimplePool<String> pool = stringPool(10, new HashSet<>(), new AtomicBoolean()); | ||
List<String> allocated = new ArrayList<>(); | ||
for (int i = 0; i < 10; i++) { | ||
allocated.add(pool.getItem()); | ||
} | ||
for (int i = 0; i < 10; i++) { | ||
pool.releaseItem(allocated.get(i)); | ||
} | ||
pool.setPoolSize(5); | ||
assertThat(pool.getPoolSize()).isEqualTo(5); | ||
} | ||
|
||
private SimplePool<String> stringPool(int size, final Set<String> strings, | ||
final AtomicBoolean stale) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have stopped to release permits.
Why is that, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this branch we need to call only
acquire()
. Original intent was to revert acquire if item==null. But this is absolutely incorrect. For example, if we have a new instance of pool, then "available" collection is empty. But setPoolSize() method should correctly update all structures. After callingsetPoolSize(5)
everything should contain5
. (permits==5, poolSize==5, and targetPoolSize==5). Of course, I am describing the situation when no objects were allocated. Please, check added test cases.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added additional checks to test that "permits" field is correctly updated