|
|
@ -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); |
|
|
|
|
|
|
|
|
|
|
|
loggerServer.stop(); |
|
|
|
Assert.assertEquals(expectedTmpDemoString, resultTmpDemoString.replaceAll("[\r|\n|\t]", StringUtils.EMPTY)); |
|
|
|
logClientService.close(); |
|
|
|
|
|
|
|
|
|
|
|
FileUtils.deleteFile("/tmp/demo.txt"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@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(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|