Browse Source

Update HadoopUtilsTest.java

pull/2/head
dailidong 5 years ago committed by GitHub
parent
commit
176c637757
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 49
      dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HadoopUtilsTest.java

49
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HadoopUtilsTest.java

@ -22,6 +22,8 @@ import org.apache.hadoop.conf.Configuration;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -29,91 +31,93 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@RunWith(MockitoJUnitRunner.class)
//todo there is no hadoop environment
public class HadoopUtilsTest {
private static final Logger logger = LoggerFactory.getLogger(HadoopUtilsTest.class);
private HadoopUtils hadoopUtils = HadoopUtils.getInstance();
@Test
public void getActiveRMTest() {
logger.info(HadoopUtils.getAppAddress("http://ark1:8088/ws/v1/cluster/apps/%s","192.168.xx.xx,192.168.xx.xx"));
logger.info(hadoopUtils.getAppAddress("http://ark1:8088/ws/v1/cluster/apps/%s","192.168.xx.xx,192.168.xx.xx"));
}
@Test
public void getApplicationStatusAddressTest(){
logger.info(HadoopUtils.getInstance().getApplicationUrl("application_1548381297012_0030"));
public void rename() throws IOException {
boolean result = hadoopUtils.rename("/dolphinscheduler/hdfs1","/dolphinscheduler/hdfs2");
Assert.assertEquals(true, result);
}
@Test
public void getConfiguration(){
Configuration conf = HadoopUtils.getInstance().getConfiguration();
Configuration conf = hadoopUtils.getConfiguration();
}
@Test
public void mkdir() throws IOException {
boolean result = HadoopUtils.getInstance().mkdir("/dolphinscheduler/hdfs");
boolean result = hadoopUtils.mkdir("/dolphinscheduler/hdfs");
Assert.assertEquals(true, result);
}
@Test
public void delete() throws IOException {
boolean result = HadoopUtils.getInstance().delete("/dolphinscheduler/hdfs",true);
boolean result = hadoopUtils.delete("/dolphinscheduler/hdfs",true);
Assert.assertEquals(true, result);
}
@Test
public void exists() throws IOException {
boolean result = HadoopUtils.getInstance().exists("/dolphinscheduler/hdfs");
boolean result = hadoopUtils.exists("/dolphinscheduler/hdfs");
Assert.assertEquals(true, result);
}
@Test
public void getHdfsDataBasePath() throws IOException {
String result = HadoopUtils.getInstance().getHdfsDataBasePath();
String result = hadoopUtils.getHdfsDataBasePath();
Assert.assertEquals("/dolphinscheduler", result);
}
@Test
public void getHdfsResDir() throws IOException {
String result = HadoopUtils.getInstance().getHdfsResDir("11000");
String result = hadoopUtils.getHdfsResDir("11000");
Assert.assertEquals("/dolphinscheduler/resources/11000", result);
}
@Test
public void getHdfsUserDir() throws IOException {
String result = HadoopUtils.getInstance().getHdfsUserDir("11000",1000);
String result = hadoopUtils.getHdfsUserDir("11000",1000);
Assert.assertEquals("/dolphinscheduler/11000/home/1000", result);
}
@Test
public void getHdfsUdfDir() throws IOException {
String result = HadoopUtils.getInstance().getHdfsUdfDir("11000");
String result = hadoopUtils.getHdfsUdfDir("11000");
Assert.assertEquals("/dolphinscheduler/11000/udfs", result);
}
@Test
public void getHdfsFileName() throws IOException {
String result = HadoopUtils.getInstance().getHdfsFileName(ResourceType.FILE,"11000","aa.txt");
String result = hadoopUtils.getHdfsFileName(ResourceType.FILE,"11000","aa.txt");
Assert.assertEquals("/dolphinscheduler/resources/11000/aa.txt", result);
}
@Test
public void isYarnEnabled() throws IOException {
boolean result = HadoopUtils.getInstance().isYarnEnabled();
boolean result = hadoopUtils.isYarnEnabled();
Assert.assertEquals(false, result);
}
@Test
public void test() throws IOException {
HadoopUtils.getInstance().copyLocalToHdfs("/root/teamviewer_13.1.8286.x86_64.rpm", "/journey", true, true);
hadoopUtils.copyLocalToHdfs("/root/teamviewer_13.1.8286.x86_64.rpm", "/journey", true, true);
}
@Test
public void readFileTest(){
try {
byte[] bytes = HadoopUtils.getInstance().catFile("/dolphinscheduler/hdfs/resources/35435.sh");
byte[] bytes = hadoopUtils.catFile("/dolphinscheduler/hdfs/resources/35435.sh");
logger.info(new String(bytes));
} catch (Exception e) {
logger.error(e.getMessage(),e);
@ -123,9 +127,8 @@ public class HadoopUtilsTest {
@Test
public void testMove(){
HadoopUtils instance = HadoopUtils.getInstance();
try {
instance.copy("/opt/apptest/test.dat","/opt/apptest/test.dat.back",true,true);
hadoopUtils.copy("/opt/apptest/test.dat","/opt/apptest/test.dat.back",true,true);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
@ -134,24 +137,24 @@ public class HadoopUtilsTest {
@Test
public void getApplicationStatus() {
logger.info(HadoopUtils.getInstance().getApplicationStatus("application_1542010131334_0029").toString());
logger.info(hadoopUtils.getApplicationStatus("application_1542010131334_0029").toString());
}
@Test
public void getApplicationUrl(){
String application_1516778421218_0042 = HadoopUtils.getInstance().getApplicationUrl("application_1529051418016_0167");
String application_1516778421218_0042 = hadoopUtils.getApplicationUrl("application_1529051418016_0167");
logger.info(application_1516778421218_0042);
}
@Test
public void catFileWithLimitTest()throws Exception{
List<String> stringList = HadoopUtils.getInstance().catFile("/dolphinscheduler/hdfs/resources/WCSparkPython.py", 0, 1000);
List<String> stringList = hadoopUtils.catFile("/dolphinscheduler/hdfs/resources/WCSparkPython.py", 0, 1000);
logger.info(String.join(",",stringList));
}
@Test
public void catFileTest()throws Exception{
byte[] content = HadoopUtils.getInstance().catFile("/dolphinscheduler/hdfs/resources/WCSparkPython.py");
byte[] content = hadoopUtils.catFile("/dolphinscheduler/hdfs/resources/WCSparkPython.py");
logger.info(Arrays.toString(content));
}
}

Loading…
Cancel
Save