提交 493ad1cc 编写于 作者: P Ping Xiao

TD-754: build taosd before jdbc tests

上级 21c77738
......@@ -37,11 +37,13 @@ public class TDNode {
this.testCluster = testCluster;
}
public void searchTaosd(File dir, ArrayList<String> taosdPath) {
File[] fileList = dir.listFiles();
if(fileList != null && fileList.length != 0) {
if(fileList == null || fileList.length == 0) {
return;
}
for(File file : fileList) {
if(file.isFile()) {
if(file.getName().equals("taosd")) {
......@@ -53,9 +55,6 @@ public class TDNode {
}
}
return;
}
public void start() {
String selfPath = System.getProperty("user.dir");
String binPath = "";
......@@ -98,10 +97,10 @@ public class TDNode {
String cmd = "";
if(this.valgrind == 0) {
cmd = "nohup " + binPath + " > /dev/null 2>&1 & ";
cmd = "nohup " + binPath + " -c " + cfgDir + " > /dev/null 2>&1 & ";
System.out.println("start taosd cmd: " + cmd);
} 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 & ";
}
......@@ -172,7 +171,9 @@ public class TDNode {
public void setCfgConfig(String option, String value) {
try{
String cmd = "echo " + option + " " + value + " >> " + this.cfgPath;
Runtime.getRuntime().exec(cmd).waitFor();
String[] cmdLine = {"sh", "-c", cmd};
Process ps = Runtime.getRuntime().exec(cmdLine);
ps.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
......@@ -229,7 +230,7 @@ public class TDNode {
}
setCfgConfig("dataDir", this.dataDir);
setCfgConfig("logDir", this.logDir);
setCfgConfig("numOfLogLines", "100000000");
setCfgConfig("numOfLogLines", "1000000/00");
setCfgConfig("mnodeEqualVnodeNum", "0");
setCfgConfig("walLevel", "1");
setCfgConfig("statusInterval", "1");
......
......@@ -3,34 +3,29 @@ package com.taosdata.jdbc.utils;
import java.io.File;
import java.util.*;
public class TDNodes {
private ArrayList<TDNode> tdNodes;
private boolean simDeployed;
private boolean testCluster;
private int valgrind;
private String path;
public TDNodes () {
tdNodes = new ArrayList<>();
for(int i = 1; i < 11; i ++) {
tdNodes.add(new TDNode(i));
}
this.simDeployed = false;
path = "";
}
public TDNodes(String path) {
public void setPath(String path) {
try {
String psCmd = "ps -ef|grep -w taosd| grep -v grep | awk '{print $2}'" ;
Process ps = Runtime.getRuntime().exec(psCmd);
ps.wait();
ps.waitFor();
String killCmd = "kill -9 " + ps.pid();
Runtime.getRuntime().exec(killCmd).waitFor();
psCmd = "ps -ef|grep -w valgrind.bin| grep -v grep | awk '{print $2}'";
ps = Runtime.getRuntime().exec(psCmd);
ps.wait();
ps.waitFor();
killCmd = "kill -9 " + ps.pid();
Runtime.getRuntime().exec(killCmd).waitFor();
......@@ -42,7 +37,7 @@ public class TDNodes {
binPath = file.getCanonicalPath();
System.out.println("binPath real path: " + binPath);
if (!path.isEmpty()) {
if(path.isEmpty()){
file = new File(path + "/../../");
path = file.getCanonicalPath();
}
......@@ -63,10 +58,6 @@ public class TDNodes {
this.valgrind = valgrind;
}
public void setPath(String path) {
this.path = path;
}
public void check(int index) {
if(index < 1 || index > 10) {
System.out.println("index: " + index + " should on a scale of [1, 10]");
......@@ -75,22 +66,18 @@ public class TDNodes {
}
public void deploy(int index) {
System.out.println("======Start deploying tsim=====");
TDSimClient sim = new TDSimClient();
sim.setPath(path);
System.out.println("======path: " + path + "=====");
sim.setTestCluster(this.testCluster);
if(this.simDeployed == false ) {
sim.deploy();
this.simDeployed = true;
}
try {
File file = new File(System.getProperty("user.dir") + "/../../../");
String projectRealPath = file.getCanonicalPath();
check(index);
tdNodes.get(index - 1).setTestCluster(this.testCluster);
tdNodes.get(index - 1).setValgrind(valgrind);
tdNodes.get(index - 1).setPath(System.getProperty("user.dir"));
tdNodes.get(index - 1).setPath(projectRealPath);
tdNodes.get(index - 1).deploy();
} catch (Exception e) {
e.printStackTrace();
System.out.println("deploy Test Exception");
}
}
public void cfg(int index, String option, String value) {
......
package com.taosdata.jdbc.utils;
public class TDSimClient {
private boolean testCluster;
private String path;
private String cfgDir;
private String logDir;
private String cfgPath;
public TDSimClient() {
testCluster = false;
}
public void setTestCluster(boolean testCluster) {
this.testCluster = testCluster;
}
public void setPath(String path) {
this.path = path;
}
public void setCfgConfig(String option, String value) {
String cmd = "echo " + option + " " + value + " >> " + this.cfgPath;
System.out.println("set cfg cmd " + cmd);
try {
Process ps = Runtime.getRuntime().exec(cmd);
System.out.println("cfg command result: " + ps.waitFor());
} catch (Exception e) {
e.printStackTrace();
}
}
public void deploy() {
this.logDir = this.path + "/sim/psim/log";
System.out.println("======logDir: " + logDir + "=====");
this.cfgDir = this.path + "/sim/psim/cfg";
System.out.println("======cfgDir: " + cfgDir + "=====");
this.cfgPath = this.path + "/sim/psim/cfg/taos.cfg";
System.out.println("======cfgPath: " + cfgPath + "=====");
try {
String cmd = "rm -rf " + this.logDir;
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;
Runtime.getRuntime().exec(cmd).waitFor();
System.out.println(cmd + " result: " +Runtime.getRuntime().exec(cmd).waitFor());
cmd = "mkdir -p " + this.logDir;
Runtime.getRuntime().exec(cmd).waitFor();
System.out.println(cmd + " result: " +Runtime.getRuntime().exec(cmd).waitFor());
cmd = "mkdir -p " + this.cfgDir;
System.out.println(cmd + " result: " +Runtime.getRuntime().exec(cmd).waitFor());
cmd = "touch " + this.cfgPath;
System.out.println(cmd + " result: " +Runtime.getRuntime().exec(cmd).waitFor());
} catch (Exception e) {
e.printStackTrace();
}
if(this.testCluster) {
setCfgConfig("masterIp", "192.168.0.1");
setCfgConfig("secondIp", "192.168.0.2");
}
setCfgConfig("logDir", this.logDir);
setCfgConfig("numOfLogLines", "100000000");
setCfgConfig("numOfThreadsPerCore", "2.0");
setCfgConfig("locale", "en_US.UTF-8");
setCfgConfig("charset", "UTF-8");
setCfgConfig("asyncLog", "0");
setCfgConfig("anyIp", "0");
setCfgConfig("sdbDebugFlag", "135");
setCfgConfig("rpcDebugFlag", "135");
setCfgConfig("tmrDebugFlag", "131");
setCfgConfig("cDebugFlag", "135");
setCfgConfig("udebugFlag", "135");
setCfgConfig("jnidebugFlag", "135");
setCfgConfig("qdebugFlag", "135");
}
}
\ No newline at end of file
package com.taosdata.jdbc;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import com.taosdata.jdbc.utils.TDNodes;
import org.junit.AfterClass;
......@@ -14,14 +11,15 @@ public class BaseTest {
private static boolean testCluster = false;
private static String deployPath = System.getProperty("user.dir");
private static int valgrind = 0;
private static TDNodes tdNodes = new TDNodes();
@BeforeClass
public static void setupEnv() {
public static void setUpEvn() {
try{
File file = new File(deployPath + "/../../../");
String rootPath = file.getCanonicalPath();
TDNodes tdNodes = new TDNodes();
tdNodes.setPath(rootPath);
tdNodes.setTestCluster(testCluster);
tdNodes.setValgrid(valgrind);
......@@ -31,11 +29,12 @@ public class BaseTest {
} catch (Exception e) {
e.printStackTrace();
System.out.println("Base Test Exception");
}
}
@AfterClass
public static void clearUpEnv() {
public static void cleanUpEnv() {
tdNodes.stop(1);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册