diff --git a/test/pitytest11/src/PitySwarm.cc b/test/pitytest11/src/PitySwarm.cc index 7bb21ca..b8a9c1e 100644 --- a/test/pitytest11/src/PitySwarm.cc +++ b/test/pitytest11/src/PitySwarm.cc @@ -1,6 +1,7 @@ +#include "PitySwarm.hh" #include "PityModel.hh" +#include "PityPerspective.hh" #include "PityUnit.hh" -#include "PitySwarm.hh" #include #include @@ -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(); + auto tmp = std::make_shared(model); createPerspective(_model, tmp.get(), n->getNr()); _perspectives.push_back(tmp); } // Construct Tree - _rootUnit = std::make_shared>( + _rootUnit = std::make_shared>( nullptr, _model.getName(), nullptr, - &_model); + nullptr); for (auto n : _model.nodes()) { - _nodeUnits.push_back(std::make_shared>( + _nodeUnits.push_back(std::make_shared>( _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::ExecutionMode::PROCESS_PARALLEL)); } } void PitySwarm::addTestUnit( int nodeNr, const std::string& name, - std::function&, PityModel*, PityPerspective*)> test_func) + PityUnit::TestFunction test_func) { - auto tmp = std::make_shared >(_nodeUnits.at(nodeNr).get(), name, test_func); + auto tmp = std::make_shared>(_nodeUnits.at(nodeNr).get(), name, test_func); _testUnits.push_back(tmp); } - - void PitySwarm::run() { - _rootUnit->run(); } - - } // namespace PityTest11 } // namespace pEp diff --git a/test/pitytest11/src/PitySwarm.hh b/test/pitytest11/src/PitySwarm.hh index 0bd9c26..05e54ec 100644 --- a/test/pitytest11/src/PitySwarm.hh +++ b/test/pitytest11/src/PitySwarm.hh @@ -6,6 +6,7 @@ #include "PityModel.hh" #include "PityUnit.hh" +#include "PityPerspective.hh" #include "../../../src/pEpLog.hh" #include #include @@ -21,7 +22,7 @@ namespace pEp { void addTestUnit( int nodeNr, const std::string& name, - std::function&, PityModel*, PityPerspective*)> test_func); + PityUnit::TestFunction test_func); //Run void run(); @@ -32,9 +33,9 @@ namespace pEp { private: PityModel& _model; - std::shared_ptr> _rootUnit; - std::vector>> _nodeUnits; - std::vector>> _testUnits; + std::shared_ptr> _rootUnit; + std::vector>> _nodeUnits; + std::vector>> _testUnits; std::vector> _perspectives; //internal logging diff --git a/test/pitytest11/test/test_swarm.cc b/test/pitytest11/test/test_swarm.cc index 0601c9e..eb6ebe5 100644 --- a/test/pitytest11/test/test_swarm.cc +++ b/test/pitytest11/test/test_swarm.cc @@ -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& unit) +void test_node1(PityUnit& 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>> nodeUnits; - for (int i = 0; i < nodesCount; i++) { - nodeUnits.emplace_back(std::make_shared>(model.unitOfNodeNr(i), "test1", &test_node1 )); + for(int i = 0; i < nodesCount; i++) { + swarm.addTestUnit(i,"test1",&test_node1); } - model.run(); + swarm.run(); } \ No newline at end of file