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 package org.rocksdb;
6 
7 import org.junit.ClassRule;
8 import org.junit.Rule;
9 import org.junit.Test;
10 import org.junit.rules.TemporaryFolder;
11 
12 import static org.assertj.core.api.Assertions.assertThat;
13 
14 public class FlushTest {
15 
16   @ClassRule
17   public static final RocksNativeLibraryResource ROCKS_NATIVE_LIBRARY_RESOURCE =
18       new RocksNativeLibraryResource();
19 
20   @Rule
21   public TemporaryFolder dbFolder = new TemporaryFolder();
22 
23   @Test
24   public void flush() throws RocksDBException {
25     try(final Options options = new Options()
26         .setCreateIfMissing(true)
27         .setMaxWriteBufferNumber(10)
28         .setMinWriteBufferNumberToMerge(10);
29         final WriteOptions wOpt = new WriteOptions()
30             .setDisableWAL(true);
31         final FlushOptions flushOptions = new FlushOptions()
32             .setWaitForFlush(true)) {
33       assertThat(flushOptions.waitForFlush()).isTrue();
34 
35       try(final RocksDB db = RocksDB.open(options,
36           dbFolder.getRoot().getAbsolutePath())) {
37         db.put(wOpt, "key1".getBytes(), "value1".getBytes());
38         db.put(wOpt, "key2".getBytes(), "value2".getBytes());
39         db.put(wOpt, "key3".getBytes(), "value3".getBytes());
40         db.put(wOpt, "key4".getBytes(), "value4".getBytes());
41         assertThat(db.getProperty("rocksdb.num-entries-active-mem-table"))
42             .isEqualTo("4");
43         db.flush(flushOptions);
44         assertThat(db.getProperty("rocksdb.num-entries-active-mem-table"))
45             .isEqualTo("0");
46       }
47     }
48   }
49 }
50