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

TD-754: build taosd before jdbc tests

上级 21c77738
...@@ -37,23 +37,22 @@ public class TDNode { ...@@ -37,23 +37,22 @@ public class TDNode {
this.testCluster = testCluster; this.testCluster = testCluster;
} }
public void searchTaosd(File dir, ArrayList<String> taosdPath) { public void searchTaosd(File dir, ArrayList<String> taosdPath) {
File[] fileList = dir.listFiles(); File[] fileList = dir.listFiles();
if(fileList != null && fileList.length != 0) { if(fileList == null || fileList.length == 0) {
for(File file : fileList) { return;
if(file.isFile()) {
if(file.getName().equals("taosd")) {
taosdPath.add(file.getAbsolutePath());
}
} else {
searchTaosd(file, taosdPath);
}
}
} }
return; for(File file : fileList) {
if(file.isFile()) {
if(file.getName().equals("taosd")) {
taosdPath.add(file.getAbsolutePath());
}
} else {
searchTaosd(file, taosdPath);
}
}
} }
public void start() { public void start() {
...@@ -98,10 +97,10 @@ public class TDNode { ...@@ -98,10 +97,10 @@ public class TDNode {
String cmd = ""; String cmd = "";
if(this.valgrind == 0) { 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); 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 & ";
} }
...@@ -152,7 +151,7 @@ public class TDNode { ...@@ -152,7 +151,7 @@ public class TDNode {
public void startIP() { public void startIP() {
try{ try{
String cmd = "sudo ifconfig lo:" + index + "192.168.0." + index + " up"; String cmd = "sudo ifconfig lo:" + index + "192.168.0." + index + " up";
Runtime.getRuntime().exec(cmd).waitFor(); Runtime.getRuntime().exec(cmd).waitFor();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -162,7 +161,7 @@ public class TDNode { ...@@ -162,7 +161,7 @@ public class TDNode {
public void stopIP() { public void stopIP() {
try{ try{
String cmd = "sudo ifconfig lo:" + index + "192.168.0." + index + " down"; String cmd = "sudo ifconfig lo:" + index + "192.168.0." + index + " down";
Runtime.getRuntime().exec(cmd).waitFor(); Runtime.getRuntime().exec(cmd).waitFor();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -172,7 +171,9 @@ public class TDNode { ...@@ -172,7 +171,9 @@ public class TDNode {
public void setCfgConfig(String option, String value) { public void setCfgConfig(String option, String value) {
try{ try{
String cmd = "echo " + option + " " + value + " >> " + this.cfgPath; 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) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -229,7 +230,7 @@ public class TDNode { ...@@ -229,7 +230,7 @@ public class TDNode {
} }
setCfgConfig("dataDir", this.dataDir); setCfgConfig("dataDir", this.dataDir);
setCfgConfig("logDir", this.logDir); setCfgConfig("logDir", this.logDir);
setCfgConfig("numOfLogLines", "100000000"); setCfgConfig("numOfLogLines", "1000000/00");
setCfgConfig("mnodeEqualVnodeNum", "0"); setCfgConfig("mnodeEqualVnodeNum", "0");
setCfgConfig("walLevel", "1"); setCfgConfig("walLevel", "1");
setCfgConfig("statusInterval", "1"); setCfgConfig("statusInterval", "1");
......
...@@ -3,34 +3,29 @@ package com.taosdata.jdbc.utils; ...@@ -3,34 +3,29 @@ package com.taosdata.jdbc.utils;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
public class TDNodes { public class TDNodes {
private ArrayList<TDNode> tdNodes; private ArrayList<TDNode> tdNodes;
private boolean simDeployed;
private boolean testCluster; private boolean testCluster;
private int valgrind; private int valgrind;
private String path;
public TDNodes () { public TDNodes () {
tdNodes = new ArrayList<>(); tdNodes = new ArrayList<>();
for(int i = 1; i < 11; i ++) { for(int i = 1; i < 11; i ++) {
tdNodes.add(new TDNode(i)); tdNodes.add(new TDNode(i));
} }
this.simDeployed = false;
path = "";
} }
public TDNodes(String path) { public void setPath(String path) {
try { try {
String psCmd = "ps -ef|grep -w taosd| grep -v grep | awk '{print $2}'" ; String psCmd = "ps -ef|grep -w taosd| grep -v grep | awk '{print $2}'" ;
Process ps = Runtime.getRuntime().exec(psCmd); Process ps = Runtime.getRuntime().exec(psCmd);
ps.wait(); ps.waitFor();
String killCmd = "kill -9 " + ps.pid(); String killCmd = "kill -9 " + ps.pid();
Runtime.getRuntime().exec(killCmd).waitFor(); Runtime.getRuntime().exec(killCmd).waitFor();
psCmd = "ps -ef|grep -w valgrind.bin| grep -v grep | awk '{print $2}'"; psCmd = "ps -ef|grep -w valgrind.bin| grep -v grep | awk '{print $2}'";
ps = Runtime.getRuntime().exec(psCmd); ps = Runtime.getRuntime().exec(psCmd);
ps.wait(); ps.waitFor();
killCmd = "kill -9 " + ps.pid(); killCmd = "kill -9 " + ps.pid();
Runtime.getRuntime().exec(killCmd).waitFor(); Runtime.getRuntime().exec(killCmd).waitFor();
...@@ -41,11 +36,11 @@ public class TDNodes { ...@@ -41,11 +36,11 @@ public class TDNodes {
File file = new File(path); File file = new File(path);
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();
} }
for(int i = 0; i < tdNodes.size(); i++) { for(int i = 0; i < tdNodes.size(); i++) {
tdNodes.get(i).setPath(path); tdNodes.get(i).setPath(path);
...@@ -63,10 +58,6 @@ public class TDNodes { ...@@ -63,10 +58,6 @@ public class TDNodes {
this.valgrind = valgrind; this.valgrind = valgrind;
} }
public void setPath(String path) {
this.path = path;
}
public void check(int index) { public void check(int index) {
if(index < 1 || index > 10) { if(index < 1 || index > 10) {
System.out.println("index: " + index + " should on a scale of [1, 10]"); System.out.println("index: " + index + " should on a scale of [1, 10]");
...@@ -75,22 +66,18 @@ public class TDNodes { ...@@ -75,22 +66,18 @@ public class TDNodes {
} }
public void deploy(int index) { public void deploy(int index) {
System.out.println("======Start deploying tsim====="); try {
TDSimClient sim = new TDSimClient(); File file = new File(System.getProperty("user.dir") + "/../../../");
String projectRealPath = file.getCanonicalPath();
sim.setPath(path); check(index);
System.out.println("======path: " + path + "====="); tdNodes.get(index - 1).setTestCluster(this.testCluster);
sim.setTestCluster(this.testCluster); tdNodes.get(index - 1).setValgrind(valgrind);
if(this.simDeployed == false ) { tdNodes.get(index - 1).setPath(projectRealPath);
sim.deploy(); tdNodes.get(index - 1).deploy();
this.simDeployed = true; } catch (Exception e) {
e.printStackTrace();
System.out.println("deploy Test Exception");
} }
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).deploy();
} }
public void cfg(int index, String option, String value) { 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; package com.taosdata.jdbc;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.InputStreamReader;
import com.taosdata.jdbc.utils.TDNodes; import com.taosdata.jdbc.utils.TDNodes;
import org.junit.AfterClass; import org.junit.AfterClass;
...@@ -13,15 +10,16 @@ public class BaseTest { ...@@ -13,15 +10,16 @@ public class BaseTest {
private static boolean testCluster = false; private static boolean testCluster = false;
private static String deployPath = System.getProperty("user.dir"); private static String deployPath = System.getProperty("user.dir");
private static int valgrind = 0; private static int valgrind = 0;
private static TDNodes tdNodes = new TDNodes();
@BeforeClass @BeforeClass
public static void setupEnv() { public static void setUpEvn() {
try{ try{
File file = new File(deployPath + "/../../../"); File file = new File(deployPath + "/../../../");
String rootPath = file.getCanonicalPath(); String rootPath = file.getCanonicalPath();
TDNodes tdNodes = new TDNodes();
tdNodes.setPath(rootPath); tdNodes.setPath(rootPath);
tdNodes.setTestCluster(testCluster); tdNodes.setTestCluster(testCluster);
tdNodes.setValgrid(valgrind); tdNodes.setValgrid(valgrind);
...@@ -31,11 +29,12 @@ public class BaseTest { ...@@ -31,11 +29,12 @@ public class BaseTest {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
System.out.println("Base Test Exception");
} }
} }
@AfterClass @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.
先完成此消息的编辑!
想要评论请 注册