[RocksJava] Addressed comments in D28971

This commit is contained in:
fyrz 2014-11-25 23:08:53 +01:00
parent fcc2dfd9f9
commit f193deea31
4 changed files with 18 additions and 11 deletions

View file

@ -51,7 +51,7 @@ endif
JAVA_TESTS = org.rocksdb.test.BackupableDBOptionsTest\ JAVA_TESTS = org.rocksdb.test.BackupableDBOptionsTest\
org.rocksdb.test.BackupableDBTest\ org.rocksdb.test.BackupableDBTest\
org.rocksdb.test.BlockBasedTableConfigTest\ org.rocksdb.test.BlockBasedTableConfigTest\
org.rocksdb.test.CheckpointTest\ org.rocksdb.test.CheckPointTest\
org.rocksdb.test.ColumnFamilyOptionsTest\ org.rocksdb.test.ColumnFamilyOptionsTest\
org.rocksdb.test.ColumnFamilyTest\ org.rocksdb.test.ColumnFamilyTest\
org.rocksdb.test.ComparatorOptionsTest\ org.rocksdb.test.ComparatorOptionsTest\

View file

@ -17,15 +17,21 @@ public class Checkpoint extends RocksObject {
* *
* @param db {@link RocksDB} instance. * @param db {@link RocksDB} instance.
* @return a Checkpoint instance. * @return a Checkpoint instance.
*
* @throws java.lang.IllegalArgumentException if {@link RocksDB}
* instance is null.
* @throws java.lang.IllegalStateException if {@link RocksDB}
* instance is not initialized.
*/ */
public static Checkpoint create(RocksDB db) { public static Checkpoint create(RocksDB db) {
if (db == null || !db.isInitialized()) { if (db == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"RocksDB instance needs to be initialized."); "RocksDB instance shall not be null.");
} else if (!db.isInitialized()) {
throw new IllegalStateException(
"RocksDB instance must be initialized.");
} }
Checkpoint checkpoint = new Checkpoint( Checkpoint checkpoint = new Checkpoint(db);
newCheckpoint(db.nativeHandle_));
checkpoint.db_ = db;
return checkpoint; return checkpoint;
} }
@ -50,9 +56,10 @@ public class Checkpoint extends RocksObject {
disposeInternal(nativeHandle_); disposeInternal(nativeHandle_);
} }
private Checkpoint(long handle) { private Checkpoint(RocksDB db) {
super(); super();
nativeHandle_ = handle; nativeHandle_ = newCheckpoint(db.nativeHandle_);
db_ = db;
} }
RocksDB db_; RocksDB db_;

View file

@ -12,7 +12,7 @@ import org.rocksdb.RocksDBException;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
public class CheckpointTest { public class CheckPointTest {
@ClassRule @ClassRule
public static final RocksMemoryResource rocksMemoryResource = public static final RocksMemoryResource rocksMemoryResource =
@ -74,7 +74,7 @@ public class CheckpointTest {
Checkpoint.create(null); Checkpoint.create(null);
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalStateException.class)
public void failIfDbNotInitialized() throws RocksDBException { public void failIfDbNotInitialized() throws RocksDBException {
RocksDB db = RocksDB.open(dbFolder.getRoot().getAbsolutePath()); RocksDB db = RocksDB.open(dbFolder.getRoot().getAbsolutePath());
db.dispose(); db.dispose();

View file

@ -58,4 +58,4 @@ void Java_org_rocksdb_Checkpoint_createCheckpoint(
if (!s.ok()) { if (!s.ok()) {
rocksdb::RocksDBExceptionJni::ThrowNew(env, s); rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
} }
} }