You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iggy.apache.org by ri...@apache.org on 2026/09/29 07:13:47 UTC
(iggy) branch master updated: feat(cpp): add user manangement and client functions to high level client (#4256)
This is an automated email from the ASF dual-hosted git repository.
slbotbm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iggy.git
The following commit(s) were added to refs/heads/master by this push:
new 4a94946da feat(cpp): add user manangement and client functions to high level client (#4256)
4a94946da is described below
commit 4a94946da453aa396f9bfad49ad392f54efabb21
Author: Rimuksh Kansal <ni...@gmail.com>
AuthorDate: Tue Sep 29 16:13:41 2026 +0900
feat(cpp): add user manangement and client functions to high level client (#4256)
---
foreign/cpp/include/iggy.hpp | 1683 +++++++++++++++++--
foreign/cpp/src/client.cpp | 77 +
foreign/cpp/src/client.rs | 6 +-
foreign/cpp/src/lib.rs | 3 +
foreign/cpp/src/type_conversion.rs | 2 +
foreign/cpp/src/type_conversions.cpp | 173 ++
foreign/cpp/tests/e2e/client.cpp | 2658 ++++++++++++++----------------
foreign/cpp/tests/e2e/consumer_group.cpp | 12 +-
foreign/cpp/tests/e2e/stream.cpp | 20 +-
foreign/cpp/tests/e2e/test_helpers.hpp | 10 +
foreign/cpp/tests/unit/unit_tests.cpp | 11 +
11 files changed, 3071 insertions(+), 1584 deletions(-)
diff --git a/foreign/cpp/include/iggy.hpp b/foreign/cpp/include/iggy.hpp
index 69ad1c4f0..4aed5cc24 100644
--- a/foreign/cpp/include/iggy.hpp
+++ b/foreign/cpp/include/iggy.hpp
@@ -52,6 +52,11 @@ namespace iggy {
class Consumer;
class ConsumerOffsetInfo;
+class ClientInfo;
+class ClientInfoDetails;
+class CacheMetricEntry;
+class Stats;
+class ConsumerGroupInfo;
class IggyBlockingClient;
class LoginInfo;
class Partition;
@@ -59,6 +64,12 @@ class Topic;
class TopicDetails;
class Stream;
class StreamDetails;
+class GlobalPermissions;
+class Permissions;
+class StreamPermissions;
+class TopicPermissions;
+class UserInfo;
+class UserInfoDetails;
class ConsumerGroup;
class ConsumerGroupDetails;
class ConsumerGroupMember;
@@ -149,6 +160,8 @@ class LoginInfo final {
class Identifier final {
public:
static constexpr std::size_t kMaxIdentifierLength = 255;
+
+ /** @brief Selects the representation stored by an Identifier. */
enum class Kind : std::uint8_t { Numeric, String };
/**
@@ -196,6 +209,494 @@ class Identifier final {
std::variant<std::uint32_t, std::string> value_;
};
+/**
+ * @brief Controls whether a user may authenticate.
+ */
+enum class UserStatus : std::uint8_t {
+ Active = 1, ///< The user may authenticate.
+ Inactive = 2, ///< Authentication for the user is rejected.
+};
+
+/**
+ * @brief Cluster-wide permissions assigned to a user.
+ *
+ * Global grants apply without naming individual streams or topics. Management
+ * grants include the corresponding read grants. Stream and topic grants form a
+ * hierarchy: managing streams includes managing topics, reading streams
+ * includes reading topics, and reading topics includes polling messages and
+ * managing consumer groups. Managing streams or topics also authorizes sending
+ * messages; SendMessages() can grant sending without management permission.
+ *
+ * A default-constructed value has every flag disabled. The setters record the
+ * supplied flags without expanding implied grants; the server applies the
+ * hierarchy when authorizing a request.
+ */
+class GlobalPermissions final {
+ public:
+ /**
+ * @brief Returns the configured cluster-management flag.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool ManageServers() const noexcept { return manage_servers_; }
+
+ /**
+ * @brief Returns the configured server-information read flag.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool ReadServers() const noexcept { return read_servers_; }
+
+ /**
+ * @brief Returns the configured user-management flag.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool ManageUsers() const noexcept { return manage_users_; }
+
+ /**
+ * @brief Returns the configured user-information read flag.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool ReadUsers() const noexcept { return read_users_; }
+
+ /**
+ * @brief Returns the configured all-stream management flag.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool ManageStreams() const noexcept { return manage_streams_; }
+
+ /**
+ * @brief Returns the configured all-stream read flag.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool ReadStreams() const noexcept { return read_streams_; }
+
+ /**
+ * @brief Returns the configured all-topic management flag.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool ManageTopics() const noexcept { return manage_topics_; }
+
+ /**
+ * @brief Returns the configured all-topic read flag.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool ReadTopics() const noexcept { return read_topics_; }
+
+ /**
+ * @brief Returns the configured all-topic message-polling flag.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool PollMessages() const noexcept { return poll_messages_; }
+
+ /**
+ * @brief Returns the configured all-topic message-sending flag.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool SendMessages() const noexcept { return send_messages_; }
+
+ /**
+ * @brief Enables or disables cluster-management permission.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ GlobalPermissions &SetManageServers(bool enabled) {
+ manage_servers_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Enables or disables permission to read server information.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ GlobalPermissions &SetReadServers(bool enabled) {
+ read_servers_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Enables or disables user-management permission.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ GlobalPermissions &SetManageUsers(bool enabled) {
+ manage_users_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Enables or disables permission to read user information.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ GlobalPermissions &SetReadUsers(bool enabled) {
+ read_users_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Enables or disables management permission for every stream.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ GlobalPermissions &SetManageStreams(bool enabled) {
+ manage_streams_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Enables or disables read permission for every stream.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ GlobalPermissions &SetReadStreams(bool enabled) {
+ read_streams_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Enables or disables management permission for every topic.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ GlobalPermissions &SetManageTopics(bool enabled) {
+ manage_topics_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Enables or disables read permission for every topic.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ GlobalPermissions &SetReadTopics(bool enabled) {
+ read_topics_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Enables or disables polling permission for every topic.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ GlobalPermissions &SetPollMessages(bool enabled) {
+ poll_messages_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Enables or disables sending permission for every topic.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ GlobalPermissions &SetSendMessages(bool enabled) {
+ send_messages_ = enabled;
+ return *this;
+ }
+
+ private:
+ [[nodiscard]] ffi::GlobalPermissions ToFfi() const;
+ static GlobalPermissions FromFfi(ffi::GlobalPermissions permissions);
+
+ friend class Permissions;
+
+ bool manage_servers_{};
+ bool read_servers_{};
+ bool manage_users_{};
+ bool read_users_{};
+ bool manage_streams_{};
+ bool read_streams_{};
+ bool manage_topics_{};
+ bool read_topics_{};
+ bool poll_messages_{};
+ bool send_messages_{};
+};
+
+/**
+ * @brief Permissions extending a user's access to one topic.
+ *
+ * These flags grant access in addition to enclosing stream and global grants;
+ * a disabled flag does not revoke access granted at a broader scope. Managing
+ * a topic includes reading it. Reading a topic includes polling messages and
+ * managing its consumer groups. Managing a topic also authorizes sending;
+ * SetSendMessages() can grant sending without management permission.
+ *
+ * A default-constructed value has every flag disabled.
+ */
+class TopicPermissions final {
+ public:
+ /**
+ * @brief Returns the configured topic-management flag.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool ManageTopic() const noexcept { return manage_topic_; }
+
+ /**
+ * @brief Returns the configured topic-read flag.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool ReadTopic() const noexcept { return read_topic_; }
+
+ /**
+ * @brief Returns the configured message-polling flag.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool PollMessages() const noexcept { return poll_messages_; }
+
+ /**
+ * @brief Returns the configured message-sending flag.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool SendMessages() const noexcept { return send_messages_; }
+
+ /**
+ * @brief Enables or disables topic-management permission.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ TopicPermissions &SetManageTopic(bool enabled) {
+ manage_topic_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Enables or disables topic-read permission.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ TopicPermissions &SetReadTopic(bool enabled) {
+ read_topic_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Enables or disables message-polling permission.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ TopicPermissions &SetPollMessages(bool enabled) {
+ poll_messages_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Enables or disables message-sending permission.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ TopicPermissions &SetSendMessages(bool enabled) {
+ send_messages_ = enabled;
+ return *this;
+ }
+
+ private:
+ [[nodiscard]] ffi::TopicPermissions ToFfi() const;
+ static TopicPermissions FromFfi(ffi::TopicPermissions permissions);
+
+ friend class StreamPermissions;
+
+ bool manage_topic_{};
+ bool read_topic_{};
+ bool poll_messages_{};
+ bool send_messages_{};
+};
+
+/**
+ * @brief Permissions extending a user's access to one stream.
+ *
+ * Stream grants apply to the stream identified by the containing Permissions
+ * map. Topic-specific grants are keyed by numeric topic ID. These flags extend
+ * broader grants and cannot revoke permissions granted globally. Managing a
+ * stream includes reading it and managing its topics; reading a stream includes
+ * reading its topics. Managing a stream or its topics also authorizes sending;
+ * SetSendMessages() can grant sending without management permission.
+ *
+ * A default-constructed value has every flag disabled and no topic entries.
+ */
+class StreamPermissions final {
+ public:
+ /**
+ * @brief Returns the configured stream-management flag.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool ManageStream() const noexcept { return manage_stream_; }
+
+ /**
+ * @brief Returns the configured stream-read flag.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool ReadStream() const noexcept { return read_stream_; }
+
+ /**
+ * @brief Returns the configured management flag for all stream topics.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool ManageTopics() const noexcept { return manage_topics_; }
+
+ /**
+ * @brief Returns the configured read flag for all stream topics.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool ReadTopics() const noexcept { return read_topics_; }
+
+ /**
+ * @brief Returns the configured polling flag for all stream topics.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool PollMessages() const noexcept { return poll_messages_; }
+
+ /**
+ * @brief Returns the configured sending flag for all stream topics.
+ * @return Configured flag value.
+ */
+ [[nodiscard]] bool SendMessages() const noexcept { return send_messages_; }
+
+ /**
+ * @brief Returns topic-specific grants keyed by numeric topic ID.
+ * @return Map owned by this value.
+ */
+ [[nodiscard]] const std::map<std::uint32_t, TopicPermissions> &Topics() const noexcept { return topics_; }
+
+ /**
+ * @brief Enables or disables stream-management permission.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ StreamPermissions &SetManageStream(bool enabled) {
+ manage_stream_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Enables or disables stream-read permission.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ StreamPermissions &SetReadStream(bool enabled) {
+ read_stream_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Enables or disables management permission for all stream topics.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ StreamPermissions &SetManageTopics(bool enabled) {
+ manage_topics_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Enables or disables read permission for all stream topics.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ StreamPermissions &SetReadTopics(bool enabled) {
+ read_topics_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Enables or disables polling permission for all stream topics.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ StreamPermissions &SetPollMessages(bool enabled) {
+ poll_messages_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Enables or disables sending permission for all stream topics.
+ * @param enabled Requested flag value.
+ * @return Reference to this permissions object.
+ */
+ StreamPermissions &SetSendMessages(bool enabled) {
+ send_messages_ = enabled;
+ return *this;
+ }
+
+ /**
+ * @brief Replaces the topic-specific permission map.
+ * @param topics Grants keyed by numeric topic ID.
+ * @return Reference to this permissions object.
+ */
+ StreamPermissions &SetTopics(std::map<std::uint32_t, TopicPermissions> topics) {
+ topics_ = std::move(topics);
+ return *this;
+ }
+
+ private:
+ [[nodiscard]] ffi::StreamPermissions ToFfi() const;
+ static StreamPermissions FromFfi(const ffi::StreamPermissions &permissions);
+
+ friend class Permissions;
+
+ bool manage_stream_{};
+ bool read_stream_{};
+ bool manage_topics_{};
+ bool read_topics_{};
+ bool poll_messages_{};
+ bool send_messages_{};
+ std::map<std::uint32_t, TopicPermissions> topics_;
+};
+
+/**
+ * @brief Complete permission assignment for a user.
+ *
+ * Global permissions apply cluster-wide. Stream entries are keyed by numeric
+ * stream ID and add narrower grants, including optional topic-specific grants.
+ * Narrower scopes extend broader scopes and do not deny an inherited grant.
+ *
+ * A default-constructed value contains no grants. Passing such a value to
+ * CreateUser() assigns an explicit but empty permission set; passing
+ * `std::nullopt` assigns no permission object.
+ */
+class Permissions final {
+ public:
+ /**
+ * @brief Returns the cluster-wide grants.
+ * @return Global permissions owned by this value.
+ */
+ [[nodiscard]] const GlobalPermissions &Global() const noexcept { return global_; }
+
+ /**
+ * @brief Returns stream-specific grants keyed by numeric stream ID.
+ * @return Map owned by this value.
+ */
+ [[nodiscard]] const std::map<std::uint32_t, StreamPermissions> &Streams() const noexcept { return streams_; }
+
+ /**
+ * @brief Replaces the cluster-wide grants.
+ * @param global New global permissions.
+ * @return Reference to this permissions object.
+ */
+ Permissions &SetGlobal(GlobalPermissions global) {
+ global_ = global;
+ return *this;
+ }
+
+ /**
+ * @brief Replaces the stream-specific grants.
+ * @param streams Grants keyed by numeric stream ID.
+ * @return Reference to this permissions object.
+ */
+ Permissions &SetStreams(std::map<std::uint32_t, StreamPermissions> streams) {
+ streams_ = std::move(streams);
+ return *this;
+ }
+
+ private:
+ [[nodiscard]] ffi::Permissions ToFfi() const;
+ static Permissions FromFfi(const ffi::Permissions &permissions);
+
+ friend class IggyBlockingClient;
+ friend class UserInfoDetails;
+
+ GlobalPermissions global_;
+ std::map<std::uint32_t, StreamPermissions> streams_;
+};
+
/**
* @brief Identifies the owner of a stored consumer offset.
*
@@ -205,6 +706,7 @@ class Identifier final {
*/
class Consumer final {
public:
+ /** @brief Selects an individual consumer or consumer-group identity. */
enum class Kind : std::uint8_t { Single, Group };
/**
@@ -608,58 +1110,195 @@ class ResourceOptions final {
friend class TopicDetails;
friend class Stream;
friend class StreamDetails;
+ friend class UserInfo;
+ friend class UserInfoDetails;
std::map<std::string, HeaderField> explicit_;
std::map<std::string, HeaderField> derived_;
};
/**
- * @brief Snapshot of one topic's metadata and aggregate statistics.
- *
- * GetStream() returns one of these values for each observed topic. It owns its
- * name and option data.
- *
- * The value describes the topic state observed by the server for one request.
- * It is not a live view. SizeBytes(), MessagesCount(), and PartitionsCount()
- * can become stale immediately after the request completes when another client
- * changes the topic.
+ * @brief Snapshot of basic user metadata.
*
- * Use GetTopic() to retrieve partition summaries. Topic IDs identify a topic
- * within its stream for its lifetime and remain stable when it is renamed.
- * CreatedAt() is the server timestamp, in microseconds, recorded when the
- * topic was created.
+ * GetUsers() returns one value for each user visible to the caller. This
+ * summary omits permissions. User IDs remain assigned to the same user until
+ * that user is deleted. CreatedAt() is expressed in microseconds since the
+ * Unix epoch.
*/
-class Topic final {
+class UserInfo final {
public:
/**
- * @brief Returns the numeric topic ID assigned within its stream.
- * @return Numeric topic ID.
+ * @brief Returns the server-assigned numeric user ID.
+ * @return Numeric user ID.
*/
[[nodiscard]] std::uint32_t Id() const noexcept { return id_; }
/**
- * @brief Returns the server creation timestamp.
- * @return Timestamp in microseconds.
+ * @brief Returns the creation timestamp.
+ * @return Timestamp in microseconds since the Unix epoch.
*/
[[nodiscard]] std::uint64_t CreatedAt() const noexcept { return created_at_; }
/**
- * @brief Returns the topic name.
- * @return Name owned by this value.
+ * @brief Returns whether the user is active or inactive.
+ * @return Current user status observed for this request.
*/
- [[nodiscard]] const std::string &Name() const noexcept { return name_; }
+ [[nodiscard]] UserStatus Status() const noexcept { return status_; }
/**
- * @brief Returns the aggregate retained topic size.
- * @return Size in bytes.
+ * @brief Returns the unique user name.
+ * @return Name owned by this value.
*/
- [[nodiscard]] std::uint64_t SizeBytes() const noexcept { return size_bytes_; }
+ [[nodiscard]] const std::string &Username() const noexcept { return username_; }
/**
- * @brief Returns the server-encoded message retention value.
- * @return Retention value in microseconds or a protocol sentinel.
+ * @brief Returns explicit user creation options.
+ * @return Options owned by this value.
*/
- [[nodiscard]] std::uint64_t MessageExpiry() const noexcept { return message_expiry_; }
+ [[nodiscard]] const ResourceOptions &Options() const noexcept { return options_; }
+
+ private:
+ UserInfo(std::uint32_t id,
+ std::uint64_t created_at,
+ UserStatus status,
+ std::string username,
+ ResourceOptions options)
+ : id_(id),
+ created_at_(created_at),
+ status_(status),
+ username_(std::move(username)),
+ options_(std::move(options)) {}
+
+ static UserInfo FromFfi(ffi::UserInfo user);
+
+ friend class IggyBlockingClient;
+
+ std::uint32_t id_;
+ std::uint64_t created_at_;
+ UserStatus status_;
+ std::string username_;
+ ResourceOptions options_;
+};
+
+/**
+ * @brief Snapshot of user metadata and assigned permissions.
+ *
+ * GetUser() and CreateUser() return this detailed form. Permissions() is empty
+ * when the user has no permission object. An engaged Permissions value can
+ * still contain no enabled grants.
+ */
+class UserInfoDetails final {
+ public:
+ /**
+ * @brief Returns the server-assigned numeric user ID.
+ * @return Numeric user ID.
+ */
+ [[nodiscard]] std::uint32_t Id() const noexcept { return id_; }
+
+ /**
+ * @brief Returns the creation timestamp.
+ * @return Timestamp in microseconds since the Unix epoch.
+ */
+ [[nodiscard]] std::uint64_t CreatedAt() const noexcept { return created_at_; }
+
+ /**
+ * @brief Returns whether the user is active or inactive.
+ * @return Current user status observed for this request.
+ */
+ [[nodiscard]] UserStatus Status() const noexcept { return status_; }
+
+ /**
+ * @brief Returns the unique user name.
+ * @return Name owned by this value.
+ */
+ [[nodiscard]] const std::string &Username() const noexcept { return username_; }
+
+ /**
+ * @brief Returns the user's explicit permission assignment.
+ * @return Empty when no permission object is assigned; otherwise the
+ * permissions owned by this value.
+ */
+ [[nodiscard]] const std::optional<::iggy::Permissions> &Permissions() const noexcept { return permissions_; }
+
+ /**
+ * @brief Returns explicit user creation options.
+ * @return Options owned by this value.
+ */
+ [[nodiscard]] const ResourceOptions &Options() const noexcept { return options_; }
+
+ private:
+ UserInfoDetails(std::uint32_t id,
+ std::uint64_t created_at,
+ UserStatus status,
+ std::string username,
+ std::optional<::iggy::Permissions> permissions,
+ ResourceOptions options)
+ : id_(id),
+ created_at_(created_at),
+ status_(status),
+ username_(std::move(username)),
+ permissions_(std::move(permissions)),
+ options_(std::move(options)) {}
+
+ static UserInfoDetails FromFfi(ffi::UserInfoDetails user);
+
+ friend class IggyBlockingClient;
+
+ std::uint32_t id_;
+ std::uint64_t created_at_;
+ UserStatus status_;
+ std::string username_;
+ std::optional<::iggy::Permissions> permissions_;
+ ResourceOptions options_;
+};
+
+/**
+ * @brief Snapshot of one topic's metadata and aggregate statistics.
+ *
+ * GetStream() returns one of these values for each observed topic. It owns its
+ * name and option data.
+ *
+ * The value describes the topic state observed by the server for one request.
+ * It is not a live view. SizeBytes(), MessagesCount(), and PartitionsCount()
+ * can become stale immediately after the request completes when another client
+ * changes the topic.
+ *
+ * Use GetTopic() to retrieve partition summaries. Topic IDs identify a topic
+ * within its stream for its lifetime and remain stable when it is renamed.
+ * CreatedAt() is the server timestamp, in microseconds, recorded when the
+ * topic was created.
+ */
+class Topic final {
+ public:
+ /**
+ * @brief Returns the numeric topic ID assigned within its stream.
+ * @return Numeric topic ID.
+ */
+ [[nodiscard]] std::uint32_t Id() const noexcept { return id_; }
+
+ /**
+ * @brief Returns the server creation timestamp.
+ * @return Timestamp in microseconds.
+ */
+ [[nodiscard]] std::uint64_t CreatedAt() const noexcept { return created_at_; }
+
+ /**
+ * @brief Returns the topic name.
+ * @return Name owned by this value.
+ */
+ [[nodiscard]] const std::string &Name() const noexcept { return name_; }
+
+ /**
+ * @brief Returns the aggregate retained topic size.
+ * @return Size in bytes.
+ */
+ [[nodiscard]] std::uint64_t SizeBytes() const noexcept { return size_bytes_; }
+
+ /**
+ * @brief Returns the server-encoded message retention value.
+ * @return Retention value in microseconds or a protocol sentinel.
+ */
+ [[nodiscard]] std::uint64_t MessageExpiry() const noexcept { return message_expiry_; }
/**
* @brief Returns the server-selected storage compression algorithm.
@@ -1110,166 +1749,686 @@ class Stream final {
static Stream FromFfi(ffi::Stream stream);
- friend class IggyBlockingClient;
+ friend class IggyBlockingClient;
+
+ std::uint32_t id_;
+ std::uint64_t created_at_;
+ std::string name_;
+ std::uint64_t size_bytes_;
+ std::uint64_t messages_count_;
+ std::uint32_t topics_count_;
+ ResourceOptions options_;
+};
+
+/**
+ * @brief Snapshot of a consumer group member and its partition assignments.
+ *
+ * ConsumerGroupDetails contains one of these values for every member observed
+ * by the server. Membership and partition assignments can change immediately
+ * after the request completes.
+ */
+class ConsumerGroupMember final {
+ public:
+ /**
+ * @brief Returns the numeric ID of the consumer group member.
+ * @return Numeric member ID assigned by the server.
+ */
+ [[nodiscard]] std::uint32_t Id() const noexcept { return id_; }
+
+ /**
+ * @brief Returns the server-reported number of partitions assigned to this member.
+ * @return Partition count reported by the server.
+ */
+ [[nodiscard]] std::uint32_t PartitionsCount() const noexcept { return partitions_count_; }
+
+ /**
+ * @brief Returns the partitions assigned to this member.
+ * @return Partition IDs owned by this value. The reference remains valid
+ * while this ConsumerGroupMember remains alive.
+ */
+ [[nodiscard]] const std::vector<std::uint32_t> &Partitions() const noexcept { return partitions_; }
+
+ private:
+ ConsumerGroupMember(std::uint32_t id, std::uint32_t partitions_count, std::vector<std::uint32_t> partitions)
+ : id_(id), partitions_count_(partitions_count), partitions_(std::move(partitions)) {}
+
+ static ConsumerGroupMember FromFfi(ffi::ConsumerGroupMember member);
+
+ friend class ConsumerGroupDetails;
+
+ std::uint32_t id_;
+ std::uint32_t partitions_count_;
+ std::vector<std::uint32_t> partitions_;
+};
+
+/**
+ * @brief Snapshot of consumer group metadata.
+ *
+ * GetConsumerGroups() returns one summary for each consumer group observed in
+ * a topic. Use GetConsumerGroup() when individual member and partition
+ * assignment details are needed.
+ */
+class ConsumerGroup final {
+ public:
+ /**
+ * @brief Returns the numeric ID assigned to the consumer group.
+ * @return Numeric consumer group ID.
+ */
+ [[nodiscard]] std::uint32_t Id() const noexcept { return id_; }
+
+ /**
+ * @brief Returns the consumer group name.
+ * @return Name owned by this value.
+ */
+ [[nodiscard]] const std::string &Name() const noexcept { return name_; }
+
+ /**
+ * @brief Returns the number of partitions consumed by the group.
+ * @return Partition count observed by the server for this request.
+ */
+ [[nodiscard]] std::uint32_t PartitionsCount() const noexcept { return partitions_count_; }
+
+ /**
+ * @brief Returns the number of members in the group.
+ * @return Member count observed by the server for this request.
+ */
+ [[nodiscard]] std::uint32_t MembersCount() const noexcept { return members_count_; }
+
+ private:
+ ConsumerGroup(std::uint32_t id, std::string name, std::uint32_t partitions_count, std::uint32_t members_count)
+ : id_(id), name_(std::move(name)), partitions_count_(partitions_count), members_count_(members_count) {}
+
+ static ConsumerGroup FromFfi(ffi::ConsumerGroup group);
+
+ friend class IggyBlockingClient;
+
+ std::uint32_t id_;
+ std::string name_;
+ std::uint32_t partitions_count_;
+ std::uint32_t members_count_;
+};
+
+/**
+ * @brief Snapshot of consumer group metadata and member details.
+ *
+ * CreateConsumerGroup() and GetConsumerGroup() return this value. Membership
+ * and partition assignments can change immediately after the request
+ * completes.
+ */
+class ConsumerGroupDetails final {
+ public:
+ /**
+ * @brief Returns the numeric ID assigned to the consumer group.
+ * @return Numeric consumer group ID.
+ */
+ [[nodiscard]] std::uint32_t Id() const noexcept { return id_; }
+
+ /**
+ * @brief Returns the consumer group name.
+ * @return Name owned by this value.
+ */
+ [[nodiscard]] const std::string &Name() const noexcept { return name_; }
+
+ /**
+ * @brief Returns the number of partitions consumed by the group.
+ * @return Partition count observed by the server for this request.
+ */
+ [[nodiscard]] std::uint32_t PartitionsCount() const noexcept { return partitions_count_; }
+
+ /**
+ * @brief Returns the server-reported number of members in the group.
+ * @return Member count reported by the server.
+ */
+ [[nodiscard]] std::uint32_t MembersCount() const noexcept { return members_count_; }
+
+ /**
+ * @brief Returns the consumer group members and their partition assignments.
+ * @return Member details owned by this value. The reference remains valid
+ * while this ConsumerGroupDetails remains alive.
+ */
+ [[nodiscard]] const std::vector<ConsumerGroupMember> &Members() const noexcept { return members_; }
+
+ private:
+ ConsumerGroupDetails(std::uint32_t id,
+ std::string name,
+ std::uint32_t partitions_count,
+ std::uint32_t members_count,
+ std::vector<ConsumerGroupMember> members)
+ : id_(id),
+ name_(std::move(name)),
+ partitions_count_(partitions_count),
+ members_count_(members_count),
+ members_(std::move(members)) {}
+
+ static ConsumerGroupDetails FromFfi(ffi::ConsumerGroupDetails group);
+
+ friend class IggyBlockingClient;
+
+ std::uint32_t id_;
+ std::string name_;
+ std::uint32_t partitions_count_;
+ std::uint32_t members_count_;
+ std::vector<ConsumerGroupMember> members_;
+};
+
+/**
+ * @brief Identifies one consumer-group membership of a connected client.
+ *
+ * ClientInfoDetails returns these numeric identifiers for each membership
+ * observed by the server. The membership can change immediately after the
+ * client information is retrieved.
+ */
+class ConsumerGroupInfo final {
+ public:
+ /**
+ * @brief Returns the numeric ID of the member group's stream.
+ * @return Numeric stream ID.
+ */
+ [[nodiscard]] std::uint32_t StreamId() const noexcept { return stream_id_; }
+
+ /**
+ * @brief Returns the numeric ID of the member group's topic.
+ * @return Numeric topic ID.
+ */
+ [[nodiscard]] std::uint32_t TopicId() const noexcept { return topic_id_; }
+
+ /**
+ * @brief Returns the numeric consumer group ID.
+ * @return Numeric consumer group ID.
+ */
+ [[nodiscard]] std::uint32_t GroupId() const noexcept { return group_id_; }
+
+ private:
+ ConsumerGroupInfo(std::uint32_t stream_id, std::uint32_t topic_id, std::uint32_t group_id)
+ : stream_id_(stream_id), topic_id_(topic_id), group_id_(group_id) {}
+
+ static ConsumerGroupInfo FromFfi(ffi::ConsumerGroupInfo info);
+
+ friend class ClientInfoDetails;
+
+ std::uint32_t stream_id_;
+ std::uint32_t topic_id_;
+ std::uint32_t group_id_;
+};
+
+/**
+ * @brief Snapshot summary of a client connection known to the server.
+ *
+ * GetClients() returns one summary for each connection observed by the server.
+ * A client is a transport connection, not an Iggy user. Connections can close,
+ * authenticate, or change consumer-group membership immediately after the
+ * request completes.
+ */
+class ClientInfo final {
+ public:
+ /**
+ * @brief Returns the server-assigned connection ID.
+ * @return Numeric client ID accepted by GetClient() while the connection
+ * remains known to the server.
+ */
+ [[nodiscard]] std::uint32_t ClientId() const noexcept { return client_id_; }
+
+ /**
+ * @brief Returns the authenticated user ID for this connection.
+ * @return Empty when the client has not authenticated.
+ */
+ [[nodiscard]] const std::optional<std::uint32_t> &UserId() const noexcept { return user_id_; }
+
+ /**
+ * @brief Returns the remote address reported by the server.
+ * @return Address owned by this value.
+ */
+ [[nodiscard]] const std::string &Address() const noexcept { return address_; }
+
+ /**
+ * @brief Returns the transport name reported by the server.
+ * @return Transport name owned by this value.
+ */
+ [[nodiscard]] const std::string &Transport() const noexcept { return transport_; }
+
+ /**
+ * @brief Returns the number of consumer groups joined by this client.
+ * @return Membership count observed for this request.
+ */
+ [[nodiscard]] std::uint32_t ConsumerGroupsCount() const noexcept { return consumer_groups_count_; }
+
+ private:
+ ClientInfo(std::uint32_t client_id,
+ std::optional<std::uint32_t> user_id,
+ std::string address,
+ std::string transport,
+ std::uint32_t consumer_groups_count)
+ : client_id_(client_id),
+ user_id_(user_id),
+ address_(std::move(address)),
+ transport_(std::move(transport)),
+ consumer_groups_count_(consumer_groups_count) {}
+
+ static ClientInfo FromFfi(ffi::ClientInfo info);
+
+ friend class IggyBlockingClient;
+
+ std::uint32_t client_id_;
+ std::optional<std::uint32_t> user_id_;
+ std::string address_;
+ std::string transport_;
+ std::uint32_t consumer_groups_count_;
+};
+
+/**
+ * @brief Snapshot of a client connection and its consumer-group memberships.
+ *
+ * GetMe() and GetClient() return this detailed form. The connection state and
+ * memberships are not live and can change immediately after retrieval.
+ */
+class ClientInfoDetails final {
+ public:
+ /**
+ * @brief Returns the server-assigned connection ID.
+ * @return Numeric client ID.
+ */
+ [[nodiscard]] std::uint32_t ClientId() const noexcept { return client_id_; }
+
+ /**
+ * @brief Returns the authenticated user ID for this connection.
+ * @return Empty when the client has not authenticated.
+ */
+ [[nodiscard]] const std::optional<std::uint32_t> &UserId() const noexcept { return user_id_; }
+
+ /**
+ * @brief Returns the remote address reported by the server.
+ * @return Address owned by this value.
+ */
+ [[nodiscard]] const std::string &Address() const noexcept { return address_; }
+
+ /**
+ * @brief Returns the transport name reported by the server.
+ * @return Transport name owned by this value.
+ */
+ [[nodiscard]] const std::string &Transport() const noexcept { return transport_; }
+
+ /**
+ * @brief Returns the server-reported consumer-group membership count.
+ * @return Membership count observed for this request.
+ */
+ [[nodiscard]] std::uint32_t ConsumerGroupsCount() const noexcept { return consumer_groups_count_; }
+
+ /**
+ * @brief Returns the observed consumer-group memberships.
+ * @return Membership identifiers owned by this value.
+ */
+ [[nodiscard]] const std::vector<ConsumerGroupInfo> &ConsumerGroups() const noexcept { return consumer_groups_; }
+
+ private:
+ ClientInfoDetails(std::uint32_t client_id,
+ std::optional<std::uint32_t> user_id,
+ std::string address,
+ std::string transport,
+ std::uint32_t consumer_groups_count,
+ std::vector<ConsumerGroupInfo> consumer_groups)
+ : client_id_(client_id),
+ user_id_(user_id),
+ address_(std::move(address)),
+ transport_(std::move(transport)),
+ consumer_groups_count_(consumer_groups_count),
+ consumer_groups_(std::move(consumer_groups)) {}
+
+ static ClientInfoDetails FromFfi(ffi::ClientInfoDetails info);
+
+ friend class IggyBlockingClient;
+
+ std::uint32_t client_id_;
+ std::optional<std::uint32_t> user_id_;
+ std::string address_;
+ std::string transport_;
+ std::uint32_t consumer_groups_count_;
+ std::vector<ConsumerGroupInfo> consumer_groups_;
+};
+
+/**
+ * @brief Cache counters for one stream, topic, and partition.
+ *
+ * Stats::CacheMetrics() contains these entries when the server implementation
+ * reports partition cache metrics. The current VSR server returns an empty
+ * cache-metrics collection.
+ */
+class CacheMetricEntry final {
+ public:
+ /**
+ * @brief Returns the numeric stream ID for this cache entry.
+ * @return Numeric stream ID.
+ */
+ [[nodiscard]] std::uint32_t StreamId() const noexcept { return stream_id_; }
+
+ /**
+ * @brief Returns the numeric topic ID for this cache entry.
+ * @return Numeric topic ID.
+ */
+ [[nodiscard]] std::uint32_t TopicId() const noexcept { return topic_id_; }
+
+ /**
+ * @brief Returns the numeric partition ID for this cache entry.
+ * @return Numeric partition ID.
+ */
+ [[nodiscard]] std::uint32_t PartitionId() const noexcept { return partition_id_; }
+
+ /**
+ * @brief Returns the cumulative number of cache hits reported by the server.
+ * @return Cache hit count.
+ */
+ [[nodiscard]] std::uint64_t Hits() const noexcept { return hits_; }
+
+ /**
+ * @brief Returns the cumulative number of cache misses reported by the server.
+ * @return Cache miss count.
+ */
+ [[nodiscard]] std::uint64_t Misses() const noexcept { return misses_; }
+
+ /**
+ * @brief Returns the server-reported ratio of hits to total cache lookups.
+ * @return Cache hit ratio.
+ */
+ [[nodiscard]] float HitRatio() const noexcept { return hit_ratio_; }
+
+ private:
+ CacheMetricEntry(std::uint32_t stream_id,
+ std::uint32_t topic_id,
+ std::uint32_t partition_id,
+ std::uint64_t hits,
+ std::uint64_t misses,
+ float hit_ratio)
+ : stream_id_(stream_id),
+ topic_id_(topic_id),
+ partition_id_(partition_id),
+ hits_(hits),
+ misses_(misses),
+ hit_ratio_(hit_ratio) {}
+
+ static CacheMetricEntry FromFfi(ffi::CacheMetricEntry entry);
+
+ friend class Stats;
+
+ std::uint32_t stream_id_;
+ std::uint32_t topic_id_;
+ std::uint32_t partition_id_;
+ std::uint64_t hits_;
+ std::uint64_t misses_;
+ float hit_ratio_;
+};
+
+/**
+ * @brief Snapshot of server process, storage, and resource statistics.
+ *
+ * GetStats() returns process and host measurements from the serving server,
+ * together with metadata totals observed for one request. Values are not a
+ * live or transactional view. CPU measurements depend on the server's sampling
+ * history, and the first sample on a serving thread can report zero. Memory
+ * totals honor an effective cgroup limit when one applies. Disk-space values
+ * describe the volume containing the configured data directory and can be zero
+ * when the server cannot probe that volume.
+ */
+class Stats final {
+ public:
+ /**
+ * @brief Returns the operating-system process ID of the server.
+ * @return Numeric process ID.
+ */
+ [[nodiscard]] std::uint32_t ProcessId() const noexcept { return process_id_; }
+
+ /**
+ * @brief Returns the server process CPU usage.
+ * @return Process CPU usage as a percentage.
+ */
+ [[nodiscard]] float CpuUsage() const noexcept { return cpu_usage_; }
+
+ /**
+ * @brief Returns total CPU usage for the available CPU set.
+ * @return Total CPU usage as a percentage.
+ */
+ [[nodiscard]] float TotalCpuUsage() const noexcept { return total_cpu_usage_; }
+
+ /**
+ * @brief Returns server process memory usage.
+ * @return Process memory usage in bytes.
+ */
+ [[nodiscard]] std::uint64_t MemoryUsage() const noexcept { return memory_usage_; }
+
+ /**
+ * @brief Returns total host or effective cgroup memory.
+ * @return Total memory in bytes.
+ */
+ [[nodiscard]] std::uint64_t TotalMemory() const noexcept { return total_memory_; }
+
+ /**
+ * @brief Returns available host or effective cgroup memory.
+ * @return Available memory in bytes.
+ */
+ [[nodiscard]] std::uint64_t AvailableMemory() const noexcept { return available_memory_; }
+
+ /**
+ * @brief Returns server process uptime.
+ * @return Process uptime in microseconds.
+ */
+ [[nodiscard]] std::uint64_t RunTimeMicros() const noexcept { return run_time_micros_; }
- std::uint32_t id_;
- std::uint64_t created_at_;
- std::string name_;
- std::uint64_t size_bytes_;
- std::uint64_t messages_count_;
- std::uint32_t topics_count_;
- ResourceOptions options_;
-};
+ /**
+ * @brief Returns the server process start time.
+ * @return Timestamp in microseconds since the Unix epoch.
+ */
+ [[nodiscard]] std::uint64_t StartTimeEpochMicros() const noexcept { return start_time_epoch_micros_; }
-/**
- * @brief Snapshot of a consumer group member and its partition assignments.
- *
- * ConsumerGroupDetails contains one of these values for every member observed
- * by the server. Membership and partition assignments can change immediately
- * after the request completes.
- */
-class ConsumerGroupMember final {
- public:
/**
- * @brief Returns the numeric ID of the consumer group member.
- * @return Numeric member ID assigned by the server.
+ * @brief Returns the server process read-byte count.
+ * @return Number of bytes read by the process.
*/
- [[nodiscard]] std::uint32_t Id() const noexcept { return id_; }
+ [[nodiscard]] std::uint64_t ReadBytes() const noexcept { return read_bytes_; }
/**
- * @brief Returns the server-reported number of partitions assigned to this member.
- * @return Partition count reported by the server.
+ * @brief Returns the server process written-byte count.
+ * @return Number of bytes written by the process.
*/
- [[nodiscard]] std::uint32_t PartitionsCount() const noexcept { return partitions_count_; }
+ [[nodiscard]] std::uint64_t WrittenBytes() const noexcept { return written_bytes_; }
/**
- * @brief Returns the partitions assigned to this member.
- * @return Partition IDs owned by this value. The reference remains valid
- * while this ConsumerGroupMember remains alive.
+ * @brief Returns the aggregate retained message size.
+ * @return Retained message size in bytes.
*/
- [[nodiscard]] const std::vector<std::uint32_t> &Partitions() const noexcept { return partitions_; }
+ [[nodiscard]] std::uint64_t MessagesSizeBytes() const noexcept { return messages_size_bytes_; }
- private:
- ConsumerGroupMember(std::uint32_t id, std::uint32_t partitions_count, std::vector<std::uint32_t> partitions)
- : id_(id), partitions_count_(partitions_count), partitions_(std::move(partitions)) {}
+ /**
+ * @brief Returns the observed number of streams.
+ * @return Stream count.
+ */
+ [[nodiscard]] std::uint32_t StreamsCount() const noexcept { return streams_count_; }
- static ConsumerGroupMember FromFfi(ffi::ConsumerGroupMember member);
+ /**
+ * @brief Returns the observed number of topics.
+ * @return Topic count.
+ */
+ [[nodiscard]] std::uint32_t TopicsCount() const noexcept { return topics_count_; }
- friend class ConsumerGroupDetails;
+ /**
+ * @brief Returns the observed number of partitions.
+ * @return Partition count.
+ */
+ [[nodiscard]] std::uint32_t PartitionsCount() const noexcept { return partitions_count_; }
- std::uint32_t id_;
- std::uint32_t partitions_count_;
- std::vector<std::uint32_t> partitions_;
-};
+ /**
+ * @brief Returns the observed number of partition segments.
+ * @return Segment count.
+ */
+ [[nodiscard]] std::uint32_t SegmentsCount() const noexcept { return segments_count_; }
-/**
- * @brief Snapshot of consumer group metadata.
- *
- * GetConsumerGroups() returns one summary for each consumer group observed in
- * a topic. Use GetConsumerGroup() when individual member and partition
- * assignment details are needed.
- */
-class ConsumerGroup final {
- public:
/**
- * @brief Returns the numeric ID assigned to the consumer group.
- * @return Numeric consumer group ID.
+ * @brief Returns the observed number of retained messages.
+ * @return Message count.
*/
- [[nodiscard]] std::uint32_t Id() const noexcept { return id_; }
+ [[nodiscard]] std::uint64_t MessagesCount() const noexcept { return messages_count_; }
/**
- * @brief Returns the consumer group name.
- * @return Name owned by this value.
+ * @brief Returns the number of client connections observed by the server.
+ * @return Client connection count.
*/
- [[nodiscard]] const std::string &Name() const noexcept { return name_; }
+ [[nodiscard]] std::uint32_t ClientsCount() const noexcept { return clients_count_; }
/**
- * @brief Returns the number of partitions consumed by the group.
- * @return Partition count observed by the server for this request.
+ * @brief Returns the observed number of consumer groups.
+ * @return Consumer group count.
*/
- [[nodiscard]] std::uint32_t PartitionsCount() const noexcept { return partitions_count_; }
+ [[nodiscard]] std::uint32_t ConsumerGroupsCount() const noexcept { return consumer_groups_count_; }
/**
- * @brief Returns the number of members in the group.
- * @return Member count observed by the server for this request.
+ * @brief Returns the server host name.
+ * @return Host name owned by this value.
*/
- [[nodiscard]] std::uint32_t MembersCount() const noexcept { return members_count_; }
+ [[nodiscard]] const std::string &Hostname() const noexcept { return hostname_; }
- private:
- ConsumerGroup(std::uint32_t id, std::string name, std::uint32_t partitions_count, std::uint32_t members_count)
- : id_(id), name_(std::move(name)), partitions_count_(partitions_count), members_count_(members_count) {}
+ /**
+ * @brief Returns the server operating-system name.
+ * @return Operating-system name owned by this value.
+ */
+ [[nodiscard]] const std::string &OsName() const noexcept { return os_name_; }
- static ConsumerGroup FromFfi(ffi::ConsumerGroup group);
+ /**
+ * @brief Returns the server operating-system version.
+ * @return Operating-system version owned by this value.
+ */
+ [[nodiscard]] const std::string &OsVersion() const noexcept { return os_version_; }
- friend class IggyBlockingClient;
+ /**
+ * @brief Returns the server kernel version.
+ * @return Kernel version owned by this value.
+ */
+ [[nodiscard]] const std::string &KernelVersion() const noexcept { return kernel_version_; }
- std::uint32_t id_;
- std::string name_;
- std::uint32_t partitions_count_;
- std::uint32_t members_count_;
-};
+ /**
+ * @brief Returns the human-readable Iggy server version.
+ * @return Version string owned by this value.
+ */
+ [[nodiscard]] const std::string &IggyServerVersion() const noexcept { return iggy_server_version_; }
-/**
- * @brief Snapshot of consumer group metadata and member details.
- *
- * CreateConsumerGroup() and GetConsumerGroup() return this value. Membership
- * and partition assignments can change immediately after the request
- * completes.
- */
-class ConsumerGroupDetails final {
- public:
/**
- * @brief Returns the numeric ID assigned to the consumer group.
- * @return Numeric consumer group ID.
+ * @brief Returns the numeric semantic version when reported by the server.
+ * @return `major * 1,000,000 + minor * 1,000 + patch`, or `std::nullopt`
+ * when the server does not report a numeric version.
*/
- [[nodiscard]] std::uint32_t Id() const noexcept { return id_; }
+ [[nodiscard]] const std::optional<std::uint32_t> &ServerSemver() const noexcept { return server_semver_; }
/**
- * @brief Returns the consumer group name.
- * @return Name owned by this value.
+ * @brief Returns partition cache metrics reported by the server.
+ * @return Entries owned by this value. The current VSR server returns an
+ * empty collection.
*/
- [[nodiscard]] const std::string &Name() const noexcept { return name_; }
+ [[nodiscard]] const std::vector<CacheMetricEntry> &CacheMetrics() const noexcept { return cache_metrics_; }
/**
- * @brief Returns the number of partitions consumed by the group.
- * @return Partition count observed by the server for this request.
+ * @brief Returns the number of threads in the server process.
+ * @return Process thread count.
*/
- [[nodiscard]] std::uint32_t PartitionsCount() const noexcept { return partitions_count_; }
+ [[nodiscard]] std::uint32_t ThreadsCount() const noexcept { return threads_count_; }
/**
- * @brief Returns the server-reported number of members in the group.
- * @return Member count reported by the server.
+ * @brief Returns free space on the server data-directory volume.
+ * @return Free space in bytes, or zero when the probe is unavailable.
*/
- [[nodiscard]] std::uint32_t MembersCount() const noexcept { return members_count_; }
+ [[nodiscard]] std::uint64_t FreeDiskSpace() const noexcept { return free_disk_space_; }
/**
- * @brief Returns the consumer group members and their partition assignments.
- * @return Member details owned by this value. The reference remains valid
- * while this ConsumerGroupDetails remains alive.
+ * @brief Returns total space on the server data-directory volume.
+ * @return Total space in bytes, or zero when the probe is unavailable.
*/
- [[nodiscard]] const std::vector<ConsumerGroupMember> &Members() const noexcept { return members_; }
+ [[nodiscard]] std::uint64_t TotalDiskSpace() const noexcept { return total_disk_space_; }
private:
- ConsumerGroupDetails(std::uint32_t id,
- std::string name,
- std::uint32_t partitions_count,
- std::uint32_t members_count,
- std::vector<ConsumerGroupMember> members)
- : id_(id),
- name_(std::move(name)),
+ Stats(std::uint32_t process_id,
+ float cpu_usage,
+ float total_cpu_usage,
+ std::uint64_t memory_usage,
+ std::uint64_t total_memory,
+ std::uint64_t available_memory,
+ std::uint64_t run_time_micros,
+ std::uint64_t start_time_epoch_micros,
+ std::uint64_t read_bytes,
+ std::uint64_t written_bytes,
+ std::uint64_t messages_size_bytes,
+ std::uint32_t streams_count,
+ std::uint32_t topics_count,
+ std::uint32_t partitions_count,
+ std::uint32_t segments_count,
+ std::uint64_t messages_count,
+ std::uint32_t clients_count,
+ std::uint32_t consumer_groups_count,
+ std::string hostname,
+ std::string os_name,
+ std::string os_version,
+ std::string kernel_version,
+ std::string iggy_server_version,
+ std::optional<std::uint32_t> server_semver,
+ std::vector<CacheMetricEntry> cache_metrics,
+ std::uint32_t threads_count,
+ std::uint64_t free_disk_space,
+ std::uint64_t total_disk_space)
+ : process_id_(process_id),
+ cpu_usage_(cpu_usage),
+ total_cpu_usage_(total_cpu_usage),
+ memory_usage_(memory_usage),
+ total_memory_(total_memory),
+ available_memory_(available_memory),
+ run_time_micros_(run_time_micros),
+ start_time_epoch_micros_(start_time_epoch_micros),
+ read_bytes_(read_bytes),
+ written_bytes_(written_bytes),
+ messages_size_bytes_(messages_size_bytes),
+ streams_count_(streams_count),
+ topics_count_(topics_count),
partitions_count_(partitions_count),
- members_count_(members_count),
- members_(std::move(members)) {}
-
- static ConsumerGroupDetails FromFfi(ffi::ConsumerGroupDetails group);
+ segments_count_(segments_count),
+ messages_count_(messages_count),
+ clients_count_(clients_count),
+ consumer_groups_count_(consumer_groups_count),
+ hostname_(std::move(hostname)),
+ os_name_(std::move(os_name)),
+ os_version_(std::move(os_version)),
+ kernel_version_(std::move(kernel_version)),
+ iggy_server_version_(std::move(iggy_server_version)),
+ server_semver_(server_semver),
+ cache_metrics_(std::move(cache_metrics)),
+ threads_count_(threads_count),
+ free_disk_space_(free_disk_space),
+ total_disk_space_(total_disk_space) {}
+
+ static Stats FromFfi(ffi::Stats stats);
friend class IggyBlockingClient;
- std::uint32_t id_;
- std::string name_;
+ std::uint32_t process_id_;
+ float cpu_usage_;
+ float total_cpu_usage_;
+ std::uint64_t memory_usage_;
+ std::uint64_t total_memory_;
+ std::uint64_t available_memory_;
+ std::uint64_t run_time_micros_;
+ std::uint64_t start_time_epoch_micros_;
+ std::uint64_t read_bytes_;
+ std::uint64_t written_bytes_;
+ std::uint64_t messages_size_bytes_;
+ std::uint32_t streams_count_;
+ std::uint32_t topics_count_;
std::uint32_t partitions_count_;
- std::uint32_t members_count_;
- std::vector<ConsumerGroupMember> members_;
+ std::uint32_t segments_count_;
+ std::uint64_t messages_count_;
+ std::uint32_t clients_count_;
+ std::uint32_t consumer_groups_count_;
+ std::string hostname_;
+ std::string os_name_;
+ std::string os_version_;
+ std::string kernel_version_;
+ std::string iggy_server_version_;
+ std::optional<std::uint32_t> server_semver_;
+ std::vector<CacheMetricEntry> cache_metrics_;
+ std::uint32_t threads_count_;
+ std::uint64_t free_disk_space_;
+ std::uint64_t total_disk_space_;
};
/**
@@ -1471,7 +2630,18 @@ class Expiry final {
std::uint64_t expiry_value_;
};
-enum class Durability : std::uint8_t { Replicated, Persisted };
+/**
+ * @brief Storage guarantee required before an operation reports completion.
+ *
+ * Both policies persist data through the replicated journal. Replicated waits
+ * for quorum commit without an additional stable-storage barrier. Persisted
+ * also requires recoverable stable-storage copies on the quorum. Topic message
+ * durability and consumer-offset durability are configured independently.
+ */
+enum class Durability : std::uint8_t {
+ Replicated, ///< Wait for quorum commit.
+ Persisted, ///< Wait for quorum commit backed by stable storage.
+};
constexpr std::string_view to_string(const Durability durability) {
switch (durability) {
@@ -1927,6 +3097,61 @@ class StreamUpdateOptions final {
friend class IggyBlockingClient;
};
+/**
+ * @brief Options for updating a user.
+ *
+ * Use this class to supply user settings to UpdateUser(). Updating a user
+ * patches only the supplied settings; omitted settings remain unchanged.
+ * Currently, Iggy does not support updating user settings, so the server
+ * rejects every supplied setting. The raw entries are retained for
+ * compatibility with future server versions that add mutable user settings.
+ */
+class UserUpdateOptions final {
+ public:
+ /** @brief Creates an update with no requested user settings. */
+ UserUpdateOptions() = default;
+
+ /**
+ * @brief Returns the requested user settings as key-value pairs.
+ * @return Ordered map of setting names and values.
+ * @note The server currently rejects all user settings.
+ */
+ [[nodiscard]] const std::map<std::string, std::string> &RawEntries() const noexcept { return raw_; }
+
+ /**
+ * @brief Adds or replaces requested user settings.
+ * @param entries Setting names and values to add.
+ * @return Reference to this options object.
+ * @note The server currently rejects all user settings.
+ */
+ UserUpdateOptions &SetRawEntries(const std::map<std::string, std::string> &entries) {
+ for (const auto &entry : entries) {
+ raw_.insert_or_assign(entry.first, entry.second);
+ }
+ return *this;
+ }
+ /**
+ * @brief Adds or replaces requested user settings.
+ * @param entries Setting names and values to move into this options object.
+ * @return Reference to this options object.
+ * @see SetRawEntries(const std::map<std::string, std::string>&)
+ * @note The server currently rejects all user settings.
+ */
+ UserUpdateOptions &SetRawEntries(std::map<std::string, std::string> &&entries) {
+ while (!entries.empty()) {
+ auto node = entries.extract(entries.begin());
+ raw_.erase(node.key());
+ raw_.insert(std::move(node));
+ }
+ return *this;
+ }
+
+ private:
+ std::map<std::string, std::string> raw_;
+
+ friend class IggyBlockingClient;
+};
+
/**
* @brief Starting position for polling messages.
*
@@ -2205,6 +3430,109 @@ class IggyBlockingClient final {
*/
void Logout();
+ /**
+ * @brief Retrieves one user by numeric ID or name.
+ *
+ * An authenticated user may retrieve its own account without the global
+ * read-users grant. Reading another account requires read-users or
+ * manage-users permission. The result is a snapshot and includes the
+ * target user's optional permission assignment.
+ *
+ * @param user User to retrieve, addressed by numeric ID or name.
+ * @return Details for the requested user.
+ * @throws IggyException if the client is unavailable or unauthenticated;
+ * the identifier is invalid; the user does not exist; the caller
+ * lacks permission; or the request fails.
+ */
+ UserInfoDetails GetUser(const Identifier &user);
+
+ /**
+ * @brief Lists user summaries visible to the authenticated caller.
+ *
+ * The summaries omit permissions. Use GetUser() to retrieve one user's
+ * permission assignment.
+ *
+ * @return User summaries observed by the server for this request.
+ * @throws IggyException if the client is unavailable or unauthenticated;
+ * the caller lacks read-users or manage-users permission; or the
+ * request fails.
+ */
+ std::vector<UserInfo> GetUsers();
+
+ /**
+ * @brief Creates a user account.
+ *
+ * User names must contain between 3 and 50 bytes and be unique. Passwords
+ * must contain between 3 and 100 bytes. An inactive account is created but
+ * cannot authenticate. Passing `std::nullopt` assigns no permission object;
+ * passing a default-constructed Permissions assigns an explicit permission
+ * object with no enabled grants.
+ *
+ * A failed or unknown transport outcome can leave the user created. Query
+ * the account by name before retrying this request.
+ *
+ * @param username Unique user name.
+ * @param password Initial user password.
+ * @param status Initial authentication status.
+ * @param permissions Optional permission assignment.
+ * @return Details of the newly created user.
+ * @throws IggyException if the client is unavailable or unauthenticated;
+ * the name, password, status, or permissions are invalid; the name
+ * is already in use; the caller lacks manage-users permission; or
+ * the request fails.
+ */
+ UserInfoDetails CreateUser(std::string username,
+ std::string password,
+ UserStatus status,
+ const std::optional<Permissions> &permissions = std::nullopt);
+
+ /**
+ * @brief Deletes a user account.
+ *
+ * The root user cannot be deleted. Deleting another user also removes its
+ * permission assignment and personal access tokens. A failed or unknown
+ * transport outcome can leave the deletion committed; look up the user
+ * before retrying.
+ *
+ * @param user User to delete, addressed by numeric ID or name.
+ * @throws IggyException if the client is unavailable or unauthenticated;
+ * the identifier is invalid; the user does not exist or is the
+ * root user; the caller lacks manage-users permission; or the
+ * request fails.
+ */
+ void DeleteUser(const Identifier &user);
+
+ /**
+ * @brief Changes a user's name, status, and mutable settings.
+ *
+ * A supplied name must contain between 3 and 50 bytes and remain unique.
+ * Setting the status to inactive prevents subsequent authentication.
+ * Passing `std::nullopt` for the name or status leaves that field
+ * unchanged. The supplied UserUpdateOptions changes only the settings it
+ * contains; settings left unset retain their current values. User settings
+ * are currently not mutable, so the options object must be empty. Passing
+ * `std::nullopt` for both fields and an empty options object is accepted as
+ * a no-op.
+ *
+ * A failed or unknown transport outcome can leave the update committed.
+ * Retrieve the user before retrying with different values.
+ *
+ * @param user User to update, addressed by numeric ID or name.
+ * @param username New unique name, or `std::nullopt` to retain the name.
+ * @param status New authentication status, or `std::nullopt` to retain the
+ * status.
+ * @param options User update options.
+ * @throws IggyException if the client is unavailable or unauthenticated;
+ * an identifier, name, status, or option is invalid; an option is
+ * unsupported; the user does not exist; the name is already in
+ * use; the caller lacks manage-users permission; or the request
+ * fails.
+ */
+ void UpdateUser(const Identifier &user,
+ std::optional<std::string> username,
+ std::optional<UserStatus> status,
+ const UserUpdateOptions &options = {});
+
/**
* @brief Creates a top-level stream in the cluster metadata.
*
@@ -2423,6 +3751,32 @@ class IggyBlockingClient final {
*/
void DeletePartitions(const Identifier &stream, const Identifier &topic, std::uint32_t partitions_count);
+ /**
+ * @brief Deletes the oldest sealed segments from one partition.
+ *
+ * The active segment is never deleted. If fewer sealed segments exist than
+ * requested, every sealed segment is selected. A count of zero, or a
+ * partition with no sealed segments, succeeds without deleting data. The
+ * server commits a truncation watermark before local replicas remove the
+ * selected segment files.
+ *
+ * A failed or unknown transport outcome can leave the truncation committed.
+ * Inspect the partition before retrying this destructive request.
+ *
+ * @param stream Parent stream, addressed by numeric ID or name.
+ * @param topic Parent topic, addressed by numeric ID or name.
+ * @param partition_id Numeric partition ID.
+ * @param segments_count Maximum number of oldest sealed segments to delete.
+ * @throws IggyException if the client is unavailable or unauthenticated;
+ * an identifier or partition is invalid; the stream, topic, or
+ * partition does not exist; the caller lacks topic-management
+ * permission; or the request fails.
+ */
+ void DeleteSegments(const Identifier &stream,
+ const Identifier &topic,
+ std::uint32_t partition_id,
+ std::uint32_t segments_count);
+
/**
* @brief Creates a consumer group for a topic.
*
@@ -2621,6 +3975,63 @@ class IggyBlockingClient final {
const Identifier &topic,
std::optional<std::uint32_t> partition_id = std::nullopt);
+ /**
+ * @brief Retrieves details for this client connection.
+ *
+ * The result includes consumer-group memberships observed for the current
+ * authenticated connection. HTTP is stateless and does not expose a
+ * persistent current connection, so the HTTP transport reports this
+ * operation as unavailable.
+ *
+ * @return Details for the current client connection.
+ * @throws IggyException if the client is unavailable or unauthenticated;
+ * the transport does not support the operation; or the request
+ * fails.
+ */
+ ClientInfoDetails GetMe();
+
+ /**
+ * @brief Retrieves one currently connected client by numeric ID.
+ *
+ * The result is a snapshot containing the connection's observed consumer-
+ * group memberships. The connection can disappear immediately after the
+ * request completes.
+ *
+ * @param client_id Server-assigned connection ID.
+ * @return Details for the requested client connection.
+ * @throws IggyException if the client is unavailable or unauthenticated;
+ * the requested connection does not exist; the caller lacks
+ * read-servers or manage-servers permission; or the request fails.
+ */
+ ClientInfoDetails GetClient(std::uint32_t client_id);
+
+ /**
+ * @brief Lists client connections currently known to the server.
+ *
+ * Each entry is a snapshot summary and omits individual consumer-group
+ * identifiers. Use GetClient() for membership details.
+ *
+ * @return Client connection summaries observed for this request.
+ * @throws IggyException if the client is unavailable or unauthenticated;
+ * the caller lacks read-servers or manage-servers permission; or
+ * the request fails.
+ */
+ std::vector<ClientInfo> GetClients();
+
+ /**
+ * @brief Retrieves server process, storage, and resource statistics.
+ *
+ * The returned fields are an observed snapshot and can change immediately.
+ * Process and host measurements describe the server that handles the
+ * request; metadata totals describe the state visible to that server.
+ *
+ * @return Statistics observed for this request.
+ * @throws IggyException if the client is unavailable or unauthenticated;
+ * the caller lacks read-servers or manage-servers permission; or
+ * the request fails.
+ */
+ Stats GetStats();
+
private:
explicit IggyBlockingClient(ffi::Client *client);
diff --git a/foreign/cpp/src/client.cpp b/foreign/cpp/src/client.cpp
index d5a3ca3f4..d1d969493 100644
--- a/foreign/cpp/src/client.cpp
+++ b/foreign/cpp/src/client.cpp
@@ -104,6 +104,49 @@ void IggyBlockingClient::Logout() {
RethrowAsIggyException([this] { Handle()->logout_user(); });
}
+UserInfoDetails IggyBlockingClient::GetUser(const Identifier &user) {
+ return RethrowAsIggyException([this, &user] { return UserInfoDetails::FromFfi(Handle()->get_user(user.ToFfi())); });
+}
+
+std::vector<UserInfo> IggyBlockingClient::GetUsers() {
+ return RethrowAsIggyException([this] {
+ std::vector<UserInfo> users;
+ auto ffi_users = Handle()->get_users();
+ users.reserve(ffi_users.size());
+ for (auto &user : ffi_users) {
+ users.push_back(UserInfo::FromFfi(std::move(user)));
+ }
+ return users;
+ });
+}
+
+UserInfoDetails IggyBlockingClient::CreateUser(std::string username,
+ std::string password,
+ UserStatus status,
+ const std::optional<Permissions> &permissions) {
+ return RethrowAsIggyException([this, &username, &password, status, &permissions] {
+ auto ffi_permissions = permissions ? permissions->ToFfi() : ffi::Permissions{};
+ return UserInfoDetails::FromFfi(Handle()->create_user(username, password, static_cast<ffi::UserStatus>(status),
+ permissions.has_value(), std::move(ffi_permissions)));
+ });
+}
+
+void IggyBlockingClient::DeleteUser(const Identifier &user) {
+ RethrowAsIggyException([this, &user] { Handle()->delete_user(user.ToFfi()); });
+}
+
+void IggyBlockingClient::UpdateUser(const Identifier &user,
+ std::optional<std::string> username,
+ std::optional<UserStatus> status,
+ const UserUpdateOptions &options) {
+ RethrowAsIggyException([this, &user, &username, status, &options] {
+ auto ffi_options = ToFfiRawOptions(options.RawEntries());
+ Handle()->update_user(user.ToFfi(), username.has_value(), username.value_or(""), status.has_value(),
+ static_cast<ffi::UserStatus>(status.value_or(UserStatus::Active)),
+ std::move(ffi_options));
+ });
+}
+
StreamDetails IggyBlockingClient::CreateStream(std::string name) {
return RethrowAsIggyException([this, &name] { return StreamDetails::FromFfi(Handle()->create_stream(name)); });
}
@@ -252,6 +295,15 @@ void IggyBlockingClient::DeletePartitions(const Identifier &stream,
});
}
+void IggyBlockingClient::DeleteSegments(const Identifier &stream,
+ const Identifier &topic,
+ const std::uint32_t partition_id,
+ const std::uint32_t segments_count) {
+ RethrowAsIggyException([this, &stream, &topic, partition_id, segments_count] {
+ Handle()->delete_segments(stream.ToFfi(), topic.ToFfi(), partition_id, segments_count);
+ });
+}
+
ConsumerGroupDetails IggyBlockingClient::CreateConsumerGroup(const Identifier &stream,
const Identifier &topic,
std::string name) {
@@ -349,6 +401,31 @@ void IggyBlockingClient::DeleteConsumerOffset(const Consumer &consumer,
});
}
+ClientInfoDetails IggyBlockingClient::GetMe() {
+ return RethrowAsIggyException([this] { return ClientInfoDetails::FromFfi(Handle()->get_me()); });
+}
+
+ClientInfoDetails IggyBlockingClient::GetClient(std::uint32_t client_id) {
+ return RethrowAsIggyException(
+ [this, client_id] { return ClientInfoDetails::FromFfi(Handle()->get_client(client_id)); });
+}
+
+std::vector<ClientInfo> IggyBlockingClient::GetClients() {
+ return RethrowAsIggyException([this] {
+ std::vector<ClientInfo> clients;
+ auto ffi_clients = Handle()->get_clients();
+ clients.reserve(ffi_clients.size());
+ for (auto &client : ffi_clients) {
+ clients.push_back(ClientInfo::FromFfi(std::move(client)));
+ }
+ return clients;
+ });
+}
+
+Stats IggyBlockingClient::GetStats() {
+ return RethrowAsIggyException([this] { return Stats::FromFfi(Handle()->get_stats()); });
+}
+
IggyBlockingClient::IggyBlockingClient(ffi::Client *client) : client_(client) {
if (client_ == nullptr) {
throw IggyException("Could not create Iggy client");
diff --git a/foreign/cpp/src/client.rs b/foreign/cpp/src/client.rs
index 9cd8e3d55..abd08b8e3 100644
--- a/foreign/cpp/src/client.rs
+++ b/foreign/cpp/src/client.rs
@@ -1139,6 +1139,7 @@ impl Client {
username: String,
has_status: bool,
status: ffi::UserStatus,
+ options: Vec<ffi::HeaderEntry>,
) -> Result<(), String> {
let rust_user_id = RustIdentifier::try_from(user_id)
.map_err(|error| format!("Could not update user: invalid user identifier: {error}"))?;
@@ -1146,6 +1147,9 @@ impl Client {
.then(|| RustUserStatus::try_from(status))
.transpose()
.map_err(|error| format!("Could not update user '{rust_user_id}': {error}"))?;
+ let raw = ffi_options_to_raw(options)
+ .map_err(|error| format!("Could not update user '{rust_user_id}': {error}"))?;
+ let rust_options = UserUpdateOptions { raw };
RUNTIME.block_on(async {
self.inner
@@ -1153,7 +1157,7 @@ impl Client {
&rust_user_id,
has_username.then_some(username.as_str()),
rust_status,
- &UserUpdateOptions::default(),
+ &rust_options,
)
.await
.map_err(|error| format!("Could not update user '{rust_user_id}': {error}"))?;
diff --git a/foreign/cpp/src/lib.rs b/foreign/cpp/src/lib.rs
index b07c4b93b..1835b0260 100644
--- a/foreign/cpp/src/lib.rs
+++ b/foreign/cpp/src/lib.rs
@@ -382,6 +382,7 @@ mod ffi {
created_at: u64,
status: UserStatus,
username: String,
+ options: Vec<HeaderEntry>,
}
struct UserInfoDetails {
@@ -391,6 +392,7 @@ mod ffi {
username: String,
has_permissions: bool,
permissions: Permissions,
+ options: Vec<HeaderEntry>,
}
struct LoginInfo {
@@ -649,6 +651,7 @@ mod ffi {
username: String,
has_status: bool,
status: UserStatus,
+ options: Vec<HeaderEntry>,
) -> Result<()>;
fn update_permissions(
self: &Client,
diff --git a/foreign/cpp/src/type_conversion.rs b/foreign/cpp/src/type_conversion.rs
index 0d95a692f..9c55c7809 100644
--- a/foreign/cpp/src/type_conversion.rs
+++ b/foreign/cpp/src/type_conversion.rs
@@ -158,6 +158,7 @@ impl From<RustUserInfo> for ffi::UserInfo {
created_at: user.created_at.as_micros(),
status: ffi::UserStatus::from(user.status),
username: user.username,
+ options: resource_options_to_ffi(&user.options, true),
}
}
}
@@ -172,6 +173,7 @@ impl From<RustUserInfoDetails> for ffi::UserInfoDetails {
username: user.username,
has_permissions,
permissions: ffi::Permissions::from(user.permissions.unwrap_or_default()),
+ options: resource_options_to_ffi(&user.options, true),
}
}
}
diff --git a/foreign/cpp/src/type_conversions.cpp b/foreign/cpp/src/type_conversions.cpp
index 166752279..9fa1032c7 100644
--- a/foreign/cpp/src/type_conversions.cpp
+++ b/foreign/cpp/src/type_conversions.cpp
@@ -32,6 +32,124 @@ LoginInfo LoginInfo::FromFfi(ffi::LoginInfo login_info) {
return LoginInfo(login_info.user_id, std::move(access_token), access_token_expiry);
}
+ffi::GlobalPermissions GlobalPermissions::ToFfi() const {
+ ffi::GlobalPermissions permissions{};
+ permissions.manage_servers = manage_servers_;
+ permissions.read_servers = read_servers_;
+ permissions.manage_users = manage_users_;
+ permissions.read_users = read_users_;
+ permissions.manage_streams = manage_streams_;
+ permissions.read_streams = read_streams_;
+ permissions.manage_topics = manage_topics_;
+ permissions.read_topics = read_topics_;
+ permissions.poll_messages = poll_messages_;
+ permissions.send_messages = send_messages_;
+ return permissions;
+}
+
+GlobalPermissions GlobalPermissions::FromFfi(ffi::GlobalPermissions permissions) {
+ GlobalPermissions result;
+ result.manage_servers_ = permissions.manage_servers;
+ result.read_servers_ = permissions.read_servers;
+ result.manage_users_ = permissions.manage_users;
+ result.read_users_ = permissions.read_users;
+ result.manage_streams_ = permissions.manage_streams;
+ result.read_streams_ = permissions.read_streams;
+ result.manage_topics_ = permissions.manage_topics;
+ result.read_topics_ = permissions.read_topics;
+ result.poll_messages_ = permissions.poll_messages;
+ result.send_messages_ = permissions.send_messages;
+ return result;
+}
+
+ffi::TopicPermissions TopicPermissions::ToFfi() const {
+ ffi::TopicPermissions permissions{};
+ permissions.manage_topic = manage_topic_;
+ permissions.read_topic = read_topic_;
+ permissions.poll_messages = poll_messages_;
+ permissions.send_messages = send_messages_;
+ return permissions;
+}
+
+TopicPermissions TopicPermissions::FromFfi(ffi::TopicPermissions permissions) {
+ TopicPermissions result;
+ result.manage_topic_ = permissions.manage_topic;
+ result.read_topic_ = permissions.read_topic;
+ result.poll_messages_ = permissions.poll_messages;
+ result.send_messages_ = permissions.send_messages;
+ return result;
+}
+
+ffi::StreamPermissions StreamPermissions::ToFfi() const {
+ ffi::StreamPermissions permissions{};
+ permissions.manage_stream = manage_stream_;
+ permissions.read_stream = read_stream_;
+ permissions.manage_topics = manage_topics_;
+ permissions.read_topics = read_topics_;
+ permissions.poll_messages = poll_messages_;
+ permissions.send_messages = send_messages_;
+ permissions.topics.reserve(topics_.size());
+ for (const auto &[topic_id, topic_permissions] : topics_) {
+ ffi::TopicPermissionEntry entry{};
+ entry.topic_id = topic_id;
+ entry.permissions = topic_permissions.ToFfi();
+ permissions.topics.push_back(entry);
+ }
+ return permissions;
+}
+
+StreamPermissions StreamPermissions::FromFfi(const ffi::StreamPermissions &permissions) {
+ StreamPermissions result;
+ result.manage_stream_ = permissions.manage_stream;
+ result.read_stream_ = permissions.read_stream;
+ result.manage_topics_ = permissions.manage_topics;
+ result.read_topics_ = permissions.read_topics;
+ result.poll_messages_ = permissions.poll_messages;
+ result.send_messages_ = permissions.send_messages;
+ for (const auto &entry : permissions.topics) {
+ result.topics_.insert_or_assign(entry.topic_id, TopicPermissions::FromFfi(entry.permissions));
+ }
+ return result;
+}
+
+ffi::Permissions Permissions::ToFfi() const {
+ ffi::Permissions permissions{};
+ permissions.global = global_.ToFfi();
+ permissions.streams.reserve(streams_.size());
+ for (const auto &[stream_id, stream_permissions] : streams_) {
+ ffi::StreamPermissionEntry entry{};
+ entry.stream_id = stream_id;
+ entry.permissions = stream_permissions.ToFfi();
+ permissions.streams.push_back(std::move(entry));
+ }
+ return permissions;
+}
+
+Permissions Permissions::FromFfi(const ffi::Permissions &permissions) {
+ Permissions result;
+ result.global_ = GlobalPermissions::FromFfi(permissions.global);
+ for (const auto &entry : permissions.streams) {
+ result.streams_.insert_or_assign(entry.stream_id, StreamPermissions::FromFfi(entry.permissions));
+ }
+ return result;
+}
+
+UserInfo UserInfo::FromFfi(ffi::UserInfo user) {
+ return UserInfo(user.id, user.created_at, static_cast<UserStatus>(user.status),
+ std::string(user.username.c_str(), user.username.size()),
+ ResourceOptions::FromFfi(std::move(user.options), rust::Vec<ffi::HeaderEntry>{}));
+}
+
+UserInfoDetails UserInfoDetails::FromFfi(ffi::UserInfoDetails user) {
+ std::optional<::iggy::Permissions> permissions;
+ if (user.has_permissions) {
+ permissions = ::iggy::Permissions::FromFfi(user.permissions);
+ }
+ return UserInfoDetails(user.id, user.created_at, static_cast<UserStatus>(user.status),
+ std::string(user.username.c_str(), user.username.size()), std::move(permissions),
+ ResourceOptions::FromFfi(std::move(user.options), rust::Vec<ffi::HeaderEntry>{}));
+}
+
ffi::Identifier Identifier::ToFfi() const {
ffi::Identifier identifier{};
if (kind_ == Kind::Numeric) {
@@ -181,4 +299,59 @@ ConsumerGroupDetails ConsumerGroupDetails::FromFfi(ffi::ConsumerGroupDetails gro
group.members_count, std::move(members));
}
+ConsumerGroupInfo ConsumerGroupInfo::FromFfi(ffi::ConsumerGroupInfo info) {
+ return ConsumerGroupInfo(info.stream_id, info.topic_id, info.group_id);
+}
+
+ClientInfo ClientInfo::FromFfi(ffi::ClientInfo info) {
+ std::optional<std::uint32_t> user_id;
+ if (info.has_user_id) {
+ user_id = info.user_id;
+ }
+ return ClientInfo(info.client_id, user_id, std::string(info.address.c_str(), info.address.size()),
+ std::string(info.transport.c_str(), info.transport.size()), info.consumer_groups_count);
+}
+
+ClientInfoDetails ClientInfoDetails::FromFfi(ffi::ClientInfoDetails info) {
+ std::optional<std::uint32_t> user_id;
+ if (info.has_user_id) {
+ user_id = info.user_id;
+ }
+ std::vector<ConsumerGroupInfo> consumer_groups;
+ consumer_groups.reserve(info.consumer_groups.size());
+ for (auto &group : info.consumer_groups) {
+ consumer_groups.push_back(ConsumerGroupInfo::FromFfi(group));
+ }
+ return ClientInfoDetails(info.client_id, user_id, std::string(info.address.c_str(), info.address.size()),
+ std::string(info.transport.c_str(), info.transport.size()), info.consumer_groups_count,
+ std::move(consumer_groups));
+}
+
+CacheMetricEntry CacheMetricEntry::FromFfi(ffi::CacheMetricEntry entry) {
+ return CacheMetricEntry(entry.stream_id, entry.topic_id, entry.partition_id, entry.hits, entry.misses,
+ entry.hit_ratio);
+}
+
+Stats Stats::FromFfi(ffi::Stats stats) {
+ std::optional<std::uint32_t> server_semver;
+ if (stats.has_server_semver) {
+ server_semver = stats.iggy_server_semver;
+ }
+ std::vector<CacheMetricEntry> cache_metrics;
+ cache_metrics.reserve(stats.cache_metrics.size());
+ for (auto &entry : stats.cache_metrics) {
+ cache_metrics.push_back(CacheMetricEntry::FromFfi(entry));
+ }
+ return Stats(stats.process_id, stats.cpu_usage, stats.total_cpu_usage, stats.memory_usage, stats.total_memory,
+ stats.available_memory, stats.run_time_micros, stats.start_time_epoch_micros, stats.read_bytes,
+ stats.written_bytes, stats.messages_size_bytes, stats.streams_count, stats.topics_count,
+ stats.partitions_count, stats.segments_count, stats.messages_count, stats.clients_count,
+ stats.consumer_groups_count, std::string(stats.hostname.c_str(), stats.hostname.size()),
+ std::string(stats.os_name.c_str(), stats.os_name.size()),
+ std::string(stats.os_version.c_str(), stats.os_version.size()),
+ std::string(stats.kernel_version.c_str(), stats.kernel_version.size()),
+ std::string(stats.iggy_server_version.c_str(), stats.iggy_server_version.size()), server_semver,
+ std::move(cache_metrics), stats.threads_count, stats.free_disk_space, stats.total_disk_space);
+}
+
} // namespace iggy
diff --git a/foreign/cpp/tests/e2e/client.cpp b/foreign/cpp/tests/e2e/client.cpp
index 7d75b021b..0ef956819 100644
--- a/foreign/cpp/tests/e2e/client.cpp
+++ b/foreign/cpp/tests/e2e/client.cpp
@@ -26,6 +26,7 @@
#include <string>
#include <thread>
#include <unordered_set>
+#include <vector>
#include <gtest/gtest.h>
@@ -33,6 +34,7 @@
#include "tests/e2e/test_helpers.hpp"
class LowLevelE2E_Client : public E2ETestFixture {};
+class E2E_Client : public E2ETestFixture {};
TEST_F(LowLevelE2E_Client, ConnectAndLogin) {
RecordProperty("description",
@@ -182,9 +184,9 @@ TEST_F(LowLevelE2E_Client, LogoutErrorsWhenCalledMoreThanOnce) {
ASSERT_THROW(client->logout_user(), std::exception);
}
-TEST_F(LowLevelE2E_Client, CreateUserWithUsernameOutsideLengthBoundsThrows) {
+TEST_F(E2E_Client, CreateUserWithUsernameOutsideLengthBoundsThrows) {
RecordProperty("description", "Rejects 2-byte and 51-byte usernames over TCP without creating users.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string too_short_username(2, 'a');
const std::string too_long_username(51, 'a');
const std::string usernames[] = {too_short_username, too_long_username};
@@ -193,17 +195,15 @@ TEST_F(LowLevelE2E_Client, CreateUserWithUsernameOutsideLengthBoundsThrows) {
ASSERT_EQ(too_long_username.size(), 51u);
for (const auto &username : usernames) {
SCOPED_TRACE(username.size());
- ASSERT_THROW(
- client->create_user(username, "secret123", iggy::ffi::UserStatus::Active, false, iggy::ffi::Permissions{}),
- std::exception);
- ASSERT_THROW(client->get_user(make_string_identifier(username)), std::exception);
+ ASSERT_THROW(client.CreateUser(username, "secret123", iggy::UserStatus::Active), std::exception);
+ ASSERT_THROW(client.GetUser(iggy::Identifier::String(username)), std::exception);
}
}
-TEST_F(LowLevelE2E_Client, CreateUserAcceptsNonAsciiAndNonAlphabeticUsernames) {
+TEST_F(E2E_Client, CreateUserAcceptsNonAsciiAndNonAlphabeticUsernames) {
RecordProperty("description",
"Creates and retrieves usernames containing punctuation, multilingual UTF-8, and emoji over TCP.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string suffix = GetRandomName(12);
const std::string usernames[] = {
"!@#_" + suffix, "ユーザー_" + suffix, "用户_" + suffix, "नाम_" + suffix, "사용자_" + suffix, "😀🚀_" + suffix,
@@ -213,58 +213,48 @@ TEST_F(LowLevelE2E_Client, CreateUserAcceptsNonAsciiAndNonAlphabeticUsernames) {
SCOPED_TRACE(username);
ASSERT_LE(username.size(), 50u);
- iggy::ffi::UserInfoDetails created_user{};
- iggy::ffi::UserInfoDetails fetched_user{};
- ASSERT_NO_THROW({ created_user = CreateUser(client, username, "secret123", iggy::ffi::UserStatus::Active); });
- ASSERT_NO_THROW({ fetched_user = client->get_user(make_string_identifier(username)); });
+ const auto created_user = CreateUser(client, username, "secret123", iggy::UserStatus::Active);
+ const auto fetched_user = client.GetUser(iggy::Identifier::String(username));
- EXPECT_EQ(fetched_user.id, created_user.id);
- EXPECT_EQ(static_cast<std::string>(created_user.username), username);
- EXPECT_EQ(static_cast<std::string>(fetched_user.username), username);
+ EXPECT_EQ(fetched_user.Id(), created_user.Id());
+ EXPECT_EQ(created_user.Username(), username);
+ EXPECT_EQ(fetched_user.Username(), username);
}
}
-TEST_F(LowLevelE2E_Client, CreateUserBeforeLoginThrows) {
+TEST_F(E2E_Client, CreateUserBeforeLoginThrows) {
RecordProperty("description", "Rejects user creation without an active authenticated session.");
- iggy::ffi::Client *client = GetLoggedOutClient();
- iggy::ffi::Client *root = GetLoggedInClient();
+ auto client = GetLoggedOutHighLevelClient();
+ auto root = GetLoggedInHighLevelClient();
const std::string before_login_username = GetRandomName(50);
const std::string logged_out_username = GetRandomName(50);
const std::string disconnected_username = GetRandomName(50);
- ASSERT_THROW(client->create_user(before_login_username, "secret123", iggy::ffi::UserStatus::Active, false,
- iggy::ffi::Permissions{}),
- std::exception);
- ASSERT_NO_THROW(client->connect());
- ASSERT_THROW(client->create_user(before_login_username, "secret123", iggy::ffi::UserStatus::Active, false,
- iggy::ffi::Permissions{}),
- std::exception);
+ ASSERT_THROW(client.CreateUser(before_login_username, "secret123", iggy::UserStatus::Active), std::exception);
+ ASSERT_NO_THROW(client.Connect());
+ ASSERT_THROW(client.CreateUser(before_login_username, "secret123", iggy::UserStatus::Active), std::exception);
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->logout_user());
- ASSERT_THROW(client->create_user(logged_out_username, "secret123", iggy::ffi::UserStatus::Active, false,
- iggy::ffi::Permissions{}),
- std::exception);
+ ASSERT_NO_THROW(client.Login("iggy", "iggy"));
+ ASSERT_NO_THROW(client.Logout());
+ ASSERT_THROW(client.CreateUser(logged_out_username, "secret123", iggy::UserStatus::Active), std::exception);
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->disconnect());
- ASSERT_THROW(client->create_user(disconnected_username, "secret123", iggy::ffi::UserStatus::Active, false,
- iggy::ffi::Permissions{}),
- std::exception);
+ ASSERT_NO_THROW(client.Login("iggy", "iggy"));
+ ASSERT_NO_THROW(client.Disconnect());
+ ASSERT_THROW(client.CreateUser(disconnected_username, "secret123", iggy::UserStatus::Active), std::exception);
- ASSERT_THROW(root->get_user(make_string_identifier(before_login_username)), std::exception);
- ASSERT_THROW(root->get_user(make_string_identifier(logged_out_username)), std::exception);
- ASSERT_THROW(root->get_user(make_string_identifier(disconnected_username)), std::exception);
+ ASSERT_THROW(root.GetUser(iggy::Identifier::String(before_login_username)), std::exception);
+ ASSERT_THROW(root.GetUser(iggy::Identifier::String(logged_out_username)), std::exception);
+ ASSERT_THROW(root.GetUser(iggy::Identifier::String(disconnected_username)), std::exception);
}
-TEST_F(LowLevelE2E_Client, CreateUserAcceptsUsernameAndPasswordLengthBounds) {
+TEST_F(E2E_Client, CreateUserAcceptsUsernameAndPasswordLengthBounds) {
RecordProperty("description",
"Creates users with shortest and longest ASCII usernames and passwords that can authenticate.");
- iggy::ffi::Client *root_client = GetLoggedInClient();
- iggy::ffi::Client *shortest_client = GetLoggedOutClient();
- iggy::ffi::Client *longest_client = GetLoggedOutClient();
- std::string shortest_username = GetRandomName(3);
- std::string longest_username = GetRandomName(50);
+ auto root_client = GetLoggedInHighLevelClient();
+ auto shortest_client = GetLoggedOutHighLevelClient();
+ auto longest_client = GetLoggedOutHighLevelClient();
+ std::string shortest_username = GetRandomName(3);
+ std::string longest_username = GetRandomName(50);
const std::string shortest_password(3, 'a');
const std::string longest_password(100, 'a');
longest_username.resize(50, 'a');
@@ -273,31 +263,24 @@ TEST_F(LowLevelE2E_Client, CreateUserAcceptsUsernameAndPasswordLengthBounds) {
ASSERT_EQ(shortest_password.size(), 3u);
ASSERT_EQ(longest_password.size(), 100u);
- iggy::ffi::UserInfoDetails shortest_user{};
- iggy::ffi::UserInfoDetails longest_user{};
- iggy::ffi::UserInfoDetails fetched_shortest{};
- iggy::ffi::UserInfoDetails fetched_longest{};
- ASSERT_NO_THROW({
- shortest_user = CreateUser(root_client, shortest_username, shortest_password, iggy::ffi::UserStatus::Active);
- });
- ASSERT_NO_THROW(
- { longest_user = CreateUser(root_client, longest_username, longest_password, iggy::ffi::UserStatus::Active); });
- ASSERT_NO_THROW({ fetched_shortest = root_client->get_user(make_string_identifier(shortest_username)); });
- ASSERT_NO_THROW({ fetched_longest = root_client->get_user(make_string_identifier(longest_username)); });
- ASSERT_NO_THROW(shortest_client->connect());
- ASSERT_NO_THROW(longest_client->connect());
- ASSERT_NO_THROW(shortest_client->login_user(shortest_username, shortest_password));
- ASSERT_NO_THROW(longest_client->login_user(longest_username, longest_password));
+ const auto shortest_user = CreateUser(root_client, shortest_username, shortest_password, iggy::UserStatus::Active);
+ const auto longest_user = CreateUser(root_client, longest_username, longest_password, iggy::UserStatus::Active);
+ const auto fetched_shortest = root_client.GetUser(iggy::Identifier::String(shortest_username));
+ const auto fetched_longest = root_client.GetUser(iggy::Identifier::String(longest_username));
+ ASSERT_NO_THROW(shortest_client.Connect());
+ ASSERT_NO_THROW(longest_client.Connect());
+ ASSERT_NO_THROW(shortest_client.Login(shortest_username, shortest_password));
+ ASSERT_NO_THROW(longest_client.Login(longest_username, longest_password));
- EXPECT_EQ(static_cast<std::string>(shortest_user.username), shortest_username);
- EXPECT_EQ(static_cast<std::string>(longest_user.username), longest_username);
- EXPECT_EQ(fetched_shortest.id, shortest_user.id);
- EXPECT_EQ(fetched_longest.id, longest_user.id);
+ EXPECT_EQ(shortest_user.Username(), shortest_username);
+ EXPECT_EQ(longest_user.Username(), longest_username);
+ EXPECT_EQ(fetched_shortest.Id(), shortest_user.Id());
+ EXPECT_EQ(fetched_longest.Id(), longest_user.Id());
}
-TEST_F(LowLevelE2E_Client, CreateUserWithPasswordOutsideLengthBoundsThrows) {
+TEST_F(E2E_Client, CreateUserWithPasswordOutsideLengthBoundsThrows) {
RecordProperty("description", "Rejects 2-byte and 101-byte passwords without creating users.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string short_username = GetRandomName(50);
const std::string long_username = GetRandomName(50);
const std::string short_password(2, 'a');
@@ -305,187 +288,150 @@ TEST_F(LowLevelE2E_Client, CreateUserWithPasswordOutsideLengthBoundsThrows) {
ASSERT_EQ(short_password.size(), 2u);
ASSERT_EQ(long_password.size(), 101u);
- ASSERT_THROW(client->create_user(short_username, short_password, iggy::ffi::UserStatus::Active, false,
- iggy::ffi::Permissions{}),
- std::exception);
- ASSERT_THROW(client->create_user(long_username, long_password, iggy::ffi::UserStatus::Active, false,
- iggy::ffi::Permissions{}),
- std::exception);
- ASSERT_THROW(client->get_user(make_string_identifier(short_username)), std::exception);
- ASSERT_THROW(client->get_user(make_string_identifier(long_username)), std::exception);
+ ASSERT_THROW(client.CreateUser(short_username, short_password, iggy::UserStatus::Active), std::exception);
+ ASSERT_THROW(client.CreateUser(long_username, long_password, iggy::UserStatus::Active), std::exception);
+ ASSERT_THROW(client.GetUser(iggy::Identifier::String(short_username)), std::exception);
+ ASSERT_THROW(client.GetUser(iggy::Identifier::String(long_username)), std::exception);
}
-TEST_F(LowLevelE2E_Client, CreateUserWithInvalidStatusThrows) {
+TEST_F(E2E_Client, CreateUserWithInvalidStatusThrows) {
RecordProperty("description", "Rejects invalid status codes before creating users.");
- iggy::ffi::Client *client = GetLoggedInClient();
- const iggy::ffi::UserStatus statuses[] = {
- static_cast<iggy::ffi::UserStatus>(0),
- static_cast<iggy::ffi::UserStatus>(3),
- static_cast<iggy::ffi::UserStatus>(std::numeric_limits<std::uint8_t>::max()),
+ auto client = GetLoggedInHighLevelClient();
+ const iggy::UserStatus statuses[] = {
+ static_cast<iggy::UserStatus>(0),
+ static_cast<iggy::UserStatus>(3),
+ static_cast<iggy::UserStatus>(std::numeric_limits<std::uint8_t>::max()),
};
for (const auto status : statuses) {
const std::string username = GetRandomName(50);
SCOPED_TRACE(static_cast<std::uint8_t>(status));
- ASSERT_THROW(client->create_user(username, "secret123", status, false, iggy::ffi::Permissions{}),
- std::exception);
- ASSERT_THROW(client->get_user(make_string_identifier(username)), std::exception);
+ ASSERT_THROW(client.CreateUser(username, "secret123", status), std::exception);
+ ASSERT_THROW(client.GetUser(iggy::Identifier::String(username)), std::exception);
}
}
-TEST_F(LowLevelE2E_Client, CreateUserReturnsCreatedActiveUserDetails) {
+TEST_F(E2E_Client, CreateUserReturnsCreatedActiveUserDetails) {
RecordProperty("description", "Returns and persists active user details.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string username = GetRandomName(50);
- iggy::ffi::UserInfoDetails created_user{};
- iggy::ffi::UserInfoDetails fetched_user{};
- ASSERT_NO_THROW({ created_user = CreateUser(client, username, "secret123", iggy::ffi::UserStatus::Active); });
- ASSERT_NO_THROW({ fetched_user = client->get_user(make_string_identifier(username)); });
-
- EXPECT_EQ(fetched_user.id, created_user.id);
- EXPECT_EQ(static_cast<std::string>(created_user.username), username);
- EXPECT_EQ(static_cast<std::string>(fetched_user.username), username);
- EXPECT_EQ(created_user.status, iggy::ffi::UserStatus::Active);
- EXPECT_EQ(fetched_user.status, iggy::ffi::UserStatus::Active);
+ ASSERT_NO_THROW({
+ const auto created_user = CreateUser(client, username, "secret123", iggy::UserStatus::Active);
+ const auto fetched_user = client.GetUser(iggy::Identifier::String(username));
+
+ EXPECT_EQ(fetched_user.Id(), created_user.Id());
+ EXPECT_EQ(created_user.Username(), username);
+ EXPECT_EQ(fetched_user.Username(), username);
+ EXPECT_EQ(created_user.Status(), iggy::UserStatus::Active);
+ EXPECT_EQ(fetched_user.Status(), iggy::UserStatus::Active);
+ });
}
-TEST_F(LowLevelE2E_Client, CreateUserRejectsDuplicateUsernameWithoutChangingOriginal) {
+TEST_F(E2E_Client, CreateUserRejectsDuplicateUsernameWithoutChangingOriginal) {
RecordProperty("description", "Rejects duplicate usernames without changing the existing user.");
- iggy::ffi::Client *root_client = GetLoggedInClient();
- iggy::ffi::Client *user_client = GetLoggedOutClient();
- const std::string username = GetRandomName(50);
- const std::string password = "original-secret";
- iggy::ffi::UserInfoDetails original{};
- ASSERT_NO_THROW({ original = CreateUser(root_client, username, password, iggy::ffi::UserStatus::Active); });
+ auto root_client = GetLoggedInHighLevelClient();
+ auto user_client = GetLoggedOutHighLevelClient();
+ const std::string username = GetRandomName(50);
+ const std::string password = "original-secret";
+ ASSERT_NO_THROW({
+ const auto original = CreateUser(root_client, username, password, iggy::UserStatus::Active);
- ASSERT_THROW(root_client->create_user(username, "replacement-secret", iggy::ffi::UserStatus::Inactive, false,
- iggy::ffi::Permissions{}),
- std::exception);
+ ASSERT_THROW(root_client.CreateUser(username, "replacement-secret", iggy::UserStatus::Inactive),
+ std::exception);
- iggy::ffi::UserInfoDetails fetched{};
- ASSERT_NO_THROW({ fetched = root_client->get_user(make_string_identifier(username)); });
- EXPECT_EQ(fetched.id, original.id);
- EXPECT_EQ(fetched.status, iggy::ffi::UserStatus::Active);
- ASSERT_NO_THROW(user_client->connect());
- ASSERT_NO_THROW(user_client->login_user(username, password));
- iggy::ffi::Client *replacement_client = GetLoggedOutClient();
- ASSERT_NO_THROW(replacement_client->connect());
- ASSERT_THROW(replacement_client->login_user(username, "replacement-secret"), std::exception);
+ const auto fetched = root_client.GetUser(iggy::Identifier::String(username));
+ EXPECT_EQ(fetched.Id(), original.Id());
+ EXPECT_EQ(fetched.Status(), iggy::UserStatus::Active);
+ });
+ ASSERT_NO_THROW(user_client.Connect());
+ ASSERT_NO_THROW(user_client.Login(username, password));
+ auto replacement_client = GetLoggedOutHighLevelClient();
+ ASSERT_NO_THROW(replacement_client.Connect());
+ ASSERT_THROW(replacement_client.Login(username, "replacement-secret"), std::exception);
}
-TEST_F(LowLevelE2E_Client, CreateUserPreservesNestedPermissionsInCreateAndGetResponses) {
+TEST_F(E2E_Client, CreateUserPreservesNestedPermissionsInCreateAndGetResponses) {
RecordProperty("description",
"Creates a user with global and per-resource permissions, then verifies create_user and get_user "
"return the same flags and numeric stream/topic IDs.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string username = GetRandomName(50);
- iggy::ffi::Permissions permissions{};
- permissions.global.manage_servers = true;
- permissions.global.read_users = true;
- permissions.global.manage_streams = true;
- permissions.global.read_topics = true;
- permissions.global.send_messages = true;
+ iggy::GlobalPermissions global;
+ global.SetManageServers(true).SetReadUsers(true).SetManageStreams(true).SetReadTopics(true).SetSendMessages(true);
- iggy::ffi::StreamPermissionEntry first_stream{};
- first_stream.stream_id = 42;
- first_stream.permissions.manage_stream = true;
- first_stream.permissions.read_topics = true;
- first_stream.permissions.send_messages = true;
- iggy::ffi::TopicPermissionEntry first_topic{};
- first_topic.topic_id = 7;
- first_topic.permissions.manage_topic = true;
- first_topic.permissions.poll_messages = true;
- iggy::ffi::TopicPermissionEntry second_topic{};
- second_topic.topic_id = 9;
- second_topic.permissions.read_topic = true;
- second_topic.permissions.send_messages = true;
- first_stream.permissions.topics.push_back(std::move(first_topic));
- first_stream.permissions.topics.push_back(std::move(second_topic));
+ iggy::TopicPermissions first_topic;
+ first_topic.SetManageTopic(true).SetPollMessages(true);
+ iggy::TopicPermissions second_topic;
+ second_topic.SetReadTopic(true).SetSendMessages(true);
+ iggy::StreamPermissions first_stream;
+ first_stream.SetManageStream(true).SetReadTopics(true).SetSendMessages(true).SetTopics(
+ {{7, first_topic}, {9, second_topic}});
- iggy::ffi::StreamPermissionEntry second_stream{};
- second_stream.stream_id = 84;
- second_stream.permissions.read_stream = true;
- second_stream.permissions.manage_topics = true;
- second_stream.permissions.poll_messages = true;
- iggy::ffi::TopicPermissionEntry third_topic{};
- third_topic.topic_id = 3;
- third_topic.permissions.read_topic = true;
- second_stream.permissions.topics.push_back(std::move(third_topic));
- permissions.streams.push_back(std::move(first_stream));
- permissions.streams.push_back(std::move(second_stream));
+ iggy::TopicPermissions third_topic;
+ third_topic.SetReadTopic(true);
+ iggy::StreamPermissions second_stream;
+ second_stream.SetReadStream(true).SetManageTopics(true).SetPollMessages(true).SetTopics({{3, third_topic}});
+
+ iggy::Permissions permissions;
+ permissions.SetGlobal(global).SetStreams({{42, first_stream}, {84, second_stream}});
- iggy::ffi::UserInfoDetails created{};
- iggy::ffi::UserInfoDetails fetched{};
ASSERT_NO_THROW({
- created =
- CreateUser(client, username, "secret123", iggy::ffi::UserStatus::Active, true, std::move(permissions));
- });
- ASSERT_NO_THROW({ fetched = client->get_user(make_string_identifier(username)); });
- for (const auto *user : {&created, &fetched}) {
- EXPECT_TRUE(user->permissions.global.manage_servers);
- EXPECT_FALSE(user->permissions.global.read_servers);
- EXPECT_FALSE(user->permissions.global.manage_users);
- EXPECT_TRUE(user->permissions.global.read_users);
- EXPECT_TRUE(user->permissions.global.manage_streams);
- EXPECT_FALSE(user->permissions.global.read_streams);
- EXPECT_FALSE(user->permissions.global.manage_topics);
- EXPECT_TRUE(user->permissions.global.read_topics);
- EXPECT_FALSE(user->permissions.global.poll_messages);
- EXPECT_TRUE(user->permissions.global.send_messages);
- ASSERT_EQ(user->permissions.streams.size(), 2u);
-
- const iggy::ffi::StreamPermissionEntry *stream_42 = nullptr;
- const iggy::ffi::StreamPermissionEntry *stream_84 = nullptr;
- for (const auto &stream : user->permissions.streams) {
- if (stream.stream_id == 42) {
- stream_42 = &stream;
- }
- if (stream.stream_id == 84) {
- stream_84 = &stream;
- }
+ const auto created = CreateUser(client, username, "secret123", iggy::UserStatus::Active, permissions);
+ const auto fetched = client.GetUser(iggy::Identifier::String(username));
+ for (const auto *user : {&created, &fetched}) {
+ ASSERT_TRUE(user->Permissions().has_value());
+ const auto &user_permissions = user->Permissions().value();
+ EXPECT_TRUE(user_permissions.Global().ManageServers());
+ EXPECT_FALSE(user_permissions.Global().ReadServers());
+ EXPECT_FALSE(user_permissions.Global().ManageUsers());
+ EXPECT_TRUE(user_permissions.Global().ReadUsers());
+ EXPECT_TRUE(user_permissions.Global().ManageStreams());
+ EXPECT_FALSE(user_permissions.Global().ReadStreams());
+ EXPECT_FALSE(user_permissions.Global().ManageTopics());
+ EXPECT_TRUE(user_permissions.Global().ReadTopics());
+ EXPECT_FALSE(user_permissions.Global().PollMessages());
+ EXPECT_TRUE(user_permissions.Global().SendMessages());
+ ASSERT_EQ(user_permissions.Streams().size(), 2u);
+
+ const auto stream_42 = user_permissions.Streams().find(42);
+ const auto stream_84 = user_permissions.Streams().find(84);
+ ASSERT_NE(stream_42, user_permissions.Streams().end());
+ ASSERT_NE(stream_84, user_permissions.Streams().end());
+ EXPECT_TRUE(stream_42->second.ManageStream());
+ EXPECT_FALSE(stream_42->second.ReadStream());
+ EXPECT_FALSE(stream_42->second.ManageTopics());
+ EXPECT_TRUE(stream_42->second.ReadTopics());
+ EXPECT_FALSE(stream_42->second.PollMessages());
+ EXPECT_TRUE(stream_42->second.SendMessages());
+ ASSERT_EQ(stream_42->second.Topics().size(), 2u);
+ const auto topic_7 = stream_42->second.Topics().find(7);
+ const auto topic_9 = stream_42->second.Topics().find(9);
+ ASSERT_NE(topic_7, stream_42->second.Topics().end());
+ ASSERT_NE(topic_9, stream_42->second.Topics().end());
+ EXPECT_TRUE(topic_7->second.ManageTopic());
+ EXPECT_FALSE(topic_7->second.ReadTopic());
+ EXPECT_TRUE(topic_7->second.PollMessages());
+ EXPECT_FALSE(topic_7->second.SendMessages());
+ EXPECT_FALSE(topic_9->second.ManageTopic());
+ EXPECT_TRUE(topic_9->second.ReadTopic());
+ EXPECT_FALSE(topic_9->second.PollMessages());
+ EXPECT_TRUE(topic_9->second.SendMessages());
+ EXPECT_FALSE(stream_84->second.ManageStream());
+ EXPECT_TRUE(stream_84->second.ReadStream());
+ EXPECT_TRUE(stream_84->second.ManageTopics());
+ EXPECT_FALSE(stream_84->second.ReadTopics());
+ EXPECT_TRUE(stream_84->second.PollMessages());
+ EXPECT_FALSE(stream_84->second.SendMessages());
+ ASSERT_EQ(stream_84->second.Topics().size(), 1u);
+ const auto topic_3 = stream_84->second.Topics().find(3);
+ ASSERT_NE(topic_3, stream_84->second.Topics().end());
+ EXPECT_EQ(topic_3->first, 3u);
+ EXPECT_FALSE(topic_3->second.ManageTopic());
+ EXPECT_TRUE(topic_3->second.ReadTopic());
+ EXPECT_FALSE(topic_3->second.PollMessages());
+ EXPECT_FALSE(topic_3->second.SendMessages());
}
- ASSERT_NE(stream_42, nullptr);
- ASSERT_NE(stream_84, nullptr);
- EXPECT_TRUE(stream_42->permissions.manage_stream);
- EXPECT_FALSE(stream_42->permissions.read_stream);
- EXPECT_FALSE(stream_42->permissions.manage_topics);
- EXPECT_TRUE(stream_42->permissions.read_topics);
- EXPECT_FALSE(stream_42->permissions.poll_messages);
- EXPECT_TRUE(stream_42->permissions.send_messages);
- ASSERT_EQ(stream_42->permissions.topics.size(), 2u);
- const iggy::ffi::TopicPermissionEntry *topic_7 = nullptr;
- const iggy::ffi::TopicPermissionEntry *topic_9 = nullptr;
- for (const auto &topic : stream_42->permissions.topics) {
- if (topic.topic_id == 7) {
- topic_7 = &topic;
- }
- if (topic.topic_id == 9) {
- topic_9 = &topic;
- }
- }
- ASSERT_NE(topic_7, nullptr);
- ASSERT_NE(topic_9, nullptr);
- EXPECT_TRUE(topic_7->permissions.manage_topic);
- EXPECT_FALSE(topic_7->permissions.read_topic);
- EXPECT_TRUE(topic_7->permissions.poll_messages);
- EXPECT_FALSE(topic_7->permissions.send_messages);
- EXPECT_FALSE(topic_9->permissions.manage_topic);
- EXPECT_TRUE(topic_9->permissions.read_topic);
- EXPECT_FALSE(topic_9->permissions.poll_messages);
- EXPECT_TRUE(topic_9->permissions.send_messages);
- EXPECT_FALSE(stream_84->permissions.manage_stream);
- EXPECT_TRUE(stream_84->permissions.read_stream);
- EXPECT_TRUE(stream_84->permissions.manage_topics);
- EXPECT_FALSE(stream_84->permissions.read_topics);
- EXPECT_TRUE(stream_84->permissions.poll_messages);
- EXPECT_FALSE(stream_84->permissions.send_messages);
- ASSERT_EQ(stream_84->permissions.topics.size(), 1u);
- EXPECT_EQ(stream_84->permissions.topics[0].topic_id, 3u);
- EXPECT_FALSE(stream_84->permissions.topics[0].permissions.manage_topic);
- EXPECT_TRUE(stream_84->permissions.topics[0].permissions.read_topic);
- EXPECT_FALSE(stream_84->permissions.topics[0].permissions.poll_messages);
- EXPECT_FALSE(stream_84->permissions.topics[0].permissions.send_messages);
- }
+ });
}
TEST_F(LowLevelE2E_Client, CreatedUserCanReadOnlyTopicGrantedByPermissions) {
@@ -677,177 +623,191 @@ TEST_F(LowLevelE2E_Client, CreatedInactiveUserCannotAuthenticate) {
ASSERT_THROW(user_client->login_user(username, password), std::exception);
}
-TEST_F(LowLevelE2E_Client, UpdateUserRejectsUnauthenticatedClientWithoutChangingTarget) {
+TEST_F(E2E_Client, UpdateUserRejectsUnauthenticatedClientWithoutChangingTarget) {
RecordProperty("description", "Rejects user updates without an active authenticated session.");
- iggy::ffi::Client *root_client = GetLoggedInClient();
- const std::string username = GetRandomName(50);
- const std::string replacement = GetRandomName(50);
- iggy::ffi::UserInfoDetails created{};
- ASSERT_NO_THROW({ created = CreateUser(root_client, username, "secret123", iggy::ffi::UserStatus::Active); });
+ auto root_client = GetLoggedInHighLevelClient();
+ const std::string username = GetRandomName(50);
+ const std::string replacement = GetRandomName(50);
+ ASSERT_NO_THROW({
+ const auto created = CreateUser(root_client, username, "secret123", iggy::UserStatus::Active);
- iggy::ffi::Client *client = GetLoggedOutClient();
- ASSERT_THROW(
- client->update_user(make_string_identifier(username), true, replacement, true, iggy::ffi::UserStatus::Inactive),
- std::exception);
- ASSERT_NO_THROW(client->connect());
- ASSERT_THROW(
- client->update_user(make_string_identifier(username), true, replacement, true, iggy::ffi::UserStatus::Inactive),
- std::exception);
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->logout_user());
- ASSERT_THROW(
- client->update_user(make_string_identifier(username), true, replacement, true, iggy::ffi::UserStatus::Inactive),
- std::exception);
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->disconnect());
- ASSERT_THROW(
- client->update_user(make_string_identifier(username), true, replacement, true, iggy::ffi::UserStatus::Inactive),
- std::exception);
+ auto client = GetLoggedOutHighLevelClient();
+ ASSERT_THROW(client.UpdateUser(iggy::Identifier::String(username), replacement, iggy::UserStatus::Inactive,
+ iggy::UserUpdateOptions{}),
+ std::exception);
+ ASSERT_NO_THROW(client.Connect());
+ ASSERT_THROW(client.UpdateUser(iggy::Identifier::String(username), replacement, iggy::UserStatus::Inactive,
+ iggy::UserUpdateOptions{}),
+ std::exception);
+ ASSERT_NO_THROW(client.Login("iggy", "iggy"));
+ ASSERT_NO_THROW(client.Logout());
+ ASSERT_THROW(client.UpdateUser(iggy::Identifier::String(username), replacement, iggy::UserStatus::Inactive,
+ iggy::UserUpdateOptions{}),
+ std::exception);
+ ASSERT_NO_THROW(client.Login("iggy", "iggy"));
+ ASSERT_NO_THROW(client.Disconnect());
+ ASSERT_THROW(client.UpdateUser(iggy::Identifier::String(username), replacement, iggy::UserStatus::Inactive,
+ iggy::UserUpdateOptions{}),
+ std::exception);
- iggy::ffi::UserInfoDetails fetched{};
- ASSERT_NO_THROW({ fetched = root_client->get_user(make_string_identifier(username)); });
- EXPECT_EQ(fetched.id, created.id);
- EXPECT_EQ(static_cast<std::string>(fetched.username), username);
- EXPECT_EQ(fetched.status, iggy::ffi::UserStatus::Active);
+ const auto fetched = root_client.GetUser(iggy::Identifier::String(username));
+ EXPECT_EQ(fetched.Id(), created.Id());
+ EXPECT_EQ(fetched.Username(), username);
+ EXPECT_EQ(fetched.Status(), iggy::UserStatus::Active);
+ });
}
-TEST_F(LowLevelE2E_Client, UpdateUserRejectsUnknownUsernameAndNumericId) {
+TEST_F(E2E_Client, UpdateUserRejectsUnknownUsernameAndNumericId) {
RecordProperty("description", "Rejects updates for unknown username and numeric identifiers.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string unknown_username = GetRandomName(50);
const std::string proposed_username = GetRandomName(50);
const auto unknown_id = std::numeric_limits<std::uint32_t>::max();
- ASSERT_THROW(client->update_user(make_string_identifier(unknown_username), true, proposed_username, true,
- iggy::ffi::UserStatus::Inactive),
+ ASSERT_THROW(client.UpdateUser(iggy::Identifier::String(unknown_username), proposed_username,
+ iggy::UserStatus::Inactive, iggy::UserUpdateOptions{}),
std::exception);
- ASSERT_THROW(client->update_user(make_numeric_identifier(unknown_id), true, GetRandomName(50), true,
- iggy::ffi::UserStatus::Inactive),
+ ASSERT_THROW(client.UpdateUser(iggy::Identifier::Numeric(unknown_id), GetRandomName(50), iggy::UserStatus::Inactive,
+ iggy::UserUpdateOptions{}),
std::exception);
- ASSERT_THROW(client->get_user(make_string_identifier(proposed_username)), std::exception);
+ ASSERT_THROW(client.GetUser(iggy::Identifier::String(proposed_username)), std::exception);
}
-TEST_F(LowLevelE2E_Client, UpdateUserByUsernameChangesUsernameAndStatus) {
+TEST_F(E2E_Client, UpdateUserByUsernameChangesUsernameAndStatus) {
RecordProperty("description", "Updates a user by username and changes both username and status.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string username = GetRandomName(50);
const std::string replacement = GetRandomName(50);
- iggy::ffi::UserInfoDetails created{};
- ASSERT_NO_THROW({ created = CreateUser(client, username, "secret123", iggy::ffi::UserStatus::Active); });
- ASSERT_NO_THROW(client->update_user(make_string_identifier(username), true, replacement, true,
- iggy::ffi::UserStatus::Inactive));
- RenameTrackedUser(username, replacement);
-
- ASSERT_THROW(client->get_user(make_string_identifier(username)), std::exception);
- iggy::ffi::UserInfoDetails fetched{};
- ASSERT_NO_THROW({ fetched = client->get_user(make_string_identifier(replacement)); });
- EXPECT_EQ(fetched.id, created.id);
- EXPECT_EQ(static_cast<std::string>(fetched.username), replacement);
- EXPECT_EQ(fetched.status, iggy::ffi::UserStatus::Inactive);
+ ASSERT_NO_THROW({
+ const auto created = CreateUser(client, username, "secret123", iggy::UserStatus::Active);
+ ASSERT_NO_THROW(client.UpdateUser(iggy::Identifier::String(username), replacement, iggy::UserStatus::Inactive,
+ iggy::UserUpdateOptions{}));
+ RenameTrackedUser(username, replacement);
+
+ ASSERT_THROW(client.GetUser(iggy::Identifier::String(username)), std::exception);
+ const auto fetched = client.GetUser(iggy::Identifier::String(replacement));
+ EXPECT_EQ(fetched.Id(), created.Id());
+ EXPECT_EQ(fetched.Username(), replacement);
+ EXPECT_EQ(fetched.Status(), iggy::UserStatus::Inactive);
+ });
}
-TEST_F(LowLevelE2E_Client, UpdateUserByNumericIdChangesUsernameAndStatus) {
+TEST_F(E2E_Client, UpdateUserByNumericIdChangesUsernameAndStatus) {
RecordProperty("description", "Updates a user by numeric ID and changes both username and status.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string username = GetRandomName(50);
const std::string replacement = GetRandomName(50);
- iggy::ffi::UserInfoDetails created{};
- ASSERT_NO_THROW({ created = CreateUser(client, username, "secret123", iggy::ffi::UserStatus::Inactive); });
- ASSERT_NO_THROW(client->update_user(make_numeric_identifier(created.id), true, replacement, true,
- iggy::ffi::UserStatus::Active));
- RenameTrackedUser(username, replacement);
-
- iggy::ffi::UserInfoDetails by_id{};
- iggy::ffi::UserInfoDetails by_name{};
- ASSERT_NO_THROW({ by_id = client->get_user(make_numeric_identifier(created.id)); });
- ASSERT_NO_THROW({ by_name = client->get_user(make_string_identifier(replacement)); });
- EXPECT_EQ(by_id.id, created.id);
- EXPECT_EQ(by_name.id, created.id);
- EXPECT_EQ(static_cast<std::string>(by_id.username), replacement);
- EXPECT_EQ(static_cast<std::string>(by_name.username), replacement);
- EXPECT_EQ(by_id.status, iggy::ffi::UserStatus::Active);
- EXPECT_EQ(by_name.status, iggy::ffi::UserStatus::Active);
-}
-
-TEST_F(LowLevelE2E_Client, UpdateUserAllowsUsernameAndStatusToBeUpdatedIndependently) {
+ ASSERT_NO_THROW({
+ const auto created = CreateUser(client, username, "secret123", iggy::UserStatus::Inactive);
+ ASSERT_NO_THROW(client.UpdateUser(iggy::Identifier::Numeric(created.Id()), replacement,
+ iggy::UserStatus::Active, iggy::UserUpdateOptions{}));
+ RenameTrackedUser(username, replacement);
+
+ const auto by_id = client.GetUser(iggy::Identifier::Numeric(created.Id()));
+ const auto by_name = client.GetUser(iggy::Identifier::String(replacement));
+ EXPECT_EQ(by_id.Id(), created.Id());
+ EXPECT_EQ(by_name.Id(), created.Id());
+ EXPECT_EQ(by_id.Username(), replacement);
+ EXPECT_EQ(by_name.Username(), replacement);
+ EXPECT_EQ(by_id.Status(), iggy::UserStatus::Active);
+ EXPECT_EQ(by_name.Status(), iggy::UserStatus::Active);
+ });
+}
+
+TEST_F(E2E_Client, UpdateUserAllowsUsernameAndStatusToBeUpdatedIndependently) {
RecordProperty("description", "Updates either username or status without changing the other field.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string username = GetRandomName(50);
const std::string replacement = GetRandomName(50);
- iggy::ffi::UserInfoDetails created{};
- ASSERT_NO_THROW({ created = CreateUser(client, username, "secret123", iggy::ffi::UserStatus::Active); });
+ ASSERT_NO_THROW({
+ const auto created = CreateUser(client, username, "secret123", iggy::UserStatus::Active);
- ASSERT_NO_THROW(
- client->update_user(make_numeric_identifier(created.id), false, "", true, iggy::ffi::UserStatus::Inactive));
- iggy::ffi::UserInfoDetails status_updated{};
- ASSERT_NO_THROW({ status_updated = client->get_user(make_numeric_identifier(created.id)); });
- EXPECT_EQ(static_cast<std::string>(status_updated.username), username);
- EXPECT_EQ(status_updated.status, iggy::ffi::UserStatus::Inactive);
+ ASSERT_NO_THROW(client.UpdateUser(iggy::Identifier::Numeric(created.Id()), std::nullopt,
+ iggy::UserStatus::Inactive, iggy::UserUpdateOptions{}));
+ const auto status_updated = client.GetUser(iggy::Identifier::Numeric(created.Id()));
+ EXPECT_EQ(status_updated.Username(), username);
+ EXPECT_EQ(status_updated.Status(), iggy::UserStatus::Inactive);
+
+ ASSERT_NO_THROW(client.UpdateUser(iggy::Identifier::Numeric(created.Id()), replacement, std::nullopt,
+ iggy::UserUpdateOptions{}));
+ RenameTrackedUser(username, replacement);
+
+ const auto username_updated = client.GetUser(iggy::Identifier::Numeric(created.Id()));
+ EXPECT_EQ(username_updated.Username(), replacement);
+ EXPECT_EQ(username_updated.Status(), iggy::UserStatus::Inactive);
+ });
+}
+
+TEST_F(E2E_Client, UpdateUserWithoutChangesIsNoOp) {
+ RecordProperty("description", "Accepts an empty user update without changing the user.");
+ auto client = GetLoggedInHighLevelClient();
+ const std::string username = GetRandomName(50);
+ ASSERT_NO_THROW({
+ const auto created = CreateUser(client, username, "secret123", iggy::UserStatus::Active);
- ASSERT_NO_THROW(client->update_user(make_numeric_identifier(created.id), true, replacement, false,
- iggy::ffi::UserStatus::Active));
- RenameTrackedUser(username, replacement);
+ ASSERT_NO_THROW(client.UpdateUser(iggy::Identifier::Numeric(created.Id()), std::nullopt, std::nullopt,
+ iggy::UserUpdateOptions{}));
- iggy::ffi::UserInfoDetails username_updated{};
- ASSERT_NO_THROW({ username_updated = client->get_user(make_numeric_identifier(created.id)); });
- EXPECT_EQ(static_cast<std::string>(username_updated.username), replacement);
- EXPECT_EQ(username_updated.status, iggy::ffi::UserStatus::Inactive);
+ const auto fetched = client.GetUser(iggy::Identifier::Numeric(created.Id()));
+ EXPECT_EQ(fetched.Id(), created.Id());
+ EXPECT_EQ(fetched.CreatedAt(), created.CreatedAt());
+ EXPECT_EQ(fetched.Username(), created.Username());
+ EXPECT_EQ(fetched.Status(), created.Status());
+ });
}
-TEST_F(LowLevelE2E_Client, UpdateUserAcceptsUsernameLengthBounds) {
+TEST_F(E2E_Client, UpdateUserAcceptsUsernameLengthBounds) {
RecordProperty("description", "Accepts exact three-byte and fifty-byte username boundaries.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string first_username = GetRandomName(50);
const std::string second_username = GetRandomName(50);
const std::string first_replacement = GetRandomName(3);
std::string second_replacement = GetRandomName(50);
second_replacement.resize(50, 'a');
ASSERT_EQ(second_replacement.size(), 50u);
- iggy::ffi::UserInfoDetails first{};
- iggy::ffi::UserInfoDetails second{};
- ASSERT_NO_THROW({ first = CreateUser(client, first_username, "secret123", iggy::ffi::UserStatus::Active); });
- ASSERT_NO_THROW({ second = CreateUser(client, second_username, "secret123", iggy::ffi::UserStatus::Active); });
- ASSERT_NO_THROW(client->update_user(make_string_identifier(first_username), true, first_replacement, true,
- iggy::ffi::UserStatus::Active));
- RenameTrackedUser(first_username, first_replacement);
- ASSERT_NO_THROW(client->update_user(make_string_identifier(second_username), true, second_replacement, true,
- iggy::ffi::UserStatus::Active));
- RenameTrackedUser(second_username, second_replacement);
-
- iggy::ffi::UserInfoDetails fetched_first{};
- iggy::ffi::UserInfoDetails fetched_second{};
- ASSERT_NO_THROW({ fetched_first = client->get_user(make_string_identifier(first_replacement)); });
- ASSERT_NO_THROW({ fetched_second = client->get_user(make_string_identifier(second_replacement)); });
- EXPECT_EQ(fetched_first.id, first.id);
- EXPECT_EQ(fetched_second.id, second.id);
- EXPECT_EQ(static_cast<std::string>(fetched_first.username), first_replacement);
- EXPECT_EQ(static_cast<std::string>(fetched_second.username), second_replacement);
-}
-
-TEST_F(LowLevelE2E_Client, UpdateUserRejectsUsernameOutsideLengthBounds) {
+ ASSERT_NO_THROW({
+ const auto first = CreateUser(client, first_username, "secret123", iggy::UserStatus::Active);
+ const auto second = CreateUser(client, second_username, "secret123", iggy::UserStatus::Active);
+ ASSERT_NO_THROW(client.UpdateUser(iggy::Identifier::String(first_username), first_replacement,
+ iggy::UserStatus::Active, iggy::UserUpdateOptions{}));
+ RenameTrackedUser(first_username, first_replacement);
+ ASSERT_NO_THROW(client.UpdateUser(iggy::Identifier::String(second_username), second_replacement,
+ iggy::UserStatus::Active, iggy::UserUpdateOptions{}));
+ RenameTrackedUser(second_username, second_replacement);
+
+ const auto fetched_first = client.GetUser(iggy::Identifier::String(first_replacement));
+ const auto fetched_second = client.GetUser(iggy::Identifier::String(second_replacement));
+ EXPECT_EQ(fetched_first.Id(), first.Id());
+ EXPECT_EQ(fetched_second.Id(), second.Id());
+ EXPECT_EQ(fetched_first.Username(), first_replacement);
+ EXPECT_EQ(fetched_second.Username(), second_replacement);
+ });
+}
+
+TEST_F(E2E_Client, UpdateUserRejectsUsernameOutsideLengthBounds) {
RecordProperty("description", "Rejects username sizes outside the SDK and server limits.");
- iggy::ffi::Client *client = GetLoggedInClient();
- const std::string source = GetRandomName(50);
- iggy::ffi::UserInfoDetails created{};
- ASSERT_NO_THROW({ created = CreateUser(client, source, "secret123", iggy::ffi::UserStatus::Active); });
+ auto client = GetLoggedInHighLevelClient();
+ const std::string source = GetRandomName(50);
const std::string invalid_usernames[] = {
"", "a", "aa", std::string(51, 'c'), std::string(255, 'd'), std::string(256, 'e')};
+ ASSERT_NO_THROW({
+ const auto created = CreateUser(client, source, "secret123", iggy::UserStatus::Active);
- for (const auto &replacement : invalid_usernames) {
- ASSERT_THROW(
- client->update_user(make_string_identifier(source), true, replacement, true, iggy::ffi::UserStatus::Active),
- std::exception);
- }
- iggy::ffi::UserInfoDetails fetched{};
- ASSERT_NO_THROW({ fetched = client->get_user(make_string_identifier(source)); });
- EXPECT_EQ(fetched.id, created.id);
- EXPECT_EQ(fetched.status, iggy::ffi::UserStatus::Active);
- EXPECT_EQ(static_cast<std::string>(fetched.username), source);
+ for (const auto &replacement : invalid_usernames) {
+ ASSERT_THROW(client.UpdateUser(iggy::Identifier::String(source), replacement, iggy::UserStatus::Active,
+ iggy::UserUpdateOptions{}),
+ std::exception);
+ }
+ const auto fetched = client.GetUser(iggy::Identifier::String(source));
+ EXPECT_EQ(fetched.Id(), created.Id());
+ EXPECT_EQ(fetched.Status(), iggy::UserStatus::Active);
+ EXPECT_EQ(fetched.Username(), source);
+ });
}
-TEST_F(LowLevelE2E_Client, UpdateUserAcceptsNonAsciiAndNonAlphabeticUsername) {
+TEST_F(E2E_Client, UpdateUserAcceptsNonAsciiAndNonAlphabeticUsername) {
RecordProperty("description", "Accepts representative non-ASCII and non-alphabetic usernames.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string suffix = GetRandomName(8);
const std::string sources[] = {GetRandomName(50), GetRandomName(50), GetRandomName(50)};
const std::string replacements[] = {"!@#_" + suffix, "ユーザー_" + suffix, "😀🚀_" + suffix};
@@ -855,163 +815,180 @@ TEST_F(LowLevelE2E_Client, UpdateUserAcceptsNonAsciiAndNonAlphabeticUsername) {
ASSERT_LE(replacements[1].size(), 50u);
ASSERT_LE(replacements[2].size(), 50u);
for (std::size_t index = 0; index < 3; ++index) {
- iggy::ffi::UserInfoDetails created{};
- ASSERT_NO_THROW({ created = CreateUser(client, sources[index], "secret123", iggy::ffi::UserStatus::Active); });
- ASSERT_NO_THROW(client->update_user(make_string_identifier(sources[index]), true, replacements[index], true,
- iggy::ffi::UserStatus::Active));
- RenameTrackedUser(sources[index], replacements[index]);
- iggy::ffi::UserInfoDetails fetched{};
- ASSERT_NO_THROW({ fetched = client->get_user(make_string_identifier(replacements[index])); });
- EXPECT_EQ(fetched.id, created.id);
- EXPECT_EQ(static_cast<std::string>(fetched.username), replacements[index]);
+ ASSERT_NO_THROW({
+ const auto created = CreateUser(client, sources[index], "secret123", iggy::UserStatus::Active);
+ ASSERT_NO_THROW(client.UpdateUser(iggy::Identifier::String(sources[index]), replacements[index],
+ iggy::UserStatus::Active, iggy::UserUpdateOptions{}));
+ RenameTrackedUser(sources[index], replacements[index]);
+ const auto fetched = client.GetUser(iggy::Identifier::String(replacements[index]));
+ EXPECT_EQ(fetched.Id(), created.Id());
+ EXPECT_EQ(fetched.Username(), replacements[index]);
+ });
}
}
-TEST_F(LowLevelE2E_Client, UpdateUserRejectsInvalidStatusWithoutRenamingTarget) {
+TEST_F(E2E_Client, UpdateUserRejectsInvalidStatusWithoutRenamingTarget) {
RecordProperty("description", "Rejects invalid status codes atomically with username changes.");
- iggy::ffi::Client *client = GetLoggedInClient();
- const std::string username = GetRandomName(50);
- iggy::ffi::UserInfoDetails created{};
- ASSERT_NO_THROW({ created = CreateUser(client, username, "secret123", iggy::ffi::UserStatus::Active); });
- const iggy::ffi::UserStatus statuses[] = {
- static_cast<iggy::ffi::UserStatus>(0),
- static_cast<iggy::ffi::UserStatus>(3),
- static_cast<iggy::ffi::UserStatus>(std::numeric_limits<std::uint8_t>::max()),
+ auto client = GetLoggedInHighLevelClient();
+ const std::string username = GetRandomName(50);
+ const iggy::UserStatus statuses[] = {
+ static_cast<iggy::UserStatus>(0),
+ static_cast<iggy::UserStatus>(3),
+ static_cast<iggy::UserStatus>(std::numeric_limits<std::uint8_t>::max()),
};
- for (const auto status : statuses) {
- const std::string replacement = GetRandomName(50);
- ASSERT_THROW(client->update_user(make_string_identifier(username), true, replacement, true, status),
- std::exception);
- ASSERT_THROW(client->get_user(make_string_identifier(replacement)), std::exception);
- }
- iggy::ffi::UserInfoDetails fetched{};
- ASSERT_NO_THROW({ fetched = client->get_user(make_string_identifier(username)); });
- EXPECT_EQ(fetched.id, created.id);
- EXPECT_EQ(fetched.status, iggy::ffi::UserStatus::Active);
- EXPECT_EQ(static_cast<std::string>(fetched.username), username);
+ ASSERT_NO_THROW({
+ const auto created = CreateUser(client, username, "secret123", iggy::UserStatus::Active);
+ for (const auto status : statuses) {
+ const std::string replacement = GetRandomName(50);
+ ASSERT_THROW(
+ client.UpdateUser(iggy::Identifier::String(username), replacement, status, iggy::UserUpdateOptions{}),
+ std::exception);
+ ASSERT_THROW(client.GetUser(iggy::Identifier::String(replacement)), std::exception);
+ }
+ const auto fetched = client.GetUser(iggy::Identifier::String(username));
+ EXPECT_EQ(fetched.Id(), created.Id());
+ EXPECT_EQ(fetched.Status(), iggy::UserStatus::Active);
+ EXPECT_EQ(fetched.Username(), username);
+ });
}
-TEST_F(LowLevelE2E_Client, UpdateUserRejectsDuplicateUsernameWithoutChangingStatus) {
+TEST_F(E2E_Client, UpdateUserRejectsDuplicateUsernameWithoutChangingStatus) {
RecordProperty("description", "Rejects duplicate usernames without partially applying the status update.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string target_username = GetRandomName(50);
const std::string conflict_username = GetRandomName(50);
- iggy::ffi::UserInfoDetails target{};
- iggy::ffi::UserInfoDetails conflict{};
- ASSERT_NO_THROW({ target = CreateUser(client, target_username, "secret123", iggy::ffi::UserStatus::Active); });
- ASSERT_NO_THROW(
- { conflict = CreateUser(client, conflict_username, "secret123", iggy::ffi::UserStatus::Inactive); });
- ASSERT_THROW(client->update_user(make_string_identifier(target_username), true, conflict_username, true,
- iggy::ffi::UserStatus::Inactive),
- std::exception);
- iggy::ffi::UserInfoDetails fetched_target{};
- iggy::ffi::UserInfoDetails fetched_conflict{};
- ASSERT_NO_THROW({ fetched_target = client->get_user(make_string_identifier(target_username)); });
- ASSERT_NO_THROW({ fetched_conflict = client->get_user(make_string_identifier(conflict_username)); });
- EXPECT_EQ(fetched_target.id, target.id);
- EXPECT_EQ(fetched_conflict.id, conflict.id);
- EXPECT_EQ(fetched_target.status, iggy::ffi::UserStatus::Active);
- EXPECT_EQ(fetched_conflict.status, iggy::ffi::UserStatus::Inactive);
+ ASSERT_NO_THROW({
+ const auto target = CreateUser(client, target_username, "secret123", iggy::UserStatus::Active);
+ const auto conflict = CreateUser(client, conflict_username, "secret123", iggy::UserStatus::Inactive);
+ ASSERT_THROW(client.UpdateUser(iggy::Identifier::String(target_username), conflict_username,
+ iggy::UserStatus::Inactive, iggy::UserUpdateOptions{}),
+ std::exception);
+ const auto fetched_target = client.GetUser(iggy::Identifier::String(target_username));
+ const auto fetched_conflict = client.GetUser(iggy::Identifier::String(conflict_username));
+ EXPECT_EQ(fetched_target.Id(), target.Id());
+ EXPECT_EQ(fetched_conflict.Id(), conflict.Id());
+ EXPECT_EQ(fetched_target.Status(), iggy::UserStatus::Active);
+ EXPECT_EQ(fetched_conflict.Status(), iggy::UserStatus::Inactive);
+ });
}
-TEST_F(LowLevelE2E_Client, UpdateUserAllowsCurrentUsernameWhileChangingStatus) {
+TEST_F(E2E_Client, UpdateUserAllowsCurrentUsernameWhileChangingStatus) {
RecordProperty("description", "Allows a same-username update that changes status.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string username = GetRandomName(50);
- iggy::ffi::UserInfoDetails created{};
- ASSERT_NO_THROW({ created = CreateUser(client, username, "secret123", iggy::ffi::UserStatus::Active); });
- ASSERT_NO_THROW(
- client->update_user(make_string_identifier(username), true, username, true, iggy::ffi::UserStatus::Inactive));
- iggy::ffi::UserInfoDetails fetched{};
- ASSERT_NO_THROW({ fetched = client->get_user(make_string_identifier(username)); });
- EXPECT_EQ(fetched.id, created.id);
- EXPECT_EQ(fetched.status, iggy::ffi::UserStatus::Inactive);
- EXPECT_EQ(static_cast<std::string>(fetched.username), username);
+ ASSERT_NO_THROW({
+ const auto created = CreateUser(client, username, "secret123", iggy::UserStatus::Active);
+ ASSERT_NO_THROW(client.UpdateUser(iggy::Identifier::String(username), username, iggy::UserStatus::Inactive,
+ iggy::UserUpdateOptions{}));
+ const auto fetched = client.GetUser(iggy::Identifier::String(username));
+ EXPECT_EQ(fetched.Id(), created.Id());
+ EXPECT_EQ(fetched.Status(), iggy::UserStatus::Inactive);
+ EXPECT_EQ(fetched.Username(), username);
+ });
}
-TEST_F(LowLevelE2E_Client, UpdateUserPreservesPasswordPermissionsAndCreationData) {
+TEST_F(E2E_Client, UpdateUserPreservesPasswordPermissionsAndCreationData) {
RecordProperty("description", "Preserves password, permissions, ID, and creation timestamp after a rename.");
- iggy::ffi::Client *root_client = GetLoggedInClient();
- iggy::ffi::Client *valid_client = GetLoggedOutClient();
- iggy::ffi::Client *old_client = GetLoggedOutClient();
- const std::string username = GetRandomName(50);
- const std::string replacement = GetRandomName(50);
- iggy::ffi::Permissions permissions{};
- permissions.global.read_users = true;
- permissions.global.read_streams = true;
- permissions.global.send_messages = true;
- iggy::ffi::UserInfoDetails created{};
+ auto root_client = GetLoggedInHighLevelClient();
+ auto valid_client = GetLoggedOutHighLevelClient();
+ auto old_client = GetLoggedOutHighLevelClient();
+ const std::string username = GetRandomName(50);
+ const std::string replacement = GetRandomName(50);
+ iggy::GlobalPermissions global;
+ global.SetReadUsers(true).SetReadStreams(true).SetSendMessages(true);
+ iggy::Permissions permissions;
+ permissions.SetGlobal(global);
ASSERT_NO_THROW({
- created = CreateUser(root_client, username, "known-secret", iggy::ffi::UserStatus::Active, true,
- std::move(permissions));
+ const auto created = CreateUser(root_client, username, "known-secret", iggy::UserStatus::Active, permissions);
+ ASSERT_NO_THROW(root_client.UpdateUser(iggy::Identifier::String(username), replacement,
+ iggy::UserStatus::Active, iggy::UserUpdateOptions{}));
+ RenameTrackedUser(username, replacement);
+ const auto fetched = root_client.GetUser(iggy::Identifier::String(replacement));
+ EXPECT_EQ(fetched.Id(), created.Id());
+ EXPECT_EQ(fetched.CreatedAt(), created.CreatedAt());
+ ASSERT_TRUE(fetched.Permissions().has_value());
+ EXPECT_TRUE(fetched.Permissions()->Global().ReadUsers());
+ EXPECT_TRUE(fetched.Permissions()->Global().ReadStreams());
+ EXPECT_TRUE(fetched.Permissions()->Global().SendMessages());
});
- ASSERT_NO_THROW(root_client->update_user(make_string_identifier(username), true, replacement, true,
- iggy::ffi::UserStatus::Active));
- RenameTrackedUser(username, replacement);
- iggy::ffi::UserInfoDetails fetched{};
- ASSERT_NO_THROW({ fetched = root_client->get_user(make_string_identifier(replacement)); });
- EXPECT_EQ(fetched.id, created.id);
- EXPECT_EQ(fetched.created_at, created.created_at);
- EXPECT_TRUE(fetched.has_permissions);
- EXPECT_TRUE(fetched.permissions.global.read_users);
- EXPECT_TRUE(fetched.permissions.global.read_streams);
- EXPECT_TRUE(fetched.permissions.global.send_messages);
- ASSERT_NO_THROW(valid_client->connect());
- ASSERT_NO_THROW(valid_client->login_user(replacement, "known-secret"));
- ASSERT_NO_THROW(old_client->connect());
- ASSERT_THROW(old_client->login_user(username, "known-secret"), std::exception);
+ ASSERT_NO_THROW(valid_client.Connect());
+ ASSERT_NO_THROW(valid_client.Login(replacement, "known-secret"));
+ ASSERT_NO_THROW(old_client.Connect());
+ ASSERT_THROW(old_client.Login(username, "known-secret"), std::exception);
}
-TEST_F(LowLevelE2E_Client, UpdateUserToInactiveBlocksFreshLoginUntilReactivated) {
+TEST_F(E2E_Client, UpdateUserToInactiveBlocksFreshLoginUntilReactivated) {
RecordProperty("description", "Blocks fresh login while inactive and restores it when active.");
- iggy::ffi::Client *root_client = GetLoggedInClient();
- iggy::ffi::Client *user_client = GetLoggedOutClient();
- const std::string username = GetRandomName(50);
- ASSERT_NO_THROW({ CreateUser(root_client, username, "known-secret", iggy::ffi::UserStatus::Active); });
- ASSERT_NO_THROW(root_client->update_user(make_string_identifier(username), true, username, true,
- iggy::ffi::UserStatus::Inactive));
- ASSERT_NO_THROW(user_client->connect());
- ASSERT_THROW(user_client->login_user(username, "known-secret"), std::exception);
- ASSERT_NO_THROW(root_client->update_user(make_string_identifier(username), true, username, true,
- iggy::ffi::UserStatus::Active));
- ASSERT_NO_THROW(user_client->login_user(username, "known-secret"));
+ auto root_client = GetLoggedInHighLevelClient();
+ auto user_client = GetLoggedOutHighLevelClient();
+ const std::string username = GetRandomName(50);
+ ASSERT_NO_THROW({ CreateUser(root_client, username, "known-secret", iggy::UserStatus::Active); });
+ ASSERT_NO_THROW(root_client.UpdateUser(iggy::Identifier::String(username), username, iggy::UserStatus::Inactive,
+ iggy::UserUpdateOptions{}));
+ ASSERT_NO_THROW(user_client.Connect());
+ ASSERT_THROW(user_client.Login(username, "known-secret"), std::exception);
+ ASSERT_NO_THROW(root_client.UpdateUser(iggy::Identifier::String(username), username, iggy::UserStatus::Active,
+ iggy::UserUpdateOptions{}));
+ ASSERT_NO_THROW(user_client.Login(username, "known-secret"));
}
-TEST_F(LowLevelE2E_Client, UpdateUserRenameMakesOldUsernameReusable) {
+TEST_F(E2E_Client, UpdateUserRenameMakesOldUsernameReusable) {
RecordProperty("description", "Releases the old username for a new user after a successful rename.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string old_username = GetRandomName(50);
const std::string new_username = GetRandomName(50);
- iggy::ffi::UserInfoDetails first{};
- ASSERT_NO_THROW({ first = CreateUser(client, old_username, "secret123", iggy::ffi::UserStatus::Active); });
- ASSERT_NO_THROW(client->update_user(make_string_identifier(old_username), true, new_username, true,
- iggy::ffi::UserStatus::Active));
- RenameTrackedUser(old_username, new_username);
- iggy::ffi::UserInfoDetails second{};
- ASSERT_NO_THROW({ second = CreateUser(client, old_username, "secret123", iggy::ffi::UserStatus::Active); });
- EXPECT_EQ(static_cast<std::string>(client->get_user(make_string_identifier(new_username)).username), new_username);
- EXPECT_EQ(static_cast<std::string>(client->get_user(make_string_identifier(old_username)).username), old_username);
-}
-
-TEST_F(LowLevelE2E_Client, UpdateUserRejectsRenameToRootUsername) {
+ ASSERT_NO_THROW({
+ const auto first = CreateUser(client, old_username, "secret123", iggy::UserStatus::Active);
+ ASSERT_NO_THROW(client.UpdateUser(iggy::Identifier::String(old_username), new_username,
+ iggy::UserStatus::Active, iggy::UserUpdateOptions{}));
+ RenameTrackedUser(old_username, new_username);
+ const auto second = CreateUser(client, old_username, "secret123", iggy::UserStatus::Active);
+ EXPECT_EQ(client.GetUser(iggy::Identifier::String(new_username)).Username(), new_username);
+ EXPECT_EQ(client.GetUser(iggy::Identifier::String(old_username)).Username(), old_username);
+ EXPECT_NE(first.Id(), second.Id());
+ });
+}
+
+TEST_F(E2E_Client, UpdateUserRejectsRenameToRootUsername) {
RecordProperty("description", "Rejects changing a non-root user's username to root's username.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string username = GetRandomName(50);
- iggy::ffi::UserInfoDetails target{};
- ASSERT_NO_THROW({ target = CreateUser(client, username, "secret123", iggy::ffi::UserStatus::Active); });
- ASSERT_THROW(
- client->update_user(make_string_identifier(username), true, "iggy", true, iggy::ffi::UserStatus::Inactive),
- std::exception);
- iggy::ffi::UserInfoDetails root{};
- iggy::ffi::UserInfoDetails fetched{};
- ASSERT_NO_THROW({ root = client->get_user(make_string_identifier("iggy")); });
- ASSERT_NO_THROW({ fetched = client->get_user(make_string_identifier(username)); });
- EXPECT_EQ(root.id, 0u);
- EXPECT_EQ(static_cast<std::string>(root.username), "iggy");
- EXPECT_EQ(root.status, iggy::ffi::UserStatus::Active);
- EXPECT_EQ(fetched.id, target.id);
- EXPECT_EQ(fetched.status, iggy::ffi::UserStatus::Active);
- EXPECT_EQ(static_cast<std::string>(fetched.username), username);
+ ASSERT_NO_THROW({
+ const auto target = CreateUser(client, username, "secret123", iggy::UserStatus::Active);
+ ASSERT_THROW(client.UpdateUser(iggy::Identifier::String(username), "iggy", iggy::UserStatus::Inactive,
+ iggy::UserUpdateOptions{}),
+ std::exception);
+ const auto root = client.GetUser(iggy::Identifier::String("iggy"));
+ const auto fetched = client.GetUser(iggy::Identifier::String(username));
+ EXPECT_EQ(root.Id(), 0u);
+ EXPECT_EQ(root.Username(), "iggy");
+ EXPECT_EQ(root.Status(), iggy::UserStatus::Active);
+ EXPECT_EQ(fetched.Id(), target.Id());
+ EXPECT_EQ(fetched.Status(), iggy::UserStatus::Active);
+ EXPECT_EQ(fetched.Username(), username);
+ });
+}
+
+TEST_F(E2E_Client, UpdateUserWithUnsupportedOptionsRejectsAndPreservesUser) {
+ RecordProperty("description", "Rejects unsupported user options without changing the user.");
+ auto client = GetLoggedInHighLevelClient();
+ const std::string username = GetRandomName(50);
+ const std::string replacement = GetRandomName(50);
+ ASSERT_NO_THROW({
+ const auto created = CreateUser(client, username, "secret123", iggy::UserStatus::Active);
+ iggy::UserUpdateOptions options;
+ options.SetRawEntries({{"not_a_real_option", "true"}});
+
+ ASSERT_THROW(
+ client.UpdateUser(iggy::Identifier::String(username), replacement, iggy::UserStatus::Inactive, options),
+ iggy::IggyException);
+
+ const auto fetched = client.GetUser(iggy::Identifier::String(username));
+ EXPECT_EQ(fetched.Id(), created.Id());
+ EXPECT_EQ(fetched.Username(), username);
+ EXPECT_EQ(fetched.Status(), iggy::UserStatus::Active);
+ ASSERT_THROW(client.GetUser(iggy::Identifier::String(replacement)), iggy::IggyException);
+ });
}
TEST_F(LowLevelE2E_Client, ReadUsersPermissionDoesNotAllowUpdateUser) {
@@ -1031,10 +1008,10 @@ TEST_F(LowLevelE2E_Client, ReadUsersPermissionDoesNotAllowUpdateUser) {
ASSERT_NO_THROW(caller_client->connect());
ASSERT_NO_THROW(caller_client->login_user(caller_username, "secret123"));
ASSERT_THROW(caller_client->update_user(make_string_identifier(target_username), true, GetRandomName(50), true,
- iggy::ffi::UserStatus::Inactive),
+ iggy::ffi::UserStatus::Inactive, {}),
std::exception);
ASSERT_THROW(caller_client->update_user(make_string_identifier(caller_username), true, GetRandomName(50), true,
- iggy::ffi::UserStatus::Inactive),
+ iggy::ffi::UserStatus::Inactive, {}),
std::exception);
iggy::ffi::UserInfoDetails fetched{};
ASSERT_NO_THROW({ fetched = root_client->get_user(make_string_identifier(target_username)); });
@@ -1060,7 +1037,7 @@ TEST_F(LowLevelE2E_Client, ManageUsersPermissionAllowsUpdateWithoutReadUsers) {
ASSERT_NO_THROW(manager_client->connect());
ASSERT_NO_THROW(manager_client->login_user(manager_username, "secret123"));
ASSERT_NO_THROW(manager_client->update_user(make_string_identifier(target_username), true, replacement, true,
- iggy::ffi::UserStatus::Inactive));
+ iggy::ffi::UserStatus::Inactive, {}));
RenameTrackedUser(target_username, replacement);
iggy::ffi::UserInfoDetails fetched{};
ASSERT_NO_THROW({ fetched = root_client->get_user(make_string_identifier(replacement)); });
@@ -1069,111 +1046,114 @@ TEST_F(LowLevelE2E_Client, ManageUsersPermissionAllowsUpdateWithoutReadUsers) {
EXPECT_EQ(static_cast<std::string>(fetched.username), replacement);
}
-TEST_F(LowLevelE2E_Client, GetUserBeforeLoginThrows) {
+TEST_F(E2E_Client, GetUserBeforeLoginThrows) {
RecordProperty("description", "Rejects user lookup without an active authenticated session.");
- iggy::ffi::Client *client = GetLoggedOutClient();
+ auto client = GetLoggedOutHighLevelClient();
- ASSERT_THROW(client->get_user(make_string_identifier("iggy")), std::exception);
- ASSERT_NO_THROW(client->connect());
- ASSERT_THROW(client->get_user(make_string_identifier("iggy")), std::exception);
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->logout_user());
- ASSERT_THROW(client->get_user(make_string_identifier("iggy")), std::exception);
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->disconnect());
- ASSERT_THROW(client->get_user(make_string_identifier("iggy")), std::exception);
+ ASSERT_THROW(client.GetUser(iggy::Identifier::String("iggy")), std::exception);
+ ASSERT_NO_THROW(client.Connect());
+ ASSERT_THROW(client.GetUser(iggy::Identifier::String("iggy")), std::exception);
+ ASSERT_NO_THROW(client.Login("iggy", "iggy"));
+ ASSERT_NO_THROW(client.Logout());
+ ASSERT_THROW(client.GetUser(iggy::Identifier::String("iggy")), std::exception);
+ ASSERT_NO_THROW(client.Login("iggy", "iggy"));
+ ASSERT_NO_THROW(client.Disconnect());
+ ASSERT_THROW(client.GetUser(iggy::Identifier::String("iggy")), std::exception);
}
-TEST_F(LowLevelE2E_Client, GetUserByUsernameReturnsRootDetails) {
+TEST_F(E2E_Client, GetUserByUsernameReturnsRootDetails) {
RecordProperty("description", "Returns deterministic root details for a username lookup.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
- iggy::ffi::UserInfoDetails user{};
- ASSERT_NO_THROW({ user = client->get_user(make_string_identifier("iggy")); });
+ const auto user = client.GetUser(iggy::Identifier::String("iggy"));
- EXPECT_EQ(user.id, 0u);
- EXPECT_EQ(static_cast<std::string>(user.username), "iggy");
- EXPECT_EQ(user.status, iggy::ffi::UserStatus::Active);
+ EXPECT_EQ(user.Id(), 0u);
+ EXPECT_EQ(user.Username(), "iggy");
+ EXPECT_EQ(user.Status(), iggy::UserStatus::Active);
}
-TEST_F(LowLevelE2E_Client, GetUserByNumericIdMatchesUsernameLookup) {
+TEST_F(E2E_Client, GetUserByNumericIdMatchesUsernameLookup) {
RecordProperty("description", "Returns equivalent root details for username and numeric identifiers.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
+
+ ASSERT_NO_THROW({
+ const auto by_username = client.GetUser(iggy::Identifier::String("iggy"));
+ const auto by_id = client.GetUser(iggy::Identifier::Numeric(0));
+
+ EXPECT_EQ(by_id.Id(), by_username.Id());
+ EXPECT_EQ(by_id.Status(), by_username.Status());
+ EXPECT_EQ(by_id.Username(), by_username.Username());
+ ASSERT_TRUE(by_id.Permissions().has_value());
+ ASSERT_TRUE(by_username.Permissions().has_value());
+ const auto &by_id_permissions = by_id.Permissions().value();
+ const auto &by_username_permissions = by_username.Permissions().value();
+ EXPECT_EQ(by_id_permissions.Global().ManageServers(), by_username_permissions.Global().ManageServers());
+ EXPECT_EQ(by_id_permissions.Global().ReadServers(), by_username_permissions.Global().ReadServers());
+ EXPECT_EQ(by_id_permissions.Global().ManageUsers(), by_username_permissions.Global().ManageUsers());
+ EXPECT_EQ(by_id_permissions.Global().ReadUsers(), by_username_permissions.Global().ReadUsers());
+ EXPECT_EQ(by_id_permissions.Global().ManageStreams(), by_username_permissions.Global().ManageStreams());
+ EXPECT_EQ(by_id_permissions.Global().ReadStreams(), by_username_permissions.Global().ReadStreams());
+ EXPECT_EQ(by_id_permissions.Global().ManageTopics(), by_username_permissions.Global().ManageTopics());
+ EXPECT_EQ(by_id_permissions.Global().ReadTopics(), by_username_permissions.Global().ReadTopics());
+ EXPECT_EQ(by_id_permissions.Global().PollMessages(), by_username_permissions.Global().PollMessages());
+ EXPECT_EQ(by_id_permissions.Global().SendMessages(), by_username_permissions.Global().SendMessages());
+ EXPECT_EQ(by_id_permissions.Streams().size(), by_username_permissions.Streams().size());
+ });
+}
- iggy::ffi::UserInfoDetails by_username{};
- iggy::ffi::UserInfoDetails by_id{};
- ASSERT_NO_THROW({ by_username = client->get_user(make_string_identifier("iggy")); });
- ASSERT_NO_THROW({ by_id = client->get_user(make_numeric_identifier(0)); });
-
- EXPECT_EQ(by_id.id, by_username.id);
- EXPECT_EQ(by_id.status, by_username.status);
- EXPECT_EQ(static_cast<std::string>(by_id.username), static_cast<std::string>(by_username.username));
- EXPECT_EQ(by_id.permissions.global.manage_servers, by_username.permissions.global.manage_servers);
- EXPECT_EQ(by_id.permissions.global.read_servers, by_username.permissions.global.read_servers);
- EXPECT_EQ(by_id.permissions.global.manage_users, by_username.permissions.global.manage_users);
- EXPECT_EQ(by_id.permissions.global.read_users, by_username.permissions.global.read_users);
- EXPECT_EQ(by_id.permissions.global.manage_streams, by_username.permissions.global.manage_streams);
- EXPECT_EQ(by_id.permissions.global.read_streams, by_username.permissions.global.read_streams);
- EXPECT_EQ(by_id.permissions.global.manage_topics, by_username.permissions.global.manage_topics);
- EXPECT_EQ(by_id.permissions.global.read_topics, by_username.permissions.global.read_topics);
- EXPECT_EQ(by_id.permissions.global.poll_messages, by_username.permissions.global.poll_messages);
- EXPECT_EQ(by_id.permissions.global.send_messages, by_username.permissions.global.send_messages);
- EXPECT_EQ(by_id.permissions.streams.size(), by_username.permissions.streams.size());
-}
-
-TEST_F(LowLevelE2E_Client, GetUserWithUnknownIdentifierThrows) {
+TEST_F(E2E_Client, GetUserWithUnknownIdentifierThrows) {
RecordProperty("description", "Rejects lookups for unknown username and numeric identifiers.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string unknown_user = GetRandomName(50);
- ASSERT_THROW(client->get_user(make_string_identifier(unknown_user)), std::exception);
- ASSERT_THROW(client->get_user(make_numeric_identifier(std::numeric_limits<std::uint32_t>::max())), std::exception);
+ ASSERT_THROW(client.GetUser(iggy::Identifier::String(unknown_user)), std::exception);
+ ASSERT_THROW(client.GetUser(iggy::Identifier::Numeric(std::numeric_limits<std::uint32_t>::max())), std::exception);
}
-TEST_F(LowLevelE2E_Client, GetUsersBeforeLoginThrows) {
+TEST_F(E2E_Client, GetUsersBeforeLoginThrows) {
RecordProperty("description", "Rejects listing users without an active authenticated session.");
- iggy::ffi::Client *client = GetLoggedOutClient();
+ auto client = GetLoggedOutHighLevelClient();
- ASSERT_THROW(client->get_users(), std::exception);
- ASSERT_NO_THROW(client->connect());
- ASSERT_THROW(client->get_users(), std::exception);
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->logout_user());
- ASSERT_THROW(client->get_users(), std::exception);
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->disconnect());
- ASSERT_THROW(client->get_users(), std::exception);
+ ASSERT_THROW(client.GetUsers(), std::exception);
+ ASSERT_NO_THROW(client.Connect());
+ ASSERT_THROW(client.GetUsers(), std::exception);
+ ASSERT_NO_THROW(client.Login("iggy", "iggy"));
+ ASSERT_NO_THROW(client.Logout());
+ ASSERT_THROW(client.GetUsers(), std::exception);
+ ASSERT_NO_THROW(client.Login("iggy", "iggy"));
+ ASSERT_NO_THROW(client.Disconnect());
+ ASSERT_THROW(client.GetUsers(), std::exception);
}
-TEST_F(LowLevelE2E_Client, GetUserAllowsSelfLookupWithoutReadUsersPermission) {
+TEST_F(E2E_Client, GetUserAllowsSelfLookupWithoutReadUsersPermission) {
RecordProperty("description", "Allows a user without read_users permission to read its own details.");
- iggy::ffi::Client *root_client = GetLoggedInClient();
- const std::string username = GetRandomName(50);
- iggy::ffi::Permissions permissions{};
- permissions.global.read_users = false;
- iggy::ffi::UserInfoDetails created_user{};
+ auto root_client = GetLoggedInHighLevelClient();
+ const std::string username = GetRandomName(50);
+ iggy::GlobalPermissions global;
+ global.SetReadUsers(false);
+ iggy::Permissions permissions;
+ permissions.SetGlobal(global);
ASSERT_NO_THROW({
- created_user =
- CreateUser(root_client, username, "secret123", iggy::ffi::UserStatus::Active, true, std::move(permissions));
+ const auto created_user = CreateUser(root_client, username, "secret123", iggy::UserStatus::Active, permissions);
+
+ auto user_client = GetLoggedOutHighLevelClient();
+ ASSERT_NO_THROW(user_client.Connect());
+ ASSERT_NO_THROW(user_client.Login(username, "secret123"));
+
+ const auto by_username = user_client.GetUser(iggy::Identifier::String(username));
+ const auto by_id = user_client.GetUser(iggy::Identifier::Numeric(created_user.Id()));
+
+ EXPECT_EQ(by_username.Id(), created_user.Id());
+ EXPECT_EQ(by_id.Id(), created_user.Id());
+ EXPECT_EQ(by_username.Username(), username);
+ EXPECT_EQ(by_id.Username(), username);
+ EXPECT_EQ(by_username.Status(), iggy::UserStatus::Active);
+ EXPECT_EQ(by_id.Status(), iggy::UserStatus::Active);
+ ASSERT_TRUE(by_username.Permissions().has_value());
+ ASSERT_TRUE(by_id.Permissions().has_value());
+ EXPECT_FALSE(by_username.Permissions()->Global().ReadUsers());
+ EXPECT_FALSE(by_id.Permissions()->Global().ReadUsers());
});
-
- iggy::ffi::Client *user_client = GetLoggedOutClient();
- ASSERT_NO_THROW(user_client->connect());
- ASSERT_NO_THROW(user_client->login_user(username, "secret123"));
-
- iggy::ffi::UserInfoDetails by_username{};
- iggy::ffi::UserInfoDetails by_id{};
- ASSERT_NO_THROW({ by_username = user_client->get_user(make_string_identifier(username)); });
- ASSERT_NO_THROW({ by_id = user_client->get_user(make_numeric_identifier(created_user.id)); });
-
- EXPECT_EQ(by_username.id, created_user.id);
- EXPECT_EQ(by_id.id, created_user.id);
- EXPECT_EQ(static_cast<std::string>(by_username.username), username);
- EXPECT_EQ(static_cast<std::string>(by_id.username), username);
- EXPECT_EQ(by_username.status, iggy::ffi::UserStatus::Active);
- EXPECT_EQ(by_id.status, iggy::ffi::UserStatus::Active);
- EXPECT_FALSE(by_username.permissions.global.read_users);
- EXPECT_FALSE(by_id.permissions.global.read_users);
}
TEST_F(LowLevelE2E_Client, UserWithoutReadUsersPermissionCannotQueryOtherUsers) {
@@ -1255,95 +1235,91 @@ TEST_F(LowLevelE2E_Client, ManageUsersPermissionImpliesReadUsers) {
EXPECT_TRUE(found_self);
}
-TEST_F(LowLevelE2E_Client, GetUsersContainsCreatedUser) {
+TEST_F(E2E_Client, GetUsersContainsCreatedUser) {
RecordProperty("description", "Lists a created user with the input username and status.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string username = GetRandomName(50);
- iggy::ffi::UserInfoDetails created_user{};
- ASSERT_NO_THROW({ created_user = CreateUser(client, username, "secret123", iggy::ffi::UserStatus::Active); });
+ ASSERT_NO_THROW({
+ const auto created_user = CreateUser(client, username, "secret123", iggy::UserStatus::Active);
- rust::Vec<iggy::ffi::UserInfo> users;
- ASSERT_NO_THROW({ users = client->get_users(); });
+ const auto users = client.GetUsers();
- bool found_user = false;
- for (const auto &user : users) {
- if (user.id == created_user.id) {
- found_user = true;
- EXPECT_EQ(static_cast<std::string>(user.username), username);
- EXPECT_EQ(user.status, iggy::ffi::UserStatus::Active);
+ bool found_user = false;
+ for (const auto &user : users) {
+ if (user.Id() == created_user.Id()) {
+ found_user = true;
+ EXPECT_EQ(user.Username(), username);
+ EXPECT_EQ(user.Status(), iggy::UserStatus::Active);
+ }
}
- }
- EXPECT_TRUE(found_user);
+ EXPECT_TRUE(found_user);
+ });
}
-TEST_F(LowLevelE2E_Client, GetUsersReturnsAllCreatedUsersOrderedById) {
+TEST_F(E2E_Client, GetUsersReturnsAllCreatedUsersOrderedById) {
RecordProperty("description", "Returns every created user without pagination, ordered by ID over TCP.");
- iggy::ffi::Client *client = GetLoggedInClient();
- rust::Vec<iggy::ffi::UserInfo> users_before;
- ASSERT_NO_THROW({ users_before = client->get_users(); });
-
- const std::string first_username = GetRandomName(50);
- const std::string second_username = GetRandomName(50);
- const std::string third_username = GetRandomName(50);
- iggy::ffi::UserInfoDetails first_user{};
- iggy::ffi::UserInfoDetails second_user{};
- iggy::ffi::UserInfoDetails third_user{};
- ASSERT_NO_THROW({ first_user = CreateUser(client, first_username, "secret123", iggy::ffi::UserStatus::Active); });
- ASSERT_NO_THROW({ second_user = CreateUser(client, second_username, "secret123", iggy::ffi::UserStatus::Active); });
- ASSERT_NO_THROW({ third_user = CreateUser(client, third_username, "secret123", iggy::ffi::UserStatus::Active); });
-
- rust::Vec<iggy::ffi::UserInfo> users_after;
- ASSERT_NO_THROW({ users_after = client->get_users(); });
- ASSERT_EQ(users_after.size(), users_before.size() + 3);
-
- bool found_first = false;
- bool found_second = false;
- bool found_third = false;
- for (std::size_t index = 0; index < users_after.size(); ++index) {
- if (index > 0) {
- EXPECT_LT(users_after[index - 1].id, users_after[index].id);
- }
- const auto &user = users_after[index];
- const std::string username = static_cast<std::string>(user.username);
- if (user.id == first_user.id && username == first_username) {
- found_first = true;
- }
- if (user.id == second_user.id && username == second_username) {
- found_second = true;
- }
- if (user.id == third_user.id && username == third_username) {
- found_third = true;
+ auto client = GetLoggedInHighLevelClient();
+ ASSERT_NO_THROW({
+ const auto users_before = client.GetUsers();
+
+ const std::string first_username = GetRandomName(50);
+ const std::string second_username = GetRandomName(50);
+ const std::string third_username = GetRandomName(50);
+ const auto first_user = CreateUser(client, first_username, "secret123", iggy::UserStatus::Active);
+ const auto second_user = CreateUser(client, second_username, "secret123", iggy::UserStatus::Active);
+ const auto third_user = CreateUser(client, third_username, "secret123", iggy::UserStatus::Active);
+
+ const auto users_after = client.GetUsers();
+ ASSERT_EQ(users_after.size(), users_before.size() + 3);
+
+ bool found_first = false;
+ bool found_second = false;
+ bool found_third = false;
+ for (std::size_t index = 0; index < users_after.size(); ++index) {
+ if (index > 0) {
+ EXPECT_LT(users_after[index - 1].Id(), users_after[index].Id());
+ }
+ const auto &user = users_after[index];
+ const std::string username = user.Username();
+ if (user.Id() == first_user.Id() && username == first_username) {
+ found_first = true;
+ }
+ if (user.Id() == second_user.Id() && username == second_username) {
+ found_second = true;
+ }
+ if (user.Id() == third_user.Id() && username == third_username) {
+ found_third = true;
+ }
}
- }
- EXPECT_TRUE(found_first);
- EXPECT_TRUE(found_second);
- EXPECT_TRUE(found_third);
+ EXPECT_TRUE(found_first);
+ EXPECT_TRUE(found_second);
+ EXPECT_TRUE(found_third);
+ });
}
-TEST_F(LowLevelE2E_Client, GetUsersMatchesGetUserDetails) {
+TEST_F(E2E_Client, GetUsersMatchesGetUserDetails) {
RecordProperty("description", "Returns consistent ID, username, and status from user query APIs.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string username = GetRandomName(50);
- iggy::ffi::UserInfoDetails created_user{};
- ASSERT_NO_THROW({ created_user = CreateUser(client, username, "secret123", iggy::ffi::UserStatus::Active); });
-
- iggy::ffi::UserInfoDetails user_details{};
- rust::Vec<iggy::ffi::UserInfo> users;
- ASSERT_NO_THROW({ user_details = client->get_user(make_string_identifier(username)); });
- ASSERT_NO_THROW({ users = client->get_users(); });
-
- EXPECT_EQ(user_details.id, created_user.id);
- EXPECT_EQ(static_cast<std::string>(user_details.username), username);
- EXPECT_EQ(user_details.status, iggy::ffi::UserStatus::Active);
- bool found_user = false;
- for (const auto &user : users) {
- if (user.id == user_details.id) {
- found_user = true;
- EXPECT_EQ(static_cast<std::string>(user.username), username);
- EXPECT_EQ(user.status, iggy::ffi::UserStatus::Active);
+ ASSERT_NO_THROW({
+ const auto created_user = CreateUser(client, username, "secret123", iggy::UserStatus::Active);
+
+ const auto user_details = client.GetUser(iggy::Identifier::String(username));
+ const auto users = client.GetUsers();
+
+ EXPECT_EQ(user_details.Id(), created_user.Id());
+ EXPECT_EQ(user_details.Username(), username);
+ EXPECT_EQ(user_details.Status(), iggy::UserStatus::Active);
+ bool found_user = false;
+ for (const auto &user : users) {
+ if (user.Id() == user_details.Id()) {
+ found_user = true;
+ EXPECT_EQ(user.Username(), username);
+ EXPECT_EQ(user.Status(), iggy::UserStatus::Active);
+ }
}
- }
- EXPECT_TRUE(found_user);
+ EXPECT_TRUE(found_user);
+ });
}
TEST_F(LowLevelE2E_Client, DeletedUserDisappearsFromGetUserAndGetUsers) {
@@ -1364,97 +1340,95 @@ TEST_F(LowLevelE2E_Client, DeletedUserDisappearsFromGetUserAndGetUsers) {
}
}
-TEST_F(LowLevelE2E_Client, DeleteUserRejectsUnauthenticatedClientWithoutDeletingTarget) {
+TEST_F(E2E_Client, DeleteUserRejectsUnauthenticatedClientWithoutDeletingTarget) {
RecordProperty("description", "Rejects user deletion without an active authenticated session.");
- iggy::ffi::Client *root_client = GetLoggedInClient();
- iggy::ffi::Client *client = GetLoggedOutClient();
- const std::string username = GetRandomName(50);
- iggy::ffi::UserInfoDetails created_user{};
- ASSERT_NO_THROW({ created_user = CreateUser(root_client, username, "secret123", iggy::ffi::UserStatus::Active); });
-
- ASSERT_THROW(client->delete_user(make_string_identifier(username)), std::exception);
- ASSERT_NO_THROW(client->connect());
- ASSERT_THROW(client->delete_user(make_string_identifier(username)), std::exception);
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->logout_user());
- ASSERT_THROW(client->delete_user(make_string_identifier(username)), std::exception);
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->disconnect());
- ASSERT_THROW(client->delete_user(make_string_identifier(username)), std::exception);
-
- iggy::ffi::UserInfoDetails fetched_user{};
- ASSERT_NO_THROW({ fetched_user = root_client->get_user(make_string_identifier(username)); });
- EXPECT_EQ(fetched_user.id, created_user.id);
+ auto root_client = GetLoggedInHighLevelClient();
+ auto client = GetLoggedOutHighLevelClient();
+ const std::string username = GetRandomName(50);
+ ASSERT_NO_THROW({
+ const auto created_user = CreateUser(root_client, username, "secret123", iggy::UserStatus::Active);
+
+ ASSERT_THROW(client.DeleteUser(iggy::Identifier::String(username)), std::exception);
+ ASSERT_NO_THROW(client.Connect());
+ ASSERT_THROW(client.DeleteUser(iggy::Identifier::String(username)), std::exception);
+ ASSERT_NO_THROW(client.Login("iggy", "iggy"));
+ ASSERT_NO_THROW(client.Logout());
+ ASSERT_THROW(client.DeleteUser(iggy::Identifier::String(username)), std::exception);
+ ASSERT_NO_THROW(client.Login("iggy", "iggy"));
+ ASSERT_NO_THROW(client.Disconnect());
+ ASSERT_THROW(client.DeleteUser(iggy::Identifier::String(username)), std::exception);
+
+ const auto fetched_user = root_client.GetUser(iggy::Identifier::String(username));
+ EXPECT_EQ(fetched_user.Id(), created_user.Id());
+ });
}
-TEST_F(LowLevelE2E_Client, DeleteUserRejectsUnknownUsernameAndNumericId) {
+TEST_F(E2E_Client, DeleteUserRejectsUnknownUsernameAndNumericId) {
RecordProperty("description", "Rejects deletion of unknown string and numeric user identifiers.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string unknown_user = GetRandomName(50);
constexpr std::uint32_t unknown_id = std::numeric_limits<std::uint32_t>::max();
- ASSERT_THROW(client->delete_user(make_string_identifier(unknown_user)), std::exception);
- ASSERT_THROW(client->delete_user(make_numeric_identifier(unknown_id)), std::exception);
+ ASSERT_THROW(client.DeleteUser(iggy::Identifier::String(unknown_user)), std::exception);
+ ASSERT_THROW(client.DeleteUser(iggy::Identifier::Numeric(unknown_id)), std::exception);
}
-TEST_F(LowLevelE2E_Client, DeleteUserRejectsRootWithoutChangingRoot) {
+TEST_F(E2E_Client, DeleteUserRejectsRootWithoutChangingRoot) {
RecordProperty("description", "Rejects root deletion by username and numeric ID without changing root.");
- iggy::ffi::Client *client = GetLoggedInClient();
- iggy::ffi::UserInfoDetails before_by_username{};
- iggy::ffi::UserInfoDetails before_by_id{};
- ASSERT_NO_THROW({ before_by_username = client->get_user(make_string_identifier("iggy")); });
- ASSERT_NO_THROW({ before_by_id = client->get_user(make_numeric_identifier(0)); });
- ASSERT_EQ(before_by_username.id, 0u);
- ASSERT_EQ(before_by_id.id, 0u);
-
- ASSERT_THROW(client->delete_user(make_string_identifier("iggy")), std::exception);
- ASSERT_THROW(client->delete_user(make_numeric_identifier(0)), std::exception);
-
- iggy::ffi::UserInfoDetails after_by_username{};
- iggy::ffi::UserInfoDetails after_by_id{};
- ASSERT_NO_THROW({ after_by_username = client->get_user(make_string_identifier("iggy")); });
- ASSERT_NO_THROW({ after_by_id = client->get_user(make_numeric_identifier(0)); });
- for (const auto *root : {&after_by_username, &after_by_id}) {
- EXPECT_EQ(root->id, 0u);
- EXPECT_EQ(static_cast<std::string>(root->username), "iggy");
- EXPECT_EQ(root->status, iggy::ffi::UserStatus::Active);
- }
+ auto client = GetLoggedInHighLevelClient();
+ ASSERT_NO_THROW({
+ const auto before_by_username = client.GetUser(iggy::Identifier::String("iggy"));
+ const auto before_by_id = client.GetUser(iggy::Identifier::Numeric(0));
+ ASSERT_EQ(before_by_username.Id(), 0u);
+ ASSERT_EQ(before_by_id.Id(), 0u);
+
+ ASSERT_THROW(client.DeleteUser(iggy::Identifier::String("iggy")), std::exception);
+ ASSERT_THROW(client.DeleteUser(iggy::Identifier::Numeric(0)), std::exception);
+
+ const auto after_by_username = client.GetUser(iggy::Identifier::String("iggy"));
+ const auto after_by_id = client.GetUser(iggy::Identifier::Numeric(0));
+ for (const auto *root : {&after_by_username, &after_by_id}) {
+ EXPECT_EQ(root->Id(), 0u);
+ EXPECT_EQ(root->Username(), "iggy");
+ EXPECT_EQ(root->Status(), iggy::UserStatus::Active);
+ }
+ });
}
-TEST_F(LowLevelE2E_Client, DeleteUserByNumericIdRemovesTarget) {
+TEST_F(E2E_Client, DeleteUserByNumericIdRemovesTarget) {
RecordProperty("description", "Deletes a user selected by its numeric ID.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string username = GetRandomName(50);
- iggy::ffi::UserInfoDetails created_user{};
- ASSERT_NO_THROW({ created_user = CreateUser(client, username, "secret123", iggy::ffi::UserStatus::Active); });
+ ASSERT_NO_THROW({
+ const auto created_user = CreateUser(client, username, "secret123", iggy::UserStatus::Active);
- ASSERT_NO_THROW(client->delete_user(make_numeric_identifier(created_user.id)));
- ForgetUser(username);
+ ASSERT_NO_THROW(client.DeleteUser(iggy::Identifier::Numeric(created_user.Id())));
+ ForgetUser(username);
- ASSERT_THROW(client->get_user(make_string_identifier(username)), std::exception);
- rust::Vec<iggy::ffi::UserInfo> users;
- ASSERT_NO_THROW({ users = client->get_users(); });
- for (const auto &user : users) {
- EXPECT_FALSE(user.id == created_user.id && static_cast<std::string>(user.username) == username);
- }
+ ASSERT_THROW(client.GetUser(iggy::Identifier::String(username)), std::exception);
+ const auto users = client.GetUsers();
+ for (const auto &user : users) {
+ EXPECT_FALSE(user.Id() == created_user.Id() && user.Username() == username);
+ }
+ });
}
-TEST_F(LowLevelE2E_Client, DeleteUserRejectsRepeatedDeletion) {
+TEST_F(E2E_Client, DeleteUserRejectsRepeatedDeletion) {
RecordProperty("description", "Rejects deleting the same user twice.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
const std::string username = GetRandomName(50);
- iggy::ffi::UserInfoDetails created_user{};
- ASSERT_NO_THROW({ created_user = CreateUser(client, username, "secret123", iggy::ffi::UserStatus::Active); });
+ ASSERT_NO_THROW({
+ const auto created_user = CreateUser(client, username, "secret123", iggy::UserStatus::Active);
- ASSERT_NO_THROW(client->delete_user(make_string_identifier(username)));
- ForgetUser(username);
- ASSERT_THROW(client->delete_user(make_string_identifier(username)), std::exception);
+ ASSERT_NO_THROW(client.DeleteUser(iggy::Identifier::String(username)));
+ ForgetUser(username);
+ ASSERT_THROW(client.DeleteUser(iggy::Identifier::String(username)), std::exception);
- rust::Vec<iggy::ffi::UserInfo> users;
- ASSERT_NO_THROW({ users = client->get_users(); });
- for (const auto &user : users) {
- EXPECT_FALSE(user.id == created_user.id && static_cast<std::string>(user.username) == username);
- }
+ const auto users = client.GetUsers();
+ for (const auto &user : users) {
+ EXPECT_FALSE(user.Id() == created_user.Id() && user.Username() == username);
+ }
+ });
}
TEST_F(LowLevelE2E_Client, ReadUsersPermissionDoesNotAllowDeleteUser) {
@@ -1516,35 +1490,32 @@ TEST_F(LowLevelE2E_Client, ManageUsersPermissionAllowsDeleteUser) {
}
}
-TEST_F(LowLevelE2E_Client, DeleteUserRemovesOnlyTheTarget) {
+TEST_F(E2E_Client, DeleteUserRemovesOnlyTheTarget) {
RecordProperty("description", "Deletes only the selected user and leaves another user usable.");
- iggy::ffi::Client *root_client = GetLoggedInClient();
- iggy::ffi::Client *survivor_client = GetLoggedOutClient();
- const std::string target_name = GetRandomName(50);
- const std::string survivor_name = GetRandomName(50);
- iggy::ffi::UserInfoDetails target{};
- iggy::ffi::UserInfoDetails survivor{};
- ASSERT_NO_THROW({ target = CreateUser(root_client, target_name, "target-secret", iggy::ffi::UserStatus::Active); });
- ASSERT_NO_THROW(
- { survivor = CreateUser(root_client, survivor_name, "survivor-secret", iggy::ffi::UserStatus::Active); });
+ auto root_client = GetLoggedInHighLevelClient();
+ auto survivor_client = GetLoggedOutHighLevelClient();
+ const std::string target_name = GetRandomName(50);
+ const std::string survivor_name = GetRandomName(50);
+ ASSERT_NO_THROW({
+ const auto target = CreateUser(root_client, target_name, "target-secret", iggy::UserStatus::Active);
+ const auto survivor = CreateUser(root_client, survivor_name, "survivor-secret", iggy::UserStatus::Active);
- ASSERT_NO_THROW(root_client->delete_user(make_numeric_identifier(target.id)));
- ForgetUser(target_name);
+ ASSERT_NO_THROW(root_client.DeleteUser(iggy::Identifier::Numeric(target.Id())));
+ ForgetUser(target_name);
- ASSERT_THROW(root_client->get_user(make_string_identifier(target_name)), std::exception);
- rust::Vec<iggy::ffi::UserInfo> users;
- ASSERT_NO_THROW({ users = root_client->get_users(); });
- for (const auto &user : users) {
- EXPECT_FALSE(user.id == target.id && static_cast<std::string>(user.username) == target_name);
- }
+ ASSERT_THROW(root_client.GetUser(iggy::Identifier::String(target_name)), std::exception);
+ const auto users = root_client.GetUsers();
+ for (const auto &user : users) {
+ EXPECT_FALSE(user.Id() == target.Id() && user.Username() == target_name);
+ }
- iggy::ffi::UserInfoDetails fetched_survivor{};
- ASSERT_NO_THROW({ fetched_survivor = root_client->get_user(make_string_identifier(survivor_name)); });
- EXPECT_EQ(fetched_survivor.id, survivor.id);
- EXPECT_EQ(static_cast<std::string>(fetched_survivor.username), survivor_name);
- EXPECT_EQ(fetched_survivor.status, survivor.status);
- ASSERT_NO_THROW(survivor_client->connect());
- ASSERT_NO_THROW(survivor_client->login_user(survivor_name, "survivor-secret"));
+ const auto fetched_survivor = root_client.GetUser(iggy::Identifier::String(survivor_name));
+ EXPECT_EQ(fetched_survivor.Id(), survivor.Id());
+ EXPECT_EQ(fetched_survivor.Username(), survivor_name);
+ EXPECT_EQ(fetched_survivor.Status(), survivor.Status());
+ });
+ ASSERT_NO_THROW(survivor_client.Connect());
+ ASSERT_NO_THROW(survivor_client.Login(survivor_name, "survivor-secret"));
}
TEST_F(LowLevelE2E_Client, DeleteInactiveUserSucceeds) {
@@ -1767,241 +1738,180 @@ TEST_F(LowLevelE2E_Client, DeleteWhileUnauthenticatedAfterFailedLogin) {
client = nullptr;
}
-TEST_F(LowLevelE2E_Client, ConnectLoginThenDisconnect) {
+TEST_F(E2E_Client, ConnectLoginThenDisconnect) {
RecordProperty("description",
"Connects, logs in, disconnects successfully, and rejects authenticated operations afterward.");
- iggy::ffi::Client *client = nullptr;
- ASSERT_NO_THROW({ client = iggy::ffi::new_connection({}); });
- ASSERT_NE(client, nullptr);
- TrackClient(client);
-
- ASSERT_NO_THROW(client->connect());
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->disconnect());
- ASSERT_THROW(client->get_me(), std::exception);
+ auto client = GetLoggedInHighLevelClient();
+ ASSERT_NO_THROW(client.Disconnect());
+ ASSERT_THROW(client.GetMe(), std::exception);
}
-TEST_F(LowLevelE2E_Client, DisconnectWithoutConnect) {
+TEST_F(E2E_Client, DisconnectWithoutConnect) {
RecordProperty("description", "Allows disconnect to be called on a client that was never explicitly connected.");
- iggy::ffi::Client *client = nullptr;
- ASSERT_NO_THROW({ client = iggy::ffi::new_connection({}); });
- ASSERT_NE(client, nullptr);
- TrackClient(client);
-
- ASSERT_NO_THROW(client->disconnect());
+ auto client = GetLoggedOutHighLevelClient();
+ ASSERT_NO_THROW(client.Disconnect());
}
-TEST_F(LowLevelE2E_Client, DisconnectWithoutLogin) {
+TEST_F(E2E_Client, DisconnectWithoutLogin) {
RecordProperty("description", "Allows disconnect after connect even when no user has authenticated.");
- iggy::ffi::Client *client = nullptr;
- ASSERT_NO_THROW({ client = iggy::ffi::new_connection({}); });
- ASSERT_NE(client, nullptr);
- TrackClient(client);
-
- ASSERT_NO_THROW(client->connect());
- ASSERT_NO_THROW(client->disconnect());
- ASSERT_THROW(client->get_stats(), std::exception);
+ auto client = GetLoggedOutHighLevelClient();
+ ASSERT_NO_THROW(client.Connect());
+ ASSERT_NO_THROW(client.Disconnect());
+ ASSERT_THROW(client.GetMe(), std::exception);
}
-TEST_F(LowLevelE2E_Client, DisconnectThenReconnectWithoutRelogin) {
+TEST_F(E2E_Client, DisconnectThenReconnectWithoutRelogin) {
RecordProperty("description",
"Requires logging in again after a disconnect and reconnect before authenticated operations work.");
- iggy::ffi::Client *client = nullptr;
- ASSERT_NO_THROW({ client = iggy::ffi::new_connection({}); });
- ASSERT_NE(client, nullptr);
- TrackClient(client);
-
- ASSERT_NO_THROW(client->connect());
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->disconnect());
- ASSERT_NO_THROW(client->connect());
- ASSERT_THROW(client->get_me(), std::exception);
+ auto client = GetLoggedInHighLevelClient();
+ ASSERT_NO_THROW(client.Disconnect());
+ ASSERT_NO_THROW(client.Connect());
+ ASSERT_THROW(client.GetMe(), std::exception);
}
-TEST_F(LowLevelE2E_Client, DisconnectAfterFailedLogin) {
+TEST_F(E2E_Client, DisconnectAfterFailedLogin) {
RecordProperty("description", "Allows disconnect after a failed login attempt leaves the client unauthenticated.");
- iggy::ffi::Client *client = nullptr;
- ASSERT_NO_THROW({ client = iggy::ffi::new_connection({}); });
- ASSERT_NE(client, nullptr);
- TrackClient(client);
-
- ASSERT_NO_THROW(client->connect());
- ASSERT_THROW(client->login_user("biggy", "biggy"), std::exception);
- ASSERT_NO_THROW(client->disconnect());
- ASSERT_THROW(client->get_me(), std::exception);
+ auto client = GetLoggedOutHighLevelClient();
+ ASSERT_NO_THROW(client.Connect());
+ ASSERT_THROW(client.Login("biggy", "biggy"), std::exception);
+ ASSERT_NO_THROW(client.Disconnect());
+ ASSERT_THROW(client.GetMe(), std::exception);
}
-TEST_F(LowLevelE2E_Client, ConnectLoginThenShutdown) {
+TEST_F(E2E_Client, ConnectLoginThenShutdown) {
RecordProperty("description",
"Connects, logs in, shuts down successfully, and rejects further operations afterward.");
- iggy::ffi::Client *client = nullptr;
- ASSERT_NO_THROW({ client = iggy::ffi::new_connection({}); });
- ASSERT_NE(client, nullptr);
- TrackClient(client);
-
- ASSERT_NO_THROW(client->connect());
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->ping());
- ASSERT_NO_THROW(client->shutdown());
- ASSERT_THROW(client->get_me(), std::exception);
- ASSERT_THROW(client->get_stats(), std::exception);
+ auto client = GetLoggedInHighLevelClient();
+ ASSERT_NO_THROW(client.GetMe());
+ ASSERT_NO_THROW(client.Shutdown());
+ ASSERT_THROW(client.GetMe(), std::exception);
+ ASSERT_THROW(client.GetClients(), std::exception);
}
-TEST_F(LowLevelE2E_Client, ShutdownWithoutConnect) {
+TEST_F(E2E_Client, ShutdownWithoutConnect) {
RecordProperty("description", "Allows shutdown to be called on a client that was never explicitly connected.");
- iggy::ffi::Client *client = nullptr;
- ASSERT_NO_THROW({ client = iggy::ffi::new_connection({}); });
- ASSERT_NE(client, nullptr);
- TrackClient(client);
-
- ASSERT_NO_THROW(client->shutdown());
+ auto client = GetLoggedOutHighLevelClient();
+ ASSERT_NO_THROW(client.Shutdown());
}
-TEST_F(LowLevelE2E_Client, ShutdownWithoutLogin) {
+TEST_F(E2E_Client, ShutdownWithoutLogin) {
RecordProperty("description", "Allows shutdown after connect even when no user has authenticated.");
- iggy::ffi::Client *client = nullptr;
- ASSERT_NO_THROW({ client = iggy::ffi::new_connection({}); });
- ASSERT_NE(client, nullptr);
- TrackClient(client);
-
- ASSERT_NO_THROW(client->connect());
- ASSERT_NO_THROW(client->shutdown());
- ASSERT_THROW(client->get_stats(), std::exception);
+ auto client = GetLoggedOutHighLevelClient();
+ ASSERT_NO_THROW(client.Connect());
+ ASSERT_NO_THROW(client.Shutdown());
+ ASSERT_THROW(client.GetMe(), std::exception);
}
-TEST_F(LowLevelE2E_Client, ShutdownAfterFailedLogin) {
+TEST_F(E2E_Client, ShutdownAfterFailedLogin) {
RecordProperty("description", "Allows shutdown after a failed login attempt leaves the client unauthenticated.");
- iggy::ffi::Client *client = nullptr;
- ASSERT_NO_THROW({ client = iggy::ffi::new_connection({}); });
- ASSERT_NE(client, nullptr);
- TrackClient(client);
-
- ASSERT_NO_THROW(client->connect());
- ASSERT_THROW(client->login_user("biggy", "biggy"), std::exception);
- ASSERT_NO_THROW(client->shutdown());
- ASSERT_THROW(client->get_me(), std::exception);
+ auto client = GetLoggedOutHighLevelClient();
+ ASSERT_NO_THROW(client.Connect());
+ ASSERT_THROW(client.Login("biggy", "biggy"), std::exception);
+ ASSERT_NO_THROW(client.Shutdown());
+ ASSERT_THROW(client.GetMe(), std::exception);
}
-TEST_F(LowLevelE2E_Client, RepeatedShutdownCallsHaveStableBehavior) {
+TEST_F(E2E_Client, RepeatedShutdownCallsHaveStableBehavior) {
RecordProperty("description", "Keeps repeated shutdown calls stable across duplicate invocations.");
- iggy::ffi::Client *client = nullptr;
- ASSERT_NO_THROW({ client = iggy::ffi::new_connection({}); });
- ASSERT_NE(client, nullptr);
- TrackClient(client);
-
- ASSERT_NO_THROW(client->connect());
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->shutdown());
- ASSERT_NO_THROW(client->shutdown());
- ASSERT_THROW(client->get_me(), std::exception);
+ auto client = GetLoggedInHighLevelClient();
+ ASSERT_NO_THROW(client.Shutdown());
+ ASSERT_NO_THROW(client.Shutdown());
+ ASSERT_THROW(client.GetMe(), std::exception);
}
-TEST_F(LowLevelE2E_Client, ShutdownThenConnectThrows) {
+TEST_F(E2E_Client, ShutdownThenConnectThrows) {
RecordProperty("description", "Rejects reconnecting a client after shutdown transitions it to a terminal state.");
- iggy::ffi::Client *client = nullptr;
- ASSERT_NO_THROW({ client = iggy::ffi::new_connection({}); });
- ASSERT_NE(client, nullptr);
- TrackClient(client);
-
- ASSERT_NO_THROW(client->connect());
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->shutdown());
- ASSERT_THROW(client->connect(), std::exception);
+ auto client = GetLoggedInHighLevelClient();
+ ASSERT_NO_THROW(client.Shutdown());
+ ASSERT_THROW(client.Connect(), std::exception);
}
-TEST_F(LowLevelE2E_Client, ShutdownThenLoginThrows) {
+TEST_F(E2E_Client, ShutdownThenLoginThrows) {
RecordProperty("description",
"Rejects logging in again after shutdown, even when login would normally auto-connect.");
- iggy::ffi::Client *client = nullptr;
- ASSERT_NO_THROW({ client = iggy::ffi::new_connection({}); });
- ASSERT_NE(client, nullptr);
- TrackClient(client);
-
- ASSERT_NO_THROW(client->shutdown());
- ASSERT_THROW(client->login_user("iggy", "iggy"), std::exception);
+ auto client = GetLoggedOutHighLevelClient();
+ ASSERT_NO_THROW(client.Shutdown());
+ ASSERT_THROW(client.Login("iggy", "iggy"), std::exception);
}
-TEST_F(LowLevelE2E_Client, GetClientsReflectsSessionRemovalAfterShutdown) {
+TEST_F(E2E_Client, GetClientsReflectsSessionRemovalAfterShutdown) {
RecordProperty("description",
- "Removes a shut down authenticated session from subsequent get_clients and get_client results.");
- iggy::ffi::Client *first_client = GetLoggedInClient();
- iggy::ffi::Client *second_client = GetLoggedInClient();
+ "Removes a shut down authenticated session from subsequent GetClients and GetClient results.");
+ auto first_client = GetLoggedInHighLevelClient();
+ auto second_client = GetLoggedInHighLevelClient();
- iggy::ffi::ClientInfoDetails first_me{};
- ASSERT_NO_THROW({ first_me = first_client->get_me(); });
+ const auto first_client_id = first_client.GetMe().ClientId();
- ASSERT_NO_THROW(first_client->shutdown());
+ ASSERT_NO_THROW(first_client.Shutdown());
constexpr auto removal_timeout = std::chrono::seconds(5);
constexpr auto removal_poll_interval = std::chrono::milliseconds(10);
const auto deadline = std::chrono::steady_clock::now() + removal_timeout;
bool removed = false;
do {
- const auto clients = second_client->get_clients();
+ const auto clients = second_client.GetClients();
removed = std::none_of(clients.begin(), clients.end(),
- [&first_me](const auto &client) { return client.client_id == first_me.client_id; });
+ [first_client_id](const auto &client) { return client.ClientId() == first_client_id; });
if (removed) {
break;
}
std::this_thread::sleep_for(removal_poll_interval);
} while (std::chrono::steady_clock::now() < deadline);
ASSERT_TRUE(removed);
- ASSERT_THROW(second_client->get_client(first_me.client_id), std::exception);
+ ASSERT_THROW(second_client.GetClient(first_client_id), iggy::IggyException);
}
-TEST_F(LowLevelE2E_Client, GetClientsReflectsSessionRemovalAfterDisconnect) {
+TEST_F(E2E_Client, GetClientsReflectsSessionRemovalAfterDisconnect) {
RecordProperty("description",
- "Removes a disconnected authenticated session from subsequent get_clients and get_client results.");
- iggy::ffi::Client *first_client = GetLoggedInClient();
- iggy::ffi::Client *second_client = GetLoggedInClient();
+ "Removes a disconnected authenticated session from subsequent GetClients and GetClient results.");
+ auto first_client = GetLoggedInHighLevelClient();
+ auto second_client = GetLoggedInHighLevelClient();
- iggy::ffi::ClientInfoDetails first_me{};
- ASSERT_NO_THROW({ first_me = first_client->get_me(); });
+ const auto first_client_id = first_client.GetMe().ClientId();
- ASSERT_NO_THROW(first_client->disconnect());
+ ASSERT_NO_THROW(first_client.Disconnect());
constexpr auto removal_timeout = std::chrono::seconds(5);
constexpr auto removal_poll_interval = std::chrono::milliseconds(10);
const auto deadline = std::chrono::steady_clock::now() + removal_timeout;
bool removed = false;
do {
- const auto clients = second_client->get_clients();
+ const auto clients = second_client.GetClients();
removed = std::none_of(clients.begin(), clients.end(),
- [&first_me](const auto &client) { return client.client_id == first_me.client_id; });
+ [first_client_id](const auto &client) { return client.ClientId() == first_client_id; });
if (removed) {
break;
}
std::this_thread::sleep_for(removal_poll_interval);
} while (std::chrono::steady_clock::now() < deadline);
ASSERT_TRUE(removed);
- ASSERT_THROW(second_client->get_client(first_me.client_id), std::exception);
+ ASSERT_THROW(second_client.GetClient(first_client_id), iggy::IggyException);
}
-TEST_F(LowLevelE2E_Client, GetClientsReflectsLoggedOutSessionAsUnauthenticated) {
- RecordProperty("description", "Drops a logged out session from get_clients and reports it missing in get_client.");
- iggy::ffi::Client *first_client = GetLoggedInClient();
- iggy::ffi::Client *second_client = GetLoggedInClient();
+TEST_F(E2E_Client, GetClientsReflectsLoggedOutSessionAsUnauthenticated) {
+ RecordProperty("description", "Drops a logged out session from GetClients and reports it missing in GetClient.");
+ auto first_client = GetLoggedInHighLevelClient();
+ auto second_client = GetLoggedInHighLevelClient();
- iggy::ffi::ClientInfoDetails first_me{};
- ASSERT_NO_THROW({ first_me = first_client->get_me(); });
+ const auto first_client_id = first_client.GetMe().ClientId();
// The VSR server drops the client-table entry on logout (an unauthenticated
// session is not tracked), unlike the legacy server which kept it visible
// without a user id.
- ASSERT_NO_THROW(first_client->logout_user());
+ ASSERT_NO_THROW(first_client.Logout());
constexpr auto removal_timeout = std::chrono::seconds(5);
constexpr auto removal_poll_interval = std::chrono::milliseconds(10);
const auto deadline = std::chrono::steady_clock::now() + removal_timeout;
bool removed = false;
do {
- const auto clients = second_client->get_clients();
+ const auto clients = second_client.GetClients();
removed = std::none_of(clients.begin(), clients.end(),
- [&first_me](const auto &client) { return client.client_id == first_me.client_id; });
+ [first_client_id](const auto &client) { return client.ClientId() == first_client_id; });
if (removed) {
break;
}
std::this_thread::sleep_for(removal_poll_interval);
} while (std::chrono::steady_clock::now() < deadline);
ASSERT_TRUE(removed);
- ASSERT_THROW(second_client->get_client(first_me.client_id), std::exception);
+ ASSERT_THROW(second_client.GetClient(first_client_id), iggy::IggyException);
}
TEST_F(LowLevelE2E_Client, LoginWithoutConnect) {
@@ -2074,170 +1984,157 @@ TEST_F(LowLevelE2E_Client, DeleteNullConnectionIsNoop) {
iggy::ffi::delete_client(client);
}
-TEST_F(LowLevelE2E_Client, GetStatsBeforeLoginThrows) {
+TEST_F(E2E_Client, GetStatsBeforeLoginThrows) {
RecordProperty("description",
- "Rejects get_stats before connect, after connect but before login, and after disconnect.");
- iggy::ffi::Client *client = GetLoggedOutClient();
+ "Rejects GetStats before connect, after connect but before login, and after disconnect.");
+ auto client = GetLoggedOutHighLevelClient();
- ASSERT_THROW(client->get_stats(), std::exception);
- ASSERT_NO_THROW(client->connect());
- ASSERT_THROW(client->get_stats(), std::exception);
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->disconnect());
- ASSERT_THROW(client->get_stats(), std::exception);
+ ASSERT_THROW((void)client.GetStats(), iggy::IggyException);
+ ASSERT_NO_THROW(client.Connect());
+ ASSERT_THROW((void)client.GetStats(), iggy::IggyException);
+ ASSERT_NO_THROW(client.Login("iggy", "iggy"));
+ ASSERT_NO_THROW(client.Disconnect());
+ ASSERT_THROW((void)client.GetStats(), iggy::IggyException);
}
-TEST_F(LowLevelE2E_Client, DeleteSegmentsBeforeLoginThrows) {
+TEST_F(E2E_Client, DeleteSegmentsBeforeLoginThrows) {
RecordProperty("description",
- "Rejects delete_segments before connect, after connect but before login, and after disconnect.");
- const std::string stream_name = GetRandomName();
- const std::string topic_name = GetRandomName();
- iggy::ffi::Client *setup_client = GetLoggedInClient();
+ "Rejects DeleteSegments before connect, after connect but before login, and after disconnect.");
+ const std::string stream_name = GetRandomName();
+ const std::string topic_name = GetRandomName();
+ auto setup_client = GetLoggedInHighLevelClient();
- ASSERT_NO_THROW(setup_client->create_stream(stream_name));
+ ASSERT_NO_THROW(setup_client.CreateStream(stream_name));
TrackStream(stream_name);
- ASSERT_NO_THROW(
- setup_client->create_topic(make_string_identifier(stream_name), topic_name,
- make_topic_create_options(1, "none", "never_expire", 0, "server_default")));
-
- iggy::ffi::Client *unauthenticated_client = GetLoggedOutClient();
- ASSERT_THROW(unauthenticated_client->delete_segments(make_string_identifier(stream_name),
- make_string_identifier(topic_name), 0, 1),
- std::exception);
- ASSERT_NO_THROW(unauthenticated_client->connect());
- ASSERT_THROW(unauthenticated_client->delete_segments(make_string_identifier(stream_name),
- make_string_identifier(topic_name), 0, 1),
- std::exception);
- ASSERT_NO_THROW(unauthenticated_client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(unauthenticated_client->disconnect());
- ASSERT_THROW(unauthenticated_client->delete_segments(make_string_identifier(stream_name),
- make_string_identifier(topic_name), 0, 1),
- std::exception);
-}
-
-TEST_F(LowLevelE2E_Client, DeleteSegmentsOnNonExistentStreamThrows) {
+ ASSERT_NO_THROW(setup_client.CreateTopic(iggy::Identifier::String(stream_name), topic_name,
+ iggy::TopicCreateOptions().SetPartitionsCount(1)));
+
+ auto unauthenticated_client = GetLoggedOutHighLevelClient();
+ ASSERT_THROW(unauthenticated_client.DeleteSegments(iggy::Identifier::String(stream_name),
+ iggy::Identifier::String(topic_name), 0, 1),
+ iggy::IggyException);
+ ASSERT_NO_THROW(unauthenticated_client.Connect());
+ ASSERT_THROW(unauthenticated_client.DeleteSegments(iggy::Identifier::String(stream_name),
+ iggy::Identifier::String(topic_name), 0, 1),
+ iggy::IggyException);
+ ASSERT_NO_THROW(unauthenticated_client.Login("iggy", "iggy"));
+ ASSERT_NO_THROW(unauthenticated_client.Disconnect());
+ ASSERT_THROW(unauthenticated_client.DeleteSegments(iggy::Identifier::String(stream_name),
+ iggy::Identifier::String(topic_name), 0, 1),
+ iggy::IggyException);
+}
+
+TEST_F(E2E_Client, DeleteSegmentsOnNonExistentStreamThrows) {
RecordProperty("description", "Throws when deleting segments from a stream that does not exist.");
const std::string stream_name = GetRandomName();
const std::string topic_name = GetRandomName();
const std::string missing_stream_name = GetRandomName();
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
- ASSERT_NO_THROW(client->create_stream(stream_name));
+ ASSERT_NO_THROW(client.CreateStream(stream_name));
TrackStream(stream_name);
- ASSERT_NO_THROW(client->create_topic(make_string_identifier(stream_name), topic_name,
- make_topic_create_options(1, "none", "never_expire", 0, "server_default")));
+ ASSERT_NO_THROW(client.CreateTopic(iggy::Identifier::String(stream_name), topic_name,
+ iggy::TopicCreateOptions().SetPartitionsCount(1)));
- ASSERT_THROW(
- client->delete_segments(make_string_identifier(missing_stream_name), make_string_identifier(topic_name), 0, 1),
- std::exception);
+ ASSERT_THROW(client.DeleteSegments(iggy::Identifier::String(missing_stream_name),
+ iggy::Identifier::String(topic_name), 0, 1),
+ iggy::IggyException);
}
-TEST_F(LowLevelE2E_Client, DeleteSegmentsOnNonExistentTopicThrows) {
+TEST_F(E2E_Client, DeleteSegmentsOnNonExistentTopicThrows) {
RecordProperty("description", "Throws when deleting segments from a topic that does not exist.");
const std::string stream_name = GetRandomName();
const std::string topic_name = GetRandomName();
const std::string missing_topic_name = GetRandomName();
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
- ASSERT_NO_THROW(client->create_stream(stream_name));
+ ASSERT_NO_THROW(client.CreateStream(stream_name));
TrackStream(stream_name);
- ASSERT_NO_THROW(client->create_topic(make_string_identifier(stream_name), topic_name,
- make_topic_create_options(1, "none", "never_expire", 0, "server_default")));
+ ASSERT_NO_THROW(client.CreateTopic(iggy::Identifier::String(stream_name), topic_name,
+ iggy::TopicCreateOptions().SetPartitionsCount(1)));
- ASSERT_THROW(
- client->delete_segments(make_string_identifier(stream_name), make_string_identifier(missing_topic_name), 0, 1),
- std::exception);
+ ASSERT_THROW(client.DeleteSegments(iggy::Identifier::String(stream_name),
+ iggy::Identifier::String(missing_topic_name), 0, 1),
+ iggy::IggyException);
}
-TEST_F(LowLevelE2E_Client, DeleteSegmentsOnNonExistentPartitionThrows) {
+TEST_F(E2E_Client, DeleteSegmentsOnNonExistentPartitionThrows) {
RecordProperty("description", "Throws when deleting segments from a partition that does not exist.");
const std::string stream_name = GetRandomName();
const std::string topic_name = GetRandomName();
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
- ASSERT_NO_THROW(client->create_stream(stream_name));
+ ASSERT_NO_THROW(client.CreateStream(stream_name));
TrackStream(stream_name);
- ASSERT_NO_THROW(client->create_topic(make_string_identifier(stream_name), topic_name,
- make_topic_create_options(1, "none", "never_expire", 0, "server_default")));
+ ASSERT_NO_THROW(client.CreateTopic(iggy::Identifier::String(stream_name), topic_name,
+ iggy::TopicCreateOptions().SetPartitionsCount(1)));
ASSERT_THROW(
- client->delete_segments(make_string_identifier(stream_name), make_string_identifier(topic_name), 999, 1),
- std::exception);
+ client.DeleteSegments(iggy::Identifier::String(stream_name), iggy::Identifier::String(topic_name), 999, 1),
+ iggy::IggyException);
}
-TEST_F(LowLevelE2E_Client, DeleteSegmentsWithZeroCountIsNoOp) {
- RecordProperty("description", "Treats delete_segments with count 0 as a no-op.");
+TEST_F(E2E_Client, DeleteSegmentsWithZeroCountIsNoOp) {
+ RecordProperty("description", "Treats DeleteSegments with count 0 as a no-op.");
const std::string stream_name = GetRandomName();
const std::string topic_name = GetRandomName();
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
- ASSERT_NO_THROW(client->create_stream(stream_name));
+ ASSERT_NO_THROW(client.CreateStream(stream_name));
TrackStream(stream_name);
- ASSERT_NO_THROW(client->create_topic(make_string_identifier(stream_name), topic_name,
- make_topic_create_options(1, "none", "never_expire", 0, "server_default")));
+ ASSERT_NO_THROW(client.CreateTopic(iggy::Identifier::String(stream_name), topic_name,
+ iggy::TopicCreateOptions().SetPartitionsCount(1)));
- std::uint32_t stream_id = 0;
- std::uint32_t topic_id = 0;
- ASSERT_NO_THROW({
- const auto stream_details = client->get_stream(make_string_identifier(stream_name));
- ASSERT_EQ(stream_details.topics.size(), 1u);
- stream_id = stream_details.id;
- topic_id = stream_details.topics.front().id;
- });
+ const auto stream_details = client.GetStream(iggy::Identifier::String(stream_name));
+ ASSERT_EQ(stream_details.Topics().size(), 1u);
+ const std::uint32_t stream_id = stream_details.Id();
+ const std::uint32_t topic_id = stream_details.Topics().front().Id();
+ iggy::ffi::Client *sender = GetLoggedInClient();
rust::Vec<iggy::ffi::IggyMessageToSend> messages;
for (std::uint32_t i = 0; i < 5; ++i) {
messages.push_back(iggy::ffi::make_message(to_payload("zero-count-" + std::to_string(i)),
rust::Vec<iggy::ffi::HeaderEntry>()));
}
- ASSERT_NO_THROW(client->send_messages(make_numeric_identifier(stream_id), make_numeric_identifier(topic_id),
+ ASSERT_NO_THROW(sender->send_messages(make_numeric_identifier(stream_id), make_numeric_identifier(topic_id),
"partition_id", partition_id_bytes(0), std::move(messages)));
- iggy::ffi::Partition partition_before_delete{};
- ASSERT_NO_THROW({
+ const auto find_partition = [&client, stream_id, topic_id](std::uint32_t partition_id) {
const auto topic_details =
- client->get_topic(make_numeric_identifier(stream_id), make_numeric_identifier(topic_id));
- for (const auto &partition : topic_details.partitions) {
- if (partition.id == 0) {
- partition_before_delete = partition;
- break;
+ client.GetTopic(iggy::Identifier::Numeric(stream_id), iggy::Identifier::Numeric(topic_id));
+ for (const auto &partition : topic_details.Partitions()) {
+ if (partition.Id() == partition_id) {
+ return partition;
}
}
- });
+ throw iggy::IggyException("Partition was not found");
+ };
+
+ const auto partition_before_delete = find_partition(0);
iggy::ffi::PolledMessages polled_before_delete{};
ASSERT_NO_THROW({
polled_before_delete =
- client->poll_messages(make_numeric_identifier(stream_id), make_numeric_identifier(topic_id), 0, "consumer",
+ sender->poll_messages(make_numeric_identifier(stream_id), make_numeric_identifier(topic_id), 0, "consumer",
make_numeric_identifier(1005), "offset", 0, 1000, false);
});
ASSERT_NO_THROW(
- client->delete_segments(make_string_identifier(stream_name), make_string_identifier(topic_name), 0, 0));
+ client.DeleteSegments(iggy::Identifier::String(stream_name), iggy::Identifier::String(topic_name), 0, 0));
- iggy::ffi::Partition partition_after_delete{};
- ASSERT_NO_THROW({
- const auto topic_details =
- client->get_topic(make_numeric_identifier(stream_id), make_numeric_identifier(topic_id));
- for (const auto &partition : topic_details.partitions) {
- if (partition.id == 0) {
- partition_after_delete = partition;
- break;
- }
- }
- });
+ const auto partition_after_delete = find_partition(0);
iggy::ffi::PolledMessages polled_after_delete{};
ASSERT_NO_THROW({
polled_after_delete =
- client->poll_messages(make_numeric_identifier(stream_id), make_numeric_identifier(topic_id), 0, "consumer",
+ sender->poll_messages(make_numeric_identifier(stream_id), make_numeric_identifier(topic_id), 0, "consumer",
make_numeric_identifier(1006), "offset", 0, 1000, false);
});
- EXPECT_EQ(partition_after_delete.segments_count, partition_before_delete.segments_count);
- EXPECT_EQ(partition_after_delete.current_offset, partition_before_delete.current_offset);
- EXPECT_EQ(partition_after_delete.messages_count, partition_before_delete.messages_count);
- EXPECT_EQ(partition_after_delete.size_bytes, partition_before_delete.size_bytes);
+ EXPECT_EQ(partition_after_delete.SegmentsCount(), partition_before_delete.SegmentsCount());
+ EXPECT_EQ(partition_after_delete.CurrentOffset(), partition_before_delete.CurrentOffset());
+ EXPECT_EQ(partition_after_delete.MessagesCount(), partition_before_delete.MessagesCount());
+ EXPECT_EQ(partition_after_delete.SizeBytes(), partition_before_delete.SizeBytes());
EXPECT_EQ(polled_after_delete.count, polled_before_delete.count);
ASSERT_EQ(polled_after_delete.messages.size(), polled_before_delete.messages.size());
for (std::size_t i = 0; i < polled_before_delete.messages.size(); ++i) {
@@ -2245,81 +2142,69 @@ TEST_F(LowLevelE2E_Client, DeleteSegmentsWithZeroCountIsNoOp) {
}
}
-TEST_F(LowLevelE2E_Client, DeleteSegmentsWhenOnlyActiveSegmentRemainsIsNoOp) {
+TEST_F(E2E_Client, DeleteSegmentsWhenOnlyActiveSegmentRemainsIsNoOp) {
RecordProperty("description",
- "Keeps the partition unchanged when delete_segments is called with only the active segment.");
+ "Keeps the partition unchanged when DeleteSegments is called with only the active segment.");
const std::string stream_name = GetRandomName();
const std::string topic_name = GetRandomName();
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
- ASSERT_NO_THROW(client->create_stream(stream_name));
+ ASSERT_NO_THROW(client.CreateStream(stream_name));
TrackStream(stream_name);
- ASSERT_NO_THROW(client->create_topic(make_string_identifier(stream_name), topic_name,
- make_topic_create_options(1, "none", "never_expire", 0, "server_default")));
+ ASSERT_NO_THROW(client.CreateTopic(iggy::Identifier::String(stream_name), topic_name,
+ iggy::TopicCreateOptions().SetPartitionsCount(1)));
- std::uint32_t stream_id = 0;
- std::uint32_t topic_id = 0;
- ASSERT_NO_THROW({
- const auto stream_details = client->get_stream(make_string_identifier(stream_name));
- ASSERT_EQ(stream_details.topics.size(), 1u);
- stream_id = stream_details.id;
- topic_id = stream_details.topics.front().id;
- });
+ const auto stream_details = client.GetStream(iggy::Identifier::String(stream_name));
+ ASSERT_EQ(stream_details.Topics().size(), 1u);
+ const std::uint32_t stream_id = stream_details.Id();
+ const std::uint32_t topic_id = stream_details.Topics().front().Id();
+ iggy::ffi::Client *sender = GetLoggedInClient();
rust::Vec<iggy::ffi::IggyMessageToSend> messages;
for (std::uint32_t i = 0; i < 5; ++i) {
messages.push_back(iggy::ffi::make_message(to_payload("active-only-" + std::to_string(i)),
rust::Vec<iggy::ffi::HeaderEntry>()));
}
- ASSERT_NO_THROW(client->send_messages(make_numeric_identifier(stream_id), make_numeric_identifier(topic_id),
+ ASSERT_NO_THROW(sender->send_messages(make_numeric_identifier(stream_id), make_numeric_identifier(topic_id),
"partition_id", partition_id_bytes(0), std::move(messages)));
- iggy::ffi::Partition partition_before_delete{};
- ASSERT_NO_THROW({
+ const auto find_partition = [&client, stream_id, topic_id](std::uint32_t partition_id) {
const auto topic_details =
- client->get_topic(make_numeric_identifier(stream_id), make_numeric_identifier(topic_id));
- for (const auto &partition : topic_details.partitions) {
- if (partition.id == 0) {
- partition_before_delete = partition;
- break;
+ client.GetTopic(iggy::Identifier::Numeric(stream_id), iggy::Identifier::Numeric(topic_id));
+ for (const auto &partition : topic_details.Partitions()) {
+ if (partition.Id() == partition_id) {
+ return partition;
}
}
- });
- ASSERT_EQ(partition_before_delete.segments_count, 1u);
+ throw iggy::IggyException("Partition was not found");
+ };
+
+ const auto partition_before_delete = find_partition(0);
+ ASSERT_EQ(partition_before_delete.SegmentsCount(), 1u);
iggy::ffi::PolledMessages polled_before_delete{};
ASSERT_NO_THROW({
polled_before_delete =
- client->poll_messages(make_numeric_identifier(stream_id), make_numeric_identifier(topic_id), 0, "consumer",
+ sender->poll_messages(make_numeric_identifier(stream_id), make_numeric_identifier(topic_id), 0, "consumer",
make_numeric_identifier(1007), "offset", 0, 1000, false);
});
ASSERT_NO_THROW(
- client->delete_segments(make_string_identifier(stream_name), make_string_identifier(topic_name), 0, 1));
+ client.DeleteSegments(iggy::Identifier::String(stream_name), iggy::Identifier::String(topic_name), 0, 1));
- iggy::ffi::Partition partition_after_delete{};
- ASSERT_NO_THROW({
- const auto topic_details =
- client->get_topic(make_numeric_identifier(stream_id), make_numeric_identifier(topic_id));
- for (const auto &partition : topic_details.partitions) {
- if (partition.id == 0) {
- partition_after_delete = partition;
- break;
- }
- }
- });
+ const auto partition_after_delete = find_partition(0);
iggy::ffi::PolledMessages polled_after_delete{};
ASSERT_NO_THROW({
polled_after_delete =
- client->poll_messages(make_numeric_identifier(stream_id), make_numeric_identifier(topic_id), 0, "consumer",
+ sender->poll_messages(make_numeric_identifier(stream_id), make_numeric_identifier(topic_id), 0, "consumer",
make_numeric_identifier(1008), "offset", 0, 1000, false);
});
- EXPECT_EQ(partition_after_delete.segments_count, partition_before_delete.segments_count);
- EXPECT_EQ(partition_after_delete.current_offset, partition_before_delete.current_offset);
- EXPECT_EQ(partition_after_delete.messages_count, partition_before_delete.messages_count);
- EXPECT_EQ(partition_after_delete.size_bytes, partition_before_delete.size_bytes);
+ EXPECT_EQ(partition_after_delete.SegmentsCount(), partition_before_delete.SegmentsCount());
+ EXPECT_EQ(partition_after_delete.CurrentOffset(), partition_before_delete.CurrentOffset());
+ EXPECT_EQ(partition_after_delete.MessagesCount(), partition_before_delete.MessagesCount());
+ EXPECT_EQ(partition_after_delete.SizeBytes(), partition_before_delete.SizeBytes());
EXPECT_EQ(polled_after_delete.count, polled_before_delete.count);
ASSERT_EQ(polled_after_delete.messages.size(), polled_before_delete.messages.size());
for (std::size_t i = 0; i < polled_before_delete.messages.size(); ++i) {
@@ -2329,7 +2214,7 @@ TEST_F(LowLevelE2E_Client, DeleteSegmentsWhenOnlyActiveSegmentRemainsIsNoOp) {
// TODO(slbotbm): add a test to create some streams, topics, partitions, and segments, send messages, and create
// consumer groups and verify it.
-TEST_F(LowLevelE2E_Client, GetStatsReturnsServerStats) {
+TEST_F(E2E_Client, GetStatsReturnsServerStats) {
RecordProperty("description",
"Returns empty resource counts first, then reflects aggregated streams, topics, partitions, "
"consumer groups, and clients.");
@@ -2342,461 +2227,398 @@ TEST_F(LowLevelE2E_Client, GetStatsReturnsServerStats) {
const std::string second_group_name = GetRandomName();
const std::string third_group_name = GetRandomName();
constexpr std::uint32_t additional_partitions_count = 2;
- iggy::ffi::Client *client = GetLoggedInClient();
-
- iggy::ffi::Client *second_client = nullptr;
- iggy::ffi::Client *third_client = nullptr;
-
- iggy::ffi::Stats empty_stats{};
- iggy::ffi::Stats stats_after_create{};
- ASSERT_NO_THROW({
- empty_stats = client->get_stats();
- EXPECT_NE(empty_stats.process_id, 0u);
- EXPECT_GT(empty_stats.threads_count, 0u);
- EXPECT_GT(empty_stats.total_memory, 0u);
- EXPECT_LE(empty_stats.available_memory, empty_stats.total_memory);
- EXPECT_GE(empty_stats.total_disk_space, empty_stats.free_disk_space);
- EXPECT_FALSE(static_cast<std::string>(empty_stats.hostname).empty());
- EXPECT_FALSE(static_cast<std::string>(empty_stats.os_name).empty());
- EXPECT_FALSE(static_cast<std::string>(empty_stats.os_version).empty());
- EXPECT_FALSE(static_cast<std::string>(empty_stats.kernel_version).empty());
- EXPECT_FALSE(static_cast<std::string>(empty_stats.iggy_server_version).empty());
- });
-
- ASSERT_NO_THROW(client->create_stream(first_stream_name));
+ auto client = GetLoggedInHighLevelClient();
+
+ const auto empty_stats = client.GetStats();
+ EXPECT_NE(empty_stats.ProcessId(), 0u);
+ EXPECT_GT(empty_stats.ThreadsCount(), 0u);
+ EXPECT_GT(empty_stats.TotalMemory(), 0u);
+ EXPECT_LE(empty_stats.AvailableMemory(), empty_stats.TotalMemory());
+ EXPECT_GE(empty_stats.TotalDiskSpace(), empty_stats.FreeDiskSpace());
+ EXPECT_FALSE(empty_stats.Hostname().empty());
+ EXPECT_FALSE(empty_stats.OsName().empty());
+ EXPECT_FALSE(empty_stats.OsVersion().empty());
+ EXPECT_FALSE(empty_stats.KernelVersion().empty());
+ EXPECT_FALSE(empty_stats.IggyServerVersion().empty());
+
+ ASSERT_NO_THROW(client.CreateStream(first_stream_name));
TrackStream(first_stream_name);
- ASSERT_NO_THROW(client->create_stream(second_stream_name));
+ ASSERT_NO_THROW(client.CreateStream(second_stream_name));
TrackStream(second_stream_name);
- ASSERT_NO_THROW(client->create_topic(make_string_identifier(first_stream_name), first_topic_name,
- make_topic_create_options(1, "none", "server_default", 0, "server_default")));
- ASSERT_NO_THROW(client->create_topic(make_string_identifier(first_stream_name), second_topic_name,
- make_topic_create_options(2, "none", "server_default", 0, "server_default")));
- ASSERT_NO_THROW(client->create_topic(make_string_identifier(second_stream_name), third_topic_name,
- make_topic_create_options(3, "none", "server_default", 0, "server_default")));
- ASSERT_NO_THROW(client->create_partitions(make_string_identifier(first_stream_name),
- make_string_identifier(first_topic_name), additional_partitions_count));
- const auto first_group = client->create_consumer_group(make_string_identifier(first_stream_name),
- make_string_identifier(first_topic_name), first_group_name);
- const auto second_group = client->create_consumer_group(
- make_string_identifier(first_stream_name), make_string_identifier(second_topic_name), second_group_name);
- const auto third_group = client->create_consumer_group(make_string_identifier(second_stream_name),
- make_string_identifier(third_topic_name), third_group_name);
-
- ASSERT_NO_THROW({ second_client = GetLoggedInClient(); });
- ASSERT_NE(second_client, nullptr);
- ASSERT_NO_THROW({ third_client = GetLoggedInClient(); });
- ASSERT_NE(third_client, nullptr);
-
- const auto first_stream_details = client->get_stream(make_string_identifier(first_stream_name));
- const auto second_stream_details = client->get_stream(make_string_identifier(second_stream_name));
- const std::uint32_t expected_topics_count = first_stream_details.topics_count + second_stream_details.topics_count;
- std::uint32_t first_topic_partitions = 0;
- std::uint32_t second_topic_partitions = 0;
- std::uint32_t third_topic_partitions = 0;
- for (const auto &topic : first_stream_details.topics) {
- if (topic.name == first_topic_name) {
- first_topic_partitions = topic.partitions_count;
+ ASSERT_NO_THROW(client.CreateTopic(iggy::Identifier::String(first_stream_name), first_topic_name,
+ iggy::TopicCreateOptions().SetPartitionsCount(1)));
+ ASSERT_NO_THROW(client.CreateTopic(iggy::Identifier::String(first_stream_name), second_topic_name,
+ iggy::TopicCreateOptions().SetPartitionsCount(2)));
+ ASSERT_NO_THROW(client.CreateTopic(iggy::Identifier::String(second_stream_name), third_topic_name,
+ iggy::TopicCreateOptions().SetPartitionsCount(3)));
+ ASSERT_NO_THROW(client.CreatePartitions(iggy::Identifier::String(first_stream_name),
+ iggy::Identifier::String(first_topic_name), additional_partitions_count));
+ const auto first_group = client.CreateConsumerGroup(iggy::Identifier::String(first_stream_name),
+ iggy::Identifier::String(first_topic_name), first_group_name);
+ const auto second_group = client.CreateConsumerGroup(
+ iggy::Identifier::String(first_stream_name), iggy::Identifier::String(second_topic_name), second_group_name);
+ const auto third_group = client.CreateConsumerGroup(iggy::Identifier::String(second_stream_name),
+ iggy::Identifier::String(third_topic_name), third_group_name);
+
+ auto second_client = GetLoggedInHighLevelClient();
+ auto third_client = GetLoggedInHighLevelClient();
+ (void)second_client;
+ (void)third_client;
+
+ const auto first_stream_details = client.GetStream(iggy::Identifier::String(first_stream_name));
+ const auto second_stream_details = client.GetStream(iggy::Identifier::String(second_stream_name));
+ const std::uint32_t expected_topics_count =
+ first_stream_details.TopicsCount() + second_stream_details.TopicsCount();
+ std::uint32_t first_topic_partitions = 0;
+ std::uint32_t second_topic_partitions = 0;
+ std::uint32_t third_topic_partitions = 0;
+ for (const auto &topic : first_stream_details.Topics()) {
+ if (topic.Name() == first_topic_name) {
+ first_topic_partitions = topic.PartitionsCount();
}
- if (topic.name == second_topic_name) {
- second_topic_partitions = topic.partitions_count;
+ if (topic.Name() == second_topic_name) {
+ second_topic_partitions = topic.PartitionsCount();
}
}
- for (const auto &topic : second_stream_details.topics) {
- if (topic.name == third_topic_name) {
- third_topic_partitions = topic.partitions_count;
+ for (const auto &topic : second_stream_details.Topics()) {
+ if (topic.Name() == third_topic_name) {
+ third_topic_partitions = topic.PartitionsCount();
}
}
const std::uint32_t expected_partitions_count =
first_topic_partitions + second_topic_partitions + third_topic_partitions;
- ASSERT_NO_THROW({
- stats_after_create = client->get_stats();
- EXPECT_GE(stats_after_create.streams_count, empty_stats.streams_count + 2u);
- EXPECT_GE(stats_after_create.topics_count, empty_stats.topics_count + expected_topics_count);
- EXPECT_GE(stats_after_create.partitions_count, empty_stats.partitions_count + expected_partitions_count);
- EXPECT_GE(stats_after_create.segments_count, empty_stats.segments_count + expected_partitions_count);
- EXPECT_GE(stats_after_create.consumer_groups_count, empty_stats.consumer_groups_count + 3u);
- EXPECT_GE(stats_after_create.clients_count, empty_stats.clients_count + 2u);
- EXPECT_EQ(first_group.partitions_count, first_topic_partitions);
- EXPECT_EQ(second_group.partitions_count, second_topic_partitions);
- EXPECT_EQ(third_group.partitions_count, third_topic_partitions);
- });
-
- ASSERT_NO_THROW(client->delete_stream(make_string_identifier(second_stream_name)));
+ const auto stats_after_create = client.GetStats();
+ EXPECT_GE(stats_after_create.StreamsCount(), empty_stats.StreamsCount() + 2u);
+ EXPECT_GE(stats_after_create.TopicsCount(), empty_stats.TopicsCount() + expected_topics_count);
+ EXPECT_GE(stats_after_create.PartitionsCount(), empty_stats.PartitionsCount() + expected_partitions_count);
+ EXPECT_GE(stats_after_create.SegmentsCount(), empty_stats.SegmentsCount() + expected_partitions_count);
+ EXPECT_GE(stats_after_create.ConsumerGroupsCount(), empty_stats.ConsumerGroupsCount() + 3u);
+ EXPECT_GE(stats_after_create.ClientsCount(), empty_stats.ClientsCount() + 2u);
+ EXPECT_EQ(first_group.PartitionsCount(), first_topic_partitions);
+ EXPECT_EQ(second_group.PartitionsCount(), second_topic_partitions);
+ EXPECT_EQ(third_group.PartitionsCount(), third_topic_partitions);
+
+ ASSERT_NO_THROW(client.DeleteStream(iggy::Identifier::String(second_stream_name)));
ForgetTrackedStream(second_stream_name);
- ASSERT_NO_THROW(client->delete_stream(make_string_identifier(first_stream_name)));
+ ASSERT_NO_THROW(client.DeleteStream(iggy::Identifier::String(first_stream_name)));
ForgetTrackedStream(first_stream_name);
- DeleteClient(third_client);
- DeleteClient(second_client);
- ASSERT_NO_THROW({
- const auto stats = client->get_stats();
- EXPECT_LE(stats.streams_count, stats_after_create.streams_count);
- EXPECT_LE(stats.topics_count, stats_after_create.topics_count);
- EXPECT_LE(stats.partitions_count, stats_after_create.partitions_count);
- EXPECT_LE(stats.segments_count, stats_after_create.segments_count);
- EXPECT_LE(stats.consumer_groups_count, stats_after_create.consumer_groups_count);
- EXPECT_LE(stats.clients_count, stats_after_create.clients_count);
- });
+ const auto stats = client.GetStats();
+ EXPECT_LE(stats.StreamsCount(), stats_after_create.StreamsCount());
+ EXPECT_LE(stats.TopicsCount(), stats_after_create.TopicsCount());
+ EXPECT_LE(stats.PartitionsCount(), stats_after_create.PartitionsCount());
+ EXPECT_LE(stats.SegmentsCount(), stats_after_create.SegmentsCount());
+ EXPECT_LE(stats.ConsumerGroupsCount(), stats_after_create.ConsumerGroupsCount());
+ EXPECT_LE(stats.ClientsCount(), stats_after_create.ClientsCount());
}
-TEST_F(LowLevelE2E_Client, GetStatsIsStableAcrossBackToBackCalls) {
- RecordProperty(
- "description",
- "Returns sane invariant fields across back-to-back get_stats calls on an idle authenticated client.");
- iggy::ffi::Client *client = GetLoggedInClient();
-
- iggy::ffi::Stats first_stats{};
- iggy::ffi::Stats second_stats{};
- ASSERT_NO_THROW({
- first_stats = client->get_stats();
- second_stats = client->get_stats();
- });
-
- EXPECT_NE(first_stats.process_id, 0u);
- EXPECT_NE(second_stats.process_id, 0u);
- EXPECT_EQ(second_stats.process_id, first_stats.process_id);
- EXPECT_GT(first_stats.threads_count, 0u);
- EXPECT_GT(second_stats.threads_count, 0u);
- EXPECT_GT(first_stats.total_memory, 0u);
- EXPECT_GT(second_stats.total_memory, 0u);
- EXPECT_FALSE(static_cast<std::string>(first_stats.hostname).empty());
- EXPECT_FALSE(static_cast<std::string>(second_stats.hostname).empty());
- EXPECT_FALSE(static_cast<std::string>(first_stats.os_name).empty());
- EXPECT_FALSE(static_cast<std::string>(second_stats.os_name).empty());
- EXPECT_FALSE(static_cast<std::string>(first_stats.os_version).empty());
- EXPECT_FALSE(static_cast<std::string>(second_stats.os_version).empty());
- EXPECT_FALSE(static_cast<std::string>(first_stats.kernel_version).empty());
- EXPECT_FALSE(static_cast<std::string>(second_stats.kernel_version).empty());
- EXPECT_FALSE(static_cast<std::string>(first_stats.iggy_server_version).empty());
- EXPECT_FALSE(static_cast<std::string>(second_stats.iggy_server_version).empty());
- EXPECT_EQ(static_cast<std::string>(second_stats.hostname), static_cast<std::string>(first_stats.hostname));
- EXPECT_EQ(static_cast<std::string>(second_stats.os_name), static_cast<std::string>(first_stats.os_name));
- EXPECT_EQ(static_cast<std::string>(second_stats.os_version), static_cast<std::string>(first_stats.os_version));
- EXPECT_EQ(static_cast<std::string>(second_stats.kernel_version),
- static_cast<std::string>(first_stats.kernel_version));
- EXPECT_EQ(static_cast<std::string>(second_stats.iggy_server_version),
- static_cast<std::string>(first_stats.iggy_server_version));
- EXPECT_EQ(second_stats.has_server_semver, first_stats.has_server_semver);
- EXPECT_EQ(second_stats.iggy_server_semver, first_stats.iggy_server_semver);
- EXPECT_GE(first_stats.clients_count, 1u);
- EXPECT_GE(second_stats.clients_count, 1u);
-}
-
-TEST_F(LowLevelE2E_Client, GetMeBeforeLoginThrows) {
+TEST_F(E2E_Client, GetStatsIsStableAcrossBackToBackCalls) {
RecordProperty("description",
- "Rejects get_me before connect, after connect but before login, and after disconnect.");
- iggy::ffi::Client *client = GetLoggedOutClient();
+ "Returns sane invariant fields across back-to-back GetStats calls on an idle authenticated client.");
+ auto client = GetLoggedInHighLevelClient();
+
+ const auto first_stats = client.GetStats();
+ const auto second_stats = client.GetStats();
+
+ EXPECT_NE(first_stats.ProcessId(), 0u);
+ EXPECT_NE(second_stats.ProcessId(), 0u);
+ EXPECT_EQ(second_stats.ProcessId(), first_stats.ProcessId());
+ EXPECT_GT(first_stats.ThreadsCount(), 0u);
+ EXPECT_GT(second_stats.ThreadsCount(), 0u);
+ EXPECT_GT(first_stats.TotalMemory(), 0u);
+ EXPECT_GT(second_stats.TotalMemory(), 0u);
+ EXPECT_FALSE(first_stats.Hostname().empty());
+ EXPECT_FALSE(second_stats.Hostname().empty());
+ EXPECT_FALSE(first_stats.OsName().empty());
+ EXPECT_FALSE(second_stats.OsName().empty());
+ EXPECT_FALSE(first_stats.OsVersion().empty());
+ EXPECT_FALSE(second_stats.OsVersion().empty());
+ EXPECT_FALSE(first_stats.KernelVersion().empty());
+ EXPECT_FALSE(second_stats.KernelVersion().empty());
+ EXPECT_FALSE(first_stats.IggyServerVersion().empty());
+ EXPECT_FALSE(second_stats.IggyServerVersion().empty());
+ EXPECT_EQ(second_stats.Hostname(), first_stats.Hostname());
+ EXPECT_EQ(second_stats.OsName(), first_stats.OsName());
+ EXPECT_EQ(second_stats.OsVersion(), first_stats.OsVersion());
+ EXPECT_EQ(second_stats.KernelVersion(), first_stats.KernelVersion());
+ EXPECT_EQ(second_stats.IggyServerVersion(), first_stats.IggyServerVersion());
+ EXPECT_EQ(second_stats.ServerSemver(), first_stats.ServerSemver());
+ EXPECT_GE(first_stats.ClientsCount(), 1u);
+ EXPECT_GE(second_stats.ClientsCount(), 1u);
+}
+
+TEST_F(E2E_Client, GetMeBeforeLoginThrows) {
+ RecordProperty("description",
+ "Rejects GetMe before connect, after connect but before login, and after disconnect.");
+ auto client = GetLoggedOutHighLevelClient();
- ASSERT_THROW(client->get_me(), std::exception);
- ASSERT_NO_THROW(client->connect());
- ASSERT_THROW(client->get_me(), std::exception);
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->disconnect());
- ASSERT_THROW(client->get_me(), std::exception);
+ ASSERT_THROW(client.GetMe(), iggy::IggyException);
+ ASSERT_NO_THROW(client.Connect());
+ ASSERT_THROW(client.GetMe(), iggy::IggyException);
+ ASSERT_NO_THROW(client.Login("iggy", "iggy"));
+ ASSERT_NO_THROW(client.Disconnect());
+ ASSERT_THROW(client.GetMe(), iggy::IggyException);
}
-TEST_F(LowLevelE2E_Client, GetMeReturnsCurrentClientDetails) {
+TEST_F(E2E_Client, GetMeReturnsCurrentClientDetails) {
RecordProperty("description", "Returns the current authenticated client details.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
- ASSERT_NO_THROW({
- const auto me = client->get_me();
- EXPECT_NE(me.client_id, 0u);
- EXPECT_TRUE(me.has_user_id);
- EXPECT_FALSE(static_cast<std::string>(me.address).empty());
- EXPECT_EQ(static_cast<std::string>(me.transport), "TCP");
- EXPECT_EQ(me.consumer_groups_count, 0u);
- EXPECT_TRUE(me.consumer_groups.empty());
- });
+ const auto me = client.GetMe();
+ EXPECT_NE(me.ClientId(), 0u);
+ EXPECT_TRUE(me.UserId().has_value());
+ EXPECT_FALSE(me.Address().empty());
+ EXPECT_EQ(me.Transport(), "TCP");
+ EXPECT_EQ(me.ConsumerGroupsCount(), 0u);
+ EXPECT_TRUE(me.ConsumerGroups().empty());
}
-TEST_F(LowLevelE2E_Client, GetMeReflectsConsumerGroupMembershipChanges) {
- RecordProperty("description", "Reflects joined consumer groups in get_me and removes them again after leaving.");
+TEST_F(E2E_Client, GetMeReflectsConsumerGroupMembershipChanges) {
+ RecordProperty("description", "Reflects joined consumer groups in GetMe and removes them again after leaving.");
const std::string stream_name = GetRandomName();
const std::string topic_name = GetRandomName();
const std::string group_name = GetRandomName();
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
- ASSERT_NO_THROW(client->create_stream(stream_name));
+ ASSERT_NO_THROW(client.CreateStream(stream_name));
TrackStream(stream_name);
- ASSERT_NO_THROW(client->create_topic(make_string_identifier(stream_name), topic_name,
- make_topic_create_options(1, "none", "server_default", 0, "server_default")));
+ const auto topic_details = client.CreateTopic(iggy::Identifier::String(stream_name), topic_name,
+ iggy::TopicCreateOptions().SetPartitionsCount(1));
- const auto stream_details = client->get_stream(make_string_identifier(stream_name));
- ASSERT_EQ(stream_details.topics.size(), 1u);
- const auto created_group = client->create_consumer_group(make_string_identifier(stream_name),
- make_string_identifier(topic_name), group_name);
+ const auto stream_details = client.GetStream(iggy::Identifier::String(stream_name));
+ const auto created_group = client.CreateConsumerGroup(iggy::Identifier::String(stream_name),
+ iggy::Identifier::String(topic_name), group_name);
- std::size_t baseline_groups_size = 0;
- std::uint32_t baseline_groups_count = 0;
- ASSERT_NO_THROW({
- const auto me = client->get_me();
- baseline_groups_count = me.consumer_groups_count;
- baseline_groups_size = me.consumer_groups.size();
- });
+ const auto baseline_me = client.GetMe();
+ const auto baseline_groups_count = baseline_me.ConsumerGroupsCount();
+ const auto baseline_groups_size = baseline_me.ConsumerGroups().size();
- ASSERT_NO_THROW(client->join_consumer_group(make_numeric_identifier(stream_details.id),
- make_numeric_identifier(stream_details.topics[0].id),
- make_numeric_identifier(created_group.id)));
+ ASSERT_NO_THROW(client.JoinConsumerGroup(iggy::Identifier::Numeric(stream_details.Id()),
+ iggy::Identifier::Numeric(topic_details.Id()),
+ iggy::Identifier::Numeric(created_group.Id())));
- ASSERT_NO_THROW({
- const auto me = client->get_me();
- EXPECT_GT(me.consumer_groups_count, baseline_groups_count);
- EXPECT_GT(me.consumer_groups.size(), baseline_groups_size);
+ {
+ const auto me = client.GetMe();
+ EXPECT_GT(me.ConsumerGroupsCount(), baseline_groups_count);
+ EXPECT_GT(me.ConsumerGroups().size(), baseline_groups_size);
bool found_group = false;
- for (const auto &group : me.consumer_groups) {
- if (group.stream_id != stream_details.id || group.topic_id != stream_details.topics[0].id ||
- group.group_id != created_group.id) {
+ for (const auto &group : me.ConsumerGroups()) {
+ if (group.StreamId() != stream_details.Id() || group.TopicId() != topic_details.Id() ||
+ group.GroupId() != created_group.Id()) {
continue;
}
found_group = true;
break;
}
EXPECT_TRUE(found_group);
- });
+ }
- ASSERT_NO_THROW(client->leave_consumer_group(make_numeric_identifier(stream_details.id),
- make_numeric_identifier(stream_details.topics[0].id),
- make_numeric_identifier(created_group.id)));
+ ASSERT_NO_THROW(client.LeaveConsumerGroup(iggy::Identifier::Numeric(stream_details.Id()),
+ iggy::Identifier::Numeric(topic_details.Id()),
+ iggy::Identifier::Numeric(created_group.Id())));
- ASSERT_NO_THROW({
- const auto me = client->get_me();
- EXPECT_GE(me.consumer_groups_count, baseline_groups_count);
- EXPECT_GE(me.consumer_groups.size(), baseline_groups_size);
+ {
+ const auto me = client.GetMe();
+ EXPECT_GE(me.ConsumerGroupsCount(), baseline_groups_count);
+ EXPECT_GE(me.ConsumerGroups().size(), baseline_groups_size);
bool found_group = false;
- for (const auto &group : me.consumer_groups) {
- if (group.stream_id != stream_details.id || group.topic_id != stream_details.topics[0].id ||
- group.group_id != created_group.id) {
+ for (const auto &group : me.ConsumerGroups()) {
+ if (group.StreamId() != stream_details.Id() || group.TopicId() != topic_details.Id() ||
+ group.GroupId() != created_group.Id()) {
continue;
}
found_group = true;
break;
}
EXPECT_FALSE(found_group);
- });
+ }
}
-TEST_F(LowLevelE2E_Client, GetMeIsStableAcrossBackToBackCalls) {
- RecordProperty("description", "Returns stable current-client details across back-to-back get_me calls.");
- iggy::ffi::Client *client = GetLoggedInClient();
+TEST_F(E2E_Client, GetMeIsStableAcrossBackToBackCalls) {
+ RecordProperty("description", "Returns stable current-client details across back-to-back GetMe calls.");
+ auto client = GetLoggedInHighLevelClient();
- iggy::ffi::ClientInfoDetails first_me{};
- iggy::ffi::ClientInfoDetails second_me{};
- ASSERT_NO_THROW({
- first_me = client->get_me();
- second_me = client->get_me();
- });
+ const auto first_me = client.GetMe();
+ const auto second_me = client.GetMe();
- EXPECT_NE(first_me.client_id, 0u);
- EXPECT_TRUE(first_me.has_user_id);
- EXPECT_TRUE(second_me.has_user_id);
- EXPECT_EQ(second_me.client_id, first_me.client_id);
- EXPECT_EQ(second_me.has_user_id, first_me.has_user_id);
- EXPECT_EQ(second_me.user_id, first_me.user_id);
- EXPECT_EQ(static_cast<std::string>(second_me.address), static_cast<std::string>(first_me.address));
- EXPECT_EQ(static_cast<std::string>(first_me.transport), "TCP");
- EXPECT_EQ(static_cast<std::string>(second_me.transport), "TCP");
- EXPECT_EQ(static_cast<std::string>(second_me.transport), static_cast<std::string>(first_me.transport));
- EXPECT_EQ(second_me.consumer_groups_count, first_me.consumer_groups_count);
- EXPECT_EQ(second_me.consumer_groups.size(), first_me.consumer_groups.size());
+ EXPECT_NE(first_me.ClientId(), 0u);
+ EXPECT_TRUE(first_me.UserId().has_value());
+ EXPECT_TRUE(second_me.UserId().has_value());
+ EXPECT_EQ(second_me.ClientId(), first_me.ClientId());
+ EXPECT_EQ(second_me.UserId(), first_me.UserId());
+ EXPECT_EQ(second_me.Address(), first_me.Address());
+ EXPECT_EQ(first_me.Transport(), "TCP");
+ EXPECT_EQ(second_me.Transport(), "TCP");
+ EXPECT_EQ(second_me.Transport(), first_me.Transport());
+ EXPECT_EQ(second_me.ConsumerGroupsCount(), first_me.ConsumerGroupsCount());
+ EXPECT_EQ(second_me.ConsumerGroups().size(), first_me.ConsumerGroups().size());
}
-TEST_F(LowLevelE2E_Client, GetMeReturnsDistinctClientIdsForDifferentSessions) {
+TEST_F(E2E_Client, GetMeReturnsDistinctClientIdsForDifferentSessions) {
RecordProperty(
"description",
"Returns different client ids for separate authenticated sessions while keeping the same user identity.");
- iggy::ffi::Client *first_client = GetLoggedInClient();
- iggy::ffi::Client *second_client = GetLoggedInClient();
+ auto first_client = GetLoggedInHighLevelClient();
+ auto second_client = GetLoggedInHighLevelClient();
- iggy::ffi::ClientInfoDetails first_me{};
- iggy::ffi::ClientInfoDetails second_me{};
- ASSERT_NO_THROW({
- first_me = first_client->get_me();
- second_me = second_client->get_me();
- });
+ const auto first_me = first_client.GetMe();
+ const auto second_me = second_client.GetMe();
- EXPECT_NE(first_me.client_id, 0u);
- EXPECT_NE(second_me.client_id, 0u);
- EXPECT_TRUE(first_me.has_user_id);
- EXPECT_TRUE(second_me.has_user_id);
- EXPECT_NE(second_me.client_id, first_me.client_id);
- EXPECT_EQ(second_me.has_user_id, first_me.has_user_id);
- EXPECT_EQ(second_me.user_id, first_me.user_id);
- EXPECT_EQ(static_cast<std::string>(first_me.transport), "TCP");
- EXPECT_EQ(static_cast<std::string>(second_me.transport), "TCP");
+ EXPECT_NE(first_me.ClientId(), 0u);
+ EXPECT_NE(second_me.ClientId(), 0u);
+ EXPECT_TRUE(first_me.UserId().has_value());
+ EXPECT_TRUE(second_me.UserId().has_value());
+ EXPECT_NE(second_me.ClientId(), first_me.ClientId());
+ EXPECT_EQ(second_me.UserId(), first_me.UserId());
+ EXPECT_EQ(first_me.Transport(), "TCP");
+ EXPECT_EQ(second_me.Transport(), "TCP");
}
-TEST_F(LowLevelE2E_Client, GetMeReturnsValidDetailsAfterReconnect) {
+TEST_F(E2E_Client, GetMeReturnsValidDetailsAfterReconnect) {
RecordProperty("description",
"Returns valid current-client details after reconnecting with a fresh authenticated session.");
- iggy::ffi::Client *first_client = GetLoggedInClient();
-
- iggy::ffi::ClientInfoDetails first_me{};
- ASSERT_NO_THROW({ first_me = first_client->get_me(); });
- EXPECT_NE(first_me.client_id, 0u);
- EXPECT_TRUE(first_me.has_user_id);
-
- DeleteClient(first_client);
-
- iggy::ffi::Client *second_client = GetLoggedInClient();
-
- iggy::ffi::ClientInfoDetails second_me{};
- ASSERT_NO_THROW({ second_me = second_client->get_me(); });
- EXPECT_NE(second_me.client_id, 0u);
- EXPECT_TRUE(second_me.has_user_id);
- EXPECT_EQ(second_me.has_user_id, first_me.has_user_id);
- EXPECT_EQ(second_me.user_id, first_me.user_id);
- EXPECT_EQ(static_cast<std::string>(first_me.transport), "TCP");
- EXPECT_EQ(static_cast<std::string>(second_me.transport), "TCP");
- EXPECT_EQ(static_cast<std::string>(second_me.transport), static_cast<std::string>(first_me.transport));
- EXPECT_FALSE(static_cast<std::string>(second_me.address).empty());
- EXPECT_EQ(second_me.consumer_groups_count, 0u);
- EXPECT_TRUE(second_me.consumer_groups.empty());
-}
-
-TEST_F(LowLevelE2E_Client, GetClientBeforeLoginThrows) {
+ const auto first_me = [this] {
+ auto first_client = GetLoggedInHighLevelClient();
+ return first_client.GetMe();
+ }();
+ EXPECT_NE(first_me.ClientId(), 0u);
+ EXPECT_TRUE(first_me.UserId().has_value());
+
+ auto second_client = GetLoggedInHighLevelClient();
+ const auto second_me = second_client.GetMe();
+ EXPECT_NE(second_me.ClientId(), 0u);
+ EXPECT_TRUE(second_me.UserId().has_value());
+ EXPECT_EQ(second_me.UserId(), first_me.UserId());
+ EXPECT_EQ(first_me.Transport(), "TCP");
+ EXPECT_EQ(second_me.Transport(), "TCP");
+ EXPECT_EQ(second_me.Transport(), first_me.Transport());
+ EXPECT_FALSE(second_me.Address().empty());
+ EXPECT_EQ(second_me.ConsumerGroupsCount(), 0u);
+ EXPECT_TRUE(second_me.ConsumerGroups().empty());
+}
+
+TEST_F(E2E_Client, GetClientBeforeLoginThrows) {
RecordProperty("description",
- "Rejects get_client before connect, after connect but before login, and after disconnect.");
- iggy::ffi::Client *client = GetLoggedOutClient();
+ "Rejects GetClient before connect, after connect but before login, and after disconnect.");
+ auto client = GetLoggedOutHighLevelClient();
- ASSERT_THROW(client->get_client(1), std::exception);
- ASSERT_NO_THROW(client->connect());
- ASSERT_THROW(client->get_client(1), std::exception);
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->disconnect());
- ASSERT_THROW(client->get_client(1), std::exception);
+ ASSERT_THROW(client.GetClient(1), iggy::IggyException);
+ ASSERT_NO_THROW(client.Connect());
+ ASSERT_THROW(client.GetClient(1), iggy::IggyException);
+ ASSERT_NO_THROW(client.Login("iggy", "iggy"));
+ ASSERT_NO_THROW(client.Disconnect());
+ ASSERT_THROW(client.GetClient(1), iggy::IggyException);
}
-TEST_F(LowLevelE2E_Client, GetClientWithWrongClientIdThrows) {
+TEST_F(E2E_Client, GetClientWithWrongClientIdThrows) {
RecordProperty("description", "Rejects querying invalid or non-existent client ids.");
- iggy::ffi::Client *client = GetLoggedInClient();
+ auto client = GetLoggedInHighLevelClient();
std::uint32_t non_existent_client_id = 1u;
- ASSERT_NO_THROW({
- const auto clients = client->get_clients();
- std::unordered_set<std::uint32_t> client_ids;
- for (const auto &entry : clients) {
- client_ids.insert(entry.client_id);
- }
+ const auto clients = client.GetClients();
+ std::unordered_set<std::uint32_t> client_ids;
+ for (const auto &entry : clients) {
+ client_ids.insert(entry.ClientId());
+ }
- while (client_ids.find(non_existent_client_id) != client_ids.end()) {
- ++non_existent_client_id;
- }
- });
+ while (client_ids.find(non_existent_client_id) != client_ids.end()) {
+ ++non_existent_client_id;
+ }
const std::uint32_t wrong_client_ids[] = {0u, non_existent_client_id};
for (const std::uint32_t wrong_client_id : wrong_client_ids) {
SCOPED_TRACE(wrong_client_id);
- ASSERT_THROW(client->get_client(wrong_client_id), std::exception);
+ ASSERT_THROW(client.GetClient(wrong_client_id), iggy::IggyException);
}
}
-TEST_F(LowLevelE2E_Client, GetClientReturnsDetailsForMatchingClientId) {
+TEST_F(E2E_Client, GetClientReturnsDetailsForMatchingClientId) {
RecordProperty("description", "Returns current client details when querying with the authenticated client id.");
- iggy::ffi::Client *client = GetLoggedInClient();
-
- iggy::ffi::ClientInfoDetails current_client{};
- iggy::ffi::ClientInfoDetails looked_up_client{};
- ASSERT_NO_THROW({
- current_client = client->get_me();
- looked_up_client = client->get_client(current_client.client_id);
- });
-
- EXPECT_NE(current_client.client_id, 0u);
- EXPECT_TRUE(current_client.has_user_id);
- EXPECT_TRUE(looked_up_client.has_user_id);
- EXPECT_EQ(looked_up_client.client_id, current_client.client_id);
- EXPECT_EQ(looked_up_client.has_user_id, current_client.has_user_id);
- EXPECT_EQ(looked_up_client.user_id, current_client.user_id);
- EXPECT_EQ(static_cast<std::string>(looked_up_client.address), static_cast<std::string>(current_client.address));
- EXPECT_EQ(static_cast<std::string>(looked_up_client.transport), "TCP");
- EXPECT_EQ(static_cast<std::string>(looked_up_client.transport), static_cast<std::string>(current_client.transport));
- EXPECT_EQ(looked_up_client.consumer_groups_count, current_client.consumer_groups_count);
- EXPECT_EQ(looked_up_client.consumer_groups.size(), current_client.consumer_groups.size());
-}
-
-TEST_F(LowLevelE2E_Client, GetClientIsStableAcrossBackToBackCalls) {
- RecordProperty("description", "Returns stable client details across back-to-back get_client calls.");
- iggy::ffi::Client *client = GetLoggedInClient();
-
- iggy::ffi::ClientInfoDetails current_client{};
- iggy::ffi::ClientInfoDetails first_lookup{};
- iggy::ffi::ClientInfoDetails second_lookup{};
- ASSERT_NO_THROW({
- current_client = client->get_me();
- first_lookup = client->get_client(current_client.client_id);
- second_lookup = client->get_client(current_client.client_id);
- });
-
- EXPECT_NE(current_client.client_id, 0u);
- EXPECT_TRUE(current_client.has_user_id);
- EXPECT_TRUE(first_lookup.has_user_id);
- EXPECT_TRUE(second_lookup.has_user_id);
- EXPECT_EQ(first_lookup.client_id, current_client.client_id);
- EXPECT_EQ(second_lookup.client_id, first_lookup.client_id);
- EXPECT_EQ(first_lookup.has_user_id, current_client.has_user_id);
- EXPECT_EQ(second_lookup.has_user_id, first_lookup.has_user_id);
- EXPECT_EQ(second_lookup.user_id, first_lookup.user_id);
- EXPECT_EQ(static_cast<std::string>(second_lookup.address), static_cast<std::string>(first_lookup.address));
- EXPECT_EQ(static_cast<std::string>(first_lookup.transport), "TCP");
- EXPECT_EQ(static_cast<std::string>(second_lookup.transport), "TCP");
- EXPECT_EQ(static_cast<std::string>(second_lookup.transport), static_cast<std::string>(first_lookup.transport));
- EXPECT_EQ(second_lookup.consumer_groups_count, first_lookup.consumer_groups_count);
- EXPECT_EQ(second_lookup.consumer_groups.size(), first_lookup.consumer_groups.size());
-}
-
-TEST_F(LowLevelE2E_Client, GetClientsBeforeLoginThrows) {
+ auto client = GetLoggedInHighLevelClient();
+
+ const auto current_client = client.GetMe();
+ const auto looked_up_client = client.GetClient(current_client.ClientId());
+
+ EXPECT_NE(current_client.ClientId(), 0u);
+ EXPECT_TRUE(current_client.UserId().has_value());
+ EXPECT_TRUE(looked_up_client.UserId().has_value());
+ EXPECT_EQ(looked_up_client.ClientId(), current_client.ClientId());
+ EXPECT_EQ(looked_up_client.UserId(), current_client.UserId());
+ EXPECT_EQ(looked_up_client.Address(), current_client.Address());
+ EXPECT_EQ(looked_up_client.Transport(), "TCP");
+ EXPECT_EQ(looked_up_client.Transport(), current_client.Transport());
+ EXPECT_EQ(looked_up_client.ConsumerGroupsCount(), current_client.ConsumerGroupsCount());
+ EXPECT_EQ(looked_up_client.ConsumerGroups().size(), current_client.ConsumerGroups().size());
+}
+
+TEST_F(E2E_Client, GetClientIsStableAcrossBackToBackCalls) {
+ RecordProperty("description", "Returns stable client details across back-to-back GetClient calls.");
+ auto client = GetLoggedInHighLevelClient();
+
+ const auto current_client = client.GetMe();
+ const auto first_lookup = client.GetClient(current_client.ClientId());
+ const auto second_lookup = client.GetClient(current_client.ClientId());
+
+ EXPECT_NE(current_client.ClientId(), 0u);
+ EXPECT_TRUE(current_client.UserId().has_value());
+ EXPECT_TRUE(first_lookup.UserId().has_value());
+ EXPECT_TRUE(second_lookup.UserId().has_value());
+ EXPECT_EQ(first_lookup.ClientId(), current_client.ClientId());
+ EXPECT_EQ(second_lookup.ClientId(), first_lookup.ClientId());
+ EXPECT_EQ(second_lookup.UserId(), first_lookup.UserId());
+ EXPECT_EQ(second_lookup.Address(), first_lookup.Address());
+ EXPECT_EQ(first_lookup.Transport(), "TCP");
+ EXPECT_EQ(second_lookup.Transport(), "TCP");
+ EXPECT_EQ(second_lookup.Transport(), first_lookup.Transport());
+ EXPECT_EQ(second_lookup.ConsumerGroupsCount(), first_lookup.ConsumerGroupsCount());
+ EXPECT_EQ(second_lookup.ConsumerGroups().size(), first_lookup.ConsumerGroups().size());
+}
+
+TEST_F(E2E_Client, GetClientsBeforeLoginThrows) {
RecordProperty("description",
- "Rejects get_clients before connect, after connect but before login, and after disconnect.");
- iggy::ffi::Client *client = GetLoggedOutClient();
+ "Rejects GetClients before connect, after connect but before login, and after disconnect.");
+ auto client = GetLoggedOutHighLevelClient();
- ASSERT_THROW(client->get_clients(), std::exception);
- ASSERT_NO_THROW(client->connect());
- ASSERT_THROW(client->get_clients(), std::exception);
- ASSERT_NO_THROW(client->login_user("iggy", "iggy"));
- ASSERT_NO_THROW(client->disconnect());
- ASSERT_THROW(client->get_clients(), std::exception);
+ ASSERT_THROW(client.GetClients(), iggy::IggyException);
+ ASSERT_NO_THROW(client.Connect());
+ ASSERT_THROW(client.GetClients(), iggy::IggyException);
+ ASSERT_NO_THROW(client.Login("iggy", "iggy"));
+ ASSERT_NO_THROW(client.Disconnect());
+ ASSERT_THROW(client.GetClients(), iggy::IggyException);
}
-TEST_F(LowLevelE2E_Client, GetClientsReturnsActiveClientSessions) {
+TEST_F(E2E_Client, GetClientsReturnsActiveClientSessions) {
RecordProperty("description", "Returns the currently active authenticated client sessions.");
- iggy::ffi::Client *first_client = GetLoggedInClient();
- iggy::ffi::Client *second_client = GetLoggedInClient();
+ auto first_client = GetLoggedInHighLevelClient();
+ auto second_client = GetLoggedInHighLevelClient();
- iggy::ffi::ClientInfoDetails first_me{};
- iggy::ffi::ClientInfoDetails second_me{};
- rust::Vec<iggy::ffi::ClientInfo> clients;
- ASSERT_NO_THROW({
- first_me = first_client->get_me();
- second_me = second_client->get_me();
- clients = first_client->get_clients();
- });
+ const auto first_me = first_client.GetMe();
+ const auto second_me = second_client.GetMe();
+ const auto clients = first_client.GetClients();
ASSERT_GE(clients.size(), 2u);
bool found_first = false;
bool found_second = false;
for (const auto &client : clients) {
- EXPECT_NE(client.client_id, 0u);
- EXPECT_EQ(static_cast<std::string>(client.transport), "TCP");
+ EXPECT_NE(client.ClientId(), 0u);
+ EXPECT_EQ(client.Transport(), "TCP");
- if (client.client_id == first_me.client_id) {
+ if (client.ClientId() == first_me.ClientId()) {
found_first = true;
- EXPECT_EQ(client.has_user_id, first_me.has_user_id);
- EXPECT_EQ(client.user_id, first_me.user_id);
- EXPECT_EQ(static_cast<std::string>(client.address), static_cast<std::string>(first_me.address));
- EXPECT_EQ(client.consumer_groups_count, first_me.consumer_groups_count);
+ EXPECT_EQ(client.UserId(), first_me.UserId());
+ EXPECT_EQ(client.Address(), first_me.Address());
+ EXPECT_EQ(client.ConsumerGroupsCount(), first_me.ConsumerGroupsCount());
}
- if (client.client_id == second_me.client_id) {
+ if (client.ClientId() == second_me.ClientId()) {
found_second = true;
- EXPECT_EQ(client.has_user_id, second_me.has_user_id);
- EXPECT_EQ(client.user_id, second_me.user_id);
- EXPECT_EQ(static_cast<std::string>(client.address), static_cast<std::string>(second_me.address));
- EXPECT_EQ(client.consumer_groups_count, second_me.consumer_groups_count);
+ EXPECT_EQ(client.UserId(), second_me.UserId());
+ EXPECT_EQ(client.Address(), second_me.Address());
+ EXPECT_EQ(client.ConsumerGroupsCount(), second_me.ConsumerGroupsCount());
}
}
@@ -2804,40 +2626,32 @@ TEST_F(LowLevelE2E_Client, GetClientsReturnsActiveClientSessions) {
EXPECT_TRUE(found_second);
}
-TEST_F(LowLevelE2E_Client, GetClientsIsStableAcrossBackToBackCalls) {
- RecordProperty("description", "Returns stable client lists across back-to-back get_clients calls.");
- iggy::ffi::Client *first_client = GetLoggedInClient();
- iggy::ffi::Client *second_client = GetLoggedInClient();
- ASSERT_NE(second_client, nullptr);
+TEST_F(E2E_Client, GetClientsIsStableAcrossBackToBackCalls) {
+ RecordProperty("description", "Returns stable client lists across back-to-back GetClients calls.");
+ auto first_client = GetLoggedInHighLevelClient();
+ auto second_client = GetLoggedInHighLevelClient();
- iggy::ffi::ClientInfoDetails first_me{};
- iggy::ffi::ClientInfoDetails second_me{};
- rust::Vec<iggy::ffi::ClientInfo> first_clients;
- rust::Vec<iggy::ffi::ClientInfo> second_clients;
- ASSERT_NO_THROW({
- first_me = first_client->get_me();
- second_me = second_client->get_me();
- first_clients = first_client->get_clients();
- second_clients = first_client->get_clients();
- });
+ const auto first_me = first_client.GetMe();
+ const auto second_me = second_client.GetMe();
+ const auto first_clients = first_client.GetClients();
+ const auto second_clients = first_client.GetClients();
ASSERT_GE(first_clients.size(), 2u);
ASSERT_GE(second_clients.size(), 2u);
- const auto expect_entry_matches = [](const rust::Vec<iggy::ffi::ClientInfo> &clients,
- const iggy::ffi::ClientInfoDetails &expected) {
+ const auto expect_entry_matches = [](const std::vector<iggy::ClientInfo> &clients,
+ const iggy::ClientInfoDetails &expected) {
bool found = false;
for (const auto &entry : clients) {
- if (entry.client_id != expected.client_id) {
+ if (entry.ClientId() != expected.ClientId()) {
continue;
}
found = true;
- EXPECT_EQ(entry.has_user_id, expected.has_user_id);
- EXPECT_EQ(entry.user_id, expected.user_id);
- EXPECT_EQ(static_cast<std::string>(entry.address), static_cast<std::string>(expected.address));
- EXPECT_EQ(static_cast<std::string>(entry.transport), static_cast<std::string>(expected.transport));
- EXPECT_EQ(entry.consumer_groups_count, expected.consumer_groups_count);
+ EXPECT_EQ(entry.UserId(), expected.UserId());
+ EXPECT_EQ(entry.Address(), expected.Address());
+ EXPECT_EQ(entry.Transport(), expected.Transport());
+ EXPECT_EQ(entry.ConsumerGroupsCount(), expected.ConsumerGroupsCount());
break;
}
@@ -2850,49 +2664,40 @@ TEST_F(LowLevelE2E_Client, GetClientsIsStableAcrossBackToBackCalls) {
expect_entry_matches(second_clients, second_me);
}
-TEST_F(LowLevelE2E_Client, GetClientsMatchesGetClientForReturnedIds) {
- RecordProperty("description", "Returns list entries that agree with get_client for each returned client id.");
- iggy::ffi::Client *first_client = GetLoggedInClient();
- iggy::ffi::Client *second_client = GetLoggedInClient();
- ASSERT_NE(second_client, nullptr);
+TEST_F(E2E_Client, GetClientsMatchesGetClientForReturnedIds) {
+ RecordProperty("description", "Returns list entries that agree with GetClient for each returned client id.");
+ auto first_client = GetLoggedInHighLevelClient();
+ auto second_client = GetLoggedInHighLevelClient();
- rust::Vec<iggy::ffi::ClientInfo> clients;
- ASSERT_NO_THROW({ clients = first_client->get_clients(); });
+ const auto clients = first_client.GetClients();
ASSERT_GE(clients.size(), 2u);
for (const auto &client : clients) {
- SCOPED_TRACE(client.client_id);
- iggy::ffi::ClientInfoDetails details{};
- ASSERT_NO_THROW({ details = first_client->get_client(client.client_id); });
-
- EXPECT_EQ(details.client_id, client.client_id);
- EXPECT_EQ(details.has_user_id, client.has_user_id);
- EXPECT_EQ(details.user_id, client.user_id);
- EXPECT_EQ(static_cast<std::string>(details.address), static_cast<std::string>(client.address));
- EXPECT_EQ(static_cast<std::string>(details.transport), static_cast<std::string>(client.transport));
- EXPECT_EQ(details.consumer_groups_count, client.consumer_groups_count);
+ SCOPED_TRACE(client.ClientId());
+ const auto details = first_client.GetClient(client.ClientId());
+
+ EXPECT_EQ(details.ClientId(), client.ClientId());
+ EXPECT_EQ(details.UserId(), client.UserId());
+ EXPECT_EQ(details.Address(), client.Address());
+ EXPECT_EQ(details.Transport(), client.Transport());
+ EXPECT_EQ(details.ConsumerGroupsCount(), client.ConsumerGroupsCount());
}
}
-TEST_F(LowLevelE2E_Client, GetClientsReflectsAdditionalSession) {
- RecordProperty("description", "Reflects a newly added authenticated session in subsequent get_clients results.");
- iggy::ffi::Client *first_client = GetLoggedInClient();
+TEST_F(E2E_Client, GetClientsReflectsAdditionalSession) {
+ RecordProperty("description", "Reflects a newly added authenticated session in subsequent GetClients results.");
+ auto first_client = GetLoggedInHighLevelClient();
- rust::Vec<iggy::ffi::ClientInfo> clients_before;
- ASSERT_NO_THROW({ clients_before = first_client->get_clients(); });
+ const auto clients_before = first_client.GetClients();
- iggy::ffi::Client *second_client = GetLoggedInClient();
+ auto second_client = GetLoggedInHighLevelClient();
- iggy::ffi::ClientInfoDetails second_me{};
- rust::Vec<iggy::ffi::ClientInfo> clients_after;
- ASSERT_NO_THROW({
- second_me = second_client->get_me();
- clients_after = first_client->get_clients();
- });
+ const auto second_me = second_client.GetMe();
+ const auto clients_after = first_client.GetClients();
bool found_before = false;
for (const auto &client : clients_before) {
- if (client.client_id == second_me.client_id) {
+ if (client.ClientId() == second_me.ClientId()) {
found_before = true;
break;
}
@@ -2901,16 +2706,15 @@ TEST_F(LowLevelE2E_Client, GetClientsReflectsAdditionalSession) {
bool found_after = false;
for (const auto &client : clients_after) {
- if (client.client_id != second_me.client_id) {
+ if (client.ClientId() != second_me.ClientId()) {
continue;
}
found_after = true;
- EXPECT_EQ(client.has_user_id, second_me.has_user_id);
- EXPECT_EQ(client.user_id, second_me.user_id);
- EXPECT_EQ(static_cast<std::string>(client.address), static_cast<std::string>(second_me.address));
- EXPECT_EQ(static_cast<std::string>(client.transport), "TCP");
- EXPECT_EQ(client.consumer_groups_count, second_me.consumer_groups_count);
+ EXPECT_EQ(client.UserId(), second_me.UserId());
+ EXPECT_EQ(client.Address(), second_me.Address());
+ EXPECT_EQ(client.Transport(), "TCP");
+ EXPECT_EQ(client.ConsumerGroupsCount(), second_me.ConsumerGroupsCount());
break;
}
EXPECT_TRUE(found_after);
diff --git a/foreign/cpp/tests/e2e/consumer_group.cpp b/foreign/cpp/tests/e2e/consumer_group.cpp
index 404932cf5..b1be8754b 100644
--- a/foreign/cpp/tests/e2e/consumer_group.cpp
+++ b/foreign/cpp/tests/e2e/consumer_group.cpp
@@ -1566,7 +1566,6 @@ TEST_F(E2E_ConsumerGroup, StoreConsumerOffsetWithoutPermissionThrowsWithoutChang
const std::string password = "secret123";
auto client = GetLoggedInHighLevelClient();
auto *message_client = GetLoggedInClient();
- auto *user_admin_client = GetLoggedInClient();
const auto consumer = iggy::Consumer::Single(iggy::Identifier::Numeric(1));
ASSERT_NO_THROW(client.CreateStream(stream_name));
@@ -1583,8 +1582,7 @@ TEST_F(E2E_ConsumerGroup, StoreConsumerOffsetWithoutPermissionThrowsWithoutChang
partition_id_bytes(0), std::move(messages)));
ASSERT_NO_THROW(client.StoreConsumerOffset(consumer, iggy::Identifier::String(stream_name),
iggy::Identifier::String(topic_name), 0, 1));
- ASSERT_NO_THROW(CreateUser(user_admin_client, username, password, iggy::ffi::UserStatus::Active, true,
- iggy::ffi::Permissions{}));
+ ASSERT_NO_THROW(CreateUser(client, username, password, iggy::UserStatus::Active, iggy::Permissions{}));
auto restricted_client = GetLoggedInHighLevelClient(username, password);
ASSERT_THROW(restricted_client.StoreConsumerOffset(consumer, iggy::Identifier::String(stream_name),
@@ -1723,7 +1721,6 @@ TEST_F(E2E_ConsumerGroup, GetConsumerOffsetWithoutPermissionThrows) {
const std::string password = "secret123";
auto client = GetLoggedInHighLevelClient();
auto *message_client = GetLoggedInClient();
- auto *user_admin_client = GetLoggedInClient();
const auto consumer = iggy::Consumer::Single(iggy::Identifier::Numeric(1));
ASSERT_NO_THROW(client.CreateStream(stream_name));
@@ -1737,8 +1734,7 @@ TEST_F(E2E_ConsumerGroup, GetConsumerOffsetWithoutPermissionThrows) {
partition_id_bytes(0), std::move(messages)));
ASSERT_NO_THROW(client.StoreConsumerOffset(consumer, iggy::Identifier::String(stream_name),
iggy::Identifier::String(topic_name), 0, 0));
- ASSERT_NO_THROW(CreateUser(user_admin_client, username, password, iggy::ffi::UserStatus::Active, true,
- iggy::ffi::Permissions{}));
+ ASSERT_NO_THROW(CreateUser(client, username, password, iggy::UserStatus::Active, iggy::Permissions{}));
auto restricted_client = GetLoggedInHighLevelClient(username, password);
ASSERT_THROW(restricted_client.GetConsumerOffset(consumer, iggy::Identifier::String(stream_name),
@@ -2000,7 +1996,6 @@ TEST_F(E2E_ConsumerGroup, DeleteConsumerOffsetWithoutPermissionThrowsWithoutRemo
const std::string password = "secret123";
auto client = GetLoggedInHighLevelClient();
auto *message_client = GetLoggedInClient();
- auto *user_admin_client = GetLoggedInClient();
const auto consumer = iggy::Consumer::Single(iggy::Identifier::Numeric(1));
ASSERT_NO_THROW(client.CreateStream(stream_name));
@@ -2017,8 +2012,7 @@ TEST_F(E2E_ConsumerGroup, DeleteConsumerOffsetWithoutPermissionThrowsWithoutRemo
partition_id_bytes(0), std::move(messages)));
ASSERT_NO_THROW(client.StoreConsumerOffset(consumer, iggy::Identifier::String(stream_name),
iggy::Identifier::String(topic_name), 0, 1));
- ASSERT_NO_THROW(CreateUser(user_admin_client, username, password, iggy::ffi::UserStatus::Active, true,
- iggy::ffi::Permissions{}));
+ ASSERT_NO_THROW(CreateUser(client, username, password, iggy::UserStatus::Active, iggy::Permissions{}));
auto restricted_client = GetLoggedInHighLevelClient(username, password);
ASSERT_THROW(restricted_client.DeleteConsumerOffset(consumer, iggy::Identifier::String(stream_name),
diff --git a/foreign/cpp/tests/e2e/stream.cpp b/foreign/cpp/tests/e2e/stream.cpp
index c02ec4c20..199b23ecb 100644
--- a/foreign/cpp/tests/e2e/stream.cpp
+++ b/foreign/cpp/tests/e2e/stream.cpp
@@ -276,16 +276,14 @@ TEST_F(E2E_Stream, UpdateStreamOnlyChangesName) {
ASSERT_NO_THROW(ffi_client->send_messages(make_numeric_identifier(stream_id), make_numeric_identifier(0),
"partition_id", partition_id_bytes(0), std::move(messages)));
- auto stream_before_update = client.GetStream(iggy::Identifier::Numeric(stream_id));
- iggy::ffi::Stats stats_before_update{};
- ASSERT_NO_THROW({ stats_before_update = ffi_client->get_stats(); });
+ auto stream_before_update = client.GetStream(iggy::Identifier::Numeric(stream_id));
+ const auto stats_before_update = client.GetStats();
ASSERT_NO_THROW(client.UpdateStream(iggy::Identifier::Numeric(stream_id), updated_stream_name));
ASSERT_THROW(client.GetStream(iggy::Identifier::String(stream_name)), iggy::IggyException);
- auto stream_after_update = client.GetStream(iggy::Identifier::Numeric(stream_id));
- iggy::ffi::Stats stats_after_update{};
- ASSERT_NO_THROW({ stats_after_update = ffi_client->get_stats(); });
+ auto stream_after_update = client.GetStream(iggy::Identifier::Numeric(stream_id));
+ const auto stats_after_update = client.GetStats();
EXPECT_EQ(stream_after_update.Id(), stream_before_update.Id());
EXPECT_EQ(stream_after_update.CreatedAt(), stream_before_update.CreatedAt());
@@ -308,11 +306,11 @@ TEST_F(E2E_Stream, UpdateStreamOnlyChangesName) {
EXPECT_EQ(after_topic.MessagesCount(), before_topic.MessagesCount());
EXPECT_EQ(after_topic.PartitionsCount(), before_topic.PartitionsCount());
- EXPECT_EQ(stats_after_update.streams_count, stats_before_update.streams_count);
- EXPECT_EQ(stats_after_update.topics_count, stats_before_update.topics_count);
- EXPECT_EQ(stats_after_update.partitions_count, stats_before_update.partitions_count);
- EXPECT_EQ(stats_after_update.segments_count, stats_before_update.segments_count);
- EXPECT_EQ(stats_after_update.messages_count, stats_before_update.messages_count);
+ EXPECT_EQ(stats_after_update.StreamsCount(), stats_before_update.StreamsCount());
+ EXPECT_EQ(stats_after_update.TopicsCount(), stats_before_update.TopicsCount());
+ EXPECT_EQ(stats_after_update.PartitionsCount(), stats_before_update.PartitionsCount());
+ EXPECT_EQ(stats_after_update.SegmentsCount(), stats_before_update.SegmentsCount());
+ EXPECT_EQ(stats_after_update.MessagesCount(), stats_before_update.MessagesCount());
}
TEST_F(E2E_Stream, UpdateStreamValidatesNameBounds) {
diff --git a/foreign/cpp/tests/e2e/test_helpers.hpp b/foreign/cpp/tests/e2e/test_helpers.hpp
index 3751311ee..4e982f8ab 100644
--- a/foreign/cpp/tests/e2e/test_helpers.hpp
+++ b/foreign/cpp/tests/e2e/test_helpers.hpp
@@ -203,6 +203,16 @@ class E2ETestFixture : public ::testing::Test {
return user;
}
+ iggy::UserInfoDetails CreateUser(iggy::IggyBlockingClient &client,
+ const std::string &username,
+ const std::string &password,
+ const iggy::UserStatus status,
+ std::optional<iggy::Permissions> permissions = std::nullopt) {
+ auto user = client.CreateUser(username, password, status, permissions);
+ tracked_user_names_.push_back(username);
+ return user;
+ }
+
void ForgetUser(const std::string &username) {
tracked_user_names_.erase(std::remove(tracked_user_names_.begin(), tracked_user_names_.end(), username),
tracked_user_names_.end());
diff --git a/foreign/cpp/tests/unit/unit_tests.cpp b/foreign/cpp/tests/unit/unit_tests.cpp
index 4f05e27e5..64b9fa411 100644
--- a/foreign/cpp/tests/unit/unit_tests.cpp
+++ b/foreign/cpp/tests/unit/unit_tests.cpp
@@ -361,6 +361,12 @@ TEST(IggyBlockingClientTest, MovedFromOperationsThrow) {
EXPECT_THROW(client.Shutdown(), iggy::IggyException);
EXPECT_THROW(client.Login("iggy", "iggy"), iggy::IggyException);
EXPECT_THROW(client.Logout(), iggy::IggyException);
+ EXPECT_THROW((void)client.GetUser(stream), iggy::IggyException);
+ EXPECT_THROW((void)client.GetUsers(), iggy::IggyException);
+ EXPECT_THROW((void)client.CreateUser("user", "secret123", iggy::UserStatus::Active), iggy::IggyException);
+ EXPECT_THROW(client.DeleteUser(stream), iggy::IggyException);
+ EXPECT_THROW(client.UpdateUser(stream, "updated-user", iggy::UserStatus::Active, iggy::UserUpdateOptions{}),
+ iggy::IggyException);
EXPECT_THROW(client.CreateStream("stream"), iggy::IggyException);
EXPECT_THROW(client.UpdateStream(stream, "updated-stream"), iggy::IggyException);
EXPECT_THROW(client.GetStreams(), iggy::IggyException);
@@ -376,6 +382,7 @@ TEST(IggyBlockingClientTest, MovedFromOperationsThrow) {
EXPECT_THROW(client.PurgeTopic(stream, topic), iggy::IggyException);
EXPECT_THROW(client.CreatePartitions(stream, topic, 1), iggy::IggyException);
EXPECT_THROW(client.DeletePartitions(stream, topic, 1), iggy::IggyException);
+ EXPECT_THROW(client.DeleteSegments(stream, topic, 0, 1), iggy::IggyException);
EXPECT_THROW(client.CreateConsumerGroup(stream, topic, "group"), iggy::IggyException);
EXPECT_THROW(client.GetConsumerGroup(stream, topic, group), iggy::IggyException);
EXPECT_THROW(client.GetConsumerGroups(stream, topic), iggy::IggyException);
@@ -385,6 +392,10 @@ TEST(IggyBlockingClientTest, MovedFromOperationsThrow) {
EXPECT_THROW(client.StoreConsumerOffset(consumer, stream, topic, 0, 0), iggy::IggyException);
EXPECT_THROW(client.GetConsumerOffset(consumer, stream, topic, 0), iggy::IggyException);
EXPECT_THROW(client.DeleteConsumerOffset(consumer, stream, topic, 0), iggy::IggyException);
+ EXPECT_THROW((void)client.GetStats(), iggy::IggyException);
+ EXPECT_THROW((void)client.GetMe(), iggy::IggyException);
+ EXPECT_THROW((void)client.GetClient(1), iggy::IggyException);
+ EXPECT_THROW((void)client.GetClients(), iggy::IggyException);
}
TEST(IggyBlockingClientTest, ConsumerOffsetOperationsRejectMaximumPartitionId) {