Skip to content

Commit

Permalink
Get/SetContext throw error
Browse files Browse the repository at this point in the history
  • Loading branch information
vsamoilov committed Nov 1, 2023
1 parent 822483b commit 6bf6f0f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ private class SdkJobsUtils extends JobsUtils with NoHelp {
}

private class SdkTaskValues extends TaskValuesUtils with NoHelp {
private var commandContext =
CommandContext(rootRunId = None, currentRunId = None, jobGroup = None, tags = Map.empty, extraContext = Map.empty)

/**
* Sets a task value on the current task run. This method is a no-op if used outside of the job context.
Expand Down Expand Up @@ -195,10 +193,10 @@ private class SdkTaskValues extends TaskValuesUtils with NoHelp {
override def getJson(taskKey: String, key: String): Seq[String] = Seq.empty

override def getContext(): CommandContext = {
commandContext
throw new NotImplementedError("getContext is not supported outside of DBR.")
}

override def setContext(context: CommandContext): Unit = {
commandContext = context
throw new NotImplementedError("setContext is not supported outside of DBR.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@ import org.scalatest.matchers.should.Matchers.{be, convertToAnyShouldWrapper}

class SdkTaskValuesTest extends AnyFlatSpec {
private val taskValues = new SdkTaskValues
"When outside of DBR, TaskValuesUtils.getContext" should "return default context initially" in {
taskValues.getContext should be(
CommandContext(
rootRunId = None,
currentRunId = None,
jobGroup = None,
tags = Map.empty,
extraContext = Map.empty))
}

"When outside of DBR, TaskValuesUtils.getContext" should "return context, which was set" in {
"When outside of DBR, TaskValuesUtils.getContext and TaskValuesUtils.setContext" should "throw error" in {
val context = CommandContext(
rootRunId = None,
currentRunId = None,
jobGroup = None,
tags = Map.empty,
extraContext = Map("test" -> "test"))

taskValues.setContext(context)
val setE = intercept[NotImplementedError] {
taskValues.setContext(context)
}

setE.getMessage should be("setContext is not supported outside of DBR.")

val getE = intercept[NotImplementedError] {
taskValues.getContext()
}

taskValues.getContext should be(context)
getE.getMessage should be("getContext is not supported outside of DBR.")
}

"When outside of DBR, TaskValuesUtils.get and TaskValues.set" should "throw error" in {
Expand Down

0 comments on commit 6bf6f0f

Please sign in to comment.