7 use List::Util 'first';
8 use Scalar::Util 'reftype';
13 eval { require Test::Moose; Test::Moose->import() };
14 plan skip_all => "Need Test::Moose to run this test" if $@;
17 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('replicated')
18 unless DBIx::Class::Optional::Dependencies->req_ok_for ('replicated');
21 use_ok 'DBIx::Class::Storage::DBI::Replicated::Pool';
22 use_ok 'DBIx::Class::Storage::DBI::Replicated::Balancer';
23 use_ok 'DBIx::Class::Storage::DBI::Replicated::Replicant';
24 use_ok 'DBIx::Class::Storage::DBI::Replicated';
28 diag "Using Moose version $Moose::VERSION and MooseX::Types version $MooseX::Types::VERSION";
32 This is a test of the replicated storage system. This will work in one of
33 two ways, either it was try to fake replication with a couple of SQLite DBs
34 and creative use of copy, or if you define a couple of %ENV vars correctly
35 will try to test those. If you do that, it will assume the setup is properly
36 replicating. Your results may vary, but I have demonstrated this to work with
37 mysql native replication.
42 ## ----------------------------------------------------------------------------
43 ## Build a class to hold all our required testing data and methods.
44 ## ----------------------------------------------------------------------------
48 ## --------------------------------------------------------------------- ##
49 ## Create an object to contain your replicated stuff.
50 ## --------------------------------------------------------------------- ##
52 package DBIx::Class::DBI::Replicated::TestReplication;
55 use base qw/Class::Accessor::Fast/;
57 __PACKAGE__->mk_accessors( qw/schema/ );
59 ## Initialize the object
62 my ($class, $schema_method) = (shift, shift);
63 my $self = $class->SUPER::new(@_);
65 $self->schema( $self->init_schema($schema_method) );
69 ## Get the Schema and set the replication storage type
72 # current SQLT SQLite producer does not handle DROP TABLE IF EXISTS, trap warnings here
73 local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /no such table.+DROP TABLE/s };
75 my ($class, $schema_method) = @_;
77 my $method = "get_schema_$schema_method";
78 my $schema = $class->$method;
83 sub get_schema_by_storage_type {
84 DBICTest->init_schema(
87 '::DBI::Replicated' => {
88 balancer_type=>'::Random',
90 auto_validate_every=>100,
91 master_read_weight => 1
101 sub get_schema_by_connect_info {
102 DBICTest->init_schema(
103 sqlite_use_file => 1,
104 storage_type=> '::DBI::Replicated',
105 balancer_type=>'::Random',
107 auto_validate_every=>100,
108 master_read_weight => 1
116 sub generate_replicant_connect_info {}
120 ## --------------------------------------------------------------------- ##
121 ## Add a connect_info option to test option merging.
122 ## --------------------------------------------------------------------- ##
124 package DBIx::Class::Storage::DBI::Replicated;
128 __PACKAGE__->meta->make_mutable;
130 around connect_info => sub {
131 my ($next, $self, $info) = @_;
132 $info->[3]{master_option} = 1;
136 __PACKAGE__->meta->make_immutable;
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 gthe slave paths.
210 foreach my $slave (@{$self->slave_paths}) {
217 ## --------------------------------------------------------------------- ##
218 ## Subclass for when you are setting the databases via custom export vars
219 ## This is for when you have a replicating database setup that you are
220 ## going to test against. You'll need to define the correct $ENV and have
221 ## two slave databases to test against, as well as a replication system
222 ## that will replicate in less than 1 second.
223 ## --------------------------------------------------------------------- ##
225 package DBIx::Class::DBI::Replicated::TestReplication::Custom;
226 use base 'DBIx::Class::DBI::Replicated::TestReplication';
228 ## Return an Array of ArrayRefs where each ArrayRef is suitable to use for
229 ## $storage->connect_info to be used for connecting replicants.
231 sub generate_replicant_connect_info {
233 [$ENV{"DBICTEST_SLAVE0_DSN"}, $ENV{"DBICTEST_SLAVE0_DBUSER"}, $ENV{"DBICTEST_SLAVE0_DBPASS"}, {AutoCommit => 1}],
234 [$ENV{"DBICTEST_SLAVE1_DSN"}, $ENV{"DBICTEST_SLAVE1_DBUSER"}, $ENV{"DBICTEST_SLAVE1_DBPASS"}, {AutoCommit => 1}],
238 ## pause a bit to let the replication catch up
245 ## ----------------------------------------------------------------------------
246 ## Create an object and run some tests
247 ## ----------------------------------------------------------------------------
249 ## Thi first bunch of tests are basic, just make sure all the bits are behaving
251 my $replicated_class = DBICTest->has_custom_dsn ?
252 'DBIx::Class::DBI::Replicated::TestReplication::Custom' :
253 'DBIx::Class::DBI::Replicated::TestReplication::SQLite';
257 for my $method (qw/by_connect_info by_storage_type/) {
259 ok $replicated = $replicated_class->new($method)
260 => "Created a replication object $method";
262 isa_ok $replicated->schema
263 => 'DBIx::Class::Schema';
265 isa_ok $replicated->schema->storage
266 => 'DBIx::Class::Storage::DBI::Replicated';
268 isa_ok $replicated->schema->storage->balancer
269 => 'DBIx::Class::Storage::DBI::Replicated::Balancer::Random'
270 => 'configured balancer_type';
273 ### check that all Storage::DBI methods are handled by ::Replicated
275 my @storage_dbi_methods = Class::MOP::Class
276 ->initialize('DBIx::Class::Storage::DBI')->get_all_method_names;
278 my @replicated_methods = DBIx::Class::Storage::DBI::Replicated->meta
279 ->get_all_method_names;
281 # remove constants and OTHER_CRAP
282 @storage_dbi_methods = grep !/^[A-Z_]+\z/, @storage_dbi_methods;
284 # remove CAG accessors
285 @storage_dbi_methods = grep !/_accessor\z/, @storage_dbi_methods;
287 # remove DBIx::Class (the root parent, with CAG and stuff) methods
288 my @root_methods = Class::MOP::Class->initialize('DBIx::Class')
289 ->get_all_method_names;
291 $count{$_}++ for (@storage_dbi_methods, @root_methods);
293 @storage_dbi_methods = grep $count{$_} != 2, @storage_dbi_methods;
296 my %storage_dbi_methods;
297 @storage_dbi_methods{@storage_dbi_methods} = ();
298 my %replicated_methods;
299 @replicated_methods{@replicated_methods} = ();
301 # remove ::Replicated-specific methods
302 for my $method (@replicated_methods) {
303 delete $replicated_methods{$method}
304 unless exists $storage_dbi_methods{$method};
306 @replicated_methods = keys %replicated_methods;
308 # check that what's left is implemented
310 $count{$_}++ for (@storage_dbi_methods, @replicated_methods);
312 if ((grep $count{$_} == 2, @storage_dbi_methods) == @storage_dbi_methods) {
313 pass 'all DBIx::Class::Storage::DBI methods implemented';
316 my @unimplemented = grep $count{$_} == 1, @storage_dbi_methods;
318 fail 'the following DBIx::Class::Storage::DBI methods are unimplemented: '
323 ok $replicated->schema->storage->meta
324 => 'has a meta object';
326 isa_ok $replicated->schema->storage->master
327 => 'DBIx::Class::Storage::DBI';
329 isa_ok $replicated->schema->storage->pool
330 => 'DBIx::Class::Storage::DBI::Replicated::Pool';
332 does_ok $replicated->schema->storage->balancer
333 => 'DBIx::Class::Storage::DBI::Replicated::Balancer';
335 ok my @replicant_connects = $replicated->generate_replicant_connect_info
336 => 'got replication connect information';
338 ok my @replicated_storages = $replicated->schema->storage->connect_replicants(@replicant_connects)
339 => 'Created some storages suitable for replicants';
342 $replicated->schema->storage->debug(1);
343 $replicated->schema->storage->debugcb(sub {
344 my ($op, $info) = @_;
345 ##warn "\n$op, $info\n";
349 dsn => ($info=~m/\[(.+)\]/)[0],
350 storage_type => $info=~m/REPLICANT/ ? 'REPLICANT' : 'MASTER',
354 ok my @all_storages = $replicated->schema->storage->all_storages
357 is scalar @all_storages,
359 => 'correct number of ->all_storages';
361 is ((grep $_->isa('DBIx::Class::Storage::DBI'), @all_storages),
363 => '->all_storages are correct type');
365 my @all_storage_opts =
366 grep { (reftype($_)||'') eq 'HASH' }
367 map @{ $_->_connect_info }, @all_storages;
369 is ((grep $_->{master_option}, @all_storage_opts),
371 => 'connect_info was merged from master to replicants');
373 my @replicant_names = keys %{ $replicated->schema->storage->replicants };
375 ok @replicant_names, "found replicant names @replicant_names";
377 ## Silence warning about not supporting the is_replicating method if using the
379 $replicated->schema->storage->debugobj->silence(1)
380 if first { m{^t/} } @replicant_names;
382 isa_ok $replicated->schema->storage->balancer->current_replicant
383 => 'DBIx::Class::Storage::DBI';
385 $replicated->schema->storage->debugobj->silence(0);
387 ok $replicated->schema->storage->pool->has_replicants
388 => 'does have replicants';
390 is $replicated->schema->storage->pool->num_replicants => 2
391 => 'has two replicants';
393 does_ok $replicated_storages[0]
394 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
396 does_ok $replicated_storages[1]
397 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
399 does_ok $replicated->schema->storage->replicants->{$replicant_names[0]}
400 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
402 does_ok $replicated->schema->storage->replicants->{$replicant_names[1]}
403 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
405 ## Add some info to the database
409 ->populate('Artist', [
410 [ qw/artistid name/ ],
411 [ 4, "Ozric Tentacles"],
414 is $debug{storage_type}, 'MASTER',
415 "got last query from a master: $debug{dsn}";
417 like $debug{info}, qr/INSERT/, 'Last was an insert';
419 ## Make sure all the slaves have the table definitions
421 $replicated->replicate;
422 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
423 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
425 ## Silence warning about not supporting the is_replicating method if using the
427 $replicated->schema->storage->debugobj->silence(1)
428 if first { m{^t/} } @replicant_names;
430 $replicated->schema->storage->pool->validate_replicants;
432 $replicated->schema->storage->debugobj->silence(0);
434 ## Make sure we can read the data.
436 ok my $artist1 = $replicated->schema->resultset('Artist')->find(4)
439 ## We removed testing here since master read weight is on, so we can't tell in
440 ## advance what storage to expect. We turn master read weight off a bit lower
441 ## is $debug{storage_type}, 'REPLICANT'
442 ## => "got last query from a replicant: $debug{dsn}, $debug{info}";
445 => 'DBICTest::Artist';
447 is $artist1->name, 'Ozric Tentacles'
448 => 'Found expected name for first result';
450 ## Check that master_read_weight is honored
452 no warnings qw/once redefine/;
455 *DBIx::Class::Storage::DBI::Replicated::Balancer::Random::_random_number =
458 $replicated->schema->storage->balancer->increment_storage;
460 is $replicated->schema->storage->balancer->current_replicant,
461 $replicated->schema->storage->master
462 => 'master_read_weight is honored';
464 ## turn it off for the duration of the test
465 $replicated->schema->storage->balancer->master_read_weight(0);
466 $replicated->schema->storage->balancer->increment_storage;
469 ## Add some new rows that only the master will have This is because
470 ## we overload any type of write operation so that is must hit the master
475 ->populate('Artist', [
476 [ qw/artistid name/ ],
477 [ 5, "Doom's Children"],
478 [ 6, "Dead On Arrival"],
482 is $debug{storage_type}, 'MASTER',
483 "got last query from a master: $debug{dsn}";
485 like $debug{info}, qr/INSERT/, 'Last was an insert';
487 ## Make sure all the slaves have the table definitions
488 $replicated->replicate;
490 ## Should find some data now
492 ok my $artist2 = $replicated->schema->resultset('Artist')->find(5)
495 is $debug{storage_type}, 'REPLICANT'
496 => "got last query from a replicant: $debug{dsn}";
499 => 'DBICTest::Artist';
501 is $artist2->name, "Doom's Children"
502 => 'Found expected name for first result';
504 ## What happens when we disconnect all the replicants?
506 is $replicated->schema->storage->pool->connected_replicants => 2
507 => "both replicants are connected";
509 $replicated->schema->storage->replicants->{$replicant_names[0]}->disconnect;
510 $replicated->schema->storage->replicants->{$replicant_names[1]}->disconnect;
512 is $replicated->schema->storage->pool->connected_replicants => 0
513 => "both replicants are now disconnected";
515 ## All these should pass, since the database should automatically reconnect
517 ok my $artist3 = $replicated->schema->resultset('Artist')->find(6)
518 => 'Still finding stuff.';
520 is $debug{storage_type}, 'REPLICANT'
521 => "got last query from a replicant: $debug{dsn}";
524 => 'DBICTest::Artist';
526 is $artist3->name, "Dead On Arrival"
527 => 'Found expected name for first result';
529 is $replicated->schema->storage->pool->connected_replicants => 1
530 => "At Least One replicant reconnected to handle the job";
532 ## What happens when we try to select something that doesn't exist?
534 ok ! $replicated->schema->resultset('Artist')->find(666)
535 => 'Correctly failed to find something.';
537 is $debug{storage_type}, 'REPLICANT'
538 => "got last query from a replicant: $debug{dsn}";
540 ## test the reliable option
544 $replicated->schema->storage->set_reliable_storage;
546 ok $replicated->schema->resultset('Artist')->find(2)
547 => 'Read from master 1';
549 is $debug{storage_type}, 'MASTER',
550 "got last query from a master: $debug{dsn}";
552 ok $replicated->schema->resultset('Artist')->find(5)
553 => 'Read from master 2';
555 is $debug{storage_type}, 'MASTER',
556 "got last query from a master: $debug{dsn}";
558 $replicated->schema->storage->set_balanced_storage;
560 ok $replicated->schema->resultset('Artist')->find(3)
561 => 'Read from replicant';
563 is $debug{storage_type}, 'REPLICANT',
564 "got last query from a replicant: $debug{dsn}";
567 ## Make sure when reliable goes out of scope, we are using replicants again
569 ok $replicated->schema->resultset('Artist')->find(1)
570 => 'back to replicant 1.';
572 is $debug{storage_type}, 'REPLICANT',
573 "got last query from a replicant: $debug{dsn}";
575 ok $replicated->schema->resultset('Artist')->find(2)
576 => 'back to replicant 2.';
578 is $debug{storage_type}, 'REPLICANT',
579 "got last query from a replicant: $debug{dsn}";
581 ## set all the replicants to inactive, and make sure the balancer falls back to
584 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
585 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
588 ## catch the fallback to master warning
589 open my $debugfh, '>', \my $fallback_warning;
590 my $oldfh = $replicated->schema->storage->debugfh;
591 $replicated->schema->storage->debugfh($debugfh);
593 ok $replicated->schema->resultset('Artist')->find(2)
594 => 'Fallback to master';
596 is $debug{storage_type}, 'MASTER',
597 "got last query from a master: $debug{dsn}";
599 like $fallback_warning, qr/falling back to master/
600 => 'emits falling back to master warning';
602 $replicated->schema->storage->debugfh($oldfh);
605 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
606 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
608 ## Silence warning about not supporting the is_replicating method if using the
610 $replicated->schema->storage->debugobj->silence(1)
611 if first { m{^t/} } @replicant_names;
613 $replicated->schema->storage->pool->validate_replicants;
615 $replicated->schema->storage->debugobj->silence(0);
617 ok $replicated->schema->resultset('Artist')->find(2)
618 => 'Returned to replicates';
620 is $debug{storage_type}, 'REPLICANT',
621 "got last query from a replicant: $debug{dsn}";
623 ## Getting slave status tests
626 ## We skip this tests unless you have a custom replicants, since the default
627 ## sqlite based replication tests don't support these functions.
629 skip 'Cannot Test Replicant Status on Non Replicating Database', 10
630 unless DBICTest->has_custom_dsn && $ENV{"DBICTEST_SLAVE0_DSN"};
632 $replicated->replicate; ## Give the slaves a chance to catchup.
634 ok $replicated->schema->storage->replicants->{$replicant_names[0]}->is_replicating
635 => 'Replicants are replicating';
637 is $replicated->schema->storage->replicants->{$replicant_names[0]}->lag_behind_master, 0
638 => 'Replicant is zero seconds behind master';
640 ## Test the validate replicants
642 $replicated->schema->storage->pool->validate_replicants;
644 is $replicated->schema->storage->pool->active_replicants, 2
645 => 'Still have 2 replicants after validation';
647 ## Force the replicants to fail the validate test by required their lag to
648 ## be negative (ie ahead of the master!)
650 $replicated->schema->storage->pool->maximum_lag(-10);
651 $replicated->schema->storage->pool->validate_replicants;
653 is $replicated->schema->storage->pool->active_replicants, 0
654 => 'No way a replicant be be ahead of the master';
656 ## Let's be fair to the replicants again. Let them lag up to 5
658 $replicated->schema->storage->pool->maximum_lag(5);
659 $replicated->schema->storage->pool->validate_replicants;
661 is $replicated->schema->storage->pool->active_replicants, 2
662 => 'Both replicants in good standing again';
664 ## Check auto validate
666 is $replicated->schema->storage->balancer->auto_validate_every, 100
667 => "Got the expected value for auto validate";
669 ## This will make sure we auto validatge everytime
670 $replicated->schema->storage->balancer->auto_validate_every(0);
672 ## set all the replicants to inactive, and make sure the balancer falls back to
675 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
676 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
678 ## Ok, now when we go to run a query, autovalidate SHOULD reconnect
680 is $replicated->schema->storage->pool->active_replicants => 0
681 => "both replicants turned off";
683 ok $replicated->schema->resultset('Artist')->find(5)
684 => 'replicant reactivated';
686 is $debug{storage_type}, 'REPLICANT',
687 "got last query from a replicant: $debug{dsn}";
689 is $replicated->schema->storage->pool->active_replicants => 2
690 => "both replicants reactivated";
693 ## Test the reliably callback
695 ok my $reliably = sub {
697 ok $replicated->schema->resultset('Artist')->find(5)
698 => 'replicant reactivated';
700 is $debug{storage_type}, 'MASTER',
701 "got last query from a master: $debug{dsn}";
703 } => 'created coderef properly';
705 $replicated->schema->storage->execute_reliably($reliably);
707 ## Try something with an error
709 ok my $unreliably = sub {
711 ok $replicated->schema->resultset('ArtistXX')->find(5)
712 => 'replicant reactivated';
714 } => 'created coderef properly';
716 throws_ok {$replicated->schema->storage->execute_reliably($unreliably)}
717 qr/Can't find source for ArtistXX/
718 => 'Bad coderef throws proper error';
720 ## Make sure replication came back
722 ok $replicated->schema->resultset('Artist')->find(3)
723 => 'replicant reactivated';
725 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
727 ## make sure transactions are set to execute_reliably
729 ok my $transaction = sub {
735 ->populate('Artist', [
736 [ qw/artistid name/ ],
737 [ $id, "Children of the Grave"],
740 ok my $result = $replicated->schema->resultset('Artist')->find($id)
741 => "Found expected artist for $id";
743 is $debug{storage_type}, 'MASTER',
744 "got last query from a master: $debug{dsn}";
746 ok my $more = $replicated->schema->resultset('Artist')->find(1)
747 => 'Found expected artist again for 1';
749 is $debug{storage_type}, 'MASTER',
750 "got last query from a master: $debug{dsn}";
752 return ($result, $more);
754 } => 'Created a coderef properly';
756 ## Test the transaction with multi return
758 ok my @return = $replicated->schema->txn_do($transaction, 666)
759 => 'did transaction';
761 is $return[0]->id, 666
762 => 'first returned value is correct';
764 is $debug{storage_type}, 'MASTER',
765 "got last query from a master: $debug{dsn}";
768 => 'second returned value is correct';
770 is $debug{storage_type}, 'MASTER',
771 "got last query from a master: $debug{dsn}";
775 ## Test that asking for single return works
777 ok my @return = $replicated->schema->txn_do($transaction, 777)
778 => 'did transaction';
780 is $return[0]->id, 777
781 => 'first returned value is correct';
784 => 'second returned value is correct';
787 ## Test transaction returning a single value
790 ok my $result = $replicated->schema->txn_do(sub {
791 ok my $more = $replicated->schema->resultset('Artist')->find(1)
792 => 'found inside a transaction';
793 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
795 }) => 'successfully processed transaction';
798 => 'Got expected single result from transaction';
801 ## Make sure replication came back
803 ok $replicated->schema->resultset('Artist')->find(1)
804 => 'replicant reactivated';
806 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
808 ## Test Discard changes
811 ok my $artist = $replicated->schema->resultset('Artist')->find(2)
812 => 'got an artist to test discard changes';
814 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
816 ok $artist->get_from_storage({force_pool=>'master'})
817 => 'properly discard changes';
819 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
821 ok $artist->discard_changes({force_pool=>'master'})
822 => 'properly called discard_changes against master (manual attrs)';
824 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
826 ok $artist->discard_changes()
827 => 'properly called discard_changes against master (default attrs)';
829 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
831 ok $artist->discard_changes({force_pool=>$replicant_names[0]})
832 => 'properly able to override the default attributes';
834 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}"
837 ## Test some edge cases, like trying to do a transaction inside a transaction, etc
840 ok my $result = $replicated->schema->txn_do(sub {
841 return $replicated->schema->txn_do(sub {
842 ok my $more = $replicated->schema->resultset('Artist')->find(1)
843 => 'found inside a transaction inside a transaction';
844 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
847 }) => 'successfully processed transaction';
850 => 'Got expected single result from transaction';
854 ok my $result = $replicated->schema->txn_do(sub {
855 return $replicated->schema->storage->execute_reliably(sub {
856 return $replicated->schema->txn_do(sub {
857 return $replicated->schema->storage->execute_reliably(sub {
858 ok my $more = $replicated->schema->resultset('Artist')->find(1)
859 => 'found inside crazy deep transactions and execute_reliably';
860 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
865 }) => 'successfully processed transaction';
868 => 'Got expected single result from transaction';
871 ## Test the force_pool resultset attribute.
874 ok my $artist_rs = $replicated->schema->resultset('Artist')
875 => 'got artist resultset';
877 ## Turn on Forced Pool Storage
878 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>'master'})
879 => 'Created a resultset using force_pool storage';
881 ok my $artist = $reliable_artist_rs->find(2)
882 => 'got an artist result via force_pool storage';
884 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
887 ## Test the force_pool resultset attribute part two.
890 ok my $artist_rs = $replicated->schema->resultset('Artist')
891 => 'got artist resultset';
893 ## Turn on Forced Pool Storage
894 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>$replicant_names[0]})
895 => 'Created a resultset using force_pool storage';
897 ok my $artist = $reliable_artist_rs->find(2)
898 => 'got an artist result via force_pool storage';
900 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
902 ## Delete the old database files
903 $replicated->cleanup;