Skip to content

Commit

Permalink
docs and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Dec 26, 2023
1 parent 37463d4 commit 9d4efea
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 64 deletions.
3 changes: 3 additions & 0 deletions debian/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ listen_addresses: '0.0.0.0:3000'
# Number of web server workers
worker_processes: 8

# Amount of memory (in MB) to use for caching tiles [default: 512, 0 to disable]
cache_size_mb: 512

# see https://maplibre.org/martin/config-file.html

# postgres:
Expand Down
3 changes: 3 additions & 0 deletions docs/src/config-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ listen_addresses: '0.0.0.0:3000'
# Number of web server workers
worker_processes: 8

# Amount of memory (in MB) to use for caching tiles [default: 512, 0 to disable]
cache_size_mb: 1024

# Database configuration. This can also be a list of PG configs.
postgres:
# Database connection string. You can use env vars too, for example:
Expand Down
6 changes: 3 additions & 3 deletions martin/src/pmtiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ impl ConfigExtras for PmtConfig {
self.client = Some(Client::new());

// Allow cache size to be disabled with 0
let cache_size = self.dir_cache_size_mb.unwrap_or(32) * 1024 * 1024;
if cache_size > 0 {
let dir_cache_size = self.dir_cache_size_mb.unwrap_or(32) * 1024 * 1024;
if dir_cache_size > 0 {
self.cache = Some(
Cache::builder()
.weigher(|_key, value: &Directory| -> u32 {
value.get_approx_byte_size().try_into().unwrap_or(u32::MAX)
})
.max_capacity(cache_size)
.max_capacity(dir_cache_size)
.build(),
);
}
Expand Down
4 changes: 2 additions & 2 deletions martin/src/srv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ pub use config::{SrvConfig, KEEP_ALIVE_DEFAULT, LISTEN_ADDRESSES_DEFAULT};

mod server;
pub use server::{
get_tile_content, get_tile_response, merge_tilejson, new_server, router, Catalog, TileRequest,
RESERVED_KEYWORDS,
get_tile_content, get_tile_response, merge_tilejson, new_server, router, Catalog, ItemCache,
TileRequest, RESERVED_KEYWORDS,
};
4 changes: 2 additions & 2 deletions martin/src/srv/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub enum CacheItemKey {
Font(String),
}

type ItemCache = Cache<CacheItemKey, TileData>;
pub type ItemCache = Cache<CacheItemKey, TileData>;

#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
pub struct Catalog {
Expand Down Expand Up @@ -586,7 +586,7 @@ pub fn new_server(config: SrvConfig, state: ServerState) -> MartinResult<(Server
.allow_any_origin()
.allowed_methods(vec!["GET"]);

let cache_size = config.cache_size_mb.unwrap_or(100) * 1024 * 1024;
let cache_size = config.cache_size_mb.unwrap_or(512) * 1024 * 1024;
let cache = if cache_size > 0 {
Some(
ItemCache::builder()
Expand Down
29 changes: 15 additions & 14 deletions martin/tests/mb_server_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ macro_rules! create_app {
.app_data(actix_web::web::Data::new(
::martin::srv::Catalog::new(&state).unwrap(),
))
.app_data(actix_web::web::Data::new(None::<::martin::srv::ItemCache>))
.app_data(actix_web::web::Data::new(state.tiles))
.configure(::martin::srv::router),
)
Expand All @@ -48,7 +49,7 @@ async fn mbt_get_catalog() {

let req = test_get("/catalog").to_request();
let response = call_service(&app, req).await;
assert!(response.status().is_success());
let response = assert_response(response).await;
let body: serde_json::Value = read_body_json(response).await;
assert_yaml_snapshot!(body, @r###"
---
Expand Down Expand Up @@ -79,7 +80,7 @@ async fn mbt_get_catalog_gzip() {
let accept = (ACCEPT_ENCODING, "gzip");
let req = test_get("/catalog").insert_header(accept).to_request();
let response = call_service(&app, req).await;
assert!(response.status().is_success());
let response = assert_response(response).await;
let body = decode_gzip(&read_body(response).await).unwrap();
let body: serde_json::Value = serde_json::from_slice(&body).unwrap();
assert_yaml_snapshot!(body, @r###"
Expand Down Expand Up @@ -110,7 +111,7 @@ async fn mbt_get_tilejson() {
let app = create_app! { CONFIG };
let req = test_get("/m_mvt").to_request();
let response = call_service(&app, req).await;
assert!(response.status().is_success());
let response = assert_response(response).await;
let headers = response.headers();
assert_eq!(headers.get(CONTENT_TYPE).unwrap(), "application/json");
assert!(headers.get(CONTENT_ENCODING).is_none());
Expand All @@ -124,7 +125,7 @@ async fn mbt_get_tilejson_gzip() {
let accept = (ACCEPT_ENCODING, "gzip");
let req = test_get("/m_webp").insert_header(accept).to_request();
let response = call_service(&app, req).await;
assert!(response.status().is_success());
let response = assert_response(response).await;
let headers = response.headers();
assert_eq!(headers.get(CONTENT_TYPE).unwrap(), "application/json");
assert_eq!(headers.get(CONTENT_ENCODING).unwrap(), "gzip");
Expand All @@ -138,7 +139,7 @@ async fn mbt_get_raster() {
let app = create_app! { CONFIG };
let req = test_get("/m_webp/0/0/0").to_request();
let response = call_service(&app, req).await;
assert!(response.status().is_success());
let response = assert_response(response).await;
assert_eq!(response.headers().get(CONTENT_TYPE).unwrap(), "image/webp");
assert!(response.headers().get(CONTENT_ENCODING).is_none());
let body = read_body(response).await;
Expand All @@ -152,7 +153,7 @@ async fn mbt_get_raster_gzip() {
let accept = (ACCEPT_ENCODING, "gzip");
let req = test_get("/m_webp/0/0/0").insert_header(accept).to_request();
let response = call_service(&app, req).await;
assert!(response.status().is_success());
let response = assert_response(response).await;
assert_eq!(response.headers().get(CONTENT_TYPE).unwrap(), "image/webp");
assert!(response.headers().get(CONTENT_ENCODING).is_none());
let body = read_body(response).await;
Expand All @@ -164,7 +165,7 @@ async fn mbt_get_mvt() {
let app = create_app! { CONFIG };
let req = test_get("/m_mvt/0/0/0").to_request();
let response = call_service(&app, req).await;
assert!(response.status().is_success());
let response = assert_response(response).await;
assert_eq!(
response.headers().get(CONTENT_TYPE).unwrap(),
"application/x-protobuf"
Expand All @@ -181,7 +182,7 @@ async fn mbt_get_mvt_gzip() {
let accept = (ACCEPT_ENCODING, "gzip");
let req = test_get("/m_mvt/0/0/0").insert_header(accept).to_request();
let response = call_service(&app, req).await;
assert!(response.status().is_success());
let response = assert_response(response).await;
assert_eq!(
response.headers().get(CONTENT_TYPE).unwrap(),
"application/x-protobuf"
Expand All @@ -200,7 +201,7 @@ async fn mbt_get_mvt_brotli() {
let accept = (ACCEPT_ENCODING, "br");
let req = test_get("/m_mvt/0/0/0").insert_header(accept).to_request();
let response = call_service(&app, req).await;
assert!(response.status().is_success());
let response = assert_response(response).await;
assert_eq!(
response.headers().get(CONTENT_TYPE).unwrap(),
"application/x-protobuf"
Expand All @@ -218,7 +219,7 @@ async fn mbt_get_raw_mvt() {
let app = create_app! { CONFIG };
let req = test_get("/m_raw_mvt/0/0/0").to_request();
let response = call_service(&app, req).await;
assert!(response.status().is_success());
let response = assert_response(response).await;
assert_eq!(
response.headers().get(CONTENT_TYPE).unwrap(),
"application/x-protobuf"
Expand All @@ -237,7 +238,7 @@ async fn mbt_get_raw_mvt_gzip() {
.insert_header(accept)
.to_request();
let response = call_service(&app, req).await;
assert!(response.status().is_success());
let response = assert_response(response).await;
assert_eq!(
response.headers().get(CONTENT_TYPE).unwrap(),
"application/x-protobuf"
Expand All @@ -259,7 +260,7 @@ async fn mbt_get_raw_mvt_gzip_br() {
.insert_header(accept)
.to_request();
let response = call_service(&app, req).await;
assert!(response.status().is_success());
let response = assert_response(response).await;
assert_eq!(
response.headers().get(CONTENT_TYPE).unwrap(),
"application/x-protobuf"
Expand All @@ -277,7 +278,7 @@ async fn mbt_get_json() {
let app = create_app! { CONFIG };
let req = test_get("/m_json/0/0/0").to_request();
let response = call_service(&app, req).await;
assert!(response.status().is_success());
let response = assert_response(response).await;
assert_eq!(
response.headers().get(CONTENT_TYPE).unwrap(),
"application/json"
Expand All @@ -294,7 +295,7 @@ async fn mbt_get_json_gzip() {
let accept = (ACCEPT_ENCODING, "gzip");
let req = test_get("/m_json/0/0/0").insert_header(accept).to_request();
let response = call_service(&app, req).await;
assert!(response.status().is_success());
let response = assert_response(response).await;
assert_eq!(
response.headers().get(CONTENT_TYPE).unwrap(),
"application/json"
Expand Down
Loading

0 comments on commit 9d4efea

Please sign in to comment.