#!/bin/bash # vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # runtest.sh of /CoreOS/postgresql/Sanity/postgres-decoderbufs # Description: Sanity test for postgres-decoderbufs plugin # Author: Jiri Pechanec # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # Copyright (c) 2015 Red Hat, Inc. # # This program is free software: you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 2 of # the License, or (at your option) any later version. # # This program is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/. # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Include Beaker environment . /usr/share/beakerlib/beakerlib.sh || exit 1 PACKAGE="postgresql" PACKAGE_DECODERBUFS="postgres-decoderbufs" rlJournalStart rlPhaseStart FAIL "Setup" rlRun "rlImport database/postgresql" PGDATA="$(postgresqlGetDataDir)"; PACKAGES="$PACKAGES ${postgresqlPackagePrefix}${PACKAGE_DECODERBUFS} \ ${postgresqlPackagePrefix}${PACKAGE} \ ${postgresqlPackagePrefix}${PACKAGE}-server"; for PACKAGE in $PACKAGES; do rlAssertRpm $PACKAGE done rlRun "postgresqlStop"; [[ -d ${postgresqlDataDir} ]] && rlFileBackup "${postgresqlDataDir}" rlRun "postgresqlCleanup" rlRun "postgresqlStart" rlRun "sed -i -e \"s/#shared_preload_libraries = ''/shared_preload_libraries = 'decoderbufs'/\" ${PGDATA}/postgresql.conf" 0 "Adding decoderbufs to the shared_preload_libraries in the config file ..." rlRun "sed -i -e \"s/#wal_level = replica/wal_level = logical/\" ${PGDATA}/postgresql.conf" 0 "Configuring wal_level to logical..." rlRun "postgresqlStop"; rlRun "postgresqlStart" rlPhaseEnd rlPhaseStartTest rlRun "postgresqlQuery \"DROP TABLE IF EXISTS streaming_table;\""; rlRun "postgresqlQuery \"CREATE TABLE streaming_table (id int, name varchar(32));\"" 0; rlRun "postgresqlQuery \"SELECT * FROM pg_drop_replication_slot('test');\"" 0,3; rlRun "postgresqlQuery \"SELECT * FROM pg_create_logical_replication_slot('test', 'decoderbufs');\"" 0; rlRun "postgresqlQuery \"INSERT INTO streaming_table VALUES (1, 'myname');\"" 0; rlRun -s "postgresqlQuery \"SELECT data FROM pg_logical_slot_peek_changes('test', NULL, 1, 'debug-mode', 'true');\"" 0; rlAssertGrep 'column_name\[id\], column_type\[23\], datum\[1\]' $rlRun_LOG -E rlRun "postgresqlQuery \"DROP TABLE IF EXISTS streaming_table;\"" 0; rlRun "postgresqlQuery \"SELECT * FROM pg_drop_replication_slot('test');\"" 0; rlPhaseEnd rlPhaseStart WARN "Cleanup"; rm -f $rlRun_LOG; rlRun "postgresqlCleanup"; rlFileRestore; rlPhaseEnd rlJournalPrintText rlJournalEnd