Merge 'trunk' into 'replication_dedux'
[dbsrgits/DBIx-Class.git] / t / 93storage_replication.t
index 5cbafef..2d1e58b 100644 (file)
@@ -13,7 +13,6 @@ BEGIN {
 
 use_ok 'DBIx::Class::Storage::DBI::Replicated::Pool';
 use_ok 'DBIx::Class::Storage::DBI::Replicated::Balancer';
-use_ok 'DBIx::Class::Storage::DBI::Replicated::Balancer::Random';
 use_ok 'DBIx::Class::Storage::DBI::Replicated::Replicant';
 use_ok 'DBIx::Class::Storage::DBI::Replicated';
 
@@ -49,10 +48,11 @@ TESTSCHEMACLASSES: {
     sub init_schema {
         my $class = shift @_;
         my $schema = DBICTest->init_schema(
-            storage_type=>'::DBI::Replicated', 
-            storage_type_args=>{
-               balancer_type=>'DBIx::Class::Storage::DBI::Replicated::Balancer::Random',
-            });
+            storage_type=>[
+               '::DBI::Replicated' => {
+                       balancer_type=>'::Random',
+               }],
+            );
 
         return $schema;
     }
@@ -310,18 +310,26 @@ TESTRELIABLE: {
     $replicated->schema->storage->set_balanced_storage;            
            
        ok $replicated->schema->resultset('Artist')->find(3)
-        => 'Read from replicant';      
+        => 'Read from replicant';
 }
 
-## Make sure when $reliable goes out of scope, we are using replicants again
+## Make sure when reliable goes out of scope, we are using replicants again
 
 ok $replicated->schema->resultset('Artist')->find(1)
     => 'back to replicant 1.';
     
 ok $replicated->schema->resultset('Artist')->find(2)
     => 'back to replicant 2.';
-    
 
+## set all the replicants to inactive, and make sure the balancer falls back to
+## the master.
+
+$replicated->schema->storage->replicants->{"t/var/DBIxClass_slave1.db"}->active(0);
+$replicated->schema->storage->replicants->{"t/var/DBIxClass_slave2.db"}->active(0);
+    
+ok $replicated->schema->resultset('Artist')->find(2)
+    => 'Fallback to master'; 
+       
 ## Delete the old database files
 $replicated->cleanup;