aboutsummaryrefslogtreecommitdiffstats
path: root/util/stream/direct_io_ut.cpp
diff options
context:
space:
mode:
authoryazevnul <yazevnul@yandex-team.ru>2022-02-10 16:46:46 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:46 +0300
commit8cbc307de0221f84c80c42dcbe07d40727537e2c (patch)
tree625d5a673015d1df891e051033e9fcde5c7be4e5 /util/stream/direct_io_ut.cpp
parent30d1ef3941e0dc835be7609de5ebee66958f215a (diff)
downloadydb-8cbc307de0221f84c80c42dcbe07d40727537e2c.tar.gz
Restoring authorship annotation for <yazevnul@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/stream/direct_io_ut.cpp')
-rw-r--r--util/stream/direct_io_ut.cpp108
1 files changed, 54 insertions, 54 deletions
diff --git a/util/stream/direct_io_ut.cpp b/util/stream/direct_io_ut.cpp
index 01d09db232..04784f5b0d 100644
--- a/util/stream/direct_io_ut.cpp
+++ b/util/stream/direct_io_ut.cpp
@@ -1,71 +1,71 @@
#include <library/cpp/testing/unittest/registar.h>
#include <util/generic/string.h>
-#include <util/generic/array_size.h>
-#include <util/system/env.h>
+#include <util/generic/array_size.h>
+#include <util/system/env.h>
-#include "buffered.h"
-#include "direct_io.h"
+#include "buffered.h"
+#include "direct_io.h"
-Y_UNIT_TEST_SUITE(TDirectIOTests) {
+Y_UNIT_TEST_SUITE(TDirectIOTests) {
// Decrease numBufToWrite further if tests continue to time out
static void Y_NO_INLINE Test(EOpenMode mode, size_t numBufToWrite) {
- const char TEMPLATE[] = "qwertyuiopQWERTYUIOPasdfghjklASD";
- const auto TEMPLATE_SIZE = Y_ARRAY_SIZE(TEMPLATE) - 1;
- static_assert(TEMPLATE_SIZE > 0, "must be greater than zero");
-
- const size_t BUFFER_SIZE = 32 * 1024;
- static_assert(0 == BUFFER_SIZE % TEMPLATE_SIZE, "must be divisible");
-
- const size_t CHUNK_SIZE_TO_READ = 512;
- static_assert(0 == CHUNK_SIZE_TO_READ % TEMPLATE_SIZE, "must be divisible");
-
- // filling buffer
- // TEMPLATE|TEMPLATE|TEMPLATE|...
- auto&& buffer = TBuffer{BUFFER_SIZE};
- for (size_t i = 0; i < BUFFER_SIZE / TEMPLATE_SIZE; ++i) {
- buffer.Append(TEMPLATE, TEMPLATE_SIZE);
- }
-
- // filling file
- // TEMPLATE|TEMPLATE|TEMPLATE|...
+ const char TEMPLATE[] = "qwertyuiopQWERTYUIOPasdfghjklASD";
+ const auto TEMPLATE_SIZE = Y_ARRAY_SIZE(TEMPLATE) - 1;
+ static_assert(TEMPLATE_SIZE > 0, "must be greater than zero");
+
+ const size_t BUFFER_SIZE = 32 * 1024;
+ static_assert(0 == BUFFER_SIZE % TEMPLATE_SIZE, "must be divisible");
+
+ const size_t CHUNK_SIZE_TO_READ = 512;
+ static_assert(0 == CHUNK_SIZE_TO_READ % TEMPLATE_SIZE, "must be divisible");
+
+ // filling buffer
+ // TEMPLATE|TEMPLATE|TEMPLATE|...
+ auto&& buffer = TBuffer{BUFFER_SIZE};
+ for (size_t i = 0; i < BUFFER_SIZE / TEMPLATE_SIZE; ++i) {
+ buffer.Append(TEMPLATE, TEMPLATE_SIZE);
+ }
+
+ // filling file
+ // TEMPLATE|TEMPLATE|TEMPLATE|...
const auto fileName = TString("test.file");
- auto&& directIOBuffer = TDirectIOBufferedFile{fileName, RdWr | CreateAlways | mode};
- {
- auto&& output = TRandomAccessFileOutput{directIOBuffer};
+ auto&& directIOBuffer = TDirectIOBufferedFile{fileName, RdWr | CreateAlways | mode};
+ {
+ auto&& output = TRandomAccessFileOutput{directIOBuffer};
for (size_t i = 0; i < numBufToWrite; ++i) {
- output.Write(buffer.Data(), BUFFER_SIZE);
- }
- }
-
- auto&& reader = TRandomAccessFileInput{directIOBuffer, 0};
- auto&& input = TBufferedInput{&reader, 1 << 17};
- auto bytesRead = size_t{};
- while (auto len = input.Read(buffer.Data(), CHUNK_SIZE_TO_READ)) {
- bytesRead += len;
- while (len) {
- if (len < TEMPLATE_SIZE) {
- UNIT_ASSERT(!memcmp(buffer.Data(), TEMPLATE, len));
- len = 0;
- } else {
- UNIT_ASSERT(!memcmp(buffer.Data(), TEMPLATE, TEMPLATE_SIZE));
- len -= TEMPLATE_SIZE;
- }
- }
- }
-
+ output.Write(buffer.Data(), BUFFER_SIZE);
+ }
+ }
+
+ auto&& reader = TRandomAccessFileInput{directIOBuffer, 0};
+ auto&& input = TBufferedInput{&reader, 1 << 17};
+ auto bytesRead = size_t{};
+ while (auto len = input.Read(buffer.Data(), CHUNK_SIZE_TO_READ)) {
+ bytesRead += len;
+ while (len) {
+ if (len < TEMPLATE_SIZE) {
+ UNIT_ASSERT(!memcmp(buffer.Data(), TEMPLATE, len));
+ len = 0;
+ } else {
+ UNIT_ASSERT(!memcmp(buffer.Data(), TEMPLATE, TEMPLATE_SIZE));
+ len -= TEMPLATE_SIZE;
+ }
+ }
+ }
+
UNIT_ASSERT_VALUES_EQUAL(bytesRead, numBufToWrite * BUFFER_SIZE);
}
- Y_UNIT_TEST(ReadWriteTest) {
+ Y_UNIT_TEST(ReadWriteTest) {
Test(0, 100 * 32);
- }
-
- Y_UNIT_TEST(ReadWriteDirectTest) {
+ }
+
+ Y_UNIT_TEST(ReadWriteDirectTest) {
Test(Direct, 100 * 4);
- }
-
- Y_UNIT_TEST(ReadWriteDirectSeqTest) {
+ }
+
+ Y_UNIT_TEST(ReadWriteDirectSeqTest) {
Test(Direct | Seq, 100 * 4);
}
}