Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
// Copyright (c) 2014, 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.
|
|
|
|
|
2014-04-19 12:26:22 +02:00
|
|
|
import java.util.Arrays;
|
2014-04-25 22:57:20 +02:00
|
|
|
import java.util.List;
|
2014-04-26 07:39:33 +02:00
|
|
|
import java.util.Map;
|
2014-04-25 22:57:20 +02:00
|
|
|
import java.util.ArrayList;
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
import org.rocksdb.*;
|
2014-04-14 23:03:43 +02:00
|
|
|
import org.rocksdb.util.SizeUnit;
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
public class RocksDBSample {
|
|
|
|
static {
|
2014-04-30 20:54:02 +02:00
|
|
|
RocksDB.loadLibrary();
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
if (args.length < 1) {
|
|
|
|
System.out.println("usage: RocksDBSample db_path");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String db_path = args[0];
|
2014-04-02 01:59:05 +02:00
|
|
|
String db_path_not_found = db_path + "_not_found";
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
|
|
|
|
System.out.println("RocksDBSample");
|
2014-04-01 06:46:10 +02:00
|
|
|
RocksDB db = null;
|
2014-04-02 01:59:05 +02:00
|
|
|
Options options = new Options();
|
|
|
|
try {
|
|
|
|
db = RocksDB.open(options, db_path_not_found);
|
|
|
|
assert(false);
|
|
|
|
} catch (RocksDBException e) {
|
|
|
|
System.out.format("caught the expceted exception -- %s\n", e);
|
|
|
|
assert(db == null);
|
|
|
|
}
|
|
|
|
|
2014-04-14 21:48:50 +02:00
|
|
|
options.setCreateIfMissing(true)
|
2014-04-15 06:06:13 +02:00
|
|
|
.createStatistics()
|
2014-04-14 23:03:43 +02:00
|
|
|
.setWriteBufferSize(8 * SizeUnit.KB)
|
2014-04-14 21:48:50 +02:00
|
|
|
.setMaxWriteBufferNumber(3)
|
2014-04-22 05:25:30 +02:00
|
|
|
.setMaxBackgroundCompactions(10)
|
2014-07-24 00:44:25 +02:00
|
|
|
.setCompressionType(CompressionType.SNAPPY_COMPRESSION)
|
|
|
|
.setCompactionStyle(CompactionStyle.UNIVERSAL);
|
2014-04-17 06:38:33 +02:00
|
|
|
Statistics stats = options.statisticsPtr();
|
2014-04-08 03:32:09 +02:00
|
|
|
|
2014-04-06 18:33:31 +02:00
|
|
|
assert(options.createIfMissing() == true);
|
2014-04-14 23:03:43 +02:00
|
|
|
assert(options.writeBufferSize() == 8 * SizeUnit.KB);
|
2014-04-06 18:33:31 +02:00
|
|
|
assert(options.maxWriteBufferNumber() == 3);
|
|
|
|
assert(options.maxBackgroundCompactions() == 10);
|
2014-07-07 18:58:54 +02:00
|
|
|
assert(options.compressionType() == CompressionType.SNAPPY_COMPRESSION);
|
2014-07-24 00:44:25 +02:00
|
|
|
assert(options.compactionStyle() == CompactionStyle.UNIVERSAL);
|
2014-04-08 03:32:09 +02:00
|
|
|
|
2014-04-22 00:40:46 +02:00
|
|
|
assert(options.memTableFactoryName().equals("SkipListFactory"));
|
|
|
|
options.setMemTableConfig(
|
|
|
|
new HashSkipListMemTableConfig()
|
|
|
|
.setHeight(4)
|
|
|
|
.setBranchingFactor(4)
|
|
|
|
.setBucketCount(2000000));
|
|
|
|
assert(options.memTableFactoryName().equals("HashSkipListRepFactory"));
|
|
|
|
|
|
|
|
options.setMemTableConfig(
|
|
|
|
new HashLinkedListMemTableConfig()
|
|
|
|
.setBucketCount(100000));
|
|
|
|
assert(options.memTableFactoryName().equals("HashLinkedListRepFactory"));
|
|
|
|
|
|
|
|
options.setMemTableConfig(
|
|
|
|
new VectorMemTableConfig().setReservedSize(10000));
|
|
|
|
assert(options.memTableFactoryName().equals("VectorRepFactory"));
|
|
|
|
|
|
|
|
options.setMemTableConfig(new SkipListMemTableConfig());
|
|
|
|
assert(options.memTableFactoryName().equals("SkipListFactory"));
|
|
|
|
|
|
|
|
options.setTableFormatConfig(new PlainTableConfig());
|
|
|
|
assert(options.tableFactoryName().equals("PlainTable"));
|
|
|
|
|
2014-08-25 23:22:55 +02:00
|
|
|
BlockBasedTableConfig table_options = new BlockBasedTableConfig();
|
|
|
|
table_options.setBlockCacheSize(64 * SizeUnit.KB)
|
|
|
|
.setFilterBitsPerKey(10)
|
|
|
|
.setCacheNumShardBits(6);
|
|
|
|
assert(table_options.blockCacheSize() == 64 * SizeUnit.KB);
|
|
|
|
assert(table_options.cacheNumShardBits() == 6);
|
|
|
|
options.setTableFormatConfig(table_options);
|
|
|
|
assert(options.tableFactoryName().equals("BlockBasedTable"));
|
|
|
|
|
2014-04-02 01:59:05 +02:00
|
|
|
try {
|
|
|
|
db = RocksDB.open(options, db_path_not_found);
|
|
|
|
db.put("hello".getBytes(), "world".getBytes());
|
|
|
|
byte[] value = db.get("hello".getBytes());
|
|
|
|
assert("world".equals(new String(value)));
|
|
|
|
} catch (RocksDBException e) {
|
|
|
|
System.out.format("[ERROR] caught the unexpceted exception -- %s\n", e);
|
|
|
|
assert(db == null);
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
// be sure to release the c++ pointer
|
|
|
|
db.close();
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
|
2014-04-22 00:52:59 +02:00
|
|
|
ReadOptions readOptions = new ReadOptions();
|
|
|
|
readOptions.setFillCache(false);
|
|
|
|
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
try {
|
2014-04-14 22:42:36 +02:00
|
|
|
db = RocksDB.open(options, db_path);
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
db.put("hello".getBytes(), "world".getBytes());
|
|
|
|
byte[] value = db.get("hello".getBytes());
|
|
|
|
System.out.format("Get('hello') = %s\n",
|
|
|
|
new String(value));
|
|
|
|
|
|
|
|
for (int i = 1; i <= 9; ++i) {
|
|
|
|
for (int j = 1; j <= 9; ++j) {
|
|
|
|
db.put(String.format("%dx%d", i, j).getBytes(),
|
|
|
|
String.format("%d", i * j).getBytes());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 1; i <= 9; ++i) {
|
|
|
|
for (int j = 1; j <= 9; ++j) {
|
|
|
|
System.out.format("%s ", new String(db.get(
|
|
|
|
String.format("%dx%d", i, j).getBytes())));
|
|
|
|
}
|
|
|
|
System.out.println("");
|
|
|
|
}
|
|
|
|
|
|
|
|
value = db.get("1x1".getBytes());
|
|
|
|
assert(value != null);
|
|
|
|
value = db.get("world".getBytes());
|
|
|
|
assert(value == null);
|
2014-04-22 00:52:59 +02:00
|
|
|
value = db.get(readOptions, "world".getBytes());
|
|
|
|
assert(value == null);
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
|
|
|
|
byte[] testKey = "asdf".getBytes();
|
|
|
|
byte[] testValue =
|
|
|
|
"asdfghjkl;'?><MNBVCXZQWERTYUIOP{+_)(*&^%$#@".getBytes();
|
|
|
|
db.put(testKey, testValue);
|
|
|
|
byte[] testResult = db.get(testKey);
|
|
|
|
assert(testResult != null);
|
|
|
|
assert(Arrays.equals(testValue, testResult));
|
|
|
|
assert(new String(testValue).equals(new String(testResult)));
|
2014-04-22 00:52:59 +02:00
|
|
|
testResult = db.get(readOptions, testKey);
|
|
|
|
assert(testResult != null);
|
|
|
|
assert(Arrays.equals(testValue, testResult));
|
|
|
|
assert(new String(testValue).equals(new String(testResult)));
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
|
|
|
|
byte[] insufficientArray = new byte[10];
|
|
|
|
byte[] enoughArray = new byte[50];
|
|
|
|
int len;
|
|
|
|
len = db.get(testKey, insufficientArray);
|
2014-03-30 07:00:52 +02:00
|
|
|
assert(len > insufficientArray.length);
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
len = db.get("asdfjkl;".getBytes(), enoughArray);
|
|
|
|
assert(len == RocksDB.NOT_FOUND);
|
|
|
|
len = db.get(testKey, enoughArray);
|
|
|
|
assert(len == testValue.length);
|
2014-04-02 22:14:55 +02:00
|
|
|
|
2014-04-22 00:52:59 +02:00
|
|
|
len = db.get(readOptions, testKey, insufficientArray);
|
|
|
|
assert(len > insufficientArray.length);
|
|
|
|
len = db.get(readOptions, "asdfjkl;".getBytes(), enoughArray);
|
|
|
|
assert(len == RocksDB.NOT_FOUND);
|
|
|
|
len = db.get(readOptions, testKey, enoughArray);
|
|
|
|
assert(len == testValue.length);
|
|
|
|
|
2014-04-02 22:14:55 +02:00
|
|
|
db.remove(testKey);
|
|
|
|
len = db.get(testKey, enoughArray);
|
|
|
|
assert(len == RocksDB.NOT_FOUND);
|
|
|
|
|
|
|
|
// repeat the test with WriteOptions
|
|
|
|
WriteOptions writeOpts = new WriteOptions();
|
|
|
|
writeOpts.setSync(true);
|
|
|
|
writeOpts.setDisableWAL(true);
|
|
|
|
db.put(writeOpts, testKey, testValue);
|
|
|
|
len = db.get(testKey, enoughArray);
|
|
|
|
assert(len == testValue.length);
|
|
|
|
assert(new String(testValue).equals(
|
|
|
|
new String(enoughArray, 0, len)));
|
|
|
|
writeOpts.dispose();
|
2014-04-15 06:06:13 +02:00
|
|
|
|
|
|
|
try {
|
2014-04-17 06:38:33 +02:00
|
|
|
for (TickerType statsType : TickerType.values()) {
|
2014-04-15 06:06:13 +02:00
|
|
|
stats.getTickerCount(statsType);
|
|
|
|
}
|
|
|
|
System.out.println("getTickerCount() passed.");
|
2014-04-17 06:38:33 +02:00
|
|
|
} catch (Exception e) {
|
2014-04-15 06:06:13 +02:00
|
|
|
System.out.println("Failed in call to getTickerCount()");
|
|
|
|
assert(false); //Should never reach here.
|
|
|
|
}
|
2014-04-17 06:55:15 +02:00
|
|
|
|
2014-04-17 06:38:33 +02:00
|
|
|
try {
|
|
|
|
for (HistogramType histogramType : HistogramType.values()) {
|
|
|
|
HistogramData data = stats.geHistogramData(histogramType);
|
|
|
|
}
|
|
|
|
System.out.println("geHistogramData() passed.");
|
|
|
|
} catch (Exception e) {
|
|
|
|
System.out.println("Failed in call to geHistogramData()");
|
|
|
|
assert(false); //Should never reach here.
|
|
|
|
}
|
2014-04-19 22:05:21 +02:00
|
|
|
|
2014-05-12 20:02:25 +02:00
|
|
|
RocksIterator iterator = db.newIterator();
|
2014-04-19 22:05:21 +02:00
|
|
|
|
2014-04-19 21:55:28 +02:00
|
|
|
boolean seekToFirstPassed = false;
|
|
|
|
for (iterator.seekToFirst(); iterator.isValid(); iterator.next()) {
|
|
|
|
iterator.status();
|
|
|
|
assert(iterator.key() != null);
|
|
|
|
assert(iterator.value() != null);
|
|
|
|
seekToFirstPassed = true;
|
|
|
|
}
|
|
|
|
if(seekToFirstPassed) {
|
|
|
|
System.out.println("iterator seekToFirst tests passed.");
|
|
|
|
}
|
2014-04-19 22:05:21 +02:00
|
|
|
|
2014-04-19 21:55:28 +02:00
|
|
|
boolean seekToLastPassed = false;
|
|
|
|
for (iterator.seekToLast(); iterator.isValid(); iterator.prev()) {
|
|
|
|
iterator.status();
|
|
|
|
assert(iterator.key() != null);
|
|
|
|
assert(iterator.value() != null);
|
|
|
|
seekToLastPassed = true;
|
|
|
|
}
|
2014-04-19 22:05:21 +02:00
|
|
|
|
2014-04-19 21:55:28 +02:00
|
|
|
if(seekToLastPassed) {
|
|
|
|
System.out.println("iterator seekToLastPassed tests passed.");
|
|
|
|
}
|
2014-04-19 22:05:21 +02:00
|
|
|
|
2014-04-19 12:26:22 +02:00
|
|
|
iterator.seekToFirst();
|
2014-04-19 21:55:28 +02:00
|
|
|
iterator.seek(iterator.key());
|
|
|
|
assert(iterator.key() != null);
|
|
|
|
assert(iterator.value() != null);
|
2014-04-19 22:05:21 +02:00
|
|
|
|
2014-04-19 21:55:28 +02:00
|
|
|
System.out.println("iterator seek test passed.");
|
2014-04-19 22:05:21 +02:00
|
|
|
|
2014-05-01 10:44:46 +02:00
|
|
|
iterator.dispose();
|
2014-04-19 21:55:28 +02:00
|
|
|
System.out.println("iterator tests passed.");
|
2014-04-26 07:39:33 +02:00
|
|
|
|
|
|
|
iterator = db.newIterator();
|
|
|
|
List<byte[]> keys = new ArrayList<byte[]>();
|
|
|
|
for (iterator.seekToLast(); iterator.isValid(); iterator.prev()) {
|
|
|
|
keys.add(iterator.key());
|
|
|
|
}
|
2014-05-01 10:44:46 +02:00
|
|
|
iterator.dispose();
|
2014-04-26 07:39:33 +02:00
|
|
|
|
|
|
|
Map<byte[], byte[]> values = db.multiGet(keys);
|
|
|
|
assert(values.size() == keys.size());
|
|
|
|
for(byte[] value1 : values.values()) {
|
|
|
|
assert(value1 != null);
|
|
|
|
}
|
|
|
|
|
|
|
|
values = db.multiGet(new ReadOptions(), keys);
|
|
|
|
assert(values.size() == keys.size());
|
|
|
|
for(byte[] value1 : values.values()) {
|
|
|
|
assert(value1 != null);
|
|
|
|
}
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
} catch (RocksDBException e) {
|
|
|
|
System.err.println(e);
|
|
|
|
}
|
2014-04-01 06:46:10 +02:00
|
|
|
if (db != null) {
|
|
|
|
db.close();
|
|
|
|
}
|
2014-04-15 06:06:13 +02:00
|
|
|
// be sure to dispose c++ pointers
|
2014-04-14 22:42:36 +02:00
|
|
|
options.dispose();
|
2014-04-22 00:52:59 +02:00
|
|
|
readOptions.dispose();
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
}
|
|
|
|
}
|