< prev index next >
test/java/nio/channels/FileChannel/LoopingTruncate.java
Print this page
rev 12806 : imported patch 8137230-LoopingTruncate-timed-out
*** 21,64 ****
* questions.
*/
/**
* @test
! * @bug 8137121
* @summary (fc) Infinite loop FileChannel.truncate
* @run main/othervm LoopingTruncate
*/
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import static java.nio.file.StandardOpenOption.*;
public class LoopingTruncate {
// (int)FATEFUL_SIZE == -3 == IOStatus.INTERRUPTED
static long FATEFUL_SIZE = 0x1FFFFFFFDL;
! static long TIMEOUT = 10_000; // 10 seconds
public static void main(String[] args) throws Throwable {
Path path = Files.createTempFile("LoopingTruncate.tmp", null);
- try {
- Thread th = new Thread(() -> {
try (FileChannel fc = FileChannel.open(path, CREATE, WRITE)) {
fc.position(FATEFUL_SIZE + 1L);
fc.write(ByteBuffer.wrap(new byte[] {0}));
fc.truncate(FATEFUL_SIZE);
} catch (Exception e) {
throw new RuntimeException(e);
}});
th.start();
th.join(TIMEOUT);
if (th.isAlive()) {
th.interrupt();
throw new RuntimeException("Failed to complete on time");
}
} finally {
Files.deleteIfExists(path);
}
--- 21,74 ----
* questions.
*/
/**
* @test
! * @bug 8137121 8137230
* @summary (fc) Infinite loop FileChannel.truncate
* @run main/othervm LoopingTruncate
*/
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
+ import java.nio.channels.ClosedByInterruptException;
import java.nio.file.Files;
import java.nio.file.Path;
import static java.nio.file.StandardOpenOption.*;
public class LoopingTruncate {
// (int)FATEFUL_SIZE == -3 == IOStatus.INTERRUPTED
static long FATEFUL_SIZE = 0x1FFFFFFFDL;
! static long TIMEOUT = 20_000; // 20 seconds
public static void main(String[] args) throws Throwable {
Path path = Files.createTempFile("LoopingTruncate.tmp", null);
try (FileChannel fc = FileChannel.open(path, CREATE, WRITE)) {
fc.position(FATEFUL_SIZE + 1L);
fc.write(ByteBuffer.wrap(new byte[] {0}));
+
+ Thread th = new Thread(() -> {
+ try {
fc.truncate(FATEFUL_SIZE);
+ } catch (ClosedByInterruptException ignore) {
} catch (Exception e) {
throw new RuntimeException(e);
}});
th.start();
th.join(TIMEOUT);
if (th.isAlive()) {
+ System.err.println("Stack trace of the guilty thread:");
+ for (StackTraceElement el : th.getStackTrace()) {
+ System.err.println("\t" + el);
+ }
+ System.err.println();
+
th.interrupt();
+ th.join();
throw new RuntimeException("Failed to complete on time");
}
} finally {
Files.deleteIfExists(path);
}
< prev index next >