// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
-// This source code is licensed under the BSD-style license found in the
-// LICENSE file in the root directory of this source tree. An additional grant
-// of patent rights can be found in the PATENTS file in the same directory.
+// This source code is licensed under both the GPLv2 (found in the
+// COPYING file in the root directory) and Apache 2.0 License
+// (found in the LICENSE.Apache file in the root directory).
package org.rocksdb;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
public class ColumnFamilyTest {
@Rule
public TemporaryFolder dbFolder = new TemporaryFolder();
+ @Test
+ public void columnFamilyDescriptorName() throws RocksDBException {
+ final byte[] cfName = "some_name".getBytes(UTF_8);
+
+ try(final ColumnFamilyOptions cfOptions = new ColumnFamilyOptions()) {
+ final ColumnFamilyDescriptor cfDescriptor =
+ new ColumnFamilyDescriptor(cfName, cfOptions);
+ assertThat(cfDescriptor.getName()).isEqualTo(cfName);
+ }
+ }
+
+ @Test
+ public void columnFamilyDescriptorOptions() throws RocksDBException {
+ final byte[] cfName = "some_name".getBytes(UTF_8);
+
+ try(final ColumnFamilyOptions cfOptions = new ColumnFamilyOptions()
+ .setCompressionType(CompressionType.BZLIB2_COMPRESSION)) {
+ final ColumnFamilyDescriptor cfDescriptor =
+ new ColumnFamilyDescriptor(cfName, cfOptions);
+
+ assertThat(cfDescriptor.getOptions().compressionType())
+ .isEqualTo(CompressionType.BZLIB2_COMPRESSION);
+ }
+ }
+
@Test
public void listColumnFamilies() throws RocksDBException {
try (final Options options = new Options().setCreateIfMissing(true);
try {
assertThat(cfh).isNotNull();
+ assertThat(cfh.getName()).isEqualTo("default".getBytes(UTF_8));
+ assertThat(cfh.getID()).isEqualTo(0);
+
final byte[] key = "key".getBytes();
final byte[] value = "value".getBytes();
@Test
public void createColumnFamily() throws RocksDBException {
+ final byte[] cfName = "new_cf".getBytes(UTF_8);
+ final ColumnFamilyDescriptor cfDescriptor = new ColumnFamilyDescriptor(cfName,
+ new ColumnFamilyOptions());
+
try (final Options options = new Options().setCreateIfMissing(true);
final RocksDB db = RocksDB.open(options,
- dbFolder.getRoot().getAbsolutePath())) {
- final ColumnFamilyHandle columnFamilyHandle = db.createColumnFamily(
- new ColumnFamilyDescriptor("new_cf".getBytes(),
- new ColumnFamilyOptions()));
+ dbFolder.getRoot().getAbsolutePath())) {
+
+ final ColumnFamilyHandle columnFamilyHandle = db.createColumnFamily(cfDescriptor);
+
try {
+ assertThat(columnFamilyHandle.getName()).isEqualTo(cfName);
+ assertThat(columnFamilyHandle.getID()).isEqualTo(1);
+
+ final ColumnFamilyDescriptor latestDescriptor = columnFamilyHandle.getDescriptor();
+ assertThat(latestDescriptor.getName()).isEqualTo(cfName);
+
final List<byte[]> columnFamilyNames = RocksDB.listColumnFamilies(
- options, dbFolder.getRoot().getAbsolutePath());
+ options, dbFolder.getRoot().getAbsolutePath());
assertThat(columnFamilyNames).isNotNull();
assertThat(columnFamilyNames.size()).isGreaterThan(0);
assertThat(columnFamilyNames.size()).isEqualTo(2);
"rocksdb.stats")).isNotNull();
assertThat(db.getProperty(columnFamilyHandleList.get(1),
"rocksdb.sstables")).isNotNull();
+ assertThat(db.getAggregatedLongProperty("rocksdb.estimate-num-keys")).
+ isNotNull();
+ assertThat(db.getAggregatedLongProperty("rocksdb.estimate-num-keys")).
+ isGreaterThanOrEqualTo(0);
} finally {
for (final ColumnFamilyHandle columnFamilyHandle :
columnFamilyHandleList) {