[Native][tests] Use ThreadSafeCache instead of ConcurrentHashMap
This commit is contained in:
@@ -17,11 +17,10 @@ import org.jetbrains.kotlin.konan.blackboxtest.TestModule.Companion.allFriends
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.util.*
|
||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
|
||||
import java.io.*
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
internal class TestCompilationFactory(private val environment: TestEnvironment) {
|
||||
private val cachedCompilations: MutableMap<TestCompilationCacheKey, TestCompilation> = ConcurrentHashMap()
|
||||
private val cachedCompilations = ThreadSafeCache<TestCompilationCacheKey, TestCompilation>()
|
||||
|
||||
private sealed interface TestCompilationCacheKey {
|
||||
data class Klib(val sourceModules: Set<TestModule>, val freeCompilerArgs: TestCompilerArgs) : TestCompilationCacheKey
|
||||
|
||||
+2
-2
@@ -8,19 +8,19 @@ package org.jetbrains.kotlin.konan.blackboxtest
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.TestCompilationResult.Companion.assertSuccess
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.group.TestCaseGroupProvider
|
||||
import org.jetbrains.kotlin.konan.blackboxtest.util.ThreadSafeCache
|
||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertTrue
|
||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail
|
||||
import org.junit.jupiter.api.Assumptions.assumeTrue
|
||||
import org.junit.jupiter.api.extension.ExtensionContext
|
||||
import java.io.File
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
internal class TestRunProvider(
|
||||
private val environment: TestEnvironment,
|
||||
private val testCaseGroupProvider: TestCaseGroupProvider
|
||||
) : ExtensionContext.Store.CloseableResource {
|
||||
private val compilationFactory = TestCompilationFactory(environment)
|
||||
private val cachedCompilations: MutableMap<TestCompilationCacheKey, TestCompilation> = ConcurrentHashMap()
|
||||
private val cachedCompilations = ThreadSafeCache<TestCompilationCacheKey, TestCompilation>()
|
||||
|
||||
fun getSingleTestRunForTestDataFile(testDataFile: File): TestRun {
|
||||
environment.assertNotDisposed()
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ internal class ThreadSafeFactory<K : Any, V>(private val function: (K) -> V) {
|
||||
internal class ThreadSafeCache<K : Any, V> {
|
||||
private val map = ConcurrentHashMap<K, Any>()
|
||||
|
||||
operator fun get(key: K): V = unwrap(map[key]) as V
|
||||
operator fun get(key: K): V? = unwrap(map[key]) as V?
|
||||
fun computeIfAbsent(key: K, function: (K) -> V): V = unwrap(map.computeIfAbsent(key) { wrap(function(key)) }) as V
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user