1
1
use strict;
2
2
use warnings;
3
- use PostgresNode ;
3
+ use Cluster ;
4
4
use TestLib;
5
5
use Test::More tests => 3;
6
6
use DBI;
7
7
use DBD::Pg ' :async' ;
8
8
9
- # ##############################################################################
10
- # Aux routines
11
- # ##############################################################################
12
-
13
- sub PostgresNode ::inet_connstr {
14
- my ($self , $dbname ) = @_ ;
15
- my $pgport = $self -> port;
16
- my $pghost = ' 127.0.0.1' ;
17
- my $pgdata = $self -> data_dir;
18
-
19
- if (!defined ($dbname ))
20
- {
21
- return " port=$pgport host=$pghost " ;
22
- }
23
- return " port=$pgport host=$pghost dbname=$dbname " ;
24
- }
25
-
26
- # ##############################################################################
27
- # Setup nodes
28
- # ##############################################################################
29
-
30
- my $nnodes = 3;
31
- my @nodes = ();
32
- my $pgconf_common = qq(
33
- listen_addresses = '127.0.0.1'
34
- max_prepared_transactions = 200
35
- max_connections = 200
36
- max_worker_processes = 100
37
- max_wal_senders = 10
38
- max_replication_slots = 10
39
- wal_level = logical
40
- wal_sender_timeout = 0
41
- shared_preload_libraries = 'raftable,multimaster'
42
- multimaster.workers=10
43
- multimaster.queue_size=10485760 # 10mb
44
- ) ;
45
-
46
- # Init nodes
47
- for (my $i =0; $i < $nnodes ; $i ++) {
48
- push (@nodes , get_new_node(" node$i " ));
49
- $nodes [$i ]-> init;
50
- }
51
-
52
- # Collect conn info
53
- my $mm_connstr = join (' , ' , map { " ${ \$ _->inet_connstr('postgres') }" } @nodes );
54
-
55
- # Configure and start nodes
56
- for (my $i =0; $i < $nnodes ; $i ++) {
57
- $nodes [$i ]-> append_conf(' postgresql.conf' , $pgconf_common );
58
- $nodes [$i ]-> append_conf(' postgresql.conf' , qq(
59
- #port = ${ \$ nodes[$i ]->port }
60
- multimaster.node_id = @{[ $i + 1 ]}
61
- multimaster.conn_strings = '$mm_connstr '
62
- #multimaster.arbiter_port = ${ \$ nodes[0]->port }
63
- ) );
64
- $nodes [$i ]-> append_conf(' pg_hba.conf' , qq(
65
- host replication all 127.0.0.1/32 trust
66
- ) );
67
- $nodes [$i ]-> start;
68
- }
9
+ my $cluster = new Cluster(3);
10
+ $cluster -> init();
11
+ $cluster -> configure();
12
+ $cluster -> start();
69
13
70
14
# ##############################################################################
71
15
# Wait until nodes are up
@@ -79,11 +23,11 @@ sub PostgresNode::inet_connstr {
79
23
# Replication check
80
24
# ##############################################################################
81
25
82
- $nodes [0] -> psql(' postgres' , "
26
+ $cluster -> psql(0, ' postgres' , "
83
27
create extension multimaster;
84
28
create table if not exists t(k int primary key, v int);
85
29
insert into t values(1, 10);" );
86
- $nodes [1] -> psql(' postgres' , " select v from t where k=1;" , stdout => \$psql_out );
30
+ $cluster -> psql(1, ' postgres' , " select v from t where k=1;" , stdout => \$psql_out );
87
31
is($psql_out , ' 10' , " Check replication while all nodes are up." );
88
32
89
33
# ##############################################################################
@@ -97,15 +41,15 @@ sub PostgresNode::inet_connstr {
97
41
# ##############################################################################
98
42
99
43
diag(" stopping node 2" );
100
- $nodes [2]-> teardown_node;
44
+ $cluster -> { nodes } -> [2]-> teardown_node;
101
45
102
46
diag(" sleeping 15" );
103
47
sleep (15);
104
48
105
49
diag(" inserting 2" );
106
- $nodes [0] -> psql(' postgres' , " insert into t values(2, 20);" );
50
+ $cluster -> psql(0, ' postgres' , " insert into t values(2, 20);" );
107
51
diag(" selecting" );
108
- $nodes [1] -> psql(' postgres' , " select v from t where k=2;" , stdout => \$psql_out );
52
+ $cluster -> psql(1, ' postgres' , " select v from t where k=2;" , stdout => \$psql_out );
109
53
diag(" selected" );
110
54
is($psql_out , ' 20' , " Check replication after node failure." );
111
55
@@ -114,13 +58,13 @@ sub PostgresNode::inet_connstr {
114
58
# ##############################################################################
115
59
116
60
diag(" starting node 2" );
117
- $nodes [2]-> start;
61
+ $cluster -> { nodes } -> [2]-> start;
118
62
diag(" sleeping 30" );
119
63
sleep (30); # XXX: here we can poll
120
64
diag(" inserting 3" );
121
- $nodes [0] -> psql(' postgres' , " insert into t values(3, 30);" );
65
+ $cluster -> psql(0, ' postgres' , " insert into t values(3, 30);" );
122
66
diag(" selecting" );
123
- $nodes [2] -> psql(' postgres' , " select v from t where k=3;" , stdout => \$psql_out );
67
+ $cluster -> psql(2, ' postgres' , " select v from t where k=3;" , stdout => \$psql_out );
124
68
diag(" selected" );
125
69
is($psql_out , ' 30' , " Check replication after failed node recovery." );
126
70
0 commit comments