Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9352738

Browse files
funbringerkelvich
authored andcommitted
test nodes (jdbc reconnect)
1 parent 2b6b2f8 commit 9352738

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

tests_testgres/connect.jsh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
/env --class-path /usr/share/java/postgresql-jdbc/postgresql-jdbc4.jar
3+
4+
import java.sql.*;
5+
Class.forName("org.postgresql.Driver");
6+
7+
int port1 = 12928;
8+
int port2 = 16682;
9+
int port3 = 18521;
10+
String connstring = String.format("jdbc:postgresql://localhost:%d,localhost:%d,localhost:%d/postgres", port1, port2, port3);
11+
12+
/* connect to DB */
13+
Connection con = DriverManager.getConnection(connstring);
14+
15+
/* show help */
16+
System.out.println("Use 'con' object!");
17+
18+
/* execute some commands */
19+
System.out.println("Execute 'SELECT 1'");
20+
Statement stmt = con.createStatement();
21+
ResultSet rs = stmt.executeQuery("select 1");
22+
rs.next();
23+
String s = rs.getString(1);
24+
System.out.println("result = " + s);
25+

tests_testgres/test_failover.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python
2+
3+
from mm_cluster import Cluster
4+
5+
6+
with Cluster(3).start().install() as cluster:
7+
print("Cluster is working")
8+
9+
node_id = 0
10+
for node in cluster.nodes:
11+
node_id += 1
12+
13+
print("Node #{}".format(node_id))
14+
print("\t-> pid: {}".format(node.get_pid()))
15+
print("\t-> port: {}".format(node.port))
16+
print("\t-> arbiter port: {}".format(node.mm_port))
17+
print("\t-> dir: {}".format(node.base_dir))
18+
print()
19+
20+
jshell = """
21+
/env --class-path /usr/share/java/postgresql-jdbc/postgresql-jdbc4.jar
22+
23+
import java.sql.*;
24+
Class.forName("org.postgresql.Driver");
25+
26+
int port1 = {};
27+
int port2 = {};
28+
int port3 = {};
29+
String connstring = String.format("jdbc:postgresql://localhost:%d,localhost:%d,localhost:%d/postgres", port1, port2, port3);
30+
31+
/* connect to DB */
32+
Connection con = DriverManager.getConnection(connstring);
33+
34+
/* show help */
35+
System.out.println("Use 'con' object!");
36+
37+
/* execute some commands */
38+
System.out.println("Execute 'SELECT 1'");
39+
Statement stmt = con.createStatement();
40+
ResultSet rs = stmt.executeQuery("select 1");
41+
rs.next();
42+
String s = rs.getString(1);
43+
System.out.println("result = " + s);
44+
""".format(cluster.nodes[0].port,
45+
cluster.nodes[1].port,
46+
cluster.nodes[2].port)
47+
48+
with open('connect.jsh', 'w') as f:
49+
f.write(jshell)
50+
print("Now run jshell with connect.jsh")
51+
print()
52+
53+
print("Press ctrl+C to exit")
54+
55+
while True:
56+
import time
57+
time.sleep(1)

0 commit comments

Comments
 (0)