summaryrefslogtreecommitdiffstats
path: root/config/src/tests/file_acquirer/file_acquirer_test.cpp
blob: 0d2e2bf914495ab39cdab0588d1917ec78c710f7 (plain) (blame)
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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/config/file_acquirer/file_acquirer.h>
#include <vespa/fnet/frt/frt.h>
#include <vespa/vespalib/util/stringfmt.h>

using namespace config;

struct ServerFixture : FRT_Invokable {
    FRT_Supervisor orb;
    vespalib::string spec;
    void init_rpc() {
        FRT_ReflectionBuilder rb(&orb);
        rb.DefineMethod("waitFor", "s", "s", true, FRT_METHOD(ServerFixture::RPC_waitFor), this);
        rb.MethodDesc("wait for and resolve file reference");
        rb.ParamDesc("file_ref", "file reference to wait for and resolve");
        rb.ReturnDesc("file_path", "actual path to the requested file");
    }
    ServerFixture() : orb() {
        init_rpc();
        orb.Listen(0);
        spec = vespalib::make_string("tcp/localhost:%d", orb.GetListenPort());
        orb.Start();
    }
    void RPC_waitFor(FRT_RPCRequest *req) {
        FRT_Values &params = *req->GetParams();
        FRT_Values &ret    = *req->GetReturn();
        if (strcmp(params[0]._string._str, "my_ref") == 0) {
            ret.AddString("my_path");
        } else {
            req->SetError(FRTE_RPC_METHOD_FAILED, "invalid file reference");
        }
    }
    ~ServerFixture() {
        orb.ShutDown(true);
    }
};

TEST_FF("require that files can be acquired over rpc", ServerFixture(), RpcFileAcquirer(f1.spec)) {
    EXPECT_EQUAL("my_path", f2.wait_for("my_ref", 60.0));
    EXPECT_EQUAL("", f2.wait_for("bogus_ref", 60.0));
}

TEST_MAIN() { TEST_RUN_ALL(); }