Skip to content

Commit 088597d

Browse files
committed
complete mpu related tests migration
1 parent 610e873 commit 088597d

File tree

2 files changed

+140
-118
lines changed

2 files changed

+140
-118
lines changed
Lines changed: 107 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
const async = require('async');
22
const assert = require('assert');
3-
3+
const { CreateBucketCommand,
4+
CreateMultipartUploadCommand,
5+
UploadPartCommand,
6+
CompleteMultipartUploadCommand,
7+
PutObjectCommand,
8+
GetObjectCommand } = require('@aws-sdk/client-s3');
49
const { s3middleware } = require('arsenal');
510
const withV4 = require('../../support/withV4');
611
const BucketUtility = require('../../../lib/utility/bucket-util');
@@ -34,25 +39,23 @@ let bucketUtil;
3439

3540
function getCheck(key, bucketMatch, cb) {
3641
let azureKey = key;
37-
s3.getObject({ Bucket: azureContainerName, Key: azureKey }, (err, s3Res) => {
38-
assert.equal(err, null, `Err getting object from S3: ${err}`);
39-
assert.strictEqual(s3Res.ETag, `"${s3MD5}"`);
42+
s3.send(new GetObjectCommand({ Bucket: azureContainerName, Key: azureKey }))
43+
.then(s3Res => {
44+
assert.strictEqual(s3Res.ETag, `"${s3MD5}"`);
4045

41-
if (!bucketMatch) {
42-
azureKey = `${azureContainerName}/${key}`;
43-
}
44-
azureClient.getContainerClient(azureContainerName).getProperties(azureKey).then(
45-
azureRes => {
46-
assert.strictEqual(expectedContentLength, azureRes.contentLength);
47-
cb();
48-
},
49-
err => {
50-
assert.equal(err, null, `Err getting object from Azure: ${err}`);
51-
cb();
52-
});
53-
});
46+
if (!bucketMatch) {
47+
azureKey = `${azureContainerName}/${key}`;
48+
}
49+
return azureClient.getContainerClient(azureContainerName).getBlobClient(azureKey).getProperties();
50+
})
51+
.then(azureRes => {
52+
assert.strictEqual(expectedContentLength, azureRes.contentLength);
53+
cb();
54+
})
55+
.catch(err => {
56+
cb(err);
57+
});
5458
}
55-
5659
function mpuSetup(key, location, cb) {
5760
const partArray = [];
5861
async.waterfall([
@@ -62,16 +65,15 @@ function mpuSetup(key, location, cb) {
6265
Key: key,
6366
Metadata: { 'scal-location-constraint': location },
6467
};
65-
s3.createMultipartUpload(params, (err, res) => {
66-
if (err) {
67-
return next(err);
68-
}
69-
const uploadId = res.UploadId;
70-
assert(uploadId);
71-
assert.strictEqual(res.Bucket, azureContainerName);
72-
assert.strictEqual(res.Key, key);
73-
return next(null, uploadId);
74-
});
68+
s3.send(new CreateMultipartUploadCommand(params))
69+
.then(res => {
70+
const uploadId = res.UploadId;
71+
assert(uploadId);
72+
assert.strictEqual(res.Bucket, azureContainerName);
73+
assert.strictEqual(res.Key, key);
74+
return next(null, uploadId);
75+
})
76+
.catch(next);
7577
},
7678
(uploadId, next) => {
7779
const partParams = {
@@ -81,13 +83,12 @@ function mpuSetup(key, location, cb) {
8183
UploadId: uploadId,
8284
Body: smallBody,
8385
};
84-
s3.uploadPart(partParams, (err, res) => {
85-
if (err) {
86-
return next(err);
87-
}
88-
partArray.push({ ETag: res.ETag, PartNumber: 1 });
89-
return next(null, uploadId);
90-
});
86+
s3.send(new UploadPartCommand(partParams))
87+
.then(res => {
88+
partArray.push({ ETag: res.ETag, PartNumber: 1 });
89+
return next(null, uploadId);
90+
})
91+
.catch(next);
9192
},
9293
(uploadId, next) => {
9394
const partParams = {
@@ -97,18 +98,19 @@ function mpuSetup(key, location, cb) {
9798
UploadId: uploadId,
9899
Body: bigBody,
99100
};
100-
s3.uploadPart(partParams, (err, res) => {
101-
if (err) {
102-
return next(err);
103-
}
104-
partArray.push({ ETag: res.ETag, PartNumber: 2 });
105-
return next(null, uploadId);
106-
});
101+
s3.send(new UploadPartCommand(partParams))
102+
.then(res => {
103+
partArray.push({ ETag: res.ETag, PartNumber: 2 });
104+
return next(null, uploadId);
105+
})
106+
.catch(next);
107107
},
108108
], (err, uploadId) => {
109+
if (err) {
110+
return cb(err);
111+
}
109112
process.stdout.write('Created MPU and put two parts\n');
110-
assert.equal(err, null, `Err setting up MPU: ${err}`);
111-
cb(uploadId, partArray);
113+
return cb(uploadId, partArray);
112114
});
113115
}
114116

@@ -121,7 +123,7 @@ function testSuite() {
121123
bucketUtil = new BucketUtility('default', sigCfg);
122124
s3 = bucketUtil.s3;
123125
this.currentTest.awsClient = awsS3;
124-
return s3.createBucket({ Bucket: azureContainerName }).promise()
126+
return s3.send(new CreateBucketCommand({ Bucket: azureContainerName }))
125127
.catch(err => {
126128
process.stdout.write(`Error creating bucket: ${err}\n`);
127129
throw err;
@@ -149,11 +151,12 @@ function testSuite() {
149151
UploadId: uploadId,
150152
MultipartUpload: { Parts: partArray },
151153
};
152-
s3.completeMultipartUpload(params, err => {
153-
assert.equal(err, null, `Err completing MPU: ${err}`);
154-
setTimeout(() => getCheck(this.test.key, true, done),
155-
azureTimeout);
156-
});
154+
s3.send(new CompleteMultipartUploadCommand(params))
155+
.then(() => {
156+
setTimeout(() => getCheck(this.test.key, true, done),
157+
azureTimeout);
158+
})
159+
.catch(done);
157160
});
158161
});
159162

