-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for cached unificator thread safety
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
unify/src/jvmTest/kotlin/it/unibo/tuprolog/unify/TestThreadSafety.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 it.unibo.tuprolog.unify | ||
|
||
import it.unibo.tuprolog.core.Substitution | ||
import it.unibo.tuprolog.unify.testutils.UnificatorUtils.successfulUnifications | ||
import java.util.* | ||
import java.util.concurrent.Executors | ||
import java.util.concurrent.Future | ||
import java.util.concurrent.TimeUnit | ||
import kotlin.test.Test | ||
import kotlin.test.assertTrue | ||
|
||
class TestThreadSafety { | ||
@Test | ||
fun testCachedUnificatorThreadSafety() { | ||
val executors = Executors.newFixedThreadPool(8) | ||
val results: MutableList<Future<Substitution>> = Collections.synchronizedList(LinkedList()) | ||
val unificator = Unificator.cached(Unificator.strict()) | ||
for (i in 1 .. 100) { | ||
for (equation in successfulUnifications.keys) { | ||
results.add(executors.submit<Substitution> { | ||
unificator.mgu(equation.lhs, equation.rhs) | ||
}) | ||
} | ||
} | ||
executors.shutdown() | ||
executors.awaitTermination(1, TimeUnit.MINUTES) | ||
for (res in results) { | ||
assertTrue { res.get() is Substitution.Unifier } | ||
} | ||
} | ||
} |