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.Test;
9 import org.rocksdb.CompactRangeOptions.BottommostLevelCompaction;
10 
11 import static org.assertj.core.api.Assertions.assertThat;
12 
13 public class CompactRangeOptionsTest {
14 
15   static {
16     RocksDB.loadLibrary();
17   }
18 
19   @Test
20   public void exclusiveManualCompaction() {
21     CompactRangeOptions opt = new CompactRangeOptions();
22     boolean value = false;
23     opt.setExclusiveManualCompaction(value);
24     assertThat(opt.exclusiveManualCompaction()).isEqualTo(value);
25     value = true;
26     opt.setExclusiveManualCompaction(value);
27     assertThat(opt.exclusiveManualCompaction()).isEqualTo(value);
28   }
29 
30   @Test
31   public void bottommostLevelCompaction() {
32     CompactRangeOptions opt = new CompactRangeOptions();
33     BottommostLevelCompaction value = BottommostLevelCompaction.kSkip;
34     opt.setBottommostLevelCompaction(value);
35     assertThat(opt.bottommostLevelCompaction()).isEqualTo(value);
36     value = BottommostLevelCompaction.kForce;
37     opt.setBottommostLevelCompaction(value);
38     assertThat(opt.bottommostLevelCompaction()).isEqualTo(value);
39     value = BottommostLevelCompaction.kIfHaveCompactionFilter;
40     opt.setBottommostLevelCompaction(value);
41     assertThat(opt.bottommostLevelCompaction()).isEqualTo(value);
42   }
43 
44   @Test
45   public void changeLevel() {
46     CompactRangeOptions opt = new CompactRangeOptions();
47     boolean value = false;
48     opt.setChangeLevel(value);
49     assertThat(opt.changeLevel()).isEqualTo(value);
50     value = true;
51     opt.setChangeLevel(value);
52     assertThat(opt.changeLevel()).isEqualTo(value);
53   }
54 
55   @Test
56   public void targetLevel() {
57     CompactRangeOptions opt = new CompactRangeOptions();
58     int value = 2;
59     opt.setTargetLevel(value);
60     assertThat(opt.targetLevel()).isEqualTo(value);
61     value = 3;
62     opt.setTargetLevel(value);
63     assertThat(opt.targetLevel()).isEqualTo(value);
64   }
65 
66   @Test
67   public void targetPathId() {
68     CompactRangeOptions opt = new CompactRangeOptions();
69     int value = 2;
70     opt.setTargetPathId(value);
71     assertThat(opt.targetPathId()).isEqualTo(value);
72     value = 3;
73     opt.setTargetPathId(value);
74     assertThat(opt.targetPathId()).isEqualTo(value);
75   }
76 
77   @Test
78   public void allowWriteStall() {
79     CompactRangeOptions opt = new CompactRangeOptions();
80     boolean value = false;
81     opt.setAllowWriteStall(value);
82     assertThat(opt.allowWriteStall()).isEqualTo(value);
83     value = true;
84     opt.setAllowWriteStall(value);
85     assertThat(opt.allowWriteStall()).isEqualTo(value);
86   }
87 
88   @Test
89   public void maxSubcompactions() {
90     CompactRangeOptions opt = new CompactRangeOptions();
91     int value = 2;
92     opt.setMaxSubcompactions(value);
93     assertThat(opt.maxSubcompactions()).isEqualTo(value);
94     value = 3;
95     opt.setMaxSubcompactions(value);
96     assertThat(opt.maxSubcompactions()).isEqualTo(value);
97   }
98 }
99