Skip to content

Commit

Permalink
fixing some example tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zach-schoenberger committed Oct 18, 2023
1 parent d0ff91f commit 6dac48d
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 19 deletions.
9 changes: 5 additions & 4 deletions cluster_benchmark/tests/benchmark/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use openraft::storage::RaftLogStorage;
use openraft::storage::RaftSnapshotBuilder;
use openraft::storage::RaftStateMachine;
use openraft::storage::Snapshot;
use openraft::raft::ExampleSnapshot;
use openraft::Entry;
use openraft::EntryPayload;
use openraft::LogId;
Expand All @@ -41,7 +42,7 @@ pub type NodeId = u64;

openraft::declare_raft_types!(
pub TypeConfig: D = ClientRequest, R = ClientResponse, NodeId = NodeId, Node = (),
Entry = Entry<TypeConfig>, SnapshotData = Cursor<Vec<u8>>, AsyncRuntime = TokioRuntime
Entry = Entry<TypeConfig>, SnapshotData = ExampleSnapshot, AsyncRuntime = TokioRuntime
);

#[derive(Debug)]
Expand Down Expand Up @@ -165,7 +166,7 @@ impl RaftSnapshotBuilder<TypeConfig> for Arc<StateMachineStore> {

Ok(Snapshot {
meta,
snapshot: Box::new(Cursor::new(data)),
snapshot: Box::new(Cursor::new(data).into()),
})
}
}
Expand Down Expand Up @@ -279,7 +280,7 @@ impl RaftStateMachine<TypeConfig> for Arc<StateMachineStore> {
async fn begin_receiving_snapshot(
&mut self,
) -> Result<Box<<TypeConfig as RaftTypeConfig>::SnapshotData>, StorageError<NodeId>> {
Ok(Box::new(Cursor::new(Vec::new())))
Ok(Box::new(Cursor::new(Vec::new()).into()))
}

#[tracing::instrument(level = "trace", skip(self, snapshot))]
Expand Down Expand Up @@ -314,7 +315,7 @@ impl RaftStateMachine<TypeConfig> for Arc<StateMachineStore> {
let data = snapshot.data.clone();
Ok(Some(Snapshot {
meta: snapshot.meta.clone(),
snapshot: Box::new(Cursor::new(data)),
snapshot: Box::new(Cursor::new(data).into()),
}))
}
None => Ok(None),
Expand Down
5 changes: 3 additions & 2 deletions examples/raft-kv-memstore/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(clippy::uninlined_format_args)]
#![deny(unused_qualifications)]

use std::io::Cursor;

use std::sync::Arc;

use actix_web::middleware;
Expand All @@ -12,6 +12,7 @@ use openraft::storage::Adaptor;
use openraft::BasicNode;
use openraft::Config;
use openraft::TokioRuntime;
use openraft::raft::ExampleSnapshot;

use crate::app::App;
use crate::network::api;
Expand All @@ -32,7 +33,7 @@ pub type NodeId = u64;
openraft::declare_raft_types!(
/// Declare the type configuration for example K/V store.
pub TypeConfig: D = Request, R = Response, NodeId = NodeId, Node = BasicNode,
Entry = openraft::Entry<TypeConfig>, SnapshotData = Cursor<Vec<u8>>, AsyncRuntime = TokioRuntime
Entry = openraft::Entry<TypeConfig>, SnapshotData = ExampleSnapshot, AsyncRuntime = TokioRuntime
);

pub type LogStore = Adaptor<TypeConfig, Arc<Store>>;
Expand Down
6 changes: 3 additions & 3 deletions examples/raft-kv-memstore/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl RaftSnapshotBuilder<TypeConfig> for Arc<Store> {

Ok(Snapshot {
meta,
snapshot: Box::new(Cursor::new(data)),
snapshot: Box::new(Cursor::new(data).into()),
})
}
}
Expand Down Expand Up @@ -280,7 +280,7 @@ impl RaftStorage<TypeConfig> for Arc<Store> {
async fn begin_receiving_snapshot(
&mut self,
) -> Result<Box<<TypeConfig as RaftTypeConfig>::SnapshotData>, StorageError<NodeId>> {
Ok(Box::new(Cursor::new(Vec::new())))
Ok(Box::new(Cursor::new(Vec::new()).into()))
}

#[tracing::instrument(level = "trace", skip(self, snapshot))]
Expand Down Expand Up @@ -320,7 +320,7 @@ impl RaftStorage<TypeConfig> for Arc<Store> {
let data = snapshot.data.clone();
Ok(Some(Snapshot {
meta: snapshot.meta.clone(),
snapshot: Box::new(Cursor::new(data)),
snapshot: Box::new(Cursor::new(data).into()),
}))
}
None => Ok(None),
Expand Down
3 changes: 2 additions & 1 deletion examples/raft-kv-rocksdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use async_std::task;
use openraft::storage::Adaptor;
use openraft::Config;
use openraft::TokioRuntime;
use openraft::raft::ExampleSnapshot;

use crate::app::App;
use crate::network::api;
Expand Down Expand Up @@ -42,7 +43,7 @@ impl Display for Node {
openraft::declare_raft_types!(
/// Declare the type configuration for example K/V store.
pub TypeConfig: D = Request, R = Response, NodeId = NodeId, Node = Node,
Entry = openraft::Entry<TypeConfig>, SnapshotData = Cursor<Vec<u8>>, AsyncRuntime = TokioRuntime
Entry = openraft::Entry<TypeConfig>, SnapshotData = ExampleSnapshot, AsyncRuntime = TokioRuntime
);

pub type LogStore = Adaptor<TypeConfig, Arc<Store>>;
Expand Down
6 changes: 3 additions & 3 deletions examples/raft-kv-rocksdb/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ impl RaftSnapshotBuilder<TypeConfig> for Arc<Store> {

Ok(Snapshot {
meta,
snapshot: Box::new(Cursor::new(data)),
snapshot: Box::new(Cursor::new(data).into()),
})
}
}
Expand Down Expand Up @@ -511,7 +511,7 @@ impl RaftStorage<TypeConfig> for Arc<Store> {
async fn begin_receiving_snapshot(
&mut self,
) -> Result<Box<<TypeConfig as RaftTypeConfig>::SnapshotData>, StorageError<NodeId>> {
Ok(Box::new(Cursor::new(Vec::new())))
Ok(Box::new(Cursor::new(Vec::new()).into()))
}

#[tracing::instrument(level = "trace", skip(self, snapshot))]
Expand Down Expand Up @@ -549,7 +549,7 @@ impl RaftStorage<TypeConfig> for Arc<Store> {
let data = snapshot.data.clone();
Ok(Some(Snapshot {
meta: snapshot.meta,
snapshot: Box::new(Cursor::new(data)),
snapshot: Box::new(Cursor::new(data).into()),
}))
}
None => Ok(None),
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/raft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ use crate::StorageHelper;
/// NodeId = u64,
/// Node = openraft::BasicNode,
/// Entry = openraft::Entry<TypeConfig>,
/// SnapshotData = Cursor<Vec<u8>>,
/// SnapshotData = openraft::ExampleSnapshot,
/// AsyncRuntime = openraft::TokioRuntime,
/// );
/// ```
Expand Down
2 changes: 1 addition & 1 deletion openraft/src/type_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::NodeId;
/// NodeId = u64,
/// Node = openraft::BasicNode,
/// Entry = openraft::Entry<TypeConfig>,
/// SnapshotData = Cursor<Vec<u8>>,
/// SnapshotData = ExampleSnapshot,
/// AsyncRuntime = openraft::TokioRuntime,
/// );
/// ```
Expand Down
9 changes: 5 additions & 4 deletions stores/rocksstore-v2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use openraft::StorageError;
use openraft::StorageIOError;
use openraft::StoredMembership;
use openraft::TokioRuntime;
use openraft::raft::ExampleSnapshot;
use openraft::Vote;
use rand::Rng;
use rocksdb::ColumnFamily;
Expand All @@ -54,7 +55,7 @@ pub type RocksNodeId = u64;
openraft::declare_raft_types!(
/// Declare the type configuration.
pub TypeConfig: D = RocksRequest, R = RocksResponse, NodeId = RocksNodeId, Node = BasicNode,
Entry = Entry<TypeConfig>, SnapshotData = Cursor<Vec<u8>>, AsyncRuntime = TokioRuntime
Entry = Entry<TypeConfig>, SnapshotData = ExampleSnapshot, AsyncRuntime = TokioRuntime
);

/**
Expand Down Expand Up @@ -305,7 +306,7 @@ impl RaftSnapshotBuilder<TypeConfig> for RocksStateMachine {

Ok(Snapshot {
meta,
snapshot: Box::new(Cursor::new(data)),
snapshot: Box::new(Cursor::new(data).into()),
})
}
}
Expand Down Expand Up @@ -455,7 +456,7 @@ impl RaftStateMachine<TypeConfig> for RocksStateMachine {
async fn begin_receiving_snapshot(
&mut self,
) -> Result<Box<<TypeConfig as RaftTypeConfig>::SnapshotData>, StorageError<RocksNodeId>> {
Ok(Box::new(Cursor::new(Vec::new())))
Ok(Box::new(Cursor::new(Vec::new()).into()))
}

async fn install_snapshot(
Expand Down Expand Up @@ -510,7 +511,7 @@ impl RaftStateMachine<TypeConfig> for RocksStateMachine {

Ok(Some(Snapshot {
meta: snapshot.meta,
snapshot: Box::new(Cursor::new(data)),
snapshot: Box::new(Cursor::new(data).into()),
}))
}
}
Expand Down

0 comments on commit 6dac48d

Please sign in to comment.