|
|
@ -16,11 +16,6 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.apache.dolphinscheduler.common.utils; |
|
|
|
package org.apache.dolphinscheduler.common.utils; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.Constants; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.configuration.Configuration; |
|
|
|
|
|
|
|
import org.apache.commons.configuration.PropertiesConfiguration; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
@ -40,12 +35,12 @@ public class OSUtilsTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testOSMetric(){ |
|
|
|
public void testOSMetric() { |
|
|
|
if (!OSUtils.isWindows()) { |
|
|
|
if (!OSUtils.isWindows()) { |
|
|
|
double availablePhysicalMemorySize = OSUtils.availablePhysicalMemorySize(); |
|
|
|
double availablePhysicalMemorySize = OSUtils.availablePhysicalMemorySize(); |
|
|
|
Assert.assertTrue(availablePhysicalMemorySize >= 0.0d); |
|
|
|
Assert.assertTrue(availablePhysicalMemorySize >= 0.0d); |
|
|
|
double totalMemorySize = OSUtils.totalMemorySize(); |
|
|
|
double totalPhysicalMemorySize = OSUtils.totalPhysicalMemorySize(); |
|
|
|
Assert.assertTrue(totalMemorySize >= 0.0d); |
|
|
|
Assert.assertTrue(totalPhysicalMemorySize >= 0.0d); |
|
|
|
double loadAverage = OSUtils.loadAverage(); |
|
|
|
double loadAverage = OSUtils.loadAverage(); |
|
|
|
logger.info("loadAverage {}", loadAverage); |
|
|
|
logger.info("loadAverage {}", loadAverage); |
|
|
|
double memoryUsage = OSUtils.memoryUsage(); |
|
|
|
double memoryUsage = OSUtils.memoryUsage(); |
|
|
@ -92,7 +87,7 @@ public class OSUtilsTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void exeCmd() { |
|
|
|
public void exeCmd() { |
|
|
|
if(OSUtils.isMacOS() || !OSUtils.isWindows()){ |
|
|
|
if (OSUtils.isMacOS() || !OSUtils.isWindows()) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
String result = OSUtils.exeCmd("echo helloWorld"); |
|
|
|
String result = OSUtils.exeCmd("echo helloWorld"); |
|
|
|
Assert.assertEquals("helloWorld\n",result); |
|
|
|
Assert.assertEquals("helloWorld\n",result); |
|
|
@ -102,39 +97,16 @@ public class OSUtilsTest { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void getProcessID(){ |
|
|
|
public void getProcessID() { |
|
|
|
int processId = OSUtils.getProcessID(); |
|
|
|
int processId = OSUtils.getProcessID(); |
|
|
|
Assert.assertNotEquals(0, processId); |
|
|
|
Assert.assertNotEquals(0, processId); |
|
|
|
} |
|
|
|
} |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void checkResource(){ |
|
|
|
public void checkResource() { |
|
|
|
boolean resource = OSUtils.checkResource(100,0); |
|
|
|
boolean resource = OSUtils.checkResource(100,0); |
|
|
|
Assert.assertTrue(resource); |
|
|
|
Assert.assertTrue(resource); |
|
|
|
resource = OSUtils.checkResource(0,Double.MAX_VALUE); |
|
|
|
resource = OSUtils.checkResource(0,Double.MAX_VALUE); |
|
|
|
Assert.assertFalse(resource); |
|
|
|
Assert.assertFalse(resource); |
|
|
|
|
|
|
|
|
|
|
|
Configuration configuration = new PropertiesConfiguration(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configuration.setProperty(Constants.MASTER_MAX_CPULOAD_AVG,100); |
|
|
|
|
|
|
|
configuration.setProperty(Constants.MASTER_RESERVED_MEMORY,0); |
|
|
|
|
|
|
|
resource = OSUtils.checkResource(configuration,true); |
|
|
|
|
|
|
|
Assert.assertTrue(resource); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configuration.setProperty(Constants.MASTER_MAX_CPULOAD_AVG,0); |
|
|
|
|
|
|
|
configuration.setProperty(Constants.MASTER_RESERVED_MEMORY,Double.MAX_VALUE); |
|
|
|
|
|
|
|
resource = OSUtils.checkResource(configuration,true); |
|
|
|
|
|
|
|
Assert.assertFalse(resource); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configuration.setProperty(Constants.WORKER_MAX_CPULOAD_AVG,100); |
|
|
|
|
|
|
|
configuration.setProperty(Constants.WORKER_RESERVED_MEMORY,0); |
|
|
|
|
|
|
|
resource = OSUtils.checkResource(configuration,false); |
|
|
|
|
|
|
|
Assert.assertTrue(resource); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configuration.setProperty(Constants.WORKER_MAX_CPULOAD_AVG,0); |
|
|
|
|
|
|
|
configuration.setProperty(Constants.WORKER_RESERVED_MEMORY,Double.MAX_VALUE); |
|
|
|
|
|
|
|
resource = OSUtils.checkResource(configuration,false); |
|
|
|
|
|
|
|
Assert.assertFalse(resource); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|