|
153 | 153 | $rows * 2, "2x$rows rows in t");
|
154 | 154 | is($node_twoways->safe_psql('d2', "SELECT count(f) FROM t2"),
|
155 | 155 | $rows * 2, "2x$rows rows in t2");
|
| 156 | + |
| 157 | +# Verify table data is synced with cascaded replication setup. This is mainly |
| 158 | +# to test whether the data written by tablesync worker gets replicated. |
| 159 | +my $node_pub = get_new_node('testpublisher1'); |
| 160 | +$node_pub->init(allows_streaming => 'logical'); |
| 161 | +$node_pub->start; |
| 162 | + |
| 163 | +my $node_pub_sub = get_new_node('testpublisher_subscriber'); |
| 164 | +$node_pub_sub->init(allows_streaming => 'logical'); |
| 165 | +$node_pub_sub->start; |
| 166 | + |
| 167 | +my $node_sub = get_new_node('testsubscriber1'); |
| 168 | +$node_sub->init(allows_streaming => 'logical'); |
| 169 | +$node_sub->start; |
| 170 | + |
| 171 | +# Create the tables in all nodes. |
| 172 | +$node_pub->safe_psql('postgres', "CREATE TABLE tab1 (a int)"); |
| 173 | +$node_pub_sub->safe_psql('postgres', "CREATE TABLE tab1 (a int)"); |
| 174 | +$node_sub->safe_psql('postgres', "CREATE TABLE tab1 (a int)"); |
| 175 | + |
| 176 | +# Create a cascaded replication setup like: |
| 177 | +# N1 - Create publication testpub1. |
| 178 | +# N2 - Create publication testpub2 and also include subscriber which subscribes |
| 179 | +# to testpub1. |
| 180 | +# N3 - Create subscription testsub2 subscribes to testpub2. |
| 181 | +# |
| 182 | +# Note that subscription on N3 needs to be created before subscription on N2 to |
| 183 | +# test whether the data written by tablesync worker of N2 gets replicated. |
| 184 | +$node_pub->safe_psql('postgres', |
| 185 | + "CREATE PUBLICATION testpub1 FOR TABLE tab1"); |
| 186 | + |
| 187 | +$node_pub_sub->safe_psql('postgres', |
| 188 | + "CREATE PUBLICATION testpub2 FOR TABLE tab1"); |
| 189 | + |
| 190 | +my $publisher1_connstr = $node_pub->connstr . ' dbname=postgres'; |
| 191 | +my $publisher2_connstr = $node_pub_sub->connstr . ' dbname=postgres'; |
| 192 | + |
| 193 | +$node_sub->safe_psql('postgres', |
| 194 | + "CREATE SUBSCRIPTION testsub2 CONNECTION '$publisher2_connstr' PUBLICATION testpub2" |
| 195 | +); |
| 196 | + |
| 197 | +$node_pub_sub->safe_psql('postgres', |
| 198 | + "CREATE SUBSCRIPTION testsub1 CONNECTION '$publisher1_connstr' PUBLICATION testpub1" |
| 199 | +); |
| 200 | + |
| 201 | +$node_pub->safe_psql('postgres', |
| 202 | + "INSERT INTO tab1 values(generate_series(1,10))"); |
| 203 | + |
| 204 | +# Verify that the data is cascaded from testpub1 to testsub1 and further from |
| 205 | +# testpub2 (which had testsub1) to testsub2. |
| 206 | +$node_pub->wait_for_catchup('testsub1'); |
| 207 | +$node_pub_sub->wait_for_catchup('testsub2'); |
| 208 | + |
| 209 | +# Drop subscriptions as we don't need them anymore |
| 210 | +$node_pub_sub->safe_psql('postgres', "DROP SUBSCRIPTION testsub1"); |
| 211 | +$node_sub->safe_psql('postgres', "DROP SUBSCRIPTION testsub2"); |
| 212 | + |
| 213 | +# Drop publications as we don't need them anymore |
| 214 | +$node_pub->safe_psql('postgres', "DROP PUBLICATION testpub1"); |
| 215 | +$node_pub_sub->safe_psql('postgres', "DROP PUBLICATION testpub2"); |
| 216 | + |
| 217 | +# Clean up the tables on both publisher and subscriber as we don't need them |
| 218 | +$node_pub->safe_psql('postgres', "DROP TABLE tab1"); |
| 219 | +$node_pub_sub->safe_psql('postgres', "DROP TABLE tab1"); |
| 220 | +$node_sub->safe_psql('postgres', "DROP TABLE tab1"); |
| 221 | + |
| 222 | +$node_pub->stop('fast'); |
| 223 | +$node_pub_sub->stop('fast'); |
| 224 | +$node_sub->stop('fast'); |
0 commit comments