Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8202142: jfr/event/io/TestInstrumentation is unstable
Reviewed-by: phh, mli
Backport-of: 0b9ff0c
  • Loading branch information
Dongbo He authored and Hamlin Li committed Dec 17, 2021
1 parent 4b68145 commit 86c2995
Show file tree
Hide file tree
Showing 12 changed files with 365 additions and 358 deletions.
1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Expand Up @@ -888,7 +888,6 @@ com/sun/jdi/RedefineCrossEvent.java 8194308 gener

# jdk_jfr

jdk/jfr/event/io/TestInstrumentation.java 8202142 generic-all
jdk/jfr/event/sampling/TestNative.java 8202142 generic-all
jdk/jfr/event/runtime/TestNetworkUtilizationEvent.java 8228990,8229370 generic-all
jdk/jfr/event/compiler/TestCodeSweeper.java 8225209 generic-all
Expand Down
9 changes: 3 additions & 6 deletions test/jdk/jdk/jfr/event/io/IOEvent.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 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
Expand Down Expand Up @@ -197,14 +197,11 @@ public static String getEventAddress(RecordedEvent event) {
}
return canonical_path;
} else {
return String.format("%s/%s:%d",
event.getValue("host"),
event.getValue("address"),
event.getValue("port"));
return event.getValue("address") + ":" + event.getValue("port");
}
}

private static String getAddress(Socket s) {
return s.getInetAddress().toString() + ":" + s.getPort();
return s.getInetAddress().getHostAddress() + ":" + s.getPort();
}
}
8 changes: 7 additions & 1 deletion test/jdk/jdk/jfr/event/io/IOHelper.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 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
Expand Down Expand Up @@ -28,6 +28,8 @@
import static jdk.test.lib.Asserts.assertEquals;
import static jdk.test.lib.Asserts.assertTrue;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -41,13 +43,17 @@
public class IOHelper {

public static void verifyEqualsInOrder(List<RecordedEvent> events, List<IOEvent> expectedEvents) throws Throwable {
Collections.sort(events, Comparator.comparing(RecordedEvent::getStartTime));
List<IOEvent> actualEvents = getTestEvents(events, expectedEvents);
try {
assertEquals(actualEvents.size(), expectedEvents.size(), "Wrong number of events.");
for (int i = 0; i < actualEvents.size(); ++i) {
assertEquals(actualEvents.get(i), expectedEvents.get(i), "Wrong event at pos " + i);
}
} catch (Throwable t) {
for (RecordedEvent e: events) {
System.out.println(e);
}
logEvents(actualEvents, expectedEvents);
throw t;
}
Expand Down
33 changes: 17 additions & 16 deletions test/jdk/jdk/jfr/event/io/TestDisabledEvents.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 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
Expand Down Expand Up @@ -57,21 +57,22 @@ public class TestDisabledEvents {
public static void main(String[] args) throws Throwable {
File tmp = File.createTempFile("TestDisabledEvents", ".tmp", new File("."));
tmp.deleteOnExit();
Recording recording = new Recording();
recording.disable(IOEvent.EVENT_FILE_READ);
recording.disable(IOEvent.EVENT_FILE_WRITE);
recording.start();

useRandomAccessFile(tmp);
useFileStreams(tmp);
useFileChannel(tmp);

recording.stop();
for (RecordedEvent event : Events.fromRecording(recording)) {
final String eventName = event.getEventType().getName();
System.out.println("Got eventName:" + eventName);
assertNotEquals(eventName, IOEvent.EVENT_FILE_READ, "Got disabled read event");
assertNotEquals(eventName, IOEvent.EVENT_FILE_WRITE, "Got disabled write event");
try (Recording recording = new Recording()) {
recording.disable(IOEvent.EVENT_FILE_READ);
recording.disable(IOEvent.EVENT_FILE_WRITE);
recording.start();

useRandomAccessFile(tmp);
useFileStreams(tmp);
useFileChannel(tmp);

recording.stop();
for (RecordedEvent event : Events.fromRecording(recording)) {
final String eventName = event.getEventType().getName();
System.out.println("Got eventName:" + eventName);
assertNotEquals(eventName, IOEvent.EVENT_FILE_READ, "Got disabled read event");
assertNotEquals(eventName, IOEvent.EVENT_FILE_WRITE, "Got disabled write event");
}
}
}

Expand Down
138 changes: 69 additions & 69 deletions test/jdk/jdk/jfr/event/io/TestFileChannelEvents.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 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
Expand Down Expand Up @@ -50,74 +50,74 @@ public class TestFileChannelEvents {
public static void main(String[] args) throws Throwable {
File tmp = File.createTempFile("TestFileChannelEvents", ".tmp", new File("."));
tmp.deleteOnExit();
Recording recording = new Recording();
List<IOEvent> expectedEvents = new ArrayList<>();

try (RandomAccessFile rf = new RandomAccessFile(tmp, "rw"); FileChannel ch = rf.getChannel();) {
recording.enable(IOEvent.EVENT_FILE_FORCE).withThreshold(Duration.ofMillis(0));
recording.enable(IOEvent.EVENT_FILE_READ).withThreshold(Duration.ofMillis(0));
recording.enable(IOEvent.EVENT_FILE_WRITE).withThreshold(Duration.ofMillis(0));
recording.start();

ByteBuffer bufA = ByteBuffer.allocateDirect(10);
ByteBuffer bufB = ByteBuffer.allocateDirect(20);
bufA.put("1234567890".getBytes());
bufB.put("1234567890".getBytes());

// test write(ByteBuffer)
bufA.flip();
long size = ch.write(bufA);
expectedEvents.add(IOEvent.createFileWriteEvent(size, tmp));

// test write(ByteBuffer, long)
bufA.flip();
size = ch.write(bufA, bufA.capacity() / 2);
expectedEvents.add(IOEvent.createFileWriteEvent(size, tmp));

// test write(ByteBuffer[])
bufA.flip();
bufA.limit(5);
bufB.flip();
bufB.limit(5);
size = ch.write(new ByteBuffer[] { bufA, bufB });
expectedEvents.add(IOEvent.createFileWriteEvent(size, tmp));

// test force(boolean)
ch.force(true);
expectedEvents.add(IOEvent.createFileForceEvent(tmp));

// reset file
ch.position(0);

// test read(ByteBuffer)
bufA.clear();
size = ch.read(bufA);
expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));

// test read(ByteBuffer, long)
bufA.clear();
size = ch.read(bufA, bufA.capacity() / 2);
expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));

// test read(ByteBuffer[])
bufA.clear();
bufA.limit(5);
bufB.clear();
bufB.limit(5);
size = ch.read(new ByteBuffer[] { bufA, bufB });
expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));

// Read at EOF. Should get size -1 in event.
ch.position(ch.size());
bufA.clear();
size = ch.read(bufA);
assertEquals(size, -1L, "Expected size -1 when read at EOF");
expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));

