diff --git a/.circleci/config.yml b/.circleci/config.yml index c41efdbf9..ba992d936 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -104,7 +104,14 @@ jobs: # refresh to get the packages apt-get update apt-get install google-cloud-cli-cbt -y + # create the baseline (for unit tests) cbt -project test -instance test createtable autopush + cbt -project test -instance test createfamily autopush message + cbt -project test -instance test createfamily autopush message_topic + cbt -project test -instance test createfamily autopush router + cbt -project test -instance test setgcpolicy autopush message maxage=1s + cbt -project test -instance test setgcpolicy autopush message_topic maxversions=1 + cbt -project test -instance test setgcpolicy autopush router maxversions=1 - run: name: Check formatting command: | @@ -114,6 +121,8 @@ jobs: name: Rust tests environment: BIGTABLE_EMULATOR_HOST: localhost:8080 + AUTOCONNECT__DB_DSN: dual + AUTOCONNECT__DB_SETTINGS: "{\"primary\":{\"db_settings\":\"{\\\"message_family\\\":\\\"message\\\",\\\"router_family\\\":\\\"router\\\",\\\"message_topic_family\\\":\\\"message_topic\\\",\\\"table_name\\\":\\\"projects/test/instances/test/tables/autopush\\\"}\",\"dsn\":\"grpc://locahost:8080\"},\"secondary\":{\"db_settings\":\"{\\\"message_table\\\":\\\"test_message\\\",\\\"router_table\\\":\\\"test_router\\\"}\",\"dsn\":\"http://localhost:8000/\"}}" command: cargo test --jobs=8 --features=dual --features=emulator - run: name: Integration tests (Autopush Legacy) diff --git a/autoendpoint/Cargo.toml b/autoendpoint/Cargo.toml index 8898082e8..f7bdc93da 100644 --- a/autoendpoint/Cargo.toml +++ b/autoendpoint/Cargo.toml @@ -65,6 +65,8 @@ tempfile = "3.2.0" tokio = { workspace = true, features = ["fs", "macros"] } [features] +default = ["dynamodb"] +dynamodb = [] emulator = ["bigtable"] dual = ["bigtable"] bigtable = ["autopush_common/bigtable"] diff --git a/autoendpoint/src/server.rs b/autoendpoint/src/server.rs index c0043a239..1b6c506ee 100644 --- a/autoendpoint/src/server.rs +++ b/autoendpoint/src/server.rs @@ -9,14 +9,17 @@ use actix_web::{ }; #[cfg(feature = "bigtable")] use autopush_common::db::bigtable::BigTableClientImpl; -#[cfg(all(feature = "dual"))] +#[cfg(feature = "dual")] use autopush_common::db::dual::DualClientImpl; use cadence::StatsdClient; use fernet::MultiFernet; use serde_json::json; +#[cfg(feature = "dynamodb")] +use autopush_common::db::dynamodb::DdbClientImpl; + use autopush_common::{ - db::{client::DbClient, dynamodb::DdbClientImpl, DbSettings, StorageType}, + db::{client::DbClient, DbSettings, StorageType}, middleware::sentry::SentryWrapper, }; @@ -65,6 +68,7 @@ impl Server { }, }; let db: Box = match StorageType::from_dsn(&db_settings.dsn) { + #[cfg(feature = "dynamodb")] StorageType::DynamoDb => { debug!("Using Dynamodb"); Box::new(DdbClientImpl::new(metrics.clone(), &db_settings)?) diff --git a/autopush-common/src/db/bigtable/bigtable_client/mod.rs b/autopush-common/src/db/bigtable/bigtable_client/mod.rs index f9fc40426..a6f34b32f 100644 --- a/autopush-common/src/db/bigtable/bigtable_client/mod.rs +++ b/autopush-common/src/db/bigtable/bigtable_client/mod.rs @@ -1081,10 +1081,18 @@ mod tests { } fn new_client() -> DbResult { + let env_dsn = format!( + "grpc://{}", + std::env::var("BIGTABLE_EMULATOR_HOST").unwrap_or("localhost:8080".to_owned()) + ); + println!("env_dsn: {:?}", &env_dsn); let settings = DbSettings { // this presumes the table was created with - // `cbt -project test -instance test createtable autopush` - dsn: Some("grpc://localhost:8086".to_owned()), + // ``` + // cbt -project test -instance test createtable autopush + // ``` + // with `message`, `router`, and `message_topic` families + dsn: Some(env_dsn), db_settings: json!({"table_name":"projects/test/instances/test/tables/autopush"}) .to_string(), }; @@ -1130,6 +1138,7 @@ mod tests { // can we add the user? let user = client.add_user(&test_user).await; + println!("User: {:?}", user); assert!(user.is_ok()); let fetched = client.get_user(&uaid).await.unwrap(); assert!(fetched.is_some()); diff --git a/autopush-common/src/db/mod.rs b/autopush-common/src/db/mod.rs index 3d4416246..519be5a33 100644 --- a/autopush-common/src/db/mod.rs +++ b/autopush-common/src/db/mod.rs @@ -22,11 +22,11 @@ use crate::db::{dynamodb::has_connected_this_month, util::generate_last_connect} #[cfg(feature = "bigtable")] pub mod bigtable; -#[cfg(feature = "dynamodb")] -pub mod dynamodb; +pub mod client; #[cfg(all(feature = "bigtable", feature = "dynamodb"))] pub mod dual; -pub mod client; +#[cfg(feature = "dynamodb")] +pub mod dynamodb; pub mod error; pub mod models; mod util;