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
impl Builder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a builder with one broker, as Java’s public Builder(), which
calls numBrokers(1).
Sourcepub fn set_cluster_id(self, cluster_id: &str) -> Self
pub fn set_cluster_id(self, cluster_id: &str) -> Self
Sourcepub fn set_brokers(self, brokers: Vec<Node>) -> Result<Self, Error>
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.
Sourcepub fn set_num_brokers(self, num_brokers: i32) -> Result<Self, Error>
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_brokersis negative: “fromIndex(0) > toIndex(n)” (Java’sIllegalArgumentException);- shrinking below the broker count while the log-dir list is shorter than
num_brokers: “toIndex = n” (Java’sIndexOutOfBoundsException).
Sourcepub fn set_controller(self, index: i32) -> Result<Self, Error>
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.
Sourcepub fn set_broker_log_dirs(self, broker_log_dirs: Vec<Vec<String>>) -> Self
pub fn set_broker_log_dirs(self, broker_log_dirs: Vec<Vec<String>>) -> Self
Sourcepub fn set_default_replication_factor(
self,
default_replication_factor: i32,
) -> Self
pub fn set_default_replication_factor( self, default_replication_factor: i32, ) -> Self
Sourcepub fn set_using_raft_controller(self, using_raft_controller: bool) -> Self
pub fn set_using_raft_controller(self, using_raft_controller: bool) -> Self
Sourcepub fn set_default_partitions(self, num_partitions: i16) -> Self
pub fn set_default_partitions(self, num_partitions: i16) -> Self
Sourcepub fn set_feature_levels(self, feature_levels: HashMap<String, i16>) -> Self
pub fn set_feature_levels(self, feature_levels: HashMap<String, i16>) -> Self
Sourcepub fn set_min_supported_feature_levels(
self,
min_supported_feature_levels: HashMap<String, i16>,
) -> Self
pub fn set_min_supported_feature_levels( self, min_supported_feature_levels: HashMap<String, i16>, ) -> Self
Sourcepub fn set_max_supported_feature_levels(
self,
max_supported_feature_levels: HashMap<String, i16>,
) -> Self
pub fn set_max_supported_feature_levels( self, max_supported_feature_levels: HashMap<String, i16>, ) -> Self
Sourcepub fn set_default_group_configs(
self,
default_group_configs: HashMap<String, String>,
) -> Self
pub fn set_default_group_configs( self, default_group_configs: HashMap<String, String>, ) -> Self
Sourcepub fn build(self) -> Result<MockAdminClient, Error>
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 byset_num_brokers(1)): “The controller node must be in the list of brokers”.