Skip to content

Commit bfd0103

Browse files
committed
Integration test
1 parent fecef1f commit bfd0103

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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.Rule;
10+
import org.junit.Test;
11+
import org.junit.rules.TemporaryFolder;
12+
13+
import java.nio.charset.StandardCharsets;
14+
15+
import static org.assertj.core.api.Assertions.assertThat;
16+
17+
public class RibbonFilterIntegrationTest {
18+
19+
@ClassRule
20+
public static final RocksNativeLibraryResource ROCKS_NATIVE_LIBRARY_RESOURCE =
21+
new RocksNativeLibraryResource();
22+
23+
@Rule
24+
public TemporaryFolder dbFolder = new TemporaryFolder();
25+
26+
@Test
27+
public void ribbonFilterBasicFunctionality() throws RocksDBException {
28+
// Test that Ribbon filter actually works in a real database scenario
29+
try (final RibbonFilter ribbonFilter = new RibbonFilter(10.0);
30+
final Options options = new Options()
31+
.setCreateIfMissing(true)) {
32+
33+
final BlockBasedTableConfig tableConfig = new BlockBasedTableConfig();
34+
tableConfig.setFilterPolicy(ribbonFilter);
35+
options.setTableFormatConfig(tableConfig);
36+
37+
try (final RocksDB db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath())) {
38+
// Write some data
39+
final byte[] key1 = "key1".getBytes(StandardCharsets.UTF_8);
40+
final byte[] value1 = "value1".getBytes(StandardCharsets.UTF_8);
41+
final byte[] key2 = "key2".getBytes(StandardCharsets.UTF_8);
42+
final byte[] value2 = "value2".getBytes(StandardCharsets.UTF_8);
43+
44+
db.put(key1, value1);
45+
db.put(key2, value2);
46+
47+
// Read the data back
48+
assertThat(db.get(key1)).isEqualTo(value1);
49+
assertThat(db.get(key2)).isEqualTo(value2);
50+
51+
// Flush to create SST file with Ribbon filter
52+
db.flush(new FlushOptions().setWaitForFlush(true));
53+
54+
// Verify data still accessible after flush
55+
assertThat(db.get(key1)).isEqualTo(value1);
56+
assertThat(db.get(key2)).isEqualTo(value2);
57+
}
58+
}
59+
}
60+
61+
@Test
62+
public void ribbonFilterHybridMode() throws RocksDBException {
63+
// Test hybrid Bloom/Ribbon configuration
64+
try (final RibbonFilter ribbonFilter = new RibbonFilter(10.0, 1);
65+
final Options options = new Options()
66+
.setCreateIfMissing(true)) {
67+
68+
final BlockBasedTableConfig tableConfig = new BlockBasedTableConfig();
69+
tableConfig.setFilterPolicy(ribbonFilter);
70+
options.setTableFormatConfig(tableConfig);
71+
72+
try (final RocksDB db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath())) {
73+
// Write and verify data works with hybrid mode
74+
final byte[] key = "testkey".getBytes(StandardCharsets.UTF_8);
75+
final byte[] value = "testvalue".getBytes(StandardCharsets.UTF_8);
76+
77+
db.put(key, value);
78+
assertThat(db.get(key)).isEqualTo(value);
79+
}
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)