diff --git a/core/src/test/kotlin/org/utbot/jcdb/impl/performance/RestoreDBBenchmark.kt b/core/src/test/kotlin/org/utbot/jcdb/impl/performance/RestoreDBBenchmark.kt index 8a28a74e5..cd74b94b0 100644 --- a/core/src/test/kotlin/org/utbot/jcdb/impl/performance/RestoreDBBenchmark.kt +++ b/core/src/test/kotlin/org/utbot/jcdb/impl/performance/RestoreDBBenchmark.kt @@ -6,6 +6,7 @@ import org.utbot.jcdb.api.JCDB import org.utbot.jcdb.impl.LibrariesMixin import org.utbot.jcdb.jcdb import java.nio.file.Files +import java.util.* import java.util.concurrent.TimeUnit @State(Scope.Benchmark) @@ -17,7 +18,7 @@ import java.util.concurrent.TimeUnit class RestoreDBBenchmark : LibrariesMixin { companion object { - private val jdbcLocation = Files.createTempDirectory("jdbc").toFile().absolutePath + private val jdbcLocation = Files.createTempDirectory("jdbc-${UUID.randomUUID()}").toFile().absolutePath } var db: JCDB? = null diff --git a/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/RemoteRdServer.kt b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/RemoteRdServer.kt index 23f1a971e..0f61dfb88 100644 --- a/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/RemoteRdServer.kt +++ b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/RemoteRdServer.kt @@ -14,7 +14,7 @@ import java.util.concurrent.ConcurrentHashMap import kotlin.concurrent.thread -class RemoteRdServer(private val port: Int, val db: JCDBImpl) : Hook { +class RemoteRdServer(private val port: Int, private val db: JCDBImpl) : Hook { companion object : KLogging() @@ -42,7 +42,8 @@ class RemoteRdServer(private val port: Int, val db: JCDBImpl) : Hook { CloseClasspathResource(classpaths), GetClassResource(classpaths), GetSubClassesResource(classpaths), - StopServerResource(this) + StopServerResource(this), + LoadLocationsResource() ) } diff --git a/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/Resources.kt b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/Resources.kt index beb2c2c27..a8b5dc1a4 100644 --- a/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/Resources.kt +++ b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/Resources.kt @@ -76,6 +76,15 @@ class GetClasspathResource(private val classpaths: ConcurrentHashMap(10, "load-locations") { + + override val serializers = listOf(GetClasspathReq) + + override suspend fun JCDB.handler(req: GetClasspathReq) { + load(req.locations.map { File(it) }.filter { it.exists() }) + } +} + class CloseClasspathResource(private val classpaths: ConcurrentHashMap = ConcurrentHashMap()) : CallResource(2, "close-classpath") { diff --git a/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/client/RemoteJCDB.kt b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/client/RemoteJCDB.kt index 3aa1070c3..134c1a856 100644 --- a/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/client/RemoteJCDB.kt +++ b/remote-rd/src/main/kotlin/org/utbot/jcdb/remote/rd/client/RemoteJCDB.kt @@ -11,6 +11,7 @@ import org.utbot.jcdb.api.ClasspathSet import org.utbot.jcdb.api.JCDB import org.utbot.jcdb.remote.rd.* import java.io.File +import java.nio.file.Paths class RemoteJCDB(port: Int) : JCDB { @@ -34,6 +35,7 @@ class RemoteJCDB(port: Int) : JCDB { private val getId = GetGlobalIdResource().clientCall(clientProtocol) private val getName = GetGlobalNameResource().clientCall(clientProtocol) + private val loadLocations = LoadLocationsResource().clientCall(clientProtocol) init { scheduler.flush() @@ -52,16 +54,20 @@ class RemoteJCDB(port: Int) : JCDB { ) } - override suspend fun load(dirOrJar: File): JCDB { - TODO("Not yet implemented") + override suspend fun load(dirOrJar: File): JCDB = apply { + loadLocations.startSuspending(GetClasspathReq(listOf(dirOrJar.absolutePath))) } - override suspend fun load(dirOrJars: List): JCDB { - TODO("Not yet implemented") + override suspend fun load(dirOrJars: List): JCDB = apply { + loadLocations.startSuspending(GetClasspathReq(dirOrJars.map { it.absolutePath })) } - override suspend fun loadLocations(locations: List): JCDB { - TODO("Not yet implemented") + override suspend fun loadLocations(locations: List): JCDB = apply { + loadLocations.startSuspending( + GetClasspathReq( + locations.map { Paths.get(it.locationURL.toURI()).toFile().absolutePath } + ) + ) } override suspend fun refresh() {