FSTLevelDBLRUGarbageCollectorTests.mm 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright 2018 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <string>
  17. #import "Firestore/Example/Tests/Local/FSTLRUGarbageCollectorTests.h"
  18. #include "Firestore/core/src/firebase/firestore/local/leveldb_key.h"
  19. #include "Firestore/core/src/firebase/firestore/local/leveldb_persistence.h"
  20. #include "Firestore/core/src/firebase/firestore/local/lru_garbage_collector.h"
  21. #include "Firestore/core/src/firebase/firestore/local/persistence.h"
  22. #include "Firestore/core/src/firebase/firestore/model/document_key.h"
  23. #include "Firestore/core/test/firebase/firestore/local/persistence_testing.h"
  24. using firebase::firestore::local::LevelDbDocumentTargetKey;
  25. using firebase::firestore::local::LevelDbPersistence;
  26. using firebase::firestore::local::LevelDbPersistenceForTesting;
  27. using firebase::firestore::local::Persistence;
  28. using firebase::firestore::model::DocumentKey;
  29. using firebase::firestore::local::LruParams;
  30. NS_ASSUME_NONNULL_BEGIN
  31. @interface FSTLevelDBLRUGarbageCollectorTests : FSTLRUGarbageCollectorTests
  32. @end
  33. @implementation FSTLevelDBLRUGarbageCollectorTests
  34. - (std::unique_ptr<Persistence>)newPersistenceWithLruParams:(LruParams)lruParams {
  35. return LevelDbPersistenceForTesting(lruParams);
  36. }
  37. - (BOOL)sentinelExists:(const DocumentKey &)key {
  38. auto db = static_cast<local::LevelDbPersistence *>(self.persistence);
  39. std::string sentinelKey = LevelDbDocumentTargetKey::SentinelKey(key);
  40. std::string unusedValue;
  41. return !db->current_transaction()->Get(sentinelKey, &unusedValue).IsNotFound();
  42. }
  43. @end
  44. NS_ASSUME_NONNULL_END