2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/ReadBufferAIO.h>
|
|
|
|
#include <Core/Defines.h>
|
2015-03-13 11:02:43 +00:00
|
|
|
|
2015-03-11 13:51:59 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2015-03-06 15:34:42 +00:00
|
|
|
|
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>
|
2015-03-10 13:16:49 +00:00
|
|
|
#include <unistd.h>
|
2015-03-06 15:34:42 +00:00
|
|
|
|
2015-03-10 13:00:29 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
void run();
|
2015-04-15 10:07:48 +00:00
|
|
|
void prepare(size_t s, std::string & filename, std::string & buf);
|
|
|
|
void prepare2(std::string & filename, std::string & buf);
|
|
|
|
void prepare3(std::string & filename, std::string & buf);
|
|
|
|
void prepare4(std::string & filename, std::string & buf);
|
|
|
|
std::string createTmpFile();
|
2015-03-10 13:00:29 +00:00
|
|
|
void die(const std::string & msg);
|
2015-04-15 10:07: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()
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
|
|
|
|
std::string filename;
|
|
|
|
std::string buf;
|
|
|
|
prepare(10 * DEFAULT_AIO_FILE_BLOCK_SIZE, filename, buf);
|
|
|
|
|
|
|
|
std::string filename2;
|
|
|
|
std::string buf2;
|
|
|
|
prepare(2 * DEFAULT_AIO_FILE_BLOCK_SIZE - 3, filename2, buf2);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
const std::vector<std::function<bool()> > tests =
|
|
|
|
{
|
|
|
|
std::bind(test1, std::ref(filename)),
|
|
|
|
std::bind(test2, std::ref(filename), std::ref(buf)),
|
|
|
|
std::bind(test3, std::ref(filename), std::ref(buf)),
|
|
|
|
std::bind(test4, std::ref(filename), std::ref(buf)),
|
|
|
|
std::bind(test5, std::ref(filename), std::ref(buf)),
|
|
|
|
std::bind(test6, std::ref(filename), std::ref(buf)),
|
|
|
|
std::bind(test7, std::ref(filename), std::ref(buf)),
|
|
|
|
std::bind(test8, std::ref(filename), std::ref(buf)),
|
|
|
|
std::bind(test9, std::ref(filename), std::ref(buf)),
|
|
|
|
std::bind(test10, std::ref(filename), std::ref(buf)),
|
|
|
|
std::bind(test11, std::ref(filename)),
|
|
|
|
std::bind(test12, std::ref(filename), std::ref(buf)),
|
|
|
|
std::bind(test13, std::ref(filename2), std::ref(buf2)),
|
|
|
|
std::bind(test14, std::ref(filename), std::ref(buf)),
|
|
|
|
std::bind(test15, std::ref(filename3), std::ref(buf3)),
|
|
|
|
std::bind(test16, std::ref(filename3), std::ref(buf3)),
|
|
|
|
std::bind(test17, std::ref(filename4), std::ref(buf4)),
|
|
|
|
std::bind(test18, std::ref(filename5), std::ref(buf5)),
|
|
|
|
std::bind(test19, std::ref(filename), std::ref(buf)),
|
|
|
|
std::bind(test20, std::ref(filename), std::ref(buf))
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-04-15 10:07:48 +00:00
|
|
|
void prepare(size_t s, 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
|
|
|
}
|
|
|
|
|
2015-04-15 10:07: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);
|
|
|
|
size_t count = in.read(&newbuf[0], newbuf.length());
|
|
|
|
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);
|
|
|
|
size_t count = in.read(&newbuf[0], 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);
|
|
|
|
size_t n_read = in.read(&newbuf[0], 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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t count = in.read(&newbuf[0], newbuf.length());
|
|
|
|
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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (in.getPositionInFile() != 0)
|
|
|
|
return false;
|
2015-03-10 15:09:17 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t count = in.read(&newbuf[0], newbuf.length());
|
|
|
|
if (count != newbuf.length())
|
|
|
|
return false;
|
2015-03-10 15:09:17 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (static_cast<size_t>(in.getPositionInFile()) != buf.length())
|
|
|
|
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);
|
|
|
|
size_t count = in.read(&newbuf[0], newbuf.length());
|
|
|
|
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);
|
|
|
|
size_t count = in.read(&newbuf[0], 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);
|
|
|
|
size_t count = in.read(&newbuf[0], newbuf.length());
|
|
|
|
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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t count1 = in.read(&newbuf[0], newbuf.length());
|
|
|
|
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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t count2 = in.read(&newbuf[0], newbuf.length());
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool test12(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(4 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
|
|
|
|
|
|
|
DB::ReadBufferAIO in(filename, 3 * DEFAULT_AIO_FILE_BLOCK_SIZE);
|
|
|
|
size_t count = in.read(&newbuf[0], newbuf.length());
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-03-17 11:30:23 +00:00
|
|
|
bool test13(const std::string & filename, const std::string & buf)
|
|
|
|
{
|
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);
|
|
|
|
size_t count1 = in.read(&newbuf[0], newbuf.length());
|
|
|
|
if (count1 != newbuf.length())
|
|
|
|
return false;
|
|
|
|
return true;
|
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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t count = in.read(&newbuf[0], newbuf.length());
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-04-03 11:51:41 +00:00
|
|
|
bool test15(const std::string & filename, const std::string & buf)
|
|
|
|
{
|
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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t count = in.read(&newbuf[0], 1);
|
|
|
|
if (count != 1)
|
|
|
|
return false;
|
|
|
|
if (newbuf[0] != '1')
|
|
|
|
return false;
|
|
|
|
return true;
|
2015-04-03 11:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool test16(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(1);
|
|
|
|
count = in.read(&newbuf[0], 1);
|
|
|
|
if (count != 1)
|
|
|
|
return false;
|
|
|
|
if (newbuf[0] != '1')
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
in.seek(2, SEEK_CUR);
|
|
|
|
|
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(3);
|
|
|
|
count = in.read(&newbuf[0], 3);
|
|
|
|
if (count != 3)
|
|
|
|
return false;
|
|
|
|
if (newbuf != "333")
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
in.seek(4, SEEK_CUR);
|
|
|
|
|
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(5);
|
|
|
|
count = in.read(&newbuf[0], 5);
|
|
|
|
if (count != 5)
|
|
|
|
return false;
|
|
|
|
if (newbuf != "55555")
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
in.seek(6, SEEK_CUR);
|
|
|
|
|
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(7);
|
|
|
|
count = in.read(&newbuf[0], 7);
|
|
|
|
if (count != 7)
|
|
|
|
return false;
|
|
|
|
if (newbuf != "7777777")
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
in.seek(8, SEEK_CUR);
|
|
|
|
|
|
|
|
{
|
|
|
|
std::string newbuf;
|
|
|
|
newbuf.resize(9);
|
|
|
|
count = in.read(&newbuf[0], 9);
|
|
|
|
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);
|
|
|
|
count = in.read(&newbuf[0], 10);
|
|
|
|
|
|
|
|
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);
|
|
|
|
count = in.read(&newbuf[0], 160);
|
|
|
|
|
|
|
|
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);
|
|
|
|
count = in.read(&newbuf[0], 50);
|
|
|
|
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);
|
|
|
|
size_t count = in.read(&newbuf[0], 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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t count1 = in.read(&newbuf[0], newbuf.length());
|
|
|
|
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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t count2 = in.read(&newbuf[0], newbuf.length());
|
|
|
|
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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t count1 = in.read(&newbuf[0], newbuf.length());
|
|
|
|
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
|
|
|
(void) in.getPositionInFile();
|
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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t count2 = in.read(&newbuf[0], newbuf.length());
|
|
|
|
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
|
|
|
}
|
2015-04-03 11:51:41 +00:00
|
|
|
|