forked from opensearch-project/opensearch-spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Chen Dai <[email protected]>
- Loading branch information
Showing
6 changed files
with
162 additions
and
11 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
50 changes: 50 additions & 0 deletions
50
...t-core/src/test/scala/org/opensearch/flint/core/metadata/FlintMetadataLogEntrySuite.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,50 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.flint.core.metadata | ||
|
||
import com.stephenn.scalatest.jsonassert.JsonMatchers.matchJson | ||
import org.json4s._ | ||
import org.json4s.native.JsonMethods._ | ||
import org.json4s.native.Serialization | ||
import org.opensearch.flint.core.metadata.log.FlintMetadataLogEntry | ||
import org.opensearch.flint.core.metadata.log.FlintMetadataLogEntry.IndexState.FAILED | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class FlintMetadataLogEntrySuite extends AnyFlatSpec with Matchers { | ||
|
||
implicit val formats: Formats = Serialization.formats(NoTypeHints) | ||
|
||
"toJson" should "correctly serialize an entry with special characters" in { | ||
val logEntry = FlintMetadataLogEntry( | ||
"id", | ||
1, | ||
2, | ||
1627890000000L, | ||
FAILED, | ||
"dataSource", | ||
s"""Error with quotes ' " and newline: \n and tab: \t characters""") | ||
|
||
val actualJson = logEntry.toJson | ||
val lastUpdateTime = (parse(actualJson) \ "lastUpdateTime").extract[Long] | ||
val expectedJson = | ||
s""" | ||
|{ | ||
| "version": "1.0", | ||
| "latestId": "id", | ||
| "type": "flintindexstate", | ||
| "state": "failed", | ||
| "applicationId": "unknown", | ||
| "jobId": "unknown", | ||
| "dataSourceName": "dataSource", | ||
| "jobStartTime": 1627890000000, | ||
| "lastUpdateTime": $lastUpdateTime, | ||
| "error": "Error with quotes ' \\" and newline: \\n and tab: \\t characters" | ||
|} | ||
|""".stripMargin | ||
actualJson should matchJson(expectedJson) | ||
} | ||
} |
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