1 // Copyright (C) 2022 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef ICING_MONKEY_TEST_ICING_MONKEY_TEST_RUNNER_H_ 16 #define ICING_MONKEY_TEST_ICING_MONKEY_TEST_RUNNER_H_ 17 18 #include <cstdint> 19 #include <memory> 20 21 #include "icing/file/destructible-directory.h" 22 #include "icing/file/filesystem.h" 23 #include "icing/icing-search-engine.h" 24 #include "icing/monkey_test/in-memory-icing-search-engine.h" 25 #include "icing/monkey_test/monkey-test-generators.h" 26 #include "icing/monkey_test/monkey-test-util.h" 27 #include "icing/proto/schema.pb.h" 28 29 namespace icing { 30 namespace lib { 31 32 class IcingMonkeyTestRunner { 33 public: 34 IcingMonkeyTestRunner(IcingMonkeyTestRunnerConfiguration config); 35 IcingMonkeyTestRunner(const IcingMonkeyTestRunner&) = delete; 36 IcingMonkeyTestRunner& operator=(const IcingMonkeyTestRunner&) = delete; 37 38 SetSchemaResultProto SetSchema(SchemaProto&& schema); 39 40 // This function must and should only be called before running the monkey 41 // test. 42 void Initialize(); 43 44 // Run the monkey test with num operations. 45 void Run(uint32_t num); 46 47 // APIs supported in icing search engine. 48 void DoUpdateSchema(); 49 void DoGet(); 50 void DoGetAllNamespaces(); 51 void DoPut(); 52 void DoDelete(); 53 void DoDeleteByNamespace(); 54 void DoDeleteBySchemaType(); 55 void DoDeleteByQuery(); 56 void DoSearch(); 57 58 // Operations with no observable side-effects. 59 void ReloadFromDisk(); 60 void DoOptimize(); 61 62 private: 63 IcingMonkeyTestRunnerConfiguration config_; 64 MonkeyTestRandomEngine random_; 65 Filesystem filesystem_; 66 std::unique_ptr<DestructibleDirectory> icing_dir_; 67 std::unique_ptr<InMemoryIcingSearchEngine> in_memory_icing_; 68 std::unique_ptr<IcingSearchEngine> icing_; 69 70 std::unique_ptr<MonkeySchemaGenerator> schema_generator_; 71 std::unique_ptr<MonkeyDocumentGenerator> document_generator_; 72 73 void CreateIcingSearchEngine(); 74 }; 75 76 } // namespace lib 77 } // namespace icing 78 79 #endif // ICING_MONKEY_TEST_ICING_MONKEY_TEST_RUNNER_H_ 80