Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
142 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,37 @@ | ||
// Copyright 2020 Nathan (Blaise) Bruer. All rights reserved. | ||
|
||
extern crate cas_server; | ||
extern crate store; | ||
|
||
use tonic::Request; | ||
|
||
use proto::build::bazel::remote::execution::v2::Digest; | ||
|
||
use cas_server::CasServer; | ||
use store::{create_store, StoreType}; | ||
|
||
#[cfg(test)] | ||
mod find_missing_blobs { | ||
use super::*; | ||
|
||
use proto::build::bazel::remote::execution::v2::{ | ||
content_addressable_storage_server::ContentAddressableStorage, FindMissingBlobsRequest, | ||
}; | ||
|
||
#[tokio::test] | ||
async fn empty_store() { | ||
let cas_server = CasServer::new(create_store(&StoreType::Memory)); | ||
let raw_response = cas_server | ||
.find_missing_blobs(Request::new(FindMissingBlobsRequest { | ||
instance_name: "foo".to_string(), | ||
blob_digests: vec![Digest { | ||
hash: "".to_string(), | ||
size_bytes: 0, | ||
}], | ||
})) | ||
.await; | ||
assert!(raw_response.is_ok()); | ||
let response = raw_response.unwrap().into_inner(); | ||
assert_eq!(response.missing_blob_digests.len(), 1); | ||
} | ||
} |
This file contains 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,26 @@ | ||
# Copyright 2020 Nathan (Blaise) Bruer. All rights reserved. | ||
|
||
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library") | ||
|
||
rust_library( | ||
name = "store", | ||
srcs = ["lib.rs"], | ||
deps = [ | ||
":memory_store", | ||
":traits", | ||
], | ||
visibility = ["//cas:__pkg__", "//cas:__subpackages__"] | ||
) | ||
|
||
rust_library( | ||
name = "traits", | ||
srcs = ["store_trait.rs"], | ||
visibility = ["//cas:__pkg__"] | ||
) | ||
|
||
rust_library( | ||
name = "memory_store", | ||
srcs = ["memory_store.rs"], | ||
deps = [":traits"], | ||
visibility = ["//cas:__pkg__"] | ||
) |
This file contains 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,15 @@ | ||
// Copyright 2020 Nathan (Blaise) Bruer. All rights reserved. | ||
|
||
pub use traits::StoreTrait as Store; | ||
|
||
use memory_store::MemoryStore; | ||
|
||
pub enum StoreType { | ||
Memory, | ||
} | ||
|
||
pub fn create_store(store_type: &StoreType) -> Box<dyn Store> { | ||
match store_type { | ||
StoreType::Memory => Box::new(MemoryStore::new()), | ||
} | ||
} |
This file contains 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,18 @@ | ||
// Copyright 2020 Nathan (Blaise) Bruer. All rights reserved. | ||
|
||
use traits::StoreTrait; | ||
|
||
#[derive(Debug)] | ||
pub struct MemoryStore {} | ||
|
||
impl MemoryStore { | ||
pub fn new() -> Self { | ||
MemoryStore {} | ||
} | ||
} | ||
|
||
impl StoreTrait for MemoryStore { | ||
fn has(&self, _hash: &str) -> bool { | ||
false | ||
} | ||
} |
This file contains 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,7 @@ | ||
// Copyright 2020 Nathan (Blaise) Bruer. All rights reserved. | ||
|
||
use std::fmt::Debug; | ||
|
||
pub trait StoreTrait: Sync + Send + Debug { | ||
fn has(&self, hash: &str) -> bool; | ||
} |