Skip to content

Commit 05ab50e

Browse files
authored
feat(server): Add a mock server implementation (#3)
Completely stubbed out grpc server built with tonic, listening on `50051`. It supports the only server message (put_blob) that is currently specified in the protobuf definitions and returns a hard-coded response. Can be used to create a first deployment in sandbox.
1 parent b2e8f74 commit 05ab50e

File tree

5 files changed

+94
-2
lines changed

5 files changed

+94
-2
lines changed

Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
11
[workspace]
22
resolver = "3"
33
members = ["client", "proto-codegen", "server", "service", "stresstest"]
4+
default-members = ["server"]
5+
6+
[profile.dev]
7+
# Debug information slows down the build and increases caches in the
8+
# target folder, but we don't require stack traces in most cases.
9+
debug = false
10+
11+
[profile.dev-debug]
12+
# A version of the dev profile with debug information enabled, for e.g. local
13+
# debugging.
14+
inherits = "dev"
15+
debug = true
16+
17+
[profile.release]
18+
# In release, however, we do want full debug information to report
19+
# panic and error stack traces to Sentry.
20+
debug = true
21+
lto = "thin"

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,19 @@ It currently contains the following pieces:
1010
as well as external clients.
1111
- `service`: The core blob storage primitives.
1212
- `stresstest`: A stresstest binary that can run various workloads against a storage backend.
13+
14+
## Development
15+
16+
Ensure `protoc` and the latest stable Rust toolchain are installed on your machine. Then, run the server with:
17+
18+
```sh
19+
cargo run
20+
```
21+
22+
To run tests:
23+
24+
```sh
25+
cargo test --workspace --all-features
26+
```
27+
28+
We recommend using Rust Analyzer and clippy.

server/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ version = "0.1.0"
44
edition = "2024"
55

66
[dependencies]
7+
tokio = { version = "1.45.1", features = ["full"] }
8+
tonic = { version = "0.13.1" }
9+
proto-codegen = { path = "../proto-codegen" }
710
service = { path = "../service" }

server/src/main.rs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,47 @@
44
//! storage layer as both a `gRPC` service for use by the `client`, as well as
55
//! an `HTTP` layer which can serve files directly to *external clients*.
66
7-
fn main() {
8-
println!("Hello, world!");
7+
use proto_codegen::storage::{AllocateBlobRequest, AllocateBlobResponse, StorageId};
8+
use tonic::{Request, Response, Status, transport::Server};
9+
10+
use proto_codegen::storage::storage_server::{Storage, StorageServer};
11+
12+
#[derive(Default)]
13+
pub struct MockStorage {}
14+
15+
#[tonic::async_trait]
16+
impl Storage for MockStorage {
17+
async fn put_blob(
18+
&self,
19+
request: Request<AllocateBlobRequest>,
20+
) -> Result<Response<AllocateBlobResponse>, Status> {
21+
// Here you would handle the blob upload logic.
22+
println!("Received a blob upload request: {:?}", request);
23+
24+
let storage_id = StorageId {
25+
id: "usecase/4711.0001".to_owned().into_bytes(),
26+
};
27+
28+
let response = AllocateBlobResponse {
29+
id: Some(storage_id),
30+
signed_put_url: "https://localhost:5000/mocked-upload".to_owned(),
31+
};
32+
33+
Ok(Response::new(response))
34+
}
35+
}
36+
37+
#[tokio::main]
38+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
39+
let addr = "0.0.0.0:50051".parse().unwrap();
40+
let greeter = MockStorage::default();
41+
42+
println!("Server listening on {addr}");
43+
44+
Server::builder()
45+
.add_service(StorageServer::new(greeter))
46+
.serve(addr)
47+
.await?;
48+
49+
Ok(())
950
}

0 commit comments

Comments
 (0)