-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more logging and IT on FlintSpark API layer
Signed-off-by: Chen Dai <[email protected]>
- Loading branch information
Showing
2 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
integ-test/src/test/scala/org/opensearch/flint/spark/FlintSparkIndexJobITSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.spark | ||
|
||
import java.util.Base64 | ||
|
||
import scala.collection.JavaConverters.mapAsJavaMapConverter | ||
|
||
import org.opensearch.flint.OpenSearchTransactionSuite | ||
import org.opensearch.flint.core.metadata.log.FlintMetadataLogEntry | ||
import org.opensearch.flint.core.metadata.log.FlintMetadataLogEntry.IndexState.FAILED | ||
import org.opensearch.flint.spark.skipping.FlintSparkSkippingIndex.getSkippingIndexName | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class FlintSparkIndexJobITSuite extends OpenSearchTransactionSuite with Matchers { | ||
|
||
/** Test table and index name */ | ||
private val testTable = "spark_catalog.default.test" | ||
private val testIndex = getSkippingIndexName(testTable) | ||
|
||
override def beforeAll(): Unit = { | ||
super.beforeAll() | ||
createPartitionedTable(testTable) | ||
} | ||
|
||
override def afterEach(): Unit = { | ||
super.afterEach() | ||
flint.deleteIndex(testIndex) | ||
} | ||
|
||
test("recover should exit if index doesn't exist") { | ||
flint.recoverIndex("non_exist_index") shouldBe false | ||
} | ||
|
||
test("recover should exit if index is not auto refreshed") { | ||
flint | ||
.skippingIndex() | ||
.onTable(testTable) | ||
.addPartitions("year") | ||
.create() | ||
flint.recoverIndex(testIndex) shouldBe false | ||
} | ||
|
||
test("recover should succeed if index exists and is auto refreshed") { | ||
flint | ||
.skippingIndex() | ||
.onTable(testTable) | ||
.addPartitions("year") | ||
.options(FlintSparkIndexOptions(Map("auto_refresh" -> "true"))) | ||
.create() | ||
|
||
flint.recoverIndex(testIndex) shouldBe true | ||
spark.streams.active.exists(_.name == testIndex) | ||
} | ||
|
||
test("recover should succeed even if index is in failed state") { | ||
flint | ||
.skippingIndex() | ||
.onTable(testTable) | ||
.addPartitions("year") | ||
.options(FlintSparkIndexOptions(Map("auto_refresh" -> "true"))) | ||
.create() | ||
|
||
val latestId = Base64.getEncoder.encodeToString(testIndex.getBytes) | ||
updateLatestLogEntry( | ||
new FlintMetadataLogEntry(latestId, 1, 1, latestLogEntry(latestId).asJava), | ||
FAILED) | ||
|
||
flint.recoverIndex(testIndex) shouldBe true | ||
spark.streams.active.exists(_.name == testIndex) | ||
} | ||
} |