-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Done with adding fork-join-pool pinning test coverage
- Loading branch information
1 parent
d6955d3
commit 93636ab
Showing
10 changed files
with
156 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
concurrent/src/main/java/org/sheinbergon/needle/concurrent/PinnedForkJoinPool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.sheinbergon.needle.concurrent; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.io.Closeable; | ||
import java.util.concurrent.ForkJoinPool; | ||
|
||
public final class PinnedForkJoinPool extends ForkJoinPool implements Closeable { | ||
|
||
/** | ||
* Creates a new affinity aware {@code PinnedForkJoinPool} with the given initial | ||
* parameters. | ||
* | ||
* @param parallelism the parallelism level (amount of worker threads to be spawned) | ||
* @param factory the {@code PinnedThread} factory to use when the executor | ||
* creates new fork-join worker threads | ||
*/ | ||
public PinnedForkJoinPool( | ||
final int parallelism, | ||
final @Nonnull PinnedThreadFactory factory) { | ||
super(parallelism, factory, null, false); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
shutdown(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 21 additions & 3 deletions
24
...src/test/kotlin/org/sheinbergon/needle/concurrent/FixedAffinityPinnedThreadFactoryTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
concurrent/src/test/kotlin/org/sheinbergon/needle/concurrent/PinnedForkJoinPoolTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.sheinbergon.needle.concurrent | ||
|
||
import com.google.common.collect.Sets | ||
import org.amshove.kluent.shouldBe | ||
import org.amshove.kluent.shouldBeEqualTo | ||
import org.junit.jupiter.api.Test | ||
import org.sheinbergon.needle.* | ||
import java.util.concurrent.CountDownLatch | ||
|
||
class PinnedForkJoinPoolTest { | ||
|
||
@Test | ||
fun `Fixed affinity PinnedForkJoinPool behavior`() { | ||
val pool = PinnedForkJoinPool(availableCores, TestMaskPinnedThreadFactory) | ||
pool.use { | ||
testPinnedThreadExecutor(availableCores, pool) | ||
} | ||
} | ||
|
||
private fun testPinnedThreadExecutor(concurrency: Int, pool: PinnedForkJoinPool) = pool.use { | ||
val visited = Sets.newConcurrentHashSet<Pinned>() | ||
val latch = CountDownLatch(concurrency) | ||
pool.parallelism shouldBeEqualTo concurrency | ||
val actions = (`0` until concurrency).map { recursiveAction(latch, visited) } | ||
val tasks = actions.map { pool.submit(it) } | ||
latch.await() | ||
Thread.sleep(5L) | ||
tasks.forEach { it.isDone shouldBe true } | ||
visited.size shouldBeEqualTo concurrency | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
junit.jupiter.execution.timeout.default=5000 ms | ||
junit.jupiter.execution.timeout.default=10000 ms |