12 eval "use DBD::Multi";
14 ? ( skip_all => 'needs DBD::Multi for testing' )
18 my $schema = DBICTest->init_schema();
20 $schema->storage_type( '::DBI::Replication' );
23 my $db_file1 = "t/var/DBIxClass.db";
24 my $db_file2 = "t/var/DBIxClass_slave1.db";
25 my $db_file3 = "t/var/DBIxClass_slave2.db";
26 my $dsn1 = $ENV{"DBICTEST_DSN"} || "dbi:SQLite:${db_file1}";
27 my $dsn2 = $ENV{"DBICTEST_DSN2"} || "dbi:SQLite:${db_file2}";
28 my $dsn3 = $ENV{"DBICTEST_DSN3"} || "dbi:SQLite:${db_file3}";
31 [ $dsn1, '', '', { AutoCommit => 1 } ],
32 [ $dsn2, '', '', { priority => 10 } ],
33 [ $dsn3, '', '', { priority => 10 } ]
37 $schema->populate('Artist', [
38 [ qw/artistid name/ ],
39 [ 4, 'Ozric Tentacles']
42 my $new_artist1 = $schema->resultset('Artist')->find(4);
44 isa_ok ($new_artist1, 'DBICTest::Artist');
47 my $schema2 = $schema->connect( [
48 [ $dsn1, '', '', { AutoCommit => 1 } ],
49 [ $dsn2, '', '', { priority => 10 } ],
50 [ $dsn3, '', '', { priority => 10 } ]
54 # try and read (should fail)
55 eval { my $new_artist2 = $schema2->resultset('Artist')->find(4); };
56 ok($@, 'read after disconnect fails because it uses slave 1 which we have neglected to "replicate" yet');
58 # try and read (should succede after faked synchronisation)
59 copy($db_file1, $db_file2);
60 $schema2 = $schema->connect( [
61 [ $dsn1, '', '', { AutoCommit => 1 } ],
62 [ $dsn2, '', '', { priority => 10 } ],
63 [ $dsn3, '', '', { priority => 10 } ]
66 my $new_artist3 = $schema2->resultset('Artist')->find(4);
67 isa_ok ($new_artist3, 'DBICTest::Artist');