Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit de27940
Showing
10 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.swp | ||
.DS_Store | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"laxcomma": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- "0.8" | ||
- "0.10" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Generated on 2013-09-15 using generator-nodejs 0.0.6 | ||
module.exports = function (grunt) { | ||
grunt.initConfig({ | ||
pkg: grunt.file.readJSON('package.json'), | ||
complexity: { | ||
generic: { | ||
src: ['app/**/*.js'], | ||
options: { | ||
errorsOnly: false, | ||
cyclometric: 6, // default is 3 | ||
halstead: 16, // default is 8 | ||
maintainability: 100 // default is 100 | ||
} | ||
} | ||
}, | ||
jshint: { | ||
all: [ | ||
'Gruntfile.js', | ||
'app/**/*.js', | ||
'test/**/*.js' | ||
], | ||
options: { | ||
jshintrc: '.jshintrc' | ||
} | ||
}, | ||
mochacli: { | ||
all: ['test/**/*.js'], | ||
options: { | ||
reporter: 'spec', | ||
ui: 'tdd' | ||
} | ||
}, | ||
watch: { | ||
js: { | ||
files: ['**/*.js'], | ||
tasks: ['default'], | ||
options: { | ||
nospawn: true | ||
} | ||
} | ||
} | ||
}); | ||
|
||
grunt.loadNpmTasks('grunt-complexity'); | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
grunt.loadNpmTasks('grunt-mocha-cli'); | ||
|
||
grunt.registerTask('test', ['complexity', 'jshint', 'mochacli', 'watch']); | ||
grunt.registerTask('ci', ['complexity', 'jshint', 'mochacli']); | ||
grunt.registerTask('default', ['test']); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Copyright (c) 2013, Eugene Ware | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
3. Neither the name of Eugene Ware nor the names of its contributors | ||
may be used to endorse or promote products derived from this software | ||
without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY EUGENE WARE ''AS IS'' AND ANY | ||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL EUGENE WARE BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# level-cluster | ||
|
||
Use consistent-hashing with hash-rings to distribute reads and writes across multiple multilevel nodes. | ||
|
||
[![build status](https://secure.travis-ci.org/eugeneware/level-cluster.png)](http://travis-ci.org/eugeneware/level-cluster) | ||
|
||
## Installation | ||
|
||
This module is installed via npm: | ||
|
||
``` bash | ||
$ npm install level-cluster | ||
``` | ||
|
||
## Example Usage | ||
|
||
``` js | ||
var levelCluster = require('level-cluster'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Ignore everything in this directory | ||
* | ||
# Except this file | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function () { | ||
return 'Hello, world'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "level-cluster", | ||
"version": "0.0.1", | ||
"description": "Use consistent-hashing with hash-rings to distribute reads and writes across multiple multilevel nodes.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node_modules/.bin/grunt ci" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/eugeneware/level-cluster" | ||
}, | ||
"keywords": [ | ||
"level", | ||
"levelup", | ||
"leveldb", | ||
"cluster", | ||
"hash", | ||
"clustering", | ||
"availability", | ||
"high-availability", | ||
"nosql", | ||
"datqbase", | ||
"node-hashring", | ||
"hashing", | ||
"consistent", | ||
"multilevel" | ||
], | ||
"author": "Eugene Ware <eugene@noblesamurai.com>", | ||
"license": "BSD-3-Clause", | ||
"bugs": { | ||
"url": "https://github.com/eugeneware/level-cluster/issues" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"expect.js": "~0.2.0", | ||
"grunt-contrib-jshint": "~0.6.4", | ||
"grunt-contrib-watch": "~0.5.3", | ||
"grunt": "~0.4.1", | ||
"grunt-mocha-cli": "~1.1.0", | ||
"grunt-complexity": "~0.1.3", | ||
"grunt-cli": "~0.1.9", | ||
"multilevel": "~5.5.0", | ||
"rimraf": "~2.2.2", | ||
"levelup": "~0.16.0", | ||
"bytewise": "~0.6.0", | ||
"leveldown": "~0.8.2", | ||
"after": "~0.8.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
var expect = require('expect.js'), | ||
multilevel = require('multilevel'), | ||
levelup = require('levelup'), | ||
net = require('net'), | ||
path = require('path'), | ||
bytewise = require('bytewise/hex'), | ||
rimraf = require('rimraf'), | ||
after = require('after'), | ||
levelCluster = require('..'); | ||
|
||
describe('level-cluster', function() { | ||
var dbPath = path.join(__dirname, '..', 'data'); | ||
|
||
it('should be able to spin up a multilevel instance', function(done) { | ||
var dbOptions = { keyEncoding: bytewise, valueEncoding: 'json' }; | ||
var db1Path = path.join(dbPath, 'db1'); | ||
rimraf.sync(db1Path); | ||
|
||
var serverDb = levelup(db1Path, dbOptions); | ||
net.createServer(function (con) { | ||
con.pipe(multilevel.server(serverDb)).pipe(con); | ||
}).listen(3000, connect); | ||
|
||
var clientDb; | ||
function connect(err) { | ||
if (err) return done(err); | ||
clientDb = multilevel.client(); | ||
var con = net.connect(3000); | ||
con.pipe(clientDb.createRpcStream()).pipe(con); | ||
clientDb.put(['mykey', 123], { please: 'work' }, get); | ||
} | ||
|
||
function get(err) { | ||
if (err) return done(err); | ||
clientDb.get(['mykey', 123], check); | ||
} | ||
|
||
function check(err, value) { | ||
if (err) return done(err); | ||
expect(value).to.eql({ please: 'work' }); | ||
cleanup(); | ||
} | ||
|
||
function cleanup() { | ||
var next = after(2, done); | ||
clientDb.close(next); | ||
serverDb.close(next); | ||
} | ||
}); | ||
}); |