Browse Source

[Test][server] Add LoggerServerTest (#3405)

pull/3/MERGE
Yichao Yang 4 years ago committed by GitHub
parent
commit
f419fe6239
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 60
      dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/log/LoggerServerTest.java
  2. 2
      pom.xml

60
dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/log/LoggerServerTest.java

@ -17,46 +17,62 @@
package org.apache.dolphinscheduler.server.log;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.utils.FileUtils;
import org.apache.dolphinscheduler.common.utils.StringUtils;
import org.apache.dolphinscheduler.service.log.LogClientService;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class LoggerServerTest {
private LoggerServer loggerServer;
@Test
public void testRollViewLog(){
LoggerServer loggerServer = new LoggerServer();
loggerServer.start();
private LogClientService logClientService;
LogClientService logClientService = new LogClientService();
logClientService.rollViewLog("localhost", Constants.RPC_PORT,"/opt/demo.txt",0,1000);
@Before
public void startServerAndClient() {
this.loggerServer = new LoggerServer();
this.loggerServer.start();
this.logClientService = new LogClientService();
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
@Test
public void testRollViewLog() throws IOException {
String expectedTmpDemoString = "testRolloViewLog";
FileUtils.writeStringToFile(new File("/tmp/demo.txt"), expectedTmpDemoString, Charset.defaultCharset());
}
String resultTmpDemoString = this.logClientService.rollViewLog(
"localhost", Constants.RPC_PORT,"/tmp/demo.txt", 0, 1000);
Assert.assertEquals(expectedTmpDemoString, resultTmpDemoString.replaceAll("[\r|\n|\t]", StringUtils.EMPTY));
loggerServer.stop();
logClientService.close();
FileUtils.deleteFile("/tmp/demo.txt");
}
@Test
public void testRemoveTaskLog(){
LoggerServer loggerServer = new LoggerServer();
loggerServer.start();
public void testRemoveTaskLog() throws IOException {
String expectedTmpRemoveString = "testRemoveTaskLog";
FileUtils.writeStringToFile(new File("/tmp/remove.txt"), expectedTmpRemoveString, Charset.defaultCharset());
Boolean b = this.logClientService.removeTaskLog("localhost", Constants.RPC_PORT,"/tmp/remove.txt");
LogClientService logClientService = new LogClientService();
logClientService.removeTaskLog("localhost", Constants.RPC_PORT,"/opt/zhangsan");
Assert.assertTrue(b);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
String result = this.logClientService.viewLog("localhost", Constants.RPC_PORT,"/tmp/demo.txt");
Assert.assertEquals(StringUtils.EMPTY, result);
}
loggerServer.stop();
logClientService.close();
@After
public void stopServerAndClient() {
this.loggerServer.stop();
this.logClientService.close();
}
}

2
pom.xml

@ -795,7 +795,7 @@
<include>**/remote/RemoveTaskLogRequestCommandTest.java</include>
<!--<include>**/remote/NettyRemotingClientTest.java</include>-->
<include>**/remote/ResponseFutureTest.java</include>
<!--<include>**/server/log/LoggerServerTest.java</include>-->
<include>**/server/log/LoggerServerTest.java</include>
<include>**/server/entity/SQLTaskExecutionContextTest.java</include>
<include>**/server/log/MasterLogFilterTest.java</include>
<include>**/server/log/SensitiveDataConverterTest.java</include>

Loading…
Cancel
Save