Mercurial > hg > release > thermostat-0.4
changeset 601:c36e9751cda4
Use better units for showing host memory
Fix 2 places in the host information where we display memory in bytes.
Round them and display as valid prefix + unit.
Reviewed-by: vanaltj
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-September/003095.html
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Tue, 11 Sep 2012 12:00:07 -0400 |
parents | 6bb30e80f53a |
children | 2eeca26d586f |
files | client/core/src/main/java/com/redhat/thermostat/client/locale/LocaleResources.java client/core/src/main/java/com/redhat/thermostat/client/ui/HostMemoryController.java client/core/src/main/java/com/redhat/thermostat/client/ui/HostOverviewController.java client/core/src/main/resources/com/redhat/thermostat/client/locale/strings.properties client/core/src/test/java/com/redhat/thermostat/client/ui/HostMemoryControllerTest.java client/core/src/test/java/com/redhat/thermostat/client/ui/HostOverviewControllerTest.java |
diffstat | 6 files changed, 19 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/client/core/src/main/java/com/redhat/thermostat/client/locale/LocaleResources.java Tue Sep 11 17:56:15 2012 +0200 +++ b/client/core/src/main/java/com/redhat/thermostat/client/locale/LocaleResources.java Tue Sep 11 12:00:07 2012 -0400 @@ -78,6 +78,8 @@ HOURS, DAYS, + NUMBER_AND_UNIT, + SEARCH_HINT, CHART_DURATION_SELECTOR_LABEL,
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/HostMemoryController.java Tue Sep 11 17:56:15 2012 +0200 +++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/HostMemoryController.java Tue Sep 11 12:00:07 2012 -0400 @@ -59,6 +59,7 @@ import com.redhat.thermostat.common.model.DiscreteTimeData; import com.redhat.thermostat.common.model.MemoryStat; import com.redhat.thermostat.common.model.MemoryType; +import com.redhat.thermostat.common.utils.DisplayableValues; public class HostMemoryController { @@ -107,7 +108,9 @@ backgroundUpdateTimer.setAction(new Runnable() { @Override public void run() { - view.setTotalMemory(String.valueOf(hostInfoDAO.getHostInfo(ref).getTotalMemory())); + long memorySize = hostInfoDAO.getHostInfo(ref).getTotalMemory(); + String[] memorySizeParts = DisplayableValues.bytes(memorySize); + view.setTotalMemory(localize(LocaleResources.NUMBER_AND_UNIT, memorySizeParts[0], memorySizeParts[1])); doMemoryChartUpdate(); } });
--- a/client/core/src/main/java/com/redhat/thermostat/client/ui/HostOverviewController.java Tue Sep 11 17:56:15 2012 +0200 +++ b/client/core/src/main/java/com/redhat/thermostat/client/ui/HostOverviewController.java Tue Sep 11 12:00:07 2012 -0400 @@ -59,6 +59,7 @@ import com.redhat.thermostat.common.dao.NetworkInterfaceInfoDAO; import com.redhat.thermostat.common.model.HostInfo; import com.redhat.thermostat.common.model.NetworkInterfaceInfo; +import com.redhat.thermostat.common.utils.DisplayableValues; import com.redhat.thermostat.common.utils.LoggingUtils; public class HostOverviewController { @@ -96,7 +97,10 @@ view.setOsKernel(hostInfo.getOsKernel()); view.setCpuModel(hostInfo.getCpuModel()); view.setCpuCount(String.valueOf(hostInfo.getCpuCount())); - view.setTotalMemory(String.valueOf(hostInfo.getTotalMemory())); + + String[] parts = DisplayableValues.bytes(hostInfo.getTotalMemory()); + String readableTotalMemory = localize(LocaleResources.NUMBER_AND_UNIT, parts[0], parts[1]); + view.setTotalMemory(readableTotalMemory); List<NetworkInterfaceInfo> networkInfo = networkInfoDAO.getNetworkInterfaces(ref);
--- a/client/core/src/main/resources/com/redhat/thermostat/client/locale/strings.properties Tue Sep 11 17:56:15 2012 +0200 +++ b/client/core/src/main/resources/com/redhat/thermostat/client/locale/strings.properties Tue Sep 11 12:00:07 2012 -0400 @@ -38,6 +38,8 @@ HOURS = Hours DAYS = Days +NUMBER_AND_UNIT = {0} {1} + SEARCH_HINT = Type here to search CHART_DURATION_SELECTOR_LABEL = Display the most recent
--- a/client/core/src/test/java/com/redhat/thermostat/client/ui/HostMemoryControllerTest.java Tue Sep 11 17:56:15 2012 +0200 +++ b/client/core/src/test/java/com/redhat/thermostat/client/ui/HostMemoryControllerTest.java Tue Sep 11 12:00:07 2012 -0400 @@ -76,7 +76,8 @@ @SuppressWarnings("unchecked") // any(List.class) @Test public void testUpdate() { - HostInfo hostInfo = new HostInfo("someHost", "someOS", "linux_0.0.1", "lreally_fast_cpu", 2, 1024); + final long TOTAL_MEMORY = 512; + HostInfo hostInfo = new HostInfo("someHost", "someOS", "linux_0.0.1", "lreally_fast_cpu", 2, TOTAL_MEMORY); HostInfoDAO hostInfoDAO = mock(HostInfoDAO.class); when(hostInfoDAO.getHostInfo(any(HostRef.class))).thenReturn(hostInfo); @@ -118,7 +119,7 @@ verify(timer).start(); timerActionCaptor.getValue().run(); - verify(view, times(1)).setTotalMemory(any(String.class)); + verify(view, times(1)).setTotalMemory(eq(TOTAL_MEMORY + " B")); verify(view, times(6)).addMemoryData(any(String.class), any(List.class)); l.actionPerformed(new ActionEvent<>(view, HostMemoryView.Action.HIDDEN));
--- a/client/core/src/test/java/com/redhat/thermostat/client/ui/HostOverviewControllerTest.java Tue Sep 11 17:56:15 2012 +0200 +++ b/client/core/src/test/java/com/redhat/thermostat/client/ui/HostOverviewControllerTest.java Tue Sep 11 12:00:07 2012 -0400 @@ -157,7 +157,9 @@ verify(view).setOsKernel(eq(KERNEL_NAME)); verify(view).setOsName(eq(OS_NAME)); - verify(view).setTotalMemory(eq(String.valueOf(TOTAL_MEMORY))); + + final String UNITS = " B"; + verify(view).setTotalMemory(eq(String.valueOf(TOTAL_MEMORY + UNITS))); } @Test