Skip to content

Commit

Permalink
Storage Internals Rename (Azure#13589)
Browse files Browse the repository at this point in the history
Renamed internal class StreamSlice to SlicedStream per naming guidelines.
Deleted a duplicate class from testing.
  • Loading branch information
jaschrep-msft authored Jul 20, 2020
1 parent 65d09d7 commit ce4638f
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<Compile Include="$(AzureStorageSharedSources)SasExtensions.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)SasQueryParametersInternals.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)SharedAccessSignatureCredentials.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)SlicedStream.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)StorageClientOptions.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)StorageConnectionString.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)StorageCollectionEnumerator.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
Expand All @@ -66,7 +67,6 @@
<Compile Include="$(AzureStorageSharedSources)StorageSharedKeyPipelinePolicy.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)StorageResponseClassifier.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)StorageVersionExtensions.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)StreamSlice.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)UriExtensions.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)UriQueryParamsCollection.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)UserDelegationKeyProperties.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
Expand Down
20 changes: 10 additions & 10 deletions sdk/storage/Azure.Storage.Common/src/Shared/PartitionedUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class PartitionedUploader<TServiceSpecificArgs, TCompleteUploadReturn>
{
#region Definitions
// delegte for getting a partition from a stream based on the selected data management stragegy
private delegate Task<StreamSlice> GetNextStreamPartition(
private delegate Task<SlicedStream> GetNextStreamPartition(
Stream stream,
long minCount,
long maxCount,
Expand Down Expand Up @@ -260,7 +260,7 @@ private async Task<Response<TCompleteUploadReturn>> UploadInSequenceInternal(
// Partition the stream into individual blocks and stage them
if (async)
{
await foreach (StreamSlice block in GetPartitionsAsync(
await foreach (SlicedStream block in GetPartitionsAsync(
content,
contentLength,
partitionSize,
Expand All @@ -281,7 +281,7 @@ await StagePartitionAndDisposeInternal(
}
else
{
foreach (StreamSlice block in GetPartitionsAsync(
foreach (SlicedStream block in GetPartitionsAsync(
content,
contentLength,
partitionSize,
Expand Down Expand Up @@ -350,7 +350,7 @@ private async Task<Response<TCompleteUploadReturn>> UploadInParallelAsync(
List<Task> runningTasks = new List<Task>();

// Partition the stream into individual blocks
await foreach (StreamSlice block in GetPartitionsAsync(
await foreach (SlicedStream block in GetPartitionsAsync(
content,
contentLength,
blockSize,
Expand Down Expand Up @@ -420,7 +420,7 @@ private async Task<Response<TCompleteUploadReturn>> UploadInParallelAsync(
/// Wraps both the async method and dispose call in one task.
/// </summary>
private async Task StagePartitionAndDisposeInternal(
StreamSlice partition,
SlicedStream partition,
long offset,
TServiceSpecificArgs args,
IProgress<long> progressHandler,
Expand Down Expand Up @@ -469,7 +469,7 @@ await _uploadPartitionInternal(
/// <summary>
/// Partition a stream into a series of blocks buffered as needed by an array pool.
/// </summary>
private static async IAsyncEnumerable<StreamSlice> GetPartitionsAsync(
private static async IAsyncEnumerable<SlicedStream> GetPartitionsAsync(
Stream stream,
long? streamLength,
long blockSize,
Expand Down Expand Up @@ -502,7 +502,7 @@ private static async IAsyncEnumerable<StreamSlice> GetPartitionsAsync(
long absolutePosition = 0;
do
{
StreamSlice partition = await getNextPartition(
SlicedStream partition = await getNextPartition(
stream,
acceptableBlockSize,
blockSize,
Expand Down Expand Up @@ -552,7 +552,7 @@ private static async IAsyncEnumerable<StreamSlice> GetPartitionsAsync(
/// <returns>
/// Task containing the buffered stream partition.
/// </returns>
private async Task<StreamSlice> GetBufferedPartitionInternal(
private async Task<SlicedStream> GetBufferedPartitionInternal(
Stream stream,
long minCount,
long maxCount,
Expand Down Expand Up @@ -594,14 +594,14 @@ private async Task<StreamSlice> GetBufferedPartitionInternal(
/// <returns>
/// Task containing the stream facade.
/// </returns>
private static Task<StreamSlice> GetStreamedPartitionInternal(
private static Task<SlicedStream> GetStreamedPartitionInternal(
Stream stream,
long minCount,
long maxCount,
long absolutePosition,
bool async,
CancellationToken cancellationToken)
=> Task.FromResult((StreamSlice)WindowStream.GetWindow(stream, maxCount, absolutePosition));
=> Task.FromResult((SlicedStream)WindowStream.GetWindow(stream, maxCount, absolutePosition));
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Azure.Storage.Shared
/// Functions like a readable <see cref="MemoryStream"/> but uses an ArrayPool to supply the backing memory.
/// This stream support buffering long sizes.
/// </summary>
internal class PooledMemoryStream : StreamSlice
internal class PooledMemoryStream : SlicedStream
{
private const int DefaultMaxArrayPoolRentalSize = 128 * Constants.MB;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Azure.Storage.Shared
/// <summary>
/// Describes a stream that is a partition of another, larger stream.
/// </summary>
internal abstract class StreamSlice : System.IO.Stream
internal abstract class SlicedStream : System.IO.Stream
{
/// <summary>
/// Absolute position of the start of this stream in the larger stream it was chunked from.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Azure.Storage.Shared
/// Exposes a predetermined slice of a larger stream using the same Stream interface.
/// There should not be access to the base stream while this facade is in use.
/// </summary>
internal abstract class WindowStream : StreamSlice
internal abstract class WindowStream : SlicedStream
{
private Stream InnerStream { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<Compile Include="$(AzureStorageSharedSources)PartitionedUploader.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)PooledMemoryStream.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)ProgressIncrementingStream.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)StreamSlice.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)SlicedStream.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)WindowStream.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
</ItemGroup>
<!-- Ensure an empty TestConfigurations.xml is always present so the build can copy it -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using Azure.Core.Pipeline;
using Azure.Storage.Shared;
using Azure.Storage.Tests.Shared;
using NUnit.Framework;

namespace Azure.Storage.Tests
Expand All @@ -19,65 +15,6 @@ public class PooledMemoryStreamTests
{
private readonly ArrayPool<byte> _pool = ArrayPool<byte>.Shared;

/// <summary>
/// Stream who's byte at position n is n % <see cref="byte.MaxValue"/>.
/// Note this means we have 255 possibilities, not 256, giving variation at likely buffer boundaries.
/// </summary>
private class PredictableStream : Stream
{
public override bool CanRead => true;

public override bool CanSeek => true;

public override bool CanWrite => false;

public override long Length => throw new NotSupportedException();

public override long Position { get; set; } = 0;

public override void Flush()
{ }

public override int Read(byte[] buffer, int offset, int count)
{
for (int i = 0; i < count; i++)
{
buffer[offset + i] = (byte)((Position + i) % byte.MaxValue);
}

Position += count;
return count;
}

public override long Seek(long offset, SeekOrigin origin)
{
switch (origin)
{
case SeekOrigin.Begin:
Position = offset;
break;
case SeekOrigin.Current:
Position += offset;
break;
case SeekOrigin.End:
Position = Length + offset;
break;
}

return Position;
}

public override void SetLength(long value)
{
throw new NotSupportedException();
}

public override void Write(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
}
}

/// <summary>
/// Sanity check for our test helper stream implementation.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<Compile Include="$(AzureStorageSharedSources)SasExtensions.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)SasQueryParametersInternals.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)SharedAccessSignatureCredentials.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)SlicedStream.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)StorageClientOptions.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)StorageConnectionString.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)StorageCollectionEnumerator.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
Expand All @@ -62,7 +63,6 @@
<Compile Include="$(AzureStorageSharedSources)StorageSharedKeyPipelinePolicy.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)StorageResponseClassifier.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)StorageVersionExtensions.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)StreamSlice.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)UriExtensions.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)UriQueryParamsCollection.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
<Compile Include="$(AzureStorageSharedSources)UserDelegationKeyProperties.cs" Link="Shared\%(RecursiveDir)\%(Filename)%(Extension)" />
Expand Down

0 comments on commit ce4638f

Please sign in to comment.