Files
doris/be/test/runtime/result_buffer_mgr_test.cpp
李超勇 6486be64c3 fix license statement (#29)
* change picture to word

* change picture to word

* SHOW FULL TABLES WHERE Table_type != VIEW sql can not execute

* change license description
2017-08-18 19:16:23 +08:00

130 lines
3.9 KiB
C++

// Copyright (c) 2017, Baidu.com, Inc. All Rights Reserved
// Licensed 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 <gtest/gtest.h>
#include <boost/shared_ptr.hpp>
#include "util/cpu_info.h"
#include "runtime/result_buffer_mgr.h"
#include "runtime/buffer_control_block.h"
#include "gen_cpp/PaloInternalService_types.h"
namespace palo {
class ResultBufferMgrTest : public testing::Test {
public:
ResultBufferMgrTest() {
}
virtual ~ResultBufferMgrTest() {
}
protected:
virtual void SetUp() {
}
private:
};
TEST_F(ResultBufferMgrTest, create_normal) {
ResultBufferMgr buffer_mgr;
TUniqueId query_id;
query_id.lo = 10;
query_id.hi = 100;
boost::shared_ptr<BufferControlBlock> control_block1;
ASSERT_TRUE(buffer_mgr.create_sender(query_id, 1024, &control_block1).ok());
}
TEST_F(ResultBufferMgrTest, create_same_buffer) {
ResultBufferMgr buffer_mgr;
TUniqueId query_id;
query_id.lo = 10;
query_id.hi = 100;
boost::shared_ptr<BufferControlBlock> control_block1;
ASSERT_TRUE(buffer_mgr.create_sender(query_id, 1024, &control_block1).ok());
boost::shared_ptr<BufferControlBlock> control_block2;
ASSERT_TRUE(buffer_mgr.create_sender(query_id, 1024, &control_block2).ok());
ASSERT_EQ(control_block1.get(), control_block1.get());
}
TEST_F(ResultBufferMgrTest, fetch_data_normal) {
ResultBufferMgr buffer_mgr;
TUniqueId query_id;
query_id.lo = 10;
query_id.hi = 100;
boost::shared_ptr<BufferControlBlock> control_block1;
ASSERT_TRUE(buffer_mgr.create_sender(query_id, 1024, &control_block1).ok());
TFetchDataResult* result = new TFetchDataResult();
result->result_batch.rows.push_back("hello test");
control_block1->add_batch(result);
TFetchDataResult get_result;
ASSERT_TRUE(buffer_mgr.fetch_data(query_id, &get_result).ok());
ASSERT_EQ(1U, get_result.result_batch.rows.size());
ASSERT_STREQ("hello test", get_result.result_batch.rows[0].c_str());
}
TEST_F(ResultBufferMgrTest, fetch_data_no_block) {
ResultBufferMgr buffer_mgr;
TUniqueId query_id;
query_id.lo = 10;
query_id.hi = 100;
boost::shared_ptr<BufferControlBlock> control_block1;
ASSERT_TRUE(buffer_mgr.create_sender(query_id, 1024, &control_block1).ok());
TFetchDataResult* result = new TFetchDataResult();
query_id.lo = 11;
query_id.hi = 100;
ASSERT_FALSE(buffer_mgr.fetch_data(query_id, result).ok());
delete result;
}
TEST_F(ResultBufferMgrTest, normal_cancel) {
ResultBufferMgr buffer_mgr;
TUniqueId query_id;
query_id.lo = 10;
query_id.hi = 100;
boost::shared_ptr<BufferControlBlock> control_block1;
ASSERT_TRUE(buffer_mgr.create_sender(query_id, 1024, &control_block1).ok());
ASSERT_TRUE(buffer_mgr.cancel(query_id).ok());
}
TEST_F(ResultBufferMgrTest, cancel_no_block) {
ResultBufferMgr buffer_mgr;
TUniqueId query_id;
query_id.lo = 10;
query_id.hi = 100;
ASSERT_TRUE(buffer_mgr.cancel(query_id).ok());
}
}
int main(int argc, char** argv) {
std::string conffile = std::string(getenv("PALO_HOME")) + "/conf/be.conf";
if (!palo::config::init(conffile.c_str(), false)) {
fprintf(stderr, "error read config file. \n");
return -1;
}
// palo::init_glog("be-test");
::testing::InitGoogleTest(&argc, argv);
palo::CpuInfo::init();
return RUN_ALL_TESTS();
}
/* vim: set ts=4 sw=4 sts=4 tw=100 */