From 7be93e19085a0c42376d59ad86d2961d8741e15a Mon Sep 17 00:00:00 2001 From: zyyang Date: Wed, 18 Nov 2020 18:16:48 +0800 Subject: [PATCH] change --- .../com/taosdata/jdbc/cases/FailOverTest.java | 47 +++++++------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/FailOverTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/FailOverTest.java index eab7ba3ea7..dd223777d9 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/FailOverTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/FailOverTest.java @@ -1,50 +1,37 @@ package com.taosdata.jdbc.cases; -import com.taosdata.jdbc.lib.TSDBCommon; import org.junit.After; import org.junit.Before; import org.junit.Test; import java.sql.*; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.concurrent.TimeUnit; public class FailOverTest { - private Connection conn; - - @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(); - } - } + private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); @Test - public void testFailOver() { - try (Statement stmt = conn.createStatement()) { - ResultSet resultSet = stmt.executeQuery("select server_status()"); - while (true) { + public void testFailOver() throws ClassNotFoundException { + Class.forName("com.taosdata.jdbc.TSDBDriver"); + final String url = "jdbc:TAOS://:/?user=root&password=taosdata"; + + while (true) { + 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(">>>>>>>>> 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(); - } - } } -- GitLab