Skip to content
Snippets Groups Projects
Commit 9044e153 authored by Sergey Yakubov's avatar Sergey Yakubov
Browse files

fix path for big files

parent 3bf39f1f
Branches
Tags
No related merge requests found
......@@ -163,4 +163,14 @@ const std::string& Request::GetBeamtimeYear() const {
return beamtime_year_;
}
std::string Request::GetFullPath(std::string root_folder) const {
return std::move(root_folder) + kPathSeparator
+ GetFacility() + kPathSeparator
+ "gpfs" + kPathSeparator
+ GetBeamline() + kPathSeparator
+ GetBeamtimeYear() + kPathSeparator
+ "data" + kPathSeparator
+ GetBeamtimeId();
}
}
\ No newline at end of file
......@@ -54,6 +54,9 @@ class Request {
VIRTUAL const std::string& GetFacility() const;
VIRTUAL const std::string& GetBeamtimeYear() const;
VIRTUAL std::string GetFullPath(std::string root_folder) const;
VIRTUAL const std::string& GetBeamline() const;
VIRTUAL const CustomRequestData& GetCustomData() const;
VIRTUAL Error PrepareDataBufferAndLockIfNeeded();
......
......@@ -11,9 +11,7 @@ Error RequestHandlerFileReceive::ProcessRequest(Request* request) const {
auto fsize = request->GetDataSize();
auto socket = request->GetSocket();
auto fname = request->GetFileName();
auto root_folder = GetReceiverConfig()->root_folder + kPathSeparator
+ request->GetBeamline() + kPathSeparator
+ request->GetBeamtimeId();
auto root_folder = request->GetFullPath(GetReceiverConfig()->root_folder);
auto err = io__->ReceiveDataToFile(socket, root_folder, fname, (size_t) fsize, true);
if (!err) {
log__->Debug("received file of size " + std::to_string(fsize) + " to " + root_folder + kPathSeparator + fname);
......
......@@ -16,14 +16,7 @@ Error RequestHandlerFileWrite::ProcessRequest(Request* request) const {
auto data = request->GetData();
auto fname = request->GetFileName();
auto root_folder = GetReceiverConfig()->root_folder + kPathSeparator
+ request->GetFacility() + kPathSeparator
+ "gpfs" + kPathSeparator
+ request->GetBeamline() + kPathSeparator
+ request->GetBeamtimeYear() + kPathSeparator
+ "data" + kPathSeparator
+ request->GetBeamtimeId();
auto root_folder = request->GetFullPath(GetReceiverConfig()->root_folder);
auto err = io__->WriteDataToFile(root_folder, fname, (uint8_t*)data, (size_t) fsize, true);
if (!err) {
log__->Debug("saved file of size " + std::to_string(fsize) + " to " + root_folder + kPathSeparator + fname);
......
......@@ -71,6 +71,8 @@ class MockRequest: public Request {
MOCK_METHOD1(SetBeamline, void (std::string));
MOCK_METHOD1(SetFacility, void (std::string));
MOCK_METHOD1(SetBeamtimeYear, void (std::string));
MOCK_CONST_METHOD1(GetFullPath, std::string (std::string));
};
......
......@@ -231,6 +231,21 @@ TEST_F(RequestTests, RequestTests_SetGetBeamtimeYear_Test) {
ASSERT_THAT(request->GetBeamtimeYear(), "2020");
}
TEST_F(RequestTests, RequestTests_GetFullPath) {
request->SetFacility("test_facility");
request->SetBeamtimeYear("2020");
request->SetBeamtimeId("beamtime");
request->SetBeamline("beamline");
std::string expected_path = std::string("test_folder") + asapo::kPathSeparator + "test_facility" +
asapo::kPathSeparator + "gpfs" +
asapo::kPathSeparator + "beamline" +
asapo::kPathSeparator + "2020" +
asapo::kPathSeparator + "data" +
asapo::kPathSeparator + "beamtime";
ASSERT_THAT(request->GetFullPath("test_folder"), expected_path);
}
}
......@@ -59,6 +59,16 @@ class FileReceiveHandlerTests : public Test {
std::string expected_file_name = "2";
std::string expected_beamtime_id = "beamtime_id";
std::string expected_beamline = "beamline";
std::string expected_root_folder = "root_folder";
std::string expected_facility = "facility";
std::string expected_year = "2020";
std::string expected_full_path = expected_root_folder + asapo::kPathSeparator + expected_facility +
asapo::kPathSeparator + "gpfs" +
asapo::kPathSeparator + expected_beamline +
asapo::kPathSeparator + expected_year +
asapo::kPathSeparator + "data" +
asapo::kPathSeparator + expected_beamtime_id;
uint64_t expected_file_size = 10;
void MockRequestData();
void SetUp() override {
......@@ -88,13 +98,8 @@ void FileReceiveHandlerTests::MockRequestData() {
.WillOnce(Return(expected_socket_id))
;
EXPECT_CALL(*mock_request, GetBeamtimeId())
.WillOnce(ReturnRef(expected_beamtime_id))
;
EXPECT_CALL(*mock_request, GetBeamline())
.WillOnce(ReturnRef(expected_beamline))
;
EXPECT_CALL(*mock_request, GetFullPath(expected_root_folder))
.WillOnce(Return(expected_full_path));
EXPECT_CALL(*mock_request, GetFileName())
.WillOnce(Return(expected_file_name))
......@@ -103,16 +108,13 @@ void FileReceiveHandlerTests::MockRequestData() {
TEST_F(FileReceiveHandlerTests, CallsReceiveFile) {
asapo::ReceiverConfig test_config;
test_config.root_folder = "test_folder";
test_config.root_folder = expected_root_folder;
asapo::SetReceiverConfig(test_config, "none");
MockRequestData();
std::string expected_path = std::string("test_folder") + asapo::kPathSeparator + expected_beamline
+ asapo::kPathSeparator + expected_beamtime_id;
EXPECT_CALL(mock_io, ReceiveDataToFile_t(expected_socket_id, expected_path, expected_file_name, expected_file_size,
EXPECT_CALL(mock_io, ReceiveDataToFile_t(expected_socket_id, expected_full_path, expected_file_name, expected_file_size,
true))
.WillOnce(
Return(asapo::IOErrorTemplates::kUnknownIOError.Generate().release())
......
......@@ -61,6 +61,13 @@ class FileWriteHandlerTests : public Test {
std::string expected_facility = "facility";
std::string expected_year = "2020";
uint64_t expected_file_size = 10;
std::string expected_root_folder = "root_folder";
std::string expected_full_path = expected_root_folder + asapo::kPathSeparator + expected_facility +
asapo::kPathSeparator + "gpfs" +
asapo::kPathSeparator + expected_beamline +
asapo::kPathSeparator + expected_year +
asapo::kPathSeparator + "data" +
asapo::kPathSeparator + expected_beamtime_id;
void MockRequestData();
void SetUp() override {
GenericRequestHeader request_header;
......@@ -96,17 +103,8 @@ void FileWriteHandlerTests::MockRequestData() {
EXPECT_CALL(*mock_request, GetData())
.WillOnce(Return(nullptr));
EXPECT_CALL(*mock_request, GetBeamtimeId())
.WillOnce(ReturnRef(expected_beamtime_id));
EXPECT_CALL(*mock_request, GetBeamline())
.WillOnce(ReturnRef(expected_beamline));
EXPECT_CALL(*mock_request, GetFacility())
.WillOnce(ReturnRef(expected_facility));
EXPECT_CALL(*mock_request, GetBeamtimeYear())
.WillOnce(ReturnRef(expected_year));
EXPECT_CALL(*mock_request, GetFullPath(expected_root_folder))
.WillOnce(Return(expected_full_path));
EXPECT_CALL(*mock_request, GetFileName())
.WillOnce(Return(expected_file_name));
......@@ -114,20 +112,13 @@ void FileWriteHandlerTests::MockRequestData() {
TEST_F(FileWriteHandlerTests, CallsWriteFile) {
asapo::ReceiverConfig test_config;
test_config.root_folder = "test_folder";
test_config.root_folder = expected_root_folder;
asapo::SetReceiverConfig(test_config, "none");
MockRequestData();
std::string expected_path = std::string("test_folder") + asapo::kPathSeparator + expected_facility +
asapo::kPathSeparator + "gpfs" +
asapo::kPathSeparator + expected_beamline +
asapo::kPathSeparator + expected_year +
asapo::kPathSeparator + "data" +
asapo::kPathSeparator + expected_beamtime_id;
EXPECT_CALL(mock_io, WriteDataToFile_t(expected_path, expected_file_name, _, expected_file_size, true))
EXPECT_CALL(mock_io, WriteDataToFile_t(expected_full_path, expected_file_name, _, expected_file_size, true))
.WillOnce(
Return(asapo::IOErrorTemplates::kUnknownIOError.Generate().release())
);
......
......@@ -14,8 +14,9 @@ receiver_folder=${receiver_root_folder}/${facility}/gpfs/${beamline}/${year}/dat
Cleanup() {
echo cleanup
# rm -rf ${receiver_root_folder}
rm -rf ${receiver_root_folder}
nomad stop receiver
nomad stop discovery
nomad stop authorizer
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment