test: simplify partition provider mock
Removes redundant fields from the MockPartitionProvider.pull/24376/head
parent
48c6ff0e09
commit
38ebd5fb20
|
@ -315,6 +315,18 @@ impl PartitionData {
|
|||
pub(crate) fn table_name(&self) -> &str {
|
||||
self.table_name.as_ref()
|
||||
}
|
||||
|
||||
/// Return the shard ID for this partition.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn shard_id(&self) -> ShardId {
|
||||
self.shard_id
|
||||
}
|
||||
|
||||
/// Return the table ID for this partition.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn table_id(&self) -> TableId {
|
||||
self.table_id
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -23,27 +23,19 @@ impl MockPartitionProvider {
|
|||
pub(crate) fn with_partition(
|
||||
mut self,
|
||||
partition_key: PartitionKey,
|
||||
shard_id: ShardId,
|
||||
table_id: TableId,
|
||||
data: PartitionData,
|
||||
) -> Self {
|
||||
self.insert(partition_key, shard_id, table_id, data);
|
||||
self.insert(partition_key, data);
|
||||
self
|
||||
}
|
||||
|
||||
/// Add `data` to the mock state, returning it when asked for the specified
|
||||
/// `(key, shard, table)` triplet.
|
||||
pub(crate) fn insert(
|
||||
&mut self,
|
||||
partition_key: PartitionKey,
|
||||
shard_id: ShardId,
|
||||
table_id: TableId,
|
||||
data: PartitionData,
|
||||
) {
|
||||
pub(crate) fn insert(&mut self, partition_key: PartitionKey, data: PartitionData) {
|
||||
assert!(
|
||||
self.partitions
|
||||
.lock()
|
||||
.insert((partition_key, shard_id, table_id), data)
|
||||
.insert((partition_key, data.shard_id(), data.table_id()), data)
|
||||
.is_none(),
|
||||
"overwriting an existing mock PartitionData"
|
||||
);
|
||||
|
|
|
@ -55,12 +55,7 @@ mod tests {
|
|||
let partition = PartitionId::new(4242);
|
||||
let data = PartitionData::new(partition, shard_id, table_id, Arc::clone(&table_name), None);
|
||||
|
||||
let mock = Arc::new(MockPartitionProvider::default().with_partition(
|
||||
key.clone(),
|
||||
shard_id,
|
||||
table_id,
|
||||
data,
|
||||
));
|
||||
let mock = Arc::new(MockPartitionProvider::default().with_partition(key.clone(), data));
|
||||
|
||||
let got = mock
|
||||
.get_partition(key, shard_id, table_id, Arc::clone(&table_name))
|
||||
|
|
Loading…
Reference in New Issue