//////////////////////////////////////////////////////////////////////////////// /// @brief test suite for application server /// /// @file /// /// DISCLAIMER /// /// Copyright 2004-2012 triagens 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 triAGENS GmbH, Cologne, Germany /// /// @author Jan Steemann /// @author Copyright 2017, ArangoDB GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// #include "Basics/Common.h" #include "gtest/gtest.h" #include "ApplicationFeatures/ApplicationFeature.h" #include "ApplicationFeatures/ApplicationServer.h" #include "Basics/Exceptions.h" #include "ProgramOptions/ProgramOptions.h" using namespace arangodb; // ----------------------------------------------------------------------------- // --SECTION-- test suite // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief setup //////////////////////////////////////////////////////////////////////////////// class TestFeatureA : public application_features::ApplicationFeature { public: TestFeatureA(application_features::ApplicationServer& server, std::string const& name, std::vector const& startsAfter, std::vector const& startsBefore) : ApplicationFeature(server, name) { for (auto const& it : startsAfter) { this->startsAfter(it); } for (auto const& it : startsBefore) { this->startsBefore(it); } } }; class TestFeatureB : public application_features::ApplicationFeature { public: TestFeatureB(application_features::ApplicationServer& server, std::string const& name, std::vector const& startsAfter, std::vector const& startsBefore) : ApplicationFeature(server, name) { for (auto const& it : startsAfter) { this->startsAfter(it); } for (auto const& it : startsBefore) { this->startsBefore(it); } } }; TEST(ApplicationServerTest, test_startsAfterValid) { bool failed = false; std::function callback = [&failed](std::string const&) { failed = true; }; auto options = std::make_shared("arangod", "something", "", "path"); application_features::ApplicationServer server(options, "path"); server.registerFailCallback(callback); auto& feature1 = server.addFeature("feature1", std::vector{}, std::vector{}); auto& feature2 = server.addFeature("feature2", std::vector{ std::type_index(typeid(TestFeatureA))}, std::vector{}); server.setupDependencies(true); EXPECT_FALSE(failed); EXPECT_TRUE(feature1.doesStartBefore()); EXPECT_FALSE(feature1.doesStartAfter()); EXPECT_FALSE(feature1.doesStartBefore()); EXPECT_TRUE(feature1.doesStartAfter()); EXPECT_FALSE(feature2.doesStartBefore()); EXPECT_TRUE(feature2.doesStartAfter()); EXPECT_FALSE(feature2.doesStartBefore()); EXPECT_TRUE(feature2.doesStartAfter()); } TEST(ApplicationServerTest, test_startsAfterCyclic) { bool failed = false; std::function callback = [&failed](std::string const&) { failed = true; }; auto options = std::make_shared("arangod", "something", "", "path"); application_features::ApplicationServer server(options, "path"); server.registerFailCallback(callback); server.addFeature("feature1", std::vector{ std::type_index(typeid(TestFeatureB))}, std::vector{}); server.addFeature("feature2", std::vector{ std::type_index(typeid(TestFeatureA))}, std::vector{}); try { server.setupDependencies(true); } catch (basics::Exception const& ex) { EXPECT_EQ(ex.code(), TRI_ERROR_INTERNAL); failed = true; } EXPECT_TRUE(failed); } TEST(ApplicationServerTest, test_startsBeforeCyclic) { bool failed = false; std::function callback = [&failed](std::string const&) { failed = true; }; auto options = std::make_shared("arangod", "something", "", "path"); application_features::ApplicationServer server(options, "path"); server.registerFailCallback(callback); server.addFeature("feature1", std::vector{}, std::vector{ std::type_index(typeid(TestFeatureB))}); server.addFeature("feature2", std::vector{}, std::vector{ std::type_index(typeid(TestFeatureA))}); try { server.setupDependencies(true); } catch (basics::Exception const& ex) { EXPECT_EQ(ex.code(), TRI_ERROR_INTERNAL); failed = true; } EXPECT_TRUE(failed); }