-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TS-38628 Registry and reworked builder pattern
- Loading branch information
1 parent
68181f5
commit 12d4308
Showing
12 changed files
with
227 additions
and
376 deletions.
There are no files selected for viewing
45 changes: 0 additions & 45 deletions
45
impacted-test-engine/src/main/java/com/teamscale/test_impacted/engine/TestDataWriter.java
This file was deleted.
Oops, something went wrong.
65 changes: 0 additions & 65 deletions
65
...cted-test-engine/src/main/java/com/teamscale/test_impacted/engine/TestEngineRegistry.java
This file was deleted.
Oops, something went wrong.
91 changes: 0 additions & 91 deletions
91
...ngine/src/main/java/com/teamscale/test_impacted/engine/options/TestEngineOptionUtils.java
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...t-engine/src/main/kotlin/com/teamscale/test_impacted/engine/InternalImpactedTestEngine.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
39 changes: 39 additions & 0 deletions
39
impacted-test-engine/src/main/kotlin/com/teamscale/test_impacted/engine/TestDataWriter.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,39 @@ | ||
package com.teamscale.test_impacted.engine | ||
|
||
import com.teamscale.client.TestDetails | ||
import com.teamscale.report.ReportUtils.writeTestExecutionReport | ||
import com.teamscale.report.ReportUtils.writeTestListReport | ||
import com.teamscale.report.testwise.model.TestExecution | ||
import com.teamscale.test_impacted.commons.LoggerUtils.createLogger | ||
import com.teamscale.test_impacted.commons.LoggerUtils.getLogger | ||
import java.io.File | ||
import java.io.IOException | ||
import java.util.logging.Level | ||
import java.util.logging.Logger | ||
|
||
/** Class for writing test data to a report directory. */ | ||
open class TestDataWriter(private val reportDirectory: File) { | ||
/** Writes the given test executions to a report file. */ | ||
fun dumpTestExecutions(testExecutions: List<TestExecution>) { | ||
val file = File(reportDirectory, "test-execution.json") | ||
try { | ||
writeTestExecutionReport(file, testExecutions) | ||
} catch (e: IOException) { | ||
LOGGER.log(Level.SEVERE, e) { "Error while writing report to file: $file" } | ||
} | ||
} | ||
|
||
/** Writes the given test details to a report file. */ | ||
fun dumpTestDetails(testDetails: List<TestDetails>) { | ||
val file = File(reportDirectory, "test-list.json") | ||
try { | ||
writeTestListReport(file, ArrayList(testDetails)) | ||
} catch (e: IOException) { | ||
LOGGER.log(Level.SEVERE, e) { "Error while writing report to file: $file" } | ||
} | ||
} | ||
|
||
companion object { | ||
private val LOGGER = createLogger() | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...cted-test-engine/src/main/kotlin/com/teamscale/test_impacted/engine/TestEngineRegistry.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,45 @@ | ||
package com.teamscale.test_impacted.engine | ||
|
||
import org.junit.platform.commons.util.ClassLoaderUtils | ||
import org.junit.platform.engine.TestEngine | ||
import java.util.* | ||
import java.util.function.Function | ||
import java.util.stream.Collectors | ||
|
||
/** The test engine registry containing all */ | ||
open class TestEngineRegistry( | ||
includedTestEngineIds: Set<String>, | ||
excludedTestEngineIds: Set<String> | ||
) : Iterable<TestEngine> { | ||
private val testEnginesById: Map<String, TestEngine> | ||
|
||
init { | ||
var otherTestEngines = loadOtherTestEngines(excludedTestEngineIds) | ||
|
||
// If there are no test engines set we don't need to filter but simply use all other test engines. | ||
if (includedTestEngineIds.isNotEmpty()) { | ||
otherTestEngines = otherTestEngines.filter { testEngine -> | ||
includedTestEngineIds.contains(testEngine.id) | ||
} | ||
} | ||
|
||
testEnginesById = otherTestEngines.associateBy { it.id } | ||
} | ||
|
||
/** | ||
* Uses the [ServiceLoader] to discover all [TestEngine]s but the [ImpactedTestEngine] and the | ||
* excluded test engines. | ||
*/ | ||
private fun loadOtherTestEngines(excludedTestEngineIds: Set<String>) = | ||
ServiceLoader.load( | ||
TestEngine::class.java, ClassLoaderUtils.getDefaultClassLoader() | ||
).filter { | ||
ImpactedTestEngine.ENGINE_ID != it.id && !excludedTestEngineIds.contains(it.id) | ||
} | ||
|
||
/** Returns the [TestEngine] for the engine id or null if none is present. */ | ||
fun getTestEngine(engineId: String) = testEnginesById[engineId] | ||
|
||
override fun iterator() = | ||
testEnginesById.values.sortedBy { it.id }.iterator() | ||
} |
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
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
Oops, something went wrong.