Constraint/index name fix from rdj
[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 10
86583fa7 11BEGIN {
12 eval "use DBD::Multi";
13 plan $@
14 ? ( skip_all => 'needs DBD::Multi for testing' )
15 : ( tests => 3 );
16}
e4dc89b3 17
18my $schema = DBICTest->init_schema();
19
20$schema->storage_type( '::DBI::Replication' );
21
22
23my $db_file1 = "t/var/DBIxClass.db";
24my $db_file2 = "t/var/DBIxClass_slave1.db";
25my $db_file3 = "t/var/DBIxClass_slave2.db";
26my $dsn1 = $ENV{"DBICTEST_DSN"} || "dbi:SQLite:${db_file1}";
27my $dsn2 = $ENV{"DBICTEST_DSN2"} || "dbi:SQLite:${db_file2}";
28my $dsn3 = $ENV{"DBICTEST_DSN3"} || "dbi:SQLite:${db_file3}";
29
30$schema->connect( [
31 [ $dsn1, '', '', { AutoCommit => 1 } ],
32 [ $dsn2, '', '', { priority => 10 } ],
33 [ $dsn3, '', '', { priority => 10 } ]
34 ]
35 );
36
37$schema->populate('Artist', [
38 [ qw/artistid name/ ],
39 [ 4, 'Ozric Tentacles']
40 ]);
41
8f7986d6 42my $new_artist1 = $schema->resultset('Artist')->find(4);
43
44isa_ok ($new_artist1, 'DBICTest::Artist');
e4dc89b3 45
8f7986d6 46# reconnect
47my $schema2 = $schema->connect( [
48 [ $dsn1, '', '', { AutoCommit => 1 } ],
49 [ $dsn2, '', '', { priority => 10 } ],
50 [ $dsn3, '', '', { priority => 10 } ]
51 ]
52 );
53
54# try and read (should fail)
55eval { my $new_artist2 = $schema2->resultset('Artist')->find(4); };
56ok($@, 'read after disconnect fails because it uses slave 1 which we have neglected to "replicate" yet');
e4dc89b3 57
58# try and read (should succede after faked synchronisation)
59copy($db_file1, $db_file2);
8f7986d6 60$schema2 = $schema->connect( [
61 [ $dsn1, '', '', { AutoCommit => 1 } ],
62 [ $dsn2, '', '', { priority => 10 } ],
63 [ $dsn3, '', '', { priority => 10 } ]
64 ]
65 );
66my $new_artist3 = $schema2->resultset('Artist')->find(4);
67isa_ok ($new_artist3, 'DBICTest::Artist');
e4dc89b3 68
69unlink $db_file2;