Skip to content

Commit

Permalink
Add IT for index state error
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Dai <[email protected]>
  • Loading branch information
dai-chen committed May 22, 2024
1 parent 941ed42 commit 053736c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public T commit(Function<FlintMetadataLogEntry, T> operation) {
if (!initialCondition.test(latest)) {
LOG.warning("Initial log entry doesn't satisfy precondition " + latest);
throw new IllegalStateException(
"Transaction failed due to initial log precondition not satisfied");
String.format("Index state [%s] doesn't satisfy precondition", latest.state()));
}

// Append optional transient log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trait FlintSparkTransactionSupport { self: Logging =>
* @param opName
* the name of the operation, used for logging
* @param forceInit
* a boolean flag indicating whether to force the initialization of the transaction
* a boolean flag indicating whether to force the initialization of the metadata log
* @param opBlock
* the operation block to execute within the transaction context, which takes an
* `OptimisticTransaction` and returns a value of type `T`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FlintSparkTransactionSupportSuite extends FlintSuite with Matchers {
private val testIndex = "test_index"
private val testOpName = "test operation"

// Creating a fake FlintSparkTransactionSupport for test
/** Creating a fake FlintSparkTransactionSupport subclass for test */
private val transactionSupport = new FlintSparkTransactionSupport with Logging {
override protected def flintClient: FlintClient = mockFlintClient
override protected def dataSourceName: String = testDataSource
Expand All @@ -41,20 +41,20 @@ class FlintSparkTransactionSupportSuite extends FlintSuite with Matchers {
test("should throw exception with nested exception message") {
the[IllegalStateException] thrownBy {
transactionSupport.withTransaction[Unit](testIndex, testOpName) { _ =>
throw new IllegalArgumentException("fake exception")
throw new IllegalArgumentException("Fake exception")
}
} should have message
"Failed to execute index operation [test operation] caused by: fake exception"
"Failed to execute index operation [test operation] caused by: Fake exception"
}

test("should throw exception with root cause exception message") {
the[IllegalStateException] thrownBy {
transactionSupport.withTransaction[Unit](testIndex, testOpName) { _ =>
val rootCause = new IllegalArgumentException("fake root cause")
val rootCause = new IllegalArgumentException("Fake root cause")
val cause = new RuntimeException("message ignored", rootCause)
throw new IllegalStateException("message ignored", cause)
}
} should have message
"Failed to execute index operation [test operation] caused by: fake root cause"
"Failed to execute index operation [test operation] caused by: Fake root cause"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ class FlintSparkTransactionITSuite extends OpenSearchTransactionSuite with Match
RequestOptions.DEFAULT) shouldBe false
}

test("should fail to vacuum index if index is not logically deleted") {
flint
.skippingIndex()
.onTable(testTable)
.addPartitions("year", "month")
.create()

the[IllegalStateException] thrownBy {
flint.vacuumIndex(testFlintIndex)
} should have message
s"Failed to execute index operation [Vacuum Flint index $testFlintIndex] caused by: Index state [active] doesn't satisfy precondition"
}

test("should not recreate index if index data still exists") {
flint
.skippingIndex()
Expand Down

0 comments on commit 053736c

Please sign in to comment.