virtual_db_mock.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 <map>
  19. #include <mutex>
  20. #include "codec_impl.h"
  21. #include "storage_type.h"
  22. #include "virtual_db.h"
  23. namespace wwsearch {
  24. class VirtualDBMock : public VirtualDB {
  25. private:
  26. CodecImpl* codec_;
  27. std::map<StorageColumnType, std::function<std::string(const std::string&)>>
  28. cf_debug_string_funcs_;
  29. using KvList = std::map<std::string, std::string>;
  30. std::map<StorageColumnType, KvList> cf_kv_list_;
  31. std::mutex mut_;
  32. public:
  33. VirtualDBMock(CodecImpl* codec);
  34. virtual ~VirtualDBMock() {}
  35. virtual bool Open() override;
  36. virtual VirtualDBSnapshot* NewSnapshot() override;
  37. virtual void ReleaseSnapshot(VirtualDBSnapshot*) override;
  38. virtual SearchStatus FlushBuffer(WriteBuffer* write_buffer) override;
  39. virtual WriteBuffer* NewWriteBuffer(const std::string* write_buffer) override;
  40. virtual void ReleaseWriteBuffer(WriteBuffer* buffer) override;
  41. virtual SearchStatus Get(StorageColumnType column, const std::string& key,
  42. std::string& value,
  43. VirtualDBSnapshot* snapshot) override;
  44. virtual void MultiGet(std::vector<StorageColumnType> columns,
  45. std::vector<std::string>& keys,
  46. std::vector<std::string>& values,
  47. std::vector<SearchStatus>& status,
  48. VirtualDBSnapshot* snapshot) override;
  49. virtual Iterator* NewIterator(StorageColumnType column,
  50. VirtualDBReadOption* options) override;
  51. virtual SearchStatus CompactRange(StorageColumnType column,
  52. const std::string& begin,
  53. const std::string& end) override;
  54. virtual SearchStatus DropDB() override;
  55. private:
  56. SearchStatus ParsePbString(const std::string& write_buffer_data);
  57. };
  58. } // namespace wwsearch