This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch fix-behavor-test-for-blocking-layer
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git

commit 09a94bb9d364ead07af386bdd6745d1389d942b4
Author: Xuanwo <[email protected]>
AuthorDate: Tue Aug 8 11:41:36 2023 +0800

    fix: Fix behaivor tests for blocking layer
    
    Signed-off-by: Xuanwo <[email protected]>
---
 core/src/layers/blocking.rs           |  7 +++----
 core/src/services/dropbox/error.rs    |  1 +
 core/tests/behavior/blocking_write.rs | 34 +++++++++++++++++++++++++++++++++-
 core/tests/behavior/utils.rs          |  3 ++-
 4 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/core/src/layers/blocking.rs b/core/src/layers/blocking.rs
index ef492d7eb..a9f8e0df4 100644
--- a/core/src/layers/blocking.rs
+++ b/core/src/layers/blocking.rs
@@ -189,8 +189,7 @@ impl<I> BlockingWrapper<I> {
 
 impl<I: oio::Read + 'static> oio::BlockingRead for BlockingWrapper<I> {
     fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
-        self.handle
-            .block_on(oio::ReadExt::read(&mut self.inner, buf))
+        self.handle.block_on(self.inner.read(buf))
     }
 
     fn seek(&mut self, pos: std::io::SeekFrom) -> Result<u64> {
@@ -204,11 +203,11 @@ impl<I: oio::Read + 'static> oio::BlockingRead for 
BlockingWrapper<I> {
 
 impl<I: oio::Write + 'static> oio::BlockingWrite for BlockingWrapper<I> {
     fn write(&mut self, bs: Bytes) -> Result<()> {
-        self.handle.block_on(oio::Write::write(&mut self.inner, bs))
+        self.handle.block_on(self.inner.write(bs))
     }
 
     fn close(&mut self) -> Result<()> {
-        self.handle.block_on(oio::Write::close(&mut self.inner))
+        self.handle.block_on(self.inner.close())
     }
 }
 
diff --git a/core/src/services/dropbox/error.rs 
b/core/src/services/dropbox/error.rs
index f25f298af..ae731df78 100644
--- a/core/src/services/dropbox/error.rs
+++ b/core/src/services/dropbox/error.rs
@@ -38,6 +38,7 @@ pub async fn parse_error(resp: Response<IncomingAsyncBody>) 
-> Result<Error> {
     let (mut kind, mut retryable) = match parts.status {
         StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
         StatusCode::FORBIDDEN => (ErrorKind::PermissionDenied, false),
+        StatusCode::TOO_MANY_REQUESTS => (ErrorKind::RateLimited, true),
         StatusCode::INTERNAL_SERVER_ERROR
         | StatusCode::BAD_GATEWAY
         | StatusCode::SERVICE_UNAVAILABLE
diff --git a/core/tests/behavior/blocking_write.rs 
b/core/tests/behavior/blocking_write.rs
index 3775509c2..62838d8e0 100644
--- a/core/tests/behavior/blocking_write.rs
+++ b/core/tests/behavior/blocking_write.rs
@@ -19,7 +19,7 @@ use std::io::Read;
 use std::io::Seek;
 
 use anyhow::Result;
-use log::debug;
+use log::{debug, warn};
 use sha2::Digest;
 use sha2::Sha256;
 
@@ -112,6 +112,12 @@ pub fn test_blocking_write_with_dir_path(op: 
BlockingOperator) -> Result<()> {
 
 /// Write a single file with special chars should succeed.
 pub fn test_blocking_write_with_special_chars(op: BlockingOperator) -> 
Result<()> {
+    // Ignore test for supabase until 
https://github.com/apache/incubator-opendal/issues/2194 addressed.
+    if op.info().scheme() == opendal::Scheme::Supabase {
+        warn!("ignore test for supabase until 
https://github.com/apache/incubator-opendal/issues/2194 is resolved");
+        return Ok(());
+    }
+
     let path = format!("{} !@#$%^&()_+-=;',.txt", uuid::Uuid::new_v4());
     debug!("Generate a random file: {}", &path);
     let (content, size) = gen_bytes();
@@ -156,6 +162,12 @@ pub fn test_blocking_stat_dir(op: BlockingOperator) -> 
Result<()> {
 
 /// Stat existing file with special chars should return metadata
 pub fn test_blocking_stat_with_special_chars(op: BlockingOperator) -> 
Result<()> {
+    // Ignore test for supabase until 
https://github.com/apache/incubator-opendal/issues/2194 addressed.
+    if op.info().scheme() == opendal::Scheme::Supabase {
+        warn!("ignore test for supabase until 
https://github.com/apache/incubator-opendal/issues/2194 is resolved");
+        return Ok(());
+    }
+
     let path = format!("{} !@#$%^&()_+-=;',.txt", uuid::Uuid::new_v4());
     debug!("Generate a random file: {}", &path);
     let (content, size) = gen_bytes();
@@ -204,6 +216,10 @@ pub fn test_blocking_read_full(op: BlockingOperator) -> 
Result<()> {
 
 /// Read range content should match.
 pub fn test_blocking_read_range(op: BlockingOperator) -> Result<()> {
+    if !op.info().capability().read_with_range {
+        return Ok(());
+    }
+
     let path = uuid::Uuid::new_v4().to_string();
     debug!("Generate a random file: {}", &path);
     let (content, size) = gen_bytes();
@@ -229,6 +245,10 @@ pub fn test_blocking_read_range(op: BlockingOperator) -> 
Result<()> {
 
 /// Read large range content should match.
 pub fn test_blocking_read_large_range(op: BlockingOperator) -> Result<()> {
+    if !op.info().capability().read_with_range {
+        return Ok(());
+    }
+
     let path = uuid::Uuid::new_v4().to_string();
     debug!("Generate a random file: {}", &path);
     let (content, size) = gen_bytes();
@@ -265,6 +285,10 @@ pub fn test_blocking_read_not_exist(op: BlockingOperator) 
-> Result<()> {
 }
 
 pub fn test_blocking_fuzz_range_reader(op: BlockingOperator) -> Result<()> {
+    if !op.info().capability().read_with_range {
+        return Ok(());
+    }
+
     let path = uuid::Uuid::new_v4().to_string();
     debug!("Generate a random file: {}", &path);
     let (content, _) = gen_bytes();
@@ -298,6 +322,10 @@ pub fn test_blocking_fuzz_range_reader(op: 
BlockingOperator) -> Result<()> {
 }
 
 pub fn test_blocking_fuzz_offset_reader(op: BlockingOperator) -> Result<()> {
+    if !op.info().capability().read_with_range {
+        return Ok(());
+    }
+
     let path = uuid::Uuid::new_v4().to_string();
     debug!("Generate a random file: {}", &path);
     let (content, _) = gen_bytes();
@@ -331,6 +359,10 @@ pub fn test_blocking_fuzz_offset_reader(op: 
BlockingOperator) -> Result<()> {
 }
 
 pub fn test_blocking_fuzz_part_reader(op: BlockingOperator) -> Result<()> {
+    if !op.info().capability().read_with_range {
+        return Ok(());
+    }
+
     let path = uuid::Uuid::new_v4().to_string();
     debug!("Generate a random file: {}", &path);
     let (content, size) = gen_bytes();
diff --git a/core/tests/behavior/utils.rs b/core/tests/behavior/utils.rs
index 62b6eccf2..5913a11ae 100644
--- a/core/tests/behavior/utils.rs
+++ b/core/tests/behavior/utils.rs
@@ -28,6 +28,7 @@ use futures::Future;
 use libtest_mimic::Failed;
 use libtest_mimic::Trial;
 use log::debug;
+use opendal::layers::BlockingLayer;
 use opendal::layers::LoggingLayer;
 use opendal::layers::RetryLayer;
 use opendal::layers::TimeoutLayer;
@@ -83,7 +84,7 @@ pub fn init_service<B: Builder>() -> Option<Operator> {
 
     let _guard = RUNTIME.enter();
     let op = op
-        // .layer(BlockingLayer::create().expect("blocking layer must be 
created"))
+        .layer(BlockingLayer::create().expect("blocking layer must be 
created"))
         .layer(LoggingLayer::default())
         .layer(TimeoutLayer::new())
         .layer(RetryLayer::new())

Reply via email to