Skip to content

Commit

Permalink
cleanup and expiration date adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ersan Bozduman committed Oct 19, 2023
1 parent 5317878 commit 46529db
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 37 deletions.
55 changes: 32 additions & 23 deletions Minio.Functional.Tests/FunctionalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,8 @@ internal static async Task PutGetStatEncryptedObject_Test2(IMinioClient minio)
aesEncryption.KeySize = 256;
aesEncryption.GenerateKey();
var ssec = new SSEC(aesEncryption.Key);

using (var filestream = rsg.GenerateStreamFromSeed(6 * MB))
Stream filestream;
await using ((filestream = rsg.GenerateStreamFromSeed(6 * MB)).ConfigureAwait(false))
{
var file_write_size = filestream.Length;

Expand All @@ -826,16 +826,18 @@ internal static async Task PutGetStatEncryptedObject_Test2(IMinioClient minio)
.WithServerSideEncryption(ssec)
.WithCallbackStream(async (stream, cancellationToken) =>
{
using var fileStream = File.Create(tempFileName);

await stream.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false);
await fileStream.DisposeAsync().ConfigureAwait(false);
Stream fileStream;
await using ((fileStream = File.Create(tempFileName)).ConfigureAwait(false))
{
await stream.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false);
await fileStream.DisposeAsync().ConfigureAwait(false);

var writtenInfo = new FileInfo(tempFileName);
file_read_size = writtenInfo.Length;
var writtenInfo = new FileInfo(tempFileName);
file_read_size = writtenInfo.Length;

Assert.AreEqual(file_write_size, file_read_size);
File.Delete(tempFileName);
Assert.AreEqual(file_write_size, file_read_size);
File.Delete(tempFileName);
}
});
var statObjectArgs = new StatObjectArgs()
.WithBucket(bucketName)
Expand All @@ -848,24 +850,26 @@ internal static async Task PutGetStatEncryptedObject_Test2(IMinioClient minio)
new MintLogger("PutGetStatEncryptedObject_Test2", putObjectSignature,
"Tests whether Put/Get/Stat multipart upload with encryption passes", TestStatus.PASS,
DateTime.Now - startTime, args: args).Log();
File.Delete(tempFileName);
await TearDown(minio, bucketName).ConfigureAwait(false);
}
catch (NotImplementedException ex)
{
new MintLogger("PutGetStatEncryptedObject_Test2", putObjectSignature,
"Tests whether Put/Get/Stat multipart upload with encryption passes", TestStatus.NA,
DateTime.Now - startTime, "", ex.Message, ex.ToString(), args).Log();
File.Delete(tempFileName);
await TearDown(minio, bucketName).ConfigureAwait(false);
throw;
}
catch (Exception ex)
{
new MintLogger("PutGetStatEncryptedObject_Test2", putObjectSignature,
"Tests whether Put/Get/Stat multipart upload with encryption passes", TestStatus.FAIL,
DateTime.Now - startTime, "", ex.Message, ex.ToString(), args).Log();
throw;
}
finally
{
File.Delete(tempFileName);
await TearDown(minio, bucketName).ConfigureAwait(false);
throw;
}
}

Expand Down Expand Up @@ -4871,18 +4875,20 @@ internal static async Task GetObject_3_OffsetLength_Tests(IMinioClient minio)

new MintLogger(testName, getObjectSignature, "Tests whether GetObject returns all the data",
TestStatus.PASS, DateTime.Now - startTime, args: args).Log();

if (File.Exists(tempFileName)) File.Delete(tempFileName);
if (File.Exists(tempSource)) File.Delete(tempSource);
await TearDown(minio, bucketName).ConfigureAwait(false);
}
catch (Exception ex)
{
new MintLogger(testName, getObjectSignature, "Tests whether GetObject returns all the data",
TestStatus.FAIL, DateTime.Now - startTime, ex.Message, ex.ToString(), args: args).Log();
throw;
}
finally
{

if (File.Exists(tempFileName)) File.Delete(tempFileName);
if (File.Exists(tempSource)) File.Delete(tempSource);
await TearDown(minio, bucketName).ConfigureAwait(false);
throw;
}
}
}
Expand Down Expand Up @@ -6055,11 +6061,12 @@ internal static async Task BucketLifecycleAsync_Test1(IMinioClient minio)
var expDate = baseDate.AddYears(1);
var exp = new Expiration(expDate);

