Skip to content

Commit

Permalink
Refactor to add setup/cleanup methods (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeharder authored Oct 8, 2019
1 parent c8a755b commit 64ddc98
Show file tree
Hide file tree
Showing 23 changed files with 406 additions and 285 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<ServerGarbageCollection>true</ServerGarbageCollection>
</PropertyGroup>

<ItemGroup>
<Compile Remove="out\**" />
<EmbeddedResource Remove="out\**" />
<None Remove="out\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.0.0-preview.3" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.0.1" />
Expand Down
6 changes: 6 additions & 0 deletions net/Azure.Storage.Blobs.PerfStress/Core/CircularStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,11 @@ public override void Write(byte[] buffer, int offset, int count)
{
throw new NotImplementedException();
}

protected override void Dispose(bool disposing)
{
_innerStream.Dispose();
base.Dispose(disposing);
}
}
}
36 changes: 36 additions & 0 deletions net/Azure.Storage.Blobs.PerfStress/Core/ContainerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Azure.Test.PerfStress;
using System;
using System.Threading.Tasks;

namespace Azure.Storage.Blobs.PerfStress.Core
{
public abstract class ContainerTest<TOptions> : ServiceTest<TOptions> where TOptions : PerfStressOptions
{
private const string _containerPrefix = "perfstress";
protected static string ContainerName { get; private set; }

static ContainerTest()
{
ContainerName = _containerPrefix + "-" + Guid.NewGuid().ToString();
}

protected BlobContainerClient BlobContainerClient { get; private set; }

public ContainerTest(TOptions options) : base(options)
{
BlobContainerClient = BlobServiceClient.GetBlobContainerClient(ContainerName);
}

public override async Task GlobalSetup()
{
await base.GlobalSetup();
await BlobContainerClient.CreateAsync();
}

public override async Task GlobalCleanup()
{
await BlobContainerClient.DeleteAsync();
await base.GlobalCleanup();
}
}
}
37 changes: 37 additions & 0 deletions net/Azure.Storage.Blobs.PerfStress/Core/ContainerV11Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Azure.Test.PerfStress;
using Microsoft.Azure.Storage.Blob;
using System;
using System.Threading.Tasks;

namespace Azure.Storage.Blobs.PerfStress.Core
{
public abstract class ContainerV11Test<TOptions> : ServiceV11Test<TOptions> where TOptions: PerfStressOptions
{
private const string _containerPrefix = "perfstress";
protected static string ContainerName { get; private set; }

static ContainerV11Test()
{
ContainerName = _containerPrefix + "-" + Guid.NewGuid().ToString();
}

protected CloudBlobContainer CloudBlobContainer { get; private set; }

public ContainerV11Test(TOptions options) : base(options)
{
CloudBlobContainer = CloudBlobClient.GetContainerReference(ContainerName);
}

public override async Task GlobalSetup()
{
await base.GlobalSetup();
await CloudBlobContainer.CreateAsync();
}

public override async Task GlobalCleanup()
{
await CloudBlobContainer.DeleteAsync();
await base.GlobalCleanup();
}
}
}
11 changes: 11 additions & 0 deletions net/Azure.Storage.Blobs.PerfStress/Core/CountOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Azure.Test.PerfStress;
using CommandLine;

