commit
a77e97c536
@ -0,0 +1,47 @@ |
||||
package org.rocksdb; |
||||
|
||||
/** |
||||
* RocksDB log levels. |
||||
*/ |
||||
public enum InfoLogLevel { |
||||
DEBUG_LEVEL((byte)0), |
||||
INFO_LEVEL((byte)1), |
||||
WARN_LEVEL((byte)2), |
||||
ERROR_LEVEL((byte)3), |
||||
FATAL_LEVEL((byte)4), |
||||
NUM_INFO_LOG_LEVELS((byte)5); |
||||
|
||||
private final byte value_; |
||||
|
||||
private InfoLogLevel(byte value) { |
||||
value_ = value; |
||||
} |
||||
|
||||
/** |
||||
* Returns the byte value of the enumerations value |
||||
* |
||||
* @return byte representation |
||||
*/ |
||||
public byte getValue() { |
||||
return value_; |
||||
} |
||||
|
||||
/** |
||||
* Get InfoLogLevel by byte value. |
||||
* |
||||
* @param value byte representation of InfoLogLevel. |
||||
* |
||||
* @return {@link org.rocksdb.InfoLogLevel} instance or null. |
||||
* @throws java.lang.IllegalArgumentException if an invalid |
||||
* value is provided. |
||||
*/ |
||||
public static InfoLogLevel getInfoLogLevel(byte value) { |
||||
for (InfoLogLevel infoLogLevel : InfoLogLevel.values()) { |
||||
if (infoLogLevel.getValue() == value){ |
||||
return infoLogLevel; |
||||
} |
||||
} |
||||
throw new IllegalArgumentException( |
||||
"Illegal value provided for InfoLogLevel."); |
||||
} |
||||
} |
@ -0,0 +1,98 @@ |
||||
package org.rocksdb.test; |
||||
|
||||
import org.junit.ClassRule; |
||||
import org.junit.Rule; |
||||
import org.junit.Test; |
||||
import org.junit.rules.TemporaryFolder; |
||||
import org.rocksdb.*; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
import static java.nio.file.Files.readAllBytes; |
||||
import static java.nio.file.Paths.get; |
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
public class InfoLogLevelTest { |
||||
|
||||
@ClassRule |
||||
public static final RocksMemoryResource rocksMemoryResource = |
||||
new RocksMemoryResource(); |
||||
|
||||
@Rule |
||||
public TemporaryFolder dbFolder = new TemporaryFolder(); |
||||
|
||||
@Test |
||||
public void testInfoLogLevel() throws RocksDBException, |
||||
IOException { |
||||
RocksDB db = null; |
||||
try { |
||||
db = RocksDB.open(dbFolder.getRoot().getAbsolutePath()); |
||||
db.put("key".getBytes(), "value".getBytes()); |
||||
assertThat(getLogContents()).isNotEmpty(); |
||||
} finally { |
||||
if (db != null) { |
||||
db.close(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void testFatalLogLevel() throws RocksDBException, |
||||
IOException { |
||||
RocksDB db = null; |
||||
Options options = null; |
||||
try { |
||||
options = new Options(). |
||||
setCreateIfMissing(true). |
||||
setInfoLogLevel(InfoLogLevel.FATAL_LEVEL); |
||||
assertThat(options.infoLogLevel()). |
||||
isEqualTo(InfoLogLevel.FATAL_LEVEL); |
||||
db = RocksDB.open(options, |
||||
dbFolder.getRoot().getAbsolutePath()); |
||||
db.put("key".getBytes(), "value".getBytes()); |
||||
assertThat(getLogContents()).isEmpty(); |
||||
} finally { |
||||
if (db != null) { |
||||
db.close(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void testFatalLogLevelWithDBOptions() |
||||
throws RocksDBException, IOException { |
||||
RocksDB db = null; |
||||
Options options = null; |
||||
DBOptions dbOptions = null; |
||||
try { |
||||
dbOptions = new DBOptions(). |
||||
setInfoLogLevel(InfoLogLevel.FATAL_LEVEL); |
||||
options = new Options(dbOptions, |
||||
new ColumnFamilyOptions()). |
||||
setCreateIfMissing(true); |
||||
assertThat(dbOptions.infoLogLevel()). |
||||
isEqualTo(InfoLogLevel.FATAL_LEVEL); |
||||
assertThat(options.infoLogLevel()). |
||||
isEqualTo(InfoLogLevel.FATAL_LEVEL); |
||||
db = RocksDB.open(options, |
||||
dbFolder.getRoot().getAbsolutePath()); |
||||
db.put("key".getBytes(), "value".getBytes()); |
||||
assertThat(getLogContents()).isEmpty(); |
||||
} finally { |
||||
if (db != null) { |
||||
db.close(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Read LOG file contents into String. |
||||
* |
||||
* @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"))); |
||||
} |
||||
} |
Loading…
Reference in new issue