kfaraz commented on code in PR #16217: URL: https://github.com/apache/druid/pull/16217#discussion_r1545931052
########## indexing-service/src/test/java/org/apache/druid/indexing/common/task/TaskReportSerdeTest.java: ########## @@ -55,47 +56,56 @@ public TaskReportSerdeTest() } @Test - public void testSerde() throws Exception + public void testSerdeOfIngestionReport() throws Exception { - IngestionStatsAndErrorsTaskReport report1 = new IngestionStatsAndErrorsTaskReport( - "testID", - new IngestionStatsAndErrors( - IngestionState.BUILD_SEGMENTS, - ImmutableMap.of( - "hello", "world" - ), - ImmutableMap.of( - "number", 1234 - ), - "an error message", - true, - 1000L, - ImmutableMap.of("PartitionA", 5000L), - 5L, - 10L - ) - ); - String report1serialized = jsonMapper.writeValueAsString(report1); - IngestionStatsAndErrorsTaskReport report2 = (IngestionStatsAndErrorsTaskReport) jsonMapper.readValue( - report1serialized, - TaskReport.class - ); - Assert.assertEquals(report1, report2); - Assert.assertEquals(report1.hashCode(), report2.hashCode()); + IngestionStatsAndErrorsTaskReport originalReport = buildTestIngestionReport(); + String reportJson = jsonMapper.writeValueAsString(originalReport); + TaskReport deserialized = jsonMapper.readValue(reportJson, TaskReport.class); + + Assert.assertTrue(deserialized instanceof IngestionStatsAndErrorsTaskReport); + + IngestionStatsAndErrorsTaskReport deserializedReport = (IngestionStatsAndErrorsTaskReport) deserialized; + Assert.assertEquals(originalReport, deserializedReport); + } + + @Test + public void testSerdeOfKillTaskReport() throws Exception + { + KillTaskReport originalReport = new KillTaskReport("taskId", new KillTaskReport.Stats(1, 2, 3)); + String reportJson = jsonMapper.writeValueAsString(originalReport); + TaskReport deserialized = jsonMapper.readValue(reportJson, TaskReport.class); + + Assert.assertTrue(deserialized instanceof KillTaskReport); + KillTaskReport deserializedReport = (KillTaskReport) deserialized; + Assert.assertEquals(originalReport, deserializedReport); + } + + @Test + public void testWriteReportMapToFileAndRead() throws Exception + { + IngestionStatsAndErrorsTaskReport report1 = buildTestIngestionReport(); final File reportFile = temporaryFolder.newFile(); final SingleFileTaskReportFileWriter writer = new SingleFileTaskReportFileWriter(reportFile); writer.setObjectMapper(jsonMapper); - Map<String, TaskReport> reportMap1 = TaskReport.buildTaskReports(report1); + TaskReport.ReportMap reportMap1 = TaskReport.buildTaskReports(report1); writer.write("testID", reportMap1); - Map<String, TaskReport> reportMap2 = jsonMapper.readValue( - reportFile, - new TypeReference<Map<String, TaskReport>>() {} - ); + TaskReport.ReportMap reportMap2 = jsonMapper.readValue(reportFile, TaskReport.ReportMap.class); Assert.assertEquals(reportMap1, reportMap2); } + @Test + public void testWriteReportMapToStringAndRead() throws Exception Review Comment: Sure, that makes sense. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org