sarvekshayr commented on code in PR #9069: URL: https://github.com/apache/ozone/pull/9069#discussion_r2412817082
########## hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/codec/TestNSSummaryCodec.java: ########## @@ -0,0 +1,125 @@ +/* + * 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.hadoop.ozone.recon.codec; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.HashSet; +import java.util.Set; +import org.apache.hadoop.hdds.utils.db.Codec; +import org.apache.hadoop.hdds.utils.db.CodecBuffer; +import org.apache.hadoop.ozone.recon.ReconConstants; +import org.apache.hadoop.ozone.recon.api.types.NSSummary; +import org.junit.jupiter.api.Test; + +/** + * Tests for NSSummaryCodec CodecBuffer implementation. + */ +public class TestNSSummaryCodec { + + private final Codec<NSSummary> codec = NSSummaryCodec.get(); + + @Test + public void testCodecBufferRoundTrip() throws Exception { + NSSummary original = createTestNSSummary(); + + CodecBuffer buffer = codec.toCodecBuffer(original, CodecBuffer.Allocator.DIRECT); + try { + NSSummary decoded = codec.fromCodecBuffer(buffer); + assertNSSummaryEquals(original, decoded); + } finally { + buffer.close(); + } + } + + @Test + public void testCodecBufferEmptyDirectory() throws Exception { + NSSummary original = new NSSummary(); + original.setDirName("empty"); + original.setParentId(42L); + + CodecBuffer buffer = codec.toCodecBuffer(original, CodecBuffer.Allocator.DIRECT); + try { + NSSummary decoded = codec.fromCodecBuffer(buffer); + assertNSSummaryEquals(original, decoded); + } finally { + buffer.close(); + } + } + + @Test + public void testCodecBufferLargeDirectory() throws Exception { + NSSummary original = new NSSummary(); + original.setDirName("large"); + original.setNumOfFiles(10000); + original.setSizeOfFiles(1024L * 1024L * 100L); // 100MB + original.setParentId(999L); + + Set<Long> childDirs = new HashSet<>(); + for (long i = 1; i <= 1000; i++) { Review Comment: Use `LinkedHashSet` in test. ########## hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/codec/TestNSSummaryCodec.java: ########## @@ -0,0 +1,125 @@ +/* + * 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.hadoop.ozone.recon.codec; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.HashSet; +import java.util.Set; +import org.apache.hadoop.hdds.utils.db.Codec; +import org.apache.hadoop.hdds.utils.db.CodecBuffer; +import org.apache.hadoop.ozone.recon.ReconConstants; +import org.apache.hadoop.ozone.recon.api.types.NSSummary; +import org.junit.jupiter.api.Test; + +/** + * Tests for NSSummaryCodec CodecBuffer implementation. + */ +public class TestNSSummaryCodec { + + private final Codec<NSSummary> codec = NSSummaryCodec.get(); + + @Test + public void testCodecBufferRoundTrip() throws Exception { + NSSummary original = createTestNSSummary(); + + CodecBuffer buffer = codec.toCodecBuffer(original, CodecBuffer.Allocator.DIRECT); + try { + NSSummary decoded = codec.fromCodecBuffer(buffer); + assertNSSummaryEquals(original, decoded); + } finally { + buffer.close(); + } + } + + @Test + public void testCodecBufferEmptyDirectory() throws Exception { + NSSummary original = new NSSummary(); + original.setDirName("empty"); + original.setParentId(42L); + + CodecBuffer buffer = codec.toCodecBuffer(original, CodecBuffer.Allocator.DIRECT); + try { + NSSummary decoded = codec.fromCodecBuffer(buffer); + assertNSSummaryEquals(original, decoded); + } finally { + buffer.close(); + } + } + + @Test + public void testCodecBufferLargeDirectory() throws Exception { + NSSummary original = new NSSummary(); + original.setDirName("large"); + original.setNumOfFiles(10000); + original.setSizeOfFiles(1024L * 1024L * 100L); // 100MB + original.setParentId(999L); + + Set<Long> childDirs = new HashSet<>(); + for (long i = 1; i <= 1000; i++) { + childDirs.add(i); + } + original.setChildDir(childDirs); + + int[] buckets = new int[ReconConstants.NUM_OF_FILE_SIZE_BINS]; + for (int i = 0; i < buckets.length; i++) { + buckets[i] = i * 100; + } + original.setFileSizeBucket(buckets); + + CodecBuffer buffer = codec.toCodecBuffer(original, CodecBuffer.Allocator.DIRECT); + try { + NSSummary decoded = codec.fromCodecBuffer(buffer); + assertNSSummaryEquals(original, decoded); + } finally { + buffer.close(); + } + } + + private NSSummary createTestNSSummary() { + NSSummary summary = new NSSummary(); + summary.setDirName("test/directory"); + summary.setNumOfFiles(100); + summary.setSizeOfFiles(1024L * 512L); // 512KB + summary.setParentId(42L); + + Set<Long> childDirs = new HashSet<>(); Review Comment: Use `LinkedHashSet` here as well. ########## hadoop-ozone/mini-cluster/src/main/java/org/apache/hadoop/ozone/MiniOzoneClusterImpl.java: ########## @@ -371,14 +371,14 @@ public String getClusterId() { public void shutdown() { try { LOG.info("Shutting down the Mini Ozone Cluster"); - CodecTestUtil.gc(); IOUtils.closeQuietly(clients); final File baseDir = new File(getBaseDir()); stop(); FileUtils.deleteDirectory(baseDir); ContainerCache.getInstance(conf).shutdownCache(); DefaultMetricsSystem.shutdown(); ManagedRocksObjectMetrics.INSTANCE.assertNoLeaks(); + CodecTestUtil.gc(); Review Comment: What's the reason behind moving `CodecTestUtil.gc();` at the end? -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
