1 use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_replicated';
7 use DBIx::Class::_Util 'modver_gt_or_eq_and_lt';
12 plan skip_all => "A trial version of Moose detected known to break replication - skipping test known to fail" if (
13 DBICTest::RunMode->is_smoker
15 modver_gt_or_eq_and_lt( 'Moose', '1.99', '1.9903' )
21 use List::Util 'first';
22 use Scalar::Util 'reftype';
26 note "Using Moose version $Moose::VERSION and MooseX::Types version $MooseX::Types::VERSION";
28 my $var_dir = quotemeta ( File::Spec->catdir(qw/t var/) );
30 ## Add a connect_info option to test option merging.
31 use DBIx::Class::Storage::DBI::Replicated;
33 package DBIx::Class::Storage::DBI::Replicated;
37 __PACKAGE__->meta->make_mutable;
39 around connect_info => sub {
40 my ($next, $self, $info) = @_;
41 $info->[3]{master_option} = 1;
45 __PACKAGE__->meta->make_immutable;
54 This is a test of the replicated storage system. This will work in one of
55 two ways, either it was try to fake replication with a couple of SQLite DBs
56 and creative use of copy, or if you define a couple of %ENV vars correctly
57 will try to test those. If you do that, it will assume the setup is properly
58 replicating. Your results may vary, but I have demonstrated this to work with
59 mysql native replication.
64 ## ----------------------------------------------------------------------------
65 ## Build a class to hold all our required testing data and methods.
66 ## ----------------------------------------------------------------------------
70 ## --------------------------------------------------------------------- ##
71 ## Create an object to contain your replicated stuff.
72 ## --------------------------------------------------------------------- ##
74 package DBIx::Class::DBI::Replicated::TestReplication;
77 use base qw/Class::Accessor::Fast/;
79 __PACKAGE__->mk_accessors( qw/schema/ );
81 ## Initialize the object
84 my ($class, $schema_method) = (shift, shift);
85 my $self = $class->SUPER::new(@_);
87 $self->schema( $self->init_schema($schema_method) );
91 ## Get the Schema and set the replication storage type
94 #my ($class, $schema_getter) = @_;
95 shift->${\ ( 'get_schema_' . shift ) };
98 sub get_schema_by_storage_type {
99 DBICTest->init_schema(
100 sqlite_use_file => 1,
102 '::DBI::Replicated' => {
103 balancer_type=>'::Random',
105 auto_validate_every=>100,
106 master_read_weight => 1
116 sub get_schema_by_connect_info {
117 DBICTest->init_schema(
118 sqlite_use_file => 1,
119 storage_type=> '::DBI::Replicated',
120 balancer_type=>'::Random',
122 auto_validate_every=>100,
123 master_read_weight => 1
134 sub generate_replicant_connect_info {}
138 ## --------------------------------------------------------------------- ##
139 ## Subclass for when you are using SQLite for testing, this provides a fake
140 ## replication support.
141 ## --------------------------------------------------------------------- ##
143 package DBIx::Class::DBI::Replicated::TestReplication::SQLite;
147 use base 'DBIx::Class::DBI::Replicated::TestReplication';
149 __PACKAGE__->mk_accessors(qw/master_path slave_paths/);
151 ## Set the master path from DBICTest
154 my $class = shift @_;
155 my $self = $class->SUPER::new(@_);
157 $self->master_path( DBICTest->_sqlite_dbfilename );
159 File::Spec->catfile(qw/t var DBIxClass_slave1.db/),
160 File::Spec->catfile(qw/t var DBIxClass_slave2.db/),
166 ## Return an Array of ArrayRefs where each ArrayRef is suitable to use for
167 ## $storage->connect_info to be used for connecting replicants.
169 sub generate_replicant_connect_info {
173 } @{$self->slave_paths};
175 my @connect_infos = map { [$_,'','',{AutoCommit=>1}] } @dsn;
177 ## Make sure nothing is left over from a failed test
181 my $c = $connect_infos[0];
182 $connect_infos[0] = {
192 ## Do a 'good enough' replication by copying the master dbfile over each of
193 ## the slave dbfiles. If the master is SQLite we do this, otherwise we
194 ## just do a one second pause to let the slaves catch up.
198 foreach my $slave (@{$self->slave_paths}) {
199 copy($self->master_path, $slave);
203 ## Cleanup after ourselves. Unlink all the slave paths.
207 $_->disconnect for values %{ $self->schema->storage->replicants };
208 foreach my $slave (@{$self->slave_paths}) {
215 ## --------------------------------------------------------------------- ##
216 ## Subclass for when you are setting the databases via custom export vars
217 ## This is for when you have a replicating database setup that you are
218 ## going to test against. You'll need to define the correct $ENV and have
219 ## two slave databases to test against, as well as a replication system
220 ## that will replicate in less than 1 second.
221 ## --------------------------------------------------------------------- ##
223 package DBIx::Class::DBI::Replicated::TestReplication::Custom;
224 use base 'DBIx::Class::DBI::Replicated::TestReplication';
226 ## Return an Array of ArrayRefs where each ArrayRef is suitable to use for
227 ## $storage->connect_info to be used for connecting replicants.
229 sub generate_replicant_connect_info {
231 [$ENV{"DBICTEST_SLAVE0_DSN"}, $ENV{"DBICTEST_SLAVE0_DBUSER"}, $ENV{"DBICTEST_SLAVE0_DBPASS"}, {AutoCommit => 1}],
232 [$ENV{"DBICTEST_SLAVE1_DSN"}, $ENV{"DBICTEST_SLAVE1_DBUSER"}, $ENV{"DBICTEST_SLAVE1_DBPASS"}, {AutoCommit => 1}],
236 ## pause a bit to let the replication catch up
243 ## ----------------------------------------------------------------------------
244 ## Create an object and run some tests
245 ## ----------------------------------------------------------------------------
247 ## Thi first bunch of tests are basic, just make sure all the bits are behaving
249 my $replicated_class = DBICTest->has_custom_dsn ?
250 'DBIx::Class::DBI::Replicated::TestReplication::Custom' :
251 'DBIx::Class::DBI::Replicated::TestReplication::SQLite';
255 for my $method (qw/by_connect_info by_storage_type/) {
257 ok $replicated = $replicated_class->new($method)
258 => "Created a replication object $method";
260 isa_ok $replicated->schema
261 => 'DBIx::Class::Schema';
263 isa_ok $replicated->schema->storage
264 => 'DBIx::Class::Storage::DBI::Replicated';
266 isa_ok $replicated->schema->storage->balancer
267 => 'DBIx::Class::Storage::DBI::Replicated::Balancer::Random'
268 => 'configured balancer_type';
271 ### check that all Storage::DBI methods are handled by ::Replicated
273 my @storage_dbi_methods = Class::MOP::Class
274 ->initialize('DBIx::Class::Storage::DBI')->get_all_method_names;
276 my @replicated_methods = DBIx::Class::Storage::DBI::Replicated->meta
277 ->get_all_method_names;
279 # remove constants and OTHER_CRAP
280 @storage_dbi_methods = grep !/^[A-Z_]+\z/, @storage_dbi_methods;
282 # remove CAG accessors
283 @storage_dbi_methods = grep !/_accessor\z/, @storage_dbi_methods;
285 # remove DBIx::Class (the root parent, with CAG and stuff) methods
286 my @root_methods = Class::MOP::Class->initialize('DBIx::Class')
287 ->get_all_method_names;
289 $count{$_}++ for (@storage_dbi_methods, @root_methods);
291 @storage_dbi_methods = grep $count{$_} != 2, @storage_dbi_methods;
294 my %storage_dbi_methods;
295 @storage_dbi_methods{@storage_dbi_methods} = ();
296 my %replicated_methods;
297 @replicated_methods{@replicated_methods} = ();
299 # remove ::Replicated-specific methods
300 for my $method (@replicated_methods) {
301 delete $replicated_methods{$method}
302 unless exists $storage_dbi_methods{$method};
304 @replicated_methods = keys %replicated_methods;
306 # check that what's left is implemented
308 $count{$_}++ for (@storage_dbi_methods, @replicated_methods);
310 if ((grep $count{$_} == 2, @storage_dbi_methods) == @storage_dbi_methods) {
311 pass 'all DBIx::Class::Storage::DBI methods implemented';
314 my @unimplemented = grep $count{$_} == 1, @storage_dbi_methods;
316 fail 'the following DBIx::Class::Storage::DBI methods are unimplemented: '
321 ok $replicated->schema->storage->meta
322 => 'has a meta object';
324 isa_ok $replicated->schema->storage->master
325 => 'DBIx::Class::Storage::DBI';
327 isa_ok $replicated->schema->storage->pool
328 => 'DBIx::Class::Storage::DBI::Replicated::Pool';
330 does_ok $replicated->schema->storage->balancer
331 => 'DBIx::Class::Storage::DBI::Replicated::Balancer';
333 ok my @replicant_connects = $replicated->generate_replicant_connect_info
334 => 'got replication connect information';
336 ok my @replicated_storages = $replicated->schema->storage->connect_replicants(@replicant_connects)
337 => 'Created some storages suitable for replicants';
340 $replicated->schema->storage->debug(1);
341 $replicated->schema->storage->debugcb(sub {
342 my ($op, $info) = @_;
343 ##warn "\n$op, $info\n";
347 dsn => ($info=~m/\[(.+)\]/)[0],
348 storage_type => $info=~m/REPLICANT/ ? 'REPLICANT' : 'MASTER',
352 ok my @all_storages = $replicated->schema->storage->all_storages
355 is scalar @all_storages,
357 => 'correct number of ->all_storages';
359 is ((grep $_->isa('DBIx::Class::Storage::DBI'), @all_storages),
361 => '->all_storages are correct type');
363 my @all_storage_opts =
364 grep { (reftype($_)||'') eq 'HASH' }
365 map @{ $_->_connect_info }, @all_storages;
367 is ((grep $_->{master_option}, @all_storage_opts),
369 => 'connect_info was merged from master to replicants');
371 my @replicant_names = keys %{ $replicated->schema->storage->replicants };
373 ok @replicant_names, "found replicant names @replicant_names";
375 ## Silence warning about not supporting the is_replicating method if using the
377 $replicated->schema->storage->debugobj->silence(1)
378 if first { $_ =~ /$var_dir/ } @replicant_names;
380 isa_ok $replicated->schema->storage->balancer->current_replicant
381 => 'DBIx::Class::Storage::DBI';
383 $replicated->schema->storage->debugobj->silence(0);
385 ok $replicated->schema->storage->pool->has_replicants
386 => 'does have replicants';
388 is $replicated->schema->storage->pool->num_replicants => 2
389 => 'has two replicants';
391 does_ok $replicated_storages[0]
392 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
394 does_ok $replicated_storages[1]
395 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
397 does_ok $replicated->schema->storage->replicants->{$replicant_names[0]}
398 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
400 does_ok $replicated->schema->storage->replicants->{$replicant_names[1]}
401 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
403 ## Add some info to the database
407 ->populate('Artist', [
408 [ qw/artistid name/ ],
409 [ 4, "Ozric Tentacles"],
412 is $debug{storage_type}, 'MASTER',
413 "got last query from a master: $debug{dsn}";
415 like $debug{info}, qr/INSERT/, 'Last was an insert';
417 ## Make sure all the slaves have the table definitions
419 $replicated->replicate;
420 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
421 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
423 ## Silence warning about not supporting the is_replicating method if using the
425 $replicated->schema->storage->debugobj->silence(1)
426 if first { $_ =~ /$var_dir/ } @replicant_names;
428 $replicated->schema->storage->pool->validate_replicants;
430 $replicated->schema->storage->debugobj->silence(0);
432 ## Make sure we can read the data.
434 ok my $artist1 = $replicated->schema->resultset('Artist')->find(4)
437 ## We removed testing here since master read weight is on, so we can't tell in
438 ## advance what storage to expect. We turn master read weight off a bit lower
439 ## is $debug{storage_type}, 'REPLICANT'
440 ## => "got last query from a replicant: $debug{dsn}, $debug{info}";
443 => 'DBICTest::Artist';
445 is $artist1->name, 'Ozric Tentacles'
446 => 'Found expected name for first result';
448 ## Check that master_read_weight is honored
450 no warnings qw/once redefine/;
453 *DBIx::Class::Storage::DBI::Replicated::Balancer::Random::_random_number =
456 $replicated->schema->storage->balancer->increment_storage;
458 is $replicated->schema->storage->balancer->current_replicant,
459 $replicated->schema->storage->master
460 => 'master_read_weight is honored';
462 ## turn it off for the duration of the test
463 $replicated->schema->storage->balancer->master_read_weight(0);
464 $replicated->schema->storage->balancer->increment_storage;
467 ## Add some new rows that only the master will have This is because
468 ## we overload any type of write operation so that is must hit the master
473 ->populate('Artist', [
474 [ qw/artistid name/ ],
475 [ 5, "Doom's Children"],
476 [ 6, "Dead On Arrival"],
480 is $debug{storage_type}, 'MASTER',
481 "got last query from a master: $debug{dsn}";
483 like $debug{info}, qr/INSERT/, 'Last was an insert';
485 ## Make sure all the slaves have the table definitions
486 $replicated->replicate;
488 ## Should find some data now
490 ok my $artist2 = $replicated->schema->resultset('Artist')->find(5)
493 is $debug{storage_type}, 'REPLICANT'
494 => "got last query from a replicant: $debug{dsn}";
497 => 'DBICTest::Artist';
499 is $artist2->name, "Doom's Children"
500 => 'Found expected name for first result';
502 ## What happens when we disconnect all the replicants?
504 is $replicated->schema->storage->pool->connected_replicants => 2
505 => "both replicants are connected";
507 $replicated->schema->storage->replicants->{$replicant_names[0]}->disconnect;
508 $replicated->schema->storage->replicants->{$replicant_names[1]}->disconnect;
510 is $replicated->schema->storage->pool->connected_replicants => 0
511 => "both replicants are now disconnected";
513 ## All these should pass, since the database should automatically reconnect
515 ok my $artist3 = $replicated->schema->resultset('Artist')->find(6)
516 => 'Still finding stuff.';
518 is $debug{storage_type}, 'REPLICANT'
519 => "got last query from a replicant: $debug{dsn}";
522 => 'DBICTest::Artist';
524 is $artist3->name, "Dead On Arrival"
525 => 'Found expected name for first result';
527 is $replicated->schema->storage->pool->connected_replicants => 1
528 => "At Least One replicant reconnected to handle the job";
530 ## What happens when we try to select something that doesn't exist?
532 ok ! $replicated->schema->resultset('Artist')->find(666)
533 => 'Correctly failed to find something.';
535 is $debug{storage_type}, 'REPLICANT'
536 => "got last query from a replicant: $debug{dsn}";
538 ## test the reliable option
542 $replicated->schema->storage->set_reliable_storage;
544 ok $replicated->schema->resultset('Artist')->find(2)
545 => 'Read from master 1';
547 is $debug{storage_type}, 'MASTER',
548 "got last query from a master: $debug{dsn}";
550 ok $replicated->schema->resultset('Artist')->find(5)
551 => 'Read from master 2';
553 is $debug{storage_type}, 'MASTER',
554 "got last query from a master: $debug{dsn}";
556 $replicated->schema->storage->set_balanced_storage;
558 ok $replicated->schema->resultset('Artist')->find(3)
559 => 'Read from replicant';
561 is $debug{storage_type}, 'REPLICANT',
562 "got last query from a replicant: $debug{dsn}";
565 ## Make sure when reliable goes out of scope, we are using replicants again
567 ok $replicated->schema->resultset('Artist')->find(1)
568 => 'back to replicant 1.';
570 is $debug{storage_type}, 'REPLICANT',
571 "got last query from a replicant: $debug{dsn}";
573 ok $replicated->schema->resultset('Artist')->find(2)
574 => 'back to replicant 2.';
576 is $debug{storage_type}, 'REPLICANT',
577 "got last query from a replicant: $debug{dsn}";
579 ## set all the replicants to inactive, and make sure the balancer falls back to
582 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
583 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
586 ## catch the fallback to master warning
587 open my $debugfh, '>', \my $fallback_warning;
588 my $oldfh = $replicated->schema->storage->debugfh;
589 $replicated->schema->storage->debugfh($debugfh);
591 ok $replicated->schema->resultset('Artist')->find(2)
592 => 'Fallback to master';
594 is $debug{storage_type}, 'MASTER',
595 "got last query from a master: $debug{dsn}";
597 like $fallback_warning, qr/falling back to master/
598 => 'emits falling back to master debug';
600 $replicated->schema->storage->debugfh($oldfh);
603 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
604 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
606 ## Silence warning about not supporting the is_replicating method if using the
608 $replicated->schema->storage->debugobj->silence(1)
609 if first { $_ =~ /$var_dir/ } @replicant_names;
611 $replicated->schema->storage->pool->validate_replicants;
613 $replicated->schema->storage->debugobj->silence(0);
616 ## catch the fallback to master warning
617 open my $debugfh, '>', \my $return_warning;
618 my $oldfh = $replicated->schema->storage->debugfh;
619 $replicated->schema->storage->debugfh($debugfh);
621 ok $replicated->schema->resultset('Artist')->find(2)
622 => 'Return to replicants';
624 is $debug{storage_type}, 'REPLICANT',
625 "got last query from a replicant: $debug{dsn}";
627 like $return_warning, qr/Moved back to slave/
628 => 'emits returning to slave debug';
630 $replicated->schema->storage->debugfh($oldfh);
633 ## Getting slave status tests
636 ## We skip this tests unless you have a custom replicants, since the default
637 ## sqlite based replication tests don't support these functions.
639 skip 'Cannot Test Replicant Status on Non Replicating Database', 10
640 unless DBICTest->has_custom_dsn && $ENV{"DBICTEST_SLAVE0_DSN"};
642 $replicated->replicate; ## Give the slaves a chance to catchup.
644 ok $replicated->schema->storage->replicants->{$replicant_names[0]}->is_replicating
645 => 'Replicants are replicating';
647 is $replicated->schema->storage->replicants->{$replicant_names[0]}->lag_behind_master, 0
648 => 'Replicant is zero seconds behind master';
650 ## Test the validate replicants
652 $replicated->schema->storage->pool->validate_replicants;
654 is $replicated->schema->storage->pool->active_replicants, 2
655 => 'Still have 2 replicants after validation';
657 ## Force the replicants to fail the validate test by required their lag to
658 ## be negative (ie ahead of the master!)
660 $replicated->schema->storage->pool->maximum_lag(-10);
661 $replicated->schema->storage->pool->validate_replicants;
663 is $replicated->schema->storage->pool->active_replicants, 0
664 => 'No way a replicant be be ahead of the master';
666 ## Let's be fair to the replicants again. Let them lag up to 5
668 $replicated->schema->storage->pool->maximum_lag(5);
669 $replicated->schema->storage->pool->validate_replicants;
671 is $replicated->schema->storage->pool->active_replicants, 2
672 => 'Both replicants in good standing again';
674 ## Check auto validate
676 is $replicated->schema->storage->balancer->auto_validate_every, 100
677 => "Got the expected value for auto validate";
679 ## This will make sure we auto validatge everytime
680 $replicated->schema->storage->balancer->auto_validate_every(0);
682 ## set all the replicants to inactive, and make sure the balancer falls back to
685 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
686 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
688 ## Ok, now when we go to run a query, autovalidate SHOULD reconnect
690 is $replicated->schema->storage->pool->active_replicants => 0
691 => "both replicants turned off";
693 ok $replicated->schema->resultset('Artist')->find(5)
694 => 'replicant reactivated';
696 is $debug{storage_type}, 'REPLICANT',
697 "got last query from a replicant: $debug{dsn}";
699 is $replicated->schema->storage->pool->active_replicants => 2
700 => "both replicants reactivated";
703 ## Test the reliably callback
705 ok my $reliably = sub {
707 ok $replicated->schema->resultset('Artist')->find(5)
708 => 'replicant reactivated';
710 is $debug{storage_type}, 'MASTER',
711 "got last query from a master: $debug{dsn}";
713 } => 'created coderef properly';
715 $replicated->schema->storage->execute_reliably($reliably);
717 ## Try something with an error
719 ok my $unreliably = sub {
721 ok $replicated->schema->resultset('ArtistXX')->find(5)
722 => 'replicant reactivated';
724 } => 'created coderef properly';
726 throws_ok {$replicated->schema->storage->execute_reliably($unreliably)}
727 qr/Can't find source for ArtistXX/
728 => 'Bad coderef throws proper error';
730 ## Make sure replication came back
732 ok $replicated->schema->resultset('Artist')->find(3)
733 => 'replicant reactivated';
735 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
737 ## make sure transactions are set to execute_reliably
739 ok my $transaction = sub {
745 ->populate('Artist', [
746 [ qw/artistid name/ ],
747 [ $id, "Children of the Grave $id"],
750 ok my $result = $replicated->schema->resultset('Artist')->find($id)
751 => "Found expected artist for $id";
753 is $debug{storage_type}, 'MASTER',
754 "got last query from a master: $debug{dsn}";
756 ok my $more = $replicated->schema->resultset('Artist')->find(1)
757 => 'Found expected artist again for 1';
759 is $debug{storage_type}, 'MASTER',
760 "got last query from a master: $debug{dsn}";
762 return ($result, $more);
764 } => 'Created a coderef properly';
766 ## Test the transaction with multi return
768 ok my @return = $replicated->schema->txn_do($transaction, 666)
769 => 'did transaction';
771 is $return[0]->id, 666
772 => 'first returned value is correct';
774 is $debug{storage_type}, 'MASTER',
775 "got last query from a master: $debug{dsn}";
778 => 'second returned value is correct';
780 is $debug{storage_type}, 'MASTER',
781 "got last query from a master: $debug{dsn}";
785 ## Test that asking for single return works
787 ok my @return = $replicated->schema->txn_do($transaction, 777)
788 => 'did transaction';
790 is $return[0]->id, 777
791 => 'first returned value is correct';
794 => 'second returned value is correct';
797 ## Test transaction returning a single value
800 ok my $result = $replicated->schema->txn_do(sub {
801 ok my $more = $replicated->schema->resultset('Artist')->find(1)
802 => 'found inside a transaction';
803 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
805 }) => 'successfully processed transaction';
808 => 'Got expected single result from transaction';
811 ## Make sure replication came back
813 ok $replicated->schema->resultset('Artist')->find(1)
814 => 'replicant reactivated';
816 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
818 ## Test Discard changes
821 ok my $artist = $replicated->schema->resultset('Artist')->find(2)
822 => 'got an artist to test discard changes';
824 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
826 ok $artist->get_from_storage({force_pool=>'master'})
827 => 'properly discard changes';
829 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
831 ok $artist->discard_changes({force_pool=>'master'})
832 => 'properly called discard_changes against master (manual attrs)';
834 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
836 ok $artist->discard_changes()
837 => 'properly called discard_changes against master (default attrs)';
839 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
841 ok $artist->discard_changes({force_pool=>$replicant_names[0]})
842 => 'properly able to override the default attributes';
844 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}"
847 ## Test some edge cases, like trying to do a transaction inside a transaction, etc
850 ok my $result = $replicated->schema->txn_do(sub {
851 return $replicated->schema->txn_do(sub {
852 ok my $more = $replicated->schema->resultset('Artist')->find(1)
853 => 'found inside a transaction inside a transaction';
854 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
857 }) => 'successfully processed transaction';
860 => 'Got expected single result from transaction';
864 ok my $result = $replicated->schema->txn_do(sub {
865 return $replicated->schema->storage->execute_reliably(sub {
866 return $replicated->schema->txn_do(sub {
867 return $replicated->schema->storage->execute_reliably(sub {
868 ok my $more = $replicated->schema->resultset('Artist')->find(1)
869 => 'found inside crazy deep transactions and execute_reliably';
870 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
875 }) => 'successfully processed transaction';
878 => 'Got expected single result from transaction';
881 ## Test the force_pool resultset attribute.
884 ok my $artist_rs = $replicated->schema->resultset('Artist')
885 => 'got artist resultset';
887 ## Turn on Forced Pool Storage
888 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>'master'})
889 => 'Created a resultset using force_pool storage';
891 ok my $artist = $reliable_artist_rs->find(2)
892 => 'got an artist result via force_pool storage';
894 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
897 ## Test the force_pool resultset attribute part two.
900 ok my $artist_rs = $replicated->schema->resultset('Artist')
901 => 'got artist resultset';
903 ## Turn on Forced Pool Storage
904 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>$replicant_names[0]})
905 => 'Created a resultset using force_pool storage';
907 ok my $artist = $reliable_artist_rs->find(2)
908 => 'got an artist result via force_pool storage';
910 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
913 ## Delete the old database files
914 $replicated->cleanup;