|
| 1 | +package com.teamscale.test_impacted.engine.executor |
| 2 | + |
| 3 | +import com.teamscale.report.testwise.model.TestExecution |
| 4 | +import com.teamscale.test_impacted.commons.LoggerUtils.createLogger |
| 5 | +import com.teamscale.tia.client.ITestwiseCoverageAgentApi |
| 6 | +import com.teamscale.tia.client.UrlUtils.encodeUrl |
| 7 | +import java.io.IOException |
| 8 | +import java.util.logging.Level |
| 9 | + |
| 10 | +/** Communicates test start and end to the agent and the end of the overall test execution. */ |
| 11 | +open class TeamscaleAgentNotifier( |
| 12 | + /** A list of API services to signal test start and end to the agent. */ |
| 13 | + private val testwiseCoverageAgentApis: List<ITestwiseCoverageAgentApi>, |
| 14 | + /** |
| 15 | + * Whether only a part of the tests is being executed (`true`) or whether all tests are executed |
| 16 | + * (`false`). |
| 17 | + */ |
| 18 | + private val partial: Boolean |
| 19 | +) { |
| 20 | + private val logger = createLogger() |
| 21 | + |
| 22 | + /** Reports the start of a test to the Teamscale JaCoCo agent. */ |
| 23 | + open fun startTest(testUniformPath: String) { |
| 24 | + try { |
| 25 | + testwiseCoverageAgentApis.forEach { apiService -> |
| 26 | + apiService.testStarted(testUniformPath.encodeUrl()).execute() |
| 27 | + } |
| 28 | + } catch (e: IOException) { |
| 29 | + logger.log( |
| 30 | + Level.SEVERE, e |
| 31 | + ) { "Error while calling service api." } |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + /** Reports the end of a test to the Teamscale JaCoCo agent. */ |
| 36 | + open fun endTest(testUniformPath: String, testExecution: TestExecution?) { |
| 37 | + try { |
| 38 | + testwiseCoverageAgentApis.forEach { apiService -> |
| 39 | + val url = testUniformPath.encodeUrl() |
| 40 | + if (testExecution == null) { |
| 41 | + apiService.testFinished(url).execute() |
| 42 | + } else { |
| 43 | + apiService.testFinished(url, testExecution).execute() |
| 44 | + } |
| 45 | + } |
| 46 | + } catch (e: IOException) { |
| 47 | + logger.log( |
| 48 | + Level.SEVERE, e |
| 49 | + ) { "Error contacting test wise coverage agent." } |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + /** Reports the end of the test run to the Teamscale JaCoCo agent. */ |
| 54 | + open fun testRunEnded() { |
| 55 | + try { |
| 56 | + testwiseCoverageAgentApis.forEach { apiService -> |
| 57 | + apiService.testRunFinished(partial).execute() |
| 58 | + } |
| 59 | + } catch (e: IOException) { |
| 60 | + logger.log( |
| 61 | + Level.SEVERE, e |
| 62 | + ) { "Error contacting test wise coverage agent." } |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments