Skip to content

Commit

Permalink
ARSN-377 fix DelimiterNonCurrent and add a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-gramain committed Dec 14, 2023
1 parent 1bc3360 commit f7144b9
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 7 deletions.
7 changes: 3 additions & 4 deletions lib/algos/list/delimiterNonCurrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ class DelimiterNonCurrent extends DelimiterVersions {
// Overwrite keyHandler_SkippingVersions to include the last version from the previous listing.
// The creation (last-modified) date of this version will be the stale date for the following version.
// eslint-disable-next-line camelcase
keyHandler_SkippingVersions(key, value) {
const { key: nonversionedKey, versionId } = this.parseKey(key);
if (nonversionedKey === this.keyMarker) {
keyHandler_SkippingVersions(key, versionId, value) {
if (key === this.keyMarker) {
// since the nonversioned key equals the marker, there is
// necessarily a versionId in this key
const _versionId = versionId;
Expand All @@ -66,7 +65,7 @@ class DelimiterNonCurrent extends DelimiterVersions {
this.setState({
id: 1 /* NotSkipping */,
});
return this.handleKey(key, value);
return this.handleKey(key, versionId, value);
}

filter(obj) {
Expand Down
119 changes: 116 additions & 3 deletions tests/unit/algos/list/delimiterNonCurrent.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ function getListingKey(key, vFormat) {

let expectedParams;
if (v === 'v0') {
expectedParams = { gte: `premark${VID_SEP}`, lt: 'prf' };
expectedParams = { gte: `${keyMarker}${VID_SEP}`, lt: 'prf' };
} else {
expectedParams = [
{
gte: `${DbPrefixes.Master}premark${VID_SEP}`,
gte: `${DbPrefixes.Master}${keyMarker}${VID_SEP}`,
lt: `${DbPrefixes.Master}prf`,
},
{
gte: `${DbPrefixes.Version}premark${VID_SEP}`,
gte: `${DbPrefixes.Version}${keyMarker}${VID_SEP}`,
lt: `${DbPrefixes.Version}prf`,
},
];
Expand Down Expand Up @@ -389,5 +389,118 @@ function getListingKey(key, vFormat) {

assert.deepStrictEqual(delimiter.result(), expectedResult);
});

it('should end filtering if max keys reached', () => {
const delimiter = new DelimiterNonCurrent({ maxKeys: 1 }, fakeLogger, v);

const masterKey = 'key';

// filter delete marker
const versionId1 = 'version1';
const versionKey1 = `${masterKey}${VID_SEP}${versionId1}`;
const date1 = '1970-01-01T00:00:00.002Z';
const value1 = `{"versionId":"${versionId1}", "last-modified": "${date1}", "isDeleteMarker": true}`;

assert.strictEqual(delimiter.filter({
key: getListingKey(versionKey1, v),
value: value1,
}), FILTER_ACCEPT);

// filter second version
const versionId2 = 'version2';
const versionKey2 = `${masterKey}${VID_SEP}${versionId2}`;
const date2 = '1970-01-01T00:00:00.001Z';
const value2 = `{"versionId":"${versionId2}", "last-modified": "${date2}"}`;

assert.strictEqual(delimiter.filter({
key: getListingKey(versionKey2, v),
value: value2,
}), FILTER_ACCEPT);

// filter third version
const versionId3 = 'version3';
const versionKey3 = `${masterKey}${VID_SEP}${versionId3}`;
const date3 = '1970-01-01T00:00:00.000Z';
const value3 = `{"versionId":"${versionId3}", "last-modified": "${date3}"}`;

assert.strictEqual(delimiter.filter({
key: getListingKey(versionKey3, v),
value: value3,
}), FILTER_END);


const expectedResult = {
Contents: [
{
key: masterKey,
value: `{"versionId":"${versionId2}","last-modified":"${date2}","staleDate":"${date1}"}`,
},
],
IsTruncated: true,
NextKeyMarker: masterKey,
NextVersionIdMarker: versionId2,
};

assert.deepStrictEqual(delimiter.result(), expectedResult);
});

it('should return noncurrent versions starting from a marker', () => {
const delimiter = new DelimiterNonCurrent({
keyMarker: 'key',
versionIdMarker: 'version1',
}, fakeLogger, v);

const masterKey = 'key';

// filter first version
const versionId1 = 'version1';
const versionKey1 = `${masterKey}${VID_SEP}${versionId1}`;
const date1 = '1970-01-01T00:00:00.002Z';
const value1 = `{"versionId":"${versionId1}", "last-modified": "${date1}"}`;

assert.strictEqual(delimiter.filter({
key: getListingKey(versionKey1, v),
value: value1,
}), FILTER_ACCEPT);

// filter second version
const versionId2 = 'version2';
const versionKey2 = `${masterKey}${VID_SEP}${versionId2}`;
const date2 = '1970-01-01T00:00:00.001Z';
const value2 = `{"versionId":"${versionId2}", "last-modified": "${date2}"}`;

assert.strictEqual(delimiter.filter({
key: getListingKey(versionKey2, v),
value: value2,
}), FILTER_ACCEPT);

// filter third version
const versionId3 = 'version3';
const versionKey3 = `${masterKey}${VID_SEP}${versionId3}`;
const date3 = '1970-01-01T00:00:00.000Z';
const value3 = `{"versionId":"${versionId3}", "last-modified": "${date3}"}`;

assert.strictEqual(delimiter.filter({
key: getListingKey(versionKey3, v),
value: value3,
}), FILTER_ACCEPT);


const expectedResult = {
Contents: [
{
key: masterKey,
value: `{"versionId":"${versionId2}","last-modified":"${date2}","staleDate":"${date1}"}`,
},
{
key: masterKey,
value: `{"versionId":"${versionId3}","last-modified":"${date3}","staleDate":"${date2}"}`,
},
],
IsTruncated: false,
};

assert.deepStrictEqual(delimiter.result(), expectedResult);
});
});
});

0 comments on commit f7144b9

Please sign in to comment.