Tests: PityTest - PitySwarm singletyped tree

LIB-11
heck 2 years ago
parent c580adbdcf
commit 09820f9e6d

@ -1,6 +1,7 @@
#include "PitySwarm.hh"
#include "PityModel.hh"
#include "PityPerspective.hh"
#include "PityUnit.hh"
#include "PitySwarm.hh"
#include <vector>
#include <functional>
@ -10,6 +11,7 @@ namespace pEp {
namespace PityTest11 {
bool PitySwarm::debug_log_enabled = false;
// The perspective currently is complete defined by specifying a node, since there is a 1-1 node/ident relationship currently
void createPerspective(const PityModel& model, PityPerspective* psp, int node_nr)
{
psp->name = model.nodeNr(node_nr)->getName();
@ -32,20 +34,20 @@ namespace pEp {
pEpLogClass("called");
// Create perspective
for (auto n : _model.nodes()) {
auto tmp = std::make_shared<PityPerspective>();
auto tmp = std::make_shared<PityPerspective>(model);
createPerspective(_model, tmp.get(), n->getNr());
_perspectives.push_back(tmp);
}
// Construct Tree
_rootUnit = std::make_shared<PityUnit<PityModel, PityPerspective>>(
_rootUnit = std::make_shared<PityUnit<PityPerspective>>(
nullptr,
_model.getName(),
nullptr,
&_model);
nullptr);
for (auto n : _model.nodes()) {
_nodeUnits.push_back(std::make_shared<PityUnit<>>(
_nodeUnits.push_back(std::make_shared<PityUnit<PityPerspective>>(
_rootUnit.get(),
n->getName(),
nullptr,
@ -55,29 +57,23 @@ namespace pEp {
// std::placeholders::_1,
// std::placeholders::_2,
// std::placeholders::_3),
&_model,
_perspectives.at(n->getNr()).get(),
PityUnit<>::ExecutionMode::PROCESS_PARALLEL));
PityUnit<PityPerspective>::ExecutionMode::PROCESS_PARALLEL));
}
}
void PitySwarm::addTestUnit(
int nodeNr,
const std::string& name,
std::function<void(PityUnit<>&, PityModel*, PityPerspective*)> test_func)
PityUnit<PityPerspective>::TestFunction test_func)
{
auto tmp = std::make_shared <PityUnit<>>(_nodeUnits.at(nodeNr).get(), name, test_func);
auto tmp = std::make_shared<PityUnit<PityPerspective>>(_nodeUnits.at(nodeNr).get(), name, test_func);
_testUnits.push_back(tmp);
}
void PitySwarm::run()
{
_rootUnit->run();
}
} // namespace PityTest11
} // namespace pEp

@ -6,6 +6,7 @@
#include "PityModel.hh"
#include "PityUnit.hh"
#include "PityPerspective.hh"
#include "../../../src/pEpLog.hh"
#include <vector>
#include <memory>
@ -21,7 +22,7 @@ namespace pEp {
void addTestUnit(
int nodeNr,
const std::string& name,
std::function<void(PityUnit<>&, PityModel*, PityPerspective*)> test_func);
PityUnit<PityPerspective>::TestFunction test_func);
//Run
void run();
@ -32,9 +33,9 @@ namespace pEp {
private:
PityModel& _model;
std::shared_ptr<PityUnit<>> _rootUnit;
std::vector<std::shared_ptr<PityUnit<>>> _nodeUnits;
std::vector<std::shared_ptr<PityUnit<>>> _testUnits;
std::shared_ptr<PityUnit<PityPerspective>> _rootUnit;
std::vector<std::shared_ptr<PityUnit<PityPerspective>>> _nodeUnits;
std::vector<std::shared_ptr<PityUnit<PityPerspective>>> _testUnits;
std::vector<std::shared_ptr<PityPerspective>> _perspectives;
//internal logging

@ -1,42 +1,41 @@
#include "../src/PityUnit.hh"
#include "../src/PityModel.hh"
#include "../../../src/std_utils.hh"
#include "../src/PitySwarm.hh"
#include "../src/PityPerspective.hh"
using namespace pEp;
using namespace pEp::Adapter;
using namespace pEp::PityTest11;
void test_node1(const PityUnit<PityModel>& unit)
void test_node1(PityUnit<PityPerspective>& unit, PityPerspective* psp)
{
unit.log("ModelName:" + unit.getModel()->getName());
unit.log("own_node:" + unit.getModel()->own_node->getName());
unit.log("partner:" + unit.getModel()->own_node->partner);
unit.log("ModelName:" + psp->model.getName());
unit.log("perspective name:" + psp->name);
unit.log("perspective partner:" + psp->partner);
std::string msg = "Message from: " + unit.getPathShort();
int throttle = 10;
int throttle = 1000;
while (true) {
Utils::sleep_millis(throttle);
for (auto peer : unit.getModel()->own_node->peers) {
unit.getModel()->sendMsg(peer, msg);
Utils::sleep_millis(throttle);
for (auto peer : unit.transportEndpoints()) {
unit.transport()->sendMsg(peer.first,msg);
}
while (unit.getModel()->hasMsg()) {
unit.log("MSG RX:" + unit.getModel()->receiveMsg());
Utils::sleep_millis(throttle);
while (unit.transport()->hasMsg()) {
unit.log("MSG RX:" + unit.transport()->receiveMsg());
}
}
}
int main(int argc, char* argv[])
{
int nodesCount = 64;
int nodesCount = 3;
PityModel model{ "test_swarm", nodesCount };
PitySwarm swarm{model};
std::vector<std::shared_ptr<PityUnit<PityModel>>> nodeUnits;
for (int i = 0; i < nodesCount; i++) {
nodeUnits.emplace_back(std::make_shared<PityUnit<PityModel>>(model.unitOfNodeNr(i), "test1", &test_node1 ));
for(int i = 0; i < nodesCount; i++) {
swarm.addTestUnit(i,"test1",&test_node1);
}
model.run();
swarm.run();
}
Loading…
Cancel
Save