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

Handle Get Address Info when Address does not exist #44

Merged
merged 1 commit into from
Mar 26, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/ArtemisNetCoreClient/ISession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ActiveMQ.Artemis.Core.Client;
public interface ISession : IAsyncDisposable
{
Task CreateAddress(string address, IEnumerable<RoutingType> routingTypes, CancellationToken cancellationToken);
Task<AddressInfo> GetAddressInfo(string address, CancellationToken cancellationToken);
Task<AddressInfo?> GetAddressInfo(string address, CancellationToken cancellationToken);
Task CreateQueue(QueueConfiguration queueConfiguration, CancellationToken cancellationToken);
Task<QueueInfo> GetQueueInfo(string queueName, CancellationToken cancellationToken);
}
19 changes: 12 additions & 7 deletions src/ArtemisNetCoreClient/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,25 @@ public async Task CreateAddress(string address, IEnumerable<RoutingType> routing
_ = await SendBlockingAsync<CreateAddressMessage, NullResponse>(createAddressMessage, cancellationToken);
}

public async Task<AddressInfo> GetAddressInfo(string address, CancellationToken cancellationToken)
public async Task<AddressInfo?> GetAddressInfo(string address, CancellationToken cancellationToken)
{
var request = new SessionBindingQueryMessage
{
Address = address
};
var response = await SendBlockingAsync<SessionBindingQueryMessage, SessionBindingQueryResponseMessageV5>(request, cancellationToken);
return new AddressInfo

if (response.Exists)
{
Name = address,
QueueNames = response.QueueNames,
RoutingTypes = GetRoutingTypes(response).ToArray(),
};
return new AddressInfo
{
Name = address,
QueueNames = response.QueueNames,
RoutingTypes = GetRoutingTypes(response).ToArray(),
};
}

return null;
}

private static IEnumerable<RoutingType> GetRoutingTypes(SessionBindingQueryResponseMessageV5 sessionBindingQueryResponseMessageV5)
Expand Down
21 changes: 21 additions & 0 deletions test/ArtemisNetCoreClient.Tests/SessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

// Assert
var addressInfo = await session.GetAddressInfo(addressName, default);
Assert.That(addressInfo.Name, Is.EqualTo(addressName));

Check warning on line 48 in test/ArtemisNetCoreClient.Tests/SessionTests.cs

View workflow job for this annotation

GitHub Actions / linux

Dereference of a possibly null reference.

Check warning on line 48 in test/ArtemisNetCoreClient.Tests/SessionTests.cs

View workflow job for this annotation

GitHub Actions / linux

Dereference of a possibly null reference.
CollectionAssert.AreEqual(routingTypes, addressInfo.RoutingTypes);
}

Expand Down Expand Up @@ -80,4 +80,25 @@
Assert.That(queueInfo.AddressName, Is.EqualTo(addressName));
Assert.That(queueInfo.RoutingType, Is.EqualTo(routingType));
}

[Test]
public async Task should_not_return_address_info_when_address_does_not_exist()
{
// Arrange
var connectionFactory = new SessionFactory();
await using var session = await connectionFactory.CreateAsync(new Endpoint
{
Host = "localhost",
Port = 5445,
User = "artemis",
Password = "artemis"
});

// Act
var addressName = Guid.NewGuid().ToString();
var addressInfo = await session.GetAddressInfo(addressName, default);

// Assert
Assert.That(addressInfo, Is.Null);
}
}
Loading