From ff57c6511de8ed5fdb3a7725e75031617b7c5e4f Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang Date: Mon, 21 Sep 2015 18:26:21 -0700 Subject: [PATCH] [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 --- .../java/org/rocksdb/InfoLogLevelTest.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/java/src/test/java/org/rocksdb/InfoLogLevelTest.java b/java/src/test/java/org/rocksdb/InfoLogLevelTest.java index 39d1ddd1d..630666b90 100644 --- a/java/src/test/java/org/rocksdb/InfoLogLevelTest.java +++ b/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(); } } -- GitLab