start taosd before jdbc tests

This commit is contained in:
Ping Xiao 2020-07-07 14:00:24 +08:00
parent e1502677e5
commit 9f233e8cf7
4 changed files with 69 additions and 44 deletions

View File

@ -1,6 +1,7 @@
package com.taosdata.jdbc.utils; package com.taosdata.jdbc.utils;
import java.io.File; import java.io.File;
import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class TDNode { public class TDNode {
@ -36,24 +37,51 @@ public class TDNode {
this.testCluster = testCluster; this.testCluster = testCluster;
} }
public void searchTaosd(File dir, ArrayList<String> taosdPath) {
File[] fileList = dir.listFiles();
if(fileList != null && fileList.length != 0) {
for(File file : fileList) {
if(file.isFile()) {
if(file.getName().equals("taosd")) {
taosdPath.add(file.getAbsolutePath());
}
} else {
searchTaosd(file, taosdPath);
}
}
}
return;
}
public void start() { public void start() {
String selfPath = System.getProperty("user.dir"); String selfPath = System.getProperty("user.dir");
String binPath = ""; String binPath = "";
String projDir = selfPath + "../../../"; String projDir = selfPath + "../../../../";
File dir = new File(projDir); try {
ArrayList<String> taosdPath = new ArrayList<>();
File[] fileList = dir.listFiles(); File dir = new File(projDir);
if(fileList == null || fileList.length == 0) { String realProjDir = dir.getCanonicalPath();
System.out.println("The project path doens't exist"); dir = new File(realProjDir);
return; System.out.println("project Dir: " + projDir);
} searchTaosd(dir, taosdPath);
for(File file : fileList) { if(taosdPath.size() == 0) {
if(file.getName().equals("taosd") && !file.getAbsolutePath().contains("packing")) { System.out.println("The project path doens't exist");
binPath = file.getAbsolutePath(); return;
break; } else {
for(String p : taosdPath) {
if(!p.contains("packing")) {
binPath = p;
}
}
} }
} catch (Exception e) {
e.printStackTrace();
} }
if(binPath.equals("")) { if(binPath.equals("")) {
@ -70,16 +98,16 @@ public class TDNode {
String cmd = ""; String cmd = "";
if(this.valgrind == 0) { if(this.valgrind == 0) {
cmd = "nohup " + binPath + " -c " + this.cfgDir + " > /dev/null 2>&1 & "; cmd = "nohup " + binPath + " > /dev/null 2>&1 & ";
System.out.println("start taosd cmd: " + cmd);
} else { } else {
String valgrindCmdline = "valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes"; String valgrindCmdline = "valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes";
cmd = "nohup " + valgrindCmdline + " " + binPath + " -c " + this.cfgDir + " 2>&1 & "; cmd = "nohup " + valgrindCmdline + " " + binPath + " -c " + this.cfgDir + " 2>&1 & ";
} }
try{ try{
if(Runtime.getRuntime().exec(cmd).waitFor() != 0) { Runtime.getRuntime().exec(cmd);
return; TimeUnit.SECONDS.sleep(5);
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -42,7 +42,7 @@ public class TDNodes {
binPath = file.getCanonicalPath(); binPath = file.getCanonicalPath();
System.out.println("binPath real path: " + binPath); System.out.println("binPath real path: " + binPath);
if (path.isEmpty()) { if (!path.isEmpty()) {
file = new File(path + "/../../"); file = new File(path + "/../../");
path = file.getCanonicalPath(); path = file.getCanonicalPath();
} }
@ -79,7 +79,7 @@ public class TDNodes {
TDSimClient sim = new TDSimClient(); TDSimClient sim = new TDSimClient();
sim.setPath(path); sim.setPath(path);
System.out.println("====== " + path + "====="); System.out.println("======path: " + path + "=====");
sim.setTestCluster(this.testCluster); sim.setTestCluster(this.testCluster);
if(this.simDeployed == false ) { if(this.simDeployed == false ) {
sim.deploy(); sim.deploy();
@ -89,6 +89,7 @@ public class TDNodes {
check(index); check(index);
tdNodes.get(index - 1).setTestCluster(this.testCluster); tdNodes.get(index - 1).setTestCluster(this.testCluster);
tdNodes.get(index - 1).setValgrind(valgrind); tdNodes.get(index - 1).setValgrind(valgrind);
tdNodes.get(index - 1).setPath(System.getProperty("user.dir"));
tdNodes.get(index - 1).deploy(); tdNodes.get(index - 1).deploy();
} }

View File

@ -1,7 +1,5 @@
package com.taosdata.jdbc.utils; package com.taosdata.jdbc.utils;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class TDSimClient { public class TDSimClient {
@ -25,16 +23,11 @@ public class TDSimClient {
public void setCfgConfig(String option, String value) { public void setCfgConfig(String option, String value) {
String cmd = "echo " + option + " " + value + " >> " + this.cfgPath; String cmd = "echo " + option + " " + value + " >> " + this.cfgPath;
System.out.println("set cfg cmd " + cmd);
try { try {
Process ps = Runtime.getRuntime().exec(cmd); Process ps = Runtime.getRuntime().exec(cmd);
System.out.println("cfg command result: " + ps.waitFor());
BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
while(br.readLine() != null) {
System.out.println(br.readLine());
}
ps.waitFor();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -50,19 +43,26 @@ public class TDSimClient {
try { try {
String cmd = "rm -rf " + this.logDir; String cmd = "rm -rf " + this.logDir;
Runtime.getRuntime().exec(cmd).waitFor(); System.out.println("cmd: = " + cmd);
Process ps = Runtime.getRuntime().exec(cmd);
System.out.println("return value " + ps.waitFor());
System.out.println(Runtime.getRuntime().exec(cmd).waitFor());
cmd = "rm -rf " + this.cfgDir; cmd = "rm -rf " + this.cfgDir;
Runtime.getRuntime().exec(cmd).waitFor(); Runtime.getRuntime().exec(cmd).waitFor();
System.out.println(cmd + " result: " +Runtime.getRuntime().exec(cmd).waitFor());
cmd = "mkdir -p " + this.logDir; cmd = "mkdir -p " + this.logDir;
Runtime.getRuntime().exec(cmd).waitFor(); Runtime.getRuntime().exec(cmd).waitFor();
System.out.println(cmd + " result: " +Runtime.getRuntime().exec(cmd).waitFor());
cmd = "mkdir -p " + this.cfgDir; cmd = "mkdir -p " + this.cfgDir;
Runtime.getRuntime().exec(cmd).waitFor(); System.out.println(cmd + " result: " +Runtime.getRuntime().exec(cmd).waitFor());
cmd = "touch " + this.cfgPath; cmd = "touch " + this.cfgPath;
Runtime.getRuntime().exec(cmd).waitFor(); System.out.println(cmd + " result: " +Runtime.getRuntime().exec(cmd).waitFor());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -6,6 +6,7 @@ import java.io.InputStreamReader;
import com.taosdata.jdbc.utils.TDNodes; import com.taosdata.jdbc.utils.TDNodes;
import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
public class BaseTest { public class BaseTest {
@ -17,17 +18,6 @@ public class BaseTest {
@BeforeClass @BeforeClass
public static void setupEnv() { public static void setupEnv() {
try{ try{
// String path = System.getProperty("user.dir");
// String bashPath = path + "/buildTDengine.sh";
// Process ps = Runtime.getRuntime().exec(bashPath);
// ps.waitFor();
// BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
// while(br.readLine() != null) {
// System.out.println(br.readLine());
// }
File file = new File(deployPath + "/../../../"); File file = new File(deployPath + "/../../../");
String rootPath = file.getCanonicalPath(); String rootPath = file.getCanonicalPath();
@ -38,8 +28,14 @@ public class BaseTest {
tdNodes.deploy(1); tdNodes.deploy(1);
tdNodes.start(1); tdNodes.start(1);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@AfterClass
public static void clearUpEnv() {
}
} }