blob: fd66acfb0fcbedcd8c6eef64bff9ecdf23b96017 (
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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespa/filedistribution/rpc/fileprovider.h>
#include <boost/thread/barrier.hpp>
namespace filedistribution {
class MockFileProvider : public FileProvider {
DownloadCompletedSignal _downloadCompleted;
DownloadFailedSignal _downloadFailed;
public:
static const std::string _queueForeverFileReference;
boost::barrier _queueForeverBarrier;
boost::optional<Path> getPath(const std::string& fileReference) override {
if (fileReference == "dd") {
return Path("direct/result/path");
} else {
return boost::optional<Path>();
}
}
void downloadFile(const std::string& fileReference) override {
if (fileReference == _queueForeverFileReference) {
_queueForeverBarrier.wait();
return;
}
sleep(1);
downloadCompleted()(fileReference, "downloaded/path/" + fileReference);
}
DownloadCompletedSignal& downloadCompleted() override {
return _downloadCompleted;
}
DownloadFailedSignal& downloadFailed() override {
return _downloadFailed;
}
MockFileProvider()
:_queueForeverBarrier(2)
{}
};
} //namespace filedistribution
|