aboutsummaryrefslogtreecommitdiffstats
path: root/config/src/tests/subscriber/subscriber.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'config/src/tests/subscriber/subscriber.cpp')
-rw-r--r--config/src/tests/subscriber/subscriber.cpp150
1 files changed, 73 insertions, 77 deletions
diff --git a/config/src/tests/subscriber/subscriber.cpp b/config/src/tests/subscriber/subscriber.cpp
index 5663b145100..0c14928521e 100644
--- a/config/src/tests/subscriber/subscriber.cpp
+++ b/config/src/tests/subscriber/subscriber.cpp
@@ -5,14 +5,14 @@
#include <vespa/config/common/configholder.h>
#include <vespa/config/subscription/configsubscription.h>
#include <vespa/config/common/exceptions.h>
-#include <vespa/fastos/time.h>
-#include <fstream>
+#include <vespa/fastos/timestamp.h>
#include "config-foo.h"
#include "config-bar.h"
#include "config-baz.h"
using namespace config;
using namespace vespalib;
+using namespace std::chrono_literals;
namespace {
@@ -78,13 +78,12 @@ namespace {
MyManager() : idCounter(0), numCancel(0) { }
- ConfigSubscription::SP subscribe(const ConfigKey & key, uint64_t timeoutInMillis) override {
+ ConfigSubscription::SP subscribe(const ConfigKey & key, milliseconds timeoutInMillis) override {
(void) timeoutInMillis;
IConfigHolder::SP holder(new ConfigHolder());
_holders.push_back(holder);
- ConfigSubscription::SP s(new ConfigSubscription(0, key, holder, Source::UP(new MySource())));
- return s;
+ return std::make_shared<ConfigSubscription>(0, key, holder, std::make_unique<MySource>());
}
void unsubscribe(const ConfigSubscription::SP & subscription) override {
(void) subscription;
@@ -93,7 +92,7 @@ namespace {
void updateValue(size_t index, const ConfigValue & value, int64_t generation) {
ASSERT_TRUE(index < _holders.size());
- _holders[index]->handle(ConfigUpdate::UP(new ConfigUpdate(value, true, generation)));
+ _holders[index]->handle(std::make_unique<ConfigUpdate>(value, true, generation));
}
void updateGeneration(size_t index, int64_t generation) {
@@ -103,7 +102,7 @@ namespace {
if (_holders[index]->poll()) {
value = _holders[index]->provide()->getValue();
}
- _holders[index]->handle(ConfigUpdate::UP(new ConfigUpdate(value, false, generation)));
+ _holders[index]->handle(std::make_unique<ConfigUpdate>(value, false, generation));
}
void reload(int64_t generation) override
@@ -151,7 +150,7 @@ namespace {
h2 = s.subscribe<BarConfig>("myid");
f1.updateValue(0, createFooValue("foo"), 1);
f1.updateValue(1, createBarValue("bar"), 1);
- ASSERT_TRUE(s.nextConfig(0));
+ ASSERT_TRUE(s.nextConfigNow());
verifyConfig("foo", h1->getConfig());
verifyConfig("bar", h2->getConfig());
}
@@ -174,7 +173,7 @@ TEST_F("requireThatSubscriberCanGetMultipleTypes", SimpleFixture()) {
ConfigSubscriber s(f.set);
ConfigHandle<FooConfig>::UP h1 = s.subscribe<FooConfig>("myid");
ConfigHandle<BarConfig>::UP h2 = s.subscribe<BarConfig>("myid");
- ASSERT_TRUE(s.nextConfig(0));
+ ASSERT_TRUE(s.nextConfigNow());
std::unique_ptr<FooConfig> foo = h1->getConfig();
std::unique_ptr<BarConfig> bar = h2->getConfig();
ASSERT_EQUAL("bar", foo->fooValue);
@@ -196,7 +195,7 @@ TEST_F("requireThatNextConfigMustBeCalled", SimpleFixture()) {
TEST_F("requireThatSubscriptionsCannotBeAddedWhenFrozen", SimpleFixture()) {
ConfigSubscriber s(f.set);
ConfigHandle<FooConfig>::UP h1 = s.subscribe<FooConfig>("myid");
- ASSERT_TRUE(s.nextConfig(0));
+ ASSERT_TRUE(s.nextConfigNow());
bool thrown = false;
try {
ConfigHandle<BarConfig>::UP h2 = s.subscribe<BarConfig>("myid");
@@ -210,19 +209,19 @@ TEST_FF("requireThatNextConfigReturnsFalseUntilSubscriptionHasSucceeded", MyMana
ConfigSubscriber s(IConfigContext::SP(new APIFixture(f2)));
ConfigHandle<FooConfig>::UP h1 = s.subscribe<FooConfig>("myid");
ConfigHandle<BarConfig>::UP h2 = s.subscribe<BarConfig>("myid");
- ASSERT_FALSE(s.nextConfig(0));
- ASSERT_FALSE(s.nextConfig(100));
+ ASSERT_FALSE(s.nextConfigNow());
+ ASSERT_FALSE(s.nextConfig(100ms));
f1.updateValue(0, createFooValue("foo"), 1);
- ASSERT_FALSE(s.nextConfig(100));
+ ASSERT_FALSE(s.nextConfig(100ms));
f1.updateValue(1, createBarValue("bar"), 1);
- ASSERT_TRUE(s.nextConfig(100));
+ ASSERT_TRUE(s.nextConfig(100ms));
}
TEST_FFF("requireThatNewGenerationIsFetchedOnReload", MyManager, APIFixture(f1), StandardFixture(f1, f2)) {
verifyConfig("foo", f3.h1->getConfig());
verifyConfig("bar", f3.h2->getConfig());
- ASSERT_FALSE(f3.s.nextConfig(1000));
+ ASSERT_FALSE(f3.s.nextConfig(1000ms));
verifyConfig("foo", f3.h1->getConfig());
verifyConfig("bar", f3.h2->getConfig());
@@ -230,7 +229,7 @@ TEST_FFF("requireThatNewGenerationIsFetchedOnReload", MyManager, APIFixture(f1),
f1.updateValue(0, createFooValue("foo2"), 3);
f1.updateValue(1, createBarValue("bar2"), 3);
- ASSERT_TRUE(f3.s.nextConfig(1000));
+ ASSERT_TRUE(f3.s.nextConfig(1000ms));
verifyConfig("foo2", f3.h1->getConfig());
verifyConfig("bar2", f3.h2->getConfig());
@@ -238,26 +237,26 @@ TEST_FFF("requireThatNewGenerationIsFetchedOnReload", MyManager, APIFixture(f1),
TEST_FFF("requireThatAllConfigsMustGetTimestampUpdate", MyManager, APIFixture(f1), StandardFixture(f1, f2)) {
f1.updateValue(0, createFooValue("foo2"), 2);
- ASSERT_FALSE(f3.s.nextConfig(100));
+ ASSERT_FALSE(f3.s.nextConfig(100ms));
verifyConfig("foo", f3.h1->getConfig());
verifyConfig("bar", f3.h2->getConfig());
f1.updateValue(0, createFooValue("foo2"), 3);
f1.updateGeneration(1, 3);
- ASSERT_TRUE(f3.s.nextConfig(0));
+ ASSERT_TRUE(f3.s.nextConfigNow());
verifyConfig("foo2", f3.h1->getConfig());
verifyConfig("bar", f3.h2->getConfig());
}
TEST_FFF("requireThatNextConfigMaySucceedIfInTheMiddleOfConfigUpdate", MyManager, APIFixture(f1), StandardFixture(f1, f2)) {
f1.updateValue(0, createFooValue("foo2"), 2);
- ASSERT_FALSE(f3.s.nextConfig(1000));
+ ASSERT_FALSE(f3.s.nextConfig(1000ms));
verifyConfig("foo", f3.h1->getConfig());
verifyConfig("bar", f3.h2->getConfig());
f1.updateGeneration(1, 2);
- ASSERT_TRUE(f3.s.nextConfig(0));
+ ASSERT_TRUE(f3.s.nextConfigNow());
verifyConfig("foo2", f3.h1->getConfig());
verifyConfig("bar", f3.h2->getConfig());
}
@@ -265,21 +264,20 @@ TEST_FFF("requireThatNextConfigMaySucceedIfInTheMiddleOfConfigUpdate", MyManager
TEST_FFF("requireThatCorrectConfigIsReturnedAfterTimestampUpdate", MyManager, APIFixture(f1), StandardFixture(f1, f2)) {
f1.updateGeneration(0, 2);
f1.updateGeneration(1, 2);
- ASSERT_FALSE(f3.s.nextConfig(1000));
+ ASSERT_FALSE(f3.s.nextConfig(1000ms));
verifyConfig("foo", f3.h1->getConfig());
verifyConfig("bar", f3.h2->getConfig());
- ASSERT_TRUE(f3.s.nextGeneration(0));
+ ASSERT_TRUE(f3.s.nextGenerationNow());
verifyConfig("foo", f3.h1->getConfig());
verifyConfig("bar", f3.h2->getConfig());
}
TEST_MT_FFF("requireThatConfigIsReturnedWhenUpdatedDuringNextConfig", 2, MyManager, APIFixture(f1), StandardFixture(f1, f2)) {
if (thread_id == 0) {
- FastOS_Time timer;
- timer.SetNow();
- ASSERT_TRUE(f3.s.nextConfig(10000));
- ASSERT_TRUE(timer.MilliSecsToNow() > 250);
- ASSERT_TRUE(timer.MilliSecsToNow() <= 5000);
+ fastos::StopWatch timer;
+ ASSERT_TRUE(f3.s.nextConfig(10000ms));
+ ASSERT_TRUE(timer.elapsed().ms() > 250);
+ ASSERT_TRUE(timer.elapsed().ms() <= 5000);
verifyConfig("foo2", f3.h1->getConfig());
verifyConfig("bar", f3.h2->getConfig());
} else {
@@ -291,15 +289,14 @@ TEST_MT_FFF("requireThatConfigIsReturnedWhenUpdatedDuringNextConfig", 2, MyManag
}
TEST_FFF("requireThatConfigIsReturnedWhenUpdatedBeforeNextConfig", MyManager, APIFixture(f1), StandardFixture(f1, f2)) {
- FastOS_Time timer;
- timer.SetNow();
- ASSERT_FALSE(f3.s.nextConfig(1000));
- ASSERT_TRUE(timer.MilliSecsToNow() > 850);
+ fastos::StopWatch timer;
+ ASSERT_FALSE(f3.s.nextConfig(1000ms));
+ ASSERT_TRUE(timer.elapsed().ms() > 850);
f1.updateGeneration(0, 2);
f1.updateGeneration(1, 2);
- timer.SetNow();
- ASSERT_TRUE(f3.s.nextGeneration(10000));
- ASSERT_TRUE(timer.MilliSecsToNow() <= 5000);
+ timer.restart();
+ ASSERT_TRUE(f3.s.nextGeneration(10000ms));
+ ASSERT_TRUE(timer.elapsed().ms() <= 5000);
verifyConfig("foo", f3.h1->getConfig());
verifyConfig("bar", f3.h2->getConfig());
}
@@ -315,7 +312,7 @@ TEST_FFF("requireThatNothingCanBeCalledAfterClose", MyManager, APIFixture(f1), S
ASSERT_FALSE(f3.s.isClosed());
f3.s.close();
ASSERT_TRUE(f3.s.isClosed());
- ASSERT_FALSE(f3.s.nextConfig(100));
+ ASSERT_FALSE(f3.s.nextConfig(100ms));
bool thrown = false;
try {
f3.h1->getConfig();
@@ -327,11 +324,10 @@ TEST_FFF("requireThatNothingCanBeCalledAfterClose", MyManager, APIFixture(f1), S
TEST_MT_FFF("requireThatNextConfigIsInterruptedOnClose", 2, MyManager, APIFixture(f1), StandardFixture(f1, f2)) {
if (thread_id == 0) {
- FastOS_Time timer;
- timer.SetNow();
- ASSERT_FALSE(f3.s.nextConfig(5000));
- ASSERT_TRUE(timer.MilliSecsToNow() >= 500.0);
- ASSERT_TRUE(timer.MilliSecsToNow() < 60000.0);
+ fastos::StopWatch timer;
+ ASSERT_FALSE(f3.s.nextConfig(5000ms));
+ ASSERT_TRUE(timer.elapsed().ms() >= 500.0);
+ ASSERT_TRUE(timer.elapsed().ms() < 60000.0);
} else {
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
f3.s.close();
@@ -342,20 +338,20 @@ TEST_FF("requireThatHandlesAreMarkedAsChanged", MyManager, APIFixture(f1)) {
ConfigSubscriber s(IConfigContext::SP(new APIFixture(f2)));
ConfigHandle<FooConfig>::UP h1 = s.subscribe<FooConfig>("myid2");
ConfigHandle<BarConfig>::UP h2 = s.subscribe<BarConfig>("myid2");
- EXPECT_FALSE(s.nextConfig(0));
+ EXPECT_FALSE(s.nextConfigNow());
f1.updateValue(0, createFooValue("foo"), 1);
f1.updateValue(1, createFooValue("bar"), 1);
- EXPECT_TRUE(s.nextConfig(100));
+ EXPECT_TRUE(s.nextConfig(100ms));
EXPECT_TRUE(h1->isChanged());
EXPECT_TRUE(h2->isChanged());
- EXPECT_FALSE(s.nextConfig(100));
+ EXPECT_FALSE(s.nextConfig(100ms));
EXPECT_FALSE(h1->isChanged());
EXPECT_FALSE(h2->isChanged());
f1.updateValue(0, createFooValue("bar"), 2);
f1.updateGeneration(1, 2);
- EXPECT_TRUE(s.nextConfig(100));
+ EXPECT_TRUE(s.nextConfig(100ms));
EXPECT_TRUE(h1->isChanged());
EXPECT_FALSE(h2->isChanged());
}
@@ -366,19 +362,19 @@ TEST_FF("requireThatNextGenerationMarksChanged", MyManager, APIFixture(f1)) {
ConfigHandle<BarConfig>::UP h2 = s.subscribe<BarConfig>("myid2");
f1.updateValue(0, createFooValue("foo"), 1);
f1.updateValue(1, createFooValue("bar"), 1);
- ASSERT_TRUE(s.nextGeneration(0));
+ ASSERT_TRUE(s.nextGenerationNow());
ASSERT_TRUE(h1->isChanged());
ASSERT_TRUE(h2->isChanged());
f1.updateValue(0, createFooValue("bar"), 2);
f1.updateGeneration(1, 2);
- ASSERT_TRUE(s.nextGeneration(0));
+ ASSERT_TRUE(s.nextGenerationNow());
ASSERT_TRUE(h1->isChanged());
ASSERT_FALSE(h2->isChanged());
f1.updateGeneration(0, 3);
f1.updateGeneration(1, 3);
- ASSERT_TRUE(s.nextGeneration(0));
+ ASSERT_TRUE(s.nextGenerationNow());
ASSERT_FALSE(h1->isChanged());
ASSERT_FALSE(h2->isChanged());
}
@@ -389,23 +385,23 @@ TEST_FF("requireThatgetGenerationIsSet", MyManager, APIFixture(f1)) {
ConfigHandle<BarConfig>::UP h2 = s.subscribe<BarConfig>("myid2");
f1.updateValue(0, createFooValue("foo"), 1);
f1.updateValue(1, createFooValue("bar"), 1);
- ASSERT_TRUE(s.nextGeneration(0));
+ ASSERT_TRUE(s.nextGenerationNow());
ASSERT_EQUAL(1, s.getGeneration());
ASSERT_TRUE(h1->isChanged());
ASSERT_TRUE(h2->isChanged());
- ASSERT_FALSE(s.nextGeneration(0));
+ ASSERT_FALSE(s.nextGenerationNow());
f1.updateGeneration(1, 2);
- ASSERT_FALSE(s.nextGeneration(0));
+ ASSERT_FALSE(s.nextGenerationNow());
ASSERT_EQUAL(1, s.getGeneration());
f1.updateGeneration(0, 2);
- ASSERT_TRUE(s.nextGeneration(0));
+ ASSERT_TRUE(s.nextGenerationNow());
ASSERT_EQUAL(2, s.getGeneration());
}
TEST_FFF("requireThatConfigHandleStillHasConfigOnTimestampUpdate", MyManager, APIFixture(f1), StandardFixture(f1, f2)) {
f1.updateGeneration(0, 2);
f1.updateGeneration(1, 2);
- ASSERT_TRUE(f3.s.nextGeneration(0));
+ ASSERT_TRUE(f3.s.nextGenerationNow());
verifyConfig("foo", f3.h1->getConfig());
verifyConfig("bar", f3.h2->getConfig());
}
@@ -418,7 +414,7 @@ TEST_FF("requireThatTimeStamp0Works", MyManager, APIFixture(f1)) {
f1.updateValue(0, createBarValue("bar"), 0);
f1.updateValue(1, createFooValue("foo"), 0);
f1.updateValue(2, createBazValue("baz"), 0);
- ASSERT_TRUE(s.nextConfig(0));
+ ASSERT_TRUE(s.nextConfigNow());
verifyConfig("bar", h2->getConfig());
verifyConfig("foo", h1->getConfig());
verifyConfig("baz", h3->getConfig());
@@ -432,58 +428,58 @@ TEST_FF("requireThatNextGenerationWorksWithManyConfigs", MyManager, APIFixture(f
f1.updateValue(0, createBarValue("bar"), 1);
f1.updateValue(1, createFooValue("foo"), 1);
f1.updateValue(2, createBazValue("baz"), 1);
- ASSERT_TRUE(s.nextGeneration(100));
+ ASSERT_TRUE(s.nextGeneration(100ms));
verifyConfig("bar", h2->getConfig());
verifyConfig("foo", h1->getConfig());
verifyConfig("baz", h3->getConfig());
int generation = 2;
f1.updateGeneration(0, generation);
- ASSERT_FALSE(s.nextGeneration(0));
+ ASSERT_FALSE(s.nextGenerationNow());
f1.updateGeneration(1, generation);
- ASSERT_FALSE(s.nextGeneration(0));
+ ASSERT_FALSE(s.nextGenerationNow());
f1.updateGeneration(2, generation);
- ASSERT_TRUE(s.nextGeneration(100));
+ ASSERT_TRUE(s.nextGeneration(100ms));
generation++;
f1.updateGeneration(0, generation);
- ASSERT_FALSE(s.nextGeneration(0));
+ ASSERT_FALSE(s.nextGenerationNow());
f1.updateGeneration(2, generation);
- ASSERT_FALSE(s.nextGeneration(0));
+ ASSERT_FALSE(s.nextGenerationNow());
f1.updateGeneration(1, generation);
- ASSERT_TRUE(s.nextGeneration(100));
+ ASSERT_TRUE(s.nextGeneration(100ms));
generation++;
f1.updateGeneration(1, generation);
- ASSERT_FALSE(s.nextGeneration(0));
+ ASSERT_FALSE(s.nextGenerationNow());
f1.updateGeneration(0, generation);
- ASSERT_FALSE(s.nextGeneration(0));
+ ASSERT_FALSE(s.nextGenerationNow());
f1.updateGeneration(2, generation);
- ASSERT_TRUE(s.nextGeneration(100));
+ ASSERT_TRUE(s.nextGeneration(100ms));
generation++;
f1.updateGeneration(1, generation);
- ASSERT_FALSE(s.nextGeneration(0));
+ ASSERT_FALSE(s.nextGenerationNow());
f1.updateGeneration(2, generation);
- ASSERT_FALSE(s.nextGeneration(0));
+ ASSERT_FALSE(s.nextGenerationNow());
f1.updateGeneration(0, generation);
- ASSERT_TRUE(s.nextGeneration(100));
+ ASSERT_TRUE(s.nextGeneration(100ms));
generation++;
f1.updateGeneration(2, generation);
- ASSERT_FALSE(s.nextGeneration(0));
+ ASSERT_FALSE(s.nextGenerationNow());
f1.updateGeneration(0, generation);
- ASSERT_FALSE(s.nextGeneration(0));
+ ASSERT_FALSE(s.nextGenerationNow());
f1.updateGeneration(1, generation);
- ASSERT_TRUE(s.nextGeneration(100));
+ ASSERT_TRUE(s.nextGeneration(100ms));
generation++;
f1.updateGeneration(2, generation);
- ASSERT_FALSE(s.nextGeneration(0));
+ ASSERT_FALSE(s.nextGenerationNow());
f1.updateGeneration(1, generation);
- ASSERT_FALSE(s.nextGeneration(0));
+ ASSERT_FALSE(s.nextGenerationNow());
f1.updateGeneration(0, generation);
- ASSERT_TRUE(s.nextGeneration(100));
+ ASSERT_TRUE(s.nextGeneration(100ms));
}
TEST_FF("requireThatConfigSubscriberHandlesProxyCache", MyManager, APIFixture(f1)) {
@@ -491,13 +487,13 @@ TEST_FF("requireThatConfigSubscriberHandlesProxyCache", MyManager, APIFixture(f1
ConfigHandle<FooConfig>::UP h1 = s.subscribe<FooConfig>("myid");
f1.updateValue(0, createFooValue("foo"), 1);
f1.updateGeneration(0, 2);
- ASSERT_TRUE(s.nextConfig(0));
+ ASSERT_TRUE(s.nextConfigNow());
ASSERT_EQUAL(2, s.getGeneration());
ASSERT_TRUE(h1->isChanged());
verifyConfig("foo", h1->getConfig());
f1.updateGeneration(0, 3);
- ASSERT_TRUE(s.nextGeneration(0));
+ ASSERT_TRUE(s.nextGenerationNow());
ASSERT_EQUAL(3, s.getGeneration());
ASSERT_FALSE(h1->isChanged());
verifyConfig("foo", h1->getConfig());
@@ -508,11 +504,11 @@ TEST_MT_FF("requireThatConfigSubscriberWaitsUntilNextConfigSucceeds", 2, MyManag
ConfigSubscriber s(IConfigContext::SP(new APIFixture(f2)));
ConfigHandle<FooConfig>::UP h1 = s.subscribe<FooConfig>("myid");
f1.updateValue(0, createFooValue("foo"), 1);
- ASSERT_TRUE(s.nextConfig(0));
+ ASSERT_TRUE(s.nextConfigNow());
f1.updateGeneration(0, 2);
- ASSERT_FALSE(s.nextConfig(1000));
+ ASSERT_FALSE(s.nextConfig(1000ms));
TEST_BARRIER();
- ASSERT_TRUE(s.nextConfig(2000));
+ ASSERT_TRUE(s.nextConfig(2000ms));
verifyConfig("foo2", h1->getConfig()); // First update is skipped
} else {
TEST_BARRIER();