7 use List::Util 'first';
8 use Scalar::Util 'reftype';
13 eval "use DBIx::Class::Storage::DBI::Replicated; use Test::Moose";
14 plan skip_all => "Deps not installed: $@" if $@;
17 use_ok 'DBIx::Class::Storage::DBI::Replicated::Pool';
18 use_ok 'DBIx::Class::Storage::DBI::Replicated::Balancer';
19 use_ok 'DBIx::Class::Storage::DBI::Replicated::Replicant';
20 use_ok 'DBIx::Class::Storage::DBI::Replicated';
24 diag "Using Moose version $Moose::VERSION and MooseX::Types version $MooseX::Types::VERSION";
28 This is a test of the replicated storage system. This will work in one of
29 two ways, either it was try to fake replication with a couple of SQLite DBs
30 and creative use of copy, or if you define a couple of %ENV vars correctly
31 will try to test those. If you do that, it will assume the setup is properly
32 replicating. Your results may vary, but I have demonstrated this to work with
33 mysql native replication.
38 ## ----------------------------------------------------------------------------
39 ## Build a class to hold all our required testing data and methods.
40 ## ----------------------------------------------------------------------------
44 ## --------------------------------------------------------------------- ##
45 ## Create an object to contain your replicated stuff.
46 ## --------------------------------------------------------------------- ##
48 package DBIx::Class::DBI::Replicated::TestReplication;
51 use base qw/Class::Accessor::Fast/;
53 __PACKAGE__->mk_accessors( qw/schema/ );
55 ## Initialize the object
58 my ($class, $schema_method) = (shift, shift);
59 my $self = $class->SUPER::new(@_);
61 $self->schema( $self->init_schema($schema_method) );
65 ## Get the Schema and set the replication storage type
68 # current SQLT SQLite producer does not handle DROP TABLE IF EXISTS, trap warnings here
69 local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /no such table.+DROP TABLE/s };
71 my ($class, $schema_method) = @_;
73 my $method = "get_schema_$schema_method";
74 my $schema = $class->$method;
79 sub get_schema_by_storage_type {
80 DBICTest->init_schema(
83 '::DBI::Replicated' => {
84 balancer_type=>'::Random',
86 auto_validate_every=>100,
87 master_read_weight => 1
97 sub get_schema_by_connect_info {
98 DBICTest->init_schema(
100 storage_type=> '::DBI::Replicated',
101 balancer_type=>'::Random',
103 auto_validate_every=>100,
104 master_read_weight => 1
112 sub generate_replicant_connect_info {}
116 ## --------------------------------------------------------------------- ##
117 ## Add a connect_info option to test option merging.
118 ## --------------------------------------------------------------------- ##
120 package DBIx::Class::Storage::DBI::Replicated;
124 __PACKAGE__->meta->make_mutable;
126 around connect_info => sub {
127 my ($next, $self, $info) = @_;
128 $info->[3]{master_option} = 1;
132 __PACKAGE__->meta->make_immutable;
137 ## --------------------------------------------------------------------- ##
138 ## Subclass for when you are using SQLite for testing, this provides a fake
139 ## replication support.
140 ## --------------------------------------------------------------------- ##
142 package DBIx::Class::DBI::Replicated::TestReplication::SQLite;
146 use base 'DBIx::Class::DBI::Replicated::TestReplication';
148 __PACKAGE__->mk_accessors(qw/master_path slave_paths/);
150 ## Set the master path from DBICTest
153 my $class = shift @_;
154 my $self = $class->SUPER::new(@_);
156 $self->master_path( DBICTest->_sqlite_dbfilename );
158 File::Spec->catfile(qw/t var DBIxClass_slave1.db/),
159 File::Spec->catfile(qw/t var DBIxClass_slave2.db/),
165 ## Return an Array of ArrayRefs where each ArrayRef is suitable to use for
166 ## $storage->connect_info to be used for connecting replicants.
168 sub generate_replicant_connect_info {
172 } @{$self->slave_paths};
174 my @connect_infos = map { [$_,'','',{AutoCommit=>1}] } @dsn;
176 ## Make sure nothing is left over from a failed test
180 my $c = $connect_infos[0];
181 $connect_infos[0] = {
191 ## Do a 'good enough' replication by copying the master dbfile over each of
192 ## the slave dbfiles. If the master is SQLite we do this, otherwise we
193 ## just do a one second pause to let the slaves catch up.
197 foreach my $slave (@{$self->slave_paths}) {
198 copy($self->master_path, $slave);
202 ## Cleanup after ourselves. Unlink all gthe slave paths.
206 foreach my $slave (@{$self->slave_paths}) {
213 ## --------------------------------------------------------------------- ##
214 ## Subclass for when you are setting the databases via custom export vars
215 ## This is for when you have a replicating database setup that you are
216 ## going to test against. You'll need to define the correct $ENV and have
217 ## two slave databases to test against, as well as a replication system
218 ## that will replicate in less than 1 second.
219 ## --------------------------------------------------------------------- ##
221 package DBIx::Class::DBI::Replicated::TestReplication::Custom;
222 use base 'DBIx::Class::DBI::Replicated::TestReplication';
224 ## Return an Array of ArrayRefs where each ArrayRef is suitable to use for
225 ## $storage->connect_info to be used for connecting replicants.
227 sub generate_replicant_connect_info {
229 [$ENV{"DBICTEST_SLAVE0_DSN"}, $ENV{"DBICTEST_SLAVE0_DBUSER"}, $ENV{"DBICTEST_SLAVE0_DBPASS"}, {AutoCommit => 1}],
230 [$ENV{"DBICTEST_SLAVE1_DSN"}, $ENV{"DBICTEST_SLAVE1_DBUSER"}, $ENV{"DBICTEST_SLAVE1_DBPASS"}, {AutoCommit => 1}],
234 ## pause a bit to let the replication catch up
241 ## ----------------------------------------------------------------------------
242 ## Create an object and run some tests
243 ## ----------------------------------------------------------------------------
245 ## Thi first bunch of tests are basic, just make sure all the bits are behaving
247 my $replicated_class = DBICTest->has_custom_dsn ?
248 'DBIx::Class::DBI::Replicated::TestReplication::Custom' :
249 'DBIx::Class::DBI::Replicated::TestReplication::SQLite';
253 for my $method (qw/by_connect_info by_storage_type/) {
255 ok $replicated = $replicated_class->new($method)
256 => "Created a replication object $method";
258 isa_ok $replicated->schema
259 => 'DBIx::Class::Schema';
261 isa_ok $replicated->schema->storage
262 => 'DBIx::Class::Storage::DBI::Replicated';
264 isa_ok $replicated->schema->storage->balancer
265 => 'DBIx::Class::Storage::DBI::Replicated::Balancer::Random'
266 => 'configured balancer_type';
269 ### check that all Storage::DBI methods are handled by ::Replicated
271 my $storage_dbi_meta = Class::MOP::Class->initialize('DBIx::Class::Storage::DBI');
272 my $replicated_meta = DBIx::Class::Storage::DBI::Replicated->meta;
274 my @storage_dbi_methods = sort $storage_dbi_meta->get_all_method_names;
275 my @replicated_methods = sort $replicated_meta->get_all_method_names;
278 @storage_dbi_methods = grep !/^[A-Z_]+\z/, @storage_dbi_methods;
280 # remove CAG accessors
281 @storage_dbi_methods = grep !/_accessor\z/, @storage_dbi_methods;
283 # remove DBIx::Class (the root parent, with CAG and stuff) methods
284 my @cag_methods = Class::MOP::Class->initialize('DBIx::Class')
285 ->get_all_method_names;
287 $count{$_}++ for (@storage_dbi_methods, @cag_methods);
289 @storage_dbi_methods = grep $count{$_} != 2, @storage_dbi_methods;
292 my %storage_dbi_methods;
293 @storage_dbi_methods{@storage_dbi_methods} = ();
294 my %replicated_methods;
295 @replicated_methods{@replicated_methods} = ();
297 # remove ::Replicated-specific methods
298 for my $method (@replicated_methods) {
299 delete $replicated_methods{$method}
300 unless exists $storage_dbi_methods{$method};
303 # check that what's left is implemented
305 $count{$_}++ for (@storage_dbi_methods, @replicated_methods);
307 if ((grep $count{$_} == 2, @storage_dbi_methods) == @storage_dbi_methods) {
308 pass 'all DBIx::Class::Storage::DBI methods implemented';
311 my @unimplemented = grep $count{$_} == 1, @storage_dbi_methods;
313 fail 'the following DBIx::Class::Storage::DBI methods are unimplemented: '
318 ok $replicated->schema->storage->meta
319 => 'has a meta object';
321 isa_ok $replicated->schema->storage->master
322 => 'DBIx::Class::Storage::DBI';
324 isa_ok $replicated->schema->storage->pool
325 => 'DBIx::Class::Storage::DBI::Replicated::Pool';
327 does_ok $replicated->schema->storage->balancer
328 => 'DBIx::Class::Storage::DBI::Replicated::Balancer';
330 ok my @replicant_connects = $replicated->generate_replicant_connect_info
331 => 'got replication connect information';
333 ok my @replicated_storages = $replicated->schema->storage->connect_replicants(@replicant_connects)
334 => 'Created some storages suitable for replicants';
337 $replicated->schema->storage->debug(1);
338 $replicated->schema->storage->debugcb(sub {
339 my ($op, $info) = @_;
340 ##warn "\n$op, $info\n";
344 dsn => ($info=~m/\[(.+)\]/)[0],
345 storage_type => $info=~m/REPLICANT/ ? 'REPLICANT' : 'MASTER',
349 ok my @all_storages = $replicated->schema->storage->all_storages
352 is scalar @all_storages,
354 => 'correct number of ->all_storages';
356 is ((grep $_->isa('DBIx::Class::Storage::DBI'), @all_storages),
358 => '->all_storages are correct type');
360 my @all_storage_opts =
361 grep { (reftype($_)||'') eq 'HASH' }
362 map @{ $_->_connect_info }, @all_storages;
364 is ((grep $_->{master_option}, @all_storage_opts),
366 => 'connect_info was merged from master to replicants');
368 my @replicant_names = keys %{ $replicated->schema->storage->replicants };
370 ok @replicant_names, "found replicant names @replicant_names";
372 ## Silence warning about not supporting the is_replicating method if using the
374 $replicated->schema->storage->debugobj->silence(1)
375 if first { m{^t/} } @replicant_names;
377 isa_ok $replicated->schema->storage->balancer->current_replicant
378 => 'DBIx::Class::Storage::DBI';
380 $replicated->schema->storage->debugobj->silence(0);
382 ok $replicated->schema->storage->pool->has_replicants
383 => 'does have replicants';
385 is $replicated->schema->storage->pool->num_replicants => 2
386 => 'has two replicants';
388 does_ok $replicated_storages[0]
389 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
391 does_ok $replicated_storages[1]
392 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
394 does_ok $replicated->schema->storage->replicants->{$replicant_names[0]}
395 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
397 does_ok $replicated->schema->storage->replicants->{$replicant_names[1]}
398 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
400 ## Add some info to the database
404 ->populate('Artist', [
405 [ qw/artistid name/ ],
406 [ 4, "Ozric Tentacles"],
409 is $debug{storage_type}, 'MASTER',
410 "got last query from a master: $debug{dsn}";
412 like $debug{info}, qr/INSERT/, 'Last was an insert';
414 ## Make sure all the slaves have the table definitions
416 $replicated->replicate;
417 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
418 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
420 ## Silence warning about not supporting the is_replicating method if using the
422 $replicated->schema->storage->debugobj->silence(1)
423 if first { m{^t/} } @replicant_names;
425 $replicated->schema->storage->pool->validate_replicants;
427 $replicated->schema->storage->debugobj->silence(0);
429 ## Make sure we can read the data.
431 ok my $artist1 = $replicated->schema->resultset('Artist')->find(4)
434 ## We removed testing here since master read weight is on, so we can't tell in
435 ## advance what storage to expect. We turn master read weight off a bit lower
436 ## is $debug{storage_type}, 'REPLICANT'
437 ## => "got last query from a replicant: $debug{dsn}, $debug{info}";
440 => 'DBICTest::Artist';
442 is $artist1->name, 'Ozric Tentacles'
443 => 'Found expected name for first result';
445 ## Check that master_read_weight is honored
447 no warnings qw/once redefine/;
450 *DBIx::Class::Storage::DBI::Replicated::Balancer::Random::_random_number =
453 $replicated->schema->storage->balancer->increment_storage;
455 is $replicated->schema->storage->balancer->current_replicant,
456 $replicated->schema->storage->master
457 => 'master_read_weight is honored';
459 ## turn it off for the duration of the test
460 $replicated->schema->storage->balancer->master_read_weight(0);
461 $replicated->schema->storage->balancer->increment_storage;
464 ## Add some new rows that only the master will have This is because
465 ## we overload any type of write operation so that is must hit the master
470 ->populate('Artist', [
471 [ qw/artistid name/ ],
472 [ 5, "Doom's Children"],
473 [ 6, "Dead On Arrival"],
477 is $debug{storage_type}, 'MASTER',
478 "got last query from a master: $debug{dsn}";
480 like $debug{info}, qr/INSERT/, 'Last was an insert';
482 ## Make sure all the slaves have the table definitions
483 $replicated->replicate;
485 ## Should find some data now
487 ok my $artist2 = $replicated->schema->resultset('Artist')->find(5)
490 is $debug{storage_type}, 'REPLICANT'
491 => "got last query from a replicant: $debug{dsn}";
494 => 'DBICTest::Artist';
496 is $artist2->name, "Doom's Children"
497 => 'Found expected name for first result';
499 ## What happens when we disconnect all the replicants?
501 is $replicated->schema->storage->pool->connected_replicants => 2
502 => "both replicants are connected";
504 $replicated->schema->storage->replicants->{$replicant_names[0]}->disconnect;
505 $replicated->schema->storage->replicants->{$replicant_names[1]}->disconnect;
507 is $replicated->schema->storage->pool->connected_replicants => 0
508 => "both replicants are now disconnected";
510 ## All these should pass, since the database should automatically reconnect
512 ok my $artist3 = $replicated->schema->resultset('Artist')->find(6)
513 => 'Still finding stuff.';
515 is $debug{storage_type}, 'REPLICANT'
516 => "got last query from a replicant: $debug{dsn}";
519 => 'DBICTest::Artist';
521 is $artist3->name, "Dead On Arrival"
522 => 'Found expected name for first result';
524 is $replicated->schema->storage->pool->connected_replicants => 1
525 => "At Least One replicant reconnected to handle the job";
527 ## What happens when we try to select something that doesn't exist?
529 ok ! $replicated->schema->resultset('Artist')->find(666)
530 => 'Correctly failed to find something.';
532 is $debug{storage_type}, 'REPLICANT'
533 => "got last query from a replicant: $debug{dsn}";
535 ## test the reliable option
539 $replicated->schema->storage->set_reliable_storage;
541 ok $replicated->schema->resultset('Artist')->find(2)
542 => 'Read from master 1';
544 is $debug{storage_type}, 'MASTER',
545 "got last query from a master: $debug{dsn}";
547 ok $replicated->schema->resultset('Artist')->find(5)
548 => 'Read from master 2';
550 is $debug{storage_type}, 'MASTER',
551 "got last query from a master: $debug{dsn}";
553 $replicated->schema->storage->set_balanced_storage;
555 ok $replicated->schema->resultset('Artist')->find(3)
556 => 'Read from replicant';
558 is $debug{storage_type}, 'REPLICANT',
559 "got last query from a replicant: $debug{dsn}";
562 ## Make sure when reliable goes out of scope, we are using replicants again
564 ok $replicated->schema->resultset('Artist')->find(1)
565 => 'back to replicant 1.';
567 is $debug{storage_type}, 'REPLICANT',
568 "got last query from a replicant: $debug{dsn}";
570 ok $replicated->schema->resultset('Artist')->find(2)
571 => 'back to replicant 2.';
573 is $debug{storage_type}, 'REPLICANT',
574 "got last query from a replicant: $debug{dsn}";
576 ## set all the replicants to inactive, and make sure the balancer falls back to
579 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
580 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
583 ## catch the fallback to master warning
584 open my $debugfh, '>', \my $fallback_warning;
585 my $oldfh = $replicated->schema->storage->debugfh;
586 $replicated->schema->storage->debugfh($debugfh);
588 ok $replicated->schema->resultset('Artist')->find(2)
589 => 'Fallback to master';
591 is $debug{storage_type}, 'MASTER',
592 "got last query from a master: $debug{dsn}";
594 like $fallback_warning, qr/falling back to master/
595 => 'emits falling back to master warning';
597 $replicated->schema->storage->debugfh($oldfh);
600 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
601 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
603 ## Silence warning about not supporting the is_replicating method if using the
605 $replicated->schema->storage->debugobj->silence(1)
606 if first { m{^t/} } @replicant_names;
608 $replicated->schema->storage->pool->validate_replicants;
610 $replicated->schema->storage->debugobj->silence(0);
612 ok $replicated->schema->resultset('Artist')->find(2)
613 => 'Returned to replicates';
615 is $debug{storage_type}, 'REPLICANT',
616 "got last query from a replicant: $debug{dsn}";
618 ## Getting slave status tests
621 ## We skip this tests unless you have a custom replicants, since the default
622 ## sqlite based replication tests don't support these functions.
624 skip 'Cannot Test Replicant Status on Non Replicating Database', 10
625 unless DBICTest->has_custom_dsn && $ENV{"DBICTEST_SLAVE0_DSN"};
627 $replicated->replicate; ## Give the slaves a chance to catchup.
629 ok $replicated->schema->storage->replicants->{$replicant_names[0]}->is_replicating
630 => 'Replicants are replicating';
632 is $replicated->schema->storage->replicants->{$replicant_names[0]}->lag_behind_master, 0
633 => 'Replicant is zero seconds behind master';
635 ## Test the validate replicants
637 $replicated->schema->storage->pool->validate_replicants;
639 is $replicated->schema->storage->pool->active_replicants, 2
640 => 'Still have 2 replicants after validation';
642 ## Force the replicants to fail the validate test by required their lag to
643 ## be negative (ie ahead of the master!)
645 $replicated->schema->storage->pool->maximum_lag(-10);
646 $replicated->schema->storage->pool->validate_replicants;
648 is $replicated->schema->storage->pool->active_replicants, 0
649 => 'No way a replicant be be ahead of the master';
651 ## Let's be fair to the replicants again. Let them lag up to 5
653 $replicated->schema->storage->pool->maximum_lag(5);
654 $replicated->schema->storage->pool->validate_replicants;
656 is $replicated->schema->storage->pool->active_replicants, 2
657 => 'Both replicants in good standing again';
659 ## Check auto validate
661 is $replicated->schema->storage->balancer->auto_validate_every, 100
662 => "Got the expected value for auto validate";
664 ## This will make sure we auto validatge everytime
665 $replicated->schema->storage->balancer->auto_validate_every(0);
667 ## set all the replicants to inactive, and make sure the balancer falls back to
670 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
671 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
673 ## Ok, now when we go to run a query, autovalidate SHOULD reconnect
675 is $replicated->schema->storage->pool->active_replicants => 0
676 => "both replicants turned off";
678 ok $replicated->schema->resultset('Artist')->find(5)
679 => 'replicant reactivated';
681 is $debug{storage_type}, 'REPLICANT',
682 "got last query from a replicant: $debug{dsn}";
684 is $replicated->schema->storage->pool->active_replicants => 2
685 => "both replicants reactivated";
688 ## Test the reliably callback
690 ok my $reliably = sub {
692 ok $replicated->schema->resultset('Artist')->find(5)
693 => 'replicant reactivated';
695 is $debug{storage_type}, 'MASTER',
696 "got last query from a master: $debug{dsn}";
698 } => 'created coderef properly';
700 $replicated->schema->storage->execute_reliably($reliably);
702 ## Try something with an error
704 ok my $unreliably = sub {
706 ok $replicated->schema->resultset('ArtistXX')->find(5)
707 => 'replicant reactivated';
709 } => 'created coderef properly';
711 throws_ok {$replicated->schema->storage->execute_reliably($unreliably)}
712 qr/Can't find source for ArtistXX/
713 => 'Bad coderef throws proper error';
715 ## Make sure replication came back
717 ok $replicated->schema->resultset('Artist')->find(3)
718 => 'replicant reactivated';
720 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
722 ## make sure transactions are set to execute_reliably
724 ok my $transaction = sub {
730 ->populate('Artist', [
731 [ qw/artistid name/ ],
732 [ $id, "Children of the Grave"],
735 ok my $result = $replicated->schema->resultset('Artist')->find($id)
736 => "Found expected artist for $id";
738 is $debug{storage_type}, 'MASTER',
739 "got last query from a master: $debug{dsn}";
741 ok my $more = $replicated->schema->resultset('Artist')->find(1)
742 => 'Found expected artist again for 1';
744 is $debug{storage_type}, 'MASTER',
745 "got last query from a master: $debug{dsn}";
747 return ($result, $more);
749 } => 'Created a coderef properly';
751 ## Test the transaction with multi return
753 ok my @return = $replicated->schema->txn_do($transaction, 666)
754 => 'did transaction';
756 is $return[0]->id, 666
757 => 'first returned value is correct';
759 is $debug{storage_type}, 'MASTER',
760 "got last query from a master: $debug{dsn}";
763 => 'second returned value is correct';
765 is $debug{storage_type}, 'MASTER',
766 "got last query from a master: $debug{dsn}";
770 ## Test that asking for single return works
772 ok my @return = $replicated->schema->txn_do($transaction, 777)
773 => 'did transaction';
775 is $return[0]->id, 777
776 => 'first returned value is correct';
779 => 'second returned value is correct';
782 ## Test transaction returning a single value
785 ok my $result = $replicated->schema->txn_do(sub {
786 ok my $more = $replicated->schema->resultset('Artist')->find(1)
787 => 'found inside a transaction';
788 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
790 }) => 'successfully processed transaction';
793 => 'Got expected single result from transaction';
796 ## Make sure replication came back
798 ok $replicated->schema->resultset('Artist')->find(1)
799 => 'replicant reactivated';
801 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
803 ## Test Discard changes
806 ok my $artist = $replicated->schema->resultset('Artist')->find(2)
807 => 'got an artist to test discard changes';
809 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
811 ok $artist->get_from_storage({force_pool=>'master'})
812 => 'properly discard changes';
814 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
816 ok $artist->discard_changes({force_pool=>'master'})
817 => 'properly called discard_changes against master (manual attrs)';
819 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
821 ok $artist->discard_changes()
822 => 'properly called discard_changes against master (default attrs)';
824 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
826 ok $artist->discard_changes({force_pool=>$replicant_names[0]})
827 => 'properly able to override the default attributes';
829 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}"
832 ## Test some edge cases, like trying to do a transaction inside a transaction, etc
835 ok my $result = $replicated->schema->txn_do(sub {
836 return $replicated->schema->txn_do(sub {
837 ok my $more = $replicated->schema->resultset('Artist')->find(1)
838 => 'found inside a transaction inside a transaction';
839 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
842 }) => 'successfully processed transaction';
845 => 'Got expected single result from transaction';
849 ok my $result = $replicated->schema->txn_do(sub {
850 return $replicated->schema->storage->execute_reliably(sub {
851 return $replicated->schema->txn_do(sub {
852 return $replicated->schema->storage->execute_reliably(sub {
853 ok my $more = $replicated->schema->resultset('Artist')->find(1)
854 => 'found inside crazy deep transactions and execute_reliably';
855 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
860 }) => 'successfully processed transaction';
863 => 'Got expected single result from transaction';
866 ## Test the force_pool resultset attribute.
869 ok my $artist_rs = $replicated->schema->resultset('Artist')
870 => 'got artist resultset';
872 ## Turn on Forced Pool Storage
873 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>'master'})
874 => 'Created a resultset using force_pool storage';
876 ok my $artist = $reliable_artist_rs->find(2)
877 => 'got an artist result via force_pool storage';
879 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
882 ## Test the force_pool resultset attribute part two.
885 ok my $artist_rs = $replicated->schema->resultset('Artist')
886 => 'got artist resultset';
888 ## Turn on Forced Pool Storage
889 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>$replicant_names[0]})
890 => 'Created a resultset using force_pool storage';
892 ok my $artist = $reliable_artist_rs->find(2)
893 => 'got an artist result via force_pool storage';
895 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
897 ## Delete the old database files
898 $replicated->cleanup;