@ -19,15 +19,11 @@ package org.apache.dolphinscheduler.common.os;
import org.apache.dolphinscheduler.common.utils.OSUtils ;
import org.apache.dolphinscheduler.common.utils.OSUtils ;
import java.math.RoundingMode ;
import org.junit.Assert ;
import java.text.DecimalFormat ;
import org.junit.Test ;
import org.junit.Test ;
import org.slf4j.Logger ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.slf4j.LoggerFactory ;
import oshi.hardware.GlobalMemory ;
/ * *
/ * *
* OSUtilsTest
* OSUtilsTest
* /
* /
@ -36,40 +32,33 @@ public class OSUtilsTest {
private static Logger logger = LoggerFactory . getLogger ( OSUtilsTest . class ) ;
private static Logger logger = LoggerFactory . getLogger ( OSUtilsTest . class ) ;
@Test
@Test
public void memoryUsage ( ) {
public void testMemoryUsage ( ) {
logger . info ( "memoryUsage : {}" , OSUtils . memoryUsage ( ) ) ; // 0.3361799418926239
double memoryUsage = OSUtils . memoryUsage ( ) ;
logger . info ( "memoryUsage : {}" , memoryUsage ) ;
Assert . assertTrue ( memoryUsage > = 0 . 0 ) ;
}
}
@Test
@Test
public void availablePhysicalMemorySize ( ) {
public void testPhysicalMemorySize ( ) {
logger . info ( "availablePhysicalMemorySize : {}" , OSUtils . availablePhysicalMemorySize ( ) ) ;
double availablePhysicalMemorySize = OSUtils . availablePhysicalMemorySize ( ) ;
logger . info ( "availablePhysicalMemorySize : {}" , OSUtils . totalMemorySize ( ) / 10 ) ;
double totalPhysicalMemorySize = OSUtils . totalPhysicalMemorySize ( ) ;
logger . info ( "availablePhysicalMemorySize : {}" , availablePhysicalMemorySize ) ;
logger . info ( "totalPhysicalMemorySize : {}" , totalPhysicalMemorySize ) ;
Assert . assertTrue ( availablePhysicalMemorySize > = 0 . 0 ) ;
Assert . assertTrue ( totalPhysicalMemorySize > = 0 . 0 ) ;
}
}
@Test
@Test
public void loadAverage ( ) {
public void testLoadAverage ( ) {
logger . info ( "memoryUsage : {}" , OSUtils . loadAverage ( ) ) ;
double loadAverage = OSUtils . loadAverage ( ) ;
}
logger . info ( "loadAverage : {}" , loadAverage ) ;
Assert . assertTrue ( loadAverage > = 0 . 0 ) ;
private void printMemory ( GlobalMemory memory ) {
logger . info ( "memoryUsage : {} %" , ( memory . getTotal ( ) - memory . getAvailable ( ) ) * 100 / memory . getTotal ( ) ) ;
}
}
@Test
@Test
public void cpuUsage ( ) throws Exception {
public void testCpuUsage ( ) {
logger . info ( "cpuUsage : {}" , OSUtils . cpuUsage ( ) ) ;
Thread . sleep ( 1000L ) ;
logger . info ( "cpuUsage : {}" , OSUtils . cpuUsage ( ) ) ;
double cpuUsage = OSUtils . cpuUsage ( ) ;
double cpuUsage = OSUtils . cpuUsage ( ) ;
logger . info ( "cpuUsage : {}" , cpuUsage ) ;
DecimalFormat df = new DecimalFormat ( "0.00" ) ;
Assert . assertTrue ( cpuUsage > = 0 . 0 ) ;
df . setRoundingMode ( RoundingMode . HALF_UP ) ;
logger . info ( "cpuUsage1 : {}" , df . format ( cpuUsage ) ) ;
}
}
}
}