change
This commit is contained in:
parent
e7bb764bd3
commit
ae26d9ac43
|
@ -3,6 +3,9 @@ package com.taosdata.jdbc;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@ -25,6 +28,7 @@ public class TSDBDriverTest {
|
||||||
"jdbc:TAOS://localhost:0/?user=root&password=taosdata"
|
"jdbc:TAOS://localhost:0/?user=root&password=taosdata"
|
||||||
};
|
};
|
||||||
private static boolean islibLoaded;
|
private static boolean islibLoaded;
|
||||||
|
private static boolean isTaosdActived;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void before() {
|
public static void before() {
|
||||||
|
@ -52,6 +56,21 @@ public class TSDBDriverTest {
|
||||||
System.out.println("load tdengine lib failed.");
|
System.out.println("load tdengine lib failed.");
|
||||||
islibLoaded = false;
|
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
|
@Test
|
||||||
|
@ -96,7 +115,6 @@ public class TSDBDriverTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectWithJdbcURL() {
|
public void testConnectWithJdbcURL() {
|
||||||
|
|
||||||
final String url = "jdbc:TAOS://localhost:3306/log?user=root&password=taosdata";
|
final String url = "jdbc:TAOS://localhost:3306/log?user=root&password=taosdata";
|
||||||
try {
|
try {
|
||||||
if (islibLoaded) {
|
if (islibLoaded) {
|
||||||
|
@ -104,7 +122,10 @@ public class TSDBDriverTest {
|
||||||
assertNotNull("failure - connection should not be null", conn);
|
assertNotNull("failure - connection should not be null", conn);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} 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);
|
assertNotNull("failure - connection should not be null", conn);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} 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);
|
assertNotNull("failure - connection should not be null", conn);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} 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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue