8 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_replicated')
9 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_replicated');
14 use List::Util 'first';
15 use Scalar::Util 'reftype';
20 note "Using Moose version $Moose::VERSION and MooseX::Types version $MooseX::Types::VERSION";
25 use_ok 'DBIx::Class::Storage::DBI::Replicated::Pool';
26 use_ok 'DBIx::Class::Storage::DBI::Replicated::Balancer';
27 use_ok 'DBIx::Class::Storage::DBI::Replicated::Replicant';
28 use_ok 'DBIx::Class::Storage::DBI::Replicated';
33 This is a test of the replicated storage system. This will work in one of
34 two ways, either it was try to fake replication with a couple of SQLite DBs
35 and creative use of copy, or if you define a couple of %ENV vars correctly
36 will try to test those. If you do that, it will assume the setup is properly
37 replicating. Your results may vary, but I have demonstrated this to work with
38 mysql native replication.
43 ## ----------------------------------------------------------------------------
44 ## Build a class to hold all our required testing data and methods.
45 ## ----------------------------------------------------------------------------
49 ## --------------------------------------------------------------------- ##
50 ## Create an object to contain your replicated stuff.
51 ## --------------------------------------------------------------------- ##
53 package DBIx::Class::DBI::Replicated::TestReplication;
56 use base qw/Class::Accessor::Fast/;
58 __PACKAGE__->mk_accessors( qw/schema/ );
60 ## Initialize the object
63 my ($class, $schema_method) = (shift, shift);
64 my $self = $class->SUPER::new(@_);
66 $self->schema( $self->init_schema($schema_method) );
70 ## Get the Schema and set the replication storage type
73 # current SQLT SQLite producer does not handle DROP TABLE IF EXISTS, trap warnings here
74 local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /no such table.+DROP TABLE/s };
76 my ($class, $schema_method) = @_;
78 my $method = "get_schema_$schema_method";
79 my $schema = $class->$method;
84 sub get_schema_by_storage_type {
85 DBICTest->init_schema(
88 '::DBI::Replicated' => {
89 balancer_type=>'::Random',
91 auto_validate_every=>100,
92 master_read_weight => 1
102 sub get_schema_by_connect_info {
103 DBICTest->init_schema(
104 sqlite_use_file => 1,
105 storage_type=> '::DBI::Replicated',
106 balancer_type=>'::Random',
108 auto_validate_every=>100,
109 master_read_weight => 1
120 sub generate_replicant_connect_info {}
124 ## --------------------------------------------------------------------- ##
125 ## Add a connect_info option to test option merging.
126 ## --------------------------------------------------------------------- ##
128 package DBIx::Class::Storage::DBI::Replicated;
132 __PACKAGE__->meta->make_mutable;
134 around connect_info => sub {
135 my ($next, $self, $info) = @_;
136 $info->[3]{master_option} = 1;
140 __PACKAGE__->meta->make_immutable;
145 ## --------------------------------------------------------------------- ##
146 ## Subclass for when you are using SQLite for testing, this provides a fake
147 ## replication support.
148 ## --------------------------------------------------------------------- ##
150 package DBIx::Class::DBI::Replicated::TestReplication::SQLite;
154 use base 'DBIx::Class::DBI::Replicated::TestReplication';
156 __PACKAGE__->mk_accessors(qw/master_path slave_paths/);
158 ## Set the master path from DBICTest
161 my $class = shift @_;
162 my $self = $class->SUPER::new(@_);
164 $self->master_path( DBICTest->_sqlite_dbfilename );
166 File::Spec->catfile(qw/t var DBIxClass_slave1.db/),
167 File::Spec->catfile(qw/t var DBIxClass_slave2.db/),
173 ## Return an Array of ArrayRefs where each ArrayRef is suitable to use for
174 ## $storage->connect_info to be used for connecting replicants.
176 sub generate_replicant_connect_info {
180 } @{$self->slave_paths};
182 my @connect_infos = map { [$_,'','',{AutoCommit=>1}] } @dsn;
184 ## Make sure nothing is left over from a failed test
188 my $c = $connect_infos[0];
189 $connect_infos[0] = {
199 ## Do a 'good enough' replication by copying the master dbfile over each of
200 ## the slave dbfiles. If the master is SQLite we do this, otherwise we
201 ## just do a one second pause to let the slaves catch up.
205 foreach my $slave (@{$self->slave_paths}) {
206 copy($self->master_path, $slave);
210 ## Cleanup after ourselves. Unlink all gthe slave paths.
214 foreach my $slave (@{$self->slave_paths}) {
221 ## --------------------------------------------------------------------- ##
222 ## Subclass for when you are setting the databases via custom export vars
223 ## This is for when you have a replicating database setup that you are
224 ## going to test against. You'll need to define the correct $ENV and have
225 ## two slave databases to test against, as well as a replication system
226 ## that will replicate in less than 1 second.
227 ## --------------------------------------------------------------------- ##
229 package DBIx::Class::DBI::Replicated::TestReplication::Custom;
230 use base 'DBIx::Class::DBI::Replicated::TestReplication';
232 ## Return an Array of ArrayRefs where each ArrayRef is suitable to use for
233 ## $storage->connect_info to be used for connecting replicants.
235 sub generate_replicant_connect_info {
237 [$ENV{"DBICTEST_SLAVE0_DSN"}, $ENV{"DBICTEST_SLAVE0_DBUSER"}, $ENV{"DBICTEST_SLAVE0_DBPASS"}, {AutoCommit => 1}],
238 [$ENV{"DBICTEST_SLAVE1_DSN"}, $ENV{"DBICTEST_SLAVE1_DBUSER"}, $ENV{"DBICTEST_SLAVE1_DBPASS"}, {AutoCommit => 1}],
242 ## pause a bit to let the replication catch up
249 ## ----------------------------------------------------------------------------
250 ## Create an object and run some tests
251 ## ----------------------------------------------------------------------------
253 ## Thi first bunch of tests are basic, just make sure all the bits are behaving
255 my $replicated_class = DBICTest->has_custom_dsn ?
256 'DBIx::Class::DBI::Replicated::TestReplication::Custom' :
257 'DBIx::Class::DBI::Replicated::TestReplication::SQLite';
261 for my $method (qw/by_connect_info by_storage_type/) {
263 ok $replicated = $replicated_class->new($method)
264 => "Created a replication object $method";
266 isa_ok $replicated->schema
267 => 'DBIx::Class::Schema';
269 isa_ok $replicated->schema->storage
270 => 'DBIx::Class::Storage::DBI::Replicated';
272 isa_ok $replicated->schema->storage->balancer
273 => 'DBIx::Class::Storage::DBI::Replicated::Balancer::Random'
274 => 'configured balancer_type';
277 ### check that all Storage::DBI methods are handled by ::Replicated
279 my @storage_dbi_methods = Class::MOP::Class
280 ->initialize('DBIx::Class::Storage::DBI')->get_all_method_names;
282 my @replicated_methods = DBIx::Class::Storage::DBI::Replicated->meta
283 ->get_all_method_names;
285 # remove constants and OTHER_CRAP
286 @storage_dbi_methods = grep !/^[A-Z_]+\z/, @storage_dbi_methods;
288 # remove CAG accessors
289 @storage_dbi_methods = grep !/_accessor\z/, @storage_dbi_methods;
291 # remove DBIx::Class (the root parent, with CAG and stuff) methods
292 my @root_methods = Class::MOP::Class->initialize('DBIx::Class')
293 ->get_all_method_names;
295 $count{$_}++ for (@storage_dbi_methods, @root_methods);
297 @storage_dbi_methods = grep $count{$_} != 2, @storage_dbi_methods;
300 my %storage_dbi_methods;
301 @storage_dbi_methods{@storage_dbi_methods} = ();
302 my %replicated_methods;
303 @replicated_methods{@replicated_methods} = ();
305 # remove ::Replicated-specific methods
306 for my $method (@replicated_methods) {
307 delete $replicated_methods{$method}
308 unless exists $storage_dbi_methods{$method};
310 @replicated_methods = keys %replicated_methods;
312 # check that what's left is implemented
314 $count{$_}++ for (@storage_dbi_methods, @replicated_methods);
316 if ((grep $count{$_} == 2, @storage_dbi_methods) == @storage_dbi_methods) {
317 pass 'all DBIx::Class::Storage::DBI methods implemented';
320 my @unimplemented = grep $count{$_} == 1, @storage_dbi_methods;
322 fail 'the following DBIx::Class::Storage::DBI methods are unimplemented: '
327 ok $replicated->schema->storage->meta
328 => 'has a meta object';
330 isa_ok $replicated->schema->storage->master
331 => 'DBIx::Class::Storage::DBI';
333 isa_ok $replicated->schema->storage->pool
334 => 'DBIx::Class::Storage::DBI::Replicated::Pool';
336 does_ok $replicated->schema->storage->balancer
337 => 'DBIx::Class::Storage::DBI::Replicated::Balancer';
339 ok my @replicant_connects = $replicated->generate_replicant_connect_info
340 => 'got replication connect information';
342 ok my @replicated_storages = $replicated->schema->storage->connect_replicants(@replicant_connects)
343 => 'Created some storages suitable for replicants';
346 $replicated->schema->storage->debug(1);
347 $replicated->schema->storage->debugcb(sub {
348 my ($op, $info) = @_;
349 ##warn "\n$op, $info\n";
353 dsn => ($info=~m/\[(.+)\]/)[0],
354 storage_type => $info=~m/REPLICANT/ ? 'REPLICANT' : 'MASTER',
358 ok my @all_storages = $replicated->schema->storage->all_storages
361 is scalar @all_storages,
363 => 'correct number of ->all_storages';
365 is ((grep $_->isa('DBIx::Class::Storage::DBI'), @all_storages),
367 => '->all_storages are correct type');
369 my @all_storage_opts =
370 grep { (reftype($_)||'') eq 'HASH' }
371 map @{ $_->_connect_info }, @all_storages;
373 is ((grep $_->{master_option}, @all_storage_opts),
375 => 'connect_info was merged from master to replicants');
377 my @replicant_names = keys %{ $replicated->schema->storage->replicants };
379 ok @replicant_names, "found replicant names @replicant_names";
381 ## Silence warning about not supporting the is_replicating method if using the
383 $replicated->schema->storage->debugobj->silence(1)
384 if first { m{^t/} } @replicant_names;
386 isa_ok $replicated->schema->storage->balancer->current_replicant
387 => 'DBIx::Class::Storage::DBI';
389 $replicated->schema->storage->debugobj->silence(0);
391 ok $replicated->schema->storage->pool->has_replicants
392 => 'does have replicants';
394 is $replicated->schema->storage->pool->num_replicants => 2
395 => 'has two replicants';
397 does_ok $replicated_storages[0]
398 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
400 does_ok $replicated_storages[1]
401 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
403 does_ok $replicated->schema->storage->replicants->{$replicant_names[0]}
404 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
406 does_ok $replicated->schema->storage->replicants->{$replicant_names[1]}
407 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
409 ## Add some info to the database
413 ->populate('Artist', [
414 [ qw/artistid name/ ],
415 [ 4, "Ozric Tentacles"],
418 is $debug{storage_type}, 'MASTER',
419 "got last query from a master: $debug{dsn}";
421 like $debug{info}, qr/INSERT/, 'Last was an insert';
423 ## Make sure all the slaves have the table definitions
425 $replicated->replicate;
426 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
427 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
429 ## Silence warning about not supporting the is_replicating method if using the
431 $replicated->schema->storage->debugobj->silence(1)
432 if first { m{^t/} } @replicant_names;
434 $replicated->schema->storage->pool->validate_replicants;
436 $replicated->schema->storage->debugobj->silence(0);
438 ## Make sure we can read the data.
440 ok my $artist1 = $replicated->schema->resultset('Artist')->find(4)
443 ## We removed testing here since master read weight is on, so we can't tell in
444 ## advance what storage to expect. We turn master read weight off a bit lower
445 ## is $debug{storage_type}, 'REPLICANT'
446 ## => "got last query from a replicant: $debug{dsn}, $debug{info}";
449 => 'DBICTest::Artist';
451 is $artist1->name, 'Ozric Tentacles'
452 => 'Found expected name for first result';
454 ## Check that master_read_weight is honored
456 no warnings qw/once redefine/;
459 *DBIx::Class::Storage::DBI::Replicated::Balancer::Random::_random_number =
462 $replicated->schema->storage->balancer->increment_storage;
464 is $replicated->schema->storage->balancer->current_replicant,
465 $replicated->schema->storage->master
466 => 'master_read_weight is honored';
468 ## turn it off for the duration of the test
469 $replicated->schema->storage->balancer->master_read_weight(0);
470 $replicated->schema->storage->balancer->increment_storage;
473 ## Add some new rows that only the master will have This is because
474 ## we overload any type of write operation so that is must hit the master
479 ->populate('Artist', [
480 [ qw/artistid name/ ],
481 [ 5, "Doom's Children"],
482 [ 6, "Dead On Arrival"],
486 is $debug{storage_type}, 'MASTER',
487 "got last query from a master: $debug{dsn}";
489 like $debug{info}, qr/INSERT/, 'Last was an insert';
491 ## Make sure all the slaves have the table definitions
492 $replicated->replicate;
494 ## Should find some data now
496 ok my $artist2 = $replicated->schema->resultset('Artist')->find(5)
499 is $debug{storage_type}, 'REPLICANT'
500 => "got last query from a replicant: $debug{dsn}";
503 => 'DBICTest::Artist';
505 is $artist2->name, "Doom's Children"
506 => 'Found expected name for first result';
508 ## What happens when we disconnect all the replicants?
510 is $replicated->schema->storage->pool->connected_replicants => 2
511 => "both replicants are connected";
513 $replicated->schema->storage->replicants->{$replicant_names[0]}->disconnect;
514 $replicated->schema->storage->replicants->{$replicant_names[1]}->disconnect;
516 is $replicated->schema->storage->pool->connected_replicants => 0
517 => "both replicants are now disconnected";
519 ## All these should pass, since the database should automatically reconnect
521 ok my $artist3 = $replicated->schema->resultset('Artist')->find(6)
522 => 'Still finding stuff.';
524 is $debug{storage_type}, 'REPLICANT'
525 => "got last query from a replicant: $debug{dsn}";
528 => 'DBICTest::Artist';
530 is $artist3->name, "Dead On Arrival"
531 => 'Found expected name for first result';
533 is $replicated->schema->storage->pool->connected_replicants => 1
534 => "At Least One replicant reconnected to handle the job";
536 ## What happens when we try to select something that doesn't exist?
538 ok ! $replicated->schema->resultset('Artist')->find(666)
539 => 'Correctly failed to find something.';
541 is $debug{storage_type}, 'REPLICANT'
542 => "got last query from a replicant: $debug{dsn}";
544 ## test the reliable option
548 $replicated->schema->storage->set_reliable_storage;
550 ok $replicated->schema->resultset('Artist')->find(2)
551 => 'Read from master 1';
553 is $debug{storage_type}, 'MASTER',
554 "got last query from a master: $debug{dsn}";
556 ok $replicated->schema->resultset('Artist')->find(5)
557 => 'Read from master 2';
559 is $debug{storage_type}, 'MASTER',
560 "got last query from a master: $debug{dsn}";
562 $replicated->schema->storage->set_balanced_storage;
564 ok $replicated->schema->resultset('Artist')->find(3)
565 => 'Read from replicant';
567 is $debug{storage_type}, 'REPLICANT',
568 "got last query from a replicant: $debug{dsn}";
571 ## Make sure when reliable goes out of scope, we are using replicants again
573 ok $replicated->schema->resultset('Artist')->find(1)
574 => 'back to replicant 1.';
576 is $debug{storage_type}, 'REPLICANT',
577 "got last query from a replicant: $debug{dsn}";
579 ok $replicated->schema->resultset('Artist')->find(2)
580 => 'back to replicant 2.';
582 is $debug{storage_type}, 'REPLICANT',
583 "got last query from a replicant: $debug{dsn}";
585 ## set all the replicants to inactive, and make sure the balancer falls back to
588 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
589 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
592 ## catch the fallback to master warning
593 open my $debugfh, '>', \my $fallback_warning;
594 my $oldfh = $replicated->schema->storage->debugfh;
595 $replicated->schema->storage->debugfh($debugfh);
597 ok $replicated->schema->resultset('Artist')->find(2)
598 => 'Fallback to master';
600 is $debug{storage_type}, 'MASTER',
601 "got last query from a master: $debug{dsn}";
603 like $fallback_warning, qr/falling back to master/
604 => 'emits falling back to master warning';
606 $replicated->schema->storage->debugfh($oldfh);
609 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
610 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
612 ## Silence warning about not supporting the is_replicating method if using the
614 $replicated->schema->storage->debugobj->silence(1)
615 if first { m{^t/} } @replicant_names;
617 $replicated->schema->storage->pool->validate_replicants;
619 $replicated->schema->storage->debugobj->silence(0);
621 ok $replicated->schema->resultset('Artist')->find(2)
622 => 'Returned to replicates';
624 is $debug{storage_type}, 'REPLICANT',
625 "got last query from a replicant: $debug{dsn}";
627 ## Getting slave status tests
630 ## We skip this tests unless you have a custom replicants, since the default
631 ## sqlite based replication tests don't support these functions.
633 skip 'Cannot Test Replicant Status on Non Replicating Database', 10
634 unless DBICTest->has_custom_dsn && $ENV{"DBICTEST_SLAVE0_DSN"};
636 $replicated->replicate; ## Give the slaves a chance to catchup.
638 ok $replicated->schema->storage->replicants->{$replicant_names[0]}->is_replicating
639 => 'Replicants are replicating';
641 is $replicated->schema->storage->replicants->{$replicant_names[0]}->lag_behind_master, 0
642 => 'Replicant is zero seconds behind master';
644 ## Test the validate replicants
646 $replicated->schema->storage->pool->validate_replicants;
648 is $replicated->schema->storage->pool->active_replicants, 2
649 => 'Still have 2 replicants after validation';
651 ## Force the replicants to fail the validate test by required their lag to
652 ## be negative (ie ahead of the master!)
654 $replicated->schema->storage->pool->maximum_lag(-10);
655 $replicated->schema->storage->pool->validate_replicants;
657 is $replicated->schema->storage->pool->active_replicants, 0
658 => 'No way a replicant be be ahead of the master';
660 ## Let's be fair to the replicants again. Let them lag up to 5
662 $replicated->schema->storage->pool->maximum_lag(5);
663 $replicated->schema->storage->pool->validate_replicants;
665 is $replicated->schema->storage->pool->active_replicants, 2
666 => 'Both replicants in good standing again';
668 ## Check auto validate
670 is $replicated->schema->storage->balancer->auto_validate_every, 100
671 => "Got the expected value for auto validate";
673 ## This will make sure we auto validatge everytime
674 $replicated->schema->storage->balancer->auto_validate_every(0);
676 ## set all the replicants to inactive, and make sure the balancer falls back to
679 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
680 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
682 ## Ok, now when we go to run a query, autovalidate SHOULD reconnect
684 is $replicated->schema->storage->pool->active_replicants => 0
685 => "both replicants turned off";
687 ok $replicated->schema->resultset('Artist')->find(5)
688 => 'replicant reactivated';
690 is $debug{storage_type}, 'REPLICANT',
691 "got last query from a replicant: $debug{dsn}";
693 is $replicated->schema->storage->pool->active_replicants => 2
694 => "both replicants reactivated";
697 ## Test the reliably callback
699 ok my $reliably = sub {
701 ok $replicated->schema->resultset('Artist')->find(5)
702 => 'replicant reactivated';
704 is $debug{storage_type}, 'MASTER',
705 "got last query from a master: $debug{dsn}";
707 } => 'created coderef properly';
709 $replicated->schema->storage->execute_reliably($reliably);
711 ## Try something with an error
713 ok my $unreliably = sub {
715 ok $replicated->schema->resultset('ArtistXX')->find(5)
716 => 'replicant reactivated';
718 } => 'created coderef properly';
720 throws_ok {$replicated->schema->storage->execute_reliably($unreliably)}
721 qr/Can't find source for ArtistXX/
722 => 'Bad coderef throws proper error';
724 ## Make sure replication came back
726 ok $replicated->schema->resultset('Artist')->find(3)
727 => 'replicant reactivated';
729 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
731 ## make sure transactions are set to execute_reliably
733 ok my $transaction = sub {
739 ->populate('Artist', [
740 [ qw/artistid name/ ],
741 [ $id, "Children of the Grave $id"],
744 ok my $result = $replicated->schema->resultset('Artist')->find($id)
745 => "Found expected artist for $id";
747 is $debug{storage_type}, 'MASTER',
748 "got last query from a master: $debug{dsn}";
750 ok my $more = $replicated->schema->resultset('Artist')->find(1)
751 => 'Found expected artist again for 1';
753 is $debug{storage_type}, 'MASTER',
754 "got last query from a master: $debug{dsn}";
756 return ($result, $more);
758 } => 'Created a coderef properly';
760 ## Test the transaction with multi return
762 ok my @return = $replicated->schema->txn_do($transaction, 666)
763 => 'did transaction';
765 is $return[0]->id, 666
766 => 'first returned value is correct';
768 is $debug{storage_type}, 'MASTER',
769 "got last query from a master: $debug{dsn}";
772 => 'second returned value is correct';
774 is $debug{storage_type}, 'MASTER',
775 "got last query from a master: $debug{dsn}";
779 ## Test that asking for single return works
781 ok my @return = $replicated->schema->txn_do($transaction, 777)
782 => 'did transaction';
784 is $return[0]->id, 777
785 => 'first returned value is correct';
788 => 'second returned value is correct';
791 ## Test transaction returning a single value
794 ok my $result = $replicated->schema->txn_do(sub {
795 ok my $more = $replicated->schema->resultset('Artist')->find(1)
796 => 'found inside a transaction';
797 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
799 }) => 'successfully processed transaction';
802 => 'Got expected single result from transaction';
805 ## Make sure replication came back
807 ok $replicated->schema->resultset('Artist')->find(1)
808 => 'replicant reactivated';
810 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
812 ## Test Discard changes
815 ok my $artist = $replicated->schema->resultset('Artist')->find(2)
816 => 'got an artist to test discard changes';
818 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
820 ok $artist->get_from_storage({force_pool=>'master'})
821 => 'properly discard changes';
823 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
825 ok $artist->discard_changes({force_pool=>'master'})
826 => 'properly called discard_changes against master (manual attrs)';
828 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
830 ok $artist->discard_changes()
831 => 'properly called discard_changes against master (default attrs)';
833 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
835 ok $artist->discard_changes({force_pool=>$replicant_names[0]})
836 => 'properly able to override the default attributes';
838 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}"
841 ## Test some edge cases, like trying to do a transaction inside a transaction, etc
844 ok my $result = $replicated->schema->txn_do(sub {
845 return $replicated->schema->txn_do(sub {
846 ok my $more = $replicated->schema->resultset('Artist')->find(1)
847 => 'found inside a transaction inside a transaction';
848 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
851 }) => 'successfully processed transaction';
854 => 'Got expected single result from transaction';
858 ok my $result = $replicated->schema->txn_do(sub {
859 return $replicated->schema->storage->execute_reliably(sub {
860 return $replicated->schema->txn_do(sub {
861 return $replicated->schema->storage->execute_reliably(sub {
862 ok my $more = $replicated->schema->resultset('Artist')->find(1)
863 => 'found inside crazy deep transactions and execute_reliably';
864 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
869 }) => 'successfully processed transaction';
872 => 'Got expected single result from transaction';
875 ## Test the force_pool resultset attribute.
878 ok my $artist_rs = $replicated->schema->resultset('Artist')
879 => 'got artist resultset';
881 ## Turn on Forced Pool Storage
882 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>'master'})
883 => 'Created a resultset using force_pool storage';
885 ok my $artist = $reliable_artist_rs->find(2)
886 => 'got an artist result via force_pool storage';
888 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
891 ## Test the force_pool resultset attribute part two.
894 ok my $artist_rs = $replicated->schema->resultset('Artist')
895 => 'got artist resultset';
897 ## Turn on Forced Pool Storage
898 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>$replicant_names[0]})
899 => 'Created a resultset using force_pool storage';
901 ok my $artist = $reliable_artist_rs->find(2)
902 => 'got an artist result via force_pool storage';
904 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
906 ## Delete the old database files
907 $replicated->cleanup;