mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Redesign CSF framework (RIPD-1361):
- Separate `Scheduler` from `BasicNetwork`. - Add an event/collector framework for monitoring invariants and calculating statistics. - Allow distinct network and trust connections between Peers. - Add a simple routing strategy to support broadcasting arbitrary messages. - Add a common directed graph (`Digraph`) class for representing network and trust topologies. - Add a `PeerGroup` class for simpler specification of the trust and network topologies. - Add a `LedgerOracle` class to ensure distinct ledger histories and simplify branch checking. - Add a `Submitter` to send transactions in at fixed or random intervals to fixed or random peers. Co-authored-by: Joseph McGee
This commit is contained in:
100
src/test/csf/Digraph_test.cpp
Normal file
100
src/test/csf/Digraph_test.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2017 Ripple Labs Inc.
|
||||
|
||||
Permission target use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <test/csf/Digraph.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
|
||||
class Digraph_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
using namespace csf;
|
||||
using Graph = Digraph<char,std::string>;
|
||||
Graph graph;
|
||||
|
||||
BEAST_EXPECT(!graph.connected('a', 'b'));
|
||||
BEAST_EXPECT(!graph.edge('a', 'b'));
|
||||
BEAST_EXPECT(!graph.disconnect('a', 'b'));
|
||||
|
||||
BEAST_EXPECT(graph.connect('a', 'b', "foobar"));
|
||||
BEAST_EXPECT(graph.connected('a', 'b'));
|
||||
BEAST_EXPECT(*graph.edge('a', 'b') == "foobar");
|
||||
|
||||
BEAST_EXPECT(!graph.connect('a', 'b', "repeat"));
|
||||
BEAST_EXPECT(graph.disconnect('a', 'b'));
|
||||
BEAST_EXPECT(graph.connect('a', 'b', "repeat"));
|
||||
BEAST_EXPECT(graph.connected('a', 'b'));
|
||||
BEAST_EXPECT(*graph.edge('a', 'b') == "repeat");
|
||||
|
||||
|
||||
BEAST_EXPECT(graph.connect('a', 'c', "tree"));
|
||||
|
||||
{
|
||||
std::vector<std::tuple<char, char, std::string>> edges;
|
||||
|
||||
for (auto const & edge : graph.outEdges('a'))
|
||||
{
|
||||
edges.emplace_back(edge.source, edge.target, edge.data);
|
||||
}
|
||||
|
||||
std::vector<std::tuple<char, char, std::string>> expected;
|
||||
expected.emplace_back('a', 'b', "repeat");
|
||||
expected.emplace_back('a', 'c', "tree");
|
||||
BEAST_EXPECT(edges == expected);
|
||||
BEAST_EXPECT(graph.outDegree('a') == expected.size());
|
||||
}
|
||||
|
||||
BEAST_EXPECT(graph.outEdges('r').size() == 0);
|
||||
BEAST_EXPECT(graph.outDegree('r') == 0);
|
||||
BEAST_EXPECT(graph.outDegree('c') == 0);
|
||||
|
||||
// only 'a' has out edges
|
||||
BEAST_EXPECT(graph.outVertices().size() == 1);
|
||||
std::vector<char> expected = {'b','c'};
|
||||
|
||||
BEAST_EXPECT((graph.outVertices('a') == expected));
|
||||
BEAST_EXPECT(graph.outVertices('b').size() == 0);
|
||||
BEAST_EXPECT(graph.outVertices('c').size() == 0);
|
||||
BEAST_EXPECT(graph.outVertices('r').size() == 0);
|
||||
|
||||
std::stringstream ss;
|
||||
graph.saveDot(ss, [](char v) { return v;});
|
||||
std::string expectedDot = "digraph {\n"
|
||||
"a -> b;\n"
|
||||
"a -> c;\n"
|
||||
"}\n";
|
||||
BEAST_EXPECT(ss.str() == expectedDot);
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(Digraph, test, ripple);
|
||||
|
||||
} // namespace test
|
||||
} // namespace ripple
|
||||
Reference in New Issue
Block a user