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 
10 import java.util.Collections;
11 
12 import static org.assertj.core.api.Assertions.*;
13 
14 public class SstFileManagerTest {
15 
16   @Test
maxAllowedSpaceUsage()17   public void maxAllowedSpaceUsage() throws RocksDBException {
18     try (final SstFileManager sstFileManager = new SstFileManager(Env.getDefault())) {
19       sstFileManager.setMaxAllowedSpaceUsage(1024 * 1024 * 64);
20       assertThat(sstFileManager.isMaxAllowedSpaceReached()).isFalse();
21       assertThat(sstFileManager.isMaxAllowedSpaceReachedIncludingCompactions()).isFalse();
22     }
23   }
24 
25   @Test
compactionBufferSize()26   public void compactionBufferSize() throws RocksDBException {
27     try (final SstFileManager sstFileManager = new SstFileManager(Env.getDefault())) {
28       sstFileManager.setCompactionBufferSize(1024 * 1024 * 10);
29       assertThat(sstFileManager.isMaxAllowedSpaceReachedIncludingCompactions()).isFalse();
30     }
31   }
32 
33   @Test
totalSize()34   public void totalSize() throws RocksDBException {
35     try (final SstFileManager sstFileManager = new SstFileManager(Env.getDefault())) {
36       assertThat(sstFileManager.getTotalSize()).isEqualTo(0);
37     }
38   }
39 
40   @Test
trackedFiles()41   public void trackedFiles() throws RocksDBException {
42     try (final SstFileManager sstFileManager = new SstFileManager(Env.getDefault())) {
43       assertThat(sstFileManager.getTrackedFiles()).isEqualTo(Collections.emptyMap());
44     }
45   }
46 
47   @Test
deleteRateBytesPerSecond()48   public void deleteRateBytesPerSecond() throws RocksDBException {
49     try (final SstFileManager sstFileManager = new SstFileManager(Env.getDefault())) {
50       assertThat(sstFileManager.getDeleteRateBytesPerSecond()).isEqualTo(SstFileManager.RATE_BYTES_PER_SEC_DEFAULT);
51       final long ratePerSecond = 1024 * 1024 * 52;
52       sstFileManager.setDeleteRateBytesPerSecond(ratePerSecond);
53       assertThat(sstFileManager.getDeleteRateBytesPerSecond()).isEqualTo(ratePerSecond);
54     }
55   }
56 
57   @Test
maxTrashDBRatio()58   public void maxTrashDBRatio() throws RocksDBException {
59     try (final SstFileManager sstFileManager = new SstFileManager(Env.getDefault())) {
60       assertThat(sstFileManager.getMaxTrashDBRatio()).isEqualTo(SstFileManager.MAX_TRASH_DB_RATION_DEFAULT);
61       final double trashRatio = 0.2;
62       sstFileManager.setMaxTrashDBRatio(trashRatio);
63       assertThat(sstFileManager.getMaxTrashDBRatio()).isEqualTo(trashRatio);
64     }
65   }
66 }
67