diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNode.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNode.java index 4db4d8f7c1f23cbebbc4a9fcec7230904e15fd60..12d026c0b3e16ebeebdd49d15453e536f333645c 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNode.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNode.java @@ -37,23 +37,22 @@ public class TDNode { this.testCluster = testCluster; } - public void searchTaosd(File dir, ArrayList 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); - } - } + if(fileList == null || fileList.length == 0) { + return; } - return; + for(File file : fileList) { + if(file.isFile()) { + if(file.getName().equals("taosd")) { + taosdPath.add(file.getAbsolutePath()); + } + } else { + searchTaosd(file, taosdPath); + } + } } public void start() { @@ -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-reacāˆhable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes"; cmd = "nohup " + valgrindCmdline + " " + binPath + " -c " + this.cfgDir + " 2>&1 & "; } @@ -152,7 +151,7 @@ public class TDNode { public void startIP() { 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(); } catch (Exception e) { e.printStackTrace(); @@ -162,7 +161,7 @@ public class TDNode { public void stopIP() { 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(); } catch (Exception e) { e.printStackTrace(); @@ -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"); diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNodes.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNodes.java index bce985bcc02e0410a9e241ab78e154ea1ba2bac0..2aa33a18408c8809a4e0212ce645475804598856 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNodes.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNodes.java @@ -3,34 +3,29 @@ package com.taosdata.jdbc.utils; import java.io.File; import java.util.*; - public class TDNodes { - private ArrayList tdNodes; - private boolean simDeployed; + private ArrayList tdNodes; private boolean testCluster; - private int valgrind; - private String path; + private int valgrind; 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(); @@ -41,11 +36,11 @@ public class TDNodes { File file = new File(path); binPath = file.getCanonicalPath(); System.out.println("binPath real path: " + binPath); - - if (!path.isEmpty()) { + + if(path.isEmpty()){ file = new File(path + "/../../"); path = file.getCanonicalPath(); - } + } for(int i = 0; i < tdNodes.size(); i++) { tdNodes.get(i).setPath(path); @@ -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(projectRealPath); + tdNodes.get(index - 1).deploy(); + } 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) { diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDSimClient.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDSimClient.java deleted file mode 100644 index fec824f7dd2db2bd40f08e25b553bf00cfc4fc33..0000000000000000000000000000000000000000 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDSimClient.java +++ /dev/null @@ -1,91 +0,0 @@ -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 diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java index 17ea54dd75e48d661209be176a88aa2ee7c6741e..8156818c1b9763b74d5659498a787519029a6420 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java @@ -1,9 +1,6 @@ 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; @@ -13,15 +10,16 @@ public class BaseTest { private static boolean testCluster = false; 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 - 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