1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
// 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("backoff_test");
#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/slobrok/backoff.h>
#include <algorithm>
using slobrok::api::BackOff;
TEST_SETUP(Test);
//-----------------------------------------------------------------------------
static double expectWait[21] = {
0.5, 1.0, 1.5, 2.0, 2.5,
3.0, 3.5, 4.0, 4.5,
5.0, 6.0, 7.0, 8.0, 9.0,
10, 15, 20, 25, 30, 30, 30
};
int
Test::Main()
{
TEST_INIT("backoff_test");
BackOff one;
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(0.500, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(1.000, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(1.500, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(2.000, one.get());
EXPECT_TRUE(one.shouldWarn());
EXPECT_EQUAL(2.500, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(3.000, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(3.500, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(4.000, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(4.500, one.get());
EXPECT_TRUE(one.shouldWarn());
EXPECT_EQUAL(5.000, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(6.000, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(7.000, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(8.000, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(9.000, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(10.00, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(15.00, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(20.00, one.get());
EXPECT_TRUE(one.shouldWarn());
EXPECT_EQUAL(25.00, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(30.00, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(30.00, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(30.00, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(30.00, one.get());
EXPECT_FALSE(one.shouldWarn());
EXPECT_EQUAL(30.00, one.get());
EXPECT_FALSE(one.shouldWarn());
TEST_FLUSH();
BackOff two;
for (int i = 0; i < 21; i++) {
EXPECT_EQUAL(expectWait[i], two.get());
if (i == 3 || i == 8 || i == 16) {
EXPECT_TRUE(two.shouldWarn());
} else {
EXPECT_FALSE(two.shouldWarn());
}
}
two.reset();
for (int i = 0; i < 21; i++) {
EXPECT_EQUAL(expectWait[i], two.get());
if (i == 7 || i == 15) {
EXPECT_TRUE(two.shouldWarn());
} else {
EXPECT_FALSE(two.shouldWarn());
}
}
TEST_DONE();
}
|