8202284: FileChannel and FileOutpuStream variants of AtomicAppend should fail silently on macOS >= 10.13

Reviewed-by: chegar
This commit is contained in:
Brian Burkhalter 2018-04-30 13:40:39 -07:00
parent 8038a3507d
commit cdd3f0ac39
3 changed files with 86 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2018, 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
@ -25,6 +25,9 @@
* @test
* @bug 6631352
* @summary Check that appends are atomic
* @library /test/lib
* @build jdk.test.lib.Platform
* @run main AtomicAppend
*/
import java.io.File;
@ -33,6 +36,8 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import jdk.test.lib.Platform;
public class AtomicAppend {
// Before the fix for
// 6631352: Implement atomic append mode using FILE_APPEND_DATA (win)
@ -73,7 +78,17 @@ public class AtomicAppend {
if (x == null ? y == null : x.equals(y)) pass();
else fail(x + " not equal to " + y);}
public static void main(String[] args) throws Throwable {
new AtomicAppend().instanceMain(args);}
if (Platform.isOSX()) {
final String version = "10.13";
int ineq = Platform.compareOsVersion(version);
if (ineq >= 0) {
System.out.format("Skipping test for macOS version %s >= %s%n",
Platform.getOsVersion(), version);
return;
}
}
new AtomicAppend().instanceMain(args);
}
void instanceMain(String[] args) throws Throwable {
try {test(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2018, 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
@ -24,6 +24,9 @@
/*
* @test
* @summary Check that appends are atomic
* @library /test/lib
* @build jdk.test.lib.Platform
* @run main AtomicAppend
* @key randomness
*/
@ -40,6 +43,8 @@ import java.nio.channels.FileChannel;
import java.nio.file.Files;
import static java.nio.file.StandardOpenOption.*;
import jdk.test.lib.Platform;
public class AtomicAppend {
static final Random rand = new Random();
@ -76,6 +81,15 @@ public class AtomicAppend {
}
public static void main(String[] args) throws Throwable {
if (Platform.isOSX()) {
final String version = "10.13";
int ineq = Platform.compareOsVersion(version);
if (ineq >= 0) {
System.out.format("Skipping test for macOS version %s >= %s%n",
Platform.getOsVersion(), version);
return;
}
}
final int nThreads = 16;
final int writes = 1000;
final File file = File.createTempFile("foo", null);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2018, 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
@ -26,12 +26,17 @@ package jdk.test.lib;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class Platform {
public static final String vmName = System.getProperty("java.vm.name");
public static final String vmInfo = System.getProperty("java.vm.info");
private static final String osVersion = System.getProperty("os.version");
private static String[] osVersionTokens;
private static int osVersionMajor = -1;
private static int osVersionMinor = -1;
private static final String osName = System.getProperty("os.name");
@ -124,12 +129,12 @@ public class Platform {
// Os version support.
private static void init_version() {
osVersionTokens = osVersion.split("\\.");
try {
final String[] tokens = osVersion.split("\\.");
if (tokens.length > 0) {
osVersionMajor = Integer.parseInt(tokens[0]);
if (tokens.length > 1) {
osVersionMinor = Integer.parseInt(tokens[1]);
if (osVersionTokens.length > 0) {
osVersionMajor = Integer.parseInt(osVersionTokens[0]);
if (osVersionTokens.length > 1) {
osVersionMinor = Integer.parseInt(osVersionTokens[1]);
}
}
} catch (NumberFormatException e) {
@ -137,6 +142,10 @@ public class Platform {
}
}
public static String getOsVersion() {
return osVersion;
}
// Returns major version number from os.version system property.
// E.g. 5 on Solaris 10 and 3 on SLES 11.3 (for the linux kernel version).
public static int getOsVersionMajor() {
@ -151,6 +160,45 @@ public class Platform {
return osVersionMinor;
}
/**
* Compares the platform version with the supplied version. The
* version must be of the form a[.b[.c[.d...]]] where a, b, c, d, ...
* are decimal integers.
*
* @throws NullPointerException if the parameter is null
* @throws NumberFormatException if there is an error parsing either
* version as split into component strings
* @return -1, 0, or 1 according to whether the platform version is
* less than, equal to, or greater than the supplied version
*/
public static int compareOsVersion(String version) {
if (osVersionTokens == null) init_version();
Objects.requireNonNull(version);
List<Integer> s1 = Arrays
.stream(osVersionTokens)
.map(Integer::valueOf)
.collect(Collectors.toList());
List<Integer> s2 = Arrays
.stream(version.split("\\."))
.map(Integer::valueOf)
.collect(Collectors.toList());
int count = Math.max(s1.size(), s2.size());
for (int i = 0; i < count; i++) {
int i1 = i < s1.size() ? s1.get(i) : 0;
int i2 = i < s2.size() ? s2.get(i) : 0;
if (i1 > i2) {
return 1;
} else if (i2 > i1) {
return -1;
}
}
return 0;
}
public static boolean isDebugBuild() {
return (jdkDebug.toLowerCase().contains("debug"));
}