privatestatic Logger logger = Logger.getLogger("stackstream"); public StackStreamTest() {
}
publicvoid test() {
A.a();
} staticclass A { publicstaticvoid a() {
B.b();
}
} staticclass B { publicstaticvoid b() {
C.c();
}
} staticclass C { publicstaticvoid c() {
D.d();
}
} staticclass D { publicstaticvoid d() {
E.e();
}
} staticclass E { publicstaticvoid e() {
F.f();
}
} staticclass F { publicstaticvoid f() {
logger.severe("log message");
G.g(); new K().k();
}
}
privatestaticboolean isTestClass(StackFrame f) { // Filter jtreg frames from the end of the stack return f.getClassName().startsWith("StackStreamTest");
}
// Do we need this?
System.out.println("Collect StackTraceElement");
List<StackTraceElement> stacktrace = STE_WALKER.walk(s ->
{ // Filter out jtreg frames return s.filter(StackStreamTest::isTestClass)
.collect(Collectors.mapping(StackFrame::toStackTraceElement, Collectors.toList()));
}); int i=0; for (StackTraceElement s : stacktrace) {
System.out.format(" %d: %s%n", i++, s);
}
// Check STEs for correctness
checkStackTraceElements(GOLDEN_CLASS_NAMES, GOLDEN_METHOD_NAMES, stacktrace);
}
staticvoid checkStackTraceElements(List<String> classNames,
List<String> methodNames,
List<StackTraceElement> stes) { if (classNames.size() != methodNames.size() ) { thrownew RuntimeException("Test error: classNames and methodNames should be same size");
} if (classNames.size() != stes.size()) {
dumpSTEInfo(classNames, methodNames, stes); thrownew RuntimeException("wrong number of elements in stes");
} for (int i = 0; i < classNames.size() ; i++) { if (!classNames.get(i).equals(stes.get(i).getClassName()) ||
!methodNames.get(i).equals(stes.get(i).getMethodName())) {
dumpSTEInfo(classNames, methodNames, stes); thrownew RuntimeException("class & method names don't match");
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.