documentwriter_unit.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Tencent is pleased to support the open source community by making wwsearch
  3. * available.
  4. *
  5. * Copyright (C) 2018-present Tencent. All Rights Reserved.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  8. * use this file except in compliance with the License. You may obtain a copy of
  9. * the License at
  10. *
  11. * https://opensource.org/licenses/Apache-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OF ANY KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations under the License.
  17. */
  18. #include <gtest/gtest.h>
  19. #include "include/document.h"
  20. #include "include/document_writer.h"
  21. #include "include/index_wrapper.h"
  22. #include "include/search_status.h"
  23. #include "include/search_util.h"
  24. #include "unittest_util.h"
  25. extern bool g_debug;
  26. extern bool g_use_rocksdb;
  27. extern bool g_use_compression;
  28. namespace wwsearch {
  29. class DocumentWriterTest : public ::testing::Test {
  30. public:
  31. static DefaultIndexWrapper *index_;
  32. static uint64_t document_id_;
  33. static uint64_t numeric_value_;
  34. wwsearch::TableID table_;
  35. std::vector<DocumentUpdater *> documents_;
  36. std::list<DocumentID> match_documentsid_;
  37. public:
  38. DocumentWriterTest() {
  39. table_.business_type = 1;
  40. table_.partition_set = 1;
  41. }
  42. static void SetUpTestCase() {
  43. index_ = new DefaultIndexWrapper();
  44. index_->DBParams().path =
  45. std::string("/tmp/unit_") + std::string("DocumentWriter");
  46. index_->Config().SetLogLevel(g_debug ? wwsearch::kSearchLogLevelDebug
  47. : wwsearch::kSearchLogLevelError);
  48. auto status = index_->Open();
  49. ASSERT_TRUE(status.GetCode() == 0);
  50. }
  51. static void TearDownTestCase() {
  52. if (index_ != nullptr) {
  53. index_->vdb_->DropDB();
  54. delete index_;
  55. index_ = nullptr;
  56. }
  57. }
  58. virtual void SetUp() override {
  59. table_.partition_set++;
  60. match_documentsid_.clear();
  61. }
  62. virtual void TearDown() override {
  63. for (auto du : documents_) {
  64. delete du;
  65. }
  66. documents_.clear();
  67. match_documentsid_.clear();
  68. }
  69. uint64_t GetDocumentID() { return document_id_++; }
  70. uint64_t GetNumeric(uint64_t alloc_len = 1000) {
  71. auto temp = numeric_value_;
  72. numeric_value_ += alloc_len;
  73. return temp;
  74. }
  75. private:
  76. };
  77. DefaultIndexWrapper *DocumentWriterTest::index_ = nullptr;
  78. DocumentID DocumentWriterTest::document_id_ = 1;
  79. DocumentID DocumentWriterTest::numeric_value_ = 1;
  80. TEST_F(DocumentWriterTest, UpdateDocuments) {}
  81. } // namespace wwsearch