Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make BasicPublishBatch work with ReadOnlyMemory<byte> #816

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 47 additions & 27 deletions RUNNING_TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ and perform protocol encoder/decoder code generation.

On Windows run:

build.bat
``` powershell
build.bat
```

On osx/linux run:
On MacOS and linux run:

build.sh
``` shell
build.sh
```

This will complete the code AMQP 0-9-1 protocol code generation and build all projects. After this open the solution in Visual Studio.

Expand All @@ -34,40 +38,56 @@ may take some time for the adapter to discover tests in the assemblies.
The test suite assumes there's a RabbitMQ node running locally with all
defaults, and the tests will need to be able to run commands against the
[`rabbitmqctl`](https://www.rabbitmq.com/rabbitmqctl.8.html) tool for that node.
Two options to accomplish this are:
Two options to accomplish this are covered below.

### Using RabbitMQ Umbrella Repository

1. Team RabbitMQ uses [rabbitmq-public-umbrella](https://github.com/rabbitmq/rabbitmq-public-umbrella), which sets up a local RabbitMQ server [built from source](https://www.rabbitmq.com/build-server.html):
```
git clone https://github.com/rabbitmq/rabbitmq-public-umbrella umbrella
cd umbrella
make co
cd deps/rabbit
make
make run-broker
```

2. You can load a RabbitMQ node in a [docker](https://www.docker.com/) container. You will need to create an environment variable `RABBITMQ_RABBITMQCTL_PATH` and set it to `DOCKER:<container_name>` (for example `DOCKER:rabbitmq01`). This tells the unit tests to run the `rabbitmqctl` commands through docker, in the format `docker exec rabbitmq01 rabbitmqctl <args>`:
```
docker run -d --hostname rabbitmq01 --name rabbitmq01 -p 15672:15672 -p 5672:5672 rabbitmq:3-management
```
```
git clone https://github.com/rabbitmq/rabbitmq-public-umbrella umbrella
cd umbrella
make co
cd deps/rabbit
make
make run-broker
```

Then, to run the tests on Windows use:
`rabbitmqctl` location will be computed using a relative path in the umbrella.
It is possible to override the location using `RABBITMQ_RABBITMQCTL_PATH`:

```
run-test.bat
```
```
RABBITMQ_RABBITMQCTL_PATH=/path/to/rabbitmqctl dotnet test projects/Unit
```

On MacOS, Linux, BSD use:
### Using a Docker Container

```
run-test.sh
```
It is also possible to run a RabbitMQ node in a [Docker](https://www.docker.com/) container. Set the environment variable `RABBITMQ_RABBITMQCTL_PATH` to `DOCKER:<container_name>` (for example `DOCKER:rabbitmq01`). This tells the unit tests to run the `rabbitmqctl` commands through Docker, in the format `docker exec rabbitmq01 rabbitmqctl <args>`:

Running individual tests and fixtures on Windows is trivial using the Visual Studio test runner.
To run a specific tests fixture on MacOS or Linux, use the NUnit filter expressions to select the tests
to be run:
``` shell
docker run -d --hostname rabbitmq01 --name rabbitmq01 -p 15672:15672 -p 5672:5672 rabbitmq:3-management
```

### Running All Tests

Then, to run the tests use:

``` powershell
run-test.bat
```

On MacOS, Linux, BSD use:

``` shell
run-test.sh
```

### Running Individual Suites or Test Casess

Running individual tests and fixtures on Windows is trivial using the Visual Studio test runner.
To run a specific tests fixture on MacOS or Linux, use the NUnit filter expressions to select the tests to be run:

``` shell
dotnet test projects/Unit --filter "Name~TestAmqpUriParseFail"

dotnet test projects/Unit --filter "FullyQualifiedName~RabbitMQ.Client.Unit.TestHeartbeats"
Expand Down
2 changes: 1 addition & 1 deletion _site
Submodule _site updated 156 files
4 changes: 3 additions & 1 deletion projects/RabbitMQ.Client/client/api/IBasicPublishBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
// The Initial Developer of the Original Code is Pivotal Software, Inc.
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
//---------------------------------------------------------------------------
using System;

namespace RabbitMQ.Client
{
public interface IBasicPublishBatch
{
void Add(string exchange, string routingKey, bool mandatory, IBasicProperties properties, byte[] body);
void Add(string exchange, string routingKey, bool mandatory, IBasicProperties properties, ReadOnlyMemory<byte> body);
void Publish();
}
}
5 changes: 3 additions & 2 deletions projects/RabbitMQ.Client/client/impl/BasicPublishBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
//---------------------------------------------------------------------------

using System;
using System.Collections.Generic;

using RabbitMQ.Client.Framing.Impl;
Expand All @@ -48,12 +49,12 @@ class BasicPublishBatch : IBasicPublishBatch
{
private readonly List<Command> _commands = new List<Command>();
private readonly ModelBase _model;
internal BasicPublishBatch (ModelBase model)
internal BasicPublishBatch(ModelBase model)
{
_model = model;
}

public void Add(string exchange, string routingKey, bool mandatory, IBasicProperties basicProperties, byte[] body)
public void Add(string exchange, string routingKey, bool mandatory, IBasicProperties basicProperties, ReadOnlyMemory<byte> body)
{
IBasicProperties bp = basicProperties ?? _model.CreateBasicProperties();
var method = new BasicPublish
Expand Down