Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/26-checkpoi…
Browse files Browse the repository at this point in the history
…nt-creation-function

# Conflicts:
#	agent/src/main/scala/za/co/absa/atum/agent/AtumContext.scala
  • Loading branch information
lsulak committed Oct 30, 2023
2 parents c2c3405 + 7681d9d commit a31fd04
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
19 changes: 13 additions & 6 deletions agent/src/main/scala/za/co/absa/atum/agent/AtumContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import scala.collection.immutable.ListMap
class AtumContext private[agent] (
val atumPartitions: AtumPartitions,
val agent: AtumAgent,
private var measures: Set[Measure] = Set.empty
private var measures: Set[Measure] = Set.empty,
private var additionalData: Map[String, Option[String]] = Map.empty
) {

def currentMeasures: Set[Measure] = measures
Expand Down Expand Up @@ -87,8 +88,12 @@ class AtumContext private[agent] (
this
}

def addAdditionalData(key: String, value: String) = {
??? // TODO #60
def addAdditionalData(key: String, value: String): Unit = {
additionalData += (key -> Some(value))
}

def currentAdditionalData: Map[String, Option[String]] = {
this.additionalData
}

def addMeasure(newMeasure: Measure): AtumContext = {
Expand All @@ -109,9 +114,10 @@ class AtumContext private[agent] (
private[agent] def copy(
atumPartitions: AtumPartitions = this.atumPartitions,
agent: AtumAgent = this.agent,
measures: Set[Measure] = this.measures
measures: Set[Measure] = this.measures,
additionalData: Map[String, Option[String]] = this.additionalData
): AtumContext = {
new AtumContext(atumPartitions, agent, measures)
new AtumContext(atumPartitions, agent, measures, additionalData)
}
}

Expand Down Expand Up @@ -140,7 +146,8 @@ object AtumContext {
new AtumContext(
AtumPartitions.fromPartitioning(atumContextDTO.partitioning),
agent,
MeasuresBuilder.mapToMeasures(atumContextDTO.measures)
MeasuresBuilder.mapToMeasures(atumContextDTO.measures),
atumContextDTO.additionalData.additionalData
)
}

Expand Down
14 changes: 14 additions & 0 deletions agent/src/test/scala/za/co/absa/atum/agent/AtumContextTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,18 @@ class AtumContextTest extends AnyFlatSpec with Matchers {
assert(argumentSecond.getValue.measurements.tail.head.result.mainValue.valueType == ResultValueType.BigDecimal)
}

"addAdditionalData" should "add key/value pair to map for additional data" in {
val atumAgent = new AtumAgent
val atumPartitions = AtumPartitions("key" -> "val")
val atumContext = atumAgent.getOrCreateAtumContext(atumPartitions)

val additionalDataKey = "additionalKey"
val additionalDataValue = "additionalVal"
val expectedAdditionalData = Map(additionalDataKey -> Some(additionalDataValue))

atumContext.addAdditionalData(additionalDataKey, additionalDataValue)

assert(atumContext.currentAdditionalData == expectedAdditionalData)
}

}

0 comments on commit a31fd04

Please sign in to comment.