@@ -167,24 +170,23 @@ function testSuite() {
167170
UploadId: uploadId,
168171
MultipartUpload: { Parts: partArray },
169172
};
170-
s3.completeMultipartUpload(params, err => {
171-
assert.equal(err, null, `Err completing MPU: ${err}`);
172-
setTimeout(() => getCheck(this.test.key, false, done),
173-
azureTimeout);
174-
});
173+
s3.send(new CompleteMultipartUploadCommand(params))
174+
.then(() => {
175+
setTimeout(() => getCheck(this.test.key, false, done),
176+
azureTimeout);
177+
})
178+
.catch(done);
175179
});
176180
});
177181

178182
it('should complete an MPU on Azure with same key as object put ' +
179183
'to file', function itFn(done) {
180184
const body = Buffer.from('I am a body', 'utf8');
181-
s3.putObject({
185+
s3.send(new PutObjectCommand({
182186
Bucket: azureContainerName,
183187
Key: this.test.key,
184188
Body: body,
185-
Metadata: { 'scal-location-constraint': fileLocation } },
186-
err => {
187-
assert.equal(err, null, `Err putting object to file: ${err}`);
189+
Metadata: { 'scal-location-constraint': fileLocation } })).then(() => {
188190
mpuSetup(this.test.key, azureLocation,
189191
(uploadId, partArray) => {
190192
const params = {
@@ -193,25 +195,24 @@ function testSuite() {
193195
UploadId: uploadId,
194196
MultipartUpload: { Parts: partArray },
195197
};
196-
s3.completeMultipartUpload(params, err => {
197-
assert.equal(err, null, `Err completing MPU: ${err}`);
198-
setTimeout(() => getCheck(this.test.key, true, done),
199-
azureTimeout);
200-
});
198+
s3.send(new CompleteMultipartUploadCommand(params))
199+
.then(() => {
200+
setTimeout(() => getCheck(this.test.key, true, done),
201+
azureTimeout);
202+
})
203+
.catch(done);
201204
});
202-
});
205+
}).catch(done);
203206
});
204207

205208
it('should complete an MPU on Azure with same key as object put ' +
206209
'to Azure', function itFn(done) {
207210
const body = Buffer.from('I am a body', 'utf8');
208-
s3.putObject({
211+
s3.send(new PutObjectCommand({
209212
Bucket: azureContainerName,
210213
Key: this.test.key,
211214
Body: body,
212-
Metadata: { 'scal-location-constraint': azureLocation } },
213-
err => {
214-
assert.equal(err, null, `Err putting object to Azure: ${err}`);
215+
Metadata: { 'scal-location-constraint': azureLocation } })).then(() => {
215216
mpuSetup(this.test.key, azureLocation,
216217
(uploadId, partArray) => {
217218
const params = {
@@ -220,10 +221,13 @@ function testSuite() {
220221
UploadId: uploadId,
221222
MultipartUpload: { Parts: partArray },
222223
};
223-
s3.completeMultipartUpload(params, err => {
224-
assert.equal(err, null, `Err completing MPU: ${err}`);
224+
s3.send(new CompleteMultipartUploadCommand(params)).then(() => {
225+
225226
setTimeout(() => getCheck(this.test.key, true, done),
226227
azureTimeout);
228+
}).catch(err => {
229+
assert.equal(err, null, `Err completing MPU: ${err}`);
230+
done(err);
227231
});
228232
});
229233
});
@@ -232,34 +236,42 @@ function testSuite() {
232236
it('should complete an MPU on Azure with same key as object put ' +
233237
'to AWS', function itFn(done) {
234238
const body = Buffer.from('I am a body', 'utf8');
235-
s3.putObject({
239+
s3.send(new PutObjectCommand({
236240
Bucket: azureContainerName,
237241
Key: this.test.key,
238242
Body: body,
239-
Metadata: { 'scal-location-constraint': awsLocation } },
240-
err => {
241-
assert.equal(err, null, `Err putting object to AWS: ${err}`);
242-
mpuSetup(this.test.key, azureLocation,
243-
(uploadId, partArray) => {
244-
const params = {
245-
Bucket: azureContainerName,
246-
Key: this.test.key,
247-
UploadId: uploadId,
248-
MultipartUpload: { Parts: partArray },
249-
};
250-
s3.completeMultipartUpload(params, err => {
251-
assert.equal(err, null, `Err completing MPU: ${err}`);
252-
// make sure object is gone from AWS
253-
setTimeout(() => {
254-
this.test.awsClient.getObject({ Bucket: awsBucket,
255-
Key: this.test.key }, err => {
256-
assert.strictEqual(err.code, 'NoSuchKey');
257-
getCheck(this.test.key, true, done);
258-
});
259-
}, azureTimeout);
243+
Metadata: { 'scal-location-constraint': awsLocation }
244+
}))
245+
.then(() => {
246+
mpuSetup(this.test.key, azureLocation,
247+
(uploadId, partArray) => {
248+
const params = {
249+
Bucket: azureContainerName,
250+
Key: this.test.key,
251+
UploadId: uploadId,
252+
MultipartUpload: { Parts: partArray },
253+
};
254+
s3.send(new CompleteMultipartUploadCommand(params))
255+
.then(() => {
256+
// make sure object is gone from AWS
257+
setTimeout(() => {
258+
this.test.awsClient.send(new GetObjectCommand({
259+
Bucket: awsBucket,
260+
Key: this.test.key
261+
}))
262+
.then(() => {
263+
done(new Error('Expected NoSuchKey error'));
264+
})
265+
.catch(err => {
266+
assert.strictEqual(err.name, 'NoSuchKey');
267+
getCheck(this.test.key, true, done);
268+
});
269+
}, azureTimeout);
270+
})
271+
.catch(done);
260272
});
261-
});
262-
});
273+
})
274+
.catch(done);
263275
});
264276
});
265277
});

0 commit comments

Comments
 (0)