10 plan skip_all => 'No DBD::Multi' unless eval { require DBD::Multi };
14 my $schema = DBICTest->init_schema();
16 $schema->storage_type( '::DBI::Replication' );
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}";
27 [ $dsn1, '', '', { AutoCommit => 1 } ],
28 [ $dsn2, '', '', { priority => 10 } ],
29 [ $dsn3, '', '', { priority => 10 } ]
33 $schema->populate('Artist', [
34 [ qw/artistid name/ ],
35 [ 4, 'Ozric Tentacles']
38 my $new_artist1 = $schema->resultset('Artist')->find(4);
40 isa_ok ($new_artist1, 'DBICTest::Artist');
43 my $schema2 = $schema->connect( [
44 [ $dsn1, '', '', { AutoCommit => 1 } ],
45 [ $dsn2, '', '', { priority => 10 } ],
46 [ $dsn3, '', '', { priority => 10 } ]
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');
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 } ]
62 my $new_artist3 = $schema2->resultset('Artist')->find(4);
63 isa_ok ($new_artist3, 'DBICTest::Artist');