Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PackageId>Microsoft.Azure.DurableTask.AzureServiceFabric</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.3.11</Version>
<Version>2.3.12</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<FileVersion>$(Version)</FileVersion>
<Title>Azure Service Fabric provider extension for the Durable Task Framework.</Title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,12 @@ private async Task PutJsonAsync(string instanceId, string fragment, object @obje
// TODO: Improve exception handling
if (result.StatusCode == HttpStatusCode.Conflict)
{
throw await result.Content?.ReadAsAsync<OrchestrationAlreadyExistsException>();
throw await (result.Content?.ReadAsAsync<OrchestrationAlreadyExistsException>() ?? Task.FromResult(new OrchestrationAlreadyExistsException()));
}

if (!result.IsSuccessStatusCode)
{
var content = await result.Content?.ReadAsStringAsync();
var content = await (result.Content?.ReadAsStringAsync() ?? Task.FromResult<string>(null));
throw new RemoteServiceException($"CreateTaskOrchestrationAsync failed with status code {result.StatusCode}: {content}", result.StatusCode);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ public async Task<IHttpActionResult> CreateTaskOrchestration([FromUri] string or

return new OkResult(this);
}
catch (OrchestrationAlreadyExistsException ex)
catch (OrchestrationAlreadyExistsException orchestrationAlreadyExistsException)
{
return Content<OrchestrationAlreadyExistsException>(System.Net.HttpStatusCode.Conflict, ex);
return Content<OrchestrationAlreadyExistsException>(System.Net.HttpStatusCode.Conflict, orchestrationAlreadyExistsException);
}
catch (NotSupportedException ex)
catch (NotSupportedException notSupportedException)
{
return Content<NotSupportedException>(System.Net.HttpStatusCode.BadRequest, ex);
return Content<NotSupportedException>(System.Net.HttpStatusCode.BadRequest, notSupportedException);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.6" />
<PackageReference Include="Moq" Version="4.10.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ namespace DurableTask.AzureServiceFabric.Integration.Tests
{
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using DurableTask.AzureServiceFabric.Exceptions;
using DurableTask.Core;
using DurableTask.Core.Exceptions;
using DurableTask.Test.Orchestrations.Performance;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Moq;
using TestApplication.Common.Orchestrations;

[TestClass]
Expand Down Expand Up @@ -586,5 +587,42 @@ public async Task ScheduledStartTest_NotSupported()
var expectedStartTime = DateTime.UtcNow.AddSeconds(30);
await Assert.ThrowsExceptionAsync<RemoteServiceException>(() => this.taskHubClient.CreateScheduledOrchestrationInstanceAsync(typeof(SimpleOrchestrationWithTasks), null, expectedStartTime));
}

[TestMethod]
public async Task CreateTaskOrchestration_HandlesConflictResponse_When_HttpClientReturnsNullContent()
{
var httpClientMock = new Mock<HttpClient>();
var response = new HttpResponseMessage(System.Net.HttpStatusCode.Conflict) { Content = null };
SetupHttpClientMockForPut(httpClientMock, response);

var taskHubClient = Utilities.CreateTaskHubClient((serviceClient) =>
{
serviceClient.HttpClient = httpClientMock.Object;
});

await Assert.ThrowsExceptionAsync<OrchestrationAlreadyExistsException>(async () =>
{
await taskHubClient.CreateOrchestrationInstanceAsync(typeof(TestOrchestration), new TestOrchestrationData());
});
}

private static void SetupHttpClientMockForPut(Mock<HttpClient> httpClientMock, HttpResponseMessage response)
{
httpClientMock
.Setup(x => x.PutAsync(It.IsAny<string>(), It.IsAny<HttpContent>()))
.ReturnsAsync(response);

httpClientMock
.Setup(x => x.PutAsync(It.IsAny<Uri>(), It.IsAny<HttpContent>()))
.ReturnsAsync(response);

httpClientMock
.Setup(x => x.PutAsync(It.IsAny<string>(), It.IsAny<HttpContent>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(response);

httpClientMock
.Setup(x => x.PutAsync(It.IsAny<Uri>(), It.IsAny<HttpContent>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(response);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,27 @@ namespace DurableTask.AzureServiceFabric.Integration.Tests
using System.Diagnostics;
using System.Net.Http;
using System.Threading.Tasks;
using DurableTask.Core;
using DurableTask.AzureServiceFabric.Remote;
using DurableTask.AzureServiceFabric.Service;

using DurableTask.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;

public static class Utilities
{
public static TaskHubClient CreateTaskHubClient()
{
return CreateTaskHubClient(_ => { });
}

public static TaskHubClient CreateTaskHubClient(Action<RemoteOrchestrationServiceClient> setupServiceClient)
{
var partitionProvider = new FabricPartitionEndpointResolver(new Uri(Constants.TestFabricApplicationAddress), new DefaultStringPartitionHashing());
var httpClientHandler = new HttpClientHandler()
{
ServerCertificateCustomValidationCallback = (message, certificate, chain, errors) => true
};
return new TaskHubClient(new RemoteOrchestrationServiceClient(partitionProvider, httpClientHandler));
var serviceClient = new RemoteOrchestrationServiceClient(partitionProvider, httpClientHandler);
setupServiceClient(serviceClient);
return new TaskHubClient(serviceClient);
}

public static async Task ThrowsException<TException>(Func<Task> action, string expectedMessage) where TException : Exception
Expand Down
Loading