Navigation Menu

Skip to content

Commit

Permalink
8281149: (fs) java/nio/file/FileStore/Basic.java fails with java.lang…
Browse files Browse the repository at this point in the history
….RuntimeException: values differ by more than 1GB

Backport-of: a5343fa60505764c088dad4a17680d92568509d5
  • Loading branch information
GoeLin committed Oct 6, 2023
1 parent 6cc9975 commit e95369b
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions test/jdk/java/nio/file/FileStore/Basic.java
@@ -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
Expand Down Expand Up @@ -57,11 +57,12 @@ static void assertTrue(boolean okay) {
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);
}
}
Expand Down Expand Up @@ -110,19 +111,19 @@ static void doTests(Path dir) throws IOException {
* 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
Expand Down

1 comment on commit e95369b

@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.