Upgrade to Abscissa v0.5
This commit is contained in:
parent
d3e954cd4a
commit
45eb81a204
File diff suppressed because it is too large
Load Diff
|
@ -8,12 +8,11 @@ edition = "2018"
|
|||
[dependencies]
|
||||
rand = "0.7"
|
||||
chrono = "0.4"
|
||||
abscissa_core = "0.3.0"
|
||||
failure = "0.1"
|
||||
gumdrop = "0.6"
|
||||
lazy_static = "1"
|
||||
abscissa_core = "0.5"
|
||||
gumdrop = "0.7"
|
||||
serde = { version = "1", features = ["serde_derive"] }
|
||||
toml = "0.5"
|
||||
thiserror = "1"
|
||||
|
||||
tokio = { version = "0.2", features = ["time", "rt-threaded", "stream"] }
|
||||
futures = "0.3"
|
||||
|
@ -30,6 +29,6 @@ tower = "0.3"
|
|||
zebra-chain = { path = "../zebra-chain" }
|
||||
zebra-network = { path = "../zebra-network" }
|
||||
|
||||
[dev-dependencies.abscissa_core]
|
||||
version = "0.3.0"
|
||||
features = ["testing"]
|
||||
[dev-dependencies]
|
||||
abscissa_core = { version = "0.5", features = ["testing"] }
|
||||
once_cell = "1.2"
|
||||
|
|
|
@ -2,14 +2,12 @@
|
|||
|
||||
use crate::{commands::ZebradCmd, config::ZebradConfig};
|
||||
use abscissa_core::{
|
||||
application, config, logging, Application, Component, EntryPoint, FrameworkError, StandardPaths,
|
||||
application::{self, AppCell},
|
||||
config, trace, Application, Component, EntryPoint, FrameworkError, StandardPaths,
|
||||
};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
lazy_static! {
|
||||
/// Application state
|
||||
pub static ref APPLICATION: application::Lock<ZebradApp> = application::Lock::default();
|
||||
}
|
||||
/// Application state
|
||||
pub static APPLICATION: AppCell<ZebradApp> = AppCell::new();
|
||||
|
||||
/// Obtain a read-only (multi-reader) lock on the application state.
|
||||
///
|
||||
|
@ -120,11 +118,11 @@ impl Application for ZebradApp {
|
|||
}
|
||||
|
||||
/// Get logging configuration from command-line options
|
||||
fn logging_config(&self, command: &EntryPoint<ZebradCmd>) -> logging::Config {
|
||||
fn tracing_config(&self, command: &EntryPoint<ZebradCmd>) -> trace::Config {
|
||||
if command.verbose {
|
||||
logging::Config::verbose()
|
||||
trace::Config::verbose()
|
||||
} else {
|
||||
logging::Config::default()
|
||||
trace::Config::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
//! `connect` subcommand - test stub for talking to zcashd
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::{
|
||||
error::{Error, ErrorKind},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
use abscissa_core::{Command, Options, Runnable};
|
||||
|
||||
|
@ -34,7 +37,7 @@ impl Runnable for ConnectCmd {
|
|||
}
|
||||
|
||||
impl ConnectCmd {
|
||||
async fn connect(&self) -> Result<(), failure::Error> {
|
||||
async fn connect(&self) -> Result<(), Error> {
|
||||
use zebra_network::{AddressBook, Request, Response};
|
||||
|
||||
info!("begin tower-based peer handling test stub");
|
||||
|
@ -44,7 +47,7 @@ impl ConnectCmd {
|
|||
service_fn(|req| {
|
||||
async move {
|
||||
info!(?req);
|
||||
Ok::<Response, failure::Error>(Response::Ok)
|
||||
Ok::<Response, Error>(Response::Ok)
|
||||
}
|
||||
}),
|
||||
1,
|
||||
|
@ -59,17 +62,22 @@ impl ConnectCmd {
|
|||
let (mut peer_set, _address_book) = zebra_network::init(config, node).await;
|
||||
|
||||
info!("waiting for peer_set ready");
|
||||
peer_set.ready().await.map_err(Error::from_boxed_compat)?;
|
||||
peer_set
|
||||
.ready()
|
||||
.await
|
||||
.map_err(|e| Error::from(ErrorKind::Io.context(e)))?;
|
||||
|
||||
info!("peer_set became ready, constructing addr requests");
|
||||
|
||||
use failure::Error;
|
||||
use futures::stream::{FuturesUnordered, StreamExt};
|
||||
|
||||
let mut addr_reqs = FuturesUnordered::new();
|
||||
for i in 0..10usize {
|
||||
info!(i, "awaiting peer_set ready");
|
||||
peer_set.ready().await.map_err(Error::from_boxed_compat)?;
|
||||
peer_set
|
||||
.ready()
|
||||
.await
|
||||
.map_err(|e| Error::from(ErrorKind::Io.context(e)))?;
|
||||
info!(i, "calling peer_set");
|
||||
addr_reqs.push(peer_set.call(Request::GetPeers));
|
||||
}
|
||||
|
|
|
@ -13,7 +13,10 @@ use tower::{buffer::Buffer, Service, ServiceExt};
|
|||
|
||||
use zebra_network::{AddressBook, BoxedStdError, Request, Response};
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::{
|
||||
error::{Error, ErrorKind},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
/// Whether our `SeedService` is poll_ready or not.
|
||||
#[derive(Debug)]
|
||||
|
@ -120,9 +123,7 @@ impl Runnable for SeedCmd {
|
|||
}
|
||||
|
||||
impl SeedCmd {
|
||||
async fn seed(&self) -> Result<(), failure::Error> {
|
||||
use failure::Error;
|
||||
|
||||
async fn seed(&self) -> Result<(), Error> {
|
||||
info!("begin tower-based peer handling test stub");
|
||||
|
||||
let (addressbook_tx, addressbook_rx) = oneshot::channel();
|
||||
|
@ -138,7 +139,10 @@ impl SeedCmd {
|
|||
let _ = addressbook_tx.send(address_book);
|
||||
|
||||
info!("waiting for peer_set ready");
|
||||
peer_set.ready().await.map_err(Error::from_boxed_compat)?;
|
||||
peer_set
|
||||
.ready()
|
||||
.await
|
||||
.map_err(|e| Error::from(ErrorKind::Io.context(e)))?;
|
||||
|
||||
info!("peer_set became ready");
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use crate::components::tokio::TokioComponent;
|
||||
|
||||
use abscissa_core::{err, Component, FrameworkError, FrameworkErrorKind};
|
||||
use abscissa_core::{format_err, Component, FrameworkError, FrameworkErrorKind};
|
||||
|
||||
use hyper::service::{make_service_fn, service_fn};
|
||||
use hyper::{Body, Request, Response, Server};
|
||||
|
@ -34,7 +34,7 @@ impl TracingEndpoint {
|
|||
// XXX this is only required if we have a dependency that uses log;
|
||||
// currently this is maybe only abscissa itself?
|
||||
LogTracer::init().map_err(|e| {
|
||||
err!(
|
||||
format_err!(
|
||||
FrameworkErrorKind::ComponentError,
|
||||
"could not set log subscriber: {}",
|
||||
e
|
||||
|
@ -52,7 +52,7 @@ impl TracingEndpoint {
|
|||
|
||||
// Set that subscriber to be the global tracing subscriber
|
||||
tracing::subscriber::set_global_default(subscriber).map_err(|e| {
|
||||
err!(
|
||||
format_err!(
|
||||
FrameworkErrorKind::ComponentError,
|
||||
"could not set tracing subscriber: {}",
|
||||
e
|
||||
|
|
|
@ -4,13 +4,12 @@
|
|||
//! application's configuration file and/or command-line options
|
||||
//! for specifying it.
|
||||
|
||||
use abscissa_core::Config;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use zebra_network::Config as NetworkSection;
|
||||
|
||||
/// Zebrad Configuration
|
||||
#[derive(Clone, Config, Default, Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Default, Debug, Deserialize, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ZebradConfig {
|
||||
/// Tracing configuration
|
||||
|
|
|
@ -1,39 +1,64 @@
|
|||
//! Error types
|
||||
|
||||
use abscissa_core::err;
|
||||
use failure::Fail;
|
||||
use std::{fmt, io};
|
||||
|
||||
/// Error type
|
||||
#[derive(Debug)]
|
||||
pub struct Error(abscissa_core::Error<ErrorKind>);
|
||||
use abscissa_core::error::{BoxError, Context};
|
||||
use std::{
|
||||
fmt::{self, Display},
|
||||
io,
|
||||
ops::Deref,
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
/// Kinds of errors
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug, Fail)]
|
||||
#[derive(Copy, Clone, Debug, Eq, Error, PartialEq)]
|
||||
pub enum ErrorKind {
|
||||
/// Error in configuration file
|
||||
#[fail(display = "config error")]
|
||||
#[error("config error")]
|
||||
Config,
|
||||
|
||||
/// Input/output error
|
||||
#[fail(display = "I/O error")]
|
||||
#[error("I/O error")]
|
||||
Io,
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
impl ErrorKind {
|
||||
/// Create an error context from this error
|
||||
pub fn context(self, source: impl Into<BoxError>) -> Context<ErrorKind> {
|
||||
Context::new(self, Some(source.into()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Error type
|
||||
#[derive(Debug)]
|
||||
pub struct Error(Box<Context<ErrorKind>>);
|
||||
|
||||
impl Deref for Error {
|
||||
type Target = Context<ErrorKind>;
|
||||
|
||||
fn deref(&self) -> &Context<ErrorKind> {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<abscissa_core::Error<ErrorKind>> for Error {
|
||||
fn from(other: abscissa_core::Error<ErrorKind>) -> Self {
|
||||
Error(other)
|
||||
impl From<Context<ErrorKind>> for Error {
|
||||
fn from(context: Context<ErrorKind>) -> Self {
|
||||
Error(Box::new(context))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(other: io::Error) -> Self {
|
||||
err!(ErrorKind::Io, other).into()
|
||||
ErrorKind::Io.context(other).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
self.0.source()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
|
||||
#[macro_use]
|
||||
extern crate tracing;
|
||||
#[macro_use]
|
||||
extern crate failure;
|
||||
|
||||
mod components;
|
||||
|
||||
|
|
|
@ -7,13 +7,9 @@ pub use crate::application::{app_config, app_reader, app_writer};
|
|||
/// Commonly used Abscissa traits
|
||||
pub use abscissa_core::{Application, Command, Runnable};
|
||||
|
||||
// These are disabled because we use tracing.
|
||||
// Logging macros
|
||||
//pub use abscissa_core::log::{debug, error, info, log, log_enabled, trace, warn};
|
||||
|
||||
/// Type alias to make working with tower traits easier.
|
||||
///
|
||||
/// Note: the 'static lifetime bound means that the *type* cannot have any
|
||||
/// non-'static lifetimes, (e.g., when a type contains a borrow and is
|
||||
/// parameterized by 'a), *not* that the object itself has 'static lifetime.
|
||||
pub(crate) type BoxedStdError = Box<dyn std::error::Error + Send + Sync + 'static>;
|
||||
pub(crate) use abscissa_core::error::BoxError;
|
||||
|
|
|
@ -11,17 +11,10 @@
|
|||
#![forbid(unsafe_code)]
|
||||
|
||||
use abscissa_core::testing::prelude::*;
|
||||
use lazy_static::lazy_static;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
lazy_static! {
|
||||
/// Executes your application binary via `cargo run`.
|
||||
///
|
||||
/// Storing this value in a `lazy_static!` ensures that all instances of
|
||||
/// the runner acquire a mutex when executing commands and inspecting
|
||||
/// exit statuses, serializing what would otherwise be multithreaded
|
||||
/// invocations as `cargo test` executes tests in parallel by default.
|
||||
pub static ref RUNNER: CmdRunner = CmdRunner::default();
|
||||
}
|
||||
/// Executes your application binary via `cargo run`.
|
||||
pub static RUNNER: Lazy<CmdRunner> = Lazy::new(|| CmdRunner::default());
|
||||
|
||||
/// Example of a test which matches a regular expression
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue