Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class JDBCMetadataStore(conf: KyuubiConf) extends MetadataStore with Logging {
targetState: String): Boolean = {
val query = s"UPDATE $METADATA_TABLE SET state = ? WHERE identifier = ? AND state = ?"
JdbcUtils.withConnection { connection =>
withUpdateCount(connection, query, fromState, identifier, targetState) { updateCount =>
withUpdateCount(connection, query, targetState, identifier, fromState) { updateCount =>
updateCount == 1
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,32 @@ class JDBCMetadataStoreSuite extends KyuubiFunSuite {
}
}

test("transformMetadataState should transition state correctly") {
val batchId = UUID.randomUUID().toString
val batchMetadata = Metadata(
identifier = batchId,
sessionType = SessionType.BATCH,
realUser = "kyuubi",
username = "kyuubi",
ipAddress = "127.0.0.1",
state = "INITIALIZED",
resource = "intern",
className = "org.apache.kyuubi.SparkWC",
requestName = "test_transform",
createTime = System.currentTimeMillis(),
engineType = "SPARK")

jdbcMetadataStore.insertMetadata(batchMetadata)

val result = jdbcMetadataStore.transformMetadataState(batchId, "INITIALIZED", "CANCELED")
assert(result, "should successfully transition from INITIALIZED to CANCELED")

val metadata = jdbcMetadataStore.getMetadata(batchId)
assert(metadata.state == "CANCELED", s"state should be CANCELED but was ${metadata.state}")

jdbcMetadataStore.cleanupMetadataByIdentifier(batchId)
}

test("throw exception if update count is 0") {
val metadata = Metadata(identifier = UUID.randomUUID().toString, state = "RUNNING")
intercept[KyuubiException] {
Expand Down
Loading