]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/src/test/java/org/rocksdb/SstPartitionerTest.java
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / java / src / test / java / org / rocksdb / SstPartitionerTest.java
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 static java.nio.charset.StandardCharsets.UTF_8;
9 import static org.assertj.core.api.Assertions.assertThat;
10
11 import java.util.List;
12 import org.junit.ClassRule;
13 import org.junit.Rule;
14 import org.junit.Test;
15 import org.junit.rules.TemporaryFolder;
16
17 public class SstPartitionerTest {
18 @ClassRule
19 public static final RocksNativeLibraryResource ROCKS_NATIVE_LIBRARY_RESOURCE =
20 new RocksNativeLibraryResource();
21
22 @Rule public TemporaryFolder dbFolder = new TemporaryFolder();
23
24 @Test
25 public void sstFixedPrefix() throws RocksDBException {
26 try (SstPartitionerFixedPrefixFactory factory = new SstPartitionerFixedPrefixFactory(4);
27 final Options opt =
28 new Options().setCreateIfMissing(true).setSstPartitionerFactory(factory);
29 final RocksDB db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath())) {
30 // writing (long)100 under key
31 db.put("aaaa1".getBytes(), "A".getBytes());
32 db.put("bbbb1".getBytes(), "B".getBytes());
33 db.flush(new FlushOptions());
34
35 db.put("aaaa0".getBytes(), "A2".getBytes());
36 db.put("aaaa2".getBytes(), "A2".getBytes());
37 db.flush(new FlushOptions());
38
39 db.compactRange();
40
41 List<LiveFileMetaData> metadata = db.getLiveFilesMetaData();
42 assertThat(metadata.size()).isEqualTo(2);
43 }
44 }
45
46 @Test
47 public void sstFixedPrefixFamily() throws RocksDBException {
48 final byte[] cfName = "new_cf".getBytes(UTF_8);
49 final ColumnFamilyDescriptor cfDescriptor = new ColumnFamilyDescriptor(cfName,
50 new ColumnFamilyOptions().setSstPartitionerFactory(
51 new SstPartitionerFixedPrefixFactory(4)));
52
53 try (final Options opt = new Options().setCreateIfMissing(true);
54 final RocksDB db = RocksDB.open(opt, dbFolder.getRoot().getAbsolutePath())) {
55 final ColumnFamilyHandle columnFamilyHandle = db.createColumnFamily(cfDescriptor);
56
57 // writing (long)100 under key
58 db.put(columnFamilyHandle, "aaaa1".getBytes(), "A".getBytes());
59 db.put(columnFamilyHandle, "bbbb1".getBytes(), "B".getBytes());
60 db.flush(new FlushOptions(), columnFamilyHandle);
61
62 db.put(columnFamilyHandle, "aaaa0".getBytes(), "A2".getBytes());
63 db.put(columnFamilyHandle, "aaaa2".getBytes(), "A2".getBytes());
64 db.flush(new FlushOptions(), columnFamilyHandle);
65
66 db.compactRange(columnFamilyHandle);
67
68 List<LiveFileMetaData> metadata = db.getLiveFilesMetaData();
69 assertThat(metadata.size()).isEqualTo(2);
70 }
71 }
72 }