8281149: (fs) java/nio/file/FileStore/Basic.java fails with java.lang.RuntimeException: values differ by more than 1GB

Reviewed-by: jpai, rriggs
This commit is contained in:
Brian Burkhalter 2023-05-19 15:37:37 +00:00
parent 44218b1c9e
commit a5343fa605

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, 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,11 +57,12 @@ public class Basic {
throw new RuntimeException("Assertion failed");
}
static void checkWithin1GB(long expected, long actual) {
static void checkWithin1GB(String space, long expected, long actual) {
long diff = Math.abs(actual - expected);
if (diff > G) {
String msg = String.format("|actual %d - expected %d| = %d (%f G)",
actual, expected, diff, (float)diff/G);
String msg = String.format("%s: |actual %d - expected %d| = %d (%f G)",
space, actual, expected, diff,
(float)diff/G);
throw new RuntimeException(msg);
}
}
@ -110,19 +111,19 @@ public class Basic {
* Test: Space atributes
*/
File f = file1.toFile();
long total = f.getTotalSpace();
long free = f.getFreeSpace();
long usable = f.getUsableSpace();
// check values are "close"
checkWithin1GB(total, store1.getTotalSpace());
checkWithin1GB(free, store1.getUnallocatedSpace());
checkWithin1GB(usable, store1.getUsableSpace());
checkWithin1GB("total", f.getTotalSpace(), store1.getTotalSpace());
checkWithin1GB("free", f.getFreeSpace(), store1.getUnallocatedSpace());
checkWithin1GB("usable", f.getUsableSpace(), store1.getUsableSpace());
// get values by name
checkWithin1GB(total, (Long)store1.getAttribute("totalSpace"));
checkWithin1GB(free, (Long)store1.getAttribute("unallocatedSpace"));
checkWithin1GB(usable, (Long)store1.getAttribute("usableSpace"));
checkWithin1GB("total", f.getTotalSpace(),
(Long)store1.getAttribute("totalSpace"));
checkWithin1GB("free", f.getFreeSpace(),
(Long)store1.getAttribute("unallocatedSpace"));
checkWithin1GB("usable", f.getUsableSpace(),
(Long)store1.getAttribute("usableSpace"));
/**
* Test: Enumerate all FileStores