pub struct IncrementalAlterConfigsService;Expand description
A Service using Storage as Context taking IncrementalAlterConfigsRequest returning IncrementalAlterConfigsResponse.
use rama::{Context, Layer as _, Service, layer::MapStateLayer};
use tansu_sans_io::{
ConfigResource, CreateTopicsRequest, DescribeConfigsRequest, ErrorCode,
IncrementalAlterConfigsRequest, OpType,
create_topics_request::CreatableTopic,
describe_configs_request::DescribeConfigsResource,
incremental_alter_configs_request::{AlterConfigsResource, AlterableConfig},
};
use tansu_storage::{
CreateTopicsService, DescribeConfigsService, Error,
IncrementalAlterConfigsService, StorageContainer,
};
use url::Url;
const HOST: &str = "localhost";
const PORT: i32 = 9092;
const NODE_ID: i32 = 111;
let storage = StorageContainer::builder()
.cluster_id("tansu")
.node_id(NODE_ID)
.advertised_listener(Url::parse(&format!("tcp://{HOST}:{PORT}"))?)
.storage(Url::parse("memory://tansu/")?)
.build()
.await?;
let resource_name = "abcba";
let create_topic = {
let storage = storage.clone();
MapStateLayer::new(|_| storage).into_layer(CreateTopicsService)
};
let response = create_topic
.serve(
Context::default(),
CreateTopicsRequest::default().topics(Some(
[CreatableTopic::default()
.name(resource_name.into())
.num_partitions(3)
.replication_factor(1)]
.into(),
)),
)
.await?;
assert_eq!(
ErrorCode::None,
ErrorCode::try_from(response.topics.unwrap_or_default()[0].error_code)?
);
let config_name = "x.y.z";
let config_value = "pqr";
let describe_configs = {
let storage = storage.clone();
MapStateLayer::new(|_| storage).into_layer(DescribeConfigsService)
};
let response = describe_configs
.serve(
Context::default(),
DescribeConfigsRequest::default()
.include_documentation(Some(false))
.include_synonyms(Some(false))
.resources(Some(
[DescribeConfigsResource::default()
.resource_name(resource_name.into())
.resource_type(ConfigResource::Topic.into())
.configuration_keys(Some([config_name.into()].into()))]
.into(),
)),
)
.await?;
assert!(response.results.unwrap_or_default()[0].configs.is_none());
let alter_configs = {
let storage = storage.clone();
MapStateLayer::new(|_| storage).into_layer(IncrementalAlterConfigsService)
};
let _response = alter_configs
.serve(
Context::default(),
IncrementalAlterConfigsRequest::default().resources(Some(
[AlterConfigsResource::default()
.resource_name(resource_name.into())
.resource_type(ConfigResource::Topic.into())
.configs(Some(
[AlterableConfig::default()
.config_operation(OpType::Set.into())
.name(config_name.into())
.value(Some(config_value.into()))]
.into(),
))]
.into(),
)),
)
.await?;
let response = describe_configs
.serve(
Context::default(),
DescribeConfigsRequest::default()
.include_documentation(Some(false))
.include_synonyms(Some(false))
.resources(Some(
[DescribeConfigsResource::default()
.resource_name(resource_name.into())
.resource_type(ConfigResource::Topic.into())
.configuration_keys(Some([config_name.into()].into()))]
.into(),
)),
)
.await?;
let results = response.results.as_deref().unwrap_or(&[]);
assert_eq!(1, results.len());
assert_eq!(resource_name, results[0].resource_name.as_str());
let configs = results[0].configs.as_deref().unwrap_or(&[]);
assert_eq!(1, configs.len());
assert_eq!(Some(config_value), configs[0].value.as_deref());Trait Implementations§
Source§impl Clone for IncrementalAlterConfigsService
impl Clone for IncrementalAlterConfigsService
Source§fn clone(&self) -> IncrementalAlterConfigsService
fn clone(&self) -> IncrementalAlterConfigsService
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for IncrementalAlterConfigsService
impl Default for IncrementalAlterConfigsService
Source§fn default() -> IncrementalAlterConfigsService
fn default() -> IncrementalAlterConfigsService
Returns the “default value” for a type. Read more
Source§impl Ord for IncrementalAlterConfigsService
impl Ord for IncrementalAlterConfigsService
Source§fn cmp(&self, other: &IncrementalAlterConfigsService) -> Ordering
fn cmp(&self, other: &IncrementalAlterConfigsService) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for IncrementalAlterConfigsService
impl PartialEq for IncrementalAlterConfigsService
Source§fn eq(&self, other: &IncrementalAlterConfigsService) -> bool
fn eq(&self, other: &IncrementalAlterConfigsService) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl PartialOrd for IncrementalAlterConfigsService
impl PartialOrd for IncrementalAlterConfigsService
Source§impl<G> Service<G, IncrementalAlterConfigsRequest> for IncrementalAlterConfigsServicewhere
G: Storage,
impl<G> Service<G, IncrementalAlterConfigsRequest> for IncrementalAlterConfigsServicewhere
G: Storage,
impl Copy for IncrementalAlterConfigsService
impl Eq for IncrementalAlterConfigsService
impl StructuralPartialEq for IncrementalAlterConfigsService
Auto Trait Implementations§
impl Freeze for IncrementalAlterConfigsService
impl RefUnwindSafe for IncrementalAlterConfigsService
impl Send for IncrementalAlterConfigsService
impl Sync for IncrementalAlterConfigsService
impl Unpin for IncrementalAlterConfigsService
impl UnsafeUnpin for IncrementalAlterConfigsService
impl UnwindSafe for IncrementalAlterConfigsService
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more