forked from minio/minio-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRetryHandlerTest.cs
88 lines (79 loc) · 2.78 KB
/
RetryHandlerTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Minio.Exceptions;
namespace Minio.Tests;
[TestClass]
public class RetryHandlerTest
{
[TestMethod]
public async Task TestRetryPolicyOnSuccess()
{
using var client = new MinioClient()
.WithEndpoint(TestHelper.Endpoint)
.WithCredentials(TestHelper.AccessKey, TestHelper.SecretKey)
.WithSSL()
.Build();
var invokeCount = 0;
client.WithRetryPolicy(
async callback =>
{
invokeCount++;
return await callback().ConfigureAwait(false);
});
var bktArgs = new BucketExistsArgs()
.WithBucket(Guid.NewGuid().ToString());
var result = await client.BucketExistsAsync(bktArgs).ConfigureAwait(false);
Assert.IsFalse(result);
Assert.AreEqual(invokeCount, 1);
}
[TestMethod]
public async Task TestRetryPolicyOnFailure()
{
using var client = new MinioClient()
.WithEndpoint(TestHelper.Endpoint)
.WithCredentials(TestHelper.AccessKey, TestHelper.SecretKey)
.WithSSL()
.Build();
var invokeCount = 0;
var retryCount = 3;
client.WithRetryPolicy(
async callback =>
{
Exception exception = null;
for (var i = 0; i < retryCount; i++)
{
invokeCount++;
try
{
return await callback().ConfigureAwait(false);
}
catch (BucketNotFoundException ex)
{
exception = ex;
}
}
throw exception;
});
var getObjectArgs = new GetObjectArgs()
.WithBucket(Guid.NewGuid().ToString())
.WithObject("aa")
.WithCallbackStream(s => { });
await Assert.ThrowsExceptionAsync<BucketNotFoundException>(
() => client.GetObjectAsync(getObjectArgs)).ConfigureAwait(false);
Assert.AreEqual(invokeCount, retryCount);
}
}