Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions admin-app/src/main/resources/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1936,13 +1936,19 @@ components:
description: Unique identifier of the test session during which the coverage was recorded. Reference to the test session id (saved via /api/data-ingest/test-session). When absent, indicates global coverage data collected outside of any specific test session context.
probes:
type: array
description: Array of boolean values representing the execution state of each bytecode probe (instruction) in the method. Index position corresponds to probe position in bytecode. True indicates the probe was executed; false indicates it was not executed during the test.
deprecated: true
description: |
Array of boolean values representing the execution state of each bytecode probe (instruction) in the method.
Index position corresponds to probe position in bytecode. True indicates the probe was executed; false indicates it was not executed during the test.
Deprecated: use "stringProbes" instead.
items:
type: boolean
stringProbes:
type: string
description: Representing the execution state of each bytecode probe (instruction) in the method as a string of '1's and '0's, where '1' represents true (executed) and '0' represents false (not executed).
required:
- signature
- bodyChecksum
- probes
MethodsPayload:
type: object
description: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.epam.drill.admin.metrics

import com.epam.drill.admin.writer.rawdata.config.toBitString
import com.epam.drill.admin.writer.rawdata.route.payload.*
import com.jayway.jsonpath.JsonPath
import io.ktor.client.*
Expand Down Expand Up @@ -74,18 +75,19 @@ suspend fun HttpClient.launchTest(
instanceId = instance.instanceId,
buildVersion = instance.buildVersion,
commitSha = instance.commitSha,
coverage = coverage.filter { c -> c.second.any { it != 0 } }.map {
coverage = coverage.filter { c -> c.second.any { it != 0 } }.map { (method, probes) ->
SingleMethodCoveragePayload(
signature = listOf(
it.first.classname,
it.first.name,
it.first.params,
it.first.returnType
method.classname,
method.name,
method.params,
method.returnType
).joinToString(":"),
bodyChecksum = it.first.bodyChecksum,
bodyChecksum = method.bodyChecksum,
testId = testLaunchId,
testSessionId = session.id,
probes = it.second.map { probe -> probe != 0 }.toBooleanArray()
probes = null,
stringProbes = probes.joinToString(separator = "") { if (it != 0) "1" else "0" }
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,27 @@ package com.epam.drill.admin.writer.rawdata.config
import org.jetbrains.exposed.sql.IColumnType
import org.postgresql.util.PGobject

class ProbesColumnType(override var nullable: Boolean = false) : IColumnType<BooleanArray> {
typealias BitString = String

class ProbesColumnType(override var nullable: Boolean = false) : IColumnType<BitString> {
override fun sqlType(): String = "VARBIT"

override fun valueFromDB(value: Any): BooleanArray =
override fun valueFromDB(value: Any): BitString =
when (value) {
is String -> stringToBooleanArray(value)
is PGobject -> stringToBooleanArray(value.value ?: "")
is String -> value
is PGobject -> value.value ?: ""
else -> throw IllegalStateException("Unsupported value type: ${value::class}")
}

override fun notNullValueToDB(value: BooleanArray): Any {
override fun notNullValueToDB(value: BitString): Any {
return PGobject().apply {
this.type = "VARBIT"
this.value = booleanArrayToString(value)
this.value = value
}
}

}

internal fun stringToBooleanArray(str: String): BooleanArray {
return BooleanArray(str.length) { index ->
str[index] == '1'
}
}

internal fun booleanArrayToString(arr: BooleanArray): String {
return arr.joinToString("") { if (it) "1" else "0" }
fun BooleanArray.toBitString(): BitString {
return joinToString(separator = "") { if (it) "1" else "0" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.epam.drill.admin.writer.rawdata.entity

import com.epam.drill.admin.writer.rawdata.config.BitString

class Coverage(
val groupId: String,
val appId: String,
Expand All @@ -23,5 +25,5 @@ class Coverage(
val methodId: String,
val testId: String?,
val testSessionId: String?,
val probes: BooleanArray
val probes: BitString
)
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CoverageRepositoryImpl : CoverageRepository {
this[MethodCoverageTable.testId] = it.testId
this[MethodCoverageTable.testSessionId] = it.testSessionId
this[MethodCoverageTable.probes] = it.probes
this[MethodCoverageTable.probesCount] = it.probes.size
this[MethodCoverageTable.probesCount] = it.probes.length
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@
val bodyChecksum: String,
val testId: String?,
val testSessionId: String?,
val probes: BooleanArray,
@Deprecated ("Use stringProbes instead")
val probes: BooleanArray?,

Check warning on line 37 in admin-writer/src/main/kotlin/com/epam/drill/admin/writer/rawdata/route/payload/CoveragePayload.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not forget to remove this deprecated code someday.

See more on https://sonarcloud.io/project/issues?id=Drill4J_admin&issues=AZ3TTIVpAC-0TuXD2CcL&open=AZ3TTIVpAC-0TuXD2CcL&pullRequest=472
val stringProbes: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.epam.drill.admin.common.principal.User
import com.epam.drill.admin.common.service.generateBuildId
import com.epam.drill.admin.writer.rawdata.config.RawDataWriterDatabaseConfig.transaction
import com.epam.drill.admin.writer.rawdata.config.toBitString
import com.epam.drill.admin.writer.rawdata.entity.*
import com.epam.drill.admin.writer.rawdata.repository.*
import com.epam.drill.admin.writer.rawdata.route.payload.*
Expand Down Expand Up @@ -172,7 +173,10 @@
coveragePayload.commitSha,
coveragePayload.buildVersion
)
coveragePayload.coverage.filter { probes -> probes.probes.any { it } }.map { coverage ->
val hasProbes: (SingleMethodCoveragePayload) -> Boolean = { coverage ->
coverage.probes?.any { it } ?: coverage.stringProbes?.contains('1') ?: false

Check warning on line 177 in admin-writer/src/main/kotlin/com/epam/drill/admin/writer/rawdata/service/impl/RawDataServiceImpl.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Deprecated code should not be used.

See more on https://sonarcloud.io/project/issues?id=Drill4J_admin&issues=AZ3TTITUAC-0TuXD2CcK&open=AZ3TTITUAC-0TuXD2CcK&pullRequest=472
}
coveragePayload.coverage.filter(hasProbes).map { coverage ->
Coverage(
groupId = coveragePayload.groupId,
appId = coveragePayload.appId,
Expand All @@ -181,11 +185,11 @@
methodId = listOf(
coverage.signature,
coverage.bodyChecksum,
coverage.probes.size
coverage.probes?.size ?: coverage.stringProbes?.length ?: 0
).joinToString(":").md5(),
testId = coverage.testId,
testSessionId = coverage.testSessionId,
probes = coverage.probes
probes = coverage.probes?.toBitString() ?: coverage.stringProbes ?: ""

Check warning on line 192 in admin-writer/src/main/kotlin/com/epam/drill/admin/writer/rawdata/service/impl/RawDataServiceImpl.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this useless elvis operation ?:, it always succeeds.

See more on https://sonarcloud.io/project/issues?id=Drill4J_admin&issues=AZ3TIWhj4fpoaG-VF449&open=AZ3TIWhj4fpoaG-VF449&pullRequest=472
)
}
.chunked(EXEC_DATA_BATCH_SIZE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.epam.drill.admin.writer.rawdata
import com.epam.drill.admin.writer.rawdata.config.ProbesColumnType
import com.epam.drill.admin.test.*
import com.epam.drill.admin.writer.rawdata.config.RawDataWriterDatabaseConfig
import com.epam.drill.admin.writer.rawdata.config.toBitString
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.SchemaUtils.create
import org.jetbrains.exposed.sql.insert
Expand All @@ -31,24 +32,24 @@ class ProbesColumnTypeTest : DatabaseTests({ RawDataWriterDatabaseConfig.init(it
@BeforeEach
fun initSchema() {
withRollback {
create(BoolArrays)
create(CoverageTable)
}
}

@Test
fun `test storing and retrieving Probes`() = withRollback {
val originalProbes = booleanArrayOf(true, false, true, false, false, true)
val originalProbes = booleanArrayOf(true, false, true, false, false, true).toBitString()

BoolArrays.insert {
it[boolArrays] = originalProbes
CoverageTable.insert {
it[probes] = originalProbes
}
val retrievedProbes = BoolArrays.selectAll().single()[BoolArrays.boolArrays]
val retrievedProbes = CoverageTable.selectAll().single()[CoverageTable.probes]

assertTrue(originalProbes.contentEquals(retrievedProbes))
}

}

object BoolArrays : IntIdTable() {
val boolArrays = registerColumn<BooleanArray>("bool_arrays", ProbesColumnType())
object CoverageTable : IntIdTable() {
val probes = registerColumn("probes", ProbesColumnType())
}
Loading