|
|
|
@ -99,6 +99,7 @@ public class AbstractLoggerTest { |
|
|
|
|
@Test |
|
|
|
|
public void dbOptionsLogger() throws RocksDBException { |
|
|
|
|
RocksDB db = null; |
|
|
|
|
AbstractLogger abstractLogger = null; |
|
|
|
|
List<ColumnFamilyHandle> cfHandles = new ArrayList<>(); |
|
|
|
|
List<ColumnFamilyDescriptor> cfDescriptors = new ArrayList<>(); |
|
|
|
|
cfDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY)); |
|
|
|
@ -111,7 +112,7 @@ public class AbstractLoggerTest { |
|
|
|
|
setCreateIfMissing(true); |
|
|
|
|
|
|
|
|
|
// Create new logger with max log level passed by options
|
|
|
|
|
AbstractLogger abstractLogger = new AbstractLogger(options) { |
|
|
|
|
abstractLogger = new AbstractLogger(options) { |
|
|
|
|
@Override |
|
|
|
|
protected void log(InfoLogLevel infoLogLevel, String logMsg) { |
|
|
|
|
assertThat(logMsg).isNotNull(); |
|
|
|
@ -135,6 +136,85 @@ public class AbstractLoggerTest { |
|
|
|
|
if (db != null) { |
|
|
|
|
db.close(); |
|
|
|
|
} |
|
|
|
|
if (abstractLogger != null) { |
|
|
|
|
abstractLogger.dispose(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void setInfoLogLevel() { |
|
|
|
|
AbstractLogger abstractLogger = null; |
|
|
|
|
try { |
|
|
|
|
// Setup options
|
|
|
|
|
final Options options = new Options(). |
|
|
|
|
setInfoLogLevel(InfoLogLevel.FATAL_LEVEL). |
|
|
|
|
setCreateIfMissing(true); |
|
|
|
|
|
|
|
|
|
// Create new logger with max log level passed by options
|
|
|
|
|
abstractLogger = new AbstractLogger(options) { |
|
|
|
|
@Override |
|
|
|
|
protected void log(InfoLogLevel infoLogLevel, String logMsg) { |
|
|
|
|
assertThat(logMsg).isNotNull(); |
|
|
|
|
assertThat(logMsg.length()).isGreaterThan(0); |
|
|
|
|
logMessageCounter.incrementAndGet(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
assertThat(abstractLogger.infoLogLevel()). |
|
|
|
|
isEqualTo(InfoLogLevel.FATAL_LEVEL); |
|
|
|
|
abstractLogger.setInfoLogLevel(InfoLogLevel.DEBUG_LEVEL); |
|
|
|
|
assertThat(abstractLogger.infoLogLevel()). |
|
|
|
|
isEqualTo(InfoLogLevel.DEBUG_LEVEL); |
|
|
|
|
} finally { |
|
|
|
|
if (abstractLogger != null) { |
|
|
|
|
abstractLogger.dispose(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void changeLogLevelAtRuntime() throws RocksDBException { |
|
|
|
|
RocksDB db = null; |
|
|
|
|
logMessageCounter.set(0); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
// Setup options
|
|
|
|
|
final Options options = new Options(). |
|
|
|
|
setInfoLogLevel(InfoLogLevel.FATAL_LEVEL). |
|
|
|
|
setCreateIfMissing(true); |
|
|
|
|
|
|
|
|
|
// Create new logger with max log level passed by options
|
|
|
|
|
AbstractLogger abstractLogger = new AbstractLogger(options) { |
|
|
|
|
@Override |
|
|
|
|
protected void log(InfoLogLevel infoLogLevel, String logMsg) { |
|
|
|
|
assertThat(logMsg).isNotNull(); |
|
|
|
|
assertThat(logMsg.length()).isGreaterThan(0); |
|
|
|
|
logMessageCounter.incrementAndGet(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// Set custom logger to options
|
|
|
|
|
options.setLogger(abstractLogger); |
|
|
|
|
db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath()); |
|
|
|
|
|
|
|
|
|
// there should be zero messages
|
|
|
|
|
// using fatal level as log level.
|
|
|
|
|
assertThat(logMessageCounter.get()).isEqualTo(0); |
|
|
|
|
|
|
|
|
|
// change log level to debug level
|
|
|
|
|
abstractLogger.setInfoLogLevel(InfoLogLevel.DEBUG_LEVEL); |
|
|
|
|
|
|
|
|
|
db.put("key".getBytes(), "value".getBytes()); |
|
|
|
|
db.flush(new FlushOptions().setWaitForFlush(true)); |
|
|
|
|
|
|
|
|
|
// messages shall be received due to previous actions.
|
|
|
|
|
assertThat(logMessageCounter.get()).isNotEqualTo(0); |
|
|
|
|
|
|
|
|
|
} finally { |
|
|
|
|
if (db != null) { |
|
|
|
|
db.close(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
logMessageCounter.set(0); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|