Attempt to fix AffinityExecutorTest and fix an IDE hint.

This test sometimes fails on Jenkins but I can't reproduce the failure here. There is a race in the tests though, I think this should fix it.
This commit is contained in:
Mike Hearn 2016-05-25 12:27:57 +02:00
parent e3727a1de6
commit fac38e1f3f
2 changed files with 4 additions and 2 deletions

View File

@ -53,7 +53,7 @@ interface AffinityExecutor : Executor {
*/
class ServiceAffinityExecutor(threadName: String, numThreads: Int) : AffinityExecutor,
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
init {

View File

@ -59,18 +59,20 @@ class AffinityExecutorTests {
assert(!executor.isOnThread)
val latch = CountDownLatch(1)
val latch2 = CountDownLatch(2)
val threads = Collections.synchronizedList(ArrayList<Thread>())
fun blockAThread() {
executor.execute {
assert(executor.isOnThread)
threads += Thread.currentThread()
latch2.countDown()
latch.await()
}
}
blockAThread()
blockAThread()
executor.flush()
latch2.await()
assertEquals(2, threads.size)
val numThreads = executor.fetchFrom {
assert(executor.isOnThread)