8251843: jfr/tool/TestPrintJSON.java fails intermittently

Reviewed-by: mgronlun
This commit is contained in:
Erik Gahlin 2020-12-04 10:37:59 +00:00
parent c6f93ec9f2
commit feabddee56
3 changed files with 50 additions and 6 deletions

@ -0,0 +1,44 @@
/*
* Copyright (c) 2020, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.jfr.tool;
import java.util.Comparator;
import jdk.jfr.consumer.RecordedEvent;
public class EndTicksComparator implements Comparator<RecordedEvent> {
public long readEndTicks(RecordedEvent event) {
long timestamp = event.getLong("startTime");
if (event.hasField("duration")) {
timestamp += event.getLong("duration");
}
return timestamp;
}
@Override
public int compare(RecordedEvent a, RecordedEvent b) {
return Long.compare(readEndTicks(a), readEndTicks(b));
}
}

@ -65,13 +65,13 @@ public class TestPrintJSON {
JSONValue recording = o.get("recording");
JSONArray jsonEvents = recording.get("events").asArray();
List<RecordedEvent> events = RecordingFile.readAllEvents(recordingFile);
Collections.sort(events, (e1, e2) -> e1.getEndTime().compareTo(e2.getEndTime()));
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());
Asserts.assertEquals(typeName, jsonEvent.get("type").asString());
assertEquals(jsonEvent, recordedEvent);
}
Asserts.assertFalse(events.size() != jsonEvents.size(), "Incorrect number of events");
@ -80,7 +80,7 @@ public class TestPrintJSON {
private static void assertEquals(Object jsonObject, Object jfrObject) throws Exception {
// Check object
if (jfrObject instanceof RecordedObject) {
JSONValue values = ((JSONValue)jsonObject).get("values");
JSONValue values = ((JSONValue) jsonObject).get("values");
RecordedObject recObject = (RecordedObject) jfrObject;
Asserts.assertEquals(values.size(), recObject.getFields().size());
for (ValueDescriptor v : recObject.getFields()) {
@ -89,7 +89,7 @@ public class TestPrintJSON {
Object expectedValue = recObject.getValue(name);
if (v.getAnnotation(Timestamp.class) != null) {
// Make instant of OffsetDateTime
String text = ((JSONValue)jsonValue).asString();
String text = ((JSONValue) jsonValue).asString();
jsonValue = OffsetDateTime.parse(text).toInstant().toString();
expectedValue = recObject.getInstant(name);
}
@ -103,7 +103,7 @@ public class TestPrintJSON {
// Check array
if (jfrObject != null && jfrObject.getClass().isArray()) {
Object[] jfrArray = (Object[]) jfrObject;
JSONArray jsArray = ((JSONArray)jsonObject);
JSONArray jsArray = ((JSONArray) jsonObject);
for (int i = 0; i < jfrArray.length; i++) {
assertEquals(jsArray.get(i), jfrArray[i]);
}

@ -96,7 +96,7 @@ public class TestPrintXML {
// Verify that all data was written correctly
List<RecordedEvent> events = RecordingFile.readAllEvents(recordingFile);
Collections.sort(events, (e1, e2) -> e1.getEndTime().compareTo(e2.getEndTime()));
Collections.sort(events, new EndTicksComparator());
Iterator<RecordedEvent> it = events.iterator();
for (XMLEvent xmlEvent : handler.events) {
RecordedEvent re = it.next();