Skip to content

Commit 3d61363

Browse files
committed
Fix multiGet corruption test and implementation.
1 parent 51e7603 commit 3d61363

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

java/rocksjni/jni_multiget_helpers.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,16 @@ jobjectArray MultiGetJNIValues::byteArrays(
158158
}
159159

160160
env->DeleteLocalRef(jentry_value);
161+
} else if (s[i].code() == ROCKSDB_NAMESPACE::Status::Code::kCorruption) {
162+
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s[i]);
163+
return nullptr;
161164
} else if (s[i].code() != ROCKSDB_NAMESPACE::Status::Code::kNotFound) {
162165
// The only way to return an error for a single key is to exception the
163166
// entire multiGet() Previous behaviour was to return a nullptr value for
164167
// this case and potentially succesfully return values for other keys; we
165168
// retain this behaviour. To change it, we need to do the following:
166169
// ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s[i]);
167170
// return nullptr;
168-
} else if (s[i].code() == ROCKSDB_NAMESPACE::Status::Code::kCorruption) {
169-
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s[i]);
170-
return nullptr;
171171
}
172172
}
173173
return jresults;

java/src/test/java/org/rocksdb/MultiGetCorruptionTest.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.io.*;
77
import java.util.ArrayList;
88
import java.util.List;
9+
import org.hamcrest.Description;
10+
import org.hamcrest.TypeSafeMatcher;
911
import org.junit.ClassRule;
1012
import org.junit.Rule;
1113
import org.junit.Test;
@@ -47,11 +49,22 @@ public void multiGetKeyException() throws RocksDBException, IOException {
4749
createCorruptedDatabase();
4850
try (Options options = new Options().setCreateIfMissing(true).setParanoidChecks(true);
4951
RocksDB db = RocksDB.openReadOnly(options, dbFolder.getRoot().getAbsolutePath())) {
50-
// exception.expect(RocksDBException.class);
52+
exception.expect(RocksDBException.class);
53+
exception.expect(new TypeSafeMatcher<RocksDBException>() {
54+
@Override
55+
protected boolean matchesSafely(RocksDBException e) {
56+
return e.getStatus().getCode() == Status.Code.Corruption;
57+
}
58+
59+
@Override
60+
public void describeTo(Description description) {
61+
description.appendText("Status.Code is not equal to Corruption");
62+
}
63+
});
64+
5165
List<byte[]> keys = new ArrayList<>();
5266
keys.add(KEY);
53-
List<byte[]> result = db.multiGetAsList(keys);
54-
assertThat(result).isNotNull();
67+
db.multiGetAsList(keys);
5568
}
5669
}
5770

0 commit comments

Comments
 (0)