From 325fbb44953ceee89adf87bf08080f57bfb9b395 Mon Sep 17 00:00:00 2001 From: Alexander Chan Date: Fri, 10 Feb 2023 10:47:29 -0800 Subject: [PATCH] tests --- tests/functional/lifecycle/LifecycleTask.js | 72 ++++++++++++++++++--- 1 file changed, 63 insertions(+), 9 deletions(-) diff --git a/tests/functional/lifecycle/LifecycleTask.js b/tests/functional/lifecycle/LifecycleTask.js index cadbf34690..880993a2d7 100644 --- a/tests/functional/lifecycle/LifecycleTask.js +++ b/tests/functional/lifecycle/LifecycleTask.js @@ -59,6 +59,7 @@ const FUTURE = new Date(CURRENT); FUTURE.setDate(FUTURE.getDate() + 5); const OWNER = 'testOwner'; +const ncd = 'NoncurrentDays'; class S3Helper { constructor(client) { @@ -394,6 +395,7 @@ class LifecycleBucketProcessorMock { this._producer = new ProducerMock(); this._kafkaBacklogMetrics = new KafkaBacklogMetricsMock(); this._kafkaBacklogMetrics.setProducer(this._producer); + this.ncvHeap = new Map(); // set test topic name ReplicationAPI.setDataMoverTopic('data-mover'); @@ -421,12 +423,14 @@ class LifecycleBucketProcessorMock { objectTasksTopic: 'object-tasks', kafkaBacklogMetrics: this._kafkaBacklogMetrics, log: this._log, + ncvHeap: this.ncvHeap, }; } reset() { this._producer.reset(); this._kafkaBacklogMetrics.reset(); + this.ncvHeap.clear(); } // NOTE: for triggering snapshot @@ -949,7 +953,7 @@ describe('lifecycle task functional tests', function dF() { async.waterfall([ next => s3Helper.setAndCreateBucket('test-bucket', next), next => s3Helper.setBucketLifecycleConfigurations([ - new LifecycleRule().addID('task-1').addNCVExpiration(2).build(), + new LifecycleRule().addID('task-1').addNCVExpiration(ncd, 2).build(), ], next), (data, next) => s3Helper.createVersions(2, next), next => s3.getBucketLifecycleConfiguration({ @@ -968,7 +972,7 @@ describe('lifecycle task functional tests', function dF() { }); }, next => s3Helper.setBucketLifecycleConfigurations([ - new LifecycleRule().addNCVExpiration(1).build(), + new LifecycleRule().addNCVExpiration(ncd, 1).build(), ], next), (data, next) => s3.getBucketLifecycleConfiguration({ Bucket: 'test-bucket', @@ -1347,7 +1351,7 @@ describe('lifecycle task functional tests', function dF() { message: 'should verify that NoncurrentVersionExpiration rule' + ' applies to each versioned object, no pagination', bucketLCRules: [ - new LifecycleRule().addID('task-1').addNCVExpiration(1).build(), + new LifecycleRule().addID('task-1').addNCVExpiration(ncd, 1).build(), ], scenarioFxn: 'createVersions', scenario: 2, @@ -1370,11 +1374,11 @@ describe('lifecycle task functional tests', function dF() { message: 'should verify that NoncurrentVersionExpiration rule' + ' applies to correct versions with pagination and prefix', bucketLCRules: [ - new LifecycleRule().addID('task-1').addNCVExpiration(3).build(), + new LifecycleRule().addID('task-1').addNCVExpiration(ncd, 3).build(), new LifecycleRule().addID('task-2').addPrefix('test/') - .addNCVExpiration(1).build(), + .addNCVExpiration(ncd, 1).build(), new LifecycleRule().addID('task-3').addPrefix('src/') - .addNCVExpiration(2).build(), + .addNCVExpiration(ncd, 2).build(), ], scenarioFxn: 'createVersions', scenario: 3, @@ -1398,9 +1402,9 @@ describe('lifecycle task functional tests', function dF() { ' applies to correct versions with tagging and pagination', bucketLCRules: [ new LifecycleRule().addID('task-1').addTag('key1', 'value1') - .addPrefix('src/').addNCVExpiration(1).build(), + .addPrefix('src/').addNCVExpiration(ncd, 1).build(), new LifecycleRule().addID('task-2').addTag('key2', 'value2') - .addNCVExpiration(2).build(), + .addNCVExpiration(ncd, 2).build(), ], scenarioFxn: 'createVersions', scenario: 3, @@ -1423,7 +1427,7 @@ describe('lifecycle task functional tests', function dF() { message: 'should verify that NoncurrentVersionExpiration rule' + ' applies to delete markers as well with pagination', bucketLCRules: [ - new LifecycleRule().addID('task-1').addNCVExpiration(1).build(), + new LifecycleRule().addID('task-1').addNCVExpiration(ncd, 1).build(), ], scenarioFxn: 'createDeleteMarkers', scenario: 2, @@ -1441,6 +1445,56 @@ describe('lifecycle task functional tests', function dF() { objectCount: 5, }, }, + // ncve: 1 day rule should expire with NewerNoncurrentVersion, no pagination + // should expire some + { + message: 'should verify that NoncurrentVersionExpiration rule' + + ' applies to each versioned object, no pagination', + bucketLCRules: [ + new LifecycleRule().addID('task-1').addNCVExpiration(ncd, 1).build(), + ], + scenarioFxn: 'createVersions', + scenario: 2, + bucketEntry: { + action: 'testing-ncve', + target: { + bucket: 'test-ncve', + owner: OWNER, + }, + details: {}, + }, + expected: { + objects: ['version-1', 'version-1'], + bucketCount: 0, + objectCount: 2, + }, + }, + // ncve: NewerNoncurrentVersion, pagination, tagging, should expire some + { + message: 'should verify that NoncurrentVersionExpiration rule' + + ' applies to correct versions with tagging and pagination', + bucketLCRules: [ + new LifecycleRule().addID('task-1').addTag('key1', 'value1') + .addPrefix('src/').addNCVExpiration(ncd, 1).build(), + new LifecycleRule().addID('task-2').addTag('key2', 'value2') + .addNCVExpiration(ncd, 2).build(), + ], + scenarioFxn: 'createVersions', + scenario: 3, + bucketEntry: { + action: 'testing-ncve', + target: { + bucket: 'test-ncve', + owner: OWNER, + }, + details: {}, + }, + expected: { + objects: Array(2).fill('src/obj-2'), + bucketCount: 5, + objectCount: 2, + }, + }, ].forEach(item => { it(item.message, done => { const params = {