Files
doris/be/test/olap/file_helper_test.cpp
Zhengguo Yang 24d38614a0 [Dependency] Upgrade thirdparty libs (#6766)
Upgrade the following dependecies:

libevent -> 2.1.12
OpenSSL 1.0.2k -> 1.1.1l
thrift 0.9.3 -> 0.13.0
protobuf 3.5.1 -> 3.14.0
gflags 2.2.0 -> 2.2.2
glog 0.3.3 -> 0.4.0
googletest 1.8.0 -> 1.10.0
snappy 1.1.7 -> 1.1.8
gperftools 2.7 -> 2.9.1
lz4 1.7.5 -> 1.9.3
curl 7.54.1 -> 7.79.0
re2 2017-05-01 -> 2021-02-02
zstd 1.3.7 -> 1.5.0
brotli 1.0.7 -> 1.0.9
flatbuffers 1.10.0 -> 2.0.0
apache-arrow 0.15.1 -> 5.0.0
CRoaring 0.2.60 -> 0.3.4
orc 1.5.8 -> 1.6.6
libdivide 4.0.0 -> 5.0
brpc 0.97 -> 1.0.0-rc02
librdkafka 1.7.0 -> 1.8.0

after this pr compile doris should use build-env:1.4.0
2021-10-15 13:03:04 +08:00

116 lines
3.6 KiB
C++

// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include "olap/file_helper.h"
#include <algorithm>
#include <filesystem>
#include <fstream>
#include "agent/status.h"
#include "common/configbase.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "olap/olap_define.h"
#include "test_util/test_util.h"
#include "util/logging.h"
#ifndef BE_TEST
#define BE_TEST
#endif
using ::testing::_;
using ::testing::Return;
using ::testing::SetArgPointee;
using std::string;
namespace doris {
class FileHandlerTest : public testing::Test {
public:
// create a mock cgroup folder
virtual void SetUp() {
std::filesystem::remove_all(_s_test_data_path);
ASSERT_FALSE(std::filesystem::exists(_s_test_data_path));
// create a mock cgroup path
ASSERT_TRUE(std::filesystem::create_directory(_s_test_data_path));
}
// delete the mock cgroup folder
virtual void TearDown() { ASSERT_TRUE(std::filesystem::remove_all(_s_test_data_path)); }
static std::string _s_test_data_path;
};
std::string FileHandlerTest::_s_test_data_path = "./log/file_handler_testxxxx123";
TEST_F(FileHandlerTest, TestWrite) {
FileHandler file_handler;
std::string file_name = _s_test_data_path + "/abcd123.txt";
// create a file using open
ASSERT_FALSE(std::filesystem::exists(file_name));
OLAPStatus op_status =
file_handler.open_with_mode(file_name, O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR);
ASSERT_EQ(OLAPStatus::OLAP_SUCCESS, op_status);
ASSERT_TRUE(std::filesystem::exists(file_name));
// tell current offset
off_t cur_offset = file_handler.tell();
ASSERT_EQ(0, cur_offset);
off_t length = file_handler.length();
ASSERT_EQ(0, length);
// seek to 10 and test offset
off_t res = file_handler.seek(10, SEEK_SET);
ASSERT_EQ(10, res);
length = file_handler.length();
ASSERT_EQ(0, length);
cur_offset = file_handler.tell();
ASSERT_EQ(10, cur_offset);
// write 12 bytes to disk
char ten_bytes[12];
memset(&ten_bytes, 0, sizeof(ten_bytes));
file_handler.write(&ten_bytes, sizeof(ten_bytes));
cur_offset = file_handler.tell();
ASSERT_EQ(22, cur_offset);
length = file_handler.length();
ASSERT_EQ(22, length);
char large_bytes2[(1 << 10)];
memset(&large_bytes2, 0, sizeof(large_bytes2));
int i = 1;
while (i < LOOP_LESS_OR_MORE(1 << 10, 1 << 17)) {
file_handler.write(&large_bytes2, sizeof(large_bytes2));
++i;
}
}
} // namespace doris
int main(int argc, char** argv) {
std::string conffile = std::string(getenv("DORIS_HOME")) + "/conf/be.conf";
if (!doris::config::init(conffile.c_str(), false)) {
fprintf(stderr, "error read config file. \n");
return -1;
}
doris::init_glog("be-test");
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}