MCPcopy Create free account
hub / github.com/e2wugui/zeze / testKeyGet

Method testKeyGet

ZezeJava/ZezeJavaTest/src/Dbh2/TestRocksDb.java:15–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13public class TestRocksDb {
14 // 测试RocksDb:key + commit_ts 方式编码,但是能快速定位到最后一个key的能力。
15 @Test
16 public void testKeyGet() throws RocksDBException {
17 var path = Path.of("TestRocksDb");
18 LogSequence.deleteDirectory(path.toFile());
19 try (var rdb = new RocksDatabase(path.toString(), RocksDatabase.DbType.eOptimisticTransactionDb)) {
20 var db = rdb.getOptimisticTransactionDb();
21 assert db != null;
22 var key = "key".getBytes(StandardCharsets.UTF_8);
23 var value = "value".getBytes(StandardCharsets.UTF_8);
24 byte[] key1;
25 {
26 var bb = ByteBuffer.Allocate();
27 bb.Append(key);
28 bb.WriteLong(1);
29 key1 = bb.Copy();
30 }
31 byte[] key2;
32 {
33 var bb = ByteBuffer.Allocate();
34 bb.Append(key);
35 bb.WriteLong(2);
36 key2 = bb.Copy();
37 }
38 byte[] key3;
39 {
40 var bb = ByteBuffer.Allocate();
41 bb.Append(key);
42 bb.WriteLong(3);
43 key3 = bb.Copy();
44 }
45 try (var trans = db.beginTransaction(RocksDatabase.getDefaultWriteOptions())) {
46 trans.put(key1, value);
47 trans.put(key2, value);
48 trans.commit();
49 }
50 try (var it = db.newIterator()) {
51 it.seekForPrev(key3);
52 while (it.isValid()) {
53 System.out.println(BitConverter.toString(it.key()) + "->" + BitConverter.toString(it.value()));
54 it.next();
55 }
56 }
57 } finally {
58 LogSequence.deleteDirectory(path.toFile());
59 }
60 }
61
62 public static void main(String[] args) throws RocksDBException {
63 var path = Path.of("TestRocksDb");

Callers

nothing calls this directly

Calls 15

deleteDirectoryMethod · 0.95
AllocateMethod · 0.95
toStringMethod · 0.95
isValidMethod · 0.80
getBytesMethod · 0.65
CopyMethod · 0.65
putMethod · 0.65
commitMethod · 0.65
keyMethod · 0.65
valueMethod · 0.65

Tested by

no test coverage detected