From a222a37083bf74b4b2992e91a4ec90921b0cc2bf Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Thu, 8 Jun 2017 13:27:29 +0200 Subject: Only include what you really need --- config/src/tests/configfetcher/configfetcher.cpp | 3 ++- config/src/tests/subscriber/subscriber.cpp | 8 ++++---- config/src/vespa/config/common/configparser.cpp | 6 ++++++ config/src/vespa/config/common/configparser.h | 5 ++--- config/src/vespa/config/helper/configfetcher.cpp | 15 ++++++++++----- config/src/vespa/config/helper/configfetcher.h | 10 ++++------ 6 files changed, 28 insertions(+), 19 deletions(-) (limited to 'config') diff --git a/config/src/tests/configfetcher/configfetcher.cpp b/config/src/tests/configfetcher/configfetcher.cpp index 02d90352f69..eab2e8a8c84 100644 --- a/config/src/tests/configfetcher/configfetcher.cpp +++ b/config/src/tests/configfetcher/configfetcher.cpp @@ -1,6 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include #include +#include #include #include "config-my.h" #include @@ -151,7 +152,7 @@ TEST_F("verify that config generation can be obtained from config fetcher", Conf if (cb._configured) { break; } - FastOS_Thread::Sleep(10); + std::this_thread::sleep_for(std::chrono::milliseconds(10));; } EXPECT_EQUAL(2, fetcher.getGeneration()); EXPECT_EQUAL("bar", cb._config.get()->myField); diff --git a/config/src/tests/subscriber/subscriber.cpp b/config/src/tests/subscriber/subscriber.cpp index 3bae5ed85b1..f0b7fe18930 100644 --- a/config/src/tests/subscriber/subscriber.cpp +++ b/config/src/tests/subscriber/subscriber.cpp @@ -281,9 +281,9 @@ TEST_MT_FFF("requireThatConfigIsReturnedWhenUpdatedDuringNextConfig", 2, MyManag verifyConfig("foo2", f3.h1->getConfig()); verifyConfig("bar", f3.h2->getConfig()); } else { - FastOS_Thread::Sleep(300); + std::this_thread::sleep_for(std::chrono::milliseconds(300)); f1.updateValue(0, createFooValue("foo2"), 2); - FastOS_Thread::Sleep(300); + std::this_thread::sleep_for(std::chrono::milliseconds(300)); f1.updateGeneration(1, 2); } } @@ -331,7 +331,7 @@ TEST_MT_FFF("requireThatNextConfigIsInterruptedOnClose", 2, MyManager, APIFixtur ASSERT_TRUE(timer.MilliSecsToNow() >= 500.0); ASSERT_TRUE(timer.MilliSecsToNow() < 60000.0); } else { - FastOS_Thread::Sleep(1000); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); f3.s.close(); } } @@ -514,7 +514,7 @@ TEST_MT_FF("requireThatConfigSubscriberWaitsUntilNextConfigSucceeds", 2, MyManag verifyConfig("foo2", h1->getConfig()); // First update is skipped } else { TEST_BARRIER(); - FastOS_Thread::Sleep(1000); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); f1.updateValue(0, createFooValue("foo2"), 3); } } diff --git a/config/src/vespa/config/common/configparser.cpp b/config/src/vespa/config/common/configparser.cpp index e0a0b0138b9..c490133172f 100644 --- a/config/src/vespa/config/common/configparser.cpp +++ b/config/src/vespa/config/common/configparser.cpp @@ -1,11 +1,17 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "configparser.h" +#include "exceptions.h" #include "misc.h" #include namespace config { +void ConfigParser::throwNoDefaultValue(const vespalib::stringref & key) { + throw InvalidConfigException("Config parameter " + key + " has no " + "default value and is not specified in config", VESPA_STRLOC); +} + vespalib::string ConfigParser::deQuote(const vespalib::stringref & source) { diff --git a/config/src/vespa/config/common/configparser.h b/config/src/vespa/config/common/configparser.h index 613dfc33d94..cde036281a5 100644 --- a/config/src/vespa/config/common/configparser.h +++ b/config/src/vespa/config/common/configparser.h @@ -1,7 +1,6 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include #include #include #include @@ -25,6 +24,7 @@ private: static std::map splitMap( const vsvector & config); static vespalib::string deQuote(const vespalib::stringref & source); + static void throwNoDefaultValue(const vespalib::stringref & key); template static T convert(const vsvector &); @@ -81,8 +81,7 @@ ConfigParser::parseInternal(const vespalib::stringref & key, const V & config) V lines = getLinesForKey(key, config); if (lines.size() == 0) { - throw InvalidConfigException("Config parameter " + key + " has no " - "default value and is not specified in config", VESPA_STRLOC); + throwNoDefaultValue(key); } return convert(lines); } diff --git a/config/src/vespa/config/helper/configfetcher.cpp b/config/src/vespa/config/helper/configfetcher.cpp index 0a4b95e9153..1f1bfe69bb8 100644 --- a/config/src/vespa/config/helper/configfetcher.cpp +++ b/config/src/vespa/config/helper/configfetcher.cpp @@ -1,7 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "configfetcher.h" - +#include #include LOG_SETUP(".config.helper.configfetcher"); @@ -9,7 +9,7 @@ namespace config { ConfigFetcher::ConfigFetcher(const IConfigContext::SP & context) : _poller(context), - _thread(_poller), + _thread(std::make_unique(_poller)), _closed(false), _started(false) { @@ -17,12 +17,17 @@ ConfigFetcher::ConfigFetcher(const IConfigContext::SP & context) ConfigFetcher::ConfigFetcher(const SourceSpec & spec) : _poller(IConfigContext::SP(new ConfigContext(spec))), - _thread(_poller), + _thread(std::make_unique(_poller)), _closed(false), _started(false) { } +void +ConfigFetcher::subscribeGenerationChanges(IGenerationCallback * callback) { + _poller.subscribeGenerationChanges(callback); +} + void ConfigFetcher::start() { @@ -30,7 +35,7 @@ ConfigFetcher::start() LOG(debug, "Polling for config"); _poller.poll(); LOG(debug, "Starting fetcher thread..."); - _thread.start(); + _thread->start(); _started = true; LOG(debug, "Fetcher thread started"); } @@ -47,7 +52,7 @@ ConfigFetcher::close() if (!_closed) { _poller.close(); if (_started) - _thread.join(); + _thread->join(); } } diff --git a/config/src/vespa/config/helper/configfetcher.h b/config/src/vespa/config/helper/configfetcher.h index ed04dc62f50..872937d8635 100644 --- a/config/src/vespa/config/helper/configfetcher.h +++ b/config/src/vespa/config/helper/configfetcher.h @@ -2,11 +2,11 @@ #pragma once #include "configpoller.h" -#include #include -#include #include +namespace vespalib { class Thread; } + namespace config { /** @@ -22,16 +22,14 @@ public: template void subscribe(const std::string & configId, IFetcherCallback * callback, uint64_t subscribeTimeout = DEFAULT_SUBSCRIBE_TIMEOUT); - void subscribeGenerationChanges(IGenerationCallback * callback) { - _poller.subscribeGenerationChanges(callback); - } + void subscribeGenerationChanges(IGenerationCallback * callback); void start(); void close(); int64_t getGeneration() const { return _poller.getGeneration(); } private: ConfigPoller _poller; - vespalib::Thread _thread; + std::unique_ptr _thread; std::atomic _closed; std::atomic _started; }; -- cgit v1.2.3