提交 7be93e19 编写于 作者: Z zyyang

change

上级 88232e2e
package com.taosdata.jdbc.cases; package com.taosdata.jdbc.cases;
import com.taosdata.jdbc.lib.TSDBCommon;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.sql.*; import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
public class FailOverTest { public class FailOverTest {
private Connection conn; private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
@Before @Test
public void before() { public void testFailOver() throws ClassNotFoundException {
try {
Class.forName("com.taosdata.jdbc.TSDBDriver"); Class.forName("com.taosdata.jdbc.TSDBDriver");
final String url = "jdbc:TAOS://:/?user=root&password=taosdata"; final String url = "jdbc:TAOS://:/?user=root&password=taosdata";
conn = DriverManager.getConnection(url);
TSDBCommon.createDatabase(conn, "failover_test");
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
@Test
public void testFailOver() {
try (Statement stmt = conn.createStatement()) {
ResultSet resultSet = stmt.executeQuery("select server_status()");
while (true) { while (true) {
try (Connection conn = DriverManager.getConnection(url)) {
Statement stmt = conn.createStatement();
ResultSet resultSet = stmt.executeQuery("select server_status()");
resultSet.next(); resultSet.next();
int status = resultSet.getInt("server_status()"); int status = resultSet.getInt("server_status()");
System.out.println(">>>>>>>>> status : " + status); System.out.println(">>>>>>>>>" + sdf.format(new Date()) + " status : " + status);
} stmt.close();
} catch (SQLException e) { TimeUnit.SECONDS.sleep(5);
} catch (SQLException | InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@After
public void after() {
try {
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册