Skip to content

Commit

Permalink
tests: add delete new partitions
Browse files Browse the repository at this point in the history
  • Loading branch information
fraidev committed Jul 4, 2024
1 parent 99a33fa commit 2584125
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions crates/fluvio-sc/src/stores/topic/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use fluvio_stream_model::{
store::{MetadataStoreObject, LocalStore},
core::MetadataItem,
};
use fluvio_types::PartitionId;
use async_trait::async_trait;

use super::*;
Expand All @@ -32,7 +31,7 @@ where
.iter()
.map(|(idx, replicas)| {
let mirror = self.status.mirror_map.get(idx);
let replica_key = ReplicaKey::new(self.key(), *idx as PartitionId);
let replica_key = ReplicaKey::new(self.key(), *idx);
let partition_spec =
PartitionSpec::from_replicas(replicas.clone(), &self.spec, mirror);
MetadataStoreObject::with_spec(replica_key, partition_spec)
Expand Down Expand Up @@ -93,8 +92,10 @@ where
#[cfg(test)]
mod test {
use fluvio_controlplane_metadata::topic::{TopicStatus, TopicResolution};
use fluvio_protocol::record::ReplicaKey;
use fluvio_sc_schema::{store::MetadataStoreObject, topic::TopicSpec};

use crate::stores::topic::{DefaultTopicMd, DefaultTopicLocalStore};
use crate::stores::topic::{DefaultTopicLocalStore, DefaultTopicMd, TopicMd};

#[test]
fn test_topic_replica_map() {
Expand Down Expand Up @@ -202,4 +203,21 @@ mod test {

assert_eq!(pending_state_names, expected);
}

#[fluvio_future::test]
async fn test_partitions_from_replicas() {
let spec: TopicSpec = (2, 2, false).into();
let key = "topic-1";
let status = TopicStatus::new(
TopicResolution::Provisioned,
vec![vec![0, 1], vec![1, 2]],
"".to_owned(),
);
let topic = MetadataStoreObject::<TopicSpec, u32>::new(key, spec, status);
let partitions = topic.partitions_from_replicas().await;

assert_eq!(partitions.len(), 2);
assert_eq!(partitions[0].key, ReplicaKey::new("topic-1", 0_u32));
assert_eq!(partitions[1].key, ReplicaKey::new("topic-1", 1_u32));
}
}

0 comments on commit 2584125

Please sign in to comment.