var calculatedExpDate = expDate.AddDays(1).AddSeconds(-1).ToUniversalTime().Date;
var expInDays = (calculatedExpDate.ToLocalTime().Date - baseDate.Date).TotalDays;
var calcDateTime = DateTime.Parse(exp.ExpiryDate, null, DateTimeStyles.RoundtripKind);
var expInDays = (calcDateTime.Date - baseDate.ToUniversalTime().Date).TotalDays;

var rule1 = new LifecycleRule(null, "txt", exp, null,
new RuleFilter(null, "txt/", null), null, null, LifecycleRule.LifecycleRuleStatusEnabled);
var rule1 = new LifecycleRule(null, "txt", exp,
null, new RuleFilter(null, "txt/", null), null,
null, LifecycleRule.LifecycleRuleStatusEnabled);
rules.Add(rule1);
var lfc = new LifecycleConfiguration(rules);
try
Expand Down Expand Up @@ -6097,7 +6104,9 @@ internal static async Task BucketLifecycleAsync_Test1(IMinioClient minio)
Assert.IsTrue(lfcObj.Rules.Count > 0);
Assert.AreEqual(lfcObj.Rules.Count, lfc.Rules.Count);
var lfcDate = DateTime.Parse(lfcObj.Rules[0].Expiration.ExpiryDate, null, DateTimeStyles.RoundtripKind);
Assert.AreEqual((lfcDate.Date - baseDate.Date).TotalDays, expInDays);
var lfcExpInDays = (lfcDate.Date - baseDate.ToUniversalTime().Date).TotalDays;
Assert.AreEqual(lfcExpInDays, expInDays);

new MintLogger(nameof(BucketLifecycleAsync_Test1) + ".2", getBucketLifecycleSignature,
"Tests whether GetBucketLifecycleAsync passes", TestStatus.PASS, DateTime.Now - startTime,
args: args)
Expand Down
11 changes: 3 additions & 8 deletions Minio/ApiEndpoints/BucketOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,17 @@ public async Task<bool> BucketExistsAsync(BucketExistsArgs args, CancellationTok
var requestMessageBuilder = await this.CreateRequest(args).ConfigureAwait(false);
using var response =
await this.ExecuteTaskAsync(ResponseErrorHandlers, requestMessageBuilder,
cancellationToken: cancellationToken)
.ConfigureAwait(false);
cancellationToken: cancellationToken).ConfigureAwait(false);
if (response.Exception is not null &&
response.Exception.GetType() == typeof(BucketNotFoundException))
{
return false;
}
return false;
}
catch (InternalClientException ice)
{
if ((ice.ServerResponse is not null &&
HttpStatusCode.NotFound.Equals(ice.ServerResponse.StatusCode)) ||
HttpStatusCode.NotFound.Equals(ice.ServerResponse.StatusCode)) ||
ice.ServerResponse is null)
{
return false;
}
}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Result/ResponseResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ResponseResult(HttpRequestMessage request, Exception exception)
Exception = exception;
}

public Exception Exception { get; set;}
public Exception Exception { get; set; }
public HttpRequestMessage Request { get; }
public HttpResponseMessage Response { get; }

Expand Down
3 changes: 1 addition & 2 deletions Minio/Helper/OperationsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ private async Task GetObjectStreamAsync(GetObjectArgs args, CancellationToken ca
var requestMessageBuilder = await this.CreateRequest(args).ConfigureAwait(false);
using var response =
await this.ExecuteTaskAsync(ResponseErrorHandlers, requestMessageBuilder,
cancellationToken: cancellationToken)
.ConfigureAwait(false);
cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down
4 changes: 1 addition & 3 deletions Minio/RequestExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http.Headers;
using Microsoft.Win32;
using Minio.Credentials;
using Minio.DataModel;
using Minio.DataModel.Args;
Expand Down Expand Up @@ -62,7 +60,7 @@ internal static Task<ResponseResult> ExecuteTaskAsync(this IMinioClient minioCli
cancellationToken = timeoutTokenSource.Token;
}

responseResult = minioClient.ExecuteWithRetry(
responseResult = minioClient.ExecuteWithRetry(
async () => await minioClient.ExecuteTaskCoreAsync(errorHandlers, requestMessageBuilder,
isSts, cancellationToken).ConfigureAwait(false));
}
Expand Down

0 comments on commit 46529db

Please sign in to comment.