6 local $TODO = 'Temporarily todo-ed for dq2eb';
13 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_replicated')
14 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_replicated');
16 if (DBICTest::RunMode->is_smoker) {
17 my $mver = Moose->VERSION;
18 plan skip_all => "A trial version $mver of Moose detected known to break replication - skipping test known to fail"
19 if ($mver >= 1.99 and $mver <= 1.9902);
26 use List::Util 'first';
27 use Scalar::Util 'reftype';
32 note "Using Moose version $Moose::VERSION and MooseX::Types version $MooseX::Types::VERSION";
34 my $var_dir = quotemeta ( File::Spec->catdir(qw/t var/) );
36 ## Add a connect_info option to test option merging.
37 use DBIx::Class::Storage::DBI::Replicated;
39 package DBIx::Class::Storage::DBI::Replicated;
43 __PACKAGE__->meta->make_mutable;
45 around connect_info => sub {
46 my ($next, $self, $info) = @_;
47 $info->[3]{master_option} = 1;
51 __PACKAGE__->meta->make_immutable;
60 This is a test of the replicated storage system. This will work in one of
61 two ways, either it was try to fake replication with a couple of SQLite DBs
62 and creative use of copy, or if you define a couple of %ENV vars correctly
63 will try to test those. If you do that, it will assume the setup is properly
64 replicating. Your results may vary, but I have demonstrated this to work with
65 mysql native replication.
70 ## ----------------------------------------------------------------------------
71 ## Build a class to hold all our required testing data and methods.
72 ## ----------------------------------------------------------------------------
76 ## --------------------------------------------------------------------- ##
77 ## Create an object to contain your replicated stuff.
78 ## --------------------------------------------------------------------- ##
80 package DBIx::Class::DBI::Replicated::TestReplication;
83 use base qw/Class::Accessor::Fast/;
85 __PACKAGE__->mk_accessors( qw/schema/ );
87 ## Initialize the object
90 my ($class, $schema_method) = (shift, shift);
91 my $self = $class->SUPER::new(@_);
93 $self->schema( $self->init_schema($schema_method) );
97 ## Get the Schema and set the replication storage type
100 #my ($class, $schema_getter) = @_;
101 shift->${\ ( 'get_schema_' . shift ) };
104 sub get_schema_by_storage_type {
105 DBICTest->init_schema(
106 sqlite_use_file => 1,
108 '::DBI::Replicated' => {
109 balancer_type=>'::Random',
111 auto_validate_every=>100,
112 master_read_weight => 1
122 sub get_schema_by_connect_info {
123 DBICTest->init_schema(
124 sqlite_use_file => 1,
125 storage_type=> '::DBI::Replicated',
126 balancer_type=>'::Random',
128 auto_validate_every=>100,
129 master_read_weight => 1
140 sub generate_replicant_connect_info {}
144 ## --------------------------------------------------------------------- ##
145 ## Subclass for when you are using SQLite for testing, this provides a fake
146 ## replication support.
147 ## --------------------------------------------------------------------- ##
149 package DBIx::Class::DBI::Replicated::TestReplication::SQLite;
153 use base 'DBIx::Class::DBI::Replicated::TestReplication';
155 __PACKAGE__->mk_accessors(qw/master_path slave_paths/);
157 ## Set the master path from DBICTest
160 my $class = shift @_;
161 my $self = $class->SUPER::new(@_);
163 $self->master_path( DBICTest->_sqlite_dbfilename );
165 File::Spec->catfile(qw/t var DBIxClass_slave1.db/),
166 File::Spec->catfile(qw/t var DBIxClass_slave2.db/),
172 ## Return an Array of ArrayRefs where each ArrayRef is suitable to use for
173 ## $storage->connect_info to be used for connecting replicants.
175 sub generate_replicant_connect_info {
179 } @{$self->slave_paths};
181 my @connect_infos = map { [$_,'','',{AutoCommit=>1}] } @dsn;
183 ## Make sure nothing is left over from a failed test
187 my $c = $connect_infos[0];
188 $connect_infos[0] = {
198 ## Do a 'good enough' replication by copying the master dbfile over each of
199 ## the slave dbfiles. If the master is SQLite we do this, otherwise we
200 ## just do a one second pause to let the slaves catch up.
204 foreach my $slave (@{$self->slave_paths}) {
205 copy($self->master_path, $slave);
209 ## Cleanup after ourselves. Unlink all gthe slave paths.
213 foreach my $slave (@{$self->slave_paths}) {
220 ## --------------------------------------------------------------------- ##
221 ## Subclass for when you are setting the databases via custom export vars
222 ## This is for when you have a replicating database setup that you are
223 ## going to test against. You'll need to define the correct $ENV and have
224 ## two slave databases to test against, as well as a replication system
225 ## that will replicate in less than 1 second.
226 ## --------------------------------------------------------------------- ##
228 package DBIx::Class::DBI::Replicated::TestReplication::Custom;
229 use base 'DBIx::Class::DBI::Replicated::TestReplication';
231 ## Return an Array of ArrayRefs where each ArrayRef is suitable to use for
232 ## $storage->connect_info to be used for connecting replicants.
234 sub generate_replicant_connect_info {
236 [$ENV{"DBICTEST_SLAVE0_DSN"}, $ENV{"DBICTEST_SLAVE0_DBUSER"}, $ENV{"DBICTEST_SLAVE0_DBPASS"}, {AutoCommit => 1}],
237 [$ENV{"DBICTEST_SLAVE1_DSN"}, $ENV{"DBICTEST_SLAVE1_DBUSER"}, $ENV{"DBICTEST_SLAVE1_DBPASS"}, {AutoCommit => 1}],
241 ## pause a bit to let the replication catch up
248 ## ----------------------------------------------------------------------------
249 ## Create an object and run some tests
250 ## ----------------------------------------------------------------------------
252 ## Thi first bunch of tests are basic, just make sure all the bits are behaving
254 my $replicated_class = DBICTest->has_custom_dsn ?
255 'DBIx::Class::DBI::Replicated::TestReplication::Custom' :
256 'DBIx::Class::DBI::Replicated::TestReplication::SQLite';
260 for my $method (qw/by_connect_info by_storage_type/) {
262 ok $replicated = $replicated_class->new($method)
263 => "Created a replication object $method";
265 isa_ok $replicated->schema
266 => 'DBIx::Class::Schema';
268 isa_ok $replicated->schema->storage
269 => 'DBIx::Class::Storage::DBI::Replicated';
271 isa_ok $replicated->schema->storage->balancer
272 => 'DBIx::Class::Storage::DBI::Replicated::Balancer::Random'
273 => 'configured balancer_type';
276 ### check that all Storage::DBI methods are handled by ::Replicated
278 my @storage_dbi_methods = Class::MOP::Class
279 ->initialize('DBIx::Class::Storage::DBI')->get_all_method_names;
281 my @replicated_methods = DBIx::Class::Storage::DBI::Replicated->meta
282 ->get_all_method_names;
284 # remove constants and OTHER_CRAP
285 @storage_dbi_methods = grep !/^[A-Z_]+\z/, @storage_dbi_methods;
287 # remove CAG accessors
288 @storage_dbi_methods = grep !/_accessor\z/, @storage_dbi_methods;
290 # remove DBIx::Class (the root parent, with CAG and stuff) methods
291 my @root_methods = Class::MOP::Class->initialize('DBIx::Class')
292 ->get_all_method_names;
294 $count{$_}++ for (@storage_dbi_methods, @root_methods);
296 @storage_dbi_methods = grep $count{$_} != 2, @storage_dbi_methods;
299 my %storage_dbi_methods;
300 @storage_dbi_methods{@storage_dbi_methods} = ();
301 my %replicated_methods;
302 @replicated_methods{@replicated_methods} = ();
304 # remove ::Replicated-specific methods
305 for my $method (@replicated_methods) {
306 delete $replicated_methods{$method}
307 unless exists $storage_dbi_methods{$method};
309 @replicated_methods = keys %replicated_methods;
311 # check that what's left is implemented
313 $count{$_}++ for (@storage_dbi_methods, @replicated_methods);
315 if ((grep $count{$_} == 2, @storage_dbi_methods) == @storage_dbi_methods) {
316 pass 'all DBIx::Class::Storage::DBI methods implemented';
319 my @unimplemented = grep $count{$_} == 1, @storage_dbi_methods;
321 fail 'the following DBIx::Class::Storage::DBI methods are unimplemented: '
326 ok $replicated->schema->storage->meta
327 => 'has a meta object';
329 isa_ok $replicated->schema->storage->master
330 => 'DBIx::Class::Storage::DBI';
332 isa_ok $replicated->schema->storage->pool
333 => 'DBIx::Class::Storage::DBI::Replicated::Pool';
335 does_ok $replicated->schema->storage->balancer
336 => 'DBIx::Class::Storage::DBI::Replicated::Balancer';
338 ok my @replicant_connects = $replicated->generate_replicant_connect_info
339 => 'got replication connect information';
341 ok my @replicated_storages = $replicated->schema->storage->connect_replicants(@replicant_connects)
342 => 'Created some storages suitable for replicants';
345 $replicated->schema->storage->debug(1);
346 $replicated->schema->storage->debugcb(sub {
347 my ($op, $info) = @_;
348 ##warn "\n$op, $info\n";
352 dsn => ($info=~m/\[(.+)\]/)[0],
353 storage_type => $info=~m/REPLICANT/ ? 'REPLICANT' : 'MASTER',
357 ok my @all_storages = $replicated->schema->storage->all_storages
360 is scalar @all_storages,
362 => 'correct number of ->all_storages';
364 is ((grep $_->isa('DBIx::Class::Storage::DBI'), @all_storages),
366 => '->all_storages are correct type');
368 my @all_storage_opts =
369 grep { (reftype($_)||'') eq 'HASH' }
370 map @{ $_->_connect_info }, @all_storages;
372 is ((grep $_->{master_option}, @all_storage_opts),
374 => 'connect_info was merged from master to replicants');
376 my @replicant_names = keys %{ $replicated->schema->storage->replicants };
378 ok @replicant_names, "found replicant names @replicant_names";
380 ## Silence warning about not supporting the is_replicating method if using the
382 $replicated->schema->storage->debugobj->silence(1)
383 if first { $_ =~ /$var_dir/ } @replicant_names;
385 isa_ok $replicated->schema->storage->balancer->current_replicant
386 => 'DBIx::Class::Storage::DBI';
388 $replicated->schema->storage->debugobj->silence(0);
390 ok $replicated->schema->storage->pool->has_replicants
391 => 'does have replicants';
393 is $replicated->schema->storage->pool->num_replicants => 2
394 => 'has two replicants';
396 does_ok $replicated_storages[0]
397 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
399 does_ok $replicated_storages[1]
400 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
402 does_ok $replicated->schema->storage->replicants->{$replicant_names[0]}
403 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
405 does_ok $replicated->schema->storage->replicants->{$replicant_names[1]}
406 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
408 ## Add some info to the database
412 ->populate('Artist', [
413 [ qw/artistid name/ ],
414 [ 4, "Ozric Tentacles"],
417 is $debug{storage_type}, 'MASTER',
418 "got last query from a master: $debug{dsn}";
420 like $debug{info}, qr/INSERT/, 'Last was an insert';
422 ## Make sure all the slaves have the table definitions
424 $replicated->replicate;
425 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
426 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
428 ## Silence warning about not supporting the is_replicating method if using the
430 $replicated->schema->storage->debugobj->silence(1)
431 if first { $_ =~ /$var_dir/ } @replicant_names;
433 $replicated->schema->storage->pool->validate_replicants;
435 $replicated->schema->storage->debugobj->silence(0);
437 ## Make sure we can read the data.
439 ok my $artist1 = $replicated->schema->resultset('Artist')->find(4)
442 ## We removed testing here since master read weight is on, so we can't tell in
443 ## advance what storage to expect. We turn master read weight off a bit lower
444 ## is $debug{storage_type}, 'REPLICANT'
445 ## => "got last query from a replicant: $debug{dsn}, $debug{info}";
448 => 'DBICTest::Artist';
450 is $artist1->name, 'Ozric Tentacles'
451 => 'Found expected name for first result';
453 ## Check that master_read_weight is honored
455 no warnings qw/once redefine/;
458 *DBIx::Class::Storage::DBI::Replicated::Balancer::Random::_random_number =
461 $replicated->schema->storage->balancer->increment_storage;
463 is $replicated->schema->storage->balancer->current_replicant,
464 $replicated->schema->storage->master
465 => 'master_read_weight is honored';
467 ## turn it off for the duration of the test
468 $replicated->schema->storage->balancer->master_read_weight(0);
469 $replicated->schema->storage->balancer->increment_storage;
472 ## Add some new rows that only the master will have This is because
473 ## we overload any type of write operation so that is must hit the master
478 ->populate('Artist', [
479 [ qw/artistid name/ ],
480 [ 5, "Doom's Children"],
481 [ 6, "Dead On Arrival"],
485 is $debug{storage_type}, 'MASTER',
486 "got last query from a master: $debug{dsn}";
488 like $debug{info}, qr/INSERT/, 'Last was an insert';
490 ## Make sure all the slaves have the table definitions
491 $replicated->replicate;
493 ## Should find some data now
495 ok my $artist2 = $replicated->schema->resultset('Artist')->find(5)
498 is $debug{storage_type}, 'REPLICANT'
499 => "got last query from a replicant: $debug{dsn}";
502 => 'DBICTest::Artist';
504 is $artist2->name, "Doom's Children"
505 => 'Found expected name for first result';
507 ## What happens when we disconnect all the replicants?
509 is $replicated->schema->storage->pool->connected_replicants => 2
510 => "both replicants are connected";
512 $replicated->schema->storage->replicants->{$replicant_names[0]}->disconnect;
513 $replicated->schema->storage->replicants->{$replicant_names[1]}->disconnect;
515 is $replicated->schema->storage->pool->connected_replicants => 0
516 => "both replicants are now disconnected";
518 ## All these should pass, since the database should automatically reconnect
520 ok my $artist3 = $replicated->schema->resultset('Artist')->find(6)
521 => 'Still finding stuff.';
523 is $debug{storage_type}, 'REPLICANT'
524 => "got last query from a replicant: $debug{dsn}";
527 => 'DBICTest::Artist';
529 is $artist3->name, "Dead On Arrival"
530 => 'Found expected name for first result';
532 is $replicated->schema->storage->pool->connected_replicants => 1
533 => "At Least One replicant reconnected to handle the job";
535 ## What happens when we try to select something that doesn't exist?
537 ok ! $replicated->schema->resultset('Artist')->find(666)
538 => 'Correctly failed to find something.';
540 is $debug{storage_type}, 'REPLICANT'
541 => "got last query from a replicant: $debug{dsn}";
543 ## test the reliable option
547 $replicated->schema->storage->set_reliable_storage;
549 ok $replicated->schema->resultset('Artist')->find(2)
550 => 'Read from master 1';
552 is $debug{storage_type}, 'MASTER',
553 "got last query from a master: $debug{dsn}";
555 ok $replicated->schema->resultset('Artist')->find(5)
556 => 'Read from master 2';
558 is $debug{storage_type}, 'MASTER',
559 "got last query from a master: $debug{dsn}";
561 $replicated->schema->storage->set_balanced_storage;
563 ok $replicated->schema->resultset('Artist')->find(3)
564 => 'Read from replicant';
566 is $debug{storage_type}, 'REPLICANT',
567 "got last query from a replicant: $debug{dsn}";
570 ## Make sure when reliable goes out of scope, we are using replicants again
572 ok $replicated->schema->resultset('Artist')->find(1)
573 => 'back to replicant 1.';
575 is $debug{storage_type}, 'REPLICANT',
576 "got last query from a replicant: $debug{dsn}";
578 ok $replicated->schema->resultset('Artist')->find(2)
579 => 'back to replicant 2.';
581 is $debug{storage_type}, 'REPLICANT',
582 "got last query from a replicant: $debug{dsn}";
584 ## set all the replicants to inactive, and make sure the balancer falls back to
587 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
588 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
591 ## catch the fallback to master warning
592 open my $debugfh, '>', \my $fallback_warning;
593 my $oldfh = $replicated->schema->storage->debugfh;
594 $replicated->schema->storage->debugfh($debugfh);
596 ok $replicated->schema->resultset('Artist')->find(2)
597 => 'Fallback to master';
599 is $debug{storage_type}, 'MASTER',
600 "got last query from a master: $debug{dsn}";
602 like $fallback_warning, qr/falling back to master/
603 => 'emits falling back to master debug';
605 $replicated->schema->storage->debugfh($oldfh);
608 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
609 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
611 ## Silence warning about not supporting the is_replicating method if using the
613 $replicated->schema->storage->debugobj->silence(1)
614 if first { $_ =~ /$var_dir/ } @replicant_names;
616 $replicated->schema->storage->pool->validate_replicants;
618 $replicated->schema->storage->debugobj->silence(0);
621 ## catch the fallback to master warning
622 open my $debugfh, '>', \my $return_warning;
623 my $oldfh = $replicated->schema->storage->debugfh;
624 $replicated->schema->storage->debugfh($debugfh);
626 ok $replicated->schema->resultset('Artist')->find(2)
627 => 'Return to replicants';
629 is $debug{storage_type}, 'REPLICANT',
630 "got last query from a replicant: $debug{dsn}";
632 like $return_warning, qr/Moved back to slave/
633 => 'emits returning to slave debug';
635 $replicated->schema->storage->debugfh($oldfh);
638 ## Getting slave status tests
641 ## We skip this tests unless you have a custom replicants, since the default
642 ## sqlite based replication tests don't support these functions.
644 skip 'Cannot Test Replicant Status on Non Replicating Database', 10
645 unless DBICTest->has_custom_dsn && $ENV{"DBICTEST_SLAVE0_DSN"};
647 $replicated->replicate; ## Give the slaves a chance to catchup.
649 ok $replicated->schema->storage->replicants->{$replicant_names[0]}->is_replicating
650 => 'Replicants are replicating';
652 is $replicated->schema->storage->replicants->{$replicant_names[0]}->lag_behind_master, 0
653 => 'Replicant is zero seconds behind master';
655 ## Test the validate replicants
657 $replicated->schema->storage->pool->validate_replicants;
659 is $replicated->schema->storage->pool->active_replicants, 2
660 => 'Still have 2 replicants after validation';
662 ## Force the replicants to fail the validate test by required their lag to
663 ## be negative (ie ahead of the master!)
665 $replicated->schema->storage->pool->maximum_lag(-10);
666 $replicated->schema->storage->pool->validate_replicants;
668 is $replicated->schema->storage->pool->active_replicants, 0
669 => 'No way a replicant be be ahead of the master';
671 ## Let's be fair to the replicants again. Let them lag up to 5
673 $replicated->schema->storage->pool->maximum_lag(5);
674 $replicated->schema->storage->pool->validate_replicants;
676 is $replicated->schema->storage->pool->active_replicants, 2
677 => 'Both replicants in good standing again';
679 ## Check auto validate
681 is $replicated->schema->storage->balancer->auto_validate_every, 100
682 => "Got the expected value for auto validate";
684 ## This will make sure we auto validatge everytime
685 $replicated->schema->storage->balancer->auto_validate_every(0);
687 ## set all the replicants to inactive, and make sure the balancer falls back to
690 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
691 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
693 ## Ok, now when we go to run a query, autovalidate SHOULD reconnect
695 is $replicated->schema->storage->pool->active_replicants => 0
696 => "both replicants turned off";
698 ok $replicated->schema->resultset('Artist')->find(5)
699 => 'replicant reactivated';
701 is $debug{storage_type}, 'REPLICANT',
702 "got last query from a replicant: $debug{dsn}";
704 is $replicated->schema->storage->pool->active_replicants => 2
705 => "both replicants reactivated";
708 ## Test the reliably callback
710 ok my $reliably = sub {
712 ok $replicated->schema->resultset('Artist')->find(5)
713 => 'replicant reactivated';
715 is $debug{storage_type}, 'MASTER',
716 "got last query from a master: $debug{dsn}";
718 } => 'created coderef properly';
720 $replicated->schema->storage->execute_reliably($reliably);
722 ## Try something with an error
724 ok my $unreliably = sub {
726 ok $replicated->schema->resultset('ArtistXX')->find(5)
727 => 'replicant reactivated';
729 } => 'created coderef properly';
731 throws_ok {$replicated->schema->storage->execute_reliably($unreliably)}
732 qr/Can't find source for ArtistXX/
733 => 'Bad coderef throws proper error';
735 ## Make sure replication came back
737 ok $replicated->schema->resultset('Artist')->find(3)
738 => 'replicant reactivated';
740 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
742 ## make sure transactions are set to execute_reliably
744 ok my $transaction = sub {
750 ->populate('Artist', [
751 [ qw/artistid name/ ],
752 [ $id, "Children of the Grave $id"],
755 ok my $result = $replicated->schema->resultset('Artist')->find($id)
756 => "Found expected artist for $id";
758 is $debug{storage_type}, 'MASTER',
759 "got last query from a master: $debug{dsn}";
761 ok my $more = $replicated->schema->resultset('Artist')->find(1)
762 => 'Found expected artist again for 1';
764 is $debug{storage_type}, 'MASTER',
765 "got last query from a master: $debug{dsn}";
767 return ($result, $more);
769 } => 'Created a coderef properly';
771 ## Test the transaction with multi return
773 ok my @return = $replicated->schema->txn_do($transaction, 666)
774 => 'did transaction';
776 is $return[0]->id, 666
777 => 'first returned value is correct';
779 is $debug{storage_type}, 'MASTER',
780 "got last query from a master: $debug{dsn}";
783 => 'second returned value is correct';
785 is $debug{storage_type}, 'MASTER',
786 "got last query from a master: $debug{dsn}";
790 ## Test that asking for single return works
792 ok my @return = $replicated->schema->txn_do($transaction, 777)
793 => 'did transaction';
795 is $return[0]->id, 777
796 => 'first returned value is correct';
799 => 'second returned value is correct';
802 ## Test transaction returning a single value
805 ok my $result = $replicated->schema->txn_do(sub {
806 ok my $more = $replicated->schema->resultset('Artist')->find(1)
807 => 'found inside a transaction';
808 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
810 }) => 'successfully processed transaction';
813 => 'Got expected single result from transaction';
816 ## Make sure replication came back
818 ok $replicated->schema->resultset('Artist')->find(1)
819 => 'replicant reactivated';
821 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
823 ## Test Discard changes
826 ok my $artist = $replicated->schema->resultset('Artist')->find(2)
827 => 'got an artist to test discard changes';
829 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
831 ok $artist->get_from_storage({force_pool=>'master'})
832 => 'properly discard changes';
834 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
836 ok $artist->discard_changes({force_pool=>'master'})
837 => 'properly called discard_changes against master (manual attrs)';
839 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
841 ok $artist->discard_changes()
842 => 'properly called discard_changes against master (default attrs)';
844 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
846 ok $artist->discard_changes({force_pool=>$replicant_names[0]})
847 => 'properly able to override the default attributes';
849 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}"
852 ## Test some edge cases, like trying to do a transaction inside a transaction, etc
855 ok my $result = $replicated->schema->txn_do(sub {
856 return $replicated->schema->txn_do(sub {
857 ok my $more = $replicated->schema->resultset('Artist')->find(1)
858 => 'found inside a transaction inside a transaction';
859 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
862 }) => 'successfully processed transaction';
865 => 'Got expected single result from transaction';
869 ok my $result = $replicated->schema->txn_do(sub {
870 return $replicated->schema->storage->execute_reliably(sub {
871 return $replicated->schema->txn_do(sub {
872 return $replicated->schema->storage->execute_reliably(sub {
873 ok my $more = $replicated->schema->resultset('Artist')->find(1)
874 => 'found inside crazy deep transactions and execute_reliably';
875 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
880 }) => 'successfully processed transaction';
883 => 'Got expected single result from transaction';
886 ## Test the force_pool resultset attribute.
889 ok my $artist_rs = $replicated->schema->resultset('Artist')
890 => 'got artist resultset';
892 ## Turn on Forced Pool Storage
893 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>'master'})
894 => 'Created a resultset using force_pool storage';
896 ok my $artist = $reliable_artist_rs->find(2)
897 => 'got an artist result via force_pool storage';
899 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
902 ## Test the force_pool resultset attribute part two.
905 ok my $artist_rs = $replicated->schema->resultset('Artist')
906 => 'got artist resultset';
908 ## Turn on Forced Pool Storage
909 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>$replicant_names[0]})
910 => 'Created a resultset using force_pool storage';
912 ok my $artist = $reliable_artist_rs->find(2)
913 => 'got an artist result via force_pool storage';
915 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
917 ## Delete the old database files
918 $replicated->cleanup;