8 plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_replicated')
9 unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_replicated');
15 if (DBICTest::RunMode->is_smoker) {
16 my $mver = Moose->VERSION;
17 plan skip_all => "A trial version $mver of Moose detected known to break replication - skipping test known to fail"
18 if ($mver >= 1.99 and $mver <= 1.9902);
23 use List::Util 'first';
24 use Scalar::Util 'reftype';
29 note "Using Moose version $Moose::VERSION and MooseX::Types version $MooseX::Types::VERSION";
31 my $var_dir = quotemeta ( File::Spec->catdir(qw/t var/) );
33 use_ok 'DBIx::Class::Storage::DBI::Replicated::Pool';
34 use_ok 'DBIx::Class::Storage::DBI::Replicated::Balancer';
35 use_ok 'DBIx::Class::Storage::DBI::Replicated::Replicant';
36 use_ok 'DBIx::Class::Storage::DBI::Replicated';
41 This is a test of the replicated storage system. This will work in one of
42 two ways, either it was try to fake replication with a couple of SQLite DBs
43 and creative use of copy, or if you define a couple of %ENV vars correctly
44 will try to test those. If you do that, it will assume the setup is properly
45 replicating. Your results may vary, but I have demonstrated this to work with
46 mysql native replication.
51 ## ----------------------------------------------------------------------------
52 ## Build a class to hold all our required testing data and methods.
53 ## ----------------------------------------------------------------------------
57 ## --------------------------------------------------------------------- ##
58 ## Create an object to contain your replicated stuff.
59 ## --------------------------------------------------------------------- ##
61 package DBIx::Class::DBI::Replicated::TestReplication;
64 use base qw/Class::Accessor::Fast/;
66 __PACKAGE__->mk_accessors( qw/schema/ );
68 ## Initialize the object
71 my ($class, $schema_method) = (shift, shift);
72 my $self = $class->SUPER::new(@_);
74 $self->schema( $self->init_schema($schema_method) );
78 ## Get the Schema and set the replication storage type
81 # current SQLT SQLite producer does not handle DROP TABLE IF EXISTS, trap warnings here
82 local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /no such table.+DROP TABLE/s };
84 my ($class, $schema_method) = @_;
86 my $method = "get_schema_$schema_method";
87 my $schema = $class->$method;
92 sub get_schema_by_storage_type {
93 DBICTest->init_schema(
96 '::DBI::Replicated' => {
97 balancer_type=>'::Random',
99 auto_validate_every=>100,
100 master_read_weight => 1
110 sub get_schema_by_connect_info {
111 DBICTest->init_schema(
112 sqlite_use_file => 1,
113 storage_type=> '::DBI::Replicated',
114 balancer_type=>'::Random',
116 auto_validate_every=>100,
117 master_read_weight => 1
128 sub generate_replicant_connect_info {}
132 ## --------------------------------------------------------------------- ##
133 ## Add a connect_info option to test option merging.
134 ## --------------------------------------------------------------------- ##
136 package DBIx::Class::Storage::DBI::Replicated;
140 __PACKAGE__->meta->make_mutable;
142 around connect_info => sub {
143 my ($next, $self, $info) = @_;
144 $info->[3]{master_option} = 1;
148 __PACKAGE__->meta->make_immutable;
153 ## --------------------------------------------------------------------- ##
154 ## Subclass for when you are using SQLite for testing, this provides a fake
155 ## replication support.
156 ## --------------------------------------------------------------------- ##
158 package DBIx::Class::DBI::Replicated::TestReplication::SQLite;
162 use base 'DBIx::Class::DBI::Replicated::TestReplication';
164 __PACKAGE__->mk_accessors(qw/master_path slave_paths/);
166 ## Set the master path from DBICTest
169 my $class = shift @_;
170 my $self = $class->SUPER::new(@_);
172 $self->master_path( DBICTest->_sqlite_dbfilename );
174 File::Spec->catfile(qw/t var DBIxClass_slave1.db/),
175 File::Spec->catfile(qw/t var DBIxClass_slave2.db/),
181 ## Return an Array of ArrayRefs where each ArrayRef is suitable to use for
182 ## $storage->connect_info to be used for connecting replicants.
184 sub generate_replicant_connect_info {
188 } @{$self->slave_paths};
190 my @connect_infos = map { [$_,'','',{AutoCommit=>1}] } @dsn;
192 ## Make sure nothing is left over from a failed test
196 my $c = $connect_infos[0];
197 $connect_infos[0] = {
207 ## Do a 'good enough' replication by copying the master dbfile over each of
208 ## the slave dbfiles. If the master is SQLite we do this, otherwise we
209 ## just do a one second pause to let the slaves catch up.
213 foreach my $slave (@{$self->slave_paths}) {
214 copy($self->master_path, $slave);
218 ## Cleanup after ourselves. Unlink all gthe slave paths.
222 foreach my $slave (@{$self->slave_paths}) {
229 ## --------------------------------------------------------------------- ##
230 ## Subclass for when you are setting the databases via custom export vars
231 ## This is for when you have a replicating database setup that you are
232 ## going to test against. You'll need to define the correct $ENV and have
233 ## two slave databases to test against, as well as a replication system
234 ## that will replicate in less than 1 second.
235 ## --------------------------------------------------------------------- ##
237 package DBIx::Class::DBI::Replicated::TestReplication::Custom;
238 use base 'DBIx::Class::DBI::Replicated::TestReplication';
240 ## Return an Array of ArrayRefs where each ArrayRef is suitable to use for
241 ## $storage->connect_info to be used for connecting replicants.
243 sub generate_replicant_connect_info {
245 [$ENV{"DBICTEST_SLAVE0_DSN"}, $ENV{"DBICTEST_SLAVE0_DBUSER"}, $ENV{"DBICTEST_SLAVE0_DBPASS"}, {AutoCommit => 1}],
246 [$ENV{"DBICTEST_SLAVE1_DSN"}, $ENV{"DBICTEST_SLAVE1_DBUSER"}, $ENV{"DBICTEST_SLAVE1_DBPASS"}, {AutoCommit => 1}],
250 ## pause a bit to let the replication catch up
257 ## ----------------------------------------------------------------------------
258 ## Create an object and run some tests
259 ## ----------------------------------------------------------------------------
261 ## Thi first bunch of tests are basic, just make sure all the bits are behaving
263 my $replicated_class = DBICTest->has_custom_dsn ?
264 'DBIx::Class::DBI::Replicated::TestReplication::Custom' :
265 'DBIx::Class::DBI::Replicated::TestReplication::SQLite';
269 for my $method (qw/by_connect_info by_storage_type/) {
271 ok $replicated = $replicated_class->new($method)
272 => "Created a replication object $method";
274 isa_ok $replicated->schema
275 => 'DBIx::Class::Schema';
277 isa_ok $replicated->schema->storage
278 => 'DBIx::Class::Storage::DBI::Replicated';
280 isa_ok $replicated->schema->storage->balancer
281 => 'DBIx::Class::Storage::DBI::Replicated::Balancer::Random'
282 => 'configured balancer_type';
285 ### check that all Storage::DBI methods are handled by ::Replicated
287 my @storage_dbi_methods = Class::MOP::Class
288 ->initialize('DBIx::Class::Storage::DBI')->get_all_method_names;
290 my @replicated_methods = DBIx::Class::Storage::DBI::Replicated->meta
291 ->get_all_method_names;
293 # remove constants and OTHER_CRAP
294 @storage_dbi_methods = grep !/^[A-Z_]+\z/, @storage_dbi_methods;
296 # remove CAG accessors
297 @storage_dbi_methods = grep !/_accessor\z/, @storage_dbi_methods;
299 # remove DBIx::Class (the root parent, with CAG and stuff) methods
300 my @root_methods = Class::MOP::Class->initialize('DBIx::Class')
301 ->get_all_method_names;
303 $count{$_}++ for (@storage_dbi_methods, @root_methods);
305 @storage_dbi_methods = grep $count{$_} != 2, @storage_dbi_methods;
308 my %storage_dbi_methods;
309 @storage_dbi_methods{@storage_dbi_methods} = ();
310 my %replicated_methods;
311 @replicated_methods{@replicated_methods} = ();
313 # remove ::Replicated-specific methods
314 for my $method (@replicated_methods) {
315 delete $replicated_methods{$method}
316 unless exists $storage_dbi_methods{$method};
318 @replicated_methods = keys %replicated_methods;
320 # check that what's left is implemented
322 $count{$_}++ for (@storage_dbi_methods, @replicated_methods);
324 if ((grep $count{$_} == 2, @storage_dbi_methods) == @storage_dbi_methods) {
325 pass 'all DBIx::Class::Storage::DBI methods implemented';
328 my @unimplemented = grep $count{$_} == 1, @storage_dbi_methods;
330 fail 'the following DBIx::Class::Storage::DBI methods are unimplemented: '
335 ok $replicated->schema->storage->meta
336 => 'has a meta object';
338 isa_ok $replicated->schema->storage->master
339 => 'DBIx::Class::Storage::DBI';
341 isa_ok $replicated->schema->storage->pool
342 => 'DBIx::Class::Storage::DBI::Replicated::Pool';
344 does_ok $replicated->schema->storage->balancer
345 => 'DBIx::Class::Storage::DBI::Replicated::Balancer';
347 ok my @replicant_connects = $replicated->generate_replicant_connect_info
348 => 'got replication connect information';
350 ok my @replicated_storages = $replicated->schema->storage->connect_replicants(@replicant_connects)
351 => 'Created some storages suitable for replicants';
354 $replicated->schema->storage->debug(1);
355 $replicated->schema->storage->debugcb(sub {
356 my ($op, $info) = @_;
357 ##warn "\n$op, $info\n";
361 dsn => ($info=~m/\[(.+)\]/)[0],
362 storage_type => $info=~m/REPLICANT/ ? 'REPLICANT' : 'MASTER',
366 ok my @all_storages = $replicated->schema->storage->all_storages
369 is scalar @all_storages,
371 => 'correct number of ->all_storages';
373 is ((grep $_->isa('DBIx::Class::Storage::DBI'), @all_storages),
375 => '->all_storages are correct type');
377 my @all_storage_opts =
378 grep { (reftype($_)||'') eq 'HASH' }
379 map @{ $_->_connect_info }, @all_storages;
381 is ((grep $_->{master_option}, @all_storage_opts),
383 => 'connect_info was merged from master to replicants');
385 my @replicant_names = keys %{ $replicated->schema->storage->replicants };
387 ok @replicant_names, "found replicant names @replicant_names";
389 ## Silence warning about not supporting the is_replicating method if using the
391 $replicated->schema->storage->debugobj->silence(1)
392 if first { $_ =~ /$var_dir/ } @replicant_names;
394 isa_ok $replicated->schema->storage->balancer->current_replicant
395 => 'DBIx::Class::Storage::DBI';
397 $replicated->schema->storage->debugobj->silence(0);
399 ok $replicated->schema->storage->pool->has_replicants
400 => 'does have replicants';
402 is $replicated->schema->storage->pool->num_replicants => 2
403 => 'has two replicants';
405 does_ok $replicated_storages[0]
406 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
408 does_ok $replicated_storages[1]
409 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
411 does_ok $replicated->schema->storage->replicants->{$replicant_names[0]}
412 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
414 does_ok $replicated->schema->storage->replicants->{$replicant_names[1]}
415 => 'DBIx::Class::Storage::DBI::Replicated::Replicant';
417 ## Add some info to the database
421 ->populate('Artist', [
422 [ qw/artistid name/ ],
423 [ 4, "Ozric Tentacles"],
426 is $debug{storage_type}, 'MASTER',
427 "got last query from a master: $debug{dsn}";
429 like $debug{info}, qr/INSERT/, 'Last was an insert';
431 ## Make sure all the slaves have the table definitions
433 $replicated->replicate;
434 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
435 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
437 ## Silence warning about not supporting the is_replicating method if using the
439 $replicated->schema->storage->debugobj->silence(1)
440 if first { $_ =~ /$var_dir/ } @replicant_names;
442 $replicated->schema->storage->pool->validate_replicants;
444 $replicated->schema->storage->debugobj->silence(0);
446 ## Make sure we can read the data.
448 ok my $artist1 = $replicated->schema->resultset('Artist')->find(4)
451 ## We removed testing here since master read weight is on, so we can't tell in
452 ## advance what storage to expect. We turn master read weight off a bit lower
453 ## is $debug{storage_type}, 'REPLICANT'
454 ## => "got last query from a replicant: $debug{dsn}, $debug{info}";
457 => 'DBICTest::Artist';
459 is $artist1->name, 'Ozric Tentacles'
460 => 'Found expected name for first result';
462 ## Check that master_read_weight is honored
464 no warnings qw/once redefine/;
467 *DBIx::Class::Storage::DBI::Replicated::Balancer::Random::_random_number =
470 $replicated->schema->storage->balancer->increment_storage;
472 is $replicated->schema->storage->balancer->current_replicant,
473 $replicated->schema->storage->master
474 => 'master_read_weight is honored';
476 ## turn it off for the duration of the test
477 $replicated->schema->storage->balancer->master_read_weight(0);
478 $replicated->schema->storage->balancer->increment_storage;
481 ## Add some new rows that only the master will have This is because
482 ## we overload any type of write operation so that is must hit the master
487 ->populate('Artist', [
488 [ qw/artistid name/ ],
489 [ 5, "Doom's Children"],
490 [ 6, "Dead On Arrival"],
494 is $debug{storage_type}, 'MASTER',
495 "got last query from a master: $debug{dsn}";
497 like $debug{info}, qr/INSERT/, 'Last was an insert';
499 ## Make sure all the slaves have the table definitions
500 $replicated->replicate;
502 ## Should find some data now
504 ok my $artist2 = $replicated->schema->resultset('Artist')->find(5)
507 is $debug{storage_type}, 'REPLICANT'
508 => "got last query from a replicant: $debug{dsn}";
511 => 'DBICTest::Artist';
513 is $artist2->name, "Doom's Children"
514 => 'Found expected name for first result';
516 ## What happens when we disconnect all the replicants?
518 is $replicated->schema->storage->pool->connected_replicants => 2
519 => "both replicants are connected";
521 $replicated->schema->storage->replicants->{$replicant_names[0]}->disconnect;
522 $replicated->schema->storage->replicants->{$replicant_names[1]}->disconnect;
524 is $replicated->schema->storage->pool->connected_replicants => 0
525 => "both replicants are now disconnected";
527 ## All these should pass, since the database should automatically reconnect
529 ok my $artist3 = $replicated->schema->resultset('Artist')->find(6)
530 => 'Still finding stuff.';
532 is $debug{storage_type}, 'REPLICANT'
533 => "got last query from a replicant: $debug{dsn}";
536 => 'DBICTest::Artist';
538 is $artist3->name, "Dead On Arrival"
539 => 'Found expected name for first result';
541 is $replicated->schema->storage->pool->connected_replicants => 1
542 => "At Least One replicant reconnected to handle the job";
544 ## What happens when we try to select something that doesn't exist?
546 ok ! $replicated->schema->resultset('Artist')->find(666)
547 => 'Correctly failed to find something.';
549 is $debug{storage_type}, 'REPLICANT'
550 => "got last query from a replicant: $debug{dsn}";
552 ## test the reliable option
556 $replicated->schema->storage->set_reliable_storage;
558 ok $replicated->schema->resultset('Artist')->find(2)
559 => 'Read from master 1';
561 is $debug{storage_type}, 'MASTER',
562 "got last query from a master: $debug{dsn}";
564 ok $replicated->schema->resultset('Artist')->find(5)
565 => 'Read from master 2';
567 is $debug{storage_type}, 'MASTER',
568 "got last query from a master: $debug{dsn}";
570 $replicated->schema->storage->set_balanced_storage;
572 ok $replicated->schema->resultset('Artist')->find(3)
573 => 'Read from replicant';
575 is $debug{storage_type}, 'REPLICANT',
576 "got last query from a replicant: $debug{dsn}";
579 ## Make sure when reliable goes out of scope, we are using replicants again
581 ok $replicated->schema->resultset('Artist')->find(1)
582 => 'back to replicant 1.';
584 is $debug{storage_type}, 'REPLICANT',
585 "got last query from a replicant: $debug{dsn}";
587 ok $replicated->schema->resultset('Artist')->find(2)
588 => 'back to replicant 2.';
590 is $debug{storage_type}, 'REPLICANT',
591 "got last query from a replicant: $debug{dsn}";
593 ## set all the replicants to inactive, and make sure the balancer falls back to
596 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
597 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
600 ## catch the fallback to master warning
601 open my $debugfh, '>', \my $fallback_warning;
602 my $oldfh = $replicated->schema->storage->debugfh;
603 $replicated->schema->storage->debugfh($debugfh);
605 ok $replicated->schema->resultset('Artist')->find(2)
606 => 'Fallback to master';
608 is $debug{storage_type}, 'MASTER',
609 "got last query from a master: $debug{dsn}";
611 like $fallback_warning, qr/falling back to master/
612 => 'emits falling back to master debug';
614 $replicated->schema->storage->debugfh($oldfh);
617 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
618 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
620 ## Silence warning about not supporting the is_replicating method if using the
622 $replicated->schema->storage->debugobj->silence(1)
623 if first { $_ =~ /$var_dir/ } @replicant_names;
625 $replicated->schema->storage->pool->validate_replicants;
627 $replicated->schema->storage->debugobj->silence(0);
630 ## catch the fallback to master warning
631 open my $debugfh, '>', \my $return_warning;
632 my $oldfh = $replicated->schema->storage->debugfh;
633 $replicated->schema->storage->debugfh($debugfh);
635 ok $replicated->schema->resultset('Artist')->find(2)
636 => 'Return to replicants';
638 is $debug{storage_type}, 'REPLICANT',
639 "got last query from a replicant: $debug{dsn}";
641 like $return_warning, qr/Moved back to slave/
642 => 'emits returning to slave debug';
644 $replicated->schema->storage->debugfh($oldfh);
647 ## Getting slave status tests
650 ## We skip this tests unless you have a custom replicants, since the default
651 ## sqlite based replication tests don't support these functions.
653 skip 'Cannot Test Replicant Status on Non Replicating Database', 10
654 unless DBICTest->has_custom_dsn && $ENV{"DBICTEST_SLAVE0_DSN"};
656 $replicated->replicate; ## Give the slaves a chance to catchup.
658 ok $replicated->schema->storage->replicants->{$replicant_names[0]}->is_replicating
659 => 'Replicants are replicating';
661 is $replicated->schema->storage->replicants->{$replicant_names[0]}->lag_behind_master, 0
662 => 'Replicant is zero seconds behind master';
664 ## Test the validate replicants
666 $replicated->schema->storage->pool->validate_replicants;
668 is $replicated->schema->storage->pool->active_replicants, 2
669 => 'Still have 2 replicants after validation';
671 ## Force the replicants to fail the validate test by required their lag to
672 ## be negative (ie ahead of the master!)
674 $replicated->schema->storage->pool->maximum_lag(-10);
675 $replicated->schema->storage->pool->validate_replicants;
677 is $replicated->schema->storage->pool->active_replicants, 0
678 => 'No way a replicant be be ahead of the master';
680 ## Let's be fair to the replicants again. Let them lag up to 5
682 $replicated->schema->storage->pool->maximum_lag(5);
683 $replicated->schema->storage->pool->validate_replicants;
685 is $replicated->schema->storage->pool->active_replicants, 2
686 => 'Both replicants in good standing again';
688 ## Check auto validate
690 is $replicated->schema->storage->balancer->auto_validate_every, 100
691 => "Got the expected value for auto validate";
693 ## This will make sure we auto validatge everytime
694 $replicated->schema->storage->balancer->auto_validate_every(0);
696 ## set all the replicants to inactive, and make sure the balancer falls back to
699 $replicated->schema->storage->replicants->{$replicant_names[0]}->active(0);
700 $replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
702 ## Ok, now when we go to run a query, autovalidate SHOULD reconnect
704 is $replicated->schema->storage->pool->active_replicants => 0
705 => "both replicants turned off";
707 ok $replicated->schema->resultset('Artist')->find(5)
708 => 'replicant reactivated';
710 is $debug{storage_type}, 'REPLICANT',
711 "got last query from a replicant: $debug{dsn}";
713 is $replicated->schema->storage->pool->active_replicants => 2
714 => "both replicants reactivated";
717 ## Test the reliably callback
719 ok my $reliably = sub {
721 ok $replicated->schema->resultset('Artist')->find(5)
722 => 'replicant reactivated';
724 is $debug{storage_type}, 'MASTER',
725 "got last query from a master: $debug{dsn}";
727 } => 'created coderef properly';
729 $replicated->schema->storage->execute_reliably($reliably);
731 ## Try something with an error
733 ok my $unreliably = sub {
735 ok $replicated->schema->resultset('ArtistXX')->find(5)
736 => 'replicant reactivated';
738 } => 'created coderef properly';
740 throws_ok {$replicated->schema->storage->execute_reliably($unreliably)}
741 qr/Can't find source for ArtistXX/
742 => 'Bad coderef throws proper error';
744 ## Make sure replication came back
746 ok $replicated->schema->resultset('Artist')->find(3)
747 => 'replicant reactivated';
749 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
751 ## make sure transactions are set to execute_reliably
753 ok my $transaction = sub {
759 ->populate('Artist', [
760 [ qw/artistid name/ ],
761 [ $id, "Children of the Grave $id"],
764 ok my $result = $replicated->schema->resultset('Artist')->find($id)
765 => "Found expected artist for $id";
767 is $debug{storage_type}, 'MASTER',
768 "got last query from a master: $debug{dsn}";
770 ok my $more = $replicated->schema->resultset('Artist')->find(1)
771 => 'Found expected artist again for 1';
773 is $debug{storage_type}, 'MASTER',
774 "got last query from a master: $debug{dsn}";
776 return ($result, $more);
778 } => 'Created a coderef properly';
780 ## Test the transaction with multi return
782 ok my @return = $replicated->schema->txn_do($transaction, 666)
783 => 'did transaction';
785 is $return[0]->id, 666
786 => 'first returned value is correct';
788 is $debug{storage_type}, 'MASTER',
789 "got last query from a master: $debug{dsn}";
792 => 'second returned value is correct';
794 is $debug{storage_type}, 'MASTER',
795 "got last query from a master: $debug{dsn}";
799 ## Test that asking for single return works
801 ok my @return = $replicated->schema->txn_do($transaction, 777)
802 => 'did transaction';
804 is $return[0]->id, 777
805 => 'first returned value is correct';
808 => 'second returned value is correct';
811 ## Test transaction returning a single value
814 ok my $result = $replicated->schema->txn_do(sub {
815 ok my $more = $replicated->schema->resultset('Artist')->find(1)
816 => 'found inside a transaction';
817 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
819 }) => 'successfully processed transaction';
822 => 'Got expected single result from transaction';
825 ## Make sure replication came back
827 ok $replicated->schema->resultset('Artist')->find(1)
828 => 'replicant reactivated';
830 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
832 ## Test Discard changes
835 ok my $artist = $replicated->schema->resultset('Artist')->find(2)
836 => 'got an artist to test discard changes';
838 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
840 ok $artist->get_from_storage({force_pool=>'master'})
841 => 'properly discard changes';
843 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
845 ok $artist->discard_changes({force_pool=>'master'})
846 => 'properly called discard_changes against master (manual attrs)';
848 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
850 ok $artist->discard_changes()
851 => 'properly called discard_changes against master (default attrs)';
853 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
855 ok $artist->discard_changes({force_pool=>$replicant_names[0]})
856 => 'properly able to override the default attributes';
858 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}"
861 ## Test some edge cases, like trying to do a transaction inside a transaction, etc
864 ok my $result = $replicated->schema->txn_do(sub {
865 return $replicated->schema->txn_do(sub {
866 ok my $more = $replicated->schema->resultset('Artist')->find(1)
867 => 'found inside a transaction inside a transaction';
868 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
871 }) => 'successfully processed transaction';
874 => 'Got expected single result from transaction';
878 ok my $result = $replicated->schema->txn_do(sub {
879 return $replicated->schema->storage->execute_reliably(sub {
880 return $replicated->schema->txn_do(sub {
881 return $replicated->schema->storage->execute_reliably(sub {
882 ok my $more = $replicated->schema->resultset('Artist')->find(1)
883 => 'found inside crazy deep transactions and execute_reliably';
884 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
889 }) => 'successfully processed transaction';
892 => 'Got expected single result from transaction';
895 ## Test the force_pool resultset attribute.
898 ok my $artist_rs = $replicated->schema->resultset('Artist')
899 => 'got artist resultset';
901 ## Turn on Forced Pool Storage
902 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>'master'})
903 => 'Created a resultset using force_pool storage';
905 ok my $artist = $reliable_artist_rs->find(2)
906 => 'got an artist result via force_pool storage';
908 is $debug{storage_type}, 'MASTER', "got last query from a master: $debug{dsn}";
911 ## Test the force_pool resultset attribute part two.
914 ok my $artist_rs = $replicated->schema->resultset('Artist')
915 => 'got artist resultset';
917 ## Turn on Forced Pool Storage
918 ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>$replicant_names[0]})
919 => 'Created a resultset using force_pool storage';
921 ok my $artist = $reliable_artist_rs->find(2)
922 => 'got an artist result via force_pool storage';
924 is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{dsn}";
926 ## Delete the old database files
927 $replicated->cleanup;