11 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_replicated')
12 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_replicated');
14 if (DBICTest::RunMode->is_smoker) {
15 my $mver = Moose->VERSION;
16 plan skip_all => "A trial version $mver of Moose detected known to break replication - skipping test known to fail"
17 if ($mver >= 1.99 and $mver <= 1.9902);
24 use List::Util 'first';
25 use Scalar::Util 'reftype';
29 note "Using Moose version $Moose::VERSION and MooseX::Types version $MooseX::Types::VERSION";
31 my $var_dir = quotemeta ( File::Spec->catdir(qw/t var/) );
33 ## Add a connect_info option to test option merging.
34 use DBIx::Class::Storage::DBI::Replicated;
36 package DBIx::Class::Storage::DBI::Replicated;
40 __PACKAGE__->meta->make_mutable;
42 around connect_info => sub {
43 my ($next, $self, $info) = @_;
44 $info->[3]{master_option} = 1;
48 __PACKAGE__->meta->make_immutable;
57 This is a test of the replicated storage system. This will work in one of
58 two ways, either it was try to fake replication with a couple of SQLite DBs
59 and creative use of copy, or if you define a couple of %ENV vars correctly
60 will try to test those. If you do that, it will assume the setup is properly
61 replicating. Your results may vary, but I have demonstrated this to work with
62 mysql native replication.
67 ## ----------------------------------------------------------------------------
68 ## Build a class to hold all our required testing data and methods.
69 ## ----------------------------------------------------------------------------
73 ## --------------------------------------------------------------------- ##
74 ## Create an object to contain your replicated stuff.
75 ## --------------------------------------------------------------------- ##
77 package DBIx::Class::DBI::Replicated::TestReplication;
80 use base qw/Class::Accessor::Fast/;
82 __PACKAGE__->mk_accessors( qw/schema/ );
84 ## Initialize the object
87 my ($class, $schema_method) = (shift, shift);
88 my $self = $class->SUPER::new(@_);
90 $self->schema( $self->init_schema($schema_method) );
94 ## Get the Schema and set the replication storage type
97 #my ($class, $schema_getter) = @_;
98 shift->${\ ( 'get_schema_' . shift ) };
101 sub get_schema_by_storage_type {
102 DBICTest->init_schema(
103 sqlite_use_file => 1,
105 '::DBI::Replicated' => {
106 balancer_type=>'::Random',
108 auto_validate_every=>100,
109 master_read_weight => 1
119 sub get_schema_by_connect_info {
120 DBICTest->init_schema(
121 sqlite_use_file => 1,
122 storage_type=> '::DBI::Replicated',
123 balancer_type=>'::Random',
125 auto_validate_every=>100,
126 master_read_weight => 1
137 sub generate_replicant_connect_info {}
141 ## --------------------------------------------------------------------- ##
142 ## Subclass for when you are using SQLite for testing, this provides a fake
143 ## replication support.
144 ## --------------------------------------------------------------------- ##
146 package DBIx::Class::DBI::Replicated::TestReplication::SQLite;
150 use base 'DBIx::Class::DBI::Replicated::TestReplication';
152 __PACKAGE__->mk_accessors(qw/master_path slave_paths/);
154 ## Set the master path from DBICTest
157 my $class = shift @_;
158 my $self = $class->SUPER::new(@_);
160 $self->master_path( DBICTest->_sqlite_dbfilename );
162 File::Spec->catfile(qw/t var DBIxClass_slave1.db/),
163 File::Spec->catfile(qw/t var DBIxClass_slave2.db/),
169 ## Return an Array of ArrayRefs where each ArrayRef is suitable to use for
170 ## $storage->connect_info to be used for connecting replicants.
172 sub generate_replicant_connect_info {
176 } @{$self->slave_paths};
178 my @connect_infos = map { [$_,'','',{AutoCommit=>1}] } @dsn;
180 ## Make sure nothing is left over from a failed test
184 my $c = $connect_infos[0];
185 $connect_infos[0] = {
195 ## Do a 'good enough' replication by copying the master dbfile over each of
196 ## the slave dbfiles. If the master is SQLite we do this, otherwise we
197 ## just do a one second pause to let the slaves catch up.
201 foreach my $slave (@{$self->slave_paths}) {
202 copy($self->master_path, $slave);
206 ## Cleanup after ourselves. Unlink all the slave paths.
210 $_->disconnect for values %{ $self->schema->storage->replicants };
211 foreach my $slave (@{$self->slave_paths}) {
218 ## --------------------------------------------------------------------- ##
219 ## Subclass for when you are setting the databases via custom export vars
220 ## This is for when you have a replicating database setup that you are
221 ## going to test against. You'll need to define the correct $ENV and have
222 ## two slave databases to test against, as well as a replication system
223 ## that will replicate in less than 1 second.
224 ## --------------------------------------------------------------------- ##
226 package DBIx::Class::DBI::Replicated::TestReplication::Custom;
227 use base 'DBIx::Class::DBI::Replicated::TestReplication';
229 ## Return an Array of ArrayRefs where each ArrayRef is suitable to use for
230 ## $storage->connect_info to be used for connecting replicants.
232 sub generate_replicant_connect_info {
234 [$ENV{"DBICTEST_SLAVE0_DSN"}, $ENV{"DBICTEST_SLAVE0_DBUSER"}, $ENV{"DBICTEST_SLAVE0_DBPASS"}, {AutoCommit => 1}],
235 [$ENV{"DBICTEST_SLAVE1_DSN"}, $ENV{"DBICTEST_SLAVE1_DBUSER"}, $ENV{"DBICTEST_SLAVE1_DBPASS"}, {AutoCommit => 1}],
239 ## pause a bit to let the replication catch up
246 ## ----------------------------------------------------------------------------
247 ## Create an object and run some tests
248 ## ----------------------------------------------------------------------------
250 ## Thi first bunch of tests are basic, just make sure all the bits are behaving
252 my $replicated_class = DBICTest->has_custom_dsn ?
253 'DBIx::Class::DBI::Replicated::TestReplication::Custom' :
254 'DBIx::Class::DBI::Replicated::TestReplication::SQLite';
258 for my $method (qw/by_connect_info by_storage_type/) {
260 ok $replicated = $replicated_class->new($method)
261 => "Created a replication object $method";
263 isa_ok $replicated->schema
264 => 'DBIx::Class::Schema';
266 isa_ok $replicated->schema->storage
267 => 'DBIx::Class::Storage::DBI::Replicated';
269 isa_ok $replicated->schema->storage->balancer
270 => 'DBIx::Class::Storage::DBI::Replicated::Balancer::Random'
271 => 'configured balancer_type';
274 ### check that all Storage::DBI methods are handled by ::Replicated
276 my @storage_dbi_methods = Class::MOP::Class
277 ->initialize('DBIx::Class::Storage::DBI')->get_all_method_names;
279 my @replicated_methods = DBIx::Class::Storage::DBI::Replicated->meta
280 ->get_all_method_names;
282 # remove constants and OTHER_CRAP
283 @storage_dbi_methods = grep !/^[A-Z_]+\z/, @storage_dbi_methods;
285 # remove CAG accessors
286 @storage_dbi_methods = grep !/_accessor\z/, @storage_dbi_methods;
288 # remove DBIx::Class (the root parent, with CAG and stuff) methods
289 my @root_methods = Class::MOP::Class->initialize('DBIx::Class')
290 ->get_all_method_names;
292 $count{$_}++ for (@storage_dbi_methods, @root_methods);
294 @storage_dbi_methods = grep $count{$_} != 2, @storage_dbi_methods;
297 my %storage_dbi_methods;
298 @storage_dbi_methods{@storage_dbi_methods} = ();
299 my %replicated_methods;
300 @replicated_methods{@replicated_methods} = ();
302 # remove ::Replicated-specific methods
303 for my $method (@replicated_methods) {
304 delete $replicated_methods{$method}
305 unless exists $storage_dbi_methods{$method};
307 @replicated_methods = keys %replicated_methods;
309 # check that what's left is implemented
311 $count{$_}++ for (@storage_dbi_methods, @replicated_methods);
313 if ((grep $count{$_} == 2, @storage_dbi_methods) == @storage_dbi_methods) {
314 pass 'all DBIx::Class::Storage::DBI methods implemented';
317 my @unimplemented = grep $count{$_} == 1, @storage_dbi_methods;
319 fail 'the following DBIx::Class::Storage::DBI methods are unimplemented: '
324 ok $replicated->schema->storage->meta
325 => 'has a meta object';
327 isa_ok $replicated->schema->storage->master
328 => 'DBIx::Class::Storage::DBI';
330 isa_ok $replicated->schema->storage->pool
331 => 'DBIx::Class::Storage::DBI::Replicated::Pool';
333 does_ok $replicated->schema->storage->balancer
334 => 'DBIx::Class::Storage::DBI::Replicated::Balancer';
336 ok my @replicant_connects = $replicated->generate_replicant_connect_info
337 => 'got replication connect information';
339 ok my @replicated_storages = $replicated->schema->storage->connect_replicants(@replicant_connects)
340 => 'Created some storages suitable for replicants';
343 $replicated->schema->storage->debug(1);
344 $replicated->schema->storage->debugcb(sub {
345 my ($op, $info) = @_;
346 ##warn "\n$op, $info\n";
350 dsn => ($info=~m/\[(.+)\]/)[0],
351 storage_type => $info=~m/REPLICANT/ ? 'REPLICANT' : 'MASTER',
355 ok my @all_storages = $replicated->schema->storage->all_storages
358 is scalar @all_storages,
360 => 'correct number of ->all_storages';
362 is ((grep $_->isa('DBIx::Class::Storage::DBI'), @all_storages),
364 => '->all_storages are correct type');
366 my @all_storage_opts =
367 grep { (reftype($_)||'') eq 'HASH' }
368 map @{ $_->_connect_info }, @all_storages;
370 is ((grep $_->{master_option}, @all_storage_opts),
372 => 'connect_info was merged from master to replicants');
374 my @replicant_names = keys %{ $replicated->schema->storage->replicants };
376 ok @replicant_names, "found replicant names @replicant_names";
378 ## Silence warning about not supporting the is_replicating method if using the
380 $replicated->schema->storage->debugobj->silence(1)
381 if first { $_ =~ /$var_dir/ } @replicant_names;
383 isa_ok $replicated->schema->storage->balancer->current_replicant
384 => 'DBIx::Class::Storage::DBI';
386 $replicated->schema->storage->debugobj->silence(0);
388 ok $replicated->schema->storage->pool->has_replicants
389 => 'does have replicants';
391 is $replicated->schema->storage->pool->num_replicants => 2
392 => 'has two replicants';
394 does_ok $replicated_storages[0]
395 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
397 does_ok $replicated_storages[1]
398 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
400 does_ok $replicated->schema->storage->replicants->{$replicant_names[0]}
401 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
403 does_ok $replicated->schema->storage->replicants->{$replicant_names[1]}
404 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
406 ## Add some info to the database
410 ->populate('Artist', [
411 [ qw/artistid name/ ],
412 [ 4, "Ozric Tentacles"],
415 is $debug{storage_type}, 'MASTER',
416 "got last query from a master: $debug{dsn}";
418 like $debug{info}, qr/INSERT/, 'Last was an insert';
420 ## Make sure all the slaves have the table definitions
422 $replicated->replicate;
423 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
424 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
426 ## Silence warning about not supporting the is_replicating method if using the
428 $replicated->schema->storage->debugobj->silence(1)
429 if first { $_ =~ /$var_dir/ } @replicant_names;
431 $replicated->schema->storage->pool->validate_replicants;
433 $replicated->schema->storage->debugobj->silence(0);
435 ## Make sure we can read the data.
437 ok my $artist1 = $replicated->schema->resultset('Artist')->find(4)
440 ## We removed testing here since master read weight is on, so we can't tell in
441 ## advance what storage to expect. We turn master read weight off a bit lower
442 ## is $debug{storage_type}, 'REPLICANT'
443 ## => "got last query from a replicant: $debug{dsn}, $debug{info}";
446 => 'DBICTest::Artist';
448 is $artist1->name, 'Ozric Tentacles'
449 => 'Found expected name for first result';
451 ## Check that master_read_weight is honored
453 no warnings qw/once redefine/;
456 *DBIx::Class::Storage::DBI::Replicated::Balancer::Random::_random_number =
459 $replicated->schema->storage->balancer->increment_storage;
461 is $replicated->schema->storage->balancer->current_replicant,
462 $replicated->schema->storage->master
463 => 'master_read_weight is honored';
465 ## turn it off for the duration of the test
466 $replicated->schema->storage->balancer->master_read_weight(0);
467 $replicated->schema->storage->balancer->increment_storage;
470 ## Add some new rows that only the master will have This is because
471 ## we overload any type of write operation so that is must hit the master
476 ->populate('Artist', [
477 [ qw/artistid name/ ],
478 [ 5, "Doom's Children"],
479 [ 6, "Dead On Arrival"],
483 is $debug{storage_type}, 'MASTER',
484 "got last query from a master: $debug{dsn}";
486 like $debug{info}, qr/INSERT/, 'Last was an insert';
488 ## Make sure all the slaves have the table definitions
489 $replicated->replicate;
491 ## Should find some data now
493 ok my $artist2 = $replicated->schema->resultset('Artist')->find(5)
496 is $debug{storage_type}, 'REPLICANT'
497 => "got last query from a replicant: $debug{dsn}";
500 => 'DBICTest::Artist';
502 is $artist2->name, "Doom's Children"
503 => 'Found expected name for first result';
505 ## What happens when we disconnect all the replicants?
507 is $replicated->schema->storage->pool->connected_replicants => 2
508 => "both replicants are connected";
510 $replicated->schema->storage->replicants->{$replicant_names[0]}->disconnect;
511 $replicated->schema->storage->replicants->{$replicant_names[1]}->disconnect;
513 is $replicated->schema->storage->pool->connected_replicants => 0
514 => "both replicants are now disconnected";
516 ## All these should pass, since the database should automatically reconnect
518 ok my $artist3 = $replicated->schema->resultset('Artist')->find(6)
519 => 'Still finding stuff.';
521 is $debug{storage_type}, 'REPLICANT'
522 => "got last query from a replicant: $debug{dsn}";
525 => 'DBICTest::Artist';
527 is $artist3->name, "Dead On Arrival"
528 => 'Found expected name for first result';
530 is $replicated->schema->storage->pool->connected_replicants => 1
531 => "At Least One replicant reconnected to handle the job";
533 ## What happens when we try to select something that doesn't exist?
535 ok ! $replicated->schema->resultset('Artist')->find(666)
536 => 'Correctly failed to find something.';
538 is $debug{storage_type}, 'REPLICANT'
539 => "got last query from a replicant: $debug{dsn}";
541 ## test the reliable option
545 $replicated->schema->storage->set_reliable_storage;
547 ok $replicated->schema->resultset('Artist')->find(2)
548 => 'Read from master 1';
550 is $debug{storage_type}, 'MASTER',
551 "got last query from a master: $debug{dsn}";
553 ok $replicated->schema->resultset('Artist')->find(5)
554 => 'Read from master 2';
556 is $debug{storage_type}, 'MASTER',
557 "got last query from a master: $debug{dsn}";
559 $replicated->schema->storage->set_balanced_storage;
561 ok $replicated->schema->resultset('Artist')->find(3)
562 => 'Read from replicant';
564 is $debug{storage_type}, 'REPLICANT',
565 "got last query from a replicant: $debug{dsn}";
568 ## Make sure when reliable goes out of scope, we are using replicants again
570 ok $replicated->schema->resultset('Artist')->find(1)
571 => 'back to replicant 1.';
573 is $debug{storage_type}, 'REPLICANT',
574 "got last query from a replicant: $debug{dsn}";
576 ok $replicated->schema->resultset('Artist')->find(2)
577 => 'back to replicant 2.';
579 is $debug{storage_type}, 'REPLICANT',
580 "got last query from a replicant: $debug{dsn}";
582 ## set all the replicants to inactive, and make sure the balancer falls back to
585 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
586 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
589 ## catch the fallback to master warning
590 open my $debugfh, '>', \my $fallback_warning;
591 my $oldfh = $replicated->schema->storage->debugfh;
592 $replicated->schema->storage->debugfh($debugfh);
594 ok $replicated->schema->resultset('Artist')->find(2)
595 => 'Fallback to master';
597 is $debug{storage_type}, 'MASTER',
598 "got last query from a master: $debug{dsn}";
600 like $fallback_warning, qr/falling back to master/
601 => 'emits falling back to master debug';
603 $replicated->schema->storage->debugfh($oldfh);
606 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
607 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
609 ## Silence warning about not supporting the is_replicating method if using the
611 $replicated->schema->storage->debugobj->silence(1)
612 if first { $_ =~ /$var_dir/ } @replicant_names;
614 $replicated->schema->storage->pool->validate_replicants;
616 $replicated->schema->storage->debugobj->silence(0);
619 ## catch the fallback to master warning
620 open my $debugfh, '>', \my $return_warning;
621 my $oldfh = $replicated->schema->storage->debugfh;
622 $replicated->schema->storage->debugfh($debugfh);
624 ok $replicated->schema->resultset('Artist')->find(2)
625 => 'Return to replicants';
627 is $debug{storage_type}, 'REPLICANT',
628 "got last query from a replicant: $debug{dsn}";
630 like $return_warning, qr/Moved back to slave/
631 => 'emits returning to slave debug';
633 $replicated->schema->storage->debugfh($oldfh);
636 ## Getting slave status tests
639 ## We skip this tests unless you have a custom replicants, since the default
640 ## sqlite based replication tests don't support these functions.
642 skip 'Cannot Test Replicant Status on Non Replicating Database', 10
643 unless DBICTest->has_custom_dsn && $ENV{"DBICTEST_SLAVE0_DSN"};
645 $replicated->replicate; ## Give the slaves a chance to catchup.
647 ok $replicated->schema->storage->replicants->{$replicant_names[0]}->is_replicating
648 => 'Replicants are replicating';
650 is $replicated->schema->storage->replicants->{$replicant_names[0]}->lag_behind_master, 0
651 => 'Replicant is zero seconds behind master';
653 ## Test the validate replicants
655 $replicated->schema->storage->pool->validate_replicants;
657 is $replicated->schema->storage->pool->active_replicants, 2
658 => 'Still have 2 replicants after validation';
660 ## Force the replicants to fail the validate test by required their lag to
661 ## be negative (ie ahead of the master!)
663 $replicated->schema->storage->pool->maximum_lag(-10);
664 $replicated->schema->storage->pool->validate_replicants;
666 is $replicated->schema->storage->pool->active_replicants, 0
667 => 'No way a replicant be be ahead of the master';
669 ## Let's be fair to the replicants again. Let them lag up to 5
671 $replicated->schema->storage->pool->maximum_lag(5);
672 $replicated->schema->storage->pool->validate_replicants;
674 is $replicated->schema->storage->pool->active_replicants, 2
675 => 'Both replicants in good standing again';
677 ## Check auto validate
679 is $replicated->schema->storage->balancer->auto_validate_every, 100
680 => "Got the expected value for auto validate";
682 ## This will make sure we auto validatge everytime
683 $replicated->schema->storage->balancer->auto_validate_every(0);
685 ## set all the replicants to inactive, and make sure the balancer falls back to
688 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
689 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
691 ## Ok, now when we go to run a query, autovalidate SHOULD reconnect
693 is $replicated->schema->storage->pool->active_replicants => 0
694 => "both replicants turned off";
696 ok $replicated->schema->resultset('Artist')->find(5)
697 => 'replicant reactivated';
699 is $debug{storage_type}, 'REPLICANT',
700 "got last query from a replicant: $debug{dsn}";
702 is $replicated->schema->storage->pool->active_replicants => 2
703 => "both replicants reactivated";
706 ## Test the reliably callback
708 ok my $reliably = sub {
710 ok $replicated->schema->resultset('Artist')->find(5)
711 => 'replicant reactivated';
713 is $debug{storage_type}, 'MASTER',
714 "got last query from a master: $debug{dsn}";
716 } => 'created coderef properly';
718 $replicated->schema->storage->execute_reliably($reliably);
720 ## Try something with an error
722 ok my $unreliably = sub {
724 ok $replicated->schema->resultset('ArtistXX')->find(5)
725 => 'replicant reactivated';
727 } => 'created coderef properly';
729 throws_ok {$replicated->schema->storage->execute_reliably($unreliably)}
730 qr/Can't find source for ArtistXX/
731 => 'Bad coderef throws proper error';
733 ## Make sure replication came back
735 ok $replicated->schema->resultset('Artist')->find(3)
736 => 'replicant reactivated';
738 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
740 ## make sure transactions are set to execute_reliably
742 ok my $transaction = sub {
748 ->populate('Artist', [
749 [ qw/artistid name/ ],
750 [ $id, "Children of the Grave $id"],
753 ok my $result = $replicated->schema->resultset('Artist')->find($id)
754 => "Found expected artist for $id";
756 is $debug{storage_type}, 'MASTER',
757 "got last query from a master: $debug{dsn}";
759 ok my $more = $replicated->schema->resultset('Artist')->find(1)
760 => 'Found expected artist again for 1';
762 is $debug{storage_type}, 'MASTER',
763 "got last query from a master: $debug{dsn}";
765 return ($result, $more);
767 } => 'Created a coderef properly';
769 ## Test the transaction with multi return
771 ok my @return = $replicated->schema->txn_do($transaction, 666)
772 => 'did transaction';
774 is $return[0]->id, 666
775 => 'first returned value is correct';
777 is $debug{storage_type}, 'MASTER',
778 "got last query from a master: $debug{dsn}";
781 => 'second returned value is correct';
783 is $debug{storage_type}, 'MASTER',
784 "got last query from a master: $debug{dsn}";
788 ## Test that asking for single return works
790 ok my @return = $replicated->schema->txn_do($transaction, 777)
791 => 'did transaction';
793 is $return[0]->id, 777
794 => 'first returned value is correct';
797 => 'second returned value is correct';
800 ## Test transaction returning a single value
803 ok my $result = $replicated->schema->txn_do(sub {
804 ok my $more = $replicated->schema->resultset('Artist')->find(1)
805 => 'found inside a transaction';
806 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
808 }) => 'successfully processed transaction';
811 => 'Got expected single result from transaction';
814 ## Make sure replication came back
816 ok $replicated->schema->resultset('Artist')->find(1)
817 => 'replicant reactivated';
819 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
821 ## Test Discard changes
824 ok my $artist = $replicated->schema->resultset('Artist')->find(2)
825 => 'got an artist to test discard changes';
827 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
829 ok $artist->get_from_storage({force_pool=>'master'})
830 => 'properly discard changes';
832 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
834 ok $artist->discard_changes({force_pool=>'master'})
835 => 'properly called discard_changes against master (manual attrs)';
837 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
839 ok $artist->discard_changes()
840 => 'properly called discard_changes against master (default attrs)';
842 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
844 ok $artist->discard_changes({force_pool=>$replicant_names[0]})
845 => 'properly able to override the default attributes';
847 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}"
850 ## Test some edge cases, like trying to do a transaction inside a transaction, etc
853 ok my $result = $replicated->schema->txn_do(sub {
854 return $replicated->schema->txn_do(sub {
855 ok my $more = $replicated->schema->resultset('Artist')->find(1)
856 => 'found inside a transaction inside a transaction';
857 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
860 }) => 'successfully processed transaction';
863 => 'Got expected single result from transaction';
867 ok my $result = $replicated->schema->txn_do(sub {
868 return $replicated->schema->storage->execute_reliably(sub {
869 return $replicated->schema->txn_do(sub {
870 return $replicated->schema->storage->execute_reliably(sub {
871 ok my $more = $replicated->schema->resultset('Artist')->find(1)
872 => 'found inside crazy deep transactions and execute_reliably';
873 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
878 }) => 'successfully processed transaction';
881 => 'Got expected single result from transaction';
884 ## Test the force_pool resultset attribute.
887 ok my $artist_rs = $replicated->schema->resultset('Artist')
888 => 'got artist resultset';
890 ## Turn on Forced Pool Storage
891 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>'master'})
892 => 'Created a resultset using force_pool storage';
894 ok my $artist = $reliable_artist_rs->find(2)
895 => 'got an artist result via force_pool storage';
897 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
900 ## Test the force_pool resultset attribute part two.
903 ok my $artist_rs = $replicated->schema->resultset('Artist')
904 => 'got artist resultset';
906 ## Turn on Forced Pool Storage
907 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>$replicant_names[0]})
908 => 'Created a resultset using force_pool storage';
910 ok my $artist = $reliable_artist_rs->find(2)
911 => 'got an artist result via force_pool storage';
913 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
916 ## Delete the old database files
917 $replicated->cleanup;