xrpld
Loading...
Searching...
No Matches
SHAMapAddNode.cpp
1#include <xrpl/shamap/SHAMapAddNode.h>
2
3#include <gtest/gtest.h>
4
5namespace xrpl::tests {
6
7// get() is a log format, so its wording is pinned here, once. Every other site reads the same tally
8// by value, through the count and verdict accessors.
9TEST(SHAMapAddNode, get_names_every_non_empty_count)
10{
11 EXPECT_EQ(SHAMapAddNode{}.get(), "no nodes processed");
12 EXPECT_EQ(SHAMapAddNode::useful().get(), "good:1");
13 EXPECT_EQ(SHAMapAddNode::invalid().get(), "bad:1");
14 EXPECT_EQ(SHAMapAddNode::duplicate().get(), "dupe:1");
15
16 // Several of a kind are counted, and the counts are joined in a fixed order with a single
17 // space, whichever order they were recorded in.
18 SHAMapAddNode san;
19 san.incInvalid();
20 san.incUseful();
21 san.incUseful();
22 san.incDuplicate();
23 EXPECT_EQ(san.get(), "good:2 bad:1 dupe:1");
24
25 san.reset();
26 EXPECT_EQ(san.get(), "no nodes processed");
27}
28
29// The three counts and the verdicts derived from them.
30TEST(SHAMapAddNode, counts_and_verdicts_agree)
31{
32 SHAMapAddNode san;
33 EXPECT_EQ(san.getGood(), 0);
34 EXPECT_EQ(san.getBad(), 0);
35 EXPECT_EQ(san.getDuplicate(), 0);
36 EXPECT_FALSE(san.isInvalid());
37 EXPECT_FALSE(san.isUseful());
38
39 // Good counts what produced a good result, and useful is that count being non-zero.
40 san.incUseful();
41 EXPECT_EQ(san.getGood(), 1);
42 EXPECT_TRUE(san.isUseful());
43 EXPECT_TRUE(san.isGood());
44
45 // A duplicate counts toward good. isUseful() here reflects the incUseful() above.
46 san.incDuplicate();
47 EXPECT_EQ(san.getDuplicate(), 1);
48 EXPECT_FALSE(san.isInvalid());
49 EXPECT_TRUE(san.isGood());
50
51 // Bad is a count, so a batch that carries on past a rejected node reports one per node, which
52 // distinguishes "stopped on the first" from "rejected several".
53 san.incInvalid();
54 EXPECT_EQ(san.getBad(), 1);
55 EXPECT_TRUE(san.isInvalid());
56 EXPECT_TRUE(san.isGood()) << "one bad node among two accepted ones is still a good batch";
57
58 san.incInvalid();
59 san.incInvalid();
60 EXPECT_EQ(san.getGood(), 1);
61 EXPECT_EQ(san.getBad(), 3);
62 EXPECT_EQ(san.getDuplicate(), 1);
63 EXPECT_FALSE(san.isGood()) << "more bad nodes than accepted ones is not a good batch";
64
65 // Adding one verdict to another sums every count.
66 SHAMapAddNode total;
67 total += SHAMapAddNode::useful();
68 total += SHAMapAddNode::invalid();
69 total += SHAMapAddNode::invalid();
70 total += SHAMapAddNode::duplicate();
71 EXPECT_EQ(total.getGood(), 1);
72 EXPECT_EQ(total.getBad(), 2);
73 EXPECT_EQ(total.getDuplicate(), 1);
74}
75
76} // namespace xrpl::tests
void incDuplicate()
Record one node that was not needed: the map already held it, or the map or its acquisition was no lo...
void reset()
Clear every count back to zero.
int getDuplicate() const
void incUseful()
Record one node that produced a good result.
static SHAMapAddNode duplicate()
static SHAMapAddNode useful()
bool isInvalid() const
bool isGood() const
Whether nodes that produced a good result or were not needed outnumber the ones rejected.
std::string get() const
Render the tally as a log line.
void incInvalid()
Record one node that was rejected.
static SHAMapAddNode invalid()
bool isUseful() const
TEST(IntrusiveSharedTest, ref_counts_on_a_bare_object)
T get(Section const &section, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.