From a3cccf5fa31e0b2b93c84aada6e909d6b8f807b7 Mon Sep 17 00:00:00 2001 From: Amit Galitzky Date: Wed, 16 Mar 2022 13:40:50 -0700 Subject: [PATCH] fixed adTaskProfile toXContent bug and added to .gitignore (#447) Signed-off-by: Amit Galitzky (cherry picked from commit b0f6475cd8349177da381c8ba5a7fb10663b9286) --- .gitignore | 1 + .../opensearch/ad/model/ADTaskProfile.java | 2 +- .../ad/transport/ADTaskProfileTests.java | 25 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7ed43c682..0eaa85571 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ out/ .classpath .vscode bin/ +._.DS_Store \ No newline at end of file diff --git a/src/main/java/org/opensearch/ad/model/ADTaskProfile.java b/src/main/java/org/opensearch/ad/model/ADTaskProfile.java index 6727defe9..1b3a4b627 100644 --- a/src/main/java/org/opensearch/ad/model/ADTaskProfile.java +++ b/src/main/java/org/opensearch/ad/model/ADTaskProfile.java @@ -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(); } diff --git a/src/test/java/org/opensearch/ad/transport/ADTaskProfileTests.java b/src/test/java/org/opensearch/ad/transport/ADTaskProfileTests.java index a71025acb..f8d57c226 100644 --- a/src/test/java/org/opensearch/ad/transport/ADTaskProfileTests.java +++ b/src/test/java/org/opensearch/ad/transport/ADTaskProfileTests.java @@ -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); + } }