voonhous commented on code in PR #19224: URL: https://github.com/apache/hudi/pull/19224#discussion_r3543454471
########## hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/index/bloom/TestHoodieBloomFilterProbingResult.java: ########## @@ -0,0 +1,65 @@ +/* + * 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.hudi.index.bloom; + +import org.junit.jupiter.api.Test; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Tests the {@link HoodieBloomFilterProbingResult} value holder. + */ +public class TestHoodieBloomFilterProbingResult { + + @Test + void exposesCandidateKeys() { + Set<String> keys = new HashSet<>(); + keys.add("k1"); + keys.add("k2"); + HoodieBloomFilterProbingResult result = new HoodieBloomFilterProbingResult(keys); + assertSame(keys, result.getCandidateKeys()); Review Comment: Switched to `assertEquals` on the contents here and in `TestClientStatsPojos`, so neither test pins the no-copy detail anymore. ########## hudi-client/hudi-client-common/src/test/java/org/apache/hudi/index/bloom/TestBloomIndexFileInfo.java: ########## @@ -0,0 +1,76 @@ +/* + * 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.hudi.index.bloom; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Tests {@link BloomIndexFileInfo} accessors and key-range checks. + */ +public class TestBloomIndexFileInfo { + + @Test + void fileIdOnlyConstructorLeavesRangeUnset() { + BloomIndexFileInfo info = new BloomIndexFileInfo("f1"); + assertEquals("f1", info.getFileId()); + assertNull(info.getMinRecordKey()); + assertNull(info.getMaxRecordKey()); + assertFalse(info.hasKeyRanges()); + } + + @Test + void fullConstructorPopulatesRange() { + BloomIndexFileInfo info = new BloomIndexFileInfo("f1", "key05", "key20"); + assertEquals("key05", info.getMinRecordKey()); + assertEquals("key20", info.getMaxRecordKey()); + assertTrue(info.hasKeyRanges()); + } + + @Test + void isKeyInRangeIsInclusiveOfBounds() { + BloomIndexFileInfo info = new BloomIndexFileInfo("f1", "key05", "key20"); + assertTrue(info.isKeyInRange("key05")); + assertTrue(info.isKeyInRange("key10")); + assertTrue(info.isKeyInRange("key20")); + assertFalse(info.isKeyInRange("key04")); + assertFalse(info.isKeyInRange("key21")); + } + + @Test + void isKeyInRangeRequiresBounds() { + BloomIndexFileInfo noRange = new BloomIndexFileInfo("f1"); + assertThrows(NullPointerException.class, () -> noRange.isKeyInRange("key10")); Review Comment: Added a short comment noting the no-bounds case currently fails fast with an NPE from `Objects.requireNonNull` rather than returning false, so a future graceful-failure change is flagged intentionally. ########## hudi-client/hudi-client-common/src/test/java/org/apache/hudi/index/bloom/TestBloomIndexFileInfo.java: ########## @@ -0,0 +1,76 @@ +/* + * 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.hudi.index.bloom; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Tests {@link BloomIndexFileInfo} accessors and key-range checks. + */ +public class TestBloomIndexFileInfo { + + @Test + void fileIdOnlyConstructorLeavesRangeUnset() { + BloomIndexFileInfo info = new BloomIndexFileInfo("f1"); + assertEquals("f1", info.getFileId()); + assertNull(info.getMinRecordKey()); + assertNull(info.getMaxRecordKey()); + assertFalse(info.hasKeyRanges()); + } + + @Test + void fullConstructorPopulatesRange() { + BloomIndexFileInfo info = new BloomIndexFileInfo("f1", "key05", "key20"); + assertEquals("key05", info.getMinRecordKey()); + assertEquals("key20", info.getMaxRecordKey()); + assertTrue(info.hasKeyRanges()); + } + + @Test + void isKeyInRangeIsInclusiveOfBounds() { + BloomIndexFileInfo info = new BloomIndexFileInfo("f1", "key05", "key20"); + assertTrue(info.isKeyInRange("key05")); + assertTrue(info.isKeyInRange("key10")); + assertTrue(info.isKeyInRange("key20")); + assertFalse(info.isKeyInRange("key04")); + assertFalse(info.isKeyInRange("key21")); + } + + @Test + void isKeyInRangeRequiresBounds() { + BloomIndexFileInfo noRange = new BloomIndexFileInfo("f1"); + assertThrows(NullPointerException.class, () -> noRange.isKeyInRange("key10")); + } + + @Test + void valueSemanticsForEqualsAndHashCode() { + BloomIndexFileInfo a = new BloomIndexFileInfo("f1", "min", "max"); + BloomIndexFileInfo same = new BloomIndexFileInfo("f1", "min", "max"); + BloomIndexFileInfo different = new BloomIndexFileInfo("f2", "min", "max"); + assertEquals(a, same); + assertEquals(a.hashCode(), same.hashCode()); + assertFalse(a.equals(different)); Review Comment: Switched to `assertNotEquals(a, different)` for consistency with the sibling equality tests. -- 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]
