use Data::Dump qw/dump/;
BEGIN {
- eval "use DBD::Multi";
+ eval "use Moose";
plan $@
- ? ( skip_all => 'needs DBD::Multi for testing' )
- : ( tests => 18 );
+ ? ( skip_all => 'needs Moose for testing' )
+ : ( tests => 2 );
}
## ----------------------------------------------------------------------------
## ----------------------------------------------------------------------------
TESTSCHEMACLASS: {
+
+ package DBIx::Class::DBI::Replicated::TestReplication;
+
+ use DBICTest;
+ use base qw/Class::Accessor::Fast/;
+
+ __PACKAGE__->mk_accessors( qw/schema/ );
+
+ ## Initialize the object
+
+ sub new {
+ my $proto = shift;
+ my $class = ref( $proto ) || $proto;
+ my $self = {};
+
+ bless( $self, $class );
+
+ $self->schema( $self->init_schema );
+
+ return $self;
+ }
+
+ ## get the Schema and set the replication storage type
+
+ sub init_schema {
+ my $class = shift @_;
+ my $schema = DBICTest->init_schema(storage_type=>'::DBI::Replicated');
+ return $schema;
+ }
+}
+
+## ----------------------------------------------------------------------------
+## Create an object and run some tests
+## ----------------------------------------------------------------------------
+
+my %params = (
+ db_paths => [
+ "t/var/DBIxClass.db",
+ "t/var/DBIxClass_slave1.db",
+ "t/var/DBIxClass_slave2.db",
+ ],
+);
+
+ok my $replicate = DBIx::Class::DBI::Replicated::TestReplication->new()
+ => 'Created a replication object';
+
+isa_ok $replicate->schema
+ => 'DBIx::Class::Schema';
+
+
+ warn dump $replicate->schema->storage->meta;
+
+ warn dump $replicate->schema->storage->master;
+
+
+__END__
+
+## ----------------------------------------------------------------------------
+## Build a class to hold all our required testing data and methods.
+## ----------------------------------------------------------------------------
+
+TESTSCHEMACLASS: {
- package DBIx::Class::DBI::Replication::TestReplication;
+ package DBIx::Class::DBI::Replicated::TestReplication;
use DBI;
use DBICTest;
sub init_schema {
my $class = shift @_;
my $schema = DBICTest->init_schema();
- $schema->storage_type( '::DBI::Replication' );
+ $schema->storage_type( '::DBI::Replicated' );
return $schema;
}
sub connect {
my $self = shift @_;
my ($master, @slaves) = @{$self->{dsns}};
- my @connections = ([$master, '','', {AutoCommit=>1, PrintError=>0}]);
- my @slavesob;
+ my $master_connect_info = [$master, '','', {AutoCommit=>1, PrintError=>0}];
+ my @slavesob;
foreach my $slave (@slaves)
{
my $dbh = shift @{$self->{slaves}}
|| DBI->connect($slave,"","",{PrintError=>0, PrintWarn=>0});
- push @connections,
+ push @{$master_connect_info->[-1]->{slaves_connect_info}},
[$dbh, '','',{priority=>10}];
push @slavesob,
$self
->{schema}
- ->connect([
- @connections,
- {limit_dialect => 'LimitXY'}
- ]);
+ ->connect(@$master_connect_info);
}
## replication
],
);
-ok my $replicate = DBIx::Class::DBI::Replication::TestReplication->new(%params)
+ok my $replicate = DBIx::Class::DBI::Replicated::TestReplication->new(%params)
=> 'Created a replication object';
isa_ok $replicate->{schema}
## we overload any type of write operation so that is must hit the master
## database.
-use Fcntl qw (:flock);
-
-my $master_path = $replicate->{db_paths}->[0];
-open LOCKFILE, ">>$master_path"
- or die "Cannot open $master_path";
-flock(LOCKFILE, LOCK_EX);
-
$replicate
->{schema}
->populate('Artist', [
ok $@ => 'Got read errors after everything failed';
+## make sure ->connect_info returns something sane
+
+ok $replicate->{schema}->storage->connect_info
+ => 'got something out of ->connect_info';
+
+## Force a connection to the write source for testing.
+
+$replicate->{schema}->storage($replicate->{schema}->storage->write_source);
+
+## What happens when we do a find for something that doesn't exist?
+
+ok ! $replicate->{schema}->resultset('Artist')->find(666)
+ => 'Correctly did not find a bad artist id';
+
## Delete the old database files
$replicate->cleanup;