diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /messagebus/src/tests/retrypolicy/retrypolicy.cpp |
Publish
Diffstat (limited to 'messagebus/src/tests/retrypolicy/retrypolicy.cpp')
-rw-r--r-- | messagebus/src/tests/retrypolicy/retrypolicy.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/messagebus/src/tests/retrypolicy/retrypolicy.cpp b/messagebus/src/tests/retrypolicy/retrypolicy.cpp new file mode 100644 index 00000000000..5426a1123cd --- /dev/null +++ b/messagebus/src/tests/retrypolicy/retrypolicy.cpp @@ -0,0 +1,39 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/fastos/fastos.h> +#include <vespa/log/log.h> +LOG_SETUP("retrypolicy_test"); + +#include <vespa/messagebus/errorcode.h> +#include <vespa/messagebus/routing/retrytransienterrorspolicy.h> +#include <vespa/vespalib/testkit/testapp.h> + +using namespace mbus; + +TEST_SETUP(Test); + +int +Test::Main() +{ + TEST_INIT("retrypolicy_test"); + + RetryTransientErrorsPolicy policy; + for (uint32_t i = 0; i < 5; ++i) { + double delay = i / 3.0; + policy.setBaseDelay(delay); + for (uint32_t j = 0; j < 5; ++j) { + EXPECT_EQUAL((int)(j * delay), (int)policy.getRetryDelay(j)); + } + for (uint32_t j = ErrorCode::NONE; j < ErrorCode::ERROR_LIMIT; ++j) { + policy.setEnabled(true); + if (j < ErrorCode::FATAL_ERROR) { + EXPECT_TRUE(policy.canRetry(j)); + } else { + EXPECT_TRUE(!policy.canRetry(j)); + } + policy.setEnabled(false); + EXPECT_TRUE(!policy.canRetry(j)); + } + } + + TEST_DONE(); +} |