mirror of
https://github.com/corda/corda.git
synced 2025-05-09 12:02:56 +00:00
Merged in fix-affinityexecutor-test (pull request #117)
Attempt to fix AffinityExecutorTest and fix an IDE hint.
This commit is contained in:
commit
1e0844ccb5
@ -53,7 +53,7 @@ interface AffinityExecutor : Executor {
|
|||||||
*/
|
*/
|
||||||
class ServiceAffinityExecutor(threadName: String, numThreads: Int) : AffinityExecutor,
|
class ServiceAffinityExecutor(threadName: String, numThreads: Int) : AffinityExecutor,
|
||||||
ThreadPoolExecutor(numThreads, numThreads, 0L, TimeUnit.MILLISECONDS, LinkedBlockingQueue<Runnable>()) {
|
ThreadPoolExecutor(numThreads, numThreads, 0L, TimeUnit.MILLISECONDS, LinkedBlockingQueue<Runnable>()) {
|
||||||
protected val threads = Collections.synchronizedSet(HashSet<Thread>())
|
private val threads = Collections.synchronizedSet(HashSet<Thread>())
|
||||||
private val uncaughtExceptionHandler = Thread.currentThread().uncaughtExceptionHandler
|
private val uncaughtExceptionHandler = Thread.currentThread().uncaughtExceptionHandler
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -59,18 +59,20 @@ class AffinityExecutorTests {
|
|||||||
assert(!executor.isOnThread)
|
assert(!executor.isOnThread)
|
||||||
|
|
||||||
val latch = CountDownLatch(1)
|
val latch = CountDownLatch(1)
|
||||||
|
val latch2 = CountDownLatch(2)
|
||||||
val threads = Collections.synchronizedList(ArrayList<Thread>())
|
val threads = Collections.synchronizedList(ArrayList<Thread>())
|
||||||
|
|
||||||
fun blockAThread() {
|
fun blockAThread() {
|
||||||
executor.execute {
|
executor.execute {
|
||||||
assert(executor.isOnThread)
|
assert(executor.isOnThread)
|
||||||
threads += Thread.currentThread()
|
threads += Thread.currentThread()
|
||||||
|
latch2.countDown()
|
||||||
latch.await()
|
latch.await()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
blockAThread()
|
blockAThread()
|
||||||
blockAThread()
|
blockAThread()
|
||||||
executor.flush()
|
latch2.await()
|
||||||
assertEquals(2, threads.size)
|
assertEquals(2, threads.size)
|
||||||
val numThreads = executor.fetchFrom {
|
val numThreads = executor.fetchFrom {
|
||||||
assert(executor.isOnThread)
|
assert(executor.isOnThread)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user