Skip to content

Commit

Permalink
adding more replication (unstable)
Browse files Browse the repository at this point in the history
  • Loading branch information
fergiemcdowall committed Aug 16, 2014
1 parent 9d26385 commit 1a20595
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 11 deletions.
4 changes: 4 additions & 0 deletions lib/indexing/replicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ fs = require('fs');
exports.createSnapShot = function(indexes, callback) {
callback(indexes.createReadStream());
}

exports.replicateFromSnapShot = function(readStream, indexes, callback) {
callback('replicated');
}
27 changes: 19 additions & 8 deletions lib/search-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ deleter = require('./indexing/deleter.js'),
replicator = require('./indexing/replicator.js'),
searcher = require('./mapreduce/searcher.js'),
docGetter = require('./mapreduce/docGetter.js'),
indexes = level('si', {valueEncoding: 'json'}),
indexesMultiply = levelMultiply(indexes);
//docFreqIndex = level('df', {valueEncoding: 'json'});
//init functions
calibrater.getTotalDocs(indexes, function(totalDocs) {
searcher.setTotalDocs(totalDocs);
});
//end init
indexes,
indexesMultiply;

exports.open = function(path, callback) {
console.log(path);
indexes = level(path, {valueEncoding: 'json'});
indexesMultiply = levelMultiply(indexes);
calibrater.getTotalDocs(indexes, function(totalDocs) {
searcher.setTotalDocs(totalDocs);
callback('index opened');
});
}


exports.del = function(docID, callback) {
Expand Down Expand Up @@ -61,6 +65,13 @@ exports.tellMeAboutMySearchIndex = function(callback) {
});
};


exports.replicate = function(snapShotStream, callback) {
replicator.replicateFromSnapShot(snapShotStream, indexes, function(msg) {
callback(msg);
});
};

exports.createSnapShot = function(callback) {
replicator.createSnapShot(indexes, function(msg) {
callback(msg);
Expand Down
22 changes: 21 additions & 1 deletion test/spec/0indexing-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,37 @@ describe('indexing and search', function () {

var data = JSON.parse(fs.readFileSync('test/testdata/reuters-000.json'));


it('should open index', function () {
runs(function() {
this.openingMsg = '';
var that = this;
si.open('si', function(openingMsg) {
that.openingMsg = openingMsg;
});
});
waitsFor(function() {
return this.openingMsg != '';
}, 'message returned from search-index', 100000)
runs(function () {
expect(this.openingMsg).toEqual('index opened');
});
});


it('should index one file of test data', function () {
runs(function() {
this.indexingMsg = '';
var that = this;
console.log('also in here');
si.add(data, 'reuters-000.json', ['places'], function(indexingMsg) {
console.log('in here');
that.indexingMsg = indexingMsg;
});
});
waitsFor(function() {
return this.indexingMsg != '';
}, 'indexingMsg not to be empty (search results returned)', 100000)
}, 'indexingMsg not to be empty (search results returned)', 30000)
runs(function () {
expect(this.indexingMsg).toEqual('[success] indexed batch: reuters-000.json');
});
Expand Down
1 change: 0 additions & 1 deletion test/spec/1searching-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var si = require('../../lib/search-index.js');

describe('indexing and search', function () {

var data = JSON.parse(fs.readFileSync('test/testdata/reuters-000.json'));

it('should be able to search in indexed data', function () {
runs(function () {
Expand Down
44 changes: 43 additions & 1 deletion test/spec/5replication-spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,52 @@
var fs = require('fs');
var logger = require('../../lib/logger.js');
var si = require('../../lib/search-index.js');
var sitwo = require('../../lib/search-index.js');
var level = require('level');
var newindexes = level('newsi', {valueEncoding: 'json'});


describe('replication', function () {
it('should be able to create a readStream', function () {

it('should open a new index', function () {
runs(function() {
this.openingMsg = '';
var that = this;
sitwo.open('sitwo', function(openingMsg) {
that.openingMsg = openingMsg;
});
});
waitsFor(function() {
return this.openingMsg != '';
}, 'message returned from search-index', 100000)
runs(function () {
expect(this.openingMsg).toEqual('index opened');
});
});


it('should be able to create a snapshot', function () {
runs(function () {
this.indexPiped = false;
var that = this;
si.createSnapShot(function(rs) {
var ws = newindexes.createWriteStream();
rs.pipe(ws).on('close', function(){
console.log('index piped');
that.indexPiped = true;
});
});
});
waitsFor(function() {
return this.indexPiped;
}, 'waiting for search results', 60000)
runs(function() {
expect(this.indexPiped).toEqual(true);
});
});


it('should be able to replicate from a snapshot', function () {
runs(function () {
this.indexPiped = false;
var that = this;
Expand All @@ -25,5 +65,7 @@ describe('replication', function () {
expect(this.indexPiped).toEqual(true);
});
});


});

0 comments on commit 1a20595

Please sign in to comment.