1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
use strict;
use warnings;
use Test::More;
use RRDTool::OO;
$| = 1;
use Log::Log4perl qw(:easy);
###################################################
my $LOGLEVEL = $OFF;
###################################################
Log::Log4perl->easy_init({level => $LOGLEVEL, layout => "%L: %m%n",
category => 'rrdtool',
file => 'stderr'});
my $rrd = RRDTool::OO->new(file => "foo");
eval { $SIG{__DIE__} = $SIG{__WARN__} = sub {}; $rrd->dump(); };
if($@ =~ /Can.t locate/) {
plan skip_all => "only with RRDs supporting dump/restore";
} else {
plan tests => 2;
}
# create with superfluous param
$rrd->create(
data_source => { name => 'foobar',
type => 'GAUGE',
},
archive => { cfunc => 'MAX',
xff => '0.5',
cpoints => 5,
rows => 10,
},
);
ok(-e "foo", "RRD exists");
my $size = -s "foo";
#####################################################
# Dump it.
#####################################################
my $pid;
unless ($pid = open DUMP, "-|") {
die "Can't fork: $!" unless defined $pid;
$rrd->dump();
exit 0;
}
#print "\$\$ = $$, pid=$pid\n";
waitpid($pid, 0);
open OUT, ">out";
print OUT $_ for <DUMP>;
close OUT;
unlink "foo";
#####################################################
# Restore it.
#####################################################
$rrd->restore("out");
ok(-f "foo", "RRD resurrected");
END { unlink "foo";
unlink "out";
}
|