Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Add check for missing shard
Browse files Browse the repository at this point in the history
  • Loading branch information
braydonf committed Apr 26, 2017
1 parent 72464e1 commit 5a5e2a9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/bridge-client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,14 @@ BridgeClient.prototype.createFileStream = function(bucket, file, opt, cb) {
return done(err);
}

// When erasure encoding is implemented, this can just
// become a missing shard that is recovered.
for (var i = 0; i < pointers.length; i++) {
if (!pointers[i].farmer) {
return done(new Error('Missing shard'));
}
}

skip += limit;
done(null, pointers);
});
Expand Down
45 changes: 45 additions & 0 deletions test/bridge-client/index.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,51 @@ describe('BridgeClient', function() {
});
});

it('should error if farmer is missing to download', function(done) {
var client = new BridgeClient();
var _getFilePointers = sinon.stub(
client,
'getFilePointers'
);
_getFilePointers.onFirstCall().callsArgWith(1, null, [
{
size: 512,
farmer: {
address: '127.0.0.1',
port: 8080,
nodeID: utils.rmd160('nodeid')
}
},
{
size: 512,
}
]);
_getFilePointers.onSecondCall().callsArgWith(1, null, [
{
size: 512,
farmer: {
address: '127.0.0.1',
port: 8080,
nodeID: utils.rmd160('nodeid')
}
}
]);
sinon.stub(client, 'getFileInfo').callsArgWith(2, null, {
size: 512 * 3
});
_getFilePointers.onThirdCall().callsArgWith(1, null, []);
var _createToken = sinon.stub(
client,
'createToken'
).callsArgWith(2, null, 'token');
client.createFileStream('bucket', 'file', {}, function(err) {
_createToken.restore();
_getFilePointers.restore();
expect(err.message).to.equal('Missing shard');
done();
});
});

it('should emit stream error if slice cannot get token', function(done) {
var client = new BridgeClient();
var _getFilePointers = sinon.stub(
Expand Down

0 comments on commit 5a5e2a9

Please sign in to comment.