Skip to content

Commit

Permalink
feat #143 JdbcDriver.listExecutedScripts() modification + test
Browse files Browse the repository at this point in the history
  • Loading branch information
asolovieff committed Oct 19, 2021
1 parent f3346e9 commit 530447e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package datamaintain.db.driver.jdbc

import datamaintain.core.db.driver.DatamaintainDriver
import datamaintain.core.script.ExecutedScript
import datamaintain.core.script.ExecutionStatus
import datamaintain.core.script.ScriptAction
import datamaintain.core.script.ScriptWithContent
import datamaintain.core.script.*
import datamaintain.core.step.executor.Execution
import java.sql.Connection
import java.sql.DriverManager
Expand All @@ -28,14 +25,14 @@ class JdbcDriver(jdbcUri: String) : DatamaintainDriver(jdbcUri) {
}
}

override fun listExecutedScripts(): Sequence<ExecutedScript> {
override fun listExecutedScripts(): Sequence<LightExecutedScript> {
createExecutedScriptsTableIfNotExists()

val statement = connection.createStatement()
val executionOutput: ResultSet = statement.executeQuery("SELECT * from $EXECUTED_SCRIPTS_TABLE")
val executedScript = mutableListOf<ExecutedScript>()
val executionOutput: ResultSet = statement.executeQuery("SELECT name, checksum, identifier from $EXECUTED_SCRIPTS_TABLE")
val executedScript = mutableListOf<LightExecutedScript>()
while (executionOutput.next()) {
executedScript.add(executionOutput.toExecutedScript())
executedScript.add(executionOutput.toLightExecutedScript())
}
return executedScript.asSequence()
}
Expand Down Expand Up @@ -94,13 +91,9 @@ class JdbcDriver(jdbcUri: String) : DatamaintainDriver(jdbcUri) {
return executedScript
}

fun ResultSet.toExecutedScript() = ExecutedScript(
name = this.getString("name"),
checksum = this.getString("checksum"),
executionDurationInMillis = this.getLong("executionDurationInMillis"),
executionOutput = this.getString("executionOutput"),
executionStatus = ExecutionStatus.valueOf(this.getString("executionStatus")),
identifier = this.getString("identifier"),
action = ScriptAction.valueOf(this.getString("action"))
private fun ResultSet.toLightExecutedScript() = LightExecutedScript(
name = this.getString("name"),
checksum = this.getString("checksum"),
identifier = this.getString("identifier")
)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package datamaintain.db.driver.jdbc

import datamaintain.core.script.ExecutedScript
import datamaintain.core.script.ExecutionStatus
import datamaintain.core.script.FileScript
import datamaintain.core.script.ScriptAction
import datamaintain.core.script.*
import org.h2.tools.Server
import org.junit.jupiter.api.*
import strikt.api.expectThat
Expand Down Expand Up @@ -45,7 +42,7 @@ internal class JdbcDriverTest {
val executedScripts = jdbcDatamaintainDriver.listExecutedScripts()

// Then
expectThat(executedScripts.toList()).containsExactlyInAnyOrder(script1, script2)
expectThat(executedScripts.toList()).containsExactlyInAnyOrder(lightScript1, lightScript2)
}

@Test
Expand All @@ -61,13 +58,19 @@ internal class JdbcDriverTest {
executionDurationInMillis = 0
)

val lightScript3 = LightExecutedScript(
script3.name,
script3.checksum,
script3.identifier
)

// When
jdbcDatamaintainDriver.markAsExecuted(script3)

// Then

expectThat(jdbcDatamaintainDriver.listExecutedScripts().toList())
.containsExactlyInAnyOrder(script1, script2, script3)
.containsExactlyInAnyOrder(lightScript1, lightScript2, lightScript3)
}

@Nested
Expand Down Expand Up @@ -138,14 +141,16 @@ internal class JdbcDriverTest {
executionStatus = ExecutionStatus.OK,
action = ScriptAction.OVERRIDE_EXECUTED)

val lightScript3 = LightExecutedScript(script3.name, script3.checksum, script3.identifier)

// When
jdbcDatamaintainDriver.overrideScript(script3)

// Then
expectThat(jdbcDatamaintainDriver.listExecutedScripts().toList())
.containsExactlyInAnyOrder(
script3,
script2
lightScript3,
lightScript2
)
}

Expand All @@ -167,6 +172,18 @@ internal class JdbcDriverTest {
0
)

private val lightScript1 = LightExecutedScript(
script1.name,
script1.checksum,
script1.identifier
)

private val lightScript2 = LightExecutedScript(
script2.name,
script2.checksum,
script2.identifier
)

private fun insertDataInDb() {
connection.prepareStatement("""
INSERT INTO ${JdbcDriver.EXECUTED_SCRIPTS_TABLE} (
Expand Down

0 comments on commit 530447e

Please sign in to comment.