mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
dbms: IO: added test [#METR-2944].
This commit is contained in:
parent
b9d6fc48eb
commit
6820638c30
@ -16,13 +16,13 @@ private:
|
||||
std::string file_name;
|
||||
|
||||
public:
|
||||
ReadBufferFromFile(const std::string & file_name_, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE,
|
||||
ReadBufferFromFile(const std::string & file_name_, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE, int flags = -1,
|
||||
char * existing_memory = NULL, size_t alignment = 0)
|
||||
: ReadBufferFromFileDescriptor(-1, buf_size, existing_memory, alignment), file_name(file_name_)
|
||||
{
|
||||
ProfileEvents::increment(ProfileEvents::FileOpen);
|
||||
|
||||
fd = open(file_name.c_str(), O_RDONLY);
|
||||
fd = open(file_name.c_str(), flags == -1 ? O_RDONLY : flags);
|
||||
|
||||
if (-1 == fd)
|
||||
throwFromErrno("Cannot open file " + file_name, errno == ENOENT ? ErrorCodes::FILE_DOESNT_EXIST : ErrorCodes::CANNOT_OPEN_FILE);
|
||||
|
45
dbms/src/IO/tests/o_direct_and_dirty_pages.cpp
Normal file
45
dbms/src/IO/tests/o_direct_and_dirty_pages.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include <string>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <DB/Core/Types.h>
|
||||
#include <DB/IO/WriteHelpers.h>
|
||||
#include <DB/IO/ReadHelpers.h>
|
||||
#include <DB/IO/WriteBufferFromFile.h>
|
||||
#include <DB/IO/ReadBufferFromFile.h>
|
||||
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
using namespace DB;
|
||||
|
||||
try
|
||||
{
|
||||
ReadBufferFromFile rand_in("/dev/urandom");
|
||||
unsigned rand = 0;
|
||||
readBinary(rand, rand_in);
|
||||
|
||||
String test = "Hello, world! " + toString(rand);
|
||||
|
||||
{
|
||||
WriteBufferFromFile wb("test", 4096);
|
||||
writeStringBinary(test, wb);
|
||||
wb.next();
|
||||
}
|
||||
|
||||
{
|
||||
ReadBufferFromFile rb("test", 4096, O_RDONLY | O_DIRECT, nullptr, 4096);
|
||||
String res;
|
||||
readStringBinary(res, rb);
|
||||
|
||||
std::cerr << "test: " << test << ", res: " << res << std::endl;
|
||||
}
|
||||
}
|
||||
catch (const Exception & e)
|
||||
{
|
||||
std::cerr << e.what() << ", " << e.displayText() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -112,7 +112,7 @@ void loadMetadata(Context & context)
|
||||
{
|
||||
static const size_t in_buf_size = 32768;
|
||||
char in_buf[in_buf_size];
|
||||
ReadBufferFromFile in(tables[j], 32768, in_buf);
|
||||
ReadBufferFromFile in(tables[j], 32768, -1, in_buf);
|
||||
WriteBufferFromString out(s);
|
||||
copyData(in, out);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user