Skip to main content

Builder

Struct Builder 

Source
pub struct Builder { /* private fields */ }
Expand description

Builds a MockAdminClient.

It has the setters, defaults and failure points of Java’s nested MockAdminClient.Builder. A fresh builder has one broker, Node(0, "localhost", 1000), with MockAdminClient::DEFAULT_LOG_DIRS.

Java’s builder throws from java.util collection methods where it reads an index out of range. The crate has no IndexOutOfBoundsException counterpart, so those failures are errors for which Error::is_local_illegal_argument_error holds (like the mock’s other argument errors), carrying the JDK’s message text.

Implementations§

Source§

impl Builder

Source

pub fn new() -> Self

Creates a builder with one broker, as Java’s public Builder(), which calls numBrokers(1).

Source

pub fn set_cluster_id(self, cluster_id: &str) -> Self

Sets the cluster id.

§Arguments
  • cluster_id - The cluster id
§Returns

This builder.

Source

pub fn set_brokers(self, brokers: Vec<Node>) -> Result<Self, Error>

Replaces the broker list.

As Java’s brokers(List<Node>), first numBrokers(brokers.size()) resizes the current lists, which keeps existing log-dir entries and pads with MockAdminClient::DEFAULT_LOG_DIRS, and only then is the broker list replaced.

§Arguments
  • brokers - The brokers
§Returns

This builder.

§Errors

The errors of set_num_brokers (Error::is_local_illegal_argument_error). With a non-negative count the only reachable one is a log-dir list shorter than brokers (after set_broker_log_dirs), where Java’s brokerLogDirs.subList(0, n) throws.

Source

pub fn set_num_brokers(self, num_brokers: i32) -> Result<Self, Error>

Sets the number of brokers, keeping the first ones.

Shrinking truncates both the broker list and the per-broker log dirs; growing appends Node(id, "localhost", 1000 + id) and MockAdminClient::DEFAULT_LOG_DIRS for each new id.

§Arguments
  • num_brokers - The number of brokers
§Returns

This builder.

§Errors

Error::is_local_illegal_argument_error where Java’s subList(0, n) (AbstractList.subListRangeCheck) throws:

  • num_brokers is negative: “fromIndex(0) > toIndex(n)” (Java’s IllegalArgumentException);
  • shrinking below the broker count while the log-dir list is shorter than num_brokers: “toIndex = n” (Java’s IndexOutOfBoundsException).
Source

pub fn set_controller(self, index: i32) -> Result<Self, Error>

Makes the broker at index the controller, reading brokers.get(index) at this call as Java’s controller(int) does.

§Arguments
  • index - The index of the controller in the broker list
§Returns

This builder.

§Errors

Error::is_local_illegal_argument_error with the JDK’s IndexOutOfBoundsException text, “Index i out of bounds for length n” (ArrayList.get → Objects.checkIndex), when index is not a broker index.

Source

pub fn set_broker_log_dirs(self, broker_log_dirs: Vec<Vec<String>>) -> Self

Replaces the per-broker log directories. Like Java’s brokerLogDirs(List<List<String>>), the length is not checked against the broker count.

§Arguments
  • broker_log_dirs - The log directories of each broker, indexed by broker id
§Returns

This builder.

Source

pub fn set_default_replication_factor( self, default_replication_factor: i32, ) -> Self

Sets the replication factor used when createTopics does not give one.

build narrows it to 16 bits the way Java’s Integer.shortValue() does: the value wraps, it is not clamped.

§Arguments
  • default_replication_factor - The default replication factor
§Returns

This builder.

Source

pub fn set_using_raft_controller(self, using_raft_controller: bool) -> Self

Sets whether the mocked cluster runs a KRaft (Raft) controller quorum, which decides whether unregister_controller succeeds (default false). The value is fixed once the mock is built.

§Arguments
  • using_raft_controller - Whether the cluster uses a Raft controller
§Returns

This builder.

Source

pub fn set_default_partitions(self, num_partitions: i16) -> Self

Sets the partition count used when createTopics does not give one.

§Arguments
  • num_partitions - The default partition count
§Returns

This builder.

Source

pub fn set_feature_levels(self, feature_levels: HashMap<String, i16>) -> Self

Sets the finalized feature levels.

§Arguments
  • feature_levels - The finalized level of each feature, by name
§Returns

This builder.

Source

pub fn set_min_supported_feature_levels( self, min_supported_feature_levels: HashMap<String, i16>, ) -> Self

Sets the minimum supported feature levels.

§Arguments
  • min_supported_feature_levels - The minimum supported level of each feature, by name
§Returns

This builder.

Source

pub fn set_max_supported_feature_levels( self, max_supported_feature_levels: HashMap<String, i16>, ) -> Self

Sets the maximum supported feature levels.

§Arguments
  • max_supported_feature_levels - The maximum supported level of each feature, by name
§Returns

This builder.

Source

pub fn set_default_group_configs( self, default_group_configs: HashMap<String, String>, ) -> Self

Sets the defaults overlaid onto every group’s configs.

§Arguments
  • default_group_configs - The default group configs, by name
§Returns

This builder.

Source

pub fn build(self) -> Result<MockAdminClient, Error>

Builds the mock.

Defaults: the controller is the first broker, the default partition count is 1, and the default replication factor is min(brokers.len(), 3).

§Returns

The mock admin client.

§Errors

Error::is_local_illegal_argument_error where Java throws:

  • no controller was set and there are no brokers: “Index 0 out of bounds for length 0”, the JDK’s text for Java’s brokers.get(0);
  • the controller is no longer one of the brokers (for example set_controller(2) followed by set_num_brokers(1)): “The controller node must be in the list of brokers”.

Trait Implementations§

Source§

impl Clone for Builder

Source§

fn clone(&self) -> Builder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Builder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Builder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V