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