refactor(router): Simplify builder code patterns
Use more fluent method names and leverage defaulting to remove the need for an option on the namespace autocreate policy.pull/24376/head
parent
2c4908bf51
commit
392972a3ad
|
@ -37,25 +37,22 @@ pub fn test_context() -> TestContextBuilder {
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct TestContextBuilder {
|
pub struct TestContextBuilder {
|
||||||
namespace_autocreate_policy: Option<NamespaceAutocreatePolicy>,
|
namespace_autocreate_policy: NamespaceAutocreatePolicy,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestContextBuilder {
|
impl TestContextBuilder {
|
||||||
pub fn autocreate_namespace(mut self, enabled: bool) -> Self {
|
pub fn with_autocreate_namespace(mut self, enabled: bool) -> Self {
|
||||||
self.namespace_autocreate_policy = match self.namespace_autocreate_policy {
|
self.namespace_autocreate_policy = NamespaceAutocreatePolicy {
|
||||||
Some(p) => Some(NamespaceAutocreatePolicy { enabled, ..p }),
|
enabled,
|
||||||
None => Some(NamespaceAutocreatePolicy::new(true, None)),
|
..self.namespace_autocreate_policy
|
||||||
};
|
};
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn autocreate_namespace_retention_period_nanos(mut self, period_nanos: i64) -> Self {
|
pub fn with_autocreate_namespace_retention_period_nanos(mut self, period_nanos: i64) -> Self {
|
||||||
self.namespace_autocreate_policy = match self.namespace_autocreate_policy {
|
self.namespace_autocreate_policy = NamespaceAutocreatePolicy {
|
||||||
Some(p) => Some(NamespaceAutocreatePolicy {
|
|
||||||
retention_period_nanos: Some(period_nanos),
|
retention_period_nanos: Some(period_nanos),
|
||||||
..p
|
..self.namespace_autocreate_policy
|
||||||
}),
|
|
||||||
None => Some(NamespaceAutocreatePolicy::new(false, Some(period_nanos))),
|
|
||||||
};
|
};
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -67,8 +64,7 @@ impl TestContextBuilder {
|
||||||
|
|
||||||
test_helpers::maybe_start_logging();
|
test_helpers::maybe_start_logging();
|
||||||
|
|
||||||
let namespace_autocreate_policy = namespace_autocreate_policy
|
let namespace_autocreate_policy = namespace_autocreate_policy;
|
||||||
.unwrap_or_else(|| NamespaceAutocreatePolicy::new(false, None));
|
|
||||||
|
|
||||||
let metrics: Arc<metric::Registry> = Default::default();
|
let metrics: Arc<metric::Registry> = Default::default();
|
||||||
|
|
||||||
|
@ -78,21 +74,12 @@ impl TestContextBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
struct NamespaceAutocreatePolicy {
|
struct NamespaceAutocreatePolicy {
|
||||||
enabled: bool,
|
enabled: bool,
|
||||||
retention_period_nanos: Option<i64>,
|
retention_period_nanos: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NamespaceAutocreatePolicy {
|
|
||||||
fn new(enabled: bool, retention_period_nanos: Option<i64>) -> Self {
|
|
||||||
Self {
|
|
||||||
enabled,
|
|
||||||
retention_period_nanos,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TestContext {
|
pub struct TestContext {
|
||||||
client: Arc<MockWriteClient>,
|
client: Arc<MockWriteClient>,
|
||||||
|
|
|
@ -140,7 +140,7 @@ async fn test_namespace_create() {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_namespace_delete() {
|
async fn test_namespace_delete() {
|
||||||
// Initialise a TestContext with implicit namespace creation.
|
// Initialise a TestContext with implicit namespace creation.
|
||||||
let ctx = test_context().autocreate_namespace(true).build().await;
|
let ctx = test_context().with_autocreate_namespace(true).build().await;
|
||||||
|
|
||||||
const RETENTION: i64 = Duration::from_secs(42 * 60 * 60).as_nanos() as _;
|
const RETENTION: i64 = Duration::from_secs(42 * 60 * 60).as_nanos() as _;
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub mod common;
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_write_ok() {
|
async fn test_write_ok() {
|
||||||
// Create a test context with implicit namespace creation.
|
// Create a test context with implicit namespace creation.
|
||||||
let ctx = test_context().autocreate_namespace(true).build().await;
|
let ctx = test_context().with_autocreate_namespace(true).build().await;
|
||||||
|
|
||||||
// Write data inside retention period
|
// Write data inside retention period
|
||||||
let now = SystemProvider::default()
|
let now = SystemProvider::default()
|
||||||
|
@ -91,8 +91,8 @@ async fn test_write_ok() {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_write_outside_retention_period() {
|
async fn test_write_outside_retention_period() {
|
||||||
let ctx = test_context()
|
let ctx = test_context()
|
||||||
.autocreate_namespace(true)
|
.with_autocreate_namespace(true)
|
||||||
.autocreate_namespace_retention_period_nanos(TEST_RETENTION_PERIOD_NS)
|
.with_autocreate_namespace_retention_period_nanos(TEST_RETENTION_PERIOD_NS)
|
||||||
.build()
|
.build()
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ async fn test_write_outside_retention_period() {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_schema_conflict() {
|
async fn test_schema_conflict() {
|
||||||
let ctx = test_context().autocreate_namespace(true).build().await;
|
let ctx = test_context().with_autocreate_namespace(true).build().await;
|
||||||
|
|
||||||
// data inside the retention period
|
// data inside the retention period
|
||||||
let now = SystemProvider::default()
|
let now = SystemProvider::default()
|
||||||
|
@ -199,7 +199,7 @@ async fn test_rejected_ns() {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_schema_limit() {
|
async fn test_schema_limit() {
|
||||||
let ctx = test_context().autocreate_namespace(true).build().await;
|
let ctx = test_context().with_autocreate_namespace(true).build().await;
|
||||||
|
|
||||||
let now = SystemProvider::default()
|
let now = SystemProvider::default()
|
||||||
.now()
|
.now()
|
||||||
|
@ -253,7 +253,7 @@ async fn test_schema_limit() {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_write_propagate_ids() {
|
async fn test_write_propagate_ids() {
|
||||||
let ctx = test_context().autocreate_namespace(true).build().await;
|
let ctx = test_context().with_autocreate_namespace(true).build().await;
|
||||||
|
|
||||||
// Create the namespace and a set of tables.
|
// Create the namespace and a set of tables.
|
||||||
let ns = ctx
|
let ns = ctx
|
||||||
|
@ -338,7 +338,7 @@ async fn test_write_propagate_ids() {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_delete_unsupported() {
|
async fn test_delete_unsupported() {
|
||||||
let ctx = test_context().autocreate_namespace(true).build().await;
|
let ctx = test_context().with_autocreate_namespace(true).build().await;
|
||||||
|
|
||||||
// Create the namespace and a set of tables.
|
// Create the namespace and a set of tables.
|
||||||
ctx.catalog()
|
ctx.catalog()
|
||||||
|
|
Loading…
Reference in New Issue