You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2023/04/21 13:42:30 UTC
[incubator-opendal] 03/03: fix: MadsimLayer should be able to built without cfg
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch fix-madsim
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
commit 6d31a9a813db0ca638de1fe8818d862f6380ba8c
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Fri Apr 21 21:42:03 2023 +0800
fix: MadsimLayer should be able to built without cfg
Signed-off-by: Xuanwo <gi...@xuanwo.io>
---
core/src/layers/madsim.rs | 67 ++++++++++++++++++++++++++++++++++++-----------
1 file changed, 51 insertions(+), 16 deletions(-)
diff --git a/core/src/layers/madsim.rs b/core/src/layers/madsim.rs
index 4c1956fe..2e0cf441 100644
--- a/core/src/layers/madsim.rs
+++ b/core/src/layers/madsim.rs
@@ -15,6 +15,12 @@
// specific language governing permissions and limitations
// under the License.
+// This module requires to be work under `cfg(madsim)` so we will allow
+// dead code and unused variables.
+#![allow(unused_imports)]
+#![allow(unused_variables)]
+#![allow(dead_code)]
+
use std::any::Any;
use std::collections::HashMap;
use std::fmt::Debug;
@@ -28,7 +34,10 @@ use std::task::Poll;
use async_trait::async_trait;
use bytes::Bytes;
+#[cfg(madsim)]
use madsim::net::Endpoint;
+#[cfg(madsim)]
+use madsim::net::Payload;
use crate::ops::*;
use crate::raw::oio;
@@ -36,8 +45,6 @@ use crate::raw::oio::Entry;
use crate::raw::*;
use crate::*;
-pub type Payload = Box<dyn Any + Send + Sync>;
-
/// Add deterministic simulation for async operations, powered by [`madsim`](https://docs.rs/madsim/latest/madsim/).
///
/// # Note
@@ -95,13 +102,22 @@ pub type Payload = Box<dyn Any + Send + Sync>;
/// ```
#[derive(Debug, Copy, Clone)]
pub struct MadsimLayer {
+ #[cfg(madsim)]
addr: SocketAddr,
}
impl MadsimLayer {
+ /// Createa new madsim layer
pub fn new(endpoint: &str) -> Self {
- Self {
- addr: endpoint.parse().unwrap(),
+ #[cfg(madsim)]
+ {
+ Self {
+ addr: endpoint.parse().unwrap(),
+ }
+ }
+ #[cfg(not(madsim))]
+ {
+ unreachable!("madsim is not enabled")
}
}
}
@@ -110,12 +126,20 @@ impl<A: Accessor> Layer<A> for MadsimLayer {
type LayeredAccessor = MadsimAccessor;
fn layer(&self, _: A) -> Self::LayeredAccessor {
- MadsimAccessor { addr: self.addr }
+ #[cfg(madsim)]
+ {
+ MadsimAccessor { addr: self.addr }
+ }
+ #[cfg(not(madsim))]
+ {
+ unreachable!("madsim is not enabled")
+ }
}
}
#[derive(Debug)]
pub struct MadsimAccessor {
+ #[cfg(madsim)]
addr: SocketAddr,
}
@@ -180,14 +204,21 @@ impl LayeredAccessor for MadsimAccessor {
}
async fn write(&self, path: &str, args: OpWrite) -> crate::Result<(RpWrite, Self::Writer)> {
- Ok((
- RpWrite::default(),
- MadsimWriter {
- path: path.to_string(),
- args,
- addr: self.addr,
- },
- ))
+ #[cfg(madsim)]
+ {
+ Ok((
+ RpWrite::default(),
+ MadsimWriter {
+ path: path.to_string(),
+ args,
+ addr: self.addr,
+ },
+ ))
+ }
+ #[cfg(not(madsim))]
+ {
+ unreachable!("madsim is not enabled")
+ }
}
async fn list(&self, path: &str, args: OpList) -> crate::Result<(RpList, Self::Pager)> {
@@ -254,7 +285,7 @@ pub struct MadsimReader {
}
impl oio::Read for MadsimReader {
- fn poll_read(&mut self, _cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<crate::Result<usize>> {
+ fn poll_read(&mut self, _: &mut Context<'_>, buf: &mut [u8]) -> Poll<crate::Result<usize>> {
if let Some(ref data) = self.data {
let len = data.len();
buf[..len].copy_from_slice(data);
@@ -264,14 +295,14 @@ impl oio::Read for MadsimReader {
}
}
- fn poll_seek(&mut self, cx: &mut Context<'_>, pos: SeekFrom) -> Poll<crate::Result<u64>> {
+ fn poll_seek(&mut self, _: &mut Context<'_>, _: SeekFrom) -> Poll<crate::Result<u64>> {
Poll::Ready(Err(Error::new(
ErrorKind::Unsupported,
"will be supported in the future",
)))
}
- fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll<Option<crate::Result<Bytes>>> {
+ fn poll_next(&mut self, _: &mut Context<'_>) -> Poll<Option<crate::Result<Bytes>>> {
Poll::Ready(Some(Err(Error::new(
ErrorKind::Unsupported,
"will be supported in the future",
@@ -280,8 +311,11 @@ impl oio::Read for MadsimReader {
}
pub struct MadsimWriter {
+ #[cfg(madsim)]
path: String,
+ #[cfg(madsim)]
args: OpWrite,
+ #[cfg(madsim)]
addr: SocketAddr,
}
@@ -338,6 +372,7 @@ impl From<std::io::Error> for Error {
pub struct MadsimServer;
impl MadsimServer {
+ /// Start serving as madsim server.
pub async fn serve(addr: SocketAddr) -> Result<()> {
#[cfg(madsim)]
{