2017-02-05 17:31:29 +02:00
|
|
|
####################################################################################################################################
|
|
|
|
# InfoUnitTest.pm - Unit tests for Info module
|
|
|
|
####################################################################################################################################
|
2017-05-12 22:43:04 +02:00
|
|
|
package pgBackRestTest::Module::Info::InfoUnitTest;
|
|
|
|
use parent 'pgBackRestTest::Env::HostEnvTest';
|
2017-02-05 17:31:29 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# Perl includes
|
|
|
|
####################################################################################################################################
|
|
|
|
use strict;
|
|
|
|
use warnings FATAL => qw(all);
|
|
|
|
use Carp qw(confess);
|
|
|
|
use English '-no_match_vars';
|
|
|
|
|
|
|
|
use File::Basename qw(dirname);
|
|
|
|
use Storable qw(dclone);
|
|
|
|
|
2017-05-15 22:01:00 +02:00
|
|
|
use pgBackRest::Backup::Info;
|
2017-02-05 17:31:29 +02:00
|
|
|
use pgBackRest::Common::Exception;
|
|
|
|
use pgBackRest::Common::Lock;
|
|
|
|
use pgBackRest::Common::Log;
|
|
|
|
use pgBackRest::Config::Config;
|
|
|
|
use pgBackRest::DbVersion;
|
|
|
|
use pgBackRest::Info;
|
2017-04-03 16:42:55 +02:00
|
|
|
use pgBackRest::Manifest;
|
2017-05-15 17:12:14 +02:00
|
|
|
use pgBackRest::Protocol::Helper;
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRest::Protocol::Storage::Helper;
|
2017-02-05 17:31:29 +02:00
|
|
|
|
|
|
|
use pgBackRestTest::Common::ExecuteTest;
|
|
|
|
use pgBackRestTest::Common::RunTest;
|
2017-05-12 22:43:04 +02:00
|
|
|
use pgBackRestTest::Env::ExpireEnvTest;
|
2017-06-09 23:51:41 +02:00
|
|
|
use pgBackRestTest::Env::Host::HostBackupTest;
|
|
|
|
use pgBackRestTest::Env::HostEnvTest;
|
2017-02-05 17:31:29 +02:00
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# initModule
|
|
|
|
####################################################################################################################################
|
|
|
|
sub initModule
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
$self->{strRepoPath} = $self->testPath() . '/repo';
|
|
|
|
$self->{strArchivePath} = "$self->{strRepoPath}/archive/" . $self->stanza();
|
|
|
|
$self->{strBackupPath} = "$self->{strRepoPath}/backup/" . $self->stanza();
|
2017-04-03 16:42:55 +02:00
|
|
|
$self->{strDbPath} = $self->testPath() . '/db';
|
2017-02-05 17:31:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# initTest
|
|
|
|
####################################################################################################################################
|
|
|
|
sub initTest
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
# Create parent path for pg_control
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate(($self->{strDbPath} . '/' . DB_PATH_GLOBAL), {bCreateParent => true});
|
2017-04-03 16:42:55 +02:00
|
|
|
|
|
|
|
# Create archive info path
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($self->{strArchivePath}, {bIgnoreExists => true, bCreateParent => true});
|
2017-04-03 16:42:55 +02:00
|
|
|
|
|
|
|
# Create backup info path
|
2017-06-09 23:51:41 +02:00
|
|
|
storageTest()->pathCreate($self->{strBackupPath}, {bIgnoreExists => true, bCreateParent => true});
|
2017-04-03 16:42:55 +02:00
|
|
|
|
2017-05-12 21:49:14 +02:00
|
|
|
# Set options for stanzaCreate
|
|
|
|
$self->optionStanzaCreate();
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
# Create the test object
|
|
|
|
$self->{oExpireTest} = new pgBackRestTest::Env::ExpireEnvTest(undef, $self->backrestExe(), storageRepo(), undef, $self);
|
|
|
|
|
2017-05-12 21:49:14 +02:00
|
|
|
$self->{oExpireTest}->stanzaCreate($self->stanza(), PG_VERSION_94);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub optionStanzaCreate
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
# Set options for stanzaCreate
|
|
|
|
my $oOption = {};
|
2017-06-09 23:51:41 +02:00
|
|
|
|
2017-04-03 16:42:55 +02:00
|
|
|
$self->optionSetTest($oOption, OPTION_STANZA, $self->stanza());
|
|
|
|
$self->optionSetTest($oOption, OPTION_DB_PATH, $self->{strDbPath});
|
|
|
|
$self->optionSetTest($oOption, OPTION_REPO_PATH, $self->{strRepoPath});
|
|
|
|
$self->optionSetTest($oOption, OPTION_LOG_PATH, $self->testPath());
|
|
|
|
$self->optionBoolSetTest($oOption, OPTION_ONLINE, false);
|
|
|
|
$self->optionSetTest($oOption, OPTION_DB_TIMEOUT, 5);
|
|
|
|
$self->optionSetTest($oOption, OPTION_PROTOCOL_TIMEOUT, 6);
|
|
|
|
|
|
|
|
$self->configLoadExpect(dclone($oOption), CMD_STANZA_CREATE);
|
2017-02-05 17:31:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
####################################################################################################################################
|
|
|
|
# run
|
|
|
|
####################################################################################################################################
|
|
|
|
sub run
|
|
|
|
{
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
my $oOption = {};
|
|
|
|
|
2017-06-09 23:51:41 +02:00
|
|
|
$self->optionSetTest($oOption, OPTION_STANZA, $self->stanza());
|
2017-02-05 17:31:29 +02:00
|
|
|
$self->optionSetTest($oOption, OPTION_REPO_PATH, $self->{strRepoPath});
|
|
|
|
|
|
|
|
# Used to create backups and WAL to test
|
|
|
|
use constant SECONDS_PER_DAY => 86400;
|
|
|
|
my $lBaseTime = 1486137448 - (60 * SECONDS_PER_DAY);
|
|
|
|
|
|
|
|
################################################################################################################################
|
|
|
|
if ($self->begin("Info->formatTextStanza() && Info->formatTextBackup()"))
|
|
|
|
{
|
2017-06-09 23:51:41 +02:00
|
|
|
logDisable(); $self->configLoadExpect(dclone($oOption), CMD_INFO); logEnable();
|
2017-02-05 17:31:29 +02:00
|
|
|
|
|
|
|
my $oInfo = new pgBackRest::Info();
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
2017-06-09 23:51:41 +02:00
|
|
|
my $hyStanza = $oInfo->stanzaList($self->stanza());
|
2017-02-05 17:31:29 +02:00
|
|
|
$self->testResult(sub {$oInfo->formatTextStanza(@{$hyStanza}[0])},
|
|
|
|
"stanza: db\n status: error (no valid backups)\n wal archive min/max: none present", "stanza text output");
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$self->{oExpireTest}->backupCreate($self->stanza(), BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY, -1, -1);
|
2017-06-09 23:51:41 +02:00
|
|
|
$hyStanza = $oInfo->stanzaList($self->stanza());
|
2017-02-05 17:31:29 +02:00
|
|
|
|
|
|
|
$self->testResult(sub {$oInfo->formatTextStanza(@{$hyStanza}[-1])},
|
|
|
|
"stanza: db\n status: ok\n wal archive min/max: none present",
|
|
|
|
"stanza text output");
|
|
|
|
|
|
|
|
$self->testResult(sub {$oInfo->formatTextBackup(@{$hyStanza}[-1]->{&INFO_BACKUP_SECTION_BACKUP}[-1])},
|
|
|
|
" full backup: 20161206-155728F\n" .
|
|
|
|
" timestamp start/stop: 2016-12-06 15:57:28 / 2016-12-06 15:57:28\n" .
|
|
|
|
" wal start/stop: n/a\n" .
|
|
|
|
" database size: 0B, backup size: 0B\n" .
|
|
|
|
" repository size: 0B, repository backup size: 0B",
|
2017-02-13 17:03:02 +02:00
|
|
|
"full backup text output");
|
2017-02-05 17:31:29 +02:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$self->{oExpireTest}->backupCreate($self->stanza(), BACKUP_TYPE_DIFF, $lBaseTime += SECONDS_PER_DAY);
|
2017-06-09 23:51:41 +02:00
|
|
|
$hyStanza = $oInfo->stanzaList($self->stanza());
|
2017-02-05 17:31:29 +02:00
|
|
|
|
|
|
|
$self->testResult(sub {$oInfo->formatTextStanza(@{$hyStanza}[-1])},
|
|
|
|
"stanza: db\n status: ok\n wal archive min/max: 000000010000000000000000 / 000000010000000000000005",
|
|
|
|
"stanza text output");
|
|
|
|
|
|
|
|
$self->testResult(sub {$oInfo->formatTextBackup(@{$hyStanza}[-1]->{&INFO_BACKUP_SECTION_BACKUP}[-1])},
|
|
|
|
" diff backup: 20161206-155728F_20161207-155728D\n" .
|
|
|
|
" timestamp start/stop: 2016-12-07 15:57:28 / 2016-12-07 15:57:28\n" .
|
|
|
|
" wal start/stop: 000000010000000000000000 / 000000010000000000000002\n" .
|
|
|
|
" database size: 0B, backup size: 0B\n" .
|
|
|
|
" repository size: 0B, repository backup size: 0B",
|
2017-02-13 17:03:02 +02:00
|
|
|
"diff backup text output");
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$self->{oExpireTest}->backupCreate($self->stanza(), BACKUP_TYPE_INCR, $lBaseTime += SECONDS_PER_DAY, 256);
|
2017-06-09 23:51:41 +02:00
|
|
|
$hyStanza = $oInfo->stanzaList($self->stanza());
|
2017-02-13 17:03:02 +02:00
|
|
|
|
|
|
|
$self->testResult(sub {$oInfo->formatTextStanza(@{$hyStanza}[-1])},
|
|
|
|
"stanza: db\n status: ok\n wal archive min/max: 000000010000000000000000 / 000000010000000100000008",
|
|
|
|
"stanza text output");
|
|
|
|
|
|
|
|
$self->testResult(sub {$oInfo->formatTextBackup(@{$hyStanza}[-1]->{&INFO_BACKUP_SECTION_BACKUP}[-1])},
|
|
|
|
" incr backup: 20161206-155728F_20161208-155728I\n" .
|
|
|
|
" timestamp start/stop: 2016-12-08 15:57:28 / 2016-12-08 15:57:28\n" .
|
|
|
|
" wal start/stop: 000000010000000000000006 / 000000010000000100000005\n" .
|
|
|
|
" database size: 0B, backup size: 0B\n" .
|
|
|
|
" repository size: 0B, repository backup size: 0B",
|
|
|
|
"incr backup text output");
|
2017-05-12 21:49:14 +02:00
|
|
|
|
|
|
|
# Upgrade the stanza, generate archive and confirm the min/max archive is for the new (current) DB version
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
|
|
$self->optionStanzaCreate();
|
|
|
|
$self->{oExpireTest}->stanzaUpgrade($self->stanza(), PG_VERSION_95);
|
|
|
|
$self->{oExpireTest}->backupCreate($self->stanza(), BACKUP_TYPE_FULL, $lBaseTime += SECONDS_PER_DAY, 2);
|
2017-06-09 23:51:41 +02:00
|
|
|
$hyStanza = $oInfo->stanzaList($self->stanza());
|
2017-05-12 21:49:14 +02:00
|
|
|
|
|
|
|
$self->testResult(sub {$oInfo->formatTextStanza(@{$hyStanza}[-1])},
|
|
|
|
"stanza: db\n status: ok\n wal archive min/max: 000000010000000000000000 / 000000010000000000000004",
|
|
|
|
"stanza text output");
|
2017-02-05 17:31:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|