mirror of https://gitee.com/bigwinds/arangodb
254 lines
9.1 KiB
C++
254 lines
9.1 KiB
C++
//////////////////////////////////////////////////////////////////////////////
|
|
/// DISCLAIMER
|
|
///
|
|
/// Copyright 2017 EMC Corporation
|
|
///
|
|
/// 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 EMC Corporation
|
|
///
|
|
/// @author Andrey Abramov
|
|
/// @author Vasiliy Nabatchikov
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "catch.hpp"
|
|
#include "common.h"
|
|
#include "ExpressionContextMock.h"
|
|
#include "StorageEngineMock.h"
|
|
|
|
#include "GeneralServer/AuthenticationFeature.h"
|
|
#include "IResearch/ApplicationServerHelper.h"
|
|
#include "IResearch/IResearchFilterFactory.h"
|
|
#include "IResearch/IResearchFeature.h"
|
|
#include "IResearch/IResearchLinkMeta.h"
|
|
#include "IResearch/IResearchViewMeta.h"
|
|
#include "IResearch/IResearchAnalyzerFeature.h"
|
|
#include "IResearch/IResearchKludge.h"
|
|
#include "IResearch/ExpressionFilter.h"
|
|
#include "IResearch/SystemDatabaseFeature.h"
|
|
#include "IResearch/AqlHelper.h"
|
|
#include "Logger/Logger.h"
|
|
#include "Logger/LogTopic.h"
|
|
#include "StorageEngine/EngineSelectorFeature.h"
|
|
#include "RestServer/AqlFeature.h"
|
|
#include "RestServer/DatabaseFeature.h"
|
|
#include "RestServer/QueryRegistryFeature.h"
|
|
#include "RestServer/TraverserEngineRegistryFeature.h"
|
|
#include "RestServer/ViewTypesFeature.h"
|
|
#include "Aql/Ast.h"
|
|
#include "Aql/Query.h"
|
|
#include "Aql/ExecutionPlan.h"
|
|
#include "Aql/AqlFunctionFeature.h"
|
|
#include "Transaction/StandaloneContext.h"
|
|
#include "Transaction/UserTransaction.h"
|
|
|
|
#ifdef USE_ENTERPRISE
|
|
#include "Enterprise/Ldap/LdapFeature.h"
|
|
#endif
|
|
|
|
#include "analysis/analyzers.hpp"
|
|
#include "analysis/token_streams.hpp"
|
|
#include "analysis/token_attributes.hpp"
|
|
#include "search/term_filter.hpp"
|
|
#include "search/all_filter.hpp"
|
|
#include "search/prefix_filter.hpp"
|
|
#include "search/range_filter.hpp"
|
|
#include "search/granular_range_filter.hpp"
|
|
#include "search/column_existence_filter.hpp"
|
|
#include "search/boolean_filter.hpp"
|
|
#include "search/phrase_filter.hpp"
|
|
|
|
NS_LOCAL
|
|
|
|
struct TestAttribute: public irs::attribute {
|
|
DECLARE_ATTRIBUTE_TYPE();
|
|
};
|
|
|
|
DEFINE_ATTRIBUTE_TYPE(TestAttribute);
|
|
|
|
struct TestTermAttribute: public irs::term_attribute {
|
|
public:
|
|
void value(irs::bytes_ref const& value) {
|
|
value_ = value;
|
|
}
|
|
};
|
|
|
|
class TestAnalyzer: public irs::analysis::analyzer {
|
|
public:
|
|
DECLARE_ANALYZER_TYPE();
|
|
|
|
static ptr make(irs::string_ref const& args) {
|
|
if (args.null()) throw std::exception();
|
|
if (args.empty()) return nullptr;
|
|
PTR_NAMED(TestAnalyzer, ptr);
|
|
return ptr;
|
|
}
|
|
|
|
TestAnalyzer() : irs::analysis::analyzer(TestAnalyzer::type()) {
|
|
_attrs.emplace(_term);
|
|
_attrs.emplace(_attr);
|
|
}
|
|
|
|
virtual irs::attribute_view const& attributes() const NOEXCEPT override { return _attrs; }
|
|
|
|
virtual bool next() override {
|
|
if (_data.empty()) {
|
|
return false;
|
|
}
|
|
|
|
_term.value(irs::bytes_ref(_data.c_str(), 1));
|
|
_data = irs::bytes_ref(_data.c_str() + 1, _data.size() - 1);
|
|
return true;
|
|
}
|
|
|
|
virtual bool reset(irs::string_ref const& data) override {
|
|
_data = irs::ref_cast<irs::byte_type>(data);
|
|
return true;
|
|
}
|
|
|
|
private:
|
|
irs::attribute_view _attrs;
|
|
irs::bytes_ref _data;
|
|
TestTermAttribute _term;
|
|
TestAttribute _attr;
|
|
};
|
|
|
|
DEFINE_ANALYZER_TYPE_NAMED(TestAnalyzer, "TestCharAnalyzer");
|
|
REGISTER_ANALYZER_JSON(TestAnalyzer, TestAnalyzer::make);
|
|
|
|
NS_END
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- setup / tear-down
|
|
// -----------------------------------------------------------------------------
|
|
|
|
struct IResearchFilterSetup {
|
|
StorageEngineMock engine;
|
|
arangodb::application_features::ApplicationServer server;
|
|
std::unique_ptr<TRI_vocbase_t> system;
|
|
std::vector<std::pair<arangodb::application_features::ApplicationFeature*, bool>> features;
|
|
|
|
IResearchFilterSetup(): server(nullptr, nullptr) {
|
|
arangodb::EngineSelectorFeature::ENGINE = &engine;
|
|
arangodb::aql::AqlFunctionFeature* functions = nullptr;
|
|
|
|
arangodb::tests::init();
|
|
|
|
// suppress INFO {authentication} Authentication is turned on (system only), authentication for unix sockets is turned on
|
|
arangodb::LogTopic::setLogLevel(arangodb::Logger::AUTHENTICATION.name(), arangodb::LogLevel::WARN);
|
|
|
|
// suppress log messages since tests check error conditions
|
|
arangodb::LogTopic::setLogLevel(arangodb::iresearch::IResearchFeature::IRESEARCH.name(), arangodb::LogLevel::FATAL);
|
|
irs::logger::output_le(iresearch::logger::IRL_FATAL, stderr);
|
|
|
|
// setup required application features
|
|
#ifdef USE_ENTERPRISE
|
|
features.emplace_back(new arangodb::LdapFeature(&server), false);
|
|
#endif
|
|
features.emplace_back(new arangodb::AuthenticationFeature(&server), true);
|
|
features.emplace_back(new arangodb::DatabaseFeature(&server), false);
|
|
features.emplace_back(new arangodb::QueryRegistryFeature(&server), false); // must be first
|
|
arangodb::application_features::ApplicationServer::server->addFeature(features.back().first);
|
|
system = irs::memory::make_unique<TRI_vocbase_t>(TRI_vocbase_type_e::TRI_VOCBASE_TYPE_NORMAL, 0, TRI_VOC_SYSTEM_DATABASE);
|
|
features.emplace_back(new arangodb::TraverserEngineRegistryFeature(&server), false); // must be before AqlFeature
|
|
features.emplace_back(new arangodb::ViewTypesFeature(&server), false); // required for IResearchFeature
|
|
features.emplace_back(new arangodb::AqlFeature(&server), true);
|
|
features.emplace_back(functions = new arangodb::aql::AqlFunctionFeature(&server), true); // required for IResearchAnalyzerFeature
|
|
features.emplace_back(new arangodb::iresearch::IResearchAnalyzerFeature(&server), true);
|
|
features.emplace_back(new arangodb::iresearch::IResearchFeature(&server), true);
|
|
features.emplace_back(new arangodb::iresearch::SystemDatabaseFeature(&server, system.get()), false); // required for IResearchAnalyzerFeature
|
|
|
|
for (auto& f : features) {
|
|
arangodb::application_features::ApplicationServer::server->addFeature(f.first);
|
|
}
|
|
|
|
for (auto& f : features) {
|
|
f.first->prepare();
|
|
}
|
|
|
|
for (auto& f : features) {
|
|
if (f.second) {
|
|
f.first->start();
|
|
}
|
|
}
|
|
|
|
// register fake non-deterministic function in order to suppress optimizations
|
|
functions->add(arangodb::aql::Function{
|
|
"_NONDETERM_",
|
|
".",
|
|
false, // fake non-deterministic
|
|
false, // fake can throw
|
|
true,
|
|
false,
|
|
[](arangodb::aql::Query*, arangodb::transaction::Methods*, arangodb::aql::VPackFunctionParameters const& params) {
|
|
TRI_ASSERT(!params.empty());
|
|
return params[0];
|
|
}});
|
|
|
|
// register fake non-deterministic function in order to suppress optimizations
|
|
functions->add(arangodb::aql::Function{
|
|
"_FORWARD_",
|
|
".",
|
|
true, // fake deterministic
|
|
false, // fake can throw
|
|
true,
|
|
false,
|
|
[](arangodb::aql::Query*, arangodb::transaction::Methods*, arangodb::aql::VPackFunctionParameters const& params) {
|
|
TRI_ASSERT(!params.empty());
|
|
return params[0];
|
|
}});
|
|
|
|
auto* analyzers = arangodb::iresearch::getFeature<arangodb::iresearch::IResearchAnalyzerFeature>();
|
|
|
|
analyzers->emplace("test_analyzer", "TestCharAnalyzer", "abc"); // cache analyzer
|
|
}
|
|
|
|
~IResearchFilterSetup() {
|
|
system.reset(); // destroy before reseting the 'ENGINE'
|
|
arangodb::AqlFeature(&server).stop(); // unset singleton instance
|
|
arangodb::LogTopic::setLogLevel(arangodb::iresearch::IResearchFeature::IRESEARCH.name(), arangodb::LogLevel::DEFAULT);
|
|
arangodb::application_features::ApplicationServer::server = nullptr;
|
|
arangodb::EngineSelectorFeature::ENGINE = nullptr;
|
|
|
|
// destroy application features
|
|
for (auto& f : features) {
|
|
if (f.second) {
|
|
f.first->stop();
|
|
}
|
|
}
|
|
|
|
for (auto& f : features) {
|
|
f.first->unprepare();
|
|
}
|
|
|
|
arangodb::LogTopic::setLogLevel(arangodb::Logger::AUTHENTICATION.name(), arangodb::LogLevel::DEFAULT);
|
|
}
|
|
}; // IResearchFilterSetup
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- test suite
|
|
// -----------------------------------------------------------------------------
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/// @brief setup
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
TEST_CASE("IResearchFilterTest", "[iresearch][iresearch-filter]") {
|
|
IResearchFilterSetup s;
|
|
UNUSED(s);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// --SECTION-- END-OF-FILE
|
|
// -----------------------------------------------------------------------------
|