2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/ReadBufferAIO.h>
|
|
|
|
#include <Core/Defines.h>
|
2019-07-31 22:37:41 +00:00
|
|
|
#include <filesystem>
|
2015-03-10 16:34:00 +00:00
|
|
|
#include <vector>
|
2015-03-06 15:34:42 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
2015-03-10 13:00:29 +00:00
|
|
|
#include <functional>
|
2015-03-06 15:34:42 +00:00
|
|
|
#include <cstdlib>
|
2020-02-17 14:27:09 +00:00
|
|
|
#include <unistd.h>
|
2018-03-23 16:05:14 +00:00
|
|
|
|
2015-03-06 15:34:42 +00:00
|
|
|
|
2015-03-10 13:00:29 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
void run();
|
2017-12-01 18:36:55 +00:00
|
|
|
void prepare(std::string & filename, std::string & buf);
|
2017-10-26 18:36:23 +00:00
|
|
|
void prepare2(std::string & filename, std::string & buf);
|
|
|
|
void prepare3(std::string & filename, std::string & buf);
|
|
|
|
void prepare4(std::string & filename, std::string & buf);
|
2015-04-15 10:07:48 +00:00
|
|
|
std::string createTmpFile();
|
2019-07-08 18:55:06 +00:00
|
|
|
[[noreturn]] void die(const std::string & msg);
|
2017-09-07 21:04:48 +00:00
|
|
|
void runTest(unsigned int num, const std::function<bool()> & func);
|
2015-03-10 15:09:17 +00:00
|
|
|
|
2015-03-10 16:34:00 +00:00
|
|
|
bool test1(const std::string & filename);
|
2015-03-10 13:00:29 +00:00
|
|
|
bool test2(const std::string & filename, const std::string & buf);
|
2015-03-10 15:09:17 +00:00
|
|
|
bool test3(const std::string & filename, const std::string & buf);
|
2015-03-11 14:47:52 +00:00
|
|
|
bool test4(const std::string & filename, const std::string & buf);
|
2015-03-17 12:44:49 +00:00
|
|
|
bool test5(const std::string & filename, const std::string & buf);
|
2015-03-10 15:09:17 +00:00
|
|
|
bool test6(const std::string & filename, const std::string & buf);
|
2015-03-11 14:47:52 +00:00
|
|
|
bool test7(const std::string & filename, const std::string & buf);
|
2015-03-17 11:30:23 +00:00
|
|
|
bool test8(const std::string & filename, const std::string & buf);
|
2015-03-11 14:47:52 +00:00
|
|
|
bool test9(const std::string & filename, const std::string & buf);
|
2015-03-12 14:09:22 +00:00
|
|
|
bool test10(const std::string & filename, const std::string & buf);
|
2015-03-12 15:38:22 +00:00
|
|
|
bool test11(const std::string & filename);
|
|
|
|
bool test12(const std::string & filename, const std::string & buf);
|
2015-03-17 11:30:23 +00:00
|
|
|
bool test13(const std::string & filename, const std::string & buf);
|
2015-03-17 12:44:49 +00:00
|
|
|
bool test14(const std::string & filename, const std::string & buf);
|
2015-04-03 11:51:41 +00:00
|
|
|
bool test15(const std::string & filename, const std::string & buf);
|
|
|
|
bool test16(const std::string & filename, const std::string & buf);
|
|
|
|
bool test17(const std::string & filename, const std::string & buf);
|
|
|
|
bool test18(const std::string & filename, const std::string & buf);
|
2015-04-03 22:44:32 +00:00
|
|
|
bool test19(const std::string & filename, const std::string & buf);
|
|
|
|
bool test20(const std::string & filename, const std::string & buf);
|
2015-03-10 13:00:29 +00:00
|
|
|
|
|
|
|
void run()
|
|
|
|
{
|
2019-07-31 22:37:41 +00:00
|
|
|
namespace fs = std::filesystem;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
std::string filename;
|
|
|
|
std::string buf;
|
2017-12-01 18:36:55 +00:00
|
|
|
prepare(filename, buf);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
std::string filename2;
|
|
|
|
std::string buf2;
|
2017-12-01 18:36:55 +00:00
|
|
|
prepare(filename2, buf2);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
std::string filename3;
|
|
|
|
std::string buf3;
|
|
|
|
prepare2(filename3, buf3);
|
|
|
|
|
|
|
|
std::string filename4;
|
|
|
|
std::string buf4;
|
|
|
|
prepare3(filename4, buf4);
|
|
|
|
|
|
|
|
std::string filename5;
|
|
|
|
std::string buf5;
|
|
|
|
prepare4(filename5, buf5);
|
|
|
|
|
2017-08-30 18:13:32 +00:00
|
|
|
const std::vector<std::function<bool()>> tests =
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2020-03-09 01:59:08 +00:00
|
|
|
[&]{ return test1(filename); },
|
|
|
|
[&]{ return test2(filename, buf); },
|
|
|
|
[&]{ return test3(filename, buf); },
|
|
|
|
[&]{ return test4(filename, buf); },
|
|
|
|
[&]{ return test5(filename, buf); },
|
|
|
|
[&]{ return test6(filename, buf); },
|
|
|
|
[&]{ return test7(filename, buf); },
|
|
|
|
[&]{ return test8(filename, buf); },
|
|
|
|
[&]{ return test9(filename, buf); },
|
|
|
|
[&]{ return test10(filename, buf); },
|
|
|
|
[&]{ return test11(filename); },
|
|
|
|
[&]{ return test12(filename, buf); },
|
|
|
|
[&]{ return test13(filename2, buf2); },
|
|
|
|
[&]{ return test14(filename, buf); },
|
|
|
|
[&]{ return test15(filename3, buf3); },
|
|
|
|
[&]{ return test16(filename3, buf3); },
|
|
|
|
[&]{ return test17(filename4, buf4); },
|
|
|
|
[&]{ return test18(filename5, buf5); },
|
|
|
|
[&]{ return test19(filename, buf); },
|
|
|
|
[&]{ return test20(filename, buf); }
|
2017-04-01 07:20:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
unsigned int num = 0;
|
|
|
|
for (const auto & test : tests)
|
|
|
|
{
|
|
|
|
++num;
|
|
|
|
runTest(num, test);
|
|
|
|
}
|
|
|
|
|
|
|
|
fs::remove_all(fs::path(filename).parent_path().string());
|
|
|
|
fs::remove_all(fs::path(filename2).parent_path().string());
|
|
|
|
fs::remove_all(fs::path(filename3).parent_path().string());
|
|
|
|
fs::remove_all(fs::path(filename4).parent_path().string());
|
|
|
|
fs::remove_all(fs::path(filename5).parent_path().string());
|
2015-03-10 13:00:29 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
void prepare(std::string & filename, std::string & buf)
|
2015-03-10 13:00:29 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static const std::string symbols = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
2015-03-10 13:00:29 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
filename = createTmpFile();
|
2015-03-10 13:00:29 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t n = 10 * DEFAULT_AIO_FILE_BLOCK_SIZE;
|
|
|
|
buf.reserve(n);
|
2015-03-10 13:00:29 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
for (size_t i = 0; i < n; ++i)
|
|
|
|
buf += symbols[i % symbols.length()];
|
2015-03-10 13:00:29 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::ofstream out(filename.c_str());
|
|
|
|
if (!out.is_open())
|
|
|
|
die("Could not open file");
|
2015-03-10 13:00:29 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
out << buf;
|
2015-03-10 13:00:29 +00:00
|
|
|
}
|
2015-03-06 15:34:42 +00:00
|
|
|
|
2015-04-15 10:07:48 +00:00
|
|
|
void prepare2(std::string & filename, std::string & buf)
|
2015-04-03 11:51:41 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
filename = createTmpFile();
|
2015-04-03 11:51:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
buf = "122333444455555666666777777788888888999999999";
|
2015-04-03 11:51:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::ofstream out(filename.c_str());
|
|
|
|
if (!out.is_open())
|
|
|
|
die("Could not open file");
|
2015-04-03 11:51:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
out << buf;
|
2015-04-03 11:51:41 +00:00
|
|
|
}
|
|
|
|
|
2015-04-15 10:07:48 +00:00
|
|
|
void prepare3(std::string & filename, std::string & buf)
|
2015-04-03 11:51:41 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
filename = createTmpFile();
|
2015-04-03 11:51:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
buf = "122333444455555666666777777788888888999999999";
|
2015-04-03 11:51:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::ofstream out(filename.c_str());
|
|
|
|
if (!out.is_open())
|
|
|
|
die("Could not open file");
|
2015-04-03 11:51:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
out.seekp(7, std::ios_base::beg);
|
|
|
|
out << buf;
|
2015-04-03 11:51:41 +00:00
|
|
|
}
|
|
|
|
|
2015-04-15 10:07:48 +00:00
|
|
|
void prepare4(std::string & filename, std::string & buf)
|
2015-04-03 11:51:41 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
static const std::string symbols = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
2015-04-03 11:51:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
filename = createTmpFile();
|
2015-04-03 11:51:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::ofstream out(filename.c_str());
|
|
|
|
if (!out.is_open())
|
|
|
|
die("Could not open file");
|
2015-04-03 11:51:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
for (size_t i = 0; i < 1340; ++i)
|
|
|
|
buf += symbols[i % symbols.length()];
|
2015-04-03 11:51:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
out.seekp(2984, std::ios_base::beg);
|
|
|
|
out << buf;
|
2015-04-03 11:51:41 +00:00
|
|
|
}
|
|
|
|
|
2015-04-15 10:07:48 +00:00
|
|
|
std::string createTmpFile()
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
char pattern[] = "/tmp/fileXXXXXX";
|
|
|
|
char * dir = ::mkdtemp(pattern);
|
|
|
|
if (dir == nullptr)
|
|
|
|
die("Could not create directory");
|
2015-04-15 10:07:48 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return std::string(dir) + "/foo";
|
2015-04-15 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
2015-03-06 15:34:42 +00:00
|
|
|
void die(const std::string & msg)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::cout << msg << "\n";
|
|
|
|
::exit(EXIT_FAILURE);
|
2015-03-06 15:34:42 +00:00
|
|
|
}
|
|
|
|
|
2017-09-07 21:04:48 +00:00
|
|
|
void runTest(unsigned int num, const std::function<bool()> & func)
|
2015-03-06 15:34:42 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
bool ok;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ok = func();
|
|
|
|
}
|
|
|
|
catch (const DB::Exception & ex)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cout << "Caught exception " << ex.displayText() << "\n";
|
|
|
|
}
|
|
|
|
catch (const std::exception & ex)
|
|
|
|
{
|
|
|
|
ok = false;
|
|
|
|
std::cout << "Caught exception " << ex.what() << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ok)
|
|
|
|
std::cout << "Test " << num << " passed\n";
|
|
|
|
else
|
|
|
|
std::cout << "Test " << num << " failed\n";
|
2015-03-10 11:43:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-10 16:34:00 +00:00
|
|
|
bool test1(const std::string & filename)
|
2015-03-10 15:09:17 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::ReadBufferAIO in(filename, 3 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
|
|
|
if (in.getFileName() != filename)
|
|
|
|
return false;
|
|
|
|
if (in.getFD() == -1)
|
|
|
|
return false;
|
|
|
|
return true;
|
2015-03-10 15:09:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test2(const std::string & filename, const std::string & buf)
|
2015-03-10 11:43:30 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(buf.length());
|
2015-03-10 11:43:30 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::ReadBufferAIO in(filename, 3 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
2018-09-02 03:00:04 +00:00
|
|
|
size_t count = in.read(newbuf.data(), newbuf.length());
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count != newbuf.length())
|
|
|
|
return false;
|
2015-03-10 13:00:29 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return (newbuf == buf);
|
2015-03-10 13:00:29 +00:00
|
|
|
}
|
|
|
|
|
2015-03-10 15:09:17 +00:00
|
|
|
bool test3(const std::string & filename, const std::string & buf)
|
2015-03-10 13:00:29 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(buf.length());
|
2015-03-10 13:16:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t requested = 9 * DEFAULT_AIO_FILE_BLOCK_SIZE;
|
2015-03-10 13:00:29 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::ReadBufferAIO in(filename, 3 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
|
|
|
in.setMaxBytes(requested);
|
2018-09-02 03:00:04 +00:00
|
|
|
size_t count = in.read(newbuf.data(), newbuf.length());
|
2015-03-10 11:43:30 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
newbuf.resize(count);
|
|
|
|
return (newbuf == buf.substr(0, requested));
|
2015-03-10 13:00:29 +00:00
|
|
|
}
|
2015-03-10 11:43:30 +00:00
|
|
|
|
2015-03-11 14:47:52 +00:00
|
|
|
bool test4(const std::string & filename, const std::string & buf)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(buf.length());
|
2015-03-11 14:47:52 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::ReadBufferAIO in(filename, 3 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
|
|
|
in.setMaxBytes(0);
|
2018-09-02 03:00:04 +00:00
|
|
|
size_t n_read = in.read(newbuf.data(), newbuf.length());
|
2015-03-11 14:47:52 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return n_read == 0;
|
2015-03-11 14:47:52 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 12:44:49 +00:00
|
|
|
bool test5(const std::string & filename, const std::string & buf)
|
2015-03-10 15:09:17 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(1 + (DEFAULT_AIO_FILE_BLOCK_SIZE >> 1));
|
2015-03-10 15:29:31 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::ReadBufferAIO in(filename, DEFAULT_AIO_FILE_BLOCK_SIZE);
|
|
|
|
in.setMaxBytes(1 + (DEFAULT_AIO_FILE_BLOCK_SIZE >> 1));
|
2015-03-17 12:44:49 +00:00
|
|
|
|
2018-09-02 03:00:04 +00:00
|
|
|
size_t count = in.read(newbuf.data(), newbuf.length());
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count != newbuf.length())
|
|
|
|
return false;
|
2015-03-17 12:44:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (newbuf != buf.substr(0, newbuf.length()))
|
|
|
|
return false;
|
2015-03-17 12:44:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2015-03-10 15:09:17 +00:00
|
|
|
}
|
|
|
|
|
2015-03-11 14:47:52 +00:00
|
|
|
bool test6(const std::string & filename, const std::string & buf)
|
2015-03-10 15:09:17 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(buf.length());
|
2015-03-10 15:09:17 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::ReadBufferAIO in(filename, 3 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
2015-03-10 15:09:17 +00:00
|
|
|
|
2020-02-17 10:49:36 +00:00
|
|
|
if (in.getPosition() != 0)
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2015-03-10 15:09:17 +00:00
|
|
|
|
2018-09-02 03:00:04 +00:00
|
|
|
size_t count = in.read(newbuf.data(), newbuf.length());
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count != newbuf.length())
|
|
|
|
return false;
|
2015-03-10 15:09:17 +00:00
|
|
|
|
2020-02-17 10:49:36 +00:00
|
|
|
if (static_cast<size_t>(in.getPosition()) != buf.length())
|
2017-04-01 07:20:54 +00:00
|
|
|
return false;
|
2015-03-10 15:09:17 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2015-03-10 15:09:17 +00:00
|
|
|
}
|
|
|
|
|
2015-03-11 14:47:52 +00:00
|
|
|
bool test7(const std::string & filename, const std::string & buf)
|
2015-03-10 15:09:17 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(buf.length() - DEFAULT_AIO_FILE_BLOCK_SIZE);
|
2015-03-10 15:09:17 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::ReadBufferAIO in(filename, 3 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
|
|
|
(void) in.seek(DEFAULT_AIO_FILE_BLOCK_SIZE, SEEK_SET);
|
2018-09-02 03:00:04 +00:00
|
|
|
size_t count = in.read(newbuf.data(), newbuf.length());
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count != (9 * DEFAULT_AIO_FILE_BLOCK_SIZE))
|
|
|
|
return false;
|
2015-03-10 15:09:17 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return (newbuf == buf.substr(DEFAULT_AIO_FILE_BLOCK_SIZE));
|
2015-03-10 15:09:17 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 11:30:23 +00:00
|
|
|
bool test8(const std::string & filename, const std::string & buf)
|
2015-03-10 15:29:31 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(DEFAULT_AIO_FILE_BLOCK_SIZE - 1);
|
2015-03-10 15:29:31 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::ReadBufferAIO in(filename, 3 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
|
|
|
(void) in.seek(DEFAULT_AIO_FILE_BLOCK_SIZE + 1, SEEK_CUR);
|
2018-09-02 03:00:04 +00:00
|
|
|
size_t count = in.read(newbuf.data(), newbuf.length());
|
2015-03-10 15:29:31 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count != newbuf.length())
|
|
|
|
return false;
|
2015-03-17 11:30:23 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (newbuf != buf.substr(DEFAULT_AIO_FILE_BLOCK_SIZE + 1, newbuf.length()))
|
|
|
|
return false;
|
2015-03-17 11:30:23 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2015-03-10 15:29:31 +00:00
|
|
|
}
|
|
|
|
|
2015-03-11 14:47:52 +00:00
|
|
|
bool test9(const std::string & filename, const std::string & buf)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
bool ok = false;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(buf.length());
|
|
|
|
|
|
|
|
DB::ReadBufferAIO in(filename, 3 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
2018-11-26 00:56:50 +00:00
|
|
|
size_t count = in.read(newbuf.data(), newbuf.length());
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count != newbuf.length())
|
|
|
|
return false;
|
|
|
|
in.setMaxBytes(9 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
|
|
|
}
|
|
|
|
catch (const DB::Exception &)
|
|
|
|
{
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
2015-03-11 14:47:52 +00:00
|
|
|
}
|
|
|
|
|
2015-03-12 14:09:22 +00:00
|
|
|
bool test10(const std::string & filename, const std::string & buf)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::ReadBufferAIO in(filename, 3 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
2015-03-12 14:09:22 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(4 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2018-09-02 03:00:04 +00:00
|
|
|
size_t count1 = in.read(newbuf.data(), newbuf.length());
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count1 != newbuf.length())
|
|
|
|
return false;
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (newbuf != buf.substr(0, 4 * DEFAULT_AIO_FILE_BLOCK_SIZE))
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-12 14:09:22 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
(void) in.seek(2 * DEFAULT_AIO_FILE_BLOCK_SIZE, SEEK_CUR);
|
2015-03-12 14:09:22 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(4 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
2015-03-12 14:09:22 +00:00
|
|
|
|
2018-09-02 03:00:04 +00:00
|
|
|
size_t count2 = in.read(newbuf.data(), newbuf.length());
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count2 != newbuf.length())
|
|
|
|
return false;
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (newbuf != buf.substr(6 * DEFAULT_AIO_FILE_BLOCK_SIZE))
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-12 14:09:22 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2015-03-12 14:09:22 +00:00
|
|
|
}
|
|
|
|
|
2015-03-12 15:38:22 +00:00
|
|
|
bool test11(const std::string & filename)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
bool ok = false;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
DB::ReadBufferAIO in(filename, 3 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
|
|
|
(void) in.seek(-DEFAULT_AIO_FILE_BLOCK_SIZE, SEEK_SET);
|
|
|
|
}
|
|
|
|
catch (const DB::Exception &)
|
|
|
|
{
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
2015-03-12 15:38:22 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
bool test12(const std::string & filename, const std::string &)
|
2015-03-12 15:38:22 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
bool ok = false;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(4 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
|
|
|
|
|
|
|
DB::ReadBufferAIO in(filename, 3 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
2018-11-26 00:56:50 +00:00
|
|
|
size_t count = in.read(newbuf.data(), newbuf.length());
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count != newbuf.length())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
(void) in.seek(-(10 * DEFAULT_AIO_FILE_BLOCK_SIZE), SEEK_CUR);
|
|
|
|
}
|
|
|
|
catch (const DB::Exception &)
|
|
|
|
{
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
2015-03-12 15:38:22 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
bool test13(const std::string & filename, const std::string &)
|
2015-03-17 11:30:23 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(2 * DEFAULT_AIO_FILE_BLOCK_SIZE - 3);
|
|
|
|
|
|
|
|
DB::ReadBufferAIO in(filename, DEFAULT_AIO_FILE_BLOCK_SIZE);
|
2018-09-02 03:00:04 +00:00
|
|
|
size_t count1 = in.read(newbuf.data(), newbuf.length());
|
2020-03-09 02:10:20 +00:00
|
|
|
return count1 == newbuf.length();
|
2015-03-17 11:30:23 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 12:44:49 +00:00
|
|
|
bool test14(const std::string & filename, const std::string & buf)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(1 + (DEFAULT_AIO_FILE_BLOCK_SIZE >> 1));
|
2015-03-17 12:44:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::ReadBufferAIO in(filename, DEFAULT_AIO_FILE_BLOCK_SIZE);
|
|
|
|
(void) in.seek(2, SEEK_SET);
|
|
|
|
in.setMaxBytes(3 + (DEFAULT_AIO_FILE_BLOCK_SIZE >> 1));
|
2015-03-17 12:44:49 +00:00
|
|
|
|
2018-09-02 03:00:04 +00:00
|
|
|
size_t count = in.read(newbuf.data(), newbuf.length());
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count != newbuf.length())
|
|
|
|
return false;
|
2015-03-17 12:44:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (newbuf != buf.substr(2, newbuf.length()))
|
|
|
|
return false;
|
2015-03-17 12:44:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2015-03-17 12:44:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
bool test15(const std::string & filename, const std::string &)
|
2015-04-03 11:51:41 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(1000);
|
2015-04-03 11:51:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::ReadBufferAIO in(filename, DEFAULT_AIO_FILE_BLOCK_SIZE);
|
2015-04-03 11:51:41 +00:00
|
|
|
|
2018-09-02 03:00:04 +00:00
|
|
|
size_t count = in.read(newbuf.data(), 1);
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count != 1)
|
|
|
|
return false;
|
|
|
|
if (newbuf[0] != '1')
|
|
|
|
return false;
|
|
|
|
return true;
|
2015-04-03 11:51:41 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
bool test16(const std::string & filename, const std::string &)
|
2015-04-03 11:51:41 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::ReadBufferAIO in(filename, DEFAULT_AIO_FILE_BLOCK_SIZE);
|
|
|
|
size_t count;
|
|
|
|
|
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(1);
|
2018-09-02 03:00:04 +00:00
|
|
|
count = in.read(newbuf.data(), 1);
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count != 1)
|
|
|
|
return false;
|
|
|
|
if (newbuf[0] != '1')
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
in.seek(2, SEEK_CUR);
|
|
|
|
|
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(3);
|
2018-09-02 03:00:04 +00:00
|
|
|
count = in.read(newbuf.data(), 3);
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count != 3)
|
|
|
|
return false;
|
|
|
|
if (newbuf != "333")
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
in.seek(4, SEEK_CUR);
|
|
|
|
|
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(5);
|
2018-09-02 03:00:04 +00:00
|
|
|
count = in.read(newbuf.data(), 5);
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count != 5)
|
|
|
|
return false;
|
|
|
|
if (newbuf != "55555")
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
in.seek(6, SEEK_CUR);
|
|
|
|
|
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(7);
|
2018-09-02 03:00:04 +00:00
|
|
|
count = in.read(newbuf.data(), 7);
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count != 7)
|
|
|
|
return false;
|
|
|
|
if (newbuf != "7777777")
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
in.seek(8, SEEK_CUR);
|
|
|
|
|
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(9);
|
2018-09-02 03:00:04 +00:00
|
|
|
count = in.read(newbuf.data(), 9);
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count != 9)
|
|
|
|
return false;
|
|
|
|
if (newbuf != "999999999")
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2015-04-03 11:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test17(const std::string & filename, const std::string & buf)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::ReadBufferAIO in(filename, DEFAULT_AIO_FILE_BLOCK_SIZE);
|
|
|
|
size_t count;
|
|
|
|
|
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(10);
|
2018-09-02 03:00:04 +00:00
|
|
|
count = in.read(newbuf.data(), 10);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
if (count != 10)
|
|
|
|
return false;
|
|
|
|
if (newbuf.substr(0, 7) != std::string(7, '\0'))
|
|
|
|
return false;
|
|
|
|
if (newbuf.substr(7) != "122")
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
in.seek(7 + buf.length() - 2, SEEK_SET);
|
|
|
|
|
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(160);
|
2018-09-02 03:00:04 +00:00
|
|
|
count = in.read(newbuf.data(), 160);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
if (count != 2)
|
|
|
|
return false;
|
|
|
|
if (newbuf.substr(0, 2) != "99")
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
in.seek(7 + buf.length() + DEFAULT_AIO_FILE_BLOCK_SIZE, SEEK_SET);
|
|
|
|
|
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(50);
|
2018-09-02 03:00:04 +00:00
|
|
|
count = in.read(newbuf.data(), 50);
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count != 0)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2015-04-03 11:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test18(const std::string & filename, const std::string & buf)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::ReadBufferAIO in(filename, DEFAULT_AIO_FILE_BLOCK_SIZE);
|
2015-04-03 11:51:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(1340);
|
2015-04-03 11:51:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
in.seek(2984, SEEK_SET);
|
2018-09-02 03:00:04 +00:00
|
|
|
size_t count = in.read(newbuf.data(), 1340);
|
2015-04-03 11:51:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count != 1340)
|
|
|
|
return false;
|
|
|
|
if (newbuf != buf)
|
|
|
|
return false;
|
2015-04-03 11:51:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2015-04-03 11:51:41 +00:00
|
|
|
}
|
|
|
|
|
2015-04-03 22:44:32 +00:00
|
|
|
bool test19(const std::string & filename, const std::string & buf)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::ReadBufferAIO in(filename, 3 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(5 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2018-09-02 03:00:04 +00:00
|
|
|
size_t count1 = in.read(newbuf.data(), newbuf.length());
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count1 != newbuf.length())
|
|
|
|
return false;
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (newbuf != buf.substr(0, 5 * DEFAULT_AIO_FILE_BLOCK_SIZE))
|
|
|
|
return false;
|
|
|
|
}
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(5 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2018-09-02 03:00:04 +00:00
|
|
|
size_t count2 = in.read(newbuf.data(), newbuf.length());
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count2 != newbuf.length())
|
|
|
|
return false;
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (newbuf != buf.substr(5 * DEFAULT_AIO_FILE_BLOCK_SIZE))
|
|
|
|
return false;
|
|
|
|
}
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2015-04-03 22:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test20(const std::string & filename, const std::string & buf)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::ReadBufferAIO in(filename, 3 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(5 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2018-09-02 03:00:04 +00:00
|
|
|
size_t count1 = in.read(newbuf.data(), newbuf.length());
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count1 != newbuf.length())
|
|
|
|
return false;
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (newbuf != buf.substr(0, 5 * DEFAULT_AIO_FILE_BLOCK_SIZE))
|
|
|
|
return false;
|
|
|
|
}
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2020-02-17 10:49:36 +00:00
|
|
|
(void) in.getPosition();
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(5 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2018-09-02 03:00:04 +00:00
|
|
|
size_t count2 = in.read(newbuf.data(), newbuf.length());
|
2017-04-01 07:20:54 +00:00
|
|
|
if (count2 != newbuf.length())
|
|
|
|
return false;
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (newbuf != buf.substr(5 * DEFAULT_AIO_FILE_BLOCK_SIZE))
|
|
|
|
return false;
|
|
|
|
}
|
2015-04-03 22:44:32 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return true;
|
2015-04-03 22:44:32 +00:00
|
|
|
}
|
|
|
|
|
2015-03-10 11:43:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
run();
|
|
|
|
return 0;
|
2015-03-06 15:34:42 +00:00
|
|
|
}
|