Skip to content

Commit

Permalink
fixed adTaskProfile toXContent bug and added to .gitignore (#447)
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Galitzky <[email protected]>
(cherry picked from commit b0f6475)
  • Loading branch information
amitgalitz committed Mar 22, 2022
1 parent b97e04b commit a3cccf5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ out/
.classpath
.vscode
bin/
._.DS_Store
2 changes: 1 addition & 1 deletion src/main/java/org/opensearch/ad/model/ADTaskProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
xContentBuilder.field(ENTITY_TASK_PROFILE_FIELD, entityTaskProfiles.toArray());
}
if (latestHCTaskRunTime != null) {
xContentBuilder.field(ENTITY_TASK_PROFILE_FIELD, latestHCTaskRunTime);
xContentBuilder.field(LATEST_HC_TASK_RUN_TIME_FIELD, latestHCTaskRunTime);
}
return xContentBuilder.endObject();
}
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/org/opensearch/ad/transport/ADTaskProfileTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,29 @@ public void testSerializeResponse() throws IOException {

// assertEquals(profile, response2.getNodes().get(0).getAdTaskProfile());
}

public void testADTaskProfileParseFullConstructor() throws IOException {
ADTaskProfile adTaskProfile = new ADTaskProfile(
TestHelpers.randomAdTask(),
randomInt(),
randomLong(),
randomBoolean(),
randomInt(),
randomLong(),
randomAlphaOfLength(5),
randomAlphaOfLength(5),
randomAlphaOfLength(5),
randomInt(),
randomBoolean(),
randomInt(),
randomInt(),
randomInt(),
ImmutableList.of(randomAlphaOfLength(5)),
Instant.now().toEpochMilli()
);
String adTaskProfileString = TestHelpers
.xContentBuilderToString(adTaskProfile.toXContent(TestHelpers.builder(), ToXContent.EMPTY_PARAMS));
ADTaskProfile parsedADTaskProfile = ADTaskProfile.parse(TestHelpers.parser(adTaskProfileString));
assertEquals(adTaskProfile, parsedADTaskProfile);
}
}

0 comments on commit a3cccf5

Please sign in to comment.