Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8280189: JFR: TestPrintXML should print mismatching XML #7140

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions test/jdk/jdk/jfr/tool/TestPrintXML.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -47,6 +47,7 @@
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.Locator;
import org.xml.sax.helpers.DefaultHandler;

import jdk.jfr.Timespan;
@@ -105,7 +106,14 @@ public static void main(String... args) throws Throwable {
System.out.println();
System.out.println("Was (XML)");
System.out.println("----------------------");
System.out.println(xmlEvent);
if (xmlEvent.begin > 0 && xmlEvent.end > 0) {
String lines[] = xml.split("\\r?\\n");
for (int i = xmlEvent.begin - 1; i < xmlEvent.end; i++) {
System.out.println(i + " " + lines[i]);
}
} else {
System.out.println("Could not locate XML position");
}
System.out.println();
throw new Exception("Event doesn't match");
}
@@ -164,6 +172,8 @@ static boolean compare(Object eventObject, Object xmlObject) {
static class XMLEvent {
String name;
private Map<String, Object> values = new HashMap<>();
private int begin = -1;
private int end = -1;

XMLEvent(String name) {
this.name = name;
@@ -172,10 +182,15 @@ static class XMLEvent {

public static final class RecordingHandler extends DefaultHandler {

private Locator locator;
private Stack<Object> objects = new Stack<>();
private Stack<SimpleEntry<String, String>> elements = new Stack<>();
private List<XMLEvent> events = new ArrayList<>();

public void setDocumentLocator(Locator locator) {
this.locator = locator;
}

@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
elements.push(new SimpleEntry<>(attrs.getValue("name"), attrs.getValue("index")));
@@ -187,7 +202,9 @@ public void startElement(String uri, String localName, String qName, Attributes

switch (qName) {
case "event":
objects.push(new XMLEvent(attrs.getValue("type")));
XMLEvent event = new XMLEvent(attrs.getValue("type"));
event.begin = locator.getLineNumber();
objects.push(event);
break;
case "struct":
objects.push(new HashMap<String, Object>());
@@ -223,7 +240,9 @@ public void endElement(String uri, String localName, String qName) {
String name = element.getKey();
Object value = objects.pop();
if (objects.isEmpty()) {
events.add((XMLEvent) value);
XMLEvent event = (XMLEvent) value;
event.end = locator.getLineNumber();
events.add(event);
return;
}
if (value instanceof StringBuilder) {