Skip to content
Snippets Groups Projects
Commit ed12624b authored by ribeaudc's avatar ribeaudc
Browse files

add: - 'FileUtilities.byteCountToDisplaySize' method added (more precise than...

add: - 'FileUtilities.byteCountToDisplaySize' method added (more precise than the Apache common io one).
change: - Add missing space in the notification message when free space is below than the high water mark.

SVN: 6249
parent 64e0a25a
No related branches found
No related tags found
No related merge requests found
......@@ -94,7 +94,7 @@ public final class HighwaterMarkWatcher implements Runnable
public final static String displayKilobyteValue(final long value)
{
return FileUtils.byteCountToDisplaySize(value * FileUtils.ONE_KB);
return FileUtilities.byteCountToDisplaySize(value * FileUtils.ONE_KB);
}
public final static boolean isBelow(final HighwaterMarkState highwaterMarkState)
......@@ -199,9 +199,11 @@ public final class HighwaterMarkWatcher implements Runnable
}
if (operationLog.isDebugEnabled())
{
operationLog.debug(String.format("Amount of available space on '%s' is: %s.",
operationLog.debug(String.format(
"Amount of available space on '%s' is %s (high water mark: %s).",
state.fileWithHighwaterMark.getCanonicalPath(),
displayKilobyteValue(state.freeSpace)));
displayKilobyteValue(state.freeSpace),
displayKilobyteValue(highwaterMarkInKb)));
}
} catch (final IOException ex)
{
......@@ -312,7 +314,8 @@ public final class HighwaterMarkWatcher implements Runnable
static final String WARNING_LOG_FORMAT =
"The amount of available space (%s) on '%s' "
+ "is lower than the specified high water mark (%s).";
+ "is lower than the specified high water mark (%s). "
+ "Missing space is %s.";
private static final Logger notificationLog =
LogFactory.getLogger(LogCategory.NOTIFY, NotificationLogChangeListener.class);
......@@ -333,8 +336,10 @@ public final class HighwaterMarkWatcher implements Runnable
final String freeSpaceDisplayed = displayKilobyteValue(event.getFreeSpace());
if (event.isBelow())
{
final String missingSpace =
displayKilobyteValue(event.getHighwaterMark() - event.getFreeSpace());
notificationLog.warn(String.format(WARNING_LOG_FORMAT, freeSpaceDisplayed, path,
highwaterMarkDisplayed));
highwaterMarkDisplayed, missingSpace));
} else
{
notificationLog.info(String.format(INFO_LOG_FORMAT, freeSpaceDisplayed, path,
......
......@@ -524,4 +524,14 @@ public final class FileUtilitiesTest extends AbstractFileSystemTestCase
assertTrue(name.endsWith(fileSuffix));
assertEquals(filePrefix.length() + fileSuffix.length() + 4, name.length());
}
@Test
public final void testByteCountToDisplaySize()
{
assertEquals("0.00 bytes", FileUtilities.byteCountToDisplaySize(0));
assertEquals("1.00 bytes", FileUtilities.byteCountToDisplaySize(1));
assertEquals("1.00 KB", FileUtilities.byteCountToDisplaySize(1024));
assertEquals("1.01 KB", FileUtilities.byteCountToDisplaySize(1034));
assertEquals("1.00 MB", FileUtilities.byteCountToDisplaySize(1024 * 1024));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment