-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
588 additions
and
223 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = [ | ||
"geth-node", | ||
"geth-engine", | ||
"geth-mikoshi", | ||
"geth-repl", | ||
"geth-client", | ||
"geth-common", | ||
"geth-consensus", | ||
"geth-domain", | ||
"geth-client-tests", | ||
"geth-node", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[package] | ||
name = "geth-client-tests" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies.geth-client] | ||
path = "../geth-client" | ||
|
||
[dependencies.geth-engine] | ||
path = "../geth-engine" | ||
|
||
[dependencies.geth-common] | ||
path = "../geth-common" | ||
|
||
[dependencies.tokio] | ||
version = "*" | ||
features = ["full"] | ||
|
||
[dependencies.fake] | ||
version = "2.9" | ||
features = ["derive"] | ||
|
||
[dependencies] | ||
temp-dir = "0.1" | ||
eyre = "0.6" | ||
uuid = "*" | ||
serde = "1" | ||
serde_json = "1" | ||
futures = "0.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use fake::faker::name::en::Name; | ||
use fake::{Fake, Faker}; | ||
use futures::TryStreamExt; | ||
use temp_dir::TempDir; | ||
use uuid::Uuid; | ||
|
||
use geth_client::GrpcClient; | ||
use geth_common::{AppendStreamCompleted, Client, Direction, ExpectedRevision, Propose, Revision}; | ||
|
||
use crate::tests::{client_endpoint, random_valid_options, Toto}; | ||
|
||
#[tokio::test] | ||
async fn simple_append() -> eyre::Result<()> { | ||
let db_dir = TempDir::new()?; | ||
let options = random_valid_options(&db_dir); | ||
|
||
let client = GrpcClient::new(client_endpoint(&options)); | ||
tokio::spawn(geth_engine::run(options.clone())); | ||
|
||
let stream_name: String = Name().fake(); | ||
let event_type: String = Name().fake(); | ||
let event_id = Uuid::new_v4(); | ||
let expected: Toto = Faker.fake(); | ||
|
||
let completed = client | ||
.append_stream( | ||
&stream_name, | ||
ExpectedRevision::Any, | ||
vec![Propose { | ||
id: event_id, | ||
r#type: event_type.clone(), | ||
data: serde_json::to_vec(&expected)?.into(), | ||
}], | ||
) | ||
.await?; | ||
|
||
let write_result = match completed { | ||
AppendStreamCompleted::Success(r) => r, | ||
AppendStreamCompleted::Error(e) => panic!("error: {}", e), | ||
}; | ||
|
||
assert_eq!( | ||
ExpectedRevision::Revision(1), | ||
write_result.next_expected_version | ||
); | ||
|
||
let mut stream = client | ||
.read_stream(&stream_name, Direction::Forward, Revision::Start, 1) | ||
.await; | ||
|
||
let event = stream.try_next().await?.unwrap(); | ||
|
||
assert_eq!(event_id, event.id); | ||
assert_eq!(event_type, event.r#type); | ||
assert_eq!(stream_name, event.stream_name); | ||
assert_eq!(0, event.revision); | ||
|
||
let actual = serde_json::from_slice::<Toto>(&event.data)?; | ||
|
||
assert_eq!(expected.key, actual.key); | ||
assert_eq!(expected.value, actual.value); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#[cfg(test)] | ||
mod append_read_tests; | ||
|
||
#[cfg(test)] | ||
pub mod tests { | ||
use fake::{Dummy, Fake}; | ||
use serde::{Deserialize, Serialize}; | ||
use temp_dir::TempDir; | ||
|
||
use geth_common::EndPoint; | ||
use geth_engine::Options; | ||
|
||
pub fn random_valid_options(temp_dir: &TempDir) -> Options { | ||
Options { | ||
host: "127.0.0.1".to_string(), | ||
port: (1_113..2_113).fake(), | ||
db: temp_dir.path().as_os_str().to_str().unwrap().to_string(), | ||
} | ||
} | ||
|
||
pub fn client_endpoint(options: &Options) -> EndPoint { | ||
EndPoint { | ||
host: options.host.clone(), | ||
port: options.port, | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Dummy)] | ||
pub struct Toto { | ||
pub key: String, | ||
pub value: u64, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
[package] | ||
name = "geth-engine" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies.geth-mikoshi] | ||
path = "../geth-mikoshi" | ||
|
||
[dependencies.geth-common] | ||
path = "../geth-common" | ||
|
||
[dependencies.geth-domain] | ||
path = "../geth-domain" | ||
|
||
[dependencies.tokio] | ||
version = "1.20" | ||
features = ["full"] | ||
|
||
[dependencies.uuid] | ||
version = "1" | ||
features = ["v4"] | ||
|
||
[dependencies.rand] | ||
version = "0.8" | ||
features = ["small_rng"] | ||
|
||
[dependencies.pyro-core] | ||
git = "https://github.com/YoEight/pyro.git" | ||
|
||
[dependencies.pyro-runtime] | ||
git = "https://github.com/YoEight/pyro.git" | ||
|
||
[dependencies.clap] | ||
version = "4.5" | ||
features = ["derive"] | ||
|
||
[dependencies] | ||
tonic = "0.10" | ||
prost = "0.12" | ||
prost-types = "0.12" | ||
prost-derive = "0.12" | ||
tracing = "0.1" | ||
futures = "*" | ||
bytes = "1" | ||
eyre = "0.6" | ||
async-stream = "0.3" | ||
byteorder = "1" | ||
chrono = "0.4" | ||
serde_json = "1" | ||
moka = "0.11" | ||
flatbuffers = "23.5.26" | ||
async-trait = "0.1.71" | ||
|
||
[build-dependencies] | ||
tonic-build = "0.10" |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::path::PathBuf; | ||
use std::sync::Arc; | ||
|
||
use tokio::select; | ||
|
||
use geth_domain::{Lsm, LsmSettings}; | ||
use geth_mikoshi::storage::FileSystemStorage; | ||
use geth_mikoshi::wal::chunks::ChunkBasedWAL; | ||
use geth_mikoshi::wal::WALRef; | ||
|
||
use crate::domain::index::Index; | ||
pub use crate::options::Options; | ||
use crate::process::{InternalClient, Processes}; | ||
|
||
mod bus; | ||
mod domain; | ||
mod grpc; | ||
mod messages; | ||
mod names; | ||
mod options; | ||
mod process; | ||
mod services; | ||
|
||
pub async fn run(options: Options) -> eyre::Result<()> { | ||
let storage = FileSystemStorage::new(PathBuf::from(&options.db))?; | ||
let lsm = Lsm::load(LsmSettings::default(), storage.clone())?; | ||
let index = Index::new(lsm); | ||
let wal = WALRef::new(ChunkBasedWAL::load(storage.clone())?); | ||
let processes = Processes::new(wal, index.clone()); | ||
let sub_client = processes.subscriptions_client().clone(); | ||
let client = Arc::new(InternalClient::new(processes)); | ||
let services = services::start(client.clone(), index, sub_client); | ||
|
||
select! { | ||
server = grpc::start_server(options, client) => { | ||
if let Err(e) = server { | ||
tracing::error!("GethDB node gRPC module crashed: {}", e); | ||
} | ||
} | ||
|
||
_ = services.exited() => { | ||
tracing::info!("GethDB node terminated"); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.