Line data Source code
1 : /*
2 : Copyright 2018-2020, Barcelona Supercomputing Center (BSC), Spain
3 : Copyright 2015-2020, Johannes Gutenberg Universitaet Mainz, Germany
4 :
5 : This software was partially supported by the
6 : EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).
7 :
8 : This software was partially supported by the
9 : ADA-FS project under the SPPEXA project funded by the DFG.
10 :
11 : SPDX-License-Identifier: MIT
12 : */
13 :
14 : #include <catch2/catch.hpp>
15 : #include <fmt/format.h>
16 : #include <common/rpc/distributor.hpp>
17 : #include <fstream>
18 :
19 1 : TEST_CASE( "Guided distributor Testing", "[Distributor]" ) {
20 :
21 4 : GIVEN( "A distributor" ) {
22 : // Generate a guided.txt that will put some files in
23 : // the server num 4
24 2 : std::ofstream o;
25 1 : o.open("/tmp/guided.txt");
26 1 : o << "/t.c01 0 3" << std::endl;
27 1 : o << "/t.c02 0 3" << std::endl;
28 1 : o << "/t.c01 1 3" << std::endl;
29 1 : o << "/t.c02 1 3" << std::endl;
30 1 : o << "/t.c01 2 3" << std::endl;
31 1 : o << "/t.c02 2 3" << std::endl;
32 1 : o << "/t.c03 1 3" << std::endl;
33 1 : o << "/t.c04 1 3" << std::endl;
34 1 : o << "/t.c05 1 3" << std::endl;
35 1 : o << "/t.c06 1 3" << std::endl;
36 1 : o << "/t.c07 1 3" << std::endl;
37 1 : o.close();
38 :
39 : // The distributor should return 3 for all the tested files
40 1 : auto d = gkfs::rpc::GuidedDistributor();
41 :
42 2 : REQUIRE( d.locate_data("/t.c01",1,10,0) == 3 );
43 2 : REQUIRE( d.locate_data("/t.c02",1,10,0) == 3 );
44 2 : REQUIRE( d.locate_data("/t.c03",1,10,0) == 3 );
45 2 : REQUIRE( d.locate_data("/t.c04",1,10,0) == 3 );
46 2 : REQUIRE( d.locate_data("/t.c05",1,10,0) == 3 );
47 2 : REQUIRE( d.locate_data("/t.c06",1,10,0) == 3 );
48 2 : REQUIRE( d.locate_data("/t.c07",1,10,0) == 3 );
49 :
50 : // Next result is random, but with the same seed is consistent
51 : // We ask for chunk 5 that is distributed randomly between the
52 : // 10 servers.
53 4 : REQUIRE ( (d.locate_data("/t.c01",5,10,0) +
54 : d.locate_data("/t.c02",5,10,0) +
55 : d.locate_data("/t.c03",5,10,0) +
56 : d.locate_data("/t.c04",5,10,0) +
57 : d.locate_data("/t.c05",5,10,0) +
58 : d.locate_data("/t.c06",5,10,0) +
59 2 : d.locate_data("/t.c07",5,10,0) ) == 42);
60 : }
61 1 : }
|