Skip to content

Commit fecef1f

Browse files
committed
Unit test
1 parent 377a49a commit fecef1f

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2+
// This source code is licensed under both the GPLv2 (found in the
3+
// COPYING file in the root directory) and Apache 2.0 License
4+
// (found in the LICENSE.Apache file in the root directory).
5+
6+
package org.rocksdb;
7+
8+
import org.junit.ClassRule;
9+
import org.junit.Test;
10+
11+
import static org.assertj.core.api.Assertions.assertThat;
12+
13+
public class RibbonFilterTest {
14+
15+
@ClassRule
16+
public static final RocksNativeLibraryResource ROCKS_NATIVE_LIBRARY_RESOURCE =
17+
new RocksNativeLibraryResource();
18+
19+
@Test
20+
public void ribbonFilter() {
21+
// Test default constructor
22+
try (final RibbonFilter ribbonFilter = new RibbonFilter()) {
23+
assertThat(ribbonFilter).isNotNull();
24+
}
25+
}
26+
27+
@Test
28+
public void ribbonFilterWithBitsPerKey() {
29+
// Test constructor with bits per key
30+
try (final RibbonFilter ribbonFilter = new RibbonFilter(10.0)) {
31+
assertThat(ribbonFilter).isNotNull();
32+
}
33+
}
34+
35+
@Test
36+
public void ribbonFilterWithHybridMode() {
37+
// Test constructor with hybrid Bloom/Ribbon mode
38+
try (final RibbonFilter ribbonFilter = new RibbonFilter(10.0, 1)) {
39+
assertThat(ribbonFilter).isNotNull();
40+
}
41+
}
42+
43+
@Test
44+
public void ribbonFilterAlwaysRibbon() {
45+
// Test always use Ribbon (bloomBeforeLevel = -1)
46+
try (final RibbonFilter ribbonFilter = new RibbonFilter(10.0, -1)) {
47+
assertThat(ribbonFilter).isNotNull();
48+
}
49+
}
50+
51+
@Test
52+
public void ribbonFilterEquality() {
53+
// Test equals and hashCode
54+
try (final RibbonFilter filter1 = new RibbonFilter(10.0, 1);
55+
final RibbonFilter filter2 = new RibbonFilter(10.0, 1);
56+
final RibbonFilter filter3 = new RibbonFilter(10.0, 2)) {
57+
assertThat(filter1).isEqualTo(filter2);
58+
assertThat(filter1.hashCode()).isEqualTo(filter2.hashCode());
59+
assertThat(filter1).isNotEqualTo(filter3);
60+
}
61+
}
62+
63+
@Test
64+
public void ribbonFilterWithTableConfig() {
65+
// Test using RibbonFilter with BlockBasedTableConfig
66+
try (final RibbonFilter ribbonFilter = new RibbonFilter(10.0);
67+
final Options options = new Options()) {
68+
final BlockBasedTableConfig tableConfig = new BlockBasedTableConfig();
69+
tableConfig.setFilterPolicy(ribbonFilter);
70+
options.setTableFormatConfig(tableConfig);
71+
assertThat(options).isNotNull();
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)