Skip to content

Commit

Permalink
Add test showing non monotonicity of next shard iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafal Studnicki committed Mar 18, 2018
1 parent ac75b2d commit 078e994
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion test/getRecords.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var crypto = require('crypto'),
BigNumber = require('bignumber.js'),
helpers = require('./helpers')
helpers = require('./helpers'),
async = require('async')

var target = 'GetRecords',
request = helpers.request,
Expand Down Expand Up @@ -173,8 +174,42 @@ describe('getRecords', function() {
})
})

var getRecordsWithIterator = function(it, rs, callback) {
request(helpers.opts('GetRecords', {ShardIterator: it}),
function(err, res) {
datas = res.body.Records.map(function(r) { return r.Data; });
callback(err,
{it: res.body.NextShardIterator, rs: rs.concat(datas)});
});
};

describe('functionality', function() {

it('next shard iterator doesnt return duplicate of the same record', function(done) {
var stream = helpers.testStream
var record = {StreamName: stream, PartitionKey: 'a', Data: crypto.randomBytes(128).toString('base64')};
var shard = 'shardId-0';
request(helpers.opts('PutRecord', record), function(err, res) {
if(err) return done(err);
request(helpers.opts('GetShardIterator', {
StreamName: stream,
ShardId: shard,
ShardIteratorType: 'TRIM_HORIZON'
}), function(err, res) {
if(err) return done(err);
async.reduce([1,2,3,4,5], {rs: [], it: res.body.ShardIterator},
function(acc, i, callback) {
getRecordsWithIterator(acc.it, acc.rs, callback);
},
function(err, res) {
if(err) return done(err);
res.rs.should.eql([record.Data])
done();
});
});
});
});

it('should return correct AT_SEQUENCE_NUMBER and AFTER_SEQUENCE_NUMBER records', function(done) {
var hashKey1 = new BigNumber(2).pow(128).minus(1).toFixed(),
hashKey2 = new BigNumber(2).pow(128).div(3).floor().times(2).minus(1).toFixed(),
Expand Down

0 comments on commit 078e994

Please sign in to comment.