1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use kvproto::kvrpcpb::Context;
use test_raftstore::{new_server_cluster, Cluster, ServerCluster, SimulateEngine};
use tikv_util::HandyRwLock;
use super::*;
pub fn new_raft_engine(
count: usize,
key: &str,
) -> (Cluster<ServerCluster>, SimulateEngine, Context) {
let mut cluster = new_server_cluster(0, count);
cluster.run();
assert_eq!(cluster.must_get(b""), None);
let region = cluster.get_region(key.as_bytes());
let leader = cluster.leader_of_region(region.get_id()).unwrap();
let engine = cluster.sim.rl().storages[&leader.get_id()].clone();
let mut ctx = Context::default();
ctx.set_region_id(region.get_id());
ctx.set_region_epoch(region.get_region_epoch().clone());
ctx.set_peer(leader);
(cluster, engine, ctx)
}
pub fn new_raft_storage_with_store_count(
count: usize,
key: &str,
) -> (
Cluster<ServerCluster>,
SyncTestStorage<SimulateEngine>,
Context,
) {
let (cluster, engine, ctx) = new_raft_engine(count, key);
(
cluster,
SyncTestStorageBuilder::from_engine(engine).build().unwrap(),
ctx,
)
}