]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | #include <chrono> |
2 | #include <iostream> | |
3 | #include <numeric> | |
4 | #include <seastar/core/app-template.hh> | |
5 | #include "common/ceph_argparse.h" | |
6 | #include "crimson/common/config_proxy.h" | |
7 | #include "crimson/os/alienstore/thread_pool.h" | |
8 | #include "include/msgr.h" | |
9 | ||
10 | using namespace std::chrono_literals; | |
11 | using ThreadPool = crimson::os::ThreadPool; | |
12 | using crimson::common::local_conf; | |
13 | ||
14 | seastar::future<> test_accumulate(ThreadPool& tp) { | |
15 | static constexpr auto N = 5; | |
16 | static constexpr auto M = 1; | |
17 | auto slow_plus = [&tp](int i) { | |
20effc67 | 18 | return tp.submit(::rand() % 2, [=] { |
f67539c2 TL |
19 | std::this_thread::sleep_for(10ns); |
20 | return i + M; | |
21 | }); | |
22 | }; | |
23 | return seastar::map_reduce( | |
24 | boost::irange(0, N), slow_plus, 0, std::plus{}).then([] (int sum) { | |
25 | auto r = boost::irange(0 + M, N + M); | |
26 | if (sum != std::accumulate(r.begin(), r.end(), 0)) { | |
27 | throw std::runtime_error("test_accumulate failed"); | |
28 | } | |
29 | }); | |
30 | } | |
31 | ||
32 | seastar::future<> test_void_return(ThreadPool& tp) { | |
20effc67 | 33 | return tp.submit(::rand() % 2, [=] { |
f67539c2 TL |
34 | std::this_thread::sleep_for(10ns); |
35 | }); | |
36 | } | |
37 | ||
38 | int main(int argc, char** argv) | |
39 | { | |
40 | seastar::app_template app; | |
41 | return app.run(argc, argv, [] { | |
42 | std::vector<const char*> args; | |
43 | std::string cluster; | |
44 | std::string conf_file_list; | |
45 | auto init_params = ceph_argparse_early_args(args, | |
46 | CEPH_ENTITY_TYPE_CLIENT, | |
47 | &cluster, | |
48 | &conf_file_list); | |
49 | return crimson::common::sharded_conf().start(init_params.name, cluster) | |
50 | .then([conf_file_list] { | |
51 | return local_conf().parse_config_files(conf_file_list); | |
52 | }).then([] { | |
20effc67 | 53 | return seastar::do_with(std::make_unique<crimson::os::ThreadPool>(2, 128, (std::vector<uint64_t>){0}), |
f67539c2 TL |
54 | [](auto& tp) { |
55 | return tp->start().then([&tp] { | |
56 | return test_accumulate(*tp); | |
57 | }).then([&tp] { | |
58 | return test_void_return(*tp); | |
59 | }).finally([&tp] { | |
60 | return tp->stop(); | |
61 | }); | |
62 | }); | |
63 | }).finally([] { | |
64 | return crimson::common::sharded_conf().stop(); | |
65 | }).handle_exception([](auto e) { | |
66 | std::cerr << "Error: " << e << std::endl; | |
67 | seastar::engine().exit(1); | |
68 | }); | |
69 | }); | |
70 | } | |
71 | ||
72 | /* | |
73 | * Local Variables: | |
74 | * compile-command: "make -j4 \ | |
75 | * -C ../../../build \ | |
76 | * unittest_seastar_thread_pool" | |
77 | * End: | |
78 | */ |