Skip to content

Commit

Permalink
fix: add transaction test in cluster mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hantmac committed Sep 5, 2024
1 parent 6cf07e5 commit ae8b885
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions databend-jdbc/src/test/java/com/databend/jdbc/TestMultiHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import java.sql.SQLException;

public class TestMultiHost {
private final String DEFAULT_JDBC_URL = "jdbc:databend://localhost:8000,localhost:8002,localhost:8003/default";
private final String RANDOM_JDBC_URL = "jdbc:databend://localhost:8000,localhost:8002,localhost:8003/default?load_balancing_policy=random";
private final String ROUND_ROBIN_JDBC_URL = "jdbc:databend://localhost:8000,localhost:8002,localhost:8003/default?load_balancing_policy=round_robin";
private final String FAIL_OVER_JDBC_URL = "jdbc:databend://localhost:7222,localhost:7223,localhost:7224,localhost:8000/default?load_balancing_policy=round_robin&max_failover_retry=4";
private final String DEFAULT_JDBC_URL = "jdbc:databend://localhost:8000,localhost:8002,localhost:8003/default";
private final String RANDOM_JDBC_URL = "jdbc:databend://localhost:8000,localhost:8002,localhost:8003/default?load_balancing_policy=random";
private final String ROUND_ROBIN_JDBC_URL = "jdbc:databend://localhost:8000,localhost:8002,localhost:8003/default?load_balancing_policy=round_robin";
private final String FAIL_OVER_JDBC_URL = "jdbc:databend://localhost:7222,localhost:7223,localhost:7224,localhost:8000/default?load_balancing_policy=round_robin&max_failover_retry=4";

private Connection createConnection(String url)
throws SQLException {
return DriverManager.getConnection(url, "databend", "databend");
Expand All @@ -33,15 +34,15 @@ public void testDefaultLoadBalancing()
statement.execute("select value from system.configs where name = 'http_handler_port';");
ResultSet r = statement.getResultSet();
r.next();
if (r.getInt(1) == 8000) {
node8000++;
} else if (r.getInt(1) == 8002) {
node8002++;
} else if (r.getInt(1) == 8003) {
node8003++;
} else {
unknown++;
}
if (r.getInt(1) == 8000) {
node8000++;
} else if (r.getInt(1) == 8002) {
node8002++;
} else if (r.getInt(1) == 8003) {
node8003++;
} else {
unknown++;
}
}
}
Assert.assertEquals(node8000, 100);
Expand Down Expand Up @@ -81,6 +82,26 @@ public void testRandomLoadBalancing()
Assert.assertEquals(node8000 + node8002 + node8003, 100);
}


@Test(groups = {"IT", "cluster"})
public void testTransactionInRobinLoadBalancing()
throws SQLException {
try (Connection connection = createConnection(ROUND_ROBIN_JDBC_URL)) {
DatabendStatement statement = (DatabendStatement) connection.createStatement();
statement.execute("BEGIN");
statement.execute("create table if not exists test (id int)");
}
try (Connection connection = createConnection(ROUND_ROBIN_JDBC_URL)) {
DatabendStatement statement = (DatabendStatement) connection.createStatement();
statement.execute("insert into test values (1)");
statement.execute("COMMIT");
} catch (SQLException e) {
e.printStackTrace();
// there should have exception because change query node
Assert.fail();
}
}

@Test(groups = {"IT", "cluster"})
public void testRoundRobinLoadBalancing()
throws SQLException {
Expand Down

0 comments on commit ae8b885

Please sign in to comment.