10 eval {use DBD::Multi};
11 plan skip_all => 'No DBD::Multi' if ($@);
15 my $schema = DBICTest->init_schema();
17 $schema->storage_type( '::DBI::Replication' );
20 my $db_file1 = "t/var/DBIxClass.db";
21 my $db_file2 = "t/var/DBIxClass_slave1.db";
22 my $db_file3 = "t/var/DBIxClass_slave2.db";
23 my $dsn1 = $ENV{"DBICTEST_DSN"} || "dbi:SQLite:${db_file1}";
24 my $dsn2 = $ENV{"DBICTEST_DSN2"} || "dbi:SQLite:${db_file2}";
25 my $dsn3 = $ENV{"DBICTEST_DSN3"} || "dbi:SQLite:${db_file3}";
28 [ $dsn1, '', '', { AutoCommit => 1 } ],
29 [ $dsn2, '', '', { priority => 10 } ],
30 [ $dsn3, '', '', { priority => 10 } ]
34 $schema->populate('Artist', [
35 [ qw/artistid name/ ],
36 [ 4, 'Ozric Tentacles']
39 my $new_artist1 = $schema->resultset('Artist')->find(4);
41 isa_ok ($new_artist1, 'DBICTest::Artist');
44 my $schema2 = $schema->connect( [
45 [ $dsn1, '', '', { AutoCommit => 1 } ],
46 [ $dsn2, '', '', { priority => 10 } ],
47 [ $dsn3, '', '', { priority => 10 } ]
51 # try and read (should fail)
52 eval { my $new_artist2 = $schema2->resultset('Artist')->find(4); };
53 ok($@, 'read after disconnect fails because it uses slave 1 which we have neglected to "replicate" yet');
55 # try and read (should succede after faked synchronisation)
56 copy($db_file1, $db_file2);
57 $schema2 = $schema->connect( [
58 [ $dsn1, '', '', { AutoCommit => 1 } ],
59 [ $dsn2, '', '', { priority => 10 } ],
60 [ $dsn3, '', '', { priority => 10 } ]
63 my $new_artist3 = $schema2->resultset('Artist')->find(4);
64 isa_ok ($new_artist3, 'DBICTest::Artist');