Skip to content

Commit

Permalink
json-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
naotoj committed Jul 19, 2024
1 parent c8a95a7 commit 9cf3207
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 15 deletions.
2 changes: 1 addition & 1 deletion test/jdk/TEST.ROOT
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ requiredVersion=7.4+1

# Path to libraries in the topmost test directory. This is needed so @library
# does not need ../../ notation to reach them
external.lib.roots = ../../
external.lib.roots = ../../../../../../json/json-parser/out/artifacts/json_parser_jar/ ../../

# Use new module options
useNewOptions=true
Expand Down
66 changes: 52 additions & 14 deletions test/jdk/jdk/jfr/tool/TestPrintJSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@
import jdk.test.lib.json.JSONValue.JSONArray;
import jdk.test.lib.Asserts;
import jdk.test.lib.process.OutputAnalyzer;
import jsonp.JsonArray;
import jsonp.JsonException;
import jsonp.JsonObject;
import jsonp.JsonParser;
import jsonp.JsonString;
import jsonp.JsonValue;

/**
* @test
* @key jfr
* @summary Tests print --json
* @requires vm.hasJFR
*
* @library /test/lib /test/jdk
* @library /test/lib /test/jdk /json-parser.jar
* @modules jdk.jfr
*
* @run main/othervm jdk.jfr.tool.TestPrintJSON
Expand All @@ -60,20 +66,52 @@ public static void main(String... args) throws Throwable {
OutputAnalyzer output = ExecuteHelper.jfr("print", "--json", "--stack-depth", "999", recordingFile.toString());
String json = output.getStdout();

JSONValue o = JSONValue.parse(json);
JSONValue recording = o.get("recording");
JSONArray jsonEvents = recording.get("events").asArray();
List<RecordedEvent> events = RecordingFile.readAllEvents(recordingFile);
Collections.sort(events, new EndTicksComparator());
// Verify events are equal
Iterator<RecordedEvent> it = events.iterator();
for (JSONValue jsonEvent : jsonEvents) {
RecordedEvent recordedEvent = it.next();
String typeName = recordedEvent.getEventType().getName();
Asserts.assertEquals(typeName, jsonEvent.get("type").asString());
assertEquals(jsonEvent, recordedEvent);
// JSONValue o = JSONValue.parse(json);
// JSONValue recording = o.get("recording");
// JSONArray jsonEvents = recording.get("events").asArray();
// List<RecordedEvent> events = RecordingFile.readAllEvents(recordingFile);
// Collections.sort(events, new EndTicksComparator());
// // Verify events are equal
// Iterator<RecordedEvent> it = events.iterator();
// for (JSONValue jsonEvent : jsonEvents) {
// RecordedEvent recordedEvent = it.next();
// String typeName = recordedEvent.getEventType().getName();
// Asserts.assertEquals(typeName, jsonEvent.get("type").asString());
// assertEquals(jsonEvent, recordedEvent);
// }
// Asserts.assertFalse(events.size() != jsonEvents.size(), "Incorrect number of events");

JsonValue o = JsonParser.parse(json);
if (o instanceof JsonObject jo &&
jo.get("recording") instanceof JsonObject req &&
req.get("events") instanceof JsonArray jsonEvents) {

List<RecordedEvent> events = RecordingFile.readAllEvents(recordingFile);
Collections.sort(events, new EndTicksComparator());
// Verify events are equal
Iterator<RecordedEvent> it = events.iterator();
for (JsonValue jsonEvent : jsonEvents.values()) {
RecordedEvent recordedEvent = it.next();
String typeName = recordedEvent.getEventType().getName();
Asserts.assertEquals(typeName, ((JsonString)((JsonObject)jsonEvent).get("type")).value());
// assertEquals(jsonEvent, recordedEvent);
}
Asserts.assertFalse(events.size() != jsonEvents.values().size(), "Incorrect number of events");
} else {
throw new JsonException("xxx");
}
Asserts.assertFalse(events.size() != jsonEvents.size(), "Incorrect number of events");

// List<RecordedEvent> events = RecordingFile.readAllEvents(recordingFile);
// Collections.sort(events, new EndTicksComparator());
// // Verify events are equal
// Iterator<RecordedEvent> it = events.iterator();
// for (JSONValue jsonEvent : jsonEvents) {
// RecordedEvent recordedEvent = it.next();
// String typeName = recordedEvent.getEventType().getName();
// Asserts.assertEquals(typeName, jsonEvent.get("type").asString());
// assertEquals(jsonEvent, recordedEvent);
// }
// Asserts.assertFalse(events.size() != jsonEvents.size(), "Incorrect number of events");
}

private static void assertEquals(Object jsonObject, Object jfrObject) throws Exception {
Expand Down

0 comments on commit 9cf3207

Please sign in to comment.