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';
30 note "Using Moose version $Moose::VERSION and MooseX::Types version $MooseX::Types::VERSION";
32 my $var_dir = quotemeta ( File::Spec->catdir(qw/t var/) );
34 ## Add a connect_info option to test option merging.
35 use DBIx::Class::Storage::DBI::Replicated;
37 package DBIx::Class::Storage::DBI::Replicated;
41 __PACKAGE__->meta->make_mutable;
43 around connect_info => sub {
44 my ($next, $self, $info) = @_;
45 $info->[3]{master_option} = 1;
49 __PACKAGE__->meta->make_immutable;
58 This is a test of the replicated storage system. This will work in one of
59 two ways, either it was try to fake replication with a couple of SQLite DBs
60 and creative use of copy, or if you define a couple of %ENV vars correctly
61 will try to test those. If you do that, it will assume the setup is properly
62 replicating. Your results may vary, but I have demonstrated this to work with
63 mysql native replication.
68 ## ----------------------------------------------------------------------------
69 ## Build a class to hold all our required testing data and methods.
70 ## ----------------------------------------------------------------------------
74 ## --------------------------------------------------------------------- ##
75 ## Create an object to contain your replicated stuff.
76 ## --------------------------------------------------------------------- ##
78 package DBIx::Class::DBI::Replicated::TestReplication;
81 use base qw/Class::Accessor::Fast/;
83 __PACKAGE__->mk_accessors( qw/schema/ );
85 ## Initialize the object
88 my ($class, $schema_method) = (shift, shift);
89 my $self = $class->SUPER::new(@_);
91 $self->schema( $self->init_schema($schema_method) );
95 ## Get the Schema and set the replication storage type
98 #my ($class, $schema_getter) = @_;
99 shift->${\ ( 'get_schema_' . shift ) };
102 sub get_schema_by_storage_type {
103 DBICTest->init_schema(
104 sqlite_use_file => 1,
106 '::DBI::Replicated' => {
107 balancer_type=>'::Random',
109 auto_validate_every=>100,
110 master_read_weight => 1
120 sub get_schema_by_connect_info {
121 DBICTest->init_schema(
122 sqlite_use_file => 1,
123 storage_type=> '::DBI::Replicated',
124 balancer_type=>'::Random',
126 auto_validate_every=>100,
127 master_read_weight => 1
138 sub generate_replicant_connect_info {}
142 ## --------------------------------------------------------------------- ##
143 ## Subclass for when you are using SQLite for testing, this provides a fake
144 ## replication support.
145 ## --------------------------------------------------------------------- ##
147 package DBIx::Class::DBI::Replicated::TestReplication::SQLite;
151 use base 'DBIx::Class::DBI::Replicated::TestReplication';
153 __PACKAGE__->mk_accessors(qw/master_path slave_paths/);
155 ## Set the master path from DBICTest
158 my $class = shift @_;
159 my $self = $class->SUPER::new(@_);
161 $self->master_path( DBICTest->_sqlite_dbfilename );
163 File::Spec->catfile(qw/t var DBIxClass_slave1.db/),
164 File::Spec->catfile(qw/t var DBIxClass_slave2.db/),
170 ## Return an Array of ArrayRefs where each ArrayRef is suitable to use for
171 ## $storage->connect_info to be used for connecting replicants.
173 sub generate_replicant_connect_info {
177 } @{$self->slave_paths};
179 my @connect_infos = map { [$_,'','',{AutoCommit=>1}] } @dsn;
181 ## Make sure nothing is left over from a failed test
185 my $c = $connect_infos[0];
186 $connect_infos[0] = {
196 ## Do a 'good enough' replication by copying the master dbfile over each of
197 ## the slave dbfiles. If the master is SQLite we do this, otherwise we
198 ## just do a one second pause to let the slaves catch up.
202 foreach my $slave (@{$self->slave_paths}) {
203 copy($self->master_path, $slave);
207 ## Cleanup after ourselves. Unlink all the slave paths.
211 $_->disconnect for values %{ $self->schema->storage->replicants };
212 foreach my $slave (@{$self->slave_paths}) {
219 ## --------------------------------------------------------------------- ##
220 ## Subclass for when you are setting the databases via custom export vars
221 ## This is for when you have a replicating database setup that you are
222 ## going to test against. You'll need to define the correct $ENV and have
223 ## two slave databases to test against, as well as a replication system
224 ## that will replicate in less than 1 second.
225 ## --------------------------------------------------------------------- ##
227 package DBIx::Class::DBI::Replicated::TestReplication::Custom;
228 use base 'DBIx::Class::DBI::Replicated::TestReplication';
230 ## Return an Array of ArrayRefs where each ArrayRef is suitable to use for
231 ## $storage->connect_info to be used for connecting replicants.
233 sub generate_replicant_connect_info {
235 [$ENV{"DBICTEST_SLAVE0_DSN"}, $ENV{"DBICTEST_SLAVE0_DBUSER"}, $ENV{"DBICTEST_SLAVE0_DBPASS"}, {AutoCommit => 1}],
236 [$ENV{"DBICTEST_SLAVE1_DSN"}, $ENV{"DBICTEST_SLAVE1_DBUSER"}, $ENV{"DBICTEST_SLAVE1_DBPASS"}, {AutoCommit => 1}],
240 ## pause a bit to let the replication catch up
247 ## ----------------------------------------------------------------------------
248 ## Create an object and run some tests
249 ## ----------------------------------------------------------------------------
251 ## Thi first bunch of tests are basic, just make sure all the bits are behaving
253 my $replicated_class = DBICTest->has_custom_dsn ?
254 'DBIx::Class::DBI::Replicated::TestReplication::Custom' :
255 'DBIx::Class::DBI::Replicated::TestReplication::SQLite';
259 for my $method (qw/by_connect_info by_storage_type/) {
261 ok $replicated = $replicated_class->new($method)
262 => "Created a replication object $method";
264 isa_ok $replicated->schema
265 => 'DBIx::Class::Schema';
267 isa_ok $replicated->schema->storage
268 => 'DBIx::Class::Storage::DBI::Replicated';
270 isa_ok $replicated->schema->storage->balancer
271 => 'DBIx::Class::Storage::DBI::Replicated::Balancer::Random'
272 => 'configured balancer_type';
275 ### check that all Storage::DBI methods are handled by ::Replicated
277 my @storage_dbi_methods = Class::MOP::Class
278 ->initialize('DBIx::Class::Storage::DBI')->get_all_method_names;
280 my @replicated_methods = DBIx::Class::Storage::DBI::Replicated->meta
281 ->get_all_method_names;
283 # remove constants and OTHER_CRAP
284 @storage_dbi_methods = grep !/^[A-Z_]+\z/, @storage_dbi_methods;
286 # remove CAG accessors
287 @storage_dbi_methods = grep !/_accessor\z/, @storage_dbi_methods;
289 # remove DBIx::Class (the root parent, with CAG and stuff) methods
290 my @root_methods = Class::MOP::Class->initialize('DBIx::Class')
291 ->get_all_method_names;
293 $count{$_}++ for (@storage_dbi_methods, @root_methods);
295 @storage_dbi_methods = grep $count{$_} != 2, @storage_dbi_methods;
298 my %storage_dbi_methods;
299 @storage_dbi_methods{@storage_dbi_methods} = ();
300 my %replicated_methods;
301 @replicated_methods{@replicated_methods} = ();
303 # remove ::Replicated-specific methods
304 for my $method (@replicated_methods) {
305 delete $replicated_methods{$method}
306 unless exists $storage_dbi_methods{$method};
308 @replicated_methods = keys %replicated_methods;
310 # check that what's left is implemented
312 $count{$_}++ for (@storage_dbi_methods, @replicated_methods);
314 if ((grep $count{$_} == 2, @storage_dbi_methods) == @storage_dbi_methods) {
315 pass 'all DBIx::Class::Storage::DBI methods implemented';
318 my @unimplemented = grep $count{$_} == 1, @storage_dbi_methods;
320 fail 'the following DBIx::Class::Storage::DBI methods are unimplemented: '
325 ok $replicated->schema->storage->meta
326 => 'has a meta object';
328 isa_ok $replicated->schema->storage->master
329 => 'DBIx::Class::Storage::DBI';
331 isa_ok $replicated->schema->storage->pool
332 => 'DBIx::Class::Storage::DBI::Replicated::Pool';
334 does_ok $replicated->schema->storage->balancer
335 => 'DBIx::Class::Storage::DBI::Replicated::Balancer';
337 ok my @replicant_connects = $replicated->generate_replicant_connect_info
338 => 'got replication connect information';
340 ok my @replicated_storages = $replicated->schema->storage->connect_replicants(@replicant_connects)
341 => 'Created some storages suitable for replicants';
344 $replicated->schema->storage->debug(1);
345 $replicated->schema->storage->debugcb(sub {
346 my ($op, $info) = @_;
347 ##warn "\n$op, $info\n";
351 dsn => ($info=~m/\[(.+)\]/)[0],
352 storage_type => $info=~m/REPLICANT/ ? 'REPLICANT' : 'MASTER',
356 ok my @all_storages = $replicated->schema->storage->all_storages
359 is scalar @all_storages,
361 => 'correct number of ->all_storages';
363 is ((grep $_->isa('DBIx::Class::Storage::DBI'), @all_storages),
365 => '->all_storages are correct type');
367 my @all_storage_opts =
368 grep { (reftype($_)||'') eq 'HASH' }
369 map @{ $_->_connect_info }, @all_storages;
371 is ((grep $_->{master_option}, @all_storage_opts),
373 => 'connect_info was merged from master to replicants');
375 my @replicant_names = keys %{ $replicated->schema->storage->replicants };
377 ok @replicant_names, "found replicant names @replicant_names";
379 ## Silence warning about not supporting the is_replicating method if using the
381 $replicated->schema->storage->debugobj->silence(1)
382 if first { $_ =~ /$var_dir/ } @replicant_names;
384 isa_ok $replicated->schema->storage->balancer->current_replicant
385 => 'DBIx::Class::Storage::DBI';
387 $replicated->schema->storage->debugobj->silence(0);
389 ok $replicated->schema->storage->pool->has_replicants
390 => 'does have replicants';
392 is $replicated->schema->storage->pool->num_replicants => 2
393 => 'has two replicants';
395 does_ok $replicated_storages[0]
396 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
398 does_ok $replicated_storages[1]
399 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
401 does_ok $replicated->schema->storage->replicants->{$replicant_names[0]}
402 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
404 does_ok $replicated->schema->storage->replicants->{$replicant_names[1]}
405 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
407 ## Add some info to the database
411 ->populate('Artist', [
412 [ qw/artistid name/ ],
413 [ 4, "Ozric Tentacles"],
416 is $debug{storage_type}, 'MASTER',
417 "got last query from a master: $debug{dsn}";
419 like $debug{info}, qr/INSERT/, 'Last was an insert';
421 ## Make sure all the slaves have the table definitions
423 $replicated->replicate;
424 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
425 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
427 ## Silence warning about not supporting the is_replicating method if using the
429 $replicated->schema->storage->debugobj->silence(1)
430 if first { $_ =~ /$var_dir/ } @replicant_names;
432 $replicated->schema->storage->pool->validate_replicants;
434 $replicated->schema->storage->debugobj->silence(0);
436 ## Make sure we can read the data.
438 ok my $artist1 = $replicated->schema->resultset('Artist')->find(4)
441 ## We removed testing here since master read weight is on, so we can't tell in
442 ## advance what storage to expect. We turn master read weight off a bit lower
443 ## is $debug{storage_type}, 'REPLICANT'
444 ## => "got last query from a replicant: $debug{dsn}, $debug{info}";
447 => 'DBICTest::Artist';
449 is $artist1->name, 'Ozric Tentacles'
450 => 'Found expected name for first result';
452 ## Check that master_read_weight is honored
454 no warnings qw/once redefine/;
457 *DBIx::Class::Storage::DBI::Replicated::Balancer::Random::_random_number =
460 $replicated->schema->storage->balancer->increment_storage;
462 is $replicated->schema->storage->balancer->current_replicant,
463 $replicated->schema->storage->master
464 => 'master_read_weight is honored';
466 ## turn it off for the duration of the test
467 $replicated->schema->storage->balancer->master_read_weight(0);
468 $replicated->schema->storage->balancer->increment_storage;
471 ## Add some new rows that only the master will have This is because
472 ## we overload any type of write operation so that is must hit the master
477 ->populate('Artist', [
478 [ qw/artistid name/ ],
479 [ 5, "Doom's Children"],
480 [ 6, "Dead On Arrival"],
484 is $debug{storage_type}, 'MASTER',
485 "got last query from a master: $debug{dsn}";
487 like $debug{info}, qr/INSERT/, 'Last was an insert';
489 ## Make sure all the slaves have the table definitions
490 $replicated->replicate;
492 ## Should find some data now
494 ok my $artist2 = $replicated->schema->resultset('Artist')->find(5)
497 is $debug{storage_type}, 'REPLICANT'
498 => "got last query from a replicant: $debug{dsn}";
501 => 'DBICTest::Artist';
503 is $artist2->name, "Doom's Children"
504 => 'Found expected name for first result';
506 ## What happens when we disconnect all the replicants?
508 is $replicated->schema->storage->pool->connected_replicants => 2
509 => "both replicants are connected";
511 $replicated->schema->storage->replicants->{$replicant_names[0]}->disconnect;
512 $replicated->schema->storage->replicants->{$replicant_names[1]}->disconnect;
514 is $replicated->schema->storage->pool->connected_replicants => 0
515 => "both replicants are now disconnected";
517 ## All these should pass, since the database should automatically reconnect
519 ok my $artist3 = $replicated->schema->resultset('Artist')->find(6)
520 => 'Still finding stuff.';
522 is $debug{storage_type}, 'REPLICANT'
523 => "got last query from a replicant: $debug{dsn}";
526 => 'DBICTest::Artist';
528 is $artist3->name, "Dead On Arrival"
529 => 'Found expected name for first result';
531 is $replicated->schema->storage->pool->connected_replicants => 1
532 => "At Least One replicant reconnected to handle the job";
534 ## What happens when we try to select something that doesn't exist?
536 ok ! $replicated->schema->resultset('Artist')->find(666)
537 => 'Correctly failed to find something.';
539 is $debug{storage_type}, 'REPLICANT'
540 => "got last query from a replicant: $debug{dsn}";
542 ## test the reliable option
546 $replicated->schema->storage->set_reliable_storage;
548 ok $replicated->schema->resultset('Artist')->find(2)
549 => 'Read from master 1';
551 is $debug{storage_type}, 'MASTER',
552 "got last query from a master: $debug{dsn}";
554 ok $replicated->schema->resultset('Artist')->find(5)
555 => 'Read from master 2';
557 is $debug{storage_type}, 'MASTER',
558 "got last query from a master: $debug{dsn}";
560 $replicated->schema->storage->set_balanced_storage;
562 ok $replicated->schema->resultset('Artist')->find(3)
563 => 'Read from replicant';
565 is $debug{storage_type}, 'REPLICANT',
566 "got last query from a replicant: $debug{dsn}";
569 ## Make sure when reliable goes out of scope, we are using replicants again
571 ok $replicated->schema->resultset('Artist')->find(1)
572 => 'back to replicant 1.';
574 is $debug{storage_type}, 'REPLICANT',
575 "got last query from a replicant: $debug{dsn}";
577 ok $replicated->schema->resultset('Artist')->find(2)
578 => 'back to replicant 2.';
580 is $debug{storage_type}, 'REPLICANT',
581 "got last query from a replicant: $debug{dsn}";
583 ## set all the replicants to inactive, and make sure the balancer falls back to
586 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
587 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
590 ## catch the fallback to master warning
591 open my $debugfh, '>', \my $fallback_warning;
592 my $oldfh = $replicated->schema->storage->debugfh;
593 $replicated->schema->storage->debugfh($debugfh);
595 ok $replicated->schema->resultset('Artist')->find(2)
596 => 'Fallback to master';
598 is $debug{storage_type}, 'MASTER',
599 "got last query from a master: $debug{dsn}";
601 like $fallback_warning, qr/falling back to master/
602 => 'emits falling back to master debug';
604 $replicated->schema->storage->debugfh($oldfh);
607 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
608 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
610 ## Silence warning about not supporting the is_replicating method if using the
612 $replicated->schema->storage->debugobj->silence(1)
613 if first { $_ =~ /$var_dir/ } @replicant_names;
615 $replicated->schema->storage->pool->validate_replicants;
617 $replicated->schema->storage->debugobj->silence(0);
620 ## catch the fallback to master warning
621 open my $debugfh, '>', \my $return_warning;
622 my $oldfh = $replicated->schema->storage->debugfh;
623 $replicated->schema->storage->debugfh($debugfh);
625 ok $replicated->schema->resultset('Artist')->find(2)
626 => 'Return to replicants';
628 is $debug{storage_type}, 'REPLICANT',
629 "got last query from a replicant: $debug{dsn}";
631 like $return_warning, qr/Moved back to slave/
632 => 'emits returning to slave debug';
634 $replicated->schema->storage->debugfh($oldfh);
637 ## Getting slave status tests
640 ## We skip this tests unless you have a custom replicants, since the default
641 ## sqlite based replication tests don't support these functions.
643 skip 'Cannot Test Replicant Status on Non Replicating Database', 10
644 unless DBICTest->has_custom_dsn && $ENV{"DBICTEST_SLAVE0_DSN"};
646 $replicated->replicate; ## Give the slaves a chance to catchup.
648 ok $replicated->schema->storage->replicants->{$replicant_names[0]}->is_replicating
649 => 'Replicants are replicating';
651 is $replicated->schema->storage->replicants->{$replicant_names[0]}->lag_behind_master, 0
652 => 'Replicant is zero seconds behind master';
654 ## Test the validate replicants
656 $replicated->schema->storage->pool->validate_replicants;
658 is $replicated->schema->storage->pool->active_replicants, 2
659 => 'Still have 2 replicants after validation';
661 ## Force the replicants to fail the validate test by required their lag to
662 ## be negative (ie ahead of the master!)
664 $replicated->schema->storage->pool->maximum_lag(-10);
665 $replicated->schema->storage->pool->validate_replicants;
667 is $replicated->schema->storage->pool->active_replicants, 0
668 => 'No way a replicant be be ahead of the master';
670 ## Let's be fair to the replicants again. Let them lag up to 5
672 $replicated->schema->storage->pool->maximum_lag(5);
673 $replicated->schema->storage->pool->validate_replicants;
675 is $replicated->schema->storage->pool->active_replicants, 2
676 => 'Both replicants in good standing again';
678 ## Check auto validate
680 is $replicated->schema->storage->balancer->auto_validate_every, 100
681 => "Got the expected value for auto validate";
683 ## This will make sure we auto validatge everytime
684 $replicated->schema->storage->balancer->auto_validate_every(0);
686 ## set all the replicants to inactive, and make sure the balancer falls back to
689 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
690 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
692 ## Ok, now when we go to run a query, autovalidate SHOULD reconnect
694 is $replicated->schema->storage->pool->active_replicants => 0
695 => "both replicants turned off";
697 ok $replicated->schema->resultset('Artist')->find(5)
698 => 'replicant reactivated';
700 is $debug{storage_type}, 'REPLICANT',
701 "got last query from a replicant: $debug{dsn}";
703 is $replicated->schema->storage->pool->active_replicants => 2
704 => "both replicants reactivated";
707 ## Test the reliably callback
709 ok my $reliably = sub {
711 ok $replicated->schema->resultset('Artist')->find(5)
712 => 'replicant reactivated';
714 is $debug{storage_type}, 'MASTER',
715 "got last query from a master: $debug{dsn}";
717 } => 'created coderef properly';
719 $replicated->schema->storage->execute_reliably($reliably);
721 ## Try something with an error
723 ok my $unreliably = sub {
725 ok $replicated->schema->resultset('ArtistXX')->find(5)
726 => 'replicant reactivated';
728 } => 'created coderef properly';
730 throws_ok {$replicated->schema->storage->execute_reliably($unreliably)}
731 qr/Can't find source for ArtistXX/
732 => 'Bad coderef throws proper error';
734 ## Make sure replication came back
736 ok $replicated->schema->resultset('Artist')->find(3)
737 => 'replicant reactivated';
739 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
741 ## make sure transactions are set to execute_reliably
743 ok my $transaction = sub {
749 ->populate('Artist', [
750 [ qw/artistid name/ ],
751 [ $id, "Children of the Grave $id"],
754 ok my $result = $replicated->schema->resultset('Artist')->find($id)
755 => "Found expected artist for $id";
757 is $debug{storage_type}, 'MASTER',
758 "got last query from a master: $debug{dsn}";
760 ok my $more = $replicated->schema->resultset('Artist')->find(1)
761 => 'Found expected artist again for 1';
763 is $debug{storage_type}, 'MASTER',
764 "got last query from a master: $debug{dsn}";
766 return ($result, $more);
768 } => 'Created a coderef properly';
770 ## Test the transaction with multi return
772 ok my @return = $replicated->schema->txn_do($transaction, 666)
773 => 'did transaction';
775 is $return[0]->id, 666
776 => 'first returned value is correct';
778 is $debug{storage_type}, 'MASTER',
779 "got last query from a master: $debug{dsn}";
782 => 'second returned value is correct';
784 is $debug{storage_type}, 'MASTER',
785 "got last query from a master: $debug{dsn}";
789 ## Test that asking for single return works
791 ok my @return = $replicated->schema->txn_do($transaction, 777)
792 => 'did transaction';
794 is $return[0]->id, 777
795 => 'first returned value is correct';
798 => 'second returned value is correct';
801 ## Test transaction returning a single value
804 ok my $result = $replicated->schema->txn_do(sub {
805 ok my $more = $replicated->schema->resultset('Artist')->find(1)
806 => 'found inside a transaction';
807 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
809 }) => 'successfully processed transaction';
812 => 'Got expected single result from transaction';
815 ## Make sure replication came back
817 ok $replicated->schema->resultset('Artist')->find(1)
818 => 'replicant reactivated';
820 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
822 ## Test Discard changes
825 ok my $artist = $replicated->schema->resultset('Artist')->find(2)
826 => 'got an artist to test discard changes';
828 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
830 ok $artist->get_from_storage({force_pool=>'master'})
831 => 'properly discard changes';
833 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
835 ok $artist->discard_changes({force_pool=>'master'})
836 => 'properly called discard_changes against master (manual attrs)';
838 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
840 ok $artist->discard_changes()
841 => 'properly called discard_changes against master (default attrs)';
843 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
845 ok $artist->discard_changes({force_pool=>$replicant_names[0]})
846 => 'properly able to override the default attributes';
848 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}"
851 ## Test some edge cases, like trying to do a transaction inside a transaction, etc
854 ok my $result = $replicated->schema->txn_do(sub {
855 return $replicated->schema->txn_do(sub {
856 ok my $more = $replicated->schema->resultset('Artist')->find(1)
857 => 'found inside a transaction inside a transaction';
858 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
861 }) => 'successfully processed transaction';
864 => 'Got expected single result from transaction';
868 ok my $result = $replicated->schema->txn_do(sub {
869 return $replicated->schema->storage->execute_reliably(sub {
870 return $replicated->schema->txn_do(sub {
871 return $replicated->schema->storage->execute_reliably(sub {
872 ok my $more = $replicated->schema->resultset('Artist')->find(1)
873 => 'found inside crazy deep transactions and execute_reliably';
874 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
879 }) => 'successfully processed transaction';
882 => 'Got expected single result from transaction';
885 ## Test the force_pool resultset attribute.
888 ok my $artist_rs = $replicated->schema->resultset('Artist')
889 => 'got artist resultset';
891 ## Turn on Forced Pool Storage
892 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>'master'})
893 => 'Created a resultset using force_pool storage';
895 ok my $artist = $reliable_artist_rs->find(2)
896 => 'got an artist result via force_pool storage';
898 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
901 ## Test the force_pool resultset attribute part two.
904 ok my $artist_rs = $replicated->schema->resultset('Artist')
905 => 'got artist resultset';
907 ## Turn on Forced Pool Storage
908 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>$replicant_names[0]})
909 => 'Created a resultset using force_pool storage';
911 ok my $artist = $reliable_artist_rs->find(2)
912 => 'got an artist result via force_pool storage';
914 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
917 ## Delete the old database files
918 $replicated->cleanup;