diff --git a/gradle.properties b/gradle.properties index 79f2f95600..60c60badef 100644 --- a/gradle.properties +++ b/gradle.properties @@ -55,7 +55,7 @@ apacheCommonsExecVersion=1.2 apacheCommonsTextVersion=1.9 rgxgenVersion=1.3 antlrVersion=4.9.2 -kryoVersion=5.3.0 +kryoVersion=5.4.0 kryoSerializersVersion=0.45 asmVersion=9.2 testNgVersion=7.6.0 diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/process/EngineProcessMain.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/process/EngineProcessMain.kt index 161cb0e371..9f51fa7088 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/process/EngineProcessMain.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/process/EngineProcessMain.kt @@ -170,7 +170,8 @@ private fun EngineProcessModel.setup(kryoHelper: KryoHelper, watchdog: IdleWatch } watchdog.measureTimeForActiveCall(findMethodParamNames, "Find method parameters names") { params -> val classId = kryoHelper.readObject(params.classId) - val byMethodDescription = kryoHelper.readObject>>(params.bySignature) + val bySignatureRaw = kryoHelper.readObject>>>(params.bySignature) + val byMethodDescription = bySignatureRaw.associate { it.first to it.second } FindMethodParamNamesResult(kryoHelper.writeObject(classId.jClass.allNestedClasses.flatMap { clazz -> clazz.id.allMethods.mapNotNull { it.method.kotlinFunction } } .mapNotNull { method -> byMethodDescription[method.methodDescription()]?.let { params -> method.executableId to params } } .toMap())) diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/util/KryoHelper.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/util/KryoHelper.kt index b632f15a21..efd5045c4c 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/util/KryoHelper.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/util/KryoHelper.kt @@ -12,6 +12,8 @@ import com.esotericsoftware.kryo.kryo5.util.DefaultInstantiatorStrategy import com.jetbrains.rd.util.lifetime.Lifetime import com.jetbrains.rd.util.lifetime.throwIfNotAlive import java.io.ByteArrayOutputStream +import java.util.concurrent.locks.ReentrantLock +import kotlin.concurrent.withLock /** * Helpful class for working with the kryo. @@ -24,36 +26,17 @@ class KryoHelper constructor( private val kryoInput= Input() private val sendKryo: Kryo = TunedKryo() private val receiveKryo: Kryo = TunedKryo() + private val myLockObject = ReentrantLock() init { + sendKryo.setAutoReset(true) + receiveKryo.setAutoReset(true) lifetime.onTermination { kryoInput.close() kryoOutput.close() } } - fun register(clazz: Class, serializer: Serializer) { - sendKryo.register(clazz, serializer) - receiveKryo.register(clazz, serializer) - } - - private fun addInstantiatorOnKryo(kryo: Kryo, clazz: Class, factory: () -> T) { - val instantiator = kryo.instantiatorStrategy - kryo.instantiatorStrategy = object : InstantiatorStrategy { - override fun newInstantiatorOf(type: Class): ObjectInstantiator { - return if (type === clazz) { - ObjectInstantiator { factory() as R } - } - else - instantiator.newInstantiatorOf(type) - } - } - } - fun addInstantiator(clazz: Class, factory: () -> T) { - addInstantiatorOnKryo(sendKryo, clazz, factory) - addInstantiatorOnKryo(receiveKryo, clazz, factory) - } - fun setKryoClassLoader(classLoader: ClassLoader) { sendKryo.classLoader = classLoader receiveKryo.classLoader = classLoader @@ -64,7 +47,7 @@ class KryoHelper constructor( * * @throws WritingToKryoException wraps all exceptions */ - fun writeObject(obj: T): ByteArray { + fun writeObject(obj: T): ByteArray = myLockObject.withLock { lifetime.throwIfNotAlive() try { sendKryo.writeClassAndObject(kryoOutput, obj) @@ -84,7 +67,7 @@ class KryoHelper constructor( * * @throws ReadingFromKryoException wraps all exceptions */ - fun readObject(byteArray: ByteArray): T { + fun readObject(byteArray: ByteArray): T = myLockObject.withLock { lifetime.throwIfNotAlive() return try { kryoInput.buffer = byteArray @@ -92,6 +75,9 @@ class KryoHelper constructor( } catch (e: Exception) { throw ReadingFromKryoException(e) } + finally { + receiveKryo.reset() + } } } diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt index 45208b14fd..089c104f22 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt @@ -242,6 +242,7 @@ object CodeGenerationController { ) } } + private fun createUtilityClassIfNeeded( utilClassListener: UtilClassListener, model: GenerateTestsModel, diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt index a92c327908..49416cce9e 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt @@ -223,7 +223,7 @@ class EngineProcess private constructor(val project: Project, private val classN val bySignature = executeWithTimeoutSuspended { DumbService.getInstance(project).runReadActionInSmartMode(Computable { - methods.associate { it.methodDescription() to it.paramNames() } + methods.map { it.methodDescription() to it.paramNames() } }) } val arguments = FindMethodParamNamesArguments( diff --git a/utbot-maven/build.gradle b/utbot-maven/build.gradle index 632be5247d..8ca1b87986 100644 --- a/utbot-maven/build.gradle +++ b/utbot-maven/build.gradle @@ -119,6 +119,8 @@ task generatePluginDescriptor(type: JavaExec, dependsOn: [compileKotlin, generat } } +classes.dependsOn(generatePluginDescriptor) + publishing { publications { pluginMaven(MavenPublication) { diff --git a/utbot-sample/build.gradle b/utbot-sample/build.gradle index db9c0e392a..658c965e05 100644 --- a/utbot-sample/build.gradle +++ b/utbot-sample/build.gradle @@ -6,6 +6,7 @@ dependencies { implementation group: 'org.jetbrains', name: 'annotations', version: '16.0.2' implementation group: 'com.github.stephenc.findbugs', name: 'findbugs-annotations', version: '1.3.9-1' implementation 'org.projectlombok:lombok:1.18.20' + testImplementation 'org.mockito:mockito-core:4.2.0' annotationProcessor 'org.projectlombok:lombok:1.18.20' implementation(project(":utbot-api")) implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'