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; 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.Constants;
import org.apache.dolphinscheduler.common.utils.FileUtils;
import org.apache.dolphinscheduler.common.utils.StringUtils;
import org.apache.dolphinscheduler.service.log.LogClientService; import org.apache.dolphinscheduler.service.log.LogClientService;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
public class LoggerServerTest { public class LoggerServerTest {
private LoggerServer loggerServer;
@Test private LogClientService logClientService;
public void testRollViewLog(){
LoggerServer loggerServer = new LoggerServer();
loggerServer.start();
LogClientService logClientService = new LogClientService(); @Before
logClientService.rollViewLog("localhost", Constants.RPC_PORT,"/opt/demo.txt",0,1000); public void startServerAndClient() {
this.loggerServer = new LoggerServer();
this.loggerServer.start();
this.logClientService = new LogClientService();
}
try { @Test
Thread.sleep(5000); public void testRollViewLog() throws IOException {
} catch (InterruptedException e) { 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(); FileUtils.deleteFile("/tmp/demo.txt");
logClientService.close();
} }
@Test @Test
public void testRemoveTaskLog(){ public void testRemoveTaskLog() throws IOException {
LoggerServer loggerServer = new LoggerServer(); String expectedTmpRemoveString = "testRemoveTaskLog";
loggerServer.start(); 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(); Assert.assertTrue(b);
logClientService.removeTaskLog("localhost", Constants.RPC_PORT,"/opt/zhangsan");
try { String result = this.logClientService.viewLog("localhost", Constants.RPC_PORT,"/tmp/demo.txt");
Thread.sleep(5000);
} catch (InterruptedException e) {
Assert.assertEquals(StringUtils.EMPTY, result);
} }
loggerServer.stop(); @After
logClientService.close(); public void stopServerAndClient() {
this.loggerServer.stop();
this.logClientService.close();
} }
} }

2
pom.xml

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

Loading…
Cancel
Save