ch.close();
recording.stop();
List<RecordedEvent> events = Events.fromRecording(recording);
IOHelper.verifyEqualsInOrder(events, expectedEvents);
try (Recording recording = new Recording()) {
List<IOEvent> expectedEvents = new ArrayList<>();
try (RandomAccessFile rf = new RandomAccessFile(tmp, "rw"); FileChannel ch = rf.getChannel();) {
recording.enable(IOEvent.EVENT_FILE_FORCE).withThreshold(Duration.ofMillis(0));
recording.enable(IOEvent.EVENT_FILE_READ).withThreshold(Duration.ofMillis(0));
recording.enable(IOEvent.EVENT_FILE_WRITE).withThreshold(Duration.ofMillis(0));
recording.start();

ByteBuffer bufA = ByteBuffer.allocateDirect(10);
ByteBuffer bufB = ByteBuffer.allocateDirect(20);
bufA.put("1234567890".getBytes());
bufB.put("1234567890".getBytes());

// test write(ByteBuffer)
bufA.flip();
long size = ch.write(bufA);
expectedEvents.add(IOEvent.createFileWriteEvent(size, tmp));

// test write(ByteBuffer, long)
bufA.flip();
size = ch.write(bufA, bufA.capacity() / 2);
expectedEvents.add(IOEvent.createFileWriteEvent(size, tmp));

// test write(ByteBuffer[])
bufA.flip();
bufA.limit(5);
bufB.flip();
bufB.limit(5);
size = ch.write(new ByteBuffer[] { bufA, bufB });
expectedEvents.add(IOEvent.createFileWriteEvent(size, tmp));

// test force(boolean)
ch.force(true);
expectedEvents.add(IOEvent.createFileForceEvent(tmp));

// reset file
ch.position(0);

// test read(ByteBuffer)
bufA.clear();
size = ch.read(bufA);
expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));

// test read(ByteBuffer, long)
bufA.clear();
size = ch.read(bufA, bufA.capacity() / 2);
expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));

