blob: f05eebed0ce9535752bd7b1347d7cbd2c32b7207 (
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/fastos/fastos.h>
#include <vespa/vdstestlib/cppunit/macros.h>
#include <tests/common/testhelper.h>
#include <tests/distributor/distributortestutil.h>
#include <vespa/storage/distributor/statusreporterdelegate.h>
namespace storage {
namespace distributor {
class StatusReporterDelegateTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(StatusReporterDelegateTest);
CPPUNIT_TEST(testDelegateInvokesDelegatorOnStatusRequest);
CPPUNIT_TEST_SUITE_END();
void testDelegateInvokesDelegatorOnStatusRequest();
};
CPPUNIT_TEST_SUITE_REGISTRATION(StatusReporterDelegateTest);
namespace {
// We really ought to get GoogleMock as part of our testing suite...
class MockDelegator : public StatusDelegator
{
mutable std::ostringstream _calls;
bool handleStatusRequest(const DelegatedStatusRequest& request) const {
_calls << "Request(" << request.path << ")";
return request.reporter.reportStatus(request.outputStream, request.path);
}
public:
std::string getCalls() const {
return _calls.str();
}
};
class MockStatusReporter : public framework::StatusReporter
{
public:
MockStatusReporter()
: framework::StatusReporter("foo", "Bar")
{}
vespalib::string getReportContentType(
const framework::HttpUrlPath&) const
{
return "foo/bar";
}
bool reportStatus(std::ostream& os,
const framework::HttpUrlPath& path) const
{
os << "reportStatus with " << path;
return true;
}
};
}
void
StatusReporterDelegateTest::testDelegateInvokesDelegatorOnStatusRequest()
{
vdstestlib::DirConfig config(getStandardConfig(false));
TestDistributorApp app(config.getConfigId());
MockDelegator mockDelegator;
MockStatusReporter reporter;
StatusReporterDelegate delegate(app.getComponentRegister(),
mockDelegator,
reporter);
framework::HttpUrlPath path("dummy");
CPPUNIT_ASSERT_EQUAL(vespalib::string("foo/bar"),
delegate.getReportContentType(path));
std::ostringstream ss;
CPPUNIT_ASSERT(delegate.reportStatus(ss, path));
CPPUNIT_ASSERT_EQUAL(std::string("Request(dummy)"),
mockDelegator.getCalls());
CPPUNIT_ASSERT_EQUAL(std::string("reportStatus with dummy"),
ss.str());
}
} // distributor
} // storage
|