OshiPlatformCache { public GlobalMemory getMemory() { GlobalMemory ret; wLock.lock(); try { if (!sysInfoCache.containsKey(PlatformResourceType.MEMORY)) { HashMap<String, GlobalMemory> cache = new HashMap<>(1); GlobalMemory mem = sysInfo.getHardware().getMemory(); cache.put(PlatformResourceType.MEMORY.getResourceTypeId().getIDString(), mem); sysInfoCache.put(PlatformResourceType.MEMORY, cache); } } finally { rLock.lock(); try { wLock.unlock(); ret = (GlobalMemory) sysInfoCache.get(PlatformResourceType.MEMORY) .get(PlatformResourceType.MEMORY.getResourceTypeId().getIDString()); } finally { rLock.unlock(); } } return ret; } OshiPlatformCache(String feedId, String machineId, String containerId); void refresh(); OperatingSystem getOperatingSystem(); @SuppressWarnings("unchecked") Map<String, OSFileStore> getFileStores(); GlobalMemory getMemory(); CentralProcessor getProcessor(); @SuppressWarnings("unchecked") Map<String, PowerSource> getPowerSources(); Double getPowerSourceMetric(String powerSourceName, ID metricToCollect); Double getProcessorMetric(String processorNumber, ID metricToCollect); Double getFileStoreMetric(String fileStoreNameName, ID metricToCollect); Double getMemoryMetric(ID metricToCollect); Double getOperatingSystemMetric(ID metricId); Double getMetric(PlatformResourceType type, String name, ID metricToCollect); String getMachineId(); String getContainerId();  }
@Test public void getMemory() { OshiPlatformCache oshi = newOshiPlatformCache(); GlobalMemory memory = oshi.getMemory(); Assert.assertNotNull(memory); long avail = memory.getAvailable(); long total = memory.getTotal(); Assert.assertTrue(avail > -1L); Assert.assertTrue(total > -1L); print("===MEMORY ==="); print(" Available=[%s] (%d)", FormatUtil.formatBytes(avail), avail); print(" Total=[%s] (%d)", FormatUtil.formatBytes(total), total); print(" toString=[%s]", memory.toString()); }