Skip to content

Commit 0f6cbf0

Browse files
committed
TS-38628 AvailableTests migration
1 parent c8ec448 commit 0f6cbf0

File tree

3 files changed

+51
-62
lines changed

3 files changed

+51
-62
lines changed

impacted-test-engine/src/main/java/com/teamscale/test_impacted/engine/executor/AvailableTests.java

Lines changed: 0 additions & 61 deletions
This file was deleted.

impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/commons/LoggerUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object LoggerUtils {
1414
private const val JAVA_UTIL_LOGGING_CONFIG_FILE_SYSTEM_PROPERTY = "java.util.logging.config.file"
1515

1616
init {
17-
// Needs to be at the very top so it also takes affect when setting the log level for Console handlers
17+
// Needs to be at the very top, so it also takes effect when setting the log level for Console handlers
1818
useDefaultJULConfigFile()
1919

2020
MAIN_LOGGER.useParentHandlers = false
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.teamscale.test_impacted.engine.executor
2+
3+
import com.teamscale.client.ClusteredTestDetails
4+
import com.teamscale.client.PrioritizableTest
5+
import com.teamscale.client.StringUtils.levenshteinDistance
6+
import com.teamscale.test_impacted.commons.LoggerUtils.getLogger
7+
import org.junit.platform.engine.UniqueId
8+
import java.util.*
9+
import java.util.logging.Logger
10+
11+
/**
12+
* Holds a list of test details that can currently be executed. Provides the ability to translate uniform paths returned
13+
* by the Teamscale server to unique IDs used in JUnit Platform.
14+
*/
15+
class AvailableTests {
16+
/**
17+
* A mapping from the tests uniform path (Teamscale internal representation) to unique id (JUnit internal
18+
* representation).
19+
*/
20+
private val uniformPathToUniqueIdMapping = mutableMapOf<String, UniqueId>()
21+
22+
/** List of all test details. */
23+
val testList = mutableListOf<ClusteredTestDetails>()
24+
25+
/** Adds a new [com.teamscale.client.TestDetails] object and the according uniqueId. */
26+
fun add(uniqueId: UniqueId, details: ClusteredTestDetails) {
27+
uniformPathToUniqueIdMapping[details.uniformPath] = uniqueId
28+
testList.add(details)
29+
}
30+
31+
/**
32+
* Converts the [PrioritizableTest] to the [UniqueId] returned by the [org.junit.platform.engine.TestEngine].
33+
*/
34+
fun convertToUniqueId(test: PrioritizableTest): Optional<UniqueId> {
35+
val clusterUniqueId = uniformPathToUniqueIdMapping[test.testName]
36+
if (clusterUniqueId == null) {
37+
LOGGER.severe { "Retrieved invalid test '${test.testName}' from Teamscale server!" }
38+
LOGGER.severe { "The following seem related:" }
39+
uniformPathToUniqueIdMapping.keys
40+
.sortedBy { test.testName.levenshteinDistance(it) }
41+
.take(5)
42+
.forEach { LOGGER.severe { " - $it" } }
43+
}
44+
return Optional.ofNullable(clusterUniqueId)
45+
}
46+
47+
companion object {
48+
private val LOGGER: Logger = getLogger(AvailableTests::class.java)
49+
}
50+
}

0 commit comments

Comments
 (0)