Further work on conflict testing.
authorGreg Sabino Mullane <greg@endpoint.com>
Mon, 7 Jul 2014 15:48:53 +0000 (11:48 -0400)
committerGreg Sabino Mullane <greg@endpoint.com>
Mon, 7 Jul 2014 15:48:53 +0000 (11:48 -0400)
MANIFEST
t/40-conflict.t
t/ctest1.pl [new file with mode: 0644]
t/ctest2.pl [new file with mode: 0644]
t/ctest3.pl [new file with mode: 0644]

index 5f8c87c4d5fc8ac17037b257a6c7a1c2ca0c1153..55c5e6558e8693c203a50aa2d16ad9d417be0e02 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -53,6 +53,9 @@ t/98-cleanup.t
 t/99-signature.t
 t/BucardoTesting.pm
 t/customcode.exception.bucardotest.pl
+t/ctest1.pl
+t/ctest2.pl
+t/ctest3.pl
 test_setup.sh
 TODO
 UPGRADE
index fc96eb316c9ecbc97275c04684b4888ed8057c9a..250423d1af31b9da7e5263a072b227931ee84f8b 100644 (file)
@@ -83,7 +83,8 @@ $bct->add_row_to_database('B', 2);
 $bct->add_row_to_database('C', 2);
 
 $bct->ctl('bucardo kick sync ctest 10');
-$bct->check_for_row([[1],[2]], [qw/ B C D/]);
+
+$bct->check_for_row([[1],[2]], [qw/ A B C D/]);
 
 $t = q{Cannot set conflict handler to invalid database name};
 $res = $bct->ctl('bucardo update sync ctest conflict="a b c"');
@@ -110,5 +111,66 @@ $bct->update_row_in_database('B', 1, 2222);
 $bct->ctl('bucardo kick sync ctest 10');
 $bct->check_for_row([[2],[1111]], [qw/ A B C D/]);
 
+## Test of the default conflict strategy
+$bct->update_row_in_database('B', 1, 102);
+$bct->update_row_in_database('A', 2, 201);
+$bct->update_row_in_database('B', 2, 202);
+$bct->add_row_to_database('A', 3);
+$bct->update_row_in_database('A', 3, 301);
+$bct->update_row_in_database('C', 2, 203);
+
+$t = q{Set conflict strategy to 'bucardo_latest'};
+$res = $bct->ctl('bucardo update sync ctest conflict=latest');
+like($res, qr{Set conflict strategy to 'bucardo_latest'}, $t);
+
+$t = q{Reloaded sync ctest};
+$res = $bct->ctl('bucardo reload sync ctest');
+like($res, qr{success}, $t);
+
+## Database B should be the winner for 1, C for 2, and A for 3
+$bct->ctl('bucardo kick sync ctest 10');
+$bct->check_for_row([[102],[203],[301]], [qw/ A B C D /]);
+
+## Test of conflict handler 'bucardo_latest_all_tables'
+$t = q{Set conflict strategy to 'bucardo_latest_all_tables'};
+$res = $bct->ctl('bucardo update sync ctest conflict=latest_all');
+like($res, qr{Set conflict strategy to 'bucardo_latest_all_tables'}, $t);
+
+$t = q{Reloaded sync ctest};
+$res = $bct->ctl('bucardo reload sync ctest');
+like($res, qr{success}, $t);
+
+$bct->update_row_in_database('B', 1, 102);
+$bct->update_row_in_database('A', 2, 201);
+$bct->update_row_in_database('B', 2, 202);
+$bct->update_row_in_database('A', 3, 301);
+$bct->update_row_in_database('C', 2, 203);
+
+## Database B should be the winner for 1, C for 2, and A for 3
+$bct->ctl('bucardo kick sync ctest 10');
+$bct->check_for_row([[102],[203],[301]], [qw/ A B C D /]);
+
+## Use a custom conflict handler by adding a customcode to this sync
+$t = q{Added new customcode ctest1 for conflict in the ctest sync};
+$res = $bct->ctl('bucardo add customcode ctest1 whenrun=conflict sync=ctest src_code=t/ctest1.pl');
+like($res, qr{Added customcode "ctest1"}, $t);
+
+$t = q{Reloaded sync ctest};
+$res = $bct->ctl('bucardo reload sync ctest');
+like($res, qr{success}, $t);
+
+$bct->update_row_in_database('A', 2, 211);
+$bct->update_row_in_database('B', 2, 212);
+$bct->update_row_in_database('C', 2, 213);
+$bct->update_row_in_database('A', 1, 111);
+$bct->update_row_in_database('C', 1, 113);
+$bct->ctl('bucardo kick sync ctest 10');
+$bct->check_for_row([[111],[212],[301]], [qw/ A B C D /]);
+
+## Customcode with winner
+
+## Customcode on a goat only
+
+
 done_testing();
 exit;
diff --git a/t/ctest1.pl b/t/ctest1.pl
new file mode 100644 (file)
index 0000000..d070bb6
--- /dev/null
@@ -0,0 +1,16 @@
+## ctest1.pl - a conflict handler for Bucardo
+use strict;
+use warnings;
+
+my $info = shift;
+
+## If this table is named 'work', do nothing
+if ($info->{tablename} eq 'work') {
+    $info->{skip} = 1;
+}
+else {
+    ## Winning databases, in order
+    $info->{winner} = 'B A C';
+}
+
+return;
diff --git a/t/ctest2.pl b/t/ctest2.pl
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/t/ctest3.pl b/t/ctest3.pl
new file mode 100644 (file)
index 0000000..e69de29