alex-plekhanov commented on code in PR #12980:
URL: https://github.com/apache/ignite/pull/12980#discussion_r3081413075


##########
modules/benchmarks/src/test/java/org/apache/ignite/internal/benchmarks/jmh/communication/JmhCacheMetricsSerializationBenchmarkTest.java:
##########
@@ -0,0 +1,217 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.benchmarks.jmh.communication;
+
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.ignite.internal.processors.cluster.CacheMetricsMessage;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Correctness test for {@link JmhCacheMetricsSerializationBenchmark}.
+ *
+ * <p>Verifies that both the new (MessageSerializer) and legacy (inline 
writeTo/readFrom)
+ * approaches produce identical round-trip results, and that all benchmark 
methods
+ * complete without errors.
+ */
+public class JmhCacheMetricsSerializationBenchmarkTest {
+    /** */
+    private JmhCacheMetricsSerializationBenchmark benchmark;
+
+    /** */
+    @Before
+    public void setUp() throws Exception {
+        benchmark = new JmhCacheMetricsSerializationBenchmark();
+        benchmark.setup();
+    }
+
+    /** New writeTo must complete in a single call. */
+    @Test
+    public void testNewWriteToCompletes() {
+        assertTrue("newWriteTo must return true", benchmark.newWriteTo());
+    }
+
+    /** New readFrom must complete in a single call. */
+    @Test
+    public void testNewReadFromCompletes() {
+        assertTrue("newReadFrom must return true", benchmark.newReadFrom());
+    }
+
+    /** Legacy writeTo must complete in a single call. */
+    @Test
+    public void testLegacyWriteToCompletes() {
+        assertTrue("legacyWriteTo must return true", 
benchmark.legacyWriteTo());
+    }
+
+    /** Legacy readFrom must complete in a single call. */
+    @Test
+    public void testLegacyReadFromCompletes() {
+        assertTrue("legacyReadFrom must return true", 
benchmark.legacyReadFrom());
+    }
+
+    /** Round-trip for new approach preserves all fields. */
+    @Test
+    public void testNewRoundTripPreservesFields() throws Exception {
+        assertTrue(benchmark.newWriteTo());
+        assertTrue(benchmark.newReadFrom());
+
+        var src = (CacheMetricsMessage)FieldUtils.readField(benchmark, 
"newMsg", true);
+        var dst = (CacheMetricsMessage)FieldUtils.readField(benchmark, 
"newReadTarget", true);
+
+        assertCacheMetricsEqual(src, dst);
+    }
+
+    /** Round-trip for legacy approach preserves all fields. */
+    @Test
+    public void testLegacyRoundTripPreservesFields() throws Exception {
+        assertTrue(benchmark.legacyWriteTo());
+        assertTrue(benchmark.legacyReadFrom());
+
+        var src = (LegacyCacheMetricsMessage)FieldUtils.readField(benchmark, 
"legacyMsg", true);
+        var dst = (LegacyCacheMetricsMessage)FieldUtils.readField(benchmark, 
"legacyReadTarget", true);
+
+        assertLegacyCacheMetricsEqual(src, dst);
+    }
+
+    // ----- helpers -----
+
+    /** Asserts all 87 fields of {@link CacheMetricsMessage} are equal. */
+    private static void assertCacheMetricsEqual(CacheMetricsMessage src, 
CacheMetricsMessage dst) {
+        assertEquals("cacheGets", src.cacheGets, dst.cacheGets);

Review Comment:
   Method can be replaced with
   ```
           assertTrue(EqualsBuilder.reflectionEquals(src, dst, false));
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to