Fixed test
This commit is contained in:
parent
b18ea8efdb
commit
cb84f7aa29
|
@ -22,6 +22,14 @@ import java.util.UUID;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.management.AttributeNotFoundException;
|
||||||
|
import javax.management.InstanceNotFoundException;
|
||||||
|
import javax.management.MBeanException;
|
||||||
|
import javax.management.MBeanServer;
|
||||||
|
import javax.management.MalformedObjectNameException;
|
||||||
|
import javax.management.ObjectName;
|
||||||
|
import javax.management.ReflectionException;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
|
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
|
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
|
||||||
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
|
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
|
||||||
|
@ -371,21 +379,39 @@ public class SmartgearResourcesTest extends ContextTest {
|
||||||
return memoryFacet;
|
return memoryFacet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final long BYTE_TO_MB = 1024*1024;
|
||||||
|
|
||||||
private MemoryFacet getRamInfo(MemoryFacet memoryFacet) {
|
private MemoryFacet getRamInfo(MemoryFacet memoryFacet) {
|
||||||
if (memoryFacet == null) {
|
if (memoryFacet == null) {
|
||||||
memoryFacet = new MemoryFacetImpl();
|
memoryFacet = new MemoryFacetImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
OperatingSystemMXBean mxbean = ManagementFactory
|
/*
|
||||||
.getOperatingSystemMXBean();
|
OperatingSystemMXBean mxbean = ManagementFactory.getOperatingSystemMXBean();
|
||||||
@SuppressWarnings("restriction")
|
|
||||||
com.sun.management.OperatingSystemMXBean sunmxbean = (com.sun.management.OperatingSystemMXBean) mxbean;
|
com.sun.management.OperatingSystemMXBean sunmxbean = (com.sun.management.OperatingSystemMXBean) mxbean;
|
||||||
@SuppressWarnings("restriction")
|
long freeMemory = sunmxbean.getFreePhysicalMemorySize() / 1048576; // in MB
|
||||||
long freeMemory = sunmxbean.getFreePhysicalMemorySize() / 1048576; // in
|
long totalMemory = sunmxbean.getTotalPhysicalMemorySize() / 1048576; // in MB
|
||||||
// MB
|
*/
|
||||||
@SuppressWarnings("restriction")
|
|
||||||
long totalMemory = sunmxbean.getTotalPhysicalMemorySize() / 1048576; // in
|
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
|
||||||
// MB
|
long freeMemory;
|
||||||
|
try {
|
||||||
|
freeMemory = Long.parseLong(mBeanServer.getAttribute(new ObjectName("java.lang","type","OperatingSystem"), "FreePhysicalMemorySize").toString()) / BYTE_TO_MB;
|
||||||
|
} catch (NumberFormatException | InstanceNotFoundException | AttributeNotFoundException
|
||||||
|
| MalformedObjectNameException | ReflectionException | MBeanException e) {
|
||||||
|
logger.warn("Unable to get free memory from Operating System. Going to get JVM Memory. Better than nothing");
|
||||||
|
long allocatedMemory = (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory());
|
||||||
|
freeMemory = Runtime.getRuntime().maxMemory() - allocatedMemory;
|
||||||
|
}
|
||||||
|
long totalMemory;
|
||||||
|
try {
|
||||||
|
totalMemory = Long.parseLong(mBeanServer.getAttribute(new ObjectName("java.lang","type","OperatingSystem"), "TotalPhysicalMemorySize").toString()) / BYTE_TO_MB;
|
||||||
|
} catch (NumberFormatException | InstanceNotFoundException | AttributeNotFoundException
|
||||||
|
| MalformedObjectNameException | ReflectionException | MBeanException e) {
|
||||||
|
logger.warn("Unable to total memory from Operating System. Going to get JVM Memory. Better than nothing");
|
||||||
|
totalMemory = Runtime.getRuntime().maxMemory();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
memoryFacet.setUnit(MemoryUnit.MB);
|
memoryFacet.setUnit(MemoryUnit.MB);
|
||||||
memoryFacet.setSize(totalMemory);
|
memoryFacet.setSize(totalMemory);
|
||||||
|
|
Loading…
Reference in New Issue