diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..4b5102c1 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,60 @@ +# Testing Pulsar .NET Client + +## Run All Tests (TL;DR) +```bash +cd pulsar-client-dotnet +dotnet test tests +``` + +## Unit Tests +You can run the unit tests without installing or running Pulsar on your machine. + +### Within your IDE +You can run the unit tests within your IDE. For example, in Visual Studio, you can right-click on the `UnitTests` project and select `Run Tests`. +On JetBrains Rider, you can right-click on the `UnitTests` project and select `Run UnitTests`. + +### From the command line +You can run the unit tests from the command line. From the root of the repository, run the following command: +```bash +cd pulsar-client-dotnet/tests/UnitTests +dotnet test tests/UnitTests.csproj +``` + +## Integration Tests + +### Prerequisites +You must have a Pulsar cluster running to run the integration tests. + +#### Disable the TLS tests (optional) +It is recommended to disable the TLS tests if you don't have a Pulsar cluster running with TLS enabled. + +In Rider, You can disable the TLS tests by right clicking on the `IntegrationTests` project and selecting `Properties`. +Then, in the `Debug` tab, add `NOTLS` to the `Define constants` field. + +Alternatively, you can simply add the following lines in `IntegrationTests.fsproj`: +```xml + + TRACE;NOTLS + +``` + +#### Using the provided Docker Compose file +You can run a Pulsar cluster locally using Docker. +You can use the provided `docker-compose.yml` file to run a Pulsar cluster locally. +From the root of the repository, run the following command: +```bash +cd pulsar-client-dotnet/tests/IntegrationTests/compose +docker-compose up -d +``` +Since the docker-compose will expose the ports at the default port number, you shouldn't have to update the `pulsarAddress` in `Common.fs` to point to your Pulsar cluster. + +#### Using your own Pulsar cluster (with minikube) +You can run a Pulsar cluster locally using minikube. +Make sure that you update the `pulsarAddress` in `Common.fs` to point to your Pulsar cluster. + +### Running the tests +You can run the integration tests from the command line. From the root of the repository, run the following command: +```bash +cd pulsar-client-dotnet/tests/IntegrationTests +dotnet test tests/IntegrationTests.csproj +``` diff --git a/tests/compose/standalone/docker-compose.yml b/tests/compose/standalone/docker-compose.yml index 457a215b..67748473 100644 --- a/tests/compose/standalone/docker-compose.yml +++ b/tests/compose/standalone/docker-compose.yml @@ -24,8 +24,8 @@ services: - ./scripts/wait-for-it.sh:/pulsar/bin/wait-for-it.sh - ./scripts/init-standalone.sh:/pulsar/bin/init-standalone.sh command: > - bash -c "tr -d '\r' < bin/init-standalone.sh > bin/init-standalone-fixed.sh && - tr -d '\r' < bin/wait-for-it.sh > bin/wait-for-it-fixed.sh && + bash -c "tr -d '\\r' < bin/init-standalone.sh > bin/init-standalone-fixed.sh && + tr -d '\\r' < bin/wait-for-it.sh > bin/wait-for-it-fixed.sh && chmod u+x bin/wait-for-it-fixed.sh && chmod u+x bin/init-standalone-fixed.sh && bin/wait-for-it-fixed.sh standalone:8080 -t 120 && @@ -67,8 +67,8 @@ services: - ./scripts/wait-for-it.sh:/pulsar/bin/wait-for-it.sh - ./scripts/init-standalone-tls.sh:/pulsar/bin/init-standalone-tls.sh command: > - bash -c "tr -d '\r' < bin/init-standalone-tls.sh > bin/init-standalone-tls-fixed.sh && - tr -d '\r' < bin/wait-for-it.sh > bin/wait-for-it-fixed.sh && + bash -c "tr -d '\\r' < bin/init-standalone-tls.sh > bin/init-standalone-tls-fixed.sh && + tr -d '\\r' < bin/wait-for-it.sh > bin/wait-for-it-fixed.sh && chmod u+x bin/wait-for-it-fixed.sh && chmod u+x bin/init-standalone-tls-fixed.sh && bin/wait-for-it-fixed.sh standaloneTls:8443 -t 120 && diff --git a/tests/compose/standalone/scripts/init-standalone-tls.sh b/tests/compose/standalone/scripts/init-standalone-tls.sh index 0d0071ae..4cd9f02e 100755 --- a/tests/compose/standalone/scripts/init-standalone-tls.sh +++ b/tests/compose/standalone/scripts/init-standalone-tls.sh @@ -4,6 +4,13 @@ bin/apply-config-from-env.py conf/client.conf sleep 5 +echo "Creating 'standalone' cluster..." bin/pulsar-admin clusters create standalone --broker-url pulsar://localhost:6650 --url http://localhost:8080 + +echo "Creating 'public' tenant..." bin/pulsar-admin tenants create public + +echo "Creating 'default' namespace..." bin/pulsar-admin namespaces create public/default + +echo "Init Standalone TLS completed!" diff --git a/tests/compose/standalone/scripts/init-standalone.sh b/tests/compose/standalone/scripts/init-standalone.sh index ebd76f24..d87c42d1 100755 --- a/tests/compose/standalone/scripts/init-standalone.sh +++ b/tests/compose/standalone/scripts/init-standalone.sh @@ -4,11 +4,16 @@ bin/apply-config-from-env.py conf/client.conf sleep 5 +echo "Creating namespaces..." bin/pulsar-admin namespaces create public/retention bin/pulsar-admin namespaces create public/deduplication + +echo "Setting namespaces settings..." bin/pulsar-admin namespaces set-retention public/retention --time 3h --size 1G bin/pulsar-admin namespaces set-deduplication public/deduplication --enable bin/pulsar-admin namespaces set-schema-validation-enforce --enable public/default + +echo "Creating partitioned topics..." bin/pulsar-admin topics create-partitioned-topic persistent://public/default/partitioned --partitions 3 bin/pulsar-admin topics create-partitioned-topic persistent://public/default/partitioned2 --partitions 2 bin/pulsar-admin topics create-partitioned-topic persistent://public/default/partitioned3 --partitions 3 @@ -17,4 +22,8 @@ bin/pulsar-admin topics create-partitioned-topic persistent://public/default/par bin/pulsar-admin topics create-partitioned-topic persistent://public/default/partitioned6 --partitions 2 bin/pulsar-admin topics create-partitioned-topic persistent://public/default/partitioned-dl-test --partitions 2 bin/pulsar-admin topics create-partitioned-topic persistent://public/deduplication/partitioned --partitions 3 -bin/pulsar initialize-transaction-coordinator-metadata -cs standalone:2181 -c standalone --initial-num-transaction-coordinators 2 \ No newline at end of file + +echo "Initializing transaction coordinator metadata..." +bin/pulsar initialize-transaction-coordinator-metadata -cs standalone:2181 -c standalone --initial-num-transaction-coordinators 2 + +echo "Init Standalone completed!"