-
Notifications
You must be signed in to change notification settings - Fork 908
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C] Handle failed log buffer delete in C Media Driver (#1073)
* [C] Add free function to the managed resources. * [C] Add aeron_map_raw_log_free function. * [C] Implement retry when freeing log buffers. * [C] Add tests that verify re-try on freeing the log buffers. * [C] Continue rename of the log functions. * [C] Pad millis with leading zeroes when less than three digits. * [Java] Reduce timer interval to 15ms to force tests to fail. * [Java] Ensure that driver output is always printed in the order they were created. * [C] Do not perform action when in wrong state, i.e. prevent accessing freed buffers when close operation is in progress.
- Loading branch information
1 parent
d23c19f
commit 2042835
Showing
21 changed files
with
471 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright 2014-2020 Real Logic Limited. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <exception> | ||
#include <functional> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
extern "C" | ||
{ | ||
#include "util/aeron_fileutil.h" | ||
#include "util/aeron_error.h" | ||
} | ||
|
||
class FileUtilTest : public testing::Test { | ||
public: | ||
FileUtilTest() { | ||
} | ||
}; | ||
|
||
TEST_F(FileUtilTest, rawLogCloseShouldUnmapAndDeleteLogFile) { | ||
aeron_mapped_raw_log_t mapped_raw_log = {}; | ||
const char *file = "test_close_unused_file.log"; | ||
const size_t file_length = 16384; | ||
ASSERT_EQ(0, aeron_raw_log_map(&mapped_raw_log, file, true, 4096, 4096)); | ||
|
||
EXPECT_NE(nullptr, mapped_raw_log.mapped_file.addr); | ||
EXPECT_EQ(file_length, mapped_raw_log.mapped_file.length); | ||
EXPECT_EQ((int64_t)file_length, aeron_file_length(file)); | ||
|
||
ASSERT_EQ(0, aeron_raw_log_close(&mapped_raw_log, file)); | ||
|
||
EXPECT_EQ(nullptr, mapped_raw_log.mapped_file.addr); | ||
EXPECT_EQ(file_length, mapped_raw_log.mapped_file.length); | ||
EXPECT_EQ(-1, aeron_file_length(file)); | ||
} | ||
|
||
TEST_F(FileUtilTest, rawLogFreeShouldUnmapAndDeleteLogFile) { | ||
aeron_mapped_raw_log_t mapped_raw_log = {}; | ||
const char *file = "test_free_unused_file.log"; | ||
const size_t file_length = 16384; | ||
ASSERT_EQ(0, aeron_raw_log_map(&mapped_raw_log, file, true, 4096, 4096)); | ||
|
||
EXPECT_NE(nullptr, mapped_raw_log.mapped_file.addr); | ||
EXPECT_EQ(file_length, mapped_raw_log.mapped_file.length); | ||
EXPECT_EQ((int64_t)file_length, aeron_file_length(file)); | ||
|
||
ASSERT_EQ(true, aeron_raw_log_free(&mapped_raw_log, file)); | ||
|
||
EXPECT_EQ(nullptr, mapped_raw_log.mapped_file.addr); | ||
EXPECT_EQ(file_length, mapped_raw_log.mapped_file.length); | ||
EXPECT_EQ(-1, aeron_file_length(file)); | ||
} | ||
|
||
TEST_F(FileUtilTest, rawLogCloseShouldNotDeleteFileIfUnmapFails) { | ||
aeron_mapped_raw_log_t mapped_raw_log = {}; | ||
const char *file = "test_close_unmap_fails.log"; | ||
const size_t file_length = 16384; | ||
ASSERT_EQ(0, aeron_raw_log_map(&mapped_raw_log, file, true, 4096, 4096)); | ||
const auto mapped_addr = mapped_raw_log.mapped_file.addr; | ||
mapped_raw_log.mapped_file.addr = reinterpret_cast<void *>(-1); | ||
|
||
ASSERT_EQ(-1, aeron_raw_log_close(&mapped_raw_log, file)); | ||
EXPECT_EQ((int64_t)file_length, aeron_file_length(file)); | ||
|
||
mapped_raw_log.mapped_file.addr = mapped_addr; | ||
ASSERT_EQ(0, aeron_raw_log_close(&mapped_raw_log, file)); | ||
EXPECT_EQ(-1, aeron_file_length(file)); | ||
} | ||
|
||
TEST_F(FileUtilTest, rawLogFreeShouldNotDeleteFileIfUnmapFails) { | ||
aeron_mapped_raw_log_t mapped_raw_log = {}; | ||
const char *file = "test_free_unmap_fails.log"; | ||
const size_t file_length = 16384; | ||
ASSERT_EQ(0, aeron_raw_log_map(&mapped_raw_log, file, true, 4096, 4096)); | ||
const auto mapped_addr = mapped_raw_log.mapped_file.addr; | ||
mapped_raw_log.mapped_file.addr = reinterpret_cast<void *>(-1); | ||
|
||
ASSERT_EQ(false, aeron_raw_log_free(&mapped_raw_log, file)); | ||
EXPECT_EQ((int64_t)file_length, aeron_file_length(file)); | ||
|
||
mapped_raw_log.mapped_file.addr = mapped_addr; | ||
ASSERT_EQ(true, aeron_raw_log_free(&mapped_raw_log, file)); | ||
EXPECT_EQ(-1, aeron_file_length(file)); | ||
} | ||
|
||
TEST_F(FileUtilTest, rawLogCloseShouldReturnErrorIfFileDeleteFailsAndSetError) { | ||
aeron_mapped_raw_log_t mapped_raw_log = {}; | ||
const char *file = "test_close_delete_unknown_file.log"; | ||
aeron_set_err(0, ""); | ||
ASSERT_EQ(-1, aeron_file_length(file)); | ||
ASSERT_EQ(0, aeron_errcode()); | ||
|
||
ASSERT_EQ(-1, aeron_raw_log_close(&mapped_raw_log, file)); | ||
EXPECT_NE(0, aeron_errcode()); | ||
EXPECT_NE(std::string(""), std::string(aeron_errmsg())); | ||
} | ||
|
||
TEST_F(FileUtilTest, rawLogFreeShouldReturnErrorIfFileDeleteFails) { | ||
aeron_mapped_raw_log_t mapped_raw_log = {}; | ||
const char *file = "test_free_delete_unknown_file.log"; | ||
aeron_set_err(0, ""); | ||
ASSERT_EQ(-1, aeron_file_length(file)); | ||
ASSERT_EQ(0, aeron_errcode()); | ||
|
||
ASSERT_EQ(false, aeron_raw_log_free(&mapped_raw_log, file)); | ||
EXPECT_EQ(0, aeron_errcode()); | ||
EXPECT_EQ(std::string(""), std::string(aeron_errmsg())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.