commit
4e15e67eaa
|
@ -5,24 +5,24 @@ import com.taosdata.jdbc.utils.TDNodes;
|
|||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class BaseTest {
|
||||
public abstract class BaseTest {
|
||||
|
||||
private static boolean testCluster = false;
|
||||
private static boolean testCluster = false;
|
||||
private static TDNodes nodes = new TDNodes();
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void setupEnv() {
|
||||
try{
|
||||
try {
|
||||
if (nodes.getTDNode(1).getTaosdPid() != null) {
|
||||
System.out.println("Kill taosd before running JDBC test");
|
||||
nodes.getTDNode(1).setRunning(1);
|
||||
nodes.stop(1);
|
||||
}
|
||||
nodes.setTestCluster(testCluster);
|
||||
nodes.setTestCluster(testCluster);
|
||||
nodes.deploy(1);
|
||||
nodes.start(1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package com.taosdata.jdbc.cases;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class FailOverTest {
|
||||
|
||||
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
||||
|
||||
@Test
|
||||
public void testFailOver() throws ClassNotFoundException {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
final String url = "jdbc:TAOS://:/?user=root&password=taosdata";
|
||||
|
||||
long end = System.currentTimeMillis() + 1000 * 60 * 5;
|
||||
while (System.currentTimeMillis() < end) {
|
||||
try (Connection conn = DriverManager.getConnection(url)) {
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet resultSet = stmt.executeQuery("select server_status()");
|
||||
resultSet.next();
|
||||
int status = resultSet.getInt("server_status()");
|
||||
System.out.println(">>>>>>>>>" + sdf.format(new Date()) + " status : " + status);
|
||||
stmt.close();
|
||||
TimeUnit.SECONDS.sleep(5);
|
||||
} catch (SQLException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue