|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | +use TestLib; |
| 4 | +use PostgresNode; |
| 5 | +use Test::More tests => 15; |
| 6 | + |
| 7 | +program_help_ok('pg_recvlogical'); |
| 8 | +program_version_ok('pg_recvlogical'); |
| 9 | +program_options_handling_ok('pg_recvlogical'); |
| 10 | + |
| 11 | +my $node = get_new_node('main'); |
| 12 | + |
| 13 | +# Initialize node without replication settings |
| 14 | +$node->init(allows_streaming => 1, has_archiving => 1); |
| 15 | +$node->append_conf('postgresql.conf', q{ |
| 16 | +wal_level = 'logical' |
| 17 | +max_replication_slots = 4 |
| 18 | +max_wal_senders = 4 |
| 19 | +log_min_messages = 'debug1' |
| 20 | +log_error_verbosity = verbose |
| 21 | +}); |
| 22 | +$node->dump_info; |
| 23 | +$node->start; |
| 24 | + |
| 25 | +$node->command_fails(['pg_recvlogical'], |
| 26 | + 'pg_recvlogical needs a slot name'); |
| 27 | +$node->command_fails(['pg_recvlogical', '-S', 'test'], |
| 28 | + 'pg_recvlogical needs a database'); |
| 29 | +$node->command_fails(['pg_recvlogical', '-S', 'test', '-d', 'postgres'], |
| 30 | + 'pg_recvlogical needs an action'); |
| 31 | +$node->command_fails(['pg_recvlogical', '-S', 'test', '-d', $node->connstr('postgres'), '--start'], |
| 32 | + 'no destionation file'); |
| 33 | + |
| 34 | +$node->command_ok(['pg_recvlogical', '-S', 'test', '-d', $node->connstr('postgres'), '--create-slot'], |
| 35 | + 'slot created'); |
| 36 | + |
| 37 | +my $slot = $node->slot('test'); |
| 38 | +isnt($slot->{'restart_lsn'}, '', 'restart lsn is defined for new slot'); |
| 39 | + |
| 40 | +$node->psql('postgres', 'CREATE TABLE test_table(x integer)'); |
| 41 | +$node->psql('postgres', 'INSERT INTO test_table(x) SELECT y FROM generate_series(1, 10) a(y);'); |
| 42 | +my $nextlsn = $node->safe_psql('postgres', 'SELECT pg_current_xlog_insert_location()'); |
| 43 | +chomp($nextlsn); |
| 44 | + |
| 45 | +$node->command_ok(['pg_recvlogical', '-S', 'test', '-d', $node->connstr('postgres'), '--start', '--endpos', "$nextlsn", '--no-loop', '-f', '-'], |
| 46 | + 'replayed a transaction'); |
0 commit comments