-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SynchronizationContext and blocking calls (#1078)
* Adding context * Adding netfx test project * conditional Task.Run * Using TaskHelper * Wrapping more calls * yml update * Adding query in test * Undoing * Removing duplicates * Removing more duplicates * Adding UTs for TaskHelper * Removing unneeded file * Undoing more changes * missing indent * Changing assemblyname * Testing another SNK * YML changes * AssemblyName * Testing properties * Testing with 471 * Testing netcore * net461 * Original setup * Testing with vstest * paths * Using full path * Updating vstest * Forcing version * Refactoring * Undoing other changes * Parameters * breaklines * Undoing some changes * Inline wrapper not conditional * Fixing tests * internal properties * Fixing tests * Fixing more tests * Fixing tests
- Loading branch information
Showing
36 changed files
with
1,172 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
Microsoft.Azure.Cosmos/src/Resource/Conflict/ConflictsInlineCore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//------------------------------------------------------------ | ||
|
||
namespace Microsoft.Azure.Cosmos | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
// This class acts as a wrapper for environments that use SynchronizationContext. | ||
internal sealed class ConflictsInlineCore : Conflicts | ||
{ | ||
private readonly ConflictsCore conflicts; | ||
|
||
internal ConflictsInlineCore(ConflictsCore conflicts) | ||
{ | ||
if (conflicts == null) | ||
{ | ||
throw new ArgumentNullException(nameof(conflicts)); | ||
} | ||
|
||
this.conflicts = conflicts; | ||
} | ||
|
||
public override Task<ResponseMessage> DeleteAsync( | ||
ConflictProperties conflict, | ||
PartitionKey partitionKey, | ||
CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.conflicts.DeleteAsync(conflict, partitionKey, cancellationToken)); | ||
} | ||
|
||
public override FeedIterator GetConflictQueryStreamIterator( | ||
string queryText = null, | ||
string continuationToken = null, | ||
QueryRequestOptions requestOptions = null) | ||
{ | ||
return this.conflicts.GetConflictQueryStreamIterator(queryText, continuationToken, requestOptions); | ||
} | ||
|
||
public override FeedIterator<T> GetConflictQueryIterator<T>( | ||
string queryText = null, | ||
string continuationToken = null, | ||
QueryRequestOptions requestOptions = null) | ||
{ | ||
return this.conflicts.GetConflictQueryIterator<T>(queryText, continuationToken, requestOptions); | ||
} | ||
|
||
public override FeedIterator GetConflictQueryStreamIterator( | ||
QueryDefinition queryDefinition, | ||
string continuationToken = null, | ||
QueryRequestOptions requestOptions = null) | ||
{ | ||
return this.conflicts.GetConflictQueryStreamIterator(queryDefinition, continuationToken, requestOptions); | ||
} | ||
|
||
public override FeedIterator<T> GetConflictQueryIterator<T>( | ||
QueryDefinition queryDefinition, | ||
string continuationToken = null, | ||
QueryRequestOptions requestOptions = null) | ||
{ | ||
return this.conflicts.GetConflictQueryIterator<T>(queryDefinition, continuationToken, requestOptions); | ||
} | ||
|
||
public override Task<ItemResponse<T>> ReadCurrentAsync<T>( | ||
ConflictProperties cosmosConflict, | ||
PartitionKey partitionKey, | ||
CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.conflicts.ReadCurrentAsync<T>(cosmosConflict, partitionKey, cancellationToken)); | ||
} | ||
|
||
public override T ReadConflictContent<T>(ConflictProperties cosmosConflict) | ||
{ | ||
return this.conflicts.ReadConflictContent<T>(cosmosConflict); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
252 changes: 252 additions & 0 deletions
252
Microsoft.Azure.Cosmos/src/Resource/Container/ContainerInlineCore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,252 @@ | ||
//------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//------------------------------------------------------------ | ||
|
||
namespace Microsoft.Azure.Cosmos | ||
{ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
// This class acts as a wrapper for environments that use SynchronizationContext. | ||
internal sealed partial class ContainerInlineCore : Container | ||
{ | ||
private readonly ContainerCore container; | ||
|
||
public override string Id => this.container.Id; | ||
|
||
public override Conflicts Conflicts => this.container.Conflicts; | ||
|
||
public override Scripts.Scripts Scripts => this.container.Scripts; | ||
|
||
internal CosmosClientContext ClientContext => this.container.ClientContext; | ||
|
||
internal Uri LinkUri => this.container.LinkUri; | ||
|
||
internal ContainerInlineCore(ContainerCore container) | ||
{ | ||
if (container == null) | ||
{ | ||
throw new ArgumentNullException(nameof(container)); | ||
} | ||
|
||
this.container = container; | ||
} | ||
|
||
public override Task<ContainerResponse> ReadContainerAsync( | ||
ContainerRequestOptions requestOptions = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReadContainerAsync(requestOptions, cancellationToken)); | ||
} | ||
|
||
public override Task<ResponseMessage> ReadContainerStreamAsync( | ||
ContainerRequestOptions requestOptions = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReadContainerStreamAsync(requestOptions, cancellationToken)); | ||
} | ||
|
||
public override Task<ContainerResponse> ReplaceContainerAsync( | ||
ContainerProperties containerProperties, | ||
ContainerRequestOptions requestOptions = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReplaceContainerAsync(containerProperties, requestOptions, cancellationToken)); | ||
} | ||
|
||
public override Task<ResponseMessage> ReplaceContainerStreamAsync( | ||
ContainerProperties containerProperties, | ||
ContainerRequestOptions requestOptions = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReplaceContainerStreamAsync(containerProperties, requestOptions, cancellationToken)); | ||
} | ||
|
||
public override Task<ContainerResponse> DeleteContainerAsync( | ||
ContainerRequestOptions requestOptions = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.DeleteContainerAsync(requestOptions, cancellationToken)); | ||
} | ||
|
||
public override Task<ResponseMessage> DeleteContainerStreamAsync( | ||
ContainerRequestOptions requestOptions = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.DeleteContainerStreamAsync(requestOptions, cancellationToken)); | ||
} | ||
|
||
public override Task<int?> ReadThroughputAsync(CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReadThroughputAsync(cancellationToken)); | ||
} | ||
|
||
public override Task<ThroughputResponse> ReadThroughputAsync( | ||
RequestOptions requestOptions, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReadThroughputAsync(requestOptions, cancellationToken)); | ||
} | ||
|
||
public override Task<ThroughputResponse> ReplaceThroughputAsync( | ||
int throughput, | ||
RequestOptions requestOptions = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReplaceThroughputAsync(throughput, requestOptions, cancellationToken)); | ||
} | ||
|
||
public override Task<ResponseMessage> CreateItemStreamAsync( | ||
Stream streamPayload, | ||
PartitionKey partitionKey, | ||
ItemRequestOptions requestOptions = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.CreateItemStreamAsync(streamPayload, partitionKey, requestOptions, cancellationToken)); | ||
} | ||
|
||
public override Task<ItemResponse<T>> CreateItemAsync<T>(T item, | ||
PartitionKey? partitionKey = null, | ||
ItemRequestOptions requestOptions = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.CreateItemAsync<T>(item, partitionKey, requestOptions, cancellationToken)); | ||
} | ||
|
||
public override Task<ResponseMessage> ReadItemStreamAsync( | ||
string id, | ||
PartitionKey partitionKey, | ||
ItemRequestOptions requestOptions = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReadItemStreamAsync(id, partitionKey, requestOptions, cancellationToken)); | ||
} | ||
|
||
public override Task<ItemResponse<T>> ReadItemAsync<T>( | ||
string id, | ||
PartitionKey partitionKey, | ||
ItemRequestOptions requestOptions = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReadItemAsync<T>(id, partitionKey, requestOptions, cancellationToken)); | ||
} | ||
|
||
public override Task<ResponseMessage> UpsertItemStreamAsync( | ||
Stream streamPayload, | ||
PartitionKey partitionKey, | ||
ItemRequestOptions requestOptions = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.UpsertItemStreamAsync(streamPayload, partitionKey, requestOptions, cancellationToken)); | ||
} | ||
|
||
public override Task<ItemResponse<T>> UpsertItemAsync<T>( | ||
T item, | ||
PartitionKey? partitionKey = null, | ||
ItemRequestOptions requestOptions = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.UpsertItemAsync<T>(item, partitionKey, requestOptions, cancellationToken)); | ||
} | ||
|
||
public override Task<ResponseMessage> ReplaceItemStreamAsync( | ||
Stream streamPayload, | ||
string id, | ||
PartitionKey partitionKey, | ||
ItemRequestOptions requestOptions = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReplaceItemStreamAsync(streamPayload, id, partitionKey, requestOptions, cancellationToken)); | ||
} | ||
|
||
public override Task<ItemResponse<T>> ReplaceItemAsync<T>( | ||
T item, | ||
string id, | ||
PartitionKey? partitionKey = null, | ||
ItemRequestOptions requestOptions = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.ReplaceItemAsync<T>(item, id, partitionKey, requestOptions, cancellationToken)); | ||
} | ||
|
||
public override Task<ResponseMessage> DeleteItemStreamAsync( | ||
string id, | ||
PartitionKey partitionKey, | ||
ItemRequestOptions requestOptions = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.DeleteItemStreamAsync(id, partitionKey, requestOptions, cancellationToken)); | ||
} | ||
|
||
public override Task<ItemResponse<T>> DeleteItemAsync<T>( | ||
string id, | ||
PartitionKey partitionKey, | ||
ItemRequestOptions requestOptions = null, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
return TaskHelper.RunInlineIfNeededAsync(() => this.container.DeleteItemAsync<T>(id, partitionKey, requestOptions, cancellationToken)); | ||
} | ||
|
||
public override FeedIterator GetItemQueryStreamIterator( | ||
QueryDefinition queryDefinition, | ||
string continuationToken = null, | ||
QueryRequestOptions requestOptions = null) | ||
{ | ||
return this.container.GetItemQueryStreamIterator(queryDefinition, continuationToken, requestOptions); | ||
} | ||
|
||
public override FeedIterator<T> GetItemQueryIterator<T>( | ||
QueryDefinition queryDefinition, | ||
string continuationToken = null, | ||
QueryRequestOptions requestOptions = null) | ||
{ | ||
return this.container.GetItemQueryIterator<T>(queryDefinition, continuationToken, requestOptions); | ||
} | ||
|
||
public override FeedIterator GetItemQueryStreamIterator(string queryText = null, | ||
string continuationToken = null, | ||
QueryRequestOptions requestOptions = null) | ||
{ | ||
return this.container.GetItemQueryStreamIterator(queryText, continuationToken, requestOptions); | ||
} | ||
|
||
public override FeedIterator<T> GetItemQueryIterator<T>( | ||
string queryText = null, | ||
string continuationToken = null, | ||
QueryRequestOptions requestOptions = null) | ||
{ | ||
return this.container.GetItemQueryIterator<T>(queryText, continuationToken, requestOptions); | ||
} | ||
|
||
public override IOrderedQueryable<T> GetItemLinqQueryable<T>(bool allowSynchronousQueryExecution = false, | ||
string continuationToken = null, | ||
QueryRequestOptions requestOptions = null) | ||
{ | ||
return this.container.GetItemLinqQueryable<T>(allowSynchronousQueryExecution, continuationToken, requestOptions); | ||
} | ||
|
||
public override ChangeFeedProcessorBuilder GetChangeFeedProcessorBuilder<T>( | ||
string processorName, | ||
ChangesHandler<T> onChangesDelegate) | ||
{ | ||
return this.container.GetChangeFeedProcessorBuilder<T>(processorName, onChangesDelegate); | ||
} | ||
|
||
public override ChangeFeedProcessorBuilder GetChangeFeedEstimatorBuilder(string processorName, | ||
ChangesEstimationHandler estimationDelegate, | ||
TimeSpan? estimationPeriod = null) | ||
{ | ||
return this.container.GetChangeFeedEstimatorBuilder(processorName, estimationDelegate, estimationPeriod); | ||
} | ||
|
||
public override TransactionalBatch CreateTransactionalBatch(PartitionKey partitionKey) | ||
{ | ||
return this.container.CreateTransactionalBatch(partitionKey); | ||
} | ||
|
||
public static implicit operator ContainerCore(ContainerInlineCore containerInlineCore) => containerInlineCore.container; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.