Skip to content

Commit

Permalink
Some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Lanayx committed Apr 19, 2024
1 parent e0282f8 commit 9eda4b2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/Pulsar.Client/Pulsar.Client.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
<Title>Pulsar.Client</Title>
<RootNamespace>Pulsar.Client</RootNamespace>
<AssemblyName>Pulsar.Client</AssemblyName>
<Version>3.3.1</Version>
<Version>3.4.0</Version>
<Company>F# community</Company>
<Description>.NET client library for Apache Pulsar</Description>
<RepositoryUrl>https://github.com/fsprojects/pulsar-client-dotnet</RepositoryUrl>
<PackageReleaseNotes>Fix for ZSTD message decompression</PackageReleaseNotes>
<PackageReleaseNotes>Support for replicateSubscriptionState</PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/fsprojects/pulsar-client-dotnet</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>pulsar</PackageTags>
<Authors>F# community</Authors>
<PackageVersion>3.3.1</PackageVersion>
<PackageVersion>3.4.0</PackageVersion>
<DebugType>portable</DebugType>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
27 changes: 10 additions & 17 deletions tests/IntegrationTests/Basic.fs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
module Pulsar.Client.IntegrationTests.Basic

open System
open System.Net.Http
open System.Text.Json
open System.Threading
open System.Diagnostics

open Expecto
open Expecto.Flip
open Expecto.Logging

open System.Text
open System.Threading.Tasks
Expand Down Expand Up @@ -281,11 +279,11 @@ let tests =
do! consumer1.DisposeAsync().AsTask()
Expect.throwsT2<AlreadyClosedException> (fun () -> consumer1.ReceiveAsync().Result |> ignore) |> ignore
do! producer1.DisposeAsync().AsTask()
Expect.throwsT2<AlreadyClosedException> (fun () -> producer1.SendAndForgetAsync([||]).Result |> ignore) |> ignore
Expect.throwsT2<AlreadyClosedException> (fun () -> producer1.SendAndForgetAsync([||]).Result) |> ignore
do! client.CloseAsync()
Expect.throwsT2<AlreadyClosedException> (fun () -> consumer2.UnsubscribeAsync().Result |> ignore) |> ignore
Expect.throwsT2<AlreadyClosedException> (fun () -> producer2.SendAndForgetAsync([||]).Result |> ignore) |> ignore
Expect.throwsT2<AlreadyClosedException> (fun () -> client.CloseAsync().Result |> ignore) |> ignore
Expect.throwsT2<AlreadyClosedException> (fun () -> consumer2.UnsubscribeAsync().Result) |> ignore
Expect.throwsT2<AlreadyClosedException> (fun () -> producer2.SendAndForgetAsync([||]).Result) |> ignore
Expect.throwsT2<AlreadyClosedException> (fun () -> client.CloseAsync().Result) |> ignore

Log.Debug("Finished 'Client, producer and consumer can't be accessed after close'")
}
Expand Down Expand Up @@ -351,7 +349,7 @@ let tests =

Log.Debug("Finished 'Scheduled message should be delivered at requested time'")
}

testTask "Create the replicated subscription should be successful" {
Log.Debug("Started 'Create the replicated subscription should be successful'")
let topicName = "public/default/topic-" + Guid.NewGuid().ToString("N")
Expand All @@ -365,17 +363,12 @@ let tests =
.SubscriptionType(SubscriptionType.Shared)
.ReplicateSubscriptionState(true)
.SubscribeAsync()

do! Task.Delay 1000
let getJsonAsync (url: string) =
async {
use httpClient = new HttpClient()
let! response = httpClient.GetStringAsync(url) |> Async.AwaitTask
return JsonDocument.Parse(response)
}

let url = "http://localhost:8080/admin/v2/persistent/" + topicName + "/stats"
let json = Async.RunSynchronously (getJsonAsync url)

let url = $"{pulsarHttpAddress}/admin/v2/persistent/" + topicName + "/stats"
let! (response: string) = commonHttpClient.GetStringAsync(url)
let json = JsonDocument.Parse(response)
let isReplicated = json.RootElement.GetProperty("subscriptions").GetProperty("replicate").GetProperty("isReplicated").GetBoolean()
Expect.isTrue "" isReplicated
Log.Debug("Finished 'Create the replicated subscription should be successful'")
Expand Down
6 changes: 6 additions & 0 deletions tests/IntegrationTests/Common.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Pulsar.Client.IntegrationTests.Common

open System
open System.Net.Http
open Pulsar.Client.Api

open System.Text
Expand All @@ -21,6 +22,9 @@ let pulsarAddress = "pulsar://127.0.0.1:6650"
[<Literal>]
let pulsarSslAddress = "pulsar+ssl://127.0.0.1:6651"

[<Literal>]
let pulsarHttpAddress = "http://127.0.0.1:8080"

// ssl folder copied by from https://github.com/apache/pulsar/tree/master/tests/docker-images/latest-version-image/ssl
// generate pfx file from pem, leave the password blank
// openssl pkcs12 -in admin.cert.pem -inkey admin.key-pk8.pem -export -out admin.pfx
Expand Down Expand Up @@ -50,6 +54,8 @@ let commonClient =
.ServiceUrl(pulsarAddress)
.BuildAsync().Result

let commonHttpClient = new HttpClient()

let getClient() = commonClient

let extractTimeStamp (date: DateTime) : TimeStamp =
Expand Down

0 comments on commit 9eda4b2

Please sign in to comment.