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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/config.hpp"
#define CAF_SUITE local_migration
#include "caf/test/unit_test.hpp"
/* --- "disabled" (see #199) ---
#include "caf/all.hpp"
#include "caf/actor_registry.hpp"
using namespace caf;
using std::endl;
namespace {
struct migratable_state {
int value = 0;
static const char* name;
};
const char* migratable_state::name = "migratable_actor";
template <class Processor>
void serialize(Processor& proc, migratable_state& x, const unsigned int) {
proc & x.value;
}
struct migratable_actor : stateful_actor<migratable_state> {
migratable_actor(actor_config& cfg) : stateful_actor<migratable_state>(cfg) {
// nop
}
behavior make_behavior() override {
return {
[=](get_atom) {
return state.value;
},
[=](put_atom, int value) {
state.value = value;
}
};
}
};
// always migrates to `dest`
behavior pseudo_mm(event_based_actor* self, const actor& dest) {
return {
[=](migrate_atom, const std::string& name, std::vector<char>& buf) {
CAF_CHECK(name == "migratable_actor");
self->delegate(dest, sys_atom_v, migrate_atom_v,
std::move(buf));
}
};
}
} // namespace
CAF_TEST(migrate_locally) {
actor_system system;
auto a = system.spawn<migratable_actor>();
auto b = system.spawn<migratable_actor>();
auto mm1 = system.spawn(pseudo_mm, b);
{ // Lifetime scope of scoped_actor
scoped_actor self{system};
self->send(a, put_atom_v, 42);
// migrate from a to b
self->request(a, infinite, sys_atom_v,
migrate_atom_v, mm1).receive(
[&](ok_atom, const actor_addr& dest) {
CAF_CHECK(dest == b);
}
);
self->request(a, infinite, get_atom_v).receive(
[&](int result) {
CAF_CHECK(result == 42);
CAF_CHECK(self->current_sender() == b.address());
}
);
auto mm2 = system.spawn(pseudo_mm, a);
self->send(b, put_atom_v, 23);
// migrate back from b to a
self->request(b, infinite, sys_atom_v,
migrate_atom_v, mm2).receive(
[&](ok_atom, const actor_addr& dest) {
CAF_CHECK(dest == a);
}
);
self->request(b, infinite, get_atom_v).receive(
[&](int result) {
CAF_CHECK(result == 23);
CAF_CHECK(self->current_sender() == a.address());
}
);
self->send_exit(a, exit_reason::kill);
self->send_exit(b, exit_reason::kill);
self->send_exit(mm1, exit_reason::kill);
self->send_exit(mm2, exit_reason::kill);
self->await_all_other_actors_done();
}
}
*/
CAF_TEST(migrate_locally) {
// nop
}
|