-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add auto upgrade mapping logic (#699)
* add auto upgrade mapping logic Signed-off-by: zhichao-aws <[email protected]> * put load mapping to initialize step Signed-off-by: zhichao-aws <[email protected]> * add schema_version field Signed-off-by: zhichao-aws <[email protected]> * add integ test Signed-off-by: zhichao-aws <[email protected]> * add integ test for lacking _meta field Signed-off-by: zhichao-aws <[email protected]> --------- Signed-off-by: zhichao-aws <[email protected]>
- Loading branch information
1 parent
216dfcb
commit 5670c35
Showing
5 changed files
with
245 additions
and
2 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
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
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
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
71 changes: 71 additions & 0 deletions
71
...ations/src/test/kotlin/org/opensearch/notifications/index/NotificationConfigIndexTests.kt
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,71 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.notifications.index | ||
|
||
import org.junit.jupiter.api.BeforeAll | ||
import org.junit.jupiter.api.Test | ||
import java.lang.reflect.Method | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFails | ||
|
||
class NotificationConfigIndexTests { | ||
|
||
@Test | ||
fun `test get schema version`() { | ||
val indexMapping = mapOf( | ||
"_meta" to mapOf("schema_version" to 10), | ||
"user" to "test" | ||
) | ||
val schemaVersion = getSchemaVersionFromIndexMapping.invoke(NotificationConfigIndex, indexMapping) | ||
assertEquals(10, schemaVersion, "wrong schema version") | ||
} | ||
|
||
@Test | ||
fun `test get schema version without _meta field`() { | ||
val indexMapping = mapOf( | ||
"meta" to mapOf("schema_version" to 10), | ||
"user" to "test" | ||
) | ||
val schemaVersion = getSchemaVersionFromIndexMapping.invoke(NotificationConfigIndex, indexMapping) | ||
assertEquals(1, schemaVersion, "wrong schema version") | ||
} | ||
|
||
@Test | ||
fun `test get schema version without schema_version field`() { | ||
val indexMapping = mapOf( | ||
"_meta" to mapOf("schema" to 10), | ||
"user" to "test" | ||
) | ||
val schemaVersion = getSchemaVersionFromIndexMapping.invoke(NotificationConfigIndex, indexMapping) | ||
assertEquals(1, schemaVersion, "wrong schema version") | ||
} | ||
|
||
@Test | ||
fun `test get non number schema_version throw exception`() { | ||
val indexMapping = mapOf( | ||
"_meta" to mapOf("schema_version" to "10"), | ||
"user" to "test" | ||
) | ||
assertFails { | ||
getSchemaVersionFromIndexMapping.invoke(NotificationConfigIndex, indexMapping) | ||
} | ||
} | ||
|
||
companion object { | ||
private lateinit var getSchemaVersionFromIndexMapping: Method | ||
|
||
@BeforeAll | ||
@JvmStatic | ||
fun initialize() { | ||
/* use reflection to get private method */ | ||
getSchemaVersionFromIndexMapping = NotificationConfigIndex::class.java.getDeclaredMethod( | ||
"getSchemaVersionFromIndexMapping", Map::class.java | ||
) | ||
|
||
getSchemaVersionFromIndexMapping.isAccessible = true | ||
} | ||
} | ||
} |