namespace Azure.Storage.Blobs.PerfStress.Core
{
public class CountOptions : PerfStressOptions
{
[Option('c', "count", Default = 100, HelpText = "Number of blobs")]
public int Count { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
using CommandLine;
using Azure.Storage.Common;
using CommandLine;

namespace Azure.Storage.Blobs.PerfStress.Core
{
public class ParallelTransferOptionsOptions : SizeOptions
{
private int? _maximumTransferLength;
private int? _maximumThreadCount;

[Option('l', "maximumTransferLength")]
public int? MaximumTransferLength { get; set; }
public int? MaximumTransferLength
{
get => _maximumTransferLength;
set
{
_maximumTransferLength = value;
UpdateParallelTransferOptions();
}
}

[Option('t', "maximumThreadCount")]
public int? MaximumThreadCount { get; set; }
public int? MaximumThreadCount
{
get => _maximumThreadCount;
set
{
_maximumThreadCount = value;
UpdateParallelTransferOptions();
}
}

public ParallelTransferOptions ParallelTransferOptions { get; private set; } = new ParallelTransferOptions();

private void UpdateParallelTransferOptions()
{
ParallelTransferOptions = new ParallelTransferOptions()
{
MaximumThreadCount = MaximumThreadCount,
MaximumTransferLength = MaximumTransferLength
};
}
}
}
18 changes: 0 additions & 18 deletions net/Azure.Storage.Blobs.PerfStress/Core/ParallelTransferTest.cs

This file was deleted.

24 changes: 0 additions & 24 deletions net/Azure.Storage.Blobs.PerfStress/Core/RandomDataTest.cs

This file was deleted.

24 changes: 0 additions & 24 deletions net/Azure.Storage.Blobs.PerfStress/Core/RandomDataV11Test.cs

This file was deleted.

17 changes: 17 additions & 0 deletions net/Azure.Storage.Blobs.PerfStress/Core/RandomStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.IO;

namespace Azure.Storage.Blobs.PerfStress.Core
{
public static class RandomStream
{
private static readonly Lazy<byte[]> _randomBytes = new Lazy<byte[]>(() =>
{
var randomData = new byte[1024 * 1024];
(new Random(0)).NextBytes(randomData);
return randomData;
});

public static Stream Create(long size) => new CircularStream(new MemoryStream(_randomBytes.Value, writable: false), size);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,12 @@

namespace Azure.Storage.Blobs.PerfStress
{
public abstract class StorageTest<TOptions> : PerfStressTest<TOptions> where TOptions: PerfStressOptions
public abstract class ServiceTest<TOptions> : PerfStressTest<TOptions> where TOptions: PerfStressOptions
{
private const string _containerName = "perfstress";

protected BlobServiceClient BlobServiceClient { get; private set; }

protected BlobContainerClient BlobContainerClient { get; private set; }

protected BlobClient BlobClient { get; private set; }

public StorageTest(string id, TOptions options) : base(id, options)
public ServiceTest(TOptions options) : base(options)
{
var blobName = this.GetType().Name.ToLowerInvariant() + id;
var connectionString = Environment.GetEnvironmentVariable("STORAGE_CONNECTION_STRING");

if (string.IsNullOrEmpty(connectionString))
Expand All @@ -33,17 +26,6 @@ public StorageTest(string id, TOptions options) : base(id, options)
blobClientOptions.Transport = new HttpClientTransport(httpClient);

BlobServiceClient = new BlobServiceClient(connectionString, blobClientOptions);
try
{
BlobServiceClient.CreateBlobContainer(_containerName);
}
catch (StorageRequestFailedException)
{
}

BlobContainerClient = BlobServiceClient.GetBlobContainerClient(_containerName);

BlobClient = BlobContainerClient.GetBlobClient(blobName);
}
}
}
27 changes: 27 additions & 0 deletions net/Azure.Storage.Blobs.PerfStress/Core/ServiceV11Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Azure.Test.PerfStress;
using Microsoft.Azure.Storage;
using Microsoft.Azure.Storage.Blob;
using System;

namespace Azure.Storage.Blobs.PerfStress.Core
{
public abstract class ServiceV11Test<TOptions> : PerfStressTest<TOptions> where TOptions : PerfStressOptions
{
protected CloudBlobClient CloudBlobClient { get; private set; }

public ServiceV11Test(TOptions options) : base(options)
{
var connectionString = Environment.GetEnvironmentVariable("STORAGE_CONNECTION_STRING");

if (string.IsNullOrEmpty(connectionString))
{
throw new InvalidOperationException("Undefined environment variable STORAGE_CONNECTION_STRING");
}

CloudStorageAccount.TryParse(connectionString, out var storageAccount);


CloudBlobClient = storageAccount.CreateCloudBlobClient();
}
}
}
43 changes: 0 additions & 43 deletions net/Azure.Storage.Blobs.PerfStress/Core/StorageV11Test.cs

This file was deleted.

Loading

0 comments on commit 64ddc98

Please sign in to comment.