From 0e8b8b49015ce29e0435b8fb0d610b3db69812e1 Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Wed, 4 Apr 2018 14:05:46 +0000 Subject: [PATCH] Add nodejs test for dataset name --- include/engine/data_watchdog.hpp | 4 ++-- include/engine/engine.hpp | 2 +- include/nodejs/node_osrm_support.hpp | 16 ++++++++++++++++ include/storage/shared_memory.hpp | 2 +- .../datafacade/shared_memory_allocator.cpp | 2 +- src/tools/routed.cpp | 17 +++++++++++------ test/nodejs/index.js | 13 ++++++++++--- 7 files changed, 42 insertions(+), 14 deletions(-) diff --git a/include/engine/data_watchdog.hpp b/include/engine/data_watchdog.hpp index 9330d80b7..eaa18b87c 100644 --- a/include/engine/data_watchdog.hpp +++ b/include/engine/data_watchdog.hpp @@ -47,7 +47,7 @@ class DataWatchdogImpl( std::make_shared(region.shm_key)); - util::Log() << "updated facade to region " << region.shm_key << " with timestamp " + util::Log() << "updated facade to region " << (int) region.shm_key << " with timestamp " << region.timestamp; } } diff --git a/include/engine/engine.hpp b/include/engine/engine.hpp index acce332b8..3b1a8b808 100644 --- a/include/engine/engine.hpp +++ b/include/engine/engine.hpp @@ -59,7 +59,7 @@ template class Engine final : public EngineInterface { if (config.use_shared_memory) { - util::Log(logDEBUG) << "Using shared memory with algorithm " + util::Log(logDEBUG) << "Using shared memory with name \"" << config.dataset_name << "\" with algorithm " << routing_algorithms::name(); facade_provider = std::make_unique>(config.dataset_name); } diff --git a/include/nodejs/node_osrm_support.hpp b/include/nodejs/node_osrm_support.hpp index 7554c816b..5b8f4ad2d 100644 --- a/include/nodejs/node_osrm_support.hpp +++ b/include/nodejs/node_osrm_support.hpp @@ -135,6 +135,22 @@ inline engine_config_ptr argumentsToEngineConfig(const Nan::FunctionCallbackInfo *v8::String::Utf8Value(Nan::To(memory_file).ToLocalChecked()); } + auto dataset_name = params->Get(Nan::New("dataset_name").ToLocalChecked()); + if (dataset_name.IsEmpty()) + return engine_config_ptr(); + if (!dataset_name->IsUndefined()) + { + if (dataset_name->IsString()) + { + engine_config->dataset_name = *v8::String::Utf8Value(Nan::To(dataset_name).ToLocalChecked()); + } + else + { + Nan::ThrowError("dataset_name needs to be a string"); + return engine_config_ptr(); + } + } + if (!path->IsUndefined()) { engine_config->storage_config = diff --git a/include/storage/shared_memory.hpp b/include/storage/shared_memory.hpp index 86dc3fe55..0ebdcb136 100644 --- a/include/storage/shared_memory.hpp +++ b/include/storage/shared_memory.hpp @@ -63,7 +63,7 @@ class SharedMemory { shm = boost::interprocess::xsi_shared_memory(boost::interprocess::open_only, key); - util::Log(logDEBUG) << "opening " << shm.get_shmid() << " from id " << id; + util::Log(logDEBUG) << "opening " << (int) shm.get_shmid() << " from id " << (int) id; region = boost::interprocess::mapped_region(shm, boost::interprocess::read_only); } diff --git a/src/engine/datafacade/shared_memory_allocator.cpp b/src/engine/datafacade/shared_memory_allocator.cpp index 8b8297a53..196992e9a 100644 --- a/src/engine/datafacade/shared_memory_allocator.cpp +++ b/src/engine/datafacade/shared_memory_allocator.cpp @@ -15,7 +15,7 @@ namespace datafacade SharedMemoryAllocator::SharedMemoryAllocator(storage::SharedRegionRegister::ShmKey data_shm_key) { - util::Log(logDEBUG) << "Loading new data for region " << data_shm_key; + util::Log(logDEBUG) << "Loading new data for region " << (int)data_shm_key; BOOST_ASSERT(storage::SharedMemory::RegionExists(data_shm_key)); m_large_memory = storage::makeSharedMemory(data_shm_key); diff --git a/src/tools/routed.cpp b/src/tools/routed.cpp index 9d669a014..66236d527 100644 --- a/src/tools/routed.cpp +++ b/src/tools/routed.cpp @@ -90,12 +90,17 @@ inline unsigned generateServerProgramOptions(const int argc, // declare a group of options that will be allowed only on command line boost::program_options::options_description generic_options("Options"); - generic_options.add_options() // - ("version,v", "Show version")("help,h", "Show this help message")( - "verbosity,l", - boost::program_options::value(&config.verbosity)->default_value("INFO"), - std::string("Log verbosity level: " + util::LogPolicy::GetLevels()).c_str())( - "trial", value(&trial)->implicit_value(true), "Quit after initialization"); + generic_options.add_options() // + ("version,v", "Show version") // + ("help,h", "Show this help message") // + ("verbosity,l", +#ifdef NDEBUG + boost::program_options::value(&config.verbosity)->default_value("INFO"), +#else + boost::program_options::value(&config.verbosity)->default_value("DEBUG"), +#endif + std::string("Log verbosity level: " + util::LogPolicy::GetLevels()).c_str()) // + ("trial", value(&trial)->implicit_value(true), "Quit after initialization"); // declare a group of options that will be allowed on command line boost::program_options::options_description config_options("Configuration"); diff --git a/test/nodejs/index.js b/test/nodejs/index.js index 719f7edfa..bbe58849f 100644 --- a/test/nodejs/index.js +++ b/test/nodejs/index.js @@ -100,9 +100,16 @@ test('constructor: autoswitches to CoreCH for a CH dataset if capable', function test('constructor: throws if data doesn\'t match algorithm', function(assert) { assert.plan(3); - assert.throws(function() { new OSRM({algorithm: 'CoreCH', path: monaco_mld_path}); }, 'CoreCH with MLD data'); - assert.ok(function() { new OSRM({algorithm: 'CoreCH', path: monaco_path}); }, 'CoreCH with CH data'); - assert.throws(function() { new OSRM({algorithm: 'MLD', path: monaco_path}); }, 'MLD with CH data'); + assert.throws(function() { new OSRM({algorithm: 'CoreCH', path: monaco_mld_path}); }, /Could not find any metrics for CH/, 'CoreCH with MLD data'); + assert.ok(new OSRM({algorithm: 'CoreCH', path: monaco_path}), 'CoreCH with CH data'); + assert.throws(function() { new OSRM({algorithm: 'MLD', path: monaco_path}); }, /Could not find any metrics for MLD/, 'MLD with CH data'); +}); + +test('constructor: throws if dataset_name is not a string', function(assert) { + assert.plan(3); + assert.throws(function() { new OSRM({dataset_name: 1337, path: monaco_mld_path}); }, /dataset_name needs to be a string/, 'Does not accept int'); + assert.ok(new OSRM({dataset_name: "", shared_memory: true}), 'Does accept string'); + assert.throws(function() { new OSRM({dataset_name: "unsued_name___", shared_memory: true}); }, /Could not find shared memory region/, 'Does not accept wrong name'); }); test('constructor: parses custom limits', function(assert) {