Skip to content

Commit

Permalink
f fix clippy issues, put all ddb stuff under feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jrconlin committed Jul 28, 2023
1 parent ae4c196 commit fae3f73
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions autoendpoint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
8 changes: 6 additions & 2 deletions autoendpoint/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -65,6 +68,7 @@ impl Server {
},
};
let db: Box<dyn DbClient> = match StorageType::from_dsn(&db_settings.dsn) {
#[cfg(feature = "dynamodb")]
StorageType::DynamoDb => {
debug!("Using Dynamodb");
Box::new(DdbClientImpl::new(metrics.clone(), &db_settings)?)
Expand Down
13 changes: 11 additions & 2 deletions autopush-common/src/db/bigtable/bigtable_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,10 +1081,18 @@ mod tests {
}

fn new_client() -> DbResult<BigTableClientImpl> {
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(),
};
Expand Down Expand Up @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions autopush-common/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fae3f73

Please sign in to comment.