diff --git a/tests/Tests/Search/PointInTime/CreatePitApiTests.cs b/tests/Tests/Search/PointInTime/CreatePitApiTests.cs index 0ccecdb9cd..779c3a9bfb 100644 --- a/tests/Tests/Search/PointInTime/CreatePitApiTests.cs +++ b/tests/Tests/Search/PointInTime/CreatePitApiTests.cs @@ -6,6 +6,7 @@ */ using System; +using System.Collections.Generic; using FluentAssertions; using OpenSearch.Client; using OpenSearch.Net; @@ -22,9 +23,15 @@ namespace Tests.Search.PointInTime; public class CreatePitApiTests : ApiIntegrationTestBase { + private static readonly Dictionary Pits = new(); + public CreatePitApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { } - private string _pitId; + private string CallIsolatedPit + { + get => Pits.TryGetValue(CallIsolatedValue, out var pit) ? pit : "default-for-unit-tests"; + set => Pits[CallIsolatedValue] = value; + } protected override bool ExpectIsValid => true; @@ -58,12 +65,12 @@ protected override LazyResponses ClientUsage() => Calls( protected override void ExpectResponse(CreatePitResponse response) { - _pitId = response.PitId; + CallIsolatedPit = response.PitId; response.ShouldBeValid(); response.PitId.Should().NotBeNullOrEmpty(); response.CreationTime.Should().BeCloseTo(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), 10000); response.Shards.Should().NotBeNull(); } - protected override void OnAfterCall(IOpenSearchClient client) => client.DeletePit(d => d.PitId(_pitId)); + protected override void OnAfterCall(IOpenSearchClient client) => client.DeletePit(d => d.PitId(CallIsolatedPit)); } diff --git a/tests/Tests/Search/PointInTime/DeleteAllPitsApiTests.cs b/tests/Tests/Search/PointInTime/DeleteAllPitsApiTests.cs index dbf50f1118..cb8035ab10 100644 --- a/tests/Tests/Search/PointInTime/DeleteAllPitsApiTests.cs +++ b/tests/Tests/Search/PointInTime/DeleteAllPitsApiTests.cs @@ -24,10 +24,14 @@ namespace Tests.Search.PointInTime; public class DeleteAllPitsApiTests : ApiIntegrationTestBase { - private readonly List _pitIds = new(); + private static readonly Dictionary> Pits = new(); public DeleteAllPitsApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + private List CallIsolatedPits => Pits.TryGetValue(CallIsolatedValue, out var pits) + ? pits + : Pits[CallIsolatedValue] = new List(); + protected override bool ExpectIsValid => true; protected override object ExpectJson => null; @@ -56,7 +60,7 @@ protected override void ExpectResponse(DeleteAllPitsResponse response) response.Pits.Should() .NotBeNull() .And.HaveCount(5) - .And.BeEquivalentTo(_pitIds.Select(p => new DeletedPit + .And.BeEquivalentTo(CallIsolatedPits.Select(p => new DeletedPit { PitId = p, Successful = true @@ -71,7 +75,7 @@ protected override void OnBeforeCall(IOpenSearchClient client) if (!pit.IsValid) throw new Exception("Setup: Initial PIT failed."); - _pitIds.Add(pit.PitId); + CallIsolatedPits.Add(pit.PitId); } } } diff --git a/tests/Tests/Search/PointInTime/DeletePitApiTests.cs b/tests/Tests/Search/PointInTime/DeletePitApiTests.cs index 95e50229c2..9d7b992b55 100644 --- a/tests/Tests/Search/PointInTime/DeletePitApiTests.cs +++ b/tests/Tests/Search/PointInTime/DeletePitApiTests.cs @@ -6,6 +6,7 @@ */ using System; +using System.Collections.Generic; using System.Linq; using FluentAssertions; using OpenSearch.Client; @@ -23,26 +24,32 @@ namespace Tests.Search.PointInTime; public class DeletePitApiTests : ApiIntegrationTestBase { - private string _pitId = "default-for-unit-tests"; + private static readonly Dictionary Pits = new(); public DeletePitApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + private string CallIsolatedPit + { + get => Pits.TryGetValue(CallIsolatedValue, out var pit) ? pit : "default-for-unit-tests"; + set => Pits[CallIsolatedValue] = value; + } + protected override bool ExpectIsValid => true; protected override object ExpectJson => new { pit_id = new[] { - _pitId + CallIsolatedPit } }; protected override int ExpectStatusCode => 200; - protected override Func Fluent => d => d.PitId(_pitId); + protected override Func Fluent => d => d.PitId(CallIsolatedPit); protected override HttpMethod HttpMethod => HttpMethod.DELETE; - protected override DeletePitRequest Initializer => new(_pitId); + protected override DeletePitRequest Initializer => new(CallIsolatedPit); protected override bool SupportsDeserialization => false; protected override string UrlPath => "/_search/point_in_time"; @@ -62,7 +69,7 @@ protected override void ExpectResponse(DeletePitResponse response) var pit = response.Pits.First(); pit.Successful.Should().BeTrue(); - pit.PitId.Should().Be(_pitId); + pit.PitId.Should().Be(CallIsolatedPit); } protected override void OnBeforeCall(IOpenSearchClient client) @@ -71,6 +78,6 @@ protected override void OnBeforeCall(IOpenSearchClient client) if (!pit.IsValid) throw new Exception("Setup: Initial PIT failed."); - _pitId = pit.PitId; + CallIsolatedPit = pit.PitId; } } diff --git a/tests/Tests/Search/PointInTime/GetAllPitsApiTests.cs b/tests/Tests/Search/PointInTime/GetAllPitsApiTests.cs index b63379c71b..aff205d071 100644 --- a/tests/Tests/Search/PointInTime/GetAllPitsApiTests.cs +++ b/tests/Tests/Search/PointInTime/GetAllPitsApiTests.cs @@ -21,13 +21,17 @@ namespace Tests.Search.PointInTime; [SkipVersion("<2.4.0", "Point-In-Time search support was added in version 2.4.0")] -public class GetAllPitsApiTests +public sealed class GetAllPitsApiTests : ApiIntegrationTestBase { - private List<(string id, long creationTime)> _pits = new(); + private static readonly Dictionary> Pits = new(); public GetAllPitsApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { } + private List<(string id, long creationTime)> CallIsolatedPits => Pits.TryGetValue(CallIsolatedValue, out var pits) + ? pits + : Pits[CallIsolatedValue] = new List<(string id, long creationTime)>(); + protected override bool ExpectIsValid => true; protected override object ExpectJson => null; @@ -52,12 +56,11 @@ protected override LazyResponses ClientUsage() => Calls( protected override void ExpectResponse(GetAllPitsResponse response) { - _pits.Should().HaveCount(5); response.ShouldBeValid(); response.Pits.Should() .NotBeNull() .And.HaveCount(5) - .And.BeEquivalentTo(_pits.Select(p => new PitDetail + .And.BeEquivalentTo(CallIsolatedPits.Select(p => new PitDetail { PitId = p.id, CreationTime = p.creationTime, @@ -73,10 +76,10 @@ protected override void OnBeforeCall(IOpenSearchClient client) if (!pit.IsValid) throw new Exception("Setup: Initial PIT failed."); - _pits.Add((pit.PitId, pit.CreationTime)); + CallIsolatedPits.Add((pit.PitId, pit.CreationTime)); } } protected override void OnAfterCall(IOpenSearchClient client) => - client.DeletePit(d => d.PitId(_pits.Select(p => p.id))); + client.DeletePit(d => d.PitId(CallIsolatedPits.Select(p => p.id))); } diff --git a/tests/Tests/Search/PointInTime/PitSearchApiTests.cs b/tests/Tests/Search/PointInTime/PitSearchApiTests.cs index 4877909c99..fb9b93f850 100644 --- a/tests/Tests/Search/PointInTime/PitSearchApiTests.cs +++ b/tests/Tests/Search/PointInTime/PitSearchApiTests.cs @@ -6,6 +6,7 @@ */ using System; +using System.Collections.Generic; using System.Linq; using FluentAssertions; using OpenSearch.Client; @@ -28,9 +29,15 @@ public sealed class PitSearchApiTests : SearchRequest > { + private static readonly Dictionary Pits = new(); + public PitSearchApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { } - private string _pitId = "default-for-unit-tests"; + private string CallIsolatedPit + { + get => Pits.TryGetValue(CallIsolatedValue, out var pit) ? pit : "default-for-unit-tests"; + set => Pits[CallIsolatedValue] = value; + } protected override object ExpectJson => new { @@ -40,7 +47,7 @@ public PitSearchApiTests(WritableCluster cluster, EndpointUsage usage) : base(cl }, pit = new { - id = _pitId, + id = CallIsolatedPit, keep_alive = "1h" }, track_total_hits = true @@ -52,7 +59,7 @@ public PitSearchApiTests(WritableCluster cluster, EndpointUsage usage) : base(cl protected override Func, ISearchRequest> Fluent => s => s .Query(q => q.MatchAll()) .PointInTime(p => p - .Id(_pitId) + .Id(CallIsolatedPit) .KeepAlive("1h")) .TrackTotalHits(); @@ -64,7 +71,7 @@ public PitSearchApiTests(WritableCluster cluster, EndpointUsage usage) : base(cl Query = new QueryContainer(new MatchAllQuery()), PointInTime = new OpenSearch.Client.PointInTime { - Id = _pitId, + Id = CallIsolatedPit, KeepAlive = "1h" }, TrackTotalHits = true @@ -94,7 +101,7 @@ protected override void OnBeforeCall(IOpenSearchClient client) var pitResp = client.CreatePit(CallIsolatedValue, p => p.KeepAlive("1h")); pitResp.ShouldBeValid(); - _pitId = pitResp.PitId; + CallIsolatedPit = pitResp.PitId; bulkResp = client.Bulk(b => b .Index(CallIsolatedValue) @@ -103,7 +110,7 @@ protected override void OnBeforeCall(IOpenSearchClient client) bulkResp.ShouldBeValid(); } - protected override void OnAfterCall(IOpenSearchClient client) => client.DeletePit(d => d.PitId(_pitId)); + protected override void OnAfterCall(IOpenSearchClient client) => client.DeletePit(d => d.PitId(CallIsolatedPit)); protected override LazyResponses ClientUsage() => Calls( (c, f) => c.Search(f),