-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
beta
-
generic
-
generic
-
Verified
Name: elR10090 Date: 12/20/2000
Logging APIs implementation fails the test
nsk/logging/MemoryHandler/MemoryHandler/memhnd001 from testbase_nsk.
The test checks if MemoryHandler created with the constructor
MemoryHandler() works as it stated by spec, that is target handler,
buffer size and push level are as defined by properties file.
The test uses properties file which defines buffer size 2, push
level FINE, level FINER and user-defined target handler. Generating
log messages the test checks that the memory handler created with
MemoryHandler() constructor uses exactly these values.
The test reveals that newly created MemoryHandler has buffer size
greater than 2.
Also, the Logging APIs spec (draft 0.55) doesn't state configuration
property "java.util.logging.MemoryHandler.target" had been stated
in previous spec. The test shows the property is actually available
in current implementation.
I think the spec should document this property.
Log and test source follow:
$ java -version
java version "1.4.0beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0beta-b45)
Java HotSpot(TM) Client VM (build B45, mixed mode)
D:/jdk1.4/bin/java -Xbootclasspath/a:. -Djava.util.logging.config.file=memhnd001.properties logging.MemoryHandler.MemoryHandler.memhnd001
Received messages expected: '_m2', '', '_m5_m6'
actual : '_m2', '', '_m3_m4_m5_m6'
------------------------------------------------------ memhnd001.properties
java.util.logging.MemoryHandler.target = logging.MemoryHandler.MemoryHandler.memhnd001_handler
java.util.logging.MemoryHandler.size = 2
java.util.logging.MemoryHandler.push = FINE
java.util.logging.MemoryHandler.level = FINER
------------------------------------------------------ memhnd001.java
package logging.MemoryHandler.MemoryHandler;
import java.util.logging.*;
import java.io.PrintStream;
import java.util.Properties;
public class memhnd001 {
static String msgs = ""; // accumulates received messages
public static void main(String argv[]) {
System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
}
public static int run(String args[], PrintStream out) {
LogManager manager = LogManager.getLogManager();
manager.removeAllGlobalHandlers();
Handler handler = new memhnd001_handler();
MemoryHandler memHandler = new MemoryHandler();
Logger logger = Logger.getLogger("memhnd001");
logger.setLevel(Level.ALL);
logger.addHandler(memHandler);
logger.finest("m1");
logger.fine("m2");
String part1 = msgs;
msgs = "";
logger.finer("m3");
logger.finer("m4");
logger.finer("m5");
String part2 = msgs;
msgs = "";
logger.info("m6");
if (part1.equals("_m2") && part2.equals("") && msgs.equals("_m5_m6")) {
return 0/*STATUS_PASSED*/;
} else {
out.println("Received messages expected: '_m2', '', '_m5_m6'");
out.println(" actual : '" + part1 + "', '" + part2 + "', '" + msgs + "'");
return 2/*STATUS_FAILED*/;
}
}
}
------------------------------------------------------ memhnd001_handler.java
package logging.MemoryHandler.MemoryHandler;
import java.util.logging.*;
public class memhnd001_handler extends Handler {
public void publish(LogRecord record) {
memhnd001.msgs += ("_" + record.getMessage());
}
// just to override abstract methods:
public void close() {}
public void flush() {}
}
======================================================================