Skip to content

Commit b55cc4b

Browse files
committed
Bootstrap Elastic.Transport.Tests in anticipation of move to separate repos
1 parent 858e61b commit b55cc4b

File tree

8 files changed

+89
-43
lines changed

8 files changed

+89
-43
lines changed

Elasticsearch.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ EndProjectSection
8181
EndProject
8282
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastic.Transport", "src\Elastic.Transport\Elastic.Transport.csproj", "{F510A0DE-8758-4A90-AE10-E25BE87A6D3D}"
8383
EndProject
84+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elastic.Transport.Tests", "tests\Elastic.Transport.Tests\Elastic.Transport.Tests.csproj", "{CB131DE7-72C9-4383-86F0-B6D268904EC8}"
85+
EndProject
8486
Global
8587
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8688
Debug|Any CPU = Debug|Any CPU
@@ -116,6 +118,7 @@ Global
116118
{5A9C1B95-9280-433E-8D1B-1F5396126166} = {29E53C13-34F7-4F0D-8D28-41EF768793E7}
117119
{432D5575-2347-4D3C-BF8C-3E38410C46CA} = {29E53C13-34F7-4F0D-8D28-41EF768793E7}
118120
{F510A0DE-8758-4A90-AE10-E25BE87A6D3D} = {3EA11364-0513-44B7-AD6D-A675485E7448}
121+
{CB131DE7-72C9-4383-86F0-B6D268904EC8} = {6C4A2627-AF22-4388-9DF7-7A9AEACFD635}
119122
EndGlobalSection
120123
GlobalSection(ProjectConfigurationPlatforms) = postSolution
121124
{5B393962-7586-49BA-BD99-3B1E35F48E94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -198,5 +201,9 @@ Global
198201
{F510A0DE-8758-4A90-AE10-E25BE87A6D3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
199202
{F510A0DE-8758-4A90-AE10-E25BE87A6D3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
200203
{F510A0DE-8758-4A90-AE10-E25BE87A6D3D}.Release|Any CPU.Build.0 = Release|Any CPU
204+
{CB131DE7-72C9-4383-86F0-B6D268904EC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
205+
{CB131DE7-72C9-4383-86F0-B6D268904EC8}.Debug|Any CPU.Build.0 = Debug|Any CPU
206+
{CB131DE7-72C9-4383-86F0-B6D268904EC8}.Release|Any CPU.ActiveCfg = Release|Any CPU
207+
{CB131DE7-72C9-4383-86F0-B6D268904EC8}.Release|Any CPU.Build.0 = Release|Any CPU
201208
EndGlobalSection
202209
EndGlobal

src/Elastic.Transport.VirtualizedCluster/VirtualizedCluster.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class VirtualizedCluster
1515
private readonly FixedPipelineFactory _fixedRequestPipeline;
1616
private readonly TestableDateTimeProvider _dateTimeProvider;
1717
private readonly ConnectionConfiguration _settings;
18-
private readonly IMockProductRegistration _productRegistration;
1918

2019
private Func<ITransport<IConnectionConfigurationValues>, Func<RequestConfigurationDescriptor, IRequestConfiguration>, Task<ITransportResponse>> _asyncCall;
2120
private Func<ITransport<IConnectionConfigurationValues>, Func<RequestConfigurationDescriptor, IRequestConfiguration>, ITransportResponse> _syncCall;
@@ -26,8 +25,7 @@ public VirtualizedCluster(TestableDateTimeProvider dateTimeProvider, ConnectionC
2625
{
2726
_dateTimeProvider = dateTimeProvider;
2827
_settings = settings;
29-
_productRegistration = productRegistration;
30-
_fixedRequestPipeline = new FixedPipelineFactory(settings, _dateTimeProvider, _productRegistration);
28+
_fixedRequestPipeline = new FixedPipelineFactory(settings, _dateTimeProvider, productRegistration);
3129

3230
_syncCall = (t, r) => t.Request<VirtualResponse>(
3331
HttpMethod.GET, "/",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
6+
<IsTestProject>True</IsTestProject>
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
12+
<PackageReference Include="xunit" Version="2.4.0" />
13+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
14+
<PackageReference Include="coverlet.collector" Version="1.0.1" />
15+
16+
<PackageReference Include="FluentAssertions" Version="5.10.3" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="..\..\src\Elastic.Transport.VirtualizedCluster\Elastic.Transport.VirtualizedCluster.csproj" />
21+
</ItemGroup>
22+
23+
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System;
6+
7+
namespace Elastic.Transport.Tests.Plumbing
8+
{
9+
public static class InMemoryConnectionFactory
10+
{
11+
public static ConnectionConfiguration Create()
12+
{
13+
var connection = new InMemoryConnection();
14+
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
15+
var settings = new ConnectionConfiguration(pool, connection);
16+
return settings;
17+
}
18+
}
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
namespace Elastic.Transport.Tests.Plumbing
6+
{
7+
public class TestResponse : TransportResponseBase { }
8+
}
Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,25 @@
88
using System.Linq;
99
using System.Threading;
1010
using System.Threading.Tasks;
11-
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
12-
using Elastic.Transport;
11+
using Elastic.Transport.Tests.Plumbing;
1312
using FluentAssertions;
14-
using Nest;
15-
using Tests.Core.Client.Settings;
13+
using Xunit;
1614

17-
namespace Tests.ClientConcepts.ConnectionPooling.Dispose
15+
namespace Elastic.Transport.Tests
1816
{
1917
public class ResponseBuilderDisposeTests
2018
{
21-
private readonly IConnectionSettingsValues _settings = new AlwaysInMemoryConnectionSettings().DisableDirectStreaming(false);
22-
private readonly IConnectionSettingsValues _settingsDisableDirectStream = new AlwaysInMemoryConnectionSettings().DisableDirectStreaming();
19+
private readonly IConnectionConfigurationValues _settings = InMemoryConnectionFactory.Create().DisableDirectStreaming(false);
20+
private readonly IConnectionConfigurationValues _settingsDisableDirectStream = InMemoryConnectionFactory.Create().DisableDirectStreaming();
2321

24-
[U] public async Task ResponseWithHttpStatusCode() => await AssertRegularResponse(false, 1);
22+
[Fact] public async Task ResponseWithHttpStatusCode() => await AssertRegularResponse(false, 1);
2523

26-
[U] public async Task ResponseBuilderWithNoHttpStatusCode() => await AssertRegularResponse(false);
24+
[Fact] public async Task ResponseBuilderWithNoHttpStatusCode() => await AssertRegularResponse(false);
2725

28-
[U] public async Task ResponseWithHttpStatusCodeDisableDirectStreaming() =>
26+
[Fact] public async Task ResponseWithHttpStatusCodeDisableDirectStreaming() =>
2927
await AssertRegularResponse(true, 1);
3028

31-
[U] public async Task ResponseBuilderWithNoHttpStatusCodeDisableDirectStreaming() =>
29+
[Fact] public async Task ResponseBuilderWithNoHttpStatusCodeDisableDirectStreaming() =>
3230
await AssertRegularResponse(true);
3331

3432
private async Task AssertRegularResponse(bool disableDirectStreaming, int? statusCode = null)
@@ -41,7 +39,7 @@ private async Task AssertRegularResponse(bool disableDirectStreaming, int? statu
4139
};
4240

4341
var stream = new TrackDisposeStream();
44-
var response = ResponseBuilder.ToResponse<RootNodeInfoResponse>(requestData, null, statusCode, null, stream);
42+
var response = ResponseBuilder.ToResponse<TestResponse>(requestData, null, statusCode, null, stream);
4543
response.Should().NotBeNull();
4644

4745
memoryStreamFactory.Created.Count().Should().Be(disableDirectStreaming ? 1 : 0);
@@ -55,7 +53,7 @@ private async Task AssertRegularResponse(bool disableDirectStreaming, int? statu
5553

5654
stream = new TrackDisposeStream();
5755
var ct = new CancellationToken();
58-
response = await ResponseBuilder.ToResponseAsync<RootNodeInfoResponse>(requestData, null, statusCode, null, stream,
56+
response = await ResponseBuilder.ToResponseAsync<TestResponse>(requestData, null, statusCode, null, stream,
5957
cancellationToken: ct);
6058
response.Should().NotBeNull();
6159
memoryStreamFactory.Created.Count().Should().Be(disableDirectStreaming ? 2 : 0);
@@ -67,14 +65,14 @@ private async Task AssertRegularResponse(bool disableDirectStreaming, int? statu
6765
stream.IsDisposed.Should().BeTrue();
6866
}
6967

70-
[U] public async Task StreamResponseWithHttpStatusCode() => await AssertStreamResponse(false, 200);
68+
[Fact] public async Task StreamResponseWithHttpStatusCode() => await AssertStreamResponse(false, 200);
7169

72-
[U] public async Task StreamResponseBuilderWithNoHttpStatusCode() => await AssertStreamResponse(false);
70+
[Fact] public async Task StreamResponseBuilderWithNoHttpStatusCode() => await AssertStreamResponse(false);
7371

74-
[U] public async Task StreamResponseWithHttpStatusCodeDisableDirectStreaming() =>
72+
[Fact] public async Task StreamResponseWithHttpStatusCodeDisableDirectStreaming() =>
7573
await AssertStreamResponse(true, 1);
7674

77-
[U] public async Task StreamResponseBuilderWithNoHttpStatusCodeDisableDirectStreaming() =>
75+
[Fact] public async Task StreamResponseBuilderWithNoHttpStatusCodeDisableDirectStreaming() =>
7876
await AssertStreamResponse(true);
7977

8078
private async Task AssertStreamResponse(bool disableDirectStreaming, int? statusCode = null)
@@ -88,21 +86,22 @@ private async Task AssertStreamResponse(bool disableDirectStreaming, int? status
8886
};
8987

9088
var stream = new TrackDisposeStream();
91-
var response = ResponseBuilder.ToResponse<RootNodeInfoResponse>(requestData, null, statusCode, null, stream);
89+
var response = ResponseBuilder.ToResponse<TestResponse>(requestData, null, statusCode, null, stream);
9290
response.Should().NotBeNull();
9391

9492
memoryStreamFactory.Created.Count().Should().Be(disableDirectStreaming ? 1 : 0);
9593
stream.IsDisposed.Should().Be(true);
9694

9795
stream = new TrackDisposeStream();
9896
var ct = new CancellationToken();
99-
response = await ResponseBuilder.ToResponseAsync<RootNodeInfoResponse>(requestData, null, statusCode, null, stream,
97+
response = await ResponseBuilder.ToResponseAsync<TestResponse>(requestData, null, statusCode, null, stream,
10098
cancellationToken: ct);
10199
response.Should().NotBeNull();
102100
memoryStreamFactory.Created.Count().Should().Be(disableDirectStreaming ? 2 : 0);
103101
stream.IsDisposed.Should().Be(true);
104102
}
105103

104+
106105
private class TrackDisposeStream : MemoryStream
107106
{
108107
public TrackDisposeStream() { }

tests/Tests/ClientConcepts/VirtualClusterTests.cs renamed to tests/Elastic.Transport.Tests/VirtualClusterTests.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44

55
using System.Linq;
66
using System.Threading.Tasks;
7-
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
8-
using Elastic.Transport;
97
using Elastic.Transport.VirtualizedCluster;
108
using Elastic.Transport.VirtualizedCluster.Audit;
119
using Elastic.Transport.VirtualizedCluster.Rules;
1210
using FluentAssertions;
1311
using Xunit;
1412
using static Elastic.Transport.Diagnostics.Auditing.AuditEvent;
1513

16-
namespace Tests.ClientConcepts
14+
namespace Elastic.Transport.Tests
1715
{
1816
public class VirtualClusterTests
1917
{
20-
[U] public async Task ThrowsExceptionWithNoRules()
18+
[Fact] public async Task ThrowsExceptionWithNoRules()
2119
{
2220
var audit = new Auditor(() => ElasticsearchVirtualCluster
2321
.Nodes(1)
@@ -30,7 +28,7 @@ [U] public async Task ThrowsExceptionWithNoRules()
3028
e.Message.Should().Contain("No ClientCalls defined for the current VirtualCluster, so we do not know how to respond");
3129
}
3230

33-
[U] public async Task ThrowsExceptionAfterDepleedingRules()
31+
[Fact] public async Task ThrowsExceptionAfterDepleedingRules()
3432
{
3533
var audit = new Auditor(() => ElasticsearchVirtualCluster
3634
.Nodes(1)
@@ -55,7 +53,7 @@ [U] public async Task ThrowsExceptionAfterDepleedingRules()
5553
e.Message.Should().Contain("No global or port specific ClientCalls rule (9200) matches any longer after 2 calls in to the cluster");
5654
}
5755

58-
[U] public async Task AGlobalRuleStaysValidForever()
56+
[Fact] public async Task AGlobalRuleStaysValidForever()
5957
{
6058
var audit = new Auditor(() => ElasticsearchVirtualCluster
6159
.Nodes(1)
@@ -72,7 +70,7 @@ [U] public async Task AGlobalRuleStaysValidForever()
7270

7371
}
7472

75-
[U] public async Task RulesAreIgnoredAfterBeingExecuted()
73+
[Fact] public async Task RulesAreIgnoredAfterBeingExecuted()
7674
{
7775
var audit = new Auditor(() => ElasticsearchVirtualCluster
7876
.Nodes(1)
Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,43 @@
66
using System.Collections.Generic;
77
using System.Linq;
88
using System.Threading;
9-
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
10-
using Elastic.Transport;
119
using FluentAssertions;
10+
using Xunit;
1211

13-
namespace Tests.ClientConcepts.ConnectionPooling.RoundRobin
12+
namespace Elastic.Transport.Tests
1413
{
1514
public class VolatileUpdates
1615
{
17-
protected int NumberOfNodes = 10;
16+
private readonly int _numberOfNodes = 10;
1817
private readonly Random _random = new Random();
1918

2019
private readonly List<Node> _update = Enumerable.Range(9200, 10)
2120
.Select(p => new Uri("http://localhost:" + p))
2221
.Select(u => new Node(u))
2322
.ToList();
2423

25-
[U] public void SniffingPoolWithstandsConcurrentReadAndWrites()
24+
[Fact] public void SniffingPoolWithstandsConcurrentReadAndWrites()
2625
{
27-
var uris = Enumerable.Range(9200, NumberOfNodes).Select(p => new Uri("http://localhost:" + p));
26+
var uris = Enumerable.Range(9200, _numberOfNodes).Select(p => new Uri("http://localhost:" + p));
2827
var sniffingPool = new SniffingConnectionPool(uris, false);
2928

3029
Action callSniffing = () => AssertCreateView(sniffingPool);
3130

3231
callSniffing.Should().NotThrow();
3332
}
3433

35-
[U] public void StaticPoolWithstandsConcurrentReadAndWrites()
34+
[Fact] public void StaticPoolWithstandsConcurrentReadAndWrites()
3635
{
37-
var uris = Enumerable.Range(9200, NumberOfNodes).Select(p => new Uri("http://localhost:" + p));
36+
var uris = Enumerable.Range(9200, _numberOfNodes).Select(p => new Uri("http://localhost:" + p));
3837
var staticPool = new StaticConnectionPool(uris, false);
3938

4039
Action callStatic = () => AssertCreateView(staticPool);
4140

4241
callStatic.Should().NotThrow();
4342
}
4443

45-
// hide
4644
private void AssertCreateView(IConnectionPool pool)
4745
{
48-
/**
49-
*/
5046
var threads = Enumerable.Range(0, 50)
5147
.Select(i => CreateReadAndUpdateThread(pool))
5248
.ToList();
@@ -55,8 +51,7 @@ private void AssertCreateView(IConnectionPool pool)
5551
foreach (var t in threads) t.Join();
5652
}
5753

58-
//hide
59-
public Thread CreateReadAndUpdateThread(IConnectionPool pool) => new Thread(() =>
54+
private Thread CreateReadAndUpdateThread(IConnectionPool pool) => new Thread(() =>
6055
{
6156
for (var i = 0; i < 1000; i++)
6257
{
@@ -67,7 +62,6 @@ private void AssertCreateView(IConnectionPool pool)
6762
}
6863
});
6964

70-
//hide
7165
private IEnumerable<int> CallGetNext(IConnectionPool pool)
7266
{
7367
foreach (var n in pool.CreateView()) yield return n.Uri.Port;

0 commit comments

Comments
 (0)