File tree Expand file tree Collapse file tree 2 files changed +40
-2
lines changed Expand file tree Collapse file tree 2 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ Cluster.prototype._replicateRawDB = function (sourceDB, targetDB) {
7979 } ) ;
8080} ;
8181
82- Cluster . prototype . _replicateDB = function ( sourceDB , targetDB ) {
82+ Cluster . prototype . _createAndReplicateDB = function ( sourceDB , targetDB ) {
8383 var self = this ;
8484 self . _log ( 'beginning replication of ' + sourceDB + '...' ) ;
8585 return self . _createDBIfMissing ( targetDB ) . then ( function ( ) {
@@ -88,8 +88,20 @@ Cluster.prototype._replicateDB = function (sourceDB, targetDB) {
8888 } ) . then ( function ( ) {
8989 return self . _replicateRawDB ( sourceDB , targetDB ) ;
9090 } ) . then ( function ( ) {
91- self . _log ( 'finished replicating ' + sourceDB ) ;
91+ return self . _log ( 'finished replicating ' + sourceDB ) ;
9292 } ) ;
9393} ;
9494
95+ Cluster . prototype . _replicateDB = function ( sourceDB , targetDB ) {
96+ var self = this ;
97+ return this . _sourceSlouch . db . exists ( sourceDB )
98+ . then ( function ( value ) {
99+ if ( value === true ) {
100+ return self . _createAndReplicateDB ( sourceDB , targetDB ) ;
101+ } else {
102+ self . _log ( 'Database does not exist, skipped replication. Database: ' , sourceDB ) ;
103+ }
104+ } ) ;
105+ } ;
106+
95107module . exports = Cluster ;
Original file line number Diff line number Diff line change @@ -290,4 +290,30 @@ describe('node and browser', function () {
290290 } ) ;
291291 } ) ;
292292
293+ it ( 'should check that the database still exists before calling replicate' , function ( ) {
294+ cluster = new Cluster ( {
295+ source : utils . couchDBURL ( ) ,
296+ target : utils . couchDBURL ( )
297+ } ) ;
298+
299+ var createAndReplicatedDB = false ;
300+ cluster . _createAndReplicateDB = function ( ) {
301+ createAndReplicatedDB = true ;
302+ } ;
303+
304+ // Perform replication when DBs exist to ensure that spy is working
305+ return cluster . _replicateDB ( 'db1' , 'db1' ) . then ( function ( ) {
306+ createAndReplicatedDB . should . eql ( false ) ;
307+
308+ // Reset the spy flag
309+ createAndReplicatedDB = false ;
310+ } ) . then ( function ( ) {
311+ // Attempt to replicate from a DB that no longer exists
312+ return cluster . _replicateDB ( 'aaa' , 'db1' ) ;
313+ } ) . then ( function ( ) {
314+ // Make sure we didn't try to actually replicate
315+ createAndReplicatedDB . should . eql ( false ) ;
316+ } ) ;
317+ } ) ;
318+
293319} ) ;
You can’t perform that action at this time.
0 commit comments