@@ -324,10 +324,19 @@ public void testDiskSpaceMonitorStartsAsDisabled() throws Exception {
324
324
}
325
325
326
326
public void testAvailableDiskSpaceMonitorWhenFileSystemStatErrors () throws Exception {
327
- aFileStore .usableSpace = randomLongBetween (1L , 100L );
328
- aFileStore .totalSpace = randomLongBetween (1L , 100L );
329
- bFileStore .usableSpace = randomLongBetween (1L , 100L );
330
- bFileStore .totalSpace = randomLongBetween (1L , 100L );
327
+ long aUsableSpace ;
328
+ long bUsableSpace ;
329
+ do {
330
+ aFileStore .usableSpace = randomLongBetween (1L , 1000L );
331
+ aFileStore .totalSpace = randomLongBetween (1L , 1000L );
332
+ bFileStore .usableSpace = randomLongBetween (1L , 1000L );
333
+ bFileStore .totalSpace = randomLongBetween (1L , 1000L );
334
+ // the default 5% (same as flood stage level)
335
+ aUsableSpace = Math .max (aFileStore .usableSpace - aFileStore .totalSpace / 20 , 0L );
336
+ bUsableSpace = Math .max (bFileStore .usableSpace - bFileStore .totalSpace / 20 , 0L );
337
+ } while (aUsableSpace == bUsableSpace ); // they must be different in order to distinguish the available disk space updates
338
+ long finalBUsableSpace = bUsableSpace ;
339
+ long finalAUsableSpace = aUsableSpace ;
331
340
boolean aErrorsFirst = randomBoolean ();
332
341
if (aErrorsFirst ) {
333
342
// the "a" file system will error when collecting stats
@@ -355,18 +364,10 @@ public void testAvailableDiskSpaceMonitorWhenFileSystemStatErrors() throws Excep
355
364
assertThat (availableDiskSpaceUpdates .size (), is (1 ));
356
365
if (aErrorsFirst ) {
357
366
// uses the stats from "b"
358
- assertThat (
359
- getLast (availableDiskSpaceUpdates ).getBytes (),
360
- // the default 5% (same as flood stage level)
361
- is (Math .max (bFileStore .usableSpace - bFileStore .totalSpace / 20 , 0L ))
362
- );
367
+ assertThat (getLast (availableDiskSpaceUpdates ).getBytes (), is (finalBUsableSpace ));
363
368
} else {
364
369
// uses the stats from "a"
365
- assertThat (
366
- getLast (availableDiskSpaceUpdates ).getBytes (),
367
- // the default 5% (same as flood stage level)
368
- is (Math .max (aFileStore .usableSpace - aFileStore .totalSpace / 20 , 0L ))
369
- );
370
+ assertThat (getLast (availableDiskSpaceUpdates ).getBytes (), is (finalAUsableSpace ));
370
371
}
371
372
}
372
373
});
@@ -393,21 +394,14 @@ public void testAvailableDiskSpaceMonitorWhenFileSystemStatErrors() throws Excep
393
394
}
394
395
assertBusy (() -> {
395
396
synchronized (availableDiskSpaceUpdates ) {
397
+ // the updates are different values
396
398
assertThat (availableDiskSpaceUpdates .size (), is (3 ));
397
399
if (aErrorsFirst ) {
398
400
// uses the stats from "a"
399
- assertThat (
400
- getLast (availableDiskSpaceUpdates ).getBytes (),
401
- // the default 5% (same as flood stage level)
402
- is (Math .max (aFileStore .usableSpace - aFileStore .totalSpace / 20 , 0L ))
403
- );
401
+ assertThat (getLast (availableDiskSpaceUpdates ).getBytes (), is (finalAUsableSpace ));
404
402
} else {
405
403
// uses the stats from "b"
406
- assertThat (
407
- getLast (availableDiskSpaceUpdates ).getBytes (),
408
- // the default 5% (same as flood stage level)
409
- is (Math .max (bFileStore .usableSpace - bFileStore .totalSpace / 20 , 0L ))
410
- );
404
+ assertThat (getLast (availableDiskSpaceUpdates ).getBytes (), is (finalBUsableSpace ));
411
405
}
412
406
}
413
407
});
0 commit comments