mirror of https://gitee.com/bigwinds/arangodb
253 lines
8.5 KiB
C++
253 lines
8.5 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
/// DISCLAIMER
|
|
///
|
|
/// Copyright 2018 ArangoDB GmbH, Cologne, Germany
|
|
///
|
|
/// 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.
|
|
///
|
|
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
|
///
|
|
/// @author Heiko Kernbach
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "RowFetcherHelper.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "Aql/AqlItemBlock.h"
|
|
#include "Aql/ExecutorInfos.h"
|
|
#include "Aql/InputAqlItemRow.h"
|
|
#include "Aql/LimitExecutor.h"
|
|
#include "Aql/ResourceUsage.h"
|
|
#include "Aql/SingleRowFetcher.h"
|
|
|
|
#include <velocypack/Builder.h>
|
|
#include <velocypack/velocypack-aliases.h>
|
|
|
|
using namespace arangodb;
|
|
using namespace arangodb::aql;
|
|
|
|
namespace arangodb {
|
|
namespace tests {
|
|
namespace aql {
|
|
|
|
class LimitExecutorTest : public ::testing::Test {
|
|
protected:
|
|
ExecutionState state;
|
|
ResourceMonitor monitor;
|
|
AqlItemBlockManager itemBlockManager;
|
|
SharedAqlItemBlockPtr block;
|
|
std::shared_ptr<const std::unordered_set<RegisterId>> outputRegisters;
|
|
std::shared_ptr<const std::unordered_set<RegisterId>> registersToKeep;
|
|
|
|
// Special parameters:
|
|
// 4th offset
|
|
// 5th limit
|
|
// 6th fullCount
|
|
// 7th queryDepth
|
|
|
|
LimitExecutorTest()
|
|
: itemBlockManager(&monitor),
|
|
block(new AqlItemBlock(itemBlockManager, 1000, 1)),
|
|
outputRegisters(std::make_shared<const std::unordered_set<RegisterId>>(
|
|
std::initializer_list<RegisterId>{})),
|
|
registersToKeep(std::make_shared<const std::unordered_set<RegisterId>>(
|
|
std::initializer_list<RegisterId>{0})) {}
|
|
};
|
|
|
|
TEST_F(LimitExecutorTest, no_rows_upstream_the_producer_doesnt_wait) {
|
|
LimitExecutorInfos infos(1, 1, {}, {0}, 0, 1, true);
|
|
VPackBuilder input;
|
|
|
|
SingleRowFetcherHelper<false> fetcher(input.steal(), false);
|
|
LimitExecutor testee(fetcher, infos);
|
|
LimitStats stats{};
|
|
|
|
OutputAqlItemRow result{std::move(block), outputRegisters, registersToKeep,
|
|
infos.registersToClear()};
|
|
std::tie(state, stats) = testee.produceRows(result);
|
|
ASSERT_TRUE(state == ExecutionState::DONE);
|
|
ASSERT_TRUE(!result.produced());
|
|
ASSERT_TRUE(stats.getFullCount() == 0);
|
|
}
|
|
|
|
TEST_F(LimitExecutorTest, now_rows_upstream_the_producer_waits) {
|
|
LimitExecutorInfos infos(1, 1, {}, {0}, 0, 1, true);
|
|
VPackBuilder input;
|
|
|
|
SingleRowFetcherHelper<false> fetcher(input.steal(), true);
|
|
LimitExecutor testee(fetcher, infos);
|
|
LimitStats stats{};
|
|
|
|
OutputAqlItemRow result{std::move(block), outputRegisters, registersToKeep,
|
|
infos.registersToClear()};
|
|
std::tie(state, stats) = testee.produceRows(result);
|
|
ASSERT_TRUE(state == ExecutionState::WAITING);
|
|
ASSERT_TRUE(!result.produced());
|
|
ASSERT_TRUE(stats.getFullCount() == 0);
|
|
|
|
std::tie(state, stats) = testee.produceRows(result);
|
|
ASSERT_TRUE(state == ExecutionState::DONE);
|
|
ASSERT_TRUE(!result.produced());
|
|
ASSERT_TRUE(stats.getFullCount() == 0);
|
|
}
|
|
|
|
TEST_F(LimitExecutorTest, rows_upstream_the_producer_doesnt_wait_limit_1_offset_0_fullcount_false) {
|
|
auto input = VPackParser::fromJson("[ [1], [2], [3], [4] ]");
|
|
LimitExecutorInfos infos(1, 1, {}, {0}, 0, 1, false);
|
|
SingleRowFetcherHelper<false> fetcher(input->steal(), false);
|
|
LimitExecutor testee(fetcher, infos);
|
|
LimitStats stats{};
|
|
|
|
OutputAqlItemRow row{std::move(block), outputRegisters, registersToKeep,
|
|
infos.registersToClear()};
|
|
|
|
std::tie(state, stats) = testee.produceRows(row);
|
|
ASSERT_TRUE(row.produced());
|
|
row.advanceRow();
|
|
|
|
std::tie(state, stats) = testee.produceRows(row);
|
|
ASSERT_TRUE(state == ExecutionState::DONE);
|
|
ASSERT_TRUE(!row.produced());
|
|
}
|
|
|
|
TEST_F(LimitExecutorTest, rows_upstream_the_producer_doesnt_wait_limit_1_offset_0_fullcount_true) {
|
|
auto input = VPackParser::fromJson("[ [1], [2], [3], [4] ]");
|
|
LimitExecutorInfos infos(1, 1, {}, {0}, 0, 1, true);
|
|
SingleRowFetcherHelper<false> fetcher(input->steal(), false);
|
|
LimitExecutor testee(fetcher, infos);
|
|
LimitStats stats{};
|
|
|
|
OutputAqlItemRow row{std::move(block), outputRegisters, registersToKeep,
|
|
infos.registersToClear()};
|
|
|
|
std::tie(state, stats) = testee.produceRows(row);
|
|
ASSERT_TRUE(state == ExecutionState::HASMORE);
|
|
ASSERT_TRUE(row.produced());
|
|
|
|
row.advanceRow();
|
|
|
|
std::tie(state, stats) = testee.produceRows(row);
|
|
ASSERT_TRUE(!row.produced());
|
|
ASSERT_TRUE(state == ExecutionState::DONE);
|
|
ASSERT_TRUE(stats.getFullCount() == 3);
|
|
|
|
auto block = row.stealBlock();
|
|
AqlValue value = block->getValue(0, 0);
|
|
ASSERT_TRUE(value.isNumber());
|
|
ASSERT_TRUE(value.toInt64() == 1);
|
|
}
|
|
|
|
TEST_F(LimitExecutorTest, rows_upstream_the_producer_doesnt_wait_limit_1_offset_1_fullcount_true) {
|
|
auto input = VPackParser::fromJson("[ [1], [2], [3], [4] ]");
|
|
LimitExecutorInfos infos(1, 1, {}, {0}, 1, 1, true);
|
|
SingleRowFetcherHelper<false> fetcher(input->steal(), false);
|
|
LimitExecutor testee(fetcher, infos);
|
|
LimitStats stats{};
|
|
|
|
OutputAqlItemRow row{std::move(block), outputRegisters, registersToKeep,
|
|
infos.registersToClear()};
|
|
|
|
std::tie(state, stats) = testee.produceRows(row);
|
|
ASSERT_TRUE(state == ExecutionState::HASMORE);
|
|
ASSERT_TRUE(row.produced());
|
|
|
|
row.advanceRow();
|
|
|
|
std::tie(state, stats) = testee.produceRows(row);
|
|
ASSERT_TRUE(!row.produced());
|
|
ASSERT_TRUE(state == ExecutionState::DONE);
|
|
ASSERT_TRUE(stats.getFullCount() == 2);
|
|
|
|
auto block = row.stealBlock();
|
|
AqlValue value = block->getValue(0, 0);
|
|
ASSERT_TRUE(value.isNumber());
|
|
ASSERT_TRUE(value.toInt64() == 2);
|
|
}
|
|
|
|
TEST_F(LimitExecutorTest, rows_upstream_the_producer_waits_limit_1_offset_0_fullcount_false) {
|
|
auto input = VPackParser::fromJson("[ [1], [2], [3], [4] ]");
|
|
LimitExecutorInfos infos(1, 1, {}, {0}, 0, 1, false);
|
|
SingleRowFetcherHelper<false> fetcher(input->steal(), true);
|
|
LimitExecutor testee(fetcher, infos);
|
|
LimitStats stats{};
|
|
|
|
OutputAqlItemRow row{std::move(block), outputRegisters, registersToKeep,
|
|
infos.registersToClear()};
|
|
|
|
std::tie(state, stats) = testee.produceRows(row);
|
|
ASSERT_TRUE(state == ExecutionState::WAITING);
|
|
ASSERT_TRUE(!row.produced());
|
|
|
|
std::tie(state, stats) = testee.produceRows(row);
|
|
ASSERT_TRUE(state == ExecutionState::DONE);
|
|
ASSERT_TRUE(row.produced());
|
|
|
|
row.advanceRow();
|
|
|
|
std::tie(state, stats) = testee.produceRows(row);
|
|
ASSERT_TRUE(state == ExecutionState::DONE);
|
|
ASSERT_TRUE(!row.produced());
|
|
|
|
auto block = row.stealBlock();
|
|
AqlValue value = block->getValue(0, 0);
|
|
ASSERT_TRUE(value.isNumber());
|
|
ASSERT_TRUE(value.toInt64() == 1);
|
|
}
|
|
|
|
TEST_F(LimitExecutorTest, rows_upstream_the_producer_waits_limit_1_offset_0_fullcount_true) {
|
|
auto input = VPackParser::fromJson("[ [1], [2], [3], [4] ]");
|
|
LimitExecutorInfos infos(1, 1, {}, {0}, 0, 1, true);
|
|
SingleRowFetcherHelper<false> fetcher(input->steal(), true);
|
|
LimitExecutor testee(fetcher, infos);
|
|
LimitStats stats{};
|
|
|
|
OutputAqlItemRow row{std::move(block), outputRegisters, registersToKeep,
|
|
infos.registersToClear()};
|
|
|
|
std::tie(state, stats) = testee.produceRows(row);
|
|
ASSERT_TRUE(state == ExecutionState::WAITING);
|
|
ASSERT_TRUE(!row.produced());
|
|
|
|
std::tie(state, stats) = testee.produceRows(row);
|
|
ASSERT_TRUE(state == ExecutionState::HASMORE);
|
|
ASSERT_TRUE(row.produced());
|
|
|
|
row.advanceRow();
|
|
|
|
std::tie(state, stats) = testee.produceRows(row);
|
|
ASSERT_TRUE(state == ExecutionState::WAITING);
|
|
ASSERT_TRUE(!row.produced());
|
|
|
|
std::tie(state, stats) = testee.produceRows(row);
|
|
ASSERT_TRUE(state == ExecutionState::WAITING);
|
|
ASSERT_TRUE(!row.produced());
|
|
|
|
std::tie(state, stats) = testee.produceRows(row);
|
|
ASSERT_TRUE(state == ExecutionState::WAITING);
|
|
ASSERT_TRUE(!row.produced());
|
|
|
|
std::tie(state, stats) = testee.produceRows(row);
|
|
ASSERT_TRUE(state == ExecutionState::DONE);
|
|
ASSERT_TRUE(stats.getFullCount() == 1);
|
|
ASSERT_TRUE(!row.produced());
|
|
|
|
auto block = row.stealBlock();
|
|
AqlValue value = block->getValue(0, 0);
|
|
ASSERT_TRUE(value.isNumber());
|
|
ASSERT_TRUE(value.toInt64() == 1);
|
|
}
|
|
|
|
} // namespace aql
|
|
} // namespace tests
|
|
} // namespace arangodb
|