## Testing-related stuff
.perlcriticrc
t/01-basic.t
-t/06-multicolpk.t
-t/06-multicolpushdelta.t
-t/07-multicolswap.t
t/08-wildkick.t
t/09-uniqueconstraint.t
t/10-fullcopy.t
+++ /dev/null
-#!perl
-
-## Test of multi-col PK replication
-
-use 5.008003;
-use strict;
-use warnings;
-use Data::Dumper;
-use lib 't','.';
-use DBD::Pg;
-use Test::More 'no_plan';
-
-use BucardoTesting;
-my $bct = BucardoTesting->new() or BAIL_OUT "Creation of BucardoTesting object failed\n";
-$location = 'fullcopy';
-
-use vars qw/$SQL $sth $t $i $result $count %sql %val %pkey/;
-
-pass("*** Beginning 'fullcopy' tests");
-
-## Prepare a clean Bucardo database on A
-my $dbhA = $bct->blank_database('A');
-my $dbhX = $bct->setup_bucardo(A => $dbhA);
-
-## Server A is the master, the rest are slaves
-my $dbhB = $bct->blank_database('B');
-my $dbhC = $bct->blank_database('C');
-
-$dbhA->do(qq{ALTER TABLE bucardo_test1 DROP CONSTRAINT bucardo_test1_pkey});
-$dbhA->do(qq{ALTER TABLE bucardo_test1 ADD CONSTRAINT bucardo_test1_pkey2 PRIMARY KEY (data1,inty)});
-$dbhA->commit();
-
-$dbhB->do(qq{ALTER TABLE bucardo_test1 DROP CONSTRAINT bucardo_test1_pkey});
-$dbhB->do(qq{ALTER TABLE bucardo_test1 ADD CONSTRAINT bucardo_test1_pkey2 PRIMARY KEY (data1,inty)});
-$dbhB->commit();
-
-## Tell Bucardo about these databases
-$bct->add_test_databases('A B C');
-
-## Create a herd for 'A' and add all test tables to it
-$bct->add_test_tables_to_herd('A', 'testherd1');
-
-## Create a new sync to fullcopy from A to B
-$t=q{Add sync works};
-$i = $bct->ctl("add sync multicoltest source=testherd1 type=pushdelta targetdb=B");
-like($i, qr{Added sync}, $t);
-
-$SQL = "SELECT * FROM sync";
-my $info = $dbhX->selectall_arrayref($SQL);
-$bct->restart_bucardo($dbhX);
-
-$dbhX->do('LISTEN bucardo_syncdone_multicoltest');
-$dbhX->commit();
-
-for my $table (sort keys %tabletype) {
-
- my $type = $tabletype{$table};
- my $val = $val{$type}{1};
- if (!defined $val) {
- BAIL_OUT "Could not determine value for $table $type\n";
- }
-
- $pkey{$table} = $table =~ /test5/ ? q{"id space"} : 'id';
-
- $SQL = $table =~ /0/
- ? "INSERT INTO $table($pkey{$table}) VALUES (?)"
- : "INSERT INTO $table($pkey{$table},data1,inty) VALUES (?,'one',1)";
- $sql{insert}{$table} = $dbhA->prepare($SQL);
- if ($type eq 'BYTEA') {
- $sql{insert}{$table}->bind_param(1, undef, {pg_type => PG_BYTEA});
- }
- $val{$table} = $val;
-
- $sql{insert}{$table}->execute($val{$table});
-
- last; ## Just the first table for now
-}
-
-$dbhA->commit();
-
-sub test_empty_drop {
- my ($table, $dbh) = @_;
- my $DROPSQL = 'SELECT * FROM droptest';
- my $line = (caller)[2];
- $t=qq{ Triggers and rules did NOT fire on remote table $table};
- $result = [];
- bc_deeply($result, $dbhB, $DROPSQL, $t, $line);
-}
-
-for my $table (sort keys %tabletype) {
- $t=qq{ Second table $table still empty before commit };
-
- $SQL = $table =~ /0/
- ? "SELECT $pkey{$table} FROM $table"
- : "SELECT $pkey{$table},data1 FROM $table";
- $result = [];
- bc_deeply($result, $dbhB, $SQL, $t);
-
- $t=q{ After insert, trigger and rule both populate droptest table };
- my $qtable = $dbhX->quote($table);
- my $LOCALDROPSQL = $table =~ /0/
- ? "SELECT type,0 FROM droptest WHERE name = $qtable ORDER BY 1,2"
- : "SELECT type,inty FROM droptest WHERE name = $qtable ORDER BY 1,2";
- my $tval = $table =~ /0/ ? 0 : 1;
- $result = [['rule',$tval],['trigger',$tval]];
- bc_deeply($result, $dbhA, $LOCALDROPSQL, $t);
-
- test_empty_drop($table,$dbhB);
- last;
-}
-
-for my $table (sort keys %tabletype) {
- $t=qq{ Second table $table still empty before kick };
- $sql{select}{$table} = "SELECT inty FROM $table ORDER BY $pkey{$table}";
- $table =~ /0/ and $sql{select}{$table} =~ s/inty/$pkey{$table}/;
- $result = [];
- bc_deeply($result, $dbhB, $sql{select}{$table}, $t);
- last;
-}
-
-$bct->ctl("kick multicoltest 0");
-wait_for_notice($dbhX, 'bucardo_syncdone_multicoltest', 5);
-
-for my $table (sort keys %tabletype) {
- $t=qq{ Second table $table got the row};
- $result = [[1]];
- bc_deeply($result, $dbhB, $sql{select}{$table}, $t);
-
- test_empty_drop($table,$dbhB);
- last;
-}
-
-END {
- $bct->stop_bucardo($dbhX);
- $dbhX->disconnect();
- $dbhA->disconnect();
- $dbhB->disconnect();
- $dbhC->disconnect();
-}
-
+++ /dev/null
-#!perl
-
-# Test multi-column primary keys
-
-use 5.008003;
-use strict;
-use warnings;
-use Data::Dumper;
-use lib 't','.';
-use DBD::Pg;
-use Test::More 'no_plan';
-
-no warnings 'redefine';
-use BucardoTesting;
-use warnings;
-
-my $bct = BucardoTesting->new() or BAIL_OUT "Creation of BucardoTesting object failed\n";
-
-pass(q{*** Beginning 'multicol pk' tests});
-
-## Prepare a clean Bucardo database on A
-my $dbhA = $bct->blank_database('A');
-my $dbhX = $bct->setup_bucardo(A => $dbhA);
-
-## Server A is the master, the rest are slaves
-my $dbhB = $bct->blank_database('B');
-
-my $res = $dbhB->selectall_arrayref('SELECT * FROM bucardo_test_multicol');
-is($#$res, -1, 'Slave test table is empty');
-$dbhB->rollback();
-
-## Tell Bucardo about these databases
-$bct->add_test_databases('A B');
-
-## Create a herd for 'A' and add all test tables to it
-$bct->add_test_tables_to_herd('A', 'testherd1');
-
-## Pushdelta sync from A to B
-my $t=q{Add sync works};
-my $i = $bct->ctl("add sync multicolpushdeltatest source=testherd1 type=pushdelta targetdb=B");
-like($i, qr{Added sync}, $t);
-
-$bct->restart_bucardo($dbhX);
-
-# Insert 5 rows and see if they replicate
-$dbhA->do(q{INSERT INTO bucardo_test_multicol (id, id2, id3, data) VALUES (1, 1, 1, 'test')});
-$dbhA->do(q{INSERT INTO bucardo_test_multicol (id, id2, id3, data) VALUES (1, 2, 1, 'test')});
-$dbhA->do(q{INSERT INTO bucardo_test_multicol (id, id2, id3, data) VALUES (1, 3, 1, 'test')});
-$dbhA->do(q{INSERT INTO bucardo_test_multicol (id, id2, id3, data) VALUES (1, 4, 1, 'test')});
-$dbhA->do(q{INSERT INTO bucardo_test_multicol (id, id2, id3, data) VALUES (1, 5, 1, 'test')});
-$dbhA->commit();
-
-$dbhX->do(q{LISTEN bucardo_syncdone_multicolpushdeltatest});
-$dbhX->commit();
-$bct->ctl('kick multicolpushdeltatest 5');
-eval {
- wait_for_notice($dbhX, 'bucardo_syncdone_multicolpushdeltatest', 5);
-};
-ok(! $@, 'Sync pushed');
-
-$res = $dbhB->selectall_arrayref('SELECT id, id2, id3, data FROM bucardo_test_multicol');
-is($#$res, 4, 'Slave table contains 5 rows');
-$dbhB->rollback();
-
-# Update a row and see if it replicates
-$dbhA->do(q{UPDATE bucardo_test_multicol SET data = 'test2' WHERE id2 = 2});
-$dbhA->commit();
-
-$bct->ctl('kick multicolpushdeltatest 5');
-eval {
- wait_for_notice($dbhX, 'bucardo_syncdone_multicolpushdeltatest', 5);
-};
-ok(! $@, 'Sync pushed');
-$res = $dbhB->selectall_arrayref(q{SELECT * FROM bucardo_test_multicol WHERE id2 = 2 AND data = 'test'});
-is($#$res, -1, 'Row successfully updated');
-$dbhB->rollback();
-
-# Remove a row and see if it replicates
-$dbhA->do(q{DELETE FROM bucardo_test_multicol WHERE id2 = 1});
-$dbhA->commit();
-
-$bct->ctl('kick multicolpushdeltatest 5');
-eval {
- wait_for_notice($dbhX, 'bucardo_syncdone_multicolpushdeltatest', 5);
-};
-ok(! $@, 'Sync pushed');
-$res = $dbhB->selectall_arrayref('SELECT * FROM bucardo_test_multicol WHERE id2 = 1');
-is($#$res, -1, 'Row successfully deleted');
-$dbhB->rollback();
-
-END {
- $bct->stop_bucardo($dbhX);
- $dbhX->disconnect();
- $dbhA->disconnect();
- $dbhB->disconnect();
-}
+++ /dev/null
-#!perl
-
-# Test multi-column primary keys
-
-use 5.008003;
-use strict;
-use warnings;
-use Data::Dumper;
-use lib 't','.';
-use DBD::Pg;
-use Test::More 'no_plan';
-
-no warnings 'redefine';
-use BucardoTesting;
-use warnings;
-
-my $bct = BucardoTesting->new() or BAIL_OUT "Creation of BucardoTesting object failed\n";
-
-pass(q{*** Beginning 'multicol pk' tests});
-
-## Prepare a clean Bucardo database on A
-my $dbhA = $bct->blank_database('A');
-my $dbhX = $bct->setup_bucardo(A => $dbhA);
-
-## Server A is the master, the rest are slaves
-my $dbhB = $bct->blank_database('B');
-
-my $res = $dbhA->selectall_arrayref('SELECT * FROM bucardo_test_multicol');
-is($#$res, -1, 'Test table in database A is empty');
-$dbhA->rollback();
-
-$res = $dbhB->selectall_arrayref('SELECT * FROM bucardo_test_multicol');
-is($#$res, -1, 'Test table in database B is empty');
-$dbhB->rollback();
-
-## Tell Bucardo about these databases
-$bct->add_test_databases('A B');
-
-## Create a herd for 'A' and add all test tables to it
-$bct->add_test_tables_to_herd('A', 'testherd1');
-
-# Setting up conflict resolution methods
-$dbhX->do(q{UPDATE bucardo.goat SET standard_conflict = 'source'});
-$dbhX->commit();
-
-## Pushdelta sync from A to B
-my $t=q{Add sync works};
-print "Adding sync\n";
-my $i = $bct->ctl("add sync multicolswaptest source=testherd1 type=swap targetdb=B");
-print "Added sync: $i\n";
-like($i, qr{Added sync}, $t);
-
-$bct->restart_bucardo($dbhX);
-
-# Insert 5 rows and see if they replicate
-$dbhA->do(q{INSERT INTO bucardo_test_multicol (id, id2, id3, data) VALUES (1, 1, 1, 'test')});
-$dbhA->do(q{INSERT INTO bucardo_test_multicol (id, id2, id3, data) VALUES (1, 2, 1, 'test')});
-$dbhA->do(q{INSERT INTO bucardo_test_multicol (id, id2, id3, data) VALUES (1, 3, 1, 'test')});
-$dbhA->do(q{INSERT INTO bucardo_test_multicol (id, id2, id3, data) VALUES (1, 4, 1, 'test')});
-$dbhA->do(q{INSERT INTO bucardo_test_multicol (id, id2, id3, data) VALUES (1, 5, 1, 'test')});
-$dbhA->commit();
-
-$dbhB->do(q{INSERT INTO bucardo_test_multicol (id, id2, id3, data) VALUES (4, 1, 1, 'test')});
-$dbhB->do(q{INSERT INTO bucardo_test_multicol (id, id2, id3, data) VALUES (4, 2, 1, 'test')});
-$dbhB->do(q{INSERT INTO bucardo_test_multicol (id, id2, id3, data) VALUES (4, 3, 1, 'test')});
-$dbhB->do(q{INSERT INTO bucardo_test_multicol (id, id2, id3, data) VALUES (4, 4, 1, 'test')});
-$dbhB->do(q{INSERT INTO bucardo_test_multicol (id, id2, id3, data) VALUES (4, 5, 1, 'test')});
-$dbhB->commit();
-
-$dbhX->do(q{LISTEN bucardo_syncdone_multicolswaptest});
-$dbhX->commit();
-$bct->ctl('kick multicolswaptest 5');
-eval {
- wait_for_notice($dbhX, 'bucardo_syncdone_multicolswaptest', 5);
-};
-ok(! $@, 'Sync pushed');
-
-$res = $dbhA->selectall_arrayref('SELECT id, id2, id3, data FROM bucardo_test_multicol');
-is($#$res, 9, 'Test table in A contains 9 rows');
-$dbhA->rollback();
-
-$res = $dbhB->selectall_arrayref('SELECT id, id2, id3, data FROM bucardo_test_multicol');
-is($#$res, 9, 'Test table in B contains 9 rows');
-$dbhB->rollback();
-
-# Update a row and see if it replicates
-$dbhA->do(q{UPDATE bucardo_test_multicol SET data = 'test2' WHERE id2 = 2});
-$dbhA->commit();
-
-$bct->ctl('kick multicolswaptest 5');
-eval {
- wait_for_notice($dbhX, 'bucardo_syncdone_multicolswaptest', 5);
-};
-ok(! $@, 'Sync pushed');
-$res = $dbhB->selectall_arrayref(q{SELECT * FROM bucardo_test_multicol WHERE id = 1 AND id2 = 2 AND data = 'test'});
-is($#$res, -1, 'Row successfully updated');
-$dbhB->rollback();
-
-# Remove a row and see if it replicates
-$dbhB->do(q{DELETE FROM bucardo_test_multicol WHERE id = 1 AND id2 = 1});
-$dbhB->commit();
-
-$bct->ctl('kick multicolswaptest 5');
-eval {
- wait_for_notice($dbhX, 'bucardo_syncdone_multicolswaptest', 5);
-};
-ok(! $@, 'Sync pushed');
-$res = $dbhA->selectall_arrayref('SELECT * FROM bucardo_test_multicol WHERE id = 1 AND id2 = 1');
-is($#$res, -1, 'Row successfully deleted');
-print Dumper($res);
-$dbhA->rollback();
-
-END {
- $bct->stop_bucardo($dbhX);
- $dbhX->disconnect();
- $dbhA->disconnect();
- $dbhB->disconnect();
-}
'bucardo_test9' => 'int_unsigned',
);
-our @tables2empty = (qw/droptest bucardo_test_multicol/);
+our @tables2empty = (qw/droptest/);
our %sequences =
(
$dbh->do($SQL);
}
- if ( !table_exists($dbh => 'bucardo_test_multicol') ) {
- $tcount++;
- $dbh->do(q{CREATE TABLE bucardo_test_multicol (
- id INTEGER,
- id2 INTEGER,
- id3 INTEGER,
- data TEXT,
- PRIMARY KEY (id, id2, id3))});
- }
-
## Create one sequence for each table type
for my $seq (sort keys %sequences) {
}
my $addstring = join ' ' => sort keys %tabletype;
- $addstring .= ' bucardo_test_multicol';
my $com = "add table $addstring db=$db herd=$herd";
$result = $self->ctl($com);
if ($result !~ /Added table/) {