diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java index 677ed8b7a218c37c9fd979875017427f8c316ea2..f7a200b33d79dcec3a8d5e5901c66c3e9c6eb43c 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java @@ -3,6 +3,9 @@ package com.taosdata.jdbc; import org.junit.BeforeClass; import org.junit.Test; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.sql.*; import java.util.Properties; @@ -25,6 +28,7 @@ public class TSDBDriverTest { "jdbc:TAOS://localhost:0/?user=root&password=taosdata" }; private static boolean islibLoaded; + private static boolean isTaosdActived; @BeforeClass public static void before() { @@ -52,6 +56,21 @@ public class TSDBDriverTest { System.out.println("load tdengine lib failed."); islibLoaded = false; } + + try { + Process exec = Runtime.getRuntime().exec("ps -ef | grep taosd | grep -v \"grep\""); + BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream())); + int lineCnt = 0; + while (reader.readLine() != null) { + lineCnt++; + } + if (lineCnt > 0) + isTaosdActived = true; + else + isTaosdActived = false; + } catch (IOException e) { + isTaosdActived = false; + } } @Test @@ -96,7 +115,6 @@ public class TSDBDriverTest { @Test public void testConnectWithJdbcURL() { - final String url = "jdbc:TAOS://localhost:3306/log?user=root&password=taosdata"; try { if (islibLoaded) { @@ -104,7 +122,10 @@ public class TSDBDriverTest { assertNotNull("failure - connection should not be null", conn); } } catch (SQLException e) { - e.printStackTrace(); + if (!isTaosdActived) + assertEquals("failure - should throw SQLException", "TDengine Error: Unable to establish connection", e.getMessage()); + else + fail("failure - should not throw Exception"); } } @@ -121,7 +142,10 @@ public class TSDBDriverTest { assertNotNull("failure - connection should not be null", conn); } } catch (SQLException e) { - e.printStackTrace(); + if (!isTaosdActived) + assertEquals("failure - should throw SQLException", "TDengine Error: Unable to establish connection", e.getMessage()); + else + fail("failure - should not throw Exception"); } } @@ -138,7 +162,10 @@ public class TSDBDriverTest { assertNotNull("failure - connection should not be null", conn); } } catch (SQLException e) { - e.printStackTrace(); + if (!isTaosdActived) + assertEquals("failure - should throw SQLException", "TDengine Error: Unable to establish connection", e.getMessage()); + else + fail("failure - should not throw Exception"); } }