use std::{ collections::HashMap, path::{Path, PathBuf}, sync::Arc, }; use async_trait::async_trait; pub use lb_framework::*; use reqwest::Url; pub use scenario::{ CoreBuilderExt, ObservabilityBuilderExt, ScenarioBuilder, ScenarioBuilderExt, ScenarioBuilderWith, }; use testing_framework_core::scenario::{ Application, DynError, ExternalNodeSource, FeedRuntime, RunContext, StartNodeOptions, }; use testing_framework_runner_local::{ BuiltNodeConfig, LocalDeployerEnv, NodeConfigEntry, process::{LaunchSpec, NodeEndpoints, ProcessSpawnError}, }; use tokio::sync::broadcast; use workloads::{LbcBlockFeedEnv, LbcScenarioEnv}; pub mod cfgsync; mod compose_env; pub mod constants; mod k8s_env; pub mod scenario; pub type LbcComposeDeployer = testing_framework_runner_compose::ComposeDeployer; pub type LbcK8sDeployer = testing_framework_runner_k8s::K8sDeployer; pub struct LbcExtEnv; #[async_trait] impl Application for LbcExtEnv { type Deployment = ::Deployment; type NodeClient = ::NodeClient; type NodeConfig = ::NodeConfig; type FeedRuntime = ::FeedRuntime; fn external_node_client(source: &ExternalNodeSource) -> Result { let base_url = Url::parse(&source.endpoint)?; Ok(NodeHttpClient::from_urls(base_url, None)) } async fn prepare_feed( client: Self::NodeClient, ) -> Result<(::Feed, Self::FeedRuntime), DynError> { ::prepare_feed(client).await } } impl LbcScenarioEnv for LbcExtEnv {} impl LbcBlockFeedEnv for LbcExtEnv { fn block_feed_subscription(ctx: &RunContext) -> broadcast::Receiver> { ctx.feed().subscribe() } } #[async_trait] impl LocalDeployerEnv for LbcExtEnv { fn build_node_config( topology: &Self::Deployment, index: usize, peer_ports_by_name: &HashMap, options: &StartNodeOptions, peer_ports: &[u16], ) -> Result::NodeConfig>, DynError> { let mapped_options = map_start_options(options)?; ::build_node_config( topology, index, peer_ports_by_name, &mapped_options, peer_ports, ) } fn build_initial_node_configs( topology: &Self::Deployment, ) -> Result::NodeConfig>>, ProcessSpawnError> { ::build_initial_node_configs(topology) } fn initial_persist_dir( topology: &Self::Deployment, node_name: &str, index: usize, ) -> Option { ::initial_persist_dir(topology, node_name, index) } fn build_launch_spec( config: &::NodeConfig, dir: &Path, label: &str, ) -> Result { ::build_launch_spec(config, dir, label) } fn node_endpoints(config: &::NodeConfig) -> NodeEndpoints { ::node_endpoints(config) } fn node_client(endpoints: &NodeEndpoints) -> Self::NodeClient { ::node_client(endpoints) } fn readiness_endpoint_path() -> &'static str { ::readiness_endpoint_path() } } fn map_start_options( options: &StartNodeOptions, ) -> Result, DynError> { if options.config_patch.is_some() { return Err("LbcExtEnv local deployer bridge does not support config_patch yet".into()); } let mut mapped = StartNodeOptions::::default(); mapped.peers = options.peers.clone(); mapped.config_override = options.config_override.clone(); mapped.persist_dir = options.persist_dir.clone(); Ok(mapped) }