-
Notifications
You must be signed in to change notification settings - Fork 33
feat: Add SpawnService
and SpawnedReqwestConnector
for running requests on a different runtime
#332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
92ce4c3
feat: spawn service
tustvold 3125289
feat: add SpawnedReqwestConnector
ion-elgreco 207d7aa
chore: add zed settings to .gitignore
ion-elgreco 53039a2
chore: add docs
ion-elgreco dfcc038
Merge remote-tracking branch 'apache/main' into feat/spawn-service
alamb dd4b145
Tweak main page documentation
alamb 2c1bea1
Update documentation and fix example
alamb d076d5c
Fix ci
alamb f5cac09
Add end to end integration test
alamb af2dfc2
cleanup test
alamb c8661cf
use separate bucket for test
alamb 8462b8d
Merge remote-tracking branch 'origin/main' into feat/spawn-service
ion-elgreco 395b35d
try and fix wasm build
alamb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ rusty-tags.vi | |
.flatbuffers/ | ||
.idea/ | ||
.vscode | ||
.zed | ||
.devcontainer | ||
venv/* | ||
# created by doctests | ||
|
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -497,6 +497,7 @@ impl MultipartStore for AmazonS3 { | |
mod tests { | ||
use super::*; | ||
use crate::client::get::GetClient; | ||
use crate::client::SpawnedReqwestConnector; | ||
use crate::integration::*; | ||
use crate::tests::*; | ||
use crate::ClientOptions; | ||
|
@@ -820,4 +821,57 @@ mod tests { | |
store.delete(location).await.unwrap(); | ||
} | ||
} | ||
|
||
/// Integration test that ensures I/O is done on an alternate threadpool | ||
/// when using the `SpawnedReqwestConnector`. | ||
#[test] | ||
fn s3_alternate_threadpool_spawned_request_connector() { | ||
maybe_skip_integration!(); | ||
let (shutdown_tx, shutdown_rx) = tokio::sync::oneshot::channel::<()>(); | ||
|
||
// Runtime with I/O enabled | ||
let io_runtime = tokio::runtime::Builder::new_current_thread() | ||
.enable_all() // <-- turns on IO | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you comment out this line the test fails |
||
.build() | ||
.unwrap(); | ||
|
||
// Runtime without I/O enabled | ||
let non_io_runtime = tokio::runtime::Builder::new_current_thread() | ||
// note: no call to enable_all | ||
.build() | ||
.unwrap(); | ||
|
||
// run the io runtime in a different thread | ||
let io_handle = io_runtime.handle().clone(); | ||
let thread_handle = std::thread::spawn(move || { | ||
io_runtime.block_on(async move { | ||
shutdown_rx.await.unwrap(); | ||
}); | ||
}); | ||
|
||
let store = AmazonS3Builder::from_env() | ||
// use different bucket to avoid collisions with other tests | ||
.with_bucket_name("test-bucket-for-spawn") | ||
.with_http_connector(SpawnedReqwestConnector::new(io_handle)) | ||
.build() | ||
.unwrap(); | ||
|
||
// run a request on the non io runtime -- will fail if the connector | ||
// does not spawn the request to the io runtime | ||
non_io_runtime | ||
.block_on(async move { | ||
let path = Path::from("alternate_threadpool/test.txt"); | ||
store.delete(&path).await.ok(); // remove the file if it exists from prior runs | ||
store.put(&path, "foo".into()).await?; | ||
let res = store.get(&path).await?.bytes().await?; | ||
assert_eq!(res.as_ref(), b"foo"); | ||
store.delete(&path).await?; // cleanup | ||
Ok(()) as Result<()> | ||
}) | ||
.expect("failed to run request on non io runtime"); | ||
|
||
// shutdown the io runtime and thread | ||
shutdown_tx.send(()).ok(); | ||
thread_handle.join().expect("runtime thread panicked"); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,27 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
//! HTTP client abstraction | ||
|
||
mod body; | ||
pub use body::*; | ||
|
||
mod connection; | ||
pub use connection::*; | ||
|
||
mod spawn; | ||
pub use spawn::*; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also wrote this end to end integration test to ensure that everything worked correctly when hooked up to an ObjectStore implementation (and it does!)