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).
10 import org
.junit
.ClassRule
;
11 import org
.junit
.Rule
;
12 import org
.junit
.Test
;
13 import org
.junit
.rules
.TemporaryFolder
;
15 import static java
.nio
.charset
.StandardCharsets
.UTF_8
;
16 import static org
.assertj
.core
.api
.Assertions
.assertThat
;
18 public class ColumnFamilyTest
{
21 public static final RocksMemoryResource rocksMemoryResource
=
22 new RocksMemoryResource();
25 public TemporaryFolder dbFolder
= new TemporaryFolder();
28 public void columnFamilyDescriptorName() throws RocksDBException
{
29 final byte[] cfName
= "some_name".getBytes(UTF_8
);
31 try(final ColumnFamilyOptions cfOptions
= new ColumnFamilyOptions()) {
32 final ColumnFamilyDescriptor cfDescriptor
=
33 new ColumnFamilyDescriptor(cfName
, cfOptions
);
34 assertThat(cfDescriptor
.getName()).isEqualTo(cfName
);
39 public void columnFamilyDescriptorOptions() throws RocksDBException
{
40 final byte[] cfName
= "some_name".getBytes(UTF_8
);
42 try(final ColumnFamilyOptions cfOptions
= new ColumnFamilyOptions()
43 .setCompressionType(CompressionType
.BZLIB2_COMPRESSION
)) {
44 final ColumnFamilyDescriptor cfDescriptor
=
45 new ColumnFamilyDescriptor(cfName
, cfOptions
);
47 assertThat(cfDescriptor
.getOptions().compressionType())
48 .isEqualTo(CompressionType
.BZLIB2_COMPRESSION
);
53 public void listColumnFamilies() throws RocksDBException
{
54 try (final Options options
= new Options().setCreateIfMissing(true);
55 final RocksDB db
= RocksDB
.open(options
,
56 dbFolder
.getRoot().getAbsolutePath())) {
57 // Test listColumnFamilies
58 final List
<byte[]> columnFamilyNames
= RocksDB
.listColumnFamilies(options
,
59 dbFolder
.getRoot().getAbsolutePath());
60 assertThat(columnFamilyNames
).isNotNull();
61 assertThat(columnFamilyNames
.size()).isGreaterThan(0);
62 assertThat(columnFamilyNames
.size()).isEqualTo(1);
63 assertThat(new String(columnFamilyNames
.get(0))).isEqualTo("default");
68 public void defaultColumnFamily() throws RocksDBException
{
69 try (final Options options
= new Options().setCreateIfMissing(true);
70 final RocksDB db
= RocksDB
.open(options
,
71 dbFolder
.getRoot().getAbsolutePath())) {
72 final ColumnFamilyHandle cfh
= db
.getDefaultColumnFamily();
74 assertThat(cfh
).isNotNull();
76 assertThat(cfh
.getName()).isEqualTo("default".getBytes(UTF_8
));
77 assertThat(cfh
.getID()).isEqualTo(0);
79 final byte[] key
= "key".getBytes();
80 final byte[] value
= "value".getBytes();
82 db
.put(cfh
, key
, value
);
84 final byte[] actualValue
= db
.get(cfh
, key
);
86 assertThat(cfh
).isNotNull();
87 assertThat(actualValue
).isEqualTo(value
);
95 public void createColumnFamily() throws RocksDBException
{
96 final byte[] cfName
= "new_cf".getBytes(UTF_8
);
97 final ColumnFamilyDescriptor cfDescriptor
= new ColumnFamilyDescriptor(cfName
,
98 new ColumnFamilyOptions());
100 try (final Options options
= new Options().setCreateIfMissing(true);
101 final RocksDB db
= RocksDB
.open(options
,
102 dbFolder
.getRoot().getAbsolutePath())) {
104 final ColumnFamilyHandle columnFamilyHandle
= db
.createColumnFamily(cfDescriptor
);
107 assertThat(columnFamilyHandle
.getName()).isEqualTo(cfName
);
108 assertThat(columnFamilyHandle
.getID()).isEqualTo(1);
110 final ColumnFamilyDescriptor latestDescriptor
= columnFamilyHandle
.getDescriptor();
111 assertThat(latestDescriptor
.getName()).isEqualTo(cfName
);
113 final List
<byte[]> columnFamilyNames
= RocksDB
.listColumnFamilies(
114 options
, dbFolder
.getRoot().getAbsolutePath());
115 assertThat(columnFamilyNames
).isNotNull();
116 assertThat(columnFamilyNames
.size()).isGreaterThan(0);
117 assertThat(columnFamilyNames
.size()).isEqualTo(2);
118 assertThat(new String(columnFamilyNames
.get(0))).isEqualTo("default");
119 assertThat(new String(columnFamilyNames
.get(1))).isEqualTo("new_cf");
121 columnFamilyHandle
.close();
127 public void openWithColumnFamilies() throws RocksDBException
{
128 final List
<ColumnFamilyDescriptor
> cfNames
= Arrays
.asList(
129 new ColumnFamilyDescriptor(RocksDB
.DEFAULT_COLUMN_FAMILY
),
130 new ColumnFamilyDescriptor("new_cf".getBytes())
133 final List
<ColumnFamilyHandle
> columnFamilyHandleList
=
136 // Test open database with column family names
137 try (final DBOptions options
= new DBOptions()
138 .setCreateIfMissing(true)
139 .setCreateMissingColumnFamilies(true);
140 final RocksDB db
= RocksDB
.open(options
,
141 dbFolder
.getRoot().getAbsolutePath(), cfNames
,
142 columnFamilyHandleList
)) {
145 assertThat(columnFamilyHandleList
.size()).isEqualTo(2);
146 db
.put("dfkey1".getBytes(), "dfvalue".getBytes());
147 db
.put(columnFamilyHandleList
.get(0), "dfkey2".getBytes(),
148 "dfvalue".getBytes());
149 db
.put(columnFamilyHandleList
.get(1), "newcfkey1".getBytes(),
150 "newcfvalue".getBytes());
152 String retVal
= new String(db
.get(columnFamilyHandleList
.get(1),
153 "newcfkey1".getBytes()));
154 assertThat(retVal
).isEqualTo("newcfvalue");
155 assertThat((db
.get(columnFamilyHandleList
.get(1),
156 "dfkey1".getBytes()))).isNull();
157 db
.remove(columnFamilyHandleList
.get(1), "newcfkey1".getBytes());
158 assertThat((db
.get(columnFamilyHandleList
.get(1),
159 "newcfkey1".getBytes()))).isNull();
160 db
.remove(columnFamilyHandleList
.get(0), new WriteOptions(),
161 "dfkey2".getBytes());
162 assertThat(db
.get(columnFamilyHandleList
.get(0), new ReadOptions(),
163 "dfkey2".getBytes())).isNull();
165 for (final ColumnFamilyHandle columnFamilyHandle
:
166 columnFamilyHandleList
) {
167 columnFamilyHandle
.close();
174 public void getWithOutValueAndCf() throws RocksDBException
{
175 final List
<ColumnFamilyDescriptor
> cfDescriptors
= Arrays
.asList(
176 new ColumnFamilyDescriptor(RocksDB
.DEFAULT_COLUMN_FAMILY
));
177 final List
<ColumnFamilyHandle
> columnFamilyHandleList
= new ArrayList
<>();
179 // Test open database with column family names
180 try (final DBOptions options
= new DBOptions()
181 .setCreateIfMissing(true)
182 .setCreateMissingColumnFamilies(true);
183 final RocksDB db
= RocksDB
.open(options
,
184 dbFolder
.getRoot().getAbsolutePath(), cfDescriptors
,
185 columnFamilyHandleList
)) {
187 db
.put(columnFamilyHandleList
.get(0), new WriteOptions(),
188 "key1".getBytes(), "value".getBytes());
189 db
.put("key2".getBytes(), "12345678".getBytes());
190 final byte[] outValue
= new byte[5];
192 int getResult
= db
.get("keyNotFound".getBytes(), outValue
);
193 assertThat(getResult
).isEqualTo(RocksDB
.NOT_FOUND
);
194 // found value which fits in outValue
195 getResult
= db
.get(columnFamilyHandleList
.get(0), "key1".getBytes(),
197 assertThat(getResult
).isNotEqualTo(RocksDB
.NOT_FOUND
);
198 assertThat(outValue
).isEqualTo("value".getBytes());
199 // found value which fits partially
200 getResult
= db
.get(columnFamilyHandleList
.get(0), new ReadOptions(),
201 "key2".getBytes(), outValue
);
202 assertThat(getResult
).isNotEqualTo(RocksDB
.NOT_FOUND
);
203 assertThat(outValue
).isEqualTo("12345".getBytes());
205 for (final ColumnFamilyHandle columnFamilyHandle
:
206 columnFamilyHandleList
) {
207 columnFamilyHandle
.close();
214 public void createWriteDropColumnFamily() throws RocksDBException
{
215 final List
<ColumnFamilyDescriptor
> cfDescriptors
= Arrays
.asList(
216 new ColumnFamilyDescriptor(RocksDB
.DEFAULT_COLUMN_FAMILY
),
217 new ColumnFamilyDescriptor("new_cf".getBytes()));
218 final List
<ColumnFamilyHandle
> columnFamilyHandleList
= new ArrayList
<>();
219 try (final DBOptions options
= new DBOptions()
220 .setCreateIfMissing(true)
221 .setCreateMissingColumnFamilies(true);
222 final RocksDB db
= RocksDB
.open(options
,
223 dbFolder
.getRoot().getAbsolutePath(), cfDescriptors
,
224 columnFamilyHandleList
)) {
225 ColumnFamilyHandle tmpColumnFamilyHandle
= null;
227 tmpColumnFamilyHandle
= db
.createColumnFamily(
228 new ColumnFamilyDescriptor("tmpCF".getBytes(),
229 new ColumnFamilyOptions()));
230 db
.put(tmpColumnFamilyHandle
, "key".getBytes(), "value".getBytes());
231 db
.dropColumnFamily(tmpColumnFamilyHandle
);
233 if (tmpColumnFamilyHandle
!= null) {
234 tmpColumnFamilyHandle
.close();
236 for (ColumnFamilyHandle columnFamilyHandle
: columnFamilyHandleList
) {
237 columnFamilyHandle
.close();
244 public void writeBatch() throws RocksDBException
{
245 try (final StringAppendOperator stringAppendOperator
= new StringAppendOperator();
246 final ColumnFamilyOptions defaultCfOptions
= new ColumnFamilyOptions()
247 .setMergeOperator(stringAppendOperator
)) {
248 final List
<ColumnFamilyDescriptor
> cfDescriptors
= Arrays
.asList(
249 new ColumnFamilyDescriptor(RocksDB
.DEFAULT_COLUMN_FAMILY
,
251 new ColumnFamilyDescriptor("new_cf".getBytes()));
252 final List
<ColumnFamilyHandle
> columnFamilyHandleList
= new ArrayList
<>();
253 try (final DBOptions options
= new DBOptions()
254 .setCreateIfMissing(true)
255 .setCreateMissingColumnFamilies(true);
256 final RocksDB db
= RocksDB
.open(options
,
257 dbFolder
.getRoot().getAbsolutePath(),
258 cfDescriptors
, columnFamilyHandleList
);
259 final WriteBatch writeBatch
= new WriteBatch();
260 final WriteOptions writeOpt
= new WriteOptions()) {
262 writeBatch
.put("key".getBytes(), "value".getBytes());
263 writeBatch
.put(db
.getDefaultColumnFamily(),
264 "mergeKey".getBytes(), "merge".getBytes());
265 writeBatch
.merge(db
.getDefaultColumnFamily(), "mergeKey".getBytes(),
267 writeBatch
.put(columnFamilyHandleList
.get(1), "newcfkey".getBytes(),
269 writeBatch
.put(columnFamilyHandleList
.get(1), "newcfkey2".getBytes(),
270 "value2".getBytes());
271 writeBatch
.remove("xyz".getBytes());
272 writeBatch
.remove(columnFamilyHandleList
.get(1), "xyz".getBytes());
273 db
.write(writeOpt
, writeBatch
);
275 assertThat(db
.get(columnFamilyHandleList
.get(1),
276 "xyz".getBytes()) == null);
277 assertThat(new String(db
.get(columnFamilyHandleList
.get(1),
278 "newcfkey".getBytes()))).isEqualTo("value");
279 assertThat(new String(db
.get(columnFamilyHandleList
.get(1),
280 "newcfkey2".getBytes()))).isEqualTo("value2");
281 assertThat(new String(db
.get("key".getBytes()))).isEqualTo("value");
282 // check if key is merged
283 assertThat(new String(db
.get(db
.getDefaultColumnFamily(),
284 "mergeKey".getBytes()))).isEqualTo("merge,merge");
286 for (final ColumnFamilyHandle columnFamilyHandle
:
287 columnFamilyHandleList
) {
288 columnFamilyHandle
.close();
296 public void iteratorOnColumnFamily() throws RocksDBException
{
297 final List
<ColumnFamilyDescriptor
> cfDescriptors
= Arrays
.asList(
298 new ColumnFamilyDescriptor(RocksDB
.DEFAULT_COLUMN_FAMILY
),
299 new ColumnFamilyDescriptor("new_cf".getBytes()));
300 final List
<ColumnFamilyHandle
> columnFamilyHandleList
= new ArrayList
<>();
301 try (final DBOptions options
= new DBOptions()
302 .setCreateIfMissing(true)
303 .setCreateMissingColumnFamilies(true);
304 final RocksDB db
= RocksDB
.open(options
,
305 dbFolder
.getRoot().getAbsolutePath(),
306 cfDescriptors
, columnFamilyHandleList
)) {
309 db
.put(columnFamilyHandleList
.get(1), "newcfkey".getBytes(),
311 db
.put(columnFamilyHandleList
.get(1), "newcfkey2".getBytes(),
312 "value2".getBytes());
313 try (final RocksIterator rocksIterator
=
314 db
.newIterator(columnFamilyHandleList
.get(1))) {
315 rocksIterator
.seekToFirst();
316 Map
<String
, String
> refMap
= new HashMap
<>();
317 refMap
.put("newcfkey", "value");
318 refMap
.put("newcfkey2", "value2");
320 while (rocksIterator
.isValid()) {
322 assertThat(refMap
.get(new String(rocksIterator
.key()))).
323 isEqualTo(new String(rocksIterator
.value()));
324 rocksIterator
.next();
326 assertThat(i
).isEqualTo(2);
329 for (final ColumnFamilyHandle columnFamilyHandle
:
330 columnFamilyHandleList
) {
331 columnFamilyHandle
.close();
338 public void multiGet() throws RocksDBException
{
339 final List
<ColumnFamilyDescriptor
> cfDescriptors
= Arrays
.asList(
340 new ColumnFamilyDescriptor(RocksDB
.DEFAULT_COLUMN_FAMILY
),
341 new ColumnFamilyDescriptor("new_cf".getBytes()));
342 final List
<ColumnFamilyHandle
> columnFamilyHandleList
= new ArrayList
<>();
343 try (final DBOptions options
= new DBOptions()
344 .setCreateIfMissing(true)
345 .setCreateMissingColumnFamilies(true);
346 final RocksDB db
= RocksDB
.open(options
,
347 dbFolder
.getRoot().getAbsolutePath(),
348 cfDescriptors
, columnFamilyHandleList
)) {
350 db
.put(columnFamilyHandleList
.get(0), "key".getBytes(),
352 db
.put(columnFamilyHandleList
.get(1), "newcfkey".getBytes(),
355 final List
<byte[]> keys
= Arrays
.asList(new byte[][]{
356 "key".getBytes(), "newcfkey".getBytes()
358 Map
<byte[], byte[]> retValues
= db
.multiGet(columnFamilyHandleList
,
360 assertThat(retValues
.size()).isEqualTo(2);
361 assertThat(new String(retValues
.get(keys
.get(0))))
363 assertThat(new String(retValues
.get(keys
.get(1))))
365 retValues
= db
.multiGet(new ReadOptions(), columnFamilyHandleList
,
367 assertThat(retValues
.size()).isEqualTo(2);
368 assertThat(new String(retValues
.get(keys
.get(0))))
370 assertThat(new String(retValues
.get(keys
.get(1))))
373 for (final ColumnFamilyHandle columnFamilyHandle
:
374 columnFamilyHandleList
) {
375 columnFamilyHandle
.close();
382 public void properties() throws RocksDBException
{
383 final List
<ColumnFamilyDescriptor
> cfDescriptors
= Arrays
.asList(
384 new ColumnFamilyDescriptor(RocksDB
.DEFAULT_COLUMN_FAMILY
),
385 new ColumnFamilyDescriptor("new_cf".getBytes()));
386 final List
<ColumnFamilyHandle
> columnFamilyHandleList
= new ArrayList
<>();
387 try (final DBOptions options
= new DBOptions()
388 .setCreateIfMissing(true)
389 .setCreateMissingColumnFamilies(true);
390 final RocksDB db
= RocksDB
.open(options
,
391 dbFolder
.getRoot().getAbsolutePath(),
392 cfDescriptors
, columnFamilyHandleList
)) {
394 assertThat(db
.getProperty("rocksdb.estimate-num-keys")).
396 assertThat(db
.getLongProperty(columnFamilyHandleList
.get(0),
397 "rocksdb.estimate-num-keys")).isGreaterThanOrEqualTo(0);
398 assertThat(db
.getProperty("rocksdb.stats")).isNotNull();
399 assertThat(db
.getProperty(columnFamilyHandleList
.get(0),
400 "rocksdb.sstables")).isNotNull();
401 assertThat(db
.getProperty(columnFamilyHandleList
.get(1),
402 "rocksdb.estimate-num-keys")).isNotNull();
403 assertThat(db
.getProperty(columnFamilyHandleList
.get(1),
404 "rocksdb.stats")).isNotNull();
405 assertThat(db
.getProperty(columnFamilyHandleList
.get(1),
406 "rocksdb.sstables")).isNotNull();
407 assertThat(db
.getAggregatedLongProperty("rocksdb.estimate-num-keys")).
409 assertThat(db
.getAggregatedLongProperty("rocksdb.estimate-num-keys")).
410 isGreaterThanOrEqualTo(0);
412 for (final ColumnFamilyHandle columnFamilyHandle
:
413 columnFamilyHandleList
) {
414 columnFamilyHandle
.close();
422 public void iterators() throws RocksDBException
{
423 final List
<ColumnFamilyDescriptor
> cfDescriptors
= Arrays
.asList(
424 new ColumnFamilyDescriptor(RocksDB
.DEFAULT_COLUMN_FAMILY
),
425 new ColumnFamilyDescriptor("new_cf".getBytes()));
426 final List
<ColumnFamilyHandle
> columnFamilyHandleList
= new ArrayList
<>();
427 try (final DBOptions options
= new DBOptions()
428 .setCreateIfMissing(true)
429 .setCreateMissingColumnFamilies(true);
430 final RocksDB db
= RocksDB
.open(options
,
431 dbFolder
.getRoot().getAbsolutePath(), cfDescriptors
,
432 columnFamilyHandleList
)) {
433 List
<RocksIterator
> iterators
= null;
435 iterators
= db
.newIterators(columnFamilyHandleList
);
436 assertThat(iterators
.size()).isEqualTo(2);
437 RocksIterator iter
= iterators
.get(0);
439 final Map
<String
, String
> defRefMap
= new HashMap
<>();
440 defRefMap
.put("dfkey1", "dfvalue");
441 defRefMap
.put("key", "value");
442 while (iter
.isValid()) {
443 assertThat(defRefMap
.get(new String(iter
.key()))).
444 isEqualTo(new String(iter
.value()));
447 // iterate over new_cf key/value pairs
448 final Map
<String
, String
> cfRefMap
= new HashMap
<>();
449 cfRefMap
.put("newcfkey", "value");
450 cfRefMap
.put("newcfkey2", "value2");
451 iter
= iterators
.get(1);
453 while (iter
.isValid()) {
454 assertThat(cfRefMap
.get(new String(iter
.key()))).
455 isEqualTo(new String(iter
.value()));
459 if (iterators
!= null) {
460 for (final RocksIterator rocksIterator
: iterators
) {
461 rocksIterator
.close();
464 for (final ColumnFamilyHandle columnFamilyHandle
:
465 columnFamilyHandleList
) {
466 columnFamilyHandle
.close();
472 @Test(expected
= RocksDBException
.class)
473 public void failPutDisposedCF() throws RocksDBException
{
474 final List
<ColumnFamilyDescriptor
> cfDescriptors
= Arrays
.asList(
475 new ColumnFamilyDescriptor(RocksDB
.DEFAULT_COLUMN_FAMILY
),
476 new ColumnFamilyDescriptor("new_cf".getBytes()));
477 final List
<ColumnFamilyHandle
> columnFamilyHandleList
= new ArrayList
<>();
478 try (final DBOptions options
= new DBOptions()
479 .setCreateIfMissing(true);
480 final RocksDB db
= RocksDB
.open(options
,
481 dbFolder
.getRoot().getAbsolutePath(),
482 cfDescriptors
, columnFamilyHandleList
)) {
484 db
.dropColumnFamily(columnFamilyHandleList
.get(1));
485 db
.put(columnFamilyHandleList
.get(1), "key".getBytes(),
488 for (ColumnFamilyHandle columnFamilyHandle
: columnFamilyHandleList
) {
489 columnFamilyHandle
.close();
495 @Test(expected
= RocksDBException
.class)
496 public void failRemoveDisposedCF() throws RocksDBException
{
497 final List
<ColumnFamilyDescriptor
> cfDescriptors
= Arrays
.asList(
498 new ColumnFamilyDescriptor(RocksDB
.DEFAULT_COLUMN_FAMILY
),
499 new ColumnFamilyDescriptor("new_cf".getBytes()));
500 final List
<ColumnFamilyHandle
> columnFamilyHandleList
= new ArrayList
<>();
501 try (final DBOptions options
= new DBOptions()
502 .setCreateIfMissing(true);
503 final RocksDB db
= RocksDB
.open(options
,
504 dbFolder
.getRoot().getAbsolutePath(),
505 cfDescriptors
, columnFamilyHandleList
)) {
507 db
.dropColumnFamily(columnFamilyHandleList
.get(1));
508 db
.remove(columnFamilyHandleList
.get(1), "key".getBytes());
510 for (final ColumnFamilyHandle columnFamilyHandle
:
511 columnFamilyHandleList
) {
512 columnFamilyHandle
.close();
518 @Test(expected
= RocksDBException
.class)
519 public void failGetDisposedCF() throws RocksDBException
{
520 final List
<ColumnFamilyDescriptor
> cfDescriptors
= Arrays
.asList(
521 new ColumnFamilyDescriptor(RocksDB
.DEFAULT_COLUMN_FAMILY
),
522 new ColumnFamilyDescriptor("new_cf".getBytes()));
523 final List
<ColumnFamilyHandle
> columnFamilyHandleList
= new ArrayList
<>();
524 try (final DBOptions options
= new DBOptions()
525 .setCreateIfMissing(true);
526 final RocksDB db
= RocksDB
.open(options
,
527 dbFolder
.getRoot().getAbsolutePath(), cfDescriptors
,
528 columnFamilyHandleList
)) {
530 db
.dropColumnFamily(columnFamilyHandleList
.get(1));
531 db
.get(columnFamilyHandleList
.get(1), "key".getBytes());
533 for (final ColumnFamilyHandle columnFamilyHandle
:
534 columnFamilyHandleList
) {
535 columnFamilyHandle
.close();
541 @Test(expected
= RocksDBException
.class)
542 public void failMultiGetWithoutCorrectNumberOfCF() throws RocksDBException
{
543 final List
<ColumnFamilyDescriptor
> cfDescriptors
= Arrays
.asList(
544 new ColumnFamilyDescriptor(RocksDB
.DEFAULT_COLUMN_FAMILY
),
545 new ColumnFamilyDescriptor("new_cf".getBytes()));
546 final List
<ColumnFamilyHandle
> columnFamilyHandleList
= new ArrayList
<>();
547 try (final DBOptions options
= new DBOptions()
548 .setCreateIfMissing(true);
549 final RocksDB db
= RocksDB
.open(options
,
550 dbFolder
.getRoot().getAbsolutePath(), cfDescriptors
,
551 columnFamilyHandleList
)) {
553 final List
<byte[]> keys
= new ArrayList
<>();
554 keys
.add("key".getBytes());
555 keys
.add("newcfkey".getBytes());
556 final List
<ColumnFamilyHandle
> cfCustomList
= new ArrayList
<>();
557 db
.multiGet(cfCustomList
, keys
);
560 for (final ColumnFamilyHandle columnFamilyHandle
:
561 columnFamilyHandleList
) {
562 columnFamilyHandle
.close();
569 public void testByteCreateFolumnFamily() throws RocksDBException
{
571 try (final Options options
= new Options().setCreateIfMissing(true);
572 final RocksDB db
= RocksDB
.open(options
,
573 dbFolder
.getRoot().getAbsolutePath())
575 final byte[] b0
= new byte[]{(byte) 0x00};
576 final byte[] b1
= new byte[]{(byte) 0x01};
577 final byte[] b2
= new byte[]{(byte) 0x02};
578 ColumnFamilyHandle cf1
= null, cf2
= null, cf3
= null;
580 cf1
= db
.createColumnFamily(new ColumnFamilyDescriptor(b0
));
581 cf2
= db
.createColumnFamily(new ColumnFamilyDescriptor(b1
));
582 final List
<byte[]> families
= RocksDB
.listColumnFamilies(options
,
583 dbFolder
.getRoot().getAbsolutePath());
584 assertThat(families
).contains("default".getBytes(), b0
, b1
);
585 cf3
= db
.createColumnFamily(new ColumnFamilyDescriptor(b2
));
601 public void testCFNamesWithZeroBytes() throws RocksDBException
{
602 ColumnFamilyHandle cf1
= null, cf2
= null;
603 try (final Options options
= new Options().setCreateIfMissing(true);
604 final RocksDB db
= RocksDB
.open(options
,
605 dbFolder
.getRoot().getAbsolutePath());
608 final byte[] b0
= new byte[]{0, 0};
609 final byte[] b1
= new byte[]{0, 1};
610 cf1
= db
.createColumnFamily(new ColumnFamilyDescriptor(b0
));
611 cf2
= db
.createColumnFamily(new ColumnFamilyDescriptor(b1
));
612 final List
<byte[]> families
= RocksDB
.listColumnFamilies(options
,
613 dbFolder
.getRoot().getAbsolutePath());
614 assertThat(families
).contains("default".getBytes(), b0
, b1
);
627 public void testCFNameSimplifiedChinese() throws RocksDBException
{
628 ColumnFamilyHandle columnFamilyHandle
= null;
629 try (final Options options
= new Options().setCreateIfMissing(true);
630 final RocksDB db
= RocksDB
.open(options
,
631 dbFolder
.getRoot().getAbsolutePath());
634 final String simplifiedChinese
= "\u7b80\u4f53\u5b57";
635 columnFamilyHandle
= db
.createColumnFamily(
636 new ColumnFamilyDescriptor(simplifiedChinese
.getBytes()));
638 final List
<byte[]> families
= RocksDB
.listColumnFamilies(options
,
639 dbFolder
.getRoot().getAbsolutePath());
640 assertThat(families
).contains("default".getBytes(),
641 simplifiedChinese
.getBytes());
643 if (columnFamilyHandle
!= null) {
644 columnFamilyHandle
.close();