diff --git a/app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts b/app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts index dfb026f42ef7575b1163e35c4f98419cc79ef9ac..7c9117cdbb98ab0044c1028ea2b2dcae2cd797b5 100644 --- a/app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts +++ b/app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts @@ -345,7 +345,16 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry> * Allow to get internal index, for unit test (see test triming-dal.ts) */ getInternalIndexes(): LevelDBTable<any>[] { - return [this.indexForTrimming, this.indexForConditions, this.indexForConditions, this.indexOfComplexeConditionForPubkeys]; + return [this.indexForTrimming, this.indexForConditions, this.indexForConsumed, this.indexOfComplexeConditionForPubkeys]; + } + getIndexForTrimming(): LevelDBTable<any> { + return this.indexForTrimming + } + getIndexForConditions(): LevelDBTable<any> { + return this.indexForConditions + } + getIndexForConsumed(): LevelDBTable<any> { + return this.indexForConsumed } private async trimConditions(condition: string, id: string) { diff --git a/test/dal/triming-dal.ts b/test/dal/triming-dal.ts index 535dcff857f75a90e155d73ec42b6d9edd9df1e4..eafe4f0b62460a7b364fd8c6be56bc7ae96ee9fd 100644 --- a/test/dal/triming-dal.ts +++ b/test/dal/triming-dal.ts @@ -120,8 +120,8 @@ describe("Triming", function(){ await dal.sindexDAL.insertBatch([ { op: 'CREATE', identifier: 'SOURCE_1', pos: 4, written_on: '126-H', writtenOn: 126, written_time: 2000, consumed: false, conditions: 'COND(SOURCE_1)'}, { op: 'UPDATE', identifier: 'SOURCE_1', pos: 4, written_on: '139-H', writtenOn: 139, written_time: 4500, consumed: true, conditions: 'COND(SOURCE_1)'}, - { op: 'CREATE', identifier: 'SOURCE_2', pos: 4, written_on: '127-H', writtenOn: 127, written_time: 2500, consumed: false, conditions: 'COND(SOURCE_2)'}, - { op: 'CREATE', identifier: 'SOURCE_3', pos: 4, written_on: '127-H', writtenOn: 127, written_time: 2500, consumed: false, conditions: 'SIG(PUB_1)'} + { op: 'CREATE', identifier: 'SOURCE_2', pos: 4, written_on: '126-H', writtenOn: 126, written_time: 2500, consumed: false, conditions: 'COND(SOURCE_2)'}, + { op: 'CREATE', identifier: 'SOURCE_3', pos: 4, written_on: '126-H', writtenOn: 126, written_time: 2500, consumed: false, conditions: 'SIG(PUB_1)'} ] as any); (await dal.sindexDAL.findByIdentifier('SOURCE_1')).should.have.length(2); (await dal.sindexDAL.getAvailableForConditions('COND(SOURCE_2)')).should.have.length(1); @@ -141,13 +141,15 @@ describe("Triming", function(){ (await dal.sindexDAL.findByPos(4)).should.have.length(2); // Check internal index + should.not.exist(await sindexDAL.getIndexForConditions().getOrNull("COND(SOURCE_1)")); // The only source at this condition was trimmed + should.not.exist(await sindexDAL.getIndexForConsumed().getOrNull("0000000139")); // The only consumption at this block was trimmed + let entriesAt0000000126 = await sindexDAL.getIndexForTrimming().getOrNull("0000000126"); + // FIXME another issue here - for (let index of sindexDAL.getInternalIndexes()) { - const keys = await index.findAllKeys(); - keys.should.not.containEql("COND(SOURCE_1)"); - keys.should.not.containEql("0000000126"); - keys.should.not.containEql("0000000139"); - } + entriesAt0000000126.should.not.containEql('SOURCE_1-0000000004'); // This CREATE entry should have been trimmed + + let entriesAt0000000139 = await sindexDAL.getIndexForTrimming().getOrNull("0000000139"); + should.not.exist(entriesAt0000000139); // Now we consume all sources await dal.sindexDAL.insertBatch([