my $replicant = $self->create_replicant($schema);
$replicant->connect_info($connect_info);
$replicant->ensure_connected;
-
DBIx::Class::Storage::DBI::Replicated::Replicant->meta->apply($replicant);
my ($key) = ($connect_info->[0]=~m/^dbi\:.+\:(.+)$/);
$self->dbh->do("ROLLBACK TO SAVEPOINT $name")
}
-
+
sub is_replicating {
- my $self = shift @_;
+ my $status = shift->dbh->selectrow_hashref('show slave status');
+ return ($status->{Slave_IO_Running} eq 'Yes') && ($status->{Slave_SQL_Running} eq 'Yes');
}
sub lag_behind_master {
- my $self = shift @_;
- return $self->dbh->selectrow_hashref('show slave status');
+ return shift->dbh->selectrow_hashref('show slave status')->{Seconds_Behind_Master};
}
1;
eval "use Moose; use Test::Moose";
plan $@
? ( skip_all => 'needs Moose for testing' )
- : ( tests => 41 );
+ : ( tests => 43 );
}
use_ok 'DBIx::Class::Storage::DBI::Replicated::Pool';
## Getting slave status tests
-use Data::Dump qw/dump/;
-my $lag1 = $replicated->schema->storage->replicants->{$replicant_names[0]}->lag_behind_master;
-warn dump $lag1;
-
+SKIP: {
+ ## We skip this tests unless you have a custom replicants, since the default
+ ## sqlite based replication tests don't support these functions.
+
+ skip 'Cannot Test Replicant Status on Non Replicating Database', 2
+ unless DBICTest->has_custom_dsn && $ENV{"DBICTEST_SLAVE0_DSN"};
+
+ $replicated->replicate; ## Give the slaves a chance to catchup.
+
+ ok $replicated->schema->storage->replicants->{$replicant_names[0]}->is_replicating
+ => 'Replicants are replicating';
+
+ is $replicated->schema->storage->replicants->{$replicant_names[0]}->lag_behind_master, 0
+ => 'Replicant is zero seconds behind master';
+}
+
## Delete the old database files
$replicated->cleanup;