[RocksJava] Fix test failure of InfoLogLevelTest

Summary:
In patch https://reviews.facebook.net/D47067, we change the
log level of the initial database information to header level.
As a result, even when the InfoLogLevel is set to Fatal, the
LOG file of a newly opened rocksdb instance will not be empty.
However, the current InfoLogLevelTest expect it should be empty.

This patch fixes this issue by enabling InfoLogLevelTest to
ignore the Log header.

Test Plan: make jtest

Reviewers: fyrz, anthony, IslamAbdelRahman, sdong, adamretter

Reviewed By: sdong

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D47229
main
Yueh-Hsuan Chiang 9 years ago
parent f1b9f804e9
commit ff57c6511d
  1. 27
      java/src/test/java/org/rocksdb/InfoLogLevelTest.java

@ -27,7 +27,7 @@ public class InfoLogLevelTest {
try {
db = RocksDB.open(dbFolder.getRoot().getAbsolutePath());
db.put("key".getBytes(), "value".getBytes());
assertThat(getLogContents()).isNotEmpty();
assertThat(getLogContentsWithoutHeader()).isNotEmpty();
} finally {
if (db != null) {
db.close();
@ -51,7 +51,7 @@ public class InfoLogLevelTest {
db.put("key".getBytes(), "value".getBytes());
// As InfoLogLevel is set to FATAL_LEVEL, here we expect the log
// content to be empty.
assertThat(getLogContents()).isEmpty();
assertThat(getLogContentsWithoutHeader()).isEmpty();
} finally {
if (db != null) {
db.close();
@ -81,7 +81,7 @@ public class InfoLogLevelTest {
db = RocksDB.open(options,
dbFolder.getRoot().getAbsolutePath());
db.put("key".getBytes(), "value".getBytes());
assertThat(getLogContents()).isEmpty();
assertThat(getLogContentsWithoutHeader()).isEmpty();
} finally {
if (db != null) {
db.close();
@ -112,8 +112,23 @@ public class InfoLogLevelTest {
* @return LOG file contents as String.
* @throws IOException if file is not found.
*/
private String getLogContents() throws IOException {
return new String(readAllBytes(get(
dbFolder.getRoot().getAbsolutePath()+ "/LOG")));
private String getLogContentsWithoutHeader() throws IOException {
final String separator = System.getProperty("line.separator");
final String[] lines = new String(readAllBytes(get(
dbFolder.getRoot().getAbsolutePath()+ "/LOG"))).split(separator);
int first_non_header = lines.length;
// Identify the last line of the header
for (int i = lines.length - 1; i >= 0; --i) {
if (lines[i].indexOf("Options.") >= 0 && lines[i].indexOf(':') >= 0) {
first_non_header = i + 1;
break;
}
}
StringBuilder builder = new StringBuilder();
for (int i = first_non_header; i < lines.length; ++i) {
builder.append(lines[i]).append(separator);
}
return builder.toString();
}
}

Loading…
Cancel
Save