Add new test file 50-star.t
authorGreg Sabino Mullane <greg@endpoint.com>
Thu, 27 Nov 2014 17:49:37 +0000 (12:49 -0500)
committerGreg Sabino Mullane <greg@endpoint.com>
Thu, 27 Nov 2014 17:49:37 +0000 (12:49 -0500)
Changes
MANIFEST
README.dev
t/50-star.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index ef905f406151290c1ffef51769c4173ab38c350c..106cffaa316a08111eaa5270c9d4a0ba59256cf5 100644 (file)
--- a/Changes
+++ b/Changes
@@ -12,6 +12,9 @@ Bucardo version 5.3.0
   - Better support for continuing once a database has crashed
     [Greg Sabino Mullane]
 
+  - New test file t/50-star.t and much improvement to testing framework
+    [Greg Sabino Mullane]
+
 
 Bucardo version 5.2.0, released November 5, 2014 (git commit 003b827a73a6e2e51cc5e833a5b4bc21631bd216)
 
index 55c5e6558e8693c203a50aa2d16ad9d417be0e02..1de7a6bdaebaf21ba03147c35de8fd468a23df76 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -49,6 +49,7 @@ t/30-delta.t
 t/40-conflict.t
 t/40-customcode-exception.t
 t/40-serializable.t
+t/50-star.t
 t/98-cleanup.t
 t/99-signature.t
 t/BucardoTesting.pm
index f898256215642a88a8b3db2aade4db16734a4e4f..c6aff9d809567c149ae1c680e49cbf0a846bb9b5 100644 (file)
@@ -126,7 +126,7 @@ t/13-ddl.t - Test pushing DDL (not complete yet)
 
 t/14-truncate.t - Test of truncation replication (requires Postgres 8.4 or greater)
 
-t/15-star.t - Test of star replication scheme
+t/50-star.t - Test of star replication scheme
 
 t/98-cleanup.t - Shuts down test databases. Called by "make distclean"
 
diff --git a/t/50-star.t b/t/50-star.t
new file mode 100644 (file)
index 0000000..bc2199b
--- /dev/null
@@ -0,0 +1,117 @@
+#!/usr/bin/env perl
+# -*-mode:cperl; indent-tabs-mode: nil-*-
+
+## Test Bucardo in a large star network
+## We will use 'A' as the hub, and the three others B C D, each having multiple dbs
+
+use 5.008003;
+use strict;
+use warnings;
+use Data::Dumper;
+use lib 't','.';
+use DBD::Pg;
+use Test::More;
+
+use vars qw/ $dbhX $dbhA $dbhB $dbhC $dbhD $res $command $t $SQL $sth $count /;
+
+use BucardoTesting;
+my $bct = BucardoTesting->new({location => 'star'})
+    or BAIL_OUT "Creation of BucardoTesting object failed\n";
+
+pass("*** Beginning star tests");
+
+END {
+    $bct and $bct->stop_bucardo();
+    $dbhX and $dbhX->disconnect();
+    $dbhA and $dbhA->disconnect();
+    $dbhB and $dbhB->disconnect();
+    $dbhC and $dbhC->disconnect();
+    $dbhD and $dbhD->disconnect();
+}
+
+## Get A, B, C, and D created, emptied out, and repopulated with sample data
+my $extras = 5;
+$dbhA = $bct->repopulate_cluster('A');
+$dbhB = $bct->repopulate_cluster('B',$extras);
+$dbhC = $bct->repopulate_cluster('C',$extras);
+$dbhD = $bct->repopulate_cluster('D',$extras);
+
+## Create a bucardo database, and install Bucardo into it
+$dbhX = $bct->setup_bucardo('A');
+
+## Teach Bucardo about all databases
+my (@alldbs, @alldbhs);
+for my $name (qw/ A B C D /) {
+    my ($dbuser,$dbport,$dbhost) = $bct->add_db_args($name);
+    for my $number (0..$extras) {
+        my $dbname = 'bucardo_test';
+        my $bname = $name;
+        ## Always a single hub
+        next if $number and $name eq 'A';
+        if ($number) {
+            $dbname .= $number;
+            $bname .= $number;
+        }
+        $t = "Added database $bname for database $dbname";
+        $command = "bucardo add db $bname dbname=$dbname user=$dbuser port=$dbport host=$dbhost";
+        $command .= ' makedelta=1' if $name eq 'A';
+        $res = $bct->ctl($command);
+        like ($res, qr/Added database "$bname"/, $t);
+        push @alldbs => $bname;
+        my $dbh = $bct->connect_database($bname);
+        push @alldbhs => $dbh;
+    }
+}
+
+## Put all pk tables into a relgroup
+$t = q{Added all PK tables to a relgroup named 'allpk'};
+$res = $bct->ctl(q{bucardo add tables '*bucardo*test*' '*Bucardo*test*' db=A relgroup=allpk pkonly});
+like ($res, qr/Created the relgroup named "allpk".*are now part of/s, $t);
+
+## Make a simpler relgroup of just one table
+$t = q{Created relgroup of just bucardo_test1 named 'rel1'};
+$res = $bct->ctl(q{bucardo add relgroup rel1 bucardo_test1});
+like ($res, qr/relgroup "rel1"/s, $t);
+
+## Create a lot of syncs. Each simulates a multi-source from center to a distinct server leaf
+my $number = 2;
+for my $db (qw/ B C D /) {
+    for my $num (0..$extras) {
+        my $syncname = "star$number";
+        my $leaf = sprintf '%s%s', $db, $num || '';
+        $t = qq{Created a new sync $syncname going for A <=> $leaf};
+        my $command = "bucardo add sync $syncname relgroup=rel1 dbs=A,$leaf:source autokick=true";
+        $res = $bct->ctl($command);
+        like ($res, qr/Added sync "$syncname"/, $t);
+        $number++;
+    }
+}
+
+## Start up the Bucardo daemon
+$bct->restart_bucardo($dbhX);
+
+## Add a row to A and make sure it gets to all leafs
+$bct->add_row_to_database('A', 1);
+$bct->ctl('bucardo kick sync star1 0');
+sleep 5;
+$bct->check_for_row([[1]], \@alldbs, '', 'bucardo_test1');
+
+$number = 0;
+my $maxnumber = 1;
+$SQL = 'INSERT INTO bucardo_test1(id,inty) VALUES (?,?)';
+for my $dbh (@alldbhs) {
+    $number++;
+    next if $number < 2; ## Do ont want to add anything to the "A" database
+    $dbh->do($SQL, undef, $number, $number);
+    $dbh->commit();
+    $maxnumber = $number;
+}
+sleep 5;
+
+my $result = [];
+push @$result, [$_] for 1..$maxnumber;
+$bct->check_for_row($result, [qw/ A B C D /], '', 'bucardo_test1');
+
+$bct->ctl('bucardo stop');
+
+done_testing();