You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by bl...@apache.org on 2020/03/29 09:25:48 UTC
[pulsar-dotpulsar] 01/02: add regression tests for connection
handshake
This is an automated email from the ASF dual-hosted git repository.
blankensteiner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-dotpulsar.git
commit 981343b60d62dbc708d3716d064d9dc707af0b19
Author: Vince Pergolizzi <pe...@gmail.com>
AuthorDate: Sat Mar 28 22:23:43 2020 -0400
add regression tests for connection handshake
---
haproxy.cfg | 40 ++++++++++++++
tests/DotPulsar.StressTests/ConnectionTests.cs | 63 ++++++++++++++++++++++
.../DotPulsar.StressTests.csproj | 3 +-
tests/docker-compose-standalone-tests.yml | 13 +++++
4 files changed, 118 insertions(+), 1 deletion(-)
diff --git a/haproxy.cfg b/haproxy.cfg
new file mode 100644
index 0000000..e93369c
--- /dev/null
+++ b/haproxy.cfg
@@ -0,0 +1,40 @@
+global
+ maxconn 10
+ stats socket ipv4@127.0.0.1:9999 level admin
+ stats socket /var/run/hapee-lb.sock mode 666 level admin
+ stats timeout 2m
+defaults
+ timeout connect 5000
+ timeout client 5000
+ timeout server 5000
+ log global
+
+frontend pulsar_tcp
+ bind *:6666
+ mode tcp
+ default_backend pulsar_tcp
+
+frontend admin_http
+ bind *:8888
+ mode http
+ default_backend admin_http
+
+backend pulsar_tcp
+ balance roundrobin
+ mode tcp
+ server pulsar_tcp pulsar:6650
+
+backend admin_http
+ balance roundrobin
+ mode http
+ server pulsar pulsar:8080 check
+ option httpchk GET /metrics/
+ http-check expect status 200
+
+listen stats
+ bind *:9999
+ mode http
+ stats enable
+ stats uri /stats
+ stats refresh 10s
+ stats admin if LOCALHOST
diff --git a/tests/DotPulsar.StressTests/ConnectionTests.cs b/tests/DotPulsar.StressTests/ConnectionTests.cs
new file mode 100644
index 0000000..3a5f694
--- /dev/null
+++ b/tests/DotPulsar.StressTests/ConnectionTests.cs
@@ -0,0 +1,63 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * 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 DotPulsar.Extensions;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using DotPulsar.StressTests.Fixtures;
+using Xunit;
+using Xunit.Abstractions;
+
+namespace DotPulsar.StressTests
+{
+ [Collection(nameof(StandaloneClusterTest))]
+ public class ConnectionTests
+ {
+ private readonly ITestOutputHelper _output;
+
+ public ConnectionTests(ITestOutputHelper output) => _output = output;
+
+ [Theory]
+ [InlineData("pulsar://localhost:54545")] // test that we can connect directly to a broker
+ [InlineData("pulsar://localhost:6666")] // test that we can connect through a reverse proxy (NOT a pulsar proxy)
+ public async Task ConnectionHandshake_GivenValidServiceUrls_ShouldEstablishConnection(string serviceUrl)
+ {
+ //Arrange
+ var testRunId = Guid.NewGuid().ToString("N");
+
+ var topic = $"persistent://public/default/consumer-tests-{testRunId}";
+
+ var builder = PulsarClient.Builder()
+ .ExceptionHandler(new XunitExceptionHandler(_output));
+
+ if (!string.IsNullOrEmpty(serviceUrl))
+ {
+ builder.ServiceUrl(new Uri(serviceUrl));
+ }
+
+ await using var client = builder.Build();
+
+ await using var producer = client.NewProducer()
+ .ProducerName($"producer-{testRunId}")
+ .Topic(topic)
+ .Create();
+
+ var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
+
+ //Act // Assert
+ await producer.StateChangedTo(ProducerState.Connected, cts.Token);
+ }
+ }
+}
diff --git a/tests/DotPulsar.StressTests/DotPulsar.StressTests.csproj b/tests/DotPulsar.StressTests/DotPulsar.StressTests.csproj
index 9e8b85d..9359a9e 100644
--- a/tests/DotPulsar.StressTests/DotPulsar.StressTests.csproj
+++ b/tests/DotPulsar.StressTests/DotPulsar.StressTests.csproj
@@ -21,10 +21,11 @@
<ItemGroup>
<None Include="..\docker-compose-standalone-tests.yml" CopyToOutputDirectory="Always" />
+ <None Include="..\..\haproxy.cfg" CopyToOutputDirectory="Always" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\DotPulsar\DotPulsar.csproj" />
</ItemGroup>
-
+
</Project>
diff --git a/tests/docker-compose-standalone-tests.yml b/tests/docker-compose-standalone-tests.yml
index 78ac29e..d591b22 100644
--- a/tests/docker-compose-standalone-tests.yml
+++ b/tests/docker-compose-standalone-tests.yml
@@ -12,3 +12,16 @@ services:
PULSAR_MEM: " -Xms1g -Xmx1g -XX:MaxDirectMemorySize=2g"
command: |
/bin/bash -c "bin/apply-config-from-env.py conf/standalone.conf && bin/pulsar standalone --no-functions-worker"
+
+ loadbalancer:
+ container_name: loadbalancer
+ image: 'haproxy:2.1.3'
+ ports:
+ - '8888:8888'
+ - '6666:6666'
+ - '9999:9999'
+ volumes:
+ - /var/run/docker.sock:/var/run/docker.sock
+ - ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
+ depends_on:
+ - pulsar