Skip to content

Commit

Permalink
[Closes #5] added fileSystem.getKeysUnder
Browse files Browse the repository at this point in the history
Callback function does not return an err parameter and instead just
returns the keys or an empty array.
  • Loading branch information
doctorrustynelson committed Dec 21, 2014
1 parent 26066e7 commit 02d915e
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/banzai-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,13 @@ function Banzai( ){
} );

socket.on( 'getLocationsOf', function( key, callback ){
console.log( arguments );
callback( data_director.getLocations( key ) );
} );

socket.on( 'getKeysUnder', function( key, callback ){
callback( data_director.getChildrenOf( key ) );
} );

socket.on( 'err', function( msg ){
LOGGER.error( msg );
} );
Expand Down
17 changes: 17 additions & 0 deletions lib/data-director.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,23 @@ function DataDirector( ){
} );
};

this.getChildrenOf = function( key ){
key = deconstructKey( key );

var focused_data_map = data_map;

while( key.length > 0 ){
focused_data_map = focused_data_map[ key[ 0 ] ];
key = key.slice( 1 );
}

if( focused_data_map instanceof DataUnit ){
return [];
} else {
return Object.keys( focused_data_map );
}
};

this.lostLocation = function( location ){
primeStoreMap( location );
store_map[ location ].forEach( function( key ){
Expand Down
4 changes: 4 additions & 0 deletions lib/file-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ function FileSystem( data_manager, banzai_socket ){
banzai_socket.emit( 'getLocationsOf', key, callback );
};

this.getKeysUnder = function( key, callback ){
banzai_socket.emit( 'getKeysUnder', key, callback );
};

}

module.exports = FileSystem;
22 changes: 22 additions & 0 deletions tests/config/temptest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{

"shenzi": {
"host": "localhost",
"port": 2102
},

"banzai": {
"host": "localhost",
"port": 2103,
"data": {
"replication": 1
}
},

"ed": {
"data": {
"location": "temp"
}
}

}
54 changes: 53 additions & 1 deletion tests/local-integration-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

var path = require( 'path' );
var config = require( '../lib/utils/config' );
config.reinitialize( path.resolve( __dirname, './config/test.config.json' ) );
config.reinitialize( path.resolve( __dirname, './config/temptest.config.json' ) );

var Shenzi = require( '../lib/shenzi-server.js' );
var Banzai = require( '../lib/banzai-server.js' );
Expand Down Expand Up @@ -323,6 +323,58 @@ module.exports.fileSystemTests = {
}
} );
} );
},

simpleGetKeysUnder: function( unit ){
var Crocuta = require( '../lib/client' );
var crocuta = new Crocuta( );

var timeout = setTimeout( function( ){
unit.ok( false, 'Test Timed Out.' );
crocuta.stop();
unit.done();
}, 10000 );

var job = crocuta.createJob( 'list' ).joule( function( ){
/* global done */
/* global input */
/* global fileSystem */

fileSystem.getKeysUnder( input, done );
} );

crocuta.onReady( function( ){
unit.ok( true, 'onReady fired.' );
crocuta.upload( 'input.zero', 'Hello Crocuta!', function( err ){
if( err ){
unit.ok( false, 'input failed to be uploaded.' );
clearTimeout( timeout );
crocuta.stop();
unit.done();
} else {
crocuta.upload( 'input.one', 'Bye Crocuta!', function( err ){
if( err ){
unit.ok( false, 'input failed to be uploaded.' );
clearTimeout( timeout );
crocuta.stop();
unit.done();
} else {
unit.ok( true, 'input was uploaded.' );
job.send( function( err, job ){
unit.ok( !err, 'No error on send' );
job.start( 'input', function( err, result ){
unit.deepEqual( result.sort(), [ 'one', 'zero' ], 'Job returned correct result.' );

clearTimeout( timeout );
crocuta.stop();
unit.done( );
} );
} );
}
} );
}
} );
} );
}
};

Expand Down
1 change: 0 additions & 1 deletion tests/test-data/input

This file was deleted.

0 comments on commit 02d915e

Please sign in to comment.