Fix the skip for DBD::Multi
[dbsrgits/DBIx-Class.git] / t / 93storage_replication.t
1 use strict;
2 use warnings;
3 use lib qw(t/lib);
4
5 use File::Copy;
6
7 use DBICTest;
8
9 use Test::More;
10 plan skip_all => 'No DBD::Multi' unless eval { require DBD::Multi };
11
12 plan tests => 3;
13
14 my $schema = DBICTest->init_schema();
15
16 $schema->storage_type( '::DBI::Replication' );
17
18
19 my $db_file1 = "t/var/DBIxClass.db";
20 my $db_file2 = "t/var/DBIxClass_slave1.db";
21 my $db_file3 = "t/var/DBIxClass_slave2.db";
22 my $dsn1 = $ENV{"DBICTEST_DSN"} || "dbi:SQLite:${db_file1}";
23 my $dsn2 = $ENV{"DBICTEST_DSN2"} || "dbi:SQLite:${db_file2}";
24 my $dsn3 = $ENV{"DBICTEST_DSN3"} || "dbi:SQLite:${db_file3}";
25
26 $schema->connect( [
27                    [ $dsn1, '', '', { AutoCommit => 1 } ],
28                    [ $dsn2, '', '', { priority => 10 } ],
29                    [ $dsn3, '', '', { priority => 10 } ]
30                   ]
31                 );
32
33 $schema->populate('Artist', [
34                              [ qw/artistid name/ ],
35                              [ 4, 'Ozric Tentacles']
36                             ]);
37
38 my $new_artist1 = $schema->resultset('Artist')->find(4);
39
40 isa_ok ($new_artist1, 'DBICTest::Artist');
41
42 # reconnect
43 my $schema2 = $schema->connect( [
44                                  [ $dsn1, '', '', { AutoCommit => 1 } ],
45                                  [ $dsn2, '', '', { priority => 10 } ],
46                                  [ $dsn3, '', '', { priority => 10 } ]
47                                 ]
48                               );
49
50 # try and read (should fail)
51 eval { my $new_artist2 = $schema2->resultset('Artist')->find(4); };
52 ok($@, 'read after disconnect fails because it uses slave 1 which we have neglected to "replicate" yet');
53
54 # try and read (should succede after faked synchronisation)
55 copy($db_file1, $db_file2);
56 $schema2 = $schema->connect( [
57                               [ $dsn1, '', '', { AutoCommit => 1 } ],
58                               [ $dsn2, '', '', { priority => 10 } ],
59                               [ $dsn3, '', '', { priority => 10 } ]
60                              ]
61                            );
62 my $new_artist3 = $schema2->resultset('Artist')->find(4);
63 isa_ok ($new_artist3, 'DBICTest::Artist');
64
65 unlink $db_file2;