// test read(ByteBuffer[])
bufA.clear();
bufA.limit(5);
bufB.clear();
bufB.limit(5);
size = ch.read(new ByteBuffer[] { bufA, bufB });
expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));

// Read at EOF. Should get size -1 in event.
ch.position(ch.size());
bufA.clear();
size = ch.read(bufA);
assertEquals(size, -1L, "Expected size -1 when read at EOF");
expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));

ch.close();
recording.stop();
List<RecordedEvent> events = Events.fromRecording(recording);
IOHelper.verifyEqualsInOrder(events, expectedEvents);
}
}
}
}
77 changes: 39 additions & 38 deletions test/jdk/jdk/jfr/event/io/TestFileReadOnly.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 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
Expand Down Expand Up @@ -52,50 +52,51 @@ public class TestFileReadOnly {
public static void main(String[] args) throws Throwable {
File tmp = File.createTempFile("TestFileReadOnly", ".tmp", new File("."));
tmp.deleteOnExit();
Recording recording = new Recording();
List<IOEvent> expectedEvents = new ArrayList<>();
try (Recording recording = new Recording()) {
List<IOEvent> expectedEvents = new ArrayList<>();

recording.enable(IOEvent.EVENT_FILE_READ).withThreshold(Duration.ofMillis(0));
recording.enable(IOEvent.EVENT_FILE_WRITE).withThreshold(Duration.ofMillis(0));
recording.start();
recording.enable(IOEvent.EVENT_FILE_READ).withThreshold(Duration.ofMillis(0));
recording.enable(IOEvent.EVENT_FILE_WRITE).withThreshold(Duration.ofMillis(0));
recording.start();

final byte[] buf = { 1, 2, 3 };
final byte[] buf = { 1, 2, 3 };

// Create the file.
try (RandomAccessFile f = new RandomAccessFile(tmp, "rw")) {
f.write(buf);
expectedEvents.add(IOEvent.createFileWriteEvent(buf.length, tmp));
}

// Reopen the file as ReadOnly and try to write to it.
// Should generate an event with bytesWritten = -1.
try (RandomAccessFile f = new RandomAccessFile(tmp, "r")) {
try {
// Create the file.
try (RandomAccessFile f = new RandomAccessFile(tmp, "rw")) {
f.write(buf);
fail("No exception for ReadOnly File");
} catch (IOException e) {
// Expected exception
expectedEvents.add(IOEvent.createFileWriteEvent(-1, tmp));
expectedEvents.add(IOEvent.createFileWriteEvent(buf.length, tmp));
}
}

// Try to write to read-only FileChannel.
try (RandomAccessFile f = new RandomAccessFile(tmp, "r"); FileChannel ch = f.getChannel()) {
ByteBuffer writeBuf = ByteBuffer.allocateDirect(buf.length);
writeBuf.put(buf);
writeBuf.flip();
ch.position(0);
try {
ch.write(writeBuf);
fail("No exception for ReadOnly FileChannel");
} catch (java.nio.channels.NonWritableChannelException e) {
// Expected exception
expectedEvents.add(IOEvent.createFileWriteEvent(-1, tmp));
// Reopen the file as ReadOnly and try to write to it.
// Should generate an event with bytesWritten = -1.
try (RandomAccessFile f = new RandomAccessFile(tmp, "r")) {
try {
f.write(buf);
fail("No exception for ReadOnly File");
} catch (IOException e) {
// Expected exception
expectedEvents.add(IOEvent.createFileWriteEvent(-1, tmp));
}
}
}

recording.stop();
List<RecordedEvent> events = Events.fromRecording(recording);
IOHelper.verifyEqualsInOrder(events, expectedEvents);
// Try to write to read-only FileChannel.
try (RandomAccessFile f = new RandomAccessFile(tmp, "r"); FileChannel ch = f.getChannel()) {
ByteBuffer writeBuf = ByteBuffer.allocateDirect(buf.length);
writeBuf.put(buf);
writeBuf.flip();
ch.position(0);
try {
ch.write(writeBuf);
fail("No exception for ReadOnly FileChannel");
} catch (java.nio.channels.NonWritableChannelException e) {
// Expected exception
expectedEvents.add(IOEvent.createFileWriteEvent(-1, tmp));
}
}

recording.stop();
List<RecordedEvent> events = Events.fromRecording(recording);
IOHelper.verifyEqualsInOrder(events, expectedEvents);
}
}
}

1 comment on commit 86c2995

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.