From 32288792f6ec61b4d4a167f7a6f1b6667888e0c9 Mon Sep 17 00:00:00 2001 From: Nick Santos Date: Mon, 22 Jun 2015 15:04:02 -0700 Subject: [PATCH] Add an api for giving local-dynamo more heap --- lib/launch.js | 52 +++++++++++++++++++++++++++++++++++++++++---------- package.json | 2 +- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/lib/launch.js b/lib/launch.js index 6f23f85..2d53fb9 100644 --- a/lib/launch.js +++ b/lib/launch.js @@ -8,11 +8,35 @@ var cp = require('child_process') var path = require('path') /** - * @param {?string} databaseDir The location of database files. Will run in memory if null. - * @param {number} port + * An options object: + * port: {number} - The port to run on. Required. + * dir: {?string=} - The location of database files. Optional Will run in-memory if null. + * heap: {?string=} - The amount of heap space, e.g., 512m. Uses JVM memory syntax. + * If not specified, uses JVM defaults. See: + * http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/java.html + * @typedef {Object} + */ +var Options; + +/** + * @param {?string|Options} options The options object. For backwards compatibility, + * accepts a string as the database dir. + * @param {=number} port The port. Prefer using the options object. * @return {ChildProcess} */ -function launch(databaseDir, port) { +function launch(options, port) { + if (typeof options == 'string') { + options = {dir: options} + } else { + options = options || {} + } + + options.port = options.port || port + + if (isNaN(options.port)) { + throw Error('Port required') + } + var opts = {env: process.env} var javaDir = path.join(__dirname, '..', 'aws_dynamodb_local') var libDir = path.join(javaDir, 'DynamoDBLocal_lib') @@ -20,16 +44,24 @@ function launch(databaseDir, port) { var args = [ '-Djava.library.path=' + libDir, - '-jar', - path.join(javaDir, 'DynamoDBLocal.jar'), - '--port', - port + '-server', ] - if (databaseDir === null) { - args.push('--inMemory') + if (options.heap) { + args.push('-Xmx=' + options.heap) + } + + args.push( + '-jar', + path.join(javaDir, 'DynamoDBLocal.jar'), + '--port', + options.port) + + + if (options.dir) { + opts.cwd = path.resolve(options.dir) } else { - opts.cwd = path.resolve(databaseDir) + args.push('--inMemory') } return cp.spawn(cmd, args, opts) diff --git a/package.json b/package.json index 91b4b5d..f5c1284 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "local-dynamo", "description": "A Node.js wrapper of AWS DynamoDB Local and utilities", - "version": "0.0.6", + "version": "0.1.0", "homepage": "https://github.com/Medium/local-dynamo", "licenses": [ {