change
This commit is contained in:
parent
88232e2e35
commit
7be93e1908
|
@ -1,50 +1,37 @@
|
||||||
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
|
|
||||||
public void before() {
|
|
||||||
try {
|
|
||||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
|
||||||
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
|
@Test
|
||||||
public void testFailOver() {
|
public void testFailOver() throws ClassNotFoundException {
|
||||||
try (Statement stmt = conn.createStatement()) {
|
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||||
ResultSet resultSet = stmt.executeQuery("select server_status()");
|
final String url = "jdbc:TAOS://:/?user=root&password=taosdata";
|
||||||
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();
|
||||||
|
TimeUnit.SECONDS.sleep(5);
|
||||||
|
} catch (SQLException | InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
|
||||||
public void after() {
|
|
||||||
try {
|
|
||||||
if (conn != null)
|
|
||||||
conn.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue