@@ -26,6 +26,18 @@ public class FlushWALOptionsTest {
2626 public void newFlushWALOptions () {
2727 try (final FlushWALOptions flushWALOptions = new FlushWALOptions ()) {
2828 assertThat (flushWALOptions ).isNotNull ();
29+ // Verify defaults
30+ assertThat (flushWALOptions .sync ()).isFalse ();
31+ assertThat (flushWALOptions .rateLimiterPriority ()).isEqualTo (IOPriority .IO_TOTAL );
32+ }
33+ }
34+
35+ @ Test
36+ public void newFlushWALOptionsWithSync () {
37+ try (final FlushWALOptions flushWALOptions = new FlushWALOptions (true )) {
38+ assertThat (flushWALOptions ).isNotNull ();
39+ assertThat (flushWALOptions .sync ()).isTrue ();
40+ assertThat (flushWALOptions .rateLimiterPriority ()).isEqualTo (IOPriority .IO_TOTAL );
2941 }
3042 }
3143
@@ -51,13 +63,35 @@ public void rateLimiterPriority() {
5163 // Default value should be IO_TOTAL
5264 assertThat (flushWALOptions .rateLimiterPriority ()).isEqualTo (IOPriority .IO_TOTAL );
5365
54- // Test setting to IO_HIGH
66+ // Test all IOPriority values
67+ flushWALOptions .setRateLimiterPriority (IOPriority .IO_LOW );
68+ assertThat (flushWALOptions .rateLimiterPriority ()).isEqualTo (IOPriority .IO_LOW );
69+
70+ flushWALOptions .setRateLimiterPriority (IOPriority .IO_MID );
71+ assertThat (flushWALOptions .rateLimiterPriority ()).isEqualTo (IOPriority .IO_MID );
72+
5573 flushWALOptions .setRateLimiterPriority (IOPriority .IO_HIGH );
5674 assertThat (flushWALOptions .rateLimiterPriority ()).isEqualTo (IOPriority .IO_HIGH );
5775
58- // Test setting to IO_LOW
59- flushWALOptions .setRateLimiterPriority (IOPriority .IO_LOW );
60- assertThat (flushWALOptions .rateLimiterPriority ()).isEqualTo (IOPriority .IO_LOW );
76+ flushWALOptions .setRateLimiterPriority (IOPriority .IO_USER );
77+ assertThat (flushWALOptions .rateLimiterPriority ()).isEqualTo (IOPriority .IO_USER );
78+
79+ flushWALOptions .setRateLimiterPriority (IOPriority .IO_TOTAL );
80+ assertThat (flushWALOptions .rateLimiterPriority ()).isEqualTo (IOPriority .IO_TOTAL );
81+ }
82+ }
83+
84+ @ Test
85+ public void fluentAPI () {
86+ try (final FlushWALOptions flushWALOptions = new FlushWALOptions ()) {
87+ // Test fluent chaining
88+ FlushWALOptions result = flushWALOptions
89+ .setSync (true )
90+ .setRateLimiterPriority (IOPriority .IO_HIGH );
91+
92+ assertThat (result ).isSameAs (flushWALOptions );
93+ assertThat (flushWALOptions .sync ()).isTrue ();
94+ assertThat (flushWALOptions .rateLimiterPriority ()).isEqualTo (IOPriority .IO_HIGH );
6195 }
6296 }
6397
@@ -109,6 +143,33 @@ public void flushWalWithRateLimiter() throws RocksDBException {
109143
110144 // Verify data is accessible
111145 assertThat (new String (db .get ("key1" .getBytes ()))).isEqualTo ("value1" );
146+
147+ // Test with different priority
148+ db .put ("key2" .getBytes (), "value2" .getBytes ());
149+ flushWALOptions .setRateLimiterPriority (IOPriority .IO_LOW );
150+ db .flushWal (flushWALOptions );
151+
152+ assertThat (new String (db .get ("key2" .getBytes ()))).isEqualTo ("value2" );
153+ }
154+ }
155+
156+ @ Test
157+ public void backwardCompatibility () throws RocksDBException {
158+ try (final Options options = new Options ()
159+ .setCreateIfMissing (true )
160+ .setManualWalFlush (true );
161+ final RocksDB db = RocksDB .open (options , dbFolder .getRoot ().getAbsolutePath ())) {
162+
163+ // Test old flushWal(boolean) still works
164+ db .put ("key1" .getBytes (), "value1" .getBytes ());
165+ db .flushWal (false );
166+
167+ db .put ("key2" .getBytes (), "value2" .getBytes ());
168+ db .flushWal (true );
169+
170+ // Verify data is accessible
171+ assertThat (new String (db .get ("key1" .getBytes ()))).isEqualTo ("value1" );
172+ assertThat (new String (db .get ("key2" .getBytes ()))).isEqualTo ("value2" );
112173 }
113174 }
114175}
0 commit comments