forked from grafbase/grafbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_runtime.rs
More file actions
68 lines (56 loc) · 1.98 KB
/
test_runtime.rs
File metadata and controls
68 lines (56 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use grafbase_telemetry::{metrics, otel::opentelemetry};
use runtime::{hooks::DynamicHooks, trusted_documents_client};
use runtime_local::{
rate_limiting::in_memory::key_based::InMemoryRateLimiter, InMemoryHotCacheFactory, InMemoryKvStore, NativeFetcher,
};
use runtime_noop::trusted_documents::NoopTrustedDocuments;
use tokio::sync::watch;
pub struct TestRuntime {
pub fetcher: runtime::fetch::Fetcher,
pub trusted_documents: trusted_documents_client::Client,
pub kv: runtime::kv::KvStore,
pub meter: opentelemetry::metrics::Meter,
pub hooks: DynamicHooks,
pub rate_limiter: runtime::rate_limiting::RateLimiter,
}
impl Default for TestRuntime {
fn default() -> Self {
let (_, rx) = watch::channel(Default::default());
Self {
fetcher: NativeFetcher::runtime_fetcher(),
trusted_documents: trusted_documents_client::Client::new(NoopTrustedDocuments),
kv: InMemoryKvStore::runtime(),
meter: metrics::meter_from_global_provider(),
hooks: Default::default(),
rate_limiter: InMemoryRateLimiter::runtime(rx),
}
}
}
impl engine_v2::Runtime for TestRuntime {
type Hooks = DynamicHooks;
type CacheFactory = InMemoryHotCacheFactory;
fn fetcher(&self) -> &runtime::fetch::Fetcher {
&self.fetcher
}
fn kv(&self) -> &runtime::kv::KvStore {
&self.kv
}
fn trusted_documents(&self) -> &trusted_documents_client::Client {
&self.trusted_documents
}
fn meter(&self) -> &opentelemetry::metrics::Meter {
&self.meter
}
fn hooks(&self) -> &Self::Hooks {
&self.hooks
}
fn cache_factory(&self) -> &Self::CacheFactory {
&InMemoryHotCacheFactory
}
fn rate_limiter(&self) -> &runtime::rate_limiting::RateLimiter {
&self.rate_limiter
}
fn sleep(&self, duration: std::time::Duration) -> futures::prelude::future::BoxFuture<'static, ()> {
Box::pin(tokio::time::sleep(duration))
}
}