提交 6820638c 编写于 作者: A Alexey Milovidov

dbms: IO: added test [#METR-2944].

上级 b9d6fc48
......@@ -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);
......
#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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册