summaryrefslogtreecommitdiffstats
path: root/filedistribution/src/tests/rpc/testfileprovider.cpp
blob: acf1208643726c00b393af9048bf57d2e5ea5f75 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN

#include "mockfileprovider.h"
#include <vespa/filedistribution/rpc/filedistributorrpc.h>
#include <vespa/frtstream/frtclientstream.h>
#include <vespa/fnet/frt/rpcrequest.h>
#include <vespa/fnet/frt/target.h>
#include <boost/test/unit_test.hpp>

namespace fd = filedistribution;

using fd::MockFileProvider;

const std::string MockFileProvider::_queueForeverFileReference("queue-forever");

BOOST_AUTO_TEST_CASE(fileDistributionRPCTest) {
    const std::string spec("tcp/localhost:9111");
    fd::FileProvider::SP provider(new fd::MockFileProvider());
    fd::FileDistributorRPC::SP fileDistributorRPC(new fd::FileDistributorRPC(spec, provider));
    fileDistributorRPC->start();

    frtstream::FrtClientStream rpc(spec);
    frtstream::Method method("waitFor");

    std::string path;
    rpc <<method <<"dd";
    rpc >> path;
    BOOST_CHECK_EQUAL("direct/result/path", path);

    rpc <<method <<"0123456789abcdef";
    rpc >> path;
    BOOST_CHECK_EQUAL("downloaded/path/0123456789abcdef", path);
}

//must be run through valgrind
BOOST_AUTO_TEST_CASE(require_that_queued_requests_does_not_leak_memory) {
    const std::string spec("tcp/localhost:9111");
    std::shared_ptr<MockFileProvider> provider(new MockFileProvider());
    fd::FileDistributorRPC::SP fileDistributorRPC(new fd::FileDistributorRPC(spec, provider));
    fileDistributorRPC->start();

    FRT_Supervisor supervisor;

    supervisor.Start();
    FRT_Target *target = supervisor.GetTarget(spec.c_str());

    FRT_RPCRequest* request = supervisor.AllocRPCRequest();
    request->SetMethodName("waitFor");
    request->GetParams()->AddString(MockFileProvider::_queueForeverFileReference.c_str());
    target->InvokeVoid(request);

    provider->_queueForeverBarrier.wait(); //the request has been enqueued.
    fileDistributorRPC.reset();

    target->SubRef();
    supervisor.ShutDown(true);

}

BOOST_AUTO_TEST_CASE(require_that_port_can_be_extracted_from_connection_spec) {
    BOOST_CHECK_EQUAL(9056, fd::FileDistributorRPC::get_port("tcp/host:9056"));
    BOOST_CHECK_EQUAL(9056, fd::FileDistributorRPC::get_port("tcp/9056"));
    BOOST_CHECK_EQUAL(9056, fd::FileDistributorRPC::get_port("9056"));
}