|
1 | 1 | use strict; |
2 | 2 | use warnings; |
3 | 3 |
|
4 | | -usePostgresNode; |
| 4 | +useCluster; |
5 | 5 | use TestLib; |
6 | 6 | use Test::Moretests=> 1; |
7 | 7 |
|
@@ -34,98 +34,19 @@ sub query_exec_async |
34 | 34 | return$rv; |
35 | 35 | } |
36 | 36 |
|
37 | | -my%allocated_ports = (); |
38 | | -suballocate_ports |
39 | | -{ |
40 | | -my@allocated_now = (); |
41 | | -my ($host,$ports_to_alloc) =@_; |
42 | | - |
43 | | -while ($ports_to_alloc > 0) |
44 | | -{ |
45 | | -my$port =int(rand() * 16384) + 49152; |
46 | | -nextif$allocated_ports{$port}; |
47 | | -diag("Checking for port$port\n"); |
48 | | -if (!TestLib::run_log(['pg_isready','-h',$host,'-p',$port])) |
49 | | -{ |
50 | | -$allocated_ports{$port} = 1; |
51 | | -push(@allocated_now,$port); |
52 | | -$ports_to_alloc--; |
53 | | -} |
54 | | -} |
55 | | - |
56 | | -return@allocated_now; |
57 | | -} |
58 | | - |
59 | | -my$nnodes = 2; |
60 | | -my@nodes = (); |
61 | | - |
62 | | -# Create nodes and allocate ports |
63 | | -foreachmy$i (1..$nnodes) |
64 | | -{ |
65 | | -my$host ="127.0.0.1"; |
66 | | -my ($pgport,$raftport) = allocate_ports($host, 2); |
67 | | -my$node = new PostgresNode("node$i",$host,$pgport); |
68 | | -$node->{id} =$i; |
69 | | -$node->{raftport} =$raftport; |
70 | | -push(@nodes,$node); |
71 | | -} |
| 37 | +my$cluster = new Cluster(2); |
72 | 38 |
|
73 | | -my$mm_connstr =join(',',map {"${\$_->connstr('postgres') }" }@nodes); |
74 | | -my$raft_peers =join(',',map {join(':',$_->{id},$_->host,$_->{raftport}) }@nodes); |
75 | | - |
76 | | -diag("mm_connstr =$mm_connstr\n"); |
77 | | -diag("raft_peers =$raft_peers\n"); |
78 | | - |
79 | | -# Init and Configure |
80 | | -foreachmy$node (@nodes) |
81 | | -{ |
82 | | -my$id =$node->{id}; |
83 | | -my$host =$node->host; |
84 | | -my$pgport =$node->port; |
85 | | -my$raftport =$node->{raftport}; |
86 | | - |
87 | | -$node->init(hba_permit_replication=> 0); |
88 | | -$node->append_conf("postgresql.conf",qq( |
89 | | -listen_addresses = '$host' |
90 | | -unix_socket_directories = '' |
91 | | -port =$pgport |
92 | | -max_prepared_transactions = 10 |
93 | | -max_worker_processes = 10 |
94 | | -wal_level = logical |
95 | | -fsync = off |
96 | | -max_wal_senders = 10 |
97 | | -wal_sender_timeout = 0 |
98 | | -max_replication_slots = 10 |
99 | | -shared_preload_libraries = 'raftable,multimaster' |
100 | | -multimaster.workers = 4 |
101 | | -multimaster.queue_size = 10485760 # 10mb |
102 | | -multimaster.node_id =$id |
103 | | -multimaster.conn_strings = '$mm_connstr' |
104 | | -multimaster.use_raftable = true |
105 | | -raftable.id =$id |
106 | | -raftable.peers = '$raft_peers' |
107 | | -)); |
108 | | - |
109 | | -$node->append_conf("pg_hba.conf",qq( |
110 | | -local replication all trust |
111 | | -host replication all 127.0.0.1/32 trust |
112 | | -host replication all ::1/128 trust |
113 | | -)); |
114 | | -} |
115 | | - |
116 | | -# Start |
117 | | -foreachmy$node (@nodes) |
118 | | -{ |
119 | | -$node->start(); |
120 | | -} |
| 39 | +$cluster->init(); |
| 40 | +$cluster->configure(); |
| 41 | +$cluster->start(); |
121 | 42 |
|
122 | 43 | my ($rc,$out,$err); |
123 | 44 | sleep(10); |
124 | 45 |
|
125 | | -$nodes[0]->psql('postgres',"create table t(k int primary key, v text)"); |
126 | | -$nodes[0]->psql('postgres',"insert into t values (1, 'hello'), (2, 'world')"); |
| 46 | +$cluster->psql(0,'postgres',"create table t(k int primary key, v text)"); |
| 47 | +$cluster->psql(0,'postgres',"insert into t values (1, 'hello'), (2, 'world')"); |
127 | 48 |
|
128 | | -my@conns =map { DBI->connect('DBI:Pg:' .$_->connstr()) }@nodes; |
| 49 | +my@conns =map { DBI->connect('DBI:Pg:' .$_->connstr()) } @{$cluster->{nodes}}; |
129 | 50 |
|
130 | 51 | query_exec($conns[0],"begin"); |
131 | 52 | query_exec($conns[1],"begin"); |
|