-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36e9a41
commit 5f5bd5a
Showing
4 changed files
with
179 additions
and
4 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
123 changes: 123 additions & 0 deletions
123
...estrations.Tests/Integration/Processes/BRS_X01/Examples/MonitorExampleUsingApiScenario.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,123 @@ | ||
// Copyright 2020 Energinet DataHub A/S | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License2"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System.Net.Http.Json; | ||
using System.Text; | ||
using System.Text.Json; | ||
using Energinet.DataHub.Core.TestCommon; | ||
using Energinet.DataHub.Example.Orchestrations.Abstractions.Processes.BRS_X01.Example.V1.Model; | ||
using Energinet.DataHub.Example.Orchestrations.Tests.Fixtures; | ||
using Energinet.DataHub.ProcessManager.Abstractions.Api.Model; | ||
using Energinet.DataHub.ProcessManager.Abstractions.Api.Model.OrchestrationInstance; | ||
using FluentAssertions; | ||
using Xunit.Abstractions; | ||
|
||
namespace Energinet.DataHub.ProcessManager.Tests.Integration.Processes; | ||
|
||
/// <summary> | ||
/// Test case where we verify the Process Manager clients can be used to start a | ||
/// calculation orchestration (with input parameter) and monitor its status during its lifetime. | ||
/// </summary> | ||
[Collection(nameof(ExampleOrchestrationsAppCollection))] | ||
public class MonitorExampleUsingApiScenario : IAsyncLifetime | ||
{ | ||
public MonitorExampleUsingApiScenario( | ||
ExampleOrchestrationsAppFixture fixture, | ||
ITestOutputHelper testOutputHelper) | ||
{ | ||
Fixture = fixture; | ||
Fixture.SetTestOutputHelper(testOutputHelper); | ||
} | ||
|
||
private ExampleOrchestrationsAppFixture Fixture { get; } | ||
|
||
public Task InitializeAsync() | ||
{ | ||
Fixture.ProcessManagerAppManager.AppHostManager.ClearHostLog(); | ||
Fixture.ExampleOrchestrationsAppManager.AppHostManager.ClearHostLog(); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public Task DisposeAsync() | ||
{ | ||
Fixture.ProcessManagerAppManager.SetTestOutputHelper(null!); | ||
Fixture.ExampleOrchestrationsAppManager.SetTestOutputHelper(null!); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
[Fact] | ||
public async Task Example_WhenStarted_CanMonitorLifecycle() | ||
{ | ||
var orchestration = new Brs_X01_Example_V1(); | ||
var input = new InputV1(false); | ||
|
||
var command = new StartExampleCommandV1( | ||
operatingIdentity: new UserIdentityDto( | ||
Guid.NewGuid(), | ||
Guid.NewGuid()), | ||
input); | ||
|
||
using var scheduleRequest = new HttpRequestMessage( | ||
HttpMethod.Post, | ||
$"/api/orchestrationinstance/command/start/custom/{orchestration.Name}/{orchestration.Version}"); | ||
scheduleRequest.Content = new StringContent( | ||
JsonSerializer.Serialize(command), | ||
Encoding.UTF8, | ||
"application/json"); | ||
|
||
// Step 1: Start new example orchestration instance | ||
using var response = await Fixture.ExampleOrchestrationsAppManager.AppHostManager | ||
.HttpClient | ||
.SendAsync(scheduleRequest); | ||
response.EnsureSuccessStatusCode(); | ||
|
||
var calculationId = await response.Content | ||
.ReadFromJsonAsync<Guid>(); | ||
|
||
// Step 2: Query until terminated with succeeded | ||
var getRequest = new GetOrchestrationInstanceByIdQuery( | ||
new UserIdentityDto( | ||
Guid.NewGuid(), | ||
Guid.NewGuid()), | ||
calculationId); | ||
|
||
var isTerminated = await Awaiter.TryWaitUntilConditionAsync( | ||
async () => | ||
{ | ||
using var queryRequest = new HttpRequestMessage( | ||
HttpMethod.Post, | ||
"/api/orchestrationinstance/query/id"); | ||
queryRequest.Content = new StringContent( | ||
JsonSerializer.Serialize(getRequest), | ||
Encoding.UTF8, | ||
"application/json"); | ||
|
||
using var queryResponse = await Fixture.ProcessManagerAppManager.AppHostManager | ||
.HttpClient | ||
.SendAsync(queryRequest); | ||
queryResponse.EnsureSuccessStatusCode(); | ||
|
||
var orchestrationInstance = await queryResponse.Content | ||
.ReadFromJsonAsync<OrchestrationInstanceDto>(); | ||
|
||
return orchestrationInstance!.Lifecycle.State == OrchestrationInstanceLifecycleStates.Terminated; | ||
}, | ||
timeLimit: TimeSpan.FromSeconds(40), | ||
delay: TimeSpan.FromSeconds(2)); | ||
|
||
isTerminated.Should().BeTrue("because we expects the orchestration instance can complete within given wait time"); | ||
} | ||
} |
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