Skip to content

Commit

Permalink
Merge pull request #23 from Medium/nick-api
Browse files Browse the repository at this point in the history
Add an api for giving local-dynamo more heap
  • Loading branch information
nicks committed Jun 22, 2015
2 parents 12733a8 + 3228879 commit 28ee0a4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
52 changes: 42 additions & 10 deletions lib/launch.js
Expand Up @@ -8,28 +8,60 @@ 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')
var cmd = 'java'

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)
Expand Down
2 changes: 1 addition & 1 deletion 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": [
{
Expand Down

0 comments on commit 28ee0a4

Please sign in to comment.