Skip to content

Commit

Permalink
Handle get queue info when queue does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Havret committed Mar 26, 2024
1 parent 907968f commit aeb722d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ArtemisNetCoreClient/ISession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public interface ISession : IAsyncDisposable
Task CreateAddress(string address, IEnumerable<RoutingType> routingTypes, CancellationToken cancellationToken);
Task<AddressInfo?> GetAddressInfo(string address, CancellationToken cancellationToken);
Task CreateQueue(QueueConfiguration queueConfiguration, CancellationToken cancellationToken);
Task<QueueInfo> GetQueueInfo(string queueName, CancellationToken cancellationToken);
Task<QueueInfo?> GetQueueInfo(string queueName, CancellationToken cancellationToken);
}
17 changes: 11 additions & 6 deletions src/ArtemisNetCoreClient/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,25 @@ public async Task CreateQueue(QueueConfiguration queueConfiguration, Cancellatio
_ = await SendBlockingAsync<CreateQueueMessageV2, NullResponse>(createQueueMessage, cancellationToken);
}

public async Task<QueueInfo> GetQueueInfo(string queueName, CancellationToken cancellationToken)
public async Task<QueueInfo?> GetQueueInfo(string queueName, CancellationToken cancellationToken)
{
var request = new SessionQueueQueryMessage
{
QueueName = queueName
};
var response = await SendBlockingAsync<SessionQueueQueryMessage, SessionQueueQueryResponseMessageV3>(request, cancellationToken);

return new QueueInfo
if (response.Exists)
{
QueueName = response.Name ?? queueName,
RoutingType = response.RoutingType,
AddressName = response.Address ?? string.Empty,
};
return new QueueInfo
{
QueueName = response.Name ?? queueName,
RoutingType = response.RoutingType,
AddressName = response.Address ?? string.Empty,
};
}

return null;
}

public async ValueTask DisposeAsync()
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 @@ -101,4 +101,25 @@ public async Task should_not_return_address_info_when_address_does_not_exist()
// Assert
Assert.That(addressInfo, Is.Null);
}

[Test]
public async Task should_not_return_queue_info_when_queue_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 queueName = Guid.NewGuid().ToString();
var queueInfo = await session.GetQueueInfo(queueName, default);

// Assert
Assert.That(queueInfo, Is.Null);
}
}

0 comments on commit aeb722d

Please sign in to comment.