Source:
<code>*/ public void serdeTest() { DiagnosticsStreamMessage diagnosticsStreamMessage = getDiagnosticsStreamMessage(); Collection<DiagnosticsExceptionEvent> exceptionEventList = getExceptionList(); diagnosticsStreamMessage.addDiagnosticsExceptionEvents(exceptionEventList); diagnosticsStreamMessage.addProcessorStopEvents(getProcessorStopEventList()); diagnosticsStreamMessage.addContainerModels(getSampleContainerModels()); <START> byte[] serializedBytes = new MetricsSnapshotSerdeV2().toBytes(diagnosticsStreamMessage.convertToMetricsSnapshot()); <END> MetricsSnapshot metricsSnapshot = new MetricsSnapshotSerdeV2().fromBytes(serializedBytes); DiagnosticsStreamMessage deserializedDiagnosticsStreamMessage = DiagnosticsStreamMessage.convertToDiagnosticsStreamMessage(metricsSnapshot); Assert.assertEquals(diagnosticsStreamMessage, deserializedDiagnosticsStreamMessage); }</code><technical_language>API for DiagnosticsStreamMessage is convertToMetricsSnapshot convertToDiagnosticsStreamMessage, need call MetricsSnapshotSerdeV2 here. In opinion, this test flow: 1) convertToMetricsSnapshot 2) check resulting MetricsSnapshot is correct 3) convertToDiagnosticsStreamMessage 4) check resulting DiagnosticsStreamMessage matches original</technical_language>

Target:
public void serdeTest() { DiagnosticsStreamMessage diagnosticsStreamMessage = getDiagnosticsStreamMessage(); Collection<DiagnosticsExceptionEvent> exceptionEventList = getExceptionList(); diagnosticsStreamMessage.addDiagnosticsExceptionEvents(exceptionEventList); diagnosticsStreamMessage.addProcessorStopEvents(getProcessorStopEventList()); diagnosticsStreamMessage.addContainerModels(getSampleContainerModels()); MetricsSnapshot metricsSnapshot = diagnosticsStreamMessage.convertToMetricsSnapshot(); Assert.assertEquals(metricsSnapshot.getHeader().getJobName(), jobName); Assert.assertEquals(metricsSnapshot.getHeader().getJobId(), jobId); Assert.assertEquals(metricsSnapshot.getHeader().getExecEnvironmentContainerId(), executionEnvContainerId); Assert.assertEquals(metricsSnapshot.getHeader().getVersion(), taskClassVersion); Assert.assertEquals(metricsSnapshot.getHeader().getSamzaVersion(), samzaVersion); Assert.assertEquals(metricsSnapshot.getHeader().getHost(), hostname); Assert.assertEquals(metricsSnapshot.getHeader().getSource(), DiagnosticsManager.class.getName()); Map<String, Map<String, Object>> metricsMap = metricsSnapshot.getMetrics().getAsMap(); Assert.assertTrue(metricsMap.get("org.apache.samza.container.SamzaContainerMetrics").containsKey("exceptions")); Assert.assertTrue(metricsMap.get(DiagnosticsManager.class.getName()).containsKey("containerModels")); Assert.assertTrue(metricsMap.get(DiagnosticsManager.class.getName()).containsKey("numStoresWithChangelog")); Assert.assertTrue(metricsMap.get(DiagnosticsManager.class.getName()).containsKey("containerNumCores")); Assert.assertTrue(metricsMap.get(DiagnosticsManager.class.getName()).containsKey("containerMemoryMb")); Assert.assertTrue(metricsMap.get(DiagnosticsManager.class.getName()).containsKey("stopEvents")); DiagnosticsStreamMessage convertedDiagnosticsStreamMessage = DiagnosticsStreamMessage.convertToDiagnosticsStreamMessage(metricsSnapshot); Assert.assertTrue(convertedDiagnosticsStreamMessage.equals(diagnosticsStreamMessage)); }