1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_replicated';
8 use DBIx::Class::_Util 'modver_gt_or_eq_and_lt';
13 plan skip_all => "A trial version of Moose detected known to break replication - skipping test known to fail" if (
14 DBICTest::RunMode->is_smoker
16 modver_gt_or_eq_and_lt( 'Moose', '1.99', '1.9903' )
22 use Scalar::Util 'reftype';
25 note "Using Moose version $Moose::VERSION and MooseX::Types version $MooseX::Types::VERSION";
27 my $var_dir_re = qr{ t [\/\\] var [\/\\] }x;
29 ## Add a connect_info option to test option merging.
30 use DBIx::Class::Storage::DBI::Replicated;
32 package DBIx::Class::Storage::DBI::Replicated;
36 __PACKAGE__->meta->make_mutable;
38 around connect_info => sub {
39 my ($next, $self, $info) = @_;
40 $info->[3]{master_option} = 1;
44 __PACKAGE__->meta->make_immutable;
53 This is a test of the replicated storage system. This will work in one of
54 two ways, either it was try to fake replication with a couple of SQLite DBs
55 and creative use of copy, or if you define a couple of %ENV vars correctly
56 will try to test those. If you do that, it will assume the setup is properly
57 replicating. Your results may vary, but I have demonstrated this to work with
58 mysql native replication.
63 ## ----------------------------------------------------------------------------
64 ## Build a class to hold all our required testing data and methods.
65 ## ----------------------------------------------------------------------------
69 ## --------------------------------------------------------------------- ##
70 ## Create an object to contain your replicated stuff.
71 ## --------------------------------------------------------------------- ##
73 package DBIx::Class::DBI::Replicated::TestReplication;
76 use base qw/Class::Accessor::Fast/;
78 __PACKAGE__->mk_accessors( qw/schema/ );
80 ## Initialize the object
83 my ($class, $schema_method) = (shift, shift);
84 my $self = $class->SUPER::new(@_);
86 $self->schema( $self->init_schema($schema_method) );
90 ## Get the Schema and set the replication storage type
93 #my ($class, $schema_getter) = @_;
94 shift->${\ ( 'get_schema_' . shift ) };
97 sub get_schema_by_storage_type {
98 DBICTest->init_schema(
101 '::DBI::Replicated' => {
102 balancer_type=>'::Random',
104 auto_validate_every=>100,
105 master_read_weight => 1
115 sub get_schema_by_connect_info {
116 DBICTest->init_schema(
117 sqlite_use_file => 1,
118 storage_type=> '::DBI::Replicated',
119 balancer_type=>'::Random',
121 auto_validate_every=>100,
122 master_read_weight => 1
133 sub generate_replicant_connect_info {}
137 ## --------------------------------------------------------------------- ##
138 ## Subclass for when you are using SQLite for testing, this provides a fake
139 ## replication support.
140 ## --------------------------------------------------------------------- ##
142 package DBIx::Class::DBI::Replicated::TestReplication::SQLite;
146 use base 'DBIx::Class::DBI::Replicated::TestReplication';
148 __PACKAGE__->mk_accessors(qw/master_path slave_paths/);
150 ## Set the master path from DBICTest
153 my $class = shift @_;
154 my $self = $class->SUPER::new(@_);
156 $self->master_path( DBICTest->_sqlite_dbfilename );
158 't/var/DBIxClass_slave1.db',
159 't/var/DBIxClass_slave2.db',
165 ## Return an Array of ArrayRefs where each ArrayRef is suitable to use for
166 ## $storage->connect_info to be used for connecting replicants.
168 sub generate_replicant_connect_info {
172 } @{$self->slave_paths};
174 my @connect_infos = map { [$_,'','',{AutoCommit=>1}] } @dsn;
176 ## Make sure nothing is left over from a failed test
180 my $c = $connect_infos[0];
181 $connect_infos[0] = {
191 ## Do a 'good enough' replication by copying the master dbfile over each of
192 ## the slave dbfiles. If the master is SQLite we do this, otherwise we
193 ## just do a one second pause to let the slaves catch up.
197 foreach my $slave (@{$self->slave_paths}) {
198 copy($self->master_path, $slave);
202 ## Cleanup after ourselves. Unlink all the slave paths.
206 $_->disconnect for values %{ $self->schema->storage->replicants };
207 foreach my $slave (@{$self->slave_paths}) {
214 ## --------------------------------------------------------------------- ##
215 ## Subclass for when you are setting the databases via custom export vars
216 ## This is for when you have a replicating database setup that you are
217 ## going to test against. You'll need to define the correct $ENV and have
218 ## two slave databases to test against, as well as a replication system
219 ## that will replicate in less than 1 second.
220 ## --------------------------------------------------------------------- ##
222 package DBIx::Class::DBI::Replicated::TestReplication::Custom;
223 use base 'DBIx::Class::DBI::Replicated::TestReplication';
225 ## Return an Array of ArrayRefs where each ArrayRef is suitable to use for
226 ## $storage->connect_info to be used for connecting replicants.
228 sub generate_replicant_connect_info {
230 [$ENV{"DBICTEST_SLAVE0_DSN"}, $ENV{"DBICTEST_SLAVE0_DBUSER"}, $ENV{"DBICTEST_SLAVE0_DBPASS"}, {AutoCommit => 1}],
231 [$ENV{"DBICTEST_SLAVE1_DSN"}, $ENV{"DBICTEST_SLAVE1_DBUSER"}, $ENV{"DBICTEST_SLAVE1_DBPASS"}, {AutoCommit => 1}],
235 ## pause a bit to let the replication catch up
242 ## ----------------------------------------------------------------------------
243 ## Create an object and run some tests
244 ## ----------------------------------------------------------------------------
246 ## Thi first bunch of tests are basic, just make sure all the bits are behaving
248 my $replicated_class = DBICTest->has_custom_dsn ?
249 'DBIx::Class::DBI::Replicated::TestReplication::Custom' :
250 'DBIx::Class::DBI::Replicated::TestReplication::SQLite';
254 for my $method (qw/by_connect_info by_storage_type/) {
256 ok $replicated = $replicated_class->new($method)
257 => "Created a replication object $method";
259 isa_ok $replicated->schema
260 => 'DBIx::Class::Schema';
262 isa_ok $replicated->schema->storage
263 => 'DBIx::Class::Storage::DBI::Replicated';
265 isa_ok $replicated->schema->storage->balancer
266 => 'DBIx::Class::Storage::DBI::Replicated::Balancer::Random'
267 => 'configured balancer_type';
270 ### check that all Storage::DBI methods are handled by ::Replicated
272 my @storage_dbi_methods = Class::MOP::Class
273 ->initialize('DBIx::Class::Storage::DBI')->get_all_method_names;
275 my @replicated_methods = DBIx::Class::Storage::DBI::Replicated->meta
276 ->get_all_method_names;
278 # remove constants and OTHER_CRAP
279 @storage_dbi_methods = grep !/^[A-Z_]+\z/, @storage_dbi_methods;
281 # remove CAG accessors
282 @storage_dbi_methods = grep !/_accessor\z/, @storage_dbi_methods;
284 # remove DBIx::Class (the root parent, with CAG and stuff) methods
285 my @root_methods = Class::MOP::Class->initialize('DBIx::Class')
286 ->get_all_method_names;
288 $count{$_}++ for (@storage_dbi_methods, @root_methods);
290 @storage_dbi_methods = grep $count{$_} != 2, @storage_dbi_methods;
293 my %storage_dbi_methods;
294 @storage_dbi_methods{@storage_dbi_methods} = ();
295 my %replicated_methods;
296 @replicated_methods{@replicated_methods} = ();
298 # remove ::Replicated-specific methods
299 for my $method (@replicated_methods) {
300 delete $replicated_methods{$method}
301 unless exists $storage_dbi_methods{$method};
303 @replicated_methods = keys %replicated_methods;
305 # check that what's left is implemented
307 $count{$_}++ for (@storage_dbi_methods, @replicated_methods);
309 if ((grep $count{$_} == 2, @storage_dbi_methods) == @storage_dbi_methods) {
310 pass 'all DBIx::Class::Storage::DBI methods implemented';
313 my @unimplemented = grep $count{$_} == 1, @storage_dbi_methods;
315 fail 'the following DBIx::Class::Storage::DBI methods are unimplemented: '
320 ok $replicated->schema->storage->meta
321 => 'has a meta object';
323 isa_ok $replicated->schema->storage->master
324 => 'DBIx::Class::Storage::DBI';
326 isa_ok $replicated->schema->storage->pool
327 => 'DBIx::Class::Storage::DBI::Replicated::Pool';
329 does_ok $replicated->schema->storage->balancer
330 => 'DBIx::Class::Storage::DBI::Replicated::Balancer';
332 ok my @replicant_connects = $replicated->generate_replicant_connect_info
333 => 'got replication connect information';
335 ok my @replicated_storages = $replicated->schema->storage->connect_replicants(@replicant_connects)
336 => 'Created some storages suitable for replicants';
339 $replicated->schema->storage->debug(1);
340 $replicated->schema->storage->debugcb(sub {
341 my ($op, $info) = @_;
342 ##warn "\n$op, $info\n";
346 dsn => ($info=~m/\[(.+)\]/)[0],
347 storage_type => $info=~m/REPLICANT/ ? 'REPLICANT' : 'MASTER',
351 ok my @all_storages = $replicated->schema->storage->all_storages
354 is scalar @all_storages,
356 => 'correct number of ->all_storages';
358 is ((grep $_->isa('DBIx::Class::Storage::DBI'), @all_storages),
360 => '->all_storages are correct type');
362 my @all_storage_opts =
363 grep { (reftype($_)||'') eq 'HASH' }
364 map @{ $_->_connect_info }, @all_storages;
366 is ((grep $_->{master_option}, @all_storage_opts),
368 => 'connect_info was merged from master to replicants');
370 my @replicant_names = keys %{ $replicated->schema->storage->replicants };
372 ok @replicant_names, "found replicant names @replicant_names";
374 ## Silence warning about not supporting the is_replicating method if using the
376 $replicated->schema->storage->debugobj->silence(1)
377 if grep { $_ =~ $var_dir_re } @replicant_names;
379 isa_ok $replicated->schema->storage->balancer->current_replicant
380 => 'DBIx::Class::Storage::DBI';
382 $replicated->schema->storage->debugobj->silence(0);
384 ok $replicated->schema->storage->pool->has_replicants
385 => 'does have replicants';
387 is $replicated->schema->storage->pool->num_replicants => 2
388 => 'has two replicants';
390 does_ok $replicated_storages[0]
391 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
393 does_ok $replicated_storages[1]
394 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
396 does_ok $replicated->schema->storage->replicants->{$replicant_names[0]}
397 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
399 does_ok $replicated->schema->storage->replicants->{$replicant_names[1]}
400 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
402 ## Add some info to the database
406 ->populate('Artist', [
407 [ qw/artistid name/ ],
408 [ 4, "Ozric Tentacles"],
411 is $debug{storage_type}, 'MASTER',
412 "got last query from a master: $debug{dsn}";
414 like $debug{info}, qr/INSERT/, 'Last was an insert';
416 ## Make sure all the slaves have the table definitions
418 $replicated->replicate;
419 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
420 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
422 ## Silence warning about not supporting the is_replicating method if using the
424 $replicated->schema->storage->debugobj->silence(1)
425 if grep { $_ =~ $var_dir_re } @replicant_names;
427 $replicated->schema->storage->pool->validate_replicants;
429 $replicated->schema->storage->debugobj->silence(0);
431 ## Make sure we can read the data.
433 ok my $artist1 = $replicated->schema->resultset('Artist')->find(4)
436 ## We removed testing here since master read weight is on, so we can't tell in
437 ## advance what storage to expect. We turn master read weight off a bit lower
438 ## is $debug{storage_type}, 'REPLICANT'
439 ## => "got last query from a replicant: $debug{dsn}, $debug{info}";
442 => 'DBICTest::Artist';
444 is $artist1->name, 'Ozric Tentacles'
445 => 'Found expected name for first result';
447 ## Check that master_read_weight is honored
449 no warnings qw/once redefine/;
452 *DBIx::Class::Storage::DBI::Replicated::Balancer::Random::_random_number =
455 $replicated->schema->storage->balancer->increment_storage;
457 is $replicated->schema->storage->balancer->current_replicant,
458 $replicated->schema->storage->master
459 => 'master_read_weight is honored';
461 ## turn it off for the duration of the test
462 $replicated->schema->storage->balancer->master_read_weight(0);
463 $replicated->schema->storage->balancer->increment_storage;
466 ## Add some new rows that only the master will have This is because
467 ## we overload any type of write operation so that is must hit the master
472 ->populate('Artist', [
473 [ qw/artistid name/ ],
474 [ 5, "Doom's Children"],
475 [ 6, "Dead On Arrival"],
479 is $debug{storage_type}, 'MASTER',
480 "got last query from a master: $debug{dsn}";
482 like $debug{info}, qr/INSERT/, 'Last was an insert';
484 ## Make sure all the slaves have the table definitions
485 $replicated->replicate;
487 ## Should find some data now
489 ok my $artist2 = $replicated->schema->resultset('Artist')->find(5)
492 is $debug{storage_type}, 'REPLICANT'
493 => "got last query from a replicant: $debug{dsn}";
496 => 'DBICTest::Artist';
498 is $artist2->name, "Doom's Children"
499 => 'Found expected name for first result';
501 ## What happens when we disconnect all the replicants?
503 is $replicated->schema->storage->pool->connected_replicants => 2
504 => "both replicants are connected";
506 $replicated->schema->storage->replicants->{$replicant_names[0]}->disconnect;
507 $replicated->schema->storage->replicants->{$replicant_names[1]}->disconnect;
509 is $replicated->schema->storage->pool->connected_replicants => 0
510 => "both replicants are now disconnected";
512 ## All these should pass, since the database should automatically reconnect
514 ok my $artist3 = $replicated->schema->resultset('Artist')->find(6)
515 => 'Still finding stuff.';
517 is $debug{storage_type}, 'REPLICANT'
518 => "got last query from a replicant: $debug{dsn}";
521 => 'DBICTest::Artist';
523 is $artist3->name, "Dead On Arrival"
524 => 'Found expected name for first result';
526 is $replicated->schema->storage->pool->connected_replicants => 1
527 => "At Least One replicant reconnected to handle the job";
529 ## What happens when we try to select something that doesn't exist?
531 ok ! $replicated->schema->resultset('Artist')->find(666)
532 => 'Correctly failed to find something.';
534 is $debug{storage_type}, 'REPLICANT'
535 => "got last query from a replicant: $debug{dsn}";
537 ## test the reliable option
541 $replicated->schema->storage->set_reliable_storage;
543 ok $replicated->schema->resultset('Artist')->find(2)
544 => 'Read from master 1';
546 is $debug{storage_type}, 'MASTER',
547 "got last query from a master: $debug{dsn}";
549 ok $replicated->schema->resultset('Artist')->find(5)
550 => 'Read from master 2';
552 is $debug{storage_type}, 'MASTER',
553 "got last query from a master: $debug{dsn}";
555 $replicated->schema->storage->set_balanced_storage;
557 ok $replicated->schema->resultset('Artist')->find(3)
558 => 'Read from replicant';
560 is $debug{storage_type}, 'REPLICANT',
561 "got last query from a replicant: $debug{dsn}";
564 ## Make sure when reliable goes out of scope, we are using replicants again
566 ok $replicated->schema->resultset('Artist')->find(1)
567 => 'back to replicant 1.';
569 is $debug{storage_type}, 'REPLICANT',
570 "got last query from a replicant: $debug{dsn}";
572 ok $replicated->schema->resultset('Artist')->find(2)
573 => 'back to replicant 2.';
575 is $debug{storage_type}, 'REPLICANT',
576 "got last query from a replicant: $debug{dsn}";
578 ## set all the replicants to inactive, and make sure the balancer falls back to
581 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
582 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
585 ## catch the fallback to master warning
586 open my $debugfh, '>', \my $fallback_warning;
587 my $oldfh = $replicated->schema->storage->debugfh;
588 $replicated->schema->storage->debugfh($debugfh);
590 ok $replicated->schema->resultset('Artist')->find(2)
591 => 'Fallback to master';
593 is $debug{storage_type}, 'MASTER',
594 "got last query from a master: $debug{dsn}";
596 like $fallback_warning, qr/falling back to master/
597 => 'emits falling back to master debug';
599 $replicated->schema->storage->debugfh($oldfh);
602 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
603 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
605 ## Silence warning about not supporting the is_replicating method if using the
607 $replicated->schema->storage->debugobj->silence(1)
608 if grep { $_ =~ $var_dir_re } @replicant_names;
610 $replicated->schema->storage->pool->validate_replicants;
612 $replicated->schema->storage->debugobj->silence(0);
615 ## catch the fallback to master warning
616 open my $debugfh, '>', \my $return_warning;
617 my $oldfh = $replicated->schema->storage->debugfh;
618 $replicated->schema->storage->debugfh($debugfh);
620 ok $replicated->schema->resultset('Artist')->find(2)
621 => 'Return to replicants';
623 is $debug{storage_type}, 'REPLICANT',
624 "got last query from a replicant: $debug{dsn}";
626 like $return_warning, qr/Moved back to slave/
627 => 'emits returning to slave debug';
629 $replicated->schema->storage->debugfh($oldfh);
632 ## Getting slave status tests
635 ## We skip this tests unless you have a custom replicants, since the default
636 ## sqlite based replication tests don't support these functions.
638 skip 'Cannot Test Replicant Status on Non Replicating Database', 10
639 unless DBICTest->has_custom_dsn && $ENV{"DBICTEST_SLAVE0_DSN"};
641 $replicated->replicate; ## Give the slaves a chance to catchup.
643 ok $replicated->schema->storage->replicants->{$replicant_names[0]}->is_replicating
644 => 'Replicants are replicating';
646 is $replicated->schema->storage->replicants->{$replicant_names[0]}->lag_behind_master, 0
647 => 'Replicant is zero seconds behind master';
649 ## Test the validate replicants
651 $replicated->schema->storage->pool->validate_replicants;
653 is $replicated->schema->storage->pool->active_replicants, 2
654 => 'Still have 2 replicants after validation';
656 ## Force the replicants to fail the validate test by required their lag to
657 ## be negative (ie ahead of the master!)
659 $replicated->schema->storage->pool->maximum_lag(-10);
660 $replicated->schema->storage->pool->validate_replicants;
662 is $replicated->schema->storage->pool->active_replicants, 0
663 => 'No way a replicant be be ahead of the master';
665 ## Let's be fair to the replicants again. Let them lag up to 5
667 $replicated->schema->storage->pool->maximum_lag(5);
668 $replicated->schema->storage->pool->validate_replicants;
670 is $replicated->schema->storage->pool->active_replicants, 2
671 => 'Both replicants in good standing again';
673 ## Check auto validate
675 is $replicated->schema->storage->balancer->auto_validate_every, 100
676 => "Got the expected value for auto validate";
678 ## This will make sure we auto validatge everytime
679 $replicated->schema->storage->balancer->auto_validate_every(0);
681 ## set all the replicants to inactive, and make sure the balancer falls back to
684 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
685 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
687 ## Ok, now when we go to run a query, autovalidate SHOULD reconnect
689 is $replicated->schema->storage->pool->active_replicants => 0
690 => "both replicants turned off";
692 ok $replicated->schema->resultset('Artist')->find(5)
693 => 'replicant reactivated';
695 is $debug{storage_type}, 'REPLICANT',
696 "got last query from a replicant: $debug{dsn}";
698 is $replicated->schema->storage->pool->active_replicants => 2
699 => "both replicants reactivated";
702 ## Test the reliably callback
704 ok my $reliably = sub {
706 ok $replicated->schema->resultset('Artist')->find(5)
707 => 'replicant reactivated';
709 is $debug{storage_type}, 'MASTER',
710 "got last query from a master: $debug{dsn}";
714 } => 'created coderef properly';
716 my @list_to_mangle = (1, 2, 3);
718 $replicated->schema->storage->execute_reliably($reliably, @list_to_mangle);
723 'Aliasing of values passed to execute_reliably works'
726 ## Try something with an error
728 ok my $unreliably = sub {
730 ok $replicated->schema->resultset('ArtistXX')->find(5)
731 => 'replicant reactivated';
733 } => 'created coderef properly';
735 throws_ok {$replicated->schema->storage->execute_reliably($unreliably)}
736 qr/Can't find source for ArtistXX/
737 => 'Bad coderef throws proper error';
740 $replicated->schema->storage->execute_reliably(sub{
741 die bless [], 'SomeExceptionThing';
743 } 'SomeExceptionThing', "Blessed exception kept intact";
745 ## Make sure replication came back
747 ok $replicated->schema->resultset('Artist')->find(3)
748 => 'replicant reactivated';
750 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
752 ## make sure transactions are set to execute_reliably
754 ok my $transaction = sub {
760 ->populate('Artist', [
761 [ qw/artistid name/ ],
762 [ $id, "Children of the Grave $id"],
765 ok my $result = $replicated->schema->resultset('Artist')->find($id)
766 => "Found expected artist for $id";
768 is $debug{storage_type}, 'MASTER',
769 "got last query from a master: $debug{dsn}";
771 ok my $more = $replicated->schema->resultset('Artist')->find(1)
772 => 'Found expected artist again for 1';
774 is $debug{storage_type}, 'MASTER',
775 "got last query from a master: $debug{dsn}";
777 return ($result, $more);
779 } => 'Created a coderef properly';
781 ## Test the transaction with multi return
783 ok my @return = $replicated->schema->txn_do($transaction, 666)
784 => 'did transaction';
786 is $return[0]->id, 666
787 => 'first returned value is correct';
789 is $debug{storage_type}, 'MASTER',
790 "got last query from a master: $debug{dsn}";
793 => 'second returned value is correct';
795 is $debug{storage_type}, 'MASTER',
796 "got last query from a master: $debug{dsn}";
800 ## Test that asking for single return works
802 ok my @return = $replicated->schema->txn_do($transaction, 777)
803 => 'did transaction';
805 is $return[0]->id, 777
806 => 'first returned value is correct';
809 => 'second returned value is correct';
812 ## Test transaction returning a single value
815 ok my $result = $replicated->schema->txn_do(sub {
816 ok my $more = $replicated->schema->resultset('Artist')->find(1)
817 => 'found inside a transaction';
818 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
820 }) => 'successfully processed transaction';
823 => 'Got expected single result from transaction';
826 ## Make sure replication came back
828 ok $replicated->schema->resultset('Artist')->find(1)
829 => 'replicant reactivated';
831 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
833 ## Test Discard changes
836 ok my $artist = $replicated->schema->resultset('Artist')->find(2)
837 => 'got an artist to test discard changes';
839 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
841 ok $artist->get_from_storage({force_pool=>'master'})
842 => 'properly discard changes';
844 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
846 ok $artist->discard_changes({force_pool=>'master'})
847 => 'properly called discard_changes against master (manual attrs)';
849 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
851 ok $artist->discard_changes()
852 => 'properly called discard_changes against master (default attrs)';
854 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
856 ok $artist->discard_changes({force_pool=>$replicant_names[0]})
857 => 'properly able to override the default attributes';
859 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}"
862 ## Test some edge cases, like trying to do a transaction inside a transaction, etc
865 ok my $result = $replicated->schema->txn_do(sub {
866 return $replicated->schema->txn_do(sub {
867 ok my $more = $replicated->schema->resultset('Artist')->find(1)
868 => 'found inside a transaction inside a transaction';
869 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
872 }) => 'successfully processed transaction';
875 => 'Got expected single result from transaction';
879 ok my $result = $replicated->schema->txn_do(sub {
880 return $replicated->schema->storage->execute_reliably(sub {
881 return $replicated->schema->txn_do(sub {
882 return $replicated->schema->storage->execute_reliably(sub {
883 ok my $more = $replicated->schema->resultset('Artist')->find(1)
884 => 'found inside crazy deep transactions and execute_reliably';
885 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
890 }) => 'successfully processed transaction';
893 => 'Got expected single result from transaction';
896 ## Test the force_pool resultset attribute.
899 ok my $artist_rs = $replicated->schema->resultset('Artist')
900 => 'got artist resultset';
902 ## Turn on Forced Pool Storage
903 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>'master'})
904 => 'Created a resultset using force_pool storage';
906 ok my $artist = $reliable_artist_rs->find(2)
907 => 'got an artist result via force_pool storage';
909 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
912 ## Test the force_pool resultset attribute part two.
915 ok my $artist_rs = $replicated->schema->resultset('Artist')
916 => 'got artist resultset';
918 ## Turn on Forced Pool Storage
919 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>$replicant_names[0]})
920 => 'Created a resultset using force_pool storage';
922 ok my $artist = $reliable_artist_rs->find(2)
923 => 'got an artist result via force_pool storage';
925 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
928 ## Delete the old database files
929 $replicated->cleanup;