Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoyuki Morita <[email protected]>
(cherry picked from commit 2c849f7)
  • Loading branch information
ykmr1224 committed May 18, 2024
1 parent 4b63df9 commit 18b2b9c
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.opensearch.sql.spark.execution.statestore;

/** Interface for copying StateModel object. Refer {@link StateStore} */
public interface CopyBuilder<T> {
T of(T copy, long seqNo, long primaryTerm);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.sql.spark.execution.statestore.StateModel;

/** Interface for XContentSerializer */
/** Interface for XContentSerializer, which serialize/deserialize XContent */
public interface XContentSerializer<T extends StateModel> {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ void toXContentShouldSerializeFlintIndexStateModel() throws Exception {

@Test
void fromXContentShouldDeserializeFlintIndexStateModel() throws Exception {
// Given
String json =
"{\"version\":\"1.0\",\"type\":\"flintindexstate\",\"state\":\"active\",\"applicationId\":\"app1\",\"jobId\":\"job1\",\"latestId\":\"latest1\",\"dataSourceName\":\"datasource1\",\"lastUpdateTime\":1623456789,\"error\":\"\"}";
XContentParser parser =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,12 @@ void toXContentShouldSerializeIndexDMLResult() throws IOException {

@Test
void toXContentShouldHandleErrorInIndexDMLResult() throws IOException {
// Given
IndexDMLResult dmlResult =
new IndexDMLResult("query1", "FAILURE", "An error occurred", "datasource1", 1000L, 2000L);

// When
XContentBuilder xContentBuilder = serializer.toXContent(dmlResult, ToXContent.EMPTY_PARAMS);
String json = xContentBuilder.toString();

// Then
String json = xContentBuilder.toString();
assertTrue(json.contains("\"queryId\":\"query1\""));
assertTrue(json.contains("\"status\":\"FAILURE\""));
assertTrue(json.contains("\"error\":\"An error occurred\""));
Expand All @@ -59,7 +56,6 @@ void toXContentShouldHandleErrorInIndexDMLResult() throws IOException {

@Test
void fromXContentShouldThrowUnsupportedOperationException() {
// When/Then
assertThrows(UnsupportedOperationException.class, () -> serializer.fromXContent(null, 0L, 0L));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class SessionModelXContentSerializerTest {

@Test
void toXContentShouldSerializeSessionModel() throws Exception {
// Given
SessionModel sessionModel =
SessionModel.builder()
.version("1.0")
Expand All @@ -41,11 +40,9 @@ void toXContentShouldSerializeSessionModel() throws Exception {
.error(null)
.build();

// When
XContentBuilder xContentBuilder = serializer.toXContent(sessionModel, ToXContent.EMPTY_PARAMS);
String json = xContentBuilder.toString();

// Then
String json = xContentBuilder.toString();
assertEquals(true, json.contains("\"version\":\"1.0\""));
assertEquals(true, json.contains("\"type\":\"session\""));
assertEquals(true, json.contains("\"sessionType\":\"interactive\""));
Expand All @@ -58,7 +55,6 @@ void toXContentShouldSerializeSessionModel() throws Exception {

@Test
void fromXContentShouldDeserializeSessionModel() throws Exception {
// Given
String json =
"{\n"
+ " \"version\": \"1.0\",\n"
Expand All @@ -78,10 +74,8 @@ void fromXContentShouldDeserializeSessionModel() throws Exception {
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, json);
parser.nextToken();

// When
SessionModel sessionModel = serializer.fromXContent(parser, 1L, 1L);

// Then
assertEquals("1.0", sessionModel.getVersion());
assertEquals(SessionType.INTERACTIVE, sessionModel.getSessionType());
assertEquals("session1", sessionModel.getSessionId().getSessionId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ class StatementModelXContentSerializerTest {

@Test
void toXContentShouldSerializeStatementModel() throws Exception {

serializer = new StatementModelXContentSerializer();
// Given
StatementModel statementModel =
StatementModel.builder()
.version("1.0")
Expand All @@ -50,11 +48,10 @@ void toXContentShouldSerializeStatementModel() throws Exception {
.error(null)
.build();

// When
XContentBuilder xContentBuilder =
serializer.toXContent(statementModel, ToXContent.EMPTY_PARAMS);
String json = xContentBuilder.toString();

String json = xContentBuilder.toString();
assertEquals(true, json.contains("\"version\":\"1.0\""));
assertEquals(true, json.contains("\"state\":\"running\""));
assertEquals(true, json.contains("\"statementId\":\"statement1\""));
Expand All @@ -63,7 +60,6 @@ void toXContentShouldSerializeStatementModel() throws Exception {
@Test
void fromXContentShouldDeserializeStatementModel() throws Exception {
StatementModelXContentSerializer serializer = new StatementModelXContentSerializer();
// Given
String json =
"{\"version\":\"1.0\",\"type\":\"statement\",\"state\":\"running\",\"statementId\":\"statement1\",\"sessionId\":\"session1\",\"applicationId\":\"app1\",\"jobId\":\"job1\",\"lang\":\"SQL\",\"dataSourceName\":\"datasource1\",\"query\":\"SELECT"
+ " * FROM table\",\"queryId\":\"query1\",\"submitTime\":1623456789,\"error\":\"\"}";
Expand All @@ -84,7 +80,6 @@ void fromXContentShouldDeserializeStatementModel() throws Exception {
@Test
void fromXContentShouldDeserializeStatementModelThrowException() throws Exception {
StatementModelXContentSerializer serializer = new StatementModelXContentSerializer();
// Given
String json =
"{\"version\":\"1.0\",\"type\":\"statement_state\",\"state\":\"running\",\"statementId\":\"statement1\",\"sessionId\":\"session1\",\"applicationId\":\"app1\",\"jobId\":\"job1\",\"lang\":\"SQL\",\"dataSourceName\":\"datasource1\",\"query\":\"SELECT"
+ " * FROM table\",\"queryId\":\"query1\",\"submitTime\":1623456789,\"error\":null}";
Expand All @@ -107,7 +102,6 @@ void fromXContentThrowsExceptionWhenParsingInvalidContent() {
@Test
void fromXContentShouldThrowExceptionForUnexpectedField() throws Exception {
StatementModelXContentSerializer serializer = new StatementModelXContentSerializer();

String jsonWithUnexpectedField =
"{\"version\":\"1.0\",\"type\":\"statement\",\"state\":\"running\",\"statementId\":\"statement1\",\"sessionId\":\"session1\",\"applicationId\":\"app1\",\"jobId\":\"job1\",\"lang\":\"SQL\",\"dataSourceName\":\"datasource1\",\"query\":\"SELECT"
+ " * FROM"
Expand Down

0 comments on commit 18b2b9c

Please sign in to comment.