Skip to content
Permalink
Browse files

8202142: jfr/event/io/TestInstrumentation is unstable

Reviewed-by: mgronlun, mseledtsov
  • Loading branch information
Erik Gahlin
Erik Gahlin committed Jan 30, 2020
1 parent d65f966 commit 0b9ff0c3a418070996f61f69165de02d33070f7f
@@ -932,7 +932,6 @@ javax/rmi/ssl/SSLSocketParametersTest.sh 8162906 generic-

# jdk_jfr

jdk/jfr/event/io/TestInstrumentation.java 8202142 generic-all
jdk/jfr/event/io/EvilInstrument.java 8221331 generic-all
jdk/jfr/event/runtime/TestNetworkUtilizationEvent.java 8228990,8229370 generic-all
jdk/jfr/event/compiler/TestCodeSweeper.java 8225209 generic-all
@@ -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
@@ -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();
}
}
@@ -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
@@ -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;

@@ -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;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, 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
@@ -57,21 +57,22 @@

public static void main(String[] args) throws Throwable {
File tmp = Utils.createTempFile("TestDisabledEvents", ".tmp").toFile();
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");
}
}
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, 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
@@ -50,74 +50,74 @@
public class TestFileChannelEvents {
public static void main(String[] args) throws Throwable {
File tmp = Utils.createTempFile("TestFileChannelEvents", ".tmp").toFile();
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);
}
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, 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
@@ -52,50 +52,51 @@

public static void main(String[] args) throws Throwable {
File tmp = Utils.createTempFile("TestFileReadOnly", ".tmp").toFile();
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);
}
}
}

0 comments on commit 0b9ff0c

Please sign in to comment.