No reason to store an empty hash ref for each column
[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;
d663c981 10plan skip_all => 'No DBD::Multi' unless eval { require DBD::Multi };
8f7986d6 11
12plan tests => 3;
e4dc89b3 13
14my $schema = DBICTest->init_schema();
15
16$schema->storage_type( '::DBI::Replication' );
17
18
19my $db_file1 = "t/var/DBIxClass.db";
20my $db_file2 = "t/var/DBIxClass_slave1.db";
21my $db_file3 = "t/var/DBIxClass_slave2.db";
22my $dsn1 = $ENV{"DBICTEST_DSN"} || "dbi:SQLite:${db_file1}";
23my $dsn2 = $ENV{"DBICTEST_DSN2"} || "dbi:SQLite:${db_file2}";
24my $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
8f7986d6 38my $new_artist1 = $schema->resultset('Artist')->find(4);
39
40isa_ok ($new_artist1, 'DBICTest::Artist');
e4dc89b3 41
8f7986d6 42# reconnect
43my $schema2 = $schema->connect( [
44 [ $dsn1, '', '', { AutoCommit => 1 } ],
45 [ $dsn2, '', '', { priority => 10 } ],
46 [ $dsn3, '', '', { priority => 10 } ]
47 ]
48 );
49
50# try and read (should fail)
51eval { my $new_artist2 = $schema2->resultset('Artist')->find(4); };
52ok($@, 'read after disconnect fails because it uses slave 1 which we have neglected to "replicate" yet');
e4dc89b3 53
54# try and read (should succede after faked synchronisation)
55copy($db_file1, $db_file2);
8f7986d6 56$schema2 = $schema->connect( [
57 [ $dsn1, '', '', { AutoCommit => 1 } ],
58 [ $dsn2, '', '', { priority => 10 } ],
59 [ $dsn3, '', '', { priority => 10 } ]
60 ]
61 );
62my $new_artist3 = $schema2->resultset('Artist')->find(4);
63isa_ok ($new_artist3, 'DBICTest::Artist');
e4dc89b3 64
65unlink $